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.
18 #include <linux/errno.h>
20 #include <asm/arch/clock.h>
21 #include <asm/mach-imx/dma.h>
22 #include <asm/arch/gpio.h>
23 #include <asm/arch/iomux.h>
24 #include <asm/arch/imx-regs.h>
25 #include <asm/arch/sys_proto.h>
26 #include <linux/compiler.h>
28 DECLARE_GLOBAL_DATA_PTR;
30 /* Lowlevel init isn't used on i.MX28, so just have a dummy here */
31 __weak void lowlevel_init(void) {}
33 void reset_cpu(ulong ignored) __attribute__((noreturn));
35 void reset_cpu(ulong ignored)
37 struct mxs_rtc_regs *rtc_regs =
38 (struct mxs_rtc_regs *)MXS_RTC_BASE;
39 struct mxs_lcdif_regs *lcdif_regs =
40 (struct mxs_lcdif_regs *)MXS_LCDIF_BASE;
43 * Shut down the LCD controller as it interferes with BootROM boot mode
46 writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr);
48 /* Wait 1 uS before doing the actual watchdog reset */
49 writel(1, &rtc_regs->hw_rtc_watchdog);
50 writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
52 /* Endless loop, reset will exit from here */
58 * This function will craft a jumptable at 0x0 which will redirect interrupt
59 * vectoring to proper location of U-Boot in RAM.
61 * The structure of the jumptable will be as follows:
62 * ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times
63 * <destination address> ... for each previous ldr, thus also repeated 8 times
65 * The "ldr pc, [pc, #0x18]" instruction above loads address from memory at
66 * offset 0x18 from current value of PC register. Note that PC is already
67 * incremented by 4 when computing the offset, so the effective offset is
68 * actually 0x20, this the associated <destination address>. Loading the PC
69 * register with an address performs a jump to that address.
71 void mx28_fixup_vt(uint32_t start_addr)
73 /* ldr pc, [pc, #0x18] */
74 const uint32_t ldr_pc = 0xe59ff018;
75 /* Jumptable location is 0x0 */
76 uint32_t *vt = (uint32_t *)0x0;
79 for (i = 0; i < 8; i++) {
80 /* cppcheck-suppress nullPointer */
82 /* cppcheck-suppress nullPointer */
83 vt[i + 8] = start_addr + (4 * i);
87 #ifdef CONFIG_ARCH_MISC_INIT
88 int arch_misc_init(void)
90 mx28_fixup_vt(gd->relocaddr);
95 int arch_cpu_init(void)
97 struct mxs_clkctrl_regs *clkctrl_regs =
98 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
99 extern uint32_t _start;
101 mx28_fixup_vt((uint32_t)&_start);
107 writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
108 &clkctrl_regs->hw_clkctrl_clkseq_set);
110 /* Set GPMI clock to ref_xtal / 1 */
111 clrbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, CLKCTRL_GPMI_CLKGATE);
112 while (readl(&clkctrl_regs->hw_clkctrl_gpmi) & CLKCTRL_GPMI_CLKGATE)
114 clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
115 CLKCTRL_GPMI_DIV_MASK, 1);
120 * Configure GPIO unit
124 #ifdef CONFIG_APBH_DMA
132 u32 get_cpu_rev(void)
134 struct mxs_digctl_regs *digctl_regs =
135 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
136 uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF;
138 switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) {
139 case HW_DIGCTL_CHIPID_MX23:
146 return (MXC_CPU_MX23 << 12) | (rev + 0x10);
150 case HW_DIGCTL_CHIPID_MX28:
153 return (MXC_CPU_MX28 << 12) | 0x12;
162 #if defined(CONFIG_DISPLAY_CPUINFO)
163 const char *get_imx_type(u32 imxtype)
175 int print_cpuinfo(void)
178 struct mxs_spl_data *data = MXS_SPL_DATA;
180 cpurev = get_cpu_rev();
181 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
182 get_imx_type((cpurev & 0xFF000) >> 12),
183 (cpurev & 0x000F0) >> 4,
184 (cpurev & 0x0000F) >> 0,
185 mxc_get_clock(MXC_ARM_CLK) / 1000000);
186 printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode);
191 int do_mx28_showclocks(struct cmd_tbl *cmdtp, int flag, int argc,
194 printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
195 printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
196 printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
197 printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
202 * Initializes on-chip ethernet controllers.
204 #if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET)
205 int cpu_eth_init(bd_t *bis)
207 struct mxs_clkctrl_regs *clkctrl_regs =
208 (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
210 /* Turn on ENET clocks */
211 clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
212 CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
214 /* Set up ENET PLL for 50 MHz */
215 /* Power on ENET PLL */
216 writel(CLKCTRL_PLL2CTRL0_POWER,
217 &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
221 /* Gate on ENET PLL */
222 writel(CLKCTRL_PLL2CTRL0_CLKGATE,
223 &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
225 /* Enable pad output */
226 setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
232 __weak void mx28_adjust_mac(int dev_id, unsigned char *mac)
235 mac[1] = 0x04; /* Use FSL vendor MAC address by default */
237 if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
241 #ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP
243 #define MXS_OCOTP_MAX_TIMEOUT 1000000
244 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
246 struct mxs_ocotp_regs *ocotp_regs =
247 (struct mxs_ocotp_regs *)MXS_OCOTP_BASE;
252 writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
254 if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
255 MXS_OCOTP_MAX_TIMEOUT)) {
256 printf("MXS FEC: Can't get MAC from OCOTP\n");
260 data = readl(&ocotp_regs->hw_ocotp_cust0);
262 mac[2] = (data >> 24) & 0xff;
263 mac[3] = (data >> 16) & 0xff;
264 mac[4] = (data >> 8) & 0xff;
265 mac[5] = data & 0xff;
266 mx28_adjust_mac(dev_id, mac);
269 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
275 int mxs_dram_init(void)
277 struct mxs_spl_data *data = MXS_SPL_DATA;
279 if (data->mem_dram_size == 0) {
281 "Error, the RAM size passed up from SPL is 0!\n");
285 gd->ram_size = data->mem_dram_size;
290 clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,