linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] usb: dwc3: enable runtime PM for drd role switch / extcon
@ 2020-03-12 14:30 Martin Kepplinger
  2020-03-15  9:13 ` Felipe Balbi
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Kepplinger @ 2020-03-12 14:30 UTC (permalink / raw)
  To: balbi, gregkh; +Cc: linux-usb, linux-kernel, Martin Kepplinger

Note: runtime PM currently needs to be enabled ("auto") manually via sysfs as
its power/control is set to "on" by the driver.

When runtime PM enabled, dwc3 currently doesn't resume when a cable is connected.
It only suspends after a cable is disconnected.

When using an extcon driver (for a different chip on the board), dwc3 can
register a hook for that. (Still undocumented -> TODO?).

Make sure, dwc3 is resumed when "set_mode" is being called by drd.

this is only a question about what's missing to properly keep runtime
PM enabled for dwc3 and if my change makes any sense at all. It seems
to work fine for me...

I'm glad about any hints on how to keep runtime PM enabled (at least when
having an extcon hook set up).

thanks,
                                martin
---
 drivers/usb/dwc3/core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 1d85c42b9c67..201b712bd961 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -118,6 +118,9 @@ static void __dwc3_set_mode(struct work_struct *work)
 	unsigned long flags;
 	int ret;
 
+	pm_runtime_mark_last_busy(dwc->dev);
+	pm_runtime_put_sync_autosuspend(dwc->dev);
+
 	if (dwc->dr_mode != USB_DR_MODE_OTG)
 		return;
 
@@ -196,6 +199,8 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
 {
 	unsigned long flags;
 
+	pm_runtime_get_sync(dwc->dev);
+
 	spin_lock_irqsave(&dwc->lock, flags);
 	dwc->desired_dr_role = mode;
 	spin_unlock_irqrestore(&dwc->lock, flags);
@@ -1552,7 +1557,7 @@ static int dwc3_probe(struct platform_device *pdev)
 		goto err5;
 
 	dwc3_debugfs_init(dwc);
-	pm_runtime_put(dev);
+	pm_runtime_put_sync(dev);
 
 	return 0;
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] usb: dwc3: enable runtime PM for drd role switch / extcon
  2020-03-12 14:30 [RFC PATCH] usb: dwc3: enable runtime PM for drd role switch / extcon Martin Kepplinger
@ 2020-03-15  9:13 ` Felipe Balbi
  2020-03-16  7:18   ` Martin Kepplinger
  0 siblings, 1 reply; 4+ messages in thread
From: Felipe Balbi @ 2020-03-15  9:13 UTC (permalink / raw)
  To: Martin Kepplinger, gregkh; +Cc: linux-usb, linux-kernel, Martin Kepplinger

[-- Attachment #1: Type: text/plain, Size: 2529 bytes --]

Hi,

(for commit logs, please break your lines at 72 characters)

Martin Kepplinger <martin.kepplinger@puri.sm> writes:

> Note: runtime PM currently needs to be enabled ("auto") manually via
> sysfs as its power/control is set to "on" by the driver.

Right, that's on purpose

> When runtime PM enabled, dwc3 currently doesn't resume when a cable is
> connected.  It only suspends after a cable is disconnected.
>
> When using an extcon driver (for a different chip on the board), dwc3
> can register a hook for that. (Still undocumented -> TODO?).
>
> Make sure, dwc3 is resumed when "set_mode" is being called by drd.
>
> this is only a question about what's missing to properly keep runtime
> PM enabled for dwc3 and if my change makes any sense at all. It seems
> to work fine for me...
>
> I'm glad about any hints on how to keep runtime PM enabled (at least when
> having an extcon hook set up).

You need to remember that what you write here is going to be placed in
the commit log and will survive forever in the history of the
project. Can you be a little bit more technical? For example, why did
you change the asynchronous pm_runtime_put() to synchronous versions?
Why was that necessary?

Also, you're missing your Signed-off-by line. Please, read the
documentation about how to write patches.

> thanks,
>                                 martin
> ---
>  drivers/usb/dwc3/core.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 1d85c42b9c67..201b712bd961 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -118,6 +118,9 @@ static void __dwc3_set_mode(struct work_struct *work)
>  	unsigned long flags;
>  	int ret;
>  
> +	pm_runtime_mark_last_busy(dwc->dev);
> +	pm_runtime_put_sync_autosuspend(dwc->dev);

why synchronous?

> +
>  	if (dwc->dr_mode != USB_DR_MODE_OTG)
>  		return;
>  
> @@ -196,6 +199,8 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>  {
>  	unsigned long flags;
>  
> +	pm_runtime_get_sync(dwc->dev);

why get here and put on another function?

> +
>  	spin_lock_irqsave(&dwc->lock, flags);
>  	dwc->desired_dr_role = mode;
>  	spin_unlock_irqrestore(&dwc->lock, flags);
> @@ -1552,7 +1557,7 @@ static int dwc3_probe(struct platform_device *pdev)
>  		goto err5;
>  
>  	dwc3_debugfs_init(dwc);
> -	pm_runtime_put(dev);
> +	pm_runtime_put_sync(dev);

why the conversion to synchronous?

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] usb: dwc3: enable runtime PM for drd role switch / extcon
  2020-03-15  9:13 ` Felipe Balbi
@ 2020-03-16  7:18   ` Martin Kepplinger
  2020-03-16  7:22     ` Felipe Balbi
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Kepplinger @ 2020-03-16  7:18 UTC (permalink / raw)
  To: Felipe Balbi, gregkh; +Cc: linux-usb, linux-kernel

