1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2013 Freescale Semiconductor, Inc.
7 #include <clock_legacy.h>
12 #include <asm/cache.h>
14 #include <asm/arch/imx-regs.h>
15 #include <asm/arch/clock.h>
16 #include <asm/arch/crm_regs.h>
17 #include <asm/mach-imx/sys_proto.h>
20 #ifdef CONFIG_FSL_ESDHC_IMX
21 #include <fsl_esdhc_imx.h>
24 #ifdef CONFIG_FSL_ESDHC_IMX
25 DECLARE_GLOBAL_DATA_PTR;
28 static char soc_type[] = "xx0";
30 #ifdef CONFIG_MXC_OCOTP
31 void enable_ocotp_clk(unsigned char enable)
33 struct ccm_reg *ccm = (struct ccm_reg *)CCM_BASE_ADDR;
36 reg = readl(&ccm->ccgr6);
38 reg |= CCM_CCGR6_OCOTP_CTRL_MASK;
40 reg &= ~CCM_CCGR6_OCOTP_CTRL_MASK;
41 writel(reg, &ccm->ccgr6);
45 static u32 get_mcu_main_clk(void)
47 struct ccm_reg *ccm = (struct ccm_reg *)CCM_BASE_ADDR;
48 u32 ccm_ccsr, ccm_cacrr, armclk_div;
49 u32 sysclk_sel, pll_pfd_sel = 0;
52 ccm_ccsr = readl(&ccm->ccsr);
53 sysclk_sel = ccm_ccsr & CCM_CCSR_SYS_CLK_SEL_MASK;
54 sysclk_sel >>= CCM_CCSR_SYS_CLK_SEL_OFFSET;
56 ccm_cacrr = readl(&ccm->cacrr);
57 armclk_div = ccm_cacrr & CCM_CACRR_ARM_CLK_DIV_MASK;
58 armclk_div >>= CCM_CACRR_ARM_CLK_DIV_OFFSET;
69 pll_pfd_sel = ccm_ccsr & CCM_CCSR_PLL2_PFD_CLK_SEL_MASK;
70 pll_pfd_sel >>= CCM_CCSR_PLL2_PFD_CLK_SEL_OFFSET;
72 freq = PLL2_MAIN_FREQ;
73 else if (pll_pfd_sel == 1)
74 freq = PLL2_PFD1_FREQ;
75 else if (pll_pfd_sel == 2)
76 freq = PLL2_PFD2_FREQ;
77 else if (pll_pfd_sel == 3)
78 freq = PLL2_PFD3_FREQ;
79 else if (pll_pfd_sel == 4)
80 freq = PLL2_PFD4_FREQ;
83 freq = PLL2_MAIN_FREQ;
86 pll_pfd_sel = ccm_ccsr & CCM_CCSR_PLL1_PFD_CLK_SEL_MASK;
87 pll_pfd_sel >>= CCM_CCSR_PLL1_PFD_CLK_SEL_OFFSET;
89 freq = PLL1_MAIN_FREQ;
90 else if (pll_pfd_sel == 1)
91 freq = PLL1_PFD1_FREQ;
92 else if (pll_pfd_sel == 2)
93 freq = PLL1_PFD2_FREQ;
94 else if (pll_pfd_sel == 3)
95 freq = PLL1_PFD3_FREQ;
96 else if (pll_pfd_sel == 4)
97 freq = PLL1_PFD4_FREQ;
100 freq = PLL3_MAIN_FREQ;
103 printf("unsupported system clock select\n");
106 return freq / armclk_div;
109 static u32 get_bus_clk(void)
111 struct ccm_reg *ccm = (struct ccm_reg *)CCM_BASE_ADDR;
112 u32 ccm_cacrr, busclk_div;
114 ccm_cacrr = readl(&ccm->cacrr);
116 busclk_div = ccm_cacrr & CCM_CACRR_BUS_CLK_DIV_MASK;
117 busclk_div >>= CCM_CACRR_BUS_CLK_DIV_OFFSET;
120 return get_mcu_main_clk() / busclk_div;
123 static u32 get_ipg_clk(void)
125 struct ccm_reg *ccm = (struct ccm_reg *)CCM_BASE_ADDR;
126 u32 ccm_cacrr, ipgclk_div;
128 ccm_cacrr = readl(&ccm->cacrr);
130 ipgclk_div = ccm_cacrr & CCM_CACRR_IPG_CLK_DIV_MASK;
131 ipgclk_div >>= CCM_CACRR_IPG_CLK_DIV_OFFSET;
134 return get_bus_clk() / ipgclk_div;
137 static u32 get_uart_clk(void)
139 return get_ipg_clk();
142 static u32 get_sdhc_clk(void)
144 struct ccm_reg *ccm = (struct ccm_reg *)CCM_BASE_ADDR;
145 u32 ccm_cscmr1, ccm_cscdr2, sdhc_clk_sel, sdhc_clk_div;
148 ccm_cscmr1 = readl(&ccm->cscmr1);
149 sdhc_clk_sel = ccm_cscmr1 & CCM_CSCMR1_ESDHC1_CLK_SEL_MASK;
150 sdhc_clk_sel >>= CCM_CSCMR1_ESDHC1_CLK_SEL_OFFSET;
152 ccm_cscdr2 = readl(&ccm->cscdr2);
153 sdhc_clk_div = ccm_cscdr2 & CCM_CSCDR2_ESDHC1_CLK_DIV_MASK;
154 sdhc_clk_div >>= CCM_CSCDR2_ESDHC1_CLK_DIV_OFFSET;
157 switch (sdhc_clk_sel) {
159 freq = PLL3_MAIN_FREQ;
162 freq = PLL3_PFD3_FREQ;
165 freq = PLL1_PFD3_FREQ;
168 freq = get_bus_clk();
172 return freq / sdhc_clk_div;
175 u32 get_fec_clk(void)
177 struct ccm_reg *ccm = (struct ccm_reg *)CCM_BASE_ADDR;
178 u32 ccm_cscmr2, rmii_clk_sel;
181 ccm_cscmr2 = readl(&ccm->cscmr2);
182 rmii_clk_sel = ccm_cscmr2 & CCM_CSCMR2_RMII_CLK_SEL_MASK;
183 rmii_clk_sel >>= CCM_CSCMR2_RMII_CLK_SEL_OFFSET;
185 switch (rmii_clk_sel) {
187 freq = ENET_EXTERNAL_CLK;
190 freq = AUDIO_EXTERNAL_CLK;
193 freq = PLL5_MAIN_FREQ;
196 freq = PLL5_MAIN_FREQ / 2;
203 static u32 get_i2c_clk(void)
205 return get_ipg_clk();
208 static u32 get_dspi_clk(void)
210 return get_ipg_clk();
213 u32 get_lpuart_clk(void)
215 return get_uart_clk();
218 unsigned int mxc_get_clock(enum mxc_clock clk)
222 return get_mcu_main_clk();
224 return get_bus_clk();
226 return get_ipg_clk();
228 return get_uart_clk();
230 return get_sdhc_clk();
232 return get_fec_clk();
234 return get_i2c_clk();
236 return get_dspi_clk();
243 /* Dump some core clocks */
244 int do_vf610_showclocks(struct cmd_tbl *cmdtp, int flag, int argc,
248 printf("cpu clock : %8d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
249 printf("bus clock : %8d MHz\n", mxc_get_clock(MXC_BUS_CLK) / 1000000);
250 printf("ipg clock : %8d MHz\n", mxc_get_clock(MXC_IPG_CLK) / 1000000);
256 clocks, CONFIG_SYS_MAXARGS, 1, do_vf610_showclocks,
261 #ifdef CONFIG_FEC_MXC
262 __weak void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
264 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
265 struct fuse_bank *bank = &ocotp->bank[4];
266 struct fuse_bank4_regs *fuse =
267 (struct fuse_bank4_regs *)bank->fuse_regs;
269 u32 value = readl(&fuse->mac_addr0);
270 mac[0] = (value >> 8);
273 value = readl(&fuse->mac_addr1);
274 mac[2] = value >> 24;
275 mac[3] = value >> 16;
281 u32 get_cpu_rev(void)
283 return MXC_CPU_VF610 << 12;
286 #if defined(CONFIG_DISPLAY_CPUINFO)
287 static char *get_reset_cause(void)
290 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
292 cause = readl(&src_regs->srsr);
293 writel(cause, &src_regs->srsr);
295 if (cause & SRC_SRSR_POR_RST)
296 return "POWER ON RESET";
297 else if (cause & SRC_SRSR_WDOG_A5)
299 else if (cause & SRC_SRSR_WDOG_M4)
301 else if (cause & SRC_SRSR_JTAG_RST)
302 return "JTAG HIGH-Z";
303 else if (cause & SRC_SRSR_SW_RST)
305 else if (cause & SRC_SRSR_RESETB)
306 return "EXTERNAL RESET";
308 return "unknown reset";
311 int print_cpuinfo(void)
313 printf("CPU: Freescale Vybrid VF%s at %d MHz\n",
314 soc_type, mxc_get_clock(MXC_ARM_CLK) / 1000000);
315 printf("Reset cause: %s\n", get_reset_cause());
321 int arch_cpu_init(void)
323 struct mscm *mscm = (struct mscm *)MSCM_BASE_ADDR;
325 soc_type[0] = mscm->cpxcount ? '6' : '5'; /*Dual Core => VF6x0 */
326 soc_type[1] = mscm->cpxcfg1 ? '1' : '0'; /* L2 Cache => VFx10 */
331 #ifdef CONFIG_ARCH_MISC_INIT
332 int arch_misc_init(void)
337 strcat(soc, soc_type);
344 int cpu_eth_init(bd_t *bis)
348 #if defined(CONFIG_FEC_MXC)
349 rc = fecmxc_initialize(bis);
355 #ifdef CONFIG_FSL_ESDHC_IMX
356 int cpu_mmc_init(bd_t *bis)
358 return fsl_esdhc_mmc_init(bis);
364 #ifdef CONFIG_FSL_ESDHC_IMX
365 gd->arch.sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
370 #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
371 void enable_caches(void)
373 #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
374 enum dcache_option option = DCACHE_WRITETHROUGH;
376 enum dcache_option option = DCACHE_WRITEBACK;
381 /* Enable caching on OCRAM */
382 mmu_set_region_dcache_behaviour(IRAM_BASE_ADDR, IRAM_SIZE, option);
386 #ifdef CONFIG_SYS_I2C_MXC
387 /* i2c_num can be from 0 - 3 */
388 int enable_i2c_clk(unsigned char enable, unsigned int i2c_num)
390 struct ccm_reg *ccm = (struct ccm_reg *)CCM_BASE_ADDR;
394 clrsetbits_le32(&ccm->ccgr4, CCM_CCGR4_I2C0_CTRL_MASK,
395 CCM_CCGR4_I2C0_CTRL_MASK);
397 clrsetbits_le32(&ccm->ccgr10, CCM_CCGR10_I2C2_CTRL_MASK,
398 CCM_CCGR10_I2C2_CTRL_MASK);