1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (c) 2014 MundoReader S.L.
4 * Author: Heiko Stuebner <heiko@sntech.de>
6 * Copyright (c) 2015 Rockchip Electronics Co. Ltd.
7 * Author: Xing Zheng <zhengxing@rock-chips.com>
12 * Copyright (c) 2013 Samsung Electronics Co., Ltd.
13 * Copyright (c) 2013 Linaro Ltd.
14 * Author: Thomas Abraham <thomas.ab@samsung.com>
17 #ifndef CLK_ROCKCHIP_CLK_H
18 #define CLK_ROCKCHIP_CLK_H
21 #include <linux/clk-provider.h>
25 #define HIWORD_UPDATE(val, mask, shift) \
26 ((val) << (shift) | (mask) << ((shift) + 16))
28 /* register positions shared by PX30, RV1108, RK2928, RK3036, RK3066, RK3188 and RK3228 */
29 #define BOOST_PLL_H_CON(x) ((x) * 0x4)
30 #define BOOST_CLK_CON 0x0008
31 #define BOOST_BOOST_CON 0x000c
32 #define BOOST_SWITCH_CNT 0x0010
33 #define BOOST_HIGH_PERF_CNT0 0x0014
34 #define BOOST_HIGH_PERF_CNT1 0x0018
35 #define BOOST_STATIS_THRESHOLD 0x001c
36 #define BOOST_SHORT_SWITCH_CNT 0x0020
37 #define BOOST_SWITCH_THRESHOLD 0x0024
38 #define BOOST_FSM_STATUS 0x0028
39 #define BOOST_PLL_L_CON(x) ((x) * 0x4 + 0x2c)
40 #define BOOST_RECOVERY_MASK 0x1
41 #define BOOST_RECOVERY_SHIFT 1
42 #define BOOST_SW_CTRL_MASK 0x1
43 #define BOOST_SW_CTRL_SHIFT 2
44 #define BOOST_LOW_FREQ_EN_MASK 0x1
45 #define BOOST_LOW_FREQ_EN_SHIFT 3
46 #define BOOST_BUSY_STATE BIT(8)
48 #define PX30_PLL_CON(x) ((x) * 0x4)
49 #define PX30_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
50 #define PX30_CLKGATE_CON(x) ((x) * 0x4 + 0x200)
51 #define PX30_GLB_SRST_FST 0xb8
52 #define PX30_GLB_SRST_SND 0xbc
53 #define PX30_SOFTRST_CON(x) ((x) * 0x4 + 0x300)
54 #define PX30_MODE_CON 0xa0
55 #define PX30_MISC_CON 0xa4
56 #define PX30_SDMMC_CON0 0x380
57 #define PX30_SDMMC_CON1 0x384
58 #define PX30_SDIO_CON0 0x388
59 #define PX30_SDIO_CON1 0x38c
60 #define PX30_EMMC_CON0 0x390
61 #define PX30_EMMC_CON1 0x394
63 #define PX30_PMU_PLL_CON(x) ((x) * 0x4)
64 #define PX30_PMU_CLKSEL_CON(x) ((x) * 0x4 + 0x40)
65 #define PX30_PMU_CLKGATE_CON(x) ((x) * 0x4 + 0x80)
66 #define PX30_PMU_MODE 0x0020
68 #define RV1108_PLL_CON(x) ((x) * 0x4)
69 #define RV1108_CLKSEL_CON(x) ((x) * 0x4 + 0x60)
70 #define RV1108_CLKGATE_CON(x) ((x) * 0x4 + 0x120)
71 #define RV1108_SOFTRST_CON(x) ((x) * 0x4 + 0x180)
72 #define RV1108_GLB_SRST_FST 0x1c0
73 #define RV1108_GLB_SRST_SND 0x1c4
74 #define RV1108_MISC_CON 0x1cc
75 #define RV1108_SDMMC_CON0 0x1d8
76 #define RV1108_SDMMC_CON1 0x1dc
77 #define RV1108_SDIO_CON0 0x1e0
78 #define RV1108_SDIO_CON1 0x1e4
79 #define RV1108_EMMC_CON0 0x1e8
80 #define RV1108_EMMC_CON1 0x1ec
82 #define RV1126_PMU_MODE 0x0
83 #define RV1126_PMU_PLL_CON(x) ((x) * 0x4 + 0x10)
84 #define RV1126_PMU_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
85 #define RV1126_PMU_CLKGATE_CON(x) ((x) * 0x4 + 0x180)
86 #define RV1126_PMU_SOFTRST_CON(x) ((x) * 0x4 + 0x200)
87 #define RV1126_PLL_CON(x) ((x) * 0x4)
88 #define RV1126_MODE_CON 0x90
89 #define RV1126_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
90 #define RV1126_CLKGATE_CON(x) ((x) * 0x4 + 0x280)
91 #define RV1126_SOFTRST_CON(x) ((x) * 0x4 + 0x300)
92 #define RV1126_GLB_SRST_FST 0x408
93 #define RV1126_GLB_SRST_SND 0x40c
94 #define RV1126_SDMMC_CON0 0x440
95 #define RV1126_SDMMC_CON1 0x444
96 #define RV1126_SDIO_CON0 0x448
97 #define RV1126_SDIO_CON1 0x44c
98 #define RV1126_EMMC_CON0 0x450
99 #define RV1126_EMMC_CON1 0x454
101 #define RK2928_PLL_CON(x) ((x) * 0x4)
102 #define RK2928_MODE_CON 0x40
103 #define RK2928_CLKSEL_CON(x) ((x) * 0x4 + 0x44)
104 #define RK2928_CLKGATE_CON(x) ((x) * 0x4 + 0xd0)
105 #define RK2928_GLB_SRST_FST 0x100
106 #define RK2928_GLB_SRST_SND 0x104
107 #define RK2928_SOFTRST_CON(x) ((x) * 0x4 + 0x110)
108 #define RK2928_MISC_CON 0x134
110 #define RK3036_SDMMC_CON0 0x144
111 #define RK3036_SDMMC_CON1 0x148
112 #define RK3036_SDIO_CON0 0x14c
113 #define RK3036_SDIO_CON1 0x150
114 #define RK3036_EMMC_CON0 0x154
115 #define RK3036_EMMC_CON1 0x158
117 #define RK3228_GLB_SRST_FST 0x1f0
118 #define RK3228_GLB_SRST_SND 0x1f4
119 #define RK3228_SDMMC_CON0 0x1c0
120 #define RK3228_SDMMC_CON1 0x1c4
121 #define RK3228_SDIO_CON0 0x1c8
122 #define RK3228_SDIO_CON1 0x1cc
123 #define RK3228_EMMC_CON0 0x1d8
124 #define RK3228_EMMC_CON1 0x1dc
126 #define RK3288_PLL_CON(x) RK2928_PLL_CON(x)
127 #define RK3288_MODE_CON 0x50
128 #define RK3288_CLKSEL_CON(x) ((x) * 0x4 + 0x60)
129 #define RK3288_CLKGATE_CON(x) ((x) * 0x4 + 0x160)
130 #define RK3288_GLB_SRST_FST 0x1b0
131 #define RK3288_GLB_SRST_SND 0x1b4
132 #define RK3288_SOFTRST_CON(x) ((x) * 0x4 + 0x1b8)
133 #define RK3288_MISC_CON 0x1e8
134 #define RK3288_SDMMC_CON0 0x200
135 #define RK3288_SDMMC_CON1 0x204
136 #define RK3288_SDIO0_CON0 0x208
137 #define RK3288_SDIO0_CON1 0x20c
138 #define RK3288_SDIO1_CON0 0x210
139 #define RK3288_SDIO1_CON1 0x214
140 #define RK3288_EMMC_CON0 0x218
141 #define RK3288_EMMC_CON1 0x21c
143 #define RK3308_PLL_CON(x) RK2928_PLL_CON(x)
144 #define RK3308_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
145 #define RK3308_CLKGATE_CON(x) ((x) * 0x4 + 0x300)
146 #define RK3308_GLB_SRST_FST 0xb8
147 #define RK3308_SOFTRST_CON(x) ((x) * 0x4 + 0x400)
148 #define RK3308_MODE_CON 0xa0
149 #define RK3308_SDMMC_CON0 0x480
150 #define RK3308_SDMMC_CON1 0x484
151 #define RK3308_SDIO_CON0 0x488
152 #define RK3308_SDIO_CON1 0x48c
153 #define RK3308_EMMC_CON0 0x490
154 #define RK3308_EMMC_CON1 0x494
156 #define RK3328_PLL_CON(x) RK2928_PLL_CON(x)
157 #define RK3328_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
158 #define RK3328_CLKGATE_CON(x) ((x) * 0x4 + 0x200)
159 #define RK3328_GRFCLKSEL_CON(x) ((x) * 0x4 + 0x100)
160 #define RK3328_GLB_SRST_FST 0x9c
161 #define RK3328_GLB_SRST_SND 0x98
162 #define RK3328_SOFTRST_CON(x) ((x) * 0x4 + 0x300)
163 #define RK3328_MODE_CON 0x80
164 #define RK3328_MISC_CON 0x84
165 #define RK3328_SDMMC_CON0 0x380
166 #define RK3328_SDMMC_CON1 0x384
167 #define RK3328_SDIO_CON0 0x388
168 #define RK3328_SDIO_CON1 0x38c
169 #define RK3328_EMMC_CON0 0x390
170 #define RK3328_EMMC_CON1 0x394
171 #define RK3328_SDMMC_EXT_CON0 0x398
172 #define RK3328_SDMMC_EXT_CON1 0x39C
174 #define RK3368_PLL_CON(x) RK2928_PLL_CON(x)
175 #define RK3368_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
176 #define RK3368_CLKGATE_CON(x) ((x) * 0x4 + 0x200)
177 #define RK3368_GLB_SRST_FST 0x280
178 #define RK3368_GLB_SRST_SND 0x284
179 #define RK3368_SOFTRST_CON(x) ((x) * 0x4 + 0x300)
180 #define RK3368_MISC_CON 0x380
181 #define RK3368_SDMMC_CON0 0x400
182 #define RK3368_SDMMC_CON1 0x404
183 #define RK3368_SDIO0_CON0 0x408
184 #define RK3368_SDIO0_CON1 0x40c
185 #define RK3368_SDIO1_CON0 0x410
186 #define RK3368_SDIO1_CON1 0x414
187 #define RK3368_EMMC_CON0 0x418
188 #define RK3368_EMMC_CON1 0x41c
190 #define RK3399_PLL_CON(x) RK2928_PLL_CON(x)
191 #define RK3399_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
192 #define RK3399_CLKGATE_CON(x) ((x) * 0x4 + 0x300)
193 #define RK3399_SOFTRST_CON(x) ((x) * 0x4 + 0x400)
194 #define RK3399_GLB_SRST_FST 0x500
195 #define RK3399_GLB_SRST_SND 0x504
196 #define RK3399_GLB_CNT_TH 0x508
197 #define RK3399_MISC_CON 0x50c
198 #define RK3399_RST_CON 0x510
199 #define RK3399_RST_ST 0x514
200 #define RK3399_SDMMC_CON0 0x580
201 #define RK3399_SDMMC_CON1 0x584
202 #define RK3399_SDIO_CON0 0x588
203 #define RK3399_SDIO_CON1 0x58c
205 #define RK3399_PMU_PLL_CON(x) RK2928_PLL_CON(x)
206 #define RK3399_PMU_CLKSEL_CON(x) ((x) * 0x4 + 0x80)
207 #define RK3399_PMU_CLKGATE_CON(x) ((x) * 0x4 + 0x100)
208 #define RK3399_PMU_SOFTRST_CON(x) ((x) * 0x4 + 0x110)
210 #define RK3568_PLL_CON(x) RK2928_PLL_CON(x)
211 #define RK3568_MODE_CON0 0xc0
212 #define RK3568_MISC_CON0 0xc4
213 #define RK3568_MISC_CON1 0xc8
214 #define RK3568_MISC_CON2 0xcc
215 #define RK3568_GLB_CNT_TH 0xd0
216 #define RK3568_GLB_SRST_FST 0xd4
217 #define RK3568_GLB_SRST_SND 0xd8
218 #define RK3568_GLB_RST_CON 0xdc
219 #define RK3568_GLB_RST_ST 0xe0
220 #define RK3568_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
221 #define RK3568_CLKGATE_CON(x) ((x) * 0x4 + 0x300)
222 #define RK3568_SOFTRST_CON(x) ((x) * 0x4 + 0x400)
223 #define RK3568_SDMMC0_CON0 0x580
224 #define RK3568_SDMMC0_CON1 0x584
225 #define RK3568_SDMMC1_CON0 0x588
226 #define RK3568_SDMMC1_CON1 0x58c
227 #define RK3568_SDMMC2_CON0 0x590
228 #define RK3568_SDMMC2_CON1 0x594
229 #define RK3568_EMMC_CON0 0x598
230 #define RK3568_EMMC_CON1 0x59c
232 #define RK3568_PMU_PLL_CON(x) RK2928_PLL_CON(x)
233 #define RK3568_PMU_MODE_CON0 0x80
234 #define RK3568_PMU_CLKSEL_CON(x) ((x) * 0x4 + 0x100)
235 #define RK3568_PMU_CLKGATE_CON(x) ((x) * 0x4 + 0x180)
236 #define RK3568_PMU_SOFTRST_CON(x) ((x) * 0x4 + 0x200)
238 #define RK3576_PHP_CRU_BASE 0x8000
239 #define RK3576_SECURE_NS_CRU_BASE 0x10000
240 #define RK3576_PMU_CRU_BASE 0x20000
241 #define RK3576_BIGCORE_CRU_BASE 0x38000
242 #define RK3576_LITCORE_CRU_BASE 0x40000
243 #define RK3576_CCI_CRU_BASE 0x48000
245 #define RK3576_PLL_CON(x) RK2928_PLL_CON(x)
246 #define RK3576_MODE_CON0 0x280
247 #define RK3576_BPLL_MODE_CON0 (RK3576_BIGCORE_CRU_BASE + 0x280)
248 #define RK3576_LPLL_MODE_CON0 (RK3576_LITCORE_CRU_BASE + 0x280)
249 #define RK3576_PPLL_MODE_CON0 (RK3576_PHP_CRU_BASE + 0x280)
250 #define RK3576_CLKSEL_CON(x) ((x) * 0x4 + 0x300)
251 #define RK3576_CLKGATE_CON(x) ((x) * 0x4 + 0x800)
252 #define RK3576_SOFTRST_CON(x) ((x) * 0x4 + 0xa00)
253 #define RK3576_GLB_CNT_TH 0xc00
254 #define RK3576_GLB_SRST_FST 0xc08
255 #define RK3576_GLB_SRST_SND 0xc0c
256 #define RK3576_GLB_RST_CON 0xc10
257 #define RK3576_GLB_RST_ST 0xc04
258 #define RK3576_SDIO_CON0 0xC24
259 #define RK3576_SDIO_CON1 0xC28
260 #define RK3576_SDMMC_CON0 0xC30
261 #define RK3576_SDMMC_CON1 0xC34
263 #define RK3576_PHP_CLKSEL_CON(x) ((x) * 0x4 + RK3576_PHP_CRU_BASE + 0x300)
264 #define RK3576_PHP_CLKGATE_CON(x) ((x) * 0x4 + RK3576_PHP_CRU_BASE + 0x800)
265 #define RK3576_PHP_SOFTRST_CON(x) ((x) * 0x4 + RK3576_PHP_CRU_BASE + 0xa00)
267 #define RK3576_PMU_PLL_CON(x) ((x) * 0x4 + RK3576_PHP_CRU_BASE)
268 #define RK3576_PMU_CLKSEL_CON(x) ((x) * 0x4 + RK3576_PMU_CRU_BASE + 0x300)
269 #define RK3576_PMU_CLKGATE_CON(x) ((x) * 0x4 + RK3576_PMU_CRU_BASE + 0x800)
270 #define RK3576_PMU_SOFTRST_CON(x) ((x) * 0x4 + RK3576_PMU_CRU_BASE + 0xa00)
272 #define RK3576_SECURE_NS_CLKSEL_CON(x) ((x) * 0x4 + RK3576_SECURE_NS_CRU_BASE + 0x300)
273 #define RK3576_SECURE_NS_CLKGATE_CON(x) ((x) * 0x4 + RK3576_SECURE_NS_CRU_BASE + 0x800)
274 #define RK3576_SECURE_NS_SOFTRST_CON(x) ((x) * 0x4 + RK3576_SECURE_NS_CRU_BASE + 0xa00)
276 #define RK3576_CCI_CLKSEL_CON(x) ((x) * 0x4 + RK3576_CCI_CRU_BASE + 0x300)
277 #define RK3576_CCI_CLKGATE_CON(x) ((x) * 0x4 + RK3576_CCI_CRU_BASE + 0x800)
278 #define RK3576_CCI_SOFTRST_CON(x) ((x) * 0x4 + RK3576_CCI_CRU_BASE + 0xa00)
280 #define RK3576_BPLL_CON(x) ((x) * 0x4 + RK3576_BIGCORE_CRU_BASE)
281 #define RK3576_BIGCORE_CLKSEL_CON(x) ((x) * 0x4 + RK3576_BIGCORE_CRU_BASE + 0x300)
282 #define RK3576_BIGCORE_CLKGATE_CON(x) ((x) * 0x4 + RK3576_BIGCORE_CRU_BASE + 0x800)
283 #define RK3576_BIGCORE_SOFTRST_CON(x) ((x) * 0x4 + RK3576_BIGCORE_CRU_BASE + 0xa00)
284 #define RK3576_LPLL_CON(x) ((x) * 0x4 + RK3576_CCI_CRU_BASE)
285 #define RK3576_LITCORE_CLKSEL_CON(x) ((x) * 0x4 + RK3576_LITCORE_CRU_BASE + 0x300)
286 #define RK3576_LITCORE_CLKGATE_CON(x) ((x) * 0x4 + RK3576_LITCORE_CRU_BASE + 0x800)
287 #define RK3576_LITCORE_SOFTRST_CON(x) ((x) * 0x4 + RK3576_LITCORE_CRU_BASE + 0xa00)
288 #define RK3576_NON_SECURE_GATING_CON00 0xc48
290 #define RK3588_PHP_CRU_BASE 0x8000
291 #define RK3588_PMU_CRU_BASE 0x30000
292 #define RK3588_BIGCORE0_CRU_BASE 0x50000
293 #define RK3588_BIGCORE1_CRU_BASE 0x52000
294 #define RK3588_DSU_CRU_BASE 0x58000
296 #define RK3588_PLL_CON(x) RK2928_PLL_CON(x)
297 #define RK3588_MODE_CON0 0x280
298 #define RK3588_B0_PLL_MODE_CON0 (RK3588_BIGCORE0_CRU_BASE + 0x280)
299 #define RK3588_B1_PLL_MODE_CON0 (RK3588_BIGCORE1_CRU_BASE + 0x280)
300 #define RK3588_LPLL_MODE_CON0 (RK3588_DSU_CRU_BASE + 0x280)
301 #define RK3588_CLKSEL_CON(x) ((x) * 0x4 + 0x300)
302 #define RK3588_CLKGATE_CON(x) ((x) * 0x4 + 0x800)
303 #define RK3588_SOFTRST_CON(x) ((x) * 0x4 + 0xa00)
304 #define RK3588_GLB_CNT_TH 0xc00
305 #define RK3588_GLB_SRST_FST 0xc08
306 #define RK3588_GLB_SRST_SND 0xc0c
307 #define RK3588_GLB_RST_CON 0xc10
308 #define RK3588_GLB_RST_ST 0xc04
309 #define RK3588_SDIO_CON0 0xC24
310 #define RK3588_SDIO_CON1 0xC28
311 #define RK3588_SDMMC_CON0 0xC30
312 #define RK3588_SDMMC_CON1 0xC34
314 #define RK3588_PHP_CLKGATE_CON(x) ((x) * 0x4 + RK3588_PHP_CRU_BASE + 0x800)
315 #define RK3588_PHP_SOFTRST_CON(x) ((x) * 0x4 + RK3588_PHP_CRU_BASE + 0xa00)
317 #define RK3588_PMU_PLL_CON(x) ((x) * 0x4 + RK3588_PHP_CRU_BASE)
318 #define RK3588_PMU_CLKSEL_CON(x) ((x) * 0x4 + RK3588_PMU_CRU_BASE + 0x300)
319 #define RK3588_PMU_CLKGATE_CON(x) ((x) * 0x4 + RK3588_PMU_CRU_BASE + 0x800)
320 #define RK3588_PMU_SOFTRST_CON(x) ((x) * 0x4 + RK3588_PMU_CRU_BASE + 0xa00)
322 #define RK3588_B0_PLL_CON(x) ((x) * 0x4 + RK3588_BIGCORE0_CRU_BASE)
323 #define RK3588_BIGCORE0_CLKSEL_CON(x) ((x) * 0x4 + RK3588_BIGCORE0_CRU_BASE + 0x300)
324 #define RK3588_BIGCORE0_CLKGATE_CON(x) ((x) * 0x4 + RK3588_BIGCORE0_CRU_BASE + 0x800)
325 #define RK3588_BIGCORE0_SOFTRST_CON(x) ((x) * 0x4 + RK3588_BIGCORE0_CRU_BASE + 0xa00)
326 #define RK3588_B1_PLL_CON(x) ((x) * 0x4 + RK3588_BIGCORE1_CRU_BASE)
327 #define RK3588_BIGCORE1_CLKSEL_CON(x) ((x) * 0x4 + RK3588_BIGCORE1_CRU_BASE + 0x300)
328 #define RK3588_BIGCORE1_CLKGATE_CON(x) ((x) * 0x4 + RK3588_BIGCORE1_CRU_BASE + 0x800)
329 #define RK3588_BIGCORE1_SOFTRST_CON(x) ((x) * 0x4 + RK3588_BIGCORE1_CRU_BASE + 0xa00)
330 #define RK3588_LPLL_CON(x) ((x) * 0x4 + RK3588_DSU_CRU_BASE)
331 #define RK3588_DSU_CLKSEL_CON(x) ((x) * 0x4 + RK3588_DSU_CRU_BASE + 0x300)
332 #define RK3588_DSU_CLKGATE_CON(x) ((x) * 0x4 + RK3588_DSU_CRU_BASE + 0x800)
333 #define RK3588_DSU_SOFTRST_CON(x) ((x) * 0x4 + RK3588_DSU_CRU_BASE + 0xa00)
335 enum rockchip_pll_type
{
345 #define RK3036_PLL_RATE(_rate, _refdiv, _fbdiv, _postdiv1, \
346 _postdiv2, _dsmpd, _frac) \
350 .postdiv1 = _postdiv1, \
352 .postdiv2 = _postdiv2, \
357 #define RK3066_PLL_RATE(_rate, _nr, _nf, _no) \
363 .nb = ((_nf) < 2) ? 1 : (_nf) >> 1, \
366 #define RK3066_PLL_RATE_NB(_rate, _nr, _nf, _no, _nb) \
375 #define RK3588_PLL_RATE(_rate, _p, _m, _s, _k) \
385 * struct rockchip_clk_provider - information about clock provider
386 * @reg_base: virtual address for the register base.
387 * @clk_data: holds clock related data like clk* and number of clocks.
388 * @cru_node: device-node of the clock-provider
389 * @grf: regmap of the general-register-files syscon
390 * @lock: maintains exclusion between callbacks for a given clock-provider.
392 struct rockchip_clk_provider
{
393 void __iomem
*reg_base
;
394 struct clk_onecell_data clk_data
;
395 struct device_node
*cru_node
;
400 struct rockchip_pll_rate_table
{
411 /* for RK3036/RK3399 */
413 unsigned int postdiv1
;
415 unsigned int postdiv2
;
430 * struct rockchip_pll_clock - information about pll clock
431 * @id: platform specific id of the clock.
432 * @name: name of this pll clock.
433 * @parent_names: name of the parent clock.
434 * @num_parents: number of parents
435 * @flags: optional flags for basic clock.
436 * @con_offset: offset of the register for configuring the PLL.
437 * @mode_offset: offset of the register for configuring the PLL-mode.
438 * @mode_shift: offset inside the mode-register for the mode of this pll.
439 * @lock_shift: offset inside the lock register for the lock status.
440 * @type: Type of PLL to be registered.
441 * @pll_flags: hardware-specific flags
442 * @rate_table: Table of usable pll rates
445 * ROCKCHIP_PLL_SYNC_RATE - check rate parameters to match against the
446 * rate_table parameters and ajust them if necessary.
448 struct rockchip_pll_clock
{
451 const char *const *parent_names
;
458 enum rockchip_pll_type type
;
460 struct rockchip_pll_rate_table
*rate_table
;
463 #define ROCKCHIP_PLL_SYNC_RATE BIT(0)
465 #define PLL(_type, _id, _name, _pnames, _flags, _con, _mode, _mshift, \
466 _lshift, _pflags, _rtable) \
471 .parent_names = _pnames, \
472 .num_parents = ARRAY_SIZE(_pnames), \
473 .flags = CLK_GET_RATE_NOCACHE | _flags, \
474 .con_offset = _con, \
475 .mode_offset = _mode, \
476 .mode_shift = _mshift, \
477 .lock_shift = _lshift, \
478 .pll_flags = _pflags, \
479 .rate_table = _rtable, \
482 struct clk
*rockchip_clk_register_pll(struct rockchip_clk_provider
*ctx
,
483 enum rockchip_pll_type pll_type
,
484 const char *name
, const char *const *parent_names
,
485 u8 num_parents
, int con_offset
, int grf_lock_offset
,
486 int lock_shift
, int mode_offset
, int mode_shift
,
487 struct rockchip_pll_rate_table
*rate_table
,
488 unsigned long flags
, u8 clk_pll_flags
);
490 struct rockchip_cpuclk_clksel
{
495 #define ROCKCHIP_CPUCLK_NUM_DIVIDERS 6
496 #define ROCKCHIP_CPUCLK_MAX_CORES 4
497 struct rockchip_cpuclk_rate_table
{
499 struct rockchip_cpuclk_clksel divs
[ROCKCHIP_CPUCLK_NUM_DIVIDERS
];
500 struct rockchip_cpuclk_clksel pre_muxs
[ROCKCHIP_CPUCLK_NUM_DIVIDERS
];
501 struct rockchip_cpuclk_clksel post_muxs
[ROCKCHIP_CPUCLK_NUM_DIVIDERS
];
505 * struct rockchip_cpuclk_reg_data - register offsets and masks of the cpuclock
506 * @core_reg[]: register offset of the cores setting register
507 * @div_core_shift[]: cores divider offset used to divide the pll value
508 * @div_core_mask[]: cores divider mask
509 * @num_cores: number of cpu cores
510 * @mux_core_reg: register offset of the cores select parent
511 * @mux_core_alt: mux value to select alternate parent
512 * @mux_core_main: mux value to select main parent of core
513 * @mux_core_shift: offset of the core multiplexer
514 * @mux_core_mask: core multiplexer mask
516 struct rockchip_cpuclk_reg_data
{
517 int core_reg
[ROCKCHIP_CPUCLK_MAX_CORES
];
518 u8 div_core_shift
[ROCKCHIP_CPUCLK_MAX_CORES
];
519 u32 div_core_mask
[ROCKCHIP_CPUCLK_MAX_CORES
];
528 struct clk
*rockchip_clk_register_cpuclk(const char *name
,
529 const char *const *parent_names
, u8 num_parents
,
530 const struct rockchip_cpuclk_reg_data
*reg_data
,
531 const struct rockchip_cpuclk_rate_table
*rates
,
532 int nrates
, void __iomem
*reg_base
, spinlock_t
*lock
);
534 struct clk
*rockchip_clk_register_mmc(const char *name
,
535 const char *const *parent_names
, u8 num_parents
,
536 void __iomem
*reg
, int shift
);
539 * DDRCLK flags, including method of setting the rate
540 * ROCKCHIP_DDRCLK_SIP: use SIP call to bl31 to change ddrclk rate.
542 #define ROCKCHIP_DDRCLK_SIP BIT(0)
544 struct clk
*rockchip_clk_register_ddrclk(const char *name
, int flags
,
545 const char *const *parent_names
,
546 u8 num_parents
, int mux_offset
,
547 int mux_shift
, int mux_width
,
548 int div_shift
, int div_width
,
549 int ddr_flags
, void __iomem
*reg_base
,
552 #define ROCKCHIP_INVERTER_HIWORD_MASK BIT(0)
554 struct clk
*rockchip_clk_register_inverter(const char *name
,
555 const char *const *parent_names
, u8 num_parents
,
556 void __iomem
*reg
, int shift
, int flags
,
559 struct clk
*rockchip_clk_register_muxgrf(const char *name
,
560 const char *const *parent_names
, u8 num_parents
,
561 int flags
, struct regmap
*grf
, int reg
,
562 int shift
, int width
, int mux_flags
);
564 #define PNAME(x) static const char *const x[] __initconst
566 enum rockchip_clk_branch_type
{
571 branch_fraction_divider
,
580 struct rockchip_clk_branch
{
582 enum rockchip_clk_branch_type branch_type
;
584 const char *const *parent_names
;
596 struct clk_div_table
*div_table
;
600 struct rockchip_clk_branch
*child
;
603 #define COMPOSITE(_id, cname, pnames, f, mo, ms, mw, mf, ds, dw,\
607 .branch_type = branch_composite, \
609 .parent_names = pnames, \
610 .num_parents = ARRAY_SIZE(pnames), \
612 .muxdiv_offset = mo, \
624 #define COMPOSITE_DIV_OFFSET(_id, cname, pnames, f, mo, ms, mw, \
625 mf, do, ds, dw, df, go, gs, gf) \
628 .branch_type = branch_composite, \
630 .parent_names = pnames, \
631 .num_parents = ARRAY_SIZE(pnames), \
633 .muxdiv_offset = mo, \
646 #define COMPOSITE_NOMUX(_id, cname, pname, f, mo, ds, dw, df, \
650 .branch_type = branch_composite, \
652 .parent_names = (const char *[]){ pname }, \
655 .muxdiv_offset = mo, \
664 #define COMPOSITE_NOMUX_DIVTBL(_id, cname, pname, f, mo, ds, dw,\
665 df, dt, go, gs, gf) \
668 .branch_type = branch_composite, \
670 .parent_names = (const char *[]){ pname }, \
673 .muxdiv_offset = mo, \
683 #define COMPOSITE_NODIV(_id, cname, pnames, f, mo, ms, mw, mf, \
687 .branch_type = branch_composite, \
689 .parent_names = pnames, \
690 .num_parents = ARRAY_SIZE(pnames), \
692 .muxdiv_offset = mo, \
701 #define COMPOSITE_NOGATE(_id, cname, pnames, f, mo, ms, mw, mf, \
705 .branch_type = branch_composite, \
707 .parent_names = pnames, \
708 .num_parents = ARRAY_SIZE(pnames), \
710 .muxdiv_offset = mo, \
720 #define COMPOSITE_NOGATE_DIVTBL(_id, cname, pnames, f, mo, ms, \
721 mw, mf, ds, dw, df, dt) \
724 .branch_type = branch_composite, \
726 .parent_names = pnames, \
727 .num_parents = ARRAY_SIZE(pnames), \
729 .muxdiv_offset = mo, \
740 #define COMPOSITE_FRAC(_id, cname, pname, f, mo, df, go, gs, gf)\
743 .branch_type = branch_fraction_divider, \
745 .parent_names = (const char *[]){ pname }, \
748 .muxdiv_offset = mo, \
757 #define COMPOSITE_FRACMUX(_id, cname, pname, f, mo, df, go, gs, gf, ch) \
760 .branch_type = branch_fraction_divider, \
762 .parent_names = (const char *[]){ pname }, \
765 .muxdiv_offset = mo, \
775 #define COMPOSITE_FRACMUX_NOGATE(_id, cname, pname, f, mo, df, ch) \
778 .branch_type = branch_fraction_divider, \
780 .parent_names = (const char *[]){ pname }, \
783 .muxdiv_offset = mo, \
791 #define COMPOSITE_DDRCLK(_id, cname, pnames, f, mo, ms, mw, \
795 .branch_type = branch_ddrclk, \
797 .parent_names = pnames, \
798 .num_parents = ARRAY_SIZE(pnames), \
800 .muxdiv_offset = mo, \
809 #define MUX(_id, cname, pnames, f, o, s, w, mf) \
812 .branch_type = branch_mux, \
814 .parent_names = pnames, \
815 .num_parents = ARRAY_SIZE(pnames), \
817 .muxdiv_offset = o, \
824 #define MUXTBL(_id, cname, pnames, f, o, s, w, mf, mt) \
827 .branch_type = branch_mux, \
829 .parent_names = pnames, \
830 .num_parents = ARRAY_SIZE(pnames), \
832 .muxdiv_offset = o, \
840 #define MUXGRF(_id, cname, pnames, f, o, s, w, mf) \
843 .branch_type = branch_muxgrf, \
845 .parent_names = pnames, \
846 .num_parents = ARRAY_SIZE(pnames), \
848 .muxdiv_offset = o, \
855 #define DIV(_id, cname, pname, f, o, s, w, df) \
858 .branch_type = branch_divider, \
860 .parent_names = (const char *[]){ pname }, \
863 .muxdiv_offset = o, \
870 #define DIVTBL(_id, cname, pname, f, o, s, w, df, dt) \
873 .branch_type = branch_divider, \
875 .parent_names = (const char *[]){ pname }, \
878 .muxdiv_offset = o, \
885 #define GATE(_id, cname, pname, f, o, b, gf) \
888 .branch_type = branch_gate, \
890 .parent_names = (const char *[]){ pname }, \
898 #define MMC(_id, cname, pname, offset, shift) \
901 .branch_type = branch_mmc, \
903 .parent_names = (const char *[]){ pname }, \
905 .muxdiv_offset = offset, \
906 .div_shift = shift, \
909 #define INVERTER(_id, cname, pname, io, is, if) \
912 .branch_type = branch_inverter, \
914 .parent_names = (const char *[]){ pname }, \
916 .muxdiv_offset = io, \
921 #define FACTOR(_id, cname, pname, f, fm, fd) \
924 .branch_type = branch_factor, \
926 .parent_names = (const char *[]){ pname }, \
933 #define FACTOR_GATE(_id, cname, pname, f, fm, fd, go, gb, gf) \
936 .branch_type = branch_factor, \
938 .parent_names = (const char *[]){ pname }, \
948 #define COMPOSITE_HALFDIV(_id, cname, pnames, f, mo, ms, mw, mf, ds, dw,\
952 .branch_type = branch_half_divider, \
954 .parent_names = pnames, \
955 .num_parents = ARRAY_SIZE(pnames), \
957 .muxdiv_offset = mo, \
969 #define COMPOSITE_NOGATE_HALFDIV(_id, cname, pnames, f, mo, ms, mw, mf, \
973 .branch_type = branch_half_divider, \
975 .parent_names = pnames, \
976 .num_parents = ARRAY_SIZE(pnames), \
978 .muxdiv_offset = mo, \
988 #define COMPOSITE_NOMUX_HALFDIV(_id, cname, pname, f, mo, ds, dw, df, \
992 .branch_type = branch_half_divider, \
994 .parent_names = (const char *[]){ pname }, \
997 .muxdiv_offset = mo, \
1001 .gate_offset = go, \
1006 #define DIV_HALF(_id, cname, pname, f, o, s, w, df) \
1009 .branch_type = branch_half_divider, \
1011 .parent_names = (const char *[]){ pname }, \
1014 .muxdiv_offset = o, \
1018 .gate_offset = -1, \
1021 /* SGRF clocks are only accessible from secure mode, so not controllable */
1022 #define SGRF_GATE(_id, cname, pname) \
1023 FACTOR(_id, cname, pname, 0, 1, 1)
1025 struct rockchip_clk_provider
*rockchip_clk_init(struct device_node
*np
,
1026 void __iomem
*base
, unsigned long nr_clks
);
1027 void rockchip_clk_of_add_provider(struct device_node
*np
,
1028 struct rockchip_clk_provider
*ctx
);
1029 unsigned long rockchip_clk_find_max_clk_id(struct rockchip_clk_branch
*list
,
1030 unsigned int nr_clk
);
1031 void rockchip_clk_register_branches(struct rockchip_clk_provider
*ctx
,
1032 struct rockchip_clk_branch
*list
,
1033 unsigned int nr_clk
);
1034 void rockchip_clk_register_plls(struct rockchip_clk_provider
*ctx
,
1035 struct rockchip_pll_clock
*pll_list
,
1036 unsigned int nr_pll
, int grf_lock_offset
);
1037 void rockchip_clk_register_armclk(struct rockchip_clk_provider
*ctx
,
1038 unsigned int lookup_id
, const char *name
,
1039 const char *const *parent_names
, u8 num_parents
,
1040 const struct rockchip_cpuclk_reg_data
*reg_data
,
1041 const struct rockchip_cpuclk_rate_table
*rates
,
1043 void rockchip_clk_protect_critical(const char *const clocks
[], int nclocks
);
1044 void rockchip_register_restart_notifier(struct rockchip_clk_provider
*ctx
,
1045 unsigned int reg
, void (*cb
)(void));
1047 #define ROCKCHIP_SOFTRST_HIWORD_MASK BIT(0)
1049 struct clk
*rockchip_clk_register_halfdiv(const char *name
,
1050 const char *const *parent_names
,
1051 u8 num_parents
, void __iomem
*base
,
1052 int muxdiv_offset
, u8 mux_shift
,
1053 u8 mux_width
, u8 mux_flags
,
1054 u8 div_shift
, u8 div_width
,
1055 u8 div_flags
, int gate_offset
,
1056 u8 gate_shift
, u8 gate_flags
,
1057 unsigned long flags
,
1060 #ifdef CONFIG_RESET_CONTROLLER
1061 void rockchip_register_softrst_lut(struct device_node
*np
,
1062 const int *lookup_table
,
1063 unsigned int num_regs
,
1064 void __iomem
*base
, u8 flags
);
1066 static inline void rockchip_register_softrst_lut(struct device_node
*np
,
1067 const int *lookup_table
,
1068 unsigned int num_regs
,
1069 void __iomem
*base
, u8 flags
)
1074 static inline void rockchip_register_softrst(struct device_node
*np
,
1075 unsigned int num_regs
,
1076 void __iomem
*base
, u8 flags
)
1078 return rockchip_register_softrst_lut(np
, NULL
, num_regs
, base
, flags
);
1081 void rk3576_rst_init(struct device_node
*np
, void __iomem
*reg_base
);
1082 void rk3588_rst_init(struct device_node
*np
, void __iomem
*reg_base
);