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>
13 #include <dt-bindings/clock/ingenic,jz4725b-cgu.h>
18 /* CGU register offsets */
19 #define CGU_REG_CPCCR 0x00
20 #define CGU_REG_LCR 0x04
21 #define CGU_REG_CPPCR 0x10
22 #define CGU_REG_CLKGR 0x20
23 #define CGU_REG_OPCR 0x24
24 #define CGU_REG_I2SCDR 0x60
25 #define CGU_REG_LPCDR 0x64
26 #define CGU_REG_MSCCDR 0x68
27 #define CGU_REG_SSICDR 0x74
28 #define CGU_REG_CIMCDR 0x78
30 /* bits within the LCR register */
31 #define LCR_SLEEP BIT(0)
33 static struct ingenic_cgu
*cgu
;
35 static const s8 pll_od_encoding
[4] = {
39 static const u8 jz4725b_cgu_cpccr_div_table
[] = {
43 static const u8 jz4725b_cgu_pll_half_div_table
[] = {
47 static const struct ingenic_cgu_clk_info jz4725b_cgu_clocks
[] = {
51 [JZ4725B_CLK_EXT
] = { "ext", CGU_CLK_EXT
},
52 [JZ4725B_CLK_OSC32K
] = { "osc32k", CGU_CLK_EXT
},
56 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
69 .od_encoding
= pll_od_encoding
,
71 .bypass_reg
= CGU_REG_CPPCR
,
77 /* Muxes & dividers */
79 [JZ4725B_CLK_PLL_HALF
] = {
80 "pll half", CGU_CLK_DIV
,
81 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
83 CGU_REG_CPCCR
, 21, 1, 1, -1, -1, -1, 0,
84 jz4725b_cgu_pll_half_div_table
,
88 [JZ4725B_CLK_CCLK
] = {
91 * Disabling the CPU clock or any parent clocks will hang the
92 * system; mark it critical.
94 .flags
= CLK_IS_CRITICAL
,
95 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
97 CGU_REG_CPCCR
, 0, 1, 4, 22, -1, -1, 0,
98 jz4725b_cgu_cpccr_div_table
,
102 [JZ4725B_CLK_HCLK
] = {
104 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
106 CGU_REG_CPCCR
, 4, 1, 4, 22, -1, -1, 0,
107 jz4725b_cgu_cpccr_div_table
,
111 [JZ4725B_CLK_PCLK
] = {
113 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
115 CGU_REG_CPCCR
, 8, 1, 4, 22, -1, -1, 0,
116 jz4725b_cgu_cpccr_div_table
,
120 [JZ4725B_CLK_MCLK
] = {
123 * Disabling MCLK or its parents will render DRAM
124 * inaccessible; mark it critical.
126 .flags
= CLK_IS_CRITICAL
,
127 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
129 CGU_REG_CPCCR
, 12, 1, 4, 22, -1, -1, 0,
130 jz4725b_cgu_cpccr_div_table
,
134 [JZ4725B_CLK_IPU
] = {
135 "ipu", CGU_CLK_DIV
| CGU_CLK_GATE
,
136 .parents
= { JZ4725B_CLK_PLL
, -1, -1, -1 },
138 CGU_REG_CPCCR
, 16, 1, 4, 22, -1, -1, 0,
139 jz4725b_cgu_cpccr_div_table
,
141 .gate
= { CGU_REG_CLKGR
, 13 },
144 [JZ4725B_CLK_LCD
] = {
145 "lcd", CGU_CLK_DIV
| CGU_CLK_GATE
,
146 .parents
= { JZ4725B_CLK_PLL_HALF
, -1, -1, -1 },
147 .div
= { CGU_REG_LPCDR
, 0, 1, 11, -1, -1, -1 },
148 .gate
= { CGU_REG_CLKGR
, 9 },
151 [JZ4725B_CLK_I2S
] = {
152 "i2s", CGU_CLK_MUX
| CGU_CLK_DIV
,
153 .parents
= { JZ4725B_CLK_EXT
, JZ4725B_CLK_PLL_HALF
, -1, -1 },
154 .mux
= { CGU_REG_CPCCR
, 31, 1 },
155 .div
= { CGU_REG_I2SCDR
, 0, 1, 9, -1, -1, -1 },
158 [JZ4725B_CLK_SPI
] = {
159 "spi", CGU_CLK_MUX
| CGU_CLK_DIV
| CGU_CLK_GATE
,
160 .parents
= { JZ4725B_CLK_EXT
, JZ4725B_CLK_PLL
, -1, -1 },
161 .mux
= { CGU_REG_SSICDR
, 31, 1 },
162 .div
= { CGU_REG_SSICDR
, 0, 1, 4, -1, -1, -1 },
163 .gate
= { CGU_REG_CLKGR
, 4 },
166 [JZ4725B_CLK_MMC_MUX
] = {
167 "mmc_mux", CGU_CLK_DIV
,
168 .parents
= { JZ4725B_CLK_PLL_HALF
, -1, -1, -1 },
169 .div
= { CGU_REG_MSCCDR
, 0, 1, 5, -1, -1, -1 },
172 [JZ4725B_CLK_UDC
] = {
173 "udc", CGU_CLK_MUX
| CGU_CLK_DIV
,
174 .parents
= { JZ4725B_CLK_EXT
, JZ4725B_CLK_PLL_HALF
, -1, -1 },
175 .mux
= { CGU_REG_CPCCR
, 29, 1 },
176 .div
= { CGU_REG_CPCCR
, 23, 1, 6, -1, -1, -1 },
179 /* Gate-only clocks */
181 [JZ4725B_CLK_UART
] = {
182 "uart", CGU_CLK_GATE
,
183 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
184 .gate
= { CGU_REG_CLKGR
, 0 },
187 [JZ4725B_CLK_DMA
] = {
189 .parents
= { JZ4725B_CLK_PCLK
, -1, -1, -1 },
190 .gate
= { CGU_REG_CLKGR
, 12 },
193 [JZ4725B_CLK_ADC
] = {
195 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
196 .gate
= { CGU_REG_CLKGR
, 7 },
199 [JZ4725B_CLK_I2C
] = {
201 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
202 .gate
= { CGU_REG_CLKGR
, 3 },
205 [JZ4725B_CLK_AIC
] = {
207 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
208 .gate
= { CGU_REG_CLKGR
, 5 },
211 [JZ4725B_CLK_MMC0
] = {
212 "mmc0", CGU_CLK_GATE
,
213 .parents
= { JZ4725B_CLK_MMC_MUX
, -1, -1, -1 },
214 .gate
= { CGU_REG_CLKGR
, 6 },
217 [JZ4725B_CLK_MMC1
] = {
218 "mmc1", CGU_CLK_GATE
,
219 .parents
= { JZ4725B_CLK_MMC_MUX
, -1, -1, -1 },
220 .gate
= { CGU_REG_CLKGR
, 16 },
223 [JZ4725B_CLK_BCH
] = {
225 .parents
= { JZ4725B_CLK_MCLK
/* not sure */, -1, -1, -1 },
226 .gate
= { CGU_REG_CLKGR
, 11 },
229 [JZ4725B_CLK_TCU
] = {
231 .parents
= { JZ4725B_CLK_EXT
/* not sure */, -1, -1, -1 },
232 .gate
= { CGU_REG_CLKGR
, 1 },
235 [JZ4725B_CLK_EXT512
] = {
236 "ext/512", CGU_CLK_FIXDIV
,
237 .parents
= { JZ4725B_CLK_EXT
},
239 /* Doc calls it EXT512, but it seems to be /256... */
243 [JZ4725B_CLK_RTC
] = {
245 .parents
= { JZ4725B_CLK_EXT512
, JZ4725B_CLK_OSC32K
, -1, -1 },
246 .mux
= { CGU_REG_OPCR
, 2, 1},
249 [JZ4725B_CLK_UDC_PHY
] = {
250 "udc_phy", CGU_CLK_GATE
,
251 .parents
= { JZ4725B_CLK_EXT
, -1, -1, -1 },
252 .gate
= { CGU_REG_OPCR
, 6, true },
256 static void __init
jz4725b_cgu_init(struct device_node
*np
)
260 cgu
= ingenic_cgu_new(jz4725b_cgu_clocks
,
261 ARRAY_SIZE(jz4725b_cgu_clocks
), np
);
263 pr_err("%s: failed to initialise CGU\n", __func__
);
267 retval
= ingenic_cgu_register_clocks(cgu
);
269 pr_err("%s: failed to register CGU Clocks\n", __func__
);
271 ingenic_cgu_register_syscore_ops(cgu
);
273 CLK_OF_DECLARE_DRIVER(jz4725b_cgu
, "ingenic,jz4725b-cgu", jz4725b_cgu_init
);