On 15.03.20 10:13, Felipe Balbi wrote:
> Hi,
> 
> (for commit logs, please break your lines at 72 characters)
> 
> Martin Kepplinger <martin.kepplinger@puri.sm> writes:
> 
>> Note: runtime PM currently needs to be enabled ("auto") manually via
>> sysfs as its power/control is set to "on" by the driver.
> 
> Right, that's on purpose
> 
>> When runtime PM enabled, dwc3 currently doesn't resume when a cable is
>> connected.  It only suspends after a cable is disconnected.
>>
>> When using an extcon driver (for a different chip on the board), dwc3
>> can register a hook for that. (Still undocumented -> TODO?).
>>
>> Make sure, dwc3 is resumed when "set_mode" is being called by drd.
>>
>> this is only a question about what's missing to properly keep runtime
>> PM enabled for dwc3 and if my change makes any sense at all. It seems
>> to work fine for me...
>>
>> I'm glad about any hints on how to keep runtime PM enabled (at least when
>> having an extcon hook set up).
> 
> You need to remember that what you write here is going to be placed in
> the commit log and will survive forever in the history of the
> project. Can you be a little bit more technical? For example, why did
> you change the asynchronous pm_runtime_put() to synchronous versions?
> Why was that necessary?>
> Also, you're missing your Signed-off-by line. Please, read the
> documentation about how to write patches.

I don't sign off on this change. It merely servers as a basis for the
question I have: How to properly have continuous runtime PM in dwc3 (at
least when having an extcon device connected) and is there any specific
reason why this isn't yet implemented?

> 
>> thanks,
>>                                 martin
>> ---
>>  drivers/usb/dwc3/core.c | 7 ++++++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>> index 1d85c42b9c67..201b712bd961 100644
>> --- a/drivers/usb/dwc3/core.c
>> +++ b/drivers/usb/dwc3/core.c
>> @@ -118,6 +118,9 @@ static void __dwc3_set_mode(struct work_struct *work)
>>  	unsigned long flags;
>>  	int ret;
>>  
>> +	pm_runtime_mark_last_busy(dwc->dev);
>> +	pm_runtime_put_sync_autosuspend(dwc->dev);
> 
> why synchronous?

Yes, that should not be necessary. please ignore switching to sync.

> 
>> +
>>  	if (dwc->dr_mode != USB_DR_MODE_OTG)
>>  		return;
>>  
>> @@ -196,6 +199,8 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>>  {
>>  	unsigned long flags;
>>  
>> +	pm_runtime_get_sync(dwc->dev);
> 
> why get here and put on another function?

Actually, no real reason. If the general idea makes sense, it would be
simpler (and also work) to have both in one function.

> 
>> +
>>  	spin_lock_irqsave(&dwc->lock, flags);
>>  	dwc->desired_dr_role = mode;
>>  	spin_unlock_irqrestore(&dwc->lock, flags);
>> @@ -1552,7 +1557,7 @@ static int dwc3_probe(struct platform_device *pdev)
>>  		goto err5;
>>  
>>  	dwc3_debugfs_init(dwc);
>> -	pm_runtime_put(dev);
>> +	pm_runtime_put_sync(dev);
> 
> why the conversion to synchronous?
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC PATCH] usb: dwc3: enable runtime PM for drd role switch / extcon
  2020-03-16  7:18   ` Martin Kepplinger
@ 2020-03-16  7:22     ` Felipe Balbi
  0 siblings, 0 replies; 4+ messages in thread
From: Felipe Balbi @ 2020-03-16  7:22 UTC (permalink / raw)
  To: Martin Kepplinger, gregkh; +Cc: linux-usb, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1982 bytes --]


Hi,

Martin Kepplinger <martin.kepplinger@puri.sm> writes:
>> (for commit logs, please break your lines at 72 characters)
>> 
>> Martin Kepplinger <martin.kepplinger@puri.sm> writes:
>> 
>>> Note: runtime PM currently needs to be enabled ("auto") manually via
>>> sysfs as its power/control is set to "on" by the driver.
>> 
>> Right, that's on purpose
>> 
>>> When runtime PM enabled, dwc3 currently doesn't resume when a cable is
>>> connected.  It only suspends after a cable is disconnected.
>>>
>>> When using an extcon driver (for a different chip on the board), dwc3
>>> can register a hook for that. (Still undocumented -> TODO?).
>>>
>>> Make sure, dwc3 is resumed when "set_mode" is being called by drd.
>>>
>>> this is only a question about what's missing to properly keep runtime
>>> PM enabled for dwc3 and if my change makes any sense at all. It seems
>>> to work fine for me...
>>>
>>> I'm glad about any hints on how to keep runtime PM enabled (at least when
>>> having an extcon hook set up).
>> 
>> You need to remember that what you write here is going to be placed in
>> the commit log and will survive forever in the history of the
>> project. Can you be a little bit more technical? For example, why did
>> you change the asynchronous pm_runtime_put() to synchronous versions?
>> Why was that necessary?>
>> Also, you're missing your Signed-off-by line. Please, read the
>> documentation about how to write patches.
>
> I don't sign off on this change. It merely servers as a basis for the
> question I have: How to properly have continuous runtime PM in dwc3 (at
> least when having an extcon device connected) and is there any specific
> reason why this isn't yet implemented?

Probably because nobody has spent the time to do it. If you have HW and
time to implement this, by all means, go ahead.

Just make sure to keep the current functionality: pm runtime should only
be enabled by userspace.

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-03-16  7:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-12 14:30 [RFC PATCH] usb: dwc3: enable runtime PM for drd role switch / extcon Martin Kepplinger
2020-03-15  9:13 ` Felipe Balbi
2020-03-16  7:18   ` Martin Kepplinger
2020-03-16  7:22     ` Felipe Balbi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).