PM: SuperH Runtime PM prototype V2
Subsystems (5)
cover PM: SuperH Runtime PM prototype V2
PM: SuperH Runtime PM prototype V2
[PATCH 01/04] sh: SuperH platform bus code for Runtime PM v11 [PATCH 02/04] i2c: Runtime PM changes for SuperH I2C driver [PATCH 03/04] uio: Runtime PM changes for UIO driver [PATCH 04/04] video: Runtime PM hack for SuperH LCDC driver
This series is the Runtime PM prototype for SuperH V2. Included is a architecture specific Runtime PM implementation prototype for the platform bus together with a few driver changes.
The patches are meant to be applied on top of the following:
"PM: Introduce core framework for run-time PM of I/O devices (rev. 11)" "PM: Runtime PM v11 - add dev_pm_ops helpers"
"PM: Runtime PM v11 - let bus-less devices succeed"
"PM: Runtime PM v11 - add debug printouts"
"PM: Runtime PM v11 - CONFIG_PM_SLEEP=n support"
"Driver Core: Runtime PM callbacks for the Platform Bus V2"
For the SuperH side of things you also need latest sh-2.6 git and:
"Driver Core: Add platform device arch data V3"
"sh: Runtime PM pdev hwblk changes"
Patch 01 + 04 need more attention
Patch 02 + 03 should be all that is needed for Runtime PM driver support.
Rafael, please have a look at the Runtime PM v11 issue in patch 04.
---
arch/sh/include/asm/device.h | 8 arch/sh/include/asm/hwblk.h | 4 arch/sh/kernel/cpu/shmobile/Makefile | 1 arch/sh/kernel/cpu/shmobile/pm_runtime.c | 244 ++++++++++++++++++++++++++++++ drivers/i2c/busses/i2c-sh_mobile.c | 39 ++++ drivers/uio/uio_pdrv_genirq.c | 54 ++++++ drivers/video/sh_mobile_lcdcfb.c | 47 +++-- 7 files changed, 376 insertions(+), 21 deletions(-)
PATCH 1/4 sh: SuperH platform bus code for Runtime PM v11
From: Magnus Damm <[email protected]>
This patch is V2 of the SuperH Platform Bus prototype implentation for Runtime PM v11.
The code gets invoked from the SuperH specific Runtime PM platform bus functions that override the weak symbols for:
- platform_pm_runtime_suspend()
- platform_pm_runtime_resume()
- platform_pm_runtime_idle()
This Runtime PM implementation performs two levels of power management. At the time of platform bus runtime suspend the clock to the device is stopped instantly. Later on if all devices within the power domain has their clocks stopped then the device driver ->runtime_suspend() callbacks are used to save hardware register state for each device.
Device driver ->runtime_suspend() calls are scheduled from cpuidle context using platform_pm_runtime_suspend_idle(). When all devices have been fully suspended the processor is allowed to enter deep sleep from cpuidle. The cpuidle implementation is however not part of this patch.
The runtime resume operation turns on clocks and also restores registers if needed. It is worth noting that the devices start in a suspended state and the device driver is responsible for calling runtime resume before accessing the actual hardware.
In this particular platform bus implementation runtime resume is not allowed from interrupt context. Runtime suspend is however allowed from interrupt context as long as the synchronous functions are avoided.
This code is already working quite well, but it needs a bit more attention before I remove the prototype label.
---
Changes since last V1:
- update from Runtime PM v9 to v11
- rework error handling
- implement platform_pm_runtime_idle()
- add might_sleep()
- use dev_pm_ops helpers
- use dev_dbg()
- use core_initcall()
TODO:
- use a mutex to serialize dev_pm_ops calls
- rewrite the schedule_work() code
arch/sh/include/asm/device.h | 8 arch/sh/include/asm/hwblk.h | 4 arch/sh/kernel/cpu/shmobile/Makefile | 1 arch/sh/kernel/cpu/shmobile/pm_runtime.c | 244 ++++++++++++++++++++++++++++++ 4 files changed, 256 insertions(+), 1 deletion(-)
arch/sh/include/asm/device.h +8 -0
@@ -14,8 +14,16 @@ int platform_resource_setup_memory(strucvoid plat_early_device_setup (void ); +#define PDEV_ARCHDATA_FLAG_INIT 0 +#define PDEV_ARCHDATA_FLAG_LIST 1 +#define PDEV_ARCHDATA_FLAG_SUSP 2 +#define PDEV_ARCHDATA_FLAG_WORK 3 +struct pdev_archdata {#ifdef CONFIG_ARCH_SHMOBILE int hwblk_id; +unsigned long flags; +struct list_head entry; +struct work_struct work;#endif };
arch/sh/include/asm/hwblk.h +3 -1
@@ -5,7 +5,9 @@#include <asm/io.h> #define HWBLK_CNT_USAGE 0 -#define HWBLK_CNT_NR 1 +#define HWBLK_CNT_IDLE 1 +#define HWBLK_CNT_DEVICES 2 +#define HWBLK_CNT_NR 3#define HWBLK_AREA_FLAG_PARENT (1 << 0)/* valid parent */
arch/sh/kernel/cpu/shmobile/Makefile +1 -0
@@ -5,3 +5,4 @@ # Power Management & Sleep mode obj-$(CONFIG_PM) += pm.o sleep.o obj-$(CONFIG_CPU_IDLE) += cpuidle.o +obj-$(CONFIG_PM_RUNTIME) += pm_runtime.o
arch/sh/kernel/cpu/shmobile/pm_runtime.c new file +244 -0
244 lines not on this page · raw message
PATCH 2/4 i2c: Runtime PM changes for SuperH I2C driver
In reply to Magnus DammFrom: Magnus Damm <[email protected]>
This patch modifies the SuperH Mobile I2C driver to support Runtime PM. These changes should be all that is needed for proper Runtime PM support in this driver. Driver callbacks for Runtime PM are empty because the registers are always re-initialized after pm_runtime_get_sync().
---
Changes from V1 prototype:
- use pm_runtime_get_sync() and pm_runtime_put_sync()
- use pm_runtime_disable()
- implement nop runtime pm functions for dev_pm_ops
- no need for pm_runtime_set_suspended()
drivers/i2c/busses/i2c-sh_mobile.c | 39 ++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-sh_mobile.c +37 -2
@@ -28,6 +28,7 @@#include <linux/interrupt.h> #include <linux/i2c.h> #include <linux/err.h> +#include <linux/pm_runtime.h> #include <linux/clk.h> #include <linux/io.h>
@@ -165,7 +166,8 @@ static void activate_ch(struct sh_mobileu_int32_t denom;u_int32_t tmp; -/* Make sure the clock is enabled */ +/* Wake up device and enable clock */ +pm_runtime_get_sync (pd->dev);clk_enable (pd->clk);/* Get clock rate after clock is enabled */
@@ -213,8 +215,9 @@ static void deactivate_ch(struct sh_mobi/* Disable channel */ iowrite8 (ioread8 (ICCR (pd)) & ~ICCR_ICE ,ICCR (pd)); -/* Disable clock */ +/* Disable clock and mark device as idle */ clk_disable (pd->clk); +pm_runtime_put_sync (pd->dev); } static unsigned char i2c_op(struct sh_mobile_i2c_data *pd,
@@ -572,6 +575,19 @@ static int sh_mobile_i2c_probe(struct pl goto err_irq; } +/* Enable Runtime PM for this device. +* +* Also tell the Runtime PM core to ignore children +* for this device since it is valid for us to suspend +* this I2C master driver even though the slave devices +* on the I2C bus may not be suspended. +* +* The state of the I2C hardware bus is unaffected by +* the Runtime PM state. +*/ +pm_suspend_ignore_children (&dev->dev, true); +pm_runtime_enable (&dev->dev); +/* setup the private data */ adap = &pd->adap;i2c_set_adapdata (adap, pd);
@@ -614,14 +630,33 @@ static int sh_mobile_i2c_remove(struct piounmap (pd->reg);sh_mobile_i2c_hook_irqs (dev,0 );clk_put (pd->clk); +pm_runtime_disable (&dev->dev);kfree (pd);return 0 ; } +static int sh_mobile_i2c_runtime_nop (struct device *dev) +{ +/* Runtime PM callback shared between ->runtime_suspend() +* and ->runtime_resume(). Simply returns success. +* +* This driver re-initializes all registers after +* pm_runtime_get_sync() anyway so there is no need +* to save and restore registers here. +*/ +return 0 ; +} + +static struct dev_pm_ops sh_mobile_i2c_dev_pm_ops = { + .runtime_suspend = sh_mobile_i2c_runtime_nop, + .runtime_resume = sh_mobile_i2c_runtime_nop, +}; +static struct platform_driver sh_mobile_i2c_driver = { .driver = { .name ="i2c-sh_mobile" , .owner =THIS_MODULE , + .pm = &sh_mobile_i2c_dev_pm_ops, }, .probe = sh_mobile_i2c_probe, .remove = sh_mobile_i2c_remove,
PATCH 3/4 uio: Runtime PM changes for UIO driver
In reply to Magnus DammFrom: Magnus Damm <[email protected]>
This patch modifies the uio_pdrv_genirq driver to support Runtime PM. The power management implementation simply runtime resumes the device at open() time and runtime suspends it at release() time. The user space driver is responsible for re-initializing the hardware after open().
---
drivers/uio/uio_pdrv_genirq.c | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
drivers/uio/uio_pdrv_genirq.c +54 -0
@@ -20,6 +20,7 @@#include <linux/bitops.h> #include <linux/interrupt.h> #include <linux/stringify.h> +#include <linux/pm_runtime.h> #define DRIVER_NAME "uio_pdrv_genirq"
@@ -27,8 +28,27 @@ struct uio_pdrv_genirq_platdata {struct uio_info *uioinfo;spinlock_t lock;unsigned long flags; +struct platform_device *pdev; }; +static int uio_pdrv_genirq_open (struct uio_info *info,struct inode *inode) +{ +struct uio_pdrv_genirq_platdata *priv = info->priv; + +/* Wait until the Runtime PM code has woken up the device */ +pm_runtime_get_sync (&priv->pdev->dev); +return 0 ; +} + +static int uio_pdrv_genirq_release (struct uio_info *info,struct inode *inode) +{ +struct uio_pdrv_genirq_platdata *priv = info->priv; + +/* Tell the Runtime PM code that the device has become idle */ +pm_runtime_put_sync (&priv->pdev->dev); +return 0 ; +} +static irqreturn_t uio_pdrv_genirq_handler (int irq,struct uio_info *dev_info) {struct uio_pdrv_genirq_platdata *priv = dev_info->priv;
@@ -97,6 +117,7 @@ static int uio_pdrv_genirq_probe(struct priv->uioinfo = uioinfo;spin_lock_init (&priv->lock); priv->flags =0 ;/* interrupt is enabled to begin with */ + priv->pdev = pdev; uiomem = &uioinfo->mem[0 ];
@@ -136,8 +157,17 @@ static int uio_pdrv_genirq_probe(struct uioinfo->irq_flags |=IRQF_DISABLED ; uioinfo->handler = uio_pdrv_genirq_handler; uioinfo->irqcontrol = uio_pdrv_genirq_irqcontrol; + uioinfo->open = uio_pdrv_genirq_open; + uioinfo->release = uio_pdrv_genirq_release; uioinfo->priv = priv; +/* Enable Runtime PM for this device: +* Starts in suspended state to allow the hardware to be turned off +* by default. The Runtime PM bus code will power on the hardware and +* enable clocks at open() during the call to pm_runtime_get_sync(). +*/ +pm_runtime_enable (&pdev->dev); + ret =uio_register_device (&pdev->dev, priv->uioinfo);if (ret) {dev_err (&pdev->dev,"unable to register uio device\n" );
@@ -157,16 +187,40 @@ static int uio_pdrv_genirq_remove(structstruct uio_pdrv_genirq_platdata *priv =platform_get_drvdata (pdev);uio_unregister_device (priv->uioinfo); +pm_runtime_disable (&pdev->dev);kfree (priv);return 0 ; } +static int uio_pdrv_genirq_runtime_nop (struct device *dev) +{ +/* Runtime PM callback shared between ->runtime_suspend() +* and ->runtime_resume(). Simply returns success. +* +* In this driver pm_runtime_get() and pm_runtime_put_sync() +* are used at open() and release() time. This allows the +* Runtime PM code to turn off power to the device while the +* device is unused, ie before open() and after release(). +* +* This Runtime PM callback does not need to save or restore +* any registers since user space will reinitialize all the +* hardware registers after open(). +*/ +return 0 ; +} + +static struct dev_pm_ops uio_pdrv_genirq_dev_pm_ops = { + .runtime_suspend = uio_pdrv_genirq_runtime_nop, + .runtime_resume = uio_pdrv_genirq_runtime_nop, +}; +static struct platform_driver uio_pdrv_genirq = { .probe = uio_pdrv_genirq_probe, .remove = uio_pdrv_genirq_remove, .driver = { .name =DRIVER_NAME , .owner =THIS_MODULE , + .pm = &uio_pdrv_genirq_dev_pm_ops, }, };
PATCH 4/4 video: Runtime PM hack for SuperH LCDC driver
In reply to Magnus DammFrom: Magnus Damm <[email protected]>
This patch modifies the SuperH Mobile LCDC framebuffer driver to support Runtime PM. This patch is experimental and is at this point still missing context save and restore support.
With debug messages it is however already possible to see that the deferred io clock management strategy pays off since in that mode the clocks are only turned on for a short period of time to redraw the screen. When the screen is unchanged the clocks are disabled and the driver can be in runtime suspended state.
Regarding pm_runtime_put_noidle()/pm_runtime_get_noresume():
This driver does not work well with the Runtime PM v11 code since it performs runtime_pm_get_sync() from probe() which is not allowed. This driver needs to access hardware registers from probe() so runtime_pm_get_sync() must really succeed in this case so the bus code gets a chance to turn on the hardware device.
---
Changes from V1 prototype:
- use pm_runtime_get_sync() and pm_runtime_put_sync()
- use pm_runtime_disable()
- no need for pm_runtime_set_suspended()
- incomplete runtime pm functions for dev_pm_ops
- work around with pm_runtime_put_noidle()/pm_runtime_get_noresume()
TODO:
- quite a bit
drivers/video/sh_mobile_lcdcfb.c | 47 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-)
drivers/video/sh_mobile_lcdcfb.c +29 -18
@@ -14,6 +14,7 @@#include <linux/mm.h> #include <linux/fb.h> #include <linux/clk.h> +#include <linux/pm_runtime.h> #include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/interrupt.h>
@@ -42,9 +43,9 @@ struct sh_mobile_lcdc_chan {struct sh_mobile_lcdc_priv {void __iomem *base;int irq; -atomic_t clk_usecnt; +atomic_t hw_usecnt; +struct device *dev;struct clk *dot_clk; -struct clk *clk;unsigned long lddckr;struct sh_mobile_lcdc_chan ch[2 ];int started;
@@ -185,8 +186,8 @@ struct sh_mobile_lcdc_sys_bus_ops sh_mobstatic void sh_mobile_lcdc_clk_on (struct sh_mobile_lcdc_priv *priv) { -if (atomic_inc_and_test (&priv->clk_usecnt)) { -clk_enable (priv->clk); +if (atomic_inc_and_test (&priv->hw_usecnt)) { +pm_runtime_get_sync (priv->dev);if (priv->dot_clk)clk_enable (priv->dot_clk); }
@@ -194,10 +195,10 @@ static void sh_mobile_lcdc_clk_on(structstatic void sh_mobile_lcdc_clk_off (struct sh_mobile_lcdc_priv *priv) { -if (atomic_sub_return (1 , &priv->clk_usecnt) ==-1 ) { +if (atomic_sub_return (1 , &priv->hw_usecnt) ==-1 ) {if (priv->dot_clk)clk_disable (priv->dot_clk); -clk_disable (priv->clk); +pm_runtime_put (priv->dev); } }
@@ -566,7 +567,6 @@ static int sh_mobile_lcdc_setup_clocks(sint clock_source, struct sh_mobile_lcdc_priv *priv) { - char clk_name[8]; char *str;int icksel;
@@ -580,23 +580,15 @@ static int sh_mobile_lcdc_setup_clocks(s priv->lddckr = icksel <<16 ; -atomic_set (&priv->clk_usecnt,-1 ); -snprintf (clk_name,sizeof (clk_name),"lcdc%d" , pdev->id); - priv->clk =clk_get (&pdev->dev, clk_name); -if (IS_ERR (priv->clk)) { -dev_err (&pdev->dev,"cannot get clock \"%s\"\n" , clk_name); -return PTR_ERR (priv->clk); - } -if (str) { priv->dot_clk =clk_get (&pdev->dev, str);if (IS_ERR (priv->dot_clk)) {dev_err (&pdev->dev,"cannot get dot clock %s\n" , str); -clk_put (priv->clk);return PTR_ERR (priv->dot_clk); } } - +atomic_set (&priv->hw_usecnt,-1 ); +pm_runtime_enable (priv->dev);return 0 ; }
@@ -714,9 +706,18 @@ static int sh_mobile_lcdc_resume(structreturn sh_mobile_lcdc_start (platform_get_drvdata (pdev)); } +static int sh_mobile_lcdc_runtime_nop (struct device *dev) +{ +/* TODO: implement register save and restore */ + +return 0 ; +} +static struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = { .suspend = sh_mobile_lcdc_suspend, .resume = sh_mobile_lcdc_resume, + .runtime_suspend = sh_mobile_lcdc_runtime_nop, + .runtime_resume = sh_mobile_lcdc_runtime_nop, };static int sh_mobile_lcdc_remove (struct platform_device *pdev);
@@ -753,6 +754,9 @@ static int __init sh_mobile_lcdc_probe(s goto err0; } +/* workaround: allow resume from probe() */ +pm_runtime_put_noidle (&pdev->dev); + error =request_irq (i, sh_mobile_lcdc_irq,IRQF_DISABLED ,dev_name (&pdev->dev), priv);if (error) {
@@ -761,6 +765,7 @@ static int __init sh_mobile_lcdc_probe(s } priv->irq = i; + priv->dev = &pdev->dev;platform_set_drvdata (pdev, priv); pdata = pdev->dev.platform_data;
@@ -896,8 +901,13 @@ static int __init sh_mobile_lcdc_probe(ssh_mobile_lcdc_clk_off (priv); } +/* workaround: balance pm_runtime_put_noidle() call */ +pm_runtime_get_noresume (&pdev->dev);return 0 ; err1: +/* workaround: balance pm_runtime_put_noidle() call */ +pm_runtime_get_noresume (&pdev->dev); +sh_mobile_lcdc_remove (pdev); err0:return error;
@@ -932,7 +942,8 @@ static int sh_mobile_lcdc_remove(structif (priv->dot_clk)clk_put (priv->dot_clk); -clk_put (priv->clk); + +pm_runtime_disable (priv->dev);if (priv->base)iounmap (priv->base);
PATCH 4/4 video: Runtime PM hack for SuperH LCDC driver
From: Magnus Damm <[email protected]>
This patch modifies the SuperH Mobile LCDC framebuffer driver to support Runtime PM. This patch is experimental and is at this point still missing context save and restore support.
With debug messages it is however already possible to see that the deferred io clock management strategy pays off since in that mode the clocks are only turned on for a short period of time to redraw the screen. When the screen is unchanged the clocks are disabled and the driver can be in runtime suspended state.
Regarding pm_runtime_put_noidle()/pm_runtime_get_noresume():
This driver does not work well with the Runtime PM v11 code since it performs runtime_pm_get_sync() from probe() which is not allowed. This driver needs to access hardware registers from probe() so runtime_pm_get_sync() must really succeed in this case so the bus code gets a chance to turn on the hardware device.
---
Changes from V1 prototype:
- use pm_runtime_get_sync() and pm_runtime_put_sync()
- use pm_runtime_disable()
- no need for pm_runtime_set_suspended()
- incomplete runtime pm functions for dev_pm_ops
- work around with pm_runtime_put_noidle()/pm_runtime_get_noresume()
TODO:
- quite a bit
drivers/video/sh_mobile_lcdcfb.c | 47 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-)
drivers/video/sh_mobile_lcdcfb.c +29 -18
@@ -14,6 +14,7 @@#include <linux/mm.h> #include <linux/fb.h> #include <linux/clk.h> +#include <linux/pm_runtime.h> #include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/interrupt.h>
@@ -42,9 +43,9 @@ struct sh_mobile_lcdc_chan {struct sh_mobile_lcdc_priv {void __iomem *base;int irq; -atomic_t clk_usecnt; +atomic_t hw_usecnt; +struct device *dev;struct clk *dot_clk; -struct clk *clk;unsigned long lddckr;struct sh_mobile_lcdc_chan ch[2 ];int started;
@@ -185,8 +186,8 @@ struct sh_mobile_lcdc_sys_bus_ops sh_mobstatic void sh_mobile_lcdc_clk_on (struct sh_mobile_lcdc_priv *priv) { -if (atomic_inc_and_test (&priv->clk_usecnt)) { -clk_enable (priv->clk); +if (atomic_inc_and_test (&priv->hw_usecnt)) { +pm_runtime_get_sync (priv->dev);if (priv->dot_clk)clk_enable (priv->dot_clk); }
@@ -194,10 +195,10 @@ static void sh_mobile_lcdc_clk_on(structstatic void sh_mobile_lcdc_clk_off (struct sh_mobile_lcdc_priv *priv) { -if (atomic_sub_return (1 , &priv->clk_usecnt) =-1 ) { +if (atomic_sub_return (1 , &priv->hw_usecnt) =-1 ) {if (priv->dot_clk)clk_disable (priv->dot_clk); -clk_disable (priv->clk); +pm_runtime_put (priv->dev); } }
@@ -566,7 +567,6 @@ static int sh_mobile_lcdc_setup_clocks(sint clock_source, struct sh_mobile_lcdc_priv *priv) { - char clk_name[8]; char *str;int icksel;
@@ -580,23 +580,15 @@ static int sh_mobile_lcdc_setup_clocks(s priv->lddckr = icksel <<16 ; -atomic_set (&priv->clk_usecnt,-1 ); -snprintf (clk_name,sizeof (clk_name),"lcdc%d" , pdev->id); - priv->clk =clk_get (&pdev->dev, clk_name); -if (IS_ERR (priv->clk)) { -dev_err (&pdev->dev,"cannot get clock \"%s\"\n" , clk_name); -return PTR_ERR (priv->clk); - } -if (str) { priv->dot_clk =clk_get (&pdev->dev, str);if (IS_ERR (priv->dot_clk)) {dev_err (&pdev->dev,"cannot get dot clock %s\n" , str); -clk_put (priv->clk);return PTR_ERR (priv->dot_clk); } } - +atomic_set (&priv->hw_usecnt,-1 ); +pm_runtime_enable (priv->dev);return 0 ; }
@@ -714,9 +706,18 @@ static int sh_mobile_lcdc_resume(structreturn sh_mobile_lcdc_start (platform_get_drvdata (pdev)); } +static int sh_mobile_lcdc_runtime_nop (struct device *dev) +{ +/* TODO: implement register save and restore */ + +return 0 ; +} +static struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = { .suspend = sh_mobile_lcdc_suspend, .resume = sh_mobile_lcdc_resume, + .runtime_suspend = sh_mobile_lcdc_runtime_nop, + .runtime_resume = sh_mobile_lcdc_runtime_nop, };static int sh_mobile_lcdc_remove (struct platform_device *pdev);
@@ -753,6 +754,9 @@ static int __init sh_mobile_lcdc_probe(s goto err0; } +/* workaround: allow resume from probe() */ +pm_runtime_put_noidle (&pdev->dev); + error =request_irq (i, sh_mobile_lcdc_irq,IRQF_DISABLED ,dev_name (&pdev->dev), priv);if (error) {
@@ -761,6 +765,7 @@ static int __init sh_mobile_lcdc_probe(s } priv->irq = i; + priv->dev = &pdev->dev;platform_set_drvdata (pdev, priv); pdata = pdev->dev.platform_data;
@@ -896,8 +901,13 @@ static int __init sh_mobile_lcdc_probe(ssh_mobile_lcdc_clk_off (priv); } +/* workaround: balance pm_runtime_put_noidle() call */ +pm_runtime_get_noresume (&pdev->dev);return 0 ; err1: +/* workaround: balance pm_runtime_put_noidle() call */ +pm_runtime_get_noresume (&pdev->dev); +sh_mobile_lcdc_remove (pdev); err0:return error;
@@ -932,7 +942,8 @@ static int sh_mobile_lcdc_remove(structif (priv->dot_clk)clk_put (priv->dot_clk); -clk_put (priv->clk); + +pm_runtime_disable (priv->dev);if (priv->base)iounmap (priv->base);
Re: [PATCH 04/04] video: Runtime PM hack for SuperH LCDC driver
Quoted 12 lines · Magnus Damm
From: Magnus Damm <[email protected]>
This patch modifies the SuperH Mobile LCDC framebuffer driver to support Runtime PM. This patch is experimental and is at this point still missing context save and restore support.
With debug messages it is however already possible to see that the deferred io clock management strategy pays off since in that mode the clocks are only turned on for a short period of time to redraw the screen. When the screen is unchanged the clocks are disabled and the driver can be in runtime suspended state.
Quoted 5 lines
Regarding pm_runtime_put_noidle()/pm_runtime_get_noresume():
This driver does not work well with the Runtime PM v11 code since it performs
runtime_pm_get_sync()fromprobe()which is not allowed.
It is allowed, but doesn't work as expected.
Quoted 120 lines
This driver needs to access hardware registers from
probe()soruntime_pm_get_sync()must really succeed in this case so the bus code gets a chance to turn on the hardware device.Signed-off-by Magnus Damm <[email protected]>---
Changes from V1 prototype:
- usepm_runtime_get_sync()andpm_runtime_put_sync()
- usepm_runtime_disable()
- no need forpm_runtime_set_suspended()
- incomplete runtime pm functions fordev_pm_ops
- work around with pm_runtime_put_noidle()/pm_runtime_get_noresume()TODO:
- quite a bitdrivers/video/sh_mobile_lcdcfb.c | 47 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-)drivers/video/sh_mobile_lcdcfb.c +18
-17@@ -14,6 +14,7 @@#include <linux/mm.h> #include <linux/fb.h> #include <linux/clk.h> +#include <linux/pm_runtime.h> #include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/interrupt.h> @@ -42,9 +43,9 @@ struct sh_mobile_lcdc_chan {struct sh_mobile_lcdc_priv {void __iomem *base;int irq; -atomic_t clk_usecnt; +atomic_t hw_usecnt; +struct device *dev;struct clk *dot_clk; -struct clk *clk;unsigned long lddckr;struct sh_mobile_lcdc_chan ch[2 ];int started;@@ -185,8 +186,8 @@ struct sh_mobile_lcdc_sys_bus_ops sh_mobstatic void sh_mobile_lcdc_clk_on (struct sh_mobile_lcdc_priv *priv) { -if (atomic_inc_and_test (&priv->clk_usecnt)) { -clk_enable (priv->clk); +if (atomic_inc_and_test (&priv->hw_usecnt)) { +pm_runtime_get_sync (priv->dev);if (priv->dot_clk)clk_enable (priv->dot_clk); }@@ -194,10 +195,10 @@ static void sh_mobile_lcdc_clk_on(structstatic void sh_mobile_lcdc_clk_off (struct sh_mobile_lcdc_priv *priv) { -if (atomic_sub_return (1 , &priv->clk_usecnt) ==-1 ) { +if (atomic_sub_return (1 , &priv->hw_usecnt) ==-1 ) {if (priv->dot_clk)clk_disable (priv->dot_clk); -clk_disable (priv->clk); +pm_runtime_put (priv->dev); } }@@ -566,7 +567,6 @@ static int sh_mobile_lcdc_setup_clocks(sint clock_source, struct sh_mobile_lcdc_priv *priv) { - char clk_name[8]; char *str;int icksel;@@ -580,23 +580,15 @@ static int sh_mobile_lcdc_setup_clocks(s priv->lddckr = icksel <<16 ; -atomic_set (&priv->clk_usecnt,-1 ); -snprintf (clk_name,sizeof (clk_name),"lcdc%d" , pdev->id); - priv->clk =clk_get (&pdev->dev, clk_name); -if (IS_ERR (priv->clk)) { -dev_err (&pdev->dev,"cannot get clock \"%s\"\n" , clk_name); -return PTR_ERR (priv->clk); - } -if (str) { priv->dot_clk =clk_get (&pdev->dev, str);if (IS_ERR (priv->dot_clk)) {dev_err (&pdev->dev,"cannot get dot clock %s\n" , str); -clk_put (priv->clk);return PTR_ERR (priv->dot_clk); } } - +atomic_set (&priv->hw_usecnt,-1 ); +pm_runtime_enable (priv->dev);return 0 ; }@@ -714,9 +706,18 @@ static int sh_mobile_lcdc_resume(structreturn sh_mobile_lcdc_start (platform_get_drvdata (pdev)); } +static int sh_mobile_lcdc_runtime_nop (struct device *dev) +{ +/* TODO: implement register save and restore */ + +return 0 ; +} +static struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = { .suspend = sh_mobile_lcdc_suspend, .resume = sh_mobile_lcdc_resume, + .runtime_suspend = sh_mobile_lcdc_runtime_nop, + .runtime_resume = sh_mobile_lcdc_runtime_nop, };static int sh_mobile_lcdc_remove (struct platform_device *pdev);
drivers/video/sh_mobile_lcdcfb.c static int __init sh_mobile_lcdc_probe(s · line 758
Quoted 5 lines
drivers/video/sh_mobile_lcdcfb.c +2
-0@@ -753,6 +754,9 @@ static int __init sh_mobile_lcdc_probe(s goto err0; } +/* workaround: allow resume from probe() */ +pm_runtime_put_noidle (&pdev->dev);
Why don't you just call pm_runtime_resume(&pdev->dev); from here?
You know that the usage counter has been incremented, because it is .probe(), so that should be safe. And you won't need that pm_runtime_get_noresume(&pdev->dev); below in that case. :-)
Quoted 27 lines
drivers/video/sh_mobile_lcdcfb.c +7
-0+ error =request_irq (i, sh_mobile_lcdc_irq,IRQF_DISABLED ,dev_name (&pdev->dev), priv);if (error) {@@ -761,6 +765,7 @@ static int __init sh_mobile_lcdc_probe(s } priv->irq = i; + priv->dev = &pdev->dev;platform_set_drvdata (pdev, priv); pdata = pdev->dev.platform_data;@@ -896,8 +901,13 @@ static int __init sh_mobile_lcdc_probe(ssh_mobile_lcdc_clk_off (priv); } +/* workaround: balance pm_runtime_put_noidle() call */ +pm_runtime_get_noresume (&pdev->dev);return 0 ; err1: +/* workaround: balance pm_runtime_put_noidle() call */ +pm_runtime_get_noresume (&pdev->dev); +sh_mobile_lcdc_remove (pdev); err0:return error;
drivers/video/sh_mobile_lcdcfb.c static int sh_mobile_lcdc_remove(struct · line 949
Quoted 9 lines
drivers/video/sh_mobile_lcdcfb.c +2
-1@@ -932,7 +942,8 @@ static int sh_mobile_lcdc_remove(structif (priv->dot_clk)clk_put (priv->dot_clk); -clk_put (priv->clk); + +pm_runtime_disable (priv->dev);if (priv->base)iounmap (priv->base);
Best,
Rafael
Re: [PATCH 04/04] video: Runtime PM hack for SuperH LCDC driver
In reply to Magnus DammQuoted 12 lines · Magnus Damm
From: Magnus Damm <[email protected]>
This patch modifies the SuperH Mobile LCDC framebuffer driver to support Runtime PM. This patch is experimental and is at this point still missing context save and restore support.
With debug messages it is however already possible to see that the deferred io clock management strategy pays off since in that mode the clocks are only turned on for a short period of time to redraw the screen. When the screen is unchanged the clocks are disabled and the driver can be in runtime suspended state.
Quoted 5 lines
Regarding pm_runtime_put_noidle()/pm_runtime_get_noresume():
This driver does not work well with the Runtime PM v11 code since it performs
runtime_pm_get_sync()fromprobe()which is not allowed.
It is allowed, but doesn't work as expected.
Quoted 120 lines
This driver needs to access hardware registers from
probe()soruntime_pm_get_sync()must really succeed in this case so the bus code gets a chance to turn on the hardware device.Signed-off-by Magnus Damm <[email protected]>---
Changes from V1 prototype:
- usepm_runtime_get_sync()andpm_runtime_put_sync()
- usepm_runtime_disable()
- no need forpm_runtime_set_suspended()
- incomplete runtime pm functions fordev_pm_ops
- work around with pm_runtime_put_noidle()/pm_runtime_get_noresume()TODO:
- quite a bitdrivers/video/sh_mobile_lcdcfb.c | 47 +++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-)drivers/video/sh_mobile_lcdcfb.c +18
-17@@ -14,6 +14,7 @@#include <linux/mm.h> #include <linux/fb.h> #include <linux/clk.h> +#include <linux/pm_runtime.h> #include <linux/platform_device.h> #include <linux/dma-mapping.h> #include <linux/interrupt.h> @@ -42,9 +43,9 @@ struct sh_mobile_lcdc_chan {struct sh_mobile_lcdc_priv {void __iomem *base;int irq; -atomic_t clk_usecnt; +atomic_t hw_usecnt; +struct device *dev;struct clk *dot_clk; -struct clk *clk;unsigned long lddckr;struct sh_mobile_lcdc_chan ch[2 ];int started;@@ -185,8 +186,8 @@ struct sh_mobile_lcdc_sys_bus_ops sh_mobstatic void sh_mobile_lcdc_clk_on (struct sh_mobile_lcdc_priv *priv) { -if (atomic_inc_and_test (&priv->clk_usecnt)) { -clk_enable (priv->clk); +if (atomic_inc_and_test (&priv->hw_usecnt)) { +pm_runtime_get_sync (priv->dev);if (priv->dot_clk)clk_enable (priv->dot_clk); }@@ -194,10 +195,10 @@ static void sh_mobile_lcdc_clk_on(structstatic void sh_mobile_lcdc_clk_off (struct sh_mobile_lcdc_priv *priv) { -if (atomic_sub_return (1 , &priv->clk_usecnt) =-1 ) { +if (atomic_sub_return (1 , &priv->hw_usecnt) =-1 ) {if (priv->dot_clk)clk_disable (priv->dot_clk); -clk_disable (priv->clk); +pm_runtime_put (priv->dev); } }@@ -566,7 +567,6 @@ static int sh_mobile_lcdc_setup_clocks(sint clock_source, struct sh_mobile_lcdc_priv *priv) { - char clk_name[8]; char *str;int icksel;@@ -580,23 +580,15 @@ static int sh_mobile_lcdc_setup_clocks(s priv->lddckr = icksel <<16 ; -atomic_set (&priv->clk_usecnt,-1 ); -snprintf (clk_name,sizeof (clk_name),"lcdc%d" , pdev->id); - priv->clk =clk_get (&pdev->dev, clk_name); -if (IS_ERR (priv->clk)) { -dev_err (&pdev->dev,"cannot get clock \"%s\"\n" , clk_name); -return PTR_ERR (priv->clk); - } -if (str) { priv->dot_clk =clk_get (&pdev->dev, str);if (IS_ERR (priv->dot_clk)) {dev_err (&pdev->dev,"cannot get dot clock %s\n" , str); -clk_put (priv->clk);return PTR_ERR (priv->dot_clk); } } - +atomic_set (&priv->hw_usecnt,-1 ); +pm_runtime_enable (priv->dev);return 0 ; }@@ -714,9 +706,18 @@ static int sh_mobile_lcdc_resume(structreturn sh_mobile_lcdc_start (platform_get_drvdata (pdev)); } +static int sh_mobile_lcdc_runtime_nop (struct device *dev) +{ +/* TODO: implement register save and restore */ + +return 0 ; +} +static struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = { .suspend = sh_mobile_lcdc_suspend, .resume = sh_mobile_lcdc_resume, + .runtime_suspend = sh_mobile_lcdc_runtime_nop, + .runtime_resume = sh_mobile_lcdc_runtime_nop, };static int sh_mobile_lcdc_remove (struct platform_device *pdev);
drivers/video/sh_mobile_lcdcfb.c static int __init sh_mobile_lcdc_probe(s · line 758
Quoted 5 lines
drivers/video/sh_mobile_lcdcfb.c +2
-0@@ -753,6 +754,9 @@ static int __init sh_mobile_lcdc_probe(s goto err0; } +/* workaround: allow resume from probe() */ +pm_runtime_put_noidle (&pdev->dev);
Why don't you just call pm_runtime_resume(&pdev->dev); from here?
You know that the usage counter has been incremented, because it is .probe(), so that should be safe. And you won't need that pm_runtime_get_noresume(&pdev->dev); below in that case. :-)
Quoted 27 lines
drivers/video/sh_mobile_lcdcfb.c +7
-0+ error =request_irq (i, sh_mobile_lcdc_irq,IRQF_DISABLED ,dev_name (&pdev->dev), priv);if (error) {@@ -761,6 +765,7 @@ static int __init sh_mobile_lcdc_probe(s } priv->irq = i; + priv->dev = &pdev->dev;platform_set_drvdata (pdev, priv); pdata = pdev->dev.platform_data;@@ -896,8 +901,13 @@ static int __init sh_mobile_lcdc_probe(ssh_mobile_lcdc_clk_off (priv); } +/* workaround: balance pm_runtime_put_noidle() call */ +pm_runtime_get_noresume (&pdev->dev);return 0 ; err1: +/* workaround: balance pm_runtime_put_noidle() call */ +pm_runtime_get_noresume (&pdev->dev); +sh_mobile_lcdc_remove (pdev); err0:return error;
drivers/video/sh_mobile_lcdcfb.c static int sh_mobile_lcdc_remove(struct · line 949
Quoted 9 lines
drivers/video/sh_mobile_lcdcfb.c +2
-1@@ -932,7 +942,8 @@ static int sh_mobile_lcdc_remove(structif (priv->dot_clk)clk_put (priv->dot_clk); -clk_put (priv->clk); + +pm_runtime_disable (priv->dev);if (priv->base)iounmap (priv->base);
Best,
Rafael