Skip to content

Commit 79714ac

Browse files
Magnus Dammpmundt
authored andcommitted
sh: hwblk base implementation
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> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 746a99a commit 79714ac

4 files changed

Lines changed: 194 additions & 1 deletion

File tree

‎arch/sh/include/asm/hwblk.h‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#ifndef __ASM_SH_HWBLK_H
2+
#define __ASM_SH_HWBLK_H
3+
4+
#include <asm/clock.h>
5+
#include <asm/io.h>
6+
7+
#define HWBLK_AREA_FLAG_PARENT (1 << 0) /* valid parent */
8+
9+
#define HWBLK_AREA(_flags, _parent) \
10+
{ \
11+
.flags = _flags, \
12+
.parent = _parent, \
13+
}
14+
15+
struct hwblk_area {
16+
unsigned long cnt;
17+
unsigned char parent;
18+
unsigned char flags;
19+
};
20+
21+
#define HWBLK(_mstp, _bit, _area) \
22+
{ \
23+
.mstp = (void __iomem *)_mstp, \
24+
.bit = _bit, \
25+
.area = _area, \
26+
}
27+
28+
struct hwblk {
29+
void __iomem *mstp;
30+
unsigned char bit;
31+
unsigned char area;
32+
unsigned long cnt;
33+
};
34+
35+
struct hwblk_info {
36+
struct hwblk_area *areas;
37+
int nr_areas;
38+
struct hwblk *hwblks;
39+
int nr_hwblks;
40+
};
41+
42+
/* Should be defined by processor-specific code */
43+
int arch_hwblk_init(void);
44+
int arch_hwblk_sleep_mode(void);
45+
46+
int hwblk_register(struct hwblk_info *info);
47+
int hwblk_init(void);
48+
49+
/* allow clocks to enable and disable hardware blocks */
50+
#define SH_HWBLK_CLK(_name, _id, _parent, _hwblk, _flags) \
51+
{ \
52+
.name = _name, \
53+
.id = _id, \
54+
.parent = _parent, \
55+
.arch_flags = _hwblk, \
56+
.flags = _flags, \
57+
}
58+
59+
int sh_hwblk_clk_register(struct clk *clks, int nr);
60+
61+
#endif /* __ASM_SH_HWBLK_H */

‎arch/sh/kernel/cpu/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ obj-$(CONFIG_UBC_WAKEUP) += ubc.o
1919
obj-$(CONFIG_SH_ADC) += adc.o
2020
obj-$(CONFIG_SH_CLK_CPG) += clock-cpg.o
2121

22-
obj-y += irq/ init.o clock.o
22+
obj-y += irq/ init.o clock.o hwblk.o

‎arch/sh/kernel/cpu/hwblk.c‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#include <linux/clk.h>
2+
#include <linux/compiler.h>
3+
#include <linux/slab.h>
4+
#include <linux/io.h>
5+
#include <linux/spinlock.h>
6+
#include <asm/suspend.h>
7+
#include <asm/hwblk.h>
8+
#include <asm/clock.h>
9+
10+
static DEFINE_SPINLOCK(hwblk_lock);
11+
12+
static void hwblk_area_inc(struct hwblk_info *info, int area)
13+
{
14+
struct hwblk_area *hap = info->areas + area;
15+
16+
hap->cnt++;
17+
if (hap->cnt == 1)
18+
if (hap->flags & HWBLK_AREA_FLAG_PARENT)
19+
hwblk_area_inc(info, hap->parent);
20+
}
21+
22+
static void hwblk_area_dec(struct hwblk_info *info, int area)
23+
{
24+
struct hwblk_area *hap = info->areas + area;
25+
26+
if (hap->cnt == 1)
27+
if (hap->flags & HWBLK_AREA_FLAG_PARENT)
28+
hwblk_area_dec(info, hap->parent);
29+
hap->cnt--;
30+
}
31+
32+
static void hwblk_enable(struct hwblk_info *info, int hwblk)
33+
{
34+
struct hwblk *hp = info->hwblks + hwblk;
35+
unsigned long tmp;
36+
unsigned long flags;
37+
38+
spin_lock_irqsave(&hwblk_lock, flags);
39+
40+
hp->cnt++;
41+
if (hp->cnt == 1) {
42+
hwblk_area_inc(info, hp->area);
43+
44+
tmp = __raw_readl(hp->mstp);
45+
tmp &= ~(1 << hp->bit);
46+
__raw_writel(tmp, hp->mstp);
47+
}
48+
49+
spin_unlock_irqrestore(&hwblk_lock, flags);
50+
}
51+
52+
static void hwblk_disable(struct hwblk_info *info, int hwblk)
53+
{
54+
struct hwblk *hp = info->hwblks + hwblk;
55+
unsigned long tmp;
56+
unsigned long flags;
57+
58+
spin_lock_irqsave(&hwblk_lock, flags);
59+
60+
if (hp->cnt == 1) {
61+
hwblk_area_dec(info, hp->area);
62+
63+
tmp = __raw_readl(hp->mstp);
64+
tmp |= 1 << hp->bit;
65+
__raw_writel(tmp, hp->mstp);
66+
}
67+
hp->cnt--;
68+
69+
spin_unlock_irqrestore(&hwblk_lock, flags);
70+
}
71+
72+
static struct hwblk_info *hwblk_info;
73+
74+
int __init hwblk_register(struct hwblk_info *info)
75+
{
76+
hwblk_info = info;
77+
return 0;
78+
}
79+
80+
int __init __weak arch_hwblk_init(void)
81+
{
82+
return 0;
83+
}
84+
85+
int __weak arch_hwblk_sleep_mode(void)
86+
{
87+
return SUSP_SH_SLEEP;
88+
}
89+
90+
int __init hwblk_init(void)
91+
{
92+
return arch_hwblk_init();
93+
}
94+
95+
/* allow clocks to enable and disable hardware blocks */
96+
static int sh_hwblk_clk_enable(struct clk *clk)
97+
{
98+
if (!hwblk_info)
99+
return -ENOENT;
100+
101+
hwblk_enable(hwblk_info, clk->arch_flags);
102+
return 0;
103+
}
104+
105+
static void sh_hwblk_clk_disable(struct clk *clk)
106+
{
107+
if (hwblk_info)
108+
hwblk_disable(hwblk_info, clk->arch_flags);
109+
}
110+
111+
static struct clk_ops sh_hwblk_clk_ops = {
112+
.enable = sh_hwblk_clk_enable,
113+
.disable = sh_hwblk_clk_disable,
114+
.recalc = followparent_recalc,
115+
};
116+
117+
int __init sh_hwblk_clk_register(struct clk *clks, int nr)
118+
{
119+
struct clk *clkp;
120+
int ret = 0;
121+
int k;
122+
123+
for (k = 0; !ret && (k < nr); k++) {
124+
clkp = clks + k;
125+
clkp->ops = &sh_hwblk_clk_ops;
126+
ret |= clk_register(clkp);
127+
}
128+
129+
return ret;
130+
}

‎arch/sh/kernel/time.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/smp.h>
2222
#include <linux/rtc.h>
2323
#include <asm/clock.h>
24+
#include <asm/hwblk.h>
2425
#include <asm/rtc.h>
2526

2627
/* Dummy RTC ops */
@@ -96,6 +97,7 @@ void __init time_init(void)
9697
if (board_time_init)
9798
board_time_init();
9899

100+
hwblk_init();
99101
clk_init();
100102

101103
rtc_sh_get_time(&xtime);

0 commit comments

Comments
 (0)