Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2012-2013 Henrik Nordstrom <henrik@henriknordstrom.net> |
| 3 | * (C) Copyright 2013 Luke Kenneth Casson Leighton <lkcl@lkcl.net> |
| 4 | * |
| 5 | * (C) Copyright 2007-2011 |
| 6 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 7 | * Tom Cubie <tangliang@allwinnertech.com> |
| 8 | * |
| 9 | * Some board init for the Allwinner A10-evb board. |
| 10 | * |
| 11 | * SPDX-License-Identifier: GPL-2.0+ |
| 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Hans de Goede | e79c7c8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 15 | #include <mmc.h> |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 16 | #include <axp_pmic.h> |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 17 | #include <asm/arch/clock.h> |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 18 | #include <asm/arch/cpu.h> |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 19 | #include <asm/arch/display.h> |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 20 | #include <asm/arch/dram.h> |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 21 | #include <asm/arch/gpio.h> |
| 22 | #include <asm/arch/mmc.h> |
Hans de Goede | 2aacc42 | 2015-04-27 15:05:10 +0200 | [diff] [blame] | 23 | #include <asm/arch/usb_phy.h> |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 24 | #ifndef CONFIG_ARM64 |
| 25 | #include <asm/armv7.h> |
| 26 | #endif |
Hans de Goede | 4f7e01c | 2015-04-23 23:23:50 +0200 | [diff] [blame] | 27 | #include <asm/gpio.h> |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 28 | #include <asm/io.h> |
Hans de Goede | f62bfa5 | 2015-08-15 11:55:26 +0200 | [diff] [blame] | 29 | #include <nand.h> |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 30 | #include <net.h> |
Jelle van der Waa | 0d8382a | 2016-02-23 18:47:19 +0100 | [diff] [blame] | 31 | #include <sy8106a.h> |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 32 | |
Hans de Goede | 5541008 | 2015-02-16 17:23:25 +0100 | [diff] [blame] | 33 | #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD) |
| 34 | /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */ |
| 35 | int soft_i2c_gpio_sda; |
| 36 | int soft_i2c_gpio_scl; |
Hans de Goede | 4f7e01c | 2015-04-23 23:23:50 +0200 | [diff] [blame] | 37 | |
| 38 | static int soft_i2c_board_init(void) |
| 39 | { |
| 40 | int ret; |
| 41 | |
| 42 | soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA); |
| 43 | if (soft_i2c_gpio_sda < 0) { |
| 44 | printf("Error invalid soft i2c sda pin: '%s', err %d\n", |
| 45 | CONFIG_VIDEO_LCD_PANEL_I2C_SDA, soft_i2c_gpio_sda); |
| 46 | return soft_i2c_gpio_sda; |
| 47 | } |
| 48 | ret = gpio_request(soft_i2c_gpio_sda, "soft-i2c-sda"); |
| 49 | if (ret) { |
| 50 | printf("Error requesting soft i2c sda pin: '%s', err %d\n", |
| 51 | CONFIG_VIDEO_LCD_PANEL_I2C_SDA, ret); |
| 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL); |
| 56 | if (soft_i2c_gpio_scl < 0) { |
| 57 | printf("Error invalid soft i2c scl pin: '%s', err %d\n", |
| 58 | CONFIG_VIDEO_LCD_PANEL_I2C_SCL, soft_i2c_gpio_scl); |
| 59 | return soft_i2c_gpio_scl; |
| 60 | } |
| 61 | ret = gpio_request(soft_i2c_gpio_scl, "soft-i2c-scl"); |
| 62 | if (ret) { |
| 63 | printf("Error requesting soft i2c scl pin: '%s', err %d\n", |
| 64 | CONFIG_VIDEO_LCD_PANEL_I2C_SCL, ret); |
| 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | #else |
| 71 | static int soft_i2c_board_init(void) { return 0; } |
Hans de Goede | 5541008 | 2015-02-16 17:23:25 +0100 | [diff] [blame] | 72 | #endif |
| 73 | |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 74 | DECLARE_GLOBAL_DATA_PTR; |
| 75 | |
| 76 | /* add board specific code here */ |
| 77 | int board_init(void) |
| 78 | { |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 79 | __maybe_unused int id_pfr1, ret; |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 80 | |
| 81 | gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100); |
| 82 | |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 83 | #ifndef CONFIG_ARM64 |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 84 | asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1)); |
| 85 | debug("id_pfr1: 0x%08x\n", id_pfr1); |
| 86 | /* Generic Timer Extension available? */ |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 87 | if ((id_pfr1 >> CPUID_ARM_GENTIMER_SHIFT) & 0xf) { |
| 88 | uint32_t freq; |
| 89 | |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 90 | debug("Setting CNTFRQ\n"); |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 91 | |
| 92 | /* |
| 93 | * CNTFRQ is a secure register, so we will crash if we try to |
| 94 | * write this from the non-secure world (read is OK, though). |
| 95 | * In case some bootcode has already set the correct value, |
| 96 | * we avoid the risk of writing to it. |
| 97 | */ |
| 98 | asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r"(freq)); |
| 99 | if (freq != CONFIG_TIMER_CLK_FREQ) { |
| 100 | debug("arch timer frequency is %d Hz, should be %d, fixing ...\n", |
| 101 | freq, CONFIG_TIMER_CLK_FREQ); |
| 102 | #ifdef CONFIG_NON_SECURE |
| 103 | printf("arch timer frequency is wrong, but cannot adjust it\n"); |
| 104 | #else |
| 105 | asm volatile("mcr p15, 0, %0, c14, c0, 0" |
| 106 | : : "r"(CONFIG_TIMER_CLK_FREQ)); |
| 107 | #endif |
| 108 | } |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 109 | } |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 110 | #endif /* !CONFIG_ARM64 */ |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 111 | |
Hans de Goede | 2fcf033 | 2015-04-25 17:25:14 +0200 | [diff] [blame] | 112 | ret = axp_gpio_init(); |
| 113 | if (ret) |
| 114 | return ret; |
| 115 | |
Hans de Goede | 9fbb0c3 | 2016-03-22 20:10:30 +0100 | [diff] [blame] | 116 | #ifdef CONFIG_SATAPWR |
| 117 | gpio_request(CONFIG_SATAPWR, "satapwr"); |
| 118 | gpio_direction_output(CONFIG_SATAPWR, 1); |
| 119 | #endif |
Hans de Goede | fc8991c | 2016-03-17 13:53:03 +0100 | [diff] [blame] | 120 | #ifdef CONFIG_MACPWR |
| 121 | gpio_request(CONFIG_MACPWR, "macpwr"); |
| 122 | gpio_direction_output(CONFIG_MACPWR, 1); |
| 123 | #endif |
| 124 | |
Hans de Goede | 4f7e01c | 2015-04-23 23:23:50 +0200 | [diff] [blame] | 125 | /* Uses dm gpio code so do this here and not in i2c_init_board() */ |
| 126 | return soft_i2c_board_init(); |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | int dram_init(void) |
| 130 | { |
| 131 | gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE); |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
Hans de Goede | e526861 | 2015-08-16 14:48:22 +0200 | [diff] [blame] | 136 | #if defined(CONFIG_NAND_SUNXI) && defined(CONFIG_SPL_BUILD) |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 137 | static void nand_pinmux_setup(void) |
| 138 | { |
| 139 | unsigned int pin; |
Hans de Goede | 022a99d | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 140 | |
| 141 | for (pin = SUNXI_GPC(0); pin <= SUNXI_GPC(19); pin++) |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 142 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND); |
| 143 | |
Hans de Goede | 022a99d | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 144 | #if defined CONFIG_MACH_SUN4I || defined CONFIG_MACH_SUN7I |
| 145 | for (pin = SUNXI_GPC(20); pin <= SUNXI_GPC(22); pin++) |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 146 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND); |
Hans de Goede | 022a99d | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 147 | #endif |
| 148 | /* sun4i / sun7i do have a PC23, but it is not used for nand, |
| 149 | * only sun7i has a PC24 */ |
| 150 | #ifdef CONFIG_MACH_SUN7I |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 151 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_NAND); |
Hans de Goede | 022a99d | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 152 | #endif |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static void nand_clock_setup(void) |
| 156 | { |
| 157 | struct sunxi_ccm_reg *const ccm = |
| 158 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
Hans de Goede | 31c2147 | 2015-08-15 11:58:03 +0200 | [diff] [blame] | 159 | |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 160 | setbits_le32(&ccm->ahb_gate0, (CLK_GATE_OPEN << AHB_GATE_OFFSET_NAND0)); |
Hans de Goede | 31c2147 | 2015-08-15 11:58:03 +0200 | [diff] [blame] | 161 | #ifdef CONFIG_MACH_SUN9I |
| 162 | setbits_le32(&ccm->ahb_gate1, (1 << AHB_GATE_OFFSET_DMA)); |
| 163 | #else |
| 164 | setbits_le32(&ccm->ahb_gate0, (1 << AHB_GATE_OFFSET_DMA)); |
| 165 | #endif |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 166 | setbits_le32(&ccm->nand0_clk_cfg, CCM_NAND_CTRL_ENABLE | AHB_DIV_1); |
| 167 | } |
Hans de Goede | f62bfa5 | 2015-08-15 11:55:26 +0200 | [diff] [blame] | 168 | |
| 169 | void board_nand_init(void) |
| 170 | { |
| 171 | nand_pinmux_setup(); |
| 172 | nand_clock_setup(); |
| 173 | } |
Karol Gugala | ad00829 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 174 | #endif |
| 175 | |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 176 | #ifdef CONFIG_GENERIC_MMC |
| 177 | static void mmc_pinmux_setup(int sdc) |
| 178 | { |
| 179 | unsigned int pin; |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 180 | __maybe_unused int pins; |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 181 | |
| 182 | switch (sdc) { |
| 183 | case 0: |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 184 | /* SDC0: PF0-PF5 */ |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 185 | for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 186 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0); |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 187 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 188 | sunxi_gpio_set_drv(pin, 2); |
| 189 | } |
| 190 | break; |
| 191 | |
| 192 | case 1: |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 193 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC1_PINS); |
| 194 | |
| 195 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 196 | if (pins == SUNXI_GPIO_H) { |
| 197 | /* SDC1: PH22-PH-27 */ |
| 198 | for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) { |
| 199 | sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1); |
| 200 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 201 | sunxi_gpio_set_drv(pin, 2); |
| 202 | } |
| 203 | } else { |
| 204 | /* SDC1: PG0-PG5 */ |
| 205 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 206 | sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1); |
| 207 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 208 | sunxi_gpio_set_drv(pin, 2); |
| 209 | } |
| 210 | } |
| 211 | #elif defined(CONFIG_MACH_SUN5I) |
| 212 | /* SDC1: PG3-PG8 */ |
Hans de Goede | bbff84b | 2014-10-03 16:44:57 +0200 | [diff] [blame] | 213 | for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 214 | sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1); |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 215 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 216 | sunxi_gpio_set_drv(pin, 2); |
| 217 | } |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 218 | #elif defined(CONFIG_MACH_SUN6I) |
| 219 | /* SDC1: PG0-PG5 */ |
| 220 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 221 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1); |
| 222 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 223 | sunxi_gpio_set_drv(pin, 2); |
| 224 | } |
| 225 | #elif defined(CONFIG_MACH_SUN8I) |
| 226 | if (pins == SUNXI_GPIO_D) { |
| 227 | /* SDC1: PD2-PD7 */ |
| 228 | for (pin = SUNXI_GPD(2); pin <= SUNXI_GPD(7); pin++) { |
| 229 | sunxi_gpio_set_cfgpin(pin, SUN8I_GPD_SDC1); |
| 230 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 231 | sunxi_gpio_set_drv(pin, 2); |
| 232 | } |
| 233 | } else { |
| 234 | /* SDC1: PG0-PG5 */ |
| 235 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 236 | sunxi_gpio_set_cfgpin(pin, SUN8I_GPG_SDC1); |
| 237 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 238 | sunxi_gpio_set_drv(pin, 2); |
| 239 | } |
| 240 | } |
| 241 | #endif |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 242 | break; |
| 243 | |
| 244 | case 2: |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 245 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC2_PINS); |
| 246 | |
| 247 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 248 | /* SDC2: PC6-PC11 */ |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 249 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) { |
Paul Kocialkowski | 487b327 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 250 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 251 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 252 | sunxi_gpio_set_drv(pin, 2); |
| 253 | } |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 254 | #elif defined(CONFIG_MACH_SUN5I) |
| 255 | if (pins == SUNXI_GPIO_E) { |
| 256 | /* SDC2: PE4-PE9 */ |
| 257 | for (pin = SUNXI_GPE(4); pin <= SUNXI_GPD(9); pin++) { |
| 258 | sunxi_gpio_set_cfgpin(pin, SUN5I_GPE_SDC2); |
| 259 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 260 | sunxi_gpio_set_drv(pin, 2); |
| 261 | } |
| 262 | } else { |
| 263 | /* SDC2: PC6-PC15 */ |
| 264 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 265 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 266 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 267 | sunxi_gpio_set_drv(pin, 2); |
| 268 | } |
| 269 | } |
| 270 | #elif defined(CONFIG_MACH_SUN6I) |
| 271 | if (pins == SUNXI_GPIO_A) { |
| 272 | /* SDC2: PA9-PA14 */ |
| 273 | for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) { |
| 274 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC2); |
| 275 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 276 | sunxi_gpio_set_drv(pin, 2); |
| 277 | } |
| 278 | } else { |
| 279 | /* SDC2: PC6-PC15, PC24 */ |
| 280 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 281 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 282 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 283 | sunxi_gpio_set_drv(pin, 2); |
| 284 | } |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 285 | |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 286 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2); |
| 287 | sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP); |
| 288 | sunxi_gpio_set_drv(SUNXI_GPC(24), 2); |
| 289 | } |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 290 | #elif defined(CONFIG_MACH_SUN8I) || defined(CONFIG_MACH_SUN50I) |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 291 | /* SDC2: PC5-PC6, PC8-PC16 */ |
| 292 | for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) { |
| 293 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 294 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 295 | sunxi_gpio_set_drv(pin, 2); |
| 296 | } |
Paul Kocialkowski | 8deacca | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 297 | |
| 298 | for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) { |
| 299 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 300 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 301 | sunxi_gpio_set_drv(pin, 2); |
| 302 | } |
| 303 | #endif |
| 304 | break; |
| 305 | |
| 306 | case 3: |
| 307 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC3_PINS); |
| 308 | |
| 309 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 310 | /* SDC3: PI4-PI9 */ |
| 311 | for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) { |
| 312 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3); |
| 313 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 314 | sunxi_gpio_set_drv(pin, 2); |
| 315 | } |
| 316 | #elif defined(CONFIG_MACH_SUN6I) |
| 317 | if (pins == SUNXI_GPIO_A) { |
| 318 | /* SDC3: PA9-PA14 */ |
| 319 | for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) { |
| 320 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC3); |
| 321 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 322 | sunxi_gpio_set_drv(pin, 2); |
| 323 | } |
| 324 | } else { |
| 325 | /* SDC3: PC6-PC15, PC24 */ |
| 326 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 327 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3); |
| 328 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 329 | sunxi_gpio_set_drv(pin, 2); |
| 330 | } |
| 331 | |
| 332 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3); |
| 333 | sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP); |
| 334 | sunxi_gpio_set_drv(SUNXI_GPC(24), 2); |
| 335 | } |
| 336 | #endif |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 337 | break; |
| 338 | |
| 339 | default: |
| 340 | printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc); |
| 341 | break; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | int board_mmc_init(bd_t *bis) |
| 346 | { |
Hans de Goede | e79c7c8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 347 | __maybe_unused struct mmc *mmc0, *mmc1; |
| 348 | __maybe_unused char buf[512]; |
| 349 | |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 350 | mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT); |
Hans de Goede | e79c7c8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 351 | mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT); |
| 352 | if (!mmc0) |
| 353 | return -1; |
| 354 | |
Hans de Goede | 2ccfac0 | 2014-10-02 20:43:50 +0200 | [diff] [blame] | 355 | #if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1 |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 356 | mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA); |
Hans de Goede | e79c7c8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 357 | mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA); |
| 358 | if (!mmc1) |
| 359 | return -1; |
| 360 | #endif |
| 361 | |
Daniel Kochmański | bf5b9b1 | 2015-05-29 17:21:00 +0200 | [diff] [blame] | 362 | #if !defined(CONFIG_SPL_BUILD) && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2 |
Hans de Goede | e79c7c8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 363 | /* |
Daniel Kochmański | bf5b9b1 | 2015-05-29 17:21:00 +0200 | [diff] [blame] | 364 | * On systems with an emmc (mmc2), figure out if we are booting from |
| 365 | * the emmc and if we are make it "mmc dev 0" so that boot.scr, etc. |
| 366 | * are searched there first. Note we only do this for u-boot proper, |
| 367 | * not for the SPL, see spl_boot_device(). |
Hans de Goede | e79c7c8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 368 | */ |
Daniel Kochmański | bf5b9b1 | 2015-05-29 17:21:00 +0200 | [diff] [blame] | 369 | if (!sunxi_mmc_has_egon_boot_signature(mmc0) && |
| 370 | sunxi_mmc_has_egon_boot_signature(mmc1)) { |
| 371 | /* Booting from emmc / mmc2, swap */ |
Simon Glass | bcce53d | 2016-02-29 15:25:51 -0700 | [diff] [blame] | 372 | mmc0->block_dev.devnum = 1; |
| 373 | mmc1->block_dev.devnum = 0; |
Daniel Kochmański | bf5b9b1 | 2015-05-29 17:21:00 +0200 | [diff] [blame] | 374 | } |
Ian Campbell | e24ea55 | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 375 | #endif |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | #endif |
| 380 | |
Hans de Goede | 6620377 | 2014-06-13 22:55:49 +0200 | [diff] [blame] | 381 | void i2c_init_board(void) |
| 382 | { |
Paul Kocialkowski | 6c739c5 | 2015-04-10 23:09:52 +0200 | [diff] [blame] | 383 | #ifdef CONFIG_I2C0_ENABLE |
| 384 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN5I) || defined(CONFIG_MACH_SUN7I) |
| 385 | sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0); |
| 386 | sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0); |
Hans de Goede | 6620377 | 2014-06-13 22:55:49 +0200 | [diff] [blame] | 387 | clock_twi_onoff(0, 1); |
Paul Kocialkowski | 6c739c5 | 2015-04-10 23:09:52 +0200 | [diff] [blame] | 388 | #elif defined(CONFIG_MACH_SUN6I) |
| 389 | sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0); |
| 390 | sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0); |
| 391 | clock_twi_onoff(0, 1); |
| 392 | #elif defined(CONFIG_MACH_SUN8I) |
| 393 | sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0); |
| 394 | sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0); |
| 395 | clock_twi_onoff(0, 1); |
| 396 | #endif |
| 397 | #endif |
| 398 | |
| 399 | #ifdef CONFIG_I2C1_ENABLE |
| 400 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 401 | sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1); |
| 402 | sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1); |
| 403 | clock_twi_onoff(1, 1); |
| 404 | #elif defined(CONFIG_MACH_SUN5I) |
| 405 | sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1); |
| 406 | sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1); |
| 407 | clock_twi_onoff(1, 1); |
| 408 | #elif defined(CONFIG_MACH_SUN6I) |
| 409 | sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1); |
| 410 | sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1); |
| 411 | clock_twi_onoff(1, 1); |
| 412 | #elif defined(CONFIG_MACH_SUN8I) |
| 413 | sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1); |
| 414 | sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1); |
| 415 | clock_twi_onoff(1, 1); |
| 416 | #endif |
| 417 | #endif |
| 418 | |
| 419 | #ifdef CONFIG_I2C2_ENABLE |
| 420 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 421 | sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN4I_GPB_TWI2); |
| 422 | sunxi_gpio_set_cfgpin(SUNXI_GPB(21), SUN4I_GPB_TWI2); |
| 423 | clock_twi_onoff(2, 1); |
| 424 | #elif defined(CONFIG_MACH_SUN5I) |
| 425 | sunxi_gpio_set_cfgpin(SUNXI_GPB(17), SUN5I_GPB_TWI2); |
| 426 | sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN5I_GPB_TWI2); |
| 427 | clock_twi_onoff(2, 1); |
| 428 | #elif defined(CONFIG_MACH_SUN6I) |
| 429 | sunxi_gpio_set_cfgpin(SUNXI_GPH(18), SUN6I_GPH_TWI2); |
| 430 | sunxi_gpio_set_cfgpin(SUNXI_GPH(19), SUN6I_GPH_TWI2); |
| 431 | clock_twi_onoff(2, 1); |
| 432 | #elif defined(CONFIG_MACH_SUN8I) |
| 433 | sunxi_gpio_set_cfgpin(SUNXI_GPE(12), SUN8I_GPE_TWI2); |
| 434 | sunxi_gpio_set_cfgpin(SUNXI_GPE(13), SUN8I_GPE_TWI2); |
| 435 | clock_twi_onoff(2, 1); |
| 436 | #endif |
| 437 | #endif |
| 438 | |
| 439 | #ifdef CONFIG_I2C3_ENABLE |
| 440 | #if defined(CONFIG_MACH_SUN6I) |
| 441 | sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUN6I_GPG_TWI3); |
| 442 | sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUN6I_GPG_TWI3); |
| 443 | clock_twi_onoff(3, 1); |
| 444 | #elif defined(CONFIG_MACH_SUN7I) |
| 445 | sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUN7I_GPI_TWI3); |
| 446 | sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUN7I_GPI_TWI3); |
| 447 | clock_twi_onoff(3, 1); |
| 448 | #endif |
| 449 | #endif |
| 450 | |
| 451 | #ifdef CONFIG_I2C4_ENABLE |
| 452 | #if defined(CONFIG_MACH_SUN7I) |
| 453 | sunxi_gpio_set_cfgpin(SUNXI_GPI(2), SUN7I_GPI_TWI4); |
| 454 | sunxi_gpio_set_cfgpin(SUNXI_GPI(3), SUN7I_GPI_TWI4); |
| 455 | clock_twi_onoff(4, 1); |
| 456 | #endif |
| 457 | #endif |
Jelle van der Waa | 9d08268 | 2016-01-14 14:06:26 +0100 | [diff] [blame] | 458 | |
| 459 | #ifdef CONFIG_R_I2C_ENABLE |
| 460 | clock_twi_onoff(5, 1); |
| 461 | sunxi_gpio_set_cfgpin(SUNXI_GPL(0), SUN8I_H3_GPL_R_TWI); |
| 462 | sunxi_gpio_set_cfgpin(SUNXI_GPL(1), SUN8I_H3_GPL_R_TWI); |
| 463 | #endif |
Hans de Goede | 6620377 | 2014-06-13 22:55:49 +0200 | [diff] [blame] | 464 | } |
| 465 | |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 466 | #ifdef CONFIG_SPL_BUILD |
| 467 | void sunxi_board_init(void) |
| 468 | { |
Henrik Nordstrom | 14bc66b | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 469 | int power_failed = 0; |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 470 | unsigned long ramsize; |
| 471 | |
Jelle van der Waa | 0d8382a | 2016-02-23 18:47:19 +0100 | [diff] [blame] | 472 | #ifdef CONFIG_SY8106A_POWER |
| 473 | power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT); |
| 474 | #endif |
| 475 | |
vishnupatekar | 95ab8fe | 2015-11-29 01:07:22 +0800 | [diff] [blame] | 476 | #if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER || \ |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 477 | defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 478 | defined CONFIG_AXP818_POWER |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 479 | power_failed = axp_init(); |
| 480 | |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 481 | #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 482 | defined CONFIG_AXP818_POWER |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 483 | power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT); |
Hans de Goede | 2428920 | 2014-06-13 22:55:51 +0200 | [diff] [blame] | 484 | #endif |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 485 | power_failed |= axp_set_dcdc2(CONFIG_AXP_DCDC2_VOLT); |
| 486 | power_failed |= axp_set_dcdc3(CONFIG_AXP_DCDC3_VOLT); |
vishnupatekar | 95ab8fe | 2015-11-29 01:07:22 +0800 | [diff] [blame] | 487 | #if !defined(CONFIG_AXP209_POWER) && !defined(CONFIG_AXP818_POWER) |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 488 | power_failed |= axp_set_dcdc4(CONFIG_AXP_DCDC4_VOLT); |
Henrik Nordstrom | 14bc66b | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 489 | #endif |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 490 | #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 491 | defined CONFIG_AXP818_POWER |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 492 | power_failed |= axp_set_dcdc5(CONFIG_AXP_DCDC5_VOLT); |
Oliver Schinagl | 5c7f10f | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 493 | #endif |
Henrik Nordstrom | 14bc66b | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 494 | |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 495 | #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 496 | defined CONFIG_AXP818_POWER |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 497 | power_failed |= axp_set_aldo1(CONFIG_AXP_ALDO1_VOLT); |
| 498 | #endif |
| 499 | power_failed |= axp_set_aldo2(CONFIG_AXP_ALDO2_VOLT); |
Chen-Yu Tsai | f3c5045 | 2016-01-12 14:42:40 +0800 | [diff] [blame] | 500 | #if !defined(CONFIG_AXP152_POWER) |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 501 | power_failed |= axp_set_aldo3(CONFIG_AXP_ALDO3_VOLT); |
| 502 | #endif |
| 503 | #ifdef CONFIG_AXP209_POWER |
| 504 | power_failed |= axp_set_aldo4(CONFIG_AXP_ALDO4_VOLT); |
| 505 | #endif |
| 506 | |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 507 | #if defined(CONFIG_AXP221_POWER) || defined(CONFIG_AXP809_POWER) || \ |
| 508 | defined(CONFIG_AXP818_POWER) |
Chen-Yu Tsai | 3517a27 | 2016-01-12 14:42:37 +0800 | [diff] [blame] | 509 | power_failed |= axp_set_dldo(1, CONFIG_AXP_DLDO1_VOLT); |
| 510 | power_failed |= axp_set_dldo(2, CONFIG_AXP_DLDO2_VOLT); |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 511 | #if !defined CONFIG_AXP809_POWER |
Chen-Yu Tsai | 3517a27 | 2016-01-12 14:42:37 +0800 | [diff] [blame] | 512 | power_failed |= axp_set_dldo(3, CONFIG_AXP_DLDO3_VOLT); |
| 513 | power_failed |= axp_set_dldo(4, CONFIG_AXP_DLDO4_VOLT); |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 514 | #endif |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 515 | power_failed |= axp_set_eldo(1, CONFIG_AXP_ELDO1_VOLT); |
| 516 | power_failed |= axp_set_eldo(2, CONFIG_AXP_ELDO2_VOLT); |
| 517 | power_failed |= axp_set_eldo(3, CONFIG_AXP_ELDO3_VOLT); |
| 518 | #endif |
Chen-Yu Tsai | 38491d9 | 2016-03-30 00:26:48 +0800 | [diff] [blame] | 519 | |
| 520 | #ifdef CONFIG_AXP818_POWER |
| 521 | power_failed |= axp_set_fldo(1, CONFIG_AXP_FLDO1_VOLT); |
| 522 | power_failed |= axp_set_fldo(2, CONFIG_AXP_FLDO2_VOLT); |
| 523 | power_failed |= axp_set_fldo(3, CONFIG_AXP_FLDO3_VOLT); |
Chen-Yu Tsai | 795857d | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 524 | #endif |
| 525 | |
| 526 | #if defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER |
Chen-Yu Tsai | 15278cc | 2016-05-02 10:28:12 +0800 | [diff] [blame] | 527 | power_failed |= axp_set_sw(IS_ENABLED(CONFIG_AXP_SW_ON)); |
Chen-Yu Tsai | 38491d9 | 2016-03-30 00:26:48 +0800 | [diff] [blame] | 528 | #endif |
Hans de Goede | 6944aff | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 529 | #endif |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 530 | printf("DRAM:"); |
| 531 | ramsize = sunxi_dram_init(); |
Hans de Goede | cd8b35d | 2016-06-26 13:56:01 +0200 | [diff] [blame] | 532 | printf(" %d MiB\n", (int)(ramsize >> 20)); |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 533 | if (!ramsize) |
| 534 | hang(); |
Henrik Nordstrom | 14bc66b | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 535 | |
| 536 | /* |
| 537 | * Only clock up the CPU to full speed if we are reasonably |
| 538 | * assured it's being powered with suitable core voltage |
| 539 | */ |
| 540 | if (!power_failed) |
Iain Paton | e71b422 | 2015-03-28 10:26:38 +0000 | [diff] [blame] | 541 | clock_set_pll1(CONFIG_SYS_CLK_FREQ); |
Henrik Nordstrom | 14bc66b | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 542 | else |
| 543 | printf("Failed to set core voltage! Can't set CPU frequency\n"); |
Ian Campbell | cba69ee | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 544 | } |
| 545 | #endif |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 546 | |
Paul Kocialkowski | f1df758 | 2015-03-22 18:07:13 +0100 | [diff] [blame] | 547 | #ifdef CONFIG_USB_GADGET |
| 548 | int g_dnl_board_usb_cable_connected(void) |
| 549 | { |
Paul Kocialkowski | 5bfdca0 | 2015-05-16 19:52:10 +0200 | [diff] [blame] | 550 | return sunxi_usb_phy_vbus_detect(0); |
Paul Kocialkowski | f1df758 | 2015-03-22 18:07:13 +0100 | [diff] [blame] | 551 | } |
| 552 | #endif |
| 553 | |
Paul Kocialkowski | 9f85221 | 2015-03-28 18:35:36 +0100 | [diff] [blame] | 554 | #ifdef CONFIG_SERIAL_TAG |
| 555 | void get_board_serial(struct tag_serialnr *serialnr) |
| 556 | { |
| 557 | char *serial_string; |
| 558 | unsigned long long serial; |
| 559 | |
| 560 | serial_string = getenv("serial#"); |
| 561 | |
| 562 | if (serial_string) { |
| 563 | serial = simple_strtoull(serial_string, NULL, 16); |
| 564 | |
| 565 | serialnr->high = (unsigned int) (serial >> 32); |
| 566 | serialnr->low = (unsigned int) (serial & 0xffffffff); |
| 567 | } else { |
| 568 | serialnr->high = 0; |
| 569 | serialnr->low = 0; |
| 570 | } |
| 571 | } |
| 572 | #endif |
| 573 | |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 574 | #if !defined(CONFIG_SPL_BUILD) |
| 575 | #include <asm/arch/spl.h> |
Bernhard Nortmann | 320e057 | 2016-06-09 07:37:35 +0200 | [diff] [blame^] | 576 | #include <environment.h> |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 577 | |
| 578 | /* |
| 579 | * Check the SPL header for the "sunxi" variant. If found: parse values |
| 580 | * that might have been passed by the loader ("fel" utility), and update |
| 581 | * the environment accordingly. |
| 582 | */ |
| 583 | static void parse_spl_header(const uint32_t spl_addr) |
| 584 | { |
Siarhei Siamashka | d96ebc4 | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 585 | struct boot_file_head *spl = (void *)(ulong)spl_addr; |
Bernhard Nortmann | 320e057 | 2016-06-09 07:37:35 +0200 | [diff] [blame^] | 586 | if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0) |
| 587 | return; /* signature mismatch, no usable header */ |
| 588 | |
| 589 | uint8_t spl_header_version = spl->spl_signature[3]; |
| 590 | if (spl_header_version != SPL_HEADER_VERSION) { |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 591 | printf("sunxi SPL version mismatch: expected %u, got %u\n", |
| 592 | SPL_HEADER_VERSION, spl_header_version); |
Bernhard Nortmann | 320e057 | 2016-06-09 07:37:35 +0200 | [diff] [blame^] | 593 | return; |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 594 | } |
Bernhard Nortmann | 320e057 | 2016-06-09 07:37:35 +0200 | [diff] [blame^] | 595 | if (!spl->fel_script_address) |
| 596 | return; |
| 597 | |
| 598 | if (spl->fel_uEnv_length != 0) { |
| 599 | /* |
| 600 | * data is expected in uEnv.txt compatible format, so "env |
| 601 | * import -t" the string(s) at fel_script_address right away. |
| 602 | */ |
| 603 | himport_r(&env_htab, (char *)spl->fel_script_address, |
| 604 | spl->fel_uEnv_length, '\n', H_NOCLEAR, 0, 0, NULL); |
| 605 | return; |
| 606 | } |
| 607 | /* otherwise assume .scr format (mkimage-type script) */ |
| 608 | setenv_hex("fel_scriptaddr", spl->fel_script_address); |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 609 | } |
| 610 | #endif |
| 611 | |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 612 | #ifdef CONFIG_MISC_INIT_R |
| 613 | int misc_init_r(void) |
| 614 | { |
Paul Kocialkowski | 8c81657 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 615 | char serial_string[17] = { 0 }; |
Hans de Goede | cac5b1c | 2014-11-26 00:04:24 +0100 | [diff] [blame] | 616 | unsigned int sid[4]; |
Paul Kocialkowski | 8c81657 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 617 | uint8_t mac_addr[6]; |
| 618 | int ret; |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 619 | |
Bernhard Nortmann | af654d1 | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 620 | #if !defined(CONFIG_SPL_BUILD) |
| 621 | setenv("fel_booted", NULL); |
| 622 | setenv("fel_scriptaddr", NULL); |
| 623 | /* determine if we are running in FEL mode */ |
| 624 | if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */ |
| 625 | setenv("fel_booted", "1"); |
| 626 | parse_spl_header(SPL_ADDR); |
| 627 | } |
| 628 | #endif |
| 629 | |
Paul Kocialkowski | 8c81657 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 630 | ret = sunxi_get_sid(sid); |
| 631 | if (ret == 0 && sid[0] != 0 && sid[3] != 0) { |
| 632 | if (!getenv("ethaddr")) { |
| 633 | /* Non OUI / registered MAC address */ |
| 634 | mac_addr[0] = 0x02; |
| 635 | mac_addr[1] = (sid[0] >> 0) & 0xff; |
| 636 | mac_addr[2] = (sid[3] >> 24) & 0xff; |
| 637 | mac_addr[3] = (sid[3] >> 16) & 0xff; |
| 638 | mac_addr[4] = (sid[3] >> 8) & 0xff; |
| 639 | mac_addr[5] = (sid[3] >> 0) & 0xff; |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 640 | |
Paul Kocialkowski | 8c81657 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 641 | eth_setenv_enetaddr("ethaddr", mac_addr); |
| 642 | } |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 643 | |
Paul Kocialkowski | 8c81657 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 644 | if (!getenv("serial#")) { |
| 645 | snprintf(serial_string, sizeof(serial_string), |
| 646 | "%08x%08x", sid[0], sid[3]); |
| 647 | |
| 648 | setenv("serial#", serial_string); |
| 649 | } |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 650 | } |
| 651 | |
Hans de Goede | 1871a8c | 2015-01-13 19:25:06 +0100 | [diff] [blame] | 652 | #ifndef CONFIG_MACH_SUN9I |
Hans de Goede | e13afee | 2015-04-27 16:50:04 +0200 | [diff] [blame] | 653 | ret = sunxi_usb_phy_probe(); |
| 654 | if (ret) |
| 655 | return ret; |
Hans de Goede | 1871a8c | 2015-01-13 19:25:06 +0100 | [diff] [blame] | 656 | #endif |
Hans de Goede | d42faf3 | 2015-06-17 15:49:26 +0200 | [diff] [blame] | 657 | sunxi_musb_board_init(); |
| 658 | |
Jonathan Liu | b41d7d0 | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 659 | return 0; |
| 660 | } |
| 661 | #endif |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 662 | |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 663 | int ft_board_setup(void *blob, bd_t *bd) |
| 664 | { |
Hans de Goede | d75111a | 2016-03-22 22:51:52 +0100 | [diff] [blame] | 665 | int __maybe_unused r; |
| 666 | |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 667 | #ifdef CONFIG_VIDEO_DT_SIMPLEFB |
Hans de Goede | d75111a | 2016-03-22 22:51:52 +0100 | [diff] [blame] | 668 | r = sunxi_simplefb_setup(blob); |
| 669 | if (r) |
| 670 | return r; |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 671 | #endif |
Hans de Goede | d75111a | 2016-03-22 22:51:52 +0100 | [diff] [blame] | 672 | return 0; |
Luc Verhaegen | 2d7a084 | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 673 | } |