All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/06][RFC] sh: Runtime PM Prototype for SuperH Mobile
@ 2009-07-09 15:19 Magnus Damm
  2009-07-09 15:19 ` [PATCH 01/06] Driver Core: Runtime PM callbacks for the Platform Bus Magnus Damm
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Magnus Damm @ 2009-07-09 15:19 UTC (permalink / raw)
  To: linux-sh

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!

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 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(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 01/06] Driver Core: Runtime PM callbacks for the Platform Bus
  2009-07-09 15:19 [PATCH 00/06][RFC] sh: Runtime PM Prototype for SuperH Mobile Magnus Damm
@ 2009-07-09 15:19 ` Magnus Damm
  2009-07-09 15:19 ` [PATCH 02/06] sh: Add support for multiple hwblk counters Magnus Damm
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Magnus Damm @ 2009-07-09 15:19 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-sh, gregkh

From: Magnus Damm <damm@igel.co.jp>

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.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 drivers/base/platform.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

--- 0001/drivers/base/platform.c
+++ work/drivers/base/platform.c	2009-06-25 18:58:56.000000000 +0900
@@ -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);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 02/06] sh: Add support for multiple hwblk counters
  2009-07-09 15:19 [PATCH 00/06][RFC] sh: Runtime PM Prototype for SuperH Mobile Magnus Damm
  2009-07-09 15:19 ` [PATCH 01/06] Driver Core: Runtime PM callbacks for the Platform Bus Magnus Damm
@ 2009-07-09 15:19 ` Magnus Damm
  2009-07-09 15:19 ` [PATCH 03/06] sh: Runtime PM for SuperH Mobile Magnus Damm
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Magnus Damm @ 2009-07-09 15:19 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-sh, gregkh

From: Magnus Damm <damm@igel.co.jp>

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

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 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(-)

