xref: /openbmc/linux/drivers/clk/sunxi-ng/ccu-sun50i-a64.c (revision b271fc467acd71630d7a2f0f2fcd2a4dbfc22edf)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2016 Maxime Ripard. All rights reserved.
4  */
5 
6 #include <linux/clk-provider.h>
7 #include <linux/io.h>
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 
11 #include "ccu_common.h"
12 #include "ccu_reset.h"
13 
14 #include "ccu_div.h"
15 #include "ccu_gate.h"
16 #include "ccu_mp.h"
17 #include "ccu_mult.h"
18 #include "ccu_nk.h"
19 #include "ccu_nkm.h"
20 #include "ccu_nkmp.h"
21 #include "ccu_nm.h"
22 #include "ccu_phase.h"
23 
24 #include "ccu-sun50i-a64.h"
25 
26 static struct ccu_nkmp pll_cpux_clk = {
27 	.enable		= BIT(31),
28 	.lock		= BIT(28),
29 	.n		= _SUNXI_CCU_MULT(8, 5),
30 	.k		= _SUNXI_CCU_MULT(4, 2),
31 	.m		= _SUNXI_CCU_DIV(0, 2),
32 	.p		= _SUNXI_CCU_DIV_MAX(16, 2, 4),
33 	.common		= {
34 		.reg		= 0x000,
35 		.hw.init	= CLK_HW_INIT("pll-cpux",
36 					      "osc24M",
37 					      &ccu_nkmp_ops,
38 					      CLK_SET_RATE_UNGATE),
39 	},
40 };
41 
42 /*
43  * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
44  * the base (2x, 4x and 8x), and one variable divider (the one true
45  * pll audio).
46  *
47  * With sigma-delta modulation for fractional-N on the audio PLL,
48  * we have to use specific dividers. This means the variable divider
49  * can no longer be used, as the audio codec requests the exact clock
50  * rates we support through this mechanism. So we now hard code the
51  * variable divider to 1. This means the clock rates will no longer
52  * match the clock names.
53  */
54 #define SUN50I_A64_PLL_AUDIO_REG	0x008
55 
56 static struct ccu_sdm_setting pll_audio_sdm_table[] = {
57 	{ .rate = 22579200, .pattern = 0xc0010d84, .m = 8, .n = 7 },
58 	{ .rate = 24576000, .pattern = 0xc000ac02, .m = 14, .n = 14 },
59 };
60 
61 static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
62 				       "osc24M", 0x008,
63 				       8, 7,	/* N */
64 				       0, 5,	/* M */
65 				       pll_audio_sdm_table, BIT(24),
66 				       0x284, BIT(31),
67 				       BIT(31),	/* gate */
68 				       BIT(28),	/* lock */
69 				       CLK_SET_RATE_UNGATE);
70 
71 static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video0_clk, "pll-video0",
72 						"osc24M", 0x010,
73 						192000000,	/* Minimum rate */
74 						1008000000,	/* Maximum rate */
75 						8, 7,		/* N */
76 						0, 4,		/* M */
77 						BIT(24),	/* frac enable */
78 						BIT(25),	/* frac select */
79 						270000000,	/* frac rate 0 */
80 						297000000,	/* frac rate 1 */
81 						BIT(31),	/* gate */
82 						BIT(28),	/* lock */
83 						CLK_SET_RATE_UNGATE);
84 
85 static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve",
86 					"osc24M", 0x018,
87 					8, 7,		/* N */
88 					0, 4,		/* M */
89 					BIT(24),	/* frac enable */
90 					BIT(25),	/* frac select */
91 					270000000,	/* frac rate 0 */
92 					297000000,	/* frac rate 1 */
93 					BIT(31),	/* gate */
94 					BIT(28),	/* lock */
95 					CLK_SET_RATE_UNGATE);
96 
97 static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr0_clk, "pll-ddr0",
98 				    "osc24M", 0x020,
99 				    8, 5,	/* N */
100 				    4, 2,	/* K */
101 				    0, 2,	/* M */
102 				    BIT(31),	/* gate */
103 				    BIT(28),	/* lock */
104 				    CLK_SET_RATE_UNGATE);
105 
106 static struct ccu_nk pll_periph0_clk = {
107 	.enable		= BIT(31),
108 	.lock		= BIT(28),
109 	.n		= _SUNXI_CCU_MULT(8, 5),
110 	.k		= _SUNXI_CCU_MULT_MIN(4, 2, 2),
111 	.fixed_post_div	= 2,
112 	.common		= {
113 		.reg		= 0x028,
114 		.features	= CCU_FEATURE_FIXED_POSTDIV,
115 		.hw.init	= CLK_HW_INIT("pll-periph0", "osc24M",
116 					      &ccu_nk_ops, CLK_SET_RATE_UNGATE),
117 	},
118 };
119 
120 static struct ccu_nk pll_periph1_clk = {
121 	.enable		= BIT(31),
122 	.lock		= BIT(28),
123 	.n		= _SUNXI_CCU_MULT(8, 5),
124 	.k		= _SUNXI_CCU_MULT_MIN(4, 2, 2),
125 	.fixed_post_div	= 2,
126 	.common		= {
127 		.reg		= 0x02c,
128 		.features	= CCU_FEATURE_FIXED_POSTDIV,
129 		.hw.init	= CLK_HW_INIT("pll-periph1", "osc24M",
130 					      &ccu_nk_ops, CLK_SET_RATE_UNGATE),
131 	},
132 };
133 
134 static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video1_clk, "pll-video1",
135 						"osc24M", 0x030,
136 						192000000,	/* Minimum rate */
137 						1008000000,	/* Maximum rate */
138 						8, 7,		/* N */
139 						0, 4,		/* M */
140 						BIT(24),	/* frac enable */
141 						BIT(25),	/* frac select */
142 						270000000,	/* frac rate 0 */
143 						297000000,	/* frac rate 1 */
144 						BIT(31),	/* gate */
145 						BIT(28),	/* lock */
146 						CLK_SET_RATE_UNGATE);
147 
148 static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_gpu_clk, "pll-gpu",
149 					"osc24M", 0x038,
150 					8, 7,		/* N */
151 					0, 4,		/* M */
152 					BIT(24),	/* frac enable */
153 					BIT(25),	/* frac select */
154 					270000000,	/* frac rate 0 */
155 					297000000,	/* frac rate 1 */
156 					BIT(31),	/* gate */
157 					BIT(28),	/* lock */
158 					CLK_SET_RATE_UNGATE);
159 
160 /*
161  * The output function can be changed to something more complex that
162  * we do not handle yet.
163  *
164  * Hardcode the mode so that we don't fall in that case.
165  */
166 #define SUN50I_A64_PLL_MIPI_REG		0x040
167 
168 static struct ccu_nkm pll_mipi_clk = {
169 	/*
170 	 * The bit 23 and 22 are called "LDO{1,2}_EN" on the SoC's
171 	 * user manual, and by experiments the PLL doesn't work without
172 	 * these bits toggled.
173 	 */
174 	.enable		= BIT(31) | BIT(23) | BIT(22),
175 	.lock		= BIT(28),
176 	.n		= _SUNXI_CCU_MULT(8, 4),
177 	.k		= _SUNXI_CCU_MULT_MIN(4, 2, 2),
178 	.m		= _SUNXI_CCU_DIV(0, 4),
179 	.common		= {
180 		.reg		= 0x040,
181 		.hw.init	= CLK_HW_INIT("pll-mipi", "pll-video0",
182 					      &ccu_nkm_ops,
183 					      CLK_SET_RATE_UNGATE | CLK_SET_RATE_PARENT),
184 	},
185 };
186 
187 static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_hsic_clk, "pll-hsic",
188 					"osc24M", 0x044,
189 					8, 7,		/* N */
190 					0, 4,		/* M */
191 					BIT(24),	/* frac enable */
192 					BIT(25),	/* frac select */
193 					270000000,	/* frac rate 0 */
194 					297000000,	/* frac rate 1 */
195 					BIT(31),	/* gate */
196 					BIT(28),	/* lock */
197 					CLK_SET_RATE_UNGATE);
198 
199 static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_de_clk, "pll-de",
200 					"osc24M", 0x048,
201 					8, 7,		/* N */
202 					0, 4,		/* M */
203 					BIT(24),	/* frac enable */
204 					BIT(25),	/* frac select */
205 					270000000,	/* frac rate 0 */
206 					297000000,	/* frac rate 1 */
207 					BIT(31),	/* gate */
208 					BIT(28),	/* lock */
209 					CLK_SET_RATE_UNGATE);
210 
211 static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_ddr1_clk, "pll-ddr1",
212 				   "osc24M", 0x04c,
213 				   8, 7,	/* N */
214 				   0, 2,	/* M */
215 				   BIT(31),	/* gate */
216 				   BIT(28),	/* lock */
217 				   CLK_SET_RATE_UNGATE);
218 
219 static const char * const cpux_parents[] = { "osc32k", "osc24M",
220 					     "pll-cpux", "pll-cpux" };
221 static SUNXI_CCU_MUX(cpux_clk, "cpux", cpux_parents,
222 		     0x050, 16, 2, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
223 
224 static SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x050, 0, 2, 0);
225 
226 static const char * const ahb1_parents[] = { "osc32k", "osc24M",
227 					     "axi", "pll-periph0" };
228 static const struct ccu_mux_var_prediv ahb1_predivs[] = {
229 	{ .index = 3, .shift = 6, .width = 2 },
230 };
231 static struct ccu_div ahb1_clk = {
232 	.div		= _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
233 
234 	.mux		= {
235 		.shift	= 12,
236 		.width	= 2,
237 
238 		.var_predivs	= ahb1_predivs,
239 		.n_var_predivs	= ARRAY_SIZE(ahb1_predivs),
240 	},
241 
242 	.common		= {
243 		.reg		= 0x054,
244 		.features	= CCU_FEATURE_VARIABLE_PREDIV,
245 		.hw.init	= CLK_HW_INIT_PARENTS("ahb1",
246 						      ahb1_parents,
247 						      &ccu_div_ops,
248 						      0),
249 	},
250 };
251 
252 static struct clk_div_table apb1_div_table[] = {
253 	{ .val = 0, .div = 2 },
254 	{ .val = 1, .div = 2 },
255 	{ .val = 2, .div = 4 },
256 	{ .val = 3, .div = 8 },
257 	{ /* Sentinel */ },
258 };
259 static SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1",
260 			   0x054, 8, 2, apb1_div_table, 0);
261 
262 static const char * const apb2_parents[] = { "osc32k", "osc24M",
263 					     "pll-periph0-2x",
264 					     "pll-periph0-2x" };
265 static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058,
266 			     0, 5,	/* M */
267 			     16, 2,	/* P */
268 			     24, 2,	/* mux */
269 			     0);
270 
271 static const char * const ahb2_parents[] = { "ahb1", "pll-periph0" };
272 static const struct ccu_mux_fixed_prediv ahb2_fixed_predivs[] = {
273 	{ .index = 1, .div = 2 },
274 };
275 static struct ccu_mux ahb2_clk = {
276 	.mux		= {
277 		.shift	= 0,
278 		.width	= 1,
279 		.fixed_predivs	= ahb2_fixed_predivs,
280 		.n_predivs	= ARRAY_SIZE(ahb2_fixed_predivs),
281 	},
282 
283 	.common		= {
284 		.reg		= 0x05c,
285 		.features	= CCU_FEATURE_FIXED_PREDIV,
286 		.hw.init	= CLK_HW_INIT_PARENTS("ahb2",
287 						      ahb2_parents,
288 						      &ccu_mux_ops,
289 						      0),
290 	},
291 };
292 
293 static SUNXI_CCU_GATE(bus_mipi_dsi_clk,	"bus-mipi-dsi",	"ahb1",
294 		      0x060, BIT(1), 0);
295 static SUNXI_CCU_GATE(bus_ce_clk,	"bus-ce",	"ahb1",
296 		      0x060, BIT(5), 0);
297 static SUNXI_CCU_GATE(bus_dma_clk,	"bus-dma",	"ahb1",
298 		      0x060, BIT(6), 0);
299 static SUNXI_CCU_GATE(bus_mmc0_clk,	"bus-mmc0",	"ahb1",
300 		      0x060, BIT(8), 0);
301 static SUNXI_CCU_GATE(bus_mmc1_clk,	"bus-mmc1",	"ahb1",
302 		      0x060, BIT(9), 0);
303 static SUNXI_CCU_GATE(bus_mmc2_clk,	"bus-mmc2",	"ahb1",
304 		      0x060, BIT(10), 0);
305 static SUNXI_CCU_GATE(bus_nand_clk,	"bus-nand",	"ahb1",
306 		      0x060, BIT(13), 0);
307 static SUNXI_CCU_GATE(bus_dram_clk,	"bus-dram",	"ahb1",
308 		      0x060, BIT(14), 0);
309 static SUNXI_CCU_GATE(bus_emac_clk,	"bus-emac",	"ahb2",
310 		      0x060, BIT(17), 0);
311 static SUNXI_CCU_GATE(bus_ts_clk,	"bus-ts",	"ahb1",
312 		      0x060, BIT(18), 0);
313 static SUNXI_CCU_GATE(bus_hstimer_clk,	"bus-hstimer",	"ahb1",
314 		      0x060, BIT(19), 0);
315 static SUNXI_CCU_GATE(bus_spi0_clk,	"bus-spi0",	"ahb1",
316 		      0x060, BIT(20), 0);
317 static SUNXI_CCU_GATE(bus_spi1_clk,	"bus-spi1",	"ahb1",
318 		      0x060, BIT(21), 0);
319 static SUNXI_CCU_GATE(bus_otg_clk,	"bus-otg",	"ahb1",
320 		      0x060, BIT(23), 0);
321 static SUNXI_CCU_GATE(bus_ehci0_clk,	"bus-ehci0",	"ahb1",
322 		      0x060, BIT(24), 0);
323 static SUNXI_CCU_GATE(bus_ehci1_clk,	"bus-ehci1",	"ahb2",
324 		      0x060, BIT(25), 0);
325 static SUNXI_CCU_GATE(bus_ohci0_clk,	"bus-ohci0",	"ahb1",
326 		      0x060, BIT(28), 0);
327 static SUNXI_CCU_GATE(bus_ohci1_clk,	"bus-ohci1",	"ahb2",
328 		      0x060, BIT(29), 0);
329 
330 static SUNXI_CCU_GATE(bus_ve_clk,	"bus-ve",	"ahb1",
331 		      0x064, BIT(0), 0);
332 static SUNXI_CCU_GATE(bus_tcon0_clk,	"bus-tcon0",	"ahb1",
333 		      0x064, BIT(3), 0);
334 static SUNXI_CCU_GATE(bus_tcon1_clk,	"bus-tcon1",	"ahb1",
335 		      0x064, BIT(4), 0);
336 static SUNXI_CCU_GATE(bus_deinterlace_clk,	"bus-deinterlace",	"ahb1",
337 		      0x064, BIT(5), 0);
338 static SUNXI_CCU_GATE(bus_csi_clk,	"bus-csi",	"ahb1",
339 		      0x064, BIT(8), 0);
340 static SUNXI_CCU_GATE(bus_hdmi_clk,	"bus-hdmi",	"ahb1",
341 		      0x064, BIT(11), 0);
342 static SUNXI_CCU_GATE(bus_de_clk,	"bus-de",	"ahb1",
343 		      0x064, BIT(12), 0);
344 static SUNXI_CCU_GATE(bus_gpu_clk,	"bus-gpu",	"ahb1",
345 		      0x064, BIT(20), 0);
346 static SUNXI_CCU_GATE(bus_msgbox_clk,	"bus-msgbox",	"ahb1",
347 		      0x064, BIT(21), 0);
348 static SUNXI_CCU_GATE(bus_spinlock_clk,	"bus-spinlock",	"ahb1",
349 		      0x064, BIT(22), 0);
350 
351 static SUNXI_CCU_GATE(bus_codec_clk,	"bus-codec",	"apb1",
352 		      0x068, BIT(0), 0);
353 static SUNXI_CCU_GATE(bus_spdif_clk,	"bus-spdif",	"apb1",
354 		      0x068, BIT(1), 0);
355 static SUNXI_CCU_GATE(bus_pio_clk,	"bus-pio",	"apb1",
356 		      0x068, BIT(5), 0);
357 static SUNXI_CCU_GATE(bus_ths_clk,	"bus-ths",	"apb1",
358 		      0x068, BIT(8), 0);
359 static SUNXI_CCU_GATE(bus_i2s0_clk,	"bus-i2s0",	"apb1",
360 		      0x068, BIT(12), 0);
361 static SUNXI_CCU_GATE(bus_i2s1_clk,	"bus-i2s1",	"apb1",
362 		      0x068, BIT(13), 0);
363 static SUNXI_CCU_GATE(bus_i2s2_clk,	"bus-i2s2",	"apb1",
364 		      0x068, BIT(14), 0);
365 
366 static SUNXI_CCU_GATE(bus_i2c0_clk,	"bus-i2c0",	"apb2",
367 		      0x06c, BIT(0), 0);
368 static SUNXI_CCU_GATE(bus_i2c1_clk,	"bus-i2c1",	"apb2",
369 		      0x06c, BIT(1), 0);
370 static SUNXI_CCU_GATE(bus_i2c2_clk,	"bus-i2c2",	"apb2",
371 		      0x06c, BIT(2), 0);
372 static SUNXI_CCU_GATE(bus_scr_clk,	"bus-scr",	"apb2",
373 		      0x06c, BIT(5), 0);
374 static SUNXI_CCU_GATE(bus_uart0_clk,	"bus-uart0",	"apb2",
375 		      0x06c, BIT(16), 0);
376 static SUNXI_CCU_GATE(bus_uart1_clk,	"bus-uart1",	"apb2",
377 		      0x06c, BIT(17), 0);
378 static SUNXI_CCU_GATE(bus_uart2_clk,	"bus-uart2",	"apb2",
379 		      0x06c, BIT(18), 0);
380 static SUNXI_CCU_GATE(bus_uart3_clk,	"bus-uart3",	"apb2",
381 		      0x06c, BIT(19), 0);
382 static SUNXI_CCU_GATE(bus_uart4_clk,	"bus-uart4",	"apb2",
383 		      0x06c, BIT(20), 0);
384 
385 static SUNXI_CCU_GATE(bus_dbg_clk,	"bus-dbg",	"ahb1",
386 		      0x070, BIT(7), 0);
387 
388 static struct clk_div_table ths_div_table[] = {
389 	{ .val = 0, .div = 1 },
390 	{ .val = 1, .div = 2 },
391 	{ .val = 2, .div = 4 },
392 	{ .val = 3, .div = 6 },
393 	{ /* Sentinel */ },
394 };
395 static const char * const ths_parents[] = { "osc24M" };
396 static struct ccu_div ths_clk = {
397 	.enable	= BIT(31),
398 	.div	= _SUNXI_CCU_DIV_TABLE(0, 2, ths_div_table),
399 	.mux	= _SUNXI_CCU_MUX(24, 2),
400 	.common	= {
401 		.reg		= 0x074,
402 		.hw.init	= CLK_HW_INIT_PARENTS("ths",
403 						      ths_parents,
404 						      &ccu_div_ops,
405 						      0),
406 	},
407 };
408 
409 static const char * const mod0_default_parents[] = { "osc24M", "pll-periph0",
410 						     "pll-periph1" };
411 static SUNXI_CCU_MP_WITH_MUX_GATE(nand_clk, "nand", mod0_default_parents, 0x080,
412 				  0, 4,		/* M */
413 				  16, 2,	/* P */
414 				  24, 2,	/* mux */
415 				  BIT(31),	/* gate */
416 				  0);
417 
418 /*
419  * MMC clocks are the new timing mode (see A83T & H3) variety, but without
420  * the mode switch. This means they have a 2x post divider between the clock
421  * and the MMC module. This is not documented in the manual, but is taken
422  * into consideration when setting the mmc module clocks in the BSP kernel.
423  * Without it, MMC performance is degraded.
424  *
425  * We model it here to be consistent with other SoCs supporting this mode.
426  * The alternative would be to add the 2x multiplier when setting the MMC
427  * module clock in the MMC driver, just for the A64.
428  */
429 static const char * const mmc_default_parents[] = { "osc24M", "pll-periph0-2x",
430 						    "pll-periph1-2x" };
431 static SUNXI_CCU_MP_WITH_MUX_GATE_POSTDIV(mmc0_clk, "mmc0",
432 					  mmc_default_parents, 0x088,
433 					  0, 4,		/* M */
434 					  16, 2,	/* P */
435 					  24, 2,	/* mux */
436 					  BIT(31),	/* gate */
437 					  2,		/* post-div */
438 					  0);
439 
440 static SUNXI_CCU_MP_WITH_MUX_GATE_POSTDIV(mmc1_clk, "mmc1",
441 					  mmc_default_parents, 0x08c,
442 					  0, 4,		/* M */
443 					  16, 2,	/* P */
444 					  24, 2,	/* mux */
445 					  BIT(31),	/* gate */
446 					  2,		/* post-div */
447 					  0);
448 
449 static SUNXI_CCU_MP_WITH_MUX_GATE_POSTDIV(mmc2_clk, "mmc2",
450 					  mmc_default_parents, 0x090,
451 					  0, 4,		/* M */
452 					  16, 2,	/* P */
453 					  24, 2,	/* mux */
454 					  BIT(31),	/* gate */
455 					  2,		/* post-div */
456 					  0);
457 
458 static const char * const ts_parents[] = { "osc24M", "pll-periph0", };
459 static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", ts_parents, 0x098,
460 				  0, 4,		/* M */
461 				  16, 2,	/* P */
462 				  24, 4,	/* mux */
463 				  BIT(31),	/* gate */
464 				  0);
465 
466 static SUNXI_CCU_MP_WITH_MUX_GATE(ce_clk, "ce", mmc_default_parents, 0x09c,
467 				  0, 4,		/* M */
468 				  16, 2,	/* P */
469 				  24, 2,	/* mux */
470 				  BIT(31),	/* gate */
471 				  0);
472 
473 static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
474 				  0, 4,		/* M */
475 				  16, 2,	/* P */
476 				  24, 2,	/* mux */
477 				  BIT(31),	/* gate */
478 				  0);
479 
480 static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents, 0x0a4,
481 				  0, 4,		/* M */
482 				  16, 2,	/* P */
483 				  24, 2,	/* mux */
484 				  BIT(31),	/* gate */
485 				  0);
486 
487 static const char * const i2s_parents[] = { "pll-audio-8x", "pll-audio-4x",
488 					    "pll-audio-2x", "pll-audio" };
489 static SUNXI_CCU_MUX_WITH_GATE(i2s0_clk, "i2s0", i2s_parents,
490 			       0x0b0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
491 
492 static SUNXI_CCU_MUX_WITH_GATE(i2s1_clk, "i2s1", i2s_parents,
493 			       0x0b4, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
494 
495 static SUNXI_CCU_MUX_WITH_GATE(i2s2_clk, "i2s2", i2s_parents,
496 			       0x0b8, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
497 
498 static SUNXI_CCU_M_WITH_GATE(spdif_clk, "spdif", "pll-audio",
499 			     0x0c0, 0, 4, BIT(31), CLK_SET_RATE_PARENT);
500 
501 static SUNXI_CCU_GATE(usb_phy0_clk,	"usb-phy0",	"osc24M",
502 		      0x0cc, BIT(8), 0);
503 static SUNXI_CCU_GATE(usb_phy1_clk,	"usb-phy1",	"osc24M",
504 		      0x0cc, BIT(9), 0);
505 static SUNXI_CCU_GATE(usb_hsic_clk,	"usb-hsic",	"pll-hsic",
506 		      0x0cc, BIT(10), 0);
507 static SUNXI_CCU_GATE(usb_hsic_12m_clk,	"usb-hsic-12M",	"osc12M",
508 		      0x0cc, BIT(11), 0);
509 static SUNXI_CCU_GATE(usb_ohci0_clk,	"usb-ohci0",	"osc12M",
510 		      0x0cc, BIT(16), 0);
511 static SUNXI_CCU_GATE(usb_ohci1_clk,	"usb-ohci1",	"usb-ohci0",
512 		      0x0cc, BIT(17), 0);
513 
514 static const char * const dram_parents[] = { "pll-ddr0", "pll-ddr1" };
515 static SUNXI_CCU_M_WITH_MUX(dram_clk, "dram", dram_parents,
516 			    0x0f4, 0, 4, 20, 2, CLK_IS_CRITICAL);
517 
518 static SUNXI_CCU_GATE(dram_ve_clk,	"dram-ve",	"dram",
519 		      0x100, BIT(0), 0);
520 static SUNXI_CCU_GATE(dram_csi_clk,	"dram-csi",	"dram",
521 		      0x100, BIT(1), 0);
522 static SUNXI_CCU_GATE(dram_deinterlace_clk,	"dram-deinterlace",	"dram",
523 		      0x100, BIT(2), 0);
524 static SUNXI_CCU_GATE(dram_ts_clk,	"dram-ts",	"dram",
525 		      0x100, BIT(3), 0);
526 
527 static const char * const de_parents[] = { "pll-periph0-2x", "pll-de" };
528 static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents,
529 				 0x104, 0, 4, 24, 3, BIT(31),
530 				 CLK_SET_RATE_PARENT);
531 
532 /*
533  * DSI output seems to work only when PLL_MIPI selected. Set it and prevent
534  * the mux from reparenting.
535  */
536 #define SUN50I_A64_TCON0_CLK_REG	0x118
537 
538 static const char * const tcon0_parents[] = { "pll-mipi", "pll-video0-2x" };
539 static const u8 tcon0_table[] = { 0, 2, };
540 static SUNXI_CCU_MUX_TABLE_WITH_GATE(tcon0_clk, "tcon0", tcon0_parents,
541 				     tcon0_table, 0x118, 24, 3, BIT(31),
542 				     CLK_SET_RATE_PARENT |
543 				     CLK_SET_RATE_NO_REPARENT);
544 
545 static const char * const tcon1_parents[] = { "pll-video0", "pll-video1" };
546 static const u8 tcon1_table[] = { 0, 2, };
547 static struct ccu_div tcon1_clk = {
548 	.enable		= BIT(31),
549 	.div		= _SUNXI_CCU_DIV(0, 4),
550 	.mux		= _SUNXI_CCU_MUX_TABLE(24, 2, tcon1_table),
551 	.common		= {
552 		.reg		= 0x11c,
553 		.hw.init	= CLK_HW_INIT_PARENTS("tcon1",
554 						      tcon1_parents,
555 						      &ccu_div_ops,
556 						      CLK_SET_RATE_PARENT),
557 	},
558 };
559 
560 static const char * const deinterlace_parents[] = { "pll-periph0", "pll-periph1" };
561 static SUNXI_CCU_M_WITH_MUX_GATE(deinterlace_clk, "deinterlace", deinterlace_parents,
562 				 0x124, 0, 4, 24, 3, BIT(31), 0);
563 
564 static SUNXI_CCU_GATE(csi_misc_clk,	"csi-misc",	"osc24M",
565 		      0x130, BIT(31), 0);
566 
567 static const char * const csi_sclk_parents[] = { "pll-periph0", "pll-periph1" };
568 static SUNXI_CCU_M_WITH_MUX_GATE(csi_sclk_clk, "csi-sclk", csi_sclk_parents,
569 				 0x134, 16, 4, 24, 3, BIT(31), 0);
570 
571 static const char * const csi_mclk_parents[] = { "osc24M", "pll-video1", "pll-periph1" };
572 static SUNXI_CCU_M_WITH_MUX_GATE(csi_mclk_clk, "csi-mclk", csi_mclk_parents,
573 				 0x134, 0, 5, 8, 3, BIT(15), 0);
574 
575 static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve",
576 			     0x13c, 16, 3, BIT(31), CLK_SET_RATE_PARENT);
577 
578 static SUNXI_CCU_GATE(ac_dig_clk,	"ac-dig",	"pll-audio",
579 		      0x140, BIT(31), CLK_SET_RATE_PARENT);
580 
581 static SUNXI_CCU_GATE(ac_dig_4x_clk,	"ac-dig-4x",	"pll-audio-4x",
582 		      0x140, BIT(30), CLK_SET_RATE_PARENT);
583 
584 static SUNXI_CCU_GATE(avs_clk,		"avs",		"osc24M",
585 		      0x144, BIT(31), 0);
586 
587 static const char * const hdmi_parents[] = { "pll-video0", "pll-video1" };
588 static SUNXI_CCU_M_WITH_MUX_GATE(hdmi_clk, "hdmi", hdmi_parents,
589 				 0x150, 0, 4, 24, 2, BIT(31), CLK_SET_RATE_PARENT);
590 
591 static SUNXI_CCU_GATE(hdmi_ddc_clk,	"hdmi-ddc",	"osc24M",
592 		      0x154, BIT(31), 0);
593 
594 static const char * const mbus_parents[] = { "osc24M", "pll-periph0-2x",
595 						 "pll-ddr0", "pll-ddr1" };
596 static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents,
597 				 0x15c, 0, 3, 24, 2, BIT(31), CLK_IS_CRITICAL);
598 
599 static const char * const dsi_dphy_parents[] = { "pll-video0", "pll-periph0" };
600 static const u8 dsi_dphy_table[] = { 0, 2, };
601 static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(dsi_dphy_clk, "dsi-dphy",
602 				       dsi_dphy_parents, dsi_dphy_table,
603 				       0x168, 0, 4, 8, 2, BIT(15), CLK_SET_RATE_PARENT);
604 
605 static SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu",
606 			     0x1a0, 0, 3, BIT(31), CLK_SET_RATE_PARENT);
607 
608 /* Fixed Factor clocks */
609 static CLK_FIXED_FACTOR_FW_NAME(osc12M_clk, "osc12M", "hosc", 2, 1, 0);
610 
611 static const struct clk_hw *clk_parent_pll_audio[] = {
612 	&pll_audio_base_clk.common.hw
613 };
614 
615 /* We hardcode the divider to 1 for now */
616 static CLK_FIXED_FACTOR_HWS(pll_audio_clk, "pll-audio",
617 			    clk_parent_pll_audio,
618 			    1, 1, CLK_SET_RATE_PARENT);
619 static CLK_FIXED_FACTOR_HWS(pll_audio_2x_clk, "pll-audio-2x",
620 			    clk_parent_pll_audio,
621 			    2, 1, CLK_SET_RATE_PARENT);
622 static CLK_FIXED_FACTOR_HWS(pll_audio_4x_clk, "pll-audio-4x",
623 			    clk_parent_pll_audio,
624 			    1, 1, CLK_SET_RATE_PARENT);
625 static CLK_FIXED_FACTOR_HWS(pll_audio_8x_clk, "pll-audio-8x",
626 			    clk_parent_pll_audio,
627 			    1, 2, CLK_SET_RATE_PARENT);
628 static CLK_FIXED_FACTOR_HW(pll_periph0_2x_clk, "pll-periph0-2x",
629 			   &pll_periph0_clk.common.hw,
630 			   1, 2, 0);
631 static CLK_FIXED_FACTOR_HW(pll_periph1_2x_clk, "pll-periph1-2x",
632 			   &pll_periph1_clk.common.hw,
633 			   1, 2, 0);
634 static CLK_FIXED_FACTOR_HW(pll_video0_2x_clk, "pll-video0-2x",
635 			   &pll_video0_clk.common.hw,
636 			   1, 2, CLK_SET_RATE_PARENT);
637 
638 static struct ccu_common *sun50i_a64_ccu_clks[] = {
639 	&pll_cpux_clk.common,
640 	&pll_audio_base_clk.common,
641 	&pll_video0_clk.common,
642 	&pll_ve_clk.common,
643 	&pll_ddr0_clk.common,
644 	&pll_periph0_clk.common,
645 	&pll_periph1_clk.common,
646 	&pll_video1_clk.common,
647 	&pll_gpu_clk.common,
648 	&pll_mipi_clk.common,
649 	&pll_hsic_clk.common,
650 	&pll_de_clk.common,
651 	&pll_ddr1_clk.common,
652 	&cpux_clk.common,
653 	&axi_clk.common,
654 	&ahb1_clk.common,
655 	&apb1_clk.common,
656 	&apb2_clk.common,
657 	&ahb2_clk.common,
658 	&bus_mipi_dsi_clk.common,
659 	&bus_ce_clk.common,
660 	&bus_dma_clk.common,
661 	&bus_mmc0_clk.common,
662 	&bus_mmc1_clk.common,
663 	&bus_mmc2_clk.common,
664 	&bus_nand_clk.common,
665 	&bus_dram_clk.common,
666 	&bus_emac_clk.common,
667 	&bus_ts_clk.common,
668 	&bus_hstimer_clk.common,
669 	&bus_spi0_clk.common,
670 	&bus_spi1_clk.common,
671 	&bus_otg_clk.common,
672 	&bus_ehci0_clk.common,
673 	&bus_ehci1_clk.common,
674 	&bus_ohci0_clk.common,
675 	&bus_ohci1_clk.common,
676 	&bus_ve_clk.common,
677 	&bus_tcon0_clk.common,
678 	&bus_tcon1_clk.common,
679 	&bus_deinterlace_clk.common,
680 	&bus_csi_clk.common,
681 	&bus_hdmi_clk.common,
682 	&bus_de_clk.common,
683 	&bus_gpu_clk.common,
684 	&bus_msgbox_clk.common,
685 	&bus_spinlock_clk.common,
686 	&bus_codec_clk.common,
687 	&bus_spdif_clk.common,
688 	&bus_pio_clk.common,
689 	&bus_ths_clk.common,
690 	&bus_i2s0_clk.common,
691 	&bus_i2s1_clk.common,
692 	&bus_i2s2_clk.common,
693 	&bus_i2c0_clk.common,
694 	&bus_i2c1_clk.common,
695 	&bus_i2c2_clk.common,
696 	&bus_scr_clk.common,
697 	&bus_uart0_clk.common,
698 	&bus_uart1_clk.common,
699 	&bus_uart2_clk.common,
700 	&bus_uart3_clk.common,
701 	&bus_uart4_clk.common,
702 	&bus_dbg_clk.common,
703 	&ths_clk.common,
704 	&nand_clk.common,
705 	&mmc0_clk.common,
706 	&mmc1_clk.common,
707 	&mmc2_clk.common,
708 	&ts_clk.common,
709 	&ce_clk.common,
710 	&spi0_clk.common,
711 	&spi1_clk.common,
712 	&i2s0_clk.common,
713 	&i2s1_clk.common,
714 	&i2s2_clk.common,
715 	&spdif_clk.common,
716 	&usb_phy0_clk.common,
717 	&usb_phy1_clk.common,
718 	&usb_hsic_clk.common,
719 	&usb_hsic_12m_clk.common,
720 	&usb_ohci0_clk.common,
721 	&usb_ohci1_clk.common,
722 	&dram_clk.common,
723 	&dram_ve_clk.common,
724 	&dram_csi_clk.common,
725 	&dram_deinterlace_clk.common,
726 	&dram_ts_clk.common,
727 	&de_clk.common,
728 	&tcon0_clk.common,
729 	&tcon1_clk.common,
730 	&deinterlace_clk.common,
731 	&csi_misc_clk.common,
732 	&csi_sclk_clk.common,
733 	&csi_mclk_clk.common,
734 	&ve_clk.common,
735 	&ac_dig_clk.common,
736 	&ac_dig_4x_clk.common,
737 	&avs_clk.common,
738 	&hdmi_clk.common,
739 	&hdmi_ddc_clk.common,
740 	&mbus_clk.common,
741 	&dsi_dphy_clk.common,
742 	&gpu_clk.common,
743 };
744 
745 static struct clk_hw_onecell_data sun50i_a64_hw_clks = {
746 	.hws	= {
747 		[CLK_OSC_12M]		= &osc12M_clk.hw,
748 		[CLK_PLL_CPUX]		= &pll_cpux_clk.common.hw,
749 		[CLK_PLL_AUDIO_BASE]	= &pll_audio_base_clk.common.hw,
750 		[CLK_PLL_AUDIO]		= &pll_audio_clk.hw,
751 		[CLK_PLL_AUDIO_2X]	= &pll_audio_2x_clk.hw,
752 		[CLK_PLL_AUDIO_4X]	= &pll_audio_4x_clk.hw,
753 		[CLK_PLL_AUDIO_8X]	= &pll_audio_8x_clk.hw,
754 		[CLK_PLL_VIDEO0]	= &pll_video0_clk.common.hw,
755 		[CLK_PLL_VIDEO0_2X]	= &pll_video0_2x_clk.hw,
756 		[CLK_PLL_VE]		= &pll_ve_clk.common.hw,
757 		[CLK_PLL_DDR0]		= &pll_ddr0_clk.common.hw,
758 		[CLK_PLL_PERIPH0]	= &pll_periph0_clk.common.hw,
759 		[CLK_PLL_PERIPH0_2X]	= &pll_periph0_2x_clk.hw,
760 		[CLK_PLL_PERIPH1]	= &pll_periph1_clk.common.hw,
761 		[CLK_PLL_PERIPH1_2X]	= &pll_periph1_2x_clk.hw,
762 		[CLK_PLL_VIDEO1]	= &pll_video1_clk.common.hw,
763 		[CLK_PLL_GPU]		= &pll_gpu_clk.common.hw,
764 		[CLK_PLL_MIPI]  	= &pll_mipi_clk.common.hw,
765 		[CLK_PLL_HSIC]		= &pll_hsic_clk.common.hw,
766 		[CLK_PLL_DE]		= &pll_de_clk.common.hw,
767 		[CLK_PLL_DDR1]		= &pll_ddr1_clk.common.hw,
768 		[CLK_CPUX]		= &cpux_clk.common.hw,
769 		[CLK_AXI]		= &axi_clk.common.hw,
770 		[CLK_AHB1]		= &ahb1_clk.common.hw,
771 		[CLK_APB1]		= &apb1_clk.common.hw,
772 		[CLK_APB2]		= &apb2_clk.common.hw,
773 		[CLK_AHB2]		= &ahb2_clk.common.hw,
774 		[CLK_BUS_MIPI_DSI]	= &bus_mipi_dsi_clk.common.hw,
775 		[CLK_BUS_CE]		= &bus_ce_clk.common.hw,
776 		[CLK_BUS_DMA]		= &bus_dma_clk.common.hw,
777 		[CLK_BUS_MMC0]		= &bus_mmc0_clk.common.hw,
778 		[CLK_BUS_MMC1]		= &bus_mmc1_clk.common.hw,
779 		[CLK_BUS_MMC2]		= &bus_mmc2_clk.common.hw,
780 		[CLK_BUS_NAND]		= &bus_nand_clk.common.hw,
781 		[CLK_BUS_DRAM]		= &bus_dram_clk.common.hw,
782 		[CLK_BUS_EMAC]		= &bus_emac_clk.common.hw,
783 		[CLK_BUS_TS]		= &bus_ts_clk.common.hw,
784 		[CLK_BUS_HSTIMER]	= &bus_hstimer_clk.common.hw,
785 		[CLK_BUS_SPI0]		= &bus_spi0_clk.common.hw,
786 		[CLK_BUS_SPI1]		= &bus_spi1_clk.common.hw,
787 		[CLK_BUS_OTG]		= &bus_otg_clk.common.hw,
788 		[CLK_BUS_EHCI0]		= &bus_ehci0_clk.common.hw,
789 		[CLK_BUS_EHCI1]		= &bus_ehci1_clk.common.hw,
790 		[CLK_BUS_OHCI0]		= &bus_ohci0_clk.common.hw,
791 		[CLK_BUS_OHCI1]		= &bus_ohci1_clk.common.hw,
792 		[CLK_BUS_VE]		= &bus_ve_clk.common.hw,
793 		[CLK_BUS_TCON0]		= &bus_tcon0_clk.common.hw,
794 		[CLK_BUS_TCON1]		= &bus_tcon1_clk.common.hw,
795 		[CLK_BUS_DEINTERLACE]	= &bus_deinterlace_clk.common.hw,
796 		[CLK_BUS_CSI]		= &bus_csi_clk.common.hw,
797 		[CLK_BUS_HDMI]		= &bus_hdmi_clk.common.hw,
798 		[CLK_BUS_DE]		= &bus_de_clk.common.hw,
799 		[CLK_BUS_GPU]		= &bus_gpu_clk.common.hw,
800 		[CLK_BUS_MSGBOX]	= &bus_msgbox_clk.common.hw,
801 		[CLK_BUS_SPINLOCK]	= &bus_spinlock_clk.common.hw,
802 		[CLK_BUS_CODEC]		= &bus_codec_clk.common.hw,
803 		[CLK_BUS_SPDIF]		= &bus_spdif_clk.common.hw,
804 		[CLK_BUS_PIO]		= &bus_pio_clk.common.hw,
805 		[CLK_BUS_THS]		= &bus_ths_clk.common.hw,
806 		[CLK_BUS_I2S0]		= &bus_i2s0_clk.common.hw,
807 		[CLK_BUS_I2S1]		= &bus_i2s1_clk.common.hw,
808 		[CLK_BUS_I2S2]		= &bus_i2s2_clk.common.hw,
809 		[CLK_BUS_I2C0]		= &bus_i2c0_clk.common.hw,
810 		[CLK_BUS_I2C1]		= &bus_i2c1_clk.common.hw,
811 		[CLK_BUS_I2C2]		= &bus_i2c2_clk.common.hw,
812 		[CLK_BUS_UART0]		= &bus_uart0_clk.common.hw,
813 		[CLK_BUS_UART1]		= &bus_uart1_clk.common.hw,
814 		[CLK_BUS_UART2]		= &bus_uart2_clk.common.hw,
815 		[CLK_BUS_UART3]		= &bus_uart3_clk.common.hw,
816 		[CLK_BUS_UART4]		= &bus_uart4_clk.common.hw,
817 		[CLK_BUS_SCR]		= &bus_scr_clk.common.hw,
818 		[CLK_BUS_DBG]		= &bus_dbg_clk.common.hw,
819 		[CLK_THS]		= &ths_clk.common.hw,
820 		[CLK_NAND]		= &nand_clk.common.hw,
821 		[CLK_MMC0]		= &mmc0_clk.common.hw,
822 		[CLK_MMC1]		= &mmc1_clk.common.hw,
823 		[CLK_MMC2]		= &mmc2_clk.common.hw,
824 		[CLK_TS]		= &ts_clk.common.hw,
825 		[CLK_CE]		= &ce_clk.common.hw,
826 		[CLK_SPI0]		= &spi0_clk.common.hw,
827 		[CLK_SPI1]		= &spi1_clk.common.hw,
828 		[CLK_I2S0]		= &i2s0_clk.common.hw,
829 		[CLK_I2S1]		= &i2s1_clk.common.hw,
830 		[CLK_I2S2]		= &i2s2_clk.common.hw,
831 		[CLK_SPDIF]		= &spdif_clk.common.hw,
832 		[CLK_USB_PHY0]		= &usb_phy0_clk.common.hw,
833 		[CLK_USB_PHY1]		= &usb_phy1_clk.common.hw,
834 		[CLK_USB_HSIC]		= &usb_hsic_clk.common.hw,
835 		[CLK_USB_HSIC_12M]	= &usb_hsic_12m_clk.common.hw,
836 		[CLK_USB_OHCI0]		= &usb_ohci0_clk.common.hw,
837 		[CLK_USB_OHCI1]		= &usb_ohci1_clk.common.hw,
838 		[CLK_DRAM]		= &dram_clk.common.hw,
839 		[CLK_DRAM_VE]		= &dram_ve_clk.common.hw,
840 		[CLK_DRAM_CSI]		= &dram_csi_clk.common.hw,
841 		[CLK_DRAM_DEINTERLACE]	= &dram_deinterlace_clk.common.hw,
842 		[CLK_DRAM_TS]		= &dram_ts_clk.common.hw,
843 		[CLK_DE]		= &de_clk.common.hw,
844 		[CLK_TCON0]		= &tcon0_clk.common.hw,
845 		[CLK_TCON1]		= &tcon1_clk.common.hw,
846 		[CLK_DEINTERLACE]	= &deinterlace_clk.common.hw,
847 		[CLK_CSI_MISC]		= &csi_misc_clk.common.hw,
848 		[CLK_CSI_SCLK]		= &csi_sclk_clk.common.hw,
849 		[CLK_CSI_MCLK]		= &csi_mclk_clk.common.hw,
850 		[CLK_VE]		= &ve_clk.common.hw,
851 		[CLK_AC_DIG]		= &ac_dig_clk.common.hw,
852 		[CLK_AC_DIG_4X]		= &ac_dig_4x_clk.common.hw,
853 		[CLK_AVS]		= &avs_clk.common.hw,
854 		[CLK_HDMI]		= &hdmi_clk.common.hw,
855 		[CLK_HDMI_DDC]		= &hdmi_ddc_clk.common.hw,
856 		[CLK_MBUS]		= &mbus_clk.common.hw,
857 		[CLK_DSI_DPHY]		= &dsi_dphy_clk.common.hw,
858 		[CLK_GPU]		= &gpu_clk.common.hw,
859 	},
860 	.num	= CLK_NUMBER,
861 };
862 
863 static struct ccu_reset_map sun50i_a64_ccu_resets[] = {
864 	[RST_USB_PHY0]		=  { 0x0cc, BIT(0) },
865 	[RST_USB_PHY1]		=  { 0x0cc, BIT(1) },
866 	[RST_USB_HSIC]		=  { 0x0cc, BIT(2) },
867 
868 	[RST_DRAM]		=  { 0x0f4, BIT(31) },
869 	[RST_MBUS]		=  { 0x0fc, BIT(31) },
870 
871 	[RST_BUS_MIPI_DSI]	=  { 0x2c0, BIT(1) },
872 	[RST_BUS_CE]		=  { 0x2c0, BIT(5) },
873 	[RST_BUS_DMA]		=  { 0x2c0, BIT(6) },
874 	[RST_BUS_MMC0]		=  { 0x2c0, BIT(8) },
875 	[RST_BUS_MMC1]		=  { 0x2c0, BIT(9) },
876 	[RST_BUS_MMC2]		=  { 0x2c0, BIT(10) },
877 	[RST_BUS_NAND]		=  { 0x2c0, BIT(13) },
878 	[RST_BUS_DRAM]		=  { 0x2c0, BIT(14) },
879 	[RST_BUS_EMAC]		=  { 0x2c0, BIT(17) },
880 	[RST_BUS_TS]		=  { 0x2c0, BIT(18) },
881 	[RST_BUS_HSTIMER]	=  { 0x2c0, BIT(19) },
882 	[RST_BUS_SPI0]		=  { 0x2c0, BIT(20) },
883 	[RST_BUS_SPI1]		=  { 0x2c0, BIT(21) },
884 	[RST_BUS_OTG]		=  { 0x2c0, BIT(23) },
885 	[RST_BUS_EHCI0]		=  { 0x2c0, BIT(24) },
886 	[RST_BUS_EHCI1]		=  { 0x2c0, BIT(25) },
887 	[RST_BUS_OHCI0]		=  { 0x2c0, BIT(28) },
888 	[RST_BUS_OHCI1]		=  { 0x2c0, BIT(29) },
889 
890 	[RST_BUS_VE]		=  { 0x2c4, BIT(0) },
891 	[RST_BUS_TCON0]		=  { 0x2c4, BIT(3) },
892 	[RST_BUS_TCON1]		=  { 0x2c4, BIT(4) },
893 	[RST_BUS_DEINTERLACE]	=  { 0x2c4, BIT(5) },
894 	[RST_BUS_CSI]		=  { 0x2c4, BIT(8) },
895 	[RST_BUS_HDMI0]		=  { 0x2c4, BIT(10) },
896 	[RST_BUS_HDMI1]		=  { 0x2c4, BIT(11) },
897 	[RST_BUS_DE]		=  { 0x2c4, BIT(12) },
898 	[RST_BUS_GPU]		=  { 0x2c4, BIT(20) },
899 	[RST_BUS_MSGBOX]	=  { 0x2c4, BIT(21) },
900 	[RST_BUS_SPINLOCK]	=  { 0x2c4, BIT(22) },
901 	[RST_BUS_DBG]		=  { 0x2c4, BIT(31) },
902 
903 	[RST_BUS_LVDS]		=  { 0x2c8, BIT(0) },
904 
905 	[RST_BUS_CODEC]		=  { 0x2d0, BIT(0) },
906 	[RST_BUS_SPDIF]		=  { 0x2d0, BIT(1) },
907 	[RST_BUS_THS]		=  { 0x2d0, BIT(8) },
908 	[RST_BUS_I2S0]		=  { 0x2d0, BIT(12) },
909 	[RST_BUS_I2S1]		=  { 0x2d0, BIT(13) },
910 	[RST_BUS_I2S2]		=  { 0x2d0, BIT(14) },
911 
912 	[RST_BUS_I2C0]		=  { 0x2d8, BIT(0) },
913 	[RST_BUS_I2C1]		=  { 0x2d8, BIT(1) },
914 	[RST_BUS_I2C2]		=  { 0x2d8, BIT(2) },
915 	[RST_BUS_SCR]		=  { 0x2d8, BIT(5) },
916 	[RST_BUS_UART0]		=  { 0x2d8, BIT(16) },
917 	[RST_BUS_UART1]		=  { 0x2d8, BIT(17) },
918 	[RST_BUS_UART2]		=  { 0x2d8, BIT(18) },
919 	[RST_BUS_UART3]		=  { 0x2d8, BIT(19) },
920 	[RST_BUS_UART4]		=  { 0x2d8, BIT(20) },
921 };
922 
923 static const struct sunxi_ccu_desc sun50i_a64_ccu_desc = {
924 	.ccu_clks	= sun50i_a64_ccu_clks,
925 	.num_ccu_clks	= ARRAY_SIZE(sun50i_a64_ccu_clks),
926 
927 	.hw_clks	= &sun50i_a64_hw_clks,
928 
929 	.resets		= sun50i_a64_ccu_resets,
930 	.num_resets	= ARRAY_SIZE(sun50i_a64_ccu_resets),
931 };
932 
933 static struct ccu_pll_nb sun50i_a64_pll_cpu_nb = {
934 	.common	= &pll_cpux_clk.common,
935 	/* copy from pll_cpux_clk */
936 	.enable	= BIT(31),
937 	.lock	= BIT(28),
938 };
939 
940 static struct ccu_mux_nb sun50i_a64_cpu_nb = {
941 	.common		= &cpux_clk.common,
942 	.cm		= &cpux_clk.mux,
943 	.delay_us	= 1, /* > 8 clock cycles at 24 MHz */
944 	.bypass_index	= 1, /* index of 24 MHz oscillator */
945 };
946 
947 static int sun50i_a64_ccu_probe(struct platform_device *pdev)
948 {
949 	void __iomem *reg;
950 	u32 val;
951 	int ret;
952 
953 	reg = devm_platform_ioremap_resource(pdev, 0);
954 	if (IS_ERR(reg))
955 		return PTR_ERR(reg);
956 
957 	/* Force the PLL-Audio-1x divider to 1 */
958 	val = readl(reg + SUN50I_A64_PLL_AUDIO_REG);
959 	val &= ~GENMASK(19, 16);
960 	writel(val | (0 << 16), reg + SUN50I_A64_PLL_AUDIO_REG);
961 
962 	writel(0x515, reg + SUN50I_A64_PLL_MIPI_REG);
963 
964 	/* Set PLL MIPI as parent for TCON0 */
965 	val = readl(reg + SUN50I_A64_TCON0_CLK_REG);
966 	val &= ~GENMASK(26, 24);
967 	writel(val | (0 << 24), reg + SUN50I_A64_TCON0_CLK_REG);
968 
969 	ret = devm_sunxi_ccu_probe(&pdev->dev, reg, &sun50i_a64_ccu_desc);
970 	if (ret)
971 		return ret;
972 
973 	/* Gate then ungate PLL CPU after any rate changes */
974 	ccu_pll_notifier_register(&sun50i_a64_pll_cpu_nb);
975 
976 	/* Reparent CPU during PLL CPU rate changes */
977 	ccu_mux_notifier_register(pll_cpux_clk.common.hw.clk,
978 				  &sun50i_a64_cpu_nb);
979 
980 	return 0;
981 }
982 
983 static const struct of_device_id sun50i_a64_ccu_ids[] = {
984 	{ .compatible = "allwinner,sun50i-a64-ccu" },
985 	{ }
986 };
987 
988 static struct platform_driver sun50i_a64_ccu_driver = {
989 	.probe	= sun50i_a64_ccu_probe,
990 	.driver	= {
991 		.name	= "sun50i-a64-ccu",
992 		.suppress_bind_attrs = true,
993 		.of_match_table	= sun50i_a64_ccu_ids,
994 	},
995 };
996 module_platform_driver(sun50i_a64_ccu_driver);
997 
998 MODULE_IMPORT_NS(SUNXI_CCU);
999 MODULE_LICENSE("GPL");
1000