Skip to contentSkip to conversation

sh: Runtime PM Prototype for SuperH Mobile

RFC PATCH New Magnus Damm 1 participant 7 messages Jul 9, 2009

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

cover sh: Runtime PM Prototype for SuperH Mobile

sh: Runtime PM Prototype for SuperH Mobile

[PATCH 01/06] Driver Core: Runtime PM callbacks for the Platform Bus [PATCH 02/06] sh: Add support for multiple hwblk counters [PATCH 03/06] sh: Runtime PM for SuperH Mobile
[PATCH 04/06] sh: Runtime PM for sh7722 and Migo-R
[PATCH 05/06] i2c: Runtime PM for i2c-sh_mobile.c
[PATCH 06/06] video: Runtime PM for sh_mobile_lcdcfb.c

This is the first complete Runtime PM prototype for SuperH Mobile. The patches above should be applied on top of the sh-2.6 git tree and the following ones:
"PM: Introduce core framework for run-time PM of I/O devices (rev. 9)" "Driver Core: Add platform device arch data V3"

Looking forward to hear what you think. Before, during or after the PM Summit!

---

 arch/sh/boards/mach-migor/setup.c        |    9 +
 arch/sh/include/asm/device.h             |   16 ++
 arch/sh/include/asm/hwblk.h              |   17 ++
 arch/sh/kernel/cpu/hwblk.c               |   69 ++++++----
 arch/sh/kernel/cpu/sh4a/hwblk-sh7722.c   |   14 +-
 arch/sh/kernel/cpu/sh4a/setup-sh7722.c   |   31 ++++
 arch/sh/kernel/cpu/shmobile/Makefile     |    1 
 arch/sh/kernel/cpu/shmobile/pm_runtime.c |  206 ++++++++++++++++++++++++++++++
 drivers/base/platform.c                  |   31 ++++
 drivers/i2c/busses/i2c-sh_mobile.c       |   21 +++
 drivers/video/sh_mobile_lcdcfb.c         |   31 +---
 11 files changed, 398 insertions(+), 48 deletions(-)
#1 lore raw

PATCH 1/6 Driver Core: Runtime PM callbacks for the Platform Bus

From: Magnus Damm <[email protected]>

This patch adds default Runtime PM callbacks to the dev_pm_ops belonging to the platform bus. The callbacks are weak symbols that architecture specific code may override. Also, call pm_runtime_enable() for the platform bus struct device.

---

 drivers/base/platform.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/base/platform.c +31 -0
@@ -17,6 +17,7 @@
 #include <linux/bootmem.h>
 #include <linux/err.h>
 #include <linux/slab.h>
+#include <linux/pm_runtime.h>
 
 #include "base.h"
 