--- 0001/arch/sh/include/asm/hwblk.h
+++ work/arch/sh/include/asm/hwblk.h	2009-07-09 18:38:04.000000000 +0900
@@ -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)	\
 {							\
--- 0001/arch/sh/kernel/cpu/hwblk.c
+++ work/arch/sh/kernel/cpu/hwblk.c	2009-07-09 18:34:46.000000000 +0900
@@ -9,38 +9,64 @@
 
 static DEFINE_SPINLOCK(hwblk_lock);
 
-static void hwblk_area_inc(struct hwblk_info *info, int area)
+static void hwblk_area_mod_cnt(struct hwblk_info *info,
+			       int area, int counter, int value, int goal)
 {
 	struct hwblk_area *hap = info->areas + area;
 
-	hap->cnt++;
-	if (hap->cnt == 1)
-		if (hap->flags & HWBLK_AREA_FLAG_PARENT)
-			hwblk_area_inc(info, hap->parent);
+	hap->cnt[counter] += value;
+
+	if (hap->cnt[counter] != goal)
+		return;
+
+	if (hap->flags & HWBLK_AREA_FLAG_PARENT)
+		hwblk_area_mod_cnt(info, hap->parent, counter, value, goal);
 }
 
-static void hwblk_area_dec(struct hwblk_info *info, int area)
+
+static int __hwblk_mod_cnt(struct hwblk_info *info, int hwblk,
+			  int counter, int value, int goal)
 {
-	struct hwblk_area *hap = info->areas + area;
+	struct hwblk *hp = info->hwblks + hwblk;
+
+	hp->cnt[counter] += value;
+	if (hp->cnt[counter] == goal)
+		hwblk_area_mod_cnt(info, hp->area, counter, value, goal);
 
-	if (hap->cnt == 1)
-		if (hap->flags & HWBLK_AREA_FLAG_PARENT)
-			hwblk_area_dec(info, hap->parent);
-	hap->cnt--;
+	return hp->cnt[counter];
 }
 
-static void hwblk_enable(struct hwblk_info *info, int hwblk)
+static void hwblk_mod_cnt(struct hwblk_info *info, int hwblk,
+			  int counter, int value, int goal)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&hwblk_lock, flags);
+	__hwblk_mod_cnt(info, hwblk, counter, value, goal);
+	spin_unlock_irqrestore(&hwblk_lock, flags);
+}
+
+void hwblk_cnt_inc(struct hwblk_info *info, int hwblk, int counter)
+{
+	hwblk_mod_cnt(info, hwblk, counter, 1, 1);
+}
+
+void hwblk_cnt_dec(struct hwblk_info *info, int hwblk, int counter)
+{
+	hwblk_mod_cnt(info, hwblk, counter, -1, 0);
+}
+
+void hwblk_enable(struct hwblk_info *info, int hwblk)
 {
 	struct hwblk *hp = info->hwblks + hwblk;
 	unsigned long tmp;
 	unsigned long flags;
+	int ret;
 
 	spin_lock_irqsave(&hwblk_lock, flags);
 
-	hp->cnt++;
-	if (hp->cnt == 1) {
-		hwblk_area_inc(info, hp->area);
-
+	ret = __hwblk_mod_cnt(info, hwblk, HWBLK_CNT_USAGE, 1, 1);
+	if (ret == 1) {
 		tmp = __raw_readl(hp->mstp);
 		tmp &= ~(1 << hp->bit);
 		__raw_writel(tmp, hp->mstp);
@@ -49,27 +75,26 @@ static void hwblk_enable(struct hwblk_in
 	spin_unlock_irqrestore(&hwblk_lock, flags);
 }
 
-static void hwblk_disable(struct hwblk_info *info, int hwblk)
+void hwblk_disable(struct hwblk_info *info, int hwblk)
 {
 	struct hwblk *hp = info->hwblks + hwblk;
 	unsigned long tmp;
 	unsigned long flags;
+	int ret;
 
 	spin_lock_irqsave(&hwblk_lock, flags);
 
-	if (hp->cnt == 1) {
-		hwblk_area_dec(info, hp->area);
-
+	ret = __hwblk_mod_cnt(info, hwblk, HWBLK_CNT_USAGE, -1, 0);
+	if (ret == 0) {
 		tmp = __raw_readl(hp->mstp);
 		tmp |= 1 << hp->bit;
 		__raw_writel(tmp, hp->mstp);
 	}
-	hp->cnt--;
 
 	spin_unlock_irqrestore(&hwblk_lock, flags);
 }
 
-static struct hwblk_info *hwblk_info;
+struct hwblk_info *hwblk_info;
 
 int __init hwblk_register(struct hwblk_info *info)
 {
--- 0001/arch/sh/kernel/cpu/sh4a/hwblk-sh7722.c
+++ work/arch/sh/kernel/cpu/sh4a/hwblk-sh7722.c	2009-07-09 18:38:48.000000000 +0900
@@ -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;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 03/06] sh: Runtime PM for SuperH Mobile
  2009-07-09 15:19 [PATCH 00/06][RFC] sh: Runtime PM Prototype for SuperH Mobile Magnus Damm
  2009-07-09 15:19 ` [PATCH 01/06] Driver Core: Runtime PM callbacks for the Platform Bus Magnus Damm
  2009-07-09 15:19 ` [PATCH 02/06] sh: Add support for multiple hwblk counters Magnus Damm
@ 2009-07-09 15:19 ` Magnus Damm
  2009-07-09 15:20 ` [PATCH 04/06] sh: Runtime PM for sh7722 and Migo-R Magnus Damm
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Magnus Damm @ 2009-07-09 15:19 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-sh, gregkh

From: Magnus Damm <damm@igel.co.jp>

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.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 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(-)

--- 0001/arch/sh/include/asm/device.h
+++ work/arch/sh/include/asm/device.h	2009-07-09 18:41:09.000000000 +0900
@@ -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
+};
--- 0005/arch/sh/include/asm/hwblk.h
+++ work/arch/sh/include/asm/hwblk.h	2009-07-09 18:42:49.000000000 +0900
@@ -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 */
 
--- 0001/arch/sh/kernel/cpu/shmobile/Makefile
+++ work/arch/sh/kernel/cpu/shmobile/Makefile	2009-07-09 18:41:12.000000000 +0900
@@ -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
--- /dev/null
+++ work/arch/sh/kernel/cpu/shmobile/pm_runtime.c	2009-07-09 18:41:12.000000000 +0900
@@ -0,0 +1,206 @@
+/*
+ * arch/sh/kernel/cpu/shmobile/pm_runtime.c
+ *
+ * Runtime PM support code for SuperH Mobile
+ *
+ *  Copyright (C) 2009 Magnus Damm
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/io.h>
+#include <linux/pm_runtime.h>
+#include <linux/platform_device.h>
+#include <asm/hwblk.h>
+
+static DEFINE_SPINLOCK(hwblk_idle_lock);
+static LIST_HEAD(hwblk_idle_list);
+
+extern struct hwblk_info *hwblk_info;
+
+static void platform_pm_runtime_work(struct work_struct *work)
+{
+	struct platform_device *pdev = container_of(work,
+						    struct platform_device,
+						    archdata.work);
+	struct device *dev = &pdev->dev;
+	struct dev_pm_ops *dev_pm_ops = NULL;
+	unsigned long flags;
+	int hwblk = pdev->archdata.hw_blk_id;
+	int ret = 0;
+
+	pr_info("platform_pm_runtime_work() suspending \"%s\" [%d]\n",
+		dev_name(dev), hwblk);
+
+	if (dev->driver && dev->driver->pm)
+		dev_pm_ops = dev->driver->pm;
+
+	if (dev_pm_ops && dev_pm_ops->runtime_suspend) {
+		hwblk_enable(hwblk_info, hwblk);
+		ret = dev_pm_ops->runtime_suspend(dev);
+		hwblk_disable(hwblk_info, hwblk);
+	}
+
+	if (ret)
+		return;
+
+	/* remove device from idle list and decrease idle count */
+	spin_lock_irqsave(&hwblk_idle_lock, flags);
+	if (test_bit(PDEV_ARCHDATA_FLAG_LIST, &pdev->archdata.flags)) {
+		list_del(&pdev->archdata.entry);
+		__clear_bit(PDEV_ARCHDATA_FLAG_LIST, &pdev->archdata.flags);
+		__set_bit(PDEV_ARCHDATA_FLAG_SUSP, &pdev->archdata.flags);
+		hwblk_cnt_dec(hwblk_info, hwblk, HWBLK_CNT_IDLE);
+	}
+	spin_unlock_irqrestore(&hwblk_idle_lock, flags);
+
+	pr_info("platform_pm_runtime_work() suspended \"%s\" [%d]\n",
+		dev_name(dev), hwblk);
+}
+
+void platform_pm_runtime_suspend_idle(void)
+{
+	struct platform_device *pdev;
+	unsigned long flags;
+
+	/* schedule suspend for all devices on the idle list */
+	spin_lock_irqsave(&hwblk_idle_lock, flags);
+	list_for_each_entry(pdev, &hwblk_idle_list, archdata.entry)
+		schedule_work(&pdev->archdata.work);
+	spin_unlock_irqrestore(&hwblk_idle_lock, flags);
+}
+
+int platform_pm_runtime_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	unsigned long flags;
+	int hwblk = pdev->archdata.hw_blk_id;
+
+	if (!hwblk)
+		return -EINVAL;
+
+	pr_info("platform_pm_runtime_suspend() \"%s\" [%d]\n",
+		dev_name(dev), hwblk);
+
+	if (test_bit(PDEV_ARCHDATA_FLAG_INIT, &pdev->archdata.flags)) {
+		pr_warning("runtime_pm: driver should start from resume!\n");
+		return -EINVAL;
+	}
+
+	/* disable the clock */
+	hwblk_disable(hwblk_info, hwblk);
+
+	/* increase idle count */
+	hwblk_cnt_inc(hwblk_info, hwblk, HWBLK_CNT_IDLE);
+
+	/* put device on idle list */
+	spin_lock_irqsave(&hwblk_idle_lock, flags);
+	list_add_tail(&pdev->archdata.entry, &hwblk_idle_list);
+	__set_bit(PDEV_ARCHDATA_FLAG_LIST, &pdev->archdata.flags);
+	spin_unlock_irqrestore(&hwblk_idle_lock, flags);
+
+	return 0;
+};
+
+int platform_pm_runtime_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct dev_pm_ops *dev_pm_ops = NULL;
+	unsigned long flags;
+	int hwblk = pdev->archdata.hw_blk_id;
+	int ret = 0;
+
+	if (!hwblk)
+		return -EINVAL;
+
+	pr_info("platform_pm_runtime_resume() \"%s\" [%d]\n",
+		dev_name(dev), hwblk);
+
+	/* remove device from idle list if needed */
+	spin_lock_irqsave(&hwblk_idle_lock, flags);
+	if (test_bit(PDEV_ARCHDATA_FLAG_LIST, &pdev->archdata.flags)) {
+		list_del(&pdev->archdata.entry);
+		__clear_bit(PDEV_ARCHDATA_FLAG_LIST, &pdev->archdata.flags);
+	}
+	spin_unlock_irqrestore(&hwblk_idle_lock, flags);
+
+	/* decrease idle count if needed */
+	if (!test_bit(PDEV_ARCHDATA_FLAG_INIT, &pdev->archdata.flags) &&
+	    !test_bit(PDEV_ARCHDATA_FLAG_SUSP, &pdev->archdata.flags))
+		hwblk_cnt_dec(hwblk_info, hwblk, HWBLK_CNT_IDLE);
+
+	__clear_bit(PDEV_ARCHDATA_FLAG_INIT, &pdev->archdata.flags);
+
+	/* enable the clock */
+	hwblk_enable(hwblk_info, hwblk);
+
+	/* resume the device if needed */
+	if (test_bit(PDEV_ARCHDATA_FLAG_SUSP, &pdev->archdata.flags)) {
+
+		pr_info("platform_pm_runtime_resume() resuming \"%s\" [%d]\n",
+			dev_name(dev), hwblk);
+
+		if (dev->driver && dev->driver->pm)
+			dev_pm_ops = dev->driver->pm;
+
+		if (dev_pm_ops && dev_pm_ops->runtime_resume)
+			ret = dev_pm_ops->runtime_resume(dev);
+
+		__clear_bit(PDEV_ARCHDATA_FLAG_SUSP, &pdev->archdata.flags);
+	}
+
+	return ret;
+};
+
+static int __devinit platform_bus_notify(struct notifier_block *nb,
+					 unsigned long action, void *data)
+{
+	struct device *dev = data;
+	struct platform_device *pdev = to_platform_device(dev);
+	int hwblk = pdev->archdata.hw_blk_id;
+
+	/* ignore off-chip non-SoC platform devices */
+	if (!hwblk)
+		return 0;
+
+	switch (action) {
+	case BUS_NOTIFY_ADD_DEVICE:
+		INIT_LIST_HEAD(&pdev->archdata.entry);
+		INIT_WORK(&pdev->archdata.work, platform_pm_runtime_work);
+		/* platform devices without drivers should be disabled */
+		hwblk_enable(hwblk_info, hwblk);
+		hwblk_disable(hwblk_info, hwblk);
+		/* make sure driver re-inits itself once */
+		__set_bit(PDEV_ARCHDATA_FLAG_INIT, &pdev->archdata.flags);
+		break;
+	/* TODO: add BUS_NOTIFY_BIND_DRIVER and increase idle count */
+	case BUS_NOTIFY_BOUND_DRIVER:
+		/* keep track of number of devices in use per hwblk */
+		hwblk_cnt_inc(hwblk_info, hwblk, HWBLK_CNT_DEVICES);
+		break;
+	case BUS_NOTIFY_UNBOUND_DRIVER:
+		/* keep track of number of devices in use per hwblk */
+		hwblk_cnt_dec(hwblk_info, hwblk, HWBLK_CNT_DEVICES);
+		/* make sure driver re-inits itself once */
+		__set_bit(PDEV_ARCHDATA_FLAG_INIT, &pdev->archdata.flags);
+		break;
+	case BUS_NOTIFY_DEL_DEVICE:
+		break;
+	}
+	return 0;
+}
+
+static struct notifier_block platform_bus_notifier = {
+	.notifier_call = platform_bus_notify
+};
+
+static int __init sh_pm_runtime_init(void)
+{
+	bus_register_notifier(&platform_bus_type, &platform_bus_notifier);
+	return 0;
+}
+
+arch_initcall(sh_pm_runtime_init);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 04/06] sh: Runtime PM for sh7722 and Migo-R
  2009-07-09 15:19 [PATCH 00/06][RFC] sh: Runtime PM Prototype for SuperH Mobile Magnus Damm
                   ` (2 preceding siblings ...)
  2009-07-09 15:19 ` [PATCH 03/06] sh: Runtime PM for SuperH Mobile Magnus Damm
