blob: b09534352f97c5952faf28523826b1d3e978d51c [file] [log] [blame]
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -08001/*
2 * R8A7740 processor support
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/io.h>
23#include <linux/sh_clk.h>
24#include <linux/clkdev.h>
25#include <mach/common.h>
26#include <mach/r8a7740.h>
27
28/*
29 * | MDx | XTAL1/EXTAL1 | System | EXTALR |
30 * Clock |-------+-----------------+ clock | 32.768 | RCLK
31 * Mode | 2/1/0 | src MHz | source | KHz | source
32 * -------+-------+-----------------+-----------+--------+----------
33 * 0 | 0 0 0 | External 20~50 | XTAL1 | O | EXTALR
34 * 1 | 0 0 1 | Crystal 20~30 | XTAL1 | O | EXTALR
35 * 2 | 0 1 0 | External 40~50 | XTAL1 / 2 | O | EXTALR
36 * 3 | 0 1 1 | Crystal 40~50 | XTAL1 / 2 | O | EXTALR
37 * 4 | 1 0 0 | External 20~50 | XTAL1 | x | XTAL1 / 1024
38 * 5 | 1 0 1 | Crystal 20~30 | XTAL1 | x | XTAL1 / 1024
39 * 6 | 1 1 0 | External 40~50 | XTAL1 / 2 | x | XTAL1 / 2048
40 * 7 | 1 1 1 | Crystal 40~50 | XTAL1 / 2 | x | XTAL1 / 2048
41 */
42
43/* CPG registers */
44#define FRQCRA 0xe6150000
45#define FRQCRB 0xe6150004
46#define FRQCRC 0xe61500e0
47#define PLLC01CR 0xe6150028
48
49#define SUBCKCR 0xe6150080
Kuninori Morimotofcca3f02012-04-24 02:07:47 -070050#define USBCKCR 0xe615008c
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080051
52#define MSTPSR0 0xe6150030
53#define MSTPSR1 0xe6150038
54#define MSTPSR2 0xe6150040
55#define MSTPSR3 0xe6150048
56#define MSTPSR4 0xe615004c
Kuninori Morimotoc6750ac2012-06-12 02:35:36 -070057#define HDMICKCR 0xe6150094
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080058#define SMSTPCR0 0xe6150130
59#define SMSTPCR1 0xe6150134
60#define SMSTPCR2 0xe6150138
61#define SMSTPCR3 0xe615013c
62#define SMSTPCR4 0xe6150140
63
64/* Fixed 32 KHz root clock from EXTALR pin */
65static struct clk extalr_clk = {
66 .rate = 32768,
67};
68
69/*
70 * 25MHz default rate for the EXTAL1 root input clock.
71 * If needed, reset this with clk_set_rate() from the platform code.
72 */
73static struct clk extal1_clk = {
74 .rate = 25000000,
75};
76
77/*
78 * 48MHz default rate for the EXTAL2 root input clock.
79 * If needed, reset this with clk_set_rate() from the platform code.
80 */
81static struct clk extal2_clk = {
82 .rate = 48000000,
83};
84
85/*
86 * 27MHz default rate for the DV_CLKI root input clock.
87 * If needed, reset this with clk_set_rate() from the platform code.
88 */
89static struct clk dv_clk = {
90 .rate = 27000000,
91};
92
93static unsigned long div_recalc(struct clk *clk)
94{
95 return clk->parent->rate / (int)(clk->priv);
96}
97
Magnus Dammd9f86702012-02-29 22:17:00 +090098static struct sh_clk_ops div_clk_ops = {
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080099 .recalc = div_recalc,
100};
101
102/* extal1 / 2 */
103static struct clk extal1_div2_clk = {
104 .ops = &div_clk_ops,
105 .priv = (void *)2,
106 .parent = &extal1_clk,
107};
108
109/* extal1 / 1024 */
110static struct clk extal1_div1024_clk = {
111 .ops = &div_clk_ops,
112 .priv = (void *)1024,
113 .parent = &extal1_clk,
114};
115
116/* extal1 / 2 / 1024 */
117static struct clk extal1_div2048_clk = {
118 .ops = &div_clk_ops,
119 .priv = (void *)1024,
120 .parent = &extal1_div2_clk,
121};
122
123/* extal2 / 2 */
124static struct clk extal2_div2_clk = {
125 .ops = &div_clk_ops,
126 .priv = (void *)2,
127 .parent = &extal2_clk,
128};
129
Magnus Dammd9f86702012-02-29 22:17:00 +0900130static struct sh_clk_ops followparent_clk_ops = {
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800131 .recalc = followparent_recalc,
132};
133
134/* Main clock */
135static struct clk system_clk = {
136 .ops = &followparent_clk_ops,
137};
138
139static struct clk system_div2_clk = {
140 .ops = &div_clk_ops,
141 .priv = (void *)2,
142 .parent = &system_clk,
143};
144
145/* r_clk */
146static struct clk r_clk = {
147 .ops = &followparent_clk_ops,
148};
149
150/* PLLC0/PLLC1 */
151static unsigned long pllc01_recalc(struct clk *clk)
152{
153 unsigned long mult = 1;
154
155 if (__raw_readl(PLLC01CR) & (1 << 14))
156 mult = ((__raw_readl(clk->enable_reg) >> 24) & 0x7f) + 1;
157
158 return clk->parent->rate * mult;
159}
160
Magnus Dammd9f86702012-02-29 22:17:00 +0900161static struct sh_clk_ops pllc01_clk_ops = {
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800162 .recalc = pllc01_recalc,
163};
164
165static struct clk pllc0_clk = {
166 .ops = &pllc01_clk_ops,
167 .flags = CLK_ENABLE_ON_INIT,
168 .parent = &system_clk,
169 .enable_reg = (void __iomem *)FRQCRC,
170};
171
172static struct clk pllc1_clk = {
173 .ops = &pllc01_clk_ops,
174 .flags = CLK_ENABLE_ON_INIT,
175 .parent = &system_div2_clk,
176 .enable_reg = (void __iomem *)FRQCRA,
177};
178
179/* PLLC1 / 2 */
180static struct clk pllc1_div2_clk = {
181 .ops = &div_clk_ops,
182 .priv = (void *)2,
183 .parent = &pllc1_clk,
184};
185
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700186/* USB clock */
187static struct clk *usb24s_parents[] = {
188 [0] = &system_clk,
189 [1] = &extal2_clk
190};
191
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700192static int usb24s_enable(struct clk *clk)
193{
194 __raw_writel(__raw_readl(USBCKCR) & ~(1 << 8), USBCKCR);
195
196 return 0;
197}
198
199static void usb24s_disable(struct clk *clk)
200{
201 __raw_writel(__raw_readl(USBCKCR) | (1 << 8), USBCKCR);
202}
203
204static int usb24s_set_parent(struct clk *clk, struct clk *parent)
205{
206 int i, ret;
207 u32 val;
208
209 if (!clk->parent_table || !clk->parent_num)
210 return -EINVAL;
211
212 /* Search the parent */
213 for (i = 0; i < clk->parent_num; i++)
214 if (clk->parent_table[i] == parent)
215 break;
216
217 if (i == clk->parent_num)
218 return -ENODEV;
219
220 ret = clk_reparent(clk, parent);
221 if (ret < 0)
222 return ret;
223
224 val = __raw_readl(USBCKCR);
225 val &= ~(1 << 7);
226 val |= i << 7;
227 __raw_writel(val, USBCKCR);
228
229 return 0;
230}
231
232static struct sh_clk_ops usb24s_clk_ops = {
Kuninori Morimotoc8241082012-05-06 18:12:41 -0700233 .recalc = followparent_recalc,
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700234 .enable = usb24s_enable,
235 .disable = usb24s_disable,
236 .set_parent = usb24s_set_parent,
237};
238
239static struct clk usb24s_clk = {
240 .ops = &usb24s_clk_ops,
241 .parent_table = usb24s_parents,
242 .parent_num = ARRAY_SIZE(usb24s_parents),
243 .parent = &system_clk,
244};
245
246static unsigned long usb24_recalc(struct clk *clk)
247{
248 return clk->parent->rate /
249 ((__raw_readl(USBCKCR) & (1 << 6)) ? 1 : 2);
250};
251
252static int usb24_set_rate(struct clk *clk, unsigned long rate)
253{
254 u32 val;
255
256 /* closer to which ? parent->rate or parent->rate/2 */
257 val = __raw_readl(USBCKCR);
258 val &= ~(1 << 6);
259 val |= (rate > (clk->parent->rate / 4) * 3) << 6;
260 __raw_writel(val, USBCKCR);
261
262 return 0;
263}
264
265static struct sh_clk_ops usb24_clk_ops = {
266 .recalc = usb24_recalc,
267 .set_rate = usb24_set_rate,
268};
269
270static struct clk usb24_clk = {
271 .ops = &usb24_clk_ops,
272 .parent = &usb24s_clk,
273};
274
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800275struct clk *main_clks[] = {
276 &extalr_clk,
277 &extal1_clk,
278 &extal2_clk,
279 &extal1_div2_clk,
280 &extal1_div1024_clk,
281 &extal1_div2048_clk,
282 &extal2_div2_clk,
283 &dv_clk,
284 &system_clk,
285 &system_div2_clk,
286 &r_clk,
287 &pllc0_clk,
288 &pllc1_clk,
289 &pllc1_div2_clk,
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700290 &usb24s_clk,
291 &usb24_clk,
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800292};
293
294static void div4_kick(struct clk *clk)
295{
296 unsigned long value;
297
298 /* set KICK bit in FRQCRB to update hardware setting */
299 value = __raw_readl(FRQCRB);
300 value |= (1 << 31);
301 __raw_writel(value, FRQCRB);
302}
303
304static int divisors[] = { 2, 3, 4, 6, 8, 12, 16, 18,
305 24, 32, 36, 48, 0, 72, 96, 0 };
306
307static struct clk_div_mult_table div4_div_mult_table = {
308 .divisors = divisors,
309 .nr_divisors = ARRAY_SIZE(divisors),
310};
311
312static struct clk_div4_table div4_table = {
313 .div_mult_table = &div4_div_mult_table,
314 .kick = div4_kick,
315};
316
Kuninori Morimotoc6750ac2012-06-12 02:35:36 -0700317/* DIV6 reparent */
318enum {
319 DIV6_HDMI,
320 DIV6_REPARENT_NR,
321};
322
323static struct clk *hdmi_parent[] = {
324 [0] = &pllc1_div2_clk,
325 [1] = &system_clk,
326 [2] = &dv_clk
327};
328
329static struct clk div6_reparent_clks[DIV6_REPARENT_NR] = {
330 [DIV6_HDMI] = SH_CLK_DIV6_EXT(HDMICKCR, 0,
331 hdmi_parent, ARRAY_SIZE(hdmi_parent), 6, 2),
332};
333
334/* HDMI1/2 clock */
335static unsigned long hdmi12_recalc(struct clk *clk)
336{
337 u32 val = __raw_readl(HDMICKCR);
338 int shift = (int)clk->priv;
339
340 val >>= shift;
341 val &= 0x3;
342
343 return clk->parent->rate / (1 << val);
344};
345
346static int hdmi12_set_rate(struct clk *clk, unsigned long rate)
347{
348 u32 val, mask;
349 int i, shift;
350
351 for (i = 0; i < 3; i++)
352 if (rate == clk->parent->rate / (1 << i))
353 goto find;
354 return -ENODEV;
355
356find:
357 shift = (int)clk->priv;
358
359 val = __raw_readl(HDMICKCR);
360 mask = ~(0x3 << shift);
361 val = (val & mask) | i << shift;
362 __raw_writel(val, HDMICKCR);
363
364 return 0;
365};
366
367static struct sh_clk_ops hdmi12_clk_ops = {
368 .recalc = hdmi12_recalc,
369 .set_rate = hdmi12_set_rate,
370};
371
372static struct clk hdmi1_clk = {
373 .ops = &hdmi12_clk_ops,
374 .priv = (void *)9,
375 .parent = &div6_reparent_clks[DIV6_HDMI], /* late install */
376};
377
378static struct clk hdmi2_clk = {
379 .ops = &hdmi12_clk_ops,
380 .priv = (void *)11,
381 .parent = &div6_reparent_clks[DIV6_HDMI], /* late install */
382};
383
384static struct clk *late_main_clks[] = {
385 &hdmi1_clk,
386 &hdmi2_clk,
387};
388
389/* MSTP */
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800390enum {
391 DIV4_I, DIV4_ZG, DIV4_B, DIV4_M1, DIV4_HP,
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700392 DIV4_HPP, DIV4_USBP, DIV4_S, DIV4_ZB, DIV4_M3, DIV4_CP,
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800393 DIV4_NR
394};
395
396struct clk div4_clks[DIV4_NR] = {
397 [DIV4_I] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 20, 0x6fff, CLK_ENABLE_ON_INIT),
398 [DIV4_ZG] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 16, 0x6fff, CLK_ENABLE_ON_INIT),
399 [DIV4_B] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 8, 0x6fff, CLK_ENABLE_ON_INIT),
400 [DIV4_M1] = SH_CLK_DIV4(&pllc1_clk, FRQCRA, 4, 0x6fff, CLK_ENABLE_ON_INIT),
401 [DIV4_HP] = SH_CLK_DIV4(&pllc1_clk, FRQCRB, 4, 0x6fff, 0),
402 [DIV4_HPP] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 20, 0x6fff, 0),
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700403 [DIV4_USBP] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 16, 0x6fff, 0),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800404 [DIV4_S] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 12, 0x6fff, 0),
405 [DIV4_ZB] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 8, 0x6fff, 0),
406 [DIV4_M3] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 4, 0x6fff, 0),
407 [DIV4_CP] = SH_CLK_DIV4(&pllc1_clk, FRQCRC, 0, 0x6fff, 0),
408};
409
410enum {
411 DIV6_SUB,
412 DIV6_NR
413};
414
415static struct clk div6_clks[DIV6_NR] = {
416 [DIV6_SUB] = SH_CLK_DIV6(&pllc1_div2_clk, SUBCKCR, 0),
417};
418
419enum {
420 MSTP125,
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800421 MSTP116, MSTP111, MSTP100, MSTP117,
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800422
423 MSTP230,
424 MSTP222,
425 MSTP207, MSTP206, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
426
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700427 MSTP329, MSTP328, MSTP323, MSTP320,
Kuninori Morimotof2c2d7e2012-04-24 02:08:29 -0700428 MSTP314, MSTP313, MSTP312,
Kuninori Morimoto9c18f232012-05-06 22:58:41 -0700429 MSTP309,
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700430
Kuninori Morimoto19ad3222012-04-24 02:08:11 -0700431 MSTP416, MSTP415, MSTP407, MSTP406,
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800432
433 MSTP_NR
434};
435
436static struct clk mstp_clks[MSTP_NR] = {
437 [MSTP125] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 25, 0), /* TMU0 */
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800438 [MSTP117] = SH_CLK_MSTP32(&div4_clks[DIV4_B], SMSTPCR1, 17, 0), /* LCDC1 */
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800439 [MSTP116] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 16, 0), /* IIC0 */
440 [MSTP111] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 11, 0), /* TMU1 */
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800441 [MSTP100] = SH_CLK_MSTP32(&div4_clks[DIV4_B], SMSTPCR1, 0, 0), /* LCDC0 */
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800442
443 [MSTP230] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 30, 0), /* SCIFA6 */
444 [MSTP222] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 22, 0), /* SCIFA7 */
445 [MSTP207] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 7, 0), /* SCIFA5 */
446 [MSTP206] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 6, 0), /* SCIFB */
447 [MSTP204] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 4, 0), /* SCIFA0 */
448 [MSTP203] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 3, 0), /* SCIFA1 */
449 [MSTP202] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 2, 0), /* SCIFA2 */
450 [MSTP201] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 1, 0), /* SCIFA3 */
451 [MSTP200] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 0, 0), /* SCIFA4 */
452
453 [MSTP329] = SH_CLK_MSTP32(&r_clk, SMSTPCR3, 29, 0), /* CMT10 */
Kuninori Morimoto7ee89482012-04-01 18:46:09 -0700454 [MSTP328] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 28, 0), /* FSI */
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800455 [MSTP323] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR3, 23, 0), /* IIC1 */
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700456 [MSTP320] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 20, 0), /* USBF */
Kuninori Morimoto19ad3222012-04-24 02:08:11 -0700457 [MSTP314] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 14, 0), /* SDHI0 */
458 [MSTP313] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 13, 0), /* SDHI1 */
Kuninori Morimotof2c2d7e2012-04-24 02:08:29 -0700459 [MSTP312] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 12, 0), /* MMC */
Kuninori Morimoto9c18f232012-05-06 22:58:41 -0700460 [MSTP309] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR3, 9, 0), /* GEther */
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700461
462 [MSTP416] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 16, 0), /* USBHOST */
Kuninori Morimoto19ad3222012-04-24 02:08:11 -0700463 [MSTP415] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 15, 0), /* SDHI2 */
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700464 [MSTP407] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 7, 0), /* USB-Func */
465 [MSTP406] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR4, 6, 0), /* USB Phy */
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800466};
467
468static struct clk_lookup lookups[] = {
469 /* main clocks */
470 CLKDEV_CON_ID("extalr", &extalr_clk),
471 CLKDEV_CON_ID("extal1", &extal1_clk),
472 CLKDEV_CON_ID("extal2", &extal2_clk),
473 CLKDEV_CON_ID("extal1_div2", &extal1_div2_clk),
474 CLKDEV_CON_ID("extal1_div1024", &extal1_div1024_clk),
475 CLKDEV_CON_ID("extal1_div2048", &extal1_div2048_clk),
476 CLKDEV_CON_ID("extal2_div2", &extal2_div2_clk),
477 CLKDEV_CON_ID("dv_clk", &dv_clk),
478 CLKDEV_CON_ID("system_clk", &system_clk),
479 CLKDEV_CON_ID("system_div2_clk", &system_div2_clk),
480 CLKDEV_CON_ID("r_clk", &r_clk),
481 CLKDEV_CON_ID("pllc0_clk", &pllc0_clk),
482 CLKDEV_CON_ID("pllc1_clk", &pllc1_clk),
483 CLKDEV_CON_ID("pllc1_div2_clk", &pllc1_div2_clk),
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700484 CLKDEV_CON_ID("usb24s", &usb24s_clk),
Kuninori Morimotoc6750ac2012-06-12 02:35:36 -0700485 CLKDEV_CON_ID("hdmi1", &hdmi1_clk),
486 CLKDEV_CON_ID("hdmi2", &hdmi2_clk),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800487
488 /* DIV4 clocks */
489 CLKDEV_CON_ID("i_clk", &div4_clks[DIV4_I]),
490 CLKDEV_CON_ID("zg_clk", &div4_clks[DIV4_ZG]),
491 CLKDEV_CON_ID("b_clk", &div4_clks[DIV4_B]),
492 CLKDEV_CON_ID("m1_clk", &div4_clks[DIV4_M1]),
493 CLKDEV_CON_ID("hp_clk", &div4_clks[DIV4_HP]),
494 CLKDEV_CON_ID("hpp_clk", &div4_clks[DIV4_HPP]),
495 CLKDEV_CON_ID("s_clk", &div4_clks[DIV4_S]),
496 CLKDEV_CON_ID("zb_clk", &div4_clks[DIV4_ZB]),
497 CLKDEV_CON_ID("m3_clk", &div4_clks[DIV4_M3]),
498 CLKDEV_CON_ID("cp_clk", &div4_clks[DIV4_CP]),
499
500 /* DIV6 clocks */
501 CLKDEV_CON_ID("sub_clk", &div6_clks[DIV6_SUB]),
502
503 /* MSTP32 clocks */
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800504 CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[MSTP100]),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800505 CLKDEV_DEV_ID("sh_tmu.1", &mstp_clks[MSTP111]),
506 CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[MSTP116]),
Kuninori Morimoto665ccfa2011-11-10 18:47:16 -0800507 CLKDEV_DEV_ID("sh_mobile_lcdc_fb.1", &mstp_clks[MSTP117]),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800508 CLKDEV_DEV_ID("sh_tmu.0", &mstp_clks[MSTP125]),
509
510 CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP200]),
511 CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP201]),
512 CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP202]),
513 CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]),
514 CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]),
515 CLKDEV_DEV_ID("sh-sci.8", &mstp_clks[MSTP206]),
516 CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP207]),
517
518 CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP222]),
519 CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP230]),
520
521 CLKDEV_DEV_ID("sh_cmt.10", &mstp_clks[MSTP329]),
Kuninori Morimoto7ee89482012-04-01 18:46:09 -0700522 CLKDEV_DEV_ID("sh_fsi2", &mstp_clks[MSTP328]),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800523 CLKDEV_DEV_ID("i2c-sh_mobile.1", &mstp_clks[MSTP323]),
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700524 CLKDEV_DEV_ID("renesas_usbhs", &mstp_clks[MSTP320]),
Kuninori Morimoto19ad3222012-04-24 02:08:11 -0700525 CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]),
526 CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP313]),
Kuninori Morimotof2c2d7e2012-04-24 02:08:29 -0700527 CLKDEV_DEV_ID("sh_mmcif", &mstp_clks[MSTP312]),
Kuninori Morimoto9c18f232012-05-06 22:58:41 -0700528 CLKDEV_DEV_ID("sh-eth", &mstp_clks[MSTP309]),
Kuninori Morimoto19ad3222012-04-24 02:08:11 -0700529
530 CLKDEV_DEV_ID("sh_mobile_sdhi.2", &mstp_clks[MSTP415]),
Kuninori Morimotofcca3f02012-04-24 02:07:47 -0700531
532 /* ICK */
533 CLKDEV_ICK_ID("host", "renesas_usbhs", &mstp_clks[MSTP416]),
534 CLKDEV_ICK_ID("func", "renesas_usbhs", &mstp_clks[MSTP407]),
535 CLKDEV_ICK_ID("phy", "renesas_usbhs", &mstp_clks[MSTP406]),
536 CLKDEV_ICK_ID("pci", "renesas_usbhs", &div4_clks[DIV4_USBP]),
537 CLKDEV_ICK_ID("usb24", "renesas_usbhs", &usb24_clk),
Kuninori Morimotoc6750ac2012-06-12 02:35:36 -0700538 CLKDEV_ICK_ID("ick", "sh-mobile-hdmi", &div6_reparent_clks[DIV6_HDMI]),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800539};
540
541void __init r8a7740_clock_init(u8 md_ck)
542{
543 int k, ret = 0;
544
545 /* detect system clock parent */
546 if (md_ck & MD_CK1)
547 system_clk.parent = &extal1_div2_clk;
548 else
549 system_clk.parent = &extal1_clk;
550
551 /* detect RCLK parent */
552 switch (md_ck & (MD_CK2 | MD_CK1)) {
553 case MD_CK2 | MD_CK1:
554 r_clk.parent = &extal1_div2048_clk;
555 break;
556 case MD_CK2:
557 r_clk.parent = &extal1_div1024_clk;
558 break;
559 case MD_CK1:
560 default:
561 r_clk.parent = &extalr_clk;
562 break;
563 }
564
565 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
566 ret = clk_register(main_clks[k]);
567
568 if (!ret)
569 ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
570
571 if (!ret)
572 ret = sh_clk_div6_register(div6_clks, DIV6_NR);
573
574 if (!ret)
Kuninori Morimotoc6750ac2012-06-12 02:35:36 -0700575 ret = sh_clk_div6_reparent_register(div6_reparent_clks,
576 DIV6_REPARENT_NR);
577
578 if (!ret)
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800579 ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
580
Kuninori Morimotoc6750ac2012-06-12 02:35:36 -0700581 for (k = 0; !ret && (k < ARRAY_SIZE(late_main_clks)); k++)
582 ret = clk_register(late_main_clks[k]);
583
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800584 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
585
586 if (!ret)
Magnus Damm6b6a4c02012-02-29 21:41:30 +0900587 shmobile_clk_init();
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800588 else
589 panic("failed to setup r8a7740 clocks\n");
590}