Skip to content

Commit 62dd422

Browse files
committed
[fix] make sure RP setting is correct before boot up
Signed-off-by: Leo_Tsai <LeoCX_Tsai@compal.com>
1 parent c72cc73 commit 62dd422

3 files changed

Lines changed: 62 additions & 44 deletions

File tree

board/hx30/cypress5525.c

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ struct extended_msg tx_emsg[CONFIG_USB_PD_PORT_MAX_COUNT];
8888
bool verbose_msg_logging;
8989
static bool firmware_update;
9090
static int pd_3a_flag;
91+
static int pd_3a_set;
9192
static int pd_3a_controller;
9293
static int pd_3a_port;
9394
static int pd_port0_1_5A;
@@ -982,12 +983,12 @@ void cyp5525_port_int(int controller, int port)
982983
break;
983984
case CYPD_RESPONSE_PD_CONTRACT_NEGOTIATION_COMPLETE:
984985
CPRINTS("CYPD_RESPONSE_PD_CONTRACT_NEGOTIATION_COMPLETE %d", port_idx);
985-
/*todo we can probably clean this up to remove some of this*/
986986
cypd_set_typec_profile(controller, port);
987987
cypd_update_port_state(controller, port);
988988
break;
989989
case CYPD_RESPONSE_PORT_CONNECT:
990990
CPRINTS("CYPD_RESPONSE_PORT_CONNECT %d", port_idx);
991+
cypd_set_typec_profile(controller, port);
991992
cypd_update_port_state(controller, port);
992993
break;
993994
case CYPD_RESPONSE_EXT_MSG_SOP_RX:
@@ -1407,13 +1408,15 @@ void cypd_aconly_reconnect(void)
14071408
cypd_enque_evt(CYPD_EVT_PORT_DISABLE, 0);
14081409
}
14091410

1410-
void cypd_usci_ppm_reset(void)
1411+
static void cypd_ucsi_wait_delay_deferred(void)
14111412
{
1412-
int events;
1413+
cypd_enque_evt(CYPD_EVT_UCSI_PPM_RESET, 0);
1414+
}
1415+
DECLARE_DEFERRED(cypd_ucsi_wait_delay_deferred);
14131416

1414-
events = task_wait_event_mask(TASK_EVENT_TIMER, 50*MSEC);
1415-
if (events & TASK_EVENT_TIMER)
1416-
cypd_enque_evt(CYPD_EVT_UCSI_PPM_RESET, 0);
1417+
void cypd_usci_ppm_reset(void)
1418+
{
1419+
hook_call_deferred(&cypd_ucsi_wait_delay_deferred_data, 1);
14171420
}
14181421

14191422
void cypd_port_current_setting(void)
@@ -1435,13 +1438,19 @@ int cypd_port_3a_status(int controller, int port)
14351438
return false;
14361439
}
14371440

1438-
void cypd_port_3a_set(int controller, int port)
1441+
int cypd_port_3a_set(int controller, int port)
14391442
{
14401443
int port_idx = (controller << 1) + port;
14411444

1445+
if (pd_3a_set)
1446+
return false;
1447+
1448+
pd_3a_set = 1;
14421449
pd_3a_flag = 1;
14431450
pd_3a_controller = controller;
14441451
pd_3a_port = port_idx;
1452+
1453+
return true;
14451454
}
14461455

14471456
void cypd_port_1_5a_set(int controller, int port)
@@ -1464,16 +1473,34 @@ void cypd_port_1_5a_set(int controller, int port)
14641473
}
14651474
}
14661475

