]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/arm926ejs/mxs/spl_boot.c
karo: merge with Ka-Ro specific tree for secure boot support
[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 /*
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.
31  */
32 /*
33  * There's nothing to be taken into consideration for the rollover.
34  * Two's complement arithmetic used correctly does all that's needed
35  * automagically.
36  */
37 void early_delay(int delay)
38 {
39         struct mxs_digctl_regs *digctl_regs =
40                 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
41         u32 start = readl(&digctl_regs->hw_digctl_microseconds);
42
43         while (readl(&digctl_regs->hw_digctl_microseconds) - start < delay);
44 }
45
46 #define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
47 static const iomux_cfg_t iomux_boot[] = {
48 #if defined(CONFIG_MX23)
49         MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
50         MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
51         MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
52         MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
53         MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
54         MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
55 #elif defined(CONFIG_MX28)
56         MX28_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
57         MX28_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
58         MX28_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
59         MX28_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
60         MX28_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
61         MX28_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
62 #endif
63 };
64
65 static uint8_t mxs_get_bootmode_index(void)
66 {
67         uint8_t bootmode = 0;
68         int i;
69         uint8_t masked;
70
71         /* Setup IOMUX of bootmode pads to GPIO */
72         mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
73
74 #if defined(CONFIG_MX23)
75         /* Setup bootmode pins as GPIO input */
76         gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
77         gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
78         gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
79         gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
80         gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
81
82         /* Read bootmode pads */
83         bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
84         bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
85         bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
86         bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
87         bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
88 #elif defined(CONFIG_MX28)
89         /* Setup bootmode pins as GPIO input */
90         gpio_direction_input(MX28_PAD_LCD_D00__GPIO_1_0);
91         gpio_direction_input(MX28_PAD_LCD_D01__GPIO_1_1);
92         gpio_direction_input(MX28_PAD_LCD_D02__GPIO_1_2);
93         gpio_direction_input(MX28_PAD_LCD_D03__GPIO_1_3);
94         gpio_direction_input(MX28_PAD_LCD_D04__GPIO_1_4);
95         gpio_direction_input(MX28_PAD_LCD_D05__GPIO_1_5);
96
97         /* Read bootmode pads */
98         bootmode |= (gpio_get_value(MX28_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
99         bootmode |= (gpio_get_value(MX28_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
100         bootmode |= (gpio_get_value(MX28_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
101         bootmode |= (gpio_get_value(MX28_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
102         bootmode |= (gpio_get_value(MX28_PAD_LCD_D04__GPIO_1_4) ? 1 : 0) << 4;
103         bootmode |= (gpio_get_value(MX28_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
104 #endif
105
106         for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
107                 masked = bootmode & mxs_boot_modes[i].boot_mask;
108                 if (masked == mxs_boot_modes[i].boot_pads)
109                         break;
110         }
111
112         return i;
113 }
114
115 static void mxs_spl_fixup_vectors(void)
116 {
117         /*
118          * Copy our vector table to 0x0, since due to HAB, we cannot
119          * be loaded to 0x0. We want to have working vectoring though,
120          * thus this fixup. Our vectoring table is PIC, so copying is
121          * fine.
122          */
123         extern uint32_t _start;
124
125         /* cppcheck-suppress nullPointer */
126         memcpy(0x0, &_start, 0x60);
127 }
128
129 static void mxs_spl_console_init(void)
130 {
131 #ifdef CONFIG_SPL_SERIAL_SUPPORT
132         gd->bd = &bdata;
133         gd->baudrate = CONFIG_BAUDRATE;
134         serial_init();
135         gd->have_console = 1;
136 #endif
137 }
138
139 void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr,
140                          const iomux_cfg_t *iomux_setup,
141                          const unsigned int iomux_size)
142 {
143         struct mxs_spl_data *data = (struct mxs_spl_data *)
144                 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
145         uint8_t bootmode = mxs_get_bootmode_index();
146         gd = &gdata;
147
148         mxs_spl_fixup_vectors();
149
150         mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
151
152         mxs_spl_console_init();
153
154         mxs_power_init();
155
156         mxs_mem_init();
157         data->mem_dram_size = mxs_mem_get_size();
158
159         data->boot_mode_idx = bootmode;
160
161         mxs_power_wait_pswitch();
162 }
163
164 /* Support apparatus */
165 inline void board_init_f(unsigned long bootflag)
166 {
167         for (;;)
168                 ;
169 }
170
171 inline void board_init_r(gd_t *id, ulong dest_addr)
172 {
173         for (;;)
174                 ;
175 }