Skip to content

Commit 9c4560e

Browse files
committed
[fix] add delay time to wait vbus drop
Following PD vendor suggestion, when disabled port needs to wait 280ms for VBUS drop than can enable port again Signed-off-by: Leo_Tsai <LeoCX_Tsai@compal.com>
1 parent 78f8929 commit 9c4560e

3 files changed

Lines changed: 71 additions & 26 deletions

File tree

board/hx30/cypress5525.c

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,14 @@ void cypd_set_error_recovery(void)
430430
}
431431
}
432432

433+
static bool reconnect_flag;
434+
435+
static void reconnect_port_deferred(void)
436+
{
437+
cypd_aconly_reconnect();
438+
}
439+
DECLARE_DEFERRED(reconnect_port_deferred);
440+
433441
void update_system_power_state(void)
434442
{
435443

@@ -440,6 +448,7 @@ void update_system_power_state(void)
440448
case POWER_S5G3:
441449
case POWER_S3S5:
442450
cypd_set_power_state(CYP5525_POWERSTATE_S5);
451+
reconnect_flag = true;
443452
break;
444453
/* wait PD FW stable */
445454
/*case POWER_S0S0ix:
@@ -449,9 +458,12 @@ void update_system_power_state(void)
449458
default:
450459
cypd_set_error_recovery();
451460
cypd_set_power_state(CYP5525_POWERSTATE_S0);
461+
if (reconnect_flag) {
462+
reconnect_flag = false;
463+
CPRINTS("CYPD reconnect");
464+
cypd_aconly_reconnect();
465+
}
452466
break;
453-
454-
455467
}
456468

457469
}
@@ -1232,7 +1244,7 @@ void cypd_reinitialize(void)
12321244

12331245
void cypd_interrupt_handler_task(void *p)
12341246
{
1235-
int i, j, evt;
1247+
int i, j, evt, events;
12361248
cypd_int_task_id = task_get_current();
12371249

12381250
/* Initialize all charge suppliers to 0 */
@@ -1270,6 +1282,25 @@ void cypd_interrupt_handler_task(void *p)
12701282
}
12711283
}
12721284

1285+
if (evt & CYPD_EVT_PORT_DISABLE) {
1286+
CPRINTS("CYPD_EVT_PORT_DISABLE");
1287+
cypd_reconnect_port_disable(0, 0);
1288+
cypd_reconnect_port_disable(1, 0);
1289+
cypd_reconnect_port_disable(0, 1);
1290+
cypd_reconnect_port_disable(1, 1);
1291+
events = task_wait_event_mask(TASK_EVENT_TIMER, 300*MSEC);
1292+
if (events & TASK_EVENT_TIMER)
1293+
cypd_enque_evt(CYPD_EVT_PORT_ENABLE, 0);
1294+
}
1295+
1296+
if (evt & CYPD_EVT_PORT_ENABLE) {
1297+
CPRINTS("CYPD_EVT_PORT_ENABLE");
1298+
cypd_reconnect_port_enable(0, 0);
1299+
cypd_reconnect_port_enable(1, 0);
1300+
cypd_reconnect_port_enable(0, 1);
1301+
cypd_reconnect_port_enable(1, 1);
1302+
}
1303+
12731304
if (evt & CYPD_EVT_S_CHANGE) {
12741305
update_system_power_state();
12751306
}
@@ -1311,13 +1342,10 @@ void cypd_interrupt_handler_task(void *p)
13111342
}
13121343
}
13131344

1314-
1315-
1316-
int cypd_reconnect_port(int controller, int port)
1345+
int cypd_reconnect_port_disable(int controller, int port)
13171346
{
13181347
int rv;
13191348
uint8_t pd_status_reg[4];
1320-
int port_idx = (controller << 1) + port;
13211349
int port_pd_state, port_power_role, data;
13221350

13231351
rv = cypd_read_reg_block(controller, CYP5525_PD_STATUS_REG(port), pd_status_reg, 4);
@@ -1334,49 +1362,61 @@ int cypd_reconnect_port(int controller, int port)
13341362
if (rv != EC_SUCCESS)
13351363
return rv;
13361364

1337-
CPRINTS("Port data0: %d", data);
1338-
13391365
data &= ~BIT(port);
13401366

1341-
CPRINTS("Port data1: %d", data);
1342-
13431367
rv = cypd_write_reg8(controller, CYP5525_PDPORT_ENABLE_REG, data);
13441368
if (rv != EC_SUCCESS)
13451369
return rv;
13461370

1347-
cyp5225_wait_for_ack(controller, 1 * SECOND);
1371+
CPRINTS("disable controller: %d, Port: %d", controller, port);
13481372

1349-
data |= BIT(port);
1373+
return rv;
1374+
}
13501375

