Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-03-22 Thread Baolin Wang
Hi,

On 22 March 2017 at 20:43, Mathias Nyman  wrote:
> On 22.03.2017 12:40, Baolin Wang wrote:
>>
>> Hi,
>>
>> On 22 March 2017 at 17:00, Felipe Balbi  wrote:
>>>
>>>
>>> Hi,
>>>
>>> Baolin Wang  writes:

 I don't yet understand why we can't just keep runtime pm disabled as
 a
 default for xhci platform devices.
 It could be enabled by whatever creates the platform device by
 setting some
 device property
 (or equivalent), which would be checked in xhci_plat_probe() before
 enabling
 runtime pm. It
 could then optionally be set in sysfs via power/control entry.
>>>
>>>
>>> I think runtime pm is not one hardware property, is it suitable if we
>>> introduce one device property to enable/disable runtime pm?
>
>
> we already this functionality exposed on sysfs.


  From my understanding, Mathias suggested me to add one device property
 (name like "usb-host-runtimePM") by platform_device_add_properties()
 to enable/disable runtime PM when creating platform device, like
 usb3_lpm_capable:

>
> It was more of generic pondering how to automatically enable runtime PM for
> platforms
> that know their xhci can runtime suspend/resume. But all this can be skipped
> for now and just
> force users to manually enable xhci platform runtime pm in sysfs for now.
>
> For me, and for xhci point of view only, patch 1/2 is quite ok.
> Only some minor adjustments like calling runtime_get in the beginning of
> probe, and runtime_put
> at the end end after both hcd's are added.
>
> Probe could additionally call pm_runtime_forbid() to prevent runtime pm frpm
> being on as
> default, (increases usage count, modifies runtime_auto)
>
> This would force the user to explicitly enable runtime pm usin power/control
> in sysfs.

Fair enough.

>
> In my opinion that patch could be a separate one, and how dwc3 deals with it
> can be a separate
> topic.

OK.

>
>>>
>>> yeah, that's silly. We already have means for doing that:
>>>
>>>  my_probe()
>>>  {
>>>  [...]
>>>
>>>  pm_runtime_enable(dev);
>>>  pm_runtime_forbid(dev);
>>
>>
>> That's same with getting the usage counter.
>>
>>>
>>>  [...]
>>>
>>>  return 0;
>>>  }
>>>
>> Secondly, we only can resume the xhci platform device by getting the
>> xhci usage counter from gadget driver, since the cable plug in/out
>> events only can be notified to glue layer of gadget driver(like dwc3
>> glue layer). That means if we want to suspend xhci platform device, we
>
>
> this is a problem with the glue layer, IMO. It should be something like
> so:
>
> static irqreturn_t dwc3_foobar_wakeup(int irq, void *_glue)
> {
>  struct dwc3_foobar_glue *glue = _glue;
>  u32 reg;
>
>  reg = real(glue->base, OFFSET);
>  if (reg & CONNECT)
>  pm_runtime_resume(&glue->dwc3);
>
>  return IRQ_HANDLED;
> }
>
> then dwc3's ->runtime_resume() should check if the event is supposed to
> be handled by host or peripheral by checking which mode it was before
> suspend and making the assumption that we don't change modes while
> suspended. Something like:
>
> static int dwc3_runtime_resume(struct device *dev)
> {
>  struct dwc3 *dwc = dev_get_drvdata(dev);
>
>  [...]
>
>  if (dwc->is_host)
>  pm_runtime_resume(dwc->xhci.dev);
>
>  [...]
>
>  return 0;
> }


 Yeah, if we don't need to get xhci usage counter in xhci_plat_probe(
 to avoid affecting other controller's runtime PM, we can do like this
 and do not need to get/put counter.
>>>
>>>
>>> why do you need to get xhci's usage counter in xhci_plat_probe() ?
>>>
>>> And why would one xhci affect the other? They are different struct
>>> device instances and, thus, have different pm usage counter. How would
>>> one xhci's pm_runtime affect another?
>>
>>
>> What I mean is if another USB controller's driver did not implement
>> runtime pm callbacks but system enables CONFIG_PM, that will make xhci
>> device auto-suspended when after probing xhci-plat if we did not get
>> xhci device usage counter, but gadget driver can not resume xhci
>> without implementing runtime PM callbacks.
>>
>> If we want to implement xhci-plat runtime resume/suspend without
>> getting usage counter, we should assume every driver using xhci-plat
>> should implement their runtime PM callbacks. Is this right?
>
>
> That is my understanding as well, Basically the xhci parents driver
> should end up calling  xhci_plat_runtime_resume() one way or another.
> Just like Felipe's glue driver fix above does.
>
> So lets keep pm_runtime_forbid() as default for xhci-plat for now.

I agreed. 

Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-03-22 Thread Mathias Nyman

On 22.03.2017 12:40, Baolin Wang wrote:

Hi,

On 22 March 2017 at 17:00, Felipe Balbi  wrote:


Hi,

Baolin Wang  writes:

I don't yet understand why we can't just keep runtime pm disabled as a
default for xhci platform devices.
It could be enabled by whatever creates the platform device by setting some
device property
(or equivalent), which would be checked in xhci_plat_probe() before enabling
runtime pm. It
could then optionally be set in sysfs via power/control entry.


I think runtime pm is not one hardware property, is it suitable if we
introduce one device property to enable/disable runtime pm?


we already this functionality exposed on sysfs.


 From my understanding, Mathias suggested me to add one device property
(name like "usb-host-runtimePM") by platform_device_add_properties()
to enable/disable runtime PM when creating platform device, like
usb3_lpm_capable:



It was more of generic pondering how to automatically enable runtime PM for 
platforms
that know their xhci can runtime suspend/resume. But all this can be skipped 
for now and just
force users to manually enable xhci platform runtime pm in sysfs for now.

For me, and for xhci point of view only, patch 1/2 is quite ok.
Only some minor adjustments like calling runtime_get in the beginning of probe, 
and runtime_put
at the end end after both hcd's are added.

Probe could additionally call pm_runtime_forbid() to prevent runtime pm frpm 
being on as
default, (increases usage count, modifies runtime_auto)

This would force the user to explicitly enable runtime pm usin power/control in 
sysfs.

In my opinion that patch could be a separate one, and how dwc3 deals with it 
can be a separate
topic.



yeah, that's silly. We already have means for doing that:

 my_probe()
 {
 [...]

 pm_runtime_enable(dev);
 pm_runtime_forbid(dev);


That's same with getting the usage counter.



 [...]

 return 0;
 }


Secondly, we only can resume the xhci platform device by getting the
xhci usage counter from gadget driver, since the cable plug in/out
events only can be notified to glue layer of gadget driver(like dwc3
glue layer). That means if we want to suspend xhci platform device, we


this is a problem with the glue layer, IMO. It should be something like
so:

