Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 1 | /* |
| 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 Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 29 | #include <asm/arch/imx-regs.h> |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 30 | #include <asm/arch/sys_proto.h> |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 31 | #include <asm/gpio.h> |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 32 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 33 | #include "mxs_init.h" |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 34 | |
| 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 Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 41 | void early_delay(int delay) |
| 42 | { |
Marek Vasut | 794cdb9 | 2012-08-28 15:15:53 +0000 | [diff] [blame] | 43 | 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 Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 47 | st += delay; |
Marek Vasut | 794cdb9 | 2012-08-28 15:15:53 +0000 | [diff] [blame] | 48 | while (st > readl(&digctl_regs->hw_digctl_microseconds)) |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 49 | ; |
| 50 | } |
| 51 | |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 52 | #define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL) |
Marek Vasut | e5cf751 | 2012-11-30 07:09:23 +0000 | [diff] [blame] | 53 | static const iomux_cfg_t iomux_boot[] = { |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 54 | #if defined(CONFIG_MX23) |
| 55 | MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD, |
| 56 | MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD, |
| 57 | MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD, |
| 58 | MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD, |
| 59 | MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD, |
| 60 | MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD, |
| 61 | #elif defined(CONFIG_MX28) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 62 | MX28_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD, |
| 63 | MX28_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD, |
| 64 | MX28_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD, |
| 65 | MX28_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD, |
| 66 | MX28_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD, |
| 67 | MX28_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD, |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 68 | #endif |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
Marek Vasut | e5cf751 | 2012-11-30 07:09:23 +0000 | [diff] [blame] | 71 | static uint8_t mxs_get_bootmode_index(void) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 72 | { |
| 73 | uint8_t bootmode = 0; |
| 74 | int i; |
| 75 | uint8_t masked; |
| 76 | |
| 77 | /* Setup IOMUX of bootmode pads to GPIO */ |
| 78 | mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot)); |
| 79 | |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 80 | #if defined(CONFIG_MX23) |
| 81 | /* Setup bootmode pins as GPIO input */ |
| 82 | gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0); |
| 83 | gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1); |
| 84 | gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2); |
| 85 | gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3); |
| 86 | gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5); |
| 87 | |
| 88 | /* Read bootmode pads */ |
| 89 | bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0; |
| 90 | bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1; |
| 91 | bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2; |
| 92 | bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3; |
| 93 | bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5; |
| 94 | #elif defined(CONFIG_MX28) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 95 | /* Setup bootmode pins as GPIO input */ |
| 96 | gpio_direction_input(MX28_PAD_LCD_D00__GPIO_1_0); |
| 97 | gpio_direction_input(MX28_PAD_LCD_D01__GPIO_1_1); |
| 98 | gpio_direction_input(MX28_PAD_LCD_D02__GPIO_1_2); |
| 99 | gpio_direction_input(MX28_PAD_LCD_D03__GPIO_1_3); |
| 100 | gpio_direction_input(MX28_PAD_LCD_D04__GPIO_1_4); |
| 101 | gpio_direction_input(MX28_PAD_LCD_D05__GPIO_1_5); |
| 102 | |
| 103 | /* Read bootmode pads */ |
| 104 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0; |
| 105 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1; |
| 106 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2; |
| 107 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3; |
| 108 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D04__GPIO_1_4) ? 1 : 0) << 4; |
| 109 | bootmode |= (gpio_get_value(MX28_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5; |
Otavio Salvador | 5304a26 | 2013-01-11 03:19:10 +0000 | [diff] [blame] | 110 | #endif |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 111 | |
Otavio Salvador | cbf0bf2 | 2012-08-13 09:53:12 +0000 | [diff] [blame] | 112 | for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) { |
| 113 | masked = bootmode & mxs_boot_modes[i].boot_mask; |
| 114 | if (masked == mxs_boot_modes[i].boot_pads) |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 115 | break; |
| 116 | } |
| 117 | |
| 118 | return i; |
| 119 | } |
| 120 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 121 | void mxs_common_spl_init(const iomux_cfg_t *iomux_setup, |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 122 | const unsigned int iomux_size) |
| 123 | { |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 124 | struct mxs_spl_data *data = (struct mxs_spl_data *) |
| 125 | ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf); |
| 126 | uint8_t bootmode = mxs_get_bootmode_index(); |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 127 | |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 128 | mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size); |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 129 | mxs_power_init(); |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 130 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 131 | mxs_mem_init(); |
| 132 | data->mem_dram_size = mxs_mem_get_size(); |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 133 | |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 134 | data->boot_mode_idx = bootmode; |
| 135 | |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 136 | mxs_power_wait_pswitch(); |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* Support aparatus */ |
| 140 | inline void board_init_f(unsigned long bootflag) |
| 141 | { |
| 142 | for (;;) |
| 143 | ; |
| 144 | } |
| 145 | |
| 146 | inline void board_init_r(gd_t *id, ulong dest_addr) |
| 147 | { |
| 148 | for (;;) |
| 149 | ; |
| 150 | } |
| 151 | |
Marek Vasut | 151f49d | 2011-12-02 03:47:40 +0000 | [diff] [blame] | 152 | void hang(void) __attribute__ ((noreturn)); |
| 153 | void hang(void) |
| 154 | { |
| 155 | for (;;) |
| 156 | ; |
| 157 | } |