Skip to contentSkip to conversation

usb: dwc3: pm_runtime implementation

PATCH Superseded Felipe Balbi 5 participants 31 messages Dec 12, 2013 – Dec 18, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover usb: dwc3: pm_runtime implementation

hi all,

these patches add pm_runtime support for all glue layers.

I plan to add pm_runtime support for dwc3 after these patches are merged upstream.

Please test.

Felipe Balbi (7):
usb: dwc3: keystone: add basic PM support
usb: dwc3: omap: add basic pm_runtime support
usb: dwc3: pci: add pm_runtime support
usb: dwc3: omap: fix pm_runtime usage
usb: dwc3: omap: fix order of pm_runtime vs child removal
usb: dwc3: exynos: remove DEV_PM_OPS hackery
usb: dwc3: exynos: add pm_runtime support

 drivers/usb/dwc3/dwc3-exynos.c   | 73 +++++++++++++++++++++++-------
 drivers/usb/dwc3/dwc3-keystone.c | 97 ++++++++++++++++++++++++++++++++++++++--
 drivers/usb/dwc3/dwc3-omap.c     | 45 +++++++++++++++----
 drivers/usb/dwc3/dwc3-pci.c      | 66 ++++++++++++++++++++-------
 4 files changed, 239 insertions(+), 42 deletions(-)
Signature · 1 line
1.8.4.GIT
#1 lore raw

PATCH 1/7 usb: dwc3: keystone: add basic PM support

A bare-minimum PM implementation which will server as building block for more complex PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

---
 drivers/usb/dwc3/dwc3-keystone.c | 97 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 94 insertions(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-keystone.c +94 -3
index 1fad161..361437f 100644
@@ -21,6 +21,7 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
+#include <linux/pm_runtime.h>
 #include <linux/io.h>
 #include <linux/of_platform.h>
 
@@ -118,13 +119,23 @@ static int kdwc3_probe(struct platform_device *pdev)
 
 	kdwc->clk = devm_clk_get(kdwc->dev, "usb");
 
-	error = clk_prepare_enable(kdwc->clk);
+	error = clk_prepare(kdwc->clk);
 	if (error < 0) {
 		dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n",
 			error);
 		return error;
 	}
 
+	pm_runtime_enable(dev);
+
+	error = pm_runtime_get_sync(dev);
+	if (error < 0) {
+		dev_dbg(dev, "unable to pm_runtime_get_sync(), err %d\n",
+				error);
+		pm_runtime_put_sync(dev);
+		goto err_runtime_get;
+	}
+
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0) {
 		dev_err(&pdev->dev, "missing irq\n");
@@ -151,8 +162,13 @@ static int kdwc3_probe(struct platform_device *pdev)
 
 err_core:
 	kdwc3_disable_irqs(kdwc);
+
 err_irq:
-	clk_disable_unprepare(kdwc->clk);
+	pm_runtime_put_sync(dev);
+
+err_runtime_get:
+	pm_runtime_disable(dev);
+	clk_unprepare(kdwc->clk);
 
 	return error;
 }
@@ -172,7 +188,9 @@ static int kdwc3_remove(struct platform_device *pdev)
 
 	kdwc3_disable_irqs(kdwc);
 	device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core);
-	clk_disable_unprepare(kdwc->clk);
+	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	clk_unprepare(kdwc->clk);
 	platform_set_drvdata(pdev, NULL);
 
 	return 0;
@@ -184,6 +202,79 @@ static const struct of_device_id kdwc3_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, kdwc3_of_match);
 