static irqreturn_t dwc3_foobar_wakeup(int irq, void *_glue)
{
 struct dwc3_foobar_glue *glue = _glue;
 u32 reg;

 reg = real(glue->base, OFFSET);
 if (reg & CONNECT)
 pm_runtime_resume(&glue->dwc3);

 return IRQ_HANDLED;
}

then dwc3's ->runtime_resume() should check if the event is supposed to
be handled by host or peripheral by checking which mode it was before
suspend and making the assumption that we don't change modes while
suspended. Something like:

static int dwc3_runtime_resume(struct device *dev)
{
 struct dwc3 *dwc = dev_get_drvdata(dev);

 [...]

 if (dwc->is_host)
 pm_runtime_resume(dwc->xhci.dev);

 [...]

 return 0;
}


Yeah, if we don't need to get xhci usage counter in xhci_plat_probe(
to avoid affecting other controller's runtime PM, we can do like this
and do not need to get/put counter.


why do you need to get xhci's usage counter in xhci_plat_probe() ?

And why would one xhci affect the other? They are different struct
device instances and, thus, have different pm usage counter. How would
one xhci's pm_runtime affect another?


What I mean is if another USB controller's driver did not implement
runtime pm callbacks but system enables CONFIG_PM, that will make xhci
device auto-suspended when after probing xhci-plat if we did not get
xhci device usage counter, but gadget driver can not resume xhci
without implementing runtime PM callbacks.

If we want to implement xhci-plat runtime resume/suspend without
getting usage counter, we should assume every driver using xhci-plat
should implement their runtime PM callbacks. Is this right?


That is my understanding as well, Basically the xhci parents driver
should end up calling  xhci_plat_runtime_resume() one way or another.
Just like Felipe's glue driver fix above does.

So lets keep pm_runtime_forbid() as default for xhci-plat for now.

-Mathias
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-03-22 Thread Baolin Wang
Hi,

On 22 March 2017 at 17:00, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
>> I don't yet understand why we can't just keep runtime pm disabled as a
>> default for xhci platform devices.
>> It could be enabled by whatever creates the platform device by setting 
>> some
>> device property
>> (or equivalent), which would be checked in xhci_plat_probe() before 
>> enabling
>> runtime pm. It
>> could then optionally be set in sysfs via power/control entry.
>
> I think runtime pm is not one hardware property, is it suitable if we
> introduce one device property to enable/disable runtime pm?

 As I said, runtime pm is not one hardware property, I think it is not
 suitable if we introduce one device property to enable/disable runtime
 pm.
>>>
>>> we already this functionality exposed on sysfs.
>>
>> From my understanding, Mathias suggested me to add one device property
>> (name like "usb-host-runtimePM") by platform_device_add_properties()
>> to enable/disable runtime PM when creating platform device, like
>> usb3_lpm_capable:
>>
>> if (dwc->usb3_lpm_capable)
>>   props[prop_idx++].name = "usb3-lpm-capable";
>>
>> ret = platform_device_add_properties(xhci, props);
>> if (ret) {
>>   dev_err(dwc->dev, "failed to add properties to xHCI\n");
>>   goto err1;
>> }
>>
>> What I think It is not suitable to introduce one device property like
>> above to enable/disable runtime PM, it is not one hardware attribute.
>
> yeah, that's silly. We already have means for doing that:
>
> my_probe()
> {
> [...]
>
> pm_runtime_enable(dev);
> pm_runtime_forbid(dev);

That's same with getting the usage counter.

>
> [...]
>
> return 0;
> }
>
 Secondly, we only can resume the xhci platform device by getting the
 xhci usage counter from gadget driver, since the cable plug in/out
 events only can be notified to glue layer of gadget driver(like dwc3
 glue layer). That means if we want to suspend xhci platform device, we
>>>
>>> this is a problem with the glue layer, IMO. It should be something like
>>> so:
>>>
>>> static irqreturn_t dwc3_foobar_wakeup(int irq, void *_glue)
>>> {
>>> struct dwc3_foobar_glue *glue = _glue;
>>> u32 reg;
>>>
>>> reg = real(glue->base, OFFSET);
>>> if (reg & CONNECT)
>>> pm_runtime_resume(&glue->dwc3);
>>>
>>> return IRQ_HANDLED;
>>> }
>>>
>>> then dwc3's ->runtime_resume() should check if the event is supposed to
>>> be handled by host or peripheral by checking which mode it was before
>>> suspend and making the assumption that we don't change modes while
>>> suspended. Something like:
>>>
>>> static int dwc3_runtime_resume(struct device *dev)
>>> {
>>> struct dwc3 *dwc = dev_get_drvdata(dev);
>>>
>>> [...]
>>>
>>> if (dwc->is_host)
>>> pm_runtime_resume(dwc->xhci.dev);
>>>
>>> [...]
>>>
>>> return 0;
>>> }
>>
>> Yeah, if we don't need to get xhci usage counter in xhci_plat_probe()
>> to avoid affecting other controller's runtime PM, we can do like this
>> and do not need to get/put counter.
>
> why do you need to get xhci's usage counter in xhci_plat_probe() ?
>
> And why would one xhci affect the other? They are different struct
> device instances and, thus, have different pm usage counter. How would
> one xhci's pm_runtime affect another?

What I mean is if another USB controller's driver did not implement
runtime pm callbacks but system enables CONFIG_PM, that will make xhci
device auto-suspended when after probing xhci-plat if we did not get
xhci device usage counter, but gadget driver can not resume xhci
without implementing runtime PM callbacks.

If we want to implement xhci-plat runtime resume/suspend without
getting usage counter, we should assume every driver using xhci-plat
should implement their runtime PM callbacks. Is this right?

>
> PM runtime is not per driver, it's per device.

Correct.

-- 
Baolin.wang
Best Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-03-22 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
> I don't yet understand why we can't just keep runtime pm disabled as a
> default for xhci platform devices.
> It could be enabled by whatever creates the platform device by setting 
> some
> device property
> (or equivalent), which would be checked in xhci_plat_probe() before 
> enabling
> runtime pm. It
> could then optionally be set in sysfs via power/control entry.

 I think runtime pm is not one hardware property, is it suitable if we
 introduce one device property to enable/disable runtime pm?
>>>
>>> As I said, runtime pm is not one hardware property, I think it is not
>>> suitable if we introduce one device property to enable/disable runtime
>>> pm.
>>
>> we already this functionality exposed on sysfs.
>
> From my understanding, Mathias suggested me to add one device property
> (name like "usb-host-runtimePM") by platform_device_add_properties()
> to enable/disable runtime PM when creating platform device, like
> usb3_lpm_capable:
>
> if (dwc->usb3_lpm_capable)
>   props[prop_idx++].name = "usb3-lpm-capable";
>
> ret = platform_device_add_properties(xhci, props);
> if (ret) {
>   dev_err(dwc->dev, "failed to add properties to xHCI\n");
>   goto err1;
> }
>
> What I think It is not suitable to introduce one device property like
> above to enable/disable runtime PM, it is not one hardware attribute.