1467-
int cypd_port_force_3A(void) {
1468-
1476+
int cypd_port_force_3A(int controller, int port)
1477+
{
1478+
int port_idx = (controller << 1) + port;
14691479
int port_1_5A_idx;
14701480

14711481
port_1_5A_idx = pd_port0_1_5A + pd_port1_1_5A + pd_port2_1_5A + pd_port3_1_5A;
14721482

1473-
if (port_1_5A_idx > 3)
1474-
return true;
1475-
else
1476-
return false;
1483+
if (port_1_5A_idx >= 3) {
1484+
switch (port_idx) {
1485+
case 0:
1486+
if (!pd_port0_1_5A)
1487+
return true;
1488+
break;
1489+
case 1:
1490+
if (!pd_port1_1_5A)
1491+
return true;
1492+
break;
1493+
case 2:
1494+
if (!pd_port2_1_5A)
1495+
return true;
1496+
break;
1497+
case 3:
1498+
if (!pd_port3_1_5A)
1499+
return true;
1500+
break;
1501+
}
1502+
}
1503+
return false;
14771504
}
14781505

14791506
void cypd_profile_setting(int controller, int port, int profile)
@@ -1488,18 +1515,21 @@ void cypd_ppm_port_clear(void)
14881515
pd_port1_1_5A = 0;
14891516
pd_port2_1_5A = 0;
14901517
pd_port3_1_5A = 0;
1518+
pd_3a_set = 0;
14911519
}
14921520

14931521
void cypd_release_port(int controller, int port)
14941522
{
14951523
int port_idx = (controller << 1) + port;
14961524

14971525
/* if port disconnect should set RP and PDO to default */
1498-
cypd_write_reg8(controller, CYP5525_PD_CONTROL_REG(port), CYPD_PD_CMD_SET_TYPEC_1_5A);
1499-
cypd_write_reg8(controller, CYP5525_SELECT_SOURCE_PDO_REG(port), CYPD_PD_CMD_SET_TYPEC_3A);
1526+
cypd_write_reg8_wait_ack(controller, CYP5525_PD_CONTROL_REG(port), CYPD_PD_CMD_SET_TYPEC_1_5A);
1527+
cypd_write_reg8_wait_ack(controller, CYP5525_SELECT_SOURCE_PDO_REG(port), CYPD_PD_CMD_SET_TYPEC_3A);
15001528

1501-
if (cypd_port_3a_status(controller, port))
1529+
if (cypd_port_3a_status(controller, port)) {
1530+
pd_3a_set = 0;
15021531
pd_3a_flag = 0;
1532+
}
15031533

15041534
switch (port_idx) {
15051535
case 0:
@@ -1523,10 +1553,8 @@ int cypd_profile_wait_check(int controller, int port)
15231553

15241554
/*
15251555
* according PD vendor suggest after PD NEGOTIATION COMPLETE
1526-
* need to wait 280ms before send Profile
1556+
* need to wait 420ms before send Profile
15271557
*/
1528-
task_wait_event_mask(TASK_EVENT_TIMER, 280*MSEC);
1529-
15301558
switch (port_idx) {
15311559
case 0:
15321560
if (pd_port0_1_5A)
@@ -1545,6 +1573,8 @@ int cypd_profile_wait_check(int controller, int port)
15451573
return true;
15461574
break;
15471575
}
1576+
1577+
task_wait_event_mask(TASK_EVENT_TIMER, 420*MSEC);
15481578
return false;
15491579
}
15501580

@@ -1555,16 +1585,9 @@ void cypd_set_typec_profile(int controller, int port)
15551585
uint8_t pd_status_reg[4];
15561586
uint8_t rdo_reg[4];
15571587

1558-
int typec_status_reg;
15591588
int rdo_max_current = 0;
15601589
int port_idx = (controller << 1) + port;
15611590

1562-
rv = cypd_read_reg8(controller, CYP5525_TYPE_C_STATUS_REG(port), &typec_status_reg);
1563-
if (rv != EC_SUCCESS)
1564-
CPRINTS("CYP5525_TYPE_C_STATUS_REG failed");
1565-
1566-
pd_port_states[port_idx].c_state = (typec_status_reg >> 2) & 0x7;
1567-
15681591
rv = cypd_read_reg_block(controller, CYP5525_PD_STATUS_REG(port), pd_status_reg, 4);
15691592
if (rv != EC_SUCCESS)
15701593
CPRINTS("CYP5525_PD_STATUS_REG failed");
@@ -1582,24 +1605,28 @@ void cypd_set_typec_profile(int controller, int port)
15821605
cypd_read_reg_block(controller, CYP5525_CURRENT_RDO_REG(port), rdo_reg, 4);
15831606
rdo_max_current = (((rdo_reg[1]>>2) + (rdo_reg[2]<<6)) & 0x3FF)*10;
15841607

1585-
if (cypd_port_force_3A() && !pd_3a_flag) {
1586-
cypd_port_3a_set(controller, port);
1608+
if ((cypd_port_force_3A(controller, port) && !pd_3a_flag) ||
1609+
cypd_port_3a_status(controller, port)) {
1610+
if (!cypd_port_3a_set(controller, port))
1611+
return;
15871612
cypd_profile_setting(controller, port, CYPD_PD_CMD_SET_TYPEC_3A);
15881613
} else if (rdo_max_current <= 1500) {
15891614
if (cypd_profile_wait_check(controller, port))
15901615
return;
15911616
cypd_port_1_5a_set(controller, port);
15921617
cypd_profile_setting(controller, port, CYPD_PD_CMD_SET_TYPEC_1_5A);
1593-
} else if (cypd_port_3a_status(controller, port) || !pd_3a_flag) {
1594-
cypd_port_3a_set(controller, port);
1618+
} else if (!pd_3a_flag) {
1619+
if (!cypd_port_3a_set(controller, port))
1620+
return;
15951621
cypd_profile_setting(controller, port, CYPD_PD_CMD_SET_TYPEC_3A);
15961622
} else {
1597-
cypd_profile_wait_check(controller, port);
1623+
if (cypd_profile_wait_check(controller, port))
1624+
return;
15981625
cypd_port_1_5a_set(controller, port);
15991626
cypd_profile_setting(controller, port, CYPD_PD_CMD_SET_TYPEC_1_5A);
16001627
}
16011628
} else
1602-
cypd_profile_setting(controller, port, CYPD_PD_CMD_SET_TYPEC_1_5A);
1629+
cypd_write_reg8(controller, CYP5525_PD_CONTROL_REG(port), CYPD_PD_CMD_SET_TYPEC_1_5A);
16031630
}
16041631
}
16051632

