diff mbox

sh: hwblk base implementation

Message ID 20090703100805.30617.20409.sendpatchset@rx1.opensource.se (mailing list archive)
State Accepted
Headers show

Commit Message

Magnus Damm July 3, 2009, 10:08 a.m. UTC
From: Magnus Damm <damm@igel.co.jp>

This patch is the hwblk base implementation, containing
structures and shared functions dealing with hardware blocks.

A each processor model should provide a list of hwblks and 
describe which module stop bit that is associated with each
hwblck and how the hwblks are grouped together into areas.

The shared code keeps track of the usage count for each
hwblk and the areas. Fallback implementations for processor
specific code are also kept as weak symbols.

The clock framework, the runtime pm code and cpuidle will
all tie into this hwblk implementation.

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

 arch/sh/include/asm/hwblk.h |   61 ++++++++++++++++++++
 arch/sh/kernel/cpu/Makefile |    2 
 arch/sh/kernel/cpu/hwblk.c  |  130 +++++++++++++++++++++++++++++++++++++++++++
 arch/sh/kernel/time.c       |    2 
 4 files changed, 194 insertions(+), 1 deletion(-)

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

Comments

Paul Mundt July 4, 2009, 3:40 p.m. UTC | #1
On Fri, Jul 03, 2009 at 07:08:05PM +0900, Magnus Damm wrote:
> This patch is the hwblk base implementation, containing
> structures and shared functions dealing with hardware blocks.
> 
> A each processor model should provide a list of hwblks and 
> describe which module stop bit that is associated with each
> hwblck and how the hwblks are grouped together into areas.
> 
> The shared code keeps track of the usage count for each
> hwblk and the areas. Fallback implementations for processor
> specific code are also kept as weak symbols.
> 
> The clock framework, the runtime pm code and cpuidle will
> all tie into this hwblk implementation.

On Fri, Jul 03, 2009 at 07:15:25PM +0900, Magnus Damm wrote:
> This patch contains the sh7722 specific hwblk implementation.
> 
> Hwblk ids are added to the processor specific header file,
> module stop bits and areas are kept track of as hwblks,
> clocks are converted to make use of the shared hwblk code.
> Code to determine allowed sleep modes is also added.

On Fri, Jul 03, 2009 at 07:28:00PM +0900, Magnus Damm wrote:
> This patch adds cpuidle support for SuperH Mobile.
> 
> The sleep mode selected by cpuidle is compared with
> the mode selected by the hwblk sleep code and the
> best allowed mode is entered.
> 
> At this point "Sleep mode" and "Sleep mode + SF" are
> supported. This code can easily be extended to support
> "Software suspend mode", but the assembly code must
> first be updated to avoid loosing interrupts.
> 
> Also, update the code to only copy the assembly snippet
> into internal memory once at bootup.

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

Patch

--- /dev/null
+++ work/arch/sh/include/asm/hwblk.h	2009-07-01 15:15:32.000000000 +0900
@@ -0,0 +1,61 @@ 
+#ifndef __ASM_SH_HWBLK_H
+#define __ASM_SH_HWBLK_H
+
+#include <asm/clock.h>
+#include <asm/io.h>
+
+#define HWBLK_AREA_FLAG_PARENT (1 << 0) /* valid parent */
+
+#define HWBLK_AREA(_flags, _parent)		\
+{						\
+	.flags = _flags,			\
+	.parent = _parent,			\
+}
+
+struct hwblk_area {
+	unsigned long cnt;
+	unsigned char parent;
+	unsigned char flags;
+};
+
+#define HWBLK(_mstp, _bit, _area)		\
+{						\
+	.mstp = (void __iomem *)_mstp,		\
+	.bit = _bit,				\
+	.area = _area,				\
+}
+
+struct hwblk {
+	void __iomem *mstp;
+	unsigned char bit;
+	unsigned char area;
+	unsigned long cnt;
+};
+
+struct hwblk_info {
+	struct hwblk_area *areas;
+	int nr_areas;
+	struct hwblk *hwblks;
+	int nr_hwblks;
+};
+
+/* Should be defined by processor-specific code */
+int arch_hwblk_init(void);
+int arch_hwblk_sleep_mode(void);
+
+int hwblk_register(struct hwblk_info *info);
+int hwblk_init(void);
+
+/* allow clocks to enable and disable hardware blocks */
+#define SH_HWBLK_CLK(_name, _id, _parent, _hwblk, _flags)	\
+{							\
+	.name		= _name,			\
+	.id		= _id,				\
+	.parent		= _parent,			\
+	.arch_flags	= _hwblk,			\
+	.flags		= _flags,			\
+}
+
+int sh_hwblk_clk_register(struct clk *clks, int nr);
+
+#endif /* __ASM_SH_HWBLK_H */
--- 0001/arch/sh/kernel/cpu/Makefile
+++ work/arch/sh/kernel/cpu/Makefile	2009-06-30 14:28:36.000000000 +0900
@@ -19,4 +19,4 @@  obj-$(CONFIG_UBC_WAKEUP)	+= ubc.o
 obj-$(CONFIG_SH_ADC)		+= adc.o
 obj-$(CONFIG_SH_CLK_CPG)	+= clock-cpg.o
 