yeah, that's silly. We already have means for doing that:

my_probe()
{
[...]

pm_runtime_enable(dev);
pm_runtime_forbid(dev);

[...]

return 0;
}

>>> Secondly, we only can resume the xhci platform device by getting the
>>> xhci usage counter from gadget driver, since the cable plug in/out
>>> events only can be notified to glue layer of gadget driver(like dwc3
>>> glue layer). That means if we want to suspend xhci platform device, we
>>
>> this is a problem with the glue layer, IMO. It should be something like
>> so:
>>
>> static irqreturn_t dwc3_foobar_wakeup(int irq, void *_glue)
>> {
>> struct dwc3_foobar_glue *glue = _glue;
>> u32 reg;
>>
>> reg = real(glue->base, OFFSET);
>> if (reg & CONNECT)
>> pm_runtime_resume(&glue->dwc3);
>>
>> return IRQ_HANDLED;
>> }
>>
>> then dwc3's ->runtime_resume() should check if the event is supposed to
>> be handled by host or peripheral by checking which mode it was before
>> suspend and making the assumption that we don't change modes while
>> suspended. Something like:
>>
>> static int dwc3_runtime_resume(struct device *dev)
>> {
>> struct dwc3 *dwc = dev_get_drvdata(dev);
>>
>> [...]
>>
>> if (dwc->is_host)
>> pm_runtime_resume(dwc->xhci.dev);
>>
>> [...]
>>
>> return 0;
>> }
>
> Yeah, if we don't need to get xhci usage counter in xhci_plat_probe()
> to avoid affecting other controller's runtime PM, we can do like this
> and do not need to get/put counter.

why do you need to get xhci's usage counter in xhci_plat_probe() ?

And why would one xhci affect the other? They are different struct
device instances and, thus, have different pm usage counter. How would
one xhci's pm_runtime affect another?

PM runtime is not per driver, it's per device.

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-03-21 Thread Baolin Wang
Hi,

On 21 March 2017 at 16:07, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
 I don't yet understand why we can't just keep runtime pm disabled as a
 default for xhci platform devices.
 It could be enabled by whatever creates the platform device by setting some
 device property
 (or equivalent), which would be checked in xhci_plat_probe() before 
 enabling
 runtime pm. It
 could then optionally be set in sysfs via power/control entry.
>>>
>>> I think runtime pm is not one hardware property, is it suitable if we
>>> introduce one device property to enable/disable runtime pm?
>>
>> As I said, runtime pm is not one hardware property, I think it is not
>> suitable if we introduce one device property to enable/disable runtime
>> pm.
>
> we already this functionality exposed on sysfs.

>From my understanding, Mathias suggested me to add one device property
(name like "usb-host-runtimePM") by platform_device_add_properties()
to enable/disable runtime PM when creating platform device, like
usb3_lpm_capable:

if (dwc->usb3_lpm_capable)
  props[prop_idx++].name = "usb3-lpm-capable";

ret = platform_device_add_properties(xhci, props);
if (ret) {
  dev_err(dwc->dev, "failed to add properties to xHCI\n");
  goto err1;
}

What I think It is not suitable to introduce one device property like
above to enable/disable runtime PM, it is not one hardware attribute.

>
>> Secondly, we only can resume the xhci platform device by getting the
>> xhci usage counter from gadget driver, since the cable plug in/out
>> events only can be notified to glue layer of gadget driver(like dwc3
>> glue layer). That means if we want to suspend xhci platform device, we
>
> this is a problem with the glue layer, IMO. It should be something like
> so:
>
> static irqreturn_t dwc3_foobar_wakeup(int irq, void *_glue)
> {
> struct dwc3_foobar_glue *glue = _glue;
> u32 reg;
>
> reg = real(glue->base, OFFSET);
> if (reg & CONNECT)
> pm_runtime_resume(&glue->dwc3);
>
> return IRQ_HANDLED;
> }
>
> then dwc3's ->runtime_resume() should check if the event is supposed to
> be handled by host or peripheral by checking which mode it was before
> suspend and making the assumption that we don't change modes while
> suspended. Something like:
>
> static int dwc3_runtime_resume(struct device *dev)
> {
> struct dwc3 *dwc = dev_get_drvdata(dev);
>
> [...]
>
> if (dwc->is_host)
> pm_runtime_resume(dwc->xhci.dev);
>
> [...]
>
> return 0;
> }

Yeah, if we don't need to get xhci usage counter in xhci_plat_probe()
to avoid affecting other controller's runtime PM, we can do like this
and do not need to get/put counter.

>> must put xhci usage counter (so we can not keep their parent-child
>> relationship intact). That is why we need
>> pm_suspend_ignore_children(dev, true).
>
> you really shouldn't need that and it's still unclear why you think you
> do.
>
> --
> balbi



-- 
Baolin.wang
Best Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-03-21 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
>>> I don't yet understand why we can't just keep runtime pm disabled as a
>>> default for xhci platform devices.
>>> It could be enabled by whatever creates the platform device by setting some
>>> device property
>>> (or equivalent), which would be checked in xhci_plat_probe() before enabling
>>> runtime pm. It
>>> could then optionally be set in sysfs via power/control entry.
>>
>> I think runtime pm is not one hardware property, is it suitable if we
>> introduce one device property to enable/disable runtime pm?
>
> As I said, runtime pm is not one hardware property, I think it is not
> suitable if we introduce one device property to enable/disable runtime
> pm.

we already this functionality exposed on sysfs.

> Secondly, we only can resume the xhci platform device by getting the
> xhci usage counter from gadget driver, since the cable plug in/out
> events only can be notified to glue layer of gadget driver(like dwc3
> glue layer). That means if we want to suspend xhci platform device, we

this is a problem with the glue layer, IMO. It should be something like
so:

static irqreturn_t dwc3_foobar_wakeup(int irq, void *_glue)
{
struct dwc3_foobar_glue *glue = _glue;
u32 reg;

reg = real(glue->base, OFFSET);
if (reg & CONNECT)
pm_runtime_resume(&glue->dwc3);

return IRQ_HANDLED;
}

then dwc3's ->runtime_resume() should check if the event is supposed to
be handled by host or peripheral by checking which mode it was before
suspend and making the assumption that we don't change modes while
suspended. Something like:

static int dwc3_runtime_resume(struct device *dev)
{
struct dwc3 *dwc = dev_get_drvdata(dev);

[...]

if (dwc->is_host)
pm_runtime_resume(dwc->xhci.dev);

[...]

return 0;
}

