From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Prashanth K <prashanth.k@oss.qualcomm.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Vladyslav Tymoshchuk <tvlad744@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>,
Faisal Hassan <faisal.hassan@oss.qualcomm.com>,
Abel Vesa <abelvesa@kernel.org>,
"linux-arm-msm@vger.kernel.org" <linux-arm-msm@vger.kernel.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] usb: dwc3: qcom: Defer VBUS override update during system suspend
Date: Thu, 5 Nov 2026 00:02:46 +0000 [thread overview]
Message-ID: <auu9hx_Xnjbi3WkB@vbox> (raw)
In-Reply-To: <f9d27fd8-cf33-4e6a-a9fc-6770a933cfb3@oss.qualcomm.com>
Hi,
On Wed, Nov 04, 2026, Prashanth K wrote:
>
>
> On 11/4/2026 8:07 AM, Thinh Nguyen wrote:
> > On Fri, Oct 23, 2026, Vladyslav Tymoshchuk wrote:
> >> dwc3_qcom_set_role_notifier() updates the VBUS override in QSCRATCH
> >> synchronously, from the context of the usb_role_switch_set_role()
> >> caller. The glue assumes that role switches only happen from a
> >> freezable workqueue, but that holds for the dwc3 core's mode switch,
> >> not for this notifier: the UCSI connector work, for one, runs on the
> >> non-freezable system workqueue.
> >>
> >
> > ....
> >
> > Good catch. However, this should be fixed in the dwc3 core. The
> > pre_set_role notifier can be called from the freezable __dwc3_set_mode()
> > work instead of from the role switch caller. Then glue drivers won't be
> > notified while suspended. This is simpler and applies to all glue
> > drivers.
>
> I think the problem with that is, dwc3_set_mode doesn't know USB_ROLE
> (especially NONE mode).
> It only knows the mode which is gadget/host/otg. Thats why vendor hooks
> are used in drd.c instead. Perhaps we can cache USB_ROLE into dwc3
> struct and use it later on __dwc3_set_mode.
>
Yes, the role needs to be cached. Something like the change below.
Hi Vladyslav,
Could you test this change instead to see if it resolves the issue?
Thanks,
Thinh
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index fd5c2cd36c59..99a39c828543 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -169,15 +169,23 @@ static void __dwc3_set_mode(struct work_struct *work)
int ret;
u32 reg;
u32 desired_dr_role;
+ enum usb_role requested_role;
+ bool notify_glue;
int i;
mutex_lock(&dwc->mutex);
spin_lock_irqsave(&dwc->lock, flags);
desired_dr_role = dwc->desired_dr_role;
+ requested_role = dwc->requested_role;
+ notify_glue = dwc->requested_role_pending;
+ dwc->requested_role_pending = false;
spin_unlock_irqrestore(&dwc->lock, flags);
pm_runtime_get_sync(dwc->dev);
+ if (notify_glue)
+ dwc3_pre_set_role(dwc, requested_role);
+
if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
dwc3_otg_update(dwc, 0);
@@ -287,7 +295,8 @@ static void __dwc3_set_mode(struct work_struct *work)
mutex_unlock(&dwc->mutex);
}
-void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
+static void __dwc3_queue_mode(struct dwc3 *dwc, u32 mode, enum usb_role role,
+ bool notify_glue)
{
unsigned long flags;
@@ -296,11 +305,25 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
spin_lock_irqsave(&dwc->lock, flags);
dwc->desired_dr_role = mode;
+ if (notify_glue) {
+ dwc->requested_role = role;
+ dwc->requested_role_pending = true;
+ }
spin_unlock_irqrestore(&dwc->lock, flags);
queue_work(system_freezable_wq, &dwc->drd_work);
}
+void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
+{
+ __dwc3_queue_mode(dwc, mode, USB_ROLE_NONE, false);
+}
+
+void dwc3_set_role(struct dwc3 *dwc, u32 mode, enum usb_role role)
+{
+ __dwc3_queue_mode(dwc, mode, role, true);
+}
+
u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
{
struct dwc3 *dwc = dep->dwc;
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index f3dabb37f806..0fbc1a446ae1 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1058,6 +1058,8 @@ struct dwc3_glue_ops {
* @dr_mode: requested mode of operation
* @current_dr_role: current role of operation when in dual-role mode
* @desired_dr_role: desired role of operation when in dual-role mode
+ * @requested_role: role requested
+ * @requested_role_pending: @requested_role is yet to be passed to the glue
* @edev: extcon handle
* @edev_nb: extcon notifier
* @hsphy_mode: UTMI phy mode, one of following:
@@ -1261,6 +1263,8 @@ struct dwc3 {
enum usb_dr_mode dr_mode;
u32 current_dr_role;
u32 desired_dr_role;
+ enum usb_role requested_role;
+ bool requested_role_pending;
struct extcon_dev *edev;
struct notifier_block edev_nb;
enum usb_phy_interface hsphy_mode;
@@ -1614,6 +1618,7 @@ struct dwc3_gadget_ep_cmd_params {
/* prototypes */
void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool ignore_susphy);
void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
+void dwc3_set_role(struct dwc3 *dwc, u32 mode, enum usb_role role);
u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
#define DWC3_IP_IS(_ip) \
diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
index f3e37d383627..55036466ec7a 100644
--- a/drivers/usb/dwc3/drd.c
+++ b/drivers/usb/dwc3/drd.c
@@ -439,8 +439,7 @@ static int dwc3_drd_notifier(struct notifier_block *nb,
enum usb_role role = mode == DWC3_GCTL_PRTCAP_HOST ?
USB_ROLE_HOST : USB_ROLE_DEVICE;
- dwc3_pre_set_role(dwc, role);
- dwc3_set_mode(dwc, mode);
+ dwc3_set_role(dwc, mode, role);
return NOTIFY_DONE;
}
@@ -468,8 +467,7 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw,
break;
}
- dwc3_pre_set_role(dwc, role);
- dwc3_set_mode(dwc, mode);
+ dwc3_set_role(dwc, mode, role);
return 0;
}
prev parent reply other threads:[~2026-11-05 0:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 22:42 Vladyslav Tymoshchuk
2026-11-02 7:58 ` Krishna Kurapati
2026-11-04 2:37 ` Thinh Nguyen
2026-11-04 4:36 ` Prashanth K
2026-11-05 0:02 ` Thinh Nguyen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=auu9hx_Xnjbi3WkB@vbox \
--to=thinh.nguyen@synopsys.com \
--cc=abelvesa@kernel.org \
--cc=faisal.hassan@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=krishna.kurapati@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=prashanth.k@oss.qualcomm.com \
--cc=tvlad744@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®