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>
20 * This delay function is intended to be used only in early stage of boot, where
21 * clock are not set up yet. The timer used here is reset on every boot and
22 * takes a few seconds to roll. The boot doesn't take that long, so to keep the
23 * code simple, it doesn't take rolling into consideration.
26 * There's nothing to be taken into consideration for the rollover.
27 * Two's complement arithmetic used correctly does all that's needed
30 void early_delay(int delay)
32 struct mxs_digctl_regs *digctl_regs =
33 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
34 u32 start = readl(&digctl_regs->hw_digctl_microseconds);
36 while (readl(&digctl_regs->hw_digctl_microseconds) - start < delay);
39 #define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
40 static const iomux_cfg_t iomux_boot[] = {
41 #if defined(CONFIG_MX23)
42 MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
43 MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
44 MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
45 MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
46 MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
47 MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
48 #elif defined(CONFIG_MX28)
49 MX28_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
50 MX28_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
51 MX28_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
52 MX28_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
53 MX28_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
54 MX28_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
58 static uint8_t mxs_get_bootmode_index(void)
64 /* Setup IOMUX of bootmode pads to GPIO */
65 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
67 #if defined(CONFIG_MX23)
68 /* Setup bootmode pins as GPIO input */
69 gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
70 gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
71 gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
72 gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
73 gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
75 /* Read bootmode pads */
76 bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
77 bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
78 bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
79 bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
80 bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
81 #elif defined(CONFIG_MX28)
82 /* Setup bootmode pins as GPIO input */
83 gpio_direction_input(MX28_PAD_LCD_D00__GPIO_1_0);
84 gpio_direction_input(MX28_PAD_LCD_D01__GPIO_1_1);
85 gpio_direction_input(MX28_PAD_LCD_D02__GPIO_1_2);
86 gpio_direction_input(MX28_PAD_LCD_D03__GPIO_1_3);
87 gpio_direction_input(MX28_PAD_LCD_D04__GPIO_1_4);
88 gpio_direction_input(MX28_PAD_LCD_D05__GPIO_1_5);
90 /* Read bootmode pads */
91 bootmode |= (gpio_get_value(MX28_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
92 bootmode |= (gpio_get_value(MX28_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
93 bootmode |= (gpio_get_value(MX28_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
94 bootmode |= (gpio_get_value(MX28_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
95 bootmode |= (gpio_get_value(MX28_PAD_LCD_D04__GPIO_1_4) ? 1 : 0) << 4;
96 bootmode |= (gpio_get_value(MX28_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
99 for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
100 masked = bootmode & mxs_boot_modes[i].boot_mask;
101 if (masked == mxs_boot_modes[i].boot_pads)
108 void mxs_common_spl_init(const iomux_cfg_t *iomux_setup,
109 const unsigned int iomux_size)
111 struct mxs_spl_data *data = (struct mxs_spl_data *)
112 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
113 uint8_t bootmode = mxs_get_bootmode_index();
115 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
119 data->mem_dram_size = mxs_mem_get_size();
121 data->boot_mode_idx = bootmode;
123 mxs_power_wait_pswitch();
126 /* Support apparatus */
127 inline void board_init_f(unsigned long bootflag)
133 inline void board_init_r(gd_t *id, ulong dest_addr)