xref: /linux/arch/sh/kernel/cpu/sh4a/clock-sh7723.c (revision 9f06cf38eca57e279b4c78e465e19f10c2f78174)
1c521dc02SMagnus Damm /*
2c521dc02SMagnus Damm  * arch/sh/kernel/cpu/sh4a/clock-sh7723.c
3c521dc02SMagnus Damm  *
4c521dc02SMagnus Damm  * SH7723 clock framework support
5c521dc02SMagnus Damm  *
6c521dc02SMagnus Damm  * Copyright (C) 2009 Magnus Damm
7c521dc02SMagnus Damm  *
8c521dc02SMagnus Damm  * This program is free software; you can redistribute it and/or modify
9c521dc02SMagnus Damm  * it under the terms of the GNU General Public License as published by
10c521dc02SMagnus Damm  * the Free Software Foundation; either version 2 of the License
11c521dc02SMagnus Damm  *
12c521dc02SMagnus Damm  * This program is distributed in the hope that it will be useful,
13c521dc02SMagnus Damm  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14c521dc02SMagnus Damm  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15c521dc02SMagnus Damm  * GNU General Public License for more details.
16c521dc02SMagnus Damm  *
17c521dc02SMagnus Damm  * You should have received a copy of the GNU General Public License
18c521dc02SMagnus Damm  * along with this program; if not, write to the Free Software
19c521dc02SMagnus Damm  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20c521dc02SMagnus Damm  */
21c521dc02SMagnus Damm #include <linux/init.h>
22c521dc02SMagnus Damm #include <linux/kernel.h>
23c521dc02SMagnus Damm #include <linux/io.h>
24f4221802SPaul Mundt #include <linux/clk.h>
256d803ba7SJean-Christop PLAGNIOL-VILLARD #include <linux/clkdev.h>
267fa4632dSGuennadi Liakhovetski #include <linux/sh_clk.h>
27c521dc02SMagnus Damm #include <asm/clock.h>
282094e504SMagnus Damm #include <cpu/sh7723.h>
29c521dc02SMagnus Damm 
30c521dc02SMagnus Damm /* SH7723 registers */
31c521dc02SMagnus Damm #define FRQCR		0xa4150000
32c521dc02SMagnus Damm #define VCLKCR		0xa4150004
33c521dc02SMagnus Damm #define SCLKACR		0xa4150008
34c521dc02SMagnus Damm #define SCLKBCR		0xa415000c
35c521dc02SMagnus Damm #define IRDACLKCR	0xa4150018
36c521dc02SMagnus Damm #define PLLCR		0xa4150024
377fa4632dSGuennadi Liakhovetski #define MSTPCR0		0xa4150030
387fa4632dSGuennadi Liakhovetski #define MSTPCR1		0xa4150034
397fa4632dSGuennadi Liakhovetski #define MSTPCR2		0xa4150038
40c521dc02SMagnus Damm #define DLLFRQ		0xa4150050
41c521dc02SMagnus Damm 
42c521dc02SMagnus Damm /* Fixed 32 KHz root clock for RTC and Power Management purposes */
43c521dc02SMagnus Damm static struct clk r_clk = {
44c521dc02SMagnus Damm 	.rate           = 32768,
45c521dc02SMagnus Damm };
46c521dc02SMagnus Damm 
47c521dc02SMagnus Damm /*
48c521dc02SMagnus Damm  * Default rate for the root input clock, reset this with clk_set_rate()
49c521dc02SMagnus Damm  * from the platform code.
50c521dc02SMagnus Damm  */
51c521dc02SMagnus Damm struct clk extal_clk = {
52c521dc02SMagnus Damm 	.rate		= 33333333,
53c521dc02SMagnus Damm };
54c521dc02SMagnus Damm 
55c521dc02SMagnus Damm /* The dll multiplies the 32khz r_clk, may be used instead of extal */
56c521dc02SMagnus Damm static unsigned long dll_recalc(struct clk *clk)
57c521dc02SMagnus Damm {
58c521dc02SMagnus Damm 	unsigned long mult;
59c521dc02SMagnus Damm 
60c521dc02SMagnus Damm 	if (__raw_readl(PLLCR) & 0x1000)
61c521dc02SMagnus Damm 		mult = __raw_readl(DLLFRQ);
62c521dc02SMagnus Damm 	else
63c521dc02SMagnus Damm 		mult = 0;
64c521dc02SMagnus Damm 
65c521dc02SMagnus Damm 	return clk->parent->rate * mult;
66c521dc02SMagnus Damm }
67c521dc02SMagnus Damm 
68c521dc02SMagnus Damm static struct clk_ops dll_clk_ops = {
69c521dc02SMagnus Damm 	.recalc		= dll_recalc,
70c521dc02SMagnus Damm };
71c521dc02SMagnus Damm 
72c521dc02SMagnus Damm static struct clk dll_clk = {
73c521dc02SMagnus Damm 	.ops		= &dll_clk_ops,
74c521dc02SMagnus Damm 	.parent		= &r_clk,
75c521dc02SMagnus Damm 	.flags		= CLK_ENABLE_ON_INIT,
76c521dc02SMagnus Damm };
77c521dc02SMagnus Damm 
78c521dc02SMagnus Damm static unsigned long pll_recalc(struct clk *clk)
79c521dc02SMagnus Damm {
80c521dc02SMagnus Damm 	unsigned long mult = 1;
81c521dc02SMagnus Damm 	unsigned long div = 1;
82c521dc02SMagnus Damm 
83c521dc02SMagnus Damm 	if (__raw_readl(PLLCR) & 0x4000)
84c521dc02SMagnus Damm 		mult = (((__raw_readl(FRQCR) >> 24) & 0x1f) + 1);
85c521dc02SMagnus Damm 	else
86c521dc02SMagnus Damm 		div = 2;
87c521dc02SMagnus Damm 
88c521dc02SMagnus Damm 	return (clk->parent->rate * mult) / div;
89c521dc02SMagnus Damm }
90c521dc02SMagnus Damm 
91c521dc02SMagnus Damm static struct clk_ops pll_clk_ops = {
92c521dc02SMagnus Damm 	.recalc		= pll_recalc,
93c521dc02SMagnus Damm };
94c521dc02SMagnus Damm 
95c521dc02SMagnus Damm static struct clk pll_clk = {
96c521dc02SMagnus Damm 	.ops		= &pll_clk_ops,
97c521dc02SMagnus Damm 	.flags		= CLK_ENABLE_ON_INIT,
98c521dc02SMagnus Damm };
99c521dc02SMagnus Damm 
100c521dc02SMagnus Damm struct clk *main_clks[] = {
101c521dc02SMagnus Damm 	&r_clk,
102c521dc02SMagnus Damm 	&extal_clk,
103c521dc02SMagnus Damm 	&dll_clk,
104c521dc02SMagnus Damm 	&pll_clk,
105c521dc02SMagnus Damm };
106c521dc02SMagnus Damm 
107c521dc02SMagnus Damm static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
108c521dc02SMagnus Damm static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
109c521dc02SMagnus Damm 
1100a5f337eSMagnus Damm static struct clk_div_mult_table div4_div_mult_table = {
111c521dc02SMagnus Damm 	.divisors = divisors,
112c521dc02SMagnus Damm 	.nr_divisors = ARRAY_SIZE(divisors),
113c521dc02SMagnus Damm 	.multipliers = multipliers,
114c521dc02SMagnus Damm 	.nr_multipliers = ARRAY_SIZE(multipliers),
115c521dc02SMagnus Damm };
116c521dc02SMagnus Damm 
1170a5f337eSMagnus Damm static struct clk_div4_table div4_table = {
1180a5f337eSMagnus Damm 	.div_mult_table = &div4_div_mult_table,
1190a5f337eSMagnus Damm };
1200a5f337eSMagnus Damm 
121801cd56eSMagnus Damm enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P, DIV4_NR };
122c521dc02SMagnus Damm 
123914ebf0bSMagnus Damm #define DIV4(_reg, _bit, _mask, _flags) \
124914ebf0bSMagnus Damm   SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)
125c521dc02SMagnus Damm 
126c521dc02SMagnus Damm struct clk div4_clks[DIV4_NR] = {
127914ebf0bSMagnus Damm 	[DIV4_I] = DIV4(FRQCR, 20, 0x0dbf, CLK_ENABLE_ON_INIT),
128914ebf0bSMagnus Damm 	[DIV4_U] = DIV4(FRQCR, 16, 0x0dbf, CLK_ENABLE_ON_INIT),
129914ebf0bSMagnus Damm 	[DIV4_SH] = DIV4(FRQCR, 12, 0x0dbf, CLK_ENABLE_ON_INIT),
130914ebf0bSMagnus Damm 	[DIV4_B] = DIV4(FRQCR, 8, 0x0dbf, CLK_ENABLE_ON_INIT),
131914ebf0bSMagnus Damm 	[DIV4_B3] = DIV4(FRQCR, 4, 0x0db4, CLK_ENABLE_ON_INIT),
132914ebf0bSMagnus Damm 	[DIV4_P] = DIV4(FRQCR, 0, 0x0dbf, 0),
133801cd56eSMagnus Damm };
134801cd56eSMagnus Damm 
135801cd56eSMagnus Damm enum { DIV4_IRDA, DIV4_ENABLE_NR };
136801cd56eSMagnus Damm 
137801cd56eSMagnus Damm struct clk div4_enable_clks[DIV4_ENABLE_NR] = {
138914ebf0bSMagnus Damm 	[DIV4_IRDA] = DIV4(IRDACLKCR, 0, 0x0dbf, 0),
139c521dc02SMagnus Damm };
140c521dc02SMagnus Damm 
141801cd56eSMagnus Damm enum { DIV4_SIUA, DIV4_SIUB, DIV4_REPARENT_NR };
142801cd56eSMagnus Damm 
143801cd56eSMagnus Damm struct clk div4_reparent_clks[DIV4_REPARENT_NR] = {
144914ebf0bSMagnus Damm 	[DIV4_SIUA] = DIV4(SCLKACR, 0, 0x0dbf, 0),
145914ebf0bSMagnus Damm 	[DIV4_SIUB] = DIV4(SCLKBCR, 0, 0x0dbf, 0),
146801cd56eSMagnus Damm };
147098ec49bSMagnus Damm enum { DIV6_V, DIV6_NR };
148098ec49bSMagnus Damm 
149098ec49bSMagnus Damm struct clk div6_clks[DIV6_NR] = {
1509e1985e1SMagnus Damm 	[DIV6_V] = SH_CLK_DIV6(&pll_clk, VCLKCR, 0),
151c521dc02SMagnus Damm };
152c521dc02SMagnus Damm 
153c521dc02SMagnus Damm static struct clk mstp_clks[] = {
154c521dc02SMagnus Damm 	/* See page 60 of Datasheet V1.0: Overview -> Block Diagram */
1557fa4632dSGuennadi Liakhovetski 	[HWBLK_TLB]    = SH_CLK_MSTP32(&div4_clks[DIV4_I],  MSTPCR0, 31, CLK_ENABLE_ON_INIT),
1567fa4632dSGuennadi Liakhovetski 	[HWBLK_IC]     = SH_CLK_MSTP32(&div4_clks[DIV4_I],  MSTPCR0, 30, CLK_ENABLE_ON_INIT),
1577fa4632dSGuennadi Liakhovetski 	[HWBLK_OC]     = SH_CLK_MSTP32(&div4_clks[DIV4_I],  MSTPCR0, 29, CLK_ENABLE_ON_INIT),
1587fa4632dSGuennadi Liakhovetski 	[HWBLK_L2C]    = SH_CLK_MSTP32(&div4_clks[DIV4_SH], MSTPCR0, 28, CLK_ENABLE_ON_INIT),
1597fa4632dSGuennadi Liakhovetski 	[HWBLK_ILMEM]  = SH_CLK_MSTP32(&div4_clks[DIV4_I],  MSTPCR0, 27, CLK_ENABLE_ON_INIT),
1607fa4632dSGuennadi Liakhovetski 	[HWBLK_FPU]    = SH_CLK_MSTP32(&div4_clks[DIV4_I],  MSTPCR0, 24, CLK_ENABLE_ON_INIT),
1617fa4632dSGuennadi Liakhovetski 	[HWBLK_INTC]   = SH_CLK_MSTP32(&div4_clks[DIV4_I],  MSTPCR0, 22, CLK_ENABLE_ON_INIT),
1627fa4632dSGuennadi Liakhovetski 	[HWBLK_DMAC0]  = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR0, 21, 0),
1637fa4632dSGuennadi Liakhovetski 	[HWBLK_SHYWAY] = SH_CLK_MSTP32(&div4_clks[DIV4_SH], MSTPCR0, 20, CLK_ENABLE_ON_INIT),
1647fa4632dSGuennadi Liakhovetski 	[HWBLK_HUDI]   = SH_CLK_MSTP32(&div4_clks[DIV4_P],  MSTPCR0, 19, 0),
1657fa4632dSGuennadi Liakhovetski 	[HWBLK_UBC]    = SH_CLK_MSTP32(&div4_clks[DIV4_I],  MSTPCR0, 17, 0),
1667fa4632dSGuennadi Liakhovetski 	[HWBLK_TMU0]   = SH_CLK_MSTP32(&div4_clks[DIV4_P],  MSTPCR0, 15, 0),
1677fa4632dSGuennadi Liakhovetski 	[HWBLK_CMT]    = SH_CLK_MSTP32(&r_clk,		    MSTPCR0, 14, 0),
1687fa4632dSGuennadi Liakhovetski 	[HWBLK_RWDT]   = SH_CLK_MSTP32(&r_clk,		    MSTPCR0, 13, 0),
1697fa4632dSGuennadi Liakhovetski 	[HWBLK_DMAC1]  = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR0, 12, 0),
1707fa4632dSGuennadi Liakhovetski 	[HWBLK_TMU1]   = SH_CLK_MSTP32(&div4_clks[DIV4_P],  MSTPCR0, 11, 0),
1717fa4632dSGuennadi Liakhovetski 	[HWBLK_FLCTL]  = SH_CLK_MSTP32(&div4_clks[DIV4_P],  MSTPCR0, 10, 0),
1727fa4632dSGuennadi Liakhovetski 	[HWBLK_SCIF0]  = SH_CLK_MSTP32(&div4_clks[DIV4_P],  MSTPCR0, 9, 0),
1737fa4632dSGuennadi Liakhovetski 	[HWBLK_SCIF1]  = SH_CLK_MSTP32(&div4_clks[DIV4_P],  MSTPCR0, 8, 0),
1747fa4632dSGuennadi Liakhovetski 	[HWBLK_SCIF2]  = SH_CLK_MSTP32(&div4_clks[DIV4_P],  MSTPCR0, 7, 0),
1757fa4632dSGuennadi Liakhovetski 	[HWBLK_SCIF3]  = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR0, 6, 0),
1767fa4632dSGuennadi Liakhovetski 	[HWBLK_SCIF4]  = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR0, 5, 0),
1777fa4632dSGuennadi Liakhovetski 	[HWBLK_SCIF5]  = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR0, 4, 0),
1787fa4632dSGuennadi Liakhovetski 	[HWBLK_MSIOF0] = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR0, 2, 0),
1797fa4632dSGuennadi Liakhovetski 	[HWBLK_MSIOF1] = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR0, 1, 0),
1807fa4632dSGuennadi Liakhovetski 	[HWBLK_MERAM]  = SH_CLK_MSTP32(&div4_clks[DIV4_SH], MSTPCR0, 0, 0),
181c521dc02SMagnus Damm 
1827fa4632dSGuennadi Liakhovetski 	[HWBLK_IIC]    = SH_CLK_MSTP32(&div4_clks[DIV4_P],  MSTPCR1, 9, 0),
1837fa4632dSGuennadi Liakhovetski 	[HWBLK_RTC]    = SH_CLK_MSTP32(&r_clk,		    MSTPCR1, 8, 0),
184c521dc02SMagnus Damm 
1857fa4632dSGuennadi Liakhovetski 	[HWBLK_ATAPI]  = SH_CLK_MSTP32(&div4_clks[DIV4_SH], MSTPCR2, 28, 0),
1867fa4632dSGuennadi Liakhovetski 	[HWBLK_ADC]    = SH_CLK_MSTP32(&div4_clks[DIV4_P],  MSTPCR2, 27, 0),
1877fa4632dSGuennadi Liakhovetski 	[HWBLK_TPU]    = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 25, 0),
1887fa4632dSGuennadi Liakhovetski 	[HWBLK_IRDA]   = SH_CLK_MSTP32(&div4_clks[DIV4_P],  MSTPCR2, 24, 0),
1897fa4632dSGuennadi Liakhovetski 	[HWBLK_TSIF]   = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 22, 0),
1907fa4632dSGuennadi Liakhovetski 	[HWBLK_ICB]    = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 21, CLK_ENABLE_ON_INIT),
1917fa4632dSGuennadi Liakhovetski 	[HWBLK_SDHI0]  = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 18, 0),
1927fa4632dSGuennadi Liakhovetski 	[HWBLK_SDHI1]  = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 17, 0),
1937fa4632dSGuennadi Liakhovetski 	[HWBLK_KEYSC]  = SH_CLK_MSTP32(&r_clk,		    MSTPCR2, 14, 0),
1947fa4632dSGuennadi Liakhovetski 	[HWBLK_USB]    = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 11, 0),
1957fa4632dSGuennadi Liakhovetski 	[HWBLK_2DG]    = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 10, 0),
1967fa4632dSGuennadi Liakhovetski 	[HWBLK_SIU]    = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 8, 0),
1977fa4632dSGuennadi Liakhovetski 	[HWBLK_VEU2H1] = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 6, 0),
1987fa4632dSGuennadi Liakhovetski 	[HWBLK_VOU]    = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 5, 0),
1997fa4632dSGuennadi Liakhovetski 	[HWBLK_BEU]    = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 4, 0),
2007fa4632dSGuennadi Liakhovetski 	[HWBLK_CEU]    = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 3, 0),
2017fa4632dSGuennadi Liakhovetski 	[HWBLK_VEU2H0] = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 2, 0),
2027fa4632dSGuennadi Liakhovetski 	[HWBLK_VPU]    = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 1, 0),
2037fa4632dSGuennadi Liakhovetski 	[HWBLK_LCDC]   = SH_CLK_MSTP32(&div4_clks[DIV4_B],  MSTPCR2, 0, 0),
204c521dc02SMagnus Damm };
205c521dc02SMagnus Damm 
206f4221802SPaul Mundt static struct clk_lookup lookups[] = {
20700522ac3SMagnus Damm 	/* main clocks */
20800522ac3SMagnus Damm 	CLKDEV_CON_ID("rclk", &r_clk),
20900522ac3SMagnus Damm 	CLKDEV_CON_ID("extal", &extal_clk),
21000522ac3SMagnus Damm 	CLKDEV_CON_ID("dll_clk", &dll_clk),
21100522ac3SMagnus Damm 	CLKDEV_CON_ID("pll_clk", &pll_clk),
21200522ac3SMagnus Damm 
2133f662349SMagnus Damm 	/* DIV4 clocks */
2143f662349SMagnus Damm 	CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
2153f662349SMagnus Damm 	CLKDEV_CON_ID("umem_clk", &div4_clks[DIV4_U]),
2163f662349SMagnus Damm 	CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
2173f662349SMagnus Damm 	CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
2183f662349SMagnus Damm 	CLKDEV_CON_ID("b3_clk", &div4_clks[DIV4_B3]),
2193f662349SMagnus Damm 	CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
2203f662349SMagnus Damm 	CLKDEV_CON_ID("irda_clk", &div4_enable_clks[DIV4_IRDA]),
2213f662349SMagnus Damm 	CLKDEV_CON_ID("siua_clk", &div4_reparent_clks[DIV4_SIUA]),
2223f662349SMagnus Damm 	CLKDEV_CON_ID("siub_clk", &div4_reparent_clks[DIV4_SIUB]),
2233f662349SMagnus Damm 
224098ec49bSMagnus Damm 	/* DIV6 clocks */
225098ec49bSMagnus Damm 	CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),
226098ec49bSMagnus Damm 
227fd30401bSMagnus Damm 	/* MSTP clocks */
228fd30401bSMagnus Damm 	CLKDEV_CON_ID("tlb0", &mstp_clks[HWBLK_TLB]),
229fd30401bSMagnus Damm 	CLKDEV_CON_ID("ic0", &mstp_clks[HWBLK_IC]),
230fd30401bSMagnus Damm 	CLKDEV_CON_ID("oc0", &mstp_clks[HWBLK_OC]),
231fd30401bSMagnus Damm 	CLKDEV_CON_ID("l2c0", &mstp_clks[HWBLK_L2C]),
232fd30401bSMagnus Damm 	CLKDEV_CON_ID("ilmem0", &mstp_clks[HWBLK_ILMEM]),
233fd30401bSMagnus Damm 	CLKDEV_CON_ID("fpu0", &mstp_clks[HWBLK_FPU]),
234fd30401bSMagnus Damm 	CLKDEV_CON_ID("intc0", &mstp_clks[HWBLK_INTC]),
2357fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("sh-dma-engine.0", &mstp_clks[HWBLK_DMAC0]),
236fd30401bSMagnus Damm 	CLKDEV_CON_ID("sh0", &mstp_clks[HWBLK_SHYWAY]),
237fd30401bSMagnus Damm 	CLKDEV_CON_ID("hudi0", &mstp_clks[HWBLK_HUDI]),
238fd30401bSMagnus Damm 	CLKDEV_CON_ID("ubc0", &mstp_clks[HWBLK_UBC]),
239fd30401bSMagnus Damm 	CLKDEV_CON_ID("cmt_fck", &mstp_clks[HWBLK_CMT]),
2407fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("sh-wdt.0", &mstp_clks[HWBLK_RWDT]),
2417fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("sh-dma-engine.1", &mstp_clks[HWBLK_DMAC1]),
242fd30401bSMagnus Damm 	CLKDEV_CON_ID("flctl0", &mstp_clks[HWBLK_FLCTL]),
2437fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("spi_sh_msiof.0", &mstp_clks[HWBLK_MSIOF0]),
2447fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("spi_sh_msiof.1", &mstp_clks[HWBLK_MSIOF1]),
2457fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("sh_mobile_meram.0", &mstp_clks[HWBLK_MERAM]),
24616d9856aSKuninori Morimoto 	CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks[HWBLK_IIC]),
247fd30401bSMagnus Damm 	CLKDEV_CON_ID("rtc0", &mstp_clks[HWBLK_RTC]),
248fd30401bSMagnus Damm 	CLKDEV_CON_ID("atapi0", &mstp_clks[HWBLK_ATAPI]),
249fd30401bSMagnus Damm 	CLKDEV_CON_ID("adc0", &mstp_clks[HWBLK_ADC]),
250fd30401bSMagnus Damm 	CLKDEV_CON_ID("tpu0", &mstp_clks[HWBLK_TPU]),
251fd30401bSMagnus Damm 	CLKDEV_CON_ID("irda0", &mstp_clks[HWBLK_IRDA]),
252fd30401bSMagnus Damm 	CLKDEV_CON_ID("tsif0", &mstp_clks[HWBLK_TSIF]),
253fd30401bSMagnus Damm 	CLKDEV_CON_ID("icb0", &mstp_clks[HWBLK_ICB]),
2547fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[HWBLK_SDHI0]),
2557fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[HWBLK_SDHI1]),
2567fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("sh_keysc.0", &mstp_clks[HWBLK_KEYSC]),
257fd30401bSMagnus Damm 	CLKDEV_CON_ID("usb0", &mstp_clks[HWBLK_USB]),
258fd30401bSMagnus Damm 	CLKDEV_CON_ID("2dg0", &mstp_clks[HWBLK_2DG]),
2597fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("siu-pcm-audio", &mstp_clks[HWBLK_SIU]),
260fd30401bSMagnus Damm 	CLKDEV_CON_ID("veu1", &mstp_clks[HWBLK_VEU2H1]),
2617fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("sh-vou.0", &mstp_clks[HWBLK_VOU]),
262fd30401bSMagnus Damm 	CLKDEV_CON_ID("beu0", &mstp_clks[HWBLK_BEU]),
2637fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("sh_mobile_ceu.0", &mstp_clks[HWBLK_CEU]),
264fd30401bSMagnus Damm 	CLKDEV_CON_ID("veu0", &mstp_clks[HWBLK_VEU2H0]),
265fd30401bSMagnus Damm 	CLKDEV_CON_ID("vpu0", &mstp_clks[HWBLK_VPU]),
2667e28c7bbSKuninori Morimoto 
2677e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("tmu_fck", "sh_tmu.0", &mstp_clks[HWBLK_TMU0]),
2687e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("tmu_fck", "sh_tmu.1", &mstp_clks[HWBLK_TMU0]),
2697e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("tmu_fck", "sh_tmu.2", &mstp_clks[HWBLK_TMU0]),
2707e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("tmu_fck", "sh_tmu.3", &mstp_clks[HWBLK_TMU1]),
2717e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("tmu_fck", "sh_tmu.4", &mstp_clks[HWBLK_TMU1]),
2727e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("tmu_fck", "sh_tmu.5", &mstp_clks[HWBLK_TMU1]),
273*9f06cf38SPaul Mundt 
2747e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("sci_fck", "sh-sci.0", &mstp_clks[HWBLK_SCIF0]),
2757e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("sci_fck", "sh-sci.1", &mstp_clks[HWBLK_SCIF1]),
2767e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("sci_fck", "sh-sci.2", &mstp_clks[HWBLK_SCIF2]),
2777e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("sci_fck", "sh-sci.3", &mstp_clks[HWBLK_SCIF3]),
2787e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("sci_fck", "sh-sci.4", &mstp_clks[HWBLK_SCIF4]),
2797e28c7bbSKuninori Morimoto 	CLKDEV_ICK_ID("sci_fck", "sh-sci.5", &mstp_clks[HWBLK_SCIF5]),
280*9f06cf38SPaul Mundt 
2817fa4632dSGuennadi Liakhovetski 	CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks[HWBLK_LCDC]),
282f4221802SPaul Mundt };
283f4221802SPaul Mundt 
284c521dc02SMagnus Damm int __init arch_clk_init(void)
285c521dc02SMagnus Damm {
286c521dc02SMagnus Damm 	int k, ret = 0;
287c521dc02SMagnus Damm 
288c521dc02SMagnus Damm 	/* autodetect extal or dll configuration */
289c521dc02SMagnus Damm 	if (__raw_readl(PLLCR) & 0x1000)
290c521dc02SMagnus Damm 		pll_clk.parent = &dll_clk;
291c521dc02SMagnus Damm 	else
292c521dc02SMagnus Damm 		pll_clk.parent = &extal_clk;
293c521dc02SMagnus Damm 
294c521dc02SMagnus Damm 	for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
295f4221802SPaul Mundt 		ret |= clk_register(main_clks[k]);
296f4221802SPaul Mundt 
297f4221802SPaul Mundt 	clkdev_add_table(lookups, ARRAY_SIZE(lookups));
298c521dc02SMagnus Damm 
299c521dc02SMagnus Damm 	if (!ret)
300c521dc02SMagnus Damm 		ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
301c521dc02SMagnus Damm 
302c521dc02SMagnus Damm 	if (!ret)
303801cd56eSMagnus Damm 		ret = sh_clk_div4_enable_register(div4_enable_clks,
304801cd56eSMagnus Damm 					DIV4_ENABLE_NR, &div4_table);
305801cd56eSMagnus Damm 
306801cd56eSMagnus Damm 	if (!ret)
307801cd56eSMagnus Damm 		ret = sh_clk_div4_reparent_register(div4_reparent_clks,
308801cd56eSMagnus Damm 					DIV4_REPARENT_NR, &div4_table);
309801cd56eSMagnus Damm 
310801cd56eSMagnus Damm 	if (!ret)
311098ec49bSMagnus Damm 		ret = sh_clk_div6_register(div6_clks, DIV6_NR);
312c521dc02SMagnus Damm 
313c521dc02SMagnus Damm 	if (!ret)
3147fa4632dSGuennadi Liakhovetski 		ret = sh_clk_mstp32_register(mstp_clks, HWBLK_NR);
315c521dc02SMagnus Damm 
316c521dc02SMagnus Damm 	return ret;
317c521dc02SMagnus Damm }
318