blob: 249f8de8fbe14c37f30a7cec8b1b0e9ba7867e4a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut151f49d2011-12-02 03:47:40 +00002/*
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 Vasut151f49d2011-12-02 03:47:40 +00007 */
8
9#include <common.h>
10#include <config.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glass36736182019-11-14 12:57:24 -070013#include <serial.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000015#include <asm/io.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000016#include <asm/arch/imx-regs.h>
Marek Vasut9136fe92012-05-01 11:09:44 +000017#include <asm/arch/sys_proto.h>
Marek Vasutb28fe462012-05-01 11:09:45 +000018#include <asm/gpio.h>
Marek Behún90dcc4f2021-05-20 13:24:12 +020019#include <asm/sections.h>
Marek Vasutd1937632023-10-18 20:51:59 +020020#include <asm/system.h>
Marek Vasutd18f74a2014-03-19 02:21:35 +010021#include <linux/compiler.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000022
Otavio Salvadorf930ea62012-08-05 09:05:32 +000023#include "mxs_init.h"
Marek Vasut151f49d2011-12-02 03:47:40 +000024
Marek Vasutd18f74a2014-03-19 02:21:35 +010025DECLARE_GLOBAL_DATA_PTR;
Marek Vasutbb9f5e22014-03-19 02:21:36 +010026static gd_t gdata __section(".data");
Simon Glassf4d60392021-08-08 12:20:12 -060027#ifdef CONFIG_SPL_SERIAL
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090028static struct bd_info bdata __section(".data");
Stefano Babicc01f10b2014-04-02 10:42:06 +020029#endif
Marek Vasutd18f74a2014-03-19 02:21:35 +010030
Marek Vasut151f49d2011-12-02 03:47:40 +000031/*
32 * This delay function is intended to be used only in early stage of boot, where
Rasmus Villemoese4c63322019-09-10 08:32:01 +000033 * clock are not set up yet.
Marek Vasut151f49d2011-12-02 03:47:40 +000034 */
Marek Vasut151f49d2011-12-02 03:47:40 +000035void early_delay(int delay)
36{
Marek Vasut794cdb92012-08-28 15:15:53 +000037 struct mxs_digctl_regs *digctl_regs =
38 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
39
40 uint32_t st = readl(&digctl_regs->hw_digctl_microseconds);
Rasmus Villemoese4c63322019-09-10 08:32:01 +000041 while (readl(&digctl_regs->hw_digctl_microseconds) - st <= delay)
Marek Vasut151f49d2011-12-02 03:47:40 +000042 ;
43}
44
Marek Vasutaaf7d122016-12-15 16:48:55 +010045#if defined(CONFIG_MX23)
Marek Vasutb28fe462012-05-01 11:09:45 +000046#define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
Marek Vasute5cf7512012-11-30 07:09:23 +000047static const iomux_cfg_t iomux_boot[] = {
Otavio Salvador5304a262013-01-11 03:19:10 +000048 MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
49 MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
50 MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
51 MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
52 MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
53 MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
Marek Vasutb28fe462012-05-01 11:09:45 +000054};
Marek Vasutaaf7d122016-12-15 16:48:55 +010055#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000056
Marek Vasute5cf7512012-11-30 07:09:23 +000057static uint8_t mxs_get_bootmode_index(void)
Marek Vasutb28fe462012-05-01 11:09:45 +000058{
59 uint8_t bootmode = 0;
60 int i;
61 uint8_t masked;
62
Jörg Krause09b00572015-03-26 23:53:11 +010063#if defined(CONFIG_MX23)
Marek Vasutb28fe462012-05-01 11:09:45 +000064 /* Setup IOMUX of bootmode pads to GPIO */
65 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
66
Otavio Salvador5304a262013-01-11 03:19:10 +000067 /* Setup bootmode pins as GPIO input */
68 gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
69 gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
70 gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
71 gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
72 gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
73
74 /* Read bootmode pads */
75 bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
76 bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
77 bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
78 bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
79 bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
80#elif defined(CONFIG_MX28)
Jörg Krause09b00572015-03-26 23:53:11 +010081 /* The global boot mode will be detected by ROM code and its value
82 * is stored at the fixed address 0x00019BF0 in OCRAM.
83 */
84#define GLOBAL_BOOT_MODE_ADDR 0x00019BF0
85 bootmode = __raw_readl(GLOBAL_BOOT_MODE_ADDR);
Otavio Salvador5304a262013-01-11 03:19:10 +000086#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000087
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +000088 for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
89 masked = bootmode & mxs_boot_modes[i].boot_mask;
90 if (masked == mxs_boot_modes[i].boot_pads)
Marek Vasutb28fe462012-05-01 11:09:45 +000091 break;
92 }
93
94 return i;
95}
96
Marek Vasutd1937632023-10-18 20:51:59 +020097static noinline
98__attribute__((target("arm")))
99void mxs_spl_fixup_vectors(void)
Marek Vasut913784a2014-03-05 20:01:13 +0100100{
101 /*
102 * Copy our vector table to 0x0, since due to HAB, we cannot
103 * be loaded to 0x0. We want to have working vectoring though,
104 * thus this fixup. Our vectoring table is PIC, so copying is
105 * fine.
106 */
Wolfgang Denk6ae80832014-11-06 14:02:57 +0100107
108 /* cppcheck-suppress nullPointer */
Shiji Yangeff11fa2023-08-03 09:47:17 +0800109 memcpy(0x0, _start, 0x60);
Marek Vasutd1937632023-10-18 20:51:59 +0200110
111 /* Make sure ARM core points to low vectors */
112 set_cr(get_cr() & ~CR_V);
Marek Vasut913784a2014-03-05 20:01:13 +0100113}
114
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100115static void mxs_spl_console_init(void)
116{
Simon Glassf4d60392021-08-08 12:20:12 -0600117#ifdef CONFIG_SPL_SERIAL
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100118 gd->bd = &bdata;
119 gd->baudrate = CONFIG_BAUDRATE;
120 serial_init();
121 gd->have_console = 1;
122#endif
123}
124
Marek Vasut0dc62ba2013-08-31 15:53:44 +0200125void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr,
126 const iomux_cfg_t *iomux_setup,
127 const unsigned int iomux_size)
Marek Vasut151f49d2011-12-02 03:47:40 +0000128{
Mans Rullgard2f66b402018-04-21 16:11:09 +0100129 struct mxs_spl_data *data = MXS_SPL_DATA;
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000130 uint8_t bootmode = mxs_get_bootmode_index();
Marek Behúna8cf1552021-05-20 13:24:10 +0200131 set_gd(&gdata);
Marek Vasut9136fe92012-05-01 11:09:44 +0000132
Marek Vasut913784a2014-03-05 20:01:13 +0100133 mxs_spl_fixup_vectors();
134
Marek Vasut151f49d2011-12-02 03:47:40 +0000135 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
Marek Vasut913784a2014-03-05 20:01:13 +0100136
Lukasz Majewski790aa812023-05-19 12:43:54 +0200137 if (!CONFIG_IS_ENABLED(DM_SERIAL)) {
138 mxs_spl_console_init();
139 debug("SPL: Serial Console Initialised\n");
140 }
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100141
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000142 mxs_power_init();
Marek Vasut9136fe92012-05-01 11:09:44 +0000143
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000144 mxs_mem_init();
145 data->mem_dram_size = mxs_mem_get_size();
Marek Vasut9136fe92012-05-01 11:09:44 +0000146
Marek Vasutb28fe462012-05-01 11:09:45 +0000147 data->boot_mode_idx = bootmode;
148
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000149 mxs_power_wait_pswitch();
Graeme Russ9bf144c2015-01-25 12:07:53 +1100150
151 if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) {
152 debug("SPL: Waiting for JTAG user\n");
153 asm volatile ("x: b x");
154 }
Marek Vasut151f49d2011-12-02 03:47:40 +0000155}
156
Mans Rullgard65d21902018-04-21 16:11:10 +0100157#ifndef CONFIG_SPL_FRAMEWORK
Marek Vasut151f49d2011-12-02 03:47:40 +0000158/* Support aparatus */
159inline void board_init_f(unsigned long bootflag)
160{
161 for (;;)
162 ;
163}
164
165inline void board_init_r(gd_t *id, ulong dest_addr)
166{
167 for (;;)
168 ;
169}
Mans Rullgard65d21902018-04-21 16:11:10 +0100170#endif