xref: /rk3399_rockchip-uboot/board/freescale/s32v234evb/clock.c (revision 51855e8981e1b5e0a7b919662c32d0e4a374f575)
19702ec00SEddy Petrișor /*
29702ec00SEddy Petrișor  * (C) Copyright 2015, Freescale Semiconductor, Inc.
39702ec00SEddy Petrișor  *
49702ec00SEddy Petrișor  * SPDX-License-Identifier:	GPL-2.0+
59702ec00SEddy Petrișor  */
69702ec00SEddy Petrișor 
79702ec00SEddy Petrișor #include <asm/io.h>
89702ec00SEddy Petrișor #include <asm/arch/imx-regs.h>
99702ec00SEddy Petrișor #include <asm/arch/mc_cgm_regs.h>
109702ec00SEddy Petrișor #include <asm/arch/mc_me_regs.h>
119702ec00SEddy Petrișor #include <asm/arch/clock.h>
129702ec00SEddy Petrișor 
139702ec00SEddy Petrișor /*
149702ec00SEddy Petrișor  * Select the clock reference for required pll.
159702ec00SEddy Petrișor  * pll - ARM_PLL, PERIPH_PLL, ENET_PLL, DDR_PLL, VIDEO_PLL.
169702ec00SEddy Petrișor  * refclk_freq - input referece clock frequency (FXOSC - 40 MHZ, FIRC - 48 MHZ)
179702ec00SEddy Petrișor  */
select_pll_source_clk(enum pll_type pll,u32 refclk_freq)189702ec00SEddy Petrișor static int select_pll_source_clk(enum pll_type pll, u32 refclk_freq)
199702ec00SEddy Petrișor {
209702ec00SEddy Petrișor 	u32 clk_src;
219702ec00SEddy Petrișor 	u32 pll_idx;
229702ec00SEddy Petrișor 	volatile struct src *src = (struct src *)SRC_SOC_BASE_ADDR;
239702ec00SEddy Petrișor 
249702ec00SEddy Petrișor 	/* select the pll clock source */
259702ec00SEddy Petrișor 	switch (refclk_freq) {
269702ec00SEddy Petrișor 	case FIRC_CLK_FREQ:
279702ec00SEddy Petrișor 		clk_src = SRC_GPR1_FIRC_CLK_SOURCE;
289702ec00SEddy Petrișor 		break;
299702ec00SEddy Petrișor 	case XOSC_CLK_FREQ:
309702ec00SEddy Petrișor 		clk_src = SRC_GPR1_XOSC_CLK_SOURCE;
319702ec00SEddy Petrișor 		break;
329702ec00SEddy Petrișor 	default:
339702ec00SEddy Petrișor 		/* The clock frequency for the source clock is unknown */
349702ec00SEddy Petrișor 		return -1;
359702ec00SEddy Petrișor 	}
369702ec00SEddy Petrișor 	/*
379702ec00SEddy Petrișor 	 * The hardware definition is not uniform, it has to calculate again
389702ec00SEddy Petrișor 	 * the recurrence formula.
399702ec00SEddy Petrișor 	 */
409702ec00SEddy Petrișor 	switch (pll) {
419702ec00SEddy Petrișor 	case PERIPH_PLL:
429702ec00SEddy Petrișor 		pll_idx = 3;
439702ec00SEddy Petrișor 		break;
449702ec00SEddy Petrișor 	case ENET_PLL:
459702ec00SEddy Petrișor 		pll_idx = 1;
469702ec00SEddy Petrișor 		break;
479702ec00SEddy Petrișor 	case DDR_PLL:
48*51855e89SMasahiro Yamada 		pll_idx = 2;
499702ec00SEddy Petrișor 		break;
509702ec00SEddy Petrișor 	default:
519702ec00SEddy Petrișor 		pll_idx = pll;
529702ec00SEddy Petrișor 	}
539702ec00SEddy Petrișor 
549702ec00SEddy Petrișor 	writel(readl(&src->gpr1) | SRC_GPR1_PLL_SOURCE(pll_idx, clk_src),
559702ec00SEddy Petrișor 	       &src->gpr1);
569702ec00SEddy Petrișor 
579702ec00SEddy Petrișor 	return 0;
589702ec00SEddy Petrișor }
599702ec00SEddy Petrișor 
entry_to_target_mode(u32 mode)609702ec00SEddy Petrișor static void entry_to_target_mode(u32 mode)
619702ec00SEddy Petrișor {
629702ec00SEddy Petrișor 	writel(mode | MC_ME_MCTL_KEY, MC_ME_MCTL);
639702ec00SEddy Petrișor 	writel(mode | MC_ME_MCTL_INVERTEDKEY, MC_ME_MCTL);
649702ec00SEddy Petrișor 	while ((readl(MC_ME_GS) & MC_ME_GS_S_MTRANS) != 0x00000000) ;
659702ec00SEddy Petrișor }
669702ec00SEddy Petrișor 
679702ec00SEddy Petrișor /*
689702ec00SEddy Petrișor  * Program the pll according to the input parameters.
699702ec00SEddy Petrișor  * pll - ARM_PLL, PERIPH_PLL, ENET_PLL, DDR_PLL, VIDEO_PLL.
709702ec00SEddy Petrișor  * refclk_freq - input reference clock frequency (FXOSC - 40 MHZ, FIRC - 48 MHZ)
719702ec00SEddy Petrișor  * freq - expected output frequency for PHY0
729702ec00SEddy Petrișor  * freq1 - expected output frequency for PHY1
739702ec00SEddy Petrișor  * dfs_nr - number of DFS modules for current PLL
749702ec00SEddy Petrișor  * dfs - array with the activation dfs field, mfn and mfi
759702ec00SEddy Petrișor  * plldv_prediv - divider of clkfreq_ref
769702ec00SEddy Petrișor  * plldv_mfd - loop multiplication factor divider
779702ec00SEddy Petrișor  * pllfd_mfn - numerator loop multiplication factor divider
789702ec00SEddy Petrișor  * Please consult the PLLDIG chapter of platform manual
799702ec00SEddy Petrișor  * before to use this function.
809702ec00SEddy Petrișor  *)
819702ec00SEddy Petrișor  */
program_pll(enum pll_type pll,u32 refclk_freq,u32 freq0,u32 freq1,u32 dfs_nr,u32 dfs[][DFS_PARAMS_Nr],u32 plldv_prediv,u32 plldv_mfd,u32 pllfd_mfn)829702ec00SEddy Petrișor static int program_pll(enum pll_type pll, u32 refclk_freq, u32 freq0, u32 freq1,
839702ec00SEddy Petrișor 		       u32 dfs_nr, u32 dfs[][DFS_PARAMS_Nr], u32 plldv_prediv,
849702ec00SEddy Petrișor 		       u32 plldv_mfd, u32 pllfd_mfn)
859702ec00SEddy Petrișor {
869702ec00SEddy Petrișor 	u32 i, rfdphi1, rfdphi, dfs_on = 0, fvco;
879702ec00SEddy Petrișor 
889702ec00SEddy Petrișor 	/*
899702ec00SEddy Petrișor 	 * This formula is from platform reference manual (Rev. 1, 6/2015), PLLDIG chapter.
909702ec00SEddy Petrișor 	 */
919702ec00SEddy Petrișor 	fvco =
929702ec00SEddy Petrișor 	    (refclk_freq / plldv_prediv) * (plldv_mfd +
939702ec00SEddy Petrișor 					    pllfd_mfn / (float)20480);
949702ec00SEddy Petrișor 
959702ec00SEddy Petrișor 	/*
969702ec00SEddy Petrișor 	 * VCO should have value in [ PLL_MIN_FREQ, PLL_MAX_FREQ ]. Please consult
979702ec00SEddy Petrișor 	 * the platform DataSheet in order to determine the allowed values.
989702ec00SEddy Petrișor 	 */
999702ec00SEddy Petrișor 
1009702ec00SEddy Petrișor 	if (fvco < PLL_MIN_FREQ || fvco > PLL_MAX_FREQ) {
1019702ec00SEddy Petrișor 		return -1;
1029702ec00SEddy Petrișor 	}
1039702ec00SEddy Petrișor 
1049702ec00SEddy Petrișor 	if (select_pll_source_clk(pll, refclk_freq) < 0) {
1059702ec00SEddy Petrișor 		return -1;
1069702ec00SEddy Petrișor 	}
1079702ec00SEddy Petrișor 
1089702ec00SEddy Petrișor 	rfdphi = fvco / freq0;
1099702ec00SEddy Petrișor 
1109702ec00SEddy Petrișor 	rfdphi1 = (freq1 == 0) ? 0 : fvco / freq1;
1119702ec00SEddy Petrișor 
1129702ec00SEddy Petrișor 	writel(PLLDIG_PLLDV_RFDPHI1_SET(rfdphi1) |
1139702ec00SEddy Petrișor 	       PLLDIG_PLLDV_RFDPHI_SET(rfdphi) |
1149702ec00SEddy Petrișor 	       PLLDIG_PLLDV_PREDIV_SET(plldv_prediv) |
1159702ec00SEddy Petrișor 	       PLLDIG_PLLDV_MFD(plldv_mfd), PLLDIG_PLLDV(pll));
1169702ec00SEddy Petrișor 
1179702ec00SEddy Petrișor 	writel(readl(PLLDIG_PLLFD(pll)) | PLLDIG_PLLFD_MFN_SET(pllfd_mfn) |
1189702ec00SEddy Petrișor 	       PLLDIG_PLLFD_SMDEN, PLLDIG_PLLFD(pll));
1199702ec00SEddy Petrișor 
1209702ec00SEddy Petrișor 	/* switch on the pll in current mode */
1219702ec00SEddy Petrișor 	writel(readl(MC_ME_RUNn_MC(0)) | MC_ME_RUNMODE_MC_PLL(pll),
1229702ec00SEddy Petrișor 	       MC_ME_RUNn_MC(0));
1239702ec00SEddy Petrișor 
1249702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
1259702ec00SEddy Petrișor 
1269702ec00SEddy Petrișor 	/* Only ARM_PLL, ENET_PLL and DDR_PLL */
1279702ec00SEddy Petrișor 	if ((pll == ARM_PLL) || (pll == ENET_PLL) || (pll == DDR_PLL)) {
1289702ec00SEddy Petrișor 		/* DFS clk enable programming */
1299702ec00SEddy Petrișor 		writel(DFS_CTRL_DLL_RESET, DFS_CTRL(pll));
1309702ec00SEddy Petrișor 
1319702ec00SEddy Petrișor 		writel(DFS_DLLPRG1_CPICTRL_SET(0x5) |
1329702ec00SEddy Petrișor 		       DFS_DLLPRG1_VSETTLCTRL_SET(0x1) |
1339702ec00SEddy Petrișor 		       DFS_DLLPRG1_CALBYPEN_SET(0x0) |
1349702ec00SEddy Petrișor 		       DFS_DLLPRG1_DACIN_SET(0x1) | DFS_DLLPRG1_LCKWT_SET(0x0) |
1359702ec00SEddy Petrișor 		       DFS_DLLPRG1_V2IGC_SET(0x5), DFS_DLLPRG1(pll));
1369702ec00SEddy Petrișor 
1379702ec00SEddy Petrișor 		for (i = 0; i < dfs_nr; i++) {
1389702ec00SEddy Petrișor 			if (dfs[i][0]) {
1399702ec00SEddy Petrișor 				writel(DFS_DVPORTn_MFI_SET(dfs[i][2]) |
1409702ec00SEddy Petrișor 				       DFS_DVPORTn_MFN_SET(dfs[i][1]),
1419702ec00SEddy Petrișor 				       DFS_DVPORTn(pll, i));
1429702ec00SEddy Petrișor 				dfs_on |= (dfs[i][0] << i);
1439702ec00SEddy Petrișor 			}
1449702ec00SEddy Petrișor 		}
1459702ec00SEddy Petrișor 
1469702ec00SEddy Petrișor 		writel(readl(DFS_CTRL(pll)) & ~DFS_CTRL_DLL_RESET,
1479702ec00SEddy Petrișor 		       DFS_CTRL(pll));
1489702ec00SEddy Petrișor 		writel(readl(DFS_PORTRESET(pll)) &
1499702ec00SEddy Petrișor 		       ~DFS_PORTRESET_PORTRESET_SET(dfs_on),
1509702ec00SEddy Petrișor 		       DFS_PORTRESET(pll));
1519702ec00SEddy Petrișor 		while ((readl(DFS_PORTSR(pll)) & dfs_on) != dfs_on) ;
1529702ec00SEddy Petrișor 	}
1539702ec00SEddy Petrișor 
1549702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
1559702ec00SEddy Petrișor 
1569702ec00SEddy Petrișor 	return 0;
1579702ec00SEddy Petrișor 
1589702ec00SEddy Petrișor }
1599702ec00SEddy Petrișor 
aux_source_clk_config(uintptr_t cgm_addr,u8 ac,u32 source)1609702ec00SEddy Petrișor static void aux_source_clk_config(uintptr_t cgm_addr, u8 ac, u32 source)
1619702ec00SEddy Petrișor {
1629702ec00SEddy Petrișor 	/* select the clock source */
1639702ec00SEddy Petrișor 	writel(MC_CGM_ACn_SEL_SET(source), CGM_ACn_SC(cgm_addr, ac));
1649702ec00SEddy Petrișor }
1659702ec00SEddy Petrișor 
aux_div_clk_config(uintptr_t cgm_addr,u8 ac,u8 dc,u32 divider)1669702ec00SEddy Petrișor static void aux_div_clk_config(uintptr_t cgm_addr, u8 ac, u8 dc, u32 divider)
1679702ec00SEddy Petrișor {
1689702ec00SEddy Petrișor 	/* set the divider */
1699702ec00SEddy Petrișor 	writel(MC_CGM_ACn_DCm_DE | MC_CGM_ACn_DCm_PREDIV(divider),
1709702ec00SEddy Petrișor 	       CGM_ACn_DCm(cgm_addr, ac, dc));
1719702ec00SEddy Petrișor }
1729702ec00SEddy Petrișor 
setup_sys_clocks(void)1739702ec00SEddy Petrișor static void setup_sys_clocks(void)
1749702ec00SEddy Petrișor {
1759702ec00SEddy Petrișor 
1769702ec00SEddy Petrișor 	/* set ARM PLL DFS 1 as SYSCLK */
1779702ec00SEddy Petrișor 	writel((readl(MC_ME_RUNn_MC(0)) & ~MC_ME_RUNMODE_MC_SYSCLK_MASK) |
1789702ec00SEddy Petrișor 	       MC_ME_RUNMODE_MC_SYSCLK(0x2), MC_ME_RUNn_MC(0));
1799702ec00SEddy Petrișor 
1809702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
1819702ec00SEddy Petrișor 
1829702ec00SEddy Petrișor 	/* select sysclks  ARMPLL, ARMPLLDFS2, ARMPLLDFS3 */
1839702ec00SEddy Petrișor 	writel(MC_ME_RUNMODE_SEC_CC_I_SYSCLK
1849702ec00SEddy Petrișor 	       (0x2,
1859702ec00SEddy Petrișor 		MC_ME_RUNMODE_SEC_CC_I_SYSCLK1_OFFSET) |
1869702ec00SEddy Petrișor 	       MC_ME_RUNMODE_SEC_CC_I_SYSCLK(0x2,
1879702ec00SEddy Petrișor 					     MC_ME_RUNMODE_SEC_CC_I_SYSCLK2_OFFSET)
1889702ec00SEddy Petrișor 	       | MC_ME_RUNMODE_SEC_CC_I_SYSCLK(0x2,
1899702ec00SEddy Petrișor 					       MC_ME_RUNMODE_SEC_CC_I_SYSCLK3_OFFSET),
1909702ec00SEddy Petrișor 	       MC_ME_RUNn_SEC_CC_I(0));
1919702ec00SEddy Petrișor 
1929702ec00SEddy Petrișor 	/* setup the sys clock divider for CORE_CLK (1000MHz) */
1939702ec00SEddy Petrișor 	writel(MC_CGM_SC_DCn_DE | MC_CGM_SC_DCn_PREDIV(0x0),
1949702ec00SEddy Petrișor 	       CGM_SC_DCn(MC_CGM1_BASE_ADDR, 0));
1959702ec00SEddy Petrișor 
1969702ec00SEddy Petrișor 	/* setup the sys clock divider for CORE2_CLK (500MHz) */
1979702ec00SEddy Petrișor 	writel(MC_CGM_SC_DCn_DE | MC_CGM_SC_DCn_PREDIV(0x1),
1989702ec00SEddy Petrișor 	       CGM_SC_DCn(MC_CGM1_BASE_ADDR, 1));
1999702ec00SEddy Petrișor 	/* setup the sys clock divider for SYS3_CLK (266 MHz) */
2009702ec00SEddy Petrișor 	writel(MC_CGM_SC_DCn_DE | MC_CGM_SC_DCn_PREDIV(0x0),
2019702ec00SEddy Petrișor 	       CGM_SC_DCn(MC_CGM0_BASE_ADDR, 0));
2029702ec00SEddy Petrișor 
2039702ec00SEddy Petrișor 	/* setup the sys clock divider for SYS6_CLK (133 Mhz) */
2049702ec00SEddy Petrișor 	writel(MC_CGM_SC_DCn_DE | MC_CGM_SC_DCn_PREDIV(0x1),
2059702ec00SEddy Petrișor 	       CGM_SC_DCn(MC_CGM0_BASE_ADDR, 1));
2069702ec00SEddy Petrișor 
2079702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
2089702ec00SEddy Petrișor 
2099702ec00SEddy Petrișor }
2109702ec00SEddy Petrișor 
setup_aux_clocks(void)2119702ec00SEddy Petrișor static void setup_aux_clocks(void)
2129702ec00SEddy Petrișor {
2139702ec00SEddy Petrișor 	/*
2149702ec00SEddy Petrișor 	 * setup the aux clock divider for PERI_CLK
2159702ec00SEddy Petrișor 	 * (source: PERIPH_PLL_PHI_0/5, PERI_CLK - 80 MHz)
2169702ec00SEddy Petrișor 	 */
2179702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM0_BASE_ADDR, 5, MC_CGM_ACn_SEL_PERPLLDIVX);
2189702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 5, 0, 4);
2199702ec00SEddy Petrișor 
2209702ec00SEddy Petrișor 	/* setup the aux clock divider for LIN_CLK (40MHz) */
2219702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM0_BASE_ADDR, 3, MC_CGM_ACn_SEL_PERPLLDIVX);
2229702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 3, 0, 1);
2239702ec00SEddy Petrișor 
2249702ec00SEddy Petrișor 	/* setup the aux clock divider for ENET_TIME_CLK (50MHz) */
2259702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM0_BASE_ADDR, 7, MC_CGM_ACn_SEL_ENETPLL);
2269702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 7, 1, 9);
2279702ec00SEddy Petrișor 
2289702ec00SEddy Petrișor 	/* setup the aux clock divider for ENET_CLK (50MHz) */
2299702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM2_BASE_ADDR, 2, MC_CGM_ACn_SEL_ENETPLL);
2309702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM2_BASE_ADDR, 2, 0, 9);
2319702ec00SEddy Petrișor 
2329702ec00SEddy Petrișor 	/* setup the aux clock divider for SDHC_CLK (50 MHz). */
2339702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM0_BASE_ADDR, 15, MC_CGM_ACn_SEL_ENETPLL);
2349702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 15, 0, 9);
2359702ec00SEddy Petrișor 
2369702ec00SEddy Petrișor 	/* setup the aux clock divider for DDR_CLK (533MHz) and APEX_SYS_CLK (266MHz) */
2379702ec00SEddy Petrișor 	aux_source_clk_config(MC_CGM0_BASE_ADDR, 8, MC_CGM_ACn_SEL_DDRPLL);
2389702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 8, 0, 0);
2399702ec00SEddy Petrișor 	/* setup the aux clock divider for DDR4_CLK (133,25MHz) */
2409702ec00SEddy Petrișor 	aux_div_clk_config(MC_CGM0_BASE_ADDR, 8, 1, 3);
2419702ec00SEddy Petrișor 
2429702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
2439702ec00SEddy Petrișor 
2449702ec00SEddy Petrișor }
2459702ec00SEddy Petrișor 
enable_modules_clock(void)2469702ec00SEddy Petrișor static void enable_modules_clock(void)
2479702ec00SEddy Petrișor {
2489702ec00SEddy Petrișor 	/* PIT0 */
2499702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL58);
2509702ec00SEddy Petrișor 	/* PIT1 */
2519702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL170);
2529702ec00SEddy Petrișor 	/* LINFLEX0 */
2539702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL83);
2549702ec00SEddy Petrișor 	/* LINFLEX1 */
2559702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL188);
2569702ec00SEddy Petrișor 	/* ENET */
2579702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL50);
2589702ec00SEddy Petrișor 	/* SDHC */
2599702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL93);
2609702ec00SEddy Petrișor 	/* IIC0 */
2619702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL81);
2629702ec00SEddy Petrișor 	/* IIC1 */
2639702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL184);
2649702ec00SEddy Petrișor 	/* IIC2 */
2659702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL186);
2669702ec00SEddy Petrișor 	/* MMDC0 */
2679702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL54);
2689702ec00SEddy Petrișor 	/* MMDC1 */
2699702ec00SEddy Petrișor 	writeb(MC_ME_PCTLn_RUNPCm(0), MC_ME_PCTL162);
2709702ec00SEddy Petrișor 
2719702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
2729702ec00SEddy Petrișor }
2739702ec00SEddy Petrișor 
clock_init(void)2749702ec00SEddy Petrișor void clock_init(void)
2759702ec00SEddy Petrișor {
2769702ec00SEddy Petrișor 	unsigned int arm_dfs[ARM_PLL_PHI1_DFS_Nr][DFS_PARAMS_Nr] = {
2779702ec00SEddy Petrișor 		{ARM_PLL_PHI1_DFS1_EN, ARM_PLL_PHI1_DFS1_MFN,
2789702ec00SEddy Petrișor 		 ARM_PLL_PHI1_DFS1_MFI},
2799702ec00SEddy Petrișor 		{ARM_PLL_PHI1_DFS2_EN, ARM_PLL_PHI1_DFS2_MFN,
2809702ec00SEddy Petrișor 		 ARM_PLL_PHI1_DFS2_MFI},
2819702ec00SEddy Petrișor 		{ARM_PLL_PHI1_DFS3_EN, ARM_PLL_PHI1_DFS3_MFN,
2829702ec00SEddy Petrișor 		 ARM_PLL_PHI1_DFS3_MFI}
2839702ec00SEddy Petrișor 	};
2849702ec00SEddy Petrișor 
2859702ec00SEddy Petrișor 	unsigned int enet_dfs[ENET_PLL_PHI1_DFS_Nr][DFS_PARAMS_Nr] = {
2869702ec00SEddy Petrișor 		{ENET_PLL_PHI1_DFS1_EN, ENET_PLL_PHI1_DFS1_MFN,
2879702ec00SEddy Petrișor 		 ENET_PLL_PHI1_DFS1_MFI},
2889702ec00SEddy Petrișor 		{ENET_PLL_PHI1_DFS2_EN, ENET_PLL_PHI1_DFS2_MFN,
2899702ec00SEddy Petrișor 		 ENET_PLL_PHI1_DFS2_MFI},
2909702ec00SEddy Petrișor 		{ENET_PLL_PHI1_DFS3_EN, ENET_PLL_PHI1_DFS3_MFN,
2919702ec00SEddy Petrișor 		 ENET_PLL_PHI1_DFS3_MFI},
2929702ec00SEddy Petrișor 		{ENET_PLL_PHI1_DFS4_EN, ENET_PLL_PHI1_DFS4_MFN,
2939702ec00SEddy Petrișor 		 ENET_PLL_PHI1_DFS4_MFI}
2949702ec00SEddy Petrișor 	};
2959702ec00SEddy Petrișor 
2969702ec00SEddy Petrișor 	unsigned int ddr_dfs[DDR_PLL_PHI1_DFS_Nr][DFS_PARAMS_Nr] = {
2979702ec00SEddy Petrișor 		{DDR_PLL_PHI1_DFS1_EN, DDR_PLL_PHI1_DFS1_MFN,
2989702ec00SEddy Petrișor 		 DDR_PLL_PHI1_DFS1_MFI},
2999702ec00SEddy Petrișor 		{DDR_PLL_PHI1_DFS2_EN, DDR_PLL_PHI1_DFS2_MFN,
3009702ec00SEddy Petrișor 		 DDR_PLL_PHI1_DFS2_MFI},
3019702ec00SEddy Petrișor 		{DDR_PLL_PHI1_DFS3_EN, DDR_PLL_PHI1_DFS3_MFN,
3029702ec00SEddy Petrișor 		 DDR_PLL_PHI1_DFS3_MFI}
3039702ec00SEddy Petrișor 	};
3049702ec00SEddy Petrișor 
3059702ec00SEddy Petrișor 	writel(MC_ME_RUN_PCn_DRUN | MC_ME_RUN_PCn_RUN0 | MC_ME_RUN_PCn_RUN1 |
3069702ec00SEddy Petrișor 	       MC_ME_RUN_PCn_RUN2 | MC_ME_RUN_PCn_RUN3, MC_ME_RUN_PCn(0));
3079702ec00SEddy Petrișor 
3089702ec00SEddy Petrișor 	/* turn on FXOSC */
3099702ec00SEddy Petrișor 	writel(MC_ME_RUNMODE_MC_MVRON | MC_ME_RUNMODE_MC_XOSCON |
3109702ec00SEddy Petrișor 	       MC_ME_RUNMODE_MC_FIRCON | MC_ME_RUNMODE_MC_SYSCLK(0x1),
3119702ec00SEddy Petrișor 	       MC_ME_RUNn_MC(0));
3129702ec00SEddy Petrișor 
3139702ec00SEddy Petrișor 	entry_to_target_mode(MC_ME_MCTL_RUN0);
3149702ec00SEddy Petrișor 
3159702ec00SEddy Petrișor 	program_pll(ARM_PLL, XOSC_CLK_FREQ, ARM_PLL_PHI0_FREQ,
3169702ec00SEddy Petrișor 		    ARM_PLL_PHI1_FREQ, ARM_PLL_PHI1_DFS_Nr, arm_dfs,
3179702ec00SEddy Petrișor 		    ARM_PLL_PLLDV_PREDIV, ARM_PLL_PLLDV_MFD, ARM_PLL_PLLDV_MFN);
3189702ec00SEddy Petrișor 
3199702ec00SEddy Petrișor 	setup_sys_clocks();
3209702ec00SEddy Petrișor 
3219702ec00SEddy Petrișor 	program_pll(PERIPH_PLL, XOSC_CLK_FREQ, PERIPH_PLL_PHI0_FREQ,
3229702ec00SEddy Petrișor 		    PERIPH_PLL_PHI1_FREQ, PERIPH_PLL_PHI1_DFS_Nr, NULL,
3239702ec00SEddy Petrișor 		    PERIPH_PLL_PLLDV_PREDIV, PERIPH_PLL_PLLDV_MFD,
3249702ec00SEddy Petrișor 		    PERIPH_PLL_PLLDV_MFN);
3259702ec00SEddy Petrișor 
3269702ec00SEddy Petrișor 	program_pll(ENET_PLL, XOSC_CLK_FREQ, ENET_PLL_PHI0_FREQ,
3279702ec00SEddy Petrișor 		    ENET_PLL_PHI1_FREQ, ENET_PLL_PHI1_DFS_Nr, enet_dfs,
3289702ec00SEddy Petrișor 		    ENET_PLL_PLLDV_PREDIV, ENET_PLL_PLLDV_MFD,
3299702ec00SEddy Petrișor 		    ENET_PLL_PLLDV_MFN);
3309702ec00SEddy Petrișor 
3319702ec00SEddy Petrișor 	program_pll(DDR_PLL, XOSC_CLK_FREQ, DDR_PLL_PHI0_FREQ,
3329702ec00SEddy Petrișor 		    DDR_PLL_PHI1_FREQ, DDR_PLL_PHI1_DFS_Nr, ddr_dfs,
3339702ec00SEddy Petrișor 		    DDR_PLL_PLLDV_PREDIV, DDR_PLL_PLLDV_MFD, DDR_PLL_PLLDV_MFN);
3349702ec00SEddy Petrișor 
3359702ec00SEddy Petrișor 	program_pll(VIDEO_PLL, XOSC_CLK_FREQ, VIDEO_PLL_PHI0_FREQ,
3369702ec00SEddy Petrișor 		    VIDEO_PLL_PHI1_FREQ, VIDEO_PLL_PHI1_DFS_Nr, NULL,
3379702ec00SEddy Petrișor 		    VIDEO_PLL_PLLDV_PREDIV, VIDEO_PLL_PLLDV_MFD,
3389702ec00SEddy Petrișor 		    VIDEO_PLL_PLLDV_MFN);
3399702ec00SEddy Petrișor 
3409702ec00SEddy Petrișor 	setup_aux_clocks();
3419702ec00SEddy Petrișor 
3429702ec00SEddy Petrișor 	enable_modules_clock();
3439702ec00SEddy Petrișor 
3449702ec00SEddy Petrișor }
345