1 // SPDX-License-Identifier: GPL-2.0
3 * arch/sh/kernel/cpu/sh4a/clock-sh7722.c
5 * SH7722 clock framework support
7 * Copyright (C) 2009 Magnus Damm
9 #include <linux/init.h>
10 #include <linux/kernel.h>
12 #include <linux/clkdev.h>
13 #include <linux/sh_clk.h>
14 #include <asm/clock.h>
15 #include <cpu/sh7722.h>
17 /* SH7722 registers */
18 #define FRQCR 0xa4150000
19 #define VCLKCR 0xa4150004
20 #define SCLKACR 0xa4150008
21 #define SCLKBCR 0xa415000c
22 #define IRDACLKCR 0xa4150018
23 #define PLLCR 0xa4150024
24 #define MSTPCR0 0xa4150030
25 #define MSTPCR1 0xa4150034
26 #define MSTPCR2 0xa4150038
27 #define DLLFRQ 0xa4150050
29 /* Fixed 32 KHz root clock for RTC and Power Management purposes */
30 static struct clk r_clk
= {
35 * Default rate for the root input clock, reset this with clk_set_rate()
36 * from the platform code.
38 struct clk extal_clk
= {
42 /* The dll block multiplies the 32khz r_clk, may be used instead of extal */
43 static unsigned long dll_recalc(struct clk
*clk
)
47 if (__raw_readl(PLLCR
) & 0x1000)
48 mult
= __raw_readl(DLLFRQ
);
52 return clk
->parent
->rate
* mult
;
55 static struct sh_clk_ops dll_clk_ops
= {
59 static struct clk dll_clk
= {
62 .flags
= CLK_ENABLE_ON_INIT
,
65 static unsigned long pll_recalc(struct clk
*clk
)
67 unsigned long mult
= 1;
68 unsigned long div
= 1;
70 if (__raw_readl(PLLCR
) & 0x4000)
71 mult
= (((__raw_readl(FRQCR
) >> 24) & 0x1f) + 1);
75 return (clk
->parent
->rate
* mult
) / div
;
78 static struct sh_clk_ops pll_clk_ops
= {
82 static struct clk pll_clk
= {
84 .flags
= CLK_ENABLE_ON_INIT
,
87 struct clk
*main_clks
[] = {
94 static int multipliers
[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
95 static int divisors
[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
97 static struct clk_div_mult_table div4_div_mult_table
= {
99 .nr_divisors
= ARRAY_SIZE(divisors
),
100 .multipliers
= multipliers
,
101 .nr_multipliers
= ARRAY_SIZE(multipliers
),
104 static struct clk_div4_table div4_table
= {
105 .div_mult_table
= &div4_div_mult_table
,
108 #define DIV4(_reg, _bit, _mask, _flags) \
109 SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)
111 enum { DIV4_I
, DIV4_U
, DIV4_SH
, DIV4_B
, DIV4_B3
, DIV4_P
, DIV4_NR
};
113 struct clk div4_clks
[DIV4_NR
] = {
114 [DIV4_I
] = DIV4(FRQCR
, 20, 0x1fef, CLK_ENABLE_ON_INIT
),
115 [DIV4_U
] = DIV4(FRQCR
, 16, 0x1fff, CLK_ENABLE_ON_INIT
),
116 [DIV4_SH
] = DIV4(FRQCR
, 12, 0x1fff, CLK_ENABLE_ON_INIT
),
117 [DIV4_B
] = DIV4(FRQCR
, 8, 0x1fff, CLK_ENABLE_ON_INIT
),
118 [DIV4_B3
] = DIV4(FRQCR
, 4, 0x1fff, CLK_ENABLE_ON_INIT
),
119 [DIV4_P
] = DIV4(FRQCR
, 0, 0x1fff, 0),
122 enum { DIV4_IRDA
, DIV4_ENABLE_NR
};
124 struct clk div4_enable_clks
[DIV4_ENABLE_NR
] = {
125 [DIV4_IRDA
] = DIV4(IRDACLKCR
, 0, 0x1fff, 0),
128 enum { DIV4_SIUA
, DIV4_SIUB
, DIV4_REPARENT_NR
};
130 struct clk div4_reparent_clks
[DIV4_REPARENT_NR
] = {
131 [DIV4_SIUA
] = DIV4(SCLKACR
, 0, 0x1fff, 0),
132 [DIV4_SIUB
] = DIV4(SCLKBCR
, 0, 0x1fff, 0),
135 enum { DIV6_V
, DIV6_NR
};
137 struct clk div6_clks
[DIV6_NR
] = {
138 [DIV6_V
] = SH_CLK_DIV6(&pll_clk
, VCLKCR
, 0),
141 static struct clk mstp_clks
[HWBLK_NR
] = {
142 [HWBLK_URAM
] = SH_CLK_MSTP32(&div4_clks
[DIV4_U
], MSTPCR0
, 28, CLK_ENABLE_ON_INIT
),
143 [HWBLK_XYMEM
] = SH_CLK_MSTP32(&div4_clks
[DIV4_B
], MSTPCR0
, 26, CLK_ENABLE_ON_INIT
),
144 [HWBLK_TMU
] = SH_CLK_MSTP32(&div4_clks
[DIV4_P
], MSTPCR0
, 15, 0),
145 [HWBLK_CMT
] = SH_CLK_MSTP32(&r_clk
, MSTPCR0
, 14, 0),
146 [HWBLK_RWDT
] = SH_CLK_MSTP32(&r_clk
, MSTPCR0
, 13, 0),
147 [HWBLK_FLCTL
] = SH_CLK_MSTP32(&div4_clks
[DIV4_P
], MSTPCR0
, 10, 0),
148 [HWBLK_SCIF0
] = SH_CLK_MSTP32(&div4_clks
[DIV4_P
], MSTPCR0
, 7, 0),
149 [HWBLK_SCIF1
] = SH_CLK_MSTP32(&div4_clks
[DIV4_P
], MSTPCR0
, 6, 0),
150 [HWBLK_SCIF2
] = SH_CLK_MSTP32(&div4_clks
[DIV4_P
], MSTPCR0
, 5, 0),
152 [HWBLK_IIC
] = SH_CLK_MSTP32(&div4_clks
[DIV4_P
], MSTPCR1
, 9, 0),
153 [HWBLK_RTC
] = SH_CLK_MSTP32(&r_clk
, MSTPCR1
, 8, 0),
155 [HWBLK_SDHI
] = SH_CLK_MSTP32(&div4_clks
[DIV4_P
], MSTPCR2
, 18, 0),
156 [HWBLK_KEYSC
] = SH_CLK_MSTP32(&r_clk
, MSTPCR2
, 14, 0),
157 [HWBLK_USBF
] = SH_CLK_MSTP32(&div4_clks
[DIV4_P
], MSTPCR2
, 11, 0),
158 [HWBLK_2DG
] = SH_CLK_MSTP32(&div4_clks
[DIV4_B
], MSTPCR2
, 9, 0),
159 [HWBLK_SIU
] = SH_CLK_MSTP32(&div4_clks
[DIV4_B
], MSTPCR2
, 8, 0),
160 [HWBLK_JPU
] = SH_CLK_MSTP32(&div4_clks
[DIV4_B
], MSTPCR2
, 6, 0),
161 [HWBLK_VOU
] = SH_CLK_MSTP32(&div4_clks
[DIV4_B
], MSTPCR2
, 5, 0),
162 [HWBLK_BEU
] = SH_CLK_MSTP32(&div4_clks
[DIV4_B
], MSTPCR2
, 4, 0),
163 [HWBLK_CEU
] = SH_CLK_MSTP32(&div4_clks
[DIV4_B
], MSTPCR2
, 3, 0),
164 [HWBLK_VEU
] = SH_CLK_MSTP32(&div4_clks
[DIV4_B
], MSTPCR2
, 2, 0),
165 [HWBLK_VPU
] = SH_CLK_MSTP32(&div4_clks
[DIV4_B
], MSTPCR2
, 1, 0),
166 [HWBLK_LCDC
] = SH_CLK_MSTP32(&div4_clks
[DIV4_P
], MSTPCR2
, 0, 0),
169 static struct clk_lookup lookups
[] = {
171 CLKDEV_CON_ID("rclk", &r_clk
),
172 CLKDEV_CON_ID("extal", &extal_clk
),
173 CLKDEV_CON_ID("dll_clk", &dll_clk
),
174 CLKDEV_CON_ID("pll_clk", &pll_clk
),
177 CLKDEV_CON_ID("cpu_clk", &div4_clks
[DIV4_I
]),
178 CLKDEV_CON_ID("umem_clk", &div4_clks
[DIV4_U
]),
179 CLKDEV_CON_ID("shyway_clk", &div4_clks
[DIV4_SH
]),
180 CLKDEV_CON_ID("bus_clk", &div4_clks
[DIV4_B
]),
181 CLKDEV_CON_ID("b3_clk", &div4_clks
[DIV4_B3
]),
182 CLKDEV_CON_ID("peripheral_clk", &div4_clks
[DIV4_P
]),
183 CLKDEV_CON_ID("irda_clk", &div4_enable_clks
[DIV4_IRDA
]),
184 CLKDEV_CON_ID("siua_clk", &div4_reparent_clks
[DIV4_SIUA
]),
185 CLKDEV_CON_ID("siub_clk", &div4_reparent_clks
[DIV4_SIUB
]),
188 CLKDEV_CON_ID("video_clk", &div6_clks
[DIV6_V
]),
191 CLKDEV_CON_ID("uram0", &mstp_clks
[HWBLK_URAM
]),
192 CLKDEV_CON_ID("xymem0", &mstp_clks
[HWBLK_XYMEM
]),
194 CLKDEV_ICK_ID("fck", "sh-tmu.0", &mstp_clks
[HWBLK_TMU
]),
196 CLKDEV_ICK_ID("fck", "sh-cmt-32.0", &mstp_clks
[HWBLK_CMT
]),
197 CLKDEV_DEV_ID("sh-wdt.0", &mstp_clks
[HWBLK_RWDT
]),
198 CLKDEV_CON_ID("flctl0", &mstp_clks
[HWBLK_FLCTL
]),
200 CLKDEV_DEV_ID("sh-sci.0", &mstp_clks
[HWBLK_SCIF0
]),
201 CLKDEV_DEV_ID("sh-sci.1", &mstp_clks
[HWBLK_SCIF1
]),
202 CLKDEV_DEV_ID("sh-sci.2", &mstp_clks
[HWBLK_SCIF2
]),
204 CLKDEV_DEV_ID("i2c-sh_mobile.0", &mstp_clks
[HWBLK_IIC
]),
205 CLKDEV_CON_ID("rtc0", &mstp_clks
[HWBLK_RTC
]),
206 CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks
[HWBLK_SDHI
]),
207 CLKDEV_DEV_ID("sh_keysc.0", &mstp_clks
[HWBLK_KEYSC
]),
208 CLKDEV_CON_ID("usbf0", &mstp_clks
[HWBLK_USBF
]),
209 CLKDEV_CON_ID("2dg0", &mstp_clks
[HWBLK_2DG
]),
210 CLKDEV_DEV_ID("siu-pcm-audio", &mstp_clks
[HWBLK_SIU
]),
211 CLKDEV_DEV_ID("sh-vou.0", &mstp_clks
[HWBLK_VOU
]),
212 CLKDEV_CON_ID("jpu0", &mstp_clks
[HWBLK_JPU
]),
213 CLKDEV_CON_ID("beu0", &mstp_clks
[HWBLK_BEU
]),
214 CLKDEV_DEV_ID("renesas-ceu.0", &mstp_clks
[HWBLK_CEU
]),
215 CLKDEV_CON_ID("veu0", &mstp_clks
[HWBLK_VEU
]),
216 CLKDEV_CON_ID("vpu0", &mstp_clks
[HWBLK_VPU
]),
217 CLKDEV_DEV_ID("sh_mobile_lcdc_fb.0", &mstp_clks
[HWBLK_LCDC
]),
220 int __init
arch_clk_init(void)
224 /* autodetect extal or dll configuration */
225 if (__raw_readl(PLLCR
) & 0x1000)
226 pll_clk
.parent
= &dll_clk
;
228 pll_clk
.parent
= &extal_clk
;
230 for (k
= 0; !ret
&& (k
< ARRAY_SIZE(main_clks
)); k
++)
231 ret
= clk_register(main_clks
[k
]);
233 clkdev_add_table(lookups
, ARRAY_SIZE(lookups
));
236 ret
= sh_clk_div4_register(div4_clks
, DIV4_NR
, &div4_table
);
239 ret
= sh_clk_div4_enable_register(div4_enable_clks
,
240 DIV4_ENABLE_NR
, &div4_table
);
243 ret
= sh_clk_div4_reparent_register(div4_reparent_clks
,
244 DIV4_REPARENT_NR
, &div4_table
);
247 ret
= sh_clk_div6_register(div6_clks
, DIV6_NR
);
250 ret
= sh_clk_mstp_register(mstp_clks
, HWBLK_NR
);