> must put xhci usage counter (so we can not keep their parent-child
> relationship intact). That is why we need
> pm_suspend_ignore_children(dev, true).

you really shouldn't need that and it's still unclear why you think you
do.

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-03-21 Thread Baolin Wang
Hi Mathias,

On 21 February 2017 at 10:09, Baolin Wang  wrote:
>> Do you have any comments about this patch? Thanks.
>>
>>>drivers/usb/host/xhci-plat.c |   41
>>> -
>>>1 file changed, 36 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/usb/host/xhci-plat.c
>>> b/drivers/usb/host/xhci-plat.c
>>> index ed56bf9..5805c6a 100644
>>> --- a/drivers/usb/host/xhci-plat.c
>>> +++ b/drivers/usb/host/xhci-plat.c
>>> @@ -246,6 +246,10 @@ static int xhci_plat_probe(struct platform_device
>>> *pdev)
>>>   if (ret)
>>>   goto dealloc_usb2_hcd;
>>>
>>> +   pm_runtime_get_noresume(&pdev->dev);
>>> +   pm_runtime_set_active(&pdev->dev);
>>> +   pm_runtime_enable(&pdev->dev);
>>> +
>>>   return 0;
>>>
>>>
>
> To me this looks like we are not really enabling runtime pm for xhci, we
> increment the
> usage count in probe, and keep it until remove is called.
>
> This would normally prevent parent dwc3 from runtime suspending, but I
> see
> that in patch 2/2 adds
> pm_suspend_ignore_children(dev, true) to dwc3, and, that dwc3 actually
> controls xhci runtime
> pm by calling pm_runtime_get/put for xhci in its own dwc3
> runtime_suspend/resume callbacks.
>
> Looks a bit upside down to me, what's the reason for this?
>
> what prevents calling pm_runtime_put_* before leaving probe in xhci and
> let
> pm code handle
> the runtime suspend and parent/child relationships?


 When dwc3 controller is working on host mode, which will create and
 add the USB hcd for host side. Then if we want to suspend dwc3
 controller as host mode, the USB device (bus) of host side will
 runtime suspend automatically if there are no slave attached (by

 usb_runtime_suspend()--->usb_suspend_both()--->usb_suspend_interface()--->usb_suspend_device()--->generic_suspend()--->hcd_bus_suspend()--->xhci_bus_suspend()),
 but we should not suspend xHCI device (issuing xhci_suspend()) now,
 since some other  controllers did not implement the runtime PM to
 control xHCI device's runtime state, which will cause other
 controllers can not resume xHCI device (issuing xhci_resume()) if the
 xHCI device suspend automatically by its child device. Thus we should
 get the runtime count for xHCI device in xhci_plat_probe() in case
 xHCI device will also suspend automatically by its child device.
 According to that, for xHCI device's parent: dwc3 device, we should
 put the xHCI device's runtime count to suspend xHCI device manually.

>>>
>>> Any more comments?
>>>
>>
>> I think I at least partially understand your point. You don't want to enable
>> runtime suspend for all xhci platform devices by default, but only for the
>> ones
>> that are part of dwc3.
>>
>> The implementation you suggest is that xhci platform driver always increase
>> the xhci platform
>> device usage counter during probe with pm_runtime_get_noresume(), and never
>> decrement it,
>> preventing xhci platform devices from runtime suspending by themselves.
>>
>> You then control xhci runtime suspend from dwc3 driver runtime suspend,
>> allowing
>> xhci platfrom controller to runtime suspend only when dwc3 runtime suspends
>> by decrementing xhci
>> platform device usage in dwc3 runtime suspend callback.
>> As xhci is a child of dwc3 in this case,  dwc3 would never runtime suspend
>> as long as xhci is running, so
>> dwc3 needed to be detached from xhci by setting dwc3 to ignore its children
>> to get it to work.
>
> Yes, that's my point.
>
>>
>> I don't yet understand why we can't just keep runtime pm disabled as a
>> default for xhci platform devices.
>> It could be enabled by whatever creates the platform device by setting some
>> device property
>> (or equivalent), which would be checked in xhci_plat_probe() before enabling
>> runtime pm. It
>> could then optionally be set in sysfs via power/control entry.
>
> I think runtime pm is not one hardware property, is it suitable if we
> introduce one device property to enable/disable runtime pm?

As I said, runtime pm is not one hardware property, I think it is not
suitable if we introduce one device property to enable/disable runtime
pm.

Secondly, we only can resume the xhci platform device by getting the
xhci usage counter from gadget driver, since the cable plug in/out
events only can be notified to glue layer of gadget driver(like dwc3
glue layer). That means if we want to suspend xhci platform device, we
must put xhci usage counter (so we can not keep their parent-child
relationship intact). That is why we need
pm_suspend_ignore_children(dev, true).

Mathias, could you re-check this patch? Thanks.

>>
>> We would keep the usage counting intact, and only enable xhci platform
>> device runtime pm
>> if the platform supports

Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-02-20 Thread Baolin Wang
On 20 February 2017 at 23:10, Mathias Nyman
 wrote:
> On 20.02.2017 04:47, Baolin Wang wrote:
>>
>> Hi Mathias,
>>
>> On 6 February 2017 at 13:26, Baolin Wang  wrote:
>>>
>>> Hi Mathias,
>>>
>>> On 31 January 2017 at 21:14, Mathias Nyman
>>>  wrote:

 On 16.01.2017 12:56, Baolin Wang wrote:
>
>
> Hi Mathias,



 Hi

 Sorry about the long review delay
 CC Alan in case my pm assumptions need to be corrected


>
> On 13 December 2016 at 15:49, Baolin Wang 
> wrote:
>>
>>
>> Enable the xhci plat runtime PM for parent device to suspend/resume
>> xhci.
>> Also call pm_runtime_get_noresume() in probe() function in case the
>> parent
>> device doesn't call suspend/resume callback by runtime PM now.
>>
>> Signed-off-by: Baolin Wang 
>> ---
>> Changes since v4:
>>- No updates.
>>
>> Changes since v3:
>>- Fix kbuild error.
>>
>> Changes since v2:
>>- Add pm_runtime_get_noresume() in probe() function.
>>- Add pm_runtime_set_suspended()/pm_runtime_put_noidle() in
>> remove()
>> function.
>>
>> Changes since v1:
>>- No updates.
>> ---
>
>
>
> Do you have any comments about this patch? Thanks.
>
>>drivers/usb/host/xhci-plat.c |   41
>> -
>>1 file changed, 36 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/usb/host/xhci-plat.c
>> b/drivers/usb/host/xhci-plat.c
>> index ed56bf9..5805c6a 100644
>> --- a/drivers/usb/host/xhci-plat.c
>> +++ b/drivers/usb/host/xhci-plat.c
>> @@ -246,6 +246,10 @@ static int xhci_plat_probe(struct platform_device
>> *pdev)
>>   if (ret)
>>   goto dealloc_usb2_hcd;
>>
>> +   pm_runtime_get_noresume(&pdev->dev);
>> +   pm_runtime_set_active(&pdev->dev);
>> +   pm_runtime_enable(&pdev->dev);
>> +
>>   return 0;
>>
>>

 To me this looks like we are not really enabling runtime pm for xhci, we
 increment the
 usage count in probe, and keep it until remove is called.

 This would normally prevent parent dwc3 from runtime suspending, but I
 see
 that in patch 2/2 adds
 pm_suspend_ignore_children(dev, true) to dwc3, and, that dwc3 actually
 controls xhci runtime
 pm by calling pm_runtime_get/put for xhci in its own dwc3
 runtime_suspend/resume callbacks.

 Looks a bit upside down to me, what's the reason for this?

 what prevents calling pm_runtime_put_* before leaving probe in xhci and
 let
 pm code handle
 the runtime suspend and parent/child relationships?
