@@ -88,6 +88,7 @@ struct extended_msg tx_emsg[CONFIG_USB_PD_PORT_MAX_COUNT];
8888bool verbose_msg_logging ;
8989static bool firmware_update ;
9090static int pd_3a_flag ;
91+ static int pd_3a_set ;
9192static int pd_3a_controller ;
9293static int pd_3a_port ;
9394static 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
14191422void 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
14471456void 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
14791506void 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
14931521void 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
0 commit comments