+static int __kdwc3_suspend(struct dwc3_keystone *kdwc)
+{
+	clk_disable(kdwc->clk);
+
+	return 0;
+}
+
+static int __kdwc3_resume(struct dwc3_keystone *kdwc)
+{
+	return clk_enable(kdwc->clk);
+}
+
+static int kdwc3_prepare(struct device *dev)
+{
+	struct dwc3_keystone	*kdwc = dev_get_drvdata(dev);
+
+	kdwc3_disable_irqs(kdwc);
+
+	return 0;
+}
+
+static void kdwc3_complete(struct device *dev)
+{
+	struct dwc3_keystone	*kdwc = dev_get_drvdata(dev);
+
+	kdwc3_enable_irqs(kdwc);
+}
+
+static int kdwc3_suspend(struct device *dev)
+{
+	struct dwc3_keystone	*kdwc = dev_get_drvdata(dev);
+
+	return __kdwc3_suspend(kdwc);
+}
+
+static int kdwc3_resume(struct device *dev)
+{
+	struct dwc3_keystone	*kdwc = dev_get_drvdata(dev);
+	int			ret;
+
+	ret = __kdwc3_resume(kdwc);
+	if (ret)
+		return ret;
+
+	pm_runtime_disable(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+
+	return 0;
+}
+
+static int kdwc3_runtime_suspend(struct device *dev)
+{
+	struct dwc3_keystone *kdwc = dev_get_drvdata(dev);
+
+	return __kdwc3_suspend(kdwc);
+}
+
+static int kdwc3_runtime_resume(struct device *dev)
+{
+	struct dwc3_keystone *kdwc = dev_get_drvdata(dev);
+
+	return __kdwc3_resume(kdwc);
+}
+
+static const struct dev_pm_ops kdwc3_dev_pm_ops = {
+	.prepare	= kdwc3_prepare,
+	.complete	= kdwc3_complete,
+
+	SET_SYSTEM_SLEEP_PM_OPS(kdwc3_suspend, kdwc3_resume)
+	SET_RUNTIME_PM_OPS(kdwc3_runtime_suspend, kdwc3_runtime_resume, NULL)
+};
+
 static struct platform_driver kdwc3_driver = {
 	.probe		= kdwc3_probe,
 	.remove		= kdwc3_remove,
Signature · 1 line
1.8.4.GIT
#2 lore raw

PATCH 1/7 usb: dwc3: keystone: add basic PM support

Quoted 33 lines · Felipe Balbi

A bare-minimum PM implementation which will server as building block for more complex PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

---
 drivers/usb/dwc3/dwc3-keystone.c | 97 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 94 insertions(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-keystone.c +2 -1
index 1fad161..361437f 100644
@@ -21,6 +21,7 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
+#include <linux/pm_runtime.h>
 #include <linux/io.h>
 #include <linux/of_platform.h>
 
@@ -118,13 +119,23 @@ static int kdwc3_probe(struct platform_device *pdev)
 
 	kdwc->clk = devm_clk_get(kdwc->dev, "usb");
 
-	error = clk_prepare_enable(kdwc->clk);
+	error = clk_prepare(kdwc->clk);
 	if (error < 0) {
 		dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n",
 			error);

drivers/usb/dwc3/dwc3-keystone.c static int kdwc3_probe(struct platform_device *pdev) · line 135

Quoted 10 lines
drivers/usb/dwc3/dwc3-keystone.c +7 -0
 		return error;
 	}
 
+	pm_runtime_enable(dev);
+
+	error = pm_runtime_get_sync(dev);
+	if (error < 0) {
+		dev_dbg(dev, "unable to pm_runtime_get_sync(), err %d\n",
+				error);
+		pm_runtime_put_sync(dev);

I can move this pm_runtime_sync() to error path, will refresh this patch.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131212/48ff909e/attachment.sig>
#3 lore raw

PATCH v2 1/7 usb: dwc3: keystone: add basic PM support

A bare-minimum PM implementation which will server as building block for more complex PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

---

improve error path a little bit.

 drivers/usb/dwc3/dwc3-keystone.c | 94 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 91 insertions(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-keystone.c +91 -3
index 1fad161..3b3761c 100644
@@ -21,6 +21,7 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
+#include <linux/pm_runtime.h>
 #include <linux/io.h>
 #include <linux/of_platform.h>
 
@@ -118,13 +119,22 @@ static int kdwc3_probe(struct platform_device *pdev)
 
 	kdwc->clk = devm_clk_get(kdwc->dev, "usb");
 
-	error = clk_prepare_enable(kdwc->clk);
+	error = clk_prepare(kdwc->clk);
 	if (error < 0) {
 		dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n",
 			error);
 		return error;
 	}
 
+	pm_runtime_enable(dev);
+
+	error = pm_runtime_get_sync(dev);
+	if (error < 0) {
+		dev_dbg(dev, "unable to pm_runtime_get_sync(), err %d\n",
+				error);
+		goto err_irq;
+	}
+
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0) {
 		dev_err(&pdev->dev, "missing irq\n");
@@ -151,8 +161,11 @@ static int kdwc3_probe(struct platform_device *pdev)
 
 err_core:
 	kdwc3_disable_irqs(kdwc);
+
 err_irq:
-	clk_disable_unprepare(kdwc->clk);
+	pm_runtime_put_sync(dev);
+	pm_runtime_disable(dev);
+	clk_unprepare(kdwc->clk);
 
 	return error;
 }
@@ -172,7 +185,9 @@ static int kdwc3_remove(struct platform_device *pdev)
 
 	kdwc3_disable_irqs(kdwc);
 	device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core);
-	clk_disable_unprepare(kdwc->clk);
+	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+	clk_unprepare(kdwc->clk);
 	platform_set_drvdata(pdev, NULL);
 
 	return 0;
@@ -184,6 +199,79 @@ static const struct of_device_id kdwc3_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, kdwc3_of_match);
 
+static int __kdwc3_suspend(struct dwc3_keystone *kdwc)
+{
+	clk_disable(kdwc->clk);
+
+	return 0;
+}
+
+static int __kdwc3_resume(struct dwc3_keystone *kdwc)
+{
+	return clk_enable(kdwc->clk);
+}
+
+static int kdwc3_prepare(struct device *dev)
+{
+	struct dwc3_keystone	*kdwc = dev_get_drvdata(dev);
+
+	kdwc3_disable_irqs(kdwc);
+
+	return 0;
+}
+
+static void kdwc3_complete(struct device *dev)
+{
+	struct dwc3_keystone	*kdwc = dev_get_drvdata(dev);
+
+	kdwc3_enable_irqs(kdwc);
+}
+
+static int kdwc3_suspend(struct device *dev)
+{
+	struct dwc3_keystone	*kdwc = dev_get_drvdata(dev);
+
+	return __kdwc3_suspend(kdwc);
+}
+
+static int kdwc3_resume(struct device *dev)
+{
+	struct dwc3_keystone	*kdwc = dev_get_drvdata(dev);
+	int			ret;
+
+	ret = __kdwc3_resume(kdwc);
+	if (ret)
+		return ret;
+
+	pm_runtime_disable(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+
+	return 0;
+}
+
+static int kdwc3_runtime_suspend(struct device *dev)
+{
+	struct dwc3_keystone *kdwc = dev_get_drvdata(dev);
+
+	return __kdwc3_suspend(kdwc);
+}
+
+static int kdwc3_runtime_resume(struct device *dev)
+{
+	struct dwc3_keystone *kdwc = dev_get_drvdata(dev);
+
+	return __kdwc3_resume(kdwc);
+}
+
+static const struct dev_pm_ops kdwc3_dev_pm_ops = {
+	.prepare	= kdwc3_prepare,
+	.complete	= kdwc3_complete,
+
+	SET_SYSTEM_SLEEP_PM_OPS(kdwc3_suspend, kdwc3_resume)
+	SET_RUNTIME_PM_OPS(kdwc3_runtime_suspend, kdwc3_runtime_resume, NULL)
+};
+
 static struct platform_driver kdwc3_driver = {
 	.probe		= kdwc3_probe,
 	.remove		= kdwc3_remove,
Signature · 1 line
1.8.4.GIT
#4 lore raw

PATCH v2 1/7 usb: dwc3: keystone: add basic PM support

Hi,

drivers/usb/dwc3/dwc3-keystone.c static const struct of_device_id kdwc3_of_match[] = { · line 273

Quoted 7 lines · Felipe Balbi
drivers/usb/dwc3/dwc3-keystone.c +7 -0
+static const struct dev_pm_ops kdwc3_dev_pm_ops = {
+	.prepare	= kdwc3_prepare,
+	.complete	= kdwc3_complete,
+
+	SET_SYSTEM_SLEEP_PM_OPS(kdwc3_suspend, kdwc3_resume)
+	SET_RUNTIME_PM_OPS(kdwc3_runtime_suspend, kdwc3_runtime_resume, NULL)
+};

did I really forget to use this ? Wonder why compiler didn't annoy me :-(

there I go to v3. Will fix in my tree only to avoid the extra traffic in the mailing list.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131212/30f9cdec/attachment.sig>
#5 lore raw

PATCH v2 1/7 usb: dwc3: keystone: add basic PM support

In reply to Felipe Balbi
Quoted 2 lines · Felipe Balbi

A bare-minimum PM implementation which will
server as building block for more complex

s/server/serve ;-)

Quoted 10 lines

PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

---

improve error path a little bit.

We will test this out. Thanks for the
patch Felipe.

Regards,
Santosh

#6 lore raw

PATCH v2 1/7 usb: dwc3: keystone: add basic PM support

Quoted 4 lines · Santosh Shilimkar
Quoted 2 lines · Felipe Balbi

A bare-minimum PM implementation which will
server as building block for more complex

s/server/serve ;-)

hah! :-) will fix in my branch.

