@@ -1611,6 +1611,7 @@ int cypd_handle_alert_msg(int controller, int port, int len)
16111611 int rv ;
16121612 int port_idx = (controller << 1 ) + port ;
16131613 uint8_t pd_status_reg [4 ];
1614+ uint32_t alert_event_type ;
16141615
16151616 if (len > 8 ) {
16161617 CPRINTS ("Alert Massage Too Long" );
@@ -1624,35 +1625,51 @@ int cypd_handle_alert_msg(int controller, int port, int len)
16241625 /* Read the pd port partner status */
16251626 rv = cypd_read_reg_block (controller , CCG_PD_STATUS_REG (port ), pd_status_reg , 4 );
16261627
1628+ CPRINTS ("PD Power Button: Data Role = %s" ,
1629+ pd_status_reg [0 ] & BIT (6 ) ? "DFP" : "UFP" );
16271630 pd_port_states [port_idx ].data_role =
16281631 pd_status_reg [0 ] & BIT (6 ) ? PD_ROLE_DFP : PD_ROLE_UFP ;
16291632
1633+ alert_event_type = ADO_EXTENDED_ALERT_EVENT_TYPE & alert_rx [port_idx ].ado ;
1634+ CPRINTS ("PD Power Button: ADO_EXTENDED_ALERT_EVENT (%X)" , alert_event_type );
1635+
16301636 /* Extended Alert */
1631- if (alert_rx [port_idx ].ado & ADO_EXTENDED_ALERT_EVENT ) {
1632- if (pd_port_states [port_idx ].data_role == PD_ROLE_DFP &&
1633- (ADO_EXTENDED_ALERT_EVENT_TYPE & alert_rx [port_idx ].ado ) ==
1634- ADO_POWER_BUTTON_PRESS ) {
1635- /**
1636- * follow Framework UI ERS Power Button Behavior
1637- * 1. <4 Seconds - Normal power event (Power on, Wake from
1638- * suspend, send event to PCH) for OS defined behavior.
1639- * 2. >8 seconds, < 12 seconds - Force CPU to G3(chipset_force_shutdown)
1640- * 3. >12 Seconds - Forced reset of system(system_reset).
1641- *
1642- * Set the maximum timer(>12s doing EC reset) to run all PB state machine.
1643- */
1644- power_button_simulate_press (13000 );
1645- alert_press = 1 ;
1646- } else if (pd_port_states [port_idx ].data_role == PD_ROLE_DFP &&
1647- (ADO_EXTENDED_ALERT_EVENT_TYPE & alert_rx [port_idx ].ado ) ==
1648- ADO_POWER_BUTTON_RELEASE ) {
1649- /**
1650- * Re-schedule to a minimal(1) to release the power button when
1651- * received the ADO_POWER_BUTTON_RELEASE event.
1652- */
1653- power_button_simulate_press (1 );
1654- alert_press = 0 ;
1655- }
1637+ if ((alert_rx [port_idx ].ado & ADO_EXTENDED_ALERT_EVENT ) == 0 ) {
1638+ CPRINTS ("PD Power Button: ADO_EXTENDED_ALERT_EVENT bit not set" );
1639+ return rv ;
1640+ }
1641+ if (pd_port_states [port_idx ].data_role != PD_ROLE_DFP ) {
1642+ CPRINTS ("PD Power Button: Data role not DFP" );
1643+ return rv ;
1644+ }
1645+
1646+ switch (alert_event_type ) {
1647+ case ADO_POWER_BUTTON_PRESS :
1648+ /**
1649+ * follow Framework UI ERS Power Button Behavior
1650+ * 1. <4 Seconds - Normal power event (Power on, Wake from
1651+ * suspend, send event to PCH) for OS defined behavior.
1652+ * 2. >8 seconds, < 12 seconds - Force CPU to G3(chipset_force_shutdown)
1653+ * 3. >12 Seconds - Forced reset of system(system_reset).
1654+ *
1655+ * Set the maximum timer(>12s doing EC reset) to run all PB state machine.
1656+ */
1657+ CPRINTS ("PD Power Button: Simulate press" );
1658+ power_button_simulate_press (13000 );
1659+ alert_press = 1 ;
1660+ break ;
1661+ case ADO_POWER_BUTTON_RELEASE :
1662+ /**
1663+ * Re-schedule to a minimal(1) to release the power button when
1664+ * received the ADO_POWER_BUTTON_RELEASE event.
1665+ */
1666+ CPRINTS ("PD Power Button: Simulate release" );
1667+ power_button_simulate_press (1 );
1668+ alert_press = 0 ;
1669+ break ;
1670+ default :
1671+ CPRINTS ("PD Power Button: ADO_EXTENDED_ALERT_EVENT invalid (%X)" , alert_event_type );
1672+ break ;
16561673 }
16571674 return rv ;
16581675}
0 commit comments