2 * Freescale i.MX28 Boot setup
4 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5 * on behalf of DENX Software Engineering GmbH
7 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/arch/imx-regs.h>
14 #include <asm/arch/sys_proto.h>
16 #include <linux/compiler.h>
20 DECLARE_GLOBAL_DATA_PTR;
21 static gd_t gdata __section(".data");
22 #ifdef CONFIG_SPL_SERIAL_SUPPORT
23 static bd_t bdata __section(".data");
27 * This delay function is intended to be used only in early stage of boot, where
28 * clock are not set up yet. The timer used here is reset on every boot and
29 * takes a few seconds to roll. The boot doesn't take that long, so to keep the
30 * code simple, it doesn't take rolling into consideration.
32 void early_delay(int delay)
34 struct mxs_digctl_regs *digctl_regs =
35 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
37 uint32_t st = readl(&digctl_regs->hw_digctl_microseconds);
39 while (st > readl(&digctl_regs->hw_digctl_microseconds))
43 #if defined(CONFIG_MX23)
44 #define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
45 static const iomux_cfg_t iomux_boot[] = {
46 MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
47 MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
48 MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
49 MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
50 MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
51 MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
55 static uint8_t mxs_get_bootmode_index(void)
61 #if defined(CONFIG_MX23)
62 /* Setup IOMUX of bootmode pads to GPIO */
63 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
65 /* Setup bootmode pins as GPIO input */
66 gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
67 gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
68 gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
69 gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
70 gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
72 /* Read bootmode pads */
73 bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
74 bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
75 bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
76 bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
77 bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
78 #elif defined(CONFIG_MX28)
79 /* The global boot mode will be detected by ROM code and its value
80 * is stored at the fixed address 0x00019BF0 in OCRAM.
82 #define GLOBAL_BOOT_MODE_ADDR 0x00019BF0
83 bootmode = __raw_readl(GLOBAL_BOOT_MODE_ADDR);
86 for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
87 masked = bootmode & mxs_boot_modes[i].boot_mask;
88 if (masked == mxs_boot_modes[i].boot_pads)
95 static void mxs_spl_fixup_vectors(void)
98 * Copy our vector table to 0x0, since due to HAB, we cannot
99 * be loaded to 0x0. We want to have working vectoring though,
100 * thus this fixup. Our vectoring table is PIC, so copying is
103 extern uint32_t _start;
105 /* cppcheck-suppress nullPointer */
106 memcpy(0x0, &_start, 0x60);
109 static void mxs_spl_console_init(void)
111 #ifdef CONFIG_SPL_SERIAL_SUPPORT
113 gd->baudrate = CONFIG_BAUDRATE;
115 gd->have_console = 1;
119 void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr,
120 const iomux_cfg_t *iomux_setup,
121 const unsigned int iomux_size)
123 struct mxs_spl_data *data = (struct mxs_spl_data *)
124 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
125 uint8_t bootmode = mxs_get_bootmode_index();
128 mxs_spl_fixup_vectors();
130 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
132 mxs_spl_console_init();
133 debug("SPL: Serial Console Initialised\n");
138 data->mem_dram_size = mxs_mem_get_size();
140 data->boot_mode_idx = bootmode;
142 mxs_power_wait_pswitch();
144 if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) {
145 debug("SPL: Waiting for JTAG user\n");
146 asm volatile ("x: b x");
150 /* Support aparatus */
151 inline void board_init_f(unsigned long bootflag)
157 inline void board_init_r(gd_t *id, ulong dest_addr)