Quoted 5 lines
Quoted 5 lines

PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

Quoted 7 lines
Quoted 5 lines

---

improve error path a little bit.

We will test this out. Thanks for the
patch Felipe.

thanks.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131212/db14b78b/attachment.sig>
#7 lore raw

PATCH v2 1/7 usb: dwc3: keystone: add basic PM support

Quoted 21 lines · Felipe Balbi
Quoted 4 lines · Santosh Shilimkar
Quoted 2 lines · Felipe Balbi

A bare-minimum PM implementation which will
server as building block for more complex

s/server/serve ;-)

hah! :-) will fix in my branch.

Quoted 12 lines
Quoted 10 lines

PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

---

improve error path a little bit.

We will test this out. Thanks for the
patch Felipe.

I see Wingman already tested the patch.
Feel free add, my ack if you need one...

#8 lore raw

PATCH v2 1/7 usb: dwc3: keystone: add basic PM support

In reply to Santosh Shilimkar

Hello

Quoted 18 lines

-----Original Message-----
From: Shilimkar, Santosh
Sent: Thursday, December 12, 2013 7:29 PM
To: Balbi, Felipe
Cc: Linux USB Mailing List; kgene.kim at samsung.com; Linux ARM Kernel Mailing List; linux-samsung-soc at vger.kernel.org; Linux OMAP Mailing List; Kwok, WingMan
Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support

Quoted 2 lines · Felipe Balbi

A bare-minimum PM implementation which will server as building block for more complex

s/server/serve ;-)

Quoted 5 lines

PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

Quoted 8 lines
Quoted 5 lines

---

improve error path a little bit.

We will test this out. Thanks for the
patch Felipe.

I have tested the patch and the keystone usb driver continues to function, though I can't test suspend at this time as the rest of the system does not that functionality yet.

Thanks
WingMan

#9 lore raw

PATCH v2 1/7 usb: dwc3: keystone: add basic PM support

Quoted 25 lines · WingMan

Hello

Quoted 23 lines

-----Original Message-----
From: Shilimkar, Santosh
Sent: Thursday, December 12, 2013 7:29 PM
To: Balbi, Felipe
Cc: Linux USB Mailing List; kgene.kim at samsung.com; Linux ARM Kernel Mailing List; linux-samsung-soc at vger.kernel.org; Linux OMAP Mailing List; Kwok, WingMan
Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support

Quoted 2 lines · Felipe Balbi

A bare-minimum PM implementation which will server as building block for more complex

s/server/serve ;-)

Quoted 10 lines

PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

---

improve error path a little bit.

Quoted 7 lines
Quoted 3 lines

We will test this out. Thanks for the
patch Felipe.

I have tested the patch and the keystone usb driver continues to function, though I can't test suspend at this time as the rest of the system does not that functionality yet.

Thanks, should I add your Tested-by ?

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131213/921df1ff/attachment.sig>
#10 lore raw

PATCH v2 1/7 usb: dwc3: keystone: add basic PM support

Quoted 37 lines

-----Original Message-----
From: Balbi, Felipe
Sent: Friday, December 13, 2013 2:55 PM
To: Kwok, WingMan
Cc: Shilimkar, Santosh; Balbi, Felipe; Linux USB Mailing List; kgene.kim at samsung.com; Linux ARM Kernel Mailing List; linux-samsung- soc at vger.kernel.org; Linux OMAP Mailing List
Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support

Quoted 26 lines · WingMan

Hello

Quoted 24 lines

-----Original Message-----
From: Shilimkar, Santosh
Sent: Thursday, December 12, 2013 7:29 PM
To: Balbi, Felipe
Cc: Linux USB Mailing List; kgene.kim at samsung.com; Linux ARM Kernel Mailing List; linux-samsung-soc at vger.kernel.org; Linux OMAP Mailing List; Kwok, WingMan
Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support

Quoted 2 lines · Felipe Balbi

A bare-minimum PM implementation which will server as building block for more complex

s/server/serve ;-)

Quoted 10 lines

PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

---

improve error path a little bit.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

We will test this out. Thanks for the patch Felipe.

I have tested the patch and the keystone usb driver continues to function, though I can't test suspend at this time as the rest of the system does not that functionality yet.

Thanks, should I add your Tested-by ?

Yes please.

Thanks
WingMan

#11 lore raw

PATCH v2 1/7 usb: dwc3: keystone: add basic PM support

Quoted 40 lines · WingMan
Quoted 40 lines

-----Original Message-----
From: Balbi, Felipe
Sent: Friday, December 13, 2013 2:55 PM
To: Kwok, WingMan
Cc: Shilimkar, Santosh; Balbi, Felipe; Linux USB Mailing List; kgene.kim at samsung.com; Linux ARM Kernel Mailing List; linux-samsung- soc at vger.kernel.org; Linux OMAP Mailing List
Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support

Quoted 29 lines · WingMan

Hello

Quoted 26 lines

-----Original Message-----
From: Shilimkar, Santosh
Sent: Thursday, December 12, 2013 7:29 PM
To: Balbi, Felipe
Cc: Linux USB Mailing List; kgene.kim at samsung.com; Linux ARM Kernel Mailing List; linux-samsung-soc at vger.kernel.org; Linux OMAP Mailing List; Kwok, WingMan
Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support

Quoted 2 lines · Felipe Balbi

A bare-minimum PM implementation which will server as building block for more complex

s/server/serve ;-)

Quoted 10 lines

PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

---

improve error path a little bit.

We will test this out. Thanks for the patch Felipe.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I have tested the patch and the keystone usb driver continues to function, though I can't test suspend at this time as the rest of the system does not that functionality yet.

Thanks, should I add your Tested-by ?

