1 // SPDX-License-Identifier: GPL-2.0+
3 * Freescale i.MX23/i.MX28 common code
6 * on behalf of DENX Software Engineering GmbH
8 * Based on code from LTIB:
9 * Copyright (C) 2010 Freescale Semiconductor, Inc.
17 #include <asm/global_data.h>
18 #include <linux/delay.h>
19 #include <linux/errno.h>
21 #include <asm/arch/clock.h>
22 #include <asm/mach-imx/dma.h>
23 #include <asm/arch/gpio.h>
24 #include <asm/arch/iomux.h>
25 #include <asm/arch/imx-regs.h>
26 #include <asm/arch/sys_proto.h>
27 #include <asm/sections.h>
28 #include <linux/compiler.h>
30 DECLARE_GLOBAL_DATA_PTR;
32 /* Lowlevel init isn't used on i.MX28, so just have a dummy here */
33 __weak void lowlevel_init(void) {}
35 void reset_cpu(void) __attribute__((noreturn));
39 struct mxs_rtc_regs *rtc_regs =
40 (struct mxs_rtc_regs *)MXS_RTC_BASE;
41 struct mxs_lcdif_regs *lcdif_regs =
42 (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
45 * Shut down the LCD controller as it interferes with BootROM boot mode
48 writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr);
50 /* Wait 1 uS before doing the actual watchdog reset */
51 writel(1, &rtc_regs->hw_rtc_watchdog);
52 writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
54 /* Endless loop, reset will exit from here */
60 * This function will craft a jumptable at 0x0 which will redirect interrupt
61 * vectoring to proper location of U-Boot in RAM.
63 * The structure of the jumptable will be as follows:
64 * ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times
65 * <destination address> ... for each previous ldr, thus also repeated 8 times
67 * The "ldr pc, [pc, #0x18]" instruction above loads address from memory at
68 * offset 0x18 from current value of PC register. Note that PC is already
69 * incremented by 4 when computing the offset, so the effective offset is
70 * actually 0x20, this the associated <destination address>. Loading the PC
71 * register with an address performs a jump to that address.
73 noinline __attribute__((target("arm")))
74 void mx28_fixup_vt(uint32_t start_addr)
76 /* ldr pc, [pc, #0x18] */
77 const uint32_t ldr_pc = 0xe59ff018;
78 /* Jumptable location is 0x0 */
79 uint32_t *vt = (uint32_t *)0x0;
82 for (i = 0; i < 8; i++) {
83 /* cppcheck-suppress nullPointer */
85 /* cppcheck-suppress nullPointer */
86 vt[i + 8] = start_addr + (4 * i);
89 /* Make sure ARM core points to low vectors */
90 set_cr(get_cr() & ~CR_V);
93 #ifdef CONFIG_ARCH_MISC_INIT
94 int arch_misc_init(void)
96 mx28_fixup_vt(gd->relocaddr);
101 int arch_cpu_init(void)
103 struct mxs_clkctrl_regs *clkctrl_regs =
104 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
106 mx28_fixup_vt((uint32_t)_start);
112 writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
113 &clkctrl_regs->hw_clkctrl_clkseq_set);
115 /* Set GPMI clock to ref_xtal / 1 */
116 clrbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, CLKCTRL_GPMI_CLKGATE);
117 while (readl(&clkctrl_regs->hw_clkctrl_gpmi) & CLKCTRL_GPMI_CLKGATE)
119 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
120 CLKCTRL_GPMI_DIV_MASK, 1);
125 * Configure GPIO unit
129 #ifdef CONFIG_APBH_DMA
137 u32 get_cpu_rev(void)
139 struct mxs_digctl_regs *digctl_regs =
140 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
141 uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;
143 switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
144 case HW_DIGCTL_CHIPID_MX23:
151 return (MXC_CPU_MX23 << 12) | (rev + 0x10);
155 case HW_DIGCTL_CHIPID_MX28:
158 return (MXC_CPU_MX28 << 12) | 0x12;
167 #if defined(CONFIG_DISPLAY_CPUINFO)
168 const char *get_imx_type(u32 imxtype)
180 int print_cpuinfo(void)
183 struct mxs_spl_data *data = MXS_SPL_DATA;
185 cpurev = get_cpu_rev();
186 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
187 get_imx_type((cpurev & 0xFF000) >> 12),
188 (cpurev & 0x000F0) >> 4,
189 (cpurev & 0x0000F) >> 0,
190 mxc_get_clock(MXC_ARM_CLK) / 1000000);
191 printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
196 int do_mx28_showclocks(struct cmd_tbl *cmdtp, int flag, int argc,
199 printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
200 printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
201 printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
202 printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
207 * Initializes on-chip ethernet controllers.
209 #if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
210 int cpu_eth_init(struct bd_info *bis)
212 struct mxs_clkctrl_regs *clkctrl_regs =
213 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
215 /* Turn on ENET clocks */
216 clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
217 CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
219 /* Set up ENET PLL for 50 MHz */
220 /* Power on ENET PLL */
221 writel(CLKCTRL_PLL2CTRL0_POWER,
222 &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
226 /* Gate on ENET PLL */
227 writel(CLKCTRL_PLL2CTRL0_CLKGATE,
228 &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
230 /* Enable pad output */
231 setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
237 __weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
240 mac[1] = 0x04; /* Use FSL vendor MAC address by default */
242 if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
246 #ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
248 #define MXS_OCOTP_MAX_TIMEOUT 1000000
249 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
251 struct mxs_ocotp_regs *ocotp_regs =
252 (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
257 writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
259 if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
260 MXS_OCOTP_MAX_TIMEOUT)) {
261 printf("MXS FEC: Can't get MAC from OCOTP\n");
265 data = readl(&ocotp_regs->hw_ocotp_cust0);
267 mac[2] = (data >> 24) & 0xff;
268 mac[3] = (data >> 16) & 0xff;
269 mac[4] = (data >> 8) & 0xff;
270 mac[5] = data & 0xff;
271 mx28_adjust_mac(dev_id, mac);
274 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
280 int mxs_dram_init(void)
282 struct mxs_spl_data *data = MXS_SPL_DATA;
284 if (data->mem_dram_size == 0) {
286 "Error, the RAM size passed up from SPL is 0!\n");
290 gd->ram_size = data->mem_dram_size;
295 clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,