diff mbox

[v2,1/7] usb: dwc3: keystone: add basic PM support

Message ID 1386884755-12366-1-git-send-email-balbi@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Felipe Balbi Dec. 12, 2013, 9:45 p.m. UTC
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>
---

improve error path a little bit.

 drivers/usb/dwc3/dwc3-keystone.c | 94 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 91 insertions(+), 3 deletions(-)

Comments

Felipe Balbi Dec. 12, 2013, 9:48 p.m. UTC | #1
Hi,

On Thu, Dec 12, 2013 at 03:45:55PM -0600, Felipe Balbi wrote:
> +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.
Santosh Shilimkar Dec. 13, 2013, 12:29 a.m. UTC | #2
On Thursday 12 December 2013 04:45 PM, Felipe Balbi wrote:
> A bare-minimum PM implementation which will
> server as building block for more complex
s/server/serve ;-)
> 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>
> ---
> 
> improve error path a little bit.
> 
We will test this out. Thanks for the
patch Felipe.

Regards,
Santosh
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Felipe Balbi Dec. 13, 2013, 12:43 a.m. UTC | #3
On Thu, Dec 12, 2013 at 07:29:24PM -0500, Santosh Shilimkar wrote:
> On Thursday 12 December 2013 04:45 PM, Felipe Balbi wrote:
> > A bare-minimum PM implementation which will
> > server as building block for more complex
> s/server/serve ;-)

hah! :-) will fix in my branch.

> > 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>
> > ---
> > 
> > improve error path a little bit.
> > 
> We will test this out. Thanks for the
> patch Felipe.

thanks.
WingMan Kwok Dec. 13, 2013, 4:04 p.m. UTC | #4
Hello

> -----Original Message-----
> From: Shilimkar, Santosh
> Sent: Thursday, December 12, 2013 7:29 PM
> To: Balbi, Felipe
> Cc: Linux USB Mailing List; kgene.kim@samsung.com; Linux ARM Kernel
> Mailing List; linux-samsung-soc@vger.kernel.org; Linux OMAP Mailing List;
> Kwok, WingMan
> Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support
> 
> On Thursday 12 December 2013 04:45 PM, Felipe Balbi wrote:
> > A bare-minimum PM implementation which will server as building block
> > for more complex
> s/server/serve ;-)
> > 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>
> > ---
> >
> > 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
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Felipe Balbi Dec. 13, 2013, 7:54 p.m. UTC | #5
On Fri, Dec 13, 2013 at 10:04:38AM -0600, Kwok, WingMan wrote:
> Hello
> 
> > -----Original Message-----
> > From: Shilimkar, Santosh
> > Sent: Thursday, December 12, 2013 7:29 PM
> > To: Balbi, Felipe
> > Cc: Linux USB Mailing List; kgene.kim@samsung.com; Linux ARM Kernel
> > Mailing List; linux-samsung-soc@vger.kernel.org; Linux OMAP Mailing List;
> > Kwok, WingMan
> > Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support
> > 
> > On Thursday 12 December 2013 04:45 PM, Felipe Balbi wrote:
> > > A bare-minimum PM implementation which will server as building block
> > > for more complex
> > s/server/serve ;-)
> > > 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>
> > > ---
> > >
> > > 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, should I add your Tested-by ?
WingMan Kwok Dec. 13, 2013, 8:18 p.m. UTC | #6
> -----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@samsung.com; Linux ARM Kernel Mailing List; linux-samsung-
> soc@vger.kernel.org; Linux OMAP Mailing List
> Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support
> 
> On Fri, Dec 13, 2013 at 10:04:38AM -0600, Kwok, WingMan wrote:
> > Hello
> >
> > > -----Original Message-----
> > > From: Shilimkar, Santosh
> > > Sent: Thursday, December 12, 2013 7:29 PM
> > > To: Balbi, Felipe
> > > Cc: Linux USB Mailing List; kgene.kim@samsung.com; Linux ARM Kernel
> > > Mailing List; linux-samsung-soc@vger.kernel.org; Linux OMAP Mailing
> > > List; Kwok, WingMan
> > > Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM
> > > support
> > >
> > > On Thursday 12 December 2013 04:45 PM, Felipe Balbi wrote:
> > > > A bare-minimum PM implementation which will server as building
> > > > block for more complex
> > > s/server/serve ;-)
> > > > 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>
> > > > ---
> > > >
> > > > 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, should I add your Tested-by ?