Yes please.

you need to reply with Tested-by: Your Name <[email protected]> just to make it all official. Sorry

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131213/6bed2d1d/attachment-0001.sig>
#12 lore raw

PATCH v2 1/7 usb: dwc3: keystone: add basic PM support

Quoted 58 lines

-----Original Message-----
From: Balbi, Felipe
Sent: Friday, December 13, 2013 3:23 PM
To: Kwok, WingMan
Cc: Balbi, Felipe; Shilimkar, Santosh; Linux USB Mailing List; kgene.kim at samsung.com; Linux ARM Kernel Mailing List; linux-samsung- soc at vger.kernel.org; Linux OMAP Mailing List
Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support

Quoted 7 lines · WingMan
Quoted 7 lines

-----Original Message-----
From: Balbi, Felipe
Sent: Friday, December 13, 2013 2:55 PM
To: Kwok, WingMan
Cc: Shilimkar, Santosh; Balbi, Felipe; Linux USB Mailing List; kgene.kim at samsung.com; Linux ARM Kernel Mailing List; linux-

samsung-

Quoted 38 lines
Quoted 38 lines

soc at vger.kernel.org; Linux OMAP Mailing List
Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support

Quoted 32 lines · WingMan

Hello

Quoted 19 lines

-----Original Message-----
From: Shilimkar, Santosh
Sent: Thursday, December 12, 2013 7:29 PM
To: Balbi, Felipe
Cc: Linux USB Mailing List; kgene.kim at samsung.com; Linux ARM Kernel Mailing List; linux-samsung-soc at vger.kernel.org; Linux OMAP Mailing List; Kwok, WingMan
Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support

Quoted 2 lines · Felipe Balbi

A bare-minimum PM implementation which will server as building block for more complex

s/server/serve ;-)

Quoted 5 lines

PM implementation in the future.

At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state.

Quoted 7 lines
Quoted 5 lines

---

improve error path a little bit.

We will test this out. Thanks for the patch Felipe.

I have tested the patch and the keystone usb driver continues to function, though I can't test suspend at this time as the rest of the system does not that functionality yet.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Thanks, should I add your Tested-by ?

Yes please.

you need to reply with Tested-by: Your Name <[email protected]> just to make it all official. Sorry

Yes, you can add

#13 lore raw

PATCH 2/7 usb: dwc3: omap: add basic pm_runtime support

In reply to Felipe Balbi

If we want to suspend/runtime in runtime, we
can do so, in OMAP's case at least, with the
same implementation we use for system pm.

This patch adds basic pm_runtime support with
that in mind.

---
 drivers/usb/dwc3/dwc3-omap.c | 39 +++++++++++++++++++++++++++++++++++----
 1 file changed, 35 insertions(+), 4 deletions(-)
drivers/usb/dwc3/dwc3-omap.c +35 -4
index b269dbd..aea305d 100644
@@ -617,20 +617,35 @@ static void dwc3_omap_complete(struct device *dev)
 	dwc3_omap_enable_irqs(omap);
 }
 
-static int dwc3_omap_suspend(struct device *dev)
+static int __dwc3_omap_suspend(struct dwc3_omap *omap)
 {
-	struct dwc3_omap	*omap = dev_get_drvdata(dev);
-
 	omap->utmi_otg_status = dwc3_omap_read_utmi_status(omap);
 
 	return 0;
 }
 
+static int __dwc3_omap_resume(struct dwc3_omap *omap)
+{
+	dwc3_omap_write_utmi_status(omap, omap->utmi_otg_status);
+
+	return 0;
+}
+
+static int dwc3_omap_suspend(struct device *dev)
+{
+	struct dwc3_omap	*omap = dev_get_drvdata(dev);
+
+	return __dwc3_omap_suspend(omap);
+}
+
 static int dwc3_omap_resume(struct device *dev)
 {
 	struct dwc3_omap	*omap = dev_get_drvdata(dev);
+	int			ret;
 
-	dwc3_omap_write_utmi_status(omap, omap->utmi_otg_status);
+	ret = __dwc3_omap_resume(omap);
+	if (ret)
+		return ret;
 
 	pm_runtime_disable(dev);
 	pm_runtime_set_active(dev);
@@ -639,11 +654,27 @@ static int dwc3_omap_resume(struct device *dev)
 	return 0;
 }
 
+static int dwc3_omap_runtime_suspend(struct device *dev)
+{
+	struct dwc3_omap	*omap = dev_get_drvdata(dev);
+
+	return __dwc3_omap_suspend(omap);
+}
+
+static int dwc3_omap_runtime_resume(struct device *dev)
+{
+	struct dwc3_omap	*omap = dev_get_drvdata(dev);
+
+	return __dwc3_omap_resume(omap);
+}
+
 static const struct dev_pm_ops dwc3_omap_dev_pm_ops = {
 	.prepare	= dwc3_omap_prepare,
 	.complete	= dwc3_omap_complete,
 
 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_omap_suspend, dwc3_omap_resume)
+	SET_RUNTIME_PM_OPS(dwc3_omap_runtime_suspend, dwc3_omap_runtime_resume,
+			NULL)
 };
 
 #define DEV_PM_OPS	(&dwc3_omap_dev_pm_ops)
Signature · 1 line
1.8.4.GIT
#14 lore raw

PATCH 3/7 usb: dwc3: pci: add pm_runtime support

In reply to Felipe Balbi

teach the PCI glue about pm_runtime so that
it's easier to teach dwc3 core about it
later.

No functional changes otherwise.

---
 drivers/usb/dwc3/dwc3-pci.c | 66 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 51 insertions(+), 15 deletions(-)
