2 * arch/sh/kernel/cpu/sh4a/clock-sh7722.c
4 * SH7343, SH7722, SH7723 & SH7366 support for the clock framework
6 * Copyright (c) 2006-2007 Nomad Global Solutions Inc
7 * Based on code for sh7343 by Paul Mundt
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
13 #include <linux/init.h>
14 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/stringify.h>
18 #include <asm/clock.h>
23 #define ROUND_NEAREST 0
27 static int adjust_algos[][3] = {
29 { NM, N, 1 }, /* N:1, N:1 */
30 { 3, 2, 2 }, /* 3:2:2 */
31 { 5, 2, 2 }, /* 5:2:2 */
32 { N, 1, 1 }, /* N:1:1 */
44 static unsigned long adjust_pair_of_clocks(unsigned long r1, unsigned long r2,
45 int m1, int m2, int round_flag)
47 unsigned long rem, div;
50 pr_debug( "Actual values: r1 = %ld\n", r1);
51 pr_debug( "...............r2 = %ld\n", r2);
55 pr_debug( "setting equal rates: r2 now %ld\n", r2);
56 } else if ((m2 == N && m1 == 1) ||
57 (m2 == NM && m1 == N)) { /* N:1 or NM:N */
58 pr_debug( "Setting rates as 1:N (N:N*M)\n");
60 pr_debug( "...remainder = %ld\n", rem);
63 pr_debug( "...div = %ld\n", div);
66 the_one = rem >= r1/2 ? 1 : 0; break;
73 r2 = r1 * (div + the_one);
74 pr_debug( "...setting r2 to %ld\n", r2);
76 } else if ((m2 == 1 && m1 == N) ||
77 (m2 == N && m1 == NM)) { /* 1:N or N:NM */
78 pr_debug( "Setting rates as N:1 (N*M:N)\n");
80 pr_debug( "...remainder = %ld\n", rem);
83 pr_debug( "...div = %ld\n", div);
86 the_one = rem > r2/2 ? 1 : 0; break;
93 r2 = r1 / (div + the_one);
94 pr_debug( "...setting r2 to %ld\n", r2);
96 } else { /* value:value */
97 pr_debug( "Setting rates as %d:%d\n", m1, m2);
100 pr_debug( "...div = %ld\n", div);
101 pr_debug( "...setting r2 to %ld\n", r2);
107 static void adjust_clocks(int originate, int *l, unsigned long v[],
112 pr_debug( "Go down from %d...\n", originate);
113 /* go up recalculation clocks */
114 for (x = originate; x>0; x -- )
115 v[x-1] = adjust_pair_of_clocks(v[x], v[x-1],
119 pr_debug( "Go up from %d...\n", originate);
120 /* go down recalculation clocks */
121 for (x = originate; x<n_in_line - 1; x ++ )
122 v[x+1] = adjust_pair_of_clocks(v[x], v[x+1],
129 * SH7722 uses a common set of multipliers and divisors, so this
133 #if defined(CONFIG_CPU_SUBTYPE_SH7724)
134 #define STCPLL(frqcr) ((((frqcr >> 24) & 0x3f) + 1) * 2)
136 #define STCPLL(frqcr) (((frqcr >> 24) & 0x1f) + 1)
140 * Instead of having two separate multipliers/divisors set, like this:
142 * static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
143 * static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
145 * I created the divisors2 array, which is used to calculate rate like
146 * rate = parent * 2 / divisors2[ divisor ];
148 #if defined(CONFIG_CPU_SUBTYPE_SH7724)
149 static int divisors2[] = { 4, 1, 8, 12, 16, 24, 32, 1, 48, 64, 72, 96, 1, 144 };
151 static int divisors2[] = { 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32, 40 };
154 static unsigned long master_clk_recalc(struct clk *clk)
156 unsigned frqcr = ctrl_inl(FRQCR);
158 return CONFIG_SH_PCLK_FREQ * STCPLL(frqcr);
161 static void master_clk_init(struct clk *clk)
164 clk->rate = master_clk_recalc(clk);
167 static unsigned long module_clk_recalc(struct clk *clk)
169 unsigned long frqcr = ctrl_inl(FRQCR);
171 return clk->parent->rate / STCPLL(frqcr);
174 #if defined(CONFIG_CPU_SUBTYPE_SH7724)
175 #define MASTERDIVS { 12, 16, 24, 30, 32, 36, 48 }
177 #define DIVCALC(div) (div/2-1)
178 #define FRQCRKICK 0x80000000
179 #elif defined(CONFIG_CPU_SUBTYPE_SH7723)
180 #define MASTERDIVS { 6, 8, 12, 16 }
182 #define DIVCALC(div) (div-1)
183 #define FRQCRKICK 0x00000000
185 #define MASTERDIVS { 2, 3, 4, 6, 8, 16 }
187 #define DIVCALC(div) (div-1)
188 #define FRQCRKICK 0x00000000
191 static int master_clk_setrate(struct clk *clk, unsigned long rate, int id)
193 int div = rate / clk->rate;
194 int master_divs[] = MASTERDIVS;
198 for (index = 1; index < ARRAY_SIZE(master_divs); index++)
199 if (div >= master_divs[index - 1] && div < master_divs[index])
202 if (index >= ARRAY_SIZE(master_divs))
203 index = ARRAY_SIZE(master_divs);
204 div = master_divs[index - 1];
206 frqcr = ctrl_inl(FRQCR);
207 frqcr &= ~(STCMASK << 24);
208 frqcr |= (DIVCALC(div) << 24);
210 ctrl_outl(frqcr, FRQCR);
215 static struct clk_ops sh7722_master_clk_ops = {
216 .init = master_clk_init,
217 .recalc = master_clk_recalc,
218 .set_rate = master_clk_setrate,
221 static struct clk_ops sh7722_module_clk_ops = {
222 .recalc = module_clk_recalc,
225 struct frqcr_context {
230 struct frqcr_context sh7722_get_clk_context(const char *name)
232 struct frqcr_context ctx = { 0, };
234 if (!strcmp(name, "peripheral_clk")) {
237 } else if (!strcmp(name, "sdram_clk")) {
240 } else if (!strcmp(name, "bus_clk")) {
243 } else if (!strcmp(name, "sh_clk")) {
246 } else if (!strcmp(name, "umem_clk")) {
249 } else if (!strcmp(name, "cpu_clk")) {
257 * sh7722_find_div_index - find divisor for setting rate
259 * All sh7722 clocks use the same set of multipliers/divisors. This function
260 * chooses correct divisor to set the rate of clock with parent clock that
261 * generates frequency of 'parent_rate'
263 * @parent_rate: rate of parent clock
264 * @rate: requested rate to be set
266 static int sh7722_find_div_index(unsigned long parent_rate, unsigned rate)
268 unsigned div2 = parent_rate * 2 / rate;
271 if (rate > parent_rate)
274 for (index = 1; index < ARRAY_SIZE(divisors2); index++) {
275 if (div2 > divisors2[index - 1] && div2 <= divisors2[index])
278 if (index >= ARRAY_SIZE(divisors2))
279 index = ARRAY_SIZE(divisors2) - 1;
283 static unsigned long sh7722_frqcr_recalc(struct clk *clk)
285 struct frqcr_context ctx = sh7722_get_clk_context(clk->name);
286 unsigned long frqcr = ctrl_inl(FRQCR);
289 index = (frqcr >> ctx.shift) & ctx.mask;
290 return clk->parent->rate * 2 / divisors2[index];
293 static int sh7722_frqcr_set_rate(struct clk *clk, unsigned long rate,
296 struct frqcr_context ctx = sh7722_get_clk_context(clk->name);
297 unsigned long parent_rate = clk->parent->rate;
303 if (parent_rate < rate)
306 /* look for multiplier/divisor pair */
307 div = sh7722_find_div_index(parent_rate, rate);
311 /* calculate new value of clock rate */
312 clk->rate = parent_rate * 2 / divisors2[div];
313 frqcr = ctrl_inl(FRQCR);
315 /* FIXME: adjust as algo_id specifies */
316 if (algo_id != NO_CHANGE) {
318 char *algo_group_1[] = { "cpu_clk", "umem_clk", "sh_clk" };
319 char *algo_group_2[] = { "sh_clk", "bus_clk" };
320 char *algo_group_3[] = { "sh_clk", "sdram_clk" };
321 char *algo_group_4[] = { "bus_clk", "peripheral_clk" };
322 char *algo_group_5[] = { "cpu_clk", "peripheral_clk" };
323 char **algo_current = NULL;
324 /* 3 is the maximum number of clocks in relation */
326 unsigned long values[3]; /* the same comment as above */
327 int part_length = -1;
331 * all the steps below only required if adjustion was
334 if (algo_id == IUS_N1_N1 ||
335 algo_id == IUS_322 ||
336 algo_id == IUS_522 ||
337 algo_id == IUS_N11) {
338 algo_current = algo_group_1;
341 if (algo_id == SB_N1) {
342 algo_current = algo_group_2;
345 if (algo_id == SB3_N1 ||
349 algo_current = algo_group_3;
352 if (algo_id == BP_N1) {
353 algo_current = algo_group_4;
356 if (algo_id == IP_N1) {
357 algo_current = algo_group_5;
361 goto incorrect_algo_id;
364 for (i = 0; i < part_length; i ++ ) {
365 if (originator >= 0 && !strcmp(clk->name,
368 ck[i] = clk_get(NULL, algo_current[i]);
369 values[i] = clk_get_rate(ck[i]);
373 adjust_clocks(originator, adjust_algos[algo_id],
374 values, part_length);
376 for (i = 0; i < part_length; i ++ ) {
377 struct frqcr_context part_ctx;
381 part_div = sh7722_find_div_index(parent_rate,
384 part_ctx = sh7722_get_clk_context(
386 frqcr &= ~(part_ctx.mask <<
388 frqcr |= part_div << part_ctx.shift;
393 ck[i]->ops->recalc(ck[i]);
398 /* was there any error during recalculation ? If so, bail out.. */
399 if (unlikely(err!=0))
402 /* clear FRQCR bits */
403 frqcr &= ~(ctx.mask << ctx.shift);
404 frqcr |= div << ctx.shift;
407 /* ...and perform actual change */
408 ctrl_outl(frqcr, FRQCR);
417 static long sh7722_frqcr_round_rate(struct clk *clk, unsigned long rate)
419 unsigned long parent_rate = clk->parent->rate;
422 /* look for multiplier/divisor pair */
423 div = sh7722_find_div_index(parent_rate, rate);
427 /* calculate new value of clock rate */
428 return parent_rate * 2 / divisors2[div];
431 static struct clk_ops sh7722_frqcr_clk_ops = {
432 .recalc = sh7722_frqcr_recalc,
433 .set_rate = sh7722_frqcr_set_rate,
434 .round_rate = sh7722_frqcr_round_rate,
438 * clock ops methods for SIU A/B and IrDA clock
440 #ifndef CONFIG_CPU_SUBTYPE_SH7343
441 static int sh7722_siu_set_rate(struct clk *clk, unsigned long rate, int algo_id)
446 r = ctrl_inl(clk->arch_flags);
447 div = sh7722_find_div_index(clk->parent->rate, rate);
450 r = (r & ~0xF) | div;
451 ctrl_outl(r, clk->arch_flags);
455 static unsigned long sh7722_siu_recalc(struct clk *clk)
459 r = ctrl_inl(clk->arch_flags);
460 return clk->parent->rate * 2 / divisors2[r & 0xF];
463 static int sh7722_siu_start_stop(struct clk *clk, int enable)
467 r = ctrl_inl(clk->arch_flags);
469 ctrl_outl(r & ~(1 << 8), clk->arch_flags);
471 ctrl_outl(r | (1 << 8), clk->arch_flags);
475 static int sh7722_siu_enable(struct clk *clk)
477 return sh7722_siu_start_stop(clk, 1);
480 static void sh7722_siu_disable(struct clk *clk)
482 sh7722_siu_start_stop(clk, 0);
485 static struct clk_ops sh7722_siu_clk_ops = {
486 .recalc = sh7722_siu_recalc,
487 .set_rate = sh7722_siu_set_rate,
488 .enable = sh7722_siu_enable,
489 .disable = sh7722_siu_disable,
492 #endif /* CONFIG_CPU_SUBTYPE_SH7343 */
494 static int sh7722_video_enable(struct clk *clk)
498 r = ctrl_inl(VCLKCR);
499 ctrl_outl( r & ~(1<<8), VCLKCR);
503 static void sh7722_video_disable(struct clk *clk)
507 r = ctrl_inl(VCLKCR);
508 ctrl_outl( r | (1<<8), VCLKCR);
511 static int sh7722_video_set_rate(struct clk *clk, unsigned long rate,
516 r = ctrl_inl(VCLKCR);
518 r |= ((clk->parent->rate / rate - 1) & 0x3F);
519 ctrl_outl(r, VCLKCR);
523 static unsigned long sh7722_video_recalc(struct clk *clk)
527 r = ctrl_inl(VCLKCR);
528 return clk->parent->rate / ((r & 0x3F) + 1);
531 static struct clk_ops sh7722_video_clk_ops = {
532 .recalc = sh7722_video_recalc,
533 .set_rate = sh7722_video_set_rate,
534 .enable = sh7722_video_enable,
535 .disable = sh7722_video_disable,
538 * and at last, clock definitions themselves
540 static struct clk sh7722_umem_clock = {
542 .ops = &sh7722_frqcr_clk_ops,
545 static struct clk sh7722_sh_clock = {
547 .ops = &sh7722_frqcr_clk_ops,
550 static struct clk sh7722_peripheral_clock = {
551 .name = "peripheral_clk",
552 .ops = &sh7722_frqcr_clk_ops,
555 static struct clk sh7722_sdram_clock = {
557 .ops = &sh7722_frqcr_clk_ops,
560 static struct clk sh7722_r_clock = {
565 #if !defined(CONFIG_CPU_SUBTYPE_SH7343) &&\
566 !defined(CONFIG_CPU_SUBTYPE_SH7724)
568 * these three clocks - SIU A, SIU B, IrDA - share the same clk_ops
569 * methods of clk_ops determine which register they should access by
570 * examining clk->name field
572 static struct clk sh7722_siu_a_clock = {
574 .arch_flags = SCLKACR,
575 .ops = &sh7722_siu_clk_ops,
578 static struct clk sh7722_siu_b_clock = {
580 .arch_flags = SCLKBCR,
581 .ops = &sh7722_siu_clk_ops,
583 #endif /* CONFIG_CPU_SUBTYPE_SH7343, SH7724 */
585 #if defined(CONFIG_CPU_SUBTYPE_SH7722) ||\
586 defined(CONFIG_CPU_SUBTYPE_SH7724)
587 static struct clk sh7722_irda_clock = {
589 .arch_flags = IrDACLKCR,
590 .ops = &sh7722_siu_clk_ops,
594 static struct clk sh7722_video_clock = {
596 .ops = &sh7722_video_clk_ops,
599 #define MSTPCR_ARCH_FLAGS(reg, bit) (((reg) << 8) | (bit))
600 #define MSTPCR_ARCH_FLAGS_REG(value) ((value) >> 8)
601 #define MSTPCR_ARCH_FLAGS_BIT(value) ((value) & 0xff)
603 static int sh7722_mstpcr_start_stop(struct clk *clk, int enable)
605 unsigned long bit = MSTPCR_ARCH_FLAGS_BIT(clk->arch_flags);
609 switch(MSTPCR_ARCH_FLAGS_REG(clk->arch_flags)) {
634 static int sh7722_mstpcr_enable(struct clk *clk)
636 return sh7722_mstpcr_start_stop(clk, 1);
639 static void sh7722_mstpcr_disable(struct clk *clk)
641 sh7722_mstpcr_start_stop(clk, 0);
644 static struct clk_ops sh7722_mstpcr_clk_ops = {
645 .enable = sh7722_mstpcr_enable,
646 .disable = sh7722_mstpcr_disable,
647 .recalc = followparent_recalc,
650 #define MSTPCR(_name, _parent, regnr, bitnr, _flags) \
654 .arch_flags = MSTPCR_ARCH_FLAGS(regnr, bitnr), \
655 .ops = (void *)_parent, \
658 static struct clk sh7722_mstpcr_clocks[] = {
659 #if defined(CONFIG_CPU_SUBTYPE_SH7722)
660 MSTPCR("uram0", "umem_clk", 0, 28, CLK_ENABLE_ON_INIT),
661 MSTPCR("xymem0", "bus_clk", 0, 26, CLK_ENABLE_ON_INIT),
662 MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
663 MSTPCR("cmt0", "r_clk", 0, 14, 0),
664 MSTPCR("rwdt0", "r_clk", 0, 13, 0),
665 MSTPCR("flctl0", "peripheral_clk", 0, 10, 0),
666 MSTPCR("scif0", "peripheral_clk", 0, 7, 0),
667 MSTPCR("scif1", "peripheral_clk", 0, 6, 0),
668 MSTPCR("scif2", "peripheral_clk", 0, 5, 0),
669 MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
670 MSTPCR("rtc0", "r_clk", 1, 8, 0),
671 MSTPCR("sdhi0", "peripheral_clk", 2, 18, 0),
672 MSTPCR("keysc0", "r_clk", 2, 14, 0),
673 MSTPCR("usbf0", "peripheral_clk", 2, 11, 0),
674 MSTPCR("2dg0", "bus_clk", 2, 9, 0),
675 MSTPCR("siu0", "bus_clk", 2, 8, 0),
676 MSTPCR("vou0", "bus_clk", 2, 5, 0),
677 MSTPCR("jpu0", "bus_clk", 2, 6, CLK_ENABLE_ON_INIT),
678 MSTPCR("beu0", "bus_clk", 2, 4, 0),
679 MSTPCR("ceu0", "bus_clk", 2, 3, 0),
680 MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
681 MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
682 MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
684 #if defined(CONFIG_CPU_SUBTYPE_SH7723)
685 /* See page 60 of Datasheet V1.0: Overview -> Block Diagram */
686 MSTPCR("tlb0", "cpu_clk", 0, 31, 0),
687 MSTPCR("ic0", "cpu_clk", 0, 30, 0),
688 MSTPCR("oc0", "cpu_clk", 0, 29, 0),
689 MSTPCR("l2c0", "sh_clk", 0, 28, 0),
690 MSTPCR("ilmem0", "cpu_clk", 0, 27, 0),
691 MSTPCR("fpu0", "cpu_clk", 0, 24, 0),
692 MSTPCR("intc0", "cpu_clk", 0, 22, 0),
693 MSTPCR("dmac0", "bus_clk", 0, 21, 0),
694 MSTPCR("sh0", "sh_clk", 0, 20, 0),
695 MSTPCR("hudi0", "peripheral_clk", 0, 19, 0),
696 MSTPCR("ubc0", "cpu_clk", 0, 17, 0),
697 MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
698 MSTPCR("cmt0", "r_clk", 0, 14, 0),
699 MSTPCR("rwdt0", "r_clk", 0, 13, 0),
700 MSTPCR("dmac1", "bus_clk", 0, 12, 0),
701 MSTPCR("tmu1", "peripheral_clk", 0, 11, 0),
702 MSTPCR("flctl0", "peripheral_clk", 0, 10, 0),
703 MSTPCR("scif0", "peripheral_clk", 0, 9, 0),
704 MSTPCR("scif1", "peripheral_clk", 0, 8, 0),
705 MSTPCR("scif2", "peripheral_clk", 0, 7, 0),
706 MSTPCR("scif3", "bus_clk", 0, 6, 0),
707 MSTPCR("scif4", "bus_clk", 0, 5, 0),
708 MSTPCR("scif5", "bus_clk", 0, 4, 0),
709 MSTPCR("msiof0", "bus_clk", 0, 2, 0),
710 MSTPCR("msiof1", "bus_clk", 0, 1, 0),
711 MSTPCR("meram0", "sh_clk", 0, 0, CLK_ENABLE_ON_INIT),
712 MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
713 MSTPCR("rtc0", "r_clk", 1, 8, 0),
714 MSTPCR("atapi0", "sh_clk", 2, 28, 0),
715 MSTPCR("adc0", "peripheral_clk", 2, 28, 0),
716 MSTPCR("tpu0", "bus_clk", 2, 25, 0),
717 MSTPCR("irda0", "peripheral_clk", 2, 24, 0),
718 MSTPCR("tsif0", "bus_clk", 2, 22, 0),
719 MSTPCR("icb0", "bus_clk", 2, 21, 0),
720 MSTPCR("sdhi0", "bus_clk", 2, 18, 0),
721 MSTPCR("sdhi1", "bus_clk", 2, 17, 0),
722 MSTPCR("keysc0", "r_clk", 2, 14, 0),
723 MSTPCR("usb0", "bus_clk", 2, 11, 0),
724 MSTPCR("2dg0", "bus_clk", 2, 10, 0),
725 MSTPCR("siu0", "bus_clk", 2, 8, 0),
726 MSTPCR("veu1", "bus_clk", 2, 6, CLK_ENABLE_ON_INIT),
727 MSTPCR("vou0", "bus_clk", 2, 5, 0),
728 MSTPCR("beu0", "bus_clk", 2, 4, 0),
729 MSTPCR("ceu0", "bus_clk", 2, 3, 0),
730 MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
731 MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
732 MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
734 #if defined(CONFIG_CPU_SUBTYPE_SH7724)
735 /* See Datasheet : Overview -> Block Diagram */
736 MSTPCR("tlb0", "cpu_clk", 0, 31, 0),
737 MSTPCR("ic0", "cpu_clk", 0, 30, 0),
738 MSTPCR("oc0", "cpu_clk", 0, 29, 0),
739 MSTPCR("rs0", "bus_clk", 0, 28, 0),
740 MSTPCR("ilmem0", "cpu_clk", 0, 27, 0),
741 MSTPCR("l2c0", "sh_clk", 0, 26, 0),
742 MSTPCR("fpu0", "cpu_clk", 0, 24, 0),
743 MSTPCR("intc0", "peripheral_clk", 0, 22, 0),
744 MSTPCR("dmac0", "bus_clk", 0, 21, 0),
745 MSTPCR("sh0", "sh_clk", 0, 20, 0),
746 MSTPCR("hudi0", "peripheral_clk", 0, 19, 0),
747 MSTPCR("ubc0", "cpu_clk", 0, 17, 0),
748 MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
749 MSTPCR("cmt0", "r_clk", 0, 14, 0),
750 MSTPCR("rwdt0", "r_clk", 0, 13, 0),
751 MSTPCR("dmac1", "bus_clk", 0, 12, 0),
752 MSTPCR("tmu1", "peripheral_clk", 0, 10, 0),
753 MSTPCR("scif0", "peripheral_clk", 0, 9, 0),
754 MSTPCR("scif1", "peripheral_clk", 0, 8, 0),
755 MSTPCR("scif2", "peripheral_clk", 0, 7, 0),
756 MSTPCR("scif3", "bus_clk", 0, 6, 0),
757 MSTPCR("scif4", "bus_clk", 0, 5, 0),
758 MSTPCR("scif5", "bus_clk", 0, 4, 0),
759 MSTPCR("msiof0", "bus_clk", 0, 2, 0),
760 MSTPCR("msiof1", "bus_clk", 0, 1, 0),
761 MSTPCR("keysc0", "r_clk", 1, 12, 0),
762 MSTPCR("rtc0", "r_clk", 1, 11, 0),
763 MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
764 MSTPCR("i2c1", "peripheral_clk", 1, 8, 0),
765 MSTPCR("mmc0", "bus_clk", 2, 29, 0),
766 MSTPCR("eth0", "bus_clk", 2, 28, 0),
767 MSTPCR("atapi0", "bus_clk", 2, 26, 0),
768 MSTPCR("tpu0", "bus_clk", 2, 25, 0),
769 MSTPCR("irda0", "peripheral_clk", 2, 24, 0),
770 MSTPCR("tsif0", "bus_clk", 2, 22, 0),
771 MSTPCR("usb1", "bus_clk", 2, 21, 0),
772 MSTPCR("usb0", "bus_clk", 2, 20, 0),
773 MSTPCR("2dg0", "bus_clk", 2, 19, 0),
774 MSTPCR("sdhi0", "bus_clk", 2, 18, 0),
775 MSTPCR("sdhi1", "bus_clk", 2, 17, 0),
776 MSTPCR("veu1", "bus_clk", 2, 15, CLK_ENABLE_ON_INIT),
777 MSTPCR("ceu1", "bus_clk", 2, 13, 0),
778 MSTPCR("beu1", "bus_clk", 2, 12, 0),
779 MSTPCR("2ddmac0", "sh_clk", 2, 10, 0),
780 MSTPCR("spu0", "bus_clk", 2, 9, 0),
781 MSTPCR("jpu0", "bus_clk", 2, 6, 0),
782 MSTPCR("vou0", "bus_clk", 2, 5, 0),
783 MSTPCR("beu0", "bus_clk", 2, 4, 0),
784 MSTPCR("ceu0", "bus_clk", 2, 3, 0),
785 MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
786 MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
787 MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
789 #if defined(CONFIG_CPU_SUBTYPE_SH7343)
790 MSTPCR("uram0", "umem_clk", 0, 28, CLK_ENABLE_ON_INIT),
791 MSTPCR("xymem0", "bus_clk", 0, 26, CLK_ENABLE_ON_INIT),
792 MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
793 MSTPCR("cmt0", "r_clk", 0, 14, 0),
794 MSTPCR("rwdt0", "r_clk", 0, 13, 0),
795 MSTPCR("scif0", "peripheral_clk", 0, 7, 0),
796 MSTPCR("scif1", "peripheral_clk", 0, 6, 0),
797 MSTPCR("scif2", "peripheral_clk", 0, 5, 0),
798 MSTPCR("scif3", "peripheral_clk", 0, 4, 0),
799 MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
800 MSTPCR("i2c1", "peripheral_clk", 1, 8, 0),
801 MSTPCR("sdhi0", "peripheral_clk", 2, 18, 0),
802 MSTPCR("keysc0", "r_clk", 2, 14, 0),
803 MSTPCR("usbf0", "peripheral_clk", 2, 11, 0),
804 MSTPCR("siu0", "bus_clk", 2, 8, 0),
805 MSTPCR("jpu0", "bus_clk", 2, 6, CLK_ENABLE_ON_INIT),
806 MSTPCR("vou0", "bus_clk", 2, 5, 0),
807 MSTPCR("beu0", "bus_clk", 2, 4, 0),
808 MSTPCR("ceu0", "bus_clk", 2, 3, 0),
809 MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
810 MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
811 MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
813 #if defined(CONFIG_CPU_SUBTYPE_SH7366)
814 /* See page 52 of Datasheet V0.40: Overview -> Block Diagram */
815 MSTPCR("tlb0", "cpu_clk", 0, 31, 0),
816 MSTPCR("ic0", "cpu_clk", 0, 30, 0),
817 MSTPCR("oc0", "cpu_clk", 0, 29, 0),
818 MSTPCR("rsmem0", "sh_clk", 0, 28, CLK_ENABLE_ON_INIT),
819 MSTPCR("xymem0", "cpu_clk", 0, 26, CLK_ENABLE_ON_INIT),
820 MSTPCR("intc30", "peripheral_clk", 0, 23, 0),
821 MSTPCR("intc0", "peripheral_clk", 0, 22, 0),
822 MSTPCR("dmac0", "bus_clk", 0, 21, 0),
823 MSTPCR("sh0", "sh_clk", 0, 20, 0),
824 MSTPCR("hudi0", "peripheral_clk", 0, 19, 0),
825 MSTPCR("ubc0", "cpu_clk", 0, 17, 0),
826 MSTPCR("tmu0", "peripheral_clk", 0, 15, 0),
827 MSTPCR("cmt0", "r_clk", 0, 14, 0),
828 MSTPCR("rwdt0", "r_clk", 0, 13, 0),
829 MSTPCR("flctl0", "peripheral_clk", 0, 10, 0),
830 MSTPCR("scif0", "peripheral_clk", 0, 7, 0),
831 MSTPCR("scif1", "bus_clk", 0, 6, 0),
832 MSTPCR("scif2", "bus_clk", 0, 5, 0),
833 MSTPCR("msiof0", "peripheral_clk", 0, 2, 0),
834 MSTPCR("sbr0", "peripheral_clk", 0, 1, 0),
835 MSTPCR("i2c0", "peripheral_clk", 1, 9, 0),
836 MSTPCR("icb0", "bus_clk", 2, 27, 0),
837 MSTPCR("meram0", "sh_clk", 2, 26, 0),
838 MSTPCR("dacc0", "peripheral_clk", 2, 24, 0),
839 MSTPCR("dacy0", "peripheral_clk", 2, 23, 0),
840 MSTPCR("tsif0", "bus_clk", 2, 22, 0),
841 MSTPCR("sdhi0", "bus_clk", 2, 18, 0),
842 MSTPCR("mmcif0", "bus_clk", 2, 17, 0),
843 MSTPCR("usb0", "bus_clk", 2, 11, 0),
844 MSTPCR("siu0", "bus_clk", 2, 8, 0),
845 MSTPCR("veu1", "bus_clk", 2, 7, CLK_ENABLE_ON_INIT),
846 MSTPCR("vou0", "bus_clk", 2, 5, 0),
847 MSTPCR("beu0", "bus_clk", 2, 4, 0),
848 MSTPCR("ceu0", "bus_clk", 2, 3, 0),
849 MSTPCR("veu0", "bus_clk", 2, 2, CLK_ENABLE_ON_INIT),
850 MSTPCR("vpu0", "bus_clk", 2, 1, CLK_ENABLE_ON_INIT),
851 MSTPCR("lcdc0", "bus_clk", 2, 0, 0),
855 static struct clk *sh7722_clocks[] = {
858 &sh7722_peripheral_clock,
860 #if !defined(CONFIG_CPU_SUBTYPE_SH7343) &&\
861 !defined(CONFIG_CPU_SUBTYPE_SH7724)
865 /* 7724 should support FSI clock */
866 #if defined(CONFIG_CPU_SUBTYPE_SH7722) || \
867 defined(CONFIG_CPU_SUBTYPE_SH7724)
874 * init in order: master, module, bus, cpu
876 struct clk_ops *onchip_ops[] = {
877 &sh7722_master_clk_ops,
878 &sh7722_module_clk_ops,
879 &sh7722_frqcr_clk_ops,
880 &sh7722_frqcr_clk_ops,
884 arch_init_clk_ops(struct clk_ops **ops, int type)
886 BUG_ON(type < 0 || type >= ARRAY_SIZE(onchip_ops));
887 *ops = onchip_ops[type];
890 int __init arch_clk_init(void)
897 clk = clk_get(NULL, "master_clk");
898 for (i = 0; i < ARRAY_SIZE(sh7722_clocks); i++) {
899 pr_debug( "Registering clock '%s'\n", sh7722_clocks[i]->name);
900 sh7722_clocks[i]->parent = clk;
901 clk_register(sh7722_clocks[i]);
905 clk_register(&sh7722_r_clock);
907 for (i = 0; i < ARRAY_SIZE(sh7722_mstpcr_clocks); i++) {
908 pr_debug( "Registering mstpcr clock '%s'\n",
909 sh7722_mstpcr_clocks[i].name);
910 clk = clk_get(NULL, (void *) sh7722_mstpcr_clocks[i].ops);
911 sh7722_mstpcr_clocks[i].parent = clk;
912 sh7722_mstpcr_clocks[i].ops = &sh7722_mstpcr_clk_ops;
913 clk_register(&sh7722_mstpcr_clocks[i]);
917 propagate_rate(&sh7722_r_clock); /* make sure rate gets propagated */