Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 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 |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 9 | #include <config.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 3673618 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 12 | #include <serial.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 14 | #include <asm/io.h> |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 15 | #include <asm/arch/imx-regs.h> |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 17 | #include <asm/gpio.h> |
Marek Behún | 90dcc4f | 2021-05-20 13:24:12 +0200 | [diff] [blame] | 18 | #include <asm/sections.h> |
Marek Vasut | d193763 | 2023-10-18 20:51:59 +0200 | [diff] [blame] | 19 | #include <asm/system.h> |
Marek Vasut | d18f74a | 2014-03-19 02:21:35 +0100 | [diff] [blame] | 20 | #include <linux/compiler.h> |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 21 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 22 | #include "mxs_init.h" |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 23 | |
Marek Vasut | d18f74a | 2014-03-19 02:21:35 +0100 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
Marek Vasut | bb9f5e2 | 2014-03-19 02:21:36 +0100 | [diff] [blame] | 25 | static gd_t gdata __section(".data"); |
Simon Glass | f4d6039 | 2021-08-08 12:20:12 -0600 | [diff] [blame] | 26 | #ifdef CONFIG_SPL_SERIAL |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 27 | static struct bd_info bdata __section(".data"); |
Stefano Babic | c01f10b | 2014-04-02 10:42:06 +0200 | [diff] [blame] | 28 | #endif |
Marek Vasut | d18f74a | 2014-03-19 02:21:35 +0100 | [diff] [blame] | 29 | |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 30 | /* |
| 31 | * This delay function is intended to be used only in early stage of boot, where |
Rasmus Villemoes | e4c6332 | 2019-09-10 08:32:01 +0000 | [diff] [blame] | 32 | * clock are not set up yet. |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 33 | */ |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 34 | void early_delay(int delay) |
| 35 | { |
Marek Vasut | 794cdb9 | 2012-08-28 15:15:53 +0000 | [diff] [blame] | 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); |
Rasmus Villemoes | e4c6332 | 2019-09-10 08:32:01 +0000 | [diff] [blame] | 40 | while (readl(&digctl_regs->hw_digctl_microseconds) - st <= delay) |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 41 | ; |
| 42 | } |
| 43 | |
Marek Vasut | aaf7d12 | 2016-12-15 16:48:55 +0100 | [diff] [blame] | 44 | #if defined(CONFIG_MX23) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 45 | #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] | 46 | static const iomux_cfg_t iomux_boot[] = { |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 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, |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 53 | }; |
Marek Vasut | aaf7d12 | 2016-12-15 16:48:55 +0100 | [diff] [blame] | 54 | #endif |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 55 | |
Marek Vasut | e5cf751 | 2012-11-30 07:09:23 +0000 | [diff] [blame] | 56 | static uint8_t mxs_get_bootmode_index(void) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 57 | { |
| 58 | uint8_t bootmode = 0; |
| 59 | int i; |
| 60 | uint8_t masked; |
| 61 | |
Jörg Krause | 09b0057 | 2015-03-26 23:53:11 +0100 | [diff] [blame] | 62 | #if defined(CONFIG_MX23) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 63 | /* Setup IOMUX of bootmode pads to GPIO */ |
| 64 | mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot)); |
| 65 | |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 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) |
Jörg Krause | 09b0057 | 2015-03-26 23:53:11 +0100 | [diff] [blame] | 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); |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 85 | #endif |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 86 | |
Otavio Salvador | cbf0bf2 | 2012-08-13 09:53:12 +0000 | [diff] [blame] | 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) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 90 | break; |
| 91 | } |
| 92 | |
| 93 | return i; |
| 94 | } |
| 95 | |
Marek Vasut | d193763 | 2023-10-18 20:51:59 +0200 | [diff] [blame] | 96 | static noinline |
| 97 | __attribute__((target("arm"))) |
| 98 | void mxs_spl_fixup_vectors(void) |
Marek Vasut | 913784a | 2014-03-05 20:01:13 +0100 | [diff] [blame] | 99 | { |
| 100 | /* |
| 101 | * Copy our vector table to 0x0, since due to HAB, we cannot |
| 102 | * be loaded to 0x0. We want to have working vectoring though, |
| 103 | * thus this fixup. Our vectoring table is PIC, so copying is |
| 104 | * fine. |
| 105 | */ |
Wolfgang Denk | 6ae8083 | 2014-11-06 14:02:57 +0100 | [diff] [blame] | 106 | |
| 107 | /* cppcheck-suppress nullPointer */ |
Shiji Yang | eff11fa | 2023-08-03 09:47:17 +0800 | [diff] [blame] | 108 | memcpy(0x0, _start, 0x60); |
Marek Vasut | d193763 | 2023-10-18 20:51:59 +0200 | [diff] [blame] | 109 | |
| 110 | /* Make sure ARM core points to low vectors */ |
| 111 | set_cr(get_cr() & ~CR_V); |
Marek Vasut | 913784a | 2014-03-05 20:01:13 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Marek Vasut | bb9f5e2 | 2014-03-19 02:21:36 +0100 | [diff] [blame] | 114 | static void mxs_spl_console_init(void) |
| 115 | { |
Simon Glass | f4d6039 | 2021-08-08 12:20:12 -0600 | [diff] [blame] | 116 | #ifdef CONFIG_SPL_SERIAL |
Marek Vasut | bb9f5e2 | 2014-03-19 02:21:36 +0100 | [diff] [blame] | 117 | gd->bd = &bdata; |
| 118 | gd->baudrate = CONFIG_BAUDRATE; |
| 119 | serial_init(); |
| 120 | gd->have_console = 1; |
| 121 | #endif |
| 122 | } |
| 123 | |
Marek Vasut | 0dc62ba | 2013-08-31 15:53:44 +0200 | [diff] [blame] | 124 | void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr, |
| 125 | const iomux_cfg_t *iomux_setup, |
| 126 | const unsigned int iomux_size) |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 127 | { |
Mans Rullgard | 2f66b40 | 2018-04-21 16:11:09 +0100 | [diff] [blame] | 128 | struct mxs_spl_data *data = MXS_SPL_DATA; |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 129 | uint8_t bootmode = mxs_get_bootmode_index(); |
Marek Behún | a8cf155 | 2021-05-20 13:24:10 +0200 | [diff] [blame] | 130 | set_gd(&gdata); |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 131 | |
Marek Vasut | 913784a | 2014-03-05 20:01:13 +0100 | [diff] [blame] | 132 | mxs_spl_fixup_vectors(); |
| 133 | |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 134 | mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size); |
Marek Vasut | 913784a | 2014-03-05 20:01:13 +0100 | [diff] [blame] | 135 | |
Lukasz Majewski | 790aa81 | 2023-05-19 12:43:54 +0200 | [diff] [blame] | 136 | if (!CONFIG_IS_ENABLED(DM_SERIAL)) { |
| 137 | mxs_spl_console_init(); |
| 138 | debug("SPL: Serial Console Initialised\n"); |
| 139 | } |
Marek Vasut | bb9f5e2 | 2014-03-19 02:21:36 +0100 | [diff] [blame] | 140 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 141 | mxs_power_init(); |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 142 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 143 | mxs_mem_init(); |
| 144 | data->mem_dram_size = mxs_mem_get_size(); |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 145 | |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 146 | data->boot_mode_idx = bootmode; |
| 147 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 148 | mxs_power_wait_pswitch(); |
Graeme Russ | 9bf144c | 2015-01-25 12:07:53 +1100 | [diff] [blame] | 149 | |
| 150 | if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) { |
| 151 | debug("SPL: Waiting for JTAG user\n"); |
| 152 | asm volatile ("x: b x"); |
| 153 | } |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Mans Rullgard | 65d2190 | 2018-04-21 16:11:10 +0100 | [diff] [blame] | 156 | #ifndef CONFIG_SPL_FRAMEWORK |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 157 | /* Support aparatus */ |
| 158 | inline void board_init_f(unsigned long bootflag) |
| 159 | { |
| 160 | for (;;) |
| 161 | ; |
| 162 | } |
| 163 | |
| 164 | inline void board_init_r(gd_t *id, ulong dest_addr) |
| 165 | { |
| 166 | for (;;) |
| 167 | ; |
| 168 | } |
Mans Rullgard | 65d2190 | 2018-04-21 16:11:10 +0100 | [diff] [blame] | 169 | #endif |