drivers/usb/dwc3/dwc3-pci.c +51 -15
index 665686e..78cd0b0 100644
@@ -109,18 +109,17 @@ static int dwc3_pci_probe(struct pci_dev *pci,
 
 	glue->dev = dev;
 
-	ret = pci_enable_device(pci);
+	pm_runtime_enable(dev);
+	ret = pm_runtime_get_sync(dev);
 	if (ret) {
 		dev_err(dev, "failed to enable pci device\n");
 		return -ENODEV;
 	}
 
-	pci_set_master(pci);
-
 	ret = dwc3_pci_register_phys(glue);
 	if (ret) {
 		dev_err(dev, "couldn't register PHYs\n");
-		return ret;
+		goto err1;
 	}
 
 	dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
@@ -167,7 +166,8 @@ static int dwc3_pci_probe(struct pci_dev *pci,
 err3:
 	platform_device_put(dwc3);
 err1:
-	pci_disable_device(pci);
+	pm_runtime_put_sync(dev);
+	pm_runtime_disable(dev);
 
 	return ret;
 }
@@ -175,11 +175,13 @@ err1:
 static void dwc3_pci_remove(struct pci_dev *pci)
 {
 	struct dwc3_pci	*glue = pci_get_drvdata(pci);
+	struct device *dev = &pci->dev;
 
 	platform_device_unregister(glue->dwc3);
 	platform_device_unregister(glue->usb2_phy);
 	platform_device_unregister(glue->usb3_phy);
-	pci_disable_device(pci);
+	pm_runtime_put_sync(dev);
+	pm_runtime_disable(dev);
 }
 
 static const struct pci_device_id dwc3_pci_id_table[] = {
@@ -193,24 +195,20 @@ static const struct pci_device_id dwc3_pci_id_table[] = {
 };
 MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
 
-#ifdef CONFIG_PM_SLEEP
-static int dwc3_pci_suspend(struct device *dev)
+static int __dwc3_pci_suspend(struct pci_dev *pci)
 {
-	struct pci_dev	*pci = to_pci_dev(dev);
-
 	pci_disable_device(pci);
 
 	return 0;
 }
 
-static int dwc3_pci_resume(struct device *dev)
+static int __dwc3_pci_resume(struct pci_dev *pci)
 {
-	struct pci_dev	*pci = to_pci_dev(dev);
-	int		ret;
+	int ret;
 
 	ret = pci_enable_device(pci);
 	if (ret) {
-		dev_err(dev, "can't re-enable device --> %d\n", ret);
+		dev_err(&pci->dev, "can't re-enable device --> %d\n", ret);
 		return ret;
 	}
 
@@ -218,10 +216,48 @@ static int dwc3_pci_resume(struct device *dev)
 
 	return 0;
 }
-#endif /* CONFIG_PM_SLEEP */
+
+static int dwc3_pci_suspend(struct device *dev)
+{
+	struct pci_dev	*pci = to_pci_dev(dev);
+
+	return __dwc3_pci_suspend(pci);
+}
+
+static int dwc3_pci_resume(struct device *dev)
+{
+	struct pci_dev	*pci = to_pci_dev(dev);
+	int		ret;
+
+	ret = __dwc3_pci_resume(pci);
+	if (ret)
+		return ret;
+
+	pm_runtime_disable(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_disable(dev);
+
+	return 0;
+}
+
+static int dwc3_pci_runtime_suspend(struct device *dev)
+{
+	struct pci_dev	*pci = to_pci_dev(dev);
+
+	return __dwc3_pci_suspend(pci);
+}
+
+static int dwc3_pci_runtime_resume(struct device *dev)
+{
+	struct pci_dev	*pci = to_pci_dev(dev);
+
+	return __dwc3_pci_resume(pci);
+}
 
 static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
+	SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume,
+			NULL)
 };
 
 static struct pci_driver dwc3_pci_driver = {
Signature · 1 line
1.8.4.GIT
#16 lore raw

PATCH 3/7 usb: dwc3: pci: add pm_runtime support

Quoted 11 lines · David Cohen
Quoted 7 lines · Felipe Balbi

teach the PCI glue about pm_runtime so that
it's easier to teach dwc3 core about it
later.

No functional changes otherwise.

I was able to test this one with Intel Merrifield:

cool, thanks. Although that'd be a Tested-by. Is it ok to add your name as Tested-by instead ?

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131212/857afe3a/attachment.sig>
#17 lore raw

PATCH 3/7 usb: dwc3: pci: add pm_runtime support

Quoted 8 lines · Felipe Balbi
Quoted 7 lines · David Cohen
Quoted 6 lines · Felipe Balbi

teach the PCI glue about pm_runtime so that
it's easier to teach dwc3 core about it
later.

No functional changes otherwise.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

I was able to test this one with Intel Merrifield:

cool, thanks. Although that'd be a Tested-by. Is it ok to add your name as Tested-by instead ?

Yeah :)

Br, David

Quoted 3 lines
Signature · 2 lines
-- 
balbi
#18 lore raw

PATCH 4/7 usb: dwc3: omap: fix pm_runtime usage

In reply to Felipe Balbi

even if pm_runtime_get*() fails, it still increments pm usage counter, so we must pm_runtime_put*() in that case too. Fix that observation in dwc3-omap.c.

---
 drivers/usb/dwc3/dwc3-omap.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/usb/dwc3/dwc3-omap.c +1 -3
index aea305d..076bb28 100644
@@ -451,7 +451,7 @@ static int dwc3_omap_probe(struct platform_device *pdev)
 	ret = pm_runtime_get_sync(dev);
 	if (ret < 0) {
 		dev_err(dev, "get_sync failed with err %d\n", ret);
-		goto err0;
+		goto err1;
 	}
 
 	reg = dwc3_omap_readl(omap->base, USBOTGSS_REVISION);
@@ -566,8 +566,6 @@ err2:
 
 err1:
 	pm_runtime_put_sync(dev);
-
-err0:
 	pm_runtime_disable(dev);
 
 	return ret;
Signature · 1 line
1.8.4.GIT
#19 lore raw

PATCH 5/7 usb: dwc3: omap: fix order of pm_runtime vs child removal

In reply to Felipe Balbi

pm_runtime_put_sync() will kill dwc3's clocks and, since dwc3 core accesses registers during removal, we must make sure to unregister core before disabling clocks and pm_runtime.

---
 drivers/usb/dwc3/dwc3-omap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc3/dwc3-omap.c +1 -1
index 076bb28..a9090a1 100644
@@ -580,9 +580,9 @@ static int dwc3_omap_remove(struct platform_device *pdev)
 	if (omap->extcon_id_dev.edev)
 		extcon_unregister_interest(&omap->extcon_id_dev);
 	dwc3_omap_disable_irqs(omap);
+	device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
 	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
-	device_for_each_child(&pdev->dev, NULL, dwc3_omap_remove_core);
 
 	return 0;
 }
Signature · 1 line
1.8.4.GIT
#20 lore raw

PATCH 6/7 usb: dwc3: exynos: remove DEV_PM_OPS hackery

