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 * SPDX-License-Identifier: GPL-2.0+ 8 */ 9 10 #include <common.h> 11 #include <config.h> 12 #include <asm/io.h> 13 #include <asm/arch/imx-regs.h> 14 #include <asm/arch/sys_proto.h> 15 #include <asm/gpio.h> 16 #include <linux/compiler.h> 17 18 #include "mxs_init.h" 19 20 DECLARE_GLOBAL_DATA_PTR; 21 static gd_t gdata __section(".data"); 22 static bd_t bdata __section(".data"); 23 24 /* 25 * This delay function is intended to be used only in early stage of boot, where 26 * clock are not set up yet. The timer used here is reset on every boot and 27 * takes a few seconds to roll. The boot doesn't take that long, so to keep the 28 * code simple, it doesn't take rolling into consideration. 29 */ 30 void early_delay(int delay) 31 { 32 struct mxs_digctl_regs *digctl_regs = 33 (struct mxs_digctl_regs *)MXS_DIGCTL_BASE; 34 35 uint32_t st = readl(&digctl_regs->hw_digctl_microseconds); 36 st += delay; 37 while (st > readl(&digctl_regs->hw_digctl_microseconds)) 38 ; 39 } 40 41 #define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL) 42 static const iomux_cfg_t iomux_boot[] = { 43 #if defined(CONFIG_MX23) 44 MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD, 45 MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD, 46 MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD, 47 MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD, 48 MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD, 49 MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD, 50 #elif defined(CONFIG_MX28) 51 MX28_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD, 52 MX28_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD, 53 MX28_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD, 54 MX28_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD, 55 MX28_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD, 56 MX28_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD, 57 #endif 58 }; 59 60 static uint8_t mxs_get_bootmode_index(void) 61 { 62 uint8_t bootmode = 0; 63 int i; 64 uint8_t masked; 65 66 /* Setup IOMUX of bootmode pads to GPIO */ 67 mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot)); 68 69 #if defined(CONFIG_MX23) 70 /* Setup bootmode pins as GPIO input */ 71 gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0); 72 gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1); 73 gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2); 74 gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3); 75 gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5); 76 77 /* Read bootmode pads */ 78 bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0; 79 bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1; 80 bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2; 81 bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3; 82 bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5; 83 #elif defined(CONFIG_MX28) 84 /* Setup bootmode pins as GPIO input */ 85 gpio_direction_input(MX28_PAD_LCD_D00__GPIO_1_0); 86 gpio_direction_input(MX28_PAD_LCD_D01__GPIO_1_1); 87 gpio_direction_input(MX28_PAD_LCD_D02__GPIO_1_2); 88 gpio_direction_input(MX28_PAD_LCD_D03__GPIO_1_3); 89 gpio_direction_input(MX28_PAD_LCD_D04__GPIO_1_4); 90 gpio_direction_input(MX28_PAD_LCD_D05__GPIO_1_5); 91 92 /* Read bootmode pads */ 93 bootmode |= (gpio_get_value(MX28_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0; 94 bootmode |= (gpio_get_value(MX28_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1; 95 bootmode |= (gpio_get_value(MX28_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2; 96 bootmode |= (gpio_get_value(MX28_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3; 97 bootmode |= (gpio_get_value(MX28_PAD_LCD_D04__GPIO_1_4) ? 1 : 0) << 4; 98 bootmode |= (gpio_get_value(MX28_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5; 99 #endif 100 101 for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) { 102 masked = bootmode & mxs_boot_modes[i].boot_mask; 103 if (masked == mxs_boot_modes[i].boot_pads) 104 break; 105 } 106 107 return i; 108 } 109 110 static void mxs_spl_fixup_vectors(void) 111 { 112 /* 113 * Copy our vector table to 0x0, since due to HAB, we cannot 114 * be loaded to 0x0. We want to have working vectoring though, 115 * thus this fixup. Our vectoring table is PIC, so copying is 116 * fine. 117 */ 118 extern uint32_t _start; 119 memcpy(0x0, &_start, 0x60); 120 } 121 122 static void mxs_spl_console_init(void) 123 { 124 #ifdef CONFIG_SPL_SERIAL_SUPPORT 125 gd->bd = &bdata; 126 gd->baudrate = CONFIG_BAUDRATE; 127 serial_init(); 128 gd->have_console = 1; 129 #endif 130 } 131 132 void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr, 133 const iomux_cfg_t *iomux_setup, 134 const unsigned int iomux_size) 135 { 136 struct mxs_spl_data *data = (struct mxs_spl_data *) 137 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf); 138 uint8_t bootmode = mxs_get_bootmode_index(); 139 gd = &gdata; 140 141 mxs_spl_fixup_vectors(); 142 143 mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size); 144 145 mxs_spl_console_init(); 146 147 mxs_power_init(); 148 149 mxs_mem_init(); 150 data->mem_dram_size = mxs_mem_get_size(); 151 152 data->boot_mode_idx = bootmode; 153 154 mxs_power_wait_pswitch(); 155 } 156 157 /* Support aparatus */ 158 inline void board_init_f(unsigned long bootflag) 159 { 160 for (;;) 161 ; 162 } 163 164 inline void board_init_r(gd_t *id, ulong dest_addr) 165 { 166 for (;;) 167 ; 168 } 169