xref: /rk3399_rockchip-uboot/board/freescale/s32v234evb/clock.c (revision 9702ec00e95dbc1fd66ef8e9624c649e1ee818e5)
1*9702ec00SEddy Petrișor /*
2*9702ec00SEddy Petrișor  * (C) Copyright 2015, Freescale Semiconductor, Inc.
3*9702ec00SEddy Petrișor  *
4*9702ec00SEddy Petrișor  * SPDX-License-Identifier:	GPL-2.0+
5*9702ec00SEddy Petrișor  */
6*9702ec00SEddy Petrișor 
7*9702ec00SEddy Petrișor #include <asm/io.h>
8*9702ec00SEddy Petrișor #include <asm/arch/imx-regs.h>
9*9702ec00SEddy Petrișor #include <asm/arch/mc_cgm_regs.h>
10*9702ec00SEddy Petrișor #include <asm/arch/mc_me_regs.h>
11*9702ec00SEddy Petrișor #include <asm/arch/clock.h>
12*9702ec00SEddy Petrișor 
13*9702ec00SEddy Petrișor /*
14*9702ec00SEddy Petrișor  * Select the clock reference for required pll.
15*9702ec00SEddy Petrișor  * pll - ARM_PLL, PERIPH_PLL, ENET_PLL, DDR_PLL, VIDEO_PLL.
16*9702ec00SEddy Petrișor  * refclk_freq - input referece clock frequency (FXOSC - 40 MHZ, FIRC - 48 MHZ)
17*9702ec00SEddy Petrișor  */
18*9702ec00SEddy Petrișor static int select_pll_source_clk(enum pll_type pll, u32 refclk_freq)
19*9702ec00SEddy Petrișor {
20*9702ec00SEddy Petrișor 	u32 clk_src;
21*9702ec00SEddy Petrișor 	u32 pll_idx;
22*9702ec00SEddy Petrișor 	volatile struct src *src = (struct src *)SRC_SOC_BASE_ADDR;
23*9702ec00SEddy Petrișor 
24*9702ec00SEddy Petrișor 	/* select the pll clock source */
25*9702ec00SEddy Petrișor 	switch (refclk_freq) {
26*9702ec00SEddy Petrișor 	case FIRC_CLK_FREQ:
27*9702ec00SEddy Petrișor 		clk_src = SRC_GPR1_FIRC_CLK_SOURCE;
28*9702ec00SEddy Petrișor 		break;
29*9702ec00SEddy Petrișor 	case XOSC_CLK_FREQ:
30*9702ec00SEddy Petrișor 		clk_src = SRC_GPR1_XOSC_CLK_SOURCE;
31*9702ec00SEddy Petrișor 		break;
32*9702ec00SEddy Petrișor 	default:
33*9702ec00SEddy Petrișor 		/* The clock frequency for the source clock is unknown */
34*9702ec00SEddy Petrișor 		return -1;
35*9702ec00SEddy Petrișor 	}
36*9702ec00SEddy Petrișor 	/*
37*9702ec00SEddy Petrișor 	 * The hardware definition is not uniform, it has to calculate again
38*9702ec00SEddy Petrișor 	 * the recurrence formula.
39*9702ec00SEddy Petrișor 	 */
40*9702ec00SEddy Petrișor 	switch (pll) {
41*9702ec00SEddy Petrișor 	case PERIPH_PLL:
42*9702ec00SEddy Petrișor 		pll_idx = 3;
43*9702ec00SEddy Petrișor 		break;
44*9702ec00SEddy Petrișor 	case ENET_PLL:
45*9702ec00SEddy Petrișor 		pll_idx = 1;
46*9702ec00SEddy Petrișor 		break;
47*9702ec00SEddy Petrișor 	case DDR_PLL:
48*9702ec00SEddy Petrișor 		pll_idx = 2;;
49*9702ec00SEddy Petrișor 		break;
50*9702ec00SEddy Petrișor 	default:
51*9702ec00SEddy Petrișor 		pll_idx = pll;
52*9702ec00SEddy Petrișor 	}
53*9702ec00SEddy Petrișor 
54*9702ec00SEddy Petrișor 	writel(readl(&src->gpr1) | SRC_GPR1_PLL_SOURCE(pll_idx, clk_src),
55*9702ec00SEddy Petrișor 	       &src->gpr1);
56*9702ec00SEddy Petrișor 
57*9702ec00SEddy Petrișor 	return 0;
58*9702ec00SEddy Petrișor }
59*9702ec00SEddy Petrișor 
60*9702ec00SEddy Petrișor static void entry_to_target_mode(u32 mode)
61*9702ec00SEddy Petrișor {
62*9702ec00SEddy Petrișor 	writel(mode | MC_ME_MCTL_KEY, MC_ME_MCTL);
63*9702ec00SEddy Petrișor 	writel(mode | MC_ME_MCTL_INVERTEDKEY, MC_ME_MCTL);
64*9702ec00SEddy Petrișor 	while ((readl(MC_ME_GS) & MC_ME_GS_S_MTRANS) != 0x00000000) ;
65*9702ec00SEddy Petrișor }
66*9702ec00SEddy Petrișor 
67*9702ec00SEddy Petrișor /*
68*9702ec00SEddy Petrișor  * Program the pll according to the input parameters.
69*9702ec00SEddy Petrișor  * pll - ARM_PLL, PERIPH_PLL, ENET_PLL, DDR_PLL, VIDEO_PLL.
70*9702ec00SEddy Petrișor  * refclk_freq - input reference clock frequency (FXOSC - 40 MHZ, FIRC - 48 MHZ)
71*9702ec00SEddy Petrișor  * freq - expected output frequency for PHY0
72*9702ec00SEddy Petrișor  * freq1 - expected output frequency for PHY1
73*9702ec00SEddy Petrișor  * dfs_nr - number of DFS modules for current PLL
74*9702ec00SEddy Petrișor  * dfs - array with the activation dfs field, mfn and mfi
75*9702ec00SEddy Petrișor  * plldv_prediv - divider of clkfreq_ref
76*9702ec00SEddy Petrișor  * plldv_mfd - loop multiplication factor divider
77*9702ec00SEddy Petrișor  * pllfd_mfn - numerator loop multiplication factor divider
78*9702ec00SEddy Petrișor  * Please consult the PLLDIG chapter of platform manual
79*9702ec00SEddy Petrișor  * before to use this function.
80*9702ec00SEddy Petrișor  *)
81*9702ec00SEddy Petrișor  */
82*9702ec00SEddy Petrișor static int program_pll(enum pll_type pll, u32 refclk_freq, u32 freq0, u32 freq1,
83*9702ec00SEddy Petrișor 		       u32 dfs_nr, u32 dfs[][DFS_PARAMS_Nr], u32 plldv_prediv,
84*9702ec00SEddy Petrișor 		       u32 plldv_mfd, u32 pllfd_mfn)
85*9702ec00SEddy Petrișor {
86*9702ec00SEddy Petrișor 	u32 i, rfdphi1, rfdphi, dfs_on = 0, fvco;
87*9702ec00SEddy Petrișor 
88*9702ec00SEddy Petrișor 	/*
89*9702ec00SEddy Petrișor 	 * This formula is from platform reference manual (Rev. 1, 6/2015), PLLDIG chapter.
90*9702ec00SEddy Petrișor 	 */
91*9702ec00SEddy Petrișor 	fvco =
92*9702ec00SEddy Petrișor 	    (refclk_freq / plldv_prediv) * (plldv_mfd +
93*9702ec00SEddy Petrișor 					    pllfd_mfn / (float)20480);
94*9702ec00SEddy Petrișor 
95*9702ec00SEddy Petrișor 	/*
96*9702ec00SEddy Petrișor 	 * VCO should have value in [ PLL_MIN_FREQ, PLL_MAX_FREQ ]. Please consult
97*9702ec00SEddy Petrișor 	 * the platform DataSheet in order to determine the allowed values.
98*9702ec00SEddy Petrișor 	 */
99*9702ec00SEddy Petrișor 
100*9702ec00SEddy Petrișor 	if (fvco < PLL_MIN_FREQ || fvco > PLL_MAX_FREQ) {
101*9702ec00SEddy Petrișor 		return -1;
102*9702ec00SEddy Petrișor 	}
103*9702ec00SEddy Petrișor 
104*9702ec00SEddy Petrișor 	if (select_pll_source_clk(pll, refclk_freq) < 0) {
105*9702ec00SEddy Petrișor 		return -1;
106*9702ec00SEddy Petrișor 	}
107*9702ec00SEddy Petrișor 
108*9702ec00SEddy Petrișor 	rfdphi = fvco / freq0;
109*9702ec00SEddy Petrișor 
110*9702ec00SEddy Petrișor 	rfdphi1 = (freq1 == 0) ? 0 : fvco / freq1;
111*9702ec00SEddy Petrișor 
112*9702ec00SEddy Petrișor 	writel(PLLDIG_PLLDV_RFDPHI1_SET(rfdphi1) |
113*9702ec00SEddy Petrișor 	       PLLDIG_PLLDV_RFDPHI_SET(rfdphi) |
114*9702ec00SEddy Petrișor 	       PLLDIG_PLLDV_PREDIV_SET(plldv_prediv) |
115*9702ec00SEddy Petrișor 	       PLLDIG_PLLDV_MFD(plldv_mfd), PLLDIG_PLLDV(pll));
116*9702ec00SEddy Petrișor 
117*9702ec00SEddy Petrișor 	writel(readl(PLLDIG_PLLFD(pll)) | PLLDIG_PLLFD_MFN_SET(pllfd_mfn) |
118*9702ec00SEddy Petrișor 	       PLLDIG_PLLFD_SMDEN, PLLDIG_PLLFD(pll));
119*9702ec00SEddy Petrișor 
120*9702ec00SEddy Petrișor 	/* switch on the pll in current mode */
121*9702ec00SEddy Petrișor 	writel(readl(MC_ME_RUNn_MC(0)) | MC_ME_RUNMODE_MC_PLL(pll),
122*9702ec00SEddy Petrișor 	       MC_ME_RUNn_MC(0));
123*9702ec00SEddy Petrișor 
124*9702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
125*9702ec00SEddy Petrișor 
126*9702ec00SEddy Petrișor 	/* Only ARM_PLL, ENET_PLL and DDR_PLL */
127*9702ec00SEddy Petrișor 	if ((pll == ARM_PLL) || (pll == ENET_PLL) || (pll == DDR_PLL)) {
128*9702ec00SEddy Petrișor 		/* DFS clk enable programming */
129*9702ec00SEddy Petrișor 		writel(DFS_CTRL_DLL_RESET, DFS_CTRL(pll));
130*9702ec00SEddy Petrișor 
131*9702ec00SEddy Petrișor 		writel(DFS_DLLPRG1_CPICTRL_SET(0x5) |
132*9702ec00SEddy Petrișor 		       DFS_DLLPRG1_VSETTLCTRL_SET(0x1) |
133*9702ec00SEddy Petrișor 		       DFS_DLLPRG1_CALBYPEN_SET(0x0) |
134*9702ec00SEddy Petrișor 		       DFS_DLLPRG1_DACIN_SET(0x1) | DFS_DLLPRG1_LCKWT_SET(0x0) |
135*9702ec00SEddy Petrișor 		       DFS_DLLPRG1_V2IGC_SET(0x5), DFS_DLLPRG1(pll));
136*9702ec00SEddy Petrișor 
137*9702ec00SEddy Petrișor 		for (i = 0; i < dfs_nr; i++) {
138*9702ec00SEddy Petrișor 			if (dfs[i][0]) {
139*9702ec00SEddy Petrișor 				writel(DFS_DVPORTn_MFI_SET(dfs[i][2]) |
140*9702ec00SEddy Petrișor 				       DFS_DVPORTn_MFN_SET(dfs[i][1]),
141*9702ec00SEddy Petrișor 				       DFS_DVPORTn(pll, i));
142*9702ec00SEddy Petrișor 				dfs_on |= (dfs[i][0] << i);
143*9702ec00SEddy Petrișor 			}
144*9702ec00SEddy Petrișor 		}
145*9702ec00SEddy Petrișor 
146*9702ec00SEddy Petrișor 		writel(readl(DFS_CTRL(pll)) & ~DFS_CTRL_DLL_RESET,
147*9702ec00SEddy Petrișor 		       DFS_CTRL(pll));
148*9702ec00SEddy Petrișor 		writel(readl(DFS_PORTRESET(pll)) &
149*9702ec00SEddy Petrișor 		       ~DFS_PORTRESET_PORTRESET_SET(dfs_on),
150*9702ec00SEddy Petrișor 		       DFS_PORTRESET(pll));
151*9702ec00SEddy Petrișor 		while ((readl(DFS_PORTSR(pll)) & dfs_on) != dfs_on) ;
152*9702ec00SEddy Petrișor 	}
153*9702ec00SEddy Petrișor 
154*9702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
155*9702ec00SEddy Petrișor 
156*9702ec00SEddy Petrișor 	return 0;
157*9702ec00SEddy Petrișor 
158*9702ec00SEddy Petrișor }
159*9702ec00SEddy Petrișor 
160*9702ec00SEddy Petrișor static void aux_source_clk_config(uintptr_t cgm_addr, u8 ac, u32 source)
161*9702ec00SEddy Petrișor {
162*9702ec00SEddy Petrișor 	/* select the clock source */
163*9702ec00SEddy Petrișor 	writel(MC_CGM_ACn_SEL_SET(source), CGM_ACn_SC(cgm_addr, ac));
164*9702ec00SEddy Petrișor }
165*9702ec00SEddy Petrișor 
166*9702ec00SEddy Petrișor static void aux_div_clk_config(uintptr_t cgm_addr, u8 ac, u8 dc, u32 divider)
167*9702ec00SEddy Petrișor {
168*9702ec00SEddy Petrișor 	/* set the divider */
169*9702ec00SEddy Petrișor 	writel(MC_CGM_ACn_DCm_DE | MC_CGM_ACn_DCm_PREDIV(divider),
170*9702ec00SEddy Petrișor 	       CGM_ACn_DCm(cgm_addr, ac, dc));
171*9702ec00SEddy Petrișor }
172*9702ec00SEddy Petrișor 
173*9702ec00SEddy Petrișor static void setup_sys_clocks(void)
174*9702ec00SEddy Petrișor {
175*9702ec00SEddy Petrișor 
176*9702ec00SEddy Petrișor 	/* set ARM PLL DFS 1 as SYSCLK */
177*9702ec00SEddy Petrișor 	writel((readl(MC_ME_RUNn_MC(0)) & ~MC_ME_RUNMODE_MC_SYSCLK_MASK) |
178*9702ec00SEddy Petrișor 	       MC_ME_RUNMODE_MC_SYSCLK(0x2), MC_ME_RUNn_MC(0));
179*9702ec00SEddy Petrișor 
180*9702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
181*9702ec00SEddy Petrișor 
182*9702ec00SEddy Petrișor 	/* select sysclks  ARMPLL, ARMPLLDFS2, ARMPLLDFS3 */
183*9702ec00SEddy Petrișor 	writel(MC_ME_RUNMODE_SEC_CC_I_SYSCLK
184*9702ec00SEddy Petrișor 	       (0x2,
185*9702ec00SEddy Petrișor 		MC_ME_RUNMODE_SEC_CC_I_SYSCLK1_OFFSET) |
186*9702ec00SEddy Petrișor 	       MC_ME_RUNMODE_SEC_CC_I_SYSCLK(0x2,
187*9702ec00SEddy Petrișor 					     MC_ME_RUNMODE_SEC_CC_I_SYSCLK2_OFFSET)
188*9702ec00SEddy Petrișor 	       | MC_ME_RUNMODE_SEC_CC_I_SYSCLK(0x2,
189*9702ec00SEddy Petrișor 					       MC_ME_RUNMODE_SEC_CC_I_SYSCLK3_OFFSET),
190*9702ec00SEddy Petrișor 	       MC_ME_RUNn_SEC_CC_I(0));
191*9702ec00SEddy Petrișor 
192*9702ec00SEddy Petrișor 	/* setup the sys clock divider for CORE_CLK (1000MHz) */
193*9702ec00SEddy Petrișor 	writel(MC_CGM_SC_DCn_DE | MC_CGM_SC_DCn_PREDIV(0x0),
194*9702ec00SEddy Petrișor 	       CGM_SC_DCn(MC_CGM1_BASE_ADDR, 0));
195*9702ec00SEddy Petrișor 
196*9702ec00SEddy Petrișor 	/* setup the sys clock divider for CORE2_CLK (500MHz) */
197*9702ec00SEddy Petrișor 	writel(MC_CGM_SC_DCn_DE | MC_CGM_SC_DCn_PREDIV(0x1),
198*9702ec00SEddy Petrișor 	       CGM_SC_DCn(MC_CGM1_BASE_ADDR, 1));
199*9702ec00SEddy Petrișor 	/* setup the sys clock divider for SYS3_CLK (266 MHz) */
200*9702ec00SEddy Petrișor 	writel(MC_CGM_SC_DCn_DE | MC_CGM_SC_DCn_PREDIV(0x0),
201*9702ec00SEddy Petrișor 	       CGM_SC_DCn(MC_CGM0_BASE_ADDR, 0));
202*9702ec00SEddy Petrișor 
203*9702ec00SEddy Petrișor 	/* setup the sys clock divider for SYS6_CLK (133 Mhz) */
204*9702ec00SEddy Petrișor 	writel(MC_CGM_SC_DCn_DE | MC_CGM_SC_DCn_PREDIV(0x1),
205*9702ec00SEddy Petrișor 	       CGM_SC_DCn(MC_CGM0_BASE_ADDR, 1));
206*9702ec00SEddy Petrișor 
207*9702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
208*9702ec00SEddy Petrișor 
209*9702ec00SEddy Petrișor }
210*9702ec00SEddy Petrișor 
211*9702ec00SEddy Petrișor static void setup_aux_clocks(void)
212*9702ec00SEddy Petrișor {
213*9702ec00SEddy Petrișor 	/*
214*9702ec00SEddy Petrișor 	 * setup the aux clock divider for PERI_CLK
215*9702ec00SEddy Petrișor 	 * (source: PERIPH_PLL_PHI_0/5, PERI_CLK - 80 MHz)
216*9702ec00SEddy Petrișor 	 */
217*9702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM0_BASE_ADDR, 5, MC_CGM_ACn_SEL_PERPLLDIVX);
218*9702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 5, 0, 4);
219*9702ec00SEddy Petrișor 
220*9702ec00SEddy Petrișor 	/* setup the aux clock divider for LIN_CLK (40MHz) */
221*9702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM0_BASE_ADDR, 3, MC_CGM_ACn_SEL_PERPLLDIVX);
222*9702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 3, 0, 1);
223*9702ec00SEddy Petrișor 
224*9702ec00SEddy Petrișor 	/* setup the aux clock divider for ENET_TIME_CLK (50MHz) */
225*9702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM0_BASE_ADDR, 7, MC_CGM_ACn_SEL_ENETPLL);
226*9702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 7, 1, 9);
227*9702ec00SEddy Petrișor 
228*9702ec00SEddy Petrișor 	/* setup the aux clock divider for ENET_CLK (50MHz) */
229*9702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM2_BASE_ADDR, 2, MC_CGM_ACn_SEL_ENETPLL);
230*9702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM2_BASE_ADDR, 2, 0, 9);
231*9702ec00SEddy Petrișor 
232*9702ec00SEddy Petrișor 	/* setup the aux clock divider for SDHC_CLK (50 MHz). */
233*9702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM0_BASE_ADDR, 15, MC_CGM_ACn_SEL_ENETPLL);
234*9702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 15, 0, 9);
235*9702ec00SEddy Petrișor 
236*9702ec00SEddy Petrișor 	/* setup the aux clock divider for DDR_CLK (533MHz) and APEX_SYS_CLK (266MHz) */
237*9702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM0_BASE_ADDR, 8, MC_CGM_ACn_SEL_DDRPLL);
238*9702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 8, 0, 0);
239*9702ec00SEddy Petrișor 	/* setup the aux clock divider for DDR4_CLK (133,25MHz) */
240*9702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 8, 1, 3);
241*9702ec00SEddy Petrișor 
242*9702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
243*9702ec00SEddy Petrișor 
244*9702ec00SEddy Petrișor }
245*9702ec00SEddy Petrișor 
246*9702ec00SEddy Petrișor static void enable_modules_clock(void)
247*9702ec00SEddy Petrișor {
248*9702ec00SEddy Petrișor 	/* PIT0 */
249*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL58);
250*9702ec00SEddy Petrișor 	/* PIT1 */
251*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL170);
252*9702ec00SEddy Petrișor 	/* LINFLEX0 */
253*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL83);
254*9702ec00SEddy Petrișor 	/* LINFLEX1 */
255*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL188);
256*9702ec00SEddy Petrișor 	/* ENET */
257*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL50);
258*9702ec00SEddy Petrișor 	/* SDHC */
259*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL93);
260*9702ec00SEddy Petrișor 	/* IIC0 */
261*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL81);
262*9702ec00SEddy Petrișor 	/* IIC1 */
263*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL184);
264*9702ec00SEddy Petrișor 	/* IIC2 */
265*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL186);
266*9702ec00SEddy Petrișor 	/* MMDC0 */
267*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL54);
268*9702ec00SEddy Petrișor 	/* MMDC1 */
269*9702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL162);
270*9702ec00SEddy Petrișor 
271*9702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
272*9702ec00SEddy Petrișor }
273*9702ec00SEddy Petrișor 
274*9702ec00SEddy Petrișor void clock_init(void)
275*9702ec00SEddy Petrișor {
276*9702ec00SEddy Petrișor 	unsigned int arm_dfs[ARM_PLL_PHI1_DFS_Nr][DFS_PARAMS_Nr] = {
277*9702ec00SEddy Petrișor 		{ARM_PLL_PHI1_DFS1_EN, ARM_PLL_PHI1_DFS1_MFN,
278*9702ec00SEddy Petrișor 		 ARM_PLL_PHI1_DFS1_MFI},
279*9702ec00SEddy Petrișor 		{ARM_PLL_PHI1_DFS2_EN, ARM_PLL_PHI1_DFS2_MFN,
280*9702ec00SEddy Petrișor 		 ARM_PLL_PHI1_DFS2_MFI},
281*9702ec00SEddy Petrișor 		{ARM_PLL_PHI1_DFS3_EN, ARM_PLL_PHI1_DFS3_MFN,
282*9702ec00SEddy Petrișor 		 ARM_PLL_PHI1_DFS3_MFI}
283*9702ec00SEddy Petrișor 	};
284*9702ec00SEddy Petrișor 
285*9702ec00SEddy Petrișor 	unsigned int enet_dfs[ENET_PLL_PHI1_DFS_Nr][DFS_PARAMS_Nr] = {
286*9702ec00SEddy Petrișor 		{ENET_PLL_PHI1_DFS1_EN, ENET_PLL_PHI1_DFS1_MFN,
287*9702ec00SEddy Petrișor 		 ENET_PLL_PHI1_DFS1_MFI},
288*9702ec00SEddy Petrișor 		{ENET_PLL_PHI1_DFS2_EN, ENET_PLL_PHI1_DFS2_MFN,
289*9702ec00SEddy Petrișor 		 ENET_PLL_PHI1_DFS2_MFI},
290*9702ec00SEddy Petrișor 		{ENET_PLL_PHI1_DFS3_EN, ENET_PLL_PHI1_DFS3_MFN,
291*9702ec00SEddy Petrișor 		 ENET_PLL_PHI1_DFS3_MFI},
292*9702ec00SEddy Petrișor 		{ENET_PLL_PHI1_DFS4_EN, ENET_PLL_PHI1_DFS4_MFN,
293*9702ec00SEddy Petrișor 		 ENET_PLL_PHI1_DFS4_MFI}
294*9702ec00SEddy Petrișor 	};
295*9702ec00SEddy Petrișor 
296*9702ec00SEddy Petrișor 	unsigned int ddr_dfs[DDR_PLL_PHI1_DFS_Nr][DFS_PARAMS_Nr] = {
297*9702ec00SEddy Petrișor 		{DDR_PLL_PHI1_DFS1_EN, DDR_PLL_PHI1_DFS1_MFN,
298*9702ec00SEddy Petrișor 		 DDR_PLL_PHI1_DFS1_MFI},
299*9702ec00SEddy Petrișor 		{DDR_PLL_PHI1_DFS2_EN, DDR_PLL_PHI1_DFS2_MFN,
300*9702ec00SEddy Petrișor 		 DDR_PLL_PHI1_DFS2_MFI},
301*9702ec00SEddy Petrișor 		{DDR_PLL_PHI1_DFS3_EN, DDR_PLL_PHI1_DFS3_MFN,
302*9702ec00SEddy Petrișor 		 DDR_PLL_PHI1_DFS3_MFI}
303*9702ec00SEddy Petrișor 	};
304*9702ec00SEddy Petrișor 
305*9702ec00SEddy Petrișor 	writel(MC_ME_RUN_PCn_DRUN | MC_ME_RUN_PCn_RUN0 | MC_ME_RUN_PCn_RUN1 |
306*9702ec00SEddy Petrișor 	       MC_ME_RUN_PCn_RUN2 | MC_ME_RUN_PCn_RUN3, MC_ME_RUN_PCn(0));
307*9702ec00SEddy Petrișor 
308*9702ec00SEddy Petrișor 	/* turn on FXOSC */
309*9702ec00SEddy Petrișor 	writel(MC_ME_RUNMODE_MC_MVRON | MC_ME_RUNMODE_MC_XOSCON |
310*9702ec00SEddy Petrișor 	       MC_ME_RUNMODE_MC_FIRCON | MC_ME_RUNMODE_MC_SYSCLK(0x1),
311*9702ec00SEddy Petrișor 	       MC_ME_RUNn_MC(0));
312*9702ec00SEddy Petrișor 
313*9702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
314*9702ec00SEddy Petrișor 
315*9702ec00SEddy Petrișor 	program_pll(ARM_PLL, XOSC_CLK_FREQ, ARM_PLL_PHI0_FREQ,
316*9702ec00SEddy Petrișor 		    ARM_PLL_PHI1_FREQ, ARM_PLL_PHI1_DFS_Nr, arm_dfs,
317*9702ec00SEddy Petrișor 		    ARM_PLL_PLLDV_PREDIV, ARM_PLL_PLLDV_MFD, ARM_PLL_PLLDV_MFN);
318*9702ec00SEddy Petrișor 
319*9702ec00SEddy Petrișor 	setup_sys_clocks();
320*9702ec00SEddy Petrișor 
321*9702ec00SEddy Petrișor 	program_pll(PERIPH_PLL, XOSC_CLK_FREQ, PERIPH_PLL_PHI0_FREQ,
322*9702ec00SEddy Petrișor 		    PERIPH_PLL_PHI1_FREQ, PERIPH_PLL_PHI1_DFS_Nr, NULL,
323*9702ec00SEddy Petrișor 		    PERIPH_PLL_PLLDV_PREDIV, PERIPH_PLL_PLLDV_MFD,
324*9702ec00SEddy Petrișor 		    PERIPH_PLL_PLLDV_MFN);
325*9702ec00SEddy Petrișor 
326*9702ec00SEddy Petrișor 	program_pll(ENET_PLL, XOSC_CLK_FREQ, ENET_PLL_PHI0_FREQ,
327*9702ec00SEddy Petrișor 		    ENET_PLL_PHI1_FREQ, ENET_PLL_PHI1_DFS_Nr, enet_dfs,
328*9702ec00SEddy Petrișor 		    ENET_PLL_PLLDV_PREDIV, ENET_PLL_PLLDV_MFD,
329*9702ec00SEddy Petrișor 		    ENET_PLL_PLLDV_MFN);
330*9702ec00SEddy Petrișor 
331*9702ec00SEddy Petrișor 	program_pll(DDR_PLL, XOSC_CLK_FREQ, DDR_PLL_PHI0_FREQ,
332*9702ec00SEddy Petrișor 		    DDR_PLL_PHI1_FREQ, DDR_PLL_PHI1_DFS_Nr, ddr_dfs,
333*9702ec00SEddy Petrișor 		    DDR_PLL_PLLDV_PREDIV, DDR_PLL_PLLDV_MFD, DDR_PLL_PLLDV_MFN);
334*9702ec00SEddy Petrișor 
335*9702ec00SEddy Petrișor 	program_pll(VIDEO_PLL, XOSC_CLK_FREQ, VIDEO_PLL_PHI0_FREQ,
336*9702ec00SEddy Petrișor 		    VIDEO_PLL_PHI1_FREQ, VIDEO_PLL_PHI1_DFS_Nr, NULL,
337*9702ec00SEddy Petrișor 		    VIDEO_PLL_PLLDV_PREDIV, VIDEO_PLL_PLLDV_MFD,
338*9702ec00SEddy Petrișor 		    VIDEO_PLL_PLLDV_MFN);
339*9702ec00SEddy Petrișor 
340*9702ec00SEddy Petrișor 	setup_aux_clocks();
341*9702ec00SEddy Petrișor 
342*9702ec00SEddy Petrișor 	enable_modules_clock();
343*9702ec00SEddy Petrișor 
344*9702ec00SEddy Petrișor }
345