diff mbox series

[1/2] usb: dwc3: support continuous runtime PM with dual role

Message ID 20200318083508.20781-1-martin.kepplinger@puri.sm (mailing list archive)
State Superseded
Headers show
Series [1/2] usb: dwc3: support continuous runtime PM with dual role | expand

Commit Message

Martin Kepplinger March 18, 2020, 8:35 a.m. UTC
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 <martin.kepplinger@puri.sm>
---
 drivers/usb/dwc3/core.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Roger Quadros March 18, 2020, 11:13 a.m. UTC | #1
Martin,

On 18/03/2020 10:35, 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
> plugging in / unplugging a cable, we need to call pm_runtime_get() in this path.
> 
> Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
> ---
>   drivers/usb/dwc3/core.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index edc17155cb2b..7743c4de82e9 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -196,11 +196,16 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>   {
>   	unsigned long flags;
>   
> +	pm_runtime_get(dwc->dev);
> +
>   	spin_lock_irqsave(&dwc->lock, flags);
>   	dwc->desired_dr_role = mode;
>   	spin_unlock_irqrestore(&dwc->lock, flags);
>   
>   	queue_work(system_freezable_wq, &dwc->drd_work);

We are not touching any IP registers and just scheduling
the drd_work in this function so it doesn't make sense to do pm_runtime_get here.

How about dong pm_runtime_get/put in __dwc3_set_mode()?

> +
> +	pm_runtime_mark_last_busy(dwc->dev);
> +	pm_runtime_put_autosuspend(dwc->dev);
>   }
>   
>   u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
>
Martin Kepplinger March 18, 2020, 11:16 a.m. UTC | #2
On 18.03.20 12:13, Roger Quadros wrote:
> Martin,
> 
> On 18/03/2020 10:35, 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
>> plugging in / unplugging a cable, we need to call pm_runtime_get() in
>> this path.
>>
>> Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
>> ---
>>   drivers/usb/dwc3/core.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>> index edc17155cb2b..7743c4de82e9 100644
>> --- a/drivers/usb/dwc3/core.c
>> +++ b/drivers/usb/dwc3/core.c
>> @@ -196,11 +196,16 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>>   {
>>       unsigned long flags;
>>   +    pm_runtime_get(dwc->dev);
>> +
>>       spin_lock_irqsave(&dwc->lock, flags);
>>       dwc->desired_dr_role = mode;
>>       spin_unlock_irqrestore(&dwc->lock, flags);
>>         queue_work(system_freezable_wq, &dwc->drd_work);
> 
> We are not touching any IP registers and just scheduling
> the drd_work in this function so it doesn't make sense to do
> pm_runtime_get here.
> 
> How about dong pm_runtime_get/put in __dwc3_set_mode()?

That would be more accurate indeed. I'll move it over there. thanks for
having a look!

                           martin


> 
>> +
>> +    pm_runtime_mark_last_busy(dwc->dev);
>> +    pm_runtime_put_autosuspend(dwc->dev);
>>   }
>>     u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
>>
>
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index edc17155cb2b..7743c4de82e9 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -196,11 +196,16 @@  void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
 {
 	unsigned long flags;
 
+	pm_runtime_get(dwc->dev);
+
 	spin_lock_irqsave(&dwc->lock, flags);
 	dwc->desired_dr_role = mode;
 	spin_unlock_irqrestore(&dwc->lock, flags);
 
 	queue_work(system_freezable_wq, &dwc->drd_work);
+
+	pm_runtime_mark_last_busy(dwc->dev);
+	pm_runtime_put_autosuspend(dwc->dev);
 }
 
 u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)