@@ -925,6 +926,30 @@ static int platform_pm_restore_noirq(str
 
 #endif /* !CONFIG_HIBERNATION */
 
+#ifdef CONFIG_PM_RUNTIME
+
+int __weak platform_pm_runtime_suspend(struct device *dev)
+{
+	return -EINVAL;
+};
+
+int __weak platform_pm_runtime_resume(struct device *dev)
+{
+	return -EINVAL;
+};
+
+void __weak platform_pm_runtime_idle(struct device *dev)
+{
+};
+
+#else /* !CONFIG_PM_RUNTIME */
+
+#define platform_pm_runtime_suspend NULL
+#define platform_pm_runtime_resume NULL
+#define platform_pm_runtime_idle NULL
+
+#endif /* !CONFIG_PM_RUNTIME */
+
 static struct dev_pm_ops platform_dev_pm_ops = {
 	.prepare = platform_pm_prepare,
 	.complete = platform_pm_complete,
@@ -940,6 +965,9 @@ static struct dev_pm_ops platform_dev_pm
 	.thaw_noirq = platform_pm_thaw_noirq,
 	.poweroff_noirq = platform_pm_poweroff_noirq,
 	.restore_noirq = platform_pm_restore_noirq,
+	.runtime_suspend = platform_pm_runtime_suspend,
+	.runtime_resume = platform_pm_runtime_resume,
+	.runtime_idle = platform_pm_runtime_idle,
 };
 
 #define PLATFORM_PM_OPS_PTR	(&platform_dev_pm_ops)
@@ -968,6 +996,9 @@ int __init platform_bus_init(void)
 	error = device_register(&platform_bus);
 	if (error)
 		return error;
+
+	pm_runtime_enable(&platform_bus);
+
 	error =  bus_register(&platform_bus_type);
 	if (error)
 		device_unregister(&platform_bus);
#2 lore raw

PATCH 2/6 sh: Add support for multiple hwblk counters

In reply to Magnus Damm

From: Magnus Damm <[email protected]>

Extend the SuperH hwblk code to support more than one counter. This is needed by the Runtime PM prototype implementation.

---

 arch/sh/include/asm/hwblk.h            |   13 +++++-
 arch/sh/kernel/cpu/hwblk.c             |   69 +++++++++++++++++++++-----------
 arch/sh/kernel/cpu/sh4a/hwblk-sh7722.c |    4 -
 3 files changed, 60 insertions(+), 26 deletions(-)
arch/sh/include/asm/hwblk.h +11 -2
@@ -4,6 +4,9 @@
 #include <asm/clock.h>
 #include <asm/io.h>
 
+#define HWBLK_CNT_USAGE 0
+#define HWBLK_CNT_NR 1
+
 #define HWBLK_AREA_FLAG_PARENT (1 << 0) /* valid parent */
 
 #define HWBLK_AREA(_flags, _parent)		\
@@ -13,7 +16,7 @@
 }
 
 struct hwblk_area {
-	unsigned long cnt;
+	int cnt[HWBLK_CNT_NR];
 	unsigned char parent;
 	unsigned char flags;
 };