>>>
>>>
>>> When dwc3 controller is working on host mode, which will create and
>>> add the USB hcd for host side. Then if we want to suspend dwc3
>>> controller as host mode, the USB device (bus) of host side will
>>> runtime suspend automatically if there are no slave attached (by
>>>
>>> usb_runtime_suspend()--->usb_suspend_both()--->usb_suspend_interface()--->usb_suspend_device()--->generic_suspend()--->hcd_bus_suspend()--->xhci_bus_suspend()),
>>> but we should not suspend xHCI device (issuing xhci_suspend()) now,
>>> since some other  controllers did not implement the runtime PM to
>>> control xHCI device's runtime state, which will cause other
>>> controllers can not resume xHCI device (issuing xhci_resume()) if the
>>> xHCI device suspend automatically by its child device. Thus we should
>>> get the runtime count for xHCI device in xhci_plat_probe() in case
>>> xHCI device will also suspend automatically by its child device.
>>> According to that, for xHCI device's parent: dwc3 device, we should
>>> put the xHCI device's runtime count to suspend xHCI device manually.
>>>
>>
>> Any more comments?
>>
>
> I think I at least partially understand your point. You don't want to enable
> runtime suspend for all xhci platform devices by default, but only for the
> ones
> that are part of dwc3.
>
> The implementation you suggest is that xhci platform driver always increase
> the xhci platform
> device usage counter during probe with pm_runtime_get_noresume(), and never
> decrement it,
> preventing xhci platform devices from runtime suspending by themselves.
>
> You then control xhci runtime suspend from dwc3 driver runtime suspend,
> allowing
> xhci platfrom controller to runtime suspend only when dwc3 runtime suspends
> by decrementing xhci
> platform device usage in dwc3 runtime suspend callback.
> As xhci is a child of dwc3 in this case,  dwc3 would never runtime suspend
> as long as xhci is running, so
> dwc3 needed to be detached from xhci by setting dwc3 to ignore its children
> to get it to work.

Yes, that's my point.

>
> I don't yet understand why we can't just keep runtime pm disabled as a
> default for xhci platform devices.
> It could be enabled by whatever creates the platform 

Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-02-20 Thread Mathias Nyman

On 20.02.2017 04:47, Baolin Wang wrote:

Hi Mathias,

On 6 February 2017 at 13:26, Baolin Wang  wrote:

Hi Mathias,

On 31 January 2017 at 21:14, Mathias Nyman
 wrote:

On 16.01.2017 12:56, Baolin Wang wrote:


Hi Mathias,



Hi

Sorry about the long review delay
CC Alan in case my pm assumptions need to be corrected




On 13 December 2016 at 15:49, Baolin Wang  wrote:


Enable the xhci plat runtime PM for parent device to suspend/resume xhci.
Also call pm_runtime_get_noresume() in probe() function in case the
parent
device doesn't call suspend/resume callback by runtime PM now.

Signed-off-by: Baolin Wang 
---
Changes since v4:
   - No updates.

Changes since v3:
   - Fix kbuild error.

Changes since v2:
   - Add pm_runtime_get_noresume() in probe() function.
   - Add pm_runtime_set_suspended()/pm_runtime_put_noidle() in remove()
function.

Changes since v1:
   - No updates.
---



Do you have any comments about this patch? Thanks.


   drivers/usb/host/xhci-plat.c |   41
-
   1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index ed56bf9..5805c6a 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -246,6 +246,10 @@ static int xhci_plat_probe(struct platform_device
*pdev)
  if (ret)
  goto dealloc_usb2_hcd;

+   pm_runtime_get_noresume(&pdev->dev);
+   pm_runtime_set_active(&pdev->dev);
+   pm_runtime_enable(&pdev->dev);
+
  return 0;




To me this looks like we are not really enabling runtime pm for xhci, we
increment the
usage count in probe, and keep it until remove is called.

This would normally prevent parent dwc3 from runtime suspending, but I see
that in patch 2/2 adds
pm_suspend_ignore_children(dev, true) to dwc3, and, that dwc3 actually
controls xhci runtime
pm by calling pm_runtime_get/put for xhci in its own dwc3
runtime_suspend/resume callbacks.

Looks a bit upside down to me, what's the reason for this?

what prevents calling pm_runtime_put_* before leaving probe in xhci and let
pm code handle
the runtime suspend and parent/child relationships?


When dwc3 controller is working on host mode, which will create and
add the USB hcd for host side. Then if we want to suspend dwc3
controller as host mode, the USB device (bus) of host side will
runtime suspend automatically if there are no slave attached (by
usb_runtime_suspend()--->usb_suspend_both()--->usb_suspend_interface()--->usb_suspend_device()--->generic_suspend()--->hcd_bus_suspend()--->xhci_bus_suspend()),
but we should not suspend xHCI device (issuing xhci_suspend()) now,
since some other  controllers did not implement the runtime PM to
control xHCI device's runtime state, which will cause other
controllers can not resume xHCI device (issuing xhci_resume()) if the
xHCI device suspend automatically by its child device. Thus we should
get the runtime count for xHCI device in xhci_plat_probe() in case
xHCI device will also suspend automatically by its child device.
According to that, for xHCI device's parent: dwc3 device, we should
put the xHCI device's runtime count to suspend xHCI device manually.



Any more comments?



I think I at least partially understand your point. You don't want to enable
runtime suspend for all xhci platform devices by default, but only for the ones
that are part of dwc3.

The implementation you suggest is that xhci platform driver always increase the 
xhci platform
device usage counter during probe with pm_runtime_get_noresume(), and never 
decrement it,
preventing xhci platform devices from runtime suspending by themselves.

