blob: a6dfca3f51f66ff87d758dbe7d9633a696191be6 [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>
29#include <asm/arch/iomux-mx28.h>
30#include <asm/arch/imx-regs.h>
Marek Vasut9136fe92012-05-01 11:09:44 +000031#include <asm/arch/sys_proto.h>
Marek Vasutb28fe462012-05-01 11:09:45 +000032#include <asm/gpio.h>
Marek Vasut151f49d2011-12-02 03:47:40 +000033
34#include "mx28_init.h"
35
36/*
37 * This delay function is intended to be used only in early stage of boot, where
38 * clock are not set up yet. The timer used here is reset on every boot and
39 * takes a few seconds to roll. The boot doesn't take that long, so to keep the
40 * code simple, it doesn't take rolling into consideration.
41 */
42#define HW_DIGCTRL_MICROSECONDS 0x8001c0c0
43void early_delay(int delay)
44{
45 uint32_t st = readl(HW_DIGCTRL_MICROSECONDS);
46 st += delay;
47 while (st > readl(HW_DIGCTRL_MICROSECONDS))
48 ;
49}
50
Marek Vasutb28fe462012-05-01 11:09:45 +000051#define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
52const iomux_cfg_t iomux_boot[] = {
53 MX28_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
54 MX28_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
55 MX28_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
56 MX28_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
57 MX28_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
58 MX28_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
59};
60
61uint8_t mx28_get_bootmode_index(void)
62{
63 uint8_t bootmode = 0;
64 int i;
65 uint8_t masked;
66
67 /* Setup IOMUX of bootmode pads to GPIO */
68 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
69
70 /* Setup bootmode pins as GPIO input */
71 gpio_direction_input(MX28_PAD_LCD_D00__GPIO_1_0);
72 gpio_direction_input(MX28_PAD_LCD_D01__GPIO_1_1);
73 gpio_direction_input(MX28_PAD_LCD_D02__GPIO_1_2);
74 gpio_direction_input(MX28_PAD_LCD_D03__GPIO_1_3);
75 gpio_direction_input(MX28_PAD_LCD_D04__GPIO_1_4);
76 gpio_direction_input(MX28_PAD_LCD_D05__GPIO_1_5);
77
78 /* Read bootmode pads */
79 bootmode |= (gpio_get_value(MX28_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
80 bootmode |= (gpio_get_value(MX28_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
81 bootmode |= (gpio_get_value(MX28_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
82 bootmode |= (gpio_get_value(MX28_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
83 bootmode |= (gpio_get_value(MX28_PAD_LCD_D04__GPIO_1_4) ? 1 : 0) << 4;
84 bootmode |= (gpio_get_value(MX28_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
85
86 for (i = 0; i < ARRAY_SIZE(mx28_boot_modes); i++) {
87 masked = bootmode & mx28_boot_modes[i].boot_mask;
88 if (masked == mx28_boot_modes[i].boot_pads)
89 break;
90 }
91
92 return i;
93}
94
Marek Vasut151f49d2011-12-02 03:47:40 +000095void mx28_common_spl_init(const iomux_cfg_t *iomux_setup,
96 const unsigned int iomux_size)
97{
Marek Vasut9136fe92012-05-01 11:09:44 +000098 struct mx28_spl_data *data = (struct mx28_spl_data *)
99 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mx28_spl_data)) & ~0xf);
Marek Vasutb28fe462012-05-01 11:09:45 +0000100 uint8_t bootmode = mx28_get_bootmode_index();
Marek Vasut9136fe92012-05-01 11:09:44 +0000101
Marek Vasut151f49d2011-12-02 03:47:40 +0000102 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
103 mx28_power_init();
Marek Vasut9136fe92012-05-01 11:09:44 +0000104
Marek Vasut151f49d2011-12-02 03:47:40 +0000105 mx28_mem_init();
Marek Vasut9136fe92012-05-01 11:09:44 +0000106 data->mem_dram_size = mx28_mem_get_size();
107
Marek Vasutb28fe462012-05-01 11:09:45 +0000108 data->boot_mode_idx = bootmode;
109
Marek Vasut151f49d2011-12-02 03:47:40 +0000110 mx28_power_wait_pswitch();
111}
112
113/* Support aparatus */
114inline void board_init_f(unsigned long bootflag)
115{
116 for (;;)
117 ;
118}
119
120inline void board_init_r(gd_t *id, ulong dest_addr)
121{
122 for (;;)
123 ;
124}
125
Marek Vasut609d35a2012-05-01 11:09:53 +0000126#ifndef CONFIG_SPL_SERIAL_SUPPORT
Marek Vasutda6c5d52011-12-08 09:46:12 +0000127void serial_putc(const char c) {}
128void serial_puts(const char *s) {}
Marek Vasut609d35a2012-05-01 11:09:53 +0000129#endif
Marek Vasut151f49d2011-12-02 03:47:40 +0000130void hang(void) __attribute__ ((noreturn));
131void hang(void)
132{
133 for (;;)
134 ;
135}