@@ -29,7 +32,7 @@ struct hwblk {
 	void __iomem *mstp;
 	unsigned char bit;
 	unsigned char area;
-	unsigned long cnt;
+	int cnt[HWBLK_CNT_NR];
 };
 
 struct hwblk_info {
@@ -46,6 +49,12 @@ int arch_hwblk_sleep_mode(void);
 int hwblk_register(struct hwblk_info *info);
 int hwblk_init(void);
 
+void hwblk_enable(struct hwblk_info *info, int hwblk);
+void hwblk_disable(struct hwblk_info *info, int hwblk);
+
+void hwblk_cnt_inc(struct hwblk_info *info, int hwblk, int cnt);
+void hwblk_cnt_dec(struct hwblk_info *info, int hwblk, int cnt);
+
 /* allow clocks to enable and disable hardware blocks */
 #define SH_HWBLK_CLK(_name, _id, _parent, _hwblk, _flags)	\
 {							\
arch/sh/kernel/cpu/hwblk.c +47 -22

112 lines not on this page · raw message

arch/sh/kernel/cpu/sh4a/hwblk-sh7722.c +2 -2
@@ -91,10 +91,10 @@ static struct hwblk_info sh7722_hwblk_in
 
 int arch_hwblk_sleep_mode(void)
 {
-	if (!sh7722_hwblk_area[CORE_AREA].cnt)
+	if (!sh7722_hwblk_area[CORE_AREA].cnt[HWBLK_CNT_USAGE])
 		return SUSP_SH_STANDBY | SUSP_SH_SF;
 
-	if (!sh7722_hwblk_area[CORE_AREA_BM].cnt)
+	if (!sh7722_hwblk_area[CORE_AREA_BM].cnt[HWBLK_CNT_USAGE])
 		return SUSP_SH_SLEEP | SUSP_SH_SF;
 
 	return SUSP_SH_SLEEP;
#3 lore raw

PATCH 3/6 sh: Runtime PM for SuperH Mobile

In reply to Magnus Damm

From: Magnus Damm <[email protected]>

This patch contains the processor independent part of the SuperH Mobile Runtime PM prototype.

The patch adds fields for Runtime PM to the architecture specific part of struct platform_device. The most important field is hw_blk_id which contains an id for the hardware block within the SoC.

This hwblk id is used by the SuperH specific Runtime PM callbacks for the platform bus. Multiple devices are allowed to use the same hwblk id.

The SuperH specific Runtime PM platform bus callbacks platform_pm_runtime_suspend() and platform_pm_runtime_resume() control clocks and adds/removes the platform device to a list of platform devices that has had their bus suspend callback executed.

The driver Runtime PM suspend callbacks get invoked when cpuidle discovers that all devices in the power domain has had their bus suspend callback executed. When all devices have been suspended using their driver Runtime PM suspend callbacks, cpuidle is allowed to enter the deepest mode which involves turning off power to the domain.

Please note that the code is very experimental. Alan kindly suggested a cleaner way to do this using the idle callback, but for that to work I need to rearrange all platform devices.

---

 arch/sh/include/asm/device.h             |   16 ++
 arch/sh/include/asm/hwblk.h              |    4 
 arch/sh/kernel/cpu/shmobile/Makefile     |    1 
 arch/sh/kernel/cpu/shmobile/pm_runtime.c |  206 ++++++++++++++++++++++++++++++
 4 files changed, 225 insertions(+), 2 deletions(-)
arch/sh/include/asm/device.h +15 -1
@@ -3,7 +3,9 @@
  *
  * This file is released under the GPLv2
  */
-#include <asm-generic/device.h>
+
+struct dev_archdata {
+};
 
 struct platform_device;
 /* allocate contiguous memory chunk and fill in struct resource */
@@ -12,3 +14,15 @@ int platform_resource_setup_memory(struc
 
 void plat_early_device_setup(void);
 
+#define PDEV_ARCHDATA_FLAG_INIT 0
+#define PDEV_ARCHDATA_FLAG_LIST 1
+#define PDEV_ARCHDATA_FLAG_SUSP 2
+
+struct pdev_archdata {
+#ifdef CONFIG_ARCH_SHMOBILE
+	int hw_blk_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 +206 -0

206 lines not on this page · raw message

#4 lore raw

PATCH 4/6 sh: Runtime PM for sh7722 and Migo-R

In reply to Magnus Damm

From: Magnus Damm <[email protected]>

This patch contains sh7722 processor specific Runtime PM code along with some Migo-R board code that deals with sh7722.

For each platform device within the SoC a hwblk id is added to the architecture specific platform device data area. The hwblk code for sh7722 which is invoked by cpuidle is extended in a hackish way to tell the system to start driver suspending.

---

 arch/sh/boards/mach-migor/setup.c      |    9 +++++++++
 arch/sh/kernel/cpu/sh4a/hwblk-sh7722.c |   10 +++++++++-
 arch/sh/kernel/cpu/sh4a/setup-sh7722.c |   31 +++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
arch/sh/boards/mach-migor/setup.c +9 -0
@@ -98,6 +98,9 @@ static struct platform_device sh_keysc_d
 	.dev	= {
 		.platform_data	= &sh_keysc_info,
 	},
+	.archdata = {
+		.hw_blk_id = HWBLK_KEYSC,
+	},
 };
 
 static struct mtd_partition migor_nor_flash_partitions[] =
@@ -292,6 +295,9 @@ static struct platform_device migor_lcdc
 	.dev	= {
 		.platform_data	= &sh_mobile_lcdc_info,
 	},
+	.archdata = {
+		.hw_blk_id = HWBLK_LCDC,
+	},
 };
 
 static struct clk *camera_clk;
@@ -379,6 +385,9 @@ static struct platform_device migor_ceu_
 	.dev	= {
 		.platform_data	= &sh_mobile_ceu_info,
 	},
+	.archdata = {
+		.hw_blk_id = HWBLK_CEU,
+	},
 };
 
 struct spi_gpio_platform_data sdcard_cn9_platform_data = {
arch/sh/kernel/cpu/sh4a/hwblk-sh7722.c +9 -1
@@ -89,10 +89,18 @@ static struct hwblk_info sh7722_hwblk_in
 	.nr_hwblks = ARRAY_SIZE(sh7722_hwblk),
 };
 
+void platform_pm_runtime_suspend_idle(void); /* FIXME */
+
 int arch_hwblk_sleep_mode(void)
 {
-	if (!sh7722_hwblk_area[CORE_AREA].cnt[HWBLK_CNT_USAGE])
+	if (!sh7722_hwblk_area[CORE_AREA].cnt[HWBLK_CNT_USAGE]) {
+		if (sh7722_hwblk_area[CORE_AREA].cnt[HWBLK_CNT_IDLE])
+			platform_pm_runtime_suspend_idle();
+		else
+			return SUSP_SH_USTANDBY | SUSP_SH_SF;
+
 		return SUSP_SH_STANDBY | SUSP_SH_SF;
+	}
 
 	if (!sh7722_hwblk_area[CORE_AREA_BM].cnt[HWBLK_CNT_USAGE])
 		return SUSP_SH_SLEEP | SUSP_SH_SF;
arch/sh/kernel/cpu/sh4a/setup-sh7722.c +31 -0
@@ -16,6 +16,7 @@
 #include <linux/sh_timer.h>
 #include <asm/clock.h>
 #include <asm/mmzone.h>
+#include <cpu/sh7722.h>
 
 static struct resource rtc_resources[] = {
 	[0] = {
@@ -45,6 +46,9 @@ static struct platform_device rtc_device
 	.id		= -1,
 	.num_resources	= ARRAY_SIZE(rtc_resources),
 	.resource	= rtc_resources,
+	.archdata = {
+		.hw_blk_id = HWBLK_RTC,
+	},
 };
 
 static struct resource usbf_resources[] = {
@@ -70,6 +74,9 @@ static struct platform_device usbf_devic
 	},
 	.num_resources	= ARRAY_SIZE(usbf_resources),
 	.resource	= usbf_resources,
+	.archdata = {
+		.hw_blk_id = HWBLK_USBF,
+	},
 };
 
 static struct resource iic_resources[] = {
@@ -91,6 +98,9 @@ static struct platform_device iic_device
 	.id             = 0, /* "i2c0" clock */
 	.num_resources  = ARRAY_SIZE(iic_resources),
 	.resource       = iic_resources,
+	.archdata = {
+		.hw_blk_id = HWBLK_IIC,
+	},
 };
 
 static struct uio_info vpu_platform_data = {
@@ -119,6 +129,9 @@ static struct platform_device vpu_device
 	},
 	.resource	= vpu_resources,
 	.num_resources	= ARRAY_SIZE(vpu_resources),
+	.archdata = {
+		.hw_blk_id = HWBLK_VPU,
+	},
 };
 
 static struct uio_info veu_platform_data = {
@@ -147,6 +160,9 @@ static struct platform_device veu_device
 	},
 	.resource	= veu_resources,
 	.num_resources	= ARRAY_SIZE(veu_resources),
+	.archdata = {
+		.hw_blk_id = HWBLK_VEU,
+	},
 };
 
 static struct uio_info jpu_platform_data = {
@@ -175,6 +191,9 @@ static struct platform_device jpu_device
 	},
 	.resource	= jpu_resources,
 	.num_resources	= ARRAY_SIZE(jpu_resources),
+	.archdata = {
+		.hw_blk_id = HWBLK_JPU,
+	},
 };
 
 static struct sh_timer_config cmt_platform_data = {
@@ -207,6 +226,9 @@ static struct platform_device cmt_device
 	},
 	.resource	= cmt_resources,
 	.num_resources	= ARRAY_SIZE(cmt_resources),
