2020-03-19 08:51:11

by Martin Kepplinger

[permalink] [raw]
Subject: [PATCH v2] usb: dwc3: support continuous runtime PM with dual role

The DRD module calls dwc3_set_mode() on role switches, i.e. when a device is
being pugged in. In order to support continuous runtime power management when
plugging in / unplugging a cable, we need to call pm_runtime_get() in this path.

Signed-off-by: Martin Kepplinger <[email protected]>
---

revision history
----------------
v2: move pm_rumtime calls into workqueue (thanks Roger)
remove unrelated documentation patch
v1: https://lore.kernel.org/linux-usb/[email protected]/T/


drivers/usb/dwc3/core.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 1d85c42b9c67..0c058b2ac21d 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -121,17 +121,19 @@ static void __dwc3_set_mode(struct work_struct *work)
if (dwc->dr_mode != USB_DR_MODE_OTG)
return;

+ pm_runtime_get(dwc->dev);
+
if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
dwc3_otg_update(dwc, 0);

if (!dwc->desired_dr_role)
- return;
+ goto out;

if (dwc->desired_dr_role == dwc->current_dr_role)
- return;
+ goto out;

if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
- return;
+ goto out;

switch (dwc->current_dr_role) {
case DWC3_GCTL_PRTCAP_HOST:
@@ -190,6 +192,9 @@ static void __dwc3_set_mode(struct work_struct *work)
break;
}

+out:
+ pm_runtime_mark_last_busy(dwc->dev);
+ pm_runtime_put_autosuspend(dwc->dev);
}

void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
--
2.20.1


2020-03-19 09:35:46

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH v2] usb: dwc3: support continuous runtime PM with dual role

Hello!

On 19.03.2020 11:49, Martin Kepplinger wrote:

> The DRD module calls dwc3_set_mode() on role switches, i.e. when a device is
> being pugged in. In order to support continuous runtime power management when

Plugged? :-)

> plugging in / unplugging a cable, we need to call pm_runtime_get() in this path.
>
> Signed-off-by: Martin Kepplinger <[email protected]>
> ---
>
> revision history
> ----------------
> v2: move pm_rumtime calls into workqueue (thanks Roger)
> remove unrelated documentation patch
> v1: https://lore.kernel.org/linux-usb/[email protected]/T/
>
>
> drivers/usb/dwc3/core.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 1d85c42b9c67..0c058b2ac21d 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -121,17 +121,19 @@ static void __dwc3_set_mode(struct work_struct *work)
> if (dwc->dr_mode != USB_DR_MODE_OTG)
> return;
>
> + pm_runtime_get(dwc->dev);

Not get_sync()

> +
> if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
> dwc3_otg_update(dwc, 0);
>
> if (!dwc->desired_dr_role)
> - return;
> + goto out;
>
> if (dwc->desired_dr_role == dwc->current_dr_role)
> - return;
> + goto out;
>
> if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
> - return;
> + goto out;
>
> switch (dwc->current_dr_role) {
> case DWC3_GCTL_PRTCAP_HOST:
> @@ -190,6 +192,9 @@ static void __dwc3_set_mode(struct work_struct *work)
> break;
> }
>
> +out:
> + pm_runtime_mark_last_busy(dwc->dev);
> + pm_runtime_put_autosuspend(dwc->dev);
> }
>
> void dwc3_set_mode(struct dwc3 *dwc, u32 mode)

MBR, Sergei

2020-03-21 11:01:31

by Jun Li

[permalink] [raw]
Subject: Re: [PATCH v2] usb: dwc3: support continuous runtime PM with dual role