In reply to Felipe Balbi

it's best to just remove all ifdefs and always
define our dev_pm_ops structure.

---
 drivers/usb/dwc3/dwc3-exynos.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +1 -7
index 8b20c70..6ccfc64 100644
@@ -184,7 +184,6 @@ static const struct of_device_id exynos_dwc3_match[] = {
 MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
 #endif
 
-#ifdef CONFIG_PM_SLEEP
 static int dwc3_exynos_suspend(struct device *dev)
 {
 	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
@@ -212,18 +211,13 @@ static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
 };
 
-#define DEV_PM_OPS	(&dwc3_exynos_dev_pm_ops)
-#else
-#define DEV_PM_OPS	NULL
-#endif /* CONFIG_PM_SLEEP */
-
 static struct platform_driver dwc3_exynos_driver = {
 	.probe		= dwc3_exynos_probe,
 	.remove		= dwc3_exynos_remove,
 	.driver		= {
 		.name	= "exynos-dwc3",
 		.of_match_table = of_match_ptr(exynos_dwc3_match),
-		.pm	= DEV_PM_OPS,
+		.pm	= &dwc3_exynos_dev_pm_ops,
 	},
 };
 
Signature · 1 line
1.8.4.GIT
#21 lore raw

PATCH 7/7 usb: dwc3: exynos: add pm_runtime support

In reply to Felipe Balbi

teach Exynos glue about pm_runtime so that
it's easier to teach dwc3 core about it
later.

No functional changes otherwise.

---
 drivers/usb/dwc3/dwc3-exynos.c | 65 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 56 insertions(+), 9 deletions(-)
drivers/usb/dwc3/dwc3-exynos.c +56 -9
index 6ccfc64..c93919a 100644
@@ -141,24 +141,40 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
 	exynos->dev	= dev;
 	exynos->clk	= clk;
 
-	clk_prepare_enable(exynos->clk);
+	ret = clk_prepare(exynos->clk);
+	if (ret) {
+		dev_err(dev, "failed to prepare clock\n");
+		goto err2;
+	}
+
+	pm_runtime_enable(dev);
+	ret = pm_runtime_get_sync(dev);
+	if (ret) {
+		dev_err(dev, "failed to enable dwc3 device\n");
+		goto err3;
+	}
 
 	if (node) {
 		ret = of_platform_populate(node, NULL, NULL, dev);
 		if (ret) {
 			dev_err(dev, "failed to add dwc3 core\n");
-			goto err2;
+			goto err3;
 		}
 	} else {
 		dev_err(dev, "no device node, failed to add dwc3 core\n");
 		ret = -ENODEV;
-		goto err2;
+		goto err3;
 	}
 
 	return 0;
 
+err3:
+	pm_runtime_put_sync(dev);
+	pm_runtime_disable(dev);
+
 err2:
-	clk_disable_unprepare(clk);
+	clk_unprepare(clk);
+
 err1:
 	return ret;
 }
@@ -171,7 +187,9 @@ static int dwc3_exynos_remove(struct platform_device *pdev)
 	platform_device_unregister(exynos->usb2_phy);
 	platform_device_unregister(exynos->usb3_phy);
 
-	clk_disable_unprepare(exynos->clk);
+	pm_runtime_put_sync(exynos->dev);
+	pm_runtime_disable(exynos->dev);
+	clk_unprepare(exynos->clk);
 
 	return 0;
 }
@@ -184,20 +202,33 @@ static const struct of_device_id exynos_dwc3_match[] = {
 MODULE_DEVICE_TABLE(of, exynos_dwc3_match);
 #endif
 
-static int dwc3_exynos_suspend(struct device *dev)
+static int __dwc3_exynos_suspend(struct dwc3_exynos *exynos)
 {
-	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
-
 	clk_disable(exynos->clk);
 
 	return 0;
 }
 
+static int __dwc3_exynos_resume(struct dwc3_exynos *exynos)
+{
+	return clk_enable(exynos->clk);
+}
+
+static int dwc3_exynos_suspend(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+
+	return __dwc3_exynos_suspend(exynos);
+}
+
 static int dwc3_exynos_resume(struct device *dev)
 {
 	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+	int ret;
 
-	clk_enable(exynos->clk);
+	ret = __dwc3_exynos_resume(exynos);
+	if (ret)
+		return ret;
 
 	/* runtime set active to reflect active state. */
 	pm_runtime_disable(dev);
@@ -207,8 +238,24 @@ static int dwc3_exynos_resume(struct device *dev)
 	return 0;
 }
 
+static int dwc3_exynos_runtime_suspend(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+
+	return __dwc3_exynos_suspend(exynos);
+}
+
+static int dwc3_exynos_runtime_resume(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+
+	return __dwc3_exynos_resume(exynos);
+}
+
 static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume)
