1 // SPDX-License-Identifier: GPL-2.0
3 * Ingenic JZ4725B SoC CGU driver
5 * Copyright (C) 2018 Paul Cercueil
6 * Author: Paul Cercueil <paul@crapouillou.net>
9 #include <linux/clk-provider.h>
10 #include <linux/delay.h>
12 #include <dt-bindings/clock/jz4725b-cgu.h>
16 /* CGU register offsets */
17 #define CGU_REG_CPCCR 0x00
18 #define CGU_REG_LCR 0x04
19 #define CGU_REG_CPPCR 0x10
20 #define CGU_REG_CLKGR 0x20
21 #define CGU_REG_OPCR 0x24
22 #define CGU_REG_I2SCDR 0x60
23 #define CGU_REG_LPCDR 0x64
24 #define CGU_REG_MSCCDR 0x68
25 #define CGU_REG_SSICDR 0x74
26 #define CGU_REG_CIMCDR 0x78
28 /* bits within the LCR register */
29 #define LCR_SLEEP BIT(0)
31 static struct ingenic_cgu
*cgu
;
33 static const s8 pll_od_encoding
[4] = {
37 static const u8 jz4725b_cgu_cpccr_div_table
[] = {
41 static const u8 jz4725b_cgu_pll_half_div_table
[] = {
45 static const struct ingenic_cgu_clk_info jz4725b_cgu_clocks
[] = {
49 [JZ4725B_CLK_EXT
] = { "ext", CGU_CLK_EXT
},
50 [JZ4725B_CLK_OSC32K
] = { "osc32k", CGU_CLK_EXT
},
54 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
66 .od_encoding
= pll_od_encoding
,
73 /* Muxes & dividers */
75 [JZ4725B_CLK_PLL_HALF
] = {
76 "pll half", CGU_CLK_DIV
,
77 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
79 CGU_REG_CPCCR
, 21, 1, 1, -1, -1, -1,
80 jz4725b_cgu_pll_half_div_table
,
84 [JZ4725B_CLK_CCLK
] = {
86 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
88 CGU_REG_CPCCR
, 0, 1, 4, 22, -1, -1,
89 jz4725b_cgu_cpccr_div_table
,
93 [JZ4725B_CLK_HCLK
] = {
95 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
97 CGU_REG_CPCCR
, 4, 1, 4, 22, -1, -1,
98 jz4725b_cgu_cpccr_div_table
,
102 [JZ4725B_CLK_PCLK
] = {
104 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
106 CGU_REG_CPCCR
, 8, 1, 4, 22, -1, -1,
107 jz4725b_cgu_cpccr_div_table
,
111 [JZ4725B_CLK_MCLK
] = {
113 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
115 CGU_REG_CPCCR
, 12, 1, 4, 22, -1, -1,
116 jz4725b_cgu_cpccr_div_table
,
120 [JZ4725B_CLK_IPU
] = {
121 "ipu", CGU_CLK_DIV
| CGU_CLK_GATE
,
122 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
124 CGU_REG_CPCCR
, 16, 1, 4, 22, -1, -1,
125 jz4725b_cgu_cpccr_div_table
,
127 .gate
= { CGU_REG_CLKGR
, 13 },
130 [JZ4725B_CLK_LCD
] = {
131 "lcd", CGU_CLK_DIV
| CGU_CLK_GATE
,
132 .parents
= { JZ4725B_CLK_PLL_HALF
, -1, -1, -1 },
133 .div
= { CGU_REG_LPCDR
, 0, 1, 11, -1, -1, -1 },
134 .gate
= { CGU_REG_CLKGR
, 9 },
137 [JZ4725B_CLK_I2S
] = {
138 "i2s", CGU_CLK_MUX
| CGU_CLK_DIV
| CGU_CLK_GATE
,
139 .parents
= { JZ4725B_CLK_EXT
, JZ4725B_CLK_PLL_HALF
, -1, -1 },
140 .mux
= { CGU_REG_CPCCR
, 31, 1 },
141 .div
= { CGU_REG_I2SCDR
, 0, 1, 9, -1, -1, -1 },
142 .gate
= { CGU_REG_CLKGR
, 6 },
145 [JZ4725B_CLK_SPI
] = {
146 "spi", CGU_CLK_MUX
| CGU_CLK_DIV
| CGU_CLK_GATE
,
147 .parents
= { JZ4725B_CLK_EXT
, JZ4725B_CLK_PLL
, -1, -1 },
148 .mux
= { CGU_REG_SSICDR
, 31, 1 },
149 .div
= { CGU_REG_SSICDR
, 0, 1, 4, -1, -1, -1 },
150 .gate
= { CGU_REG_CLKGR
, 4 },
153 [JZ4725B_CLK_MMC_MUX
] = {
154 "mmc_mux", CGU_CLK_DIV
,
155 .parents
= { JZ4725B_CLK_PLL_HALF
, -1, -1, -1 },
156 .div
= { CGU_REG_MSCCDR
, 0, 1, 5, -1, -1, -1 },
159 [JZ4725B_CLK_UDC
] = {
160 "udc", CGU_CLK_MUX
| CGU_CLK_DIV
,
161 .parents
= { JZ4725B_CLK_EXT
, JZ4725B_CLK_PLL_HALF
, -1, -1 },
162 .mux
= { CGU_REG_CPCCR
, 29, 1 },
163 .div
= { CGU_REG_CPCCR
, 23, 1, 6, -1, -1, -1 },
166 /* Gate-only clocks */
168 [JZ4725B_CLK_UART
] = {
169 "uart", CGU_CLK_GATE
,
170 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
171 .gate
= { CGU_REG_CLKGR
, 0 },
174 [JZ4725B_CLK_DMA
] = {
176 .parents
= { JZ4725B_CLK_PCLK
, -1, -1, -1 },
177 .gate
= { CGU_REG_CLKGR
, 12 },
180 [JZ4725B_CLK_ADC
] = {
182 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
183 .gate
= { CGU_REG_CLKGR
, 7 },
186 [JZ4725B_CLK_I2C
] = {
188 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
189 .gate
= { CGU_REG_CLKGR
, 3 },
192 [JZ4725B_CLK_AIC
] = {
194 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
195 .gate
= { CGU_REG_CLKGR
, 5 },
198 [JZ4725B_CLK_MMC0
] = {
199 "mmc0", CGU_CLK_GATE
,
200 .parents
= { JZ4725B_CLK_MMC_MUX
, -1, -1, -1 },
201 .gate
= { CGU_REG_CLKGR
, 6 },
204 [JZ4725B_CLK_MMC1
] = {
205 "mmc1", CGU_CLK_GATE
,
206 .parents
= { JZ4725B_CLK_MMC_MUX
, -1, -1, -1 },
207 .gate
= { CGU_REG_CLKGR
, 16 },
210 [JZ4725B_CLK_BCH
] = {
212 .parents
= { JZ4725B_CLK_MCLK
/* not sure */, -1, -1, -1 },
213 .gate
= { CGU_REG_CLKGR
, 11 },
216 [JZ4725B_CLK_TCU
] = {
218 .parents
= { JZ4725B_CLK_EXT
/* not sure */, -1, -1, -1 },
219 .gate
= { CGU_REG_CLKGR
, 1 },
222 [JZ4725B_CLK_EXT512
] = {
223 "ext/512", CGU_CLK_FIXDIV
,
224 .parents
= { JZ4725B_CLK_EXT
},
226 /* Doc calls it EXT512, but it seems to be /256... */
230 [JZ4725B_CLK_RTC
] = {
232 .parents
= { JZ4725B_CLK_EXT512
, JZ4725B_CLK_OSC32K
, -1, -1 },
233 .mux
= { CGU_REG_OPCR
, 2, 1},
236 [JZ4725B_CLK_UDC_PHY
] = {
237 "udc_phy", CGU_CLK_GATE
,
238 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
239 .gate
= { CGU_REG_OPCR
, 6, true },
243 static void __init
jz4725b_cgu_init(struct device_node
*np
)
247 cgu
= ingenic_cgu_new(jz4725b_cgu_clocks
,
248 ARRAY_SIZE(jz4725b_cgu_clocks
), np
);
250 pr_err("%s: failed to initialise CGU\n", __func__
);
254 retval
= ingenic_cgu_register_clocks(cgu
);
256 pr_err("%s: failed to register CGU Clocks\n", __func__
);
258 ingenic_cgu_register_syscore_ops(cgu
);
260 CLK_OF_DECLARE_DRIVER(jz4725b_cgu
, "ingenic,jz4725b-cgu", jz4725b_cgu_init
);