-obj-y	+= irq/ init.o clock.o
+obj-y	+= irq/ init.o clock.o hwblk.o
--- /dev/null
+++ work/arch/sh/kernel/cpu/hwblk.c	2009-06-30 14:28:36.000000000 +0900
@@ -0,0 +1,130 @@ 
+#include <linux/clk.h>
+#include <linux/compiler.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <linux/spinlock.h>
+#include <asm/suspend.h>
+#include <asm/hwblk.h>
+#include <asm/clock.h>
+
+static DEFINE_SPINLOCK(hwblk_lock);
+
+static void hwblk_area_inc(struct hwblk_info *info, int area)
+{
+	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);
+}
+
+static void hwblk_area_dec(struct hwblk_info *info, int area)
+{
+	struct hwblk_area *hap = info->areas + area;
+
+	if (hap->cnt == 1)
+		if (hap->flags & HWBLK_AREA_FLAG_PARENT)
+			hwblk_area_dec(info, hap->parent);
+	hap->cnt--;
+}
+
+static void hwblk_enable(struct hwblk_info *info, int hwblk)
+{
+	struct hwblk *hp = info->hwblks + hwblk;
+	unsigned long tmp;
+	unsigned long flags;
+
+	spin_lock_irqsave(&hwblk_lock, flags);
+
+	hp->cnt++;
+	if (hp->cnt == 1) {
+		hwblk_area_inc(info, hp->area);
+
+		tmp = __raw_readl(hp->mstp);
+		tmp &= ~(1 << hp->bit);
+		__raw_writel(tmp, hp->mstp);
+	}
+
+	spin_unlock_irqrestore(&hwblk_lock, flags);
+}
+
+static void hwblk_disable(struct hwblk_info *info, int hwblk)
+{
+	struct hwblk *hp = info->hwblks + hwblk;
+	unsigned long tmp;
+	unsigned long flags;
+
+	spin_lock_irqsave(&hwblk_lock, flags);
+
+	if (hp->cnt == 1) {
+		hwblk_area_dec(info, hp->area);
+
+		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;
+
+int __init hwblk_register(struct hwblk_info *info)
+{
+	hwblk_info = info;
+	return 0;
+}
+
+int __init __weak arch_hwblk_init(void)
+{
+	return 0;
+}
+
+int __weak arch_hwblk_sleep_mode(void)
+{
+	return SUSP_SH_SLEEP;
+}
+
+int __init hwblk_init(void)
+{
+	return arch_hwblk_init();
+}
+
+/* allow clocks to enable and disable hardware blocks */
+static int sh_hwblk_clk_enable(struct clk *clk)
+{
+	if (!hwblk_info)
+		return -ENOENT;
+
+	hwblk_enable(hwblk_info, clk->arch_flags);
+	return 0;
+}
+
+static void sh_hwblk_clk_disable(struct clk *clk)
+{
+	if (hwblk_info)
+		hwblk_disable(hwblk_info, clk->arch_flags);
+}
+
+static struct clk_ops sh_hwblk_clk_ops = {
+	.enable		= sh_hwblk_clk_enable,
+	.disable	= sh_hwblk_clk_disable,
+	.recalc		= followparent_recalc,
+};
+
+int __init sh_hwblk_clk_register(struct clk *clks, int nr)
+{
+	struct clk *clkp;
+	int ret = 0;
+	int k;
+
+	for (k = 0; !ret && (k < nr); k++) {
+		clkp = clks + k;
+		clkp->ops = &sh_hwblk_clk_ops;
+		ret |= clk_register(clkp);
+	}
+
+	return ret;
+}
--- 0001/arch/sh/kernel/time.c
+++ work/arch/sh/kernel/time.c	2009-06-30 14:28:36.000000000 +0900
@@ -21,6 +21,7 @@ 
 #include <linux/smp.h>
 #include <linux/rtc.h>
 #include <asm/clock.h>
+#include <asm/hwblk.h>
 #include <asm/rtc.h>
 
 /* Dummy RTC ops */
@@ -96,6 +97,7 @@  void __init time_init(void)
 	if (board_time_init)
 		board_time_init();
 
+	hwblk_init();
 	clk_init();
 
 	rtc_sh_get_time(&xtime);