+	SET_RUNTIME_PM_OPS(dwc3_exynos_runtime_suspend,
+			dwc3_exynos_runtime_resume, NULL)
 };
 
 static struct platform_driver dwc3_exynos_driver = {
Signature · 1 line
1.8.4.GIT
#22 lore raw

PATCH 7/7 usb: dwc3: exynos: add pm_runtime support

Hi Felipe,

Quoted 10 lines
drivers/usb/dwc3/dwc3-exynos.c +1 -3
-static int dwc3_exynos_suspend(struct device *dev)
+static int __dwc3_exynos_suspend(struct dwc3_exynos *exynos)
 {
-	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
-
 	clk_disable(exynos->clk);
 
 	return 0;
 }
 

drivers/usb/dwc3/dwc3-exynos.c static const struct of_device_id exynos_dwc3_match[] = { · line 221

Quoted 10 lines
drivers/usb/dwc3/dwc3-exynos.c +10 -0
+static int __dwc3_exynos_resume(struct dwc3_exynos *exynos)
+{
+	return clk_enable(exynos->clk);
+}
+
+static int dwc3_exynos_suspend(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+
+	return __dwc3_exynos_suspend(exynos);

If dwc3-exynos is runtime suspended, the clock will be disabled second time here (unbalanced clk_enable/clk_disable).

Quoted 21 lines
drivers/usb/dwc3/dwc3-exynos.c +9 -1
+}
+
 static int dwc3_exynos_resume(struct device *dev)
 {
 	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+	int ret;	
 
-	clk_enable(exynos->clk);
+	ret = __dwc3_exynos_resume(exynos);
+	if (ret)
+		return ret;
 
 	/* runtime set active to reflect active state. */
 	pm_runtime_disable(dev);
@@ -207,8 +238,24 @@ static int dwc3_exynos_resume(struct device *dev)
 	return 0;
 }
 
+static int dwc3_exynos_runtime_suspend(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);

drivers/usb/dwc3/dwc3-exynos.c static int dwc3_exynos_resume(struct device *dev) · line 253

Quoted 10 lines
drivers/usb/dwc3/dwc3-exynos.c +10 -0
+
+	return __dwc3_exynos_suspend(exynos);
+}
+
+static int dwc3_exynos_runtime_resume(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+
+	return __dwc3_exynos_resume(exynos);
+}

Thanks

#23 lore raw

PATCH 7/7 usb: dwc3: exynos: add pm_runtime support

Quoted 12 lines · Anton Tikhomirov

Hi Felipe,

Quoted 10 lines
(quoted diff) +1 -3
-static int dwc3_exynos_suspend(struct device *dev)
+static int __dwc3_exynos_suspend(struct dwc3_exynos *exynos)
 {
-	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
-
 	clk_disable(exynos->clk);
 
 	return 0;
 }
Quoted 13 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+static int __dwc3_exynos_resume(struct dwc3_exynos *exynos)
+{
+	return clk_enable(exynos->clk);
+}
+
+static int dwc3_exynos_suspend(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+
+	return __dwc3_exynos_suspend(exynos);

If dwc3-exynos is runtime suspended, the clock will be disabled second time here (unbalanced clk_enable/clk_disable).

I don't get what you mean but there is something that probably needs fixing, I guess below makes it better:

drivers/usb/dwc3/dwc3-exynos.c +3 -0
index c93919a..1e5720a 100644
@@ -218,6 +218,9 @@ static int dwc3_exynos_suspend(struct device *dev)
 {
 	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
 
+	if (pm_runtime_suspended(dev))
+		return 0;
+
 	return __dwc3_exynos_suspend(exynos);
 }
 

Is that what you meant ?

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131213/b6321c93/attachment-0001.sig>
#24 lore raw

PATCH 7/7 usb: dwc3: exynos: add pm_runtime support

Quoted 45 lines · Felipe Balbi
Quoted 12 lines · Anton Tikhomirov

Hi Felipe,

Quoted 10 lines
(quoted diff) +1 -3
-static int dwc3_exynos_suspend(struct device *dev)
+static int __dwc3_exynos_suspend(struct dwc3_exynos *exynos)
 {
-	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
-
 	clk_disable(exynos->clk);
 
 	return 0;
 }
Quoted 13 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+static int __dwc3_exynos_resume(struct dwc3_exynos *exynos)
+{
+	return clk_enable(exynos->clk);
+}
+
+static int dwc3_exynos_suspend(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+
+	return __dwc3_exynos_suspend(exynos);

If dwc3-exynos is runtime suspended, the clock will be disabled second time here (unbalanced clk_enable/clk_disable).

I don't get what you mean but there is something that probably needs fixing, I guess below makes it better:

drivers/usb/dwc3/dwc3-exynos.c +3 -0
index c93919a..1e5720a 100644
@@ -218,6 +218,9 @@ static int dwc3_exynos_suspend(struct device *dev)
 {
 	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
 
+	if (pm_runtime_suspended(dev))
+		return 0;
+
 	return __dwc3_exynos_suspend(exynos);
 }
 
Quoted 1 line

Is that what you meant ?

note, however, that this is *not* a case where we would fall today. See that we pm_runtime_get() in probe and only pm_runtime_put() during remove. So there would never be a case where we would try system suspend while device was already runtime suspended.

I have fixed all patches in my testing/next branch anyway, just to make sure we're "idiot-proof" when it comes to implementing real runtime pm later on :-)

cheers

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131213/7849ea7a/attachment.sig>
#25 lore raw

PATCH 7/7 usb: dwc3: exynos: add pm_runtime support

Hi Felipe,

Quoted 47 lines · Felipe Balbi

drivers/usb/dwc3/dwc3-

Quoted 31 lines · Anton Tikhomirov
Quoted 12 lines

Hi Felipe,

Quoted 10 lines
(quoted diff) +1 -3
-static int dwc3_exynos_suspend(struct device *dev)
+static int __dwc3_exynos_suspend(struct dwc3_exynos *exynos)
 {
-	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
-
 	clk_disable(exynos->clk);
 
 	return 0;
 }
Quoted 13 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+static int __dwc3_exynos_resume(struct dwc3_exynos *exynos)
+{
+	return clk_enable(exynos->clk);
+}
+
+static int dwc3_exynos_suspend(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+
+	return __dwc3_exynos_suspend(exynos);

If dwc3-exynos is runtime suspended, the clock will be disabled second time here (unbalanced clk_enable/clk_disable).

I don't get what you mean but there is something that probably needs fixing, I guess below makes it better:

drivers/usb/dwc3/dwc3- renamed from drivers/usb/dwc3/dwc3-exynos.c +0 -0

exynos.c

Quoted 14 lines

index c93919a..1e5720a 100644

drivers/usb/dwc3/dwc3-exynos.c +3 -0
@@ -218,6 +218,9 @@ static int dwc3_exynos_suspend(struct device *dev)
 {
 	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
 
+	if (pm_runtime_suspended(dev))
+		return 0;
+
 	return __dwc3_exynos_suspend(exynos);
 }
 
Quoted 7 lines
Quoted 1 line

Is that what you meant ?

note, however, that this is *not* a case where we would fall today. See that we pm_runtime_get() in probe and only pm_runtime_put() during remove. So there would never be a case where we would try system suspend
while device was already runtime suspended.

You are right, while runtime PM is blocked by get_sync() in probe, this check
doesn't matter.

Quoted 9 lines

I have fixed all patches in my testing/next branch anyway, just to make sure we're "idiot-proof" when it comes to implementing real runtime pm later on :-)

cheers

--
balbi

Thank you

#26 lore raw

PATCH 7/7 usb: dwc3: exynos: add pm_runtime support

In reply to Felipe Balbi

Hi Felipe,

Quoted 46 lines · Anton Tikhomirov
Quoted 12 lines

Hi Felipe,

Quoted 10 lines
(quoted diff) +1 -3
-static int dwc3_exynos_suspend(struct device *dev)
+static int __dwc3_exynos_suspend(struct dwc3_exynos *exynos)
 {
-	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
-
 	clk_disable(exynos->clk);
 
 	return 0;
 }
Quoted 13 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+static int __dwc3_exynos_resume(struct dwc3_exynos *exynos)
+{
+	return clk_enable(exynos->clk);
+}
+
+static int dwc3_exynos_suspend(struct device *dev)
+{
+	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
+
+	return __dwc3_exynos_suspend(exynos);

If dwc3-exynos is runtime suspended, the clock will be disabled second time here (unbalanced clk_enable/clk_disable).

I don't get what you mean but there is something that probably needs fixing, I guess below makes it better:

drivers/usb/dwc3/dwc3- renamed from drivers/usb/dwc3/dwc3-exynos.c +0 -0

exynos.c
index c93919a..1e5720a 100644

drivers/usb/dwc3/dwc3-exynos.c +3 -0
@@ -218,6 +218,9 @@ static int dwc3_exynos_suspend(struct device *dev)
 {
 	struct dwc3_exynos *exynos = dev_get_drvdata(dev);
 
+	if (pm_runtime_suspended(dev))
+		return 0;
+
 	return __dwc3_exynos_suspend(exynos);
 }
 
Quoted 1 line

Is that what you meant ?

Yes, this is exactly what I meant.

Thanks.

#27 lore raw

cover usb: dwc3: pm_runtime implementation

In reply to Felipe Balbi
Quoted 8 lines · Felipe Balbi

hi all,

these patches add pm_runtime support for all glue layers.

I plan to add pm_runtime support for dwc3 after these patches are merged upstream.

Please test.

At first time I failed to notice you were removing #ifdef's around pm callback functions. Instead of saying DWC3 will start to have warnings when CONFIG_PM is not selected, I'd say your patch set is now a dependence of my RFC :)
https://lkml.org/lkml/2013/12/13/4

Br, David Cohen

Quoted 23 lines

Felipe Balbi (7):
usb: dwc3: keystone: add basic PM support
usb: dwc3: omap: add basic pm_runtime support
usb: dwc3: pci: add pm_runtime support
usb: dwc3: omap: fix pm_runtime usage
usb: dwc3: omap: fix order of pm_runtime vs child removal
usb: dwc3: exynos: remove DEV_PM_OPS hackery
usb: dwc3: exynos: add pm_runtime support

 drivers/usb/dwc3/dwc3-exynos.c   | 73 +++++++++++++++++++++++-------
 drivers/usb/dwc3/dwc3-keystone.c | 97 ++++++++++++++++++++++++++++++++++++++--
 drivers/usb/dwc3/dwc3-omap.c     | 45 +++++++++++++++----
 drivers/usb/dwc3/dwc3-pci.c      | 66 ++++++++++++++++++++-------
 4 files changed, 239 insertions(+), 42 deletions(-)
Signature · 6 lines
1.8.4.GIT

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

cover usb: dwc3: pm_runtime implementation

Quoted 8 lines · David Cohen
Quoted 7 lines · Felipe Balbi

hi all,

these patches add pm_runtime support for all glue layers.

I plan to add pm_runtime support for dwc3 after these patches are merged upstream.

Quoted 6 lines
Quoted 1 line

Please test.

At first time I failed to notice you were removing #ifdef's around pm callback functions. Instead of saying DWC3 will start to have warnings when CONFIG_PM is not selected, I'd say your patch set is now a dependence of my RFC :)

I guess I said it in wrong order :P
Your patch set depends on my RFC.

Quoted 31 lines

https://lkml.org/lkml/2013/12/13/4

Br, David Cohen

Quoted 10 lines

Felipe Balbi (7):
usb: dwc3: keystone: add basic PM support
usb: dwc3: omap: add basic pm_runtime support
usb: dwc3: pci: add pm_runtime support
usb: dwc3: omap: fix pm_runtime usage
usb: dwc3: omap: fix order of pm_runtime vs child removal
usb: dwc3: exynos: remove DEV_PM_OPS hackery
usb: dwc3: exynos: add pm_runtime support

Quoted 13 lines
 drivers/usb/dwc3/dwc3-exynos.c   | 73 +++++++++++++++++++++++-------
 drivers/usb/dwc3/dwc3-keystone.c | 97 ++++++++++++++++++++++++++++++++++++++--
 drivers/usb/dwc3/dwc3-omap.c     | 45 +++++++++++++++----
 drivers/usb/dwc3/dwc3-pci.c      | 66 ++++++++++++++++++++-------
 4 files changed, 239 insertions(+), 42 deletions(-)
Signature · 6 lines
1.8.4.GIT

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

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

#29 lore raw

cover usb: dwc3: pm_runtime implementation

Hi,

Quoted 11 lines · David Cohen
Quoted 10 lines · David Cohen
Quoted 8 lines · Felipe Balbi

hi all,

these patches add pm_runtime support for all glue layers.

I plan to add pm_runtime support for dwc3 after these patches are merged upstream.

Please test.

Quoted 7 lines
Quoted 4 lines

At first time I failed to notice you were removing #ifdef's around pm callback functions. Instead of saying DWC3 will start to have warnings when CONFIG_PM is not selected, I'd say your patch set is now a dependence of my RFC :)

I guess I said it in wrong order :P
Your patch set depends on my RFC.

Or I just modify my patchset a little bit for now ;-)

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131218/26000716/attachment.sig>
#30 lore raw

cover usb: dwc3: pm_runtime implementation

Quoted 19 lines · Felipe Balbi

Hi,

Quoted 16 lines · David Cohen
Quoted 14 lines · David Cohen
Quoted 8 lines · Felipe Balbi

hi all,

these patches add pm_runtime support for all glue layers.

I plan to add pm_runtime support for dwc3 after these patches are merged upstream.

Please test.

At first time I failed to notice you were removing #ifdef's around pm callback functions. Instead of saying DWC3 will start to have warnings when CONFIG_PM is not selected, I'd say your patch set is now a dependence of my RFC :)

Quoted 4 lines
Quoted 2 lines

I guess I said it in wrong order :P
Your patch set depends on my RFC.

Or I just modify my patchset a little bit for now ;-)

nah, it looks horrible with all those ifdefs around. I'll delay my patch series.

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20131218/80debeb2/attachment.sig>