From: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
To: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>,
linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/4] usb: dwc3: qcom: Implement glue callbacks to facilitate runtime suspend
Date: Wed, 11 Jun 2025 20:14:42 +0530 [thread overview]
Message-ID: <ccff34b1-4245-4fcf-92cc-5021b2d78ea4@oss.qualcomm.com> (raw)
In-Reply-To: <shpn2wf64trpnulc7dsyyc76mafeila3amxl53wh4ksmtv2jte@3lccqv6wz72q>
On 6/10/2025 10:53 PM, Dmitry Baryshkov wrote:
> On Tue, Jun 10, 2025 at 10:06:24PM +0530, Krishna Kurapati wrote:
>>
>>
>> On 6/10/2025 4:28 PM, Dmitry Baryshkov wrote:
>>> On Tue, Jun 10, 2025 at 02:43:55PM +0530, Krishna Kurapati wrote:
>>>> On Qualcomm DWC3 dual-role controllers, the conndone/disconnect events in
>>>> device mode are generated by controller when software writes to QSCRATCH
>>>> registers in Qualcomm Glue layer rather than the vbus line being routed to
>>>> dwc3 core IP for it to recognize and generate these events.
>>>>
>>>> UTMI_OTG_VBUS_VALID bit of QSCRATCH_HS_PHY_CTRL register needs to be set
>>>> to generate a connection done event and to be cleared for the controller to
>>>> generate a disconnect event during cable removal. When the disconnect is
>>>> not generated upon cable removal, the "connected" flag of dwc3 is left
>>>> marked as "true" and it blocks suspend routines and for that to happen upon
>>>> cable removal, the cable disconnect notification coming in via set_role
>>>> call need to be provided to the Qualcomm glue layer as well.
>>>>
>>>> Currently, the way DWC3 core and Qualcomm legacy glue driver are designed,
>>>> there is no mechanism through which the DWC3 core can notify the Qualcomm
>>>> glue layer of any role changes which it receives via role switch. To
>>>> register these glue callbacks at probe time, for enabling core to notify
>>>> glue layer, the legacy Qualcomm driver has no way to find out when the
>>>> child driver probe was successful since it does not check for the same
>>>> during of_platform_populate.
>>>>
>>>> Hence implement the following glue callbacks for flattened Qualcomm glue
>>>> driver:
>>>>
>>>> 1. set_role: To pass role switching information from drd layer to glue.
>>>> This information is needed to identify NONE/DEVICE mode switch and modify
>>>> QSCRATCH to generate connect-done event on device mode entry and disconnect
>>>> event on cable removal in device mode.
>>>>
>>>> 2. run_stop: When booting up in device mode, if autouspend is enabled and
>>>> userspace doesn't write UDC on boot, controller enters autosuspend. After
>>>> this, if the userspace writes to UDC in the future, run_stop notifier is
>>>> required to enable UTMI_OTG_VBUS_VALID of QSCRATCH so that connect done
>>>> event is generated after run_stop(1) is done to finish enumeration.
>>>>
>>>> Signed-off-by: Krishna Kurapati <krishna.kurapati@oss.qualcomm.com>
>>>> ---
>>>> drivers/usb/dwc3/dwc3-qcom.c | 82 ++++++++++++++++++++++++++++++++----
>>>> 1 file changed, 73 insertions(+), 9 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
>>>> index ca7e1c02773a..d40b52e2ba01 100644
>>>> --- a/drivers/usb/dwc3/dwc3-qcom.c
>>>> +++ b/drivers/usb/dwc3/dwc3-qcom.c
>>>> @@ -89,6 +89,12 @@ struct dwc3_qcom {
>>>> bool pm_suspended;
>>>> struct icc_path *icc_path_ddr;
>>>> struct icc_path *icc_path_apps;
>>>> +
>>>> + /*
>>>> + * Current role changes via usb_role_switch_set_role callback protected
>>>> + * internally by mutex lock.
>>>> + */
>>>> + enum usb_role current_role;
>>>> };
>>>> #define to_dwc3_qcom(d) container_of((d), struct dwc3_qcom, dwc)
>>>> @@ -118,9 +124,9 @@ static inline void dwc3_qcom_clrbits(void __iomem *base, u32 offset, u32 val)
>>>> }
>>>> /*
>>>> - * TODO: Make the in-core role switching code invoke dwc3_qcom_vbus_override_enable(),
>>>> - * validate that the in-core extcon support is functional, and drop extcon
>>>> - * handling from the glue
>>>> + * TODO: Validate that the in-core extcon support is functional, and drop
>>>> + * extcon handling from the glue. Make in-core extcon invoke
>>>> + * dwc3_qcom_vbus_override_enable()
>>>> */
>>>> static void dwc3_qcom_vbus_override_enable(struct dwc3_qcom *qcom, bool enable)
>>>> {
>>>> @@ -641,6 +647,53 @@ static int dwc3_qcom_setup_irq(struct dwc3_qcom *qcom, struct platform_device *p
>>>> return 0;
>>>> }
>>>> +static void dwc3_qcom_set_role_notifier(struct dwc3 *dwc, enum usb_role next_role)
>>>> +{
>>>> + struct dwc3_qcom *qcom = to_dwc3_qcom(dwc);
>>>> +
>>>> + if (qcom->current_role == next_role)
>>>> + return;
>>>> +
>>>> + if (pm_runtime_resume_and_get(qcom->dev) < 0) {
>>>> + dev_dbg(qcom->dev, "Failed to resume device\n");
>>>> + return;
>>>> + }
>>>> +
>>>> + if (qcom->current_role == USB_ROLE_DEVICE &&
>>>> + next_role != USB_ROLE_DEVICE)
>>>> + dwc3_qcom_vbus_override_enable(qcom, false);
>>>> + else if ((qcom->current_role != USB_ROLE_DEVICE) &&
>>>> + (next_role == USB_ROLE_DEVICE))
>>>> + dwc3_qcom_vbus_override_enable(qcom, true);
>>>> +
>>>> + pm_runtime_mark_last_busy(qcom->dev);
>>>> + pm_runtime_put_sync(qcom->dev);
>>>> +
>>>> + qcom->current_role = next_role;
>>>
>>> How is it protected by the mutex? Which mutex?
>>>
>>
>> I see a mutex lock in usb_role_switch_set_role() that invokes set role. I
>> think that should be sufficient here.
>
> Please add a comment to the source code.
>
Hi Dmitry,
I added the comment at the declaration of variable in structure. Will
move it to the function.
Thank you for the review.
Regards,
Krishna,
next prev parent reply other threads:[~2025-06-11 14:44 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 9:13 [PATCH v2 0/4] usb: dwc3: Modify role-switching QC drd usb controllers Krishna Kurapati
2025-06-10 9:13 ` [PATCH v2 1/4] usb: dwc3: core: Introduce glue callbacks for flattened implementations Krishna Kurapati
2025-06-17 1:29 ` Thinh Nguyen
2025-06-23 23:24 ` Thinh Nguyen
2025-06-24 13:03 ` Krishna Kurapati
2025-06-10 9:13 ` [PATCH v2 2/4] usb: dwc3: qcom: Implement glue callbacks to facilitate runtime suspend Krishna Kurapati
2025-06-10 10:58 ` Dmitry Baryshkov
2025-06-10 16:36 ` Krishna Kurapati
2025-06-10 17:23 ` Dmitry Baryshkov
2025-06-11 14:44 ` Krishna Kurapati [this message]
2025-06-23 23:32 ` Thinh Nguyen
2025-06-24 13:04 ` Krishna Kurapati
2025-07-11 23:29 ` Thinh Nguyen
2025-07-13 9:29 ` Krishna Kurapati
2025-07-30 1:23 ` Thinh Nguyen
2025-07-30 2:16 ` Krishna Kurapati
2025-08-01 1:01 ` Thinh Nguyen
2025-08-05 11:18 ` Krishna Kurapati
2025-08-05 23:18 ` Thinh Nguyen
2025-08-06 0:18 ` Krishna Kurapati
2025-08-06 0:50 ` Thinh Nguyen
2025-06-10 9:13 ` [PATCH v2 3/4] usb: dwc3: qcom: Facilitate autosuspend during host mode Krishna Kurapati
2025-06-10 11:00 ` Dmitry Baryshkov
2025-06-10 16:40 ` Krishna Kurapati
2025-06-10 17:24 ` Dmitry Baryshkov
2025-06-23 23:59 ` Thinh Nguyen
2025-06-24 13:08 ` Krishna Kurapati
2025-06-10 9:13 ` [PATCH v2 4/4] usb: dwc3: qcom: Remove extcon functionality from glue Krishna Kurapati
2025-06-10 11:04 ` Dmitry Baryshkov
2025-06-10 10:01 ` [PATCH v2 0/4] usb: dwc3: Modify role-switching QC drd usb controllers Krishna Kurapati
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=ccff34b1-4245-4fcf-92cc-5021b2d78ea4@oss.qualcomm.com \
--to=krishna.kurapati@oss.qualcomm.com \
--cc=Thinh.Nguyen@synopsys.com \
--cc=bjorn.andersson@oss.qualcomm.com \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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®