@ 2009-07-09 15:20 ` Magnus Damm
  2009-07-09 15:20 ` [PATCH 05/06] i2c: Runtime PM for i2c-sh_mobile.c Magnus Damm
  2009-07-09 15:20 ` [PATCH 06/06] video: Runtime PM for sh_mobile_lcdcfb.c Magnus Damm
  5 siblings, 0 replies; 8+ messages in thread
From: Magnus Damm @ 2009-07-09 15:20 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-sh, gregkh

From: Magnus Damm <damm@igel.co.jp>

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.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 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(-)

--- 0001/arch/sh/boards/mach-migor/setup.c
+++ work/arch/sh/boards/mach-migor/setup.c	2009-07-09 18:43:42.000000000 +0900
@@ -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 = {
--- 0005/arch/sh/kernel/cpu/sh4a/hwblk-sh7722.c
+++ work/arch/sh/kernel/cpu/sh4a/hwblk-sh7722.c	2009-07-09 18:44:44.000000000 +0900
@@ -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;
--- 0001/arch/sh/kernel/cpu/sh4a/setup-sh7722.c
+++ work/arch/sh/kernel/cpu/sh4a/setup-sh7722.c	2009-07-09 18:43:36.000000000 +0900
@@ -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[] = {

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 05/06] i2c: Runtime PM for i2c-sh_mobile.c
  2009-07-09 15:19 [PATCH 00/06][RFC] sh: Runtime PM Prototype for SuperH Mobile Magnus Damm
                   ` (3 preceding siblings ...)
  2009-07-09 15:20 ` [PATCH 04/06] sh: Runtime PM for sh7722 and Migo-R Magnus Damm
@ 2009-07-09 15:20 ` Magnus Damm
  2009-07-09 15:20 ` [PATCH 06/06] video: Runtime PM for sh_mobile_lcdcfb.c Magnus Damm
  5 siblings, 0 replies; 8+ messages in thread
From: Magnus Damm @ 2009-07-09 15:20 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-sh, gregkh

From: Magnus Damm <damm@igel.co.jp>

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.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 drivers/i2c/busses/i2c-sh_mobile.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

--- 0001/drivers/i2c/busses/i2c-sh_mobile.c
+++ work/drivers/i2c/busses/i2c-sh_mobile.c	2009-07-07 18:50:53.000000000 +0900
@@ -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);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 06/06] video: Runtime PM for sh_mobile_lcdcfb.c
  2009-07-09 15:19 [PATCH 00/06][RFC] sh: Runtime PM Prototype for SuperH Mobile Magnus Damm
                   ` (4 preceding siblings ...)
  2009-07-09 15:20 ` [PATCH 05/06] i2c: Runtime PM for i2c-sh_mobile.c Magnus Damm
@ 2009-07-09 15:20 ` Magnus Damm
  5 siblings, 0 replies; 8+ messages in thread
