Skip to content

Commit 60beb13

Browse files
committed
- Introduced 200ms after anx init after some tests
- Introduced the power role detection and VBUS enable according to this bit
1 parent 3018961 commit 60beb13

File tree

3 files changed

+116
-3
lines changed

3 files changed

+116
-3
lines changed

libraries/Portenta_Video/anx7625.cpp

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ int anx7625_init(uint8_t bus)
13241324
return -1;
13251325
}
13261326
ANXINFO("Powering on anx7625 successfull.\n");
1327-
1327+
mdelay(200); // Wait for anx7625 to be stable
13281328
return 0;
13291329
}
13301330

@@ -1338,3 +1338,95 @@ void anx7625_wait_hpd_event(uint8_t bus)
13381338
break;
13391339
}
13401340
}
1341+
1342+
int anx7625_get_cc_status(uint8_t bus, uint8_t *cc_status)
1343+
{
1344+
int ret = 0;
1345+
ret = anx7625_reg_read(bus, RX_P0_ADDR, NEW_CC_STATUS, cc_status); // 0x7e, 0x46
1346+
if (ret < 0) {
1347+
ANXERROR("Failed %s", __func__);
1348+
return ret;
1349+
}
1350+
switch (*cc_status & 0x0F) {
1351+
case 0:
1352+
ANXDEBUG("anx: CC1: SRC.Open\n"); break;
1353+
case 1:
1354+
ANXDEBUG("anx: CC1: SRC.Rd\n"); break;
1355+
case 2:
1356+
ANXDEBUG("anx: CC1: SRC.Ra\n"); break;
1357+
case 4:
1358+
ANXDEBUG("anx: CC1: SNK.default\n"); break;
1359+
case 8:
1360+
ANXDEBUG("anx: CC1: SNK.power.1.5\n"); break;
1361+
case 12:
1362+
ANXDEBUG("anx: CC1: SNK.power.3.0\n"); break;
1363+
default:
1364+
ANXDEBUG("anx: CC1: Reserved\n");
1365+
}
1366+
switch (*cc_status & 0xF0) {
1367+
case 0:
1368+
ANXDEBUG("anx: CC2: SRC.Open\n"); break;
1369+
case 1:
1370+
ANXDEBUG("anx: CC2: SRC.Rd\n"); break;
1371+
case 2:
1372+
ANXDEBUG("anx: CC2: SRC.Ra\n"); break;
1373+
case 4:
1374+
ANXDEBUG("anx: CC2: SNK.default\n"); break;
1375+
case 8:
1376+
ANXDEBUG("anx: CC2: SNK.power.1.5\n"); break;
1377+
case 12:
1378+
ANXDEBUG("anx: CC2: SNK.power.3.0\n"); break;
1379+
default:
1380+
ANXDEBUG("anx: CC2: Reserved\n");
1381+
}
1382+
return ret;
1383+
}
1384+
1385+
int anx7625_read_system_status(uint8_t bus, uint8_t *sys_status)
1386+
{
1387+
int ret = 0;
1388+
ret = anx7625_reg_read(bus, RX_P0_ADDR, SYSTEM_STSTUS, sys_status); // 0x7e, 0x45
1389+
if (ret < 0) {
1390+
ANXERROR("Failed %s", __func__);
1391+
return ret;
1392+
}
1393+
if (*sys_status & (1<<2))
1394+
ANXDEBUG("anx: - VCONN status ON\n");
1395+
if (!(*sys_status & (1<<2)))
1396+
ANXDEBUG("anx: - VCONN status OFF\n");
1397+
1398+
if (*sys_status & (1<<3))
1399+
ANXDEBUG("anx: - VBUS power provider\n");
1400+
if (!(*sys_status & (1<<3)))
1401+
ANXDEBUG("anx: - VBUS power consumer\n");
1402+
1403+
if (*sys_status & (1<<5))
1404+
ANXDEBUG("anx: - Data Role: DFP\n");
1405+
if (!(*sys_status & (1<<5)))
1406+
ANXDEBUG("anx: - Data Role: UFP\n");
1407+
1408+
if (*sys_status & (1<<7))
1409+
ANXDEBUG("anx: - DP HPD high\n");
1410+
if (!(*sys_status & (1<<7)))
1411+
ANXDEBUG("anx: - DP HPD low\n");
1412+
return ret;
1413+
}
1414+
1415+
// This function is used to understand if we need to provide VBUS on USB-C
1416+
// connector or not
1417+
bool anx7625_is_power_provider(uint8_t bus)
1418+
{
1419+
int ret = 0;
1420+
uint8_t sys_status = 0;
1421+
anx7625_read_system_status(bus, &sys_status);
1422+
if (ret < 0) {
1423+
ANXERROR("Failed %s", __func__);
1424+
return false; // Conservative
1425+
}
1426+
else {
1427+
if (sys_status & (1<<3))
1428+
return true;
1429+
else
1430+
return false;
1431+
}
1432+
}

