blob: 565392eab5647ddb2c6f516268b34076fed350dd [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>
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 Vasutd18f74a2014-03-19 02:21:35 +010018#include <linux/compiler.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000019
Otavio Salvadorf930ea62012-08-05 09:05:32 +000020#include "mxs_init.h"
Marek Vasut151f49d2011-12-02 03:47:40 +000021
Marek Vasutd18f74a2014-03-19 02:21:35 +010022DECLARE_GLOBAL_DATA_PTR;
Marek Vasutbb9f5e22014-03-19 02:21:36 +010023static gd_t gdata __section(".data");
Stefano Babicc01f10b2014-04-02 10:42:06 +020024#ifdef CONFIG_SPL_SERIAL_SUPPORT
Marek Vasutbb9f5e22014-03-19 02:21:36 +010025static bd_t bdata __section(".data");
Stefano Babicc01f10b2014-04-02 10:42:06 +020026#endif
Marek Vasutd18f74a2014-03-19 02:21:35 +010027
Marek Vasut151f49d2011-12-02 03:47:40 +000028/*
29 * This delay function is intended to be used only in early stage of boot, where
Rasmus Villemoese4c63322019-09-10 08:32:01 +000030 * clock are not set up yet.
Marek Vasut151f49d2011-12-02 03:47:40 +000031 */
Marek Vasut151f49d2011-12-02 03:47:40 +000032void early_delay(int delay)
33{
Marek Vasut794cdb92012-08-28 15:15:53 +000034 struct mxs_digctl_regs *digctl_regs =
35 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
36
37 uint32_t st = readl(&digctl_regs->hw_digctl_microseconds);
Rasmus Villemoese4c63322019-09-10 08:32:01 +000038 while (readl(&digctl_regs->hw_digctl_microseconds) - st <= delay)
Marek Vasut151f49d2011-12-02 03:47:40 +000039 ;
40}
41
Marek Vasutaaf7d122016-12-15 16:48:55 +010042#if defined(CONFIG_MX23)
Marek Vasutb28fe462012-05-01 11:09:45 +000043#define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
Marek Vasute5cf7512012-11-30 07:09:23 +000044static const iomux_cfg_t iomux_boot[] = {
Otavio Salvador5304a262013-01-11 03:19:10 +000045 MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
46 MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
47 MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
48 MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
49 MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
50 MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
Marek Vasutb28fe462012-05-01 11:09:45 +000051};
Marek Vasutaaf7d122016-12-15 16:48:55 +010052#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000053
Marek Vasute5cf7512012-11-30 07:09:23 +000054static uint8_t mxs_get_bootmode_index(void)
Marek Vasutb28fe462012-05-01 11:09:45 +000055{
56 uint8_t bootmode = 0;
57 int i;
58 uint8_t masked;
59
Jörg Krause09b00572015-03-26 23:53:11 +010060#if defined(CONFIG_MX23)
Marek Vasutb28fe462012-05-01 11:09:45 +000061 /* Setup IOMUX of bootmode pads to GPIO */
62 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
63
Otavio Salvador5304a262013-01-11 03:19:10 +000064 /* Setup bootmode pins as GPIO input */
65 gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
66 gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
67 gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
68 gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
69 gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
70
71 /* Read bootmode pads */
72 bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
73 bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
74 bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
75 bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
76 bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
77#elif defined(CONFIG_MX28)
Jörg Krause09b00572015-03-26 23:53:11 +010078 /* The global boot mode will be detected by ROM code and its value
79 * is stored at the fixed address 0x00019BF0 in OCRAM.
80 */
81#define GLOBAL_BOOT_MODE_ADDR 0x00019BF0
82 bootmode = __raw_readl(GLOBAL_BOOT_MODE_ADDR);
Otavio Salvador5304a262013-01-11 03:19:10 +000083#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000084
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +000085 for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
86 masked = bootmode & mxs_boot_modes[i].boot_mask;
87 if (masked == mxs_boot_modes[i].boot_pads)
Marek Vasutb28fe462012-05-01 11:09:45 +000088 break;
89 }
90
91 return i;
92}
93
Marek Vasut913784a2014-03-05 20:01:13 +010094static void mxs_spl_fixup_vectors(void)
95{
96 /*
97 * Copy our vector table to 0x0, since due to HAB, we cannot
98 * be loaded to 0x0. We want to have working vectoring though,
99 * thus this fixup. Our vectoring table is PIC, so copying is
100 * fine.
101 */
102 extern uint32_t _start;
Wolfgang Denk6ae80832014-11-06 14:02:57 +0100103
104 /* cppcheck-suppress nullPointer */
Marek Vasut913784a2014-03-05 20:01:13 +0100105 memcpy(0x0, &_start, 0x60);
106}
107
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100108static void mxs_spl_console_init(void)
109{
110#ifdef CONFIG_SPL_SERIAL_SUPPORT
111 gd->bd = &bdata;
112 gd->baudrate = CONFIG_BAUDRATE;
113 serial_init();
114 gd->have_console = 1;
115#endif
116}
117
Marek Vasut0dc62ba2013-08-31 15:53:44 +0200118void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr,
119 const iomux_cfg_t *iomux_setup,
120 const unsigned int iomux_size)
Marek Vasut151f49d2011-12-02 03:47:40 +0000121{
Mans Rullgard2f66b402018-04-21 16:11:09 +0100122 struct mxs_spl_data *data = MXS_SPL_DATA;
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000123 uint8_t bootmode = mxs_get_bootmode_index();
Marek Vasutd18f74a2014-03-19 02:21:35 +0100124 gd = &gdata;
Marek Vasut9136fe92012-05-01 11:09:44 +0000125
Marek Vasut913784a2014-03-05 20:01:13 +0100126 mxs_spl_fixup_vectors();
127
Marek Vasut151f49d2011-12-02 03:47:40 +0000128 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
Marek Vasut913784a2014-03-05 20:01:13 +0100129
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100130 mxs_spl_console_init();
Graeme Russ0f2483a2015-01-25 12:07:51 +1100131 debug("SPL: Serial Console Initialised\n");
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100132
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000133 mxs_power_init();
Marek Vasut9136fe92012-05-01 11:09:44 +0000134
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000135 mxs_mem_init();
136 data->mem_dram_size = mxs_mem_get_size();
Marek Vasut9136fe92012-05-01 11:09:44 +0000137
Marek Vasutb28fe462012-05-01 11:09:45 +0000138 data->boot_mode_idx = bootmode;
139
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000140 mxs_power_wait_pswitch();
Graeme Russ9bf144c2015-01-25 12:07:53 +1100141
142 if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) {
143 debug("SPL: Waiting for JTAG user\n");
144 asm volatile ("x: b x");
145 }
Marek Vasut151f49d2011-12-02 03:47:40 +0000146}
147
Mans Rullgard65d21902018-04-21 16:11:10 +0100148#ifndef CONFIG_SPL_FRAMEWORK
Marek Vasut151f49d2011-12-02 03:47:40 +0000149/* Support aparatus */
150inline void board_init_f(unsigned long bootflag)
151{
152 for (;;)
153 ;
154}
155
156inline void board_init_r(gd_t *id, ulong dest_addr)
157{
158 for (;;)
159 ;
160}
Mans Rullgard65d21902018-04-21 16:11:10 +0100161#endif