Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <config.h> |
| 12 | #include <asm/io.h> |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 13 | #include <asm/arch/imx-regs.h> |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 14 | #include <asm/arch/sys_proto.h> |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 15 | #include <asm/gpio.h> |
Marek Vasut | d18f74a | 2014-03-19 02:21:35 +0100 | [diff] [blame] | 16 | #include <linux/compiler.h> |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 17 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 18 | #include "mxs_init.h" |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 19 | |
Marek Vasut | d18f74a | 2014-03-19 02:21:35 +0100 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
Marek Vasut | bb9f5e2 | 2014-03-19 02:21:36 +0100 | [diff] [blame] | 21 | static gd_t gdata __section(".data"); |
Stefano Babic | c01f10b | 2014-04-02 10:42:06 +0200 | [diff] [blame] | 22 | #ifdef CONFIG_SPL_SERIAL_SUPPORT |
Marek Vasut | bb9f5e2 | 2014-03-19 02:21:36 +0100 | [diff] [blame] | 23 | static bd_t bdata __section(".data"); |
Stefano Babic | c01f10b | 2014-04-02 10:42:06 +0200 | [diff] [blame] | 24 | #endif |
Marek Vasut | d18f74a | 2014-03-19 02:21:35 +0100 | [diff] [blame] | 25 | |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 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 | */ |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 32 | void early_delay(int delay) |
| 33 | { |
Marek Vasut | 794cdb9 | 2012-08-28 15:15:53 +0000 | [diff] [blame] | 34 | struct mxs_digctl_regs *digctl_regs = |
| 35 | (struct mxs_digctl_regs *)MXS_DIGCTL_BASE; |
| 36 | |
| 37 | uint32_t st = readl(&digctl_regs->hw_digctl_microseconds); |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 38 | st += delay; |
Marek Vasut | 794cdb9 | 2012-08-28 15:15:53 +0000 | [diff] [blame] | 39 | while (st > readl(&digctl_regs->hw_digctl_microseconds)) |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 40 | ; |
| 41 | } |
| 42 | |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 43 | #define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL) |
Marek Vasut | e5cf751 | 2012-11-30 07:09:23 +0000 | [diff] [blame] | 44 | static const iomux_cfg_t iomux_boot[] = { |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 45 | #if defined(CONFIG_MX23) |
| 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, |
| 52 | #elif defined(CONFIG_MX28) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 53 | MX28_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD, |
| 54 | MX28_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD, |
| 55 | MX28_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD, |
| 56 | MX28_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD, |
| 57 | MX28_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD, |
| 58 | MX28_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD, |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 59 | #endif |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
Marek Vasut | e5cf751 | 2012-11-30 07:09:23 +0000 | [diff] [blame] | 62 | static uint8_t mxs_get_bootmode_index(void) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 63 | { |
| 64 | uint8_t bootmode = 0; |
| 65 | int i; |
| 66 | uint8_t masked; |
| 67 | |
| 68 | /* Setup IOMUX of bootmode pads to GPIO */ |
| 69 | mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot)); |
| 70 | |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 71 | #if defined(CONFIG_MX23) |
| 72 | /* Setup bootmode pins as GPIO input */ |
| 73 | gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0); |
| 74 | gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1); |
| 75 | gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2); |
| 76 | gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3); |
| 77 | gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5); |
| 78 | |
| 79 | /* Read bootmode pads */ |
| 80 | bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0; |
| 81 | bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1; |
| 82 | bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2; |
| 83 | bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3; |
| 84 | bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5; |
| 85 | #elif defined(CONFIG_MX28) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 86 | /* Setup bootmode pins as GPIO input */ |
| 87 | gpio_direction_input(MX28_PAD_LCD_D00__GPIO_1_0); |
| 88 | gpio_direction_input(MX28_PAD_LCD_D01__GPIO_1_1); |
| 89 | gpio_direction_input(MX28_PAD_LCD_D02__GPIO_1_2); |
| 90 | gpio_direction_input(MX28_PAD_LCD_D03__GPIO_1_3); |
| 91 | gpio_direction_input(MX28_PAD_LCD_D04__GPIO_1_4); |
| 92 | gpio_direction_input(MX28_PAD_LCD_D05__GPIO_1_5); |
| 93 | |
| 94 | /* Read bootmode pads */ |
| 95 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0; |
| 96 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1; |
| 97 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2; |
| 98 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3; |
| 99 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D04__GPIO_1_4) ? 1 : 0) << 4; |
| 100 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5; |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 101 | #endif |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 102 | |
Otavio Salvador | cbf0bf2 | 2012-08-13 09:53:12 +0000 | [diff] [blame] | 103 | for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) { |
| 104 | masked = bootmode & mxs_boot_modes[i].boot_mask; |
| 105 | if (masked == mxs_boot_modes[i].boot_pads) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 106 | break; |
| 107 | } |
| 108 | |
| 109 | return i; |
| 110 | } |
| 111 | |
Marek Vasut | 913784a | 2014-03-05 20:01:13 +0100 | [diff] [blame] | 112 | static void mxs_spl_fixup_vectors(void) |
| 113 | { |
| 114 | /* |
| 115 | * Copy our vector table to 0x0, since due to HAB, we cannot |
| 116 | * be loaded to 0x0. We want to have working vectoring though, |
| 117 | * thus this fixup. Our vectoring table is PIC, so copying is |
| 118 | * fine. |
| 119 | */ |
| 120 | extern uint32_t _start; |
Wolfgang Denk | 6ae8083 | 2014-11-06 14:02:57 +0100 | [diff] [blame] | 121 | |
| 122 | /* cppcheck-suppress nullPointer */ |
Marek Vasut | 913784a | 2014-03-05 20:01:13 +0100 | [diff] [blame] | 123 | memcpy(0x0, &_start, 0x60); |
| 124 | } |
| 125 | |
Marek Vasut | bb9f5e2 | 2014-03-19 02:21:36 +0100 | [diff] [blame] | 126 | static void mxs_spl_console_init(void) |
| 127 | { |
| 128 | #ifdef CONFIG_SPL_SERIAL_SUPPORT |
| 129 | gd->bd = &bdata; |
| 130 | gd->baudrate = CONFIG_BAUDRATE; |
| 131 | serial_init(); |
| 132 | gd->have_console = 1; |
| 133 | #endif |
| 134 | } |
| 135 | |
Marek Vasut | 0dc62ba | 2013-08-31 15:53:44 +0200 | [diff] [blame] | 136 | void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr, |
| 137 | const iomux_cfg_t *iomux_setup, |
| 138 | const unsigned int iomux_size) |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 139 | { |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 140 | struct mxs_spl_data *data = (struct mxs_spl_data *) |
| 141 | ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf); |
| 142 | uint8_t bootmode = mxs_get_bootmode_index(); |
Marek Vasut | d18f74a | 2014-03-19 02:21:35 +0100 | [diff] [blame] | 143 | gd = &gdata; |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 144 | |
Marek Vasut | 913784a | 2014-03-05 20:01:13 +0100 | [diff] [blame] | 145 | mxs_spl_fixup_vectors(); |
| 146 | |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 147 | mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size); |
Marek Vasut | 913784a | 2014-03-05 20:01:13 +0100 | [diff] [blame] | 148 | |
Marek Vasut | bb9f5e2 | 2014-03-19 02:21:36 +0100 | [diff] [blame] | 149 | mxs_spl_console_init(); |
Graeme Russ | 0f2483a | 2015-01-25 12:07:51 +1100 | [diff] [blame] | 150 | debug("SPL: Serial Console Initialised\n"); |
Marek Vasut | bb9f5e2 | 2014-03-19 02:21:36 +0100 | [diff] [blame] | 151 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 152 | mxs_power_init(); |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 153 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 154 | mxs_mem_init(); |
| 155 | data->mem_dram_size = mxs_mem_get_size(); |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 156 | |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 157 | data->boot_mode_idx = bootmode; |
| 158 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 159 | mxs_power_wait_pswitch(); |
Graeme Russ | 9bf144c | 2015-01-25 12:07:53 +1100 | [diff] [blame] | 160 | |
| 161 | if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) { |
| 162 | debug("SPL: Waiting for JTAG user\n"); |
| 163 | asm volatile ("x: b x"); |
| 164 | } |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /* Support aparatus */ |
| 168 | inline void board_init_f(unsigned long bootflag) |
| 169 | { |
| 170 | for (;;) |
| 171 | ; |
| 172 | } |
| 173 | |
| 174 | inline void board_init_r(gd_t *id, ulong dest_addr) |
| 175 | { |
| 176 | for (;;) |
| 177 | ; |
| 178 | } |