libraries/Portenta_Video/anx7625.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ extern "C" {
6868
#define INTR_SOFTWARE_INT (1<<3)
6969
#define INTR_RECEIVED_MSG (1<<5)
7070

71-
#define SYSTEM_STSTUS 0x45
7271
#define INTERFACE_CHANGE_INT 0x44
7372
#define HPD_STATUS_CHANGE 0x80
74-
#define HPD_STATUS 0x80
7573

7674
/******** END of I2C Address 0x58 ********/
7775

@@ -199,6 +197,16 @@ extern "C" {
199197
#define AP_MIPI_RX_EN (1<<5) /* 1: MIPI RX input in 0: no RX in */
200198
#define AP_DISABLE_PD (1<<6)
201199
#define AP_DISABLE_DISPLAY (1<<7)
200+
201+
#define SYSTEM_STSTUS 0x45
202+
#define VCONN_STATUS (1<<2)
203+
#define VBUS_STATUS (1<<3)
204+
#define DATA_ROLE_STATUS (1<<5)
205+
#define HPD_STATUS (1<<7)
206+
#define NEW_CC_STATUS 0x46
207+
208+
/******** END of I2C Address 0x7e *********/
209+
202210
/***************************************************************/
203211
/* Register definition of device address 0x84 */
204212
#define MIPI_PHY_CONTROL_3 0x03
@@ -364,6 +372,9 @@ int anx7625_dp_start(uint8_t bus, const struct edid *edid, enum edid_modes mode
364372
int anx7625_dp_get_edid(uint8_t bus, struct edid *out);
365373
int anx7625_init(uint8_t bus);
366374
void anx7625_wait_hpd_event(uint8_t bus);
375+
int anx7625_get_cc_status(uint8_t bus, uint8_t *cc_status);
376+
int anx7625_read_system_status(uint8_t bus, uint8_t *sys_status);
377+
bool anx7625_is_power_provider(uint8_t bus);
367378
int stm32_dsi_config(uint8_t bus, struct edid *edid, struct display_timing *dt);
368379
void stm32_BriefDisplay(void);
369380
void stm32_LCD_Clear(uint32_t color);

libraries/Portenta_Video/examples/Envie_video_coreboot/Envie_video_coreboot.ino

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ struct edid recognized_edid;
77

88
mbed::DigitalOut video_on(PK_2);
99
mbed::DigitalOut video_rst(PJ_3);
10+
mbed::DigitalOut otg_on(PJ_6);
1011

1112
void setup() {
1213
// put your setup code here, to run once:
14+
printf("OTG_ON = 1 -> VBUS OFF\n");
15+
otg_on = 1;
16+
1317
delay(1000);
1418
video_on = 1;
1519
delay(10);
@@ -32,6 +36,12 @@ void setup() {
3236
while(1);
3337
}
3438

39+
if(anx7625_is_power_provider(0)) {
40+
printf("OTG_ON = 0 -> VBUS ON\n");
41+
otg_on = 0;
42+
delay(1000); // Wait for device to be stable
43+
}
44+
3545
anx7625_wait_hpd_event(0);
3646

3747
anx7625_dp_get_edid(0, &recognized_edid);

0 commit comments

Comments
 (0)