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

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.

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-2-badhri@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Badhri Jagan Sridharan and committed by
Greg Kroah-Hartman
dea6f87e d112efbe

+18 -21
+18 -21
drivers/usb/typec/tcpm/tcpm.c
··· 774 774 port->tcpc->set_cc(port->tcpc, cc); 775 775 } 776 776 777 + static int tcpm_enable_auto_vbus_discharge(struct tcpm_port *port, bool enable) 778 + { 779 + int ret = 0; 780 + 781 + if (port->tcpc->enable_auto_vbus_discharge) { 782 + ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, enable); 783 + tcpm_log_force(port, "%s vbus discharge ret:%d", enable ? "enable" : "disable", 784 + ret); 785 + if (!ret) 786 + port->auto_vbus_discharge_enabled = enable; 787 + } 788 + 789 + return ret; 790 + } 791 + 777 792 /* 778 793 * Determine RP value to set based on maximum current supported 779 794 * by a port if configured as source. ··· 3487 3472 if (ret < 0) 3488 3473 return ret; 3489 3474 3490 - if (port->tcpc->enable_auto_vbus_discharge) { 3491 - ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, true); 3492 - tcpm_log_force(port, "enable vbus discharge ret:%d", ret); 3493 - if (!ret) 3494 - port->auto_vbus_discharge_enabled = true; 3495 - } 3475 + tcpm_enable_auto_vbus_discharge(port, true); 3496 3476 3497 3477 ret = tcpm_set_roles(port, true, TYPEC_SOURCE, tcpm_data_role_for_source(port)); 3498 3478 if (ret < 0) ··· 3564 3554 3565 3555 static void tcpm_reset_port(struct tcpm_port *port) 3566 3556 { 3567 - int ret; 3568 - 3569 - if (port->tcpc->enable_auto_vbus_discharge) { 3570 - ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, false); 3571 - tcpm_log_force(port, "Disable vbus discharge ret:%d", ret); 3572 - if (!ret) 3573 - port->auto_vbus_discharge_enabled = false; 3574 - } 3557 + tcpm_enable_auto_vbus_discharge(port, false); 3575 3558 port->in_ams = false; 3576 3559 port->ams = NONE_AMS; 3577 3560 port->vdm_sm_running = false; ··· 3632 3629 if (ret < 0) 3633 3630 return ret; 3634 3631 3635 - if (port->tcpc->enable_auto_vbus_discharge) { 3636 - tcpm_set_auto_vbus_discharge_threshold(port, TYPEC_PWR_MODE_USB, false, VSAFE5V); 3637 - ret = port->tcpc->enable_auto_vbus_discharge(port->tcpc, true); 3638 - tcpm_log_force(port, "enable vbus discharge ret:%d", ret); 3639 - if (!ret) 3640 - port->auto_vbus_discharge_enabled = true; 3641 - } 3632 + tcpm_enable_auto_vbus_discharge(port, true); 3642 3633 3643 3634 ret = tcpm_set_roles(port, true, TYPEC_SINK, tcpm_data_role_for_sink(port)); 3644 3635 if (ret < 0)