blob: 8ea7c36f46f8d94ed5b5953362fead3f431ba254 [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 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <config.h>
28#include <asm/io.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000029#include <asm/arch/imx-regs.h>
Marek Vasut9136fe92012-05-01 11:09:44 +000030#include <asm/arch/sys_proto.h>
Marek Vasutb28fe462012-05-01 11:09:45 +000031#include <asm/gpio.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000032
Otavio Salvadorf930ea62012-08-05 09:05:32 +000033#include "mxs_init.h"
Marek Vasut151f49d2011-12-02 03:47:40 +000034
35/*
36 * This delay function is intended to be used only in early stage of boot, where
37 * clock are not set up yet. The timer used here is reset on every boot and
38 * takes a few seconds to roll. The boot doesn't take that long, so to keep the
39 * code simple, it doesn't take rolling into consideration.
40 */
Marek Vasut151f49d2011-12-02 03:47:40 +000041void early_delay(int delay)
42{
Marek Vasut794cdb92012-08-28 15:15:53 +000043 struct mxs_digctl_regs *digctl_regs =
44 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
45
46 uint32_t st = readl(&digctl_regs->hw_digctl_microseconds);
Marek Vasut151f49d2011-12-02 03:47:40 +000047 st += delay;
Marek Vasut794cdb92012-08-28 15:15:53 +000048 while (st > readl(&digctl_regs->hw_digctl_microseconds))
Marek Vasut151f49d2011-12-02 03:47:40 +000049 ;
50}
51
Marek Vasutb28fe462012-05-01 11:09:45 +000052#define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
53const iomux_cfg_t iomux_boot[] = {
54 MX28_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
55 MX28_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
56 MX28_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
57 MX28_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
58 MX28_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
59 MX28_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
60};
61
Otavio Salvadorf930ea62012-08-05 09:05:32 +000062uint8_t mxs_get_bootmode_index(void)
Marek Vasutb28fe462012-05-01 11:09:45 +000063{
64 uint8_t bootmode = 0;
65 int i;
66 uint8_t masked;
67
68 /* Setup IOMUX of bootmode pads to GPIO */
69 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
70
71 /* Setup bootmode pins as GPIO input */
72 gpio_direction_input(MX28_PAD_LCD_D00__GPIO_1_0);
73 gpio_direction_input(MX28_PAD_LCD_D01__GPIO_1_1);
74 gpio_direction_input(MX28_PAD_LCD_D02__GPIO_1_2);
75 gpio_direction_input(MX28_PAD_LCD_D03__GPIO_1_3);
76 gpio_direction_input(MX28_PAD_LCD_D04__GPIO_1_4);
77 gpio_direction_input(MX28_PAD_LCD_D05__GPIO_1_5);
78
79 /* Read bootmode pads */
80 bootmode |= (gpio_get_value(MX28_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
81 bootmode |= (gpio_get_value(MX28_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
82 bootmode |= (gpio_get_value(MX28_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
83 bootmode |= (gpio_get_value(MX28_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
84 bootmode |= (gpio_get_value(MX28_PAD_LCD_D04__GPIO_1_4) ? 1 : 0) << 4;
85 bootmode |= (gpio_get_value(MX28_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
86
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
Otavio Salvadorf930ea62012-08-05 09:05:32 +000096void mxs_common_spl_init(const iomux_cfg_t *iomux_setup,
Marek Vasut151f49d2011-12-02 03:47:40 +000097 const unsigned int iomux_size)
98{
Otavio Salvadorf930ea62012-08-05 09:05:32 +000099 struct mxs_spl_data *data = (struct mxs_spl_data *)
100 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf);
101 uint8_t bootmode = mxs_get_bootmode_index();
Marek Vasut9136fe92012-05-01 11:09:44 +0000102
Marek Vasut151f49d2011-12-02 03:47:40 +0000103 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000104 mxs_power_init();
Marek Vasut9136fe92012-05-01 11:09:44 +0000105
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000106 mxs_mem_init();
107 data->mem_dram_size = mxs_mem_get_size();
Marek Vasut9136fe92012-05-01 11:09:44 +0000108
Marek Vasutb28fe462012-05-01 11:09:45 +0000109 data->boot_mode_idx = bootmode;
110
Otavio Salvadorf930ea62012-08-05 09:05:32 +0000111 mxs_power_wait_pswitch();
Marek Vasut151f49d2011-12-02 03:47:40 +0000112}
113
114/* Support aparatus */
115inline void board_init_f(unsigned long bootflag)
116{
117 for (;;)
118 ;
119}
120
121inline void board_init_r(gd_t *id, ulong dest_addr)
122{
123 for (;;)
124 ;
125}
126
Marek Vasut151f49d2011-12-02 03:47:40 +0000127void hang(void) __attribute__ ((noreturn));
128void hang(void)
129{
130 for (;;)
131 ;
132}