board/hx30/cypress5525.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,6 @@ void cypd_release_port(int controller, int port);
477477

478478
void cypd_ppm_port_clear(void);
479479

480+
int cypd_check_typec_port(int controller, int port);
481+
480482
#endif /* __CROS_EC_CYPRESS5525_H */

board/hx30/ucsi.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const char *command_names(uint8_t command)
7272
return "";
7373
}
7474

75-
static int is_delay;
7675
int ucsi_write_tunnel(void)
7776
{
7877
uint8_t *message_out = host_get_customer_memmap(EC_MEMMAP_UCSI_MESSAGE_OUT);
@@ -100,17 +99,7 @@ int ucsi_write_tunnel(void)
10099

101100
switch (*command) {
102101
case UCSI_CMD_GET_CONNECTOR_STATUS:
103-
/**
104-
* try to delay 500 msec to wait PD negotiation complete then send command
105-
* to PD chip
106-
*/
107-
if (!is_delay) {
108-
is_delay = 1;
109-
return EC_ERROR_BUSY;
110-
}
111-
112-
CPRINTS("Already delay 500ms, send command to PD chip");
113-
is_delay = 0;
102+
CPRINTS("Send command to PD chip");
114103
case UCSI_CMD_GET_CONNECTOR_CAPABILITY:
115104
case UCSI_CMD_CONNECTOR_RESET:
116105
case UCSI_CMD_SET_UOM:

0 commit comments

Comments
 (0)