1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Freescale i.MX28 Boot setup
4 *
5 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
6 * on behalf of DENX Software Engineering GmbH
7 */
8
9 #include <common.h>
10 #include <config.h>
11 #include <init.h>
12 #include <log.h>
13 #include <serial.h>
14 #include <asm/global_data.h>
15 #include <asm/io.h>
16 #include <asm/arch/imx-regs.h>
17 #include <asm/arch/sys_proto.h>
18 #include <asm/gpio.h>
19 #include <asm/sections.h>
20 #include <linux/compiler.h>
21
22 #include "mxs_init.h"
23
24 DECLARE_GLOBAL_DATA_PTR;
25 static gd_t gdata __section(".data");
26 #ifdef CONFIG_SPL_SERIAL_SUPPORT
27 static struct bd_info bdata __section(".data");
28 #endif
29
30 /*
31 * This delay function is intended to be used only in early stage of boot, where
32 * clock are not set up yet.
33 */
early_delay(int delay)34 void early_delay(int delay)
35 {
36 struct mxs_digctl_regs *digctl_regs =
37 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
38
39 uint32_t st = readl(&digctl_regs->hw_digctl_microseconds);
40 while (readl(&digctl_regs->hw_digctl_microseconds) - st <= delay)
41 ;
42 }
43
44 #if defined(CONFIG_MX23)
45 #define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
46 static const iomux_cfg_t iomux_boot[] = {
47 MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
48 MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
49 MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
50 MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
51 MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
52 MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
53 };
54 #endif
55
mxs_get_bootmode_index(void)56 static uint8_t mxs_get_bootmode_index(void)
57 {
58 uint8_t bootmode = 0;
59 int i;
60 uint8_t masked;
61
62 #if defined(CONFIG_MX23)
63 /* Setup IOMUX of bootmode pads to GPIO */
64 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
65
66 /* Setup bootmode pins as GPIO input */
67 gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
68 gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
69 gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
70 gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
71 gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
72
73 /* Read bootmode pads */
74 bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
75 bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
76 bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
77 bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
78 bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
79 #elif defined(CONFIG_MX28)
80 /* The global boot mode will be detected by ROM code and its value
81 * is stored at the fixed address 0x00019BF0 in OCRAM.
82 */
83 #define GLOBAL_BOOT_MODE_ADDR 0x00019BF0
84 bootmode = __raw_readl(GLOBAL_BOOT_MODE_ADDR);
85 #endif
86
87 for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
88 masked = bootmode & mxs_boot_modes[i].boot_mask;
89 if (masked == mxs_boot_modes[i].boot_pads)
90 break;
91 }
92
93 return i;
94 }
95
mxs_spl_fixup_vectors(void)96 static void mxs_spl_fixup_vectors(void)
97 {
98 /*
99 * Copy our vector table to 0x0, since due to HAB, we cannot
100 * be loaded to 0x0. We want to have working vectoring though,
101 * thus this fixup. Our vectoring table is PIC, so copying is
102 * fine.
103 */
104
105 /* cppcheck-suppress nullPointer */
106 memcpy(0x0, &_start, 0x60);
107 }
108
mxs_spl_console_init(void)109 static void mxs_spl_console_init(void)
110 {
111 #ifdef CONFIG_SPL_SERIAL_SUPPORT
112 gd->bd = &bdata;
113 gd->baudrate = CONFIG_BAUDRATE;
114 serial_init();
115 gd->have_console = 1;
116 #endif
117 }
118
mxs_common_spl_init(const uint32_t arg,const uint32_t * resptr,const iomux_cfg_t * iomux_setup,const unsigned int iomux_size)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)
122 {
123 struct mxs_spl_data *data = MXS_SPL_DATA;
124 uint8_t bootmode = mxs_get_bootmode_index();
125 set_gd(&gdata);
126
127 mxs_spl_fixup_vectors();
128
129 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
130
131 mxs_spl_console_init();
132 debug("SPL: Serial Console Initialised\n");
133
134 mxs_power_init();
135
136 mxs_mem_init();
137 data->mem_dram_size = mxs_mem_get_size();
138
139 data->boot_mode_idx = bootmode;
140
141 mxs_power_wait_pswitch();
142
143 if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) {
144 debug("SPL: Waiting for JTAG user\n");
145 asm volatile ("x: b x");
146 }
147 }
148
149 #ifndef CONFIG_SPL_FRAMEWORK
150 /* Support aparatus */
board_init_f(unsigned long bootflag)151 inline void board_init_f(unsigned long bootflag)
152 {
153 for (;;)
154 ;
155 }
156
board_init_r(gd_t * id,ulong dest_addr)157 inline void board_init_r(gd_t *id, ulong dest_addr)
158 {
159 for (;;)
160 ;
161 }
162 #endif
163