Message ID | 20210515052613.3261340-1-badhri@google.com |
---|---|
State | Superseded |
Headers | show |
Series | [v1,1/4] usb: typec: tcpm: Fix up PR_SWAP when vsafe0v is signalled | expand |
On 21-05-14 22:26:10, Badhri Jagan Sridharan wrote: > During PR_SWAP, When TCPM is in PR_SWAP_SNK_SRC_SINK_OFF, vbus is > expected to reach VSAFE0V when source turns of vbus. Do not move %s/of/off Peter > to SNK_UNATTACHED state when this happens. > > Fixes: 28b43d3d746b ("usb: typec: tcpm: Introduce vsafe0v for vbus") > Signed-off-by: Badhri Jagan Sridharan <badhri@google.com> > --- > drivers/usb/typec/tcpm/tcpm.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index c4fdc00a3bc8..b93c4c8d7b15 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -5114,6 +5114,9 @@ static void _tcpm_pd_vbus_vsafe0v(struct tcpm_port *port) > tcpm_set_state(port, SNK_UNATTACHED, 0); > } > break; > + case PR_SWAP_SNK_SRC_SINK_OFF: > + /* Do nothing, vsafe0v is expected during transition */ > + break; > default: > if (port->pwr_role == TYPEC_SINK && port->auto_vbus_discharge_enabled) > tcpm_set_state(port, SNK_UNATTACHED, 0); > -- > 2.31.1.751.gd2f1c929bd-goog > -- Thanks, Peter Chen
On Fri, May 14, 2021 at 10:26:10PM -0700, Badhri Jagan Sridharan wrote: > During PR_SWAP, When TCPM is in PR_SWAP_SNK_SRC_SINK_OFF, vbus is > expected to reach VSAFE0V when source turns of vbus. Do not move s/of/off/ as already reported > to SNK_UNATTACHED state when this happens. > > Fixes: 28b43d3d746b ("usb: typec: tcpm: Introduce vsafe0v for vbus") > Signed-off-by: Badhri Jagan Sridharan <badhri@google.com> Otherwise Reviewed-by: Guenter Roeck <linux@roeck-us.net> > --- > drivers/usb/typec/tcpm/tcpm.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index c4fdc00a3bc8..b93c4c8d7b15 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -5114,6 +5114,9 @@ static void _tcpm_pd_vbus_vsafe0v(struct tcpm_port *port) > tcpm_set_state(port, SNK_UNATTACHED, 0); > } > break; > + case PR_SWAP_SNK_SRC_SINK_OFF: > + /* Do nothing, vsafe0v is expected during transition */ > + break; > default: > if (port->pwr_role == TYPEC_SINK && port->auto_vbus_discharge_enabled) > tcpm_set_state(port, SNK_UNATTACHED, 0); > -- > 2.31.1.751.gd2f1c929bd-goog >
On Fri, May 14, 2021 at 10:26:11PM -0700, Badhri Jagan Sridharan wrote: > The logic to enable vbus auto discharge on disconnect is used in > more than one place. Since this is repetitive code, moving this into > its own method. > > Fixes: f321a02caebd ("usb: typec: tcpm: Implement enabling Auto Discharge disconnect support") > Signed-off-by: Badhri Jagan Sridharan <badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> > --- > drivers/usb/typec/tcpm/tcpm.c | 39 ++++++++++++++++------------------- > 1 file changed, 18 insertions(+), 21 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c > index b93c4c8d7b15..b475d9b9d38d 100644 > --- a/drivers/usb/typec/tcpm/tcpm.c > +++ b/drivers/usb/typec/tcpm/tcpm.c > @@ -771,6 +771,21 @@ static void tcpm_set_cc(struct tcpm_port *port, enum typec_cc_status cc) > port->tcpc->set_cc(port->tcpc, cc); > } > > +static int tcpm_enable_auto_vbus_discharge(struct tcpm_port *port, bool enable) > +{ > + int ret = 0; > + > + if (port->tcpc->enable_auto_vbus_discharge) { > + ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, enable); > + tcpm_log_force(port, "%s vbus discharge ret:%d", enable ? "enable" : "disable", > + ret); > + if (!ret) > + port->auto_vbus_discharge_enabled = enable; > + } > + > + return ret; > +} > + > /* > * Determine RP value to set based on maximum current supported > * by a port if configured as source. > @@ -3445,12 +3460,7 @@ static int tcpm_src_attach(struct tcpm_port *port) > if (ret < 0) > return ret; > > - if (port->tcpc->enable_auto_vbus_discharge) { > - ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, true); > - tcpm_log_force(port, "enable vbus discharge ret:%d", ret); > - if (!ret) > - port->auto_vbus_discharge_enabled = true; > - } > + tcpm_enable_auto_vbus_discharge(port, true); > > ret = tcpm_set_roles(port, true, TYPEC_SOURCE, tcpm_data_role_for_source(port)); > if (ret < 0) > @@ -3527,14 +3537,7 @@ static void tcpm_set_partner_usb_comm_capable(struct tcpm_port *port, bool capab > > static void tcpm_reset_port(struct tcpm_port *port) > { > - int ret; > - > - if (port->tcpc->enable_auto_vbus_discharge) { > - ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, false); > - tcpm_log_force(port, "Disable vbus discharge ret:%d", ret); > - if (!ret) > - port->auto_vbus_discharge_enabled = false; > - } > + tcpm_enable_auto_vbus_discharge(port, false); > port->in_ams = false; > port->ams = NONE_AMS; > port->vdm_sm_running = false; > @@ -3602,13 +3605,7 @@ static int tcpm_snk_attach(struct tcpm_port *port) > if (ret < 0) > return ret; > > - if (port->tcpc->enable_auto_vbus_discharge) { > - tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_USB, false, VSAFE5V); > - ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, true); > - tcpm_log_force(port, "enable vbus discharge ret:%d", ret); > - if (!ret) > - port->auto_vbus_discharge_enabled = true; > - } > + tcpm_enable_auto_vbus_discharge(port, true); > > ret = tcpm_set_roles(port, true, TYPEC_SINK, tcpm_data_role_for_sink(port)); > if (ret < 0) > -- > 2.31.1.751.gd2f1c929bd-goog >
On Fri, May 14, 2021 at 10:26:13PM -0700, Badhri Jagan Sridharan wrote: > APPLY RC is defined as ROLE_CONTROL.CC1 != ROLE_CONTROL.CC2 and > POWER_CONTROL.AutodischargeDisconnect is 0. When ROLE_CONTROL.CC1 == > ROLE_CONTROL.CC2, set the other CC to OPEN. > > Fixes: f321a02caebd ("usb: typec: tcpm: Implement enabling Auto Discharge disconnect support") > Signed-off-by: Badhri Jagan Sridharan <badhri@google.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> > --- > drivers/usb/typec/tcpm/tcpci.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/drivers/usb/typec/tcpm/tcpci.c b/drivers/usb/typec/tcpm/tcpci.c > index 25b480752266..34b5095cc84f 100644 > --- a/drivers/usb/typec/tcpm/tcpci.c > +++ b/drivers/usb/typec/tcpm/tcpci.c > @@ -115,6 +115,32 @@ static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc) > return 0; > } > > +int tcpci_apply_rc(struct tcpc_dev *tcpc, enum typec_cc_status cc, enum typec_cc_polarity polarity) > +{ > + struct tcpci *tcpci = tcpc_to_tcpci(tcpc); > + unsigned int reg; > + int ret; > + > + ret = regmap_read(tcpci->regmap, TCPC_ROLE_CTRL, ®); > + if (ret < 0) > + return ret; > + > + /* > + * APPLY_RC state is when ROLE_CONTROL.CC1 != ROLE_CONTROL.CC2 and vbus autodischarge on > + * disconnect is disabled. Bail out when ROLE_CONTROL.CC1 != ROLE_CONTROL.CC2. > + */ > + if (((reg & (TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT)) >> > + TCPC_ROLE_CTRL_CC2_SHIFT) != > + ((reg & (TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT)) >> > + TCPC_ROLE_CTRL_CC1_SHIFT)) > + return 0; > + > + return regmap_update_bits(tcpci->regmap, TCPC_ROLE_CTRL, polarity == TYPEC_POLARITY_CC1 ? > + TCPC_ROLE_CTRL_CC2_MASK << TCPC_ROLE_CTRL_CC2_SHIFT : > + TCPC_ROLE_CTRL_CC1_MASK << TCPC_ROLE_CTRL_CC1_SHIFT, > + TCPC_ROLE_CTRL_CC_OPEN); > +} > + > static int tcpci_start_toggling(struct tcpc_dev *tcpc, > enum typec_port_type port_type, > enum typec_cc_status cc) > @@ -728,6 +754,7 @@ struct tcpci *tcpci_register_port(struct device *dev, struct tcpci_data *data) > tcpci->tcpc.get_vbus = tcpci_get_vbus; > tcpci->tcpc.set_vbus = tcpci_set_vbus; > tcpci->tcpc.set_cc = tcpci_set_cc; > + tcpci->tcpc.apply_rc = tcpci_apply_rc; > tcpci->tcpc.get_cc = tcpci_get_cc; > tcpci->tcpc.set_polarity = tcpci_set_polarity; > tcpci->tcpc.set_vconn = tcpci_set_vconn; > -- > 2.31.1.751.gd2f1c929bd-goog >
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index c4fdc00a3bc8..b93c4c8d7b15 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -5114,6 +5114,9 @@ static void _tcpm_pd_vbus_vsafe0v(struct tcpm_port *port) tcpm_set_state(port, SNK_UNATTACHED, 0); } break; + case PR_SWAP_SNK_SRC_SINK_OFF: + /* Do nothing, vsafe0v is expected during transition */ + break; default: if (port->pwr_role == TYPEC_SINK && port->auto_vbus_discharge_enabled) tcpm_set_state(port, SNK_UNATTACHED, 0);
During PR_SWAP, When TCPM is in PR_SWAP_SNK_SRC_SINK_OFF, vbus is expected to reach VSAFE0V when source turns of vbus. Do not move to SNK_UNATTACHED state when this happens. Fixes: 28b43d3d746b ("usb: typec: tcpm: Introduce vsafe0v for vbus") Signed-off-by: Badhri Jagan Sridharan <badhri@google.com> --- drivers/usb/typec/tcpm/tcpm.c | 3 +++ 1 file changed, 3 insertions(+)