* [PATCH v2] spi/pl022: get/put resources on suspend/resume
@ 2012-09-26 16:06 Linus Walleij
[not found] ` <1348675582-11538-1-git-send-email-linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2012-09-26 16:06 UTC (permalink / raw)
To: Grant Likely, Mark Brown,
spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
Cc: Anmar Oueja, Viresh Kumar, Vipul Kumar Samar, Linus Walleij
This factors out the resource handling in runtime
suspend/resume and also calls it from the ordinary suspend
and resume hooks.
The semantics require that ordinary PM op suspend is called
with runtime PM in resumed mode, so that ordinary suspend
can assume that it will e.g. decrease the clock reference
counter to 0, runtime resume having previously increased it
to 1.
Cc: Vipul Kumar Samar <vipulkumar.samar-qxv4g6HH51o@public.gmane.org>
Cc: Viresh Kumar <viresh.kumar-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Acked-by: Ulf Hansson <ulf.hansson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Signed-off-by: Linus Walleij <linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>
---
ChangeLog v1->v2:
- Add more #ifdef for the case where we have neither normal
PM nor runtime PM.
---
drivers/spi/spi-pl022.c | 66 ++++++++++++++++++++++++++++++++-----------------
1 file changed, 44 insertions(+), 22 deletions(-)
diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
index 15737bc..9194641 100644
--- a/drivers/spi/spi-pl022.c
+++ b/drivers/spi/spi-pl022.c
@@ -2300,6 +2300,45 @@ pl022_remove(struct amba_device *adev)
return 0;
}
+#if defined(CONFIG_SUSPEND) || defined(CONFIG_PM_RUNTIME)
+/*
+ * These two functions are used from both suspend/resume and
+ * the runtime counterparts to handle external resources like
+ * clocks, pins and regulators when going to sleep.
+ */
+static void pl022_suspend_resources(struct pl022 *pl022)
+{
+ int ret;
+
+ clk_disable(pl022->clk);
+
+ /* Optionally let pins go into sleep states */
+ if (!IS_ERR(pl022->pins_sleep)) {
+ ret = pinctrl_select_state(pl022->pinctrl,
+ pl022->pins_sleep);
+ if (ret)
+ dev_err(&pl022->adev->dev,
+ "could not set pins to sleep state\n");
+ }
+}
+
+static void pl022_resume_resources(struct pl022 *pl022)
+{
+ int ret;
+
+ /* Optionaly enable pins to be muxed in and configured */
+ if (!IS_ERR(pl022->pins_default)) {
+ ret = pinctrl_select_state(pl022->pinctrl,
+ pl022->pins_default);
+ if (ret)
+ dev_err(&pl022->adev->dev,
+ "could not set default pins\n");
+ }
+
+ clk_enable(pl022->clk);
+}
+#endif
+
#ifdef CONFIG_SUSPEND
static int pl022_suspend(struct device *dev)
{
@@ -2311,6 +2350,7 @@ static int pl022_suspend(struct device *dev)
dev_warn(dev, "cannot suspend master\n");
return ret;
}
+ pl022_suspend_resources(pl022);
dev_dbg(dev, "suspended\n");
return 0;
@@ -2321,6 +2361,8 @@ static int pl022_resume(struct device *dev)
struct pl022 *pl022 = dev_get_drvdata(dev);
int ret;
+ pl022_resume_resources(pl022);
+
/* Start the queue running */
ret = spi_master_resume(pl022->master);
if (ret)
@@ -2336,36 +2378,16 @@ static int pl022_resume(struct device *dev)
static int pl022_runtime_suspend(struct device *dev)
{
struct pl022 *pl022 = dev_get_drvdata(dev);
- int status = 0;
-
- clk_disable(pl022->clk);
-
- /* Optionally let pins go into sleep states */
- if (!IS_ERR(pl022->pins_sleep)) {
- status = pinctrl_select_state(pl022->pinctrl,
- pl022->pins_sleep);
- if (status)
- dev_err(dev, "could not set pins to sleep state\n");
- }
+ pl022_suspend_resources(pl022);
return 0;
}
static int pl022_runtime_resume(struct device *dev)
{
struct pl022 *pl022 = dev_get_drvdata(dev);
- int status = 0;
-
- /* Optionaly enable pins to be muxed in and configured */
- if (!IS_ERR(pl022->pins_default)) {
- status = pinctrl_select_state(pl022->pinctrl,
- pl022->pins_default);
- if (status)
- dev_err(dev, "could not set default pins\n");
- }
-
- clk_enable(pl022->clk);
+ pl022_resume_resources(pl022);
return 0;
}
#endif
--
1.7.11.3
------------------------------------------------------------------------------
How fast is your code?
3 out of 4 devs don\\\'t know how their code performs in production.
Find out how slow your code is with AppDynamics Lite.
http://ad.doubleclick.net/clk;262219672;13503038;z?
http://info.appdynamics.com/FreeJavaPerformanceDownload.html
^ permalink raw reply related [flat|nested] 4+ messages in thread[parent not found: <1348675582-11538-1-git-send-email-linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>]
* Re: [PATCH v2] spi/pl022: get/put resources on suspend/resume [not found] ` <1348675582-11538-1-git-send-email-linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org> @ 2012-09-27 4:27 ` vipul kumar samar [not found] ` <5063D5C5.2050303-qxv4g6HH51o@public.gmane.org> 2012-09-28 13:04 ` Mark Brown 1 sibling, 1 reply; 4+ messages in thread From: vipul kumar samar @ 2012-09-27 4:27 UTC (permalink / raw) To: Linus WALLEIJ Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org, Anmar Oueja, Mark Brown, Viresh Kumar On 9/26/2012 9:36 PM, Linus WALLEIJ wrote: > This factors out the resource handling in runtime > suspend/resume and also calls it from the ordinary suspend > and resume hooks. > > The semantics require that ordinary PM op suspend is called > with runtime PM in resumed mode, so that ordinary suspend > can assume that it will e.g. decrease the clock reference > counter to 0, runtime resume having previously increased it > to 1. > > Cc: Vipul Kumar Samar<vipulkumar.samar-qxv4g6HH51o@public.gmane.org> > Cc: Viresh Kumar<viresh.kumar-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> > Acked-by: Ulf Hansson<ulf.hansson-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org> > Signed-off-by: Linus Walleij<linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org> > --- > ChangeLog v1->v2: > - Add more #ifdef for the case where we have neither normal > PM nor runtime PM. > --- > drivers/spi/spi-pl022.c | 66 ++++++++++++++++++++++++++++++++----------------- > 1 file changed, 44 insertions(+), 22 deletions(-) > > diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c > index 15737bc..9194641 100644 > --- a/drivers/spi/spi-pl022.c > +++ b/drivers/spi/spi-pl022.c > @@ -2300,6 +2300,45 @@ pl022_remove(struct amba_device *adev) > return 0; > } > > +#if defined(CONFIG_SUSPEND) || defined(CONFIG_PM_RUNTIME) > +/* > + * These two functions are used from both suspend/resume and > + * the runtime counterparts to handle external resources like > + * clocks, pins and regulators when going to sleep. > + */ > +static void pl022_suspend_resources(struct pl022 *pl022) > +{ > + int ret; > + > + clk_disable(pl022->clk); > + > + /* Optionally let pins go into sleep states */ > + if (!IS_ERR(pl022->pins_sleep)) { > + ret = pinctrl_select_state(pl022->pinctrl, > + pl022->pins_sleep); > + if (ret) > + dev_err(&pl022->adev->dev, > + "could not set pins to sleep state\n"); > + } > +} > + > +static void pl022_resume_resources(struct pl022 *pl022) > +{ > + int ret; > + > + /* Optionaly enable pins to be muxed in and configured */ > + if (!IS_ERR(pl022->pins_default)) { > + ret = pinctrl_select_state(pl022->pinctrl, > + pl022->pins_default); > + if (ret) > + dev_err(&pl022->adev->dev, > + "could not set default pins\n"); > + } > + > + clk_enable(pl022->clk); What happen in case clk_enable returns an error?? Rest all is fine. Regards Vipul Samar ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://ad.doubleclick.net/clk;258768047;13503038;j? http://info.appdynamics.com/FreeJavaPerformanceDownload.html ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <5063D5C5.2050303-qxv4g6HH51o@public.gmane.org>]
* Re: [PATCH v2] spi/pl022: get/put resources on suspend/resume [not found] ` <5063D5C5.2050303-qxv4g6HH51o@public.gmane.org> @ 2012-09-27 11:28 ` Linus Walleij 0 siblings, 0 replies; 4+ messages in thread From: Linus Walleij @ 2012-09-27 11:28 UTC (permalink / raw) To: vipul kumar samar Cc: Anmar Oueja, spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org, Mark Brown, Linus WALLEIJ, Viresh Kumar On Thu, Sep 27, 2012 at 6:27 AM, vipul kumar samar <vipulkumar.samar-qxv4g6HH51o@public.gmane.org> wrote: >> + clk_enable(pl022->clk); > > What happen in case clk_enable returns an error?? Same as today, it gets ignored. This is not uncommon among drivers, there are just too many things to check. On many platforms the clk_enable() just cannot return anything but 0, For example in the SPEAr ultimately a gate clock seems to be registered for this clock and the code handling enable looks like this (drivers/clk/clk-gate.c): static int clk_gate_enable(struct clk_hw *hw) { clk_gate_endisable(hw, 1); return 0; } Yours, Linus Walleij ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://ad.doubleclick.net/clk;258768047;13503038;j? http://info.appdynamics.com/FreeJavaPerformanceDownload.html ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] spi/pl022: get/put resources on suspend/resume [not found] ` <1348675582-11538-1-git-send-email-linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org> 2012-09-27 4:27 ` vipul kumar samar @ 2012-09-28 13:04 ` Mark Brown 1 sibling, 0 replies; 4+ messages in thread From: Mark Brown @ 2012-09-28 13:04 UTC (permalink / raw) To: Linus Walleij Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Anmar Oueja, Vipul Kumar Samar, Viresh Kumar On Wed, Sep 26, 2012 at 06:06:22PM +0200, Linus Walleij wrote: > This factors out the resource handling in runtime > suspend/resume and also calls it from the ordinary suspend > and resume hooks. Applied, thanks. ------------------------------------------------------------------------------ Got visibility? Most devs has no idea what their production app looks like. Find out how fast your code is with AppDynamics Lite. http://ad.doubleclick.net/clk;262219671;13503038;y? http://info.appdynamics.com/FreeJavaPerformanceDownload.html ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-09-28 13:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-26 16:06 [PATCH v2] spi/pl022: get/put resources on suspend/resume Linus Walleij
[not found] ` <1348675582-11538-1-git-send-email-linus.walleij-0IS4wlFg1OjSUeElwK9/Pw@public.gmane.org>
2012-09-27 4:27 ` vipul kumar samar
[not found] ` <5063D5C5.2050303-qxv4g6HH51o@public.gmane.org>
2012-09-27 11:28 ` Linus Walleij
2012-09-28 13:04 ` Mark Brown
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.