From ca9fb9573ecbbeebcb748907d14d13c199da2b18 Mon Sep 17 00:00:00 2001 From: Pavankumar Kondeti Date: Wed, 5 Jan 2022 08:53:56 +0530 Subject: [PATCH] usb: dwc3: dwc3-msm-core: Bail out early when there is no change in role If the same role as the current role is requested, bail out early. Change-Id: I42dc3f6759800926a4a98254a2ff30f932394704 Signed-off-by: Pavankumar Kondeti --- drivers/usb/dwc3/dwc3-msm-core.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-msm-core.c b/drivers/usb/dwc3/dwc3-msm-core.c index 9e56a29a4a5a..689c09779fb6 100644 --- a/drivers/usb/dwc3/dwc3-msm-core.c +++ b/drivers/usb/dwc3/dwc3-msm-core.c @@ -4741,7 +4741,7 @@ static bool dwc3_msm_role_allowed(struct dwc3_msm *mdwc, enum usb_role role) { dev_dbg(mdwc->dev, "%s: dr_mode=%s role_requested=%s\n", __func__, usb_dr_modes[mdwc->dr_mode], - usb_role_string(role)); + dwc3_msm_usb_role_string(role)); if (role == USB_ROLE_HOST && mdwc->dr_mode == USB_DR_MODE_PERIPHERAL) return false; @@ -4779,6 +4779,20 @@ static int dwc3_msm_usb_set_role(struct usb_role_switch *sw, enum usb_role role) mutex_lock(&mdwc->role_switch_mutex); cur_role = dwc3_msm_usb_get_role(sw); + dbg_log_string("cur_role:%s new_role:%s\n", dwc3_msm_usb_role_string(cur_role), + dwc3_msm_usb_role_string(role)); + + /* + * For boot up without USB cable connected case, don't check + * previous role value to allow resetting USB controller and + * PHYs. + */ + if (mdwc->drd_state != DRD_STATE_UNDEFINED && cur_role == role) { + dbg_log_string("no USB role change"); + mutex_unlock(&mdwc->role_switch_mutex); + return 0; + } + switch (role) { case USB_ROLE_HOST: mdwc->vbus_active = false; @@ -4797,19 +4811,6 @@ static int dwc3_msm_usb_set_role(struct usb_role_switch *sw, enum usb_role role) } mutex_unlock(&mdwc->role_switch_mutex); - dbg_log_string("cur_role:%s new_role:%s\n", dwc3_msm_usb_role_string(cur_role), - dwc3_msm_usb_role_string(role)); - - /* - * For boot up without USB cable connected case, don't check - * previous role value to allow resetting USB controller and - * PHYs. - */ - if (mdwc->drd_state != DRD_STATE_UNDEFINED && cur_role == role) { - dbg_log_string("no USB role change"); - return 0; - } - dwc3_ext_event_notify(mdwc); return 0; }