+	.archdata = {
+		.hw_blk_id = HWBLK_CMT,
+	},
 };
 
 static struct sh_timer_config tmu0_platform_data = {
@@ -238,6 +260,9 @@ static struct platform_device tmu0_devic
 	},
 	.resource	= tmu0_resources,
 	.num_resources	= ARRAY_SIZE(tmu0_resources),
+	.archdata = {
+		.hw_blk_id = HWBLK_TMU,
+	},
 };
 
 static struct sh_timer_config tmu1_platform_data = {
@@ -269,6 +294,9 @@ static struct platform_device tmu1_devic
 	},
 	.resource	= tmu1_resources,
 	.num_resources	= ARRAY_SIZE(tmu1_resources),
+	.archdata = {
+		.hw_blk_id = HWBLK_TMU,
+	},
 };
 
 static struct sh_timer_config tmu2_platform_data = {
@@ -299,6 +327,9 @@ static struct platform_device tmu2_devic
 	},
 	.resource	= tmu2_resources,
 	.num_resources	= ARRAY_SIZE(tmu2_resources),
+	.archdata = {
+		.hw_blk_id = HWBLK_TMU,
+	},
 };
 
 static struct plat_sci_port sci_platform_data[] = {
#5 lore raw

PATCH 5/6 i2c: Runtime PM for i2c-sh_mobile.c

In reply to Magnus Damm

From: 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 not needed becuase the registers are always re-initialized.

---

 drivers/i2c/busses/i2c-sh_mobile.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/i2c/busses/i2c-sh_mobile.c +21 -0
@@ -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,6 +166,9 @@ static void activate_ch(struct sh_mobile
 	u_int32_t denom;
 	u_int32_t tmp;
 
+	/* Runtime PM must wake up device */
+	pm_runtime_resume(pd->dev);
+
 	/* Make sure the clock is enabled */
 	clk_enable(pd->clk);
 
@@ -215,6 +219,9 @@ static void deactivate_ch(struct sh_mobi
 
 	/* Disable clock */
 	clk_disable(pd->clk);
+
+	/* Runtime PM code may suspend now */
+	pm_runtime_suspend(pd->dev);
 }
 
 static unsigned char i2c_op(struct sh_mobile_i2c_data *pd,
@@ -572,6 +579,20 @@ 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_set_suspended(&dev->dev);
+	pm_runtime_enable(&dev->dev);
+
 	/* setup the private data */
 	adap = &pd->adap;
 	i2c_set_adapdata(adap, pd);
#6 lore raw

PATCH 6/6 video: Runtime PM for sh_mobile_lcdcfb.c

In reply to Magnus Damm

From: Magnus Damm <[email protected]>

This patch modifies the SuperH Mobile LCDC framebuffer driver to support Runtime PM. This patch is very experimental and is missing context save and restore support.

At this early point 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.

---

 drivers/video/sh_mobile_lcdcfb.c |   31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)
drivers/video/sh_mobile_lcdcfb.c +12 -19
@@ -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_mob
 
 static 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_resume(priv->dev);
 		if (priv->dot_clk)
 			clk_enable(priv->dot_clk);
 	}
@@ -194,10 +195,10 @@ static void sh_mobile_lcdc_clk_on(struct
 
 static 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_schedule_suspend(priv->dev, 0);
 	}
 }
 
@@ -566,7 +567,6 @@ static int sh_mobile_lcdc_setup_clocks(s
 				       int clock_source,
 				       struct sh_mobile_lcdc_priv *priv)
 {
-	char clk_name[8];
 	char *str;
 	int icksel;
 
@@ -580,23 +580,17 @@ 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_suspend_ignore_children(priv->dev, true);
+	pm_runtime_set_suspended(priv->dev);
+	pm_runtime_enable(priv->dev);
 	return 0;
 }
 
@@ -761,6 +755,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;
 
@@ -888,7 +883,6 @@ static int __init sh_mobile_lcdc_probe(s
 		if (info->fbdefio)
 			sh_mobile_lcdc_clk_off(priv);
 	}
-
 	return 0;
  err1:
 	sh_mobile_lcdc_remove(pdev);
@@ -924,7 +918,6 @@ static int sh_mobile_lcdc_remove(struct 
 
 	if (priv->dot_clk)
 		clk_put(priv->dot_clk);
-	clk_put(priv->clk);
 
 	if (priv->base)
 		iounmap(priv->base);