diff options
author | viresh kumar <viresh.kumar@st.com> | 2010-04-01 07:30:46 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2010-04-14 06:34:33 -0400 |
commit | 8c0236fc465c71d98203bcf5609db01b9cf5f70f (patch) | |
tree | be5754541381f3978a470455a0d0892f278ef689 | |
parent | 986435e3596cbae662b86812e4563fbb6013b994 (diff) |
ARM: 6014/1: ST SPEAr: Added clock framework for SPEAr platform and machines
Clock framework for SPEAr is based upon clkdev framework for ARM
Reviewed-by: Linus Walleij <linux.walleij@stericsson.com>
Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r-- | arch/arm/mach-spear3xx/clock.c | 389 | ||||
-rw-r--r-- | arch/arm/mach-spear3xx/include/mach/clkdev.h | 19 | ||||
-rw-r--r--[-rwxr-xr-x] | arch/arm/mach-spear3xx/include/mach/misc_regs.h | 0 | ||||
-rw-r--r-- | arch/arm/mach-spear6xx/clock.c | 483 | ||||
-rw-r--r-- | arch/arm/mach-spear6xx/include/mach/clkdev.h | 19 | ||||
-rw-r--r-- | arch/arm/plat-spear/clock.c | 435 | ||||
-rw-r--r-- | arch/arm/plat-spear/include/plat/clkdev.h | 20 | ||||
-rw-r--r-- | arch/arm/plat-spear/include/plat/clock.h | 126 |
8 files changed, 1491 insertions, 0 deletions
diff --git a/arch/arm/mach-spear3xx/clock.c b/arch/arm/mach-spear3xx/clock.c new file mode 100644 index 000000000000..39f6ccf22294 --- /dev/null +++ b/arch/arm/mach-spear3xx/clock.c | |||
@@ -0,0 +1,389 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-spear3xx/clock.c | ||
3 | * | ||
4 | * SPEAr3xx machines clock framework source file | ||
5 | * | ||
6 | * Copyright (C) 2009 ST Microelectronics | ||
7 | * Viresh Kumar<viresh.kumar@st.com> | ||
8 | * | ||
9 | * This file is licensed under the terms of the GNU General Public | ||
10 | * License version 2. This program is licensed "as is" without any | ||
11 | * warranty of any kind, whether express or implied. | ||
12 | */ | ||
13 | |||
14 | #include <linux/init.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <mach/misc_regs.h> | ||
17 | #include <plat/clock.h> | ||
18 | |||
19 | /* root clks */ | ||
20 | /* 32 KHz oscillator clock */ | ||
21 | static struct clk osc_32k_clk = { | ||
22 | .flags = ALWAYS_ENABLED, | ||
23 | .rate = 32000, | ||
24 | }; | ||
25 | |||
26 | /* 24 MHz oscillator clock */ | ||
27 | static struct clk osc_24m_clk = { | ||
28 | .flags = ALWAYS_ENABLED, | ||
29 | .rate = 24000000, | ||
30 | }; | ||
31 | |||
32 | /* clock derived from 32 KHz osc clk */ | ||
33 | /* rtc clock */ | ||
34 | static struct clk rtc_clk = { | ||
35 | .pclk = &osc_32k_clk, | ||
36 | .en_reg = PERIP1_CLK_ENB, | ||
37 | .en_reg_bit = RTC_CLK_ENB, | ||
38 | .recalc = &follow_parent, | ||
39 | }; | ||
40 | |||
41 | /* clock derived from 24 MHz osc clk */ | ||
42 | /* pll1 configuration structure */ | ||
43 | static struct pll_clk_config pll1_config = { | ||
44 | .mode_reg = PLL1_CTR, | ||
45 | .cfg_reg = PLL1_FRQ, | ||
46 | }; | ||
47 | |||
48 | /* PLL1 clock */ | ||
49 | static struct clk pll1_clk = { | ||
50 | .pclk = &osc_24m_clk, | ||
51 | .en_reg = PLL1_CTR, | ||
52 | .en_reg_bit = PLL_ENABLE, | ||
53 | .recalc = &pll1_clk_recalc, | ||
54 | .private_data = &pll1_config, | ||
55 | }; | ||
56 | |||
57 | /* PLL3 48 MHz clock */ | ||
58 | static struct clk pll3_48m_clk = { | ||
59 | .flags = ALWAYS_ENABLED, | ||
60 | .pclk = &osc_24m_clk, | ||
61 | .rate = 48000000, | ||
62 | }; | ||
63 | |||
64 | /* watch dog timer clock */ | ||
65 | static struct clk wdt_clk = { | ||
66 | .flags = ALWAYS_ENABLED, | ||
67 | .pclk = &osc_24m_clk, | ||
68 | .recalc = &follow_parent, | ||
69 | }; | ||
70 | |||
71 | /* clock derived from pll1 clk */ | ||
72 | /* cpu clock */ | ||
73 | static struct clk cpu_clk = { | ||
74 | .flags = ALWAYS_ENABLED, | ||
75 | .pclk = &pll1_clk, | ||
76 | .recalc = &follow_parent, | ||
77 | }; | ||
78 | |||
79 | /* ahb configuration structure */ | ||
80 | static struct bus_clk_config ahb_config = { | ||
81 | .reg = CORE_CLK_CFG, | ||
82 | .mask = PLL_HCLK_RATIO_MASK, | ||
83 | .shift = PLL_HCLK_RATIO_SHIFT, | ||
84 | }; | ||
85 | |||
86 | /* ahb clock */ | ||
87 | static struct clk ahb_clk = { | ||
88 | .flags = ALWAYS_ENABLED, | ||
89 | .pclk = &pll1_clk, | ||
90 | .recalc = &bus_clk_recalc, | ||
91 | .private_data = &ahb_config, | ||
92 | }; | ||
93 | |||
94 | /* uart configurations */ | ||
95 | static struct aux_clk_config uart_config = { | ||
96 | .synth_reg = UART_CLK_SYNT, | ||
97 | }; | ||
98 | |||
99 | /* uart parents */ | ||
100 | static struct pclk_info uart_pclk_info[] = { | ||
101 | { | ||
102 | .pclk = &pll1_clk, | ||
103 | .pclk_mask = AUX_CLK_PLL1_MASK, | ||
104 | .scalable = 1, | ||
105 | }, { | ||
106 | .pclk = &pll3_48m_clk, | ||
107 | .pclk_mask = AUX_CLK_PLL3_MASK, | ||
108 | .scalable = 0, | ||
109 | }, | ||
110 | }; | ||
111 | |||
112 | /* uart parent select structure */ | ||
113 | static struct pclk_sel uart_pclk_sel = { | ||
114 | .pclk_info = uart_pclk_info, | ||
115 | .pclk_count = ARRAY_SIZE(uart_pclk_info), | ||
116 | .pclk_sel_reg = PERIP_CLK_CFG, | ||
117 | .pclk_sel_mask = UART_CLK_MASK, | ||
118 | }; | ||
119 | |||
120 | /* uart clock */ | ||
121 | static struct clk uart_clk = { | ||
122 | .en_reg = PERIP1_CLK_ENB, | ||
123 | .en_reg_bit = UART_CLK_ENB, | ||
124 | .pclk_sel = &uart_pclk_sel, | ||
125 | .pclk_sel_shift = UART_CLK_SHIFT, | ||
126 | .recalc = &aux_clk_recalc, | ||
127 | .private_data = &uart_config, | ||
128 | }; | ||
129 | |||
130 | /* firda configurations */ | ||
131 | static struct aux_clk_config firda_config = { | ||
132 | .synth_reg = FIRDA_CLK_SYNT, | ||
133 | }; | ||
134 | |||
135 | /* firda parents */ | ||
136 | static struct pclk_info firda_pclk_info[] = { | ||
137 | { | ||
138 | .pclk = &pll1_clk, | ||
139 | .pclk_mask = AUX_CLK_PLL1_MASK, | ||
140 | .scalable = 1, | ||
141 | }, { | ||
142 | .pclk = &pll3_48m_clk, | ||
143 | .pclk_mask = AUX_CLK_PLL3_MASK, | ||
144 | .scalable = 0, | ||
145 | }, | ||
146 | }; | ||
147 | |||
148 | /* firda parent select structure */ | ||
149 | static struct pclk_sel firda_pclk_sel = { | ||
150 | .pclk_info = firda_pclk_info, | ||
151 | .pclk_count = ARRAY_SIZE(firda_pclk_info), | ||
152 | .pclk_sel_reg = PERIP_CLK_CFG, | ||
153 | .pclk_sel_mask = FIRDA_CLK_MASK, | ||
154 | }; | ||
155 | |||
156 | /* firda clock */ | ||
157 | static struct clk firda_clk = { | ||
158 | .en_reg = PERIP1_CLK_ENB, | ||
159 | .en_reg_bit = FIRDA_CLK_ENB, | ||
160 | .pclk_sel = &firda_pclk_sel, | ||
161 | .pclk_sel_shift = FIRDA_CLK_SHIFT, | ||
162 | .recalc = &aux_clk_recalc, | ||
163 | .private_data = &firda_config, | ||
164 | }; | ||
165 | |||
166 | /* gpt parents */ | ||
167 | static struct pclk_info gpt_pclk_info[] = { | ||
168 | { | ||
169 | .pclk = &pll1_clk, | ||
170 | .pclk_mask = AUX_CLK_PLL1_MASK, | ||
171 | .scalable = 1, | ||
172 | }, { | ||
173 | .pclk = &pll3_48m_clk, | ||
174 | .pclk_mask = AUX_CLK_PLL3_MASK, | ||
175 | .scalable = 0, | ||
176 | }, | ||
177 | }; | ||
178 | |||
179 | /* gpt parent select structure */ | ||
180 | static struct pclk_sel gpt_pclk_sel = { | ||
181 | .pclk_info = gpt_pclk_info, | ||
182 | .pclk_count = ARRAY_SIZE(gpt_pclk_info), | ||
183 | .pclk_sel_reg = PERIP_CLK_CFG, | ||
184 | .pclk_sel_mask = GPT_CLK_MASK, | ||
185 | }; | ||
186 | |||
187 | /* gpt0 configurations */ | ||
188 | static struct aux_clk_config gpt0_config = { | ||
189 | .synth_reg = PRSC1_CLK_CFG, | ||
190 | }; | ||
191 | |||
192 | /* gpt0 timer clock */ | ||
193 | static struct clk gpt0_clk = { | ||
194 | .flags = ALWAYS_ENABLED, | ||
195 | .pclk_sel = &gpt_pclk_sel, | ||
196 | .pclk_sel_shift = GPT0_CLK_SHIFT, | ||
197 | .recalc = &gpt_clk_recalc, | ||
198 | .private_data = &gpt0_config, | ||
199 | }; | ||
200 | |||
201 | /* gpt1 configurations */ | ||
202 | static struct aux_clk_config gpt1_config = { | ||
203 | .synth_reg = PRSC2_CLK_CFG, | ||
204 | }; | ||
205 | |||
206 | /* gpt1 timer clock */ | ||
207 | static struct clk gpt1_clk = { | ||
208 | .en_reg = PERIP1_CLK_ENB, | ||
209 | .en_reg_bit = GPT1_CLK_ENB, | ||
210 | .pclk_sel = &gpt_pclk_sel, | ||
211 | .pclk_sel_shift = GPT1_CLK_SHIFT, | ||
212 | .recalc = &gpt_clk_recalc, | ||
213 | .private_data = &gpt1_config, | ||
214 | }; | ||
215 | |||
216 | /* gpt2 configurations */ | ||
217 | static struct aux_clk_config gpt2_config = { | ||
218 | .synth_reg = PRSC3_CLK_CFG, | ||
219 | }; | ||
220 | |||
221 | /* gpt2 timer clock */ | ||
222 | static struct clk gpt2_clk = { | ||
223 | .en_reg = PERIP1_CLK_ENB, | ||
224 | .en_reg_bit = GPT2_CLK_ENB, | ||
225 | .pclk_sel = &gpt_pclk_sel, | ||
226 | .pclk_sel_shift = GPT2_CLK_SHIFT, | ||
227 | .recalc = &gpt_clk_recalc, | ||
228 | .private_data = &gpt2_config, | ||
229 | }; | ||
230 | |||
231 | /* clock derived from pll3 clk */ | ||
232 | /* usbh clock */ | ||
233 | static struct clk usbh_clk = { | ||
234 | .pclk = &pll3_48m_clk, | ||
235 | .en_reg = PERIP1_CLK_ENB, | ||
236 | .en_reg_bit = USBH_CLK_ENB, | ||
237 | .recalc = &follow_parent, | ||
238 | }; | ||
239 | |||
240 | /* usbd clock */ | ||
241 | static struct clk usbd_clk = { | ||
242 | .pclk = &pll3_48m_clk, | ||
243 | .en_reg = PERIP1_CLK_ENB, | ||
244 | .en_reg_bit = USBD_CLK_ENB, | ||
245 | .recalc = &follow_parent, | ||
246 | }; | ||
247 | |||
248 | /* clcd clock */ | ||
249 | static struct clk clcd_clk = { | ||
250 | .flags = ALWAYS_ENABLED, | ||
251 | .pclk = &pll3_48m_clk, | ||
252 | .recalc = &follow_parent, | ||
253 | }; | ||
254 | |||
255 | /* clock derived from ahb clk */ | ||
256 | /* apb configuration structure */ | ||
257 | static struct bus_clk_config apb_config = { | ||
258 | .reg = CORE_CLK_CFG, | ||
259 | .mask = HCLK_PCLK_RATIO_MASK, | ||
260 | .shift = HCLK_PCLK_RATIO_SHIFT, | ||
261 | }; | ||
262 | |||
263 | /* apb clock */ | ||
264 | static struct clk apb_clk = { | ||
265 | .flags = ALWAYS_ENABLED, | ||
266 | .pclk = &ahb_clk, | ||
267 | .recalc = &bus_clk_recalc, | ||
268 | .private_data = &apb_config, | ||
269 | }; | ||
270 | |||
271 | /* i2c clock */ | ||
272 | static struct clk i2c_clk = { | ||
273 | .pclk = &ahb_clk, | ||
274 | .en_reg = PERIP1_CLK_ENB, | ||
275 | .en_reg_bit = I2C_CLK_ENB, | ||
276 | .recalc = &follow_parent, | ||
277 | }; | ||
278 | |||
279 | /* dma clock */ | ||
280 | static struct clk dma_clk = { | ||
281 | .pclk = &ahb_clk, | ||
282 | .en_reg = PERIP1_CLK_ENB, | ||
283 | .en_reg_bit = DMA_CLK_ENB, | ||
284 | .recalc = &follow_parent, | ||
285 | }; | ||
286 | |||
287 | /* jpeg clock */ | ||
288 | static struct clk jpeg_clk = { | ||
289 | .pclk = &ahb_clk, | ||
290 | .en_reg = PERIP1_CLK_ENB, | ||
291 | .en_reg_bit = JPEG_CLK_ENB, | ||
292 | .recalc = &follow_parent, | ||
293 | }; | ||
294 | |||
295 | /* gmac clock */ | ||
296 | static struct clk gmac_clk = { | ||
297 | .pclk = &ahb_clk, | ||
298 | .en_reg = PERIP1_CLK_ENB, | ||
299 | .en_reg_bit = GMAC_CLK_ENB, | ||
300 | .recalc = &follow_parent, | ||
301 | }; | ||
302 | |||
303 | /* smi clock */ | ||
304 | static struct clk smi_clk = { | ||
305 | .pclk = &ahb_clk, | ||
306 | .en_reg = PERIP1_CLK_ENB, | ||
307 | .en_reg_bit = SMI_CLK_ENB, | ||
308 | .recalc = &follow_parent, | ||
309 | }; | ||
310 | |||
311 | /* c3 clock */ | ||
312 | static struct clk c3_clk = { | ||
313 | .pclk = &ahb_clk, | ||
314 | .en_reg = PERIP1_CLK_ENB, | ||
315 | .en_reg_bit = C3_CLK_ENB, | ||
316 | .recalc = &follow_parent, | ||
317 | }; | ||
318 | |||
319 | /* clock derived from apb clk */ | ||
320 | /* adc clock */ | ||
321 | static struct clk adc_clk = { | ||
322 | .pclk = &apb_clk, | ||
323 | .en_reg = PERIP1_CLK_ENB, | ||
324 | .en_reg_bit = ADC_CLK_ENB, | ||
325 | .recalc = &follow_parent, | ||
326 | }; | ||
327 | |||
328 | /* ssp clock */ | ||
329 | static struct clk ssp_clk = { | ||
330 | .pclk = &apb_clk, | ||
331 | .en_reg = PERIP1_CLK_ENB, | ||
332 | .en_reg_bit = SSP_CLK_ENB, | ||
333 | .recalc = &follow_parent, | ||
334 | }; | ||
335 | |||
336 | /* gpio clock */ | ||
337 | static struct clk gpio_clk = { | ||
338 | .pclk = &apb_clk, | ||
339 | .en_reg = PERIP1_CLK_ENB, | ||
340 | .en_reg_bit = GPIO_CLK_ENB, | ||
341 | .recalc = &follow_parent, | ||
342 | }; | ||
343 | |||
344 | /* array of all spear 3xx clock lookups */ | ||
345 | static struct clk_lookup spear_clk_lookups[] = { | ||
346 | /* root clks */ | ||
347 | { .con_id = "osc_32k_clk", .clk = &osc_32k_clk}, | ||
348 | { .con_id = "osc_24m_clk", .clk = &osc_24m_clk}, | ||
349 | /* clock derived from 32 KHz osc clk */ | ||
350 | { .dev_id = "rtc", .clk = &rtc_clk}, | ||
351 | /* clock derived from 24 MHz osc clk */ | ||
352 | { .con_id = "pll1_clk", .clk = &pll1_clk}, | ||
353 | { .con_id = "pll3_48m_clk", .clk = &pll3_48m_clk}, | ||
354 | { .dev_id = "wdt", .clk = &wdt_clk}, | ||
355 | /* clock derived from pll1 clk */ | ||
356 | { .con_id = "cpu_clk", .clk = &cpu_clk}, | ||
357 | { .con_id = "ahb_clk", .clk = &ahb_clk}, | ||
358 | { .dev_id = "uart", .clk = &uart_clk}, | ||
359 | { .dev_id = "firda", .clk = &firda_clk}, | ||
360 | { .dev_id = "gpt0", .clk = &gpt0_clk}, | ||
361 | { .dev_id = "gpt1", .clk = &gpt1_clk}, | ||
362 | { .dev_id = "gpt2", .clk = &gpt2_clk}, | ||
363 | /* clock derived from pll3 clk */ | ||
364 | { .dev_id = "usbh", .clk = &usbh_clk}, | ||
365 | { .dev_id = "usbd", .clk = &usbd_clk}, | ||
366 | { .dev_id = "clcd", .clk = &clcd_clk}, | ||
367 | /* clock derived from ahb clk */ | ||
368 | { .con_id = "apb_clk", .clk = &apb_clk}, | ||
369 | { .dev_id = "i2c", .clk = &i2c_clk}, | ||
370 | { .dev_id = "dma", .clk = &dma_clk}, | ||
371 | { .dev_id = "jpeg", .clk = &jpeg_clk}, | ||
372 | { .dev_id = "gmac", .clk = &gmac_clk}, | ||
373 | { .dev_id = "smi", .clk = &smi_clk}, | ||
374 | { .dev_id = "c3", .clk = &c3_clk}, | ||
375 | /* clock derived from apb clk */ | ||
376 | { .dev_id = "adc", .clk = &adc_clk}, | ||
377 | { .dev_id = "ssp", .clk = &ssp_clk}, | ||
378 | { .dev_id = "gpio", .clk = &gpio_clk}, | ||
379 | }; | ||
380 | |||
381 | void __init clk_init(void) | ||
382 | { | ||
383 | int i; | ||
384 | |||
385 | for (i = 0; i < ARRAY_SIZE(spear_clk_lookups); i++) | ||
386 | clk_register(&spear_clk_lookups[i]); | ||
387 | |||
388 | recalc_root_clocks(); | ||
389 | } | ||
diff --git a/arch/arm/mach-spear3xx/include/mach/clkdev.h b/arch/arm/mach-spear3xx/include/mach/clkdev.h new file mode 100644 index 000000000000..a3d07339d9f1 --- /dev/null +++ b/arch/arm/mach-spear3xx/include/mach/clkdev.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-spear3xx/include/mach/clkdev.h | ||
3 | * | ||
4 | * Clock Dev framework definitions for SPEAr3xx machine family | ||
5 | * | ||
6 | * Copyright (C) 2009 ST Microelectronics | ||
7 | * Viresh Kumar<viresh.kumar@st.com> | ||
8 | * | ||
9 | * This file is licensed under the terms of the GNU General Public | ||
10 | * License version 2. This program is licensed "as is" without any | ||
11 | * warranty of any kind, whether express or implied. | ||
12 | */ | ||
13 | |||
14 | #ifndef __MACH_CLKDEV_H | ||
15 | #define __MACH_CLKDEV_H | ||
16 | |||
17 | #include <plat/clkdev.h> | ||
18 | |||
19 | #endif /* __MACH_CLKDEV_H */ | ||
diff --git a/arch/arm/mach-spear3xx/include/mach/misc_regs.h b/arch/arm/mach-spear3xx/include/mach/misc_regs.h index 38d767a1aba0..38d767a1aba0 100755..100644 --- a/arch/arm/mach-spear3xx/include/mach/misc_regs.h +++ b/arch/arm/mach-spear3xx/include/mach/misc_regs.h | |||
diff --git a/arch/arm/mach-spear6xx/clock.c b/arch/arm/mach-spear6xx/clock.c new file mode 100644 index 000000000000..13e27c769685 --- /dev/null +++ b/arch/arm/mach-spear6xx/clock.c | |||
@@ -0,0 +1,483 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-spear6xx/clock.c | ||
3 | * | ||
4 | * SPEAr6xx machines clock framework source file | ||
5 | * | ||
6 | * Copyright (C) 2009 ST Microelectronics | ||
7 | * Viresh Kumar<viresh.kumar@st.com> | ||
8 | * | ||
9 | * This file is licensed under the terms of the GNU General Public | ||
10 | * License version 2. This program is licensed "as is" without any | ||
11 | * warranty of any kind, whether express or implied. | ||
12 | */ | ||
13 | |||
14 | #include <linux/init.h> | ||
15 | #include <linux/kernel.h> | ||
16 | #include <mach/misc_regs.h> | ||
17 | #include <plat/clock.h> | ||
18 | |||
19 | /* root clks */ | ||
20 | /* 32 KHz oscillator clock */ | ||
21 | static struct clk osc_32k_clk = { | ||
22 | .flags = ALWAYS_ENABLED, | ||
23 | .rate = 32000, | ||
24 | }; | ||
25 | |||
26 | /* 30 MHz oscillator clock */ | ||
27 | static struct clk osc_30m_clk = { | ||
28 | .flags = ALWAYS_ENABLED, | ||
29 | .rate = 30000000, | ||
30 | }; | ||
31 | |||
32 | /* clock derived from 32 KHz osc clk */ | ||
33 | /* rtc clock */ | ||
34 | static struct clk rtc_clk = { | ||
35 | .pclk = &osc_32k_clk, | ||
36 | .en_reg = PERIP1_CLK_ENB, | ||
37 | .en_reg_bit = RTC_CLK_ENB, | ||
38 | .recalc = &follow_parent, | ||
39 | }; | ||
40 | |||
41 | /* clock derived from 30 MHz osc clk */ | ||
42 | /* pll1 configuration structure */ | ||
43 | static struct pll_clk_config pll1_config = { | ||
44 | .mode_reg = PLL1_CTR, | ||
45 | .cfg_reg = PLL1_FRQ, | ||
46 | }; | ||
47 | |||
48 | /* PLL1 clock */ | ||
49 | static struct clk pll1_clk = { | ||
50 | .pclk = &osc_30m_clk, | ||
51 | .en_reg = PLL1_CTR, | ||
52 | .en_reg_bit = PLL_ENABLE, | ||
53 | .recalc = &pll1_clk_recalc, | ||
54 | .private_data = &pll1_config, | ||
55 | }; | ||
56 | |||
57 | /* PLL3 48 MHz clock */ | ||
58 | static struct clk pll3_48m_clk = { | ||
59 | .flags = ALWAYS_ENABLED, | ||
60 | .pclk = &osc_30m_clk, | ||
61 | .rate = 48000000, | ||
62 | }; | ||
63 | |||
64 | /* watch dog timer clock */ | ||
65 | static struct clk wdt_clk = { | ||
66 | .flags = ALWAYS_ENABLED, | ||
67 | .pclk = &osc_30m_clk, | ||
68 | .recalc = &follow_parent, | ||
69 | }; | ||
70 | |||
71 | /* clock derived from pll1 clk */ | ||
72 | /* cpu clock */ | ||
73 | static struct clk cpu_clk = { | ||
74 | .flags = ALWAYS_ENABLED, | ||
75 | .pclk = &pll1_clk, | ||
76 | .recalc = &follow_parent, | ||
77 | }; | ||
78 | |||
79 | /* ahb configuration structure */ | ||
80 | static struct bus_clk_config ahb_config = { | ||
81 | .reg = CORE_CLK_CFG, | ||
82 | .mask = PLL_HCLK_RATIO_MASK, | ||
83 | .shift = PLL_HCLK_RATIO_SHIFT, | ||
84 | }; | ||
85 | |||
86 | /* ahb clock */ | ||
87 | static struct clk ahb_clk = { | ||
88 | .flags = ALWAYS_ENABLED, | ||
89 | .pclk = &pll1_clk, | ||
90 | .recalc = &bus_clk_recalc, | ||
91 | .private_data = &ahb_config, | ||
92 | }; | ||
93 | |||
94 | /* uart parents */ | ||
95 | static struct pclk_info uart_pclk_info[] = { | ||
96 | { | ||
97 | .pclk = &pll1_clk, | ||
98 | .pclk_mask = AUX_CLK_PLL1_MASK, | ||
99 | .scalable = 1, | ||
100 | }, { | ||
101 | .pclk = &pll3_48m_clk, | ||
102 | .pclk_mask = AUX_CLK_PLL3_MASK, | ||
103 | .scalable = 0, | ||
104 | }, | ||
105 | }; | ||
106 | |||
107 | /* uart parent select structure */ | ||
108 | static struct pclk_sel uart_pclk_sel = { | ||
109 | .pclk_info = uart_pclk_info, | ||
110 | .pclk_count = ARRAY_SIZE(uart_pclk_info), | ||
111 | .pclk_sel_reg = PERIP_CLK_CFG, | ||
112 | .pclk_sel_mask = UART_CLK_MASK, | ||
113 | }; | ||
114 | |||
115 | /* uart configurations */ | ||
116 | static struct aux_clk_config uart_config = { | ||
117 | .synth_reg = UART_CLK_SYNT, | ||
118 | }; | ||
119 | |||
120 | /* uart0 clock */ | ||
121 | static struct clk uart0_clk = { | ||
122 | .en_reg = PERIP1_CLK_ENB, | ||
123 | .en_reg_bit = UART0_CLK_ENB, | ||
124 | .pclk_sel = &uart_pclk_sel, | ||
125 | .pclk_sel_shift = UART_CLK_SHIFT, | ||
126 | .recalc = &aux_clk_recalc, | ||
127 | .private_data = &uart_config, | ||
128 | }; | ||
129 | |||
130 | /* uart1 clock */ | ||
131 | static struct clk uart1_clk = { | ||
132 | .en_reg = PERIP1_CLK_ENB, | ||
133 | .en_reg_bit = UART1_CLK_ENB, | ||
134 | .pclk_sel = &uart_pclk_sel, | ||
135 | .pclk_sel_shift = UART_CLK_SHIFT, | ||
136 | .recalc = &aux_clk_recalc, | ||
137 | .private_data = &uart_config, | ||
138 | }; | ||
139 | |||
140 | /* firda configurations */ | ||
141 | static struct aux_clk_config firda_config = { | ||
142 | .synth_reg = FIRDA_CLK_SYNT, | ||
143 | }; | ||
144 | |||
145 | /* firda parents */ | ||
146 | static struct pclk_info firda_pclk_info[] = { | ||
147 | { | ||
148 | .pclk = &pll1_clk, | ||
149 | .pclk_mask = AUX_CLK_PLL1_MASK, | ||
150 | .scalable = 1, | ||
151 | }, { | ||
152 | .pclk = &pll3_48m_clk, | ||
153 | .pclk_mask = AUX_CLK_PLL3_MASK, | ||
154 | .scalable = 0, | ||
155 | }, | ||
156 | }; | ||
157 | |||
158 | /* firda parent select structure */ | ||
159 | static struct pclk_sel firda_pclk_sel = { | ||
160 | .pclk_info = firda_pclk_info, | ||
161 | .pclk_count = ARRAY_SIZE(firda_pclk_info), | ||
162 | .pclk_sel_reg = PERIP_CLK_CFG, | ||
163 | .pclk_sel_mask = FIRDA_CLK_MASK, | ||
164 | }; | ||
165 | |||
166 | /* firda clock */ | ||
167 | static struct clk firda_clk = { | ||
168 | .en_reg = PERIP1_CLK_ENB, | ||
169 | .en_reg_bit = FIRDA_CLK_ENB, | ||
170 | .pclk_sel = &firda_pclk_sel, | ||
171 | .pclk_sel_shift = FIRDA_CLK_SHIFT, | ||
172 | .recalc = &aux_clk_recalc, | ||
173 | .private_data = &firda_config, | ||
174 | }; | ||
175 | |||
176 | /* clcd configurations */ | ||
177 | static struct aux_clk_config clcd_config = { | ||
178 | .synth_reg = CLCD_CLK_SYNT, | ||
179 | }; | ||
180 | |||
181 | /* clcd parents */ | ||
182 | static struct pclk_info clcd_pclk_info[] = { | ||
183 | { | ||
184 | .pclk = &pll1_clk, | ||
185 | .pclk_mask = AUX_CLK_PLL1_MASK, | ||
186 | .scalable = 1, | ||
187 | }, { | ||
188 | .pclk = &pll3_48m_clk, | ||
189 | .pclk_mask = AUX_CLK_PLL3_MASK, | ||
190 | .scalable = 0, | ||
191 | }, | ||
192 | }; | ||
193 | |||
194 | /* clcd parent select structure */ | ||
195 | static struct pclk_sel clcd_pclk_sel = { | ||
196 | .pclk_info = clcd_pclk_info, | ||
197 | .pclk_count = ARRAY_SIZE(clcd_pclk_info), | ||
198 | .pclk_sel_reg = PERIP_CLK_CFG, | ||
199 | .pclk_sel_mask = CLCD_CLK_MASK, | ||
200 | }; | ||
201 | |||
202 | /* clcd clock */ | ||
203 | static struct clk clcd_clk = { | ||
204 | .en_reg = PERIP1_CLK_ENB, | ||
205 | .en_reg_bit = CLCD_CLK_ENB, | ||
206 | .pclk_sel = &clcd_pclk_sel, | ||
207 | .pclk_sel_shift = CLCD_CLK_SHIFT, | ||
208 | .recalc = &aux_clk_recalc, | ||
209 | .private_data = &clcd_config, | ||
210 | }; | ||
211 | |||
212 | /* gpt parents */ | ||
213 | static struct pclk_info gpt_pclk_info[] = { | ||
214 | { | ||
215 | .pclk = &pll1_clk, | ||
216 | .pclk_mask = AUX_CLK_PLL1_MASK, | ||
217 | .scalable = 1, | ||
218 | }, { | ||
219 | .pclk = &pll3_48m_clk, | ||
220 | .pclk_mask = AUX_CLK_PLL3_MASK, | ||
221 | .scalable = 0, | ||
222 | }, | ||
223 | }; | ||
224 | |||
225 | /* gpt parent select structure */ | ||
226 | static struct pclk_sel gpt_pclk_sel = { | ||
227 | .pclk_info = gpt_pclk_info, | ||
228 | .pclk_count = ARRAY_SIZE(gpt_pclk_info), | ||
229 | .pclk_sel_reg = PERIP_CLK_CFG, | ||
230 | .pclk_sel_mask = GPT_CLK_MASK, | ||
231 | }; | ||
232 | |||
233 | /* gpt0_1 configurations */ | ||
234 | static struct aux_clk_config gpt0_1_config = { | ||
235 | .synth_reg = PRSC1_CLK_CFG, | ||
236 | }; | ||
237 | |||
238 | /* gpt0 ARM1 subsystem timer clock */ | ||
239 | static struct clk gpt0_clk = { | ||
240 | .flags = ALWAYS_ENABLED, | ||
241 | .pclk_sel = &gpt_pclk_sel, | ||
242 | .pclk_sel_shift = GPT0_CLK_SHIFT, | ||
243 | .recalc = &gpt_clk_recalc, | ||
244 | .private_data = &gpt0_1_config, | ||
245 | }; | ||
246 | |||
247 | /* gpt1 timer clock */ | ||
248 | static struct clk gpt1_clk = { | ||
249 | .flags = ALWAYS_ENABLED, | ||
250 | .pclk_sel = &gpt_pclk_sel, | ||
251 | .pclk_sel_shift = GPT1_CLK_SHIFT, | ||
252 | .recalc = &gpt_clk_recalc, | ||
253 | .private_data = &gpt0_1_config, | ||
254 | }; | ||
255 | |||
256 | /* gpt2 configurations */ | ||
257 | static struct aux_clk_config gpt2_config = { | ||
258 | .synth_reg = PRSC2_CLK_CFG, | ||
259 | }; | ||
260 | |||
261 | /* gpt2 timer clock */ | ||
262 | static struct clk gpt2_clk = { | ||
263 | .en_reg = PERIP1_CLK_ENB, | ||
264 | .en_reg_bit = GPT2_CLK_ENB, | ||
265 | .pclk_sel = &gpt_pclk_sel, | ||
266 | .pclk_sel_shift = GPT2_CLK_SHIFT, | ||
267 | .recalc = &gpt_clk_recalc, | ||
268 | .private_data = &gpt2_config, | ||
269 | }; | ||
270 | |||
271 | /* gpt3 configurations */ | ||
272 | static struct aux_clk_config gpt3_config = { | ||
273 | .synth_reg = PRSC3_CLK_CFG, | ||
274 | }; | ||
275 | |||
276 | /* gpt3 timer clock */ | ||
277 | static struct clk gpt3_clk = { | ||
278 | .en_reg = PERIP1_CLK_ENB, | ||
279 | .en_reg_bit = GPT3_CLK_ENB, | ||
280 | .pclk_sel = &gpt_pclk_sel, | ||
281 | .pclk_sel_shift = GPT3_CLK_SHIFT, | ||
282 | .recalc = &gpt_clk_recalc, | ||
283 | .private_data = &gpt3_config, | ||
284 | }; | ||
285 | |||
286 | /* clock derived from pll3 clk */ | ||
287 | /* usbh0 clock */ | ||
288 | static struct clk usbh0_clk = { | ||
289 | .pclk = &pll3_48m_clk, | ||
290 | .en_reg = PERIP1_CLK_ENB, | ||
291 | .en_reg_bit = USBH0_CLK_ENB, | ||
292 | .recalc = &follow_parent, | ||
293 | }; | ||
294 | |||
295 | /* usbh1 clock */ | ||
296 | static struct clk usbh1_clk = { | ||
297 | .pclk = &pll3_48m_clk, | ||
298 | .en_reg = PERIP1_CLK_ENB, | ||
299 | .en_reg_bit = USBH1_CLK_ENB, | ||
300 | .recalc = &follow_parent, | ||
301 | }; | ||
302 | |||
303 | /* usbd clock */ | ||
304 | static struct clk usbd_clk = { | ||
305 | .pclk = &pll3_48m_clk, | ||
306 | .en_reg = PERIP1_CLK_ENB, | ||
307 | .en_reg_bit = USBD_CLK_ENB, | ||
308 | .recalc = &follow_parent, | ||
309 | }; | ||
310 | |||
311 | /* clock derived from ahb clk */ | ||
312 | /* apb configuration structure */ | ||
313 | static struct bus_clk_config apb_config = { | ||
314 | .reg = CORE_CLK_CFG, | ||
315 | .mask = HCLK_PCLK_RATIO_MASK, | ||
316 | .shift = HCLK_PCLK_RATIO_SHIFT, | ||
317 | }; | ||
318 | |||
319 | /* apb clock */ | ||
320 | static struct clk apb_clk = { | ||
321 | .flags = ALWAYS_ENABLED, | ||
322 | .pclk = &ahb_clk, | ||
323 | .recalc = &bus_clk_recalc, | ||
324 | .private_data = &apb_config, | ||
325 | }; | ||
326 | |||
327 | /* i2c clock */ | ||
328 | static struct clk i2c_clk = { | ||
329 | .pclk = &ahb_clk, | ||
330 | .en_reg = PERIP1_CLK_ENB, | ||
331 | .en_reg_bit = I2C_CLK_ENB, | ||
332 | .recalc = &follow_parent, | ||
333 | }; | ||
334 | |||
335 | /* dma clock */ | ||
336 | static struct clk dma_clk = { | ||
337 | .pclk = &ahb_clk, | ||
338 | .en_reg = PERIP1_CLK_ENB, | ||
339 | .en_reg_bit = DMA_CLK_ENB, | ||
340 | .recalc = &follow_parent, | ||
341 | }; | ||
342 | |||
343 | /* jpeg clock */ | ||
344 | static struct clk jpeg_clk = { | ||
345 | .pclk = &ahb_clk, | ||
346 | .en_reg = PERIP1_CLK_ENB, | ||
347 | .en_reg_bit = JPEG_CLK_ENB, | ||
348 | .recalc = &follow_parent, | ||
349 | }; | ||
350 | |||
351 | /* gmac clock */ | ||
352 | static struct clk gmac_clk = { | ||
353 | .pclk = &ahb_clk, | ||
354 | .en_reg = PERIP1_CLK_ENB, | ||
355 | .en_reg_bit = GMAC_CLK_ENB, | ||
356 | .recalc = &follow_parent, | ||
357 | }; | ||
358 | |||
359 | /* smi clock */ | ||
360 | static struct clk smi_clk = { | ||
361 | .pclk = &ahb_clk, | ||
362 | .en_reg = PERIP1_CLK_ENB, | ||
363 | .en_reg_bit = SMI_CLK_ENB, | ||
364 | .recalc = &follow_parent, | ||
365 | }; | ||
366 | |||
367 | /* fsmc clock */ | ||
368 | static struct clk fsmc_clk = { | ||
369 | .pclk = &ahb_clk, | ||
370 | .en_reg = PERIP1_CLK_ENB, | ||
371 | .en_reg_bit = FSMC_CLK_ENB, | ||
372 | .recalc = &follow_parent, | ||
373 | }; | ||
374 | |||
375 | /* clock derived from apb clk */ | ||
376 | /* adc clock */ | ||
377 | static struct clk adc_clk = { | ||
378 | .pclk = &apb_clk, | ||
379 | .en_reg = PERIP1_CLK_ENB, | ||
380 | .en_reg_bit = ADC_CLK_ENB, | ||
381 | .recalc = &follow_parent, | ||
382 | }; | ||
383 | |||
384 | /* ssp0 clock */ | ||
385 | static struct clk ssp0_clk = { | ||
386 | .pclk = &apb_clk, | ||
387 | .en_reg = PERIP1_CLK_ENB, | ||
388 | .en_reg_bit = SSP0_CLK_ENB, | ||
389 | .recalc = &follow_parent, | ||
390 | }; | ||
391 | |||
392 | /* ssp1 clock */ | ||
393 | static struct clk ssp1_clk = { | ||
394 | .pclk = &apb_clk, | ||
395 | .en_reg = PERIP1_CLK_ENB, | ||
396 | .en_reg_bit = SSP1_CLK_ENB, | ||
397 | .recalc = &follow_parent, | ||
398 | }; | ||
399 | |||
400 | /* ssp2 clock */ | ||
401 | static struct clk ssp2_clk = { | ||
402 | .pclk = &apb_clk, | ||
403 | .en_reg = PERIP1_CLK_ENB, | ||
404 | .en_reg_bit = SSP2_CLK_ENB, | ||
405 | .recalc = &follow_parent, | ||
406 | }; | ||
407 | |||
408 | /* gpio0 ARM subsystem clock */ | ||
409 | static struct clk gpio0_clk = { | ||
410 | .flags = ALWAYS_ENABLED, | ||
411 | .pclk = &apb_clk, | ||
412 | .recalc = &follow_parent, | ||
413 | }; | ||
414 | |||
415 | /* gpio1 clock */ | ||
416 | static struct clk gpio1_clk = { | ||
417 | .pclk = &apb_clk, | ||
418 | .en_reg = PERIP1_CLK_ENB, | ||
419 | .en_reg_bit = GPIO1_CLK_ENB, | ||
420 | .recalc = &follow_parent, | ||
421 | }; | ||
422 | |||
423 | /* gpio2 clock */ | ||
424 | static struct clk gpio2_clk = { | ||
425 | .pclk = &apb_clk, | ||
426 | .en_reg = PERIP1_CLK_ENB, | ||
427 | .en_reg_bit = GPIO2_CLK_ENB, | ||
428 | .recalc = &follow_parent, | ||
429 | }; | ||
430 | |||
431 | /* array of all spear 6xx clock lookups */ | ||
432 | static struct clk_lookup spear_clk_lookups[] = { | ||
433 | /* root clks */ | ||
434 | { .con_id = "osc_32k_clk", .clk = &osc_32k_clk}, | ||
435 | { .con_id = "osc_30m_clk", .clk = &osc_30m_clk}, | ||
436 | /* clock derived from 32 KHz os clk */ | ||
437 | { .dev_id = "rtc", .clk = &rtc_clk}, | ||
438 | /* clock derived from 30 MHz os clk */ | ||
439 | { .con_id = "pll1_clk", .clk = &pll1_clk}, | ||
440 | { .con_id = "pll3_48m_clk", .clk = &pll3_48m_clk}, | ||
441 | { .dev_id = "wdt", .clk = &wdt_clk}, | ||
442 | /* clock derived from pll1 clk */ | ||
443 | { .con_id = "cpu_clk", .clk = &cpu_clk}, | ||
444 | { .con_id = "ahb_clk", .clk = &ahb_clk}, | ||
445 | { .dev_id = "uart0", .clk = &uart0_clk}, | ||
446 | { .dev_id = "uart1", .clk = &uart1_clk}, | ||
447 | { .dev_id = "firda", .clk = &firda_clk}, | ||
448 | { .dev_id = "clcd", .clk = &clcd_clk}, | ||
449 | { .dev_id = "gpt0", .clk = &gpt0_clk}, | ||
450 | { .dev_id = "gpt1", .clk = &gpt1_clk}, | ||
451 | { .dev_id = "gpt2", .clk = &gpt2_clk}, | ||
452 | { .dev_id = "gpt3", .clk = &gpt3_clk}, | ||
453 | /* clock derived from pll3 clk */ | ||
454 | { .dev_id = "usbh0", .clk = &usbh0_clk}, | ||
455 | { .dev_id = "usbh1", .clk = &usbh1_clk}, | ||
456 | { .dev_id = "usbd", .clk = &usbd_clk}, | ||
457 | /* clock derived from ahb clk */ | ||
458 | { .con_id = "apb_clk", .clk = &apb_clk}, | ||
459 | { .dev_id = "i2c", .clk = &i2c_clk}, | ||
460 | { .dev_id = "dma", .clk = &dma_clk}, | ||
461 | { .dev_id = "jpeg", .clk = &jpeg_clk}, | ||
462 | { .dev_id = "gmac", .clk = &gmac_clk}, | ||
463 | { .dev_id = "smi", .clk = &smi_clk}, | ||
464 | { .dev_id = "fsmc", .clk = &fsmc_clk}, | ||
465 | /* clock derived from apb clk */ | ||
466 | { .dev_id = "adc", .clk = &adc_clk}, | ||
467 | { .dev_id = "ssp0", .clk = &ssp0_clk}, | ||
468 | { .dev_id = "ssp1", .clk = &ssp1_clk}, | ||
469 | { .dev_id = "ssp2", .clk = &ssp2_clk}, | ||
470 | { .dev_id = "gpio0", .clk = &gpio0_clk}, | ||
471 | { .dev_id = "gpio1", .clk = &gpio1_clk}, | ||
472 | { .dev_id = "gpio2", .clk = &gpio2_clk}, | ||
473 | }; | ||
474 | |||
475 | void __init clk_init(void) | ||
476 | { | ||
477 | int i; | ||
478 | |||
479 | for (i = 0; i < ARRAY_SIZE(spear_clk_lookups); i++) | ||
480 | clk_register(&spear_clk_lookups[i]); | ||
481 | |||
482 | recalc_root_clocks(); | ||
483 | } | ||
diff --git a/arch/arm/mach-spear6xx/include/mach/clkdev.h b/arch/arm/mach-spear6xx/include/mach/clkdev.h new file mode 100644 index 000000000000..05676bf440d3 --- /dev/null +++ b/arch/arm/mach-spear6xx/include/mach/clkdev.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-spear6xx/include/mach/clkdev.h | ||
3 | * | ||
4 | * Clock Dev framework definitions for SPEAr6xx machine family | ||
5 | * | ||
6 | * Copyright (C) 2009 ST Microelectronics | ||
7 | * Viresh Kumar<viresh.kumar@st.com> | ||
8 | * | ||
9 | * This file is licensed under the terms of the GNU General Public | ||
10 | * License version 2. This program is licensed "as is" without any | ||
11 | * warranty of any kind, whether express or implied. | ||
12 | */ | ||
13 | |||
14 | #ifndef __MACH_CLKDEV_H | ||
15 | #define __MACH_CLKDEV_H | ||
16 | |||
17 | #include <plat/clkdev.h> | ||
18 | |||
19 | #endif /* __MACH_CLKDEV_H */ | ||
diff --git a/arch/arm/plat-spear/clock.c b/arch/arm/plat-spear/clock.c new file mode 100644 index 000000000000..ee4f90e534d8 --- /dev/null +++ b/arch/arm/plat-spear/clock.c | |||
@@ -0,0 +1,435 @@ | |||
1 | /* | ||
2 | * arch/arm/plat-spear/clock.c | ||
3 | * | ||
4 | * Clock framework for SPEAr platform | ||
5 | * | ||
6 | * Copyright (C) 2009 ST Microelectronics | ||
7 | * Viresh Kumar<viresh.kumar@st.com> | ||
8 | * | ||
9 | * This file is licensed under the terms of the GNU General Public | ||
10 | * License version 2. This program is licensed "as is" without any | ||
11 | * warranty of any kind, whether express or implied. | ||
12 | */ | ||
13 | |||
14 | #include <linux/bug.h> | ||
15 | #include <linux/err.h> | ||
16 | #include <linux/io.h> | ||
17 | #include <linux/list.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/spinlock.h> | ||
20 | #include <mach/misc_regs.h> | ||
21 | #include <plat/clock.h> | ||
22 | |||
23 | static DEFINE_SPINLOCK(clocks_lock); | ||
24 | static LIST_HEAD(root_clks); | ||
25 | |||
26 | static void propagate_rate(struct list_head *); | ||
27 | |||
28 | static int generic_clk_enable(struct clk *clk) | ||
29 | { | ||
30 | unsigned int val; | ||
31 | |||
32 | if (!clk->en_reg) | ||
33 | return -EFAULT; | ||
34 | |||
35 | val = readl(clk->en_reg); | ||
36 | if (unlikely(clk->flags & RESET_TO_ENABLE)) | ||
37 | val &= ~(1 << clk->en_reg_bit); | ||
38 | else | ||
39 | val |= 1 << clk->en_reg_bit; | ||
40 | |||
41 | writel(val, clk->en_reg); | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | static void generic_clk_disable(struct clk *clk) | ||
47 | { | ||
48 | unsigned int val; | ||
49 | |||
50 | if (!clk->en_reg) | ||
51 | return; | ||
52 | |||
53 | val = readl(clk->en_reg); | ||
54 | if (unlikely(clk->flags & RESET_TO_ENABLE)) | ||
55 | val |= 1 << clk->en_reg_bit; | ||
56 | else | ||
57 | val &= ~(1 << clk->en_reg_bit); | ||
58 | |||
59 | writel(val, clk->en_reg); | ||
60 | } | ||
61 | |||
62 | /* generic clk ops */ | ||
63 | static struct clkops generic_clkops = { | ||
64 | .enable = generic_clk_enable, | ||
65 | .disable = generic_clk_disable, | ||
66 | }; | ||
67 | |||
68 | /* | ||
69 | * clk_enable - inform the system when the clock source should be running. | ||
70 | * @clk: clock source | ||
71 | * | ||
72 | * If the clock can not be enabled/disabled, this should return success. | ||
73 | * | ||
74 | * Returns success (0) or negative errno. | ||
75 | */ | ||
76 | int clk_enable(struct clk *clk) | ||
77 | { | ||
78 | unsigned long flags; | ||
79 | int ret = 0; | ||
80 | |||
81 | if (!clk || IS_ERR(clk)) | ||
82 | return -EFAULT; | ||
83 | |||
84 | spin_lock_irqsave(&clocks_lock, flags); | ||
85 | if (clk->usage_count == 0) { | ||
86 | if (clk->ops && clk->ops->enable) | ||
87 | ret = clk->ops->enable(clk); | ||
88 | } | ||
89 | clk->usage_count++; | ||
90 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
91 | |||
92 | return ret; | ||
93 | } | ||
94 | EXPORT_SYMBOL(clk_enable); | ||
95 | |||
96 | /* | ||
97 | * clk_disable - inform the system when the clock source is no longer required. | ||
98 | * @clk: clock source | ||
99 | * | ||
100 | * Inform the system that a clock source is no longer required by | ||
101 | * a driver and may be shut down. | ||
102 | * | ||
103 | * Implementation detail: if the clock source is shared between | ||
104 | * multiple drivers, clk_enable() calls must be balanced by the | ||
105 | * same number of clk_disable() calls for the clock source to be | ||
106 | * disabled. | ||
107 | */ | ||
108 | void clk_disable(struct clk *clk) | ||
109 | { | ||
110 | unsigned long flags; | ||
111 | |||
112 | if (!clk || IS_ERR(clk)) | ||
113 | return; | ||
114 | |||
115 | WARN_ON(clk->usage_count == 0); | ||
116 | |||
117 | spin_lock_irqsave(&clocks_lock, flags); | ||
118 | clk->usage_count--; | ||
119 | if (clk->usage_count == 0) { | ||
120 | if (clk->ops && clk->ops->disable) | ||
121 | clk->ops->disable(clk); | ||
122 | } | ||
123 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
124 | } | ||
125 | EXPORT_SYMBOL(clk_disable); | ||
126 | |||
127 | /** | ||
128 | * clk_get_rate - obtain the current clock rate (in Hz) for a clock source. | ||
129 | * This is only valid once the clock source has been enabled. | ||
130 | * @clk: clock source | ||
131 | */ | ||
132 | unsigned long clk_get_rate(struct clk *clk) | ||
133 | { | ||
134 | unsigned long flags, rate; | ||
135 | |||
136 | spin_lock_irqsave(&clocks_lock, flags); | ||
137 | rate = clk->rate; | ||
138 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
139 | |||
140 | return rate; | ||
141 | } | ||
142 | EXPORT_SYMBOL(clk_get_rate); | ||
143 | |||
144 | /** | ||
145 | * clk_set_parent - set the parent clock source for this clock | ||
146 | * @clk: clock source | ||
147 | * @parent: parent clock source | ||
148 | * | ||
149 | * Returns success (0) or negative errno. | ||
150 | */ | ||
151 | int clk_set_parent(struct clk *clk, struct clk *parent) | ||
152 | { | ||
153 | int i, found = 0, val = 0; | ||
154 | unsigned long flags; | ||
155 | |||
156 | if (!clk || IS_ERR(clk) || !parent || IS_ERR(parent)) | ||
157 | return -EFAULT; | ||
158 | if (clk->usage_count) | ||
159 | return -EBUSY; | ||
160 | if (!clk->pclk_sel) | ||
161 | return -EPERM; | ||
162 | if (clk->pclk == parent) | ||
163 | return 0; | ||
164 | |||
165 | for (i = 0; i < clk->pclk_sel->pclk_count; i++) { | ||
166 | if (clk->pclk_sel->pclk_info[i].pclk == parent) { | ||
167 | found = 1; | ||
168 | break; | ||
169 | } | ||
170 | } | ||
171 | |||
172 | if (!found) | ||
173 | return -EINVAL; | ||
174 | |||
175 | spin_lock_irqsave(&clocks_lock, flags); | ||
176 | /* reflect parent change in hardware */ | ||
177 | val = readl(clk->pclk_sel->pclk_sel_reg); | ||
178 | val &= ~(clk->pclk_sel->pclk_sel_mask << clk->pclk_sel_shift); | ||
179 | val |= clk->pclk_sel->pclk_info[i].pclk_mask << clk->pclk_sel_shift; | ||
180 | writel(val, clk->pclk_sel->pclk_sel_reg); | ||
181 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
182 | |||
183 | /* reflect parent change in software */ | ||
184 | clk->recalc(clk); | ||
185 | propagate_rate(&clk->children); | ||
186 | return 0; | ||
187 | } | ||
188 | EXPORT_SYMBOL(clk_set_parent); | ||
189 | |||
190 | /* registers clock in platform clock framework */ | ||
191 | void clk_register(struct clk_lookup *cl) | ||
192 | { | ||
193 | struct clk *clk = cl->clk; | ||
194 | unsigned long flags; | ||
195 | |||
196 | if (!clk || IS_ERR(clk)) | ||
197 | return; | ||
198 | |||
199 | spin_lock_irqsave(&clocks_lock, flags); | ||
200 | |||
201 | INIT_LIST_HEAD(&clk->children); | ||
202 | if (clk->flags & ALWAYS_ENABLED) | ||
203 | clk->ops = NULL; | ||
204 | else if (!clk->ops) | ||
205 | clk->ops = &generic_clkops; | ||
206 | |||
207 | /* root clock don't have any parents */ | ||
208 | if (!clk->pclk && !clk->pclk_sel) { | ||
209 | list_add(&clk->sibling, &root_clks); | ||
210 | /* add clocks with only one parent to parent's children list */ | ||
211 | } else if (clk->pclk && !clk->pclk_sel) { | ||
212 | list_add(&clk->sibling, &clk->pclk->children); | ||
213 | } else { | ||
214 | /* add clocks with > 1 parent to 1st parent's children list */ | ||
215 | list_add(&clk->sibling, | ||
216 | &clk->pclk_sel->pclk_info[0].pclk->children); | ||
217 | } | ||
218 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
219 | |||
220 | /* add clock to arm clockdev framework */ | ||
221 | clkdev_add(cl); | ||
222 | } | ||
223 | |||
224 | /** | ||
225 | * propagate_rate - recalculate and propagate all clocks in list head | ||
226 | * | ||
227 | * Recalculates all root clocks in list head, which if the clock's .recalc is | ||
228 | * set correctly, should also propagate their rates. | ||
229 | */ | ||
230 | static void propagate_rate(struct list_head *lhead) | ||
231 | { | ||
232 | struct clk *clkp, *_temp; | ||
233 | |||
234 | list_for_each_entry_safe(clkp, _temp, lhead, sibling) { | ||
235 | if (clkp->recalc) | ||
236 | clkp->recalc(clkp); | ||
237 | propagate_rate(&clkp->children); | ||
238 | } | ||
239 | } | ||
240 | |||
241 | /* returns current programmed clocks clock info structure */ | ||
242 | static struct pclk_info *pclk_info_get(struct clk *clk) | ||
243 | { | ||
244 | unsigned int mask, i; | ||
245 | unsigned long flags; | ||
246 | struct pclk_info *info = NULL; | ||
247 | |||
248 | spin_lock_irqsave(&clocks_lock, flags); | ||
249 | mask = (readl(clk->pclk_sel->pclk_sel_reg) >> clk->pclk_sel_shift) | ||
250 | & clk->pclk_sel->pclk_sel_mask; | ||
251 | |||
252 | for (i = 0; i < clk->pclk_sel->pclk_count; i++) { | ||
253 | if (clk->pclk_sel->pclk_info[i].pclk_mask == mask) | ||
254 | info = &clk->pclk_sel->pclk_info[i]; | ||
255 | } | ||
256 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
257 | |||
258 | return info; | ||
259 | } | ||
260 | |||
261 | /* | ||
262 | * Set pclk as cclk's parent and add clock sibling node to current parents | ||
263 | * children list | ||
264 | */ | ||
265 | static void change_parent(struct clk *cclk, struct clk *pclk) | ||
266 | { | ||
267 | unsigned long flags; | ||
268 | |||
269 | spin_lock_irqsave(&clocks_lock, flags); | ||
270 | list_del(&cclk->sibling); | ||
271 | list_add(&cclk->sibling, &pclk->children); | ||
272 | |||
273 | cclk->pclk = pclk; | ||
274 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
275 | } | ||
276 | |||
277 | /* | ||
278 | * calculates current programmed rate of pll1 | ||
279 | * | ||
280 | * In normal mode | ||
281 | * rate = (2 * M[15:8] * Fin)/(N * 2^P) | ||
282 | * | ||
283 | * In Dithered mode | ||
284 | * rate = (2 * M[15:0] * Fin)/(256 * N * 2^P) | ||
285 | */ | ||
286 | void pll1_clk_recalc(struct clk *clk) | ||
287 | { | ||
288 | struct pll_clk_config *config = clk->private_data; | ||
289 | unsigned int num = 2, den = 0, val, mode = 0; | ||
290 | unsigned long flags; | ||
291 | |||
292 | spin_lock_irqsave(&clocks_lock, flags); | ||
293 | mode = (readl(config->mode_reg) >> PLL_MODE_SHIFT) & | ||
294 | PLL_MODE_MASK; | ||
295 | |||
296 | val = readl(config->cfg_reg); | ||
297 | /* calculate denominator */ | ||
298 | den = (val >> PLL_DIV_P_SHIFT) & PLL_DIV_P_MASK; | ||
299 | den = 1 << den; | ||
300 | den *= (val >> PLL_DIV_N_SHIFT) & PLL_DIV_N_MASK; | ||
301 | |||
302 | /* calculate numerator & denominator */ | ||
303 | if (!mode) { | ||
304 | /* Normal mode */ | ||
305 | num *= (val >> PLL_NORM_FDBK_M_SHIFT) & PLL_NORM_FDBK_M_MASK; | ||
306 | } else { | ||
307 | /* Dithered mode */ | ||
308 | num *= (val >> PLL_DITH_FDBK_M_SHIFT) & PLL_DITH_FDBK_M_MASK; | ||
309 | den *= 256; | ||
310 | } | ||
311 | |||
312 | clk->rate = (((clk->pclk->rate/10000) * num) / den) * 10000; | ||
313 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
314 | } | ||
315 | |||
316 | /* calculates current programmed rate of ahb or apb bus */ | ||
317 | void bus_clk_recalc(struct clk *clk) | ||
318 | { | ||
319 | struct bus_clk_config *config = clk->private_data; | ||
320 | unsigned int div; | ||
321 | unsigned long flags; | ||
322 | |||
323 | spin_lock_irqsave(&clocks_lock, flags); | ||
324 | div = ((readl(config->reg) >> config->shift) & config->mask) + 1; | ||
325 | clk->rate = (unsigned long)clk->pclk->rate / div; | ||
326 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
327 | } | ||
328 | |||
329 | /* | ||
330 | * calculates current programmed rate of auxiliary synthesizers | ||
331 | * used by: UART, FIRDA | ||
332 | * | ||
333 | * Fout from synthesizer can be given from two equations: | ||
334 | * Fout1 = (Fin * X/Y)/2 | ||
335 | * Fout2 = Fin * X/Y | ||
336 | * | ||
337 | * Selection of eqn 1 or 2 is programmed in register | ||
338 | */ | ||
339 | void aux_clk_recalc(struct clk *clk) | ||
340 | { | ||
341 | struct aux_clk_config *config = clk->private_data; | ||
342 | struct pclk_info *pclk_info = NULL; | ||
343 | unsigned int num = 1, den = 1, val, eqn; | ||
344 | unsigned long flags; | ||
345 | |||
346 | /* get current programmed parent */ | ||
347 | pclk_info = pclk_info_get(clk); | ||
348 | if (!pclk_info) { | ||
349 | spin_lock_irqsave(&clocks_lock, flags); | ||
350 | clk->pclk = NULL; | ||
351 | clk->rate = 0; | ||
352 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
353 | return; | ||
354 | } | ||
355 | |||
356 | change_parent(clk, pclk_info->pclk); | ||
357 | |||
358 | spin_lock_irqsave(&clocks_lock, flags); | ||
359 | if (pclk_info->scalable) { | ||
360 | val = readl(config->synth_reg); | ||
361 | |||
362 | eqn = (val >> AUX_EQ_SEL_SHIFT) & AUX_EQ_SEL_MASK; | ||
363 | if (eqn == AUX_EQ1_SEL) | ||
364 | den *= 2; | ||
365 | |||
366 | /* calculate numerator */ | ||
367 | num = (val >> AUX_XSCALE_SHIFT) & AUX_XSCALE_MASK; | ||
368 | |||
369 | /* calculate denominator */ | ||
370 | den *= (val >> AUX_YSCALE_SHIFT) & AUX_YSCALE_MASK; | ||
371 | val = (((clk->pclk->rate/10000) * num) / den) * 10000; | ||
372 | } else | ||
373 | val = clk->pclk->rate; | ||
374 | |||
375 | clk->rate = val; | ||
376 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
377 | } | ||
378 | |||
379 | /* | ||
380 | * calculates current programmed rate of gpt synthesizers | ||
381 | * Fout from synthesizer can be given from below equations: | ||
382 | * Fout= Fin/((2 ^ (N+1)) * (M+1)) | ||
383 | */ | ||
384 | void gpt_clk_recalc(struct clk *clk) | ||
385 | { | ||
386 | struct aux_clk_config *config = clk->private_data; | ||
387 | struct pclk_info *pclk_info = NULL; | ||
388 | unsigned int div = 1, val; | ||
389 | unsigned long flags; | ||
390 | |||
391 | pclk_info = pclk_info_get(clk); | ||
392 | if (!pclk_info) { | ||
393 | spin_lock_irqsave(&clocks_lock, flags); | ||
394 | clk->pclk = NULL; | ||
395 | clk->rate = 0; | ||
396 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
397 | return; | ||
398 | } | ||
399 | |||
400 | change_parent(clk, pclk_info->pclk); | ||
401 | |||
402 | spin_lock_irqsave(&clocks_lock, flags); | ||
403 | if (pclk_info->scalable) { | ||
404 | val = readl(config->synth_reg); | ||
405 | div += (val >> GPT_MSCALE_SHIFT) & GPT_MSCALE_MASK; | ||
406 | div *= 1 << (((val >> GPT_NSCALE_SHIFT) & GPT_NSCALE_MASK) + 1); | ||
407 | } | ||
408 | |||
409 | clk->rate = (unsigned long)clk->pclk->rate / div; | ||
410 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
411 | } | ||
412 | |||
413 | /* | ||
414 | * Used for clocks that always have same value as the parent clock divided by a | ||
415 | * fixed divisor | ||
416 | */ | ||
417 | void follow_parent(struct clk *clk) | ||
418 | { | ||
419 | unsigned long flags; | ||
420 | |||
421 | spin_lock_irqsave(&clocks_lock, flags); | ||
422 | clk->rate = clk->pclk->rate; | ||
423 | spin_unlock_irqrestore(&clocks_lock, flags); | ||
424 | } | ||
425 | |||
426 | /** | ||
427 | * recalc_root_clocks - recalculate and propagate all root clocks | ||
428 | * | ||
429 | * Recalculates all root clocks (clocks with no parent), which if the | ||
430 | * clock's .recalc is set correctly, should also propagate their rates. | ||
431 | */ | ||
432 | void recalc_root_clocks(void) | ||
433 | { | ||
434 | propagate_rate(&root_clks); | ||
435 | } | ||
diff --git a/arch/arm/plat-spear/include/plat/clkdev.h b/arch/arm/plat-spear/include/plat/clkdev.h new file mode 100644 index 000000000000..a2d0112fcaf7 --- /dev/null +++ b/arch/arm/plat-spear/include/plat/clkdev.h | |||
@@ -0,0 +1,20 @@ | |||
1 | /* | ||
2 | * arch/arm/plat-spear/include/plat/clkdev.h | ||
3 | * | ||
4 | * Clock Dev framework definitions for SPEAr platform | ||
5 | * | ||
6 | * Copyright (C) 2009 ST Microelectronics | ||
7 | * Viresh Kumar<viresh.kumar@st.com> | ||
8 | * | ||
9 | * This file is licensed under the terms of the GNU General Public | ||
10 | * License version 2. This program is licensed "as is" without any | ||
11 | * warranty of any kind, whether express or implied. | ||
12 | */ | ||
13 | |||
14 | #ifndef __PLAT_CLKDEV_H | ||
15 | #define __PLAT_CLKDEV_H | ||
16 | |||
17 | #define __clk_get(clk) ({ 1; }) | ||
18 | #define __clk_put(clk) do { } while (0) | ||
19 | |||
20 | #endif /* __PLAT_CLKDEV_H */ | ||
diff --git a/arch/arm/plat-spear/include/plat/clock.h b/arch/arm/plat-spear/include/plat/clock.h new file mode 100644 index 000000000000..298bafc0a52f --- /dev/null +++ b/arch/arm/plat-spear/include/plat/clock.h | |||
@@ -0,0 +1,126 @@ | |||
1 | /* | ||
2 | * arch/arm/plat-spear/include/plat/clock.h | ||
3 | * | ||
4 | * Clock framework definitions for SPEAr platform | ||
5 | * | ||
6 | * Copyright (C) 2009 ST Microelectronics | ||
7 | * Viresh Kumar<viresh.kumar@st.com> | ||
8 | * | ||
9 | * This file is licensed under the terms of the GNU General Public | ||
10 | * License version 2. This program is licensed "as is" without any | ||
11 | * warranty of any kind, whether express or implied. | ||
12 | */ | ||
13 | |||
14 | #ifndef __PLAT_CLOCK_H | ||
15 | #define __PLAT_CLOCK_H | ||
16 | |||
17 | #include <linux/list.h> | ||
18 | #include <asm/clkdev.h> | ||
19 | #include <linux/types.h> | ||
20 | |||
21 | /* clk structure flags */ | ||
22 | #define ALWAYS_ENABLED (1 << 0) /* clock always enabled */ | ||
23 | #define RESET_TO_ENABLE (1 << 1) /* reset register bit to enable clk */ | ||
24 | |||
25 | /** | ||
26 | * struct clkops - clock operations | ||
27 | * @enable: pointer to clock enable function | ||
28 | * @disable: pointer to clock disable function | ||
29 | */ | ||
30 | struct clkops { | ||
31 | int (*enable) (struct clk *); | ||
32 | void (*disable) (struct clk *); | ||
33 | }; | ||
34 | |||
35 | /** | ||
36 | * struct pclk_info - parents info | ||
37 | * @pclk: pointer to parent clk | ||
38 | * @pclk_mask: value to be written for selecting this parent | ||
39 | * @scalable: Is parent scalable (1 - YES, 0 - NO) | ||
40 | */ | ||
41 | struct pclk_info { | ||
42 | struct clk *pclk; | ||
43 | u8 pclk_mask; | ||
44 | u8 scalable; | ||
45 | }; | ||
46 | |||
47 | /** | ||
48 | * struct pclk_sel - parents selection configuration | ||
49 | * @pclk_info: pointer to array of parent clock info | ||
50 | * @pclk_count: number of parents | ||
51 | * @pclk_sel_reg: register for selecting a parent | ||
52 | * @pclk_sel_mask: mask for selecting parent (can be used to clear bits also) | ||
53 | */ | ||
54 | struct pclk_sel { | ||
55 | struct pclk_info *pclk_info; | ||
56 | u8 pclk_count; | ||
57 | unsigned int *pclk_sel_reg; | ||
58 | unsigned int pclk_sel_mask; | ||
59 | }; | ||
60 | |||
61 | /** | ||
62 | * struct clk - clock structure | ||
63 | * @usage_count: num of users who enabled this clock | ||
64 | * @flags: flags for clock properties | ||
65 | * @rate: programmed clock rate in Hz | ||
66 | * @en_reg: clk enable/disable reg | ||
67 | * @en_reg_bit: clk enable/disable bit | ||
68 | * @ops: clk enable/disable ops - generic_clkops selected if NULL | ||
69 | * @recalc: pointer to clock rate recalculate function | ||
70 | * @pclk: current parent clk | ||
71 | * @pclk_sel: pointer to parent selection structure | ||
72 | * @pclk_sel_shift: register shift for selecting parent of this clock | ||
73 | * @children: list for childrens or this clock | ||
74 | * @sibling: node for list of clocks having same parents | ||
75 | * @private_data: clock specific private data | ||
76 | */ | ||
77 | struct clk { | ||
78 | unsigned int usage_count; | ||
79 | unsigned int flags; | ||
80 | unsigned long rate; | ||
81 | unsigned int *en_reg; | ||
82 | u8 en_reg_bit; | ||
83 | const struct clkops *ops; | ||
84 | void (*recalc) (struct clk *); | ||
85 | |||
86 | struct clk *pclk; | ||
87 | struct pclk_sel *pclk_sel; | ||
88 | unsigned int pclk_sel_shift; | ||
89 | |||
90 | struct list_head children; | ||
91 | struct list_head sibling; | ||
92 | void *private_data; | ||
93 | }; | ||
94 | |||
95 | /* pll configuration structure */ | ||
96 | struct pll_clk_config { | ||
97 | unsigned int *mode_reg; | ||
98 | unsigned int *cfg_reg; | ||
99 | }; | ||
100 | |||
101 | /* ahb and apb bus configuration structure */ | ||
102 | struct bus_clk_config { | ||
103 | unsigned int *reg; | ||
104 | unsigned int mask; | ||
105 | unsigned int shift; | ||
106 | }; | ||
107 | |||
108 | /* | ||
109 | * Aux clk configuration structure: applicable to GPT, UART and FIRDA | ||
110 | */ | ||
111 | struct aux_clk_config { | ||
112 | unsigned int *synth_reg; | ||
113 | }; | ||
114 | |||
115 | /* platform specific clock functions */ | ||
116 | void clk_register(struct clk_lookup *cl); | ||
117 | void recalc_root_clocks(void); | ||
118 | |||
119 | /* clock recalc functions */ | ||
120 | void follow_parent(struct clk *clk); | ||
121 | void pll1_clk_recalc(struct clk *clk); | ||
122 | void bus_clk_recalc(struct clk *clk); | ||
123 | void gpt_clk_recalc(struct clk *clk); | ||
124 | void aux_clk_recalc(struct clk *clk); | ||
125 | |||
126 | #endif /* __PLAT_CLOCK_H */ | ||