blob: 76a69d7f9586b3e29bd45cd1216b2d9b7e97b9b5 [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
Marek Vasut151f49d2011-12-02 03:47:40 +00009#include <config.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glass36736182019-11-14 12:57:24 -070012#include <serial.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000014#include <asm/io.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000015#include <asm/arch/imx-regs.h>
Marek Vasut9136fe92012-05-01 11:09:44 +000016#include <asm/arch/sys_proto.h>
Marek Vasutb28fe462012-05-01 11:09:45 +000017#include <asm/gpio.h>
Marek Behún90dcc4f2021-05-20 13:24:12 +020018#include <asm/sections.h>
Marek Vasutd1937632023-10-18 20:51:59 +020019#include <asm/system.h>
Marek Vasutd18f74a2014-03-19 02:21:35 +010020#include <linux/compiler.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000021
Otavio Salvadorf930ea62012-08-05 09:05:32 +000022#include "mxs_init.h"
Marek Vasut151f49d2011-12-02 03:47:40 +000023
Marek Vasutd18f74a2014-03-19 02:21:35 +010024DECLARE_GLOBAL_DATA_PTR;
Marek Vasutbb9f5e22014-03-19 02:21:36 +010025static gd_t gdata __section(".data");
Simon Glassf4d60392021-08-08 12:20:12 -060026#ifdef CONFIG_SPL_SERIAL
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090027static struct bd_info bdata __section(".data");
Stefano Babicc01f10b2014-04-02 10:42:06 +020028#endif
Marek Vasutd18f74a2014-03-19 02:21:35 +010029
Marek Vasut151f49d2011-12-02 03:47:40 +000030/*
31 * This delay function is intended to be used only in early stage of boot, where
Rasmus Villemoese4c63322019-09-10 08:32:01 +000032 * clock are not set up yet.
Marek Vasut151f49d2011-12-02 03:47:40 +000033 */
Marek Vasut151f49d2011-12-02 03:47:40 +000034void early_delay(int delay)
35{
Marek Vasut794cdb92012-08-28 15:15:53 +000036 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 Villemoese4c63322019-09-10 08:32:01 +000040 while (readl(&digctl_regs->hw_digctl_microseconds) - st <= delay)
Marek Vasut151f49d2011-12-02 03:47:40 +000041 ;
42}
43
Marek Vasutaaf7d122016-12-15 16:48:55 +010044#if defined(CONFIG_MX23)
Marek Vasutb28fe462012-05-01 11:09:45 +000045#define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
Marek Vasute5cf7512012-11-30 07:09:23 +000046static const iomux_cfg_t iomux_boot[] = {
Otavio Salvador5304a262013-01-11 03:19:10 +000047 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 Vasutb28fe462012-05-01 11:09:45 +000053};
Marek Vasutaaf7d122016-12-15 16:48:55 +010054#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000055
Marek Vasute5cf7512012-11-30 07:09:23 +000056static uint8_t mxs_get_bootmode_index(void)
Marek Vasutb28fe462012-05-01 11:09:45 +000057{
58 uint8_t bootmode = 0;
59 int i;
60 uint8_t masked;
61
Jörg Krause09b00572015-03-26 23:53:11 +010062#if defined(CONFIG_MX23)
Marek Vasutb28fe462012-05-01 11:09:45 +000063 /* Setup IOMUX of bootmode pads to GPIO */
64 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
65
Otavio Salvador5304a262013-01-11 03:19:10 +000066 /* 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 Krause09b00572015-03-26 23:53:11 +010080 /* 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 Salvador5304a262013-01-11 03:19:10 +000085#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000086
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +000087 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 Vasutb28fe462012-05-01 11:09:45 +000090 break;
91 }
92
93 return i;
94}
95
Marek Vasutd1937632023-10-18 20:51:59 +020096static noinline
97__attribute__((target("arm")))
98void mxs_spl_fixup_vectors(void)
Marek Vasut913784a2014-03-05 20:01:13 +010099{
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 Denk6ae80832014-11-06 14:02:57 +0100106
107 /* cppcheck-suppress nullPointer */
Shiji Yangeff11fa2023-08-03 09:47:17 +0800108 memcpy(0x0, _start, 0x60);
Marek Vasutd1937632023-10-18 20:51:59 +0200109
110 /* Make sure ARM core points to low vectors */
111 set_cr(get_cr() & ~CR_V);
Marek Vasut913784a2014-03-05 20:01:13 +0100112}
113
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100114static void mxs_spl_console_init(void)
115{
Simon Glassf4d60392021-08-08 12:20:12 -0600116#ifdef CONFIG_SPL_SERIAL
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100117 gd->bd = &bdata;
118 gd->baudrate = CONFIG_BAUDRATE;
119 serial_init();
120 gd->have_console = 1;
121#endif
122}
123
Marek Vasut0dc62ba2013-08-31 15:53:44 +0200124void 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 Vasut151f49d2011-12-02 03:47:40 +0000127{
Mans Rullgard2f66b402018-04-21 16:11:09 +0100128 struct mxs_spl_data *data = MXS_SPL_DATA;
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000129 uint8_t bootmode = mxs_get_bootmode_index();
Marek Behúna8cf1552021-05-20 13:24:10 +0200130 set_gd(&gdata);
Marek Vasut9136fe92012-05-01 11:09:44 +0000131
Marek Vasut913784a2014-03-05 20:01:13 +0100132 mxs_spl_fixup_vectors();
133
Marek Vasut151f49d2011-12-02 03:47:40 +0000134 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
Marek Vasut913784a2014-03-05 20:01:13 +0100135
Lukasz Majewski790aa812023-05-19 12:43:54 +0200136 if (!CONFIG_IS_ENABLED(DM_SERIAL)) {
137 mxs_spl_console_init();
138 debug("SPL: Serial Console Initialised\n");
139 }
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100140
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000141 mxs_power_init();
Marek Vasut9136fe92012-05-01 11:09:44 +0000142
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000143 mxs_mem_init();
144 data->mem_dram_size = mxs_mem_get_size();
Marek Vasut9136fe92012-05-01 11:09:44 +0000145
Marek Vasutb28fe462012-05-01 11:09:45 +0000146 data->boot_mode_idx = bootmode;
147
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000148 mxs_power_wait_pswitch();
Graeme Russ9bf144c2015-01-25 12:07:53 +1100149
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 Vasut151f49d2011-12-02 03:47:40 +0000154}
155
Mans Rullgard65d21902018-04-21 16:11:10 +0100156#ifndef CONFIG_SPL_FRAMEWORK
Marek Vasut151f49d2011-12-02 03:47:40 +0000157/* Support aparatus */
158inline void board_init_f(unsigned long bootflag)
159{
160 for (;;)
161 ;
162}
163
164inline void board_init_r(gd_t *id, ulong dest_addr)
165{
166 for (;;)
167 ;
168}
Mans Rullgard65d21902018-04-21 16:11:10 +0100169#endif