Martin Kepplinger <[email protected]> 于2020年3月19日周四 下午4:50写道:
>
> The DRD module calls dwc3_set_mode() on role switches, i.e. when a device is
> being pugged in. In order to support continuous runtime power management when
> plugging in / unplugging a cable, we need to call pm_runtime_get() in this path.
>
> Signed-off-by: Martin Kepplinger <[email protected]>
> ---
>
> revision history
> ----------------
> v2: move pm_rumtime calls into workqueue (thanks Roger)
> remove unrelated documentation patch
> v1: https://lore.kernel.org/linux-usb/[email protected]/T/
>
>
> drivers/usb/dwc3/core.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 1d85c42b9c67..0c058b2ac21d 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -121,17 +121,19 @@ static void __dwc3_set_mode(struct work_struct *work)
> if (dwc->dr_mode != USB_DR_MODE_OTG)
> return;
>
> + pm_runtime_get(dwc->dev);

I think this needs _get_sync(), as the following mode settings may
require runtime resumed
to enable clocks...

Li Jun

> +
> if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
> dwc3_otg_update(dwc, 0);
>
> if (!dwc->desired_dr_role)
> - return;
> + goto out;
>
> if (dwc->desired_dr_role == dwc->current_dr_role)
> - return;
> + goto out;
>
> if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
> - return;
> + goto out;
>
> switch (dwc->current_dr_role) {
> case DWC3_GCTL_PRTCAP_HOST:
> @@ -190,6 +192,9 @@ static void __dwc3_set_mode(struct work_struct *work)
> break;
> }
>
> +out:
> + pm_runtime_mark_last_busy(dwc->dev);
> + pm_runtime_put_autosuspend(dwc->dev);
> }
>
> void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
> --
> 2.20.1
>

2020-03-21 11:06:27

by Jun Li

[permalink] [raw]
Subject: Re: [PATCH v2] usb: dwc3: support continuous runtime PM with dual role

Jun Li <[email protected]> 于2020年3月21日周六 下午6:59写道:
>
> Martin Kepplinger <[email protected]> 于2020年3月19日周四 下午4:50写道:
> >
> > The DRD module calls dwc3_set_mode() on role switches, i.e. when a device is
> > being pugged in. In order to support continuous runtime power management when
> > plugging in / unplugging a cable, we need to call pm_runtime_get() in this path.
> >
> > Signed-off-by: Martin Kepplinger <[email protected]>
> > ---
> >
> > revision history
> > ----------------
> > v2: move pm_rumtime calls into workqueue (thanks Roger)
> > remove unrelated documentation patch
> > v1: https://lore.kernel.org/linux-usb/[email protected]/T/
> >
> >
> > drivers/usb/dwc3/core.c | 11 ++++++++---
> > 1 file changed, 8 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> > index 1d85c42b9c67..0c058b2ac21d 100644
> > --- a/drivers/usb/dwc3/core.c
> > +++ b/drivers/usb/dwc3/core.c
> > @@ -121,17 +121,19 @@ static void __dwc3_set_mode(struct work_struct *work)
> > if (dwc->dr_mode != USB_DR_MODE_OTG)
> > return;
> >
> > + pm_runtime_get(dwc->dev);
>
> I think this needs _get_sync(), as the following mode settings may
> require runtime resumed
> to enable clocks...
>

See your v3, it's ok now.

> Li Jun
>
> > +
> > if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
> > dwc3_otg_update(dwc, 0);
> >
> > if (!dwc->desired_dr_role)
> > - return;
> > + goto out;
> >
> > if (dwc->desired_dr_role == dwc->current_dr_role)
> > - return;
> > + goto out;
> >
> > if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
> > - return;
> > + goto out;
> >
> > switch (dwc->current_dr_role) {
> > case DWC3_GCTL_PRTCAP_HOST:
> > @@ -190,6 +192,9 @@ static void __dwc3_set_mode(struct work_struct *work)
> > break;
> > }
> >
> > +out:
> > + pm_runtime_mark_last_busy(dwc->dev);
> > + pm_runtime_put_autosuspend(dwc->dev);
> > }
> >
> > void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
> > --
> > 2.20.1
> >