xref: /openbmc/u-boot/drivers/clk/aspeed/clk_ast2600.c (revision 39283ea71d1556dd24ac2a1fd61905e017e1f518)
1550e691bSryan_chen // SPDX-License-Identifier: GPL-2.0
2550e691bSryan_chen /*
3550e691bSryan_chen  * Copyright (C) ASPEED Technology Inc.
4550e691bSryan_chen  * Ryan Chen <ryan_chen@aspeedtech.com>
5550e691bSryan_chen  */
6550e691bSryan_chen 
7550e691bSryan_chen #include <common.h>
8550e691bSryan_chen #include <clk-uclass.h>
9550e691bSryan_chen #include <dm.h>
10550e691bSryan_chen #include <asm/io.h>
11550e691bSryan_chen #include <dm/lists.h>
1262a6bcbfSryan_chen #include <asm/arch/scu_ast2600.h>
13d6e349c7Sryan_chen #include <dt-bindings/clock/ast2600-clock.h>
14*39283ea7Sryan_chen #include <dt-bindings/reset/ast2600-reset.h>
15550e691bSryan_chen 
16550e691bSryan_chen /*
17550e691bSryan_chen  * MAC Clock Delay settings, taken from Aspeed SDK
18550e691bSryan_chen  */
19550e691bSryan_chen #define RGMII_TXCLK_ODLY		8
20550e691bSryan_chen #define RMII_RXCLK_IDLY		2
21550e691bSryan_chen 
22550e691bSryan_chen /*
23550e691bSryan_chen  * TGMII Clock Duty constants, taken from Aspeed SDK
24550e691bSryan_chen  */
25550e691bSryan_chen #define RGMII2_TXCK_DUTY	0x66
26550e691bSryan_chen #define RGMII1_TXCK_DUTY	0x64
27550e691bSryan_chen 
28550e691bSryan_chen #define D2PLL_DEFAULT_RATE	(250 * 1000 * 1000)
29550e691bSryan_chen 
30550e691bSryan_chen DECLARE_GLOBAL_DATA_PTR;
31550e691bSryan_chen 
32550e691bSryan_chen /*
33550e691bSryan_chen  * Clock divider/multiplier configuration struct.
34550e691bSryan_chen  * For H-PLL and M-PLL the formula is
35550e691bSryan_chen  * (Output Frequency) = CLKIN * ((M + 1) / (N + 1)) / (P + 1)
36550e691bSryan_chen  * M - Numerator
37550e691bSryan_chen  * N - Denumerator
38550e691bSryan_chen  * P - Post Divider
39550e691bSryan_chen  * They have the same layout in their control register.
40550e691bSryan_chen  *
41550e691bSryan_chen  * D-PLL and D2-PLL have extra divider (OD + 1), which is not
42550e691bSryan_chen  * yet needed and ignored by clock configurations.
43550e691bSryan_chen  */
44*39283ea7Sryan_chen struct ast2600_div_config {
45550e691bSryan_chen 	unsigned int num;
46550e691bSryan_chen 	unsigned int denum;
47550e691bSryan_chen 	unsigned int post_div;
48550e691bSryan_chen };
49550e691bSryan_chen 
50d6e349c7Sryan_chen #define AST2600_CLK_IN	25000000
51550e691bSryan_chen 
52550e691bSryan_chen /*
53550e691bSryan_chen  * Get the rate of the M-PLL clock from input clock frequency and
54550e691bSryan_chen  * the value of the M-PLL Parameter Register.
55550e691bSryan_chen  */
56*39283ea7Sryan_chen static u32 ast2600_get_mpll_rate(struct ast2600_scu *scu)
57550e691bSryan_chen {
58d6e349c7Sryan_chen 	u32 clkin = AST2600_CLK_IN;
59*39283ea7Sryan_chen 	u32 mpll_reg = readl(&scu->m_pll_param);
60550e691bSryan_chen 
61*39283ea7Sryan_chen 	printf("&scu->m_pll_param %x \n", (u32) &scu->m_pll_param);
62*39283ea7Sryan_chen 	const ulong num = mpll_reg & 0x1fff;
63*39283ea7Sryan_chen 	const ulong denum = (mpll_reg >> 13) & 0x3f;
64*39283ea7Sryan_chen 	const ulong post_div = (mpll_reg >> 19) & 0xf;
65550e691bSryan_chen 
66550e691bSryan_chen 	return (clkin * ((num + 1) / (denum + 1))) / (post_div + 1);
67550e691bSryan_chen }
68550e691bSryan_chen 
69550e691bSryan_chen /*
70550e691bSryan_chen  * Get the rate of the H-PLL clock from input clock frequency and
71550e691bSryan_chen  * the value of the H-PLL Parameter Register.
72550e691bSryan_chen  */
73*39283ea7Sryan_chen static ulong ast2600_get_hpll_rate(struct ast2600_scu *scu)
74550e691bSryan_chen {
75d6e349c7Sryan_chen 	ulong clkin = AST2600_CLK_IN;
76*39283ea7Sryan_chen 	u32 hpll_reg = readl(&scu->h_pll_param);
77f0d895afSryan_chen 
78*39283ea7Sryan_chen 	printf("&scu->h_pll_param %x \n", (u32) &scu->h_pll_param);
79f0d895afSryan_chen 
80*39283ea7Sryan_chen 	const ulong num = (hpll_reg & 0x1fff);
81*39283ea7Sryan_chen 	const ulong denum = (hpll_reg >> 13) & 0x3f;
82*39283ea7Sryan_chen 	const ulong post_div = (hpll_reg >> 19) & 0xf;
83550e691bSryan_chen 
84550e691bSryan_chen 	return (clkin * ((num + 1) / (denum + 1))) / (post_div + 1);
85550e691bSryan_chen }
86550e691bSryan_chen 
87*39283ea7Sryan_chen static ulong ast2600_get_apll_rate(struct ast2600_scu *scu)
88550e691bSryan_chen {
89*39283ea7Sryan_chen 	u32 clk_in = AST2600_CLK_IN;
90*39283ea7Sryan_chen 	u32 apll_reg = readl(&scu->a_pll_param);
91*39283ea7Sryan_chen 	unsigned int mult, div = 1;
92d6e349c7Sryan_chen 
93*39283ea7Sryan_chen 	printf("&scu->h_pll_param %x \n", (u32) &scu->a_pll_param);
94f0d895afSryan_chen 
95*39283ea7Sryan_chen 	if (apll_reg & BIT(20)) {
96d6e349c7Sryan_chen 		/* Pass through mode */
97d6e349c7Sryan_chen 		mult = div = 1;
98d6e349c7Sryan_chen 	} else {
99d6e349c7Sryan_chen 		/* F = 25Mhz * (2-OD) * [(M + 2) / (n + 1)] */
100*39283ea7Sryan_chen 		u32 m = (apll_reg >> 5) & 0x3f;
101*39283ea7Sryan_chen 		u32 od = (apll_reg >> 4) & 0x1;
102*39283ea7Sryan_chen 		u32 n = apll_reg & 0xf;
103d6e349c7Sryan_chen 
104*39283ea7Sryan_chen 		mult = (2 - od) * ((m + 2) / (n + 1));
105d6e349c7Sryan_chen 	}
106d6e349c7Sryan_chen 	return (clk_in * mult)/div;
107d6e349c7Sryan_chen }
108d6e349c7Sryan_chen 
109*39283ea7Sryan_chen static ulong ast2600_get_epll_rate(struct ast2600_scu *scu)
110*39283ea7Sryan_chen {
111*39283ea7Sryan_chen 	u32 clk_in = AST2600_CLK_IN;
112*39283ea7Sryan_chen 	u32 epll_reg = readl(&scu->e_pll_param);
113*39283ea7Sryan_chen 	unsigned int mult, div = 1;
114*39283ea7Sryan_chen 
115*39283ea7Sryan_chen 	printf("&scu->e_pll_param %x \n", (u32) &scu->e_pll_param);
116*39283ea7Sryan_chen 
117*39283ea7Sryan_chen 	if (epll_reg & BIT(24)) {
118*39283ea7Sryan_chen 		/* Pass through mode */
119*39283ea7Sryan_chen 		mult = div = 1;
120*39283ea7Sryan_chen 	} else {
121*39283ea7Sryan_chen 		/* F = 25Mhz * [(M + 2) / (n + 1)] / (p + 1)*/
122*39283ea7Sryan_chen 		u32 m = epll_reg  & 0x1fff;
123*39283ea7Sryan_chen 		u32 n = (epll_reg >> 13) & 0x3f;
124*39283ea7Sryan_chen 		u32 p = (epll_reg >> 19) & 0x7;
125*39283ea7Sryan_chen 
126*39283ea7Sryan_chen 		mult = ((m + 1) / (n + 1));
127*39283ea7Sryan_chen 		div = (p + 1);
128*39283ea7Sryan_chen 	}
129*39283ea7Sryan_chen 	return (clk_in * mult)/div;
130*39283ea7Sryan_chen }
131*39283ea7Sryan_chen 
132*39283ea7Sryan_chen static ulong ast2600_get_dpll_rate(struct ast2600_scu *scu)
133*39283ea7Sryan_chen {
134*39283ea7Sryan_chen 	u32 clk_in = AST2600_CLK_IN;
135*39283ea7Sryan_chen 	u32 dpll_reg = readl(&scu->d_pll_param);
136*39283ea7Sryan_chen 	unsigned int mult, div = 1;
137*39283ea7Sryan_chen 
138*39283ea7Sryan_chen 	printf("&scu->d_pll_param %x \n", (u32) &scu->d_pll_param);
139*39283ea7Sryan_chen 
140*39283ea7Sryan_chen 	if (dpll_reg & BIT(24)) {
141*39283ea7Sryan_chen 		/* Pass through mode */
142*39283ea7Sryan_chen 		mult = div = 1;
143*39283ea7Sryan_chen 	} else {
144*39283ea7Sryan_chen 		/* F = 25Mhz * [(M + 2) / (n + 1)] / (p + 1)*/
145*39283ea7Sryan_chen 		u32 m = dpll_reg  & 0x1fff;
146*39283ea7Sryan_chen 		u32 n = (dpll_reg >> 13) & 0x3f;
147*39283ea7Sryan_chen 		u32 p = (dpll_reg >> 19) & 0x7;
148*39283ea7Sryan_chen 
149*39283ea7Sryan_chen 		mult = ((m + 1) / (n + 1));
150*39283ea7Sryan_chen 		div = (p + 1);
151*39283ea7Sryan_chen 	}
152*39283ea7Sryan_chen 	return (clk_in * mult)/div;
153*39283ea7Sryan_chen }
154d6e349c7Sryan_chen 
155f0d895afSryan_chen static ulong ast2600_get_uart_clk_rate(struct ast2600_clk_priv *priv, int uart_index)
156d6e349c7Sryan_chen {
157550e691bSryan_chen 	ulong uart_clkin;
158550e691bSryan_chen 
159*39283ea7Sryan_chen 	printf("ast2600_get_uart_clk_rate source %ld \n\n", ast2600_get_apll_rate(priv->scu));
160d6e349c7Sryan_chen 	return (24000000/13);
161d6e349c7Sryan_chen 
162f0d895afSryan_chen 	if (readl(&priv->scu->misc_ctrl2) &
163550e691bSryan_chen 	    (1 << (uart_index - 1 + SCU_MISC2_UARTCLK_SHIFT)))
164550e691bSryan_chen 		uart_clkin = 192 * 1000 * 1000;
165550e691bSryan_chen 	else
166550e691bSryan_chen 		uart_clkin = 24 * 1000 * 1000;
167550e691bSryan_chen 
168f0d895afSryan_chen 	if (readl(&priv->scu->misc_ctrl2) & SCU_MISC_UARTCLK_DIV13)
169550e691bSryan_chen 		uart_clkin /= 13;
170550e691bSryan_chen 
171550e691bSryan_chen 	return uart_clkin;
172550e691bSryan_chen }
173550e691bSryan_chen 
174550e691bSryan_chen struct aspeed_clock_config {
175550e691bSryan_chen 	ulong input_rate;
176550e691bSryan_chen 	ulong rate;
177*39283ea7Sryan_chen 	struct ast2600_div_config cfg;
178550e691bSryan_chen };
179550e691bSryan_chen 
180550e691bSryan_chen static const struct aspeed_clock_config aspeed_clock_config_defaults[] = {
181550e691bSryan_chen 	{ 24000000, 250000000, { .num = 124, .denum = 1, .post_div = 5 } },
182550e691bSryan_chen };
183550e691bSryan_chen 
184550e691bSryan_chen static bool aspeed_get_clock_config_default(ulong input_rate,
185550e691bSryan_chen 					     ulong requested_rate,
186*39283ea7Sryan_chen 					     struct ast2600_div_config *cfg)
187550e691bSryan_chen {
188550e691bSryan_chen 	int i;
189550e691bSryan_chen 
190550e691bSryan_chen 	for (i = 0; i < ARRAY_SIZE(aspeed_clock_config_defaults); i++) {
191550e691bSryan_chen 		const struct aspeed_clock_config *default_cfg =
192550e691bSryan_chen 			&aspeed_clock_config_defaults[i];
193550e691bSryan_chen 		if (default_cfg->input_rate == input_rate &&
194550e691bSryan_chen 		    default_cfg->rate == requested_rate) {
195550e691bSryan_chen 			*cfg = default_cfg->cfg;
196550e691bSryan_chen 			return true;
197550e691bSryan_chen 		}
198550e691bSryan_chen 	}
199550e691bSryan_chen 
200550e691bSryan_chen 	return false;
201550e691bSryan_chen }
202550e691bSryan_chen 
203550e691bSryan_chen /*
204550e691bSryan_chen  * @input_rate - the rate of input clock in Hz
205550e691bSryan_chen  * @requested_rate - desired output rate in Hz
206550e691bSryan_chen  * @div - this is an IN/OUT parameter, at input all fields of the config
207550e691bSryan_chen  * need to be set to their maximum allowed values.
208550e691bSryan_chen  * The result (the best config we could find), would also be returned
209550e691bSryan_chen  * in this structure.
210550e691bSryan_chen  *
211550e691bSryan_chen  * @return The clock rate, when the resulting div_config is used.
212550e691bSryan_chen  */
213550e691bSryan_chen static ulong aspeed_calc_clock_config(ulong input_rate, ulong requested_rate,
214*39283ea7Sryan_chen 				       struct ast2600_div_config *cfg)
215550e691bSryan_chen {
216550e691bSryan_chen 	/*
217550e691bSryan_chen 	 * The assumption is that kHz precision is good enough and
218550e691bSryan_chen 	 * also enough to avoid overflow when multiplying.
219550e691bSryan_chen 	 */
220550e691bSryan_chen 	const ulong input_rate_khz = input_rate / 1000;
221550e691bSryan_chen 	const ulong rate_khz = requested_rate / 1000;
222*39283ea7Sryan_chen 	const struct ast2600_div_config max_vals = *cfg;
223*39283ea7Sryan_chen 	struct ast2600_div_config it = { 0, 0, 0 };
224550e691bSryan_chen 	ulong delta = rate_khz;
225550e691bSryan_chen 	ulong new_rate_khz = 0;
226550e691bSryan_chen 
227550e691bSryan_chen 	/*
228550e691bSryan_chen 	 * Look for a well known frequency first.
229550e691bSryan_chen 	 */
230550e691bSryan_chen 	if (aspeed_get_clock_config_default(input_rate, requested_rate, cfg))
231550e691bSryan_chen 		return requested_rate;
232550e691bSryan_chen 
233550e691bSryan_chen 	for (; it.denum <= max_vals.denum; ++it.denum) {
234550e691bSryan_chen 		for (it.post_div = 0; it.post_div <= max_vals.post_div;
235550e691bSryan_chen 		     ++it.post_div) {
236550e691bSryan_chen 			it.num = (rate_khz * (it.post_div + 1) / input_rate_khz)
237550e691bSryan_chen 			    * (it.denum + 1);
238550e691bSryan_chen 			if (it.num > max_vals.num)
239550e691bSryan_chen 				continue;
240550e691bSryan_chen 
241550e691bSryan_chen 			new_rate_khz = (input_rate_khz
242550e691bSryan_chen 					* ((it.num + 1) / (it.denum + 1)))
243550e691bSryan_chen 			    / (it.post_div + 1);
244550e691bSryan_chen 
245550e691bSryan_chen 			/* Keep the rate below requested one. */
246550e691bSryan_chen 			if (new_rate_khz > rate_khz)
247550e691bSryan_chen 				continue;
248550e691bSryan_chen 
249550e691bSryan_chen 			if (new_rate_khz - rate_khz < delta) {
250550e691bSryan_chen 				delta = new_rate_khz - rate_khz;
251550e691bSryan_chen 				*cfg = it;
252550e691bSryan_chen 				if (delta == 0)
253550e691bSryan_chen 					return new_rate_khz * 1000;
254550e691bSryan_chen 			}
255550e691bSryan_chen 		}
256550e691bSryan_chen 	}
257550e691bSryan_chen 
258550e691bSryan_chen 	return new_rate_khz * 1000;
259550e691bSryan_chen }
260550e691bSryan_chen 
261*39283ea7Sryan_chen static u32 ast2600_configure_ddr(struct ast2600_clk_priv *priv, ulong rate)
262550e691bSryan_chen {
263d6e349c7Sryan_chen 	u32 clkin = AST2600_CLK_IN;
264550e691bSryan_chen 	u32 mpll_reg;
265*39283ea7Sryan_chen 	struct ast2600_div_config div_cfg = {
266550e691bSryan_chen 		.num = (SCU_MPLL_NUM_MASK >> SCU_MPLL_NUM_SHIFT),
267550e691bSryan_chen 		.denum = (SCU_MPLL_DENUM_MASK >> SCU_MPLL_DENUM_SHIFT),
268550e691bSryan_chen 		.post_div = (SCU_MPLL_POST_MASK >> SCU_MPLL_POST_SHIFT),
269550e691bSryan_chen 	};
270550e691bSryan_chen 
271550e691bSryan_chen 	aspeed_calc_clock_config(clkin, rate, &div_cfg);
272550e691bSryan_chen 
273f0d895afSryan_chen 	mpll_reg = readl(&priv->scu->m_pll_param);
274550e691bSryan_chen 	mpll_reg &= ~(SCU_MPLL_POST_MASK | SCU_MPLL_NUM_MASK
275550e691bSryan_chen 		      | SCU_MPLL_DENUM_MASK);
276550e691bSryan_chen 	mpll_reg |= (div_cfg.post_div << SCU_MPLL_POST_SHIFT)
277550e691bSryan_chen 	    | (div_cfg.num << SCU_MPLL_NUM_SHIFT)
278550e691bSryan_chen 	    | (div_cfg.denum << SCU_MPLL_DENUM_SHIFT);
279550e691bSryan_chen 
280f0d895afSryan_chen 	writel(mpll_reg, &priv->scu->m_pll_param);
281550e691bSryan_chen 
282*39283ea7Sryan_chen 	return ast2600_get_mpll_rate(priv->scu);
283550e691bSryan_chen }
284550e691bSryan_chen 
285*39283ea7Sryan_chen static u32 ast2600_configure_mac(struct ast2600_clk_priv *priv, int index)
286550e691bSryan_chen {
287*39283ea7Sryan_chen 	return 0;
288550e691bSryan_chen }
289550e691bSryan_chen 
290f0d895afSryan_chen static u32 ast2600_a0_axi_ahb_div_table[] = {
291f0d895afSryan_chen 	2, 2, 3, 5,
292f0d895afSryan_chen };
293f0d895afSryan_chen 
294f0d895afSryan_chen static u32 ast2600_a1_axi_ahb_div_table[] = {
295f0d895afSryan_chen 	4, 6, 2, 4,
296f0d895afSryan_chen };
297f0d895afSryan_chen 
298f0d895afSryan_chen static u32 ast2600_hpll_pclk_div_table[] = {
299f0d895afSryan_chen 	4, 8, 12, 16, 20, 24, 28, 32,
300f0d895afSryan_chen };
301d6e349c7Sryan_chen static ulong ast2600_clk_get_rate(struct clk *clk)
302d6e349c7Sryan_chen {
303f0d895afSryan_chen 	struct ast2600_clk_priv *priv = dev_get_priv(clk->dev);
304d6e349c7Sryan_chen 	ulong rate;
305d6e349c7Sryan_chen 
306d6e349c7Sryan_chen 	switch (clk->id) {
307d1e64dd1Sryan_chen 	//HPLL
308d1e64dd1Sryan_chen 	case ASPEED_CLK_HPLL:
309*39283ea7Sryan_chen 		rate = ast2600_get_hpll_rate(priv->scu);
310*39283ea7Sryan_chen 		printf("hpll %ld \n", rate);
311d6e349c7Sryan_chen 		break;
312d1e64dd1Sryan_chen 	//HCLK
313d1e64dd1Sryan_chen 	case ASPEED_CLK_AHB:
31462a6bcbfSryan_chen 		{
315f0d895afSryan_chen 			u32 hw_rev = readl(&priv->scu->chip_id0);
316f0d895afSryan_chen 			u32 hwstrap1 = readl(&priv->scu->hwstrap1);
317f0d895afSryan_chen 			u32 axi_div = 1;
318f0d895afSryan_chen 			u32 ahb_div = 0;
319f0d895afSryan_chen 			if((hwstrap1 >> 16) & 0x1)
320f0d895afSryan_chen 				axi_div = 1;
321f0d895afSryan_chen 			else
322f0d895afSryan_chen 				axi_div = 2;
32362a6bcbfSryan_chen 
324f0d895afSryan_chen 			if (hw_rev & BIT(16))
325f0d895afSryan_chen 				ahb_div = ast2600_a1_axi_ahb_div_table[(hwstrap1 >> 11) & 0x3];
326f0d895afSryan_chen 			else
327f0d895afSryan_chen 				ahb_div = ast2600_a0_axi_ahb_div_table[(hwstrap1 >> 11) & 0x3];
328f0d895afSryan_chen 
329*39283ea7Sryan_chen 			rate = ast2600_get_hpll_rate(priv->scu);
33062a6bcbfSryan_chen 			rate = rate / axi_div / ahb_div;
33162a6bcbfSryan_chen 		}
332d1e64dd1Sryan_chen 		break;
333f0d895afSryan_chen 	case ASPEED_CLK_MPLL:
334*39283ea7Sryan_chen 		rate = ast2600_get_mpll_rate(priv->scu);
335d6e349c7Sryan_chen 		break;
336*39283ea7Sryan_chen 	//pclk
337*39283ea7Sryan_chen 	case ASPEED_CLK_APB:
338d6e349c7Sryan_chen 		{
339f0d895afSryan_chen 			u32 clk_sel1 = readl(&priv->scu->clk_sel1);
340f0d895afSryan_chen 			u32 apb_div = ast2600_hpll_pclk_div_table[((clk_sel1 >> 23) & 0x7)];
341*39283ea7Sryan_chen 			rate = ast2600_get_hpll_rate(priv->scu);
342d6e349c7Sryan_chen 			rate = rate / apb_div;
343d6e349c7Sryan_chen 		}
344d6e349c7Sryan_chen 		break;
345d6e349c7Sryan_chen 	case PCLK_UART1:
346d6e349c7Sryan_chen 		rate = ast2600_get_uart_clk_rate(priv, 1);
347d6e349c7Sryan_chen 		break;
348d6e349c7Sryan_chen 	case PCLK_UART2:
349d6e349c7Sryan_chen 		rate = ast2600_get_uart_clk_rate(priv, 2);
350d6e349c7Sryan_chen 		break;
351d6e349c7Sryan_chen 	case PCLK_UART3:
352d6e349c7Sryan_chen 		rate = ast2600_get_uart_clk_rate(priv, 3);
353d6e349c7Sryan_chen 		break;
354d6e349c7Sryan_chen 	case PCLK_UART4:
355d6e349c7Sryan_chen 		rate = ast2600_get_uart_clk_rate(priv, 4);
356d6e349c7Sryan_chen 		break;
357d1e64dd1Sryan_chen 	case ASPEED_CLK_GATE_UART5CLK:
358d6e349c7Sryan_chen 		rate = ast2600_get_uart_clk_rate(priv, 5);
359d6e349c7Sryan_chen 		break;
360d6e349c7Sryan_chen 	default:
361d6e349c7Sryan_chen 		return -ENOENT;
362d6e349c7Sryan_chen 	}
363d6e349c7Sryan_chen 
364d6e349c7Sryan_chen 	return rate;
365d6e349c7Sryan_chen }
366d6e349c7Sryan_chen 
367d6e349c7Sryan_chen static ulong ast2600_clk_set_rate(struct clk *clk, ulong rate)
368550e691bSryan_chen {
369f0d895afSryan_chen 	struct ast2600_clk_priv *priv = dev_get_priv(clk->dev);
370550e691bSryan_chen 
371550e691bSryan_chen 	ulong new_rate;
372550e691bSryan_chen 	switch (clk->id) {
373f0d895afSryan_chen 	case ASPEED_CLK_MPLL:
374*39283ea7Sryan_chen 		new_rate = ast2600_configure_ddr(priv, rate);
375550e691bSryan_chen 		break;
376550e691bSryan_chen 	default:
377550e691bSryan_chen 		return -ENOENT;
378550e691bSryan_chen 	}
379550e691bSryan_chen 
380550e691bSryan_chen 	return new_rate;
381550e691bSryan_chen }
382550e691bSryan_chen 
383d6e349c7Sryan_chen static int ast2600_clk_enable(struct clk *clk)
384550e691bSryan_chen {
385f0d895afSryan_chen 	struct ast2600_clk_priv *priv = dev_get_priv(clk->dev);
386550e691bSryan_chen 
387550e691bSryan_chen 	switch (clk->id) {
388550e691bSryan_chen 	/*
389550e691bSryan_chen 	 * For MAC clocks the clock rate is
390550e691bSryan_chen 	 * configured based on whether RGMII or RMII mode has been selected
391550e691bSryan_chen 	 * through hardware strapping.
392550e691bSryan_chen 	 */
393550e691bSryan_chen 	case PCLK_MAC1:
394*39283ea7Sryan_chen 		ast2600_configure_mac(priv, 1);
395550e691bSryan_chen 		break;
396550e691bSryan_chen 	case PCLK_MAC2:
397*39283ea7Sryan_chen 		ast2600_configure_mac(priv, 2);
398550e691bSryan_chen 		break;
399550e691bSryan_chen 	default:
400550e691bSryan_chen 		return -ENOENT;
401550e691bSryan_chen 	}
402550e691bSryan_chen 
403550e691bSryan_chen 	return 0;
404550e691bSryan_chen }
405550e691bSryan_chen 
406550e691bSryan_chen struct clk_ops aspeed_clk_ops = {
407d6e349c7Sryan_chen 	.get_rate = ast2600_clk_get_rate,
408d6e349c7Sryan_chen 	.set_rate = ast2600_clk_set_rate,
409d6e349c7Sryan_chen 	.enable = ast2600_clk_enable,
410550e691bSryan_chen };
411550e691bSryan_chen 
412d6e349c7Sryan_chen static int ast2600_clk_probe(struct udevice *dev)
413550e691bSryan_chen {
414*39283ea7Sryan_chen 	char buf[32];
415f0d895afSryan_chen 	struct ast2600_clk_priv *priv = dev_get_priv(dev);
416550e691bSryan_chen 
417f0d895afSryan_chen 	priv->scu = devfdt_get_addr_ptr(dev);
418f0d895afSryan_chen 	if (IS_ERR(priv->scu))
419f0d895afSryan_chen 		return PTR_ERR(priv->scu);
420550e691bSryan_chen 
421*39283ea7Sryan_chen 	printf("PLL   : %4s MHz\n", strmhz(buf, AST2600_CLK_IN));
422*39283ea7Sryan_chen 	printf("HPLL  : %4s MHz\n", strmhz(buf, ast2600_get_hpll_rate(priv->scu)));
423*39283ea7Sryan_chen 	printf("MPLL  :	%4s Mhz\n", strmhz(buf, ast2600_get_mpll_rate(priv->scu)));
424*39283ea7Sryan_chen 	printf("APLL  :	%4s Mhz\n", strmhz(buf, ast2600_get_apll_rate(priv->scu)));
425*39283ea7Sryan_chen 	printf("EPLL :	%4s Mhz\n", strmhz(buf, ast2600_get_epll_rate(priv->scu)));
426*39283ea7Sryan_chen 	printf("DPLL :	%4s Mhz\n", strmhz(buf, ast2600_get_dpll_rate(priv->scu)));
427*39283ea7Sryan_chen 
428*39283ea7Sryan_chen 
429550e691bSryan_chen 	return 0;
430550e691bSryan_chen }
431550e691bSryan_chen 
432d6e349c7Sryan_chen static int ast2600_clk_bind(struct udevice *dev)
433550e691bSryan_chen {
434550e691bSryan_chen 	int ret;
435550e691bSryan_chen 
436550e691bSryan_chen 	/* The reset driver does not have a device node, so bind it here */
437550e691bSryan_chen 	ret = device_bind_driver(gd->dm_root, "ast_sysreset", "reset", &dev);
438550e691bSryan_chen 	if (ret)
439550e691bSryan_chen 		debug("Warning: No reset driver: ret=%d\n", ret);
440550e691bSryan_chen 
441550e691bSryan_chen 	return 0;
442550e691bSryan_chen }
443550e691bSryan_chen 
444d6e349c7Sryan_chen static const struct udevice_id ast2600_clk_ids[] = {
445d6e349c7Sryan_chen 	{ .compatible = "aspeed,ast2600-scu", },
446550e691bSryan_chen 	{ }
447550e691bSryan_chen };
448550e691bSryan_chen 
449aa36597fSDylan Hung U_BOOT_DRIVER(aspeed_scu) = {
450aa36597fSDylan Hung 	.name		= "aspeed_scu",
451550e691bSryan_chen 	.id		= UCLASS_CLK,
452d6e349c7Sryan_chen 	.of_match	= ast2600_clk_ids,
453f0d895afSryan_chen 	.priv_auto_alloc_size = sizeof(struct ast2600_clk_priv),
454550e691bSryan_chen 	.ops		= &aspeed_clk_ops,
455d6e349c7Sryan_chen 	.bind		= ast2600_clk_bind,
456d6e349c7Sryan_chen 	.probe		= ast2600_clk_probe,
457550e691bSryan_chen };
458