blob: 0392afd9be4b024083be19f7e359dc7f0d4d9957 [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 Vasut151f49d2011-12-02 03:47:40 +000016
Otavio Salvadorf930ea62012-08-05 09:05:32 +000017#include "mxs_init.h"
Marek Vasut151f49d2011-12-02 03:47:40 +000018
19/*
20 * This delay function is intended to be used only in early stage of boot, where
21 * clock are not set up yet. The timer used here is reset on every boot and
22 * takes a few seconds to roll. The boot doesn't take that long, so to keep the
23 * code simple, it doesn't take rolling into consideration.
24 */
Marek Vasut151f49d2011-12-02 03:47:40 +000025void early_delay(int delay)
26{
Marek Vasut794cdb92012-08-28 15:15:53 +000027 struct mxs_digctl_regs *digctl_regs =
28 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
29
30 uint32_t st = readl(&digctl_regs->hw_digctl_microseconds);
Marek Vasut151f49d2011-12-02 03:47:40 +000031 st += delay;
Marek Vasut794cdb92012-08-28 15:15:53 +000032 while (st > readl(&digctl_regs->hw_digctl_microseconds))
Marek Vasut151f49d2011-12-02 03:47:40 +000033 ;
34}
35
Marek Vasutb28fe462012-05-01 11:09:45 +000036#define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
Marek Vasute5cf7512012-11-30 07:09:23 +000037static const iomux_cfg_t iomux_boot[] = {
Otavio Salvador5304a262013-01-11 03:19:10 +000038#if defined(CONFIG_MX23)
39 MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
40 MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
41 MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
42 MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
43 MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
44 MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
45#elif defined(CONFIG_MX28)
Marek Vasutb28fe462012-05-01 11:09:45 +000046 MX28_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
47 MX28_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
48 MX28_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
49 MX28_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
50 MX28_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
51 MX28_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
Otavio Salvador5304a262013-01-11 03:19:10 +000052#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000053};
54
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
61 /* 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#if defined(CONFIG_MX23)
65 /* 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)
Marek Vasutb28fe462012-05-01 11:09:45 +000079 /* Setup bootmode pins as GPIO input */
80 gpio_direction_input(MX28_PAD_LCD_D00__GPIO_1_0);
81 gpio_direction_input(MX28_PAD_LCD_D01__GPIO_1_1);
82 gpio_direction_input(MX28_PAD_LCD_D02__GPIO_1_2);
83 gpio_direction_input(MX28_PAD_LCD_D03__GPIO_1_3);
84 gpio_direction_input(MX28_PAD_LCD_D04__GPIO_1_4);
85 gpio_direction_input(MX28_PAD_LCD_D05__GPIO_1_5);
86
87 /* Read bootmode pads */
88 bootmode |= (gpio_get_value(MX28_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
89 bootmode |= (gpio_get_value(MX28_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
90 bootmode |= (gpio_get_value(MX28_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
91 bootmode |= (gpio_get_value(MX28_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
92 bootmode |= (gpio_get_value(MX28_PAD_LCD_D04__GPIO_1_4) ? 1 : 0) << 4;
93 bootmode |= (gpio_get_value(MX28_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
Otavio Salvador5304a262013-01-11 03:19:10 +000094#endif
Marek Vasutb28fe462012-05-01 11:09:45 +000095
Otavio Salvadorcbf0bf22012-08-13 09:53:12 +000096 for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
97 masked = bootmode & mxs_boot_modes[i].boot_mask;
98 if (masked == mxs_boot_modes[i].boot_pads)
Marek Vasutb28fe462012-05-01 11:09:45 +000099 break;
100 }
101
102 return i;
103}
104
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000105void mxs_common_spl_init(const iomux_cfg_t *iomux_setup,
Marek Vasut151f49d2011-12-02 03:47:40 +0000106 const unsigned int iomux_size)
107{
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000108 struct mxs_spl_data *data = (struct mxs_spl_data *)
109 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
110 uint8_t bootmode = mxs_get_bootmode_index();
Marek Vasut9136fe92012-05-01 11:09:44 +0000111
Marek Vasut151f49d2011-12-02 03:47:40 +0000112 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000113 mxs_power_init();
Marek Vasut9136fe92012-05-01 11:09:44 +0000114
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000115 mxs_mem_init();
116 data->mem_dram_size = mxs_mem_get_size();
Marek Vasut9136fe92012-05-01 11:09:44 +0000117
Marek Vasutb28fe462012-05-01 11:09:45 +0000118 data->boot_mode_idx = bootmode;
119
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000120 mxs_power_wait_pswitch();
Marek Vasut151f49d2011-12-02 03:47:40 +0000121}
122
123/* Support aparatus */
124inline void board_init_f(unsigned long bootflag)
125{
126 for (;;)
127 ;
128}
129
130inline void board_init_r(gd_t *id, ulong dest_addr)
131{
132 for (;;)
133 ;
134}