]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/arm926ejs/mxs/spl_boot.c
mxs: spl: replace bogus early_delay() function with standard udelay() calls
[karo-tx-uboot.git] / arch / arm / cpu / arm926ejs / mxs / spl_boot.c
1 /*
2  * Freescale i.MX28 Boot setup
3  *
4  * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5  * on behalf of DENX Software Engineering GmbH
6  *
7  * SPDX-License-Identifier:     GPL-2.0+
8  */
9
10 #include <common.h>
11 #include <config.h>
12 #include <asm/io.h>
13 #include <asm/arch/imx-regs.h>
14 #include <asm/arch/sys_proto.h>
15 #include <asm/gpio.h>
16 #include <linux/compiler.h>
17
18 #include "mxs_init.h"
19
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");
24 #endif
25
26 #define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
27 static const iomux_cfg_t iomux_boot[] = {
28 #if defined(CONFIG_SOC_MX23)
29         MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
30         MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
31         MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
32         MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
33         MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
34         MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
35 #endif
36 };
37
38 static uint8_t mxs_get_bootmode_index(void)
39 {
40         uint8_t bootmode = 0;
41         int i;
42         uint8_t masked;
43
44 #if defined(CONFIG_SOC_MX23)
45         /* Setup IOMUX of bootmode pads to GPIO */
46         mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
47
48         /* Setup bootmode pins as GPIO input */
49         gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
50         gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
51         gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
52         gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
53         gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
54
55         /* Read bootmode pads */
56         bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
57         bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
58         bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
59         bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
60         bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
61 #elif defined(CONFIG_SOC_MX28)
62         /* The global boot mode will be detected by ROM code and its value
63          * is stored at the fixed address 0x00019BF0 in OCRAM.
64          */
65 #define GLOBAL_BOOT_MODE_ADDR 0x00019BF0
66         bootmode = __raw_readl(GLOBAL_BOOT_MODE_ADDR);
67 #endif
68
69         for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
70                 masked = bootmode & mxs_boot_modes[i].boot_mask;
71                 if (masked == mxs_boot_modes[i].boot_pads)
72                         break;
73         }
74
75         return i;
76 }
77
78 static void mxs_spl_fixup_vectors(void)
79 {
80         /*
81          * Copy our vector table to 0x0, since due to HAB, we cannot
82          * be loaded to 0x0. We want to have working vectoring though,
83          * thus this fixup. Our vectoring table is PIC, so copying is
84          * fine.
85          */
86         extern uint32_t _start;
87
88         /* cppcheck-suppress nullPointer */
89         memcpy(0x0, &_start, 0x60);
90 }
91
92 static void mxs_spl_console_init(void)
93 {
94 #ifdef CONFIG_SPL_SERIAL_SUPPORT
95         gd->bd = &bdata;
96         gd->baudrate = CONFIG_BAUDRATE;
97         serial_init();
98         gd->have_console = 1;
99 #endif
100 }
101
102 void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr,
103                          const iomux_cfg_t *iomux_setup,
104                          const unsigned int iomux_size)
105 {
106         struct mxs_spl_data *data = (struct mxs_spl_data *)
107                 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
108         uint8_t bootmode = mxs_get_bootmode_index();
109         gd = &gdata;
110
111         mxs_spl_fixup_vectors();
112
113         mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
114
115         mxs_spl_console_init();
116         debug("SPL: Serial Console Initialised\n");
117
118         mxs_power_init();
119
120         mxs_mem_init();
121         data->mem_dram_size = mxs_mem_get_size();
122
123         data->boot_mode_idx = bootmode;
124
125         mxs_power_wait_pswitch();
126
127         if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) {
128                 debug("SPL: Waiting for JTAG user\n");
129                 asm volatile ("x: b x");
130         }
131 }
132
133 /* Support apparatus */
134 inline void board_init_f(unsigned long bootflag)
135 {
136         for (;;)
137                 ;
138 }
139
140 inline void board_init_r(gd_t *id, ulong dest_addr)
141 {
142         for (;;)
143                 ;
144 }