xref: /linux/drivers/clk/thead/clk-th1520-ap.c (revision 216595b708dac1707fc68d48042738d6d559ddd5)
1ae81b69fSDrew Fustini // SPDX-License-Identifier: GPL-2.0
2ae81b69fSDrew Fustini /*
3ae81b69fSDrew Fustini  * Copyright (C) 2023 Jisheng Zhang <jszhang@kernel.org>
4ae81b69fSDrew Fustini  * Copyright (C) 2023 Vivo Communication Technology Co. Ltd.
5ae81b69fSDrew Fustini  *  Authors: Yangtao Li <frank.li@vivo.com>
6ae81b69fSDrew Fustini  */
7ae81b69fSDrew Fustini 
8ae81b69fSDrew Fustini #include <dt-bindings/clock/thead,th1520-clk-ap.h>
9ae81b69fSDrew Fustini #include <linux/bitfield.h>
10ae81b69fSDrew Fustini #include <linux/clk-provider.h>
11ae81b69fSDrew Fustini #include <linux/device.h>
12ae81b69fSDrew Fustini #include <linux/module.h>
13ae81b69fSDrew Fustini #include <linux/platform_device.h>
14ae81b69fSDrew Fustini #include <linux/regmap.h>
15ae81b69fSDrew Fustini 
16ae81b69fSDrew Fustini #define TH1520_PLL_POSTDIV2	GENMASK(26, 24)
17ae81b69fSDrew Fustini #define TH1520_PLL_POSTDIV1	GENMASK(22, 20)
18ae81b69fSDrew Fustini #define TH1520_PLL_FBDIV	GENMASK(19, 8)
19ae81b69fSDrew Fustini #define TH1520_PLL_REFDIV	GENMASK(5, 0)
20ae81b69fSDrew Fustini #define TH1520_PLL_BYPASS	BIT(30)
21ae81b69fSDrew Fustini #define TH1520_PLL_DSMPD	BIT(24)
22ae81b69fSDrew Fustini #define TH1520_PLL_FRAC		GENMASK(23, 0)
23ae81b69fSDrew Fustini #define TH1520_PLL_FRAC_BITS    24
24ae81b69fSDrew Fustini 
25ae81b69fSDrew Fustini struct ccu_internal {
26ae81b69fSDrew Fustini 	u8	shift;
27ae81b69fSDrew Fustini 	u8	width;
28ae81b69fSDrew Fustini };
29ae81b69fSDrew Fustini 
30ae81b69fSDrew Fustini struct ccu_div_internal {
31ae81b69fSDrew Fustini 	u8	shift;
32ae81b69fSDrew Fustini 	u8	width;
33ae81b69fSDrew Fustini 	u32	flags;
34ae81b69fSDrew Fustini };
35ae81b69fSDrew Fustini 
36ae81b69fSDrew Fustini struct ccu_common {
37ae81b69fSDrew Fustini 	int		clkid;
38ae81b69fSDrew Fustini 	struct regmap	*map;
39ae81b69fSDrew Fustini 	u16		cfg0;
40ae81b69fSDrew Fustini 	u16		cfg1;
41ae81b69fSDrew Fustini 	struct clk_hw	hw;
42ae81b69fSDrew Fustini };
43ae81b69fSDrew Fustini 
44ae81b69fSDrew Fustini struct ccu_mux {
45ae81b69fSDrew Fustini 	struct ccu_internal	mux;
46ae81b69fSDrew Fustini 	struct ccu_common	common;
47ae81b69fSDrew Fustini };
48ae81b69fSDrew Fustini 
49ae81b69fSDrew Fustini struct ccu_gate {
50ae81b69fSDrew Fustini 	u32			enable;
51ae81b69fSDrew Fustini 	struct ccu_common	common;
52ae81b69fSDrew Fustini };
53ae81b69fSDrew Fustini 
54ae81b69fSDrew Fustini struct ccu_div {
55ae81b69fSDrew Fustini 	u32			enable;
56ae81b69fSDrew Fustini 	struct ccu_div_internal	div;
57ae81b69fSDrew Fustini 	struct ccu_internal	mux;
58ae81b69fSDrew Fustini 	struct ccu_common	common;
59ae81b69fSDrew Fustini };
60ae81b69fSDrew Fustini 
61ae81b69fSDrew Fustini struct ccu_pll {
62ae81b69fSDrew Fustini 	struct ccu_common	common;
63ae81b69fSDrew Fustini };
64ae81b69fSDrew Fustini 
65ae81b69fSDrew Fustini #define TH_CCU_ARG(_shift, _width)					\
66ae81b69fSDrew Fustini 	{								\
67ae81b69fSDrew Fustini 		.shift	= _shift,					\
68ae81b69fSDrew Fustini 		.width	= _width,					\
69ae81b69fSDrew Fustini 	}
70ae81b69fSDrew Fustini 
71ae81b69fSDrew Fustini #define TH_CCU_DIV_FLAGS(_shift, _width, _flags)			\
72ae81b69fSDrew Fustini 	{								\
73ae81b69fSDrew Fustini 		.shift	= _shift,					\
74ae81b69fSDrew Fustini 		.width	= _width,					\
75ae81b69fSDrew Fustini 		.flags	= _flags,					\
76ae81b69fSDrew Fustini 	}
77ae81b69fSDrew Fustini 
78ae81b69fSDrew Fustini #define CCU_GATE(_clkid, _struct, _name, _parent, _reg, _gate, _flags)	\
79ae81b69fSDrew Fustini 	struct ccu_gate _struct = {					\
80ae81b69fSDrew Fustini 		.enable	= _gate,					\
81ae81b69fSDrew Fustini 		.common	= {						\
82ae81b69fSDrew Fustini 			.clkid		= _clkid,			\
83ae81b69fSDrew Fustini 			.cfg0		= _reg,				\
84ae81b69fSDrew Fustini 			.hw.init	= CLK_HW_INIT_PARENTS_DATA(	\
85ae81b69fSDrew Fustini 						_name,			\
86ae81b69fSDrew Fustini 						_parent,		\
87ae81b69fSDrew Fustini 						&clk_gate_ops,		\
88ae81b69fSDrew Fustini 						_flags),		\
89ae81b69fSDrew Fustini 		}							\
90ae81b69fSDrew Fustini 	}
91ae81b69fSDrew Fustini 
hw_to_ccu_common(struct clk_hw * hw)92ae81b69fSDrew Fustini static inline struct ccu_common *hw_to_ccu_common(struct clk_hw *hw)
93ae81b69fSDrew Fustini {
94ae81b69fSDrew Fustini 	return container_of(hw, struct ccu_common, hw);
95ae81b69fSDrew Fustini }
96ae81b69fSDrew Fustini 
hw_to_ccu_mux(struct clk_hw * hw)97ae81b69fSDrew Fustini static inline struct ccu_mux *hw_to_ccu_mux(struct clk_hw *hw)
98ae81b69fSDrew Fustini {
99ae81b69fSDrew Fustini 	struct ccu_common *common = hw_to_ccu_common(hw);
100ae81b69fSDrew Fustini 
101ae81b69fSDrew Fustini 	return container_of(common, struct ccu_mux, common);
102ae81b69fSDrew Fustini }
103ae81b69fSDrew Fustini 
hw_to_ccu_pll(struct clk_hw * hw)104ae81b69fSDrew Fustini static inline struct ccu_pll *hw_to_ccu_pll(struct clk_hw *hw)
105ae81b69fSDrew Fustini {
106ae81b69fSDrew Fustini 	struct ccu_common *common = hw_to_ccu_common(hw);
107ae81b69fSDrew Fustini 
108ae81b69fSDrew Fustini 	return container_of(common, struct ccu_pll, common);
109ae81b69fSDrew Fustini }
110ae81b69fSDrew Fustini 
hw_to_ccu_div(struct clk_hw * hw)111ae81b69fSDrew Fustini static inline struct ccu_div *hw_to_ccu_div(struct clk_hw *hw)
112ae81b69fSDrew Fustini {
113ae81b69fSDrew Fustini 	struct ccu_common *common = hw_to_ccu_common(hw);
114ae81b69fSDrew Fustini 
115ae81b69fSDrew Fustini 	return container_of(common, struct ccu_div, common);
116ae81b69fSDrew Fustini }
117ae81b69fSDrew Fustini 
hw_to_ccu_gate(struct clk_hw * hw)118ae81b69fSDrew Fustini static inline struct ccu_gate *hw_to_ccu_gate(struct clk_hw *hw)
119ae81b69fSDrew Fustini {
120ae81b69fSDrew Fustini 	struct ccu_common *common = hw_to_ccu_common(hw);
121ae81b69fSDrew Fustini 
122ae81b69fSDrew Fustini 	return container_of(common, struct ccu_gate, common);
123ae81b69fSDrew Fustini }
124ae81b69fSDrew Fustini 
ccu_get_parent_helper(struct ccu_common * common,struct ccu_internal * mux)125ae81b69fSDrew Fustini static u8 ccu_get_parent_helper(struct ccu_common *common,
126ae81b69fSDrew Fustini 				struct ccu_internal *mux)
127ae81b69fSDrew Fustini {
128ae81b69fSDrew Fustini 	unsigned int val;
129ae81b69fSDrew Fustini 	u8 parent;
130ae81b69fSDrew Fustini 
131ae81b69fSDrew Fustini 	regmap_read(common->map, common->cfg0, &val);
132ae81b69fSDrew Fustini 	parent = val >> mux->shift;
133ae81b69fSDrew Fustini 	parent &= GENMASK(mux->width - 1, 0);
134ae81b69fSDrew Fustini 
135ae81b69fSDrew Fustini 	return parent;
136ae81b69fSDrew Fustini }
137ae81b69fSDrew Fustini 
ccu_set_parent_helper(struct ccu_common * common,struct ccu_internal * mux,u8 index)138ae81b69fSDrew Fustini static int ccu_set_parent_helper(struct ccu_common *common,
139ae81b69fSDrew Fustini 				 struct ccu_internal *mux,
140ae81b69fSDrew Fustini 				 u8 index)
141ae81b69fSDrew Fustini {
142ae81b69fSDrew Fustini 	return regmap_update_bits(common->map, common->cfg0,
143ae81b69fSDrew Fustini 			GENMASK(mux->width - 1, 0) << mux->shift,
144ae81b69fSDrew Fustini 			index << mux->shift);
145ae81b69fSDrew Fustini }
146ae81b69fSDrew Fustini 
ccu_disable_helper(struct ccu_common * common,u32 gate)147ae81b69fSDrew Fustini static void ccu_disable_helper(struct ccu_common *common, u32 gate)
148ae81b69fSDrew Fustini {
149ae81b69fSDrew Fustini 	if (!gate)
150ae81b69fSDrew Fustini 		return;
151ae81b69fSDrew Fustini 	regmap_update_bits(common->map, common->cfg0,
152ae81b69fSDrew Fustini 			   gate, ~gate);
153ae81b69fSDrew Fustini }
154ae81b69fSDrew Fustini 
ccu_enable_helper(struct ccu_common * common,u32 gate)155ae81b69fSDrew Fustini static int ccu_enable_helper(struct ccu_common *common, u32 gate)
156ae81b69fSDrew Fustini {
157ae81b69fSDrew Fustini 	unsigned int val;
158ae81b69fSDrew Fustini 	int ret;
159ae81b69fSDrew Fustini 
160ae81b69fSDrew Fustini 	if (!gate)
161ae81b69fSDrew Fustini 		return 0;
162ae81b69fSDrew Fustini 
163ae81b69fSDrew Fustini 	ret = regmap_update_bits(common->map, common->cfg0, gate, gate);
164ae81b69fSDrew Fustini 	regmap_read(common->map, common->cfg0, &val);
165ae81b69fSDrew Fustini 	return ret;
166ae81b69fSDrew Fustini }
167ae81b69fSDrew Fustini 
ccu_is_enabled_helper(struct ccu_common * common,u32 gate)168ae81b69fSDrew Fustini static int ccu_is_enabled_helper(struct ccu_common *common, u32 gate)
169ae81b69fSDrew Fustini {
170ae81b69fSDrew Fustini 	unsigned int val;
171ae81b69fSDrew Fustini 
172ae81b69fSDrew Fustini 	if (!gate)
173ae81b69fSDrew Fustini 		return true;
174ae81b69fSDrew Fustini 
175ae81b69fSDrew Fustini 	regmap_read(common->map, common->cfg0, &val);
176ae81b69fSDrew Fustini 	return val & gate;
177ae81b69fSDrew Fustini }
178ae81b69fSDrew Fustini 
ccu_div_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)179ae81b69fSDrew Fustini static unsigned long ccu_div_recalc_rate(struct clk_hw *hw,
180ae81b69fSDrew Fustini 					 unsigned long parent_rate)
181ae81b69fSDrew Fustini {
182ae81b69fSDrew Fustini 	struct ccu_div *cd = hw_to_ccu_div(hw);
183ae81b69fSDrew Fustini 	unsigned long rate;
184ae81b69fSDrew Fustini 	unsigned int val;
185ae81b69fSDrew Fustini 
186ae81b69fSDrew Fustini 	regmap_read(cd->common.map, cd->common.cfg0, &val);
187ae81b69fSDrew Fustini 	val = val >> cd->div.shift;
188ae81b69fSDrew Fustini 	val &= GENMASK(cd->div.width - 1, 0);
189ae81b69fSDrew Fustini 	rate = divider_recalc_rate(hw, parent_rate, val, NULL,
190ae81b69fSDrew Fustini 				   cd->div.flags, cd->div.width);
191ae81b69fSDrew Fustini 
192ae81b69fSDrew Fustini 	return rate;
193ae81b69fSDrew Fustini }
194ae81b69fSDrew Fustini 
ccu_div_get_parent(struct clk_hw * hw)195ae81b69fSDrew Fustini static u8 ccu_div_get_parent(struct clk_hw *hw)
196ae81b69fSDrew Fustini {
197ae81b69fSDrew Fustini 	struct ccu_div *cd = hw_to_ccu_div(hw);
198ae81b69fSDrew Fustini 
199ae81b69fSDrew Fustini 	return ccu_get_parent_helper(&cd->common, &cd->mux);
200ae81b69fSDrew Fustini }
201ae81b69fSDrew Fustini 
ccu_div_set_parent(struct clk_hw * hw,u8 index)202ae81b69fSDrew Fustini static int ccu_div_set_parent(struct clk_hw *hw, u8 index)
203ae81b69fSDrew Fustini {
204ae81b69fSDrew Fustini 	struct ccu_div *cd = hw_to_ccu_div(hw);
205ae81b69fSDrew Fustini 
206ae81b69fSDrew Fustini 	return ccu_set_parent_helper(&cd->common, &cd->mux, index);
207ae81b69fSDrew Fustini }
208ae81b69fSDrew Fustini 
ccu_div_disable(struct clk_hw * hw)209ae81b69fSDrew Fustini static void ccu_div_disable(struct clk_hw *hw)
210ae81b69fSDrew Fustini {
211ae81b69fSDrew Fustini 	struct ccu_div *cd = hw_to_ccu_div(hw);
212ae81b69fSDrew Fustini 
213ae81b69fSDrew Fustini 	ccu_disable_helper(&cd->common, cd->enable);
214ae81b69fSDrew Fustini }
215ae81b69fSDrew Fustini 
ccu_div_enable(struct clk_hw * hw)216ae81b69fSDrew Fustini static int ccu_div_enable(struct clk_hw *hw)
217ae81b69fSDrew Fustini {
218ae81b69fSDrew Fustini 	struct ccu_div *cd = hw_to_ccu_div(hw);
219ae81b69fSDrew Fustini 
220ae81b69fSDrew Fustini 	return ccu_enable_helper(&cd->common, cd->enable);
221ae81b69fSDrew Fustini }
222ae81b69fSDrew Fustini 
ccu_div_is_enabled(struct clk_hw * hw)223ae81b69fSDrew Fustini static int ccu_div_is_enabled(struct clk_hw *hw)
224ae81b69fSDrew Fustini {
225ae81b69fSDrew Fustini 	struct ccu_div *cd = hw_to_ccu_div(hw);
226ae81b69fSDrew Fustini 
227ae81b69fSDrew Fustini 	return ccu_is_enabled_helper(&cd->common, cd->enable);
228ae81b69fSDrew Fustini }
229ae81b69fSDrew Fustini 
230ae81b69fSDrew Fustini static const struct clk_ops ccu_div_ops = {
231ae81b69fSDrew Fustini 	.disable	= ccu_div_disable,
232ae81b69fSDrew Fustini 	.enable		= ccu_div_enable,
233ae81b69fSDrew Fustini 	.is_enabled	= ccu_div_is_enabled,
234ae81b69fSDrew Fustini 	.get_parent	= ccu_div_get_parent,
235ae81b69fSDrew Fustini 	.set_parent	= ccu_div_set_parent,
236ae81b69fSDrew Fustini 	.recalc_rate	= ccu_div_recalc_rate,
237ae81b69fSDrew Fustini 	.determine_rate	= clk_hw_determine_rate_no_reparent,
238ae81b69fSDrew Fustini };
239ae81b69fSDrew Fustini 
th1520_pll_vco_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)240ae81b69fSDrew Fustini static unsigned long th1520_pll_vco_recalc_rate(struct clk_hw *hw,
241ae81b69fSDrew Fustini 						unsigned long parent_rate)
242ae81b69fSDrew Fustini {
243ae81b69fSDrew Fustini 	struct ccu_pll *pll = hw_to_ccu_pll(hw);
244ae81b69fSDrew Fustini 	unsigned long div, mul, frac;
245ae81b69fSDrew Fustini 	unsigned int cfg0, cfg1;
246ae81b69fSDrew Fustini 	u64 rate = parent_rate;
247ae81b69fSDrew Fustini 
248ae81b69fSDrew Fustini 	regmap_read(pll->common.map, pll->common.cfg0, &cfg0);
249ae81b69fSDrew Fustini 	regmap_read(pll->common.map, pll->common.cfg1, &cfg1);
250ae81b69fSDrew Fustini 
251ae81b69fSDrew Fustini 	mul = FIELD_GET(TH1520_PLL_FBDIV, cfg0);
252ae81b69fSDrew Fustini 	div = FIELD_GET(TH1520_PLL_REFDIV, cfg0);
253ae81b69fSDrew Fustini 	if (!(cfg1 & TH1520_PLL_DSMPD)) {
254ae81b69fSDrew Fustini 		mul <<= TH1520_PLL_FRAC_BITS;
255ae81b69fSDrew Fustini 		frac = FIELD_GET(TH1520_PLL_FRAC, cfg1);
256ae81b69fSDrew Fustini 		mul += frac;
257ae81b69fSDrew Fustini 		div <<= TH1520_PLL_FRAC_BITS;
258ae81b69fSDrew Fustini 	}
259ae81b69fSDrew Fustini 	rate = parent_rate * mul;
260ae81b69fSDrew Fustini 	rate = rate / div;
261ae81b69fSDrew Fustini 	return rate;
262ae81b69fSDrew Fustini }
263ae81b69fSDrew Fustini 
th1520_pll_postdiv_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)264ae81b69fSDrew Fustini static unsigned long th1520_pll_postdiv_recalc_rate(struct clk_hw *hw,
265ae81b69fSDrew Fustini 						    unsigned long parent_rate)
266ae81b69fSDrew Fustini {
267ae81b69fSDrew Fustini 	struct ccu_pll *pll = hw_to_ccu_pll(hw);
268ae81b69fSDrew Fustini 	unsigned long div, rate = parent_rate;
269ae81b69fSDrew Fustini 	unsigned int cfg0, cfg1;
270ae81b69fSDrew Fustini 
271ae81b69fSDrew Fustini 	regmap_read(pll->common.map, pll->common.cfg0, &cfg0);
272ae81b69fSDrew Fustini 	regmap_read(pll->common.map, pll->common.cfg1, &cfg1);
273ae81b69fSDrew Fustini 
274ae81b69fSDrew Fustini 	if (cfg1 & TH1520_PLL_BYPASS)
275ae81b69fSDrew Fustini 		return rate;
276ae81b69fSDrew Fustini 
277ae81b69fSDrew Fustini 	div = FIELD_GET(TH1520_PLL_POSTDIV1, cfg0) *
278ae81b69fSDrew Fustini 	      FIELD_GET(TH1520_PLL_POSTDIV2, cfg0);
279ae81b69fSDrew Fustini 
280ae81b69fSDrew Fustini 	rate = rate / div;
281ae81b69fSDrew Fustini 
282ae81b69fSDrew Fustini 	return rate;
283ae81b69fSDrew Fustini }
284ae81b69fSDrew Fustini 
ccu_pll_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)285ae81b69fSDrew Fustini static unsigned long ccu_pll_recalc_rate(struct clk_hw *hw,
286ae81b69fSDrew Fustini 					 unsigned long parent_rate)
287ae81b69fSDrew Fustini {
288ae81b69fSDrew Fustini 	unsigned long rate = parent_rate;
289ae81b69fSDrew Fustini 
290ae81b69fSDrew Fustini 	rate = th1520_pll_vco_recalc_rate(hw, rate);
291ae81b69fSDrew Fustini 	rate = th1520_pll_postdiv_recalc_rate(hw, rate);
292ae81b69fSDrew Fustini 
293ae81b69fSDrew Fustini 	return rate;
294ae81b69fSDrew Fustini }
295ae81b69fSDrew Fustini 
296ae81b69fSDrew Fustini static const struct clk_ops clk_pll_ops = {
297ae81b69fSDrew Fustini 	.recalc_rate	= ccu_pll_recalc_rate,
298ae81b69fSDrew Fustini };
299ae81b69fSDrew Fustini 
300ae81b69fSDrew Fustini static const struct clk_parent_data osc_24m_clk[] = {
301ae81b69fSDrew Fustini 	{ .index = 0 }
302ae81b69fSDrew Fustini };
303ae81b69fSDrew Fustini 
304ae81b69fSDrew Fustini static struct ccu_pll cpu_pll0_clk = {
305ae81b69fSDrew Fustini 	.common		= {
306ae81b69fSDrew Fustini 		.clkid		= CLK_CPU_PLL0,
307ae81b69fSDrew Fustini 		.cfg0		= 0x000,
308ae81b69fSDrew Fustini 		.cfg1		= 0x004,
309ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("cpu-pll0",
310ae81b69fSDrew Fustini 					      osc_24m_clk,
311ae81b69fSDrew Fustini 					      &clk_pll_ops,
312ae81b69fSDrew Fustini 					      0),
313ae81b69fSDrew Fustini 	},
314ae81b69fSDrew Fustini };
315ae81b69fSDrew Fustini 
316ae81b69fSDrew Fustini static struct ccu_pll cpu_pll1_clk = {
317ae81b69fSDrew Fustini 	.common		= {
318ae81b69fSDrew Fustini 		.clkid		= CLK_CPU_PLL1,
319ae81b69fSDrew Fustini 		.cfg0		= 0x010,
320ae81b69fSDrew Fustini 		.cfg1		= 0x014,
321ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("cpu-pll1",
322ae81b69fSDrew Fustini 					      osc_24m_clk,
323ae81b69fSDrew Fustini 					      &clk_pll_ops,
324ae81b69fSDrew Fustini 					      0),
325ae81b69fSDrew Fustini 	},
326ae81b69fSDrew Fustini };
327ae81b69fSDrew Fustini 
328ae81b69fSDrew Fustini static struct ccu_pll gmac_pll_clk = {
329ae81b69fSDrew Fustini 	.common		= {
330ae81b69fSDrew Fustini 		.clkid		= CLK_GMAC_PLL,
331ae81b69fSDrew Fustini 		.cfg0		= 0x020,
332ae81b69fSDrew Fustini 		.cfg1		= 0x024,
333ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("gmac-pll",
334ae81b69fSDrew Fustini 					      osc_24m_clk,
335ae81b69fSDrew Fustini 					      &clk_pll_ops,
336ae81b69fSDrew Fustini 					      0),
337ae81b69fSDrew Fustini 	},
338ae81b69fSDrew Fustini };
339ae81b69fSDrew Fustini 
340ae81b69fSDrew Fustini static const struct clk_hw *gmac_pll_clk_parent[] = {
341ae81b69fSDrew Fustini 	&gmac_pll_clk.common.hw
342ae81b69fSDrew Fustini };
343ae81b69fSDrew Fustini 
344ae81b69fSDrew Fustini static const struct clk_parent_data gmac_pll_clk_pd[] = {
345ae81b69fSDrew Fustini 	{ .hw = &gmac_pll_clk.common.hw }
346ae81b69fSDrew Fustini };
347ae81b69fSDrew Fustini 
348ae81b69fSDrew Fustini static struct ccu_pll video_pll_clk = {
349ae81b69fSDrew Fustini 	.common		= {
350ae81b69fSDrew Fustini 		.clkid		= CLK_VIDEO_PLL,
351ae81b69fSDrew Fustini 		.cfg0		= 0x030,
352ae81b69fSDrew Fustini 		.cfg1		= 0x034,
353ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("video-pll",
354ae81b69fSDrew Fustini 					      osc_24m_clk,
355ae81b69fSDrew Fustini 					      &clk_pll_ops,
356ae81b69fSDrew Fustini 					      0),
357ae81b69fSDrew Fustini 	},
358ae81b69fSDrew Fustini };
359ae81b69fSDrew Fustini 
360ae81b69fSDrew Fustini static const struct clk_hw *video_pll_clk_parent[] = {
361ae81b69fSDrew Fustini 	&video_pll_clk.common.hw
362ae81b69fSDrew Fustini };
363ae81b69fSDrew Fustini 
364ae81b69fSDrew Fustini static const struct clk_parent_data video_pll_clk_pd[] = {
365ae81b69fSDrew Fustini 	{ .hw = &video_pll_clk.common.hw }
366ae81b69fSDrew Fustini };
367ae81b69fSDrew Fustini 
368ae81b69fSDrew Fustini static struct ccu_pll dpu0_pll_clk = {
369ae81b69fSDrew Fustini 	.common		= {
370ae81b69fSDrew Fustini 		.clkid		= CLK_DPU0_PLL,
371ae81b69fSDrew Fustini 		.cfg0		= 0x040,
372ae81b69fSDrew Fustini 		.cfg1		= 0x044,
373ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("dpu0-pll",
374ae81b69fSDrew Fustini 					      osc_24m_clk,
375ae81b69fSDrew Fustini 					      &clk_pll_ops,
376ae81b69fSDrew Fustini 					      0),
377ae81b69fSDrew Fustini 	},
378ae81b69fSDrew Fustini };
379ae81b69fSDrew Fustini 
380ae81b69fSDrew Fustini static const struct clk_hw *dpu0_pll_clk_parent[] = {
381ae81b69fSDrew Fustini 	&dpu0_pll_clk.common.hw
382ae81b69fSDrew Fustini };
383ae81b69fSDrew Fustini 
384ae81b69fSDrew Fustini static struct ccu_pll dpu1_pll_clk = {
385ae81b69fSDrew Fustini 	.common		= {
386ae81b69fSDrew Fustini 		.clkid		= CLK_DPU1_PLL,
387ae81b69fSDrew Fustini 		.cfg0		= 0x050,
388ae81b69fSDrew Fustini 		.cfg1		= 0x054,
389ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("dpu1-pll",
390ae81b69fSDrew Fustini 					      osc_24m_clk,
391ae81b69fSDrew Fustini 					      &clk_pll_ops,
392ae81b69fSDrew Fustini 					      0),
393ae81b69fSDrew Fustini 	},
394ae81b69fSDrew Fustini };
395ae81b69fSDrew Fustini 
396ae81b69fSDrew Fustini static const struct clk_hw *dpu1_pll_clk_parent[] = {
397ae81b69fSDrew Fustini 	&dpu1_pll_clk.common.hw
398ae81b69fSDrew Fustini };
399ae81b69fSDrew Fustini 
400ae81b69fSDrew Fustini static struct ccu_pll tee_pll_clk = {
401ae81b69fSDrew Fustini 	.common		= {
402ae81b69fSDrew Fustini 		.clkid		= CLK_TEE_PLL,
403ae81b69fSDrew Fustini 		.cfg0		= 0x060,
404ae81b69fSDrew Fustini 		.cfg1		= 0x064,
405ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("tee-pll",
406ae81b69fSDrew Fustini 					      osc_24m_clk,
407ae81b69fSDrew Fustini 					      &clk_pll_ops,
408ae81b69fSDrew Fustini 					      0),
409ae81b69fSDrew Fustini 	},
410ae81b69fSDrew Fustini };
411ae81b69fSDrew Fustini 
412ae81b69fSDrew Fustini static const struct clk_parent_data c910_i0_parents[] = {
413ae81b69fSDrew Fustini 	{ .hw = &cpu_pll0_clk.common.hw },
414ae81b69fSDrew Fustini 	{ .index = 0 }
415ae81b69fSDrew Fustini };
416ae81b69fSDrew Fustini 
417ae81b69fSDrew Fustini static struct ccu_mux c910_i0_clk = {
418ae81b69fSDrew Fustini 	.mux	= TH_CCU_ARG(1, 1),
419ae81b69fSDrew Fustini 	.common	= {
420ae81b69fSDrew Fustini 		.clkid		= CLK_C910_I0,
421ae81b69fSDrew Fustini 		.cfg0		= 0x100,
422ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("c910-i0",
423ae81b69fSDrew Fustini 					      c910_i0_parents,
424ae81b69fSDrew Fustini 					      &clk_mux_ops,
425ae81b69fSDrew Fustini 					      0),
426ae81b69fSDrew Fustini 	}
427ae81b69fSDrew Fustini };
428ae81b69fSDrew Fustini 
429ae81b69fSDrew Fustini static const struct clk_parent_data c910_parents[] = {
430ae81b69fSDrew Fustini 	{ .hw = &c910_i0_clk.common.hw },
431ae81b69fSDrew Fustini 	{ .hw = &cpu_pll1_clk.common.hw }
432ae81b69fSDrew Fustini };
433ae81b69fSDrew Fustini 
434ae81b69fSDrew Fustini static struct ccu_mux c910_clk = {
435ae81b69fSDrew Fustini 	.mux	= TH_CCU_ARG(0, 1),
436ae81b69fSDrew Fustini 	.common	= {
437ae81b69fSDrew Fustini 		.clkid		= CLK_C910,
438ae81b69fSDrew Fustini 		.cfg0		= 0x100,
439ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("c910",
440ae81b69fSDrew Fustini 					      c910_parents,
441ae81b69fSDrew Fustini 					      &clk_mux_ops,
442ae81b69fSDrew Fustini 					      0),
443ae81b69fSDrew Fustini 	}
444ae81b69fSDrew Fustini };
445ae81b69fSDrew Fustini 
446ae81b69fSDrew Fustini static const struct clk_parent_data ahb2_cpusys_parents[] = {
447ae81b69fSDrew Fustini 	{ .hw = &gmac_pll_clk.common.hw },
448ae81b69fSDrew Fustini 	{ .index = 0 }
449ae81b69fSDrew Fustini };
450ae81b69fSDrew Fustini 
451ae81b69fSDrew Fustini static struct ccu_div ahb2_cpusys_hclk = {
452ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED),
453ae81b69fSDrew Fustini 	.mux		= TH_CCU_ARG(5, 1),
454ae81b69fSDrew Fustini 	.common		= {
455ae81b69fSDrew Fustini 		.clkid          = CLK_AHB2_CPUSYS_HCLK,
456ae81b69fSDrew Fustini 		.cfg0		= 0x120,
457ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("ahb2-cpusys-hclk",
458ae81b69fSDrew Fustini 						      ahb2_cpusys_parents,
459ae81b69fSDrew Fustini 						      &ccu_div_ops,
460ae81b69fSDrew Fustini 						      0),
461ae81b69fSDrew Fustini 	},
462ae81b69fSDrew Fustini };
463ae81b69fSDrew Fustini 
464ae81b69fSDrew Fustini static const struct clk_parent_data ahb2_cpusys_hclk_pd[] = {
465ae81b69fSDrew Fustini 	{ .hw = &ahb2_cpusys_hclk.common.hw }
466ae81b69fSDrew Fustini };
467ae81b69fSDrew Fustini 
468ae81b69fSDrew Fustini static const struct clk_hw *ahb2_cpusys_hclk_parent[] = {
469ae81b69fSDrew Fustini 	&ahb2_cpusys_hclk.common.hw,
470ae81b69fSDrew Fustini };
471ae81b69fSDrew Fustini 
472ae81b69fSDrew Fustini static struct ccu_div apb3_cpusys_pclk = {
473ae81b69fSDrew Fustini 	.div		= TH_CCU_ARG(0, 3),
474ae81b69fSDrew Fustini 	.common		= {
475ae81b69fSDrew Fustini 		.clkid          = CLK_APB3_CPUSYS_PCLK,
476ae81b69fSDrew Fustini 		.cfg0		= 0x130,
477ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("apb3-cpusys-pclk",
478ae81b69fSDrew Fustini 							   ahb2_cpusys_hclk_parent,
479ae81b69fSDrew Fustini 							   &ccu_div_ops,
480ae81b69fSDrew Fustini 							   0),
481ae81b69fSDrew Fustini 	},
482ae81b69fSDrew Fustini };
483ae81b69fSDrew Fustini 
484ae81b69fSDrew Fustini static const struct clk_parent_data apb3_cpusys_pclk_pd[] = {
485ae81b69fSDrew Fustini 	{ .hw = &apb3_cpusys_pclk.common.hw }
486ae81b69fSDrew Fustini };
487ae81b69fSDrew Fustini 
488ae81b69fSDrew Fustini static struct ccu_div axi4_cpusys2_aclk = {
489ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED),
490ae81b69fSDrew Fustini 	.common		= {
491ae81b69fSDrew Fustini 		.clkid          = CLK_AXI4_CPUSYS2_ACLK,
492ae81b69fSDrew Fustini 		.cfg0		= 0x134,
493ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("axi4-cpusys2-aclk",
494ae81b69fSDrew Fustini 					      gmac_pll_clk_parent,
495ae81b69fSDrew Fustini 					      &ccu_div_ops,
496ae81b69fSDrew Fustini 					      0),
497ae81b69fSDrew Fustini 	},
498ae81b69fSDrew Fustini };
499ae81b69fSDrew Fustini 
500ae81b69fSDrew Fustini static const struct clk_parent_data axi4_cpusys2_aclk_pd[] = {
501ae81b69fSDrew Fustini 	{ .hw = &axi4_cpusys2_aclk.common.hw }
502ae81b69fSDrew Fustini };
503ae81b69fSDrew Fustini 
504ae81b69fSDrew Fustini static const struct clk_parent_data axi_parents[] = {
505ae81b69fSDrew Fustini 	{ .hw = &video_pll_clk.common.hw },
506ae81b69fSDrew Fustini 	{ .index = 0 }
507ae81b69fSDrew Fustini };
508ae81b69fSDrew Fustini 
509ae81b69fSDrew Fustini static struct ccu_div axi_aclk = {
510ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ONE_BASED),
511ae81b69fSDrew Fustini 	.mux		= TH_CCU_ARG(5, 1),
512ae81b69fSDrew Fustini 	.common		= {
513ae81b69fSDrew Fustini 		.clkid          = CLK_AXI_ACLK,
514ae81b69fSDrew Fustini 		.cfg0		= 0x138,
515ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("axi-aclk",
516ae81b69fSDrew Fustini 						      axi_parents,
517ae81b69fSDrew Fustini 						      &ccu_div_ops,
518ae81b69fSDrew Fustini 						      0),
519ae81b69fSDrew Fustini 	},
520ae81b69fSDrew Fustini };
521ae81b69fSDrew Fustini 
522ae81b69fSDrew Fustini static const struct clk_parent_data axi_aclk_pd[] = {
523ae81b69fSDrew Fustini 	{ .hw = &axi_aclk.common.hw }
524ae81b69fSDrew Fustini };
525ae81b69fSDrew Fustini 
526ae81b69fSDrew Fustini static const struct clk_parent_data perisys_ahb_hclk_parents[] = {
527ae81b69fSDrew Fustini 	{ .hw = &gmac_pll_clk.common.hw },
528ae81b69fSDrew Fustini 	{ .index = 0 },
529ae81b69fSDrew Fustini };
530ae81b69fSDrew Fustini 
531ae81b69fSDrew Fustini static struct ccu_div perisys_ahb_hclk = {
532ae81b69fSDrew Fustini 	.enable		= BIT(6),
533ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ONE_BASED),
534ae81b69fSDrew Fustini 	.mux		= TH_CCU_ARG(5, 1),
535ae81b69fSDrew Fustini 	.common		= {
536ae81b69fSDrew Fustini 		.clkid          = CLK_PERI_AHB_HCLK,
537ae81b69fSDrew Fustini 		.cfg0		= 0x140,
538ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("perisys-ahb-hclk",
539ae81b69fSDrew Fustini 						      perisys_ahb_hclk_parents,
540ae81b69fSDrew Fustini 						      &ccu_div_ops,
541ae81b69fSDrew Fustini 						      0),
542ae81b69fSDrew Fustini 	},
543ae81b69fSDrew Fustini };
544ae81b69fSDrew Fustini 
545ae81b69fSDrew Fustini static const struct clk_parent_data perisys_ahb_hclk_pd[] = {
546ae81b69fSDrew Fustini 	{ .hw = &perisys_ahb_hclk.common.hw }
547ae81b69fSDrew Fustini };
548ae81b69fSDrew Fustini 
549ae81b69fSDrew Fustini static const struct clk_hw *perisys_ahb_hclk_parent[] = {
550ae81b69fSDrew Fustini 	&perisys_ahb_hclk.common.hw
551ae81b69fSDrew Fustini };
552ae81b69fSDrew Fustini 
553ae81b69fSDrew Fustini static struct ccu_div perisys_apb_pclk = {
554ae81b69fSDrew Fustini 	.div		= TH_CCU_ARG(0, 3),
555ae81b69fSDrew Fustini 	.common		= {
556ae81b69fSDrew Fustini 		.clkid          = CLK_PERI_APB_PCLK,
557ae81b69fSDrew Fustini 		.cfg0		= 0x150,
558ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("perisys-apb-pclk",
559ae81b69fSDrew Fustini 					      perisys_ahb_hclk_parent,
560ae81b69fSDrew Fustini 					      &ccu_div_ops,
561ae81b69fSDrew Fustini 					      0),
562ae81b69fSDrew Fustini 	},
563ae81b69fSDrew Fustini };
564ae81b69fSDrew Fustini 
565ae81b69fSDrew Fustini static const struct clk_parent_data perisys_apb_pclk_pd[] = {
566ae81b69fSDrew Fustini 	{ .hw = &perisys_apb_pclk.common.hw }
567ae81b69fSDrew Fustini };
568ae81b69fSDrew Fustini 
569ae81b69fSDrew Fustini static struct ccu_div peri2sys_apb_pclk = {
570ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(4, 3, CLK_DIVIDER_ONE_BASED),
571ae81b69fSDrew Fustini 	.common		= {
572ae81b69fSDrew Fustini 		.clkid          = CLK_PERI2APB_PCLK,
573ae81b69fSDrew Fustini 		.cfg0		= 0x150,
574ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("peri2sys-apb-pclk",
575ae81b69fSDrew Fustini 					      gmac_pll_clk_parent,
576ae81b69fSDrew Fustini 					      &ccu_div_ops,
577ae81b69fSDrew Fustini 					      0),
578ae81b69fSDrew Fustini 	},
579ae81b69fSDrew Fustini };
580ae81b69fSDrew Fustini 
581ae81b69fSDrew Fustini static const struct clk_parent_data peri2sys_apb_pclk_pd[] = {
582ae81b69fSDrew Fustini 	{ .hw = &peri2sys_apb_pclk.common.hw }
583ae81b69fSDrew Fustini };
584ae81b69fSDrew Fustini 
585ae81b69fSDrew Fustini static CLK_FIXED_FACTOR_FW_NAME(osc12m_clk, "osc_12m", "osc_24m", 2, 1, 0);
586ae81b69fSDrew Fustini 
587ae81b69fSDrew Fustini static const char * const out_parents[] = { "osc_24m", "osc_12m" };
588ae81b69fSDrew Fustini 
589ae81b69fSDrew Fustini static struct ccu_div out1_clk = {
590ae81b69fSDrew Fustini 	.enable		= BIT(5),
591ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED),
592ae81b69fSDrew Fustini 	.mux		= TH_CCU_ARG(4, 1),
593ae81b69fSDrew Fustini 	.common		= {
594ae81b69fSDrew Fustini 		.clkid          = CLK_OUT1,
595ae81b69fSDrew Fustini 		.cfg0		= 0x1b4,
596ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS("out1",
597ae81b69fSDrew Fustini 						      out_parents,
598ae81b69fSDrew Fustini 						      &ccu_div_ops,
599ae81b69fSDrew Fustini 						      0),
600ae81b69fSDrew Fustini 	},
601ae81b69fSDrew Fustini };
602ae81b69fSDrew Fustini 
603ae81b69fSDrew Fustini static struct ccu_div out2_clk = {
604ae81b69fSDrew Fustini 	.enable		= BIT(5),
605ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED),
606ae81b69fSDrew Fustini 	.mux		= TH_CCU_ARG(4, 1),
607ae81b69fSDrew Fustini 	.common		= {
608ae81b69fSDrew Fustini 		.clkid          = CLK_OUT2,
609ae81b69fSDrew Fustini 		.cfg0		= 0x1b8,
610ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS("out2",
611ae81b69fSDrew Fustini 						      out_parents,
612ae81b69fSDrew Fustini 						      &ccu_div_ops,
613ae81b69fSDrew Fustini 						      0),
614ae81b69fSDrew Fustini 	},
615ae81b69fSDrew Fustini };
616ae81b69fSDrew Fustini 
617ae81b69fSDrew Fustini static struct ccu_div out3_clk = {
618ae81b69fSDrew Fustini 	.enable		= BIT(5),
619ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED),
620ae81b69fSDrew Fustini 	.mux		= TH_CCU_ARG(4, 1),
621ae81b69fSDrew Fustini 	.common		= {
622ae81b69fSDrew Fustini 		.clkid          = CLK_OUT3,
623ae81b69fSDrew Fustini 		.cfg0		= 0x1bc,
624ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS("out3",
625ae81b69fSDrew Fustini 						      out_parents,
626ae81b69fSDrew Fustini 						      &ccu_div_ops,
627ae81b69fSDrew Fustini 						      0),
628ae81b69fSDrew Fustini 	},
629ae81b69fSDrew Fustini };
630ae81b69fSDrew Fustini 
631ae81b69fSDrew Fustini static struct ccu_div out4_clk = {
632ae81b69fSDrew Fustini 	.enable		= BIT(5),
633ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED),
634ae81b69fSDrew Fustini 	.mux		= TH_CCU_ARG(4, 1),
635ae81b69fSDrew Fustini 	.common		= {
636ae81b69fSDrew Fustini 		.clkid          = CLK_OUT4,
637ae81b69fSDrew Fustini 		.cfg0		= 0x1c0,
638ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS("out4",
639ae81b69fSDrew Fustini 						      out_parents,
640ae81b69fSDrew Fustini 						      &ccu_div_ops,
641ae81b69fSDrew Fustini 						      0),
642ae81b69fSDrew Fustini 	},
643ae81b69fSDrew Fustini };
644ae81b69fSDrew Fustini 
645ae81b69fSDrew Fustini static const struct clk_parent_data apb_parents[] = {
646ae81b69fSDrew Fustini 	{ .hw = &gmac_pll_clk.common.hw },
647ae81b69fSDrew Fustini 	{ .index = 0 },
648ae81b69fSDrew Fustini };
649ae81b69fSDrew Fustini 
650ae81b69fSDrew Fustini static struct ccu_div apb_pclk = {
651ae81b69fSDrew Fustini 	.enable		= BIT(5),
652ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ONE_BASED),
653ae81b69fSDrew Fustini 	.mux		= TH_CCU_ARG(7, 1),
654ae81b69fSDrew Fustini 	.common		= {
655ae81b69fSDrew Fustini 		.clkid          = CLK_APB_PCLK,
656ae81b69fSDrew Fustini 		.cfg0		= 0x1c4,
657ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("apb-pclk",
658ae81b69fSDrew Fustini 						      apb_parents,
659ae81b69fSDrew Fustini 						      &ccu_div_ops,
660ae81b69fSDrew Fustini 						      0),
661ae81b69fSDrew Fustini 	},
662ae81b69fSDrew Fustini };
663ae81b69fSDrew Fustini 
664ae81b69fSDrew Fustini static const struct clk_hw *npu_parents[] = {
665ae81b69fSDrew Fustini 	&gmac_pll_clk.common.hw,
666ae81b69fSDrew Fustini 	&video_pll_clk.common.hw
667ae81b69fSDrew Fustini };
668ae81b69fSDrew Fustini 
669ae81b69fSDrew Fustini static struct ccu_div npu_clk = {
670ae81b69fSDrew Fustini 	.enable		= BIT(4),
671ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED),
672ae81b69fSDrew Fustini 	.mux		= TH_CCU_ARG(6, 1),
673ae81b69fSDrew Fustini 	.common		= {
674ae81b69fSDrew Fustini 		.clkid          = CLK_NPU,
675ae81b69fSDrew Fustini 		.cfg0		= 0x1c8,
676ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("npu",
677ae81b69fSDrew Fustini 						      npu_parents,
678ae81b69fSDrew Fustini 						      &ccu_div_ops,
679ae81b69fSDrew Fustini 						      0),
680ae81b69fSDrew Fustini 	},
681ae81b69fSDrew Fustini };
682ae81b69fSDrew Fustini 
683ae81b69fSDrew Fustini static struct ccu_div vi_clk = {
684ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(16, 4, CLK_DIVIDER_ONE_BASED),
685ae81b69fSDrew Fustini 	.common		= {
686ae81b69fSDrew Fustini 		.clkid          = CLK_VI,
687ae81b69fSDrew Fustini 		.cfg0		= 0x1d0,
688ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("vi",
689ae81b69fSDrew Fustini 					      video_pll_clk_parent,
690ae81b69fSDrew Fustini 					      &ccu_div_ops,
691ae81b69fSDrew Fustini 					      0),
692ae81b69fSDrew Fustini 	},
693ae81b69fSDrew Fustini };
694ae81b69fSDrew Fustini 
695ae81b69fSDrew Fustini static struct ccu_div vi_ahb_clk = {
696ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ONE_BASED),
697ae81b69fSDrew Fustini 	.common		= {
698ae81b69fSDrew Fustini 		.clkid          = CLK_VI_AHB,
699ae81b69fSDrew Fustini 		.cfg0		= 0x1d0,
700ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("vi-ahb",
701ae81b69fSDrew Fustini 					      video_pll_clk_parent,
702ae81b69fSDrew Fustini 					      &ccu_div_ops,
703ae81b69fSDrew Fustini 					      0),
704ae81b69fSDrew Fustini 	},
705ae81b69fSDrew Fustini };
706ae81b69fSDrew Fustini 
707ae81b69fSDrew Fustini static struct ccu_div vo_axi_clk = {
708ae81b69fSDrew Fustini 	.enable		= BIT(5),
709ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ONE_BASED),
710ae81b69fSDrew Fustini 	.common		= {
711ae81b69fSDrew Fustini 		.clkid          = CLK_VO_AXI,
712ae81b69fSDrew Fustini 		.cfg0		= 0x1dc,
713ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("vo-axi",
714ae81b69fSDrew Fustini 					      video_pll_clk_parent,
715ae81b69fSDrew Fustini 					      &ccu_div_ops,
716ae81b69fSDrew Fustini 					      0),
717ae81b69fSDrew Fustini 	},
718ae81b69fSDrew Fustini };
719ae81b69fSDrew Fustini 
720ae81b69fSDrew Fustini static struct ccu_div vp_apb_clk = {
721ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED),
722ae81b69fSDrew Fustini 	.common		= {
723ae81b69fSDrew Fustini 		.clkid          = CLK_VP_APB,
724ae81b69fSDrew Fustini 		.cfg0		= 0x1e0,
725ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("vp-apb",
726ae81b69fSDrew Fustini 					      gmac_pll_clk_parent,
727ae81b69fSDrew Fustini 					      &ccu_div_ops,
728ae81b69fSDrew Fustini 					      0),
729ae81b69fSDrew Fustini 	},
730ae81b69fSDrew Fustini };
731ae81b69fSDrew Fustini 
732ae81b69fSDrew Fustini static struct ccu_div vp_axi_clk = {
733ae81b69fSDrew Fustini 	.enable		= BIT(15),
734ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(8, 4, CLK_DIVIDER_ONE_BASED),
735ae81b69fSDrew Fustini 	.common		= {
736ae81b69fSDrew Fustini 		.clkid          = CLK_VP_AXI,
737ae81b69fSDrew Fustini 		.cfg0		= 0x1e0,
738ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("vp-axi",
739ae81b69fSDrew Fustini 					      video_pll_clk_parent,
740ae81b69fSDrew Fustini 					      &ccu_div_ops,
741*39a33965SDrew Fustini 					      CLK_IGNORE_UNUSED),
742ae81b69fSDrew Fustini 	},
743ae81b69fSDrew Fustini };
744ae81b69fSDrew Fustini 
745ae81b69fSDrew Fustini static struct ccu_div venc_clk = {
746ae81b69fSDrew Fustini 	.enable		= BIT(5),
747ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 3, CLK_DIVIDER_ONE_BASED),
748ae81b69fSDrew Fustini 	.common		= {
749ae81b69fSDrew Fustini 		.clkid          = CLK_VENC,
750ae81b69fSDrew Fustini 		.cfg0		= 0x1e4,
751ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("venc",
752ae81b69fSDrew Fustini 					      gmac_pll_clk_parent,
753ae81b69fSDrew Fustini 					      &ccu_div_ops,
754ae81b69fSDrew Fustini 					      0),
755ae81b69fSDrew Fustini 	},
756ae81b69fSDrew Fustini };
757ae81b69fSDrew Fustini 
758ae81b69fSDrew Fustini static struct ccu_div dpu0_clk = {
759ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 8, CLK_DIVIDER_ONE_BASED),
760ae81b69fSDrew Fustini 	.common		= {
761ae81b69fSDrew Fustini 		.clkid          = CLK_DPU0,
762ae81b69fSDrew Fustini 		.cfg0		= 0x1e8,
763ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("dpu0",
764ae81b69fSDrew Fustini 					      dpu0_pll_clk_parent,
765ae81b69fSDrew Fustini 					      &ccu_div_ops,
766ae81b69fSDrew Fustini 					      0),
767ae81b69fSDrew Fustini 	},
768ae81b69fSDrew Fustini };
769ae81b69fSDrew Fustini 
770ae81b69fSDrew Fustini static struct ccu_div dpu1_clk = {
771ae81b69fSDrew Fustini 	.div		= TH_CCU_DIV_FLAGS(0, 8, CLK_DIVIDER_ONE_BASED),
772ae81b69fSDrew Fustini 	.common		= {
773ae81b69fSDrew Fustini 		.clkid          = CLK_DPU1,
774ae81b69fSDrew Fustini 		.cfg0		= 0x1ec,
775ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_HW("dpu1",
776ae81b69fSDrew Fustini 					      dpu1_pll_clk_parent,
777ae81b69fSDrew Fustini 					      &ccu_div_ops,
778ae81b69fSDrew Fustini 					      0),
779ae81b69fSDrew Fustini 	},
780ae81b69fSDrew Fustini };
781ae81b69fSDrew Fustini 
782ae81b69fSDrew Fustini static CCU_GATE(CLK_BROM, brom_clk, "brom", ahb2_cpusys_hclk_pd, 0x100, BIT(4), 0);
783ae81b69fSDrew Fustini static CCU_GATE(CLK_BMU, bmu_clk, "bmu", axi4_cpusys2_aclk_pd, 0x100, BIT(5), 0);
784ae81b69fSDrew Fustini static CCU_GATE(CLK_AON2CPU_A2X, aon2cpu_a2x_clk, "aon2cpu-a2x", axi4_cpusys2_aclk_pd,
785ae81b69fSDrew Fustini 		0x134, BIT(8), 0);
786ae81b69fSDrew Fustini static CCU_GATE(CLK_X2X_CPUSYS, x2x_cpusys_clk, "x2x-cpusys", axi4_cpusys2_aclk_pd,
787ae81b69fSDrew Fustini 		0x134, BIT(7), 0);
788ae81b69fSDrew Fustini static CCU_GATE(CLK_CPU2AON_X2H, cpu2aon_x2h_clk, "cpu2aon-x2h", axi_aclk_pd, 0x138, BIT(8), 0);
789ae81b69fSDrew Fustini static CCU_GATE(CLK_CPU2PERI_X2H, cpu2peri_x2h_clk, "cpu2peri-x2h", axi4_cpusys2_aclk_pd,
790ae81b69fSDrew Fustini 		0x140, BIT(9), 0);
791ae81b69fSDrew Fustini static CCU_GATE(CLK_PERISYS_APB1_HCLK, perisys_apb1_hclk, "perisys-apb1-hclk", perisys_ahb_hclk_pd,
792ae81b69fSDrew Fustini 		0x150, BIT(9), 0);
793ae81b69fSDrew Fustini static CCU_GATE(CLK_PERISYS_APB2_HCLK, perisys_apb2_hclk, "perisys-apb2-hclk", perisys_ahb_hclk_pd,
794ae81b69fSDrew Fustini 		0x150, BIT(10), 0);
795ae81b69fSDrew Fustini static CCU_GATE(CLK_PERISYS_APB3_HCLK, perisys_apb3_hclk, "perisys-apb3-hclk", perisys_ahb_hclk_pd,
796ae81b69fSDrew Fustini 		0x150, BIT(11), 0);
797ae81b69fSDrew Fustini static CCU_GATE(CLK_PERISYS_APB4_HCLK, perisys_apb4_hclk, "perisys-apb4-hclk", perisys_ahb_hclk_pd,
798ae81b69fSDrew Fustini 		0x150, BIT(12), 0);
799ae81b69fSDrew Fustini static CCU_GATE(CLK_NPU_AXI, npu_axi_clk, "npu-axi", axi_aclk_pd, 0x1c8, BIT(5), 0);
800ae81b69fSDrew Fustini static CCU_GATE(CLK_CPU2VP, cpu2vp_clk, "cpu2vp", axi_aclk_pd, 0x1e0, BIT(13), 0);
801ae81b69fSDrew Fustini static CCU_GATE(CLK_EMMC_SDIO, emmc_sdio_clk, "emmc-sdio", video_pll_clk_pd, 0x204, BIT(30), 0);
802ae81b69fSDrew Fustini static CCU_GATE(CLK_GMAC1, gmac1_clk, "gmac1", gmac_pll_clk_pd, 0x204, BIT(26), 0);
803ae81b69fSDrew Fustini static CCU_GATE(CLK_PADCTRL1, padctrl1_clk, "padctrl1", perisys_apb_pclk_pd, 0x204, BIT(24), 0);
804ae81b69fSDrew Fustini static CCU_GATE(CLK_DSMART, dsmart_clk, "dsmart", perisys_apb_pclk_pd, 0x204, BIT(23), 0);
805ae81b69fSDrew Fustini static CCU_GATE(CLK_PADCTRL0, padctrl0_clk, "padctrl0", perisys_apb_pclk_pd, 0x204, BIT(22), 0);
806ae81b69fSDrew Fustini static CCU_GATE(CLK_GMAC_AXI, gmac_axi_clk, "gmac-axi", axi4_cpusys2_aclk_pd, 0x204, BIT(21), 0);
807ae81b69fSDrew Fustini static CCU_GATE(CLK_GPIO3, gpio3_clk, "gpio3-clk", peri2sys_apb_pclk_pd, 0x204, BIT(20), 0);
808ae81b69fSDrew Fustini static CCU_GATE(CLK_GMAC0, gmac0_clk, "gmac0", gmac_pll_clk_pd, 0x204, BIT(19), 0);
809ae81b69fSDrew Fustini static CCU_GATE(CLK_PWM, pwm_clk, "pwm", perisys_apb_pclk_pd, 0x204, BIT(18), 0);
810ae81b69fSDrew Fustini static CCU_GATE(CLK_QSPI0, qspi0_clk, "qspi0", video_pll_clk_pd, 0x204, BIT(17), 0);
811ae81b69fSDrew Fustini static CCU_GATE(CLK_QSPI1, qspi1_clk, "qspi1", video_pll_clk_pd, 0x204, BIT(16), 0);
812ae81b69fSDrew Fustini static CCU_GATE(CLK_SPI, spi_clk, "spi", video_pll_clk_pd, 0x204, BIT(15), 0);
813ae81b69fSDrew Fustini static CCU_GATE(CLK_UART0_PCLK, uart0_pclk, "uart0-pclk", perisys_apb_pclk_pd, 0x204, BIT(14), 0);
814ae81b69fSDrew Fustini static CCU_GATE(CLK_UART1_PCLK, uart1_pclk, "uart1-pclk", perisys_apb_pclk_pd, 0x204, BIT(13), 0);
815ae81b69fSDrew Fustini static CCU_GATE(CLK_UART2_PCLK, uart2_pclk, "uart2-pclk", perisys_apb_pclk_pd, 0x204, BIT(12), 0);
816ae81b69fSDrew Fustini static CCU_GATE(CLK_UART3_PCLK, uart3_pclk, "uart3-pclk", perisys_apb_pclk_pd, 0x204, BIT(11), 0);
817ae81b69fSDrew Fustini static CCU_GATE(CLK_UART4_PCLK, uart4_pclk, "uart4-pclk", perisys_apb_pclk_pd, 0x204, BIT(10), 0);
818ae81b69fSDrew Fustini static CCU_GATE(CLK_UART5_PCLK, uart5_pclk, "uart5-pclk", perisys_apb_pclk_pd, 0x204, BIT(9), 0);
819ae81b69fSDrew Fustini static CCU_GATE(CLK_GPIO0, gpio0_clk, "gpio0-clk", perisys_apb_pclk_pd, 0x204, BIT(8), 0);
820ae81b69fSDrew Fustini static CCU_GATE(CLK_GPIO1, gpio1_clk, "gpio1-clk", perisys_apb_pclk_pd, 0x204, BIT(7), 0);
821ae81b69fSDrew Fustini static CCU_GATE(CLK_GPIO2, gpio2_clk, "gpio2-clk", peri2sys_apb_pclk_pd, 0x204, BIT(6), 0);
822ae81b69fSDrew Fustini static CCU_GATE(CLK_I2C0, i2c0_clk, "i2c0", perisys_apb_pclk_pd, 0x204, BIT(5), 0);
823ae81b69fSDrew Fustini static CCU_GATE(CLK_I2C1, i2c1_clk, "i2c1", perisys_apb_pclk_pd, 0x204, BIT(4), 0);
824ae81b69fSDrew Fustini static CCU_GATE(CLK_I2C2, i2c2_clk, "i2c2", perisys_apb_pclk_pd, 0x204, BIT(3), 0);
825ae81b69fSDrew Fustini static CCU_GATE(CLK_I2C3, i2c3_clk, "i2c3", perisys_apb_pclk_pd, 0x204, BIT(2), 0);
826ae81b69fSDrew Fustini static CCU_GATE(CLK_I2C4, i2c4_clk, "i2c4", perisys_apb_pclk_pd, 0x204, BIT(1), 0);
827ae81b69fSDrew Fustini static CCU_GATE(CLK_I2C5, i2c5_clk, "i2c5", perisys_apb_pclk_pd, 0x204, BIT(0), 0);
828ae81b69fSDrew Fustini static CCU_GATE(CLK_SPINLOCK, spinlock_clk, "spinlock", ahb2_cpusys_hclk_pd, 0x208, BIT(10), 0);
829ae81b69fSDrew Fustini static CCU_GATE(CLK_DMA, dma_clk, "dma", axi4_cpusys2_aclk_pd, 0x208, BIT(8), 0);
830ae81b69fSDrew Fustini static CCU_GATE(CLK_MBOX0, mbox0_clk, "mbox0", apb3_cpusys_pclk_pd, 0x208, BIT(7), 0);
831ae81b69fSDrew Fustini static CCU_GATE(CLK_MBOX1, mbox1_clk, "mbox1", apb3_cpusys_pclk_pd, 0x208, BIT(6), 0);
832ae81b69fSDrew Fustini static CCU_GATE(CLK_MBOX2, mbox2_clk, "mbox2", apb3_cpusys_pclk_pd, 0x208, BIT(5), 0);
833ae81b69fSDrew Fustini static CCU_GATE(CLK_MBOX3, mbox3_clk, "mbox3", apb3_cpusys_pclk_pd, 0x208, BIT(4), 0);
834ae81b69fSDrew Fustini static CCU_GATE(CLK_WDT0, wdt0_clk, "wdt0", apb3_cpusys_pclk_pd, 0x208, BIT(3), 0);
835ae81b69fSDrew Fustini static CCU_GATE(CLK_WDT1, wdt1_clk, "wdt1", apb3_cpusys_pclk_pd, 0x208, BIT(2), 0);
836ae81b69fSDrew Fustini static CCU_GATE(CLK_TIMER0, timer0_clk, "timer0", apb3_cpusys_pclk_pd, 0x208, BIT(1), 0);
837ae81b69fSDrew Fustini static CCU_GATE(CLK_TIMER1, timer1_clk, "timer1", apb3_cpusys_pclk_pd, 0x208, BIT(0), 0);
838ae81b69fSDrew Fustini static CCU_GATE(CLK_SRAM0, sram0_clk, "sram0", axi_aclk_pd, 0x20c, BIT(4), 0);
839ae81b69fSDrew Fustini static CCU_GATE(CLK_SRAM1, sram1_clk, "sram1", axi_aclk_pd, 0x20c, BIT(3), 0);
840ae81b69fSDrew Fustini static CCU_GATE(CLK_SRAM2, sram2_clk, "sram2", axi_aclk_pd, 0x20c, BIT(2), 0);
841ae81b69fSDrew Fustini static CCU_GATE(CLK_SRAM3, sram3_clk, "sram3", axi_aclk_pd, 0x20c, BIT(1), 0);
842ae81b69fSDrew Fustini 
843ae81b69fSDrew Fustini static CLK_FIXED_FACTOR_HW(gmac_pll_clk_100m, "gmac-pll-clk-100m",
844ae81b69fSDrew Fustini 			   &gmac_pll_clk.common.hw, 10, 1, 0);
845ae81b69fSDrew Fustini 
846ae81b69fSDrew Fustini static const struct clk_parent_data uart_sclk_parents[] = {
847ae81b69fSDrew Fustini 	{ .hw = &gmac_pll_clk_100m.hw },
848ae81b69fSDrew Fustini 	{ .index = 0 },
849ae81b69fSDrew Fustini };
850ae81b69fSDrew Fustini 
851ae81b69fSDrew Fustini static struct ccu_mux uart_sclk = {
852ae81b69fSDrew Fustini 	.mux	= TH_CCU_ARG(0, 1),
853ae81b69fSDrew Fustini 	.common	= {
854ae81b69fSDrew Fustini 		.clkid          = CLK_UART_SCLK,
855ae81b69fSDrew Fustini 		.cfg0		= 0x210,
856ae81b69fSDrew Fustini 		.hw.init	= CLK_HW_INIT_PARENTS_DATA("uart-sclk",
857ae81b69fSDrew Fustini 					      uart_sclk_parents,
858ae81b69fSDrew Fustini 					      &clk_mux_ops,
859ae81b69fSDrew Fustini 					      0),
860ae81b69fSDrew Fustini 	}
861ae81b69fSDrew Fustini };
862ae81b69fSDrew Fustini 
863ae81b69fSDrew Fustini static struct ccu_common *th1520_pll_clks[] = {
864ae81b69fSDrew Fustini 	&cpu_pll0_clk.common,
865ae81b69fSDrew Fustini 	&cpu_pll1_clk.common,
866ae81b69fSDrew Fustini 	&gmac_pll_clk.common,
867ae81b69fSDrew Fustini 	&video_pll_clk.common,
868ae81b69fSDrew Fustini 	&dpu0_pll_clk.common,
869ae81b69fSDrew Fustini 	&dpu1_pll_clk.common,
870ae81b69fSDrew Fustini 	&tee_pll_clk.common,
871ae81b69fSDrew Fustini };
872ae81b69fSDrew Fustini 
873ae81b69fSDrew Fustini static struct ccu_common *th1520_div_clks[] = {
874ae81b69fSDrew Fustini 	&ahb2_cpusys_hclk.common,
875ae81b69fSDrew Fustini 	&apb3_cpusys_pclk.common,
876ae81b69fSDrew Fustini 	&axi4_cpusys2_aclk.common,
877ae81b69fSDrew Fustini 	&perisys_ahb_hclk.common,
878ae81b69fSDrew Fustini 	&perisys_apb_pclk.common,
879ae81b69fSDrew Fustini 	&axi_aclk.common,
880ae81b69fSDrew Fustini 	&peri2sys_apb_pclk.common,
881ae81b69fSDrew Fustini 	&out1_clk.common,
882ae81b69fSDrew Fustini 	&out2_clk.common,
883ae81b69fSDrew Fustini 	&out3_clk.common,
884ae81b69fSDrew Fustini 	&out4_clk.common,
885ae81b69fSDrew Fustini 	&apb_pclk.common,
886ae81b69fSDrew Fustini 	&npu_clk.common,
887ae81b69fSDrew Fustini 	&vi_clk.common,
888ae81b69fSDrew Fustini 	&vi_ahb_clk.common,
889ae81b69fSDrew Fustini 	&vo_axi_clk.common,
890ae81b69fSDrew Fustini 	&vp_apb_clk.common,
891ae81b69fSDrew Fustini 	&vp_axi_clk.common,
892ae81b69fSDrew Fustini 	&cpu2vp_clk.common,
893ae81b69fSDrew Fustini 	&venc_clk.common,
894ae81b69fSDrew Fustini 	&dpu0_clk.common,
895ae81b69fSDrew Fustini 	&dpu1_clk.common,
896ae81b69fSDrew Fustini };
897ae81b69fSDrew Fustini 
898ae81b69fSDrew Fustini static struct ccu_common *th1520_mux_clks[] = {
899ae81b69fSDrew Fustini 	&c910_i0_clk.common,
900ae81b69fSDrew Fustini 	&c910_clk.common,
901ae81b69fSDrew Fustini 	&uart_sclk.common,
902ae81b69fSDrew Fustini };
903ae81b69fSDrew Fustini 
904ae81b69fSDrew Fustini static struct ccu_common *th1520_gate_clks[] = {
905ae81b69fSDrew Fustini 	&emmc_sdio_clk.common,
906ae81b69fSDrew Fustini 	&aon2cpu_a2x_clk.common,
907ae81b69fSDrew Fustini 	&x2x_cpusys_clk.common,
908ae81b69fSDrew Fustini 	&brom_clk.common,
909ae81b69fSDrew Fustini 	&bmu_clk.common,
910ae81b69fSDrew Fustini 	&cpu2aon_x2h_clk.common,
911ae81b69fSDrew Fustini 	&cpu2peri_x2h_clk.common,
912ae81b69fSDrew Fustini 	&perisys_apb1_hclk.common,
913ae81b69fSDrew Fustini 	&perisys_apb2_hclk.common,
914ae81b69fSDrew Fustini 	&perisys_apb3_hclk.common,
915ae81b69fSDrew Fustini 	&perisys_apb4_hclk.common,
916ae81b69fSDrew Fustini 	&npu_axi_clk.common,
917ae81b69fSDrew Fustini 	&gmac1_clk.common,
918ae81b69fSDrew Fustini 	&padctrl1_clk.common,
919ae81b69fSDrew Fustini 	&dsmart_clk.common,
920ae81b69fSDrew Fustini 	&padctrl0_clk.common,
921ae81b69fSDrew Fustini 	&gmac_axi_clk.common,
922ae81b69fSDrew Fustini 	&gpio3_clk.common,
923ae81b69fSDrew Fustini 	&gmac0_clk.common,
924ae81b69fSDrew Fustini 	&pwm_clk.common,
925ae81b69fSDrew Fustini 	&qspi0_clk.common,
926ae81b69fSDrew Fustini 	&qspi1_clk.common,
927ae81b69fSDrew Fustini 	&spi_clk.common,
928ae81b69fSDrew Fustini 	&uart0_pclk.common,
929ae81b69fSDrew Fustini 	&uart1_pclk.common,
930ae81b69fSDrew Fustini 	&uart2_pclk.common,
931ae81b69fSDrew Fustini 	&uart3_pclk.common,
932ae81b69fSDrew Fustini 	&uart4_pclk.common,
933ae81b69fSDrew Fustini 	&uart5_pclk.common,
934ae81b69fSDrew Fustini 	&gpio0_clk.common,
935ae81b69fSDrew Fustini 	&gpio1_clk.common,
936ae81b69fSDrew Fustini 	&gpio2_clk.common,
937ae81b69fSDrew Fustini 	&i2c0_clk.common,
938ae81b69fSDrew Fustini 	&i2c1_clk.common,
939ae81b69fSDrew Fustini 	&i2c2_clk.common,
940ae81b69fSDrew Fustini 	&i2c3_clk.common,
941ae81b69fSDrew Fustini 	&i2c4_clk.common,
942ae81b69fSDrew Fustini 	&i2c5_clk.common,
943ae81b69fSDrew Fustini 	&spinlock_clk.common,
944ae81b69fSDrew Fustini 	&dma_clk.common,
945ae81b69fSDrew Fustini 	&mbox0_clk.common,
946ae81b69fSDrew Fustini 	&mbox1_clk.common,
947ae81b69fSDrew Fustini 	&mbox2_clk.common,
948ae81b69fSDrew Fustini 	&mbox3_clk.common,
949ae81b69fSDrew Fustini 	&wdt0_clk.common,
950ae81b69fSDrew Fustini 	&wdt1_clk.common,
951ae81b69fSDrew Fustini 	&timer0_clk.common,
952ae81b69fSDrew Fustini 	&timer1_clk.common,
953ae81b69fSDrew Fustini 	&sram0_clk.common,
954ae81b69fSDrew Fustini 	&sram1_clk.common,
955ae81b69fSDrew Fustini 	&sram2_clk.common,
956ae81b69fSDrew Fustini 	&sram3_clk.common,
957ae81b69fSDrew Fustini };
958ae81b69fSDrew Fustini 
959ae81b69fSDrew Fustini #define NR_CLKS	(CLK_UART_SCLK + 1)
960ae81b69fSDrew Fustini 
961ae81b69fSDrew Fustini static const struct regmap_config th1520_clk_regmap_config = {
962ae81b69fSDrew Fustini 	.reg_bits = 32,
963ae81b69fSDrew Fustini 	.val_bits = 32,
964ae81b69fSDrew Fustini 	.reg_stride = 4,
965ae81b69fSDrew Fustini 	.fast_io = true,
966ae81b69fSDrew Fustini };
967ae81b69fSDrew Fustini 
th1520_clk_probe(struct platform_device * pdev)968ae81b69fSDrew Fustini static int th1520_clk_probe(struct platform_device *pdev)
969ae81b69fSDrew Fustini {
970ae81b69fSDrew Fustini 	struct device *dev = &pdev->dev;
971ae81b69fSDrew Fustini 	struct clk_hw_onecell_data *priv;
972ae81b69fSDrew Fustini 
973ae81b69fSDrew Fustini 	struct regmap *map;
974ae81b69fSDrew Fustini 	void __iomem *base;
975ae81b69fSDrew Fustini 	struct clk_hw *hw;
976ae81b69fSDrew Fustini 	int ret, i;
977ae81b69fSDrew Fustini 
978ae81b69fSDrew Fustini 	priv = devm_kzalloc(dev, struct_size(priv, hws, NR_CLKS), GFP_KERNEL);
979ae81b69fSDrew Fustini 	if (!priv)
980ae81b69fSDrew Fustini 		return -ENOMEM;
981ae81b69fSDrew Fustini 
982ae81b69fSDrew Fustini 	priv->num = NR_CLKS;
983ae81b69fSDrew Fustini 
984ae81b69fSDrew Fustini 	base = devm_platform_ioremap_resource(pdev, 0);
985ae81b69fSDrew Fustini 	if (IS_ERR(base))
986ae81b69fSDrew Fustini 		return PTR_ERR(base);
987ae81b69fSDrew Fustini 
988ae81b69fSDrew Fustini 	map = devm_regmap_init_mmio(dev, base, &th1520_clk_regmap_config);
989ae81b69fSDrew Fustini 	if (IS_ERR(map))
990ae81b69fSDrew Fustini 		return PTR_ERR(map);
991ae81b69fSDrew Fustini 
992ae81b69fSDrew Fustini 	for (i = 0; i < ARRAY_SIZE(th1520_pll_clks); i++) {
993ae81b69fSDrew Fustini 		struct ccu_pll *cp = hw_to_ccu_pll(&th1520_pll_clks[i]->hw);
994ae81b69fSDrew Fustini 
995ae81b69fSDrew Fustini 		th1520_pll_clks[i]->map = map;
996ae81b69fSDrew Fustini 
997ae81b69fSDrew Fustini 		ret = devm_clk_hw_register(dev, &th1520_pll_clks[i]->hw);
998ae81b69fSDrew Fustini 		if (ret)
999ae81b69fSDrew Fustini 			return ret;
1000ae81b69fSDrew Fustini 
1001ae81b69fSDrew Fustini 		priv->hws[cp->common.clkid] = &cp->common.hw;
1002ae81b69fSDrew Fustini 	}
1003ae81b69fSDrew Fustini 
1004ae81b69fSDrew Fustini 	for (i = 0; i < ARRAY_SIZE(th1520_div_clks); i++) {
1005ae81b69fSDrew Fustini 		struct ccu_div *cd = hw_to_ccu_div(&th1520_div_clks[i]->hw);
1006ae81b69fSDrew Fustini 
1007ae81b69fSDrew Fustini 		th1520_div_clks[i]->map = map;
1008ae81b69fSDrew Fustini 
1009ae81b69fSDrew Fustini 		ret = devm_clk_hw_register(dev, &th1520_div_clks[i]->hw);
1010ae81b69fSDrew Fustini 		if (ret)
1011ae81b69fSDrew Fustini 			return ret;
1012ae81b69fSDrew Fustini 
1013ae81b69fSDrew Fustini 		priv->hws[cd->common.clkid] = &cd->common.hw;
1014ae81b69fSDrew Fustini 	}
1015ae81b69fSDrew Fustini 
1016ae81b69fSDrew Fustini 	for (i = 0; i < ARRAY_SIZE(th1520_mux_clks); i++) {
1017ae81b69fSDrew Fustini 		struct ccu_mux *cm = hw_to_ccu_mux(&th1520_mux_clks[i]->hw);
1018ae81b69fSDrew Fustini 		const struct clk_init_data *init = cm->common.hw.init;
1019ae81b69fSDrew Fustini 
1020ae81b69fSDrew Fustini 		th1520_mux_clks[i]->map = map;
1021ae81b69fSDrew Fustini 		hw = devm_clk_hw_register_mux_parent_data_table(dev,
1022ae81b69fSDrew Fustini 								init->name,
1023ae81b69fSDrew Fustini 								init->parent_data,
1024ae81b69fSDrew Fustini 								init->num_parents,
1025ae81b69fSDrew Fustini 								0,
1026ae81b69fSDrew Fustini 								base + cm->common.cfg0,
1027ae81b69fSDrew Fustini 								cm->mux.shift,
1028ae81b69fSDrew Fustini 								cm->mux.width,
1029ae81b69fSDrew Fustini 								0, NULL, NULL);
1030ae81b69fSDrew Fustini 		if (IS_ERR(hw))
1031ae81b69fSDrew Fustini 			return PTR_ERR(hw);
1032ae81b69fSDrew Fustini 
1033ae81b69fSDrew Fustini 		priv->hws[cm->common.clkid] = hw;
1034ae81b69fSDrew Fustini 	}
1035ae81b69fSDrew Fustini 
1036ae81b69fSDrew Fustini 	for (i = 0; i < ARRAY_SIZE(th1520_gate_clks); i++) {
1037ae81b69fSDrew Fustini 		struct ccu_gate *cg = hw_to_ccu_gate(&th1520_gate_clks[i]->hw);
1038ae81b69fSDrew Fustini 
1039ae81b69fSDrew Fustini 		th1520_gate_clks[i]->map = map;
1040ae81b69fSDrew Fustini 
1041ae81b69fSDrew Fustini 		hw = devm_clk_hw_register_gate_parent_data(dev,
1042ae81b69fSDrew Fustini 							   cg->common.hw.init->name,
1043ae81b69fSDrew Fustini 							   cg->common.hw.init->parent_data,
1044ae81b69fSDrew Fustini 							   0, base + cg->common.cfg0,
1045ae81b69fSDrew Fustini 							   ffs(cg->enable) - 1, 0, NULL);
1046ae81b69fSDrew Fustini 		if (IS_ERR(hw))
1047ae81b69fSDrew Fustini 			return PTR_ERR(hw);
1048ae81b69fSDrew Fustini 
1049ae81b69fSDrew Fustini 		priv->hws[cg->common.clkid] = hw;
1050ae81b69fSDrew Fustini 	}
1051ae81b69fSDrew Fustini 
1052ae81b69fSDrew Fustini 	ret = devm_clk_hw_register(dev, &osc12m_clk.hw);
1053ae81b69fSDrew Fustini 	if (ret)
1054ae81b69fSDrew Fustini 		return ret;
1055ae81b69fSDrew Fustini 	priv->hws[CLK_OSC12M] = &osc12m_clk.hw;
1056ae81b69fSDrew Fustini 
1057ae81b69fSDrew Fustini 	ret = devm_clk_hw_register(dev, &gmac_pll_clk_100m.hw);
1058ae81b69fSDrew Fustini 	if (ret)
1059ae81b69fSDrew Fustini 		return ret;
1060ae81b69fSDrew Fustini 	priv->hws[CLK_PLL_GMAC_100M] = &gmac_pll_clk_100m.hw;
1061ae81b69fSDrew Fustini 
1062ae81b69fSDrew Fustini 	ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, priv);
1063ae81b69fSDrew Fustini 	if (ret)
1064ae81b69fSDrew Fustini 		return ret;
1065ae81b69fSDrew Fustini 
1066ae81b69fSDrew Fustini 	return 0;
1067ae81b69fSDrew Fustini }
1068ae81b69fSDrew Fustini 
1069ae81b69fSDrew Fustini static const struct of_device_id th1520_clk_match[] = {
1070ae81b69fSDrew Fustini 	{
1071ae81b69fSDrew Fustini 		.compatible = "thead,th1520-clk-ap",
1072ae81b69fSDrew Fustini 	},
1073ae81b69fSDrew Fustini 	{ /* sentinel */ },
1074ae81b69fSDrew Fustini };
1075ae81b69fSDrew Fustini MODULE_DEVICE_TABLE(of, th1520_clk_match);
1076ae81b69fSDrew Fustini 
1077ae81b69fSDrew Fustini static struct platform_driver th1520_clk_driver = {
1078ae81b69fSDrew Fustini 	.probe		= th1520_clk_probe,
1079ae81b69fSDrew Fustini 	.driver		= {
1080ae81b69fSDrew Fustini 		.name	= "th1520-clk",
1081ae81b69fSDrew Fustini 		.of_match_table = th1520_clk_match,
1082ae81b69fSDrew Fustini 	},
1083ae81b69fSDrew Fustini };
1084ae81b69fSDrew Fustini module_platform_driver(th1520_clk_driver);
1085ae81b69fSDrew Fustini 
1086ae81b69fSDrew Fustini MODULE_DESCRIPTION("T-HEAD TH1520 AP Clock driver");
1087ae81b69fSDrew Fustini MODULE_AUTHOR("Yangtao Li <frank.li@vivo.com>");
1088ae81b69fSDrew Fustini MODULE_AUTHOR("Jisheng Zhang <jszhang@kernel.org>");
1089ae81b69fSDrew Fustini MODULE_LICENSE("GPL");
1090