Yes please.

Thanks
WingMan

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Felipe Balbi Dec. 13, 2013, 8:22 p.m. UTC | #7
On Fri, Dec 13, 2013 at 02:18:42PM -0600, Kwok, WingMan wrote:
> 
> > -----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@samsung.com; Linux ARM Kernel Mailing List; linux-samsung-
> > soc@vger.kernel.org; Linux OMAP Mailing List
> > Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support
> > 
> > On Fri, Dec 13, 2013 at 10:04:38AM -0600, Kwok, WingMan wrote:
> > > Hello
> > >
> > > > -----Original Message-----
> > > > From: Shilimkar, Santosh
> > > > Sent: Thursday, December 12, 2013 7:29 PM
> > > > To: Balbi, Felipe
> > > > Cc: Linux USB Mailing List; kgene.kim@samsung.com; Linux ARM Kernel
> > > > Mailing List; linux-samsung-soc@vger.kernel.org; Linux OMAP Mailing
> > > > List; Kwok, WingMan
> > > > Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM
> > > > support
> > > >
> > > > On Thursday 12 December 2013 04:45 PM, Felipe Balbi wrote:
> > > > > A bare-minimum PM implementation which will server as building
> > > > > block for more complex
> > > > s/server/serve ;-)
> > > > > 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>
> > > > > ---
> > > > >
> > > > > 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, should I add your Tested-by ?
> 
> Yes please.

you need to reply with Tested-by: Your Name <your.email@domain.com> just
to make it all official. Sorry
WingMan Kwok Dec. 13, 2013, 9:26 p.m. UTC | #8
> -----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@samsung.com; Linux ARM Kernel Mailing List; linux-samsung-
> soc@vger.kernel.org; Linux OMAP Mailing List
> Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM support
> 
> On Fri, Dec 13, 2013 at 02:18:42PM -0600, Kwok, WingMan wrote:
> >
> > > -----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@samsung.com; Linux ARM Kernel Mailing List; linux-
> samsung-
> > > soc@vger.kernel.org; Linux OMAP Mailing List
> > > Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM
> > > support
> > >
> > > On Fri, Dec 13, 2013 at 10:04:38AM -0600, Kwok, WingMan wrote:
> > > > Hello
> > > >
> > > > > -----Original Message-----
> > > > > From: Shilimkar, Santosh
> > > > > Sent: Thursday, December 12, 2013 7:29 PM
> > > > > To: Balbi, Felipe
> > > > > Cc: Linux USB Mailing List; kgene.kim@samsung.com; Linux ARM
> > > > > Kernel Mailing List; linux-samsung-soc@vger.kernel.org; Linux
> > > > > OMAP Mailing List; Kwok, WingMan
> > > > > Subject: Re: [PATCH v2 1/7] usb: dwc3: keystone: add basic PM
> > > > > support
> > > > >
> > > > > On Thursday 12 December 2013 04:45 PM, Felipe Balbi wrote:
> > > > > > A bare-minimum PM implementation which will server as building
> > > > > > block for more complex
> > > > > s/server/serve ;-)
> > > > > > 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>
> > > > > > ---
> > > > > >
> > > > > > 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, should I add your Tested-by ?
> >
> > Yes please.
> 
> you need to reply with Tested-by: Your Name <your.email@domain.com>
> just to make it all official. Sorry
> 

Yes, you can add
Tested-by: WingMan Kwok <w-kwok2@ti.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Santosh Shilimkar Dec. 13, 2013, 11:15 p.m. UTC | #9
On Thursday 12 December 2013 07:43 PM, Felipe Balbi wrote:
> On Thu, Dec 12, 2013 at 07:29:24PM -0500, Santosh Shilimkar wrote:
>> On Thursday 12 December 2013 04:45 PM, Felipe Balbi wrote:
>>> A bare-minimum PM implementation which will
>>> server as building block for more complex
>> s/server/serve ;-)
> 
> hah! :-) will fix in my branch.
> 
>>> 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>
>>> ---
>>>
>>> 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...

Acked-by: Santosh Shilimkar <santosh.shilimkar@ti.com>

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

Patch

diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
index 1fad161..3b3761c 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,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,