xref: /openbmc/linux/drivers/clk/sunxi-ng/ccu-sun8i-r40.c (revision c7b305267eb77fe47498676e9337324c9653494c)
19c92ab61SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2cd030a78SIcenowy Zheng /*
3cd030a78SIcenowy Zheng  * Copyright (c) 2017 Icenowy Zheng <icenowy@aosc.io>
4cd030a78SIcenowy Zheng  */
5cd030a78SIcenowy Zheng 
6cd030a78SIcenowy Zheng #include <linux/clk-provider.h>
762e59c4eSStephen Boyd #include <linux/io.h>
8c3bf29f6SIcenowy Zheng #include <linux/platform_device.h>
9c3bf29f6SIcenowy Zheng #include <linux/regmap.h>
10cd030a78SIcenowy Zheng 
11cd030a78SIcenowy Zheng #include "ccu_common.h"
12cd030a78SIcenowy Zheng #include "ccu_reset.h"
13cd030a78SIcenowy Zheng 
14cd030a78SIcenowy Zheng #include "ccu_div.h"
15cd030a78SIcenowy Zheng #include "ccu_gate.h"
16cd030a78SIcenowy Zheng #include "ccu_mp.h"
17cd030a78SIcenowy Zheng #include "ccu_mult.h"
18cd030a78SIcenowy Zheng #include "ccu_nk.h"
19cd030a78SIcenowy Zheng #include "ccu_nkm.h"
20cd030a78SIcenowy Zheng #include "ccu_nkmp.h"
21cd030a78SIcenowy Zheng #include "ccu_nm.h"
22cd030a78SIcenowy Zheng #include "ccu_phase.h"
23cd030a78SIcenowy Zheng 
24cd030a78SIcenowy Zheng #include "ccu-sun8i-r40.h"
25cd030a78SIcenowy Zheng 
26cd030a78SIcenowy Zheng /* TODO: The result of N*K is required to be in [10, 88] range. */
27cd030a78SIcenowy Zheng static struct ccu_nkmp pll_cpu_clk = {
28cd030a78SIcenowy Zheng 	.enable		= BIT(31),
29cd030a78SIcenowy Zheng 	.lock		= BIT(28),
30cd030a78SIcenowy Zheng 	.n		= _SUNXI_CCU_MULT(8, 5),
31cd030a78SIcenowy Zheng 	.k		= _SUNXI_CCU_MULT(4, 2),
32cd030a78SIcenowy Zheng 	.m		= _SUNXI_CCU_DIV(0, 2),
33cd030a78SIcenowy Zheng 	.p		= _SUNXI_CCU_DIV_MAX(16, 2, 4),
34cd030a78SIcenowy Zheng 	.common		= {
35cd030a78SIcenowy Zheng 		.reg		= 0x000,
36cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT("pll-cpu",
37cd030a78SIcenowy Zheng 					      "osc24M",
38cd030a78SIcenowy Zheng 					      &ccu_nkmp_ops,
39cd030a78SIcenowy Zheng 					      CLK_SET_RATE_UNGATE),
40cd030a78SIcenowy Zheng 	},
41cd030a78SIcenowy Zheng };
42cd030a78SIcenowy Zheng 
43cd030a78SIcenowy Zheng /*
44cd030a78SIcenowy Zheng  * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
45cd030a78SIcenowy Zheng  * the base (2x, 4x and 8x), and one variable divider (the one true
46cd030a78SIcenowy Zheng  * pll audio).
47cd030a78SIcenowy Zheng  *
48cd030a78SIcenowy Zheng  * We don't have any need for the variable divider for now, so we just
49cd030a78SIcenowy Zheng  * hardcode it to match with the clock names
50cd030a78SIcenowy Zheng  */
51cd030a78SIcenowy Zheng #define SUN8I_R40_PLL_AUDIO_REG	0x008
52cd030a78SIcenowy Zheng 
53cd030a78SIcenowy Zheng static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
54cd030a78SIcenowy Zheng 				   "osc24M", 0x008,
55cd030a78SIcenowy Zheng 				   8, 7,	/* N */
56cd030a78SIcenowy Zheng 				   0, 5,	/* M */
57cd030a78SIcenowy Zheng 				   BIT(31),	/* gate */
58cd030a78SIcenowy Zheng 				   BIT(28),	/* lock */
59cd030a78SIcenowy Zheng 				   CLK_SET_RATE_UNGATE);
60cd030a78SIcenowy Zheng 
61b16fb669SJernej Skrabec static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video0_clk, "pll-video0",
62cd030a78SIcenowy Zheng 						"osc24M", 0x0010,
6324a95f75SJernej Skrabec 						192000000,  /* Minimum rate */
64b16fb669SJernej Skrabec 						1008000000, /* Maximum rate */
65cd030a78SIcenowy Zheng 						8, 7,       /* N */
66cd030a78SIcenowy Zheng 						0, 4,       /* M */
67cd030a78SIcenowy Zheng 						BIT(24),    /* frac enable */
68cd030a78SIcenowy Zheng 						BIT(25),    /* frac select */
69cd030a78SIcenowy Zheng 						270000000,  /* frac rate 0 */
70cd030a78SIcenowy Zheng 						297000000,  /* frac rate 1 */
71cd030a78SIcenowy Zheng 						BIT(31),    /* gate */
72cd030a78SIcenowy Zheng 						BIT(28),    /* lock */
73cd030a78SIcenowy Zheng 						CLK_SET_RATE_UNGATE);
74cd030a78SIcenowy Zheng 
75cd030a78SIcenowy Zheng /* TODO: The result of N/M is required to be in [8, 25] range. */
76cd030a78SIcenowy Zheng static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve",
77cd030a78SIcenowy Zheng 					"osc24M", 0x0018,
78cd030a78SIcenowy Zheng 					8, 7,		/* N */
79cd030a78SIcenowy Zheng 					0, 4,		/* M */
80cd030a78SIcenowy Zheng 					BIT(24),	/* frac enable */
81cd030a78SIcenowy Zheng 					BIT(25),	/* frac select */
82cd030a78SIcenowy Zheng 					270000000,	/* frac rate 0 */
83cd030a78SIcenowy Zheng 					297000000,	/* frac rate 1 */
84cd030a78SIcenowy Zheng 					BIT(31),	/* gate */
85cd030a78SIcenowy Zheng 					BIT(28),	/* lock */
86cd030a78SIcenowy Zheng 					CLK_SET_RATE_UNGATE);
87cd030a78SIcenowy Zheng 
88cd030a78SIcenowy Zheng /* TODO: The result of N*K is required to be in [10, 77] range. */
89cd030a78SIcenowy Zheng static SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr0_clk, "pll-ddr0",
90cd030a78SIcenowy Zheng 				    "osc24M", 0x020,
91cd030a78SIcenowy Zheng 				    8, 5,	/* N */
92cd030a78SIcenowy Zheng 				    4, 2,	/* K */
93cd030a78SIcenowy Zheng 				    0, 2,	/* M */
94cd030a78SIcenowy Zheng 				    BIT(31),	/* gate */
95cd030a78SIcenowy Zheng 				    BIT(28),	/* lock */
96cd030a78SIcenowy Zheng 				    CLK_SET_RATE_UNGATE);
97cd030a78SIcenowy Zheng 
98cd030a78SIcenowy Zheng /* TODO: The result of N*K is required to be in [21, 58] range. */
99cd030a78SIcenowy Zheng static struct ccu_nk pll_periph0_clk = {
100cd030a78SIcenowy Zheng 	.enable		= BIT(31),
101cd030a78SIcenowy Zheng 	.lock		= BIT(28),
102cd030a78SIcenowy Zheng 	.n		= _SUNXI_CCU_MULT(8, 5),
103cd030a78SIcenowy Zheng 	.k		= _SUNXI_CCU_MULT(4, 2),
104cd030a78SIcenowy Zheng 	.fixed_post_div	= 2,
105cd030a78SIcenowy Zheng 	.common		= {
106cd030a78SIcenowy Zheng 		.reg		= 0x028,
107cd030a78SIcenowy Zheng 		.features	= CCU_FEATURE_FIXED_POSTDIV,
108cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT("pll-periph0", "osc24M",
109cd030a78SIcenowy Zheng 					      &ccu_nk_ops,
110cd030a78SIcenowy Zheng 					      CLK_SET_RATE_UNGATE),
111cd030a78SIcenowy Zheng 	},
112cd030a78SIcenowy Zheng };
113cd030a78SIcenowy Zheng 
114cd030a78SIcenowy Zheng static struct ccu_div pll_periph0_sata_clk = {
115cd030a78SIcenowy Zheng 	.enable		= BIT(24),
116cd030a78SIcenowy Zheng 	.div		= _SUNXI_CCU_DIV(0, 2),
117cd030a78SIcenowy Zheng 	/*
118cd030a78SIcenowy Zheng 	 * The formula of pll-periph0 (1x) is 24MHz*N*K/2, and the formula
119cd030a78SIcenowy Zheng 	 * of pll-periph0-sata is 24MHz*N*K/M/6, so the postdiv here is
120cd030a78SIcenowy Zheng 	 * 6/2 = 3.
121cd030a78SIcenowy Zheng 	 */
122cd030a78SIcenowy Zheng 	.fixed_post_div	= 3,
123cd030a78SIcenowy Zheng 	.common		= {
124cd030a78SIcenowy Zheng 		.reg		= 0x028,
125cd030a78SIcenowy Zheng 		.features	= CCU_FEATURE_FIXED_POSTDIV,
126cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT("pll-periph0-sata",
127cd030a78SIcenowy Zheng 					      "pll-periph0",
128cd030a78SIcenowy Zheng 					      &ccu_div_ops, 0),
129cd030a78SIcenowy Zheng 	},
130cd030a78SIcenowy Zheng };
131cd030a78SIcenowy Zheng 
132cd030a78SIcenowy Zheng /* TODO: The result of N*K is required to be in [21, 58] range. */
133cd030a78SIcenowy Zheng static struct ccu_nk pll_periph1_clk = {
134cd030a78SIcenowy Zheng 	.enable		= BIT(31),
135cd030a78SIcenowy Zheng 	.lock		= BIT(28),
136cd030a78SIcenowy Zheng 	.n		= _SUNXI_CCU_MULT(8, 5),
137cd030a78SIcenowy Zheng 	.k		= _SUNXI_CCU_MULT(4, 2),
138cd030a78SIcenowy Zheng 	.fixed_post_div	= 2,
139cd030a78SIcenowy Zheng 	.common		= {
140cd030a78SIcenowy Zheng 		.reg		= 0x02c,
141cd030a78SIcenowy Zheng 		.features	= CCU_FEATURE_FIXED_POSTDIV,
142cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT("pll-periph1", "osc24M",
143cd030a78SIcenowy Zheng 					      &ccu_nk_ops,
144cd030a78SIcenowy Zheng 					      CLK_SET_RATE_UNGATE),
145cd030a78SIcenowy Zheng 	},
146cd030a78SIcenowy Zheng };
147cd030a78SIcenowy Zheng 
148b16fb669SJernej Skrabec static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video1_clk, "pll-video1",
149cd030a78SIcenowy Zheng 						"osc24M", 0x030,
15024a95f75SJernej Skrabec 						192000000,  /* Minimum rate */
151b16fb669SJernej Skrabec 						1008000000, /* Maximum rate */
152cd030a78SIcenowy Zheng 						8, 7,       /* N */
153cd030a78SIcenowy Zheng 						0, 4,       /* M */
154cd030a78SIcenowy Zheng 						BIT(24),    /* frac enable */
155cd030a78SIcenowy Zheng 						BIT(25),    /* frac select */
156cd030a78SIcenowy Zheng 						270000000,  /* frac rate 0 */
157cd030a78SIcenowy Zheng 						297000000,  /* frac rate 1 */
158cd030a78SIcenowy Zheng 						BIT(31),    /* gate */
159cd030a78SIcenowy Zheng 						BIT(28),    /* lock */
160cd030a78SIcenowy Zheng 						CLK_SET_RATE_UNGATE);
161cd030a78SIcenowy Zheng 
162cd030a78SIcenowy Zheng static struct ccu_nkm pll_sata_clk = {
163cd030a78SIcenowy Zheng 	.enable		= BIT(31),
164cd030a78SIcenowy Zheng 	.lock		= BIT(28),
165cd030a78SIcenowy Zheng 	.n		= _SUNXI_CCU_MULT(8, 5),
166cd030a78SIcenowy Zheng 	.k		= _SUNXI_CCU_MULT(4, 2),
167cd030a78SIcenowy Zheng 	.m		= _SUNXI_CCU_DIV(0, 2),
168cd030a78SIcenowy Zheng 	.fixed_post_div	= 6,
169cd030a78SIcenowy Zheng 	.common		= {
170cd030a78SIcenowy Zheng 		.reg		= 0x034,
171cd030a78SIcenowy Zheng 		.features	= CCU_FEATURE_FIXED_POSTDIV,
172cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT("pll-sata", "osc24M",
173cd030a78SIcenowy Zheng 					      &ccu_nkm_ops,
174cd030a78SIcenowy Zheng 					      CLK_SET_RATE_UNGATE),
175cd030a78SIcenowy Zheng 	},
176cd030a78SIcenowy Zheng };
177cd030a78SIcenowy Zheng 
178cd030a78SIcenowy Zheng static const char * const pll_sata_out_parents[] = { "pll-sata",
179cd030a78SIcenowy Zheng 						     "pll-periph0-sata" };
180cd030a78SIcenowy Zheng static SUNXI_CCU_MUX_WITH_GATE(pll_sata_out_clk, "pll-sata-out",
181cd030a78SIcenowy Zheng 			       pll_sata_out_parents, 0x034,
182cd030a78SIcenowy Zheng 			       30, 1,	/* mux */
183cd030a78SIcenowy Zheng 			       BIT(14),	/* gate */
184cd030a78SIcenowy Zheng 			       CLK_SET_RATE_PARENT);
185cd030a78SIcenowy Zheng 
186cd030a78SIcenowy Zheng /* TODO: The result of N/M is required to be in [8, 25] range. */
187cd030a78SIcenowy Zheng static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_gpu_clk, "pll-gpu",
188cd030a78SIcenowy Zheng 					"osc24M", 0x038,
189cd030a78SIcenowy Zheng 					8, 7,		/* N */
190cd030a78SIcenowy Zheng 					0, 4,		/* M */
191cd030a78SIcenowy Zheng 					BIT(24),	/* frac enable */
192cd030a78SIcenowy Zheng 					BIT(25),	/* frac select */
193cd030a78SIcenowy Zheng 					270000000,	/* frac rate 0 */
194cd030a78SIcenowy Zheng 					297000000,	/* frac rate 1 */
195cd030a78SIcenowy Zheng 					BIT(31),	/* gate */
196cd030a78SIcenowy Zheng 					BIT(28),	/* lock */
197cd030a78SIcenowy Zheng 					CLK_SET_RATE_UNGATE);
198cd030a78SIcenowy Zheng 
199cd030a78SIcenowy Zheng /*
200cd030a78SIcenowy Zheng  * The MIPI PLL has 2 modes: "MIPI" and "HDMI".
201cd030a78SIcenowy Zheng  *
202cd030a78SIcenowy Zheng  * The MIPI mode is a standard NKM-style clock. The HDMI mode is an
203cd030a78SIcenowy Zheng  * integer / fractional clock with switchable multipliers and dividers.
204cd030a78SIcenowy Zheng  * This is not supported here. We hardcode the PLL to MIPI mode.
205cd030a78SIcenowy Zheng  *
206cd030a78SIcenowy Zheng  * TODO: In the MIPI mode, M/N is required to be equal or lesser than 3,
207cd030a78SIcenowy Zheng  * which cannot be implemented now.
208cd030a78SIcenowy Zheng  */
209cd030a78SIcenowy Zheng #define SUN8I_R40_PLL_MIPI_REG	0x040
210cd030a78SIcenowy Zheng 
211cd030a78SIcenowy Zheng static const char * const pll_mipi_parents[] = { "pll-video0" };
212cd030a78SIcenowy Zheng static struct ccu_nkm pll_mipi_clk = {
213cd030a78SIcenowy Zheng 	.enable	= BIT(31) | BIT(23) | BIT(22),
214cd030a78SIcenowy Zheng 	.lock	= BIT(28),
215cd030a78SIcenowy Zheng 	.n	= _SUNXI_CCU_MULT(8, 4),
216cd030a78SIcenowy Zheng 	.k	= _SUNXI_CCU_MULT_MIN(4, 2, 2),
217cd030a78SIcenowy Zheng 	.m	= _SUNXI_CCU_DIV(0, 4),
218cd030a78SIcenowy Zheng 	.mux	= _SUNXI_CCU_MUX(21, 1),
219cd030a78SIcenowy Zheng 	.common	= {
220cd030a78SIcenowy Zheng 		.reg		= 0x040,
221cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT_PARENTS("pll-mipi",
222cd030a78SIcenowy Zheng 						      pll_mipi_parents,
223cd030a78SIcenowy Zheng 						      &ccu_nkm_ops,
224cd030a78SIcenowy Zheng 						      CLK_SET_RATE_UNGATE)
225cd030a78SIcenowy Zheng 	},
226cd030a78SIcenowy Zheng };
227cd030a78SIcenowy Zheng 
228cd030a78SIcenowy Zheng /* TODO: The result of N/M is required to be in [8, 25] range. */
229cd030a78SIcenowy Zheng static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_de_clk, "pll-de",
230cd030a78SIcenowy Zheng 					"osc24M", 0x048,
231cd030a78SIcenowy Zheng 					8, 7,		/* N */
232cd030a78SIcenowy Zheng 					0, 4,		/* M */
233cd030a78SIcenowy Zheng 					BIT(24),	/* frac enable */
234cd030a78SIcenowy Zheng 					BIT(25),	/* frac select */
235cd030a78SIcenowy Zheng 					270000000,	/* frac rate 0 */
236cd030a78SIcenowy Zheng 					297000000,	/* frac rate 1 */
237cd030a78SIcenowy Zheng 					BIT(31),	/* gate */
238cd030a78SIcenowy Zheng 					BIT(28),	/* lock */
239cd030a78SIcenowy Zheng 					CLK_SET_RATE_UNGATE);
240cd030a78SIcenowy Zheng 
241cd030a78SIcenowy Zheng /* TODO: The N factor is required to be in [16, 75] range. */
242cd030a78SIcenowy Zheng static SUNXI_CCU_NM_WITH_GATE_LOCK(pll_ddr1_clk, "pll-ddr1",
243cd030a78SIcenowy Zheng 				   "osc24M", 0x04c,
244cd030a78SIcenowy Zheng 				   8, 7,	/* N */
245cd030a78SIcenowy Zheng 				   0, 2,	/* M */
246cd030a78SIcenowy Zheng 				   BIT(31),	/* gate */
247cd030a78SIcenowy Zheng 				   BIT(28),	/* lock */
248cd030a78SIcenowy Zheng 				   CLK_SET_RATE_UNGATE);
249cd030a78SIcenowy Zheng 
250cd030a78SIcenowy Zheng static const char * const cpu_parents[] = { "osc32k", "osc24M",
251cd030a78SIcenowy Zheng 					     "pll-cpu", "pll-cpu" };
252cd030a78SIcenowy Zheng static SUNXI_CCU_MUX(cpu_clk, "cpu", cpu_parents,
253cd030a78SIcenowy Zheng 		     0x050, 16, 2, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT);
254cd030a78SIcenowy Zheng 
255cd030a78SIcenowy Zheng static SUNXI_CCU_M(axi_clk, "axi", "cpu", 0x050, 0, 2, 0);
256cd030a78SIcenowy Zheng 
257cd030a78SIcenowy Zheng static const char * const ahb1_parents[] = { "osc32k", "osc24M",
258cd030a78SIcenowy Zheng 					     "axi", "pll-periph0" };
259cd030a78SIcenowy Zheng static const struct ccu_mux_var_prediv ahb1_predivs[] = {
260cd030a78SIcenowy Zheng 	{ .index = 3, .shift = 6, .width = 2 },
261cd030a78SIcenowy Zheng };
262cd030a78SIcenowy Zheng static struct ccu_div ahb1_clk = {
263cd030a78SIcenowy Zheng 	.div		= _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
264cd030a78SIcenowy Zheng 
265cd030a78SIcenowy Zheng 	.mux		= {
266cd030a78SIcenowy Zheng 		.shift	= 12,
267cd030a78SIcenowy Zheng 		.width	= 2,
268cd030a78SIcenowy Zheng 
269cd030a78SIcenowy Zheng 		.var_predivs	= ahb1_predivs,
270cd030a78SIcenowy Zheng 		.n_var_predivs	= ARRAY_SIZE(ahb1_predivs),
271cd030a78SIcenowy Zheng 	},
272cd030a78SIcenowy Zheng 
273cd030a78SIcenowy Zheng 	.common		= {
274cd030a78SIcenowy Zheng 		.reg		= 0x054,
275cd030a78SIcenowy Zheng 		.features	= CCU_FEATURE_VARIABLE_PREDIV,
276cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT_PARENTS("ahb1",
277cd030a78SIcenowy Zheng 						      ahb1_parents,
278cd030a78SIcenowy Zheng 						      &ccu_div_ops,
279cd030a78SIcenowy Zheng 						      0),
280cd030a78SIcenowy Zheng 	},
281cd030a78SIcenowy Zheng };
282cd030a78SIcenowy Zheng 
283cd030a78SIcenowy Zheng static struct clk_div_table apb1_div_table[] = {
284cd030a78SIcenowy Zheng 	{ .val = 0, .div = 2 },
285cd030a78SIcenowy Zheng 	{ .val = 1, .div = 2 },
286cd030a78SIcenowy Zheng 	{ .val = 2, .div = 4 },
287cd030a78SIcenowy Zheng 	{ .val = 3, .div = 8 },
288cd030a78SIcenowy Zheng 	{ /* Sentinel */ },
289cd030a78SIcenowy Zheng };
290cd030a78SIcenowy Zheng static SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1",
291cd030a78SIcenowy Zheng 			   0x054, 8, 2, apb1_div_table, 0);
292cd030a78SIcenowy Zheng 
293cd030a78SIcenowy Zheng static const char * const apb2_parents[] = { "osc32k", "osc24M",
294cd030a78SIcenowy Zheng 					     "pll-periph0-2x",
295cd030a78SIcenowy Zheng 					     "pll-periph0-2x" };
296cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058,
297cd030a78SIcenowy Zheng 			     0, 5,	/* M */
298cd030a78SIcenowy Zheng 			     16, 2,	/* P */
299cd030a78SIcenowy Zheng 			     24, 2,	/* mux */
300cd030a78SIcenowy Zheng 			     0);
301cd030a78SIcenowy Zheng 
302cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_mipi_dsi_clk,	"bus-mipi-dsi",	"ahb1",
303cd030a78SIcenowy Zheng 		      0x060, BIT(1), 0);
304cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ce_clk,	"bus-ce",	"ahb1",
305cd030a78SIcenowy Zheng 		      0x060, BIT(5), 0);
306cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_dma_clk,	"bus-dma",	"ahb1",
307cd030a78SIcenowy Zheng 		      0x060, BIT(6), 0);
308cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_mmc0_clk,	"bus-mmc0",	"ahb1",
309cd030a78SIcenowy Zheng 		      0x060, BIT(8), 0);
310cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_mmc1_clk,	"bus-mmc1",	"ahb1",
311cd030a78SIcenowy Zheng 		      0x060, BIT(9), 0);
312cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_mmc2_clk,	"bus-mmc2",	"ahb1",
313cd030a78SIcenowy Zheng 		      0x060, BIT(10), 0);
314cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_mmc3_clk,	"bus-mmc3",	"ahb1",
315cd030a78SIcenowy Zheng 		      0x060, BIT(11), 0);
316cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_nand_clk,	"bus-nand",	"ahb1",
317cd030a78SIcenowy Zheng 		      0x060, BIT(13), 0);
318cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_dram_clk,	"bus-dram",	"ahb1",
319cd030a78SIcenowy Zheng 		      0x060, BIT(14), 0);
320cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_emac_clk,	"bus-emac",	"ahb1",
321cd030a78SIcenowy Zheng 		      0x060, BIT(17), 0);
322cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ts_clk,	"bus-ts",	"ahb1",
323cd030a78SIcenowy Zheng 		      0x060, BIT(18), 0);
324cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_hstimer_clk,	"bus-hstimer",	"ahb1",
325cd030a78SIcenowy Zheng 		      0x060, BIT(19), 0);
326cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_spi0_clk,	"bus-spi0",	"ahb1",
327cd030a78SIcenowy Zheng 		      0x060, BIT(20), 0);
328cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_spi1_clk,	"bus-spi1",	"ahb1",
329cd030a78SIcenowy Zheng 		      0x060, BIT(21), 0);
330cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_spi2_clk,	"bus-spi2",	"ahb1",
331cd030a78SIcenowy Zheng 		      0x060, BIT(22), 0);
332cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_spi3_clk,	"bus-spi3",	"ahb1",
333cd030a78SIcenowy Zheng 		      0x060, BIT(23), 0);
334cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_sata_clk,	"bus-sata",	"ahb1",
335cd030a78SIcenowy Zheng 		      0x060, BIT(24), 0);
336cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_otg_clk,	"bus-otg",	"ahb1",
337cd030a78SIcenowy Zheng 		      0x060, BIT(25), 0);
338cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ehci0_clk,	"bus-ehci0",	"ahb1",
339cd030a78SIcenowy Zheng 		      0x060, BIT(26), 0);
340cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ehci1_clk,	"bus-ehci1",	"ahb1",
341cd030a78SIcenowy Zheng 		      0x060, BIT(27), 0);
342cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ehci2_clk,	"bus-ehci2",	"ahb1",
343cd030a78SIcenowy Zheng 		      0x060, BIT(28), 0);
344cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ohci0_clk,	"bus-ohci0",	"ahb1",
345cd030a78SIcenowy Zheng 		      0x060, BIT(29), 0);
346cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ohci1_clk,	"bus-ohci1",	"ahb1",
347cd030a78SIcenowy Zheng 		      0x060, BIT(30), 0);
348cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ohci2_clk,	"bus-ohci2",	"ahb1",
349cd030a78SIcenowy Zheng 		      0x060, BIT(31), 0);
350cd030a78SIcenowy Zheng 
351cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ve_clk,	"bus-ve",	"ahb1",
352cd030a78SIcenowy Zheng 		      0x064, BIT(0), 0);
353cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_mp_clk,	"bus-mp",	"ahb1",
354cd030a78SIcenowy Zheng 		      0x064, BIT(2), 0);
355cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_deinterlace_clk,	"bus-deinterlace",	"ahb1",
356cd030a78SIcenowy Zheng 		      0x064, BIT(5), 0);
357cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_csi0_clk,	"bus-csi0",	"ahb1",
358cd030a78SIcenowy Zheng 		      0x064, BIT(8), 0);
359cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_csi1_clk,	"bus-csi1",	"ahb1",
360cd030a78SIcenowy Zheng 		      0x064, BIT(9), 0);
361cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_hdmi0_clk,	"bus-hdmi0",	"ahb1",
362cd030a78SIcenowy Zheng 		      0x064, BIT(10), 0);
363cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_hdmi1_clk,	"bus-hdmi1",	"ahb1",
364cd030a78SIcenowy Zheng 		      0x064, BIT(11), 0);
365cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_de_clk,	"bus-de",	"ahb1",
366cd030a78SIcenowy Zheng 		      0x064, BIT(12), 0);
367cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tve0_clk,	"bus-tve0",	"ahb1",
368cd030a78SIcenowy Zheng 		      0x064, BIT(13), 0);
369cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tve1_clk,	"bus-tve1",	"ahb1",
370cd030a78SIcenowy Zheng 		      0x064, BIT(14), 0);
371cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tve_top_clk,	"bus-tve-top",	"ahb1",
372cd030a78SIcenowy Zheng 		      0x064, BIT(15), 0);
373cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_gmac_clk,	"bus-gmac",	"ahb1",
374cd030a78SIcenowy Zheng 		      0x064, BIT(17), 0);
375cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_gpu_clk,	"bus-gpu",	"ahb1",
376cd030a78SIcenowy Zheng 		      0x064, BIT(20), 0);
377cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tvd0_clk,	"bus-tvd0",	"ahb1",
378cd030a78SIcenowy Zheng 		      0x064, BIT(21), 0);
379cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tvd1_clk,	"bus-tvd1",	"ahb1",
380cd030a78SIcenowy Zheng 		      0x064, BIT(22), 0);
381cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tvd2_clk,	"bus-tvd2",	"ahb1",
382cd030a78SIcenowy Zheng 		      0x064, BIT(23), 0);
383cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tvd3_clk,	"bus-tvd3",	"ahb1",
384cd030a78SIcenowy Zheng 		      0x064, BIT(24), 0);
385cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tvd_top_clk,	"bus-tvd-top",	"ahb1",
386cd030a78SIcenowy Zheng 		      0x064, BIT(25), 0);
387cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tcon_lcd0_clk,	"bus-tcon-lcd0",	"ahb1",
388cd030a78SIcenowy Zheng 		      0x064, BIT(26), 0);
389cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tcon_lcd1_clk,	"bus-tcon-lcd1",	"ahb1",
390cd030a78SIcenowy Zheng 		      0x064, BIT(27), 0);
391cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tcon_tv0_clk,	"bus-tcon-tv0",	"ahb1",
392cd030a78SIcenowy Zheng 		      0x064, BIT(28), 0);
393cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tcon_tv1_clk,	"bus-tcon-tv1",	"ahb1",
394cd030a78SIcenowy Zheng 		      0x064, BIT(29), 0);
395cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_tcon_top_clk,	"bus-tcon-top",	"ahb1",
396cd030a78SIcenowy Zheng 		      0x064, BIT(30), 0);
397cd030a78SIcenowy Zheng 
398cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_codec_clk,	"bus-codec",	"apb1",
399cd030a78SIcenowy Zheng 		      0x068, BIT(0), 0);
400cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_spdif_clk,	"bus-spdif",	"apb1",
401cd030a78SIcenowy Zheng 		      0x068, BIT(1), 0);
402cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ac97_clk,	"bus-ac97",	"apb1",
403cd030a78SIcenowy Zheng 		      0x068, BIT(2), 0);
404cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_pio_clk,	"bus-pio",	"apb1",
405cd030a78SIcenowy Zheng 		      0x068, BIT(5), 0);
406cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ir0_clk,	"bus-ir0",	"apb1",
407cd030a78SIcenowy Zheng 		      0x068, BIT(6), 0);
408cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ir1_clk,	"bus-ir1",	"apb1",
409cd030a78SIcenowy Zheng 		      0x068, BIT(7), 0);
410cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ths_clk,	"bus-ths",	"apb1",
411cd030a78SIcenowy Zheng 		      0x068, BIT(8), 0);
412cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_keypad_clk,	"bus-keypad",	"apb1",
413cd030a78SIcenowy Zheng 		      0x068, BIT(10), 0);
414cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_i2s0_clk,	"bus-i2s0",	"apb1",
415cd030a78SIcenowy Zheng 		      0x068, BIT(12), 0);
416cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_i2s1_clk,	"bus-i2s1",	"apb1",
417cd030a78SIcenowy Zheng 		      0x068, BIT(13), 0);
418cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_i2s2_clk,	"bus-i2s2",	"apb1",
419cd030a78SIcenowy Zheng 		      0x068, BIT(14), 0);
420cd030a78SIcenowy Zheng 
421cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_i2c0_clk,	"bus-i2c0",	"apb2",
422cd030a78SIcenowy Zheng 		      0x06c, BIT(0), 0);
423cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_i2c1_clk,	"bus-i2c1",	"apb2",
424cd030a78SIcenowy Zheng 		      0x06c, BIT(1), 0);
425cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_i2c2_clk,	"bus-i2c2",	"apb2",
426cd030a78SIcenowy Zheng 		      0x06c, BIT(2), 0);
427cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_i2c3_clk,	"bus-i2c3",	"apb2",
428cd030a78SIcenowy Zheng 		      0x06c, BIT(3), 0);
429cd030a78SIcenowy Zheng /*
430cd030a78SIcenowy Zheng  * In datasheet here's "Reserved", however the gate exists in BSP soucre
431cd030a78SIcenowy Zheng  * code.
432cd030a78SIcenowy Zheng  */
433cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_can_clk,	"bus-can",	"apb2",
434cd030a78SIcenowy Zheng 		      0x06c, BIT(4), 0);
435cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_scr_clk,	"bus-scr",	"apb2",
436cd030a78SIcenowy Zheng 		      0x06c, BIT(5), 0);
437cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ps20_clk,	"bus-ps20",	"apb2",
438cd030a78SIcenowy Zheng 		      0x06c, BIT(6), 0);
439cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_ps21_clk,	"bus-ps21",	"apb2",
440cd030a78SIcenowy Zheng 		      0x06c, BIT(7), 0);
441cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_i2c4_clk,	"bus-i2c4",	"apb2",
442cd030a78SIcenowy Zheng 		      0x06c, BIT(15), 0);
443cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_uart0_clk,	"bus-uart0",	"apb2",
444cd030a78SIcenowy Zheng 		      0x06c, BIT(16), 0);
445cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_uart1_clk,	"bus-uart1",	"apb2",
446cd030a78SIcenowy Zheng 		      0x06c, BIT(17), 0);
447cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_uart2_clk,	"bus-uart2",	"apb2",
448cd030a78SIcenowy Zheng 		      0x06c, BIT(18), 0);
449cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_uart3_clk,	"bus-uart3",	"apb2",
450cd030a78SIcenowy Zheng 		      0x06c, BIT(19), 0);
451cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_uart4_clk,	"bus-uart4",	"apb2",
452cd030a78SIcenowy Zheng 		      0x06c, BIT(20), 0);
453cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_uart5_clk,	"bus-uart5",	"apb2",
454cd030a78SIcenowy Zheng 		      0x06c, BIT(21), 0);
455cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_uart6_clk,	"bus-uart6",	"apb2",
456cd030a78SIcenowy Zheng 		      0x06c, BIT(22), 0);
457cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_uart7_clk,	"bus-uart7",	"apb2",
458cd030a78SIcenowy Zheng 		      0x06c, BIT(23), 0);
459cd030a78SIcenowy Zheng 
460cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(bus_dbg_clk,	"bus-dbg",	"ahb1",
461cd030a78SIcenowy Zheng 		      0x070, BIT(7), 0);
462cd030a78SIcenowy Zheng 
463cd030a78SIcenowy Zheng static const char * const ths_parents[] = { "osc24M" };
464cd030a78SIcenowy Zheng static struct ccu_div ths_clk = {
465cd030a78SIcenowy Zheng 	.enable	= BIT(31),
466cd030a78SIcenowy Zheng 	.div	= _SUNXI_CCU_DIV_FLAGS(0, 2, CLK_DIVIDER_POWER_OF_TWO),
467cd030a78SIcenowy Zheng 	.mux	= _SUNXI_CCU_MUX(24, 2),
468cd030a78SIcenowy Zheng 	.common	= {
469cd030a78SIcenowy Zheng 		.reg		= 0x074,
470cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT_PARENTS("ths",
471cd030a78SIcenowy Zheng 						      ths_parents,
472cd030a78SIcenowy Zheng 						      &ccu_div_ops,
473cd030a78SIcenowy Zheng 						      0),
474cd030a78SIcenowy Zheng 	},
475cd030a78SIcenowy Zheng };
476cd030a78SIcenowy Zheng 
477cd030a78SIcenowy Zheng static const char * const mod0_default_parents[] = { "osc24M", "pll-periph0",
478cd030a78SIcenowy Zheng 						     "pll-periph1" };
479cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(nand_clk, "nand", mod0_default_parents, 0x080,
480cd030a78SIcenowy Zheng 				  0, 4,		/* M */
481cd030a78SIcenowy Zheng 				  16, 2,	/* P */
482cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
483cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
484cd030a78SIcenowy Zheng 				  0);
485cd030a78SIcenowy Zheng 
486cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents, 0x088,
487cd030a78SIcenowy Zheng 				  0, 4,		/* M */
488cd030a78SIcenowy Zheng 				  16, 2,	/* P */
489cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
490cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
491cd030a78SIcenowy Zheng 				  0);
492cd030a78SIcenowy Zheng 
493cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents, 0x08c,
494cd030a78SIcenowy Zheng 				  0, 4,		/* M */
495cd030a78SIcenowy Zheng 				  16, 2,	/* P */
496cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
497cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
498cd030a78SIcenowy Zheng 				  0);
499cd030a78SIcenowy Zheng 
500cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents, 0x090,
501cd030a78SIcenowy Zheng 				  0, 4,		/* M */
502cd030a78SIcenowy Zheng 				  16, 2,	/* P */
503cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
504cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
505cd030a78SIcenowy Zheng 				  0);
506cd030a78SIcenowy Zheng 
507cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(mmc3_clk, "mmc3", mod0_default_parents, 0x094,
508cd030a78SIcenowy Zheng 				  0, 4,		/* M */
509cd030a78SIcenowy Zheng 				  16, 2,	/* P */
510cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
511cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
512cd030a78SIcenowy Zheng 				  0);
513cd030a78SIcenowy Zheng 
514cd030a78SIcenowy Zheng static const char * const ts_parents[] = { "osc24M", "pll-periph0", };
515cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(ts_clk, "ts", ts_parents, 0x098,
516cd030a78SIcenowy Zheng 				  0, 4,		/* M */
517cd030a78SIcenowy Zheng 				  16, 2,	/* P */
518cd030a78SIcenowy Zheng 				  24, 4,	/* mux */
519cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
520cd030a78SIcenowy Zheng 				  0);
521cd030a78SIcenowy Zheng 
522cd030a78SIcenowy Zheng static const char * const ce_parents[] = { "osc24M", "pll-periph0-2x",
523cd030a78SIcenowy Zheng 					   "pll-periph1-2x" };
524cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(ce_clk, "ce", ce_parents, 0x09c,
525cd030a78SIcenowy Zheng 				  0, 4,		/* M */
526cd030a78SIcenowy Zheng 				  16, 2,	/* P */
527cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
528cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
529cd030a78SIcenowy Zheng 				  0);
530cd030a78SIcenowy Zheng 
531cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
532cd030a78SIcenowy Zheng 				  0, 4,		/* M */
533cd030a78SIcenowy Zheng 				  16, 2,	/* P */
534cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
535cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
536cd030a78SIcenowy Zheng 				  0);
537cd030a78SIcenowy Zheng 
538cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents, 0x0a4,
539cd030a78SIcenowy Zheng 				  0, 4,		/* M */
540cd030a78SIcenowy Zheng 				  16, 2,	/* P */
541cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
542cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
543cd030a78SIcenowy Zheng 				  0);
544cd030a78SIcenowy Zheng 
545cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(spi2_clk, "spi2", mod0_default_parents, 0x0a8,
546cd030a78SIcenowy Zheng 				  0, 4,		/* M */
547cd030a78SIcenowy Zheng 				  16, 2,	/* P */
548cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
549cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
550cd030a78SIcenowy Zheng 				  0);
551cd030a78SIcenowy Zheng 
552cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(spi3_clk, "spi3", mod0_default_parents, 0x0ac,
553cd030a78SIcenowy Zheng 				  0, 4,		/* M */
554cd030a78SIcenowy Zheng 				  16, 2,	/* P */
555cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
556cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
557cd030a78SIcenowy Zheng 				  0);
558cd030a78SIcenowy Zheng 
559cd030a78SIcenowy Zheng static const char * const i2s_parents[] = { "pll-audio-8x", "pll-audio-4x",
560cd030a78SIcenowy Zheng 					    "pll-audio-2x", "pll-audio" };
561cd030a78SIcenowy Zheng static SUNXI_CCU_MUX_WITH_GATE(i2s0_clk, "i2s0", i2s_parents,
562cd030a78SIcenowy Zheng 			       0x0b0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
563cd030a78SIcenowy Zheng 
564cd030a78SIcenowy Zheng static SUNXI_CCU_MUX_WITH_GATE(i2s1_clk, "i2s1", i2s_parents,
565cd030a78SIcenowy Zheng 			       0x0b4, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
566cd030a78SIcenowy Zheng 
567cd030a78SIcenowy Zheng static SUNXI_CCU_MUX_WITH_GATE(i2s2_clk, "i2s2", i2s_parents,
568cd030a78SIcenowy Zheng 			       0x0b8, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
569cd030a78SIcenowy Zheng 
570cd030a78SIcenowy Zheng static SUNXI_CCU_MUX_WITH_GATE(ac97_clk, "ac97", i2s_parents,
571cd030a78SIcenowy Zheng 			       0x0bc, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
572cd030a78SIcenowy Zheng 
573cd030a78SIcenowy Zheng static SUNXI_CCU_MUX_WITH_GATE(spdif_clk, "spdif", i2s_parents,
574cd030a78SIcenowy Zheng 			       0x0c0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
575cd030a78SIcenowy Zheng 
576cd030a78SIcenowy Zheng static const char * const keypad_parents[] = { "osc24M", "osc32k" };
577cd030a78SIcenowy Zheng static const u8 keypad_table[] = { 0, 2 };
578cd030a78SIcenowy Zheng static struct ccu_mp keypad_clk = {
579cd030a78SIcenowy Zheng 	.enable	= BIT(31),
580cd030a78SIcenowy Zheng 	.m	= _SUNXI_CCU_DIV(0, 5),
581cd030a78SIcenowy Zheng 	.p	= _SUNXI_CCU_DIV(16, 2),
582cd030a78SIcenowy Zheng 	.mux	= _SUNXI_CCU_MUX_TABLE(24, 2, keypad_table),
583cd030a78SIcenowy Zheng 	.common	= {
584cd030a78SIcenowy Zheng 		.reg		= 0x0c4,
585cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT_PARENTS("keypad",
586cd030a78SIcenowy Zheng 						      keypad_parents,
587cd030a78SIcenowy Zheng 						      &ccu_mp_ops,
588cd030a78SIcenowy Zheng 						      0),
589cd030a78SIcenowy Zheng 	}
590cd030a78SIcenowy Zheng };
591cd030a78SIcenowy Zheng 
592cd030a78SIcenowy Zheng static const char * const sata_parents[] = { "pll-sata-out", "sata-ext" };
593cd030a78SIcenowy Zheng static SUNXI_CCU_MUX_WITH_GATE(sata_clk, "sata", sata_parents,
594cd030a78SIcenowy Zheng 			       0x0c8, 24, 1, BIT(31), CLK_SET_RATE_PARENT);
595cd030a78SIcenowy Zheng 
596cd030a78SIcenowy Zheng /*
597cd030a78SIcenowy Zheng  * There are 3 OHCI 12M clock source selection bits in this register.
598cd030a78SIcenowy Zheng  * We will force them to 0 (12M divided from 48M).
599cd030a78SIcenowy Zheng  */
600cd030a78SIcenowy Zheng #define SUN8I_R40_USB_CLK_REG	0x0cc
601cd030a78SIcenowy Zheng 
602cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(usb_phy0_clk,	"usb-phy0",	"osc24M",
603cd030a78SIcenowy Zheng 		      0x0cc, BIT(8), 0);
604cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(usb_phy1_clk,	"usb-phy1",	"osc24M",
605cd030a78SIcenowy Zheng 		      0x0cc, BIT(9), 0);
606cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(usb_phy2_clk,	"usb-phy2",	"osc24M",
607cd030a78SIcenowy Zheng 		      0x0cc, BIT(10), 0);
608cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(usb_ohci0_clk,	"usb-ohci0",	"osc12M",
609cd030a78SIcenowy Zheng 		      0x0cc, BIT(16), 0);
610cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(usb_ohci1_clk,	"usb-ohci1",	"osc12M",
611cd030a78SIcenowy Zheng 		      0x0cc, BIT(17), 0);
612cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(usb_ohci2_clk,	"usb-ohci2",	"osc12M",
613cd030a78SIcenowy Zheng 		      0x0cc, BIT(18), 0);
614cd030a78SIcenowy Zheng 
615cd030a78SIcenowy Zheng static const char * const ir_parents[] = { "osc24M", "pll-periph0",
616cd030a78SIcenowy Zheng 					   "pll-periph1", "osc32k" };
617cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(ir0_clk, "ir0", ir_parents, 0x0d0,
618cd030a78SIcenowy Zheng 				  0, 4,		/* M */
619cd030a78SIcenowy Zheng 				  16, 2,	/* P */
620cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
621cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
622cd030a78SIcenowy Zheng 				  0);
623cd030a78SIcenowy Zheng 
624cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(ir1_clk, "ir1", ir_parents, 0x0d4,
625cd030a78SIcenowy Zheng 				  0, 4,		/* M */
626cd030a78SIcenowy Zheng 				  16, 2,	/* P */
627cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
628cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
629cd030a78SIcenowy Zheng 				  0);
630cd030a78SIcenowy Zheng 
631cd030a78SIcenowy Zheng static const char * const dram_parents[] = { "pll-ddr0", "pll-ddr1" };
632cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX(dram_clk, "dram", dram_parents,
633cd030a78SIcenowy Zheng 			    0x0f4, 0, 2, 20, 2, CLK_IS_CRITICAL);
634cd030a78SIcenowy Zheng 
635cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(dram_ve_clk,	"dram-ve",	"dram",
636cd030a78SIcenowy Zheng 		      0x100, BIT(0), 0);
637cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(dram_csi0_clk,	"dram-csi0",	"dram",
638cd030a78SIcenowy Zheng 		      0x100, BIT(1), 0);
639cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(dram_csi1_clk,	"dram-csi1",	"dram",
640cd030a78SIcenowy Zheng 		      0x100, BIT(2), 0);
641cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(dram_ts_clk,	"dram-ts",	"dram",
642cd030a78SIcenowy Zheng 		      0x100, BIT(3), 0);
643cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(dram_tvd_clk,	"dram-tvd",	"dram",
644cd030a78SIcenowy Zheng 		      0x100, BIT(4), 0);
645cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(dram_mp_clk,	"dram-mp",	"dram",
646cd030a78SIcenowy Zheng 		      0x100, BIT(5), 0);
647cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(dram_deinterlace_clk,	"dram-deinterlace",	"dram",
648cd030a78SIcenowy Zheng 		      0x100, BIT(6), 0);
649cd030a78SIcenowy Zheng 
650cd030a78SIcenowy Zheng static const char * const de_parents[] = { "pll-periph0-2x", "pll-de" };
651cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents,
652fb4aa0f6SJernej Skrabec 				 0x104, 0, 4, 24, 3, BIT(31),
653fb4aa0f6SJernej Skrabec 				 CLK_SET_RATE_PARENT);
654cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(mp_clk, "mp", de_parents,
655cd030a78SIcenowy Zheng 				 0x108, 0, 4, 24, 3, BIT(31), 0);
656cd030a78SIcenowy Zheng 
657cd030a78SIcenowy Zheng static const char * const tcon_parents[] = { "pll-video0", "pll-video1",
658cd030a78SIcenowy Zheng 					     "pll-video0-2x", "pll-video1-2x",
659cd030a78SIcenowy Zheng 					     "pll-mipi" };
660cd030a78SIcenowy Zheng static SUNXI_CCU_MUX_WITH_GATE(tcon_lcd0_clk, "tcon-lcd0", tcon_parents,
661cd030a78SIcenowy Zheng 			       0x110, 24, 3, BIT(31), CLK_SET_RATE_PARENT);
662cd030a78SIcenowy Zheng static SUNXI_CCU_MUX_WITH_GATE(tcon_lcd1_clk, "tcon-lcd1", tcon_parents,
663cd030a78SIcenowy Zheng 			       0x114, 24, 3, BIT(31), CLK_SET_RATE_PARENT);
664cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(tcon_tv0_clk, "tcon-tv0", tcon_parents,
665fb4aa0f6SJernej Skrabec 				 0x118, 0, 4, 24, 3, BIT(31),
666fb4aa0f6SJernej Skrabec 				 CLK_SET_RATE_PARENT);
667cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(tcon_tv1_clk, "tcon-tv1", tcon_parents,
668fb4aa0f6SJernej Skrabec 				 0x11c, 0, 4, 24, 3, BIT(31),
669fb4aa0f6SJernej Skrabec 				 CLK_SET_RATE_PARENT);
670cd030a78SIcenowy Zheng 
671cd030a78SIcenowy Zheng static const char * const deinterlace_parents[] = { "pll-periph0",
672cd030a78SIcenowy Zheng 						    "pll-periph1" };
673cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(deinterlace_clk, "deinterlace",
674cd030a78SIcenowy Zheng 				 deinterlace_parents, 0x124, 0, 4, 24, 3,
675cd030a78SIcenowy Zheng 				 BIT(31), 0);
676cd030a78SIcenowy Zheng 
677cd030a78SIcenowy Zheng static const char * const csi_mclk_parents[] = { "osc24M", "pll-video1",
678cd030a78SIcenowy Zheng 						 "pll-periph1" };
679cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(csi1_mclk_clk, "csi1-mclk", csi_mclk_parents,
680cd030a78SIcenowy Zheng 				 0x130, 0, 5, 8, 3, BIT(15), 0);
681cd030a78SIcenowy Zheng 
682cd030a78SIcenowy Zheng static const char * const csi_sclk_parents[] = { "pll-periph0", "pll-periph1" };
683cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(csi_sclk_clk, "csi-sclk", csi_sclk_parents,
684cd030a78SIcenowy Zheng 				 0x134, 16, 4, 24, 3, BIT(31), 0);
685cd030a78SIcenowy Zheng 
686cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(csi0_mclk_clk, "csi0-mclk", csi_mclk_parents,
687cd030a78SIcenowy Zheng 				 0x134, 0, 5, 8, 3, BIT(15), 0);
688cd030a78SIcenowy Zheng 
689cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve",
690cd030a78SIcenowy Zheng 			     0x13c, 16, 3, BIT(31), CLK_SET_RATE_PARENT);
691cd030a78SIcenowy Zheng 
692cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(codec_clk,	"codec",	"pll-audio",
693cd030a78SIcenowy Zheng 		      0x140, BIT(31), CLK_SET_RATE_PARENT);
694cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(avs_clk,		"avs",		"osc24M",
695cd030a78SIcenowy Zheng 		      0x144, BIT(31), 0);
696cd030a78SIcenowy Zheng 
697cd030a78SIcenowy Zheng static const char * const hdmi_parents[] = { "pll-video0", "pll-video1" };
698cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(hdmi_clk, "hdmi", hdmi_parents,
699fb4aa0f6SJernej Skrabec 				 0x150, 0, 4, 24, 2, BIT(31),
700fb4aa0f6SJernej Skrabec 				 CLK_SET_RATE_PARENT);
701cd030a78SIcenowy Zheng 
702cd030a78SIcenowy Zheng static SUNXI_CCU_GATE(hdmi_slow_clk,	"hdmi-slow",	"osc24M",
703cd030a78SIcenowy Zheng 		      0x154, BIT(31), 0);
704cd030a78SIcenowy Zheng 
705cd030a78SIcenowy Zheng /*
706cd030a78SIcenowy Zheng  * In the SoC's user manual, the P factor is mentioned, but not used in
707cd030a78SIcenowy Zheng  * the frequency formula.
708cd030a78SIcenowy Zheng  *
709cd030a78SIcenowy Zheng  * Here the factor is included, according to the BSP kernel source,
710cd030a78SIcenowy Zheng  * which contains the P factor of this clock.
711cd030a78SIcenowy Zheng  */
712cd030a78SIcenowy Zheng static const char * const mbus_parents[] = { "osc24M", "pll-periph0-2x",
713cd030a78SIcenowy Zheng 					     "pll-ddr0" };
714cd030a78SIcenowy Zheng static SUNXI_CCU_MP_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents, 0x15c,
715cd030a78SIcenowy Zheng 				  0, 4,		/* M */
716cd030a78SIcenowy Zheng 				  16, 2,	/* P */
717cd030a78SIcenowy Zheng 				  24, 2,	/* mux */
718cd030a78SIcenowy Zheng 				  BIT(31),	/* gate */
719cd030a78SIcenowy Zheng 				  CLK_IS_CRITICAL);
720cd030a78SIcenowy Zheng 
721cd030a78SIcenowy Zheng static const char * const dsi_dphy_parents[] = { "pll-video0", "pll-video1",
722cd030a78SIcenowy Zheng 						 "pll-periph0" };
723cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(dsi_dphy_clk, "dsi-dphy", dsi_dphy_parents,
724cd030a78SIcenowy Zheng 				 0x168, 0, 4, 8, 2, BIT(15), 0);
725cd030a78SIcenowy Zheng 
726cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(tve0_clk, "tve0", tcon_parents,
727cd030a78SIcenowy Zheng 				 0x180, 0, 4, 24, 3, BIT(31), 0);
728cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(tve1_clk, "tve1", tcon_parents,
729cd030a78SIcenowy Zheng 				 0x184, 0, 4, 24, 3, BIT(31), 0);
730cd030a78SIcenowy Zheng 
731cd030a78SIcenowy Zheng static const char * const tvd_parents[] = { "pll-video0", "pll-video1",
732cd030a78SIcenowy Zheng 					    "pll-video0-2x", "pll-video1-2x" };
733cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(tvd0_clk, "tvd0", tvd_parents,
734cd030a78SIcenowy Zheng 				 0x188, 0, 4, 24, 3, BIT(31), 0);
735cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(tvd1_clk, "tvd1", tvd_parents,
736cd030a78SIcenowy Zheng 				 0x18c, 0, 4, 24, 3, BIT(31), 0);
737cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(tvd2_clk, "tvd2", tvd_parents,
738cd030a78SIcenowy Zheng 				 0x190, 0, 4, 24, 3, BIT(31), 0);
739cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_MUX_GATE(tvd3_clk, "tvd3", tvd_parents,
740cd030a78SIcenowy Zheng 				 0x194, 0, 4, 24, 3, BIT(31), 0);
741cd030a78SIcenowy Zheng 
742cd030a78SIcenowy Zheng static SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu",
743cd030a78SIcenowy Zheng 			     0x1a0, 0, 3, BIT(31), CLK_SET_RATE_PARENT);
744cd030a78SIcenowy Zheng 
745cd030a78SIcenowy Zheng static const char * const out_parents[] = { "osc24M", "osc32k", "osc24M" };
746cd030a78SIcenowy Zheng static const struct ccu_mux_fixed_prediv out_predivs[] = {
747cd030a78SIcenowy Zheng 	{ .index = 0, .div = 750, },
748cd030a78SIcenowy Zheng };
749cd030a78SIcenowy Zheng 
750cd030a78SIcenowy Zheng static struct ccu_mp outa_clk = {
751cd030a78SIcenowy Zheng 	.enable	= BIT(31),
752cd030a78SIcenowy Zheng 	.m	= _SUNXI_CCU_DIV(8, 5),
753cd030a78SIcenowy Zheng 	.p	= _SUNXI_CCU_DIV(20, 2),
754cd030a78SIcenowy Zheng 	.mux	= {
755cd030a78SIcenowy Zheng 		.shift		= 24,
756cd030a78SIcenowy Zheng 		.width		= 2,
757cd030a78SIcenowy Zheng 		.fixed_predivs	= out_predivs,
758cd030a78SIcenowy Zheng 		.n_predivs	= ARRAY_SIZE(out_predivs),
759cd030a78SIcenowy Zheng 	},
760cd030a78SIcenowy Zheng 	.common	= {
761cd030a78SIcenowy Zheng 		.reg		= 0x1f0,
762cd030a78SIcenowy Zheng 		.features	= CCU_FEATURE_FIXED_PREDIV,
763cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT_PARENTS("outa", out_parents,
764*c7b30526SChen-Yu Tsai 						      &ccu_mp_ops,
765*c7b30526SChen-Yu Tsai 						      CLK_SET_RATE_PARENT),
766cd030a78SIcenowy Zheng 	}
767cd030a78SIcenowy Zheng };
768cd030a78SIcenowy Zheng 
769cd030a78SIcenowy Zheng static struct ccu_mp outb_clk = {
770cd030a78SIcenowy Zheng 	.enable	= BIT(31),
771cd030a78SIcenowy Zheng 	.m	= _SUNXI_CCU_DIV(8, 5),
772cd030a78SIcenowy Zheng 	.p	= _SUNXI_CCU_DIV(20, 2),
773cd030a78SIcenowy Zheng 	.mux	= {
774cd030a78SIcenowy Zheng 		.shift		= 24,
775cd030a78SIcenowy Zheng 		.width		= 2,
776cd030a78SIcenowy Zheng 		.fixed_predivs	= out_predivs,
777cd030a78SIcenowy Zheng 		.n_predivs	= ARRAY_SIZE(out_predivs),
778cd030a78SIcenowy Zheng 	},
779cd030a78SIcenowy Zheng 	.common	= {
780cd030a78SIcenowy Zheng 		.reg		= 0x1f4,
781cd030a78SIcenowy Zheng 		.features	= CCU_FEATURE_FIXED_PREDIV,
782cd030a78SIcenowy Zheng 		.hw.init	= CLK_HW_INIT_PARENTS("outb", out_parents,
783*c7b30526SChen-Yu Tsai 						      &ccu_mp_ops,
784*c7b30526SChen-Yu Tsai 						      CLK_SET_RATE_PARENT),
785cd030a78SIcenowy Zheng 	}
786cd030a78SIcenowy Zheng };
787cd030a78SIcenowy Zheng 
788cd030a78SIcenowy Zheng static struct ccu_common *sun8i_r40_ccu_clks[] = {
789cd030a78SIcenowy Zheng 	&pll_cpu_clk.common,
790cd030a78SIcenowy Zheng 	&pll_audio_base_clk.common,
791cd030a78SIcenowy Zheng 	&pll_video0_clk.common,
792cd030a78SIcenowy Zheng 	&pll_ve_clk.common,
793cd030a78SIcenowy Zheng 	&pll_ddr0_clk.common,
794cd030a78SIcenowy Zheng 	&pll_periph0_clk.common,
795cd030a78SIcenowy Zheng 	&pll_periph0_sata_clk.common,
796cd030a78SIcenowy Zheng 	&pll_periph1_clk.common,
797cd030a78SIcenowy Zheng 	&pll_video1_clk.common,
798cd030a78SIcenowy Zheng 	&pll_sata_clk.common,
799cd030a78SIcenowy Zheng 	&pll_sata_out_clk.common,
800cd030a78SIcenowy Zheng 	&pll_gpu_clk.common,
801cd030a78SIcenowy Zheng 	&pll_mipi_clk.common,
802cd030a78SIcenowy Zheng 	&pll_de_clk.common,
803cd030a78SIcenowy Zheng 	&pll_ddr1_clk.common,
804cd030a78SIcenowy Zheng 	&cpu_clk.common,
805cd030a78SIcenowy Zheng 	&axi_clk.common,
806cd030a78SIcenowy Zheng 	&ahb1_clk.common,
807cd030a78SIcenowy Zheng 	&apb1_clk.common,
808cd030a78SIcenowy Zheng 	&apb2_clk.common,
809cd030a78SIcenowy Zheng 	&bus_mipi_dsi_clk.common,
810cd030a78SIcenowy Zheng 	&bus_ce_clk.common,
811cd030a78SIcenowy Zheng 	&bus_dma_clk.common,
812cd030a78SIcenowy Zheng 	&bus_mmc0_clk.common,
813cd030a78SIcenowy Zheng 	&bus_mmc1_clk.common,
814cd030a78SIcenowy Zheng 	&bus_mmc2_clk.common,
815cd030a78SIcenowy Zheng 	&bus_mmc3_clk.common,
816cd030a78SIcenowy Zheng 	&bus_nand_clk.common,
817cd030a78SIcenowy Zheng 	&bus_dram_clk.common,
818cd030a78SIcenowy Zheng 	&bus_emac_clk.common,
819cd030a78SIcenowy Zheng 	&bus_ts_clk.common,
820cd030a78SIcenowy Zheng 	&bus_hstimer_clk.common,
821cd030a78SIcenowy Zheng 	&bus_spi0_clk.common,
822cd030a78SIcenowy Zheng 	&bus_spi1_clk.common,
823cd030a78SIcenowy Zheng 	&bus_spi2_clk.common,
824cd030a78SIcenowy Zheng 	&bus_spi3_clk.common,
825cd030a78SIcenowy Zheng 	&bus_sata_clk.common,
826cd030a78SIcenowy Zheng 	&bus_otg_clk.common,
827cd030a78SIcenowy Zheng 	&bus_ehci0_clk.common,
828cd030a78SIcenowy Zheng 	&bus_ehci1_clk.common,
829cd030a78SIcenowy Zheng 	&bus_ehci2_clk.common,
830cd030a78SIcenowy Zheng 	&bus_ohci0_clk.common,
831cd030a78SIcenowy Zheng 	&bus_ohci1_clk.common,
832cd030a78SIcenowy Zheng 	&bus_ohci2_clk.common,
833cd030a78SIcenowy Zheng 	&bus_ve_clk.common,
834cd030a78SIcenowy Zheng 	&bus_mp_clk.common,
835cd030a78SIcenowy Zheng 	&bus_deinterlace_clk.common,
836cd030a78SIcenowy Zheng 	&bus_csi0_clk.common,
837cd030a78SIcenowy Zheng 	&bus_csi1_clk.common,
838cd030a78SIcenowy Zheng 	&bus_hdmi0_clk.common,
839cd030a78SIcenowy Zheng 	&bus_hdmi1_clk.common,
840cd030a78SIcenowy Zheng 	&bus_de_clk.common,
841cd030a78SIcenowy Zheng 	&bus_tve0_clk.common,
842cd030a78SIcenowy Zheng 	&bus_tve1_clk.common,
843cd030a78SIcenowy Zheng 	&bus_tve_top_clk.common,
844cd030a78SIcenowy Zheng 	&bus_gmac_clk.common,
845cd030a78SIcenowy Zheng 	&bus_gpu_clk.common,
846cd030a78SIcenowy Zheng 	&bus_tvd0_clk.common,
847cd030a78SIcenowy Zheng 	&bus_tvd1_clk.common,
848cd030a78SIcenowy Zheng 	&bus_tvd2_clk.common,
849cd030a78SIcenowy Zheng 	&bus_tvd3_clk.common,
850cd030a78SIcenowy Zheng 	&bus_tvd_top_clk.common,
851cd030a78SIcenowy Zheng 	&bus_tcon_lcd0_clk.common,
852cd030a78SIcenowy Zheng 	&bus_tcon_lcd1_clk.common,
853cd030a78SIcenowy Zheng 	&bus_tcon_tv0_clk.common,
854cd030a78SIcenowy Zheng 	&bus_tcon_tv1_clk.common,
855cd030a78SIcenowy Zheng 	&bus_tcon_top_clk.common,
856cd030a78SIcenowy Zheng 	&bus_codec_clk.common,
857cd030a78SIcenowy Zheng 	&bus_spdif_clk.common,
858cd030a78SIcenowy Zheng 	&bus_ac97_clk.common,
859cd030a78SIcenowy Zheng 	&bus_pio_clk.common,
860cd030a78SIcenowy Zheng 	&bus_ir0_clk.common,
861cd030a78SIcenowy Zheng 	&bus_ir1_clk.common,
862cd030a78SIcenowy Zheng 	&bus_ths_clk.common,
863cd030a78SIcenowy Zheng 	&bus_keypad_clk.common,
864cd030a78SIcenowy Zheng 	&bus_i2s0_clk.common,
865cd030a78SIcenowy Zheng 	&bus_i2s1_clk.common,
866cd030a78SIcenowy Zheng 	&bus_i2s2_clk.common,
867cd030a78SIcenowy Zheng 	&bus_i2c0_clk.common,
868cd030a78SIcenowy Zheng 	&bus_i2c1_clk.common,
869cd030a78SIcenowy Zheng 	&bus_i2c2_clk.common,
870cd030a78SIcenowy Zheng 	&bus_i2c3_clk.common,
871cd030a78SIcenowy Zheng 	&bus_can_clk.common,
872cd030a78SIcenowy Zheng 	&bus_scr_clk.common,
873cd030a78SIcenowy Zheng 	&bus_ps20_clk.common,
874cd030a78SIcenowy Zheng 	&bus_ps21_clk.common,
875cd030a78SIcenowy Zheng 	&bus_i2c4_clk.common,
876cd030a78SIcenowy Zheng 	&bus_uart0_clk.common,
877cd030a78SIcenowy Zheng 	&bus_uart1_clk.common,
878cd030a78SIcenowy Zheng 	&bus_uart2_clk.common,
879cd030a78SIcenowy Zheng 	&bus_uart3_clk.common,
880cd030a78SIcenowy Zheng 	&bus_uart4_clk.common,
881cd030a78SIcenowy Zheng 	&bus_uart5_clk.common,
882cd030a78SIcenowy Zheng 	&bus_uart6_clk.common,
883cd030a78SIcenowy Zheng 	&bus_uart7_clk.common,
884cd030a78SIcenowy Zheng 	&bus_dbg_clk.common,
885cd030a78SIcenowy Zheng 	&ths_clk.common,
886cd030a78SIcenowy Zheng 	&nand_clk.common,
887cd030a78SIcenowy Zheng 	&mmc0_clk.common,
888cd030a78SIcenowy Zheng 	&mmc1_clk.common,
889cd030a78SIcenowy Zheng 	&mmc2_clk.common,
890cd030a78SIcenowy Zheng 	&mmc3_clk.common,
891cd030a78SIcenowy Zheng 	&ts_clk.common,
892cd030a78SIcenowy Zheng 	&ce_clk.common,
893cd030a78SIcenowy Zheng 	&spi0_clk.common,
894cd030a78SIcenowy Zheng 	&spi1_clk.common,
895cd030a78SIcenowy Zheng 	&spi2_clk.common,
896cd030a78SIcenowy Zheng 	&spi3_clk.common,
897cd030a78SIcenowy Zheng 	&i2s0_clk.common,
898cd030a78SIcenowy Zheng 	&i2s1_clk.common,
899cd030a78SIcenowy Zheng 	&i2s2_clk.common,
900cd030a78SIcenowy Zheng 	&ac97_clk.common,
901cd030a78SIcenowy Zheng 	&spdif_clk.common,
902cd030a78SIcenowy Zheng 	&keypad_clk.common,
903cd030a78SIcenowy Zheng 	&sata_clk.common,
904cd030a78SIcenowy Zheng 	&usb_phy0_clk.common,
905cd030a78SIcenowy Zheng 	&usb_phy1_clk.common,
906cd030a78SIcenowy Zheng 	&usb_phy2_clk.common,
907cd030a78SIcenowy Zheng 	&usb_ohci0_clk.common,
908cd030a78SIcenowy Zheng 	&usb_ohci1_clk.common,
909cd030a78SIcenowy Zheng 	&usb_ohci2_clk.common,
910cd030a78SIcenowy Zheng 	&ir0_clk.common,
911cd030a78SIcenowy Zheng 	&ir1_clk.common,
912cd030a78SIcenowy Zheng 	&dram_clk.common,
913cd030a78SIcenowy Zheng 	&dram_ve_clk.common,
914cd030a78SIcenowy Zheng 	&dram_csi0_clk.common,
915cd030a78SIcenowy Zheng 	&dram_csi1_clk.common,
916cd030a78SIcenowy Zheng 	&dram_ts_clk.common,
917cd030a78SIcenowy Zheng 	&dram_tvd_clk.common,
918cd030a78SIcenowy Zheng 	&dram_mp_clk.common,
919cd030a78SIcenowy Zheng 	&dram_deinterlace_clk.common,
920cd030a78SIcenowy Zheng 	&de_clk.common,
921cd030a78SIcenowy Zheng 	&mp_clk.common,
922cd030a78SIcenowy Zheng 	&tcon_lcd0_clk.common,
923cd030a78SIcenowy Zheng 	&tcon_lcd1_clk.common,
924cd030a78SIcenowy Zheng 	&tcon_tv0_clk.common,
925cd030a78SIcenowy Zheng 	&tcon_tv1_clk.common,
926cd030a78SIcenowy Zheng 	&deinterlace_clk.common,
927cd030a78SIcenowy Zheng 	&csi1_mclk_clk.common,
928cd030a78SIcenowy Zheng 	&csi_sclk_clk.common,
929cd030a78SIcenowy Zheng 	&csi0_mclk_clk.common,
930cd030a78SIcenowy Zheng 	&ve_clk.common,
931cd030a78SIcenowy Zheng 	&codec_clk.common,
932cd030a78SIcenowy Zheng 	&avs_clk.common,
933cd030a78SIcenowy Zheng 	&hdmi_clk.common,
934cd030a78SIcenowy Zheng 	&hdmi_slow_clk.common,
935cd030a78SIcenowy Zheng 	&mbus_clk.common,
936cd030a78SIcenowy Zheng 	&dsi_dphy_clk.common,
937cd030a78SIcenowy Zheng 	&tve0_clk.common,
938cd030a78SIcenowy Zheng 	&tve1_clk.common,
939cd030a78SIcenowy Zheng 	&tvd0_clk.common,
940cd030a78SIcenowy Zheng 	&tvd1_clk.common,
941cd030a78SIcenowy Zheng 	&tvd2_clk.common,
942cd030a78SIcenowy Zheng 	&tvd3_clk.common,
943cd030a78SIcenowy Zheng 	&gpu_clk.common,
944cd030a78SIcenowy Zheng 	&outa_clk.common,
945cd030a78SIcenowy Zheng 	&outb_clk.common,
946cd030a78SIcenowy Zheng };
947cd030a78SIcenowy Zheng 
948cd030a78SIcenowy Zheng /* Fixed Factor clocks */
9493fccf2edSChen-Yu Tsai static CLK_FIXED_FACTOR_FW_NAME(osc12M_clk, "osc12M", "hosc", 2, 1, 0);
9503fccf2edSChen-Yu Tsai 
9513fccf2edSChen-Yu Tsai static const struct clk_hw *clk_parent_pll_audio[] = {
9523fccf2edSChen-Yu Tsai 	&pll_audio_base_clk.common.hw
9533fccf2edSChen-Yu Tsai };
954cd030a78SIcenowy Zheng 
955cd030a78SIcenowy Zheng /* We hardcode the divider to 4 for now */
9563fccf2edSChen-Yu Tsai static CLK_FIXED_FACTOR_HWS(pll_audio_clk, "pll-audio",
9573fccf2edSChen-Yu Tsai 			    clk_parent_pll_audio,
9583fccf2edSChen-Yu Tsai 			    4, 1, CLK_SET_RATE_PARENT);
9593fccf2edSChen-Yu Tsai static CLK_FIXED_FACTOR_HWS(pll_audio_2x_clk, "pll-audio-2x",
9603fccf2edSChen-Yu Tsai 			    clk_parent_pll_audio,
9613fccf2edSChen-Yu Tsai 			    2, 1, CLK_SET_RATE_PARENT);
9623fccf2edSChen-Yu Tsai static CLK_FIXED_FACTOR_HWS(pll_audio_4x_clk, "pll-audio-4x",
9633fccf2edSChen-Yu Tsai 			    clk_parent_pll_audio,
9643fccf2edSChen-Yu Tsai 			    1, 1, CLK_SET_RATE_PARENT);
9653fccf2edSChen-Yu Tsai static CLK_FIXED_FACTOR_HWS(pll_audio_8x_clk, "pll-audio-8x",
9663fccf2edSChen-Yu Tsai 			    clk_parent_pll_audio,
9673fccf2edSChen-Yu Tsai 			    1, 2, CLK_SET_RATE_PARENT);
9683fccf2edSChen-Yu Tsai static CLK_FIXED_FACTOR_HW(pll_periph0_2x_clk, "pll-periph0-2x",
9693fccf2edSChen-Yu Tsai 			   &pll_periph0_clk.common.hw,
9703fccf2edSChen-Yu Tsai 			   1, 2, 0);
9713fccf2edSChen-Yu Tsai static CLK_FIXED_FACTOR_HW(pll_periph1_2x_clk, "pll-periph1-2x",
9723fccf2edSChen-Yu Tsai 			   &pll_periph1_clk.common.hw,
9733fccf2edSChen-Yu Tsai 			   1, 2, 0);
9743fccf2edSChen-Yu Tsai static CLK_FIXED_FACTOR_HW(pll_video0_2x_clk, "pll-video0-2x",
9753fccf2edSChen-Yu Tsai 			   &pll_video0_clk.common.hw,
9763fccf2edSChen-Yu Tsai 			   1, 2, 0);
9773fccf2edSChen-Yu Tsai static CLK_FIXED_FACTOR_HW(pll_video1_2x_clk, "pll-video1-2x",
9783fccf2edSChen-Yu Tsai 			   &pll_video1_clk.common.hw,
9793fccf2edSChen-Yu Tsai 			   1, 2, 0);
980cd030a78SIcenowy Zheng 
981cd030a78SIcenowy Zheng static struct clk_hw_onecell_data sun8i_r40_hw_clks = {
982cd030a78SIcenowy Zheng 	.hws	= {
983cd030a78SIcenowy Zheng 		[CLK_OSC_12M]		= &osc12M_clk.hw,
984cd030a78SIcenowy Zheng 		[CLK_PLL_CPU]		= &pll_cpu_clk.common.hw,
985cd030a78SIcenowy Zheng 		[CLK_PLL_AUDIO_BASE]	= &pll_audio_base_clk.common.hw,
986cd030a78SIcenowy Zheng 		[CLK_PLL_AUDIO]		= &pll_audio_clk.hw,
987cd030a78SIcenowy Zheng 		[CLK_PLL_AUDIO_2X]	= &pll_audio_2x_clk.hw,
988cd030a78SIcenowy Zheng 		[CLK_PLL_AUDIO_4X]	= &pll_audio_4x_clk.hw,
989cd030a78SIcenowy Zheng 		[CLK_PLL_AUDIO_8X]	= &pll_audio_8x_clk.hw,
990cd030a78SIcenowy Zheng 		[CLK_PLL_VIDEO0]	= &pll_video0_clk.common.hw,
991cd030a78SIcenowy Zheng 		[CLK_PLL_VIDEO0_2X]	= &pll_video0_2x_clk.hw,
992cd030a78SIcenowy Zheng 		[CLK_PLL_VE]		= &pll_ve_clk.common.hw,
993cd030a78SIcenowy Zheng 		[CLK_PLL_DDR0]		= &pll_ddr0_clk.common.hw,
994cd030a78SIcenowy Zheng 		[CLK_PLL_PERIPH0]	= &pll_periph0_clk.common.hw,
995cd030a78SIcenowy Zheng 		[CLK_PLL_PERIPH0_SATA]	= &pll_periph0_sata_clk.common.hw,
996cd030a78SIcenowy Zheng 		[CLK_PLL_PERIPH0_2X]	= &pll_periph0_2x_clk.hw,
997cd030a78SIcenowy Zheng 		[CLK_PLL_PERIPH1]	= &pll_periph1_clk.common.hw,
998cd030a78SIcenowy Zheng 		[CLK_PLL_PERIPH1_2X]	= &pll_periph1_2x_clk.hw,
999cd030a78SIcenowy Zheng 		[CLK_PLL_VIDEO1]	= &pll_video1_clk.common.hw,
1000cd030a78SIcenowy Zheng 		[CLK_PLL_VIDEO1_2X]	= &pll_video1_2x_clk.hw,
1001cd030a78SIcenowy Zheng 		[CLK_PLL_SATA]		= &pll_sata_clk.common.hw,
1002cd030a78SIcenowy Zheng 		[CLK_PLL_SATA_OUT]	= &pll_sata_out_clk.common.hw,
1003cd030a78SIcenowy Zheng 		[CLK_PLL_GPU]		= &pll_gpu_clk.common.hw,
1004cd030a78SIcenowy Zheng 		[CLK_PLL_MIPI]		= &pll_mipi_clk.common.hw,
1005cd030a78SIcenowy Zheng 		[CLK_PLL_DE]		= &pll_de_clk.common.hw,
1006cd030a78SIcenowy Zheng 		[CLK_PLL_DDR1]		= &pll_ddr1_clk.common.hw,
1007cd030a78SIcenowy Zheng 		[CLK_CPU]		= &cpu_clk.common.hw,
1008cd030a78SIcenowy Zheng 		[CLK_AXI]		= &axi_clk.common.hw,
1009cd030a78SIcenowy Zheng 		[CLK_AHB1]		= &ahb1_clk.common.hw,
1010cd030a78SIcenowy Zheng 		[CLK_APB1]		= &apb1_clk.common.hw,
1011cd030a78SIcenowy Zheng 		[CLK_APB2]		= &apb2_clk.common.hw,
1012cd030a78SIcenowy Zheng 		[CLK_BUS_MIPI_DSI]	= &bus_mipi_dsi_clk.common.hw,
1013cd030a78SIcenowy Zheng 		[CLK_BUS_CE]		= &bus_ce_clk.common.hw,
1014cd030a78SIcenowy Zheng 		[CLK_BUS_DMA]		= &bus_dma_clk.common.hw,
1015cd030a78SIcenowy Zheng 		[CLK_BUS_MMC0]		= &bus_mmc0_clk.common.hw,
1016cd030a78SIcenowy Zheng 		[CLK_BUS_MMC1]		= &bus_mmc1_clk.common.hw,
1017cd030a78SIcenowy Zheng 		[CLK_BUS_MMC2]		= &bus_mmc2_clk.common.hw,
1018cd030a78SIcenowy Zheng 		[CLK_BUS_MMC3]		= &bus_mmc3_clk.common.hw,
1019cd030a78SIcenowy Zheng 		[CLK_BUS_NAND]		= &bus_nand_clk.common.hw,
1020cd030a78SIcenowy Zheng 		[CLK_BUS_DRAM]		= &bus_dram_clk.common.hw,
1021cd030a78SIcenowy Zheng 		[CLK_BUS_EMAC]		= &bus_emac_clk.common.hw,
1022cd030a78SIcenowy Zheng 		[CLK_BUS_TS]		= &bus_ts_clk.common.hw,
1023cd030a78SIcenowy Zheng 		[CLK_BUS_HSTIMER]	= &bus_hstimer_clk.common.hw,
1024cd030a78SIcenowy Zheng 		[CLK_BUS_SPI0]		= &bus_spi0_clk.common.hw,
1025cd030a78SIcenowy Zheng 		[CLK_BUS_SPI1]		= &bus_spi1_clk.common.hw,
1026cd030a78SIcenowy Zheng 		[CLK_BUS_SPI2]		= &bus_spi2_clk.common.hw,
1027cd030a78SIcenowy Zheng 		[CLK_BUS_SPI3]		= &bus_spi3_clk.common.hw,
1028cd030a78SIcenowy Zheng 		[CLK_BUS_SATA]		= &bus_sata_clk.common.hw,
1029cd030a78SIcenowy Zheng 		[CLK_BUS_OTG]		= &bus_otg_clk.common.hw,
1030cd030a78SIcenowy Zheng 		[CLK_BUS_EHCI0]		= &bus_ehci0_clk.common.hw,
1031cd030a78SIcenowy Zheng 		[CLK_BUS_EHCI1]		= &bus_ehci1_clk.common.hw,
1032cd030a78SIcenowy Zheng 		[CLK_BUS_EHCI2]		= &bus_ehci2_clk.common.hw,
1033cd030a78SIcenowy Zheng 		[CLK_BUS_OHCI0]		= &bus_ohci0_clk.common.hw,
1034cd030a78SIcenowy Zheng 		[CLK_BUS_OHCI1]		= &bus_ohci1_clk.common.hw,
1035cd030a78SIcenowy Zheng 		[CLK_BUS_OHCI2]		= &bus_ohci2_clk.common.hw,
1036cd030a78SIcenowy Zheng 		[CLK_BUS_VE]		= &bus_ve_clk.common.hw,
1037cd030a78SIcenowy Zheng 		[CLK_BUS_MP]		= &bus_mp_clk.common.hw,
1038cd030a78SIcenowy Zheng 		[CLK_BUS_DEINTERLACE]	= &bus_deinterlace_clk.common.hw,
1039cd030a78SIcenowy Zheng 		[CLK_BUS_CSI0]		= &bus_csi0_clk.common.hw,
1040cd030a78SIcenowy Zheng 		[CLK_BUS_CSI1]		= &bus_csi1_clk.common.hw,
1041cd030a78SIcenowy Zheng 		[CLK_BUS_HDMI0]		= &bus_hdmi0_clk.common.hw,
1042cd030a78SIcenowy Zheng 		[CLK_BUS_HDMI1]		= &bus_hdmi1_clk.common.hw,
1043cd030a78SIcenowy Zheng 		[CLK_BUS_DE]		= &bus_de_clk.common.hw,
1044cd030a78SIcenowy Zheng 		[CLK_BUS_TVE0]		= &bus_tve0_clk.common.hw,
1045cd030a78SIcenowy Zheng 		[CLK_BUS_TVE1]		= &bus_tve1_clk.common.hw,
1046cd030a78SIcenowy Zheng 		[CLK_BUS_TVE_TOP]	= &bus_tve_top_clk.common.hw,
1047cd030a78SIcenowy Zheng 		[CLK_BUS_GMAC]		= &bus_gmac_clk.common.hw,
1048cd030a78SIcenowy Zheng 		[CLK_BUS_GPU]		= &bus_gpu_clk.common.hw,
1049cd030a78SIcenowy Zheng 		[CLK_BUS_TVD0]		= &bus_tvd0_clk.common.hw,
1050cd030a78SIcenowy Zheng 		[CLK_BUS_TVD1]		= &bus_tvd1_clk.common.hw,
1051cd030a78SIcenowy Zheng 		[CLK_BUS_TVD2]		= &bus_tvd2_clk.common.hw,
1052cd030a78SIcenowy Zheng 		[CLK_BUS_TVD3]		= &bus_tvd3_clk.common.hw,
1053cd030a78SIcenowy Zheng 		[CLK_BUS_TVD_TOP]	= &bus_tvd_top_clk.common.hw,
1054cd030a78SIcenowy Zheng 		[CLK_BUS_TCON_LCD0]	= &bus_tcon_lcd0_clk.common.hw,
1055cd030a78SIcenowy Zheng 		[CLK_BUS_TCON_LCD1]	= &bus_tcon_lcd1_clk.common.hw,
1056cd030a78SIcenowy Zheng 		[CLK_BUS_TCON_TV0]	= &bus_tcon_tv0_clk.common.hw,
1057cd030a78SIcenowy Zheng 		[CLK_BUS_TCON_TV1]	= &bus_tcon_tv1_clk.common.hw,
1058cd030a78SIcenowy Zheng 		[CLK_BUS_TCON_TOP]	= &bus_tcon_top_clk.common.hw,
1059cd030a78SIcenowy Zheng 		[CLK_BUS_CODEC]		= &bus_codec_clk.common.hw,
1060cd030a78SIcenowy Zheng 		[CLK_BUS_SPDIF]		= &bus_spdif_clk.common.hw,
1061cd030a78SIcenowy Zheng 		[CLK_BUS_AC97]		= &bus_ac97_clk.common.hw,
1062cd030a78SIcenowy Zheng 		[CLK_BUS_PIO]		= &bus_pio_clk.common.hw,
1063cd030a78SIcenowy Zheng 		[CLK_BUS_IR0]		= &bus_ir0_clk.common.hw,
1064cd030a78SIcenowy Zheng 		[CLK_BUS_IR1]		= &bus_ir1_clk.common.hw,
1065cd030a78SIcenowy Zheng 		[CLK_BUS_THS]		= &bus_ths_clk.common.hw,
1066cd030a78SIcenowy Zheng 		[CLK_BUS_KEYPAD]	= &bus_keypad_clk.common.hw,
1067cd030a78SIcenowy Zheng 		[CLK_BUS_I2S0]		= &bus_i2s0_clk.common.hw,
1068cd030a78SIcenowy Zheng 		[CLK_BUS_I2S1]		= &bus_i2s1_clk.common.hw,
1069cd030a78SIcenowy Zheng 		[CLK_BUS_I2S2]		= &bus_i2s2_clk.common.hw,
1070cd030a78SIcenowy Zheng 		[CLK_BUS_I2C0]		= &bus_i2c0_clk.common.hw,
1071cd030a78SIcenowy Zheng 		[CLK_BUS_I2C1]		= &bus_i2c1_clk.common.hw,
1072cd030a78SIcenowy Zheng 		[CLK_BUS_I2C2]		= &bus_i2c2_clk.common.hw,
1073cd030a78SIcenowy Zheng 		[CLK_BUS_I2C3]		= &bus_i2c3_clk.common.hw,
1074cd030a78SIcenowy Zheng 		[CLK_BUS_CAN]		= &bus_can_clk.common.hw,
1075cd030a78SIcenowy Zheng 		[CLK_BUS_SCR]		= &bus_scr_clk.common.hw,
1076cd030a78SIcenowy Zheng 		[CLK_BUS_PS20]		= &bus_ps20_clk.common.hw,
1077cd030a78SIcenowy Zheng 		[CLK_BUS_PS21]		= &bus_ps21_clk.common.hw,
1078cd030a78SIcenowy Zheng 		[CLK_BUS_I2C4]		= &bus_i2c4_clk.common.hw,
1079cd030a78SIcenowy Zheng 		[CLK_BUS_UART0]		= &bus_uart0_clk.common.hw,
1080cd030a78SIcenowy Zheng 		[CLK_BUS_UART1]		= &bus_uart1_clk.common.hw,
1081cd030a78SIcenowy Zheng 		[CLK_BUS_UART2]		= &bus_uart2_clk.common.hw,
1082cd030a78SIcenowy Zheng 		[CLK_BUS_UART3]		= &bus_uart3_clk.common.hw,
1083cd030a78SIcenowy Zheng 		[CLK_BUS_UART4]		= &bus_uart4_clk.common.hw,
1084cd030a78SIcenowy Zheng 		[CLK_BUS_UART5]		= &bus_uart5_clk.common.hw,
1085cd030a78SIcenowy Zheng 		[CLK_BUS_UART6]		= &bus_uart6_clk.common.hw,
1086cd030a78SIcenowy Zheng 		[CLK_BUS_UART7]		= &bus_uart7_clk.common.hw,
1087cd030a78SIcenowy Zheng 		[CLK_BUS_DBG]		= &bus_dbg_clk.common.hw,
1088cd030a78SIcenowy Zheng 		[CLK_THS]		= &ths_clk.common.hw,
1089cd030a78SIcenowy Zheng 		[CLK_NAND]		= &nand_clk.common.hw,
1090cd030a78SIcenowy Zheng 		[CLK_MMC0]		= &mmc0_clk.common.hw,
1091cd030a78SIcenowy Zheng 		[CLK_MMC1]		= &mmc1_clk.common.hw,
1092cd030a78SIcenowy Zheng 		[CLK_MMC2]		= &mmc2_clk.common.hw,
1093cd030a78SIcenowy Zheng 		[CLK_MMC3]		= &mmc3_clk.common.hw,
1094cd030a78SIcenowy Zheng 		[CLK_TS]		= &ts_clk.common.hw,
1095cd030a78SIcenowy Zheng 		[CLK_CE]		= &ce_clk.common.hw,
1096cd030a78SIcenowy Zheng 		[CLK_SPI0]		= &spi0_clk.common.hw,
1097cd030a78SIcenowy Zheng 		[CLK_SPI1]		= &spi1_clk.common.hw,
1098cd030a78SIcenowy Zheng 		[CLK_SPI2]		= &spi2_clk.common.hw,
1099cd030a78SIcenowy Zheng 		[CLK_SPI3]		= &spi3_clk.common.hw,
1100cd030a78SIcenowy Zheng 		[CLK_I2S0]		= &i2s0_clk.common.hw,
1101cd030a78SIcenowy Zheng 		[CLK_I2S1]		= &i2s1_clk.common.hw,
1102cd030a78SIcenowy Zheng 		[CLK_I2S2]		= &i2s2_clk.common.hw,
1103cd030a78SIcenowy Zheng 		[CLK_AC97]		= &ac97_clk.common.hw,
1104cd030a78SIcenowy Zheng 		[CLK_SPDIF]		= &spdif_clk.common.hw,
1105cd030a78SIcenowy Zheng 		[CLK_KEYPAD]		= &keypad_clk.common.hw,
1106cd030a78SIcenowy Zheng 		[CLK_SATA]		= &sata_clk.common.hw,
1107cd030a78SIcenowy Zheng 		[CLK_USB_PHY0]		= &usb_phy0_clk.common.hw,
1108cd030a78SIcenowy Zheng 		[CLK_USB_PHY1]		= &usb_phy1_clk.common.hw,
1109cd030a78SIcenowy Zheng 		[CLK_USB_PHY2]		= &usb_phy2_clk.common.hw,
1110cd030a78SIcenowy Zheng 		[CLK_USB_OHCI0]		= &usb_ohci0_clk.common.hw,
1111cd030a78SIcenowy Zheng 		[CLK_USB_OHCI1]		= &usb_ohci1_clk.common.hw,
1112cd030a78SIcenowy Zheng 		[CLK_USB_OHCI2]		= &usb_ohci2_clk.common.hw,
1113cd030a78SIcenowy Zheng 		[CLK_IR0]		= &ir0_clk.common.hw,
1114cd030a78SIcenowy Zheng 		[CLK_IR1]		= &ir1_clk.common.hw,
1115cd030a78SIcenowy Zheng 		[CLK_DRAM]		= &dram_clk.common.hw,
1116cd030a78SIcenowy Zheng 		[CLK_DRAM_VE]		= &dram_ve_clk.common.hw,
1117cd030a78SIcenowy Zheng 		[CLK_DRAM_CSI0]		= &dram_csi0_clk.common.hw,
1118cd030a78SIcenowy Zheng 		[CLK_DRAM_CSI1]		= &dram_csi1_clk.common.hw,
1119cd030a78SIcenowy Zheng 		[CLK_DRAM_TS]		= &dram_ts_clk.common.hw,
1120cd030a78SIcenowy Zheng 		[CLK_DRAM_TVD]		= &dram_tvd_clk.common.hw,
1121cd030a78SIcenowy Zheng 		[CLK_DRAM_MP]		= &dram_mp_clk.common.hw,
1122cd030a78SIcenowy Zheng 		[CLK_DRAM_DEINTERLACE]	= &dram_deinterlace_clk.common.hw,
1123cd030a78SIcenowy Zheng 		[CLK_DE]		= &de_clk.common.hw,
1124cd030a78SIcenowy Zheng 		[CLK_MP]		= &mp_clk.common.hw,
1125cd030a78SIcenowy Zheng 		[CLK_TCON_LCD0]		= &tcon_lcd0_clk.common.hw,
1126cd030a78SIcenowy Zheng 		[CLK_TCON_LCD1]		= &tcon_lcd1_clk.common.hw,
1127cd030a78SIcenowy Zheng 		[CLK_TCON_TV0]		= &tcon_tv0_clk.common.hw,
1128cd030a78SIcenowy Zheng 		[CLK_TCON_TV1]		= &tcon_tv1_clk.common.hw,
1129cd030a78SIcenowy Zheng 		[CLK_DEINTERLACE]	= &deinterlace_clk.common.hw,
1130cd030a78SIcenowy Zheng 		[CLK_CSI1_MCLK]		= &csi1_mclk_clk.common.hw,
1131cd030a78SIcenowy Zheng 		[CLK_CSI_SCLK]		= &csi_sclk_clk.common.hw,
1132cd030a78SIcenowy Zheng 		[CLK_CSI0_MCLK]		= &csi0_mclk_clk.common.hw,
1133cd030a78SIcenowy Zheng 		[CLK_VE]		= &ve_clk.common.hw,
1134cd030a78SIcenowy Zheng 		[CLK_CODEC]		= &codec_clk.common.hw,
1135cd030a78SIcenowy Zheng 		[CLK_AVS]		= &avs_clk.common.hw,
1136cd030a78SIcenowy Zheng 		[CLK_HDMI]		= &hdmi_clk.common.hw,
1137cd030a78SIcenowy Zheng 		[CLK_HDMI_SLOW]		= &hdmi_slow_clk.common.hw,
1138cd030a78SIcenowy Zheng 		[CLK_MBUS]		= &mbus_clk.common.hw,
1139cd030a78SIcenowy Zheng 		[CLK_DSI_DPHY]		= &dsi_dphy_clk.common.hw,
1140cd030a78SIcenowy Zheng 		[CLK_TVE0]		= &tve0_clk.common.hw,
1141cd030a78SIcenowy Zheng 		[CLK_TVE1]		= &tve1_clk.common.hw,
1142cd030a78SIcenowy Zheng 		[CLK_TVD0]		= &tvd0_clk.common.hw,
1143cd030a78SIcenowy Zheng 		[CLK_TVD1]		= &tvd1_clk.common.hw,
1144cd030a78SIcenowy Zheng 		[CLK_TVD2]		= &tvd2_clk.common.hw,
1145cd030a78SIcenowy Zheng 		[CLK_TVD3]		= &tvd3_clk.common.hw,
1146cd030a78SIcenowy Zheng 		[CLK_GPU]		= &gpu_clk.common.hw,
1147cd030a78SIcenowy Zheng 		[CLK_OUTA]		= &outa_clk.common.hw,
1148cd030a78SIcenowy Zheng 		[CLK_OUTB]		= &outb_clk.common.hw,
1149cd030a78SIcenowy Zheng 	},
1150cd030a78SIcenowy Zheng 	.num	= CLK_NUMBER,
1151cd030a78SIcenowy Zheng };
1152cd030a78SIcenowy Zheng 
1153cd030a78SIcenowy Zheng static struct ccu_reset_map sun8i_r40_ccu_resets[] = {
1154cd030a78SIcenowy Zheng 	[RST_USB_PHY0]		=  { 0x0cc, BIT(0) },
1155cd030a78SIcenowy Zheng 	[RST_USB_PHY1]		=  { 0x0cc, BIT(1) },
1156cd030a78SIcenowy Zheng 	[RST_USB_PHY2]		=  { 0x0cc, BIT(2) },
1157cd030a78SIcenowy Zheng 
1158cd030a78SIcenowy Zheng 	[RST_DRAM]		=  { 0x0f4, BIT(31) },
1159cd030a78SIcenowy Zheng 	[RST_MBUS]		=  { 0x0fc, BIT(31) },
1160cd030a78SIcenowy Zheng 
1161cd030a78SIcenowy Zheng 	[RST_BUS_MIPI_DSI]	=  { 0x2c0, BIT(1) },
1162cd030a78SIcenowy Zheng 	[RST_BUS_CE]		=  { 0x2c0, BIT(5) },
1163cd030a78SIcenowy Zheng 	[RST_BUS_DMA]		=  { 0x2c0, BIT(6) },
1164cd030a78SIcenowy Zheng 	[RST_BUS_MMC0]		=  { 0x2c0, BIT(8) },
1165cd030a78SIcenowy Zheng 	[RST_BUS_MMC1]		=  { 0x2c0, BIT(9) },
1166cd030a78SIcenowy Zheng 	[RST_BUS_MMC2]		=  { 0x2c0, BIT(10) },
1167cd030a78SIcenowy Zheng 	[RST_BUS_MMC3]		=  { 0x2c0, BIT(11) },
1168cd030a78SIcenowy Zheng 	[RST_BUS_NAND]		=  { 0x2c0, BIT(13) },
1169cd030a78SIcenowy Zheng 	[RST_BUS_DRAM]		=  { 0x2c0, BIT(14) },
1170cd030a78SIcenowy Zheng 	[RST_BUS_EMAC]		=  { 0x2c0, BIT(17) },
1171cd030a78SIcenowy Zheng 	[RST_BUS_TS]		=  { 0x2c0, BIT(18) },
1172cd030a78SIcenowy Zheng 	[RST_BUS_HSTIMER]	=  { 0x2c0, BIT(19) },
1173cd030a78SIcenowy Zheng 	[RST_BUS_SPI0]		=  { 0x2c0, BIT(20) },
1174cd030a78SIcenowy Zheng 	[RST_BUS_SPI1]		=  { 0x2c0, BIT(21) },
1175cd030a78SIcenowy Zheng 	[RST_BUS_SPI2]		=  { 0x2c0, BIT(22) },
1176cd030a78SIcenowy Zheng 	[RST_BUS_SPI3]		=  { 0x2c0, BIT(23) },
1177cd030a78SIcenowy Zheng 	[RST_BUS_SATA]		=  { 0x2c0, BIT(24) },
1178cd030a78SIcenowy Zheng 	[RST_BUS_OTG]		=  { 0x2c0, BIT(25) },
1179cd030a78SIcenowy Zheng 	[RST_BUS_EHCI0]		=  { 0x2c0, BIT(26) },
1180cd030a78SIcenowy Zheng 	[RST_BUS_EHCI1]		=  { 0x2c0, BIT(27) },
1181cd030a78SIcenowy Zheng 	[RST_BUS_EHCI2]		=  { 0x2c0, BIT(28) },
1182cd030a78SIcenowy Zheng 	[RST_BUS_OHCI0]		=  { 0x2c0, BIT(29) },
1183cd030a78SIcenowy Zheng 	[RST_BUS_OHCI1]		=  { 0x2c0, BIT(30) },
1184cd030a78SIcenowy Zheng 	[RST_BUS_OHCI2]		=  { 0x2c0, BIT(31) },
1185cd030a78SIcenowy Zheng 
1186cd030a78SIcenowy Zheng 	[RST_BUS_VE]		=  { 0x2c4, BIT(0) },
1187cd030a78SIcenowy Zheng 	[RST_BUS_MP]		=  { 0x2c4, BIT(2) },
1188cd030a78SIcenowy Zheng 	[RST_BUS_DEINTERLACE]	=  { 0x2c4, BIT(5) },
1189cd030a78SIcenowy Zheng 	[RST_BUS_CSI0]		=  { 0x2c4, BIT(8) },
1190cd030a78SIcenowy Zheng 	[RST_BUS_CSI1]		=  { 0x2c4, BIT(9) },
1191cd030a78SIcenowy Zheng 	[RST_BUS_HDMI0]		=  { 0x2c4, BIT(10) },
1192cd030a78SIcenowy Zheng 	[RST_BUS_HDMI1]		=  { 0x2c4, BIT(11) },
1193cd030a78SIcenowy Zheng 	[RST_BUS_DE]		=  { 0x2c4, BIT(12) },
1194cd030a78SIcenowy Zheng 	[RST_BUS_TVE0]		=  { 0x2c4, BIT(13) },
1195cd030a78SIcenowy Zheng 	[RST_BUS_TVE1]		=  { 0x2c4, BIT(14) },
1196cd030a78SIcenowy Zheng 	[RST_BUS_TVE_TOP]	=  { 0x2c4, BIT(15) },
1197cd030a78SIcenowy Zheng 	[RST_BUS_GMAC]		=  { 0x2c4, BIT(17) },
1198cd030a78SIcenowy Zheng 	[RST_BUS_GPU]		=  { 0x2c4, BIT(20) },
1199cd030a78SIcenowy Zheng 	[RST_BUS_TVD0]		=  { 0x2c4, BIT(21) },
1200cd030a78SIcenowy Zheng 	[RST_BUS_TVD1]		=  { 0x2c4, BIT(22) },
1201cd030a78SIcenowy Zheng 	[RST_BUS_TVD2]		=  { 0x2c4, BIT(23) },
1202cd030a78SIcenowy Zheng 	[RST_BUS_TVD3]		=  { 0x2c4, BIT(24) },
1203cd030a78SIcenowy Zheng 	[RST_BUS_TVD_TOP]	=  { 0x2c4, BIT(25) },
1204cd030a78SIcenowy Zheng 	[RST_BUS_TCON_LCD0]	=  { 0x2c4, BIT(26) },
1205cd030a78SIcenowy Zheng 	[RST_BUS_TCON_LCD1]	=  { 0x2c4, BIT(27) },
1206cd030a78SIcenowy Zheng 	[RST_BUS_TCON_TV0]	=  { 0x2c4, BIT(28) },
1207cd030a78SIcenowy Zheng 	[RST_BUS_TCON_TV1]	=  { 0x2c4, BIT(29) },
1208cd030a78SIcenowy Zheng 	[RST_BUS_TCON_TOP]	=  { 0x2c4, BIT(30) },
1209cd030a78SIcenowy Zheng 	[RST_BUS_DBG]		=  { 0x2c4, BIT(31) },
1210cd030a78SIcenowy Zheng 
1211cd030a78SIcenowy Zheng 	[RST_BUS_LVDS]		=  { 0x2c8, BIT(0) },
1212cd030a78SIcenowy Zheng 
1213cd030a78SIcenowy Zheng 	[RST_BUS_CODEC]		=  { 0x2d0, BIT(0) },
1214cd030a78SIcenowy Zheng 	[RST_BUS_SPDIF]		=  { 0x2d0, BIT(1) },
1215cd030a78SIcenowy Zheng 	[RST_BUS_AC97]		=  { 0x2d0, BIT(2) },
1216cd030a78SIcenowy Zheng 	[RST_BUS_IR0]		=  { 0x2d0, BIT(6) },
1217cd030a78SIcenowy Zheng 	[RST_BUS_IR1]		=  { 0x2d0, BIT(7) },
1218cd030a78SIcenowy Zheng 	[RST_BUS_THS]		=  { 0x2d0, BIT(8) },
1219cd030a78SIcenowy Zheng 	[RST_BUS_KEYPAD]	=  { 0x2d0, BIT(10) },
1220cd030a78SIcenowy Zheng 	[RST_BUS_I2S0]		=  { 0x2d0, BIT(12) },
1221cd030a78SIcenowy Zheng 	[RST_BUS_I2S1]		=  { 0x2d0, BIT(13) },
1222cd030a78SIcenowy Zheng 	[RST_BUS_I2S2]		=  { 0x2d0, BIT(14) },
1223cd030a78SIcenowy Zheng 
1224cd030a78SIcenowy Zheng 	[RST_BUS_I2C0]		=  { 0x2d8, BIT(0) },
1225cd030a78SIcenowy Zheng 	[RST_BUS_I2C1]		=  { 0x2d8, BIT(1) },
1226cd030a78SIcenowy Zheng 	[RST_BUS_I2C2]		=  { 0x2d8, BIT(2) },
1227cd030a78SIcenowy Zheng 	[RST_BUS_I2C3]		=  { 0x2d8, BIT(3) },
1228cd030a78SIcenowy Zheng 	[RST_BUS_CAN]		=  { 0x2d8, BIT(4) },
1229cd030a78SIcenowy Zheng 	[RST_BUS_SCR]		=  { 0x2d8, BIT(5) },
1230cd030a78SIcenowy Zheng 	[RST_BUS_PS20]		=  { 0x2d8, BIT(6) },
1231cd030a78SIcenowy Zheng 	[RST_BUS_PS21]		=  { 0x2d8, BIT(7) },
1232cd030a78SIcenowy Zheng 	[RST_BUS_I2C4]		=  { 0x2d8, BIT(15) },
1233cd030a78SIcenowy Zheng 	[RST_BUS_UART0]		=  { 0x2d8, BIT(16) },
1234cd030a78SIcenowy Zheng 	[RST_BUS_UART1]		=  { 0x2d8, BIT(17) },
1235cd030a78SIcenowy Zheng 	[RST_BUS_UART2]		=  { 0x2d8, BIT(18) },
1236cd030a78SIcenowy Zheng 	[RST_BUS_UART3]		=  { 0x2d8, BIT(19) },
1237cd030a78SIcenowy Zheng 	[RST_BUS_UART4]		=  { 0x2d8, BIT(20) },
1238cd030a78SIcenowy Zheng 	[RST_BUS_UART5]		=  { 0x2d8, BIT(21) },
1239cd030a78SIcenowy Zheng 	[RST_BUS_UART6]		=  { 0x2d8, BIT(22) },
1240cd030a78SIcenowy Zheng 	[RST_BUS_UART7]		=  { 0x2d8, BIT(23) },
1241cd030a78SIcenowy Zheng };
1242cd030a78SIcenowy Zheng 
1243cd030a78SIcenowy Zheng static const struct sunxi_ccu_desc sun8i_r40_ccu_desc = {
1244cd030a78SIcenowy Zheng 	.ccu_clks	= sun8i_r40_ccu_clks,
1245cd030a78SIcenowy Zheng 	.num_ccu_clks	= ARRAY_SIZE(sun8i_r40_ccu_clks),
1246cd030a78SIcenowy Zheng 
1247cd030a78SIcenowy Zheng 	.hw_clks	= &sun8i_r40_hw_clks,
1248cd030a78SIcenowy Zheng 
1249cd030a78SIcenowy Zheng 	.resets		= sun8i_r40_ccu_resets,
1250cd030a78SIcenowy Zheng 	.num_resets	= ARRAY_SIZE(sun8i_r40_ccu_resets),
1251cd030a78SIcenowy Zheng };
1252cd030a78SIcenowy Zheng 
1253cd030a78SIcenowy Zheng static struct ccu_pll_nb sun8i_r40_pll_cpu_nb = {
1254cd030a78SIcenowy Zheng 	.common	= &pll_cpu_clk.common,
1255cd030a78SIcenowy Zheng 	/* copy from pll_cpu_clk */
1256cd030a78SIcenowy Zheng 	.enable	= BIT(31),
1257cd030a78SIcenowy Zheng 	.lock	= BIT(28),
1258cd030a78SIcenowy Zheng };
1259cd030a78SIcenowy Zheng 
1260cd030a78SIcenowy Zheng static struct ccu_mux_nb sun8i_r40_cpu_nb = {
1261cd030a78SIcenowy Zheng 	.common		= &cpu_clk.common,
1262cd030a78SIcenowy Zheng 	.cm		= &cpu_clk.mux,
1263cd030a78SIcenowy Zheng 	.delay_us	= 1, /* > 8 clock cycles at 24 MHz */
1264cd030a78SIcenowy Zheng 	.bypass_index	= 1, /* index of 24 MHz oscillator */
1265cd030a78SIcenowy Zheng };
1266cd030a78SIcenowy Zheng 
126717de4c85SIcenowy Zheng /*
126817de4c85SIcenowy Zheng  * Add a regmap for the GMAC driver (dwmac-sun8i) to access the
126917de4c85SIcenowy Zheng  * GMAC configuration register.
127017de4c85SIcenowy Zheng  * Only this register is allowed to be written, in order to
127117de4c85SIcenowy Zheng  * prevent overriding critical clock configuration.
127217de4c85SIcenowy Zheng  */
127317de4c85SIcenowy Zheng 
127417de4c85SIcenowy Zheng #define SUN8I_R40_GMAC_CFG_REG 0x164
127517de4c85SIcenowy Zheng static bool sun8i_r40_ccu_regmap_accessible_reg(struct device *dev,
127617de4c85SIcenowy Zheng 						unsigned int reg)
127717de4c85SIcenowy Zheng {
127817de4c85SIcenowy Zheng 	if (reg == SUN8I_R40_GMAC_CFG_REG)
127917de4c85SIcenowy Zheng 		return true;
128017de4c85SIcenowy Zheng 	return false;
128117de4c85SIcenowy Zheng }
128217de4c85SIcenowy Zheng 
128317de4c85SIcenowy Zheng static struct regmap_config sun8i_r40_ccu_regmap_config = {
128417de4c85SIcenowy Zheng 	.reg_bits	= 32,
128517de4c85SIcenowy Zheng 	.val_bits	= 32,
128617de4c85SIcenowy Zheng 	.reg_stride	= 4,
128717de4c85SIcenowy Zheng 	.max_register	= 0x320, /* PLL_LOCK_CTRL_REG */
128817de4c85SIcenowy Zheng 
128917de4c85SIcenowy Zheng 	/* other devices have no business accessing other registers */
129017de4c85SIcenowy Zheng 	.readable_reg	= sun8i_r40_ccu_regmap_accessible_reg,
129117de4c85SIcenowy Zheng 	.writeable_reg	= sun8i_r40_ccu_regmap_accessible_reg,
129217de4c85SIcenowy Zheng };
129317de4c85SIcenowy Zheng 
129401a7ea76SChen-Yu Tsai #define SUN8I_R40_SYS_32K_CLK_REG 0x310
129501a7ea76SChen-Yu Tsai #define SUN8I_R40_SYS_32K_CLK_KEY (0x16AA << 16)
129601a7ea76SChen-Yu Tsai 
1297c3bf29f6SIcenowy Zheng static int sun8i_r40_ccu_probe(struct platform_device *pdev)
1298cd030a78SIcenowy Zheng {
1299c3bf29f6SIcenowy Zheng 	struct resource *res;
130017de4c85SIcenowy Zheng 	struct regmap *regmap;
1301cd030a78SIcenowy Zheng 	void __iomem *reg;
1302cd030a78SIcenowy Zheng 	u32 val;
1303c3bf29f6SIcenowy Zheng 	int ret;
1304cd030a78SIcenowy Zheng 
1305c3bf29f6SIcenowy Zheng 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1306c3bf29f6SIcenowy Zheng 	reg = devm_ioremap_resource(&pdev->dev, res);
1307c3bf29f6SIcenowy Zheng 	if (IS_ERR(reg))
1308c3bf29f6SIcenowy Zheng 		return PTR_ERR(reg);
1309cd030a78SIcenowy Zheng 
1310cd030a78SIcenowy Zheng 	/* Force the PLL-Audio-1x divider to 4 */
1311cd030a78SIcenowy Zheng 	val = readl(reg + SUN8I_R40_PLL_AUDIO_REG);
1312cd030a78SIcenowy Zheng 	val &= ~GENMASK(19, 16);
1313cd030a78SIcenowy Zheng 	writel(val | (3 << 16), reg + SUN8I_R40_PLL_AUDIO_REG);
1314cd030a78SIcenowy Zheng 
1315cd030a78SIcenowy Zheng 	/* Force PLL-MIPI to MIPI mode */
1316cd030a78SIcenowy Zheng 	val = readl(reg + SUN8I_R40_PLL_MIPI_REG);
1317cd030a78SIcenowy Zheng 	val &= ~BIT(16);
1318cd030a78SIcenowy Zheng 	writel(val, reg + SUN8I_R40_PLL_MIPI_REG);
1319cd030a78SIcenowy Zheng 
1320cd030a78SIcenowy Zheng 	/* Force OHCI 12M parent to 12M divided from 48M */
1321cd030a78SIcenowy Zheng 	val = readl(reg + SUN8I_R40_USB_CLK_REG);
1322cd030a78SIcenowy Zheng 	val &= ~GENMASK(25, 20);
1323cd030a78SIcenowy Zheng 	writel(val, reg + SUN8I_R40_USB_CLK_REG);
1324cd030a78SIcenowy Zheng 
132501a7ea76SChen-Yu Tsai 	/*
132601a7ea76SChen-Yu Tsai 	 * Force SYS 32k (otherwise known as LOSC throughout the CCU)
132701a7ea76SChen-Yu Tsai 	 * clock parent to LOSC output from RTC module instead of the
132801a7ea76SChen-Yu Tsai 	 * CCU's internal RC oscillator divided output.
132901a7ea76SChen-Yu Tsai 	 */
133001a7ea76SChen-Yu Tsai 	writel(SUN8I_R40_SYS_32K_CLK_KEY | BIT(8),
133101a7ea76SChen-Yu Tsai 	       reg + SUN8I_R40_SYS_32K_CLK_REG);
133201a7ea76SChen-Yu Tsai 
133317de4c85SIcenowy Zheng 	regmap = devm_regmap_init_mmio(&pdev->dev, reg,
133417de4c85SIcenowy Zheng 				       &sun8i_r40_ccu_regmap_config);
133517de4c85SIcenowy Zheng 	if (IS_ERR(regmap))
133617de4c85SIcenowy Zheng 		return PTR_ERR(regmap);
133717de4c85SIcenowy Zheng 
1338c3bf29f6SIcenowy Zheng 	ret = sunxi_ccu_probe(pdev->dev.of_node, reg, &sun8i_r40_ccu_desc);
1339c3bf29f6SIcenowy Zheng 	if (ret)
1340c3bf29f6SIcenowy Zheng 		return ret;
1341cd030a78SIcenowy Zheng 
1342cd030a78SIcenowy Zheng 	/* Gate then ungate PLL CPU after any rate changes */
1343cd030a78SIcenowy Zheng 	ccu_pll_notifier_register(&sun8i_r40_pll_cpu_nb);
1344cd030a78SIcenowy Zheng 
1345cd030a78SIcenowy Zheng 	/* Reparent CPU during PLL CPU rate changes */
1346cd030a78SIcenowy Zheng 	ccu_mux_notifier_register(pll_cpu_clk.common.hw.clk,
1347cd030a78SIcenowy Zheng 				  &sun8i_r40_cpu_nb);
1348c3bf29f6SIcenowy Zheng 
1349c3bf29f6SIcenowy Zheng 	return 0;
1350cd030a78SIcenowy Zheng }
1351c3bf29f6SIcenowy Zheng 
1352c3bf29f6SIcenowy Zheng static const struct of_device_id sun8i_r40_ccu_ids[] = {
1353c3bf29f6SIcenowy Zheng 	{ .compatible = "allwinner,sun8i-r40-ccu" },
1354c3bf29f6SIcenowy Zheng 	{ }
1355c3bf29f6SIcenowy Zheng };
1356c3bf29f6SIcenowy Zheng 
1357c3bf29f6SIcenowy Zheng static struct platform_driver sun8i_r40_ccu_driver = {
1358c3bf29f6SIcenowy Zheng 	.probe	= sun8i_r40_ccu_probe,
1359c3bf29f6SIcenowy Zheng 	.driver	= {
1360c3bf29f6SIcenowy Zheng 		.name	= "sun8i-r40-ccu",
1361c3bf29f6SIcenowy Zheng 		.of_match_table	= sun8i_r40_ccu_ids,
1362c3bf29f6SIcenowy Zheng 	},
1363c3bf29f6SIcenowy Zheng };
1364c3bf29f6SIcenowy Zheng builtin_platform_driver(sun8i_r40_ccu_driver);
1365