You then control xhci runtime suspend from dwc3 driver runtime suspend, allowing
xhci platfrom controller to runtime suspend only when dwc3 runtime suspends by 
decrementing xhci
platform device usage in dwc3 runtime suspend callback.
As xhci is a child of dwc3 in this case,  dwc3 would never runtime suspend as 
long as xhci is running, so
dwc3 needed to be detached from xhci by setting dwc3 to ignore its children to 
get it to work.

I don't yet understand why we can't just keep runtime pm disabled as a default 
for xhci platform devices.
It could be enabled by whatever creates the platform device by setting some 
device property
(or equivalent), which would be checked in xhci_plat_probe() before enabling 
runtime pm. It
could then optionally be set in sysfs via power/control entry.

We would keep the usage counting intact, and only enable xhci platform device 
runtime pm
if the platform supports it, and dwc3 and xhci would keep their parent-child 
relationship
intact and make sure dwc3 can't runtime suspend before xhci.

To the concerns about xhci runtime suspending too early, the codepath you 
describet only applies
for roothub devices, which sohuld be called only after other devices have 
suspended.

To make sure xhci platform device does not runtime suspend during probe after 
first
hcd is added (wi

Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-02-19 Thread Baolin Wang
Hi Mathias,

On 6 February 2017 at 13:26, Baolin Wang  wrote:
> Hi Mathias,
>
> On 31 January 2017 at 21:14, Mathias Nyman
>  wrote:
>> On 16.01.2017 12:56, Baolin Wang wrote:
>>>
>>> Hi Mathias,
>>
>>
>> Hi
>>
>> Sorry about the long review delay
>> CC Alan in case my pm assumptions need to be corrected
>>
>>
>>>
>>> On 13 December 2016 at 15:49, Baolin Wang  wrote:

 Enable the xhci plat runtime PM for parent device to suspend/resume xhci.
 Also call pm_runtime_get_noresume() in probe() function in case the
 parent
 device doesn't call suspend/resume callback by runtime PM now.

 Signed-off-by: Baolin Wang 
 ---
 Changes since v4:
   - No updates.

 Changes since v3:
   - Fix kbuild error.

 Changes since v2:
   - Add pm_runtime_get_noresume() in probe() function.
   - Add pm_runtime_set_suspended()/pm_runtime_put_noidle() in remove()
 function.

 Changes since v1:
   - No updates.
 ---
>>>
>>>
>>> Do you have any comments about this patch? Thanks.
>>>
   drivers/usb/host/xhci-plat.c |   41
 -
   1 file changed, 36 insertions(+), 5 deletions(-)

 diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
 index ed56bf9..5805c6a 100644
 --- a/drivers/usb/host/xhci-plat.c
 +++ b/drivers/usb/host/xhci-plat.c
 @@ -246,6 +246,10 @@ static int xhci_plat_probe(struct platform_device
 *pdev)
  if (ret)
  goto dealloc_usb2_hcd;

 +   pm_runtime_get_noresume(&pdev->dev);
 +   pm_runtime_set_active(&pdev->dev);
 +   pm_runtime_enable(&pdev->dev);
 +
  return 0;


>>
>> To me this looks like we are not really enabling runtime pm for xhci, we
>> increment the
>> usage count in probe, and keep it until remove is called.
>>
>> This would normally prevent parent dwc3 from runtime suspending, but I see
>> that in patch 2/2 adds
>> pm_suspend_ignore_children(dev, true) to dwc3, and, that dwc3 actually
>> controls xhci runtime
>> pm by calling pm_runtime_get/put for xhci in its own dwc3
>> runtime_suspend/resume callbacks.
>>
>> Looks a bit upside down to me, what's the reason for this?
>>
>> what prevents calling pm_runtime_put_* before leaving probe in xhci and let
>> pm code handle
>> the runtime suspend and parent/child relationships?
>
> When dwc3 controller is working on host mode, which will create and
> add the USB hcd for host side. Then if we want to suspend dwc3
> controller as host mode, the USB device (bus) of host side will
> runtime suspend automatically if there are no slave attached (by
> usb_runtime_suspend()--->usb_suspend_both()--->usb_suspend_interface()--->usb_suspend_device()--->generic_suspend()--->hcd_bus_suspend()--->xhci_bus_suspend()),
> but we should not suspend xHCI device (issuing xhci_suspend()) now,
> since some other  controllers did not implement the runtime PM to
> control xHCI device's runtime state, which will cause other
> controllers can not resume xHCI device (issuing xhci_resume()) if the
> xHCI device suspend automatically by its child device. Thus we should
> get the runtime count for xHCI device in xhci_plat_probe() in case
> xHCI device will also suspend automatically by its child device.
> According to that, for xHCI device's parent: dwc3 device, we should
> put the xHCI device's runtime count to suspend xHCI device manually.
>

Any more comments?

-- 
Baolin.wang
Best Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-02-05 Thread Baolin Wang
Hi Robert,

On 26 January 2017 at 01:30, Robert Foss  wrote:
> Looks good to me.
>
> Feel free to add my r-b.

OK, thanks for your reviewing.

-- 
Baolin.wang
Best Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-02-05 Thread Baolin Wang
Hi Mathias,

On 31 January 2017 at 21:14, Mathias Nyman
 wrote:
> On 16.01.2017 12:56, Baolin Wang wrote:
>>
>> Hi Mathias,
>
>
> Hi
>
> Sorry about the long review delay
> CC Alan in case my pm assumptions need to be corrected
>
>
>>
>> On 13 December 2016 at 15:49, Baolin Wang  wrote:
>>>
>>> Enable the xhci plat runtime PM for parent device to suspend/resume xhci.
>>> Also call pm_runtime_get_noresume() in probe() function in case the
>>> parent
>>> device doesn't call suspend/resume callback by runtime PM now.
>>>
>>> Signed-off-by: Baolin Wang 
>>> ---
>>> Changes since v4:
>>>   - No updates.
>>>
>>> Changes since v3:
>>>   - Fix kbuild error.
>>>
>>> Changes since v2:
>>>   - Add pm_runtime_get_noresume() in probe() function.
>>>   - Add pm_runtime_set_suspended()/pm_runtime_put_noidle() in remove()
>>> function.
>>>
>>> Changes since v1:
>>>   - No updates.
>>> ---
>>
>>
>> Do you have any comments about this patch? Thanks.
>>
>>>   drivers/usb/host/xhci-plat.c |   41
>>> -
>>>   1 file changed, 36 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
>>> index ed56bf9..5805c6a 100644
>>> --- a/drivers/usb/host/xhci-plat.c
>>> +++ b/drivers/usb/host/xhci-plat.c
>>> @@ -246,6 +246,10 @@ static int xhci_plat_probe(struct platform_device
>>> *pdev)
>>>  if (ret)
>>>  goto dealloc_usb2_hcd;
>>>
>>> +   pm_runtime_get_noresume(&pdev->dev);
>>> +   pm_runtime_set_active(&pdev->dev);
>>> +   pm_runtime_enable(&pdev->dev);
>>> +
>>>  return 0;
>>>
>>>
>
> To me this looks like we are not really enabling runtime pm for xhci, we
> increment the
> usage count in probe, and keep it until remove is called.
>
> This would normally prevent parent dwc3 from runtime suspending, but I see
> that in patch 2/2 adds
> pm_suspend_ignore_children(dev, true) to dwc3, and, that dwc3 actually
> controls xhci runtime
> pm by calling pm_runtime_get/put for xhci in its own dwc3
> runtime_suspend/resume callbacks.
>
> Looks a bit upside down to me, what's the reason for this?
>
> what prevents calling pm_runtime_put_* before leaving probe in xhci and let
> pm code handle
> the runtime suspend and parent/child relationships?

When dwc3 controller is working on host mode, which will create and
add the USB hcd for host side. Then if we want to suspend dwc3
controller as host mode, the USB device (bus) of host side will
runtime suspend automatically if there are no slave attached (by
usb_runtime_suspend()--->usb_suspend_both()--->usb_suspend_interface()--->usb_suspend_device()--->generic_suspend()--->hcd_bus_suspend()--->xhci_bus_suspend()),
but we should not suspend xHCI device (issuing xhci_suspend()) now,
since some other  controllers did not implement the runtime PM to
control xHCI device's runtime state, which will cause other
controllers can not resume xHCI device (issuing xhci_resume()) if the
xHCI device suspend automatically by its child device. Thus we should
get the runtime count for xHCI device in xhci_plat_probe() in case
xHCI device will also suspend automatically by its child device.
According to that, for xHCI device's parent: dwc3 device, we should
put the xHCI device's runtime count to suspend xHCI device manually.

-- 
Baolin.wang
Best Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-01-31 Thread Mathias Nyman

On 16.01.2017 12:56, Baolin Wang wrote:

Hi Mathias,


Hi

Sorry about the long review delay
CC Alan in case my pm assumptions need to be corrected



On 13 December 2016 at 15:49, Baolin Wang  wrote:

Enable the xhci plat runtime PM for parent device to suspend/resume xhci.
Also call pm_runtime_get_noresume() in probe() function in case the parent
device doesn't call suspend/resume callback by runtime PM now.

Signed-off-by: Baolin Wang 
---
Changes since v4:
  - No updates.

Changes since v3:
  - Fix kbuild error.

Changes since v2:
  - Add pm_runtime_get_noresume() in probe() function.
  - Add pm_runtime_set_suspended()/pm_runtime_put_noidle() in remove() function.

Changes since v1:
  - No updates.
---


Do you have any comments about this patch? Thanks.


  drivers/usb/host/xhci-plat.c |   41 -
  1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index ed56bf9..5805c6a 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -246,6 +246,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
 if (ret)
 goto dealloc_usb2_hcd;

+   pm_runtime_get_noresume(&pdev->dev);
+   pm_runtime_set_active(&pdev->dev);
+   pm_runtime_enable(&pdev->dev);
+
 return 0;




To me this looks like we are not really enabling runtime pm for xhci, we 
increment the
usage count in probe, and keep it until remove is called.

This would normally prevent parent dwc3 from runtime suspending, but I see that 
in patch 2/2 adds
pm_suspend_ignore_children(dev, true) to dwc3, and, that dwc3 actually controls 
xhci runtime
pm by calling pm_runtime_get/put for xhci in its own dwc3 
runtime_suspend/resume callbacks.

Looks a bit upside down to me, what's the reason for this?

what prevents calling pm_runtime_put_* before leaving probe in xhci and let pm 
code handle
the runtime suspend and parent/child relationships?

-Mathias

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-01-25 Thread Robert Foss

Looks good to me.

Feel free to add my r-b.

On 2016-12-13 02:49 AM, Baolin Wang wrote:

Enable the xhci plat runtime PM for parent device to suspend/resume xhci.
Also call pm_runtime_get_noresume() in probe() function in case the parent
device doesn't call suspend/resume callback by runtime PM now.

Signed-off-by: Baolin Wang 
---
Changes since v4:
 - No updates.

Changes since v3:
 - Fix kbuild error.

Changes since v2:
 - Add pm_runtime_get_noresume() in probe() function.
 - Add pm_runtime_set_suspended()/pm_runtime_put_noidle() in remove() function.

Changes since v1:
 - No updates.
---
 drivers/usb/host/xhci-plat.c |   41 -
 1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index ed56bf9..5805c6a 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -246,6 +246,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
if (ret)
goto dealloc_usb2_hcd;

+   pm_runtime_get_noresume(&pdev->dev);
+   pm_runtime_set_active(&pdev->dev);
+   pm_runtime_enable(&pdev->dev);
+
return 0;


@@ -274,6 +278,10 @@ static int xhci_plat_remove(struct platform_device *dev)
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct clk *clk = xhci->clk;

+   pm_runtime_set_suspended(&dev->dev);
+   pm_runtime_put_noidle(&dev->dev);
+   pm_runtime_disable(&dev->dev);
+
usb_remove_hcd(xhci->shared_hcd);
usb_phy_shutdown(hcd->usb_phy);

@@ -311,14 +319,37 @@ static int xhci_plat_resume(struct device *dev)

return xhci_resume(xhci, 0);
 }
