linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
@ 2016-12-13  7:49 Baolin Wang
  2016-12-13  7:49 ` [PATCH v5 2/2] usb: dwc3: core: Support the dwc3 host suspend/resume Baolin Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Baolin Wang @ 2016-12-13  7:49 UTC (permalink / raw)
  To: mathias.nyman, balbi
  Cc: gregkh, broonie, linux-usb, linux-kernel, 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 <baolin.wang@linaro.org>
---
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

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

* [PATCH v5 2/2] usb: dwc3: core: Support the dwc3 host suspend/resume
  2016-12-13  7:49 [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM Baolin Wang
@ 2016-12-13  7:49 ` Baolin Wang
  2017-01-16 10:28   ` Felipe Balbi
  2017-01-25 17:31   ` Robert Foss
  2017-01-16 10:56 ` [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM Baolin Wang
  2017-01-25 17:30 ` Robert Foss
  2 siblings, 2 replies; 20+ messages in thread
From: Baolin Wang @ 2016-12-13  7:49 UTC (permalink / raw)
  To: mathias.nyman, balbi
  Cc: gregkh, broonie, linux-usb, linux-kernel, baolin.wang

For some mobile devices with strict power management, we also want to suspend
the host when the slave is detached for power saving. Thus we add the host
suspend/resume functions to support this requirement.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
---
Changes since v4:
 - Remove Kconfig and just enable host suspend/resume.
 - Simplify the dwc3_host_suspend/resume() function.

Changes since v3:
 - No updates.

Changes since v2:
 - Remove pm_children_suspended() and other unused macros.

Changes since v1:
 - Add pm_runtime.h head file to avoid kbuild error.
---
 drivers/usb/dwc3/core.c |   26 +++++++++++++++++++++++++-
 drivers/usb/dwc3/core.h |    7 +++++++
 drivers/usb/dwc3/host.c |   21 +++++++++++++++++++++
 3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 9a4a5e4..7ad4bc3 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -1091,6 +1091,7 @@ static int dwc3_probe(struct platform_device *pdev)
 	pm_runtime_use_autosuspend(dev);
 	pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY);
 	pm_runtime_enable(dev);
+	pm_suspend_ignore_children(dev, true);
 	ret = pm_runtime_get_sync(dev);
 	if (ret < 0)
 		goto err1;