1351-
CPRINTS("Port data2: %d", data);
1376+
int cypd_reconnect_port_enable(int controller, int port)
1377+
{
1378+
int rv;
1379+
uint8_t pd_status_reg[4];
1380+
int port_pd_state, port_power_role, data;
1381+
1382+
rv = cypd_read_reg_block(controller, CYP5525_PD_STATUS_REG(port), pd_status_reg, 4);
1383+
if (rv != EC_SUCCESS)
1384+
CPRINTS("CYP5525_PD_STATUS_REG failed");
1385+
1386+
port_pd_state = pd_status_reg[1] & BIT(2);
1387+
port_power_role = pd_status_reg[1] & BIT(0);
1388+
1389+
if (port_power_role == PD_ROLE_SINK && port_pd_state)
1390+
return EC_SUCCESS;
1391+
1392+
rv = cypd_read_reg8(controller, CYP5525_PDPORT_ENABLE_REG, &data);
1393+
if (rv != EC_SUCCESS)
1394+
return rv;
1395+
1396+
data |= BIT(port);
13521397

13531398
rv = cypd_write_reg8(controller, CYP5525_PDPORT_ENABLE_REG, data);
13541399
if (rv != EC_SUCCESS)
13551400
return rv;
13561401

1357-
cyp5225_wait_for_ack(controller, 200 * MSEC);
1402+
CPRINTS("enable controller: %d, Port: %d", controller, port);
13581403

1359-
CPRINTS("PD Re connect controller: %d, Port: %d", controller, port_idx);
13601404
return rv;
13611405
}
13621406

13631407
void cypd_aconly_reconnect(void)
13641408
{
1365-
int batt_status;
1409+
int batt_status, events;
13661410

13671411
battery_status(&batt_status);
13681412

13691413
if (extpower_is_present() && battery_is_present() != BP_YES) {
1370-
cypd_reconnect_port(0, 0);
1371-
msleep(20);
1372-
cypd_reconnect_port(0, 1);
1373-
cypd_reconnect_port(1, 0);
1374-
msleep(20);
1375-
cypd_reconnect_port(1, 1);
1414+
events = task_wait_event_mask(TASK_EVENT_TIMER, 100*MSEC);
1415+
if (events & TASK_EVENT_TIMER)
1416+
cypd_enque_evt(CYPD_EVT_PORT_DISABLE, 0);
13761417
}
13771418
}
13781419

1379-
13801420
int cypd_get_pps_power_budget(void)
13811421
{
13821422
/* TODO:

board/hx30/cypress5525.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,9 @@ enum pd_task_evt {
404404
CYPD_EVT_UCSI_POLL_CTRL_0 = BIT(7),
405405
CYPD_EVT_UCSI_POLL_CTRL_1 = BIT(8),
406406
CYPD_EVT_RETIMER_PWR = BIT(9),
407-
CYPD_EVT_UPDATE_PWRSTAT = BIT(10)
407+
CYPD_EVT_UPDATE_PWRSTAT = BIT(10),
408+
CYPD_EVT_PORT_ENABLE = BIT(11),
409+
CYPD_EVT_PORT_DISABLE = BIT(12)
408410
};
409411

410412
/* PD CHIP */
@@ -459,4 +461,8 @@ void set_pd_fw_update(bool update);
459461
void cypd_charger_init_complete(void);
460462

461463
void cypd_aconly_reconnect(void);
464+
465+
int cypd_reconnect_port_enable(int controller, int port);
466+
467+
int cypd_reconnect_port_disable(int controller, int port);
462468
#endif /* __CROS_EC_CYPRESS5525_H */

board/hx30/power_sequence.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ enum power_state power_handle_state(enum power_state state)
563563
me_gpio_change(GPIO_FLAG_NONE);
564564

565565
cypd_set_power_active(POWER_S0);
566-
cypd_aconly_reconnect();
567566
CPRINTS("PH S3S0->S0");
568567
return POWER_S0;
569568

0 commit comments

Comments
 (0)