diff options
author | Kelvin Cheung <keguang.zhang@gmail.com> | 2012-10-23 01:17:00 -0400 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2012-11-09 05:37:20 -0500 |
commit | 17ded0a89b3b0b6ac626d58d469ef899f21e2d42 (patch) | |
tree | 6db9edc67a722d391c7ae3dfc4796b60d02d63e1 /arch/mips | |
parent | ed21cfe207276e2d2883173399dd0380db372e18 (diff) |
MIPS: Loongson1B: use common clock infrastructure instead of private APIs
Use common clock infrastructure instead of private APIs.
1. Enable COMMON_CLK in the Kconfig.
2. Remove private clock APIs, which are replaced by the code in
drivers/clk/clk-ls1x.c.
3. Modify header file for drivers/clk/clk-ls1x.c.
Signed-off-by: Kelvin Cheung <keguang.zhang@gmail.com>
Patchwork: http://patchwork.linux-mips.org/patch/4431
Signed-off-by: John Crispin <blogic@openwrt.org>
Diffstat (limited to 'arch/mips')
-rw-r--r-- | arch/mips/include/asm/mach-loongson1/platform.h | 1 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-loongson1/regs-clk.h | 7 | ||||
-rw-r--r-- | arch/mips/loongson1/Kconfig | 2 | ||||
-rw-r--r-- | arch/mips/loongson1/common/clock.c | 157 |
4 files changed, 8 insertions, 159 deletions
diff --git a/arch/mips/include/asm/mach-loongson1/platform.h b/arch/mips/include/asm/mach-loongson1/platform.h index 2f171617bade..f584017eb8a7 100644 --- a/arch/mips/include/asm/mach-loongson1/platform.h +++ b/arch/mips/include/asm/mach-loongson1/platform.h | |||
@@ -18,6 +18,7 @@ extern struct platform_device ls1x_eth0_device; | |||
18 | extern struct platform_device ls1x_ehci_device; | 18 | extern struct platform_device ls1x_ehci_device; |
19 | extern struct platform_device ls1x_rtc_device; | 19 | extern struct platform_device ls1x_rtc_device; |
20 | 20 | ||
21 | extern void __init ls1x_clk_init(void); | ||
21 | void ls1x_serial_setup(void); | 22 | void ls1x_serial_setup(void); |
22 | 23 | ||
23 | #endif /* __ASM_MACH_LOONGSON1_PLATFORM_H */ | 24 | #endif /* __ASM_MACH_LOONGSON1_PLATFORM_H */ |
diff --git a/arch/mips/include/asm/mach-loongson1/regs-clk.h b/arch/mips/include/asm/mach-loongson1/regs-clk.h index 8efa7fb9f73a..a81fa3d0dc91 100644 --- a/arch/mips/include/asm/mach-loongson1/regs-clk.h +++ b/arch/mips/include/asm/mach-loongson1/regs-clk.h | |||
@@ -20,14 +20,15 @@ | |||
20 | 20 | ||
21 | /* Clock PLL Divisor Register Bits */ | 21 | /* Clock PLL Divisor Register Bits */ |
22 | #define DIV_DC_EN (0x1 << 31) | 22 | #define DIV_DC_EN (0x1 << 31) |
23 | #define DIV_DC (0x1f << 26) | ||
24 | #define DIV_CPU_EN (0x1 << 25) | 23 | #define DIV_CPU_EN (0x1 << 25) |
25 | #define DIV_CPU (0x1f << 20) | ||
26 | #define DIV_DDR_EN (0x1 << 19) | 24 | #define DIV_DDR_EN (0x1 << 19) |
27 | #define DIV_DDR (0x1f << 14) | ||
28 | 25 | ||
29 | #define DIV_DC_SHIFT 26 | 26 | #define DIV_DC_SHIFT 26 |
30 | #define DIV_CPU_SHIFT 20 | 27 | #define DIV_CPU_SHIFT 20 |
31 | #define DIV_DDR_SHIFT 14 | 28 | #define DIV_DDR_SHIFT 14 |
32 | 29 | ||
30 | #define DIV_DC_WIDTH 5 | ||
31 | #define DIV_CPU_WIDTH 5 | ||
32 | #define DIV_DDR_WIDTH 5 | ||
33 | |||
33 | #endif /* __ASM_MACH_LOONGSON1_REGS_CLK_H */ | 34 | #endif /* __ASM_MACH_LOONGSON1_REGS_CLK_H */ |
diff --git a/arch/mips/loongson1/Kconfig b/arch/mips/loongson1/Kconfig index a9a14d6e81af..fbf75f635798 100644 --- a/arch/mips/loongson1/Kconfig +++ b/arch/mips/loongson1/Kconfig | |||
@@ -15,7 +15,7 @@ config LOONGSON1_LS1B | |||
15 | select SYS_SUPPORTS_LITTLE_ENDIAN | 15 | select SYS_SUPPORTS_LITTLE_ENDIAN |
16 | select SYS_SUPPORTS_HIGHMEM | 16 | select SYS_SUPPORTS_HIGHMEM |
17 | select SYS_HAS_EARLY_PRINTK | 17 | select SYS_HAS_EARLY_PRINTK |
18 | select HAVE_CLK | 18 | select COMMON_CLK |
19 | 19 | ||
20 | endchoice | 20 | endchoice |
21 | 21 | ||
diff --git a/arch/mips/loongson1/common/clock.c b/arch/mips/loongson1/common/clock.c index 1bbbbec12085..7db0a6aab20b 100644 --- a/arch/mips/loongson1/common/clock.c +++ b/arch/mips/loongson1/common/clock.c | |||
@@ -7,170 +7,17 @@ | |||
7 | * option) any later version. | 7 | * option) any later version. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/list.h> | ||
12 | #include <linux/mutex.h> | ||
13 | #include <linux/clk.h> | 10 | #include <linux/clk.h> |
14 | #include <linux/err.h> | 11 | #include <linux/err.h> |
15 | #include <asm/clock.h> | ||
16 | #include <asm/time.h> | 12 | #include <asm/time.h> |
17 | 13 | #include <platform.h> | |
18 | #include <loongson1.h> | ||
19 | |||
20 | static LIST_HEAD(clocks); | ||
21 | static DEFINE_MUTEX(clocks_mutex); | ||
22 | |||
23 | struct clk *clk_get(struct device *dev, const char *name) | ||
24 | { | ||
25 | struct clk *c; | ||
26 | struct clk *ret = NULL; | ||
27 | |||
28 | mutex_lock(&clocks_mutex); | ||
29 | list_for_each_entry(c, &clocks, node) { | ||
30 | if (!strcmp(c->name, name)) { | ||
31 | ret = c; | ||
32 | break; | ||
33 | } | ||
34 | } | ||
35 | mutex_unlock(&clocks_mutex); | ||
36 | |||
37 | return ret; | ||
38 | } | ||
39 | EXPORT_SYMBOL(clk_get); | ||
40 | |||
41 | int clk_enable(struct clk *clk) | ||
42 | { | ||
43 | return 0; | ||
44 | } | ||
45 | EXPORT_SYMBOL(clk_enable); | ||
46 | |||
47 | void clk_disable(struct clk *clk) | ||
48 | { | ||
49 | } | ||
50 | EXPORT_SYMBOL(clk_disable); | ||
51 | |||
52 | unsigned long clk_get_rate(struct clk *clk) | ||
53 | { | ||
54 | return clk->rate; | ||
55 | } | ||
56 | EXPORT_SYMBOL(clk_get_rate); | ||
57 | |||
58 | void clk_put(struct clk *clk) | ||
59 | { | ||
60 | } | ||
61 | EXPORT_SYMBOL(clk_put); | ||
62 | |||
63 | static void pll_clk_init(struct clk *clk) | ||
64 | { | ||
65 | u32 pll; | ||
66 | |||
67 | pll = __raw_readl(LS1X_CLK_PLL_FREQ); | ||
68 | clk->rate = (12 + (pll & 0x3f)) * 33 / 2 | ||
69 | + ((pll >> 8) & 0x3ff) * 33 / 1024 / 2; | ||
70 | clk->rate *= 1000000; | ||
71 | } | ||
72 | |||
73 | static void cpu_clk_init(struct clk *clk) | ||
74 | { | ||
75 | u32 pll, ctrl; | ||
76 | |||
77 | pll = clk_get_rate(clk->parent); | ||
78 | ctrl = __raw_readl(LS1X_CLK_PLL_DIV) & DIV_CPU; | ||
79 | clk->rate = pll / (ctrl >> DIV_CPU_SHIFT); | ||
80 | } | ||
81 | |||
82 | static void ddr_clk_init(struct clk *clk) | ||
83 | { | ||
84 | u32 pll, ctrl; | ||
85 | |||
86 | pll = clk_get_rate(clk->parent); | ||
87 | ctrl = __raw_readl(LS1X_CLK_PLL_DIV) & DIV_DDR; | ||
88 | clk->rate = pll / (ctrl >> DIV_DDR_SHIFT); | ||
89 | } | ||
90 | |||
91 | static void dc_clk_init(struct clk *clk) | ||
92 | { | ||
93 | u32 pll, ctrl; | ||
94 | |||
95 | pll = clk_get_rate(clk->parent); | ||
96 | ctrl = __raw_readl(LS1X_CLK_PLL_DIV) & DIV_DC; | ||
97 | clk->rate = pll / (ctrl >> DIV_DC_SHIFT); | ||
98 | } | ||
99 | |||
100 | static struct clk_ops pll_clk_ops = { | ||
101 | .init = pll_clk_init, | ||
102 | }; | ||
103 | |||
104 | static struct clk_ops cpu_clk_ops = { | ||
105 | .init = cpu_clk_init, | ||
106 | }; | ||
107 | |||
108 | static struct clk_ops ddr_clk_ops = { | ||
109 | .init = ddr_clk_init, | ||
110 | }; | ||
111 | |||
112 | static struct clk_ops dc_clk_ops = { | ||
113 | .init = dc_clk_init, | ||
114 | }; | ||
115 | |||
116 | static struct clk pll_clk = { | ||
117 | .name = "pll", | ||
118 | .ops = &pll_clk_ops, | ||
119 | }; | ||
120 | |||
121 | static struct clk cpu_clk = { | ||
122 | .name = "cpu", | ||
123 | .parent = &pll_clk, | ||
124 | .ops = &cpu_clk_ops, | ||
125 | }; | ||
126 | |||
127 | static struct clk ddr_clk = { | ||
128 | .name = "ddr", | ||
129 | .parent = &pll_clk, | ||
130 | .ops = &ddr_clk_ops, | ||
131 | }; | ||
132 | |||
133 | static struct clk dc_clk = { | ||
134 | .name = "dc", | ||
135 | .parent = &pll_clk, | ||
136 | .ops = &dc_clk_ops, | ||
137 | }; | ||
138 | |||
139 | int clk_register(struct clk *clk) | ||
140 | { | ||
141 | mutex_lock(&clocks_mutex); | ||
142 | list_add(&clk->node, &clocks); | ||
143 | if (clk->ops->init) | ||
144 | clk->ops->init(clk); | ||
145 | mutex_unlock(&clocks_mutex); | ||
146 | |||
147 | return 0; | ||
148 | } | ||
149 | EXPORT_SYMBOL(clk_register); | ||
150 | |||
151 | static struct clk *ls1x_clks[] = { | ||
152 | &pll_clk, | ||
153 | &cpu_clk, | ||
154 | &ddr_clk, | ||
155 | &dc_clk, | ||
156 | }; | ||
157 | |||
158 | int __init ls1x_clock_init(void) | ||
159 | { | ||
160 | int i; | ||
161 | |||
162 | for (i = 0; i < ARRAY_SIZE(ls1x_clks); i++) | ||
163 | clk_register(ls1x_clks[i]); | ||
164 | |||
165 | return 0; | ||
166 | } | ||
167 | 14 | ||
168 | void __init plat_time_init(void) | 15 | void __init plat_time_init(void) |
169 | { | 16 | { |
170 | struct clk *clk; | 17 | struct clk *clk; |
171 | 18 | ||
172 | /* Initialize LS1X clocks */ | 19 | /* Initialize LS1X clocks */ |
173 | ls1x_clock_init(); | 20 | ls1x_clk_init(); |
174 | 21 | ||
175 | /* setup mips r4k timer */ | 22 | /* setup mips r4k timer */ |
176 | clk = clk_get(NULL, "cpu"); | 23 | clk = clk_get(NULL, "cpu"); |