All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@ti.com>
To: Linux USB Mailing List <linux-usb@vger.kernel.org>
Cc: kgene.kim@samsung.com,
	Linux ARM Kernel Mailing List
	<linux-arm-kernel@lists.infradead.org>,
	linux-samsung-soc@vger.kernel.org,
	Linux OMAP Mailing List <linux-omap@vger.kernel.org>,
	w-kwok2@ti.com, Santosh Shilimkar <santosh.shilimkar@ti.com>,
	Felipe Balbi <balbi@ti.com>
Subject: [PATCH 1/7] usb: dwc3: keystone: add basic PM support
Date: Thu, 12 Dec 2013 15:38:39 -0600	[thread overview]
Message-ID: <1386884325-11440-2-git-send-email-balbi@ti.com> (raw)
In-Reply-To: <1386884325-11440-1-git-send-email-balbi@ti.com>

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.

Signed-off-by: Felipe Balbi <balbi@ti.com>
---
 drivers/usb/dwc3/dwc3-keystone.c | 97 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 94 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
index 1fad161..361437f 100644
--- a/drivers/usb/dwc3/dwc3-keystone.c
+++ b/drivers/usb/dwc3/dwc3-keystone.c
@@ -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,
-- 
1.8.4.GIT


WARNING: multiple messages have this Message-ID (diff)
From: balbi@ti.com (Felipe Balbi)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/7] usb: dwc3: keystone: add basic PM support
Date: Thu, 12 Dec 2013 15:38:39 -0600	[thread overview]
Message-ID: <1386884325-11440-2-git-send-email-balbi@ti.com> (raw)
In-Reply-To: <1386884325-11440-1-git-send-email-balbi@ti.com>

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.

Signed-off-by: Felipe Balbi <balbi@ti.com>
---
 drivers/usb/dwc3/dwc3-keystone.c | 97 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 94 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
index 1fad161..361437f 100644
--- a/drivers/usb/dwc3/dwc3-keystone.c
+++ b/drivers/usb/dwc3/dwc3-keystone.c
@@ -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,
-- 
1.8.4.GIT

  reply	other threads:[~2013-12-12 21:39 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-12 21:38 [PATCH 0/7] usb: dwc3: pm_runtime implementation Felipe Balbi
2013-12-12 21:38 ` Felipe Balbi
2013-12-12 21:38 ` Felipe Balbi [this message]
2013-12-12 21:38   ` [PATCH 1/7] usb: dwc3: keystone: add basic PM support Felipe Balbi
2013-12-12 21:43   ` Felipe Balbi
2013-12-12 21:43     ` Felipe Balbi
2013-12-12 21:45     ` [PATCH v2 " Felipe Balbi
2013-12-12 21:45       ` Felipe Balbi
2013-12-12 21:48       ` Felipe Balbi
2013-12-12 21:48         ` Felipe Balbi
2013-12-13  0:29       ` Santosh Shilimkar
2013-12-13  0:29         ` Santosh Shilimkar
2013-12-13  0:43         ` Felipe Balbi
2013-12-13  0:43           ` Felipe Balbi
2013-12-13 23:15           ` Santosh Shilimkar
2013-12-13 23:15             ` Santosh Shilimkar
     [not found]         ` <52AA54E4.5000606-l0cyMroinI0@public.gmane.org>
2013-12-13 16:04           ` Kwok, WingMan
2013-12-13 16:04             ` Kwok, WingMan
2013-12-13 19:54             ` Felipe Balbi
2013-12-13 19:54               ` Felipe Balbi
2013-12-13 20:18               ` Kwok, WingMan
2013-12-13 20:18                 ` Kwok, WingMan
2013-12-13 20:22                 ` Felipe Balbi
2013-12-13 20:22                   ` Felipe Balbi
2013-12-13 21:26                   ` Kwok, WingMan
2013-12-13 21:26                     ` Kwok, WingMan
2013-12-12 21:38 ` [PATCH 2/7] usb: dwc3: omap: add basic pm_runtime support Felipe Balbi
2013-12-12 21:38   ` Felipe Balbi
2013-12-12 21:38 ` [PATCH 4/7] usb: dwc3: omap: fix pm_runtime usage Felipe Balbi
2013-12-12 21:38   ` Felipe Balbi
     [not found] ` <1386884325-11440-1-git-send-email-balbi-l0cyMroinI0@public.gmane.org>
2013-12-12 21:38   ` [PATCH 3/7] usb: dwc3: pci: add pm_runtime support Felipe Balbi
2013-12-12 21:38     ` Felipe Balbi
2013-12-13  1:56     ` David Cohen
2013-12-13  1:56       ` David Cohen
2013-12-13  4:17       ` Felipe Balbi
2013-12-13  4:17         ` Felipe Balbi
2013-12-13  4:29         ` David Cohen
2013-12-13  4:29           ` David Cohen
2013-12-12 21:38   ` [PATCH 5/7] usb: dwc3: omap: fix order of pm_runtime vs child removal Felipe Balbi
2013-12-12 21:38     ` Felipe Balbi
2013-12-17 23:31   ` [PATCH 0/7] usb: dwc3: pm_runtime implementation David Cohen
2013-12-17 23:31     ` David Cohen
2013-12-17 23:35     ` David Cohen
2013-12-17 23:35       ` David Cohen
2013-12-18 15:36       ` Felipe Balbi
2013-12-18 15:36         ` Felipe Balbi
2013-12-18 15:40         ` Felipe Balbi
2013-12-18 15:40           ` Felipe Balbi
2013-12-12 21:38 ` [PATCH 6/7] usb: dwc3: exynos: remove DEV_PM_OPS hackery Felipe Balbi
2013-12-12 21:38   ` Felipe Balbi
2013-12-12 21:38 ` [PATCH 7/7] usb: dwc3: exynos: add pm_runtime support Felipe Balbi
2013-12-12 21:38   ` Felipe Balbi
2013-12-13  5:01   ` Anton Tikhomirov
2013-12-13  5:01     ` Anton Tikhomirov
2013-12-13 19:56     ` Felipe Balbi
2013-12-13 19:56       ` Felipe Balbi
2013-12-13 20:18       ` Felipe Balbi
2013-12-13 20:18         ` Felipe Balbi
2013-12-16  2:47         ` Anton Tikhomirov
2013-12-16  2:47           ` Anton Tikhomirov
     [not found]       ` <20131213195618.GG5292-HgARHv6XitL9zxVx7UNMDg@public.gmane.org>
2013-12-16  2:31         ` Anton Tikhomirov
2013-12-16  2:31           ` Anton Tikhomirov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386884325-11440-2-git-send-email-balbi@ti.com \
    --to=balbi@ti.com \
    --cc=kgene.kim@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=santosh.shilimkar@ti.com \
    --cc=w-kwok2@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.