FROMGIT: usb: typec: tcpm: Refactor logic to enable/disable auto vbus dicharge
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. Bug: 185300749 Fixes:f321a02cae("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-2-badhri@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commitdea6f87e60https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-next) Signed-off-by: Badhri Jagan Sridharan <badhri@google.com> Change-Id: I416e9a8a131b1dcd17d69322af77e5fb575e86cc
This commit is contained in:
parent
ee87839030
commit
24455210fa
1 changed files with 18 additions and 21 deletions
|
|
@ -777,6 +777,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.
|
||||
|
|
@ -3526,12 +3541,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)
|
||||
|
|
@ -3609,14 +3619,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;
|
||||
|
|
@ -3684,13 +3687,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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue