blob: 9168b91f27af1ae10dbb5c6b7cab6aba383d7a32 [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 Glass36736182019-11-14 12:57:24 -070011#include <serial.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000012#include <asm/io.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000013#include <asm/arch/imx-regs.h>
Marek Vasut9136fe92012-05-01 11:09:44 +000014#include <asm/arch/sys_proto.h>
Marek Vasutb28fe462012-05-01 11:09:45 +000015#include <asm/gpio.h>
Marek Vasutd18f74a2014-03-19 02:21:35 +010016#include <linux/compiler.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000017
Otavio Salvadorf930ea62012-08-05 09:05:32 +000018#include "mxs_init.h"
Marek Vasut151f49d2011-12-02 03:47:40 +000019
Marek Vasutd18f74a2014-03-19 02:21:35 +010020DECLARE_GLOBAL_DATA_PTR;
Marek Vasutbb9f5e22014-03-19 02:21:36 +010021static gd_t gdata __section(".data");
Stefano Babicc01f10b2014-04-02 10:42:06 +020022#ifdef CONFIG_SPL_SERIAL_SUPPORT
Marek Vasutbb9f5e22014-03-19 02:21:36 +010023static bd_t bdata __section(".data");
Stefano Babicc01f10b2014-04-02 10:42:06 +020024#endif
Marek Vasutd18f74a2014-03-19 02:21:35 +010025
Marek Vasut151f49d2011-12-02 03:47:40 +000026/*
27 * This delay function is intended to be used only in early stage of boot, where
Rasmus Villemoese4c63322019-09-10 08:32:01 +000028 * clock are not set up yet.
Marek Vasut151f49d2011-12-02 03:47:40 +000029 */
Marek Vasut151f49d2011-12-02 03:47:40 +000030void early_delay(int delay)
31{
Marek Vasut794cdb92012-08-28 15:15:53 +000032 struct mxs_digctl_regs *digctl_regs =
33 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
34
35 uint32_t st = readl(&digctl_regs->hw_digctl_microseconds);
Rasmus Villemoese4c63322019-09-10 08:32:01 +000036 while (readl(&digctl_regs->hw_digctl_microseconds) - st <= delay)
Marek Vasut151f49d2011-12-02 03:47:40 +000037 ;
38}
39
Marek Vasutaaf7d122016-12-15 16:48:55 +010040#if defined(CONFIG_MX23)
Marek Vasutb28fe462012-05-01 11:09:45 +000041#define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
Marek Vasute5cf7512012-11-30 07:09:23 +000042static const iomux_cfg_t iomux_boot[] = {
Otavio Salvador5304a262013-01-11 03:19:10 +000043 MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
44 MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
45 MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
46 MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
47 MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
48 MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
Marek Vasutb28fe462012-05-01 11:09:45 +000049};
Marek Vasutaaf7d122016-12-15 16:48:55 +010050#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000051
Marek Vasute5cf7512012-11-30 07:09:23 +000052static uint8_t mxs_get_bootmode_index(void)
Marek Vasutb28fe462012-05-01 11:09:45 +000053{
54 uint8_t bootmode = 0;
55 int i;
56 uint8_t masked;
57
Jörg Krause09b00572015-03-26 23:53:11 +010058#if defined(CONFIG_MX23)
Marek Vasutb28fe462012-05-01 11:09:45 +000059 /* Setup IOMUX of bootmode pads to GPIO */
60 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
61
Otavio Salvador5304a262013-01-11 03:19:10 +000062 /* Setup bootmode pins as GPIO input */
63 gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
64 gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
65 gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
66 gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
67 gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
68
69 /* Read bootmode pads */
70 bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
71 bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
72 bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
73 bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
74 bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
75#elif defined(CONFIG_MX28)
Jörg Krause09b00572015-03-26 23:53:11 +010076 /* The global boot mode will be detected by ROM code and its value
77 * is stored at the fixed address 0x00019BF0 in OCRAM.
78 */
79#define GLOBAL_BOOT_MODE_ADDR 0x00019BF0
80 bootmode = __raw_readl(GLOBAL_BOOT_MODE_ADDR);
Otavio Salvador5304a262013-01-11 03:19:10 +000081#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000082
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +000083 for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
84 masked = bootmode & mxs_boot_modes[i].boot_mask;
85 if (masked == mxs_boot_modes[i].boot_pads)
Marek Vasutb28fe462012-05-01 11:09:45 +000086 break;
87 }
88
89 return i;
90}
91
Marek Vasut913784a2014-03-05 20:01:13 +010092static void mxs_spl_fixup_vectors(void)
93{
94 /*
95 * Copy our vector table to 0x0, since due to HAB, we cannot
96 * be loaded to 0x0. We want to have working vectoring though,
97 * thus this fixup. Our vectoring table is PIC, so copying is
98 * fine.
99 */
100 extern uint32_t _start;
Wolfgang Denk6ae80832014-11-06 14:02:57 +0100101
102 /* cppcheck-suppress nullPointer */
Marek Vasut913784a2014-03-05 20:01:13 +0100103 memcpy(0x0, &_start, 0x60);
104}
105
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100106static void mxs_spl_console_init(void)
107{
108#ifdef CONFIG_SPL_SERIAL_SUPPORT
109 gd->bd = &bdata;
110 gd->baudrate = CONFIG_BAUDRATE;
111 serial_init();
112 gd->have_console = 1;
113#endif
114}
115
Marek Vasut0dc62ba2013-08-31 15:53:44 +0200116void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr,
117 const iomux_cfg_t *iomux_setup,
118 const unsigned int iomux_size)
Marek Vasut151f49d2011-12-02 03:47:40 +0000119{
Mans Rullgard2f66b402018-04-21 16:11:09 +0100120 struct mxs_spl_data *data = MXS_SPL_DATA;
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000121 uint8_t bootmode = mxs_get_bootmode_index();
Marek Vasutd18f74a2014-03-19 02:21:35 +0100122 gd = &gdata;
Marek Vasut9136fe92012-05-01 11:09:44 +0000123
Marek Vasut913784a2014-03-05 20:01:13 +0100124 mxs_spl_fixup_vectors();
125
Marek Vasut151f49d2011-12-02 03:47:40 +0000126 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
Marek Vasut913784a2014-03-05 20:01:13 +0100127
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100128 mxs_spl_console_init();
Graeme Russ0f2483a2015-01-25 12:07:51 +1100129 debug("SPL: Serial Console Initialised\n");
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100130
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000131 mxs_power_init();
Marek Vasut9136fe92012-05-01 11:09:44 +0000132
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000133 mxs_mem_init();
134 data->mem_dram_size = mxs_mem_get_size();
Marek Vasut9136fe92012-05-01 11:09:44 +0000135
Marek Vasutb28fe462012-05-01 11:09:45 +0000136 data->boot_mode_idx = bootmode;
137
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000138 mxs_power_wait_pswitch();
Graeme Russ9bf144c2015-01-25 12:07:53 +1100139
140 if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) {
141 debug("SPL: Waiting for JTAG user\n");
142 asm volatile ("x: b x");
143 }
Marek Vasut151f49d2011-12-02 03:47:40 +0000144}
145
Mans Rullgard65d21902018-04-21 16:11:10 +0100146#ifndef CONFIG_SPL_FRAMEWORK
Marek Vasut151f49d2011-12-02 03:47:40 +0000147/* Support aparatus */
148inline void board_init_f(unsigned long bootflag)
149{
150 for (;;)
151 ;
152}
153
154inline void board_init_r(gd_t *id, ulong dest_addr)
155{
156 for (;;)
157 ;
158}
Mans Rullgard65d21902018-04-21 16:11:10 +0100159#endif