blob: 763d79e8036a41a0f157ce11f534d33dd19d5d01 [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 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 Vasut913784a2014-03-05 20:01:13 +010096static void mxs_spl_fixup_vectors(void)
97{
98 /*
99 * Copy our vector table to 0x0, since due to HAB, we cannot
100 * be loaded to 0x0. We want to have working vectoring though,
101 * thus this fixup. Our vectoring table is PIC, so copying is
102 * fine.
103 */
Wolfgang Denk6ae80832014-11-06 14:02:57 +0100104
105 /* cppcheck-suppress nullPointer */
Marek Vasut913784a2014-03-05 20:01:13 +0100106 memcpy(0x0, &_start, 0x60);
107}
108
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100109static void mxs_spl_console_init(void)
110{
Simon Glassf4d60392021-08-08 12:20:12 -0600111#ifdef CONFIG_SPL_SERIAL
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100112 gd->bd = &bdata;
113 gd->baudrate = CONFIG_BAUDRATE;
114 serial_init();
115 gd->have_console = 1;
116#endif
117}
118
Marek Vasut0dc62ba2013-08-31 15:53:44 +0200119void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr,
120 const iomux_cfg_t *iomux_setup,
121 const unsigned int iomux_size)
Marek Vasut151f49d2011-12-02 03:47:40 +0000122{
Mans Rullgard2f66b402018-04-21 16:11:09 +0100123 struct mxs_spl_data *data = MXS_SPL_DATA;
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000124 uint8_t bootmode = mxs_get_bootmode_index();
Marek Behúna8cf1552021-05-20 13:24:10 +0200125 set_gd(&gdata);
Marek Vasut9136fe92012-05-01 11:09:44 +0000126
Marek Vasut913784a2014-03-05 20:01:13 +0100127 mxs_spl_fixup_vectors();
128
Marek Vasut151f49d2011-12-02 03:47:40 +0000129 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
Marek Vasut913784a2014-03-05 20:01:13 +0100130
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100131 mxs_spl_console_init();
Graeme Russ0f2483a2015-01-25 12:07:51 +1100132 debug("SPL: Serial Console Initialised\n");
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100133
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000134 mxs_power_init();
Marek Vasut9136fe92012-05-01 11:09:44 +0000135
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000136 mxs_mem_init();
137 data->mem_dram_size = mxs_mem_get_size();
Marek Vasut9136fe92012-05-01 11:09:44 +0000138
Marek Vasutb28fe462012-05-01 11:09:45 +0000139 data->boot_mode_idx = bootmode;
140
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000141 mxs_power_wait_pswitch();
Graeme Russ9bf144c2015-01-25 12:07:53 +1100142
143 if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) {
144 debug("SPL: Waiting for JTAG user\n");
145 asm volatile ("x: b x");
146 }
Marek Vasut151f49d2011-12-02 03:47:40 +0000147}
148
Mans Rullgard65d21902018-04-21 16:11:10 +0100149#ifndef CONFIG_SPL_FRAMEWORK
Marek Vasut151f49d2011-12-02 03:47:40 +0000150/* Support aparatus */
151inline void board_init_f(unsigned long bootflag)
152{
153 for (;;)
154 ;
155}
156
157inline void board_init_r(gd_t *id, ulong dest_addr)
158{
159 for (;;)
160 ;
161}
Mans Rullgard65d21902018-04-21 16:11:10 +0100162#endif