summaryrefslogtreecommitdiffstats
path: root/arch/sh/kernel/cpu/hwblk.c
diff options
context:
space:
mode:
authorMagnus Damm <damm@igel.co.jp>2009-07-17 14:24:55 +0000
committerPaul Mundt <lethal@linux-sh.org>2009-07-20 04:23:39 +0900
commit0f8ee1874fa80899debc0a0670e2bed0a28d2548 (patch)
treef9d58ced4b3b8e6ac50371fdb009e3446bce40c8 /arch/sh/kernel/cpu/hwblk.c
parenta61c1a636628a28ab5b42a9d36582a8f6a08893a (diff)
downloadop-kernel-dev-0f8ee1874fa80899debc0a0670e2bed0a28d2548.zip
op-kernel-dev-0f8ee1874fa80899debc0a0670e2bed0a28d2548.tar.gz
sh: Add support for multiple hwblk counters
Extend the SuperH hwblk code to support more than one counter. Contains ground work for the future Runtime PM implementation. Signed-off-by: Magnus Damm <damm@igel.co.jp> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
Diffstat (limited to 'arch/sh/kernel/cpu/hwblk.c')
-rw-r--r--arch/sh/kernel/cpu/hwblk.c69
1 files changed, 47 insertions, 22 deletions
diff --git a/arch/sh/kernel/cpu/hwblk.c b/arch/sh/kernel/cpu/hwblk.c
index 7c3a73d..c0ad7d4 100644
--- a/arch/sh/kernel/cpu/hwblk.c
+++ b/arch/sh/kernel/cpu/hwblk.c
@@ -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_info *info, int hwblk)
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)
{
OpenPOWER on IntegriCloud