Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: typec: tcpm: Move TCPC to APPLY_RC state during PR_SWAP

When vbus auto discharge is enabled, TCPCI based TCPC transitions
into Attached.SNK/Attached.SRC state. During PR_SWAP, TCPCI based
TCPC would disconnect when partner changes power roles. TCPC has
to be moved APPLY RC state during PR_SWAP. This is done by
ROLE_CONTROL.CC1 != ROLE_CONTROL.CC2 and
POWER_CONTROL.AutodischargeDisconnect is 0. Once the swap sequence
is done, AutoDischargeDisconnect is re-enabled.

Fixes: f321a02caebd ("usb: typec: tcpm: Implement enabling Auto Discharge disconnect support")
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Link: https://lore.kernel.org/r/20210517192112.40934-3-badhri@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Badhri Jagan Sridharan and committed by
Greg Kroah-Hartman
59d4d06c dea6f87e

+20
+16
drivers/usb/typec/tcpm/tcpm.c
··· 789 789 return ret; 790 790 } 791 791 792 + static void tcpm_apply_rc(struct tcpm_port *port) 793 + { 794 + /* 795 + * TCPCI: Move to APPLY_RC state to prevent disconnect during PR_SWAP 796 + * when Vbus auto discharge on disconnect is enabled. 797 + */ 798 + if (port->tcpc->enable_auto_vbus_discharge && port->tcpc->apply_rc) { 799 + tcpm_log(port, "Apply_RC"); 800 + port->tcpc->apply_rc(port->tcpc, port->cc_req, port->polarity); 801 + tcpm_enable_auto_vbus_discharge(port, false); 802 + } 803 + } 804 + 792 805 /* 793 806 * Determine RP value to set based on maximum current supported 794 807 * by a port if configured as source. ··· 4482 4469 tcpm_set_state(port, ready_state(port), 0); 4483 4470 break; 4484 4471 case PR_SWAP_START: 4472 + tcpm_apply_rc(port); 4485 4473 if (port->pwr_role == TYPEC_SOURCE) 4486 4474 tcpm_set_state(port, PR_SWAP_SRC_SNK_TRANSITION_OFF, 4487 4475 PD_T_SRC_TRANSITION); ··· 4522 4508 tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_ON_PRS); 4523 4509 break; 4524 4510 case PR_SWAP_SRC_SNK_SINK_ON: 4511 + tcpm_enable_auto_vbus_discharge(port, true); 4525 4512 /* Set the vbus disconnect threshold for implicit contract */ 4526 4513 tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_USB, false, VSAFE5V); 4527 4514 tcpm_set_state(port, SNK_STARTUP, 0); ··· 4539 4524 PD_T_PS_SOURCE_OFF); 4540 4525 break; 4541 4526 case PR_SWAP_SNK_SRC_SOURCE_ON: 4527 + tcpm_enable_auto_vbus_discharge(port, true); 4542 4528 tcpm_set_cc(port, tcpm_rp_cc(port)); 4543 4529 tcpm_set_vbus(port, true); 4544 4530 /*
+4
include/linux/usb/tcpm.h
··· 66 66 * For example, some tcpcs may include BC1.2 charger detection 67 67 * and use that in this case. 68 68 * @set_cc: Called to set value of CC pins 69 + * @apply_rc: Optional; Needed to move TCPCI based chipset to APPLY_RC state 70 + * as stated by the TCPCI specification. 69 71 * @get_cc: Called to read current CC pin values 70 72 * @set_polarity: 71 73 * Called to set polarity ··· 122 120 int (*get_vbus)(struct tcpc_dev *dev); 123 121 int (*get_current_limit)(struct tcpc_dev *dev); 124 122 int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc); 123 + int (*apply_rc)(struct tcpc_dev *dev, enum typec_cc_status cc, 124 + enum typec_cc_polarity polarity); 125 125 int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1, 126 126 enum typec_cc_status *cc2); 127 127 int (*set_polarity)(struct tcpc_dev *dev,