blob: 8d8c99f895583e1382381d7cd79ee184176f3af5 [file] [log] [blame]
Hans J. Kochda157972010-09-17 18:15:11 +02001/*
2 * Lowlevel clock handling for Telechips TCC8xxx SoCs
3 *
4 * Copyright (C) 2010 by Hans J. Koch <hjk@linutronix.de>
5 *
6 * Licensed under the terms of the GPL v2
7 */
8
9#include <linux/clk.h>
10#include <linux/delay.h>
11#include <linux/err.h>
12#include <linux/io.h>
13#include <linux/module.h>
14#include <linux/spinlock.h>
Jean-Christop PLAGNIOL-VILLARD6d803ba2010-11-17 10:04:33 +010015#include <linux/clkdev.h>
Hans J. Kochda157972010-09-17 18:15:11 +020016
17#include <mach/clock.h>
18#include <mach/irqs.h>
19#include <mach/tcc8k-regs.h>
20
21#include "common.h"
22
23#define BCLKCTR0 (CKC_BASE + BCLKCTR0_OFFS)
24#define BCLKCTR1 (CKC_BASE + BCLKCTR1_OFFS)
25
26#define ACLKREF (CKC_BASE + ACLKREF_OFFS)
27#define ACLKUART0 (CKC_BASE + ACLKUART0_OFFS)
28#define ACLKUART1 (CKC_BASE + ACLKUART1_OFFS)
29#define ACLKUART2 (CKC_BASE + ACLKUART2_OFFS)
30#define ACLKUART3 (CKC_BASE + ACLKUART3_OFFS)
31#define ACLKUART4 (CKC_BASE + ACLKUART4_OFFS)
32#define ACLKI2C (CKC_BASE + ACLKI2C_OFFS)
33#define ACLKADC (CKC_BASE + ACLKADC_OFFS)
34#define ACLKUSBH (CKC_BASE + ACLKUSBH_OFFS)
35#define ACLKLCD (CKC_BASE + ACLKLCD_OFFS)
36#define ACLKSDH0 (CKC_BASE + ACLKSDH0_OFFS)
37#define ACLKSDH1 (CKC_BASE + ACLKSDH1_OFFS)
38#define ACLKSPI0 (CKC_BASE + ACLKSPI0_OFFS)
39#define ACLKSPI1 (CKC_BASE + ACLKSPI1_OFFS)
40#define ACLKSPDIF (CKC_BASE + ACLKSPDIF_OFFS)
41#define ACLKC3DEC (CKC_BASE + ACLKC3DEC_OFFS)
42#define ACLKCAN0 (CKC_BASE + ACLKCAN0_OFFS)
43#define ACLKCAN1 (CKC_BASE + ACLKCAN1_OFFS)
44#define ACLKGSB0 (CKC_BASE + ACLKGSB0_OFFS)
45#define ACLKGSB1 (CKC_BASE + ACLKGSB1_OFFS)
46#define ACLKGSB2 (CKC_BASE + ACLKGSB2_OFFS)
47#define ACLKGSB3 (CKC_BASE + ACLKGSB3_OFFS)
Hans J. Kochda157972010-09-17 18:15:11 +020048#define ACLKTCT (CKC_BASE + ACLKTCT_OFFS)
49#define ACLKTCX (CKC_BASE + ACLKTCX_OFFS)
50#define ACLKTCZ (CKC_BASE + ACLKTCZ_OFFS)
51
Hans J. Kochfe03a9f2011-02-17 16:42:59 +010052#define ACLK_MAX_DIV (0xfff + 1)
53
Hans J. Kochda157972010-09-17 18:15:11 +020054/* Crystal frequencies */
55static unsigned long xi_rate, xti_rate;
56
57static void __iomem *pll_cfg_addr(int pll)
58{
59 switch (pll) {
60 case 0: return (CKC_BASE + PLL0CFG_OFFS);
61 case 1: return (CKC_BASE + PLL1CFG_OFFS);
62 case 2: return (CKC_BASE + PLL2CFG_OFFS);
63 default:
64 BUG();
65 }
66}
67
68static int pll_enable(int pll, int enable)
69{
70 u32 reg;
71 void __iomem *addr = pll_cfg_addr(pll);
72
73 reg = __raw_readl(addr);
74 if (enable)
75 reg &= ~PLLxCFG_PD;
76 else
77 reg |= PLLxCFG_PD;
78
79 __raw_writel(reg, addr);
80 return 0;
81}
82
83static int xi_enable(int enable)
84{
85 u32 reg;
86
87 reg = __raw_readl(CKC_BASE + CLKCTRL_OFFS);
88 if (enable)
89 reg |= CLKCTRL_XE;
90 else
91 reg &= ~CLKCTRL_XE;
92
93 __raw_writel(reg, CKC_BASE + CLKCTRL_OFFS);
94 return 0;
95}
96
97static int root_clk_enable(enum root_clks src)
98{
99 switch (src) {
100 case CLK_SRC_PLL0: return pll_enable(0, 1);
101 case CLK_SRC_PLL1: return pll_enable(1, 1);
102 case CLK_SRC_PLL2: return pll_enable(2, 1);
103 case CLK_SRC_XI: return xi_enable(1);
104 default:
105 BUG();
106 }
107 return 0;
108}
109
Oskar Schirmercfeeb2f2011-02-17 16:43:01 +0100110static int root_clk_disable(enum root_clks src)
Hans J. Kochda157972010-09-17 18:15:11 +0200111{
Oskar Schirmercfeeb2f2011-02-17 16:43:01 +0100112 switch (src) {
Hans J. Kochda157972010-09-17 18:15:11 +0200113 case CLK_SRC_PLL0: return pll_enable(0, 0);
114 case CLK_SRC_PLL1: return pll_enable(1, 0);
115 case CLK_SRC_PLL2: return pll_enable(2, 0);
116 case CLK_SRC_XI: return xi_enable(0);
117 default:
118 BUG();
119 }
120 return 0;
121}
122
123static int enable_clk(struct clk *clk)
124{
125 u32 reg;
126
127 if (clk->root_id != CLK_SRC_NOROOT)
128 return root_clk_enable(clk->root_id);
129
130 if (clk->aclkreg) {
131 reg = __raw_readl(clk->aclkreg);
132 reg |= ACLK_EN;
133 __raw_writel(reg, clk->aclkreg);
134 }
135 if (clk->bclkctr) {
136 reg = __raw_readl(clk->bclkctr);
137 reg |= 1 << clk->bclk_shift;
138 __raw_writel(reg, clk->bclkctr);
139 }
140 return 0;
141}
142
143static void disable_clk(struct clk *clk)
144{
145 u32 reg;
146
147 if (clk->root_id != CLK_SRC_NOROOT) {
148 root_clk_disable(clk->root_id);
149 return;
150 }
151
152 if (clk->bclkctr) {
153 reg = __raw_readl(clk->bclkctr);
154 reg &= ~(1 << clk->bclk_shift);
155 __raw_writel(reg, clk->bclkctr);
156 }
157 if (clk->aclkreg) {
158 reg = __raw_readl(clk->aclkreg);
159 reg &= ~ACLK_EN;
160 __raw_writel(reg, clk->aclkreg);
161 }
162}
163
164static unsigned long get_rate_pll(int pll)
165{
166 u32 reg;
167 unsigned long s, m, p;
168 void __iomem *addr = pll_cfg_addr(pll);
169
170 reg = __raw_readl(addr);
171 s = (reg >> 16) & 0x07;
172 m = (reg >> 8) & 0xff;
173 p = reg & 0x3f;
174
175 return (m * xi_rate) / (p * (1 << s));
176}
177
178static unsigned long get_rate_pll_div(int pll)
179{
180 u32 reg;
181 unsigned long div = 0;
182 void __iomem *addr;
183
184 switch (pll) {
185 case 0:
186 addr = CKC_BASE + CLKDIVC0_OFFS;
187 reg = __raw_readl(addr);
188 if (reg & CLKDIVC0_P0E)
189 div = (reg >> 24) & 0x3f;
190 break;
191 case 1:
192 addr = CKC_BASE + CLKDIVC0_OFFS;
193 reg = __raw_readl(addr);
194 if (reg & CLKDIVC0_P1E)
195 div = (reg >> 16) & 0x3f;
196 break;
197 case 2:
198 addr = CKC_BASE + CLKDIVC1_OFFS;
199 reg = __raw_readl(addr);
200 if (reg & CLKDIVC1_P2E)
Oskar Schirmer25d7a602011-02-17 16:43:00 +0100201 div = reg & 0x3f;
Hans J. Kochda157972010-09-17 18:15:11 +0200202 break;
203 }
204 return get_rate_pll(pll) / (div + 1);
205}
206
207static unsigned long get_rate_xi_div(void)
208{
209 unsigned long div = 0;
210 u32 reg = __raw_readl(CKC_BASE + CLKDIVC0_OFFS);
211
212 if (reg & CLKDIVC0_XE)
213 div = (reg >> 8) & 0x3f;
214
215 return xi_rate / (div + 1);
216}
217
218static unsigned long get_rate_xti_div(void)
219{
220 unsigned long div = 0;
221 u32 reg = __raw_readl(CKC_BASE + CLKDIVC0_OFFS);
222
223 if (reg & CLKDIVC0_XTE)
224 div = reg & 0x3f;
225
226 return xti_rate / (div + 1);
227}
228
229static unsigned long root_clk_get_rate(enum root_clks src)
230{
231 switch (src) {
232 case CLK_SRC_PLL0: return get_rate_pll(0);
233 case CLK_SRC_PLL1: return get_rate_pll(1);
234 case CLK_SRC_PLL2: return get_rate_pll(2);
235 case CLK_SRC_PLL0DIV: return get_rate_pll_div(0);
236 case CLK_SRC_PLL1DIV: return get_rate_pll_div(1);
237 case CLK_SRC_PLL2DIV: return get_rate_pll_div(2);
238 case CLK_SRC_XI: return xi_rate;
239 case CLK_SRC_XTI: return xti_rate;
240 case CLK_SRC_XIDIV: return get_rate_xi_div();
241 case CLK_SRC_XTIDIV: return get_rate_xti_div();
242 default: return 0;
243 }
244}
245
246static unsigned long aclk_get_rate(struct clk *clk)
247{
248 u32 reg;
249 unsigned long div;
250 unsigned int src;
251
252 reg = __raw_readl(clk->aclkreg);
253 div = reg & 0x0fff;
254 src = (reg >> ACLK_SEL_SHIFT) & CLK_SRC_MASK;
255 return root_clk_get_rate(src) / (div + 1);
256}
257
258static unsigned long aclk_best_div(struct clk *clk, unsigned long rate)
259{
260 unsigned long div, src, freq, r1, r2;
261
Hans J. Kochfe03a9f2011-02-17 16:42:59 +0100262 if (!rate)
263 return ACLK_MAX_DIV;
264
Hans J. Kochda157972010-09-17 18:15:11 +0200265 src = __raw_readl(clk->aclkreg) >> ACLK_SEL_SHIFT;
266 src &= CLK_SRC_MASK;
267 freq = root_clk_get_rate(src);
Hans J. Kochfe03a9f2011-02-17 16:42:59 +0100268 div = freq / rate;
269 if (!div)
270 return 1;
271 if (div >= ACLK_MAX_DIV)
272 return ACLK_MAX_DIV;
Hans J. Kochda157972010-09-17 18:15:11 +0200273 r1 = freq / div;
274 r2 = freq / (div + 1);
Hans J. Kochda157972010-09-17 18:15:11 +0200275 if ((rate - r2) < (r1 - rate))
276 return div + 1;
277
278 return div;
279}
280
281static unsigned long aclk_round_rate(struct clk *clk, unsigned long rate)
282{
283 unsigned int src;
284
285 src = __raw_readl(clk->aclkreg) >> ACLK_SEL_SHIFT;
286 src &= CLK_SRC_MASK;
287
288 return root_clk_get_rate(src) / aclk_best_div(clk, rate);
289}
290
291static int aclk_set_rate(struct clk *clk, unsigned long rate)
292{
293 u32 reg;
294
295 reg = __raw_readl(clk->aclkreg) & ~ACLK_DIV_MASK;
Hans J. Kochfe03a9f2011-02-17 16:42:59 +0100296 reg |= aclk_best_div(clk, rate) - 1;
297 __raw_writel(reg, clk->aclkreg);
Hans J. Kochda157972010-09-17 18:15:11 +0200298 return 0;
299}
300
301static unsigned long get_rate_sys(struct clk *clk)
302{
303 unsigned int src;
304
305 src = __raw_readl(CKC_BASE + CLKCTRL_OFFS) & CLK_SRC_MASK;
Oskar Schirmercfeeb2f2011-02-17 16:43:01 +0100306 return root_clk_get_rate(src);
Hans J. Kochda157972010-09-17 18:15:11 +0200307}
308
309static unsigned long get_rate_bus(struct clk *clk)
310{
311 unsigned int div;
312
313 div = (__raw_readl(CKC_BASE + CLKCTRL_OFFS) >> 4) & 0xff;
314 return get_rate_sys(clk) / (div + 1);
315}
316
317static unsigned long get_rate_cpu(struct clk *clk)
318{
319 unsigned int reg, div, fsys, fbus;
320
321 fbus = get_rate_bus(clk);
322 reg = __raw_readl(CKC_BASE + CLKCTRL_OFFS);
323 if (reg & (1 << 29))
324 return fbus;
325 fsys = get_rate_sys(clk);
326 div = (reg >> 16) & 0x0f;
327 return fbus + ((fsys - fbus) * (div + 1)) / 16;
328}
329
330static unsigned long get_rate_root(struct clk *clk)
331{
332 return root_clk_get_rate(clk->root_id);
333}
334
335static int aclk_set_parent(struct clk *clock, struct clk *parent)
336{
337 u32 reg;
338
339 if (clock->parent == parent)
340 return 0;
341
342 clock->parent = parent;
343
344 if (!parent)
345 return 0;
346
347 if (parent->root_id == CLK_SRC_NOROOT)
348 return 0;
349 reg = __raw_readl(clock->aclkreg);
350 reg &= ~ACLK_SEL_MASK;
351 reg |= (parent->root_id << ACLK_SEL_SHIFT) & ACLK_SEL_MASK;
352 __raw_writel(reg, clock->aclkreg);
353
354 return 0;
355}
356
357#define DEFINE_ROOT_CLOCK(name, ri, p) \
358 static struct clk name = { \
359 .root_id = ri, \
360 .get_rate = get_rate_root, \
361 .enable = enable_clk, \
362 .disable = disable_clk, \
363 .parent = p, \
364 };
365
366#define DEFINE_SPECIAL_CLOCK(name, gr, p) \
367 static struct clk name = { \
368 .root_id = CLK_SRC_NOROOT, \
369 .get_rate = gr, \
370 .parent = p, \
371 };
372
373#define DEFINE_ACLOCK(name, bc, bs, ar) \
374 static struct clk name = { \
375 .root_id = CLK_SRC_NOROOT, \
376 .bclkctr = bc, \
377 .bclk_shift = bs, \
378 .aclkreg = ar, \
379 .get_rate = aclk_get_rate, \
380 .set_rate = aclk_set_rate, \
381 .round_rate = aclk_round_rate, \
382 .enable = enable_clk, \
383 .disable = disable_clk, \
384 .set_parent = aclk_set_parent, \
385 };
386
387#define DEFINE_BCLOCK(name, bc, bs, gr, p) \
388 static struct clk name = { \
389 .root_id = CLK_SRC_NOROOT, \
390 .bclkctr = bc, \
391 .bclk_shift = bs, \
392 .get_rate = gr, \
393 .enable = enable_clk, \
394 .disable = disable_clk, \
395 .parent = p, \
396 };
397
398DEFINE_ROOT_CLOCK(xi, CLK_SRC_XI, NULL)
399DEFINE_ROOT_CLOCK(xti, CLK_SRC_XTI, NULL)
400DEFINE_ROOT_CLOCK(xidiv, CLK_SRC_XIDIV, &xi)
401DEFINE_ROOT_CLOCK(xtidiv, CLK_SRC_XTIDIV, &xti)
402DEFINE_ROOT_CLOCK(pll0, CLK_SRC_PLL0, &xi)
403DEFINE_ROOT_CLOCK(pll1, CLK_SRC_PLL1, &xi)
404DEFINE_ROOT_CLOCK(pll2, CLK_SRC_PLL2, &xi)
405DEFINE_ROOT_CLOCK(pll0div, CLK_SRC_PLL0DIV, &pll0)
406DEFINE_ROOT_CLOCK(pll1div, CLK_SRC_PLL1DIV, &pll1)
407DEFINE_ROOT_CLOCK(pll2div, CLK_SRC_PLL2DIV, &pll2)
408
409/* The following 3 clocks are special and are initialized explicitly later */
410DEFINE_SPECIAL_CLOCK(sys, get_rate_sys, NULL)
411DEFINE_SPECIAL_CLOCK(bus, get_rate_bus, &sys)
412DEFINE_SPECIAL_CLOCK(cpu, get_rate_cpu, &sys)
413
414DEFINE_ACLOCK(tct, NULL, 0, ACLKTCT)
415DEFINE_ACLOCK(tcx, NULL, 0, ACLKTCX)
416DEFINE_ACLOCK(tcz, NULL, 0, ACLKTCZ)
417DEFINE_ACLOCK(ref, NULL, 0, ACLKREF)
418DEFINE_ACLOCK(uart0, BCLKCTR0, 5, ACLKUART0)
419DEFINE_ACLOCK(uart1, BCLKCTR0, 23, ACLKUART1)
420DEFINE_ACLOCK(uart2, BCLKCTR0, 6, ACLKUART2)
421DEFINE_ACLOCK(uart3, BCLKCTR0, 8, ACLKUART3)
422DEFINE_ACLOCK(uart4, BCLKCTR1, 6, ACLKUART4)
423DEFINE_ACLOCK(i2c, BCLKCTR0, 7, ACLKI2C)
424DEFINE_ACLOCK(adc, BCLKCTR0, 10, ACLKADC)
425DEFINE_ACLOCK(usbh0, BCLKCTR0, 11, ACLKUSBH)
426DEFINE_ACLOCK(lcd, BCLKCTR0, 13, ACLKLCD)
427DEFINE_ACLOCK(sd0, BCLKCTR0, 17, ACLKSDH0)
428DEFINE_ACLOCK(sd1, BCLKCTR1, 5, ACLKSDH1)
429DEFINE_ACLOCK(spi0, BCLKCTR0, 24, ACLKSPI0)
430DEFINE_ACLOCK(spi1, BCLKCTR0, 30, ACLKSPI1)
431DEFINE_ACLOCK(spdif, BCLKCTR1, 2, ACLKSPDIF)
432DEFINE_ACLOCK(c3dec, BCLKCTR1, 9, ACLKC3DEC)
433DEFINE_ACLOCK(can0, BCLKCTR1, 10, ACLKCAN0)
434DEFINE_ACLOCK(can1, BCLKCTR1, 11, ACLKCAN1)
435DEFINE_ACLOCK(gsb0, BCLKCTR1, 13, ACLKGSB0)
436DEFINE_ACLOCK(gsb1, BCLKCTR1, 14, ACLKGSB1)
437DEFINE_ACLOCK(gsb2, BCLKCTR1, 15, ACLKGSB2)
438DEFINE_ACLOCK(gsb3, BCLKCTR1, 16, ACLKGSB3)
439DEFINE_ACLOCK(usbh1, BCLKCTR1, 20, ACLKUSBH)
440
441DEFINE_BCLOCK(dai0, BCLKCTR0, 0, NULL, NULL)
442DEFINE_BCLOCK(pic, BCLKCTR0, 1, NULL, NULL)
443DEFINE_BCLOCK(tc, BCLKCTR0, 2, NULL, NULL)
444DEFINE_BCLOCK(gpio, BCLKCTR0, 3, NULL, NULL)
445DEFINE_BCLOCK(usbd, BCLKCTR0, 4, NULL, NULL)
446DEFINE_BCLOCK(ecc, BCLKCTR0, 9, NULL, NULL)
447DEFINE_BCLOCK(gdma0, BCLKCTR0, 12, NULL, NULL)
448DEFINE_BCLOCK(rtc, BCLKCTR0, 15, NULL, NULL)
449DEFINE_BCLOCK(nfc, BCLKCTR0, 16, NULL, NULL)
450DEFINE_BCLOCK(g2d, BCLKCTR0, 18, NULL, NULL)
451DEFINE_BCLOCK(gdma1, BCLKCTR0, 22, NULL, NULL)
452DEFINE_BCLOCK(mscl, BCLKCTR0, 25, NULL, NULL)
453DEFINE_BCLOCK(bdma, BCLKCTR1, 0, NULL, NULL)
454DEFINE_BCLOCK(adma0, BCLKCTR1, 1, NULL, NULL)
455DEFINE_BCLOCK(scfg, BCLKCTR1, 3, NULL, NULL)
456DEFINE_BCLOCK(cid, BCLKCTR1, 4, NULL, NULL)
457DEFINE_BCLOCK(dai1, BCLKCTR1, 7, NULL, NULL)
458DEFINE_BCLOCK(adma1, BCLKCTR1, 8, NULL, NULL)
459DEFINE_BCLOCK(gps, BCLKCTR1, 12, NULL, NULL)
460DEFINE_BCLOCK(gdma2, BCLKCTR1, 17, NULL, NULL)
461DEFINE_BCLOCK(gdma3, BCLKCTR1, 18, NULL, NULL)
462DEFINE_BCLOCK(ddrc, BCLKCTR1, 19, NULL, NULL)
463
464#define _REGISTER_CLOCK(d, n, c) \
465 { \
466 .dev_id = d, \
467 .con_id = n, \
468 .clk = &c, \
469 },
470
471static struct clk_lookup lookups[] = {
472 _REGISTER_CLOCK(NULL, "bus", bus)
473 _REGISTER_CLOCK(NULL, "cpu", cpu)
474 _REGISTER_CLOCK(NULL, "tct", tct)
475 _REGISTER_CLOCK(NULL, "tcx", tcx)
476 _REGISTER_CLOCK(NULL, "tcz", tcz)
477 _REGISTER_CLOCK(NULL, "ref", ref)
478 _REGISTER_CLOCK(NULL, "dai0", dai0)
479 _REGISTER_CLOCK(NULL, "pic", pic)
480 _REGISTER_CLOCK(NULL, "tc", tc)
481 _REGISTER_CLOCK(NULL, "gpio", gpio)
482 _REGISTER_CLOCK(NULL, "usbd", usbd)
483 _REGISTER_CLOCK("tcc-uart.0", NULL, uart0)
484 _REGISTER_CLOCK("tcc-uart.2", NULL, uart2)
485 _REGISTER_CLOCK("tcc-i2c", NULL, i2c)
486 _REGISTER_CLOCK("tcc-uart.3", NULL, uart3)
487 _REGISTER_CLOCK(NULL, "ecc", ecc)
488 _REGISTER_CLOCK(NULL, "adc", adc)
489 _REGISTER_CLOCK("tcc-usbh.0", "usb", usbh0)
490 _REGISTER_CLOCK(NULL, "gdma0", gdma0)
491 _REGISTER_CLOCK(NULL, "lcd", lcd)
492 _REGISTER_CLOCK(NULL, "rtc", rtc)
493 _REGISTER_CLOCK(NULL, "nfc", nfc)
494 _REGISTER_CLOCK("tcc-mmc.0", NULL, sd0)
495 _REGISTER_CLOCK(NULL, "g2d", g2d)
496 _REGISTER_CLOCK(NULL, "gdma1", gdma1)
497 _REGISTER_CLOCK("tcc-uart.1", NULL, uart1)
498 _REGISTER_CLOCK("tcc-spi.0", NULL, spi0)
499 _REGISTER_CLOCK(NULL, "mscl", mscl)
500 _REGISTER_CLOCK("tcc-spi.1", NULL, spi1)
501 _REGISTER_CLOCK(NULL, "bdma", bdma)
502 _REGISTER_CLOCK(NULL, "adma0", adma0)
503 _REGISTER_CLOCK(NULL, "spdif", spdif)
504 _REGISTER_CLOCK(NULL, "scfg", scfg)
505 _REGISTER_CLOCK(NULL, "cid", cid)
506 _REGISTER_CLOCK("tcc-mmc.1", NULL, sd1)
507 _REGISTER_CLOCK("tcc-uart.4", NULL, uart4)
508 _REGISTER_CLOCK(NULL, "dai1", dai1)
509 _REGISTER_CLOCK(NULL, "adma1", adma1)
510 _REGISTER_CLOCK(NULL, "c3dec", c3dec)
511 _REGISTER_CLOCK("tcc-can.0", NULL, can0)
512 _REGISTER_CLOCK("tcc-can.1", NULL, can1)
513 _REGISTER_CLOCK(NULL, "gps", gps)
514 _REGISTER_CLOCK("tcc-gsb.0", NULL, gsb0)
515 _REGISTER_CLOCK("tcc-gsb.1", NULL, gsb1)
516 _REGISTER_CLOCK("tcc-gsb.2", NULL, gsb2)
517 _REGISTER_CLOCK("tcc-gsb.3", NULL, gsb3)
518 _REGISTER_CLOCK(NULL, "gdma2", gdma2)
519 _REGISTER_CLOCK(NULL, "gdma3", gdma3)
520 _REGISTER_CLOCK(NULL, "ddrc", ddrc)
521 _REGISTER_CLOCK("tcc-usbh.1", "usb", usbh1)
522};
523
524static struct clk *root_clk_by_index(enum root_clks src)
525{
526 switch (src) {
527 case CLK_SRC_PLL0: return &pll0;
528 case CLK_SRC_PLL1: return &pll1;
529 case CLK_SRC_PLL2: return &pll2;
530 case CLK_SRC_PLL0DIV: return &pll0div;
531 case CLK_SRC_PLL1DIV: return &pll1div;
532 case CLK_SRC_PLL2DIV: return &pll2div;
533 case CLK_SRC_XI: return &xi;
534 case CLK_SRC_XTI: return &xti;
535 case CLK_SRC_XIDIV: return &xidiv;
536 case CLK_SRC_XTIDIV: return &xtidiv;
537 default: return NULL;
538 }
539}
540
541static void find_aclk_parent(struct clk *clk)
542{
543 unsigned int src;
544 struct clk *clock;
545
546 if (!clk->aclkreg)
547 return;
548
549 src = __raw_readl(clk->aclkreg) >> ACLK_SEL_SHIFT;
550 src &= CLK_SRC_MASK;
551
552 clock = root_clk_by_index(src);
553 if (!clock)
554 return;
555
556 clk->parent = clock;
557 clk->set_parent = aclk_set_parent;
558}
559
560void __init tcc_clocks_init(unsigned long xi_freq, unsigned long xti_freq)
561{
562 int i;
563
564 xi_rate = xi_freq;
565 xti_rate = xti_freq;
566
567 /* fixup parents and add the clock */
568 for (i = 0; i < ARRAY_SIZE(lookups); i++) {
569 find_aclk_parent(lookups[i].clk);
570 clkdev_add(&lookups[i]);
571 }
Hans J. Koch3de7b512010-09-17 18:17:42 +0200572 tcc8k_timer_init(&tcz, (void __iomem *)TIMER_BASE, INT_TC32);
Hans J. Kochda157972010-09-17 18:15:11 +0200573}