+#endif /* CONFIG_PM_SLEEP */
+
+#ifdef CONFIG_PM
+static int xhci_plat_runtime_suspend(struct device *dev)
+{
+   struct usb_hcd  *hcd = dev_get_drvdata(dev);
+   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+
+   return xhci_suspend(xhci, device_may_wakeup(dev));
+}
+
+static int xhci_plat_runtime_resume(struct device *dev)
+{
+   struct usb_hcd  *hcd = dev_get_drvdata(dev);
+   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+
+   return xhci_resume(xhci, 0);
+}
+
+static int xhci_plat_runtime_idle(struct device *dev)
+{
+   return 0;
+}
+#endif /* CONFIG_PM */

 static const struct dev_pm_ops xhci_plat_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
+
+   SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, xhci_plat_runtime_resume,
+  xhci_plat_runtime_idle)
 };
-#define DEV_PM_OPS (&xhci_plat_pm_ops)
-#else
-#define DEV_PM_OPS NULL
-#endif /* CONFIG_PM */

 static const struct acpi_device_id usb_xhci_acpi_match[] = {
/* XHCI-compliant USB Controller */
@@ -332,7 +363,7 @@ static int xhci_plat_resume(struct device *dev)
.remove = xhci_plat_remove,
.driver = {
.name = "xhci-hcd",
-   .pm = DEV_PM_OPS,
+   .pm = &xhci_plat_pm_ops,
.of_match_table = of_match_ptr(usb_xhci_of_match),
.acpi_match_table = ACPI_PTR(usb_xhci_acpi_match),
},


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2017-01-16 Thread Baolin Wang
Hi Mathias,

On 13 December 2016 at 15:49, Baolin Wang  wrote:
> Enable the xhci plat runtime PM for parent device to suspend/resume xhci.
> Also call pm_runtime_get_noresume() in probe() function in case the parent
> device doesn't call suspend/resume callback by runtime PM now.
>
> Signed-off-by: Baolin Wang 
> ---
> Changes since v4:
>  - No updates.
>
> Changes since v3:
>  - Fix kbuild error.
>
> Changes since v2:
>  - Add pm_runtime_get_noresume() in probe() function.
>  - Add pm_runtime_set_suspended()/pm_runtime_put_noidle() in remove() 
> function.
>
> Changes since v1:
>  - No updates.
> ---

Do you have any comments about this patch? Thanks.

>  drivers/usb/host/xhci-plat.c |   41 -
>  1 file changed, 36 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index ed56bf9..5805c6a 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -246,6 +246,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
> if (ret)
> goto dealloc_usb2_hcd;
>
> +   pm_runtime_get_noresume(&pdev->dev);
> +   pm_runtime_set_active(&pdev->dev);
> +   pm_runtime_enable(&pdev->dev);
> +
> return 0;
>
>
> @@ -274,6 +278,10 @@ static int xhci_plat_remove(struct platform_device *dev)
> struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> struct clk *clk = xhci->clk;
>
> +   pm_runtime_set_suspended(&dev->dev);
> +   pm_runtime_put_noidle(&dev->dev);
> +   pm_runtime_disable(&dev->dev);
> +
> usb_remove_hcd(xhci->shared_hcd);
> usb_phy_shutdown(hcd->usb_phy);
>
> @@ -311,14 +319,37 @@ static int xhci_plat_resume(struct device *dev)
>
> return xhci_resume(xhci, 0);
>  }
> +#endif /* CONFIG_PM_SLEEP */
> +
> +#ifdef CONFIG_PM
> +static int xhci_plat_runtime_suspend(struct device *dev)
> +{
> +   struct usb_hcd  *hcd = dev_get_drvdata(dev);
> +   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> +
> +   return xhci_suspend(xhci, device_may_wakeup(dev));
> +}
> +
> +static int xhci_plat_runtime_resume(struct device *dev)
> +{
> +   struct usb_hcd  *hcd = dev_get_drvdata(dev);
> +   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
> +
> +   return xhci_resume(xhci, 0);
> +}
> +
> +static int xhci_plat_runtime_idle(struct device *dev)
> +{
> +   return 0;
> +}
> +#endif /* CONFIG_PM */
>
>  static const struct dev_pm_ops xhci_plat_pm_ops = {
> SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
> +
> +   SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, 
> xhci_plat_runtime_resume,
> +  xhci_plat_runtime_idle)
>  };
> -#define DEV_PM_OPS (&xhci_plat_pm_ops)
> -#else
> -#define DEV_PM_OPS NULL
> -#endif /* CONFIG_PM */
>
>  static const struct acpi_device_id usb_xhci_acpi_match[] = {
> /* XHCI-compliant USB Controller */
> @@ -332,7 +363,7 @@ static int xhci_plat_resume(struct device *dev)
> .remove = xhci_plat_remove,
> .driver = {
> .name = "xhci-hcd",
> -   .pm = DEV_PM_OPS,
> +   .pm = &xhci_plat_pm_ops,
> .of_match_table = of_match_ptr(usb_xhci_of_match),
> .acpi_match_table = ACPI_PTR(usb_xhci_acpi_match),
> },
> --
> 1.7.9.5
>



-- 
Baolin.wang
Best Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM

2016-12-12 Thread Baolin Wang
Enable the xhci plat runtime PM for parent device to suspend/resume xhci.
Also call pm_runtime_get_noresume() in probe() function in case the parent
device doesn't call suspend/resume callback by runtime PM now.

Signed-off-by: Baolin Wang 
---
Changes since v4:
 - No updates.

Changes since v3:
 - Fix kbuild error.

Changes since v2:
 - Add pm_runtime_get_noresume() in probe() function.
 - Add pm_runtime_set_suspended()/pm_runtime_put_noidle() in remove() function.

Changes since v1:
 - No updates.
---
 drivers/usb/host/xhci-plat.c |   41 -
 1 file changed, 36 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index ed56bf9..5805c6a 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -246,6 +246,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
if (ret)
goto dealloc_usb2_hcd;
 
+   pm_runtime_get_noresume(&pdev->dev);
+   pm_runtime_set_active(&pdev->dev);
+   pm_runtime_enable(&pdev->dev);
+
return 0;
 
 
@@ -274,6 +278,10 @@ static int xhci_plat_remove(struct platform_device *dev)
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
struct clk *clk = xhci->clk;
 
+   pm_runtime_set_suspended(&dev->dev);
+   pm_runtime_put_noidle(&dev->dev);
+   pm_runtime_disable(&dev->dev);
+
usb_remove_hcd(xhci->shared_hcd);
usb_phy_shutdown(hcd->usb_phy);
 
@@ -311,14 +319,37 @@ static int xhci_plat_resume(struct device *dev)
 
return xhci_resume(xhci, 0);
 }
