xref: /openbmc/linux/drivers/clk/at91/sama7g5.c (revision 7996dfd6)
1cb783bbbSClaudiu Beznea // SPDX-License-Identifier: GPL-2.0
2cb783bbbSClaudiu Beznea /*
3cb783bbbSClaudiu Beznea  * SAMA7G5 PMC code.
4cb783bbbSClaudiu Beznea  *
5cb783bbbSClaudiu Beznea  * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries
6cb783bbbSClaudiu Beznea  *
7cb783bbbSClaudiu Beznea  * Author: Claudiu Beznea <claudiu.beznea@microchip.com>
8cb783bbbSClaudiu Beznea  *
9cb783bbbSClaudiu Beznea  */
10cb783bbbSClaudiu Beznea #include <linux/clk.h>
11cb783bbbSClaudiu Beznea #include <linux/clk-provider.h>
12cb783bbbSClaudiu Beznea #include <linux/mfd/syscon.h>
13cb783bbbSClaudiu Beznea #include <linux/slab.h>
14cb783bbbSClaudiu Beznea 
15cb783bbbSClaudiu Beznea #include <dt-bindings/clock/at91.h>
16cb783bbbSClaudiu Beznea 
17cb783bbbSClaudiu Beznea #include "pmc.h"
18cb783bbbSClaudiu Beznea 
19cb783bbbSClaudiu Beznea #define SAMA7G5_INIT_TABLE(_table, _count)		\
20cb783bbbSClaudiu Beznea 	do {						\
21cb783bbbSClaudiu Beznea 		u8 _i;					\
22cb783bbbSClaudiu Beznea 		for (_i = 0; _i < (_count); _i++)	\
23cb783bbbSClaudiu Beznea 			(_table)[_i] = _i;		\
24cb783bbbSClaudiu Beznea 	} while (0)
25cb783bbbSClaudiu Beznea 
26cb783bbbSClaudiu Beznea #define SAMA7G5_FILL_TABLE(_to, _from, _count)		\
27cb783bbbSClaudiu Beznea 	do {						\
28cb783bbbSClaudiu Beznea 		u8 _i;					\
29cb783bbbSClaudiu Beznea 		for (_i = 0; _i < (_count); _i++) {	\
30cb783bbbSClaudiu Beznea 			(_to)[_i] = (_from)[_i];	\
31cb783bbbSClaudiu Beznea 		}					\
32cb783bbbSClaudiu Beznea 	} while (0)
33cb783bbbSClaudiu Beznea 
34cb783bbbSClaudiu Beznea static DEFINE_SPINLOCK(pmc_pll_lock);
357a110b91SClaudiu Beznea static DEFINE_SPINLOCK(pmc_mck0_lock);
36cb783bbbSClaudiu Beznea static DEFINE_SPINLOCK(pmc_mckX_lock);
37cb783bbbSClaudiu Beznea 
38cb783bbbSClaudiu Beznea /**
39cb783bbbSClaudiu Beznea  * PLL clocks identifiers
40cb783bbbSClaudiu Beznea  * @PLL_ID_CPU:		CPU PLL identifier
41cb783bbbSClaudiu Beznea  * @PLL_ID_SYS:		System PLL identifier
42cb783bbbSClaudiu Beznea  * @PLL_ID_DDR:		DDR PLL identifier
43cb783bbbSClaudiu Beznea  * @PLL_ID_IMG:		Image subsystem PLL identifier
44cb783bbbSClaudiu Beznea  * @PLL_ID_BAUD:	Baud PLL identifier
45cb783bbbSClaudiu Beznea  * @PLL_ID_AUDIO:	Audio PLL identifier
46cb783bbbSClaudiu Beznea  * @PLL_ID_ETH:		Ethernet PLL identifier
47cb783bbbSClaudiu Beznea  */
48cb783bbbSClaudiu Beznea enum pll_ids {
49cb783bbbSClaudiu Beznea 	PLL_ID_CPU,
50cb783bbbSClaudiu Beznea 	PLL_ID_SYS,
51cb783bbbSClaudiu Beznea 	PLL_ID_DDR,
52cb783bbbSClaudiu Beznea 	PLL_ID_IMG,
53cb783bbbSClaudiu Beznea 	PLL_ID_BAUD,
54cb783bbbSClaudiu Beznea 	PLL_ID_AUDIO,
55cb783bbbSClaudiu Beznea 	PLL_ID_ETH,
56cb783bbbSClaudiu Beznea 	PLL_ID_MAX,
57cb783bbbSClaudiu Beznea };
58cb783bbbSClaudiu Beznea 
59cb783bbbSClaudiu Beznea /**
60cb783bbbSClaudiu Beznea  * PLL type identifiers
61cb783bbbSClaudiu Beznea  * @PLL_TYPE_FRAC:	fractional PLL identifier
62cb783bbbSClaudiu Beznea  * @PLL_TYPE_DIV:	divider PLL identifier
63cb783bbbSClaudiu Beznea  */
64cb783bbbSClaudiu Beznea enum pll_type {
65cb783bbbSClaudiu Beznea 	PLL_TYPE_FRAC,
66cb783bbbSClaudiu Beznea 	PLL_TYPE_DIV,
67cb783bbbSClaudiu Beznea };
68cb783bbbSClaudiu Beznea 
69cb783bbbSClaudiu Beznea /* Layout for fractional PLLs. */
70cb783bbbSClaudiu Beznea static const struct clk_pll_layout pll_layout_frac = {
71cb783bbbSClaudiu Beznea 	.mul_mask	= GENMASK(31, 24),
72cb783bbbSClaudiu Beznea 	.frac_mask	= GENMASK(21, 0),
73cb783bbbSClaudiu Beznea 	.mul_shift	= 24,
74cb783bbbSClaudiu Beznea 	.frac_shift	= 0,
75cb783bbbSClaudiu Beznea };
76cb783bbbSClaudiu Beznea 
77cb783bbbSClaudiu Beznea /* Layout for DIVPMC dividers. */
78cb783bbbSClaudiu Beznea static const struct clk_pll_layout pll_layout_divpmc = {
79cb783bbbSClaudiu Beznea 	.div_mask	= GENMASK(7, 0),
80cb783bbbSClaudiu Beznea 	.endiv_mask	= BIT(29),
81cb783bbbSClaudiu Beznea 	.div_shift	= 0,
82cb783bbbSClaudiu Beznea 	.endiv_shift	= 29,
83cb783bbbSClaudiu Beznea };
84cb783bbbSClaudiu Beznea 
85cb783bbbSClaudiu Beznea /* Layout for DIVIO dividers. */
86cb783bbbSClaudiu Beznea static const struct clk_pll_layout pll_layout_divio = {
87cb783bbbSClaudiu Beznea 	.div_mask	= GENMASK(19, 12),
88cb783bbbSClaudiu Beznea 	.endiv_mask	= BIT(30),
89cb783bbbSClaudiu Beznea 	.div_shift	= 12,
90cb783bbbSClaudiu Beznea 	.endiv_shift	= 30,
91cb783bbbSClaudiu Beznea };
92cb783bbbSClaudiu Beznea 
93120d5d8bSClaudiu Beznea /*
94120d5d8bSClaudiu Beznea  * CPU PLL output range.
95120d5d8bSClaudiu Beznea  * Notice: The upper limit has been setup to 1000000002 due to hardware
96120d5d8bSClaudiu Beznea  * block which cannot output exactly 1GHz.
97120d5d8bSClaudiu Beznea  */
98120d5d8bSClaudiu Beznea static const struct clk_range cpu_pll_outputs[] = {
99120d5d8bSClaudiu Beznea 	{ .min = 2343750, .max = 1000000002 },
100120d5d8bSClaudiu Beznea };
101120d5d8bSClaudiu Beznea 
102120d5d8bSClaudiu Beznea /* PLL output range. */
103120d5d8bSClaudiu Beznea static const struct clk_range pll_outputs[] = {
104120d5d8bSClaudiu Beznea 	{ .min = 2343750, .max = 1200000000 },
105120d5d8bSClaudiu Beznea };
106120d5d8bSClaudiu Beznea 
107120d5d8bSClaudiu Beznea /* CPU PLL characteristics. */
108120d5d8bSClaudiu Beznea static const struct clk_pll_characteristics cpu_pll_characteristics = {
109120d5d8bSClaudiu Beznea 	.input = { .min = 12000000, .max = 50000000 },
110120d5d8bSClaudiu Beznea 	.num_output = ARRAY_SIZE(cpu_pll_outputs),
111120d5d8bSClaudiu Beznea 	.output = cpu_pll_outputs,
112120d5d8bSClaudiu Beznea };
113120d5d8bSClaudiu Beznea 
114120d5d8bSClaudiu Beznea /* PLL characteristics. */
115120d5d8bSClaudiu Beznea static const struct clk_pll_characteristics pll_characteristics = {
116120d5d8bSClaudiu Beznea 	.input = { .min = 12000000, .max = 50000000 },
117120d5d8bSClaudiu Beznea 	.num_output = ARRAY_SIZE(pll_outputs),
118120d5d8bSClaudiu Beznea 	.output = pll_outputs,
119120d5d8bSClaudiu Beznea };
120120d5d8bSClaudiu Beznea 
121cb783bbbSClaudiu Beznea /**
122cb783bbbSClaudiu Beznea  * PLL clocks description
123cb783bbbSClaudiu Beznea  * @n:		clock name
124cb783bbbSClaudiu Beznea  * @p:		clock parent
125cb783bbbSClaudiu Beznea  * @l:		clock layout
126120d5d8bSClaudiu Beznea  * @c:		clock characteristics
127cb783bbbSClaudiu Beznea  * @t:		clock type
1288dc4af8bSClaudiu Beznea  * @f:		clock flags
129cb783bbbSClaudiu Beznea  * @eid:	export index in sama7g5->chws[] array
130cb783bbbSClaudiu Beznea  */
131cb783bbbSClaudiu Beznea static const struct {
132cb783bbbSClaudiu Beznea 	const char *n;
133cb783bbbSClaudiu Beznea 	const char *p;
134cb783bbbSClaudiu Beznea 	const struct clk_pll_layout *l;
135120d5d8bSClaudiu Beznea 	const struct clk_pll_characteristics *c;
1368dc4af8bSClaudiu Beznea 	unsigned long f;
137cb783bbbSClaudiu Beznea 	u8 t;
138cb783bbbSClaudiu Beznea 	u8 eid;
139cb783bbbSClaudiu Beznea } sama7g5_plls[][PLL_ID_MAX] = {
140cb783bbbSClaudiu Beznea 	[PLL_ID_CPU] = {
141cb783bbbSClaudiu Beznea 		{ .n = "cpupll_fracck",
142cb783bbbSClaudiu Beznea 		  .p = "mainck",
143cb783bbbSClaudiu Beznea 		  .l = &pll_layout_frac,
144120d5d8bSClaudiu Beznea 		  .c = &cpu_pll_characteristics,
145cb783bbbSClaudiu Beznea 		  .t = PLL_TYPE_FRAC,
1468dc4af8bSClaudiu Beznea 		   /*
1478dc4af8bSClaudiu Beznea 		    * This feeds cpupll_divpmcck which feeds CPU. It should
1488dc4af8bSClaudiu Beznea 		    * not be disabled.
1498dc4af8bSClaudiu Beznea 		    */
1508dc4af8bSClaudiu Beznea 		  .f = CLK_IS_CRITICAL, },
151cb783bbbSClaudiu Beznea 
152cb783bbbSClaudiu Beznea 		{ .n = "cpupll_divpmcck",
153cb783bbbSClaudiu Beznea 		  .p = "cpupll_fracck",
154cb783bbbSClaudiu Beznea 		  .l = &pll_layout_divpmc,
155120d5d8bSClaudiu Beznea 		  .c = &cpu_pll_characteristics,
156cb783bbbSClaudiu Beznea 		  .t = PLL_TYPE_DIV,
1578dc4af8bSClaudiu Beznea 		   /* This feeds CPU. It should not be disabled. */
1588dc4af8bSClaudiu Beznea 		  .f = CLK_IS_CRITICAL | CLK_SET_RATE_PARENT,
15983d00287SEugen Hristev 		  .eid = PMC_CPUPLL, },
160cb783bbbSClaudiu Beznea 	},
161cb783bbbSClaudiu Beznea 
162cb783bbbSClaudiu Beznea 	[PLL_ID_SYS] = {
163cb783bbbSClaudiu Beznea 		{ .n = "syspll_fracck",
164cb783bbbSClaudiu Beznea 		  .p = "mainck",
165cb783bbbSClaudiu Beznea 		  .l = &pll_layout_frac,
166120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
167cb783bbbSClaudiu Beznea 		  .t = PLL_TYPE_FRAC,
1688dc4af8bSClaudiu Beznea 		   /*
169*7996dfd6SBhaskar Chowdhury 		    * This feeds syspll_divpmcck which may feed critical parts
1708dc4af8bSClaudiu Beznea 		    * of the systems like timers. Therefore it should not be
1718dc4af8bSClaudiu Beznea 		    * disabled.
1728dc4af8bSClaudiu Beznea 		    */
1738dc4af8bSClaudiu Beznea 		  .f = CLK_IS_CRITICAL | CLK_SET_RATE_GATE, },
174cb783bbbSClaudiu Beznea 
175cb783bbbSClaudiu Beznea 		{ .n = "syspll_divpmcck",
176cb783bbbSClaudiu Beznea 		  .p = "syspll_fracck",
177cb783bbbSClaudiu Beznea 		  .l = &pll_layout_divpmc,
178120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
179cb783bbbSClaudiu Beznea 		  .t = PLL_TYPE_DIV,
1808dc4af8bSClaudiu Beznea 		   /*
181*7996dfd6SBhaskar Chowdhury 		    * This may feed critical parts of the systems like timers.
1828dc4af8bSClaudiu Beznea 		    * Therefore it should not be disabled.
1838dc4af8bSClaudiu Beznea 		    */
1848dc4af8bSClaudiu Beznea 		  .f = CLK_IS_CRITICAL | CLK_SET_RATE_GATE,
18583d00287SEugen Hristev 		  .eid = PMC_SYSPLL, },
186cb783bbbSClaudiu Beznea 	},
187cb783bbbSClaudiu Beznea 
188cb783bbbSClaudiu Beznea 	[PLL_ID_DDR] = {
189cb783bbbSClaudiu Beznea 		{ .n = "ddrpll_fracck",
190cb783bbbSClaudiu Beznea 		  .p = "mainck",
191cb783bbbSClaudiu Beznea 		  .l = &pll_layout_frac,
192120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
193cb783bbbSClaudiu Beznea 		  .t = PLL_TYPE_FRAC,
1948dc4af8bSClaudiu Beznea 		   /*
1958dc4af8bSClaudiu Beznea 		    * This feeds ddrpll_divpmcck which feeds DDR. It should not
1968dc4af8bSClaudiu Beznea 		    * be disabled.
1978dc4af8bSClaudiu Beznea 		    */
1988dc4af8bSClaudiu Beznea 		  .f = CLK_IS_CRITICAL | CLK_SET_RATE_GATE, },
199cb783bbbSClaudiu Beznea 
200cb783bbbSClaudiu Beznea 		{ .n = "ddrpll_divpmcck",
201cb783bbbSClaudiu Beznea 		  .p = "ddrpll_fracck",
202cb783bbbSClaudiu Beznea 		  .l = &pll_layout_divpmc,
203120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
204cb783bbbSClaudiu Beznea 		  .t = PLL_TYPE_DIV,
2058dc4af8bSClaudiu Beznea 		   /* This feeds DDR. It should not be disabled. */
2068dc4af8bSClaudiu Beznea 		  .f = CLK_IS_CRITICAL | CLK_SET_RATE_GATE, },
207cb783bbbSClaudiu Beznea 	},
208cb783bbbSClaudiu Beznea 
209cb783bbbSClaudiu Beznea 	[PLL_ID_IMG] = {
210cb783bbbSClaudiu Beznea 		{ .n = "imgpll_fracck",
211cb783bbbSClaudiu Beznea 		  .p = "mainck",
212cb783bbbSClaudiu Beznea 		  .l = &pll_layout_frac,
213120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
2148dc4af8bSClaudiu Beznea 		  .t = PLL_TYPE_FRAC,
2158dc4af8bSClaudiu Beznea 		  .f = CLK_SET_RATE_GATE, },
216cb783bbbSClaudiu Beznea 
217cb783bbbSClaudiu Beznea 		{ .n = "imgpll_divpmcck",
218cb783bbbSClaudiu Beznea 		  .p = "imgpll_fracck",
219cb783bbbSClaudiu Beznea 		  .l = &pll_layout_divpmc,
220120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
2218dc4af8bSClaudiu Beznea 		  .t = PLL_TYPE_DIV,
2228dc4af8bSClaudiu Beznea 		  .f = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE |
2238dc4af8bSClaudiu Beznea 		       CLK_SET_RATE_PARENT, },
224cb783bbbSClaudiu Beznea 	},
225cb783bbbSClaudiu Beznea 
226cb783bbbSClaudiu Beznea 	[PLL_ID_BAUD] = {
227cb783bbbSClaudiu Beznea 		{ .n = "baudpll_fracck",
228cb783bbbSClaudiu Beznea 		  .p = "mainck",
229cb783bbbSClaudiu Beznea 		  .l = &pll_layout_frac,
230120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
2318dc4af8bSClaudiu Beznea 		  .t = PLL_TYPE_FRAC,
2328dc4af8bSClaudiu Beznea 		  .f = CLK_SET_RATE_GATE, },
233cb783bbbSClaudiu Beznea 
234cb783bbbSClaudiu Beznea 		{ .n = "baudpll_divpmcck",
235cb783bbbSClaudiu Beznea 		  .p = "baudpll_fracck",
236cb783bbbSClaudiu Beznea 		  .l = &pll_layout_divpmc,
237120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
2388dc4af8bSClaudiu Beznea 		  .t = PLL_TYPE_DIV,
2398dc4af8bSClaudiu Beznea 		  .f = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE |
2408dc4af8bSClaudiu Beznea 		       CLK_SET_RATE_PARENT, },
241cb783bbbSClaudiu Beznea 	},
242cb783bbbSClaudiu Beznea 
243cb783bbbSClaudiu Beznea 	[PLL_ID_AUDIO] = {
244cb783bbbSClaudiu Beznea 		{ .n = "audiopll_fracck",
245cb783bbbSClaudiu Beznea 		  .p = "main_xtal",
246cb783bbbSClaudiu Beznea 		  .l = &pll_layout_frac,
247120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
2488dc4af8bSClaudiu Beznea 		  .t = PLL_TYPE_FRAC,
2498dc4af8bSClaudiu Beznea 		  .f = CLK_SET_RATE_GATE, },
250cb783bbbSClaudiu Beznea 
251cb783bbbSClaudiu Beznea 		{ .n = "audiopll_divpmcck",
252cb783bbbSClaudiu Beznea 		  .p = "audiopll_fracck",
253cb783bbbSClaudiu Beznea 		  .l = &pll_layout_divpmc,
254120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
255cb783bbbSClaudiu Beznea 		  .t = PLL_TYPE_DIV,
2568dc4af8bSClaudiu Beznea 		  .f = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE |
2578dc4af8bSClaudiu Beznea 		       CLK_SET_RATE_PARENT,
2583d86ee17SEugen Hristev 		  .eid = PMC_AUDIOPMCPLL, },
259cb783bbbSClaudiu Beznea 
260cb783bbbSClaudiu Beznea 		{ .n = "audiopll_diviock",
261cb783bbbSClaudiu Beznea 		  .p = "audiopll_fracck",
262cb783bbbSClaudiu Beznea 		  .l = &pll_layout_divio,
263120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
264cb783bbbSClaudiu Beznea 		  .t = PLL_TYPE_DIV,
2658dc4af8bSClaudiu Beznea 		  .f = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE |
2668dc4af8bSClaudiu Beznea 		       CLK_SET_RATE_PARENT,
2673d86ee17SEugen Hristev 		  .eid = PMC_AUDIOIOPLL, },
268cb783bbbSClaudiu Beznea 	},
269cb783bbbSClaudiu Beznea 
270cb783bbbSClaudiu Beznea 	[PLL_ID_ETH] = {
271cb783bbbSClaudiu Beznea 		{ .n = "ethpll_fracck",
272cb783bbbSClaudiu Beznea 		  .p = "main_xtal",
273cb783bbbSClaudiu Beznea 		  .l = &pll_layout_frac,
274120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
2758dc4af8bSClaudiu Beznea 		  .t = PLL_TYPE_FRAC,
2768dc4af8bSClaudiu Beznea 		  .f = CLK_SET_RATE_GATE, },
277cb783bbbSClaudiu Beznea 
278cb783bbbSClaudiu Beznea 		{ .n = "ethpll_divpmcck",
279cb783bbbSClaudiu Beznea 		  .p = "ethpll_fracck",
280cb783bbbSClaudiu Beznea 		  .l = &pll_layout_divpmc,
281120d5d8bSClaudiu Beznea 		  .c = &pll_characteristics,
2828dc4af8bSClaudiu Beznea 		  .t = PLL_TYPE_DIV,
2838dc4af8bSClaudiu Beznea 		  .f = CLK_SET_RATE_GATE | CLK_SET_PARENT_GATE |
2848dc4af8bSClaudiu Beznea 		       CLK_SET_RATE_PARENT, },
285cb783bbbSClaudiu Beznea 	},
286cb783bbbSClaudiu Beznea };
287cb783bbbSClaudiu Beznea 
288cb783bbbSClaudiu Beznea /**
289cb783bbbSClaudiu Beznea  * Master clock (MCK[1..4]) description
290cb783bbbSClaudiu Beznea  * @n:			clock name
291cb783bbbSClaudiu Beznea  * @ep:			extra parents names array
292cb783bbbSClaudiu Beznea  * @ep_chg_chg_id:	index in parents array that specifies the changeable
293cb783bbbSClaudiu Beznea  *			parent
294cb783bbbSClaudiu Beznea  * @ep_count:		extra parents count
295cb783bbbSClaudiu Beznea  * @ep_mux_table:	mux table for extra parents
296cb783bbbSClaudiu Beznea  * @id:			clock id
297cb783bbbSClaudiu Beznea  * @c:			true if clock is critical and cannot be disabled
298cb783bbbSClaudiu Beznea  */
299cb783bbbSClaudiu Beznea static const struct {
300cb783bbbSClaudiu Beznea 	const char *n;
301cb783bbbSClaudiu Beznea 	const char *ep[4];
302cb783bbbSClaudiu Beznea 	int ep_chg_id;
303cb783bbbSClaudiu Beznea 	u8 ep_count;
304cb783bbbSClaudiu Beznea 	u8 ep_mux_table[4];
305cb783bbbSClaudiu Beznea 	u8 id;
306cb783bbbSClaudiu Beznea 	u8 c;
307cb783bbbSClaudiu Beznea } sama7g5_mckx[] = {
308cb783bbbSClaudiu Beznea 	{ .n = "mck1",
309cb783bbbSClaudiu Beznea 	  .id = 1,
310cb783bbbSClaudiu Beznea 	  .ep = { "syspll_divpmcck", },
311cb783bbbSClaudiu Beznea 	  .ep_mux_table = { 5, },
312cb783bbbSClaudiu Beznea 	  .ep_count = 1,
313cb783bbbSClaudiu Beznea 	  .ep_chg_id = INT_MIN,
314cb783bbbSClaudiu Beznea 	  .c = 1, },
315cb783bbbSClaudiu Beznea 
316cb783bbbSClaudiu Beznea 	{ .n = "mck2",
317cb783bbbSClaudiu Beznea 	  .id = 2,
318cb783bbbSClaudiu Beznea 	  .ep = { "ddrpll_divpmcck", },
319cb783bbbSClaudiu Beznea 	  .ep_mux_table = { 6, },
320cb783bbbSClaudiu Beznea 	  .ep_count = 1,
321cb783bbbSClaudiu Beznea 	  .ep_chg_id = INT_MIN,
322cb783bbbSClaudiu Beznea 	  .c = 1, },
323cb783bbbSClaudiu Beznea 
324cb783bbbSClaudiu Beznea 	{ .n = "mck3",
325cb783bbbSClaudiu Beznea 	  .id = 3,
326cb783bbbSClaudiu Beznea 	  .ep = { "syspll_divpmcck", "ddrpll_divpmcck", "imgpll_divpmcck", },
327cb783bbbSClaudiu Beznea 	  .ep_mux_table = { 5, 6, 7, },
328cb783bbbSClaudiu Beznea 	  .ep_count = 3,
3294011f03eSClaudiu Beznea 	  .ep_chg_id = 5, },
330cb783bbbSClaudiu Beznea 
331cb783bbbSClaudiu Beznea 	{ .n = "mck4",
332cb783bbbSClaudiu Beznea 	  .id = 4,
333cb783bbbSClaudiu Beznea 	  .ep = { "syspll_divpmcck", },
334cb783bbbSClaudiu Beznea 	  .ep_mux_table = { 5, },
335cb783bbbSClaudiu Beznea 	  .ep_count = 1,
336cb783bbbSClaudiu Beznea 	  .ep_chg_id = INT_MIN,
337cb783bbbSClaudiu Beznea 	  .c = 1, },
338cb783bbbSClaudiu Beznea };
339cb783bbbSClaudiu Beznea 
340cb783bbbSClaudiu Beznea /**
341cb783bbbSClaudiu Beznea  * System clock description
342cb783bbbSClaudiu Beznea  * @n:	clock name
343cb783bbbSClaudiu Beznea  * @p:	clock parent name
344cb783bbbSClaudiu Beznea  * @id: clock id
345cb783bbbSClaudiu Beznea  */
346cb783bbbSClaudiu Beznea static const struct {
347cb783bbbSClaudiu Beznea 	const char *n;
348cb783bbbSClaudiu Beznea 	const char *p;
349cb783bbbSClaudiu Beznea 	u8 id;
350cb783bbbSClaudiu Beznea } sama7g5_systemck[] = {
351cb783bbbSClaudiu Beznea 	{ .n = "pck0",		.p = "prog0", .id = 8, },
352cb783bbbSClaudiu Beznea 	{ .n = "pck1",		.p = "prog1", .id = 9, },
353cb783bbbSClaudiu Beznea 	{ .n = "pck2",		.p = "prog2", .id = 10, },
354cb783bbbSClaudiu Beznea 	{ .n = "pck3",		.p = "prog3", .id = 11, },
355cb783bbbSClaudiu Beznea 	{ .n = "pck4",		.p = "prog4", .id = 12, },
356cb783bbbSClaudiu Beznea 	{ .n = "pck5",		.p = "prog5", .id = 13, },
357cb783bbbSClaudiu Beznea 	{ .n = "pck6",		.p = "prog6", .id = 14, },
358cb783bbbSClaudiu Beznea 	{ .n = "pck7",		.p = "prog7", .id = 15, },
359cb783bbbSClaudiu Beznea };
360cb783bbbSClaudiu Beznea 
361cb783bbbSClaudiu Beznea /* Mux table for programmable clocks. */
3624011f03eSClaudiu Beznea static u32 sama7g5_prog_mux_table[] = { 0, 1, 2, 5, 6, 7, 8, 9, 10, };
363cb783bbbSClaudiu Beznea 
364cb783bbbSClaudiu Beznea /**
365cb783bbbSClaudiu Beznea  * Peripheral clock description
366cb783bbbSClaudiu Beznea  * @n:		clock name
367cb783bbbSClaudiu Beznea  * @p:		clock parent name
368cb783bbbSClaudiu Beznea  * @r:		clock range values
369cb783bbbSClaudiu Beznea  * @id:		clock id
370cb783bbbSClaudiu Beznea  * @chgp:	index in parent array of the changeable parent
371cb783bbbSClaudiu Beznea  */
372cb783bbbSClaudiu Beznea static const struct {
373cb783bbbSClaudiu Beznea 	const char *n;
374cb783bbbSClaudiu Beznea 	const char *p;
375cb783bbbSClaudiu Beznea 	struct clk_range r;
376cb783bbbSClaudiu Beznea 	u8 chgp;
377cb783bbbSClaudiu Beznea 	u8 id;
378cb783bbbSClaudiu Beznea } sama7g5_periphck[] = {
379cb783bbbSClaudiu Beznea 	{ .n = "pioA_clk",	.p = "mck0", .id = 11, },
380cb783bbbSClaudiu Beznea 	{ .n = "sfr_clk",	.p = "mck1", .id = 19, },
381cb783bbbSClaudiu Beznea 	{ .n = "hsmc_clk",	.p = "mck1", .id = 21, },
382cb783bbbSClaudiu Beznea 	{ .n = "xdmac0_clk",	.p = "mck1", .id = 22, },
383cb783bbbSClaudiu Beznea 	{ .n = "xdmac1_clk",	.p = "mck1", .id = 23, },
384cb783bbbSClaudiu Beznea 	{ .n = "xdmac2_clk",	.p = "mck1", .id = 24, },
385cb783bbbSClaudiu Beznea 	{ .n = "acc_clk",	.p = "mck1", .id = 25, },
386cb783bbbSClaudiu Beznea 	{ .n = "aes_clk",	.p = "mck1", .id = 27, },
387cb783bbbSClaudiu Beznea 	{ .n = "tzaesbasc_clk",	.p = "mck1", .id = 28, },
388cb783bbbSClaudiu Beznea 	{ .n = "asrc_clk",	.p = "mck1", .id = 30, .r = { .max = 200000000, }, },
389cb783bbbSClaudiu Beznea 	{ .n = "cpkcc_clk",	.p = "mck0", .id = 32, },
390cb783bbbSClaudiu Beznea 	{ .n = "csi_clk",	.p = "mck3", .id = 33, .r = { .max = 266000000, }, .chgp = 1, },
391cb783bbbSClaudiu Beznea 	{ .n = "csi2dc_clk",	.p = "mck3", .id = 34, .r = { .max = 266000000, }, .chgp = 1, },
392cb783bbbSClaudiu Beznea 	{ .n = "eic_clk",	.p = "mck1", .id = 37, },
393cb783bbbSClaudiu Beznea 	{ .n = "flex0_clk",	.p = "mck1", .id = 38, },
394cb783bbbSClaudiu Beznea 	{ .n = "flex1_clk",	.p = "mck1", .id = 39, },
395cb783bbbSClaudiu Beznea 	{ .n = "flex2_clk",	.p = "mck1", .id = 40, },
396cb783bbbSClaudiu Beznea 	{ .n = "flex3_clk",	.p = "mck1", .id = 41, },
397cb783bbbSClaudiu Beznea 	{ .n = "flex4_clk",	.p = "mck1", .id = 42, },
398cb783bbbSClaudiu Beznea 	{ .n = "flex5_clk",	.p = "mck1", .id = 43, },
399cb783bbbSClaudiu Beznea 	{ .n = "flex6_clk",	.p = "mck1", .id = 44, },
400cb783bbbSClaudiu Beznea 	{ .n = "flex7_clk",	.p = "mck1", .id = 45, },
401cb783bbbSClaudiu Beznea 	{ .n = "flex8_clk",	.p = "mck1", .id = 46, },
402cb783bbbSClaudiu Beznea 	{ .n = "flex9_clk",	.p = "mck1", .id = 47, },
403cb783bbbSClaudiu Beznea 	{ .n = "flex10_clk",	.p = "mck1", .id = 48, },
404cb783bbbSClaudiu Beznea 	{ .n = "flex11_clk",	.p = "mck1", .id = 49, },
405cb783bbbSClaudiu Beznea 	{ .n = "gmac0_clk",	.p = "mck1", .id = 51, },
406cb783bbbSClaudiu Beznea 	{ .n = "gmac1_clk",	.p = "mck1", .id = 52, },
407cb783bbbSClaudiu Beznea 	{ .n = "icm_clk",	.p = "mck1", .id = 55, },
408cb783bbbSClaudiu Beznea 	{ .n = "isc_clk",	.p = "mck3", .id = 56, .r = { .max = 266000000, }, .chgp = 1, },
409cb783bbbSClaudiu Beznea 	{ .n = "i2smcc0_clk",	.p = "mck1", .id = 57, .r = { .max = 200000000, }, },
410cb783bbbSClaudiu Beznea 	{ .n = "i2smcc1_clk",	.p = "mck1", .id = 58, .r = { .max = 200000000, }, },
411cb783bbbSClaudiu Beznea 	{ .n = "matrix_clk",	.p = "mck1", .id = 60, },
412cb783bbbSClaudiu Beznea 	{ .n = "mcan0_clk",	.p = "mck1", .id = 61, .r = { .max = 200000000, }, },
413cb783bbbSClaudiu Beznea 	{ .n = "mcan1_clk",	.p = "mck1", .id = 62, .r = { .max = 200000000, }, },
414cb783bbbSClaudiu Beznea 	{ .n = "mcan2_clk",	.p = "mck1", .id = 63, .r = { .max = 200000000, }, },
415cb783bbbSClaudiu Beznea 	{ .n = "mcan3_clk",	.p = "mck1", .id = 64, .r = { .max = 200000000, }, },
416cb783bbbSClaudiu Beznea 	{ .n = "mcan4_clk",	.p = "mck1", .id = 65, .r = { .max = 200000000, }, },
417cb783bbbSClaudiu Beznea 	{ .n = "mcan5_clk",	.p = "mck1", .id = 66, .r = { .max = 200000000, }, },
418cb783bbbSClaudiu Beznea 	{ .n = "pdmc0_clk",	.p = "mck1", .id = 68, .r = { .max = 200000000, }, },
419cb783bbbSClaudiu Beznea 	{ .n = "pdmc1_clk",	.p = "mck1", .id = 69, .r = { .max = 200000000, }, },
420cb783bbbSClaudiu Beznea 	{ .n = "pit64b0_clk",	.p = "mck1", .id = 70, },
421cb783bbbSClaudiu Beznea 	{ .n = "pit64b1_clk",	.p = "mck1", .id = 71, },
422cb783bbbSClaudiu Beznea 	{ .n = "pit64b2_clk",	.p = "mck1", .id = 72, },
423cb783bbbSClaudiu Beznea 	{ .n = "pit64b3_clk",	.p = "mck1", .id = 73, },
424cb783bbbSClaudiu Beznea 	{ .n = "pit64b4_clk",	.p = "mck1", .id = 74, },
425cb783bbbSClaudiu Beznea 	{ .n = "pit64b5_clk",	.p = "mck1", .id = 75, },
426cb783bbbSClaudiu Beznea 	{ .n = "pwm_clk",	.p = "mck1", .id = 77, },
427cb783bbbSClaudiu Beznea 	{ .n = "qspi0_clk",	.p = "mck1", .id = 78, },
428cb783bbbSClaudiu Beznea 	{ .n = "qspi1_clk",	.p = "mck1", .id = 79, },
429cb783bbbSClaudiu Beznea 	{ .n = "sdmmc0_clk",	.p = "mck1", .id = 80, },
430cb783bbbSClaudiu Beznea 	{ .n = "sdmmc1_clk",	.p = "mck1", .id = 81, },
431cb783bbbSClaudiu Beznea 	{ .n = "sdmmc2_clk",	.p = "mck1", .id = 82, },
432cb783bbbSClaudiu Beznea 	{ .n = "sha_clk",	.p = "mck1", .id = 83, },
433cb783bbbSClaudiu Beznea 	{ .n = "spdifrx_clk",	.p = "mck1", .id = 84, .r = { .max = 200000000, }, },
434cb783bbbSClaudiu Beznea 	{ .n = "spdiftx_clk",	.p = "mck1", .id = 85, .r = { .max = 200000000, }, },
435cb783bbbSClaudiu Beznea 	{ .n = "ssc0_clk",	.p = "mck1", .id = 86, .r = { .max = 200000000, }, },
436cb783bbbSClaudiu Beznea 	{ .n = "ssc1_clk",	.p = "mck1", .id = 87, .r = { .max = 200000000, }, },
437cb783bbbSClaudiu Beznea 	{ .n = "tcb0_ch0_clk",	.p = "mck1", .id = 88, .r = { .max = 200000000, }, },
438cb783bbbSClaudiu Beznea 	{ .n = "tcb0_ch1_clk",	.p = "mck1", .id = 89, .r = { .max = 200000000, }, },
439cb783bbbSClaudiu Beznea 	{ .n = "tcb0_ch2_clk",	.p = "mck1", .id = 90, .r = { .max = 200000000, }, },
440cb783bbbSClaudiu Beznea 	{ .n = "tcb1_ch0_clk",	.p = "mck1", .id = 91, .r = { .max = 200000000, }, },
441cb783bbbSClaudiu Beznea 	{ .n = "tcb1_ch1_clk",	.p = "mck1", .id = 92, .r = { .max = 200000000, }, },
442cb783bbbSClaudiu Beznea 	{ .n = "tcb1_ch2_clk",	.p = "mck1", .id = 93, .r = { .max = 200000000, }, },
443cb783bbbSClaudiu Beznea 	{ .n = "tcpca_clk",	.p = "mck1", .id = 94, },
444cb783bbbSClaudiu Beznea 	{ .n = "tcpcb_clk",	.p = "mck1", .id = 95, },
445cb783bbbSClaudiu Beznea 	{ .n = "tdes_clk",	.p = "mck1", .id = 96, },
446cb783bbbSClaudiu Beznea 	{ .n = "trng_clk",	.p = "mck1", .id = 97, },
447cb783bbbSClaudiu Beznea 	{ .n = "udphsa_clk",	.p = "mck1", .id = 104, },
448cb783bbbSClaudiu Beznea 	{ .n = "udphsb_clk",	.p = "mck1", .id = 105, },
449cb783bbbSClaudiu Beznea 	{ .n = "uhphs_clk",	.p = "mck1", .id = 106, },
450cb783bbbSClaudiu Beznea };
451cb783bbbSClaudiu Beznea 
452cb783bbbSClaudiu Beznea /**
453cb783bbbSClaudiu Beznea  * Generic clock description
454cb783bbbSClaudiu Beznea  * @n:			clock name
455cb783bbbSClaudiu Beznea  * @pp:			PLL parents
456cb783bbbSClaudiu Beznea  * @pp_mux_table:	PLL parents mux table
457cb783bbbSClaudiu Beznea  * @r:			clock output range
458*7996dfd6SBhaskar Chowdhury  * @pp_chg_id:		id in parent array of changeable PLL parent
459cb783bbbSClaudiu Beznea  * @pp_count:		PLL parents count
460cb783bbbSClaudiu Beznea  * @id:			clock id
461cb783bbbSClaudiu Beznea  */
462cb783bbbSClaudiu Beznea static const struct {
463cb783bbbSClaudiu Beznea 	const char *n;
464cb783bbbSClaudiu Beznea 	const char *pp[8];
465cb783bbbSClaudiu Beznea 	const char pp_mux_table[8];
466cb783bbbSClaudiu Beznea 	struct clk_range r;
467cb783bbbSClaudiu Beznea 	int pp_chg_id;
468cb783bbbSClaudiu Beznea 	u8 pp_count;
469cb783bbbSClaudiu Beznea 	u8 id;
470cb783bbbSClaudiu Beznea } sama7g5_gck[] = {
471cb783bbbSClaudiu Beznea 	{ .n  = "adc_gclk",
472cb783bbbSClaudiu Beznea 	  .id = 26,
473cb783bbbSClaudiu Beznea 	  .r = { .max = 100000000, },
474cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "audiopll_divpmcck", },
475cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 7, 9, },
476cb783bbbSClaudiu Beznea 	  .pp_count = 3,
477cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
478cb783bbbSClaudiu Beznea 
479cb783bbbSClaudiu Beznea 	{ .n  = "asrc_gclk",
480cb783bbbSClaudiu Beznea 	  .id = 30,
481cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
482cb783bbbSClaudiu Beznea 	  .pp = { "audiopll_divpmcck", },
483cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 9, },
484cb783bbbSClaudiu Beznea 	  .pp_count = 1,
4854011f03eSClaudiu Beznea 	  .pp_chg_id = 3, },
486cb783bbbSClaudiu Beznea 
487cb783bbbSClaudiu Beznea 	{ .n  = "csi_gclk",
488cb783bbbSClaudiu Beznea 	  .id = 33,
489cb783bbbSClaudiu Beznea 	  .r = { .max = 27000000  },
490cb783bbbSClaudiu Beznea 	  .pp = { "ddrpll_divpmcck", "imgpll_divpmcck", },
491cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 6, 7, },
492cb783bbbSClaudiu Beznea 	  .pp_count = 2,
493cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
494cb783bbbSClaudiu Beznea 
495cb783bbbSClaudiu Beznea 	{ .n  = "flex0_gclk",
496cb783bbbSClaudiu Beznea 	  .id = 38,
497cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
498cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
499cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
500cb783bbbSClaudiu Beznea 	  .pp_count = 2,
501cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
502cb783bbbSClaudiu Beznea 
503cb783bbbSClaudiu Beznea 	{ .n  = "flex1_gclk",
504cb783bbbSClaudiu Beznea 	  .id = 39,
505cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
506cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
507cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
508cb783bbbSClaudiu Beznea 	  .pp_count = 2,
509cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
510cb783bbbSClaudiu Beznea 
511cb783bbbSClaudiu Beznea 	{ .n  = "flex2_gclk",
512cb783bbbSClaudiu Beznea 	  .id = 40,
513cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
514cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
515cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
516cb783bbbSClaudiu Beznea 	  .pp_count = 2,
517cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
518cb783bbbSClaudiu Beznea 
519cb783bbbSClaudiu Beznea 	{ .n  = "flex3_gclk",
520cb783bbbSClaudiu Beznea 	  .id = 41,
521cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
522cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
523cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
524cb783bbbSClaudiu Beznea 	  .pp_count = 2,
525cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
526cb783bbbSClaudiu Beznea 
527cb783bbbSClaudiu Beznea 	{ .n  = "flex4_gclk",
528cb783bbbSClaudiu Beznea 	  .id = 42,
529cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
530cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
531cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
532cb783bbbSClaudiu Beznea 	  .pp_count = 2,
533cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
534cb783bbbSClaudiu Beznea 
535cb783bbbSClaudiu Beznea 	{ .n  = "flex5_gclk",
536cb783bbbSClaudiu Beznea 	  .id = 43,
537cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
538cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
539cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
540cb783bbbSClaudiu Beznea 	  .pp_count = 2,
541cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
542cb783bbbSClaudiu Beznea 
543cb783bbbSClaudiu Beznea 	{ .n  = "flex6_gclk",
544cb783bbbSClaudiu Beznea 	  .id = 44,
545cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
546cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
547cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
548cb783bbbSClaudiu Beznea 	  .pp_count = 2,
549cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
550cb783bbbSClaudiu Beznea 
551cb783bbbSClaudiu Beznea 	{ .n  = "flex7_gclk",
552cb783bbbSClaudiu Beznea 	  .id = 45,
553cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
554cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
555cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
556cb783bbbSClaudiu Beznea 	  .pp_count = 2,
557cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
558cb783bbbSClaudiu Beznea 
559cb783bbbSClaudiu Beznea 	{ .n  = "flex8_gclk",
560cb783bbbSClaudiu Beznea 	  .id = 46,
561cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
562cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
563cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
564cb783bbbSClaudiu Beznea 	  .pp_count = 2,
565cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
566cb783bbbSClaudiu Beznea 
567cb783bbbSClaudiu Beznea 	{ .n  = "flex9_gclk",
568cb783bbbSClaudiu Beznea 	  .id = 47,
569cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
570cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
571cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
572cb783bbbSClaudiu Beznea 	  .pp_count = 2,
573cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
574cb783bbbSClaudiu Beznea 
575cb783bbbSClaudiu Beznea 	{ .n  = "flex10_gclk",
576cb783bbbSClaudiu Beznea 	  .id = 48,
577cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
578cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
579cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
580cb783bbbSClaudiu Beznea 	  .pp_count = 2,
581cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
582cb783bbbSClaudiu Beznea 
583cb783bbbSClaudiu Beznea 	{ .n  = "flex11_gclk",
584cb783bbbSClaudiu Beznea 	  .id = 49,
585cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
586cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
587cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
588cb783bbbSClaudiu Beznea 	  .pp_count = 2,
589cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
590cb783bbbSClaudiu Beznea 
591cb783bbbSClaudiu Beznea 	{ .n  = "gmac0_gclk",
592cb783bbbSClaudiu Beznea 	  .id = 51,
593cb783bbbSClaudiu Beznea 	  .r = { .max = 125000000 },
594cb783bbbSClaudiu Beznea 	  .pp = { "ethpll_divpmcck", },
595cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 10, },
596cb783bbbSClaudiu Beznea 	  .pp_count = 1,
5974011f03eSClaudiu Beznea 	  .pp_chg_id = 3, },
598cb783bbbSClaudiu Beznea 
599cb783bbbSClaudiu Beznea 	{ .n  = "gmac1_gclk",
600cb783bbbSClaudiu Beznea 	  .id = 52,
601cb783bbbSClaudiu Beznea 	  .r = { .max = 50000000  },
602cb783bbbSClaudiu Beznea 	  .pp = { "ethpll_divpmcck", },
603cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 10, },
604cb783bbbSClaudiu Beznea 	  .pp_count = 1,
605cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
606cb783bbbSClaudiu Beznea 
607cb783bbbSClaudiu Beznea 	{ .n  = "gmac0_tsu_gclk",
608cb783bbbSClaudiu Beznea 	  .id = 53,
609cb783bbbSClaudiu Beznea 	  .r = { .max = 300000000 },
610cb783bbbSClaudiu Beznea 	  .pp = { "audiopll_divpmcck", "ethpll_divpmcck", },
611cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 9, 10, },
612cb783bbbSClaudiu Beznea 	  .pp_count = 2,
613cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
614cb783bbbSClaudiu Beznea 
615cb783bbbSClaudiu Beznea 	{ .n  = "gmac1_tsu_gclk",
616cb783bbbSClaudiu Beznea 	  .id = 54,
617cb783bbbSClaudiu Beznea 	  .r = { .max = 300000000 },
618cb783bbbSClaudiu Beznea 	  .pp = { "audiopll_divpmcck", "ethpll_divpmcck", },
619cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 9, 10, },
620cb783bbbSClaudiu Beznea 	  .pp_count = 2,
621cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
622cb783bbbSClaudiu Beznea 
623cb783bbbSClaudiu Beznea 	{ .n  = "i2smcc0_gclk",
624cb783bbbSClaudiu Beznea 	  .id = 57,
625cb783bbbSClaudiu Beznea 	  .r = { .max = 100000000 },
626cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "audiopll_divpmcck", },
627cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 9, },
628cb783bbbSClaudiu Beznea 	  .pp_count = 2,
6294011f03eSClaudiu Beznea 	  .pp_chg_id = 4, },
630cb783bbbSClaudiu Beznea 
631cb783bbbSClaudiu Beznea 	{ .n  = "i2smcc1_gclk",
632cb783bbbSClaudiu Beznea 	  .id = 58,
633cb783bbbSClaudiu Beznea 	  .r = { .max = 100000000 },
634cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "audiopll_divpmcck", },
635cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 9, },
636cb783bbbSClaudiu Beznea 	  .pp_count = 2,
6374011f03eSClaudiu Beznea 	  .pp_chg_id = 4, },
638cb783bbbSClaudiu Beznea 
639cb783bbbSClaudiu Beznea 	{ .n  = "mcan0_gclk",
640cb783bbbSClaudiu Beznea 	  .id = 61,
641cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
642cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
643cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
644cb783bbbSClaudiu Beznea 	  .pp_count = 2,
645cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
646cb783bbbSClaudiu Beznea 
647cb783bbbSClaudiu Beznea 	{ .n  = "mcan1_gclk",
648cb783bbbSClaudiu Beznea 	  .id = 62,
649cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
650cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
651cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
652cb783bbbSClaudiu Beznea 	  .pp_count = 2,
653cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
654cb783bbbSClaudiu Beznea 
655cb783bbbSClaudiu Beznea 	{ .n  = "mcan2_gclk",
656cb783bbbSClaudiu Beznea 	  .id = 63,
657cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
658cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
659cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
660cb783bbbSClaudiu Beznea 	  .pp_count = 2,
661cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
662cb783bbbSClaudiu Beznea 
663cb783bbbSClaudiu Beznea 	{ .n  = "mcan3_gclk",
664cb783bbbSClaudiu Beznea 	  .id = 64,
665cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
666cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
667cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
668cb783bbbSClaudiu Beznea 	  .pp_count = 2,
669cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
670cb783bbbSClaudiu Beznea 
671cb783bbbSClaudiu Beznea 	{ .n  = "mcan4_gclk",
672cb783bbbSClaudiu Beznea 	  .id = 65,
673cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
674cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
675cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
676cb783bbbSClaudiu Beznea 	  .pp_count = 2,
677cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
678cb783bbbSClaudiu Beznea 
679cb783bbbSClaudiu Beznea 	{ .n  = "mcan5_gclk",
680cb783bbbSClaudiu Beznea 	  .id = 66,
681cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
682cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
683cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
684cb783bbbSClaudiu Beznea 	  .pp_count = 2,
685cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
686cb783bbbSClaudiu Beznea 
687cb783bbbSClaudiu Beznea 	{ .n  = "pdmc0_gclk",
688cb783bbbSClaudiu Beznea 	  .id = 68,
689cb783bbbSClaudiu Beznea 	  .r = { .max = 50000000  },
690cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
691cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
692cb783bbbSClaudiu Beznea 	  .pp_count = 2,
693cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
694cb783bbbSClaudiu Beznea 
695cb783bbbSClaudiu Beznea 	{ .n  = "pdmc1_gclk",
696cb783bbbSClaudiu Beznea 	  .id = 69,
697cb783bbbSClaudiu Beznea 	  .r = { .max = 50000000, },
698cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
699cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
700cb783bbbSClaudiu Beznea 	  .pp_count = 2,
701cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
702cb783bbbSClaudiu Beznea 
703cb783bbbSClaudiu Beznea 	{ .n  = "pit64b0_gclk",
704cb783bbbSClaudiu Beznea 	  .id = 70,
705cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
706cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
707cb783bbbSClaudiu Beznea 		  "audiopll_divpmcck", "ethpll_divpmcck", },
708cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 7, 8, 9, 10, },
709cb783bbbSClaudiu Beznea 	  .pp_count = 5,
710cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
711cb783bbbSClaudiu Beznea 
712cb783bbbSClaudiu Beznea 	{ .n  = "pit64b1_gclk",
713cb783bbbSClaudiu Beznea 	  .id = 71,
714cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
715cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
716cb783bbbSClaudiu Beznea 		  "audiopll_divpmcck", "ethpll_divpmcck", },
717cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 7, 8, 9, 10, },
718cb783bbbSClaudiu Beznea 	  .pp_count = 5,
719cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
720cb783bbbSClaudiu Beznea 
721cb783bbbSClaudiu Beznea 	{ .n  = "pit64b2_gclk",
722cb783bbbSClaudiu Beznea 	  .id = 72,
723cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
724cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
725cb783bbbSClaudiu Beznea 		  "audiopll_divpmcck", "ethpll_divpmcck", },
726cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 7, 8, 9, 10, },
727cb783bbbSClaudiu Beznea 	  .pp_count = 5,
728cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
729cb783bbbSClaudiu Beznea 
730cb783bbbSClaudiu Beznea 	{ .n  = "pit64b3_gclk",
731cb783bbbSClaudiu Beznea 	  .id = 73,
732cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
733cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
734cb783bbbSClaudiu Beznea 		  "audiopll_divpmcck", "ethpll_divpmcck", },
735cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 7, 8, 9, 10, },
736cb783bbbSClaudiu Beznea 	  .pp_count = 5,
737cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
738cb783bbbSClaudiu Beznea 
739cb783bbbSClaudiu Beznea 	{ .n  = "pit64b4_gclk",
740cb783bbbSClaudiu Beznea 	  .id = 74,
741cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
742cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
743cb783bbbSClaudiu Beznea 		  "audiopll_divpmcck", "ethpll_divpmcck", },
744cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 7, 8, 9, 10, },
745cb783bbbSClaudiu Beznea 	  .pp_count = 5,
746cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
747cb783bbbSClaudiu Beznea 
748cb783bbbSClaudiu Beznea 	{ .n  = "pit64b5_gclk",
749cb783bbbSClaudiu Beznea 	  .id = 75,
750cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
751cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
752cb783bbbSClaudiu Beznea 		  "audiopll_divpmcck", "ethpll_divpmcck", },
753cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 7, 8, 9, 10, },
754cb783bbbSClaudiu Beznea 	  .pp_count = 5,
755cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
756cb783bbbSClaudiu Beznea 
757cb783bbbSClaudiu Beznea 	{ .n  = "qspi0_gclk",
758cb783bbbSClaudiu Beznea 	  .id = 78,
759cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
760cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
761cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
762cb783bbbSClaudiu Beznea 	  .pp_count = 2,
763cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
764cb783bbbSClaudiu Beznea 
765cb783bbbSClaudiu Beznea 	{ .n  = "qspi1_gclk",
766cb783bbbSClaudiu Beznea 	  .id = 79,
767cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
768cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
769cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
770cb783bbbSClaudiu Beznea 	  .pp_count = 2,
771cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
772cb783bbbSClaudiu Beznea 
773cb783bbbSClaudiu Beznea 	{ .n  = "sdmmc0_gclk",
774cb783bbbSClaudiu Beznea 	  .id = 80,
775cb783bbbSClaudiu Beznea 	  .r = { .max = 208000000 },
776cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
777cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
778cb783bbbSClaudiu Beznea 	  .pp_count = 2,
7794011f03eSClaudiu Beznea 	  .pp_chg_id = 4, },
780cb783bbbSClaudiu Beznea 
781cb783bbbSClaudiu Beznea 	{ .n  = "sdmmc1_gclk",
782cb783bbbSClaudiu Beznea 	  .id = 81,
783cb783bbbSClaudiu Beznea 	  .r = { .max = 208000000 },
784cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
785cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
786cb783bbbSClaudiu Beznea 	  .pp_count = 2,
7874011f03eSClaudiu Beznea 	  .pp_chg_id = 4, },
788cb783bbbSClaudiu Beznea 
789cb783bbbSClaudiu Beznea 	{ .n  = "sdmmc2_gclk",
790cb783bbbSClaudiu Beznea 	  .id = 82,
791cb783bbbSClaudiu Beznea 	  .r = { .max = 208000000 },
792cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "baudpll_divpmcck", },
793cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 8, },
794cb783bbbSClaudiu Beznea 	  .pp_count = 2,
7954011f03eSClaudiu Beznea 	  .pp_chg_id = 4, },
796cb783bbbSClaudiu Beznea 
797cb783bbbSClaudiu Beznea 	{ .n  = "spdifrx_gclk",
798cb783bbbSClaudiu Beznea 	  .id = 84,
799cb783bbbSClaudiu Beznea 	  .r = { .max = 150000000 },
800cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "audiopll_divpmcck", },
801cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 9, },
802cb783bbbSClaudiu Beznea 	  .pp_count = 2,
8034011f03eSClaudiu Beznea 	  .pp_chg_id = 4, },
804cb783bbbSClaudiu Beznea 
805cb783bbbSClaudiu Beznea 	{ .n = "spdiftx_gclk",
806cb783bbbSClaudiu Beznea 	  .id = 85,
807cb783bbbSClaudiu Beznea 	  .r = { .max = 25000000  },
808cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "audiopll_divpmcck", },
809cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 9, },
810cb783bbbSClaudiu Beznea 	  .pp_count = 2,
8114011f03eSClaudiu Beznea 	  .pp_chg_id = 4, },
812cb783bbbSClaudiu Beznea 
813cb783bbbSClaudiu Beznea 	{ .n  = "tcb0_ch0_gclk",
814cb783bbbSClaudiu Beznea 	  .id = 88,
815cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
816cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
817cb783bbbSClaudiu Beznea 		  "audiopll_divpmcck", "ethpll_divpmcck", },
818cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 7, 8, 9, 10, },
819cb783bbbSClaudiu Beznea 	  .pp_count = 5,
820cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
821cb783bbbSClaudiu Beznea 
822cb783bbbSClaudiu Beznea 	{ .n  = "tcb1_ch0_gclk",
823cb783bbbSClaudiu Beznea 	  .id = 91,
824cb783bbbSClaudiu Beznea 	  .r = { .max = 200000000 },
825cb783bbbSClaudiu Beznea 	  .pp = { "syspll_divpmcck", "imgpll_divpmcck", "baudpll_divpmcck",
826cb783bbbSClaudiu Beznea 		  "audiopll_divpmcck", "ethpll_divpmcck", },
827cb783bbbSClaudiu Beznea 	  .pp_mux_table = { 5, 7, 8, 9, 10, },
828cb783bbbSClaudiu Beznea 	  .pp_count = 5,
829cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
830cb783bbbSClaudiu Beznea 
831cb783bbbSClaudiu Beznea 	{ .n  = "tcpca_gclk",
832cb783bbbSClaudiu Beznea 	  .id = 94,
833cb783bbbSClaudiu Beznea 	  .r = { .max = 32768, },
834cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
835cb783bbbSClaudiu Beznea 
836cb783bbbSClaudiu Beznea 	{ .n  = "tcpcb_gclk",
837cb783bbbSClaudiu Beznea 	  .id = 95,
838cb783bbbSClaudiu Beznea 	  .r = { .max = 32768, },
839cb783bbbSClaudiu Beznea 	  .pp_chg_id = INT_MIN, },
840cb783bbbSClaudiu Beznea };
841cb783bbbSClaudiu Beznea 
842cb783bbbSClaudiu Beznea /* MCK0 characteristics. */
843cb783bbbSClaudiu Beznea static const struct clk_master_characteristics mck0_characteristics = {
844f803858aSClaudiu Beznea 	.output = { .min = 50000000, .max = 200000000 },
8450bb4623fSEugen Hristev 	.divisors = { 1, 2, 4, 3, 5 },
846cb783bbbSClaudiu Beznea 	.have_div3_pres = 1,
847cb783bbbSClaudiu Beznea };
848cb783bbbSClaudiu Beznea 
849cb783bbbSClaudiu Beznea /* MCK0 layout. */
850cb783bbbSClaudiu Beznea static const struct clk_master_layout mck0_layout = {
8510bb4623fSEugen Hristev 	.mask = 0x773,
852cb783bbbSClaudiu Beznea 	.pres_shift = 4,
853cb783bbbSClaudiu Beznea 	.offset = 0x28,
854cb783bbbSClaudiu Beznea };
855cb783bbbSClaudiu Beznea 
856cb783bbbSClaudiu Beznea /* Programmable clock layout. */
857cb783bbbSClaudiu Beznea static const struct clk_programmable_layout programmable_layout = {
858cb783bbbSClaudiu Beznea 	.pres_mask = 0xff,
859cb783bbbSClaudiu Beznea 	.pres_shift = 8,
860cb783bbbSClaudiu Beznea 	.css_mask = 0x1f,
861cb783bbbSClaudiu Beznea 	.have_slck_mck = 0,
862cb783bbbSClaudiu Beznea 	.is_pres_direct = 1,
863cb783bbbSClaudiu Beznea };
864cb783bbbSClaudiu Beznea 
865cb783bbbSClaudiu Beznea /* Peripheral clock layout. */
866cb783bbbSClaudiu Beznea static const struct clk_pcr_layout sama7g5_pcr_layout = {
867cb783bbbSClaudiu Beznea 	.offset = 0x88,
868cb783bbbSClaudiu Beznea 	.cmd = BIT(31),
869cb783bbbSClaudiu Beznea 	.gckcss_mask = GENMASK(12, 8),
870cb783bbbSClaudiu Beznea 	.pid_mask = GENMASK(6, 0),
871cb783bbbSClaudiu Beznea };
872cb783bbbSClaudiu Beznea 
873cb783bbbSClaudiu Beznea static void __init sama7g5_pmc_setup(struct device_node *np)
874cb783bbbSClaudiu Beznea {
875cb783bbbSClaudiu Beznea 	const char *td_slck_name, *md_slck_name, *mainxtal_name;
876cb783bbbSClaudiu Beznea 	struct pmc_data *sama7g5_pmc;
877cb783bbbSClaudiu Beznea 	const char *parent_names[10];
878cb783bbbSClaudiu Beznea 	void **alloc_mem = NULL;
879cb783bbbSClaudiu Beznea 	int alloc_mem_size = 0;
880cb783bbbSClaudiu Beznea 	struct regmap *regmap;
881cb783bbbSClaudiu Beznea 	struct clk_hw *hw;
882cb783bbbSClaudiu Beznea 	bool bypass;
883cb783bbbSClaudiu Beznea 	int i, j;
884cb783bbbSClaudiu Beznea 
885cb783bbbSClaudiu Beznea 	i = of_property_match_string(np, "clock-names", "td_slck");
886cb783bbbSClaudiu Beznea 	if (i < 0)
887cb783bbbSClaudiu Beznea 		return;
888cb783bbbSClaudiu Beznea 
889cb783bbbSClaudiu Beznea 	td_slck_name = of_clk_get_parent_name(np, i);
890cb783bbbSClaudiu Beznea 
891cb783bbbSClaudiu Beznea 	i = of_property_match_string(np, "clock-names", "md_slck");
892cb783bbbSClaudiu Beznea 	if (i < 0)
893cb783bbbSClaudiu Beznea 		return;
894cb783bbbSClaudiu Beznea 
895cb783bbbSClaudiu Beznea 	md_slck_name = of_clk_get_parent_name(np, i);
896cb783bbbSClaudiu Beznea 
897cb783bbbSClaudiu Beznea 	i = of_property_match_string(np, "clock-names", "main_xtal");
898cb783bbbSClaudiu Beznea 	if (i < 0)
899cb783bbbSClaudiu Beznea 		return;
900cb783bbbSClaudiu Beznea 
901cb783bbbSClaudiu Beznea 	mainxtal_name = of_clk_get_parent_name(np, i);
902cb783bbbSClaudiu Beznea 
903cb783bbbSClaudiu Beznea 	regmap = device_node_to_regmap(np);
904cb783bbbSClaudiu Beznea 	if (IS_ERR(regmap))
905cb783bbbSClaudiu Beznea 		return;
906cb783bbbSClaudiu Beznea 
90791f3bf0dSClaudiu Beznea 	sama7g5_pmc = pmc_data_allocate(PMC_CPU + 1,
908cb783bbbSClaudiu Beznea 					nck(sama7g5_systemck),
909cb783bbbSClaudiu Beznea 					nck(sama7g5_periphck),
91091274497SClaudiu Beznea 					nck(sama7g5_gck), 8);
911cb783bbbSClaudiu Beznea 	if (!sama7g5_pmc)
912cb783bbbSClaudiu Beznea 		return;
913cb783bbbSClaudiu Beznea 
914cb783bbbSClaudiu Beznea 	alloc_mem = kmalloc(sizeof(void *) *
915cb783bbbSClaudiu Beznea 			    (ARRAY_SIZE(sama7g5_mckx) + ARRAY_SIZE(sama7g5_gck)),
916cb783bbbSClaudiu Beznea 			    GFP_KERNEL);
917cb783bbbSClaudiu Beznea 	if (!alloc_mem)
918cb783bbbSClaudiu Beznea 		goto err_free;
919cb783bbbSClaudiu Beznea 
920cb783bbbSClaudiu Beznea 	hw = at91_clk_register_main_rc_osc(regmap, "main_rc_osc", 12000000,
921cb783bbbSClaudiu Beznea 					   50000000);
922cb783bbbSClaudiu Beznea 	if (IS_ERR(hw))
923cb783bbbSClaudiu Beznea 		goto err_free;
924cb783bbbSClaudiu Beznea 
925cb783bbbSClaudiu Beznea 	bypass = of_property_read_bool(np, "atmel,osc-bypass");
926cb783bbbSClaudiu Beznea 
927cb783bbbSClaudiu Beznea 	hw = at91_clk_register_main_osc(regmap, "main_osc", mainxtal_name,
928cb783bbbSClaudiu Beznea 					bypass);
929cb783bbbSClaudiu Beznea 	if (IS_ERR(hw))
930cb783bbbSClaudiu Beznea 		goto err_free;
931cb783bbbSClaudiu Beznea 
932cb783bbbSClaudiu Beznea 	parent_names[0] = "main_rc_osc";
933cb783bbbSClaudiu Beznea 	parent_names[1] = "main_osc";
934cb783bbbSClaudiu Beznea 	hw = at91_clk_register_sam9x5_main(regmap, "mainck", parent_names, 2);
935cb783bbbSClaudiu Beznea 	if (IS_ERR(hw))
936cb783bbbSClaudiu Beznea 		goto err_free;
937cb783bbbSClaudiu Beznea 
938cb783bbbSClaudiu Beznea 	sama7g5_pmc->chws[PMC_MAIN] = hw;
939cb783bbbSClaudiu Beznea 
940cb783bbbSClaudiu Beznea 	for (i = 0; i < PLL_ID_MAX; i++) {
941cb783bbbSClaudiu Beznea 		for (j = 0; j < 3; j++) {
942cb783bbbSClaudiu Beznea 			struct clk_hw *parent_hw;
943cb783bbbSClaudiu Beznea 
944cb783bbbSClaudiu Beznea 			if (!sama7g5_plls[i][j].n)
945cb783bbbSClaudiu Beznea 				continue;
946cb783bbbSClaudiu Beznea 
947cb783bbbSClaudiu Beznea 			switch (sama7g5_plls[i][j].t) {
948cb783bbbSClaudiu Beznea 			case PLL_TYPE_FRAC:
949cb783bbbSClaudiu Beznea 				if (!strcmp(sama7g5_plls[i][j].p, "mainck"))
950cb783bbbSClaudiu Beznea 					parent_hw = sama7g5_pmc->chws[PMC_MAIN];
951cb783bbbSClaudiu Beznea 				else
952cb783bbbSClaudiu Beznea 					parent_hw = __clk_get_hw(of_clk_get_by_name(np,
953cb783bbbSClaudiu Beznea 						sama7g5_plls[i][j].p));
954cb783bbbSClaudiu Beznea 
955cb783bbbSClaudiu Beznea 				hw = sam9x60_clk_register_frac_pll(regmap,
956cb783bbbSClaudiu Beznea 					&pmc_pll_lock, sama7g5_plls[i][j].n,
957cb783bbbSClaudiu Beznea 					sama7g5_plls[i][j].p, parent_hw, i,
958120d5d8bSClaudiu Beznea 					sama7g5_plls[i][j].c,
959cb783bbbSClaudiu Beznea 					sama7g5_plls[i][j].l,
9608dc4af8bSClaudiu Beznea 					sama7g5_plls[i][j].f);
961cb783bbbSClaudiu Beznea 				break;
962cb783bbbSClaudiu Beznea 
963cb783bbbSClaudiu Beznea 			case PLL_TYPE_DIV:
964cb783bbbSClaudiu Beznea 				hw = sam9x60_clk_register_div_pll(regmap,
965cb783bbbSClaudiu Beznea 					&pmc_pll_lock, sama7g5_plls[i][j].n,
966cb783bbbSClaudiu Beznea 					sama7g5_plls[i][j].p, i,
967120d5d8bSClaudiu Beznea 					sama7g5_plls[i][j].c,
968cb783bbbSClaudiu Beznea 					sama7g5_plls[i][j].l,
9698dc4af8bSClaudiu Beznea 					sama7g5_plls[i][j].f);
970cb783bbbSClaudiu Beznea 				break;
971cb783bbbSClaudiu Beznea 
972cb783bbbSClaudiu Beznea 			default:
973cb783bbbSClaudiu Beznea 				continue;
974cb783bbbSClaudiu Beznea 			}
975cb783bbbSClaudiu Beznea 
976cb783bbbSClaudiu Beznea 			if (IS_ERR(hw))
977cb783bbbSClaudiu Beznea 				goto err_free;
978cb783bbbSClaudiu Beznea 
979cb783bbbSClaudiu Beznea 			if (sama7g5_plls[i][j].eid)
980cb783bbbSClaudiu Beznea 				sama7g5_pmc->chws[sama7g5_plls[i][j].eid] = hw;
981cb783bbbSClaudiu Beznea 		}
982cb783bbbSClaudiu Beznea 	}
983cb783bbbSClaudiu Beznea 
98491f3bf0dSClaudiu Beznea 	parent_names[0] = "cpupll_divpmcck";
98591f3bf0dSClaudiu Beznea 	hw = at91_clk_register_master_pres(regmap, "cpuck", 1, parent_names,
9867a110b91SClaudiu Beznea 					   &mck0_layout, &mck0_characteristics,
9877a110b91SClaudiu Beznea 					   &pmc_mck0_lock,
9887a110b91SClaudiu Beznea 					   CLK_SET_RATE_PARENT, 0);
9897a110b91SClaudiu Beznea 	if (IS_ERR(hw))
9907a110b91SClaudiu Beznea 		goto err_free;
9917a110b91SClaudiu Beznea 
99291f3bf0dSClaudiu Beznea 	sama7g5_pmc->chws[PMC_CPU] = hw;
99391f3bf0dSClaudiu Beznea 
99491f3bf0dSClaudiu Beznea 	hw = at91_clk_register_master_div(regmap, "mck0", "cpuck",
9957a110b91SClaudiu Beznea 					  &mck0_layout, &mck0_characteristics,
9967a110b91SClaudiu Beznea 					  &pmc_mck0_lock, 0);
997cb783bbbSClaudiu Beznea 	if (IS_ERR(hw))
998cb783bbbSClaudiu Beznea 		goto err_free;
999cb783bbbSClaudiu Beznea 
1000cb783bbbSClaudiu Beznea 	sama7g5_pmc->chws[PMC_MCK] = hw;
1001cb783bbbSClaudiu Beznea 
1002cb783bbbSClaudiu Beznea 	parent_names[0] = md_slck_name;
1003cb783bbbSClaudiu Beznea 	parent_names[1] = td_slck_name;
1004cb783bbbSClaudiu Beznea 	parent_names[2] = "mainck";
1005cb783bbbSClaudiu Beznea 	for (i = 0; i < ARRAY_SIZE(sama7g5_mckx); i++) {
10064011f03eSClaudiu Beznea 		u8 num_parents = 3 + sama7g5_mckx[i].ep_count;
1007cb783bbbSClaudiu Beznea 		u32 *mux_table;
1008cb783bbbSClaudiu Beznea 
1009cb783bbbSClaudiu Beznea 		mux_table = kmalloc_array(num_parents, sizeof(*mux_table),
1010cb783bbbSClaudiu Beznea 					  GFP_KERNEL);
1011cb783bbbSClaudiu Beznea 		if (!mux_table)
1012cb783bbbSClaudiu Beznea 			goto err_free;
1013cb783bbbSClaudiu Beznea 
10144011f03eSClaudiu Beznea 		SAMA7G5_INIT_TABLE(mux_table, 3);
10154011f03eSClaudiu Beznea 		SAMA7G5_FILL_TABLE(&mux_table[3], sama7g5_mckx[i].ep_mux_table,
1016cb783bbbSClaudiu Beznea 				   sama7g5_mckx[i].ep_count);
10174011f03eSClaudiu Beznea 		SAMA7G5_FILL_TABLE(&parent_names[3], sama7g5_mckx[i].ep,
1018cb783bbbSClaudiu Beznea 				   sama7g5_mckx[i].ep_count);
1019cb783bbbSClaudiu Beznea 
1020cb783bbbSClaudiu Beznea 		hw = at91_clk_sama7g5_register_master(regmap, sama7g5_mckx[i].n,
1021cb783bbbSClaudiu Beznea 				   num_parents, parent_names, mux_table,
1022cb783bbbSClaudiu Beznea 				   &pmc_mckX_lock, sama7g5_mckx[i].id,
1023cb783bbbSClaudiu Beznea 				   sama7g5_mckx[i].c,
1024cb783bbbSClaudiu Beznea 				   sama7g5_mckx[i].ep_chg_id);
1025cb783bbbSClaudiu Beznea 		if (IS_ERR(hw))
1026cb783bbbSClaudiu Beznea 			goto err_free;
1027cb783bbbSClaudiu Beznea 
1028cb783bbbSClaudiu Beznea 		alloc_mem[alloc_mem_size++] = mux_table;
1029cb783bbbSClaudiu Beznea 	}
1030cb783bbbSClaudiu Beznea 
1031cb783bbbSClaudiu Beznea 	hw = at91_clk_sama7g5_register_utmi(regmap, "utmick", "main_xtal");
1032cb783bbbSClaudiu Beznea 	if (IS_ERR(hw))
1033cb783bbbSClaudiu Beznea 		goto err_free;
1034cb783bbbSClaudiu Beznea 
1035cb783bbbSClaudiu Beznea 	sama7g5_pmc->chws[PMC_UTMI] = hw;
1036cb783bbbSClaudiu Beznea 
1037cb783bbbSClaudiu Beznea 	parent_names[0] = md_slck_name;
1038cb783bbbSClaudiu Beznea 	parent_names[1] = td_slck_name;
1039cb783bbbSClaudiu Beznea 	parent_names[2] = "mainck";
10404011f03eSClaudiu Beznea 	parent_names[3] = "syspll_divpmcck";
10414011f03eSClaudiu Beznea 	parent_names[4] = "ddrpll_divpmcck";
10424011f03eSClaudiu Beznea 	parent_names[5] = "imgpll_divpmcck";
10434011f03eSClaudiu Beznea 	parent_names[6] = "baudpll_divpmcck";
10444011f03eSClaudiu Beznea 	parent_names[7] = "audiopll_divpmcck";
10454011f03eSClaudiu Beznea 	parent_names[8] = "ethpll_divpmcck";
1046cb783bbbSClaudiu Beznea 	for (i = 0; i < 8; i++) {
1047cb783bbbSClaudiu Beznea 		char name[6];
1048cb783bbbSClaudiu Beznea 
1049cb783bbbSClaudiu Beznea 		snprintf(name, sizeof(name), "prog%d", i);
1050cb783bbbSClaudiu Beznea 
1051cb783bbbSClaudiu Beznea 		hw = at91_clk_register_programmable(regmap, name, parent_names,
10524011f03eSClaudiu Beznea 						    9, i,
1053cb783bbbSClaudiu Beznea 						    &programmable_layout,
1054cb783bbbSClaudiu Beznea 						    sama7g5_prog_mux_table);
1055cb783bbbSClaudiu Beznea 		if (IS_ERR(hw))
1056cb783bbbSClaudiu Beznea 			goto err_free;
105791274497SClaudiu Beznea 
105891274497SClaudiu Beznea 		sama7g5_pmc->pchws[i] = hw;
1059cb783bbbSClaudiu Beznea 	}
1060cb783bbbSClaudiu Beznea 
1061cb783bbbSClaudiu Beznea 	for (i = 0; i < ARRAY_SIZE(sama7g5_systemck); i++) {
1062cb783bbbSClaudiu Beznea 		hw = at91_clk_register_system(regmap, sama7g5_systemck[i].n,
1063cb783bbbSClaudiu Beznea 					      sama7g5_systemck[i].p,
1064cb783bbbSClaudiu Beznea 					      sama7g5_systemck[i].id);
1065cb783bbbSClaudiu Beznea 		if (IS_ERR(hw))
1066cb783bbbSClaudiu Beznea 			goto err_free;
1067cb783bbbSClaudiu Beznea 
1068cb783bbbSClaudiu Beznea 		sama7g5_pmc->shws[sama7g5_systemck[i].id] = hw;
1069cb783bbbSClaudiu Beznea 	}
1070cb783bbbSClaudiu Beznea 
1071cb783bbbSClaudiu Beznea 	for (i = 0; i < ARRAY_SIZE(sama7g5_periphck); i++) {
1072cb783bbbSClaudiu Beznea 		hw = at91_clk_register_sam9x5_peripheral(regmap, &pmc_pcr_lock,
1073cb783bbbSClaudiu Beznea 						&sama7g5_pcr_layout,
1074cb783bbbSClaudiu Beznea 						sama7g5_periphck[i].n,
1075cb783bbbSClaudiu Beznea 						sama7g5_periphck[i].p,
1076cb783bbbSClaudiu Beznea 						sama7g5_periphck[i].id,
1077cb783bbbSClaudiu Beznea 						&sama7g5_periphck[i].r,
1078cb783bbbSClaudiu Beznea 						sama7g5_periphck[i].chgp ? 0 :
1079cb783bbbSClaudiu Beznea 						INT_MIN);
1080cb783bbbSClaudiu Beznea 		if (IS_ERR(hw))
1081cb783bbbSClaudiu Beznea 			goto err_free;
1082cb783bbbSClaudiu Beznea 
1083cb783bbbSClaudiu Beznea 		sama7g5_pmc->phws[sama7g5_periphck[i].id] = hw;
1084cb783bbbSClaudiu Beznea 	}
1085cb783bbbSClaudiu Beznea 
1086cb783bbbSClaudiu Beznea 	parent_names[0] = md_slck_name;
1087cb783bbbSClaudiu Beznea 	parent_names[1] = td_slck_name;
1088cb783bbbSClaudiu Beznea 	parent_names[2] = "mainck";
1089cb783bbbSClaudiu Beznea 	for (i = 0; i < ARRAY_SIZE(sama7g5_gck); i++) {
10904011f03eSClaudiu Beznea 		u8 num_parents = 3 + sama7g5_gck[i].pp_count;
1091cb783bbbSClaudiu Beznea 		u32 *mux_table;
1092cb783bbbSClaudiu Beznea 
1093cb783bbbSClaudiu Beznea 		mux_table = kmalloc_array(num_parents, sizeof(*mux_table),
1094cb783bbbSClaudiu Beznea 					  GFP_KERNEL);
1095cb783bbbSClaudiu Beznea 		if (!mux_table)
1096cb783bbbSClaudiu Beznea 			goto err_free;
1097cb783bbbSClaudiu Beznea 
10984011f03eSClaudiu Beznea 		SAMA7G5_INIT_TABLE(mux_table, 3);
10994011f03eSClaudiu Beznea 		SAMA7G5_FILL_TABLE(&mux_table[3], sama7g5_gck[i].pp_mux_table,
1100cb783bbbSClaudiu Beznea 				   sama7g5_gck[i].pp_count);
11014011f03eSClaudiu Beznea 		SAMA7G5_FILL_TABLE(&parent_names[3], sama7g5_gck[i].pp,
1102cb783bbbSClaudiu Beznea 				   sama7g5_gck[i].pp_count);
1103cb783bbbSClaudiu Beznea 
1104cb783bbbSClaudiu Beznea 		hw = at91_clk_register_generated(regmap, &pmc_pcr_lock,
1105cb783bbbSClaudiu Beznea 						 &sama7g5_pcr_layout,
1106cb783bbbSClaudiu Beznea 						 sama7g5_gck[i].n,
1107cb783bbbSClaudiu Beznea 						 parent_names, mux_table,
1108cb783bbbSClaudiu Beznea 						 num_parents,
1109cb783bbbSClaudiu Beznea 						 sama7g5_gck[i].id,
1110cb783bbbSClaudiu Beznea 						 &sama7g5_gck[i].r,
1111cb783bbbSClaudiu Beznea 						 sama7g5_gck[i].pp_chg_id);
1112cb783bbbSClaudiu Beznea 		if (IS_ERR(hw))
1113cb783bbbSClaudiu Beznea 			goto err_free;
1114cb783bbbSClaudiu Beznea 
1115cb783bbbSClaudiu Beznea 		sama7g5_pmc->ghws[sama7g5_gck[i].id] = hw;
1116cb783bbbSClaudiu Beznea 		alloc_mem[alloc_mem_size++] = mux_table;
1117cb783bbbSClaudiu Beznea 	}
1118cb783bbbSClaudiu Beznea 
1119cb783bbbSClaudiu Beznea 	of_clk_add_hw_provider(np, of_clk_hw_pmc_get, sama7g5_pmc);
1120cb783bbbSClaudiu Beznea 
1121cb783bbbSClaudiu Beznea 	return;
1122cb783bbbSClaudiu Beznea 
1123cb783bbbSClaudiu Beznea err_free:
1124cb783bbbSClaudiu Beznea 	if (alloc_mem) {
1125cb783bbbSClaudiu Beznea 		for (i = 0; i < alloc_mem_size; i++)
1126cb783bbbSClaudiu Beznea 			kfree(alloc_mem[i]);
1127cb783bbbSClaudiu Beznea 		kfree(alloc_mem);
1128cb783bbbSClaudiu Beznea 	}
1129cb783bbbSClaudiu Beznea 
113091274497SClaudiu Beznea 	kfree(sama7g5_pmc);
1131cb783bbbSClaudiu Beznea }
1132cb783bbbSClaudiu Beznea 
1133cb783bbbSClaudiu Beznea /* Some clks are used for a clocksource */
1134cb783bbbSClaudiu Beznea CLK_OF_DECLARE(sama7g5_pmc, "microchip,sama7g5-pmc", sama7g5_pmc_setup);
1135