usb: typec: tcpm: fix source caps may lost after soft reset

Invoke set_pd_rx() may flush the RX FIFO of PD controller, so do
set_pd_rx() before sending Soft Reset in case Source caps may be flushed
at debounce time between SOFT_RESET_SEND and SNK_WAIT_CAPABILITIES state.

Without this patch, in PD charger stress test, the FUSB302 driver may
occur the following exceptions in power negotiation stage.

[ ...]
[ 4.512252] fusb302_irq_intn
[ 4.512260] AMS SOFT_RESET_AMS finished
[ 4.512269] state change SOFT_RESET_SEND ->SNK_WAIT_CAPABILITIES [rev3 NONE_AMS]
[ 4.514511] pd := on
[ 4.514516] pending state change SNK_WAIT_CAPABILITIES ->HARD_RESET_SEND @ 310 ms [rev3 NONE_AMS]
[ 4.515428] IRQ: 0x51, a: 0x00, b: 0x01, status0: 0x93
[ 4.515431] IRQ: BC_LVL, handler pending
[ 4.515435] IRQ: PD sent good CRC
[ 4.516434] PD message header: 0
[ 4.516437] PD message len: 0
[ 4.516444] PD RX, header: 0x0 [1]

Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
Change-Id: Icf8748e319094bee5dd010e353254c532fdea6ab
This commit is contained in:
Frank Wang
2023-02-16 15:35:41 +08:00
committed by Tao Huang
parent 136d6212d6
commit 8dc7042e4b

View File

@@ -4300,10 +4300,12 @@ static void run_state_machine(struct tcpm_port *port)
tcpm_set_state(port, unattached_state(port), 0);
break;
case SNK_WAIT_CAPABILITIES:
ret = port->tcpc->set_pd_rx(port->tcpc, true);
if (ret < 0) {
tcpm_set_state(port, SNK_READY, 0);
break;
if (port->prev_state != SOFT_RESET_SEND) {
ret = port->tcpc->set_pd_rx(port->tcpc, true);
if (ret < 0) {
tcpm_set_state(port, SNK_READY, 0);
break;
}
}
timer_val_msecs = PD_T_SINK_WAIT_CAP;
trace_android_vh_typec_tcpm_get_timer(tcpm_states[SNK_WAIT_CAPABILITIES],
@@ -4598,6 +4600,7 @@ static void run_state_machine(struct tcpm_port *port)
case SOFT_RESET_SEND:
port->message_id = 0;
port->rx_msgid = -1;
port->tcpc->set_pd_rx(port->tcpc, true);
if (tcpm_pd_send_control(port, PD_CTRL_SOFT_RESET))
tcpm_set_state_cond(port, hard_reset_state(port), 0);
else