blob: d9d1d73d1af4fe25d78442f9be62b96aecf43401 [file] [log] [blame]
Marek Vasut151f49d2011-12-02 03:47:40 +00001/*
2 * Freescale i.MX28 Boot setup
3 *
4 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5 * on behalf of DENX Software Engineering GmbH
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Marek Vasut151f49d2011-12-02 03:47:40 +00008 */
9
10#include <common.h>
11#include <config.h>
12#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
28 * clock are not set up yet. The timer used here is reset on every boot and
29 * takes a few seconds to roll. The boot doesn't take that long, so to keep the
30 * code simple, it doesn't take rolling into consideration.
31 */
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);
Marek Vasut151f49d2011-12-02 03:47:40 +000038 st += delay;
Marek Vasut794cdb92012-08-28 15:15:53 +000039 while (st > readl(&digctl_regs->hw_digctl_microseconds))
Marek Vasut151f49d2011-12-02 03:47:40 +000040 ;
41}
42
Marek Vasutaaf7d122016-12-15 16:48:55 +010043#if defined(CONFIG_MX23)
Marek Vasutb28fe462012-05-01 11:09:45 +000044#define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
Marek Vasute5cf7512012-11-30 07:09:23 +000045static const iomux_cfg_t iomux_boot[] = {
Otavio Salvador5304a262013-01-11 03:19:10 +000046 MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
47 MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
48 MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
49 MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
50 MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
51 MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
Marek Vasutb28fe462012-05-01 11:09:45 +000052};
Marek Vasutaaf7d122016-12-15 16:48:55 +010053#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000054
Marek Vasute5cf7512012-11-30 07:09:23 +000055static uint8_t mxs_get_bootmode_index(void)
Marek Vasutb28fe462012-05-01 11:09:45 +000056{
57 uint8_t bootmode = 0;
58 int i;
59 uint8_t masked;
60
Jörg Krause09b00572015-03-26 23:53:11 +010061#if defined(CONFIG_MX23)
Marek Vasutb28fe462012-05-01 11:09:45 +000062 /* Setup IOMUX of bootmode pads to GPIO */
63 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
64
Otavio Salvador5304a262013-01-11 03:19:10 +000065 /* Setup bootmode pins as GPIO input */
66 gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
67 gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
68 gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
69 gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
70 gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
71
72 /* Read bootmode pads */
73 bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
74 bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
75 bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
76 bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
77 bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
78#elif defined(CONFIG_MX28)
Jörg Krause09b00572015-03-26 23:53:11 +010079 /* The global boot mode will be detected by ROM code and its value
80 * is stored at the fixed address 0x00019BF0 in OCRAM.
81 */
82#define GLOBAL_BOOT_MODE_ADDR 0x00019BF0
83 bootmode = __raw_readl(GLOBAL_BOOT_MODE_ADDR);
Otavio Salvador5304a262013-01-11 03:19:10 +000084#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000085
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +000086 for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
87 masked = bootmode & mxs_boot_modes[i].boot_mask;
88 if (masked == mxs_boot_modes[i].boot_pads)
Marek Vasutb28fe462012-05-01 11:09:45 +000089 break;
90 }
91
92 return i;
93}
94
Marek Vasut913784a2014-03-05 20:01:13 +010095static void mxs_spl_fixup_vectors(void)
96{
97 /*
98 * Copy our vector table to 0x0, since due to HAB, we cannot
99 * be loaded to 0x0. We want to have working vectoring though,
100 * thus this fixup. Our vectoring table is PIC, so copying is
101 * fine.
102 */
103 extern uint32_t _start;
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{
111#ifdef CONFIG_SPL_SERIAL_SUPPORT
112 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{
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000123 struct mxs_spl_data *data = (struct mxs_spl_data *)
124 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
125 uint8_t bootmode = mxs_get_bootmode_index();
Marek Vasutd18f74a2014-03-19 02:21:35 +0100126 gd = &gdata;
Marek Vasut9136fe92012-05-01 11:09:44 +0000127
Marek Vasut913784a2014-03-05 20:01:13 +0100128 mxs_spl_fixup_vectors();
129
Marek Vasut151f49d2011-12-02 03:47:40 +0000130 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
Marek Vasut913784a2014-03-05 20:01:13 +0100131
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100132 mxs_spl_console_init();
Graeme Russ0f2483a2015-01-25 12:07:51 +1100133 debug("SPL: Serial Console Initialised\n");
Marek Vasutbb9f5e22014-03-19 02:21:36 +0100134
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000135 mxs_power_init();
Marek Vasut9136fe92012-05-01 11:09:44 +0000136
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000137 mxs_mem_init();
138 data->mem_dram_size = mxs_mem_get_size();
Marek Vasut9136fe92012-05-01 11:09:44 +0000139
Marek Vasutb28fe462012-05-01 11:09:45 +0000140 data->boot_mode_idx = bootmode;
141
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000142 mxs_power_wait_pswitch();
Graeme Russ9bf144c2015-01-25 12:07:53 +1100143
144 if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) {
145 debug("SPL: Waiting for JTAG user\n");
146 asm volatile ("x: b x");
147 }
Marek Vasut151f49d2011-12-02 03:47:40 +0000148}
149
150/* 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}