+#endif /* CONFIG_PM_SLEEP */
+
+#ifdef CONFIG_PM
+static int xhci_plat_runtime_suspend(struct device *dev)
+{
+   struct usb_hcd  *hcd = dev_get_drvdata(dev);
+   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+
+   return xhci_suspend(xhci, device_may_wakeup(dev));
+}
+
+static int xhci_plat_runtime_resume(struct device *dev)
+{
+   struct usb_hcd  *hcd = dev_get_drvdata(dev);
+   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+
+   return xhci_resume(xhci, 0);
+}
+
+static int xhci_plat_runtime_idle(struct device *dev)
+{
+   return 0;
+}
+#endif /* CONFIG_PM */
 
 static const struct dev_pm_ops xhci_plat_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume)
+
+   SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, xhci_plat_runtime_resume,
+  xhci_plat_runtime_idle)
 };
-#define DEV_PM_OPS (&xhci_plat_pm_ops)
-#else
-#define DEV_PM_OPS NULL
-#endif /* CONFIG_PM */
 
 static const struct acpi_device_id usb_xhci_acpi_match[] = {
/* XHCI-compliant USB Controller */
@@ -332,7 +363,7 @@ static int xhci_plat_resume(struct device *dev)
.remove = xhci_plat_remove,
.driver = {
.name = "xhci-hcd",
-   .pm = DEV_PM_OPS,
+   .pm = &xhci_plat_pm_ops,
.of_match_table = of_match_ptr(usb_xhci_of_match),
.acpi_match_table = ACPI_PTR(usb_xhci_acpi_match),
},
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html