From: Magnus Damm @ 2009-07-09 15:20 UTC (permalink / raw)
  To: linux-pm; +Cc: linux-sh, gregkh

From: Magnus Damm <damm@igel.co.jp>

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.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 drivers/video/sh_mobile_lcdcfb.c |   31 ++++++++++++-------------------
 1 file changed, 12 insertions(+), 19 deletions(-)

--- 0001/drivers/video/sh_mobile_lcdcfb.c
+++ work/drivers/video/sh_mobile_lcdcfb.c	2009-07-09 18:24:22.000000000 +0900
@@ -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);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 01/06] Driver Core: Runtime PM callbacks for the Platform Bus
@ 2009-07-09 15:19 Magnus Damm
  0 siblings, 0 replies; 8+ messages in thread
From: Magnus Damm @ 2009-07-09 15:19 UTC (permalink / raw)
  To: linux-sh

From: Magnus Damm <damm@igel.co.jp>

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.

Signed-off-by: Magnus Damm <damm@igel.co.jp>
---

 drivers/base/platform.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

--- 0001/drivers/base/platform.c
+++ work/drivers/base/platform.c	2009-06-25 18:58:56.000000000 +0900
@@ -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);

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-07-09 15:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-09 15:19 [PATCH 00/06][RFC] sh: Runtime PM Prototype for SuperH Mobile Magnus Damm
2009-07-09 15:19 ` [PATCH 01/06] Driver Core: Runtime PM callbacks for the Platform Bus Magnus Damm
2009-07-09 15:19 ` [PATCH 02/06] sh: Add support for multiple hwblk counters Magnus Damm
2009-07-09 15:19 ` [PATCH 03/06] sh: Runtime PM for SuperH Mobile Magnus Damm
2009-07-09 15:20 ` [PATCH 04/06] sh: Runtime PM for sh7722 and Migo-R Magnus Damm
2009-07-09 15:20 ` [PATCH 05/06] i2c: Runtime PM for i2c-sh_mobile.c Magnus Damm
2009-07-09 15:20 ` [PATCH 06/06] video: Runtime PM for sh_mobile_lcdcfb.c Magnus Damm
2009-07-09 15:19 [PATCH 01/06] Driver Core: Runtime PM callbacks for the Platform Bus Magnus Damm

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.