@@ -1215,15 +1216,27 @@ static int dwc3_remove(struct platform_device *pdev)
 static int dwc3_suspend_common(struct dwc3 *dwc)
 {
 	unsigned long	flags;
+	int		ret;
 
 	switch (dwc->dr_mode) {
 	case USB_DR_MODE_PERIPHERAL:
+		spin_lock_irqsave(&dwc->lock, flags);
+		dwc3_gadget_suspend(dwc);
+		spin_unlock_irqrestore(&dwc->lock, flags);
+		break;
 	case USB_DR_MODE_OTG:
+		ret = dwc3_host_suspend(dwc);
+		if (ret)
+			return ret;
+
 		spin_lock_irqsave(&dwc->lock, flags);
 		dwc3_gadget_suspend(dwc);
 		spin_unlock_irqrestore(&dwc->lock, flags);
 		break;
 	case USB_DR_MODE_HOST:
+		ret = dwc3_host_suspend(dwc);
+		if (ret)
+			return ret;
 	default:
 		/* do nothing */
 		break;
@@ -1245,12 +1258,23 @@ static int dwc3_resume_common(struct dwc3 *dwc)
 
 	switch (dwc->dr_mode) {
 	case USB_DR_MODE_PERIPHERAL:
+		spin_lock_irqsave(&dwc->lock, flags);
+		dwc3_gadget_resume(dwc);
+		spin_unlock_irqrestore(&dwc->lock, flags);
+		break;
 	case USB_DR_MODE_OTG:
+		ret = dwc3_host_resume(dwc);
+		if (ret)
+			return ret;
+
 		spin_lock_irqsave(&dwc->lock, flags);
 		dwc3_gadget_resume(dwc);
 		spin_unlock_irqrestore(&dwc->lock, flags);
-		/* FALLTHROUGH */
+		break;
 	case USB_DR_MODE_HOST:
+		ret = dwc3_host_resume(dwc);
+		if (ret)
+			return ret;
 	default:
 		/* do nothing */
 		break;
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index b585a30..1099168 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1158,11 +1158,18 @@ static inline bool dwc3_is_usb31(struct dwc3 *dwc)
 #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
 int dwc3_host_init(struct dwc3 *dwc);
 void dwc3_host_exit(struct dwc3 *dwc);
+int dwc3_host_suspend(struct dwc3 *dwc);
+int dwc3_host_resume(struct dwc3 *dwc);
 #else
 static inline int dwc3_host_init(struct dwc3 *dwc)
 { return 0; }
 static inline void dwc3_host_exit(struct dwc3 *dwc)
 { }
+
+static inline int dwc3_host_suspend(struct dwc3 *dwc)
+{ return 0; }
+static inline int dwc3_host_resume(struct dwc3 *dwc)
+{ return 0; }
 #endif
 
 #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index ed82464..7959ef0 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -16,6 +16,7 @@
  */
 
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 
 #include "core.h"
 
@@ -130,3 +131,23 @@ void dwc3_host_exit(struct dwc3 *dwc)
 			  dev_name(&dwc->xhci->dev));
 	platform_device_unregister(dwc->xhci);
 }
+
+int dwc3_host_suspend(struct dwc3 *dwc)
+{
+	struct device *xhci = &dwc->xhci->dev;
+
+	/*
+	 * Note: if we get the -EBUSY, which means the xHCI children devices are
+	 * not in suspend state yet, the glue layer need to wait for a while and
+	 * try to suspend xHCI device again.
+	 */
+	return pm_runtime_put_sync(xhci);
+}
+
+int dwc3_host_resume(struct dwc3 *dwc)
+{
+	struct device *xhci = &dwc->xhci->dev;
+
+	/* Resume the xHCI device synchronously. */
+	return pm_runtime_get_sync(xhci);
+}
-- 
1.7.9.5

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

* Re: [PATCH v5 2/2] usb: dwc3: core: Support the dwc3 host suspend/resume
  2016-12-13  7:49 ` [PATCH v5 2/2] usb: dwc3: core: Support the dwc3 host suspend/resume Baolin Wang
@ 2017-01-16 10:28   ` Felipe Balbi
  2017-01-16 10:53     ` Baolin Wang
  2017-01-25 17:31   ` Robert Foss
  1 sibling, 1 reply; 20+ messages in thread
From: Felipe Balbi @ 2017-01-16 10:28 UTC (permalink / raw)
  To: Baolin Wang, mathias.nyman
  Cc: gregkh, broonie, linux-usb, linux-kernel, baolin.wang

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


Hi,

Baolin Wang <baolin.wang@linaro.org> writes:
> For some mobile devices with strict power management, we also want to suspend
> the host when the slave is detached for power saving. Thus we add the host
> suspend/resume functions to support this requirement.
>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> ---
> Changes since v4:
>  - Remove Kconfig and just enable host suspend/resume.
>  - Simplify the dwc3_host_suspend/resume() function.
>
> Changes since v3:
>  - No updates.
>
> Changes since v2:
>  - Remove pm_children_suspended() and other unused macros.
>
> Changes since v1:
>  - Add pm_runtime.h head file to avoid kbuild error.
> ---
>  drivers/usb/dwc3/core.c |   26 +++++++++++++++++++++++++-
>  drivers/usb/dwc3/core.h |    7 +++++++
>  drivers/usb/dwc3/host.c |   21 +++++++++++++++++++++
>  3 files changed, 53 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 9a4a5e4..7ad4bc3 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1091,6 +1091,7 @@ static int dwc3_probe(struct platform_device *pdev)
>  	pm_runtime_use_autosuspend(dev);
>  	pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY);
>  	pm_runtime_enable(dev);
> +	pm_suspend_ignore_children(dev, true);
>  	ret = pm_runtime_get_sync(dev);
>  	if (ret < 0)
>  		goto err1;
> @@ -1215,15 +1216,27 @@ static int dwc3_remove(struct platform_device *pdev)
>  static int dwc3_suspend_common(struct dwc3 *dwc)
>  {
>  	unsigned long	flags;
> +	int		ret;
>  
>  	switch (dwc->dr_mode) {
>  	case USB_DR_MODE_PERIPHERAL:
> +		spin_lock_irqsave(&dwc->lock, flags);
> +		dwc3_gadget_suspend(dwc);
> +		spin_unlock_irqrestore(&dwc->lock, flags);
> +		break;
>  	case USB_DR_MODE_OTG:
> +		ret = dwc3_host_suspend(dwc);
> +		if (ret)
> +			return ret;
> +
>  		spin_lock_irqsave(&dwc->lock, flags);
>  		dwc3_gadget_suspend(dwc);
>  		spin_unlock_irqrestore(&dwc->lock, flags);
>  		break;
>  	case USB_DR_MODE_HOST:
> +		ret = dwc3_host_suspend(dwc);
> +		if (ret)
> +			return ret;
>  	default:
>  		/* do nothing */
>  		break;
> @@ -1245,12 +1258,23 @@ static int dwc3_resume_common(struct dwc3 *dwc)
>  
>  	switch (dwc->dr_mode) {
>  	case USB_DR_MODE_PERIPHERAL:
> +		spin_lock_irqsave(&dwc->lock, flags);
> +		dwc3_gadget_resume(dwc);
> +		spin_unlock_irqrestore(&dwc->lock, flags);
> +		break;
>  	case USB_DR_MODE_OTG:
> +		ret = dwc3_host_resume(dwc);
> +		if (ret)
> +			return ret;
> +
>  		spin_lock_irqsave(&dwc->lock, flags);
>  		dwc3_gadget_resume(dwc);
>  		spin_unlock_irqrestore(&dwc->lock, flags);
> -		/* FALLTHROUGH */
> +		break;
>  	case USB_DR_MODE_HOST:
> +		ret = dwc3_host_resume(dwc);
> +		if (ret)
> +			return ret;
>  	default:
>  		/* do nothing */
>  		break;
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index b585a30..1099168 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1158,11 +1158,18 @@ static inline bool dwc3_is_usb31(struct dwc3 *dwc)
>  #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
>  int dwc3_host_init(struct dwc3 *dwc);
>  void dwc3_host_exit(struct dwc3 *dwc);
> +int dwc3_host_suspend(struct dwc3 *dwc);
> +int dwc3_host_resume(struct dwc3 *dwc);
>  #else
>  static inline int dwc3_host_init(struct dwc3 *dwc)
>  { return 0; }
>  static inline void dwc3_host_exit(struct dwc3 *dwc)
>  { }
> +
> +static inline int dwc3_host_suspend(struct dwc3 *dwc)
> +{ return 0; }
> +static inline int dwc3_host_resume(struct dwc3 *dwc)
> +{ return 0; }
>  #endif
>  
>  #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
> diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
> index ed82464..7959ef0 100644
> --- a/drivers/usb/dwc3/host.c
> +++ b/drivers/usb/dwc3/host.c
> @@ -16,6 +16,7 @@
>   */
>  
>  #include <linux/platform_device.h>
> +#include <linux/pm_runtime.h>
>  
>  #include "core.h"
>  
> @@ -130,3 +131,23 @@ void dwc3_host_exit(struct dwc3 *dwc)
>  			  dev_name(&dwc->xhci->dev));
>  	platform_device_unregister(dwc->xhci);
>  }
> +
> +int dwc3_host_suspend(struct dwc3 *dwc)
> +{
> +	struct device *xhci = &dwc->xhci->dev;
> +
> +	/*
> +	 * Note: if we get the -EBUSY, which means the xHCI children devices are
> +	 * not in suspend state yet, the glue layer need to wait for a while and
> +	 * try to suspend xHCI device again.
> +	 */
> +	return pm_runtime_put_sync(xhci);
> +}
> +
> +int dwc3_host_resume(struct dwc3 *dwc)
> +{
> +	struct device *xhci = &dwc->xhci->dev;
> +
> +	/* Resume the xHCI device synchronously. */
> +	return pm_runtime_get_sync(xhci);
> +}
> -- 
> 1.7.9.5

I can't take this without Mathias taking xhci side of things.

-- 
balbi

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

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

* Re: [PATCH v5 2/2] usb: dwc3: core: Support the dwc3 host suspend/resume
  2017-01-16 10:28   ` Felipe Balbi
@ 2017-01-16 10:53     ` Baolin Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Baolin Wang @ 2017-01-16 10:53 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Mathias Nyman, Greg KH, Mark Brown, USB, LKML

Hi,

On 16 January 2017 at 18:28, Felipe Balbi <balbi@kernel.org> wrote:
>
> Hi,
>
> Baolin Wang <baolin.wang@linaro.org> writes:
>> For some mobile devices with strict power management, we also want to suspend
>> the host when the slave is detached for power saving. Thus we add the host
>> suspend/resume functions to support this requirement.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
>> ---
>> Changes since v4:
>>  - Remove Kconfig and just enable host suspend/resume.
>>  - Simplify the dwc3_host_suspend/resume() function.
>>
>> Changes since v3:
>>  - No updates.
>>
>> Changes since v2:
>>  - Remove pm_children_suspended() and other unused macros.
>>
>> Changes since v1:
>>  - Add pm_runtime.h head file to avoid kbuild error.
>> ---
>>  drivers/usb/dwc3/core.c |   26 +++++++++++++++++++++++++-
>>  drivers/usb/dwc3/core.h |    7 +++++++
>>  drivers/usb/dwc3/host.c |   21 +++++++++++++++++++++
>>  3 files changed, 53 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>> index 9a4a5e4..7ad4bc3 100644
>> --- a/drivers/usb/dwc3/core.c
>> +++ b/drivers/usb/dwc3/core.c
>> @@ -1091,6 +1091,7 @@ static int dwc3_probe(struct platform_device *pdev)
>>       pm_runtime_use_autosuspend(dev);
>>       pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY);
>>       pm_runtime_enable(dev);
>> +     pm_suspend_ignore_children(dev, true);
>>       ret = pm_runtime_get_sync(dev);
>>       if (ret < 0)
>>               goto err1;
>> @@ -1215,15 +1216,27 @@ static int dwc3_remove(struct platform_device *pdev)
>>  static int dwc3_suspend_common(struct dwc3 *dwc)
>>  {
>>       unsigned long   flags;
>> +     int             ret;
>>
>>       switch (dwc->dr_mode) {
>>       case USB_DR_MODE_PERIPHERAL:
>> +             spin_lock_irqsave(&dwc->lock, flags);
>> +             dwc3_gadget_suspend(dwc);
>> +             spin_unlock_irqrestore(&dwc->lock, flags);
>> +             break;
>>       case USB_DR_MODE_OTG:
>> +             ret = dwc3_host_suspend(dwc);
>> +             if (ret)
>> +                     return ret;
>> +
>>               spin_lock_irqsave(&dwc->lock, flags);
>>               dwc3_gadget_suspend(dwc);
>>               spin_unlock_irqrestore(&dwc->lock, flags);
>>               break;
>>       case USB_DR_MODE_HOST:
>> +             ret = dwc3_host_suspend(dwc);
>> +             if (ret)
>> +                     return ret;
>>       default:
>>               /* do nothing */
>>               break;
>> @@ -1245,12 +1258,23 @@ static int dwc3_resume_common(struct dwc3 *dwc)
>>
>>       switch (dwc->dr_mode) {
>>       case USB_DR_MODE_PERIPHERAL:
>> +             spin_lock_irqsave(&dwc->lock, flags);
>> +             dwc3_gadget_resume(dwc);
>> +             spin_unlock_irqrestore(&dwc->lock, flags);
>> +             break;
>>       case USB_DR_MODE_OTG:
>> +             ret = dwc3_host_resume(dwc);
>> +             if (ret)
>> +                     return ret;
>> +
>>               spin_lock_irqsave(&dwc->lock, flags);
>>               dwc3_gadget_resume(dwc);
>>               spin_unlock_irqrestore(&dwc->lock, flags);
>> -             /* FALLTHROUGH */
>> +             break;
>>       case USB_DR_MODE_HOST:
>> +             ret = dwc3_host_resume(dwc);
>> +             if (ret)
>> +                     return ret;
>>       default:
>>               /* do nothing */
>>               break;
>> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
>> index b585a30..1099168 100644
>> --- a/drivers/usb/dwc3/core.h
>> +++ b/drivers/usb/dwc3/core.h
>> @@ -1158,11 +1158,18 @@ static inline bool dwc3_is_usb31(struct dwc3 *dwc)
>>  #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
>>  int dwc3_host_init(struct dwc3 *dwc);
>>  void dwc3_host_exit(struct dwc3 *dwc);
>> +int dwc3_host_suspend(struct dwc3 *dwc);
>> +int dwc3_host_resume(struct dwc3 *dwc);
>>  #else
>>  static inline int dwc3_host_init(struct dwc3 *dwc)
>>  { return 0; }
>>  static inline void dwc3_host_exit(struct dwc3 *dwc)
>>  { }
>> +
>> +static inline int dwc3_host_suspend(struct dwc3 *dwc)
>> +{ return 0; }
>> +static inline int dwc3_host_resume(struct dwc3 *dwc)
>> +{ return 0; }
>>  #endif
>>
>>  #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
>> diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
>> index ed82464..7959ef0 100644
>> --- a/drivers/usb/dwc3/host.c
>> +++ b/drivers/usb/dwc3/host.c
>> @@ -16,6 +16,7 @@
>>   */
>>
>>  #include <linux/platform_device.h>
>> +#include <linux/pm_runtime.h>
>>
>>  #include "core.h"
>>
>> @@ -130,3 +131,23 @@ void dwc3_host_exit(struct dwc3 *dwc)
>>                         dev_name(&dwc->xhci->dev));
>>       platform_device_unregister(dwc->xhci);
>>  }
>> +
>> +int dwc3_host_suspend(struct dwc3 *dwc)
>> +{
>> +     struct device *xhci = &dwc->xhci->dev;
>> +
>> +     /*
>> +      * Note: if we get the -EBUSY, which means the xHCI children devices are
>> +      * not in suspend state yet, the glue layer need to wait for a while and
>> +      * try to suspend xHCI device again.
>> +      */
>> +     return pm_runtime_put_sync(xhci);
>> +}
>> +
>> +int dwc3_host_resume(struct dwc3 *dwc)
>> +{
>> +     struct device *xhci = &dwc->xhci->dev;
>> +
>> +     /* Resume the xHCI device synchronously. */
>> +     return pm_runtime_get_sync(xhci);
>> +}
>> --
>> 1.7.9.5
>
> I can't take this without Mathias taking xhci side of things.

Okay, I will wait for Mathias' comments. Thanks.

-- 
Baolin.wang
Best Regards

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2016-12-13  7:49 [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM Baolin Wang
  2016-12-13  7:49 ` [PATCH v5 2/2] usb: dwc3: core: Support the dwc3 host suspend/resume Baolin Wang
@ 2017-01-16 10:56 ` Baolin Wang
  2017-01-31 13:14   ` Mathias Nyman
  2017-01-25 17:30 ` Robert Foss
  2 siblings, 1 reply; 20+ messages in thread
From: Baolin Wang @ 2017-01-16 10:56 UTC (permalink / raw)
  To: Mathias Nyman, Felipe Balbi; +Cc: Greg KH, Mark Brown, USB, LKML, Baolin Wang

Hi Mathias,

On 13 December 2016 at 15:49, Baolin Wang <baolin.wang@linaro.org> 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 <baolin.wang@linaro.org>
> ---
> 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

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2016-12-13  7:49 [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM Baolin Wang
  2016-12-13  7:49 ` [PATCH v5 2/2] usb: dwc3: core: Support the dwc3 host suspend/resume Baolin Wang
  2017-01-16 10:56 ` [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM Baolin Wang
@ 2017-01-25 17:30 ` Robert Foss
  2017-02-06  5:27   ` Baolin Wang
  2 siblings, 1 reply; 20+ messages in thread
From: Robert Foss @ 2017-01-25 17:30 UTC (permalink / raw)
  To: Baolin Wang, mathias.nyman, balbi
  Cc: gregkh, broonie, linux-usb, linux-kernel

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 <baolin.wang@linaro.org>
> ---
> 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),
>  	},
>

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

* Re: [PATCH v5 2/2] usb: dwc3: core: Support the dwc3 host suspend/resume
  2016-12-13  7:49 ` [PATCH v5 2/2] usb: dwc3: core: Support the dwc3 host suspend/resume Baolin Wang
  2017-01-16 10:28   ` Felipe Balbi
@ 2017-01-25 17:31   ` Robert Foss
  1 sibling, 0 replies; 20+ messages in thread
From: Robert Foss @ 2017-01-25 17:31 UTC (permalink / raw)
  To: Baolin Wang, mathias.nyman, balbi
  Cc: gregkh, broonie, linux-usb, linux-kernel

Looks good to me.

Feel free to add my r-b.


Rob.

On 2016-12-13 02:49 AM, Baolin Wang wrote:
> For some mobile devices with strict power management, we also want to suspend
> the host when the slave is detached for power saving. Thus we add the host
> suspend/resume functions to support this requirement.
>
> Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
> ---
> Changes since v4:
>  - Remove Kconfig and just enable host suspend/resume.
>  - Simplify the dwc3_host_suspend/resume() function.
>
> Changes since v3:
>  - No updates.
>
> Changes since v2:
>  - Remove pm_children_suspended() and other unused macros.
>
> Changes since v1:
>  - Add pm_runtime.h head file to avoid kbuild error.
> ---
>  drivers/usb/dwc3/core.c |   26 +++++++++++++++++++++++++-
>  drivers/usb/dwc3/core.h |    7 +++++++
>  drivers/usb/dwc3/host.c |   21 +++++++++++++++++++++
>  3 files changed, 53 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 9a4a5e4..7ad4bc3 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1091,6 +1091,7 @@ static int dwc3_probe(struct platform_device *pdev)
>  	pm_runtime_use_autosuspend(dev);
>  	pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY);
>  	pm_runtime_enable(dev);
> +	pm_suspend_ignore_children(dev, true);
>  	ret = pm_runtime_get_sync(dev);
>  	if (ret < 0)
>  		goto err1;
> @@ -1215,15 +1216,27 @@ static int dwc3_remove(struct platform_device *pdev)
>  static int dwc3_suspend_common(struct dwc3 *dwc)
>  {
>  	unsigned long	flags;
> +	int		ret;
>
>  	switch (dwc->dr_mode) {
>  	case USB_DR_MODE_PERIPHERAL:
> +		spin_lock_irqsave(&dwc->lock, flags);
> +		dwc3_gadget_suspend(dwc);
> +		spin_unlock_irqrestore(&dwc->lock, flags);
> +		break;
>  	case USB_DR_MODE_OTG:
> +		ret = dwc3_host_suspend(dwc);
> +		if (ret)
> +			return ret;
> +
>  		spin_lock_irqsave(&dwc->lock, flags);
>  		dwc3_gadget_suspend(dwc);
>  		spin_unlock_irqrestore(&dwc->lock, flags);
>  		break;
>  	case USB_DR_MODE_HOST:
> +		ret = dwc3_host_suspend(dwc);
> +		if (ret)
> +			return ret;
>  	default:
>  		/* do nothing */
>  		break;
> @@ -1245,12 +1258,23 @@ static int dwc3_resume_common(struct dwc3 *dwc)
>
>  	switch (dwc->dr_mode) {
>  	case USB_DR_MODE_PERIPHERAL:
> +		spin_lock_irqsave(&dwc->lock, flags);
> +		dwc3_gadget_resume(dwc);
> +		spin_unlock_irqrestore(&dwc->lock, flags);
> +		break;
>  	case USB_DR_MODE_OTG:
> +		ret = dwc3_host_resume(dwc);
> +		if (ret)
> +			return ret;
> +
>  		spin_lock_irqsave(&dwc->lock, flags);
>  		dwc3_gadget_resume(dwc);
>  		spin_unlock_irqrestore(&dwc->lock, flags);
> -		/* FALLTHROUGH */
> +		break;
>  	case USB_DR_MODE_HOST:
> +		ret = dwc3_host_resume(dwc);
> +		if (ret)
> +			return ret;
>  	default:
>  		/* do nothing */
>  		break;
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index b585a30..1099168 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1158,11 +1158,18 @@ static inline bool dwc3_is_usb31(struct dwc3 *dwc)
>  #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
>  int dwc3_host_init(struct dwc3 *dwc);
>  void dwc3_host_exit(struct dwc3 *dwc);
> +int dwc3_host_suspend(struct dwc3 *dwc);
> +int dwc3_host_resume(struct dwc3 *dwc);
>  #else
>  static inline int dwc3_host_init(struct dwc3 *dwc)
>  { return 0; }
>  static inline void dwc3_host_exit(struct dwc3 *dwc)
>  { }
> +
> +static inline int dwc3_host_suspend(struct dwc3 *dwc)
> +{ return 0; }
> +static inline int dwc3_host_resume(struct dwc3 *dwc)
> +{ return 0; }
>  #endif
>
>  #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
> diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
> index ed82464..7959ef0 100644
> --- a/drivers/usb/dwc3/host.c
> +++ b/drivers/usb/dwc3/host.c
> @@ -16,6 +16,7 @@
>   */
>
>  #include <linux/platform_device.h>
> +#include <linux/pm_runtime.h>
>
>  #include "core.h"
>
> @@ -130,3 +131,23 @@ void dwc3_host_exit(struct dwc3 *dwc)
>  			  dev_name(&dwc->xhci->dev));
>  	platform_device_unregister(dwc->xhci);
>  }
> +
> +int dwc3_host_suspend(struct dwc3 *dwc)
> +{
> +	struct device *xhci = &dwc->xhci->dev;
> +
> +	/*
> +	 * Note: if we get the -EBUSY, which means the xHCI children devices are
> +	 * not in suspend state yet, the glue layer need to wait for a while and
> +	 * try to suspend xHCI device again.
> +	 */
> +	return pm_runtime_put_sync(xhci);
> +}
> +
> +int dwc3_host_resume(struct dwc3 *dwc)
> +{
> +	struct device *xhci = &dwc->xhci->dev;
> +
> +	/* Resume the xHCI device synchronously. */
> +	return pm_runtime_get_sync(xhci);
> +}
>

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-01-16 10:56 ` [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM Baolin Wang
@ 2017-01-31 13:14   ` Mathias Nyman
  2017-02-06  5:26     ` Baolin Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Mathias Nyman @ 2017-01-31 13:14 UTC (permalink / raw)
  To: Baolin Wang, Mathias Nyman, Felipe Balbi
  Cc: Greg KH, Mark Brown, USB, LKML, Alan Stern

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 <baolin.wang@linaro.org> 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 <baolin.wang@linaro.org>
>> ---
>> 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

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-01-31 13:14   ` Mathias Nyman
@ 2017-02-06  5:26     ` Baolin Wang
  2017-02-20  2:47       ` Baolin Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Baolin Wang @ 2017-02-06  5:26 UTC (permalink / raw)
  To: Mathias Nyman
  Cc: Mathias Nyman, Felipe Balbi, Greg KH, Mark Brown, USB, LKML, Alan Stern

Hi Mathias,

On 31 January 2017 at 21:14, Mathias Nyman
<mathias.nyman@linux.intel.com> 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 <baolin.wang@linaro.org> 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 <baolin.wang@linaro.org>
>>> ---
>>> 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

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-01-25 17:30 ` Robert Foss
@ 2017-02-06  5:27   ` Baolin Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Baolin Wang @ 2017-02-06  5:27 UTC (permalink / raw)
  To: Robert Foss; +Cc: Mathias Nyman, Felipe Balbi, Greg KH, Mark Brown, USB, LKML

Hi Robert,

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

OK, thanks for your reviewing.

-- 
Baolin.wang
Best Regards

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-02-06  5:26     ` Baolin Wang
@ 2017-02-20  2:47       ` Baolin Wang
  2017-02-20 15:10         ` Mathias Nyman
  0 siblings, 1 reply; 20+ messages in thread
From: Baolin Wang @ 2017-02-20  2:47 UTC (permalink / raw)
  To: Mathias Nyman
  Cc: Mathias Nyman, Felipe Balbi, Greg KH, Mark Brown, USB, LKML, Alan Stern

Hi Mathias,

On 6 February 2017 at 13:26, Baolin Wang <baolin.wang@linaro.org> wrote:
> Hi Mathias,
>
> On 31 January 2017 at 21:14, Mathias Nyman
> <mathias.nyman@linux.intel.com> 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 <baolin.wang@linaro.org> 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 <baolin.wang@linaro.org>
>>>> ---
>>>> 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

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-02-20  2:47       ` Baolin Wang
@ 2017-02-20 15:10         ` Mathias Nyman
  2017-02-21  2:09           ` Baolin Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Mathias Nyman @ 2017-02-20 15:10 UTC (permalink / raw)
  To: Baolin Wang
  Cc: Mathias Nyman, Felipe Balbi, Greg KH, Mark Brown, USB, LKML, Alan Stern

On 20.02.2017 04:47, Baolin Wang wrote:
> Hi Mathias,
>
> On 6 February 2017 at 13:26, Baolin Wang <baolin.wang@linaro.org> wrote:
>> Hi Mathias,
>>
>> On 31 January 2017 at 21:14, Mathias Nyman
>> <mathias.nyman@linux.intel.com> 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 <baolin.wang@linaro.org> 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 <baolin.wang@linaro.org>
>>>>> ---
>>>>> 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 (without children), but before second one, make sure to increase the usage count before creating and adding
both hcd's, and only decrease it after both are  ready.

This way it will only runtime suspend after both buses are created.

xhci_plat_probe(pdev)
   /* prevent platform device runtime suspend between adding main and shared_hcd */	
   pm_runtime_get_noresume(&pdev->dev)
   usb_create_hcd()
   usb_create_shared_hcd()
   usb_add_hcd(hcd)
   usb_add_hcd(shared_hcd)		
   /* both hcs's added, allow platform device to runtime suspend */
   pm_runtime_put_noidle(&dev->dev);

-Mathias



     

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-02-20 15:10         ` Mathias Nyman
@ 2017-02-21  2:09           ` Baolin Wang
  2017-03-21  7:55             ` Baolin Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Baolin Wang @ 2017-02-21  2:09 UTC (permalink / raw)
  To: Mathias Nyman
  Cc: Mathias Nyman, Felipe Balbi, Greg KH, Mark Brown, USB, LKML, Alan Stern

On 20 February 2017 at 23:10, Mathias Nyman
<mathias.nyman@linux.intel.com> wrote:
> On 20.02.2017 04:47, Baolin Wang wrote:
>>
>> Hi Mathias,
>>
>> On 6 February 2017 at 13:26, Baolin Wang <baolin.wang@linaro.org> wrote:
>>>
>>> Hi Mathias,
>>>
>>> On 31 January 2017 at 21:14, Mathias Nyman
>>> <mathias.nyman@linux.intel.com> 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 <baolin.wang@linaro.org>
>>>>> 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 <baolin.wang@linaro.org>
>>>>>> ---
>>>>>> 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 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 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.

Yes, that is the benefits.

>
> 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 (without children), but before second one, make sure to
> increase the usage count before creating and adding
> both hcd's, and only decrease it after both are  ready.
>
> This way it will only runtime suspend after both buses are created.
>
> xhci_plat_probe(pdev)
>   /* prevent platform device runtime suspend between adding main and
> shared_hcd */
>   pm_runtime_get_noresume(&pdev->dev)
>   usb_create_hcd()
>   usb_create_shared_hcd()
>   usb_add_hcd(hcd)
>   usb_add_hcd(shared_hcd)
>   /* both hcs's added, allow platform device to runtime suspend */
>   pm_runtime_put_noidle(&dev->dev);
>

Make sense.

-- 
Baolin.wang
Best Regards

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-02-21  2:09           ` Baolin Wang
@ 2017-03-21  7:55             ` Baolin Wang
  2017-03-21  8:07               ` Felipe Balbi
  0 siblings, 1 reply; 20+ messages in thread
From: Baolin Wang @ 2017-03-21  7:55 UTC (permalink / raw)
  To: Mathias Nyman
  Cc: Mathias Nyman, Felipe Balbi, Greg KH, Mark Brown, USB, LKML, Alan Stern

Hi Mathias,

On 21 February 2017 at 10:09, Baolin Wang <baolin.wang@linaro.org> 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 it, and dwc3 and xhci would keep their parent-child
>> relationship
>> intact and make sure dwc3 can't runtime suspend before xhci.
>
> Yes, that is the benefits.
>
>>
>> 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 (without children), but before second one, make sure to
>> increase the usage count before creating and adding
>> both hcd's, and only decrease it after both are  ready.
>>
>> This way it will only runtime suspend after both buses are created.
>>
>> xhci_plat_probe(pdev)
>>   /* prevent platform device runtime suspend between adding main and
>> shared_hcd */
>>   pm_runtime_get_noresume(&pdev->dev)
>>   usb_create_hcd()
>>   usb_create_shared_hcd()
>>   usb_add_hcd(hcd)
>>   usb_add_hcd(shared_hcd)
>>   /* both hcs's added, allow platform device to runtime suspend */
>>   pm_runtime_put_noidle(&dev->dev);
>>
>
> Make sense.
>
> --
> Baolin.wang
> Best Regards



-- 
Baolin.wang
Best Regards

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-03-21  7:55             ` Baolin Wang
@ 2017-03-21  8:07               ` Felipe Balbi
  2017-03-22  5:07                 ` Baolin Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Felipe Balbi @ 2017-03-21  8:07 UTC (permalink / raw)
  To: Baolin Wang, Mathias Nyman
  Cc: Mathias Nyman, Greg KH, Mark Brown, USB, LKML, Alan Stern

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


Hi,

Baolin Wang <baolin.wang@linaro.org> 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

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

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-03-21  8:07               ` Felipe Balbi
@ 2017-03-22  5:07                 ` Baolin Wang
  2017-03-22  9:00                   ` Felipe Balbi
  0 siblings, 1 reply; 20+ messages in thread
From: Baolin Wang @ 2017-03-22  5:07 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Mathias Nyman, Mathias Nyman, Greg KH, Mark Brown, USB, LKML, Alan Stern

Hi,

On 21 March 2017 at 16:07, Felipe Balbi <balbi@kernel.org> wrote:
>
> Hi,
>
> Baolin Wang <baolin.wang@linaro.org> 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

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-03-22  5:07                 ` Baolin Wang
@ 2017-03-22  9:00                   ` Felipe Balbi
  2017-03-22 10:40                     ` Baolin Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Felipe Balbi @ 2017-03-22  9:00 UTC (permalink / raw)
  To: Baolin Wang
  Cc: Mathias Nyman, Mathias Nyman, Greg KH, Mark Brown, USB, LKML, Alan Stern

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


Hi,

Baolin Wang <baolin.wang@linaro.org> 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

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

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-03-22  9:00                   ` Felipe Balbi
@ 2017-03-22 10:40                     ` Baolin Wang
  2017-03-22 12:43                       ` Mathias Nyman
  0 siblings, 1 reply; 20+ messages in thread
From: Baolin Wang @ 2017-03-22 10:40 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Mathias Nyman, Mathias Nyman, Greg KH, Mark Brown, USB, LKML, Alan Stern

Hi,

On 22 March 2017 at 17:00, Felipe Balbi <balbi@kernel.org> wrote:
>
> Hi,
>
> Baolin Wang <baolin.wang@linaro.org> 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

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-03-22 10:40                     ` Baolin Wang
@ 2017-03-22 12:43                       ` Mathias Nyman
  2017-03-23  2:17                         ` Baolin Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Mathias Nyman @ 2017-03-22 12:43 UTC (permalink / raw)
  To: Baolin Wang, Felipe Balbi
  Cc: Mathias Nyman, Greg KH, Mark Brown, USB, LKML, Alan Stern

On 22.03.2017 12:40, Baolin Wang wrote:
> Hi,
>
> On 22 March 2017 at 17:00, Felipe Balbi <balbi@kernel.org> wrote:
>>
>> Hi,
>>
>> Baolin Wang <baolin.wang@linaro.org> 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

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

* Re: [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM
  2017-03-22 12:43                       ` Mathias Nyman
@ 2017-03-23  2:17                         ` Baolin Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Baolin Wang @ 2017-03-23  2:17 UTC (permalink / raw)
  To: Mathias Nyman
  Cc: Felipe Balbi, Mathias Nyman, Greg KH, Mark Brown, USB, LKML, Alan Stern

Hi,

On 22 March 2017 at 20:43, Mathias Nyman <mathias.nyman@linux.intel.com> wrote:
> On 22.03.2017 12:40, Baolin Wang wrote:
>>
>> Hi,
>>
>> On 22 March 2017 at 17:00, Felipe Balbi <balbi@kernel.org> wrote:
>>>
>>>
>>> Hi,
>>>
>>> Baolin Wang <baolin.wang@linaro.org> 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. I will create new patches. Thanks Mathias and Felipe's suggestion.

-- 
Baolin.wang
Best Regards

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

end of thread, other threads:[~2017-03-23  2:18 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-13  7:49 [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM Baolin Wang
2016-12-13  7:49 ` [PATCH v5 2/2] usb: dwc3: core: Support the dwc3 host suspend/resume Baolin Wang
2017-01-16 10:28   ` Felipe Balbi
2017-01-16 10:53     ` Baolin Wang
2017-01-25 17:31   ` Robert Foss
2017-01-16 10:56 ` [PATCH v5 1/2] usb: host: plat: Enable xhci plat runtime PM Baolin Wang
2017-01-31 13:14   ` Mathias Nyman
2017-02-06  5:26     ` Baolin Wang
2017-02-20  2:47       ` Baolin Wang
2017-02-20 15:10         ` Mathias Nyman
2017-02-21  2:09           ` Baolin Wang
2017-03-21  7:55             ` Baolin Wang
2017-03-21  8:07               ` Felipe Balbi
2017-03-22  5:07                 ` Baolin Wang
2017-03-22  9:00                   ` Felipe Balbi
2017-03-22 10:40                     ` Baolin Wang
2017-03-22 12:43                       ` Mathias Nyman
2017-03-23  2:17                         ` Baolin Wang
2017-01-25 17:30 ` Robert Foss
2017-02-06  5:27   ` Baolin Wang

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).