Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012-2013 Henrik Nordstrom <henrik@henriknordstrom.net> |
| 4 | * (C) Copyright 2013 Luke Kenneth Casson Leighton <lkcl@lkcl.net> |
| 5 | * |
| 6 | * (C) Copyright 2007-2011 |
| 7 | * Allwinner Technology Co., Ltd. <www.allwinnertech.com> |
| 8 | * Tom Cubie <tangliang@allwinnertech.com> |
| 9 | * |
| 10 | * Some board init for the Allwinner A10-evb board. |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Jagan Teki | 73a3ecf | 2018-05-07 13:03:36 +0530 | [diff] [blame] | 14 | #include <dm.h> |
Hans de Goede | 63deaa8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 15 | #include <mmc.h> |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 16 | #include <axp_pmic.h> |
Jagan Teki | 73a3ecf | 2018-05-07 13:03:36 +0530 | [diff] [blame] | 17 | #include <generic-phy.h> |
| 18 | #include <phy-sun4i-usb.h> |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 19 | #include <asm/arch/clock.h> |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 20 | #include <asm/arch/cpu.h> |
Luc Verhaegen | 4869a8c | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 21 | #include <asm/arch/display.h> |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 22 | #include <asm/arch/dram.h> |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 23 | #include <asm/arch/gpio.h> |
| 24 | #include <asm/arch/mmc.h> |
Hans de Goede | a146c50 | 2016-07-09 09:56:56 +0200 | [diff] [blame] | 25 | #include <asm/arch/spl.h> |
Siarhei Siamashka | 26c50fb | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 26 | #ifndef CONFIG_ARM64 |
| 27 | #include <asm/armv7.h> |
| 28 | #endif |
Hans de Goede | d9d0565 | 2015-04-23 23:23:50 +0200 | [diff] [blame] | 29 | #include <asm/gpio.h> |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 30 | #include <asm/io.h> |
Philipp Tomsich | 36b26d1 | 2018-11-25 19:22:18 +0100 | [diff] [blame] | 31 | #include <u-boot/crc.h> |
Hans de Goede | a146c50 | 2016-07-09 09:56:56 +0200 | [diff] [blame] | 32 | #include <environment.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 33 | #include <linux/libfdt.h> |
Hans de Goede | 5ed52f6 | 2015-08-15 11:55:26 +0200 | [diff] [blame] | 34 | #include <nand.h> |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 35 | #include <net.h> |
Maxime Ripard | ae56d97 | 2017-08-23 10:08:29 +0200 | [diff] [blame] | 36 | #include <spl.h> |
Jelle van der Waa | 3f3a309 | 2016-02-23 18:47:19 +0100 | [diff] [blame] | 37 | #include <sy8106a.h> |
Simon Glass | d9a766f | 2017-05-17 08:23:00 -0600 | [diff] [blame] | 38 | #include <asm/setup.h> |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 39 | |
Hans de Goede | a5b4cfe | 2015-02-16 17:23:25 +0100 | [diff] [blame] | 40 | #if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD) |
| 41 | /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */ |
| 42 | int soft_i2c_gpio_sda; |
| 43 | int soft_i2c_gpio_scl; |
Hans de Goede | d9d0565 | 2015-04-23 23:23:50 +0200 | [diff] [blame] | 44 | |
| 45 | static int soft_i2c_board_init(void) |
| 46 | { |
| 47 | int ret; |
| 48 | |
| 49 | soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA); |
| 50 | if (soft_i2c_gpio_sda < 0) { |
| 51 | printf("Error invalid soft i2c sda pin: '%s', err %d\n", |
| 52 | CONFIG_VIDEO_LCD_PANEL_I2C_SDA, soft_i2c_gpio_sda); |
| 53 | return soft_i2c_gpio_sda; |
| 54 | } |
| 55 | ret = gpio_request(soft_i2c_gpio_sda, "soft-i2c-sda"); |
| 56 | if (ret) { |
| 57 | printf("Error requesting soft i2c sda pin: '%s', err %d\n", |
| 58 | CONFIG_VIDEO_LCD_PANEL_I2C_SDA, ret); |
| 59 | return ret; |
| 60 | } |
| 61 | |
| 62 | soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL); |
| 63 | if (soft_i2c_gpio_scl < 0) { |
| 64 | printf("Error invalid soft i2c scl pin: '%s', err %d\n", |
| 65 | CONFIG_VIDEO_LCD_PANEL_I2C_SCL, soft_i2c_gpio_scl); |
| 66 | return soft_i2c_gpio_scl; |
| 67 | } |
| 68 | ret = gpio_request(soft_i2c_gpio_scl, "soft-i2c-scl"); |
| 69 | if (ret) { |
| 70 | printf("Error requesting soft i2c scl pin: '%s', err %d\n", |
| 71 | CONFIG_VIDEO_LCD_PANEL_I2C_SCL, ret); |
| 72 | return ret; |
| 73 | } |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | #else |
| 78 | static int soft_i2c_board_init(void) { return 0; } |
Hans de Goede | a5b4cfe | 2015-02-16 17:23:25 +0100 | [diff] [blame] | 79 | #endif |
| 80 | |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 81 | DECLARE_GLOBAL_DATA_PTR; |
| 82 | |
Jernej Skrabec | 07da880 | 2017-04-27 00:03:35 +0200 | [diff] [blame] | 83 | void i2c_init_board(void) |
| 84 | { |
| 85 | #ifdef CONFIG_I2C0_ENABLE |
| 86 | #if defined(CONFIG_MACH_SUN4I) || \ |
| 87 | defined(CONFIG_MACH_SUN5I) || \ |
| 88 | defined(CONFIG_MACH_SUN7I) || \ |
| 89 | defined(CONFIG_MACH_SUN8I_R40) |
| 90 | sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0); |
| 91 | sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0); |
| 92 | clock_twi_onoff(0, 1); |
| 93 | #elif defined(CONFIG_MACH_SUN6I) |
| 94 | sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0); |
| 95 | sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0); |
| 96 | clock_twi_onoff(0, 1); |
| 97 | #elif defined(CONFIG_MACH_SUN8I) |
| 98 | sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0); |
| 99 | sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0); |
| 100 | clock_twi_onoff(0, 1); |
Stefan Mavrodiev | cabe992 | 2019-01-08 12:04:30 +0200 | [diff] [blame] | 101 | #elif defined(CONFIG_MACH_SUN50I) |
| 102 | sunxi_gpio_set_cfgpin(SUNXI_GPH(0), SUN50I_GPH_TWI0); |
| 103 | sunxi_gpio_set_cfgpin(SUNXI_GPH(1), SUN50I_GPH_TWI0); |
| 104 | clock_twi_onoff(0, 1); |
Jernej Skrabec | 07da880 | 2017-04-27 00:03:35 +0200 | [diff] [blame] | 105 | #endif |
| 106 | #endif |
| 107 | |
| 108 | #ifdef CONFIG_I2C1_ENABLE |
| 109 | #if defined(CONFIG_MACH_SUN4I) || \ |
| 110 | defined(CONFIG_MACH_SUN7I) || \ |
| 111 | defined(CONFIG_MACH_SUN8I_R40) |
| 112 | sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1); |
| 113 | sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1); |
| 114 | clock_twi_onoff(1, 1); |
| 115 | #elif defined(CONFIG_MACH_SUN5I) |
| 116 | sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1); |
| 117 | sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1); |
| 118 | clock_twi_onoff(1, 1); |
| 119 | #elif defined(CONFIG_MACH_SUN6I) |
| 120 | sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1); |
| 121 | sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1); |
| 122 | clock_twi_onoff(1, 1); |
| 123 | #elif defined(CONFIG_MACH_SUN8I) |
| 124 | sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1); |
| 125 | sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1); |
| 126 | clock_twi_onoff(1, 1); |
Stefan Mavrodiev | cabe992 | 2019-01-08 12:04:30 +0200 | [diff] [blame] | 127 | #elif defined(CONFIG_MACH_SUN50I) |
| 128 | sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN50I_GPH_TWI1); |
| 129 | sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN50I_GPH_TWI1); |
| 130 | clock_twi_onoff(1, 1); |
Jernej Skrabec | 07da880 | 2017-04-27 00:03:35 +0200 | [diff] [blame] | 131 | #endif |
| 132 | #endif |
| 133 | |
| 134 | #ifdef CONFIG_I2C2_ENABLE |
| 135 | #if defined(CONFIG_MACH_SUN4I) || \ |
| 136 | defined(CONFIG_MACH_SUN7I) || \ |
| 137 | defined(CONFIG_MACH_SUN8I_R40) |
| 138 | sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN4I_GPB_TWI2); |
| 139 | sunxi_gpio_set_cfgpin(SUNXI_GPB(21), SUN4I_GPB_TWI2); |
| 140 | clock_twi_onoff(2, 1); |
| 141 | #elif defined(CONFIG_MACH_SUN5I) |
| 142 | sunxi_gpio_set_cfgpin(SUNXI_GPB(17), SUN5I_GPB_TWI2); |
| 143 | sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN5I_GPB_TWI2); |
| 144 | clock_twi_onoff(2, 1); |
| 145 | #elif defined(CONFIG_MACH_SUN6I) |
| 146 | sunxi_gpio_set_cfgpin(SUNXI_GPH(18), SUN6I_GPH_TWI2); |
| 147 | sunxi_gpio_set_cfgpin(SUNXI_GPH(19), SUN6I_GPH_TWI2); |
| 148 | clock_twi_onoff(2, 1); |
| 149 | #elif defined(CONFIG_MACH_SUN8I) |
| 150 | sunxi_gpio_set_cfgpin(SUNXI_GPE(12), SUN8I_GPE_TWI2); |
| 151 | sunxi_gpio_set_cfgpin(SUNXI_GPE(13), SUN8I_GPE_TWI2); |
| 152 | clock_twi_onoff(2, 1); |
Stefan Mavrodiev | cabe992 | 2019-01-08 12:04:30 +0200 | [diff] [blame] | 153 | #elif defined(CONFIG_MACH_SUN50I) |
| 154 | sunxi_gpio_set_cfgpin(SUNXI_GPE(14), SUN50I_GPE_TWI2); |
| 155 | sunxi_gpio_set_cfgpin(SUNXI_GPE(15), SUN50I_GPE_TWI2); |
| 156 | clock_twi_onoff(2, 1); |
Jernej Skrabec | 07da880 | 2017-04-27 00:03:35 +0200 | [diff] [blame] | 157 | #endif |
| 158 | #endif |
| 159 | |
| 160 | #ifdef CONFIG_I2C3_ENABLE |
| 161 | #if defined(CONFIG_MACH_SUN6I) |
| 162 | sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUN6I_GPG_TWI3); |
| 163 | sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUN6I_GPG_TWI3); |
| 164 | clock_twi_onoff(3, 1); |
| 165 | #elif defined(CONFIG_MACH_SUN7I) || \ |
| 166 | defined(CONFIG_MACH_SUN8I_R40) |
| 167 | sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUN7I_GPI_TWI3); |
| 168 | sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUN7I_GPI_TWI3); |
| 169 | clock_twi_onoff(3, 1); |
| 170 | #endif |
| 171 | #endif |
| 172 | |
| 173 | #ifdef CONFIG_I2C4_ENABLE |
| 174 | #if defined(CONFIG_MACH_SUN7I) || \ |
| 175 | defined(CONFIG_MACH_SUN8I_R40) |
| 176 | sunxi_gpio_set_cfgpin(SUNXI_GPI(2), SUN7I_GPI_TWI4); |
| 177 | sunxi_gpio_set_cfgpin(SUNXI_GPI(3), SUN7I_GPI_TWI4); |
| 178 | clock_twi_onoff(4, 1); |
| 179 | #endif |
| 180 | #endif |
| 181 | |
| 182 | #ifdef CONFIG_R_I2C_ENABLE |
Vasily Khoruzhick | 6f4c344 | 2018-11-05 20:24:30 -0800 | [diff] [blame] | 183 | #ifdef CONFIG_MACH_SUN50I |
| 184 | clock_twi_onoff(5, 1); |
| 185 | sunxi_gpio_set_cfgpin(SUNXI_GPL(8), SUN50I_GPL_R_TWI); |
| 186 | sunxi_gpio_set_cfgpin(SUNXI_GPL(9), SUN50I_GPL_R_TWI); |
| 187 | #else |
Jernej Skrabec | 07da880 | 2017-04-27 00:03:35 +0200 | [diff] [blame] | 188 | clock_twi_onoff(5, 1); |
| 189 | sunxi_gpio_set_cfgpin(SUNXI_GPL(0), SUN8I_H3_GPL_R_TWI); |
| 190 | sunxi_gpio_set_cfgpin(SUNXI_GPL(1), SUN8I_H3_GPL_R_TWI); |
| 191 | #endif |
Vasily Khoruzhick | 6f4c344 | 2018-11-05 20:24:30 -0800 | [diff] [blame] | 192 | #endif |
Jernej Skrabec | 07da880 | 2017-04-27 00:03:35 +0200 | [diff] [blame] | 193 | } |
| 194 | |
Maxime Ripard | 9ba2ac7 | 2018-01-23 21:17:03 +0100 | [diff] [blame] | 195 | #if defined(CONFIG_ENV_IS_IN_MMC) && defined(CONFIG_ENV_IS_IN_FAT) |
| 196 | enum env_location env_get_location(enum env_operation op, int prio) |
| 197 | { |
| 198 | switch (prio) { |
| 199 | case 0: |
| 200 | return ENVL_FAT; |
| 201 | |
| 202 | case 1: |
| 203 | return ENVL_MMC; |
| 204 | |
| 205 | default: |
| 206 | return ENVL_UNKNOWN; |
| 207 | } |
| 208 | } |
| 209 | #endif |
| 210 | |
Andre Przywara | d7cea36 | 2019-01-29 15:54:14 +0000 | [diff] [blame] | 211 | #ifdef CONFIG_DM_MMC |
| 212 | static void mmc_pinmux_setup(int sdc); |
| 213 | #endif |
| 214 | |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 215 | /* add board specific code here */ |
| 216 | int board_init(void) |
| 217 | { |
Mylène Josserand | 147c606 | 2017-04-02 12:59:10 +0200 | [diff] [blame] | 218 | __maybe_unused int id_pfr1, ret, satapwr_pin, macpwr_pin; |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 219 | |
| 220 | gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100); |
| 221 | |
Siarhei Siamashka | 26c50fb | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 222 | #ifndef CONFIG_ARM64 |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 223 | asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1)); |
| 224 | debug("id_pfr1: 0x%08x\n", id_pfr1); |
| 225 | /* Generic Timer Extension available? */ |
Siarhei Siamashka | 26c50fb | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 226 | if ((id_pfr1 >> CPUID_ARM_GENTIMER_SHIFT) & 0xf) { |
| 227 | uint32_t freq; |
| 228 | |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 229 | debug("Setting CNTFRQ\n"); |
Siarhei Siamashka | 26c50fb | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 230 | |
| 231 | /* |
| 232 | * CNTFRQ is a secure register, so we will crash if we try to |
| 233 | * write this from the non-secure world (read is OK, though). |
| 234 | * In case some bootcode has already set the correct value, |
| 235 | * we avoid the risk of writing to it. |
| 236 | */ |
| 237 | asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r"(freq)); |
Andre Przywara | 70c7893 | 2017-02-16 01:20:19 +0000 | [diff] [blame] | 238 | if (freq != COUNTER_FREQUENCY) { |
Siarhei Siamashka | 26c50fb | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 239 | debug("arch timer frequency is %d Hz, should be %d, fixing ...\n", |
Andre Przywara | 70c7893 | 2017-02-16 01:20:19 +0000 | [diff] [blame] | 240 | freq, COUNTER_FREQUENCY); |
Siarhei Siamashka | 26c50fb | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 241 | #ifdef CONFIG_NON_SECURE |
| 242 | printf("arch timer frequency is wrong, but cannot adjust it\n"); |
| 243 | #else |
| 244 | asm volatile("mcr p15, 0, %0, c14, c0, 0" |
Andre Przywara | 70c7893 | 2017-02-16 01:20:19 +0000 | [diff] [blame] | 245 | : : "r"(COUNTER_FREQUENCY)); |
Siarhei Siamashka | 26c50fb | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 246 | #endif |
| 247 | } |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 248 | } |
Siarhei Siamashka | 26c50fb | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 249 | #endif /* !CONFIG_ARM64 */ |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 250 | |
Hans de Goede | 3ae1d13 | 2015-04-25 17:25:14 +0200 | [diff] [blame] | 251 | ret = axp_gpio_init(); |
| 252 | if (ret) |
| 253 | return ret; |
| 254 | |
Hans de Goede | 9c34c3e | 2016-03-22 20:10:30 +0100 | [diff] [blame] | 255 | #ifdef CONFIG_SATAPWR |
Mylène Josserand | 628426a | 2017-04-02 12:59:09 +0200 | [diff] [blame] | 256 | satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR); |
| 257 | gpio_request(satapwr_pin, "satapwr"); |
| 258 | gpio_direction_output(satapwr_pin, 1); |
Werner Böllmann | e58f830 | 2017-11-10 19:14:20 +0530 | [diff] [blame] | 259 | /* Give attached sata device time to power-up to avoid link timeouts */ |
| 260 | mdelay(500); |
Hans de Goede | 9c34c3e | 2016-03-22 20:10:30 +0100 | [diff] [blame] | 261 | #endif |
Hans de Goede | 42cbbe3 | 2016-03-17 13:53:03 +0100 | [diff] [blame] | 262 | #ifdef CONFIG_MACPWR |
Mylène Josserand | 147c606 | 2017-04-02 12:59:10 +0200 | [diff] [blame] | 263 | macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR); |
| 264 | gpio_request(macpwr_pin, "macpwr"); |
| 265 | gpio_direction_output(macpwr_pin, 1); |
Hans de Goede | 42cbbe3 | 2016-03-17 13:53:03 +0100 | [diff] [blame] | 266 | #endif |
| 267 | |
Jernej Skrabec | 9220d50 | 2017-04-27 00:03:36 +0200 | [diff] [blame] | 268 | #ifdef CONFIG_DM_I2C |
| 269 | /* |
| 270 | * Temporary workaround for enabling I2C clocks until proper sunxi DM |
| 271 | * clk, reset and pinctrl drivers land. |
| 272 | */ |
| 273 | i2c_init_board(); |
| 274 | #endif |
Andre Przywara | d7cea36 | 2019-01-29 15:54:14 +0000 | [diff] [blame] | 275 | |
| 276 | #ifdef CONFIG_DM_MMC |
| 277 | /* |
| 278 | * Temporary workaround for enabling MMC clocks until a sunxi DM |
| 279 | * pinctrl driver lands. |
| 280 | */ |
| 281 | mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT); |
| 282 | #if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1 |
| 283 | mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA); |
| 284 | #endif |
| 285 | #endif /* CONFIG_DM_MMC */ |
Jernej Skrabec | 9220d50 | 2017-04-27 00:03:36 +0200 | [diff] [blame] | 286 | |
Hans de Goede | d9d0565 | 2015-04-23 23:23:50 +0200 | [diff] [blame] | 287 | /* Uses dm gpio code so do this here and not in i2c_init_board() */ |
| 288 | return soft_i2c_board_init(); |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 289 | } |
| 290 | |
Andre Przywara | 14a2539 | 2018-10-25 17:23:04 +0800 | [diff] [blame] | 291 | /* |
| 292 | * On older SoCs the SPL is actually at address zero, so using NULL as |
| 293 | * an error value does not work. |
| 294 | */ |
| 295 | #define INVALID_SPL_HEADER ((void *)~0UL) |
| 296 | |
| 297 | static struct boot_file_head * get_spl_header(uint8_t req_version) |
| 298 | { |
| 299 | struct boot_file_head *spl = (void *)(ulong)SPL_ADDR; |
| 300 | uint8_t spl_header_version = spl->spl_signature[3]; |
| 301 | |
| 302 | /* Is there really the SPL header (still) there? */ |
| 303 | if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0) |
| 304 | return INVALID_SPL_HEADER; |
| 305 | |
| 306 | if (spl_header_version < req_version) { |
| 307 | printf("sunxi SPL version mismatch: expected %u, got %u\n", |
| 308 | req_version, spl_header_version); |
| 309 | return INVALID_SPL_HEADER; |
| 310 | } |
| 311 | |
| 312 | return spl; |
| 313 | } |
| 314 | |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 315 | int dram_init(void) |
| 316 | { |
Andre Przywara | 08ee1ba | 2018-10-25 17:23:07 +0800 | [diff] [blame] | 317 | struct boot_file_head *spl = get_spl_header(SPL_DRAM_HEADER_VERSION); |
| 318 | |
| 319 | if (spl == INVALID_SPL_HEADER) |
| 320 | gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, |
| 321 | PHYS_SDRAM_0_SIZE); |
| 322 | else |
| 323 | gd->ram_size = (phys_addr_t)spl->dram_size << 20; |
| 324 | |
| 325 | if (gd->ram_size > CONFIG_SUNXI_DRAM_MAX_SIZE) |
| 326 | gd->ram_size = CONFIG_SUNXI_DRAM_MAX_SIZE; |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
Boris Brezillon | 57f2038 | 2016-06-15 21:09:23 +0200 | [diff] [blame] | 331 | #if defined(CONFIG_NAND_SUNXI) |
Karol Gugala | 7bea893 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 332 | static void nand_pinmux_setup(void) |
| 333 | { |
| 334 | unsigned int pin; |
Karol Gugala | 7bea893 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 335 | |
Hans de Goede | d223678 | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 336 | for (pin = SUNXI_GPC(0); pin <= SUNXI_GPC(19); pin++) |
Karol Gugala | 7bea893 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 337 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND); |
| 338 | |
Hans de Goede | d223678 | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 339 | #if defined CONFIG_MACH_SUN4I || defined CONFIG_MACH_SUN7I |
| 340 | for (pin = SUNXI_GPC(20); pin <= SUNXI_GPC(22); pin++) |
| 341 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND); |
| 342 | #endif |
| 343 | /* sun4i / sun7i do have a PC23, but it is not used for nand, |
| 344 | * only sun7i has a PC24 */ |
| 345 | #ifdef CONFIG_MACH_SUN7I |
Karol Gugala | 7bea893 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 346 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_NAND); |
Hans de Goede | d223678 | 2015-08-15 13:17:49 +0200 | [diff] [blame] | 347 | #endif |
Karol Gugala | 7bea893 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static void nand_clock_setup(void) |
| 351 | { |
| 352 | struct sunxi_ccm_reg *const ccm = |
| 353 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
Hans de Goede | e5561a8 | 2015-08-15 11:58:03 +0200 | [diff] [blame] | 354 | |
Karol Gugala | 7bea893 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 355 | setbits_le32(&ccm->ahb_gate0, (CLK_GATE_OPEN << AHB_GATE_OFFSET_NAND0)); |
Miquel Raynal | ebeeb80 | 2018-02-28 20:51:53 +0100 | [diff] [blame] | 356 | #if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I || \ |
| 357 | defined CONFIG_MACH_SUN9I || defined CONFIG_MACH_SUN50I |
| 358 | setbits_le32(&ccm->ahb_reset0_cfg, (1 << AHB_GATE_OFFSET_NAND0)); |
| 359 | #endif |
Karol Gugala | 7bea893 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 360 | setbits_le32(&ccm->nand0_clk_cfg, CCM_NAND_CTRL_ENABLE | AHB_DIV_1); |
| 361 | } |
Hans de Goede | 5ed52f6 | 2015-08-15 11:55:26 +0200 | [diff] [blame] | 362 | |
| 363 | void board_nand_init(void) |
| 364 | { |
| 365 | nand_pinmux_setup(); |
| 366 | nand_clock_setup(); |
Boris Brezillon | 57f2038 | 2016-06-15 21:09:23 +0200 | [diff] [blame] | 367 | #ifndef CONFIG_SPL_BUILD |
| 368 | sunxi_nand_init(); |
| 369 | #endif |
Hans de Goede | 5ed52f6 | 2015-08-15 11:55:26 +0200 | [diff] [blame] | 370 | } |
Karol Gugala | 7bea893 | 2015-07-23 14:33:01 +0200 | [diff] [blame] | 371 | #endif |
| 372 | |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 373 | #ifdef CONFIG_MMC |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 374 | static void mmc_pinmux_setup(int sdc) |
| 375 | { |
| 376 | unsigned int pin; |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 377 | __maybe_unused int pins; |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 378 | |
| 379 | switch (sdc) { |
| 380 | case 0: |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 381 | /* SDC0: PF0-PF5 */ |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 382 | for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) { |
Paul Kocialkowski | ae358a4 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 383 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0); |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 384 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 385 | sunxi_gpio_set_drv(pin, 2); |
| 386 | } |
| 387 | break; |
| 388 | |
| 389 | case 1: |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 390 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC1_PINS); |
| 391 | |
Chen-Yu Tsai | 111bc59 | 2016-11-30 16:28:34 +0800 | [diff] [blame] | 392 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \ |
| 393 | defined(CONFIG_MACH_SUN8I_R40) |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 394 | if (pins == SUNXI_GPIO_H) { |
| 395 | /* SDC1: PH22-PH-27 */ |
| 396 | for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) { |
| 397 | sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1); |
| 398 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 399 | sunxi_gpio_set_drv(pin, 2); |
| 400 | } |
| 401 | } else { |
| 402 | /* SDC1: PG0-PG5 */ |
| 403 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 404 | sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1); |
| 405 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 406 | sunxi_gpio_set_drv(pin, 2); |
| 407 | } |
| 408 | } |
| 409 | #elif defined(CONFIG_MACH_SUN5I) |
| 410 | /* SDC1: PG3-PG8 */ |
Hans de Goede | 4dccfd4 | 2014-10-03 16:44:57 +0200 | [diff] [blame] | 411 | for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) { |
Paul Kocialkowski | ae358a4 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 412 | sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1); |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 413 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 414 | sunxi_gpio_set_drv(pin, 2); |
| 415 | } |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 416 | #elif defined(CONFIG_MACH_SUN6I) |
| 417 | /* SDC1: PG0-PG5 */ |
| 418 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 419 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1); |
| 420 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 421 | sunxi_gpio_set_drv(pin, 2); |
| 422 | } |
| 423 | #elif defined(CONFIG_MACH_SUN8I) |
| 424 | if (pins == SUNXI_GPIO_D) { |
| 425 | /* SDC1: PD2-PD7 */ |
| 426 | for (pin = SUNXI_GPD(2); pin <= SUNXI_GPD(7); pin++) { |
| 427 | sunxi_gpio_set_cfgpin(pin, SUN8I_GPD_SDC1); |
| 428 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 429 | sunxi_gpio_set_drv(pin, 2); |
| 430 | } |
| 431 | } else { |
| 432 | /* SDC1: PG0-PG5 */ |
| 433 | for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) { |
| 434 | sunxi_gpio_set_cfgpin(pin, SUN8I_GPG_SDC1); |
| 435 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 436 | sunxi_gpio_set_drv(pin, 2); |
| 437 | } |
| 438 | } |
| 439 | #endif |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 440 | break; |
| 441 | |
| 442 | case 2: |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 443 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC2_PINS); |
| 444 | |
| 445 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) |
| 446 | /* SDC2: PC6-PC11 */ |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 447 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) { |
Paul Kocialkowski | ae358a4 | 2015-03-22 18:12:22 +0100 | [diff] [blame] | 448 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 449 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 450 | sunxi_gpio_set_drv(pin, 2); |
| 451 | } |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 452 | #elif defined(CONFIG_MACH_SUN5I) |
| 453 | if (pins == SUNXI_GPIO_E) { |
| 454 | /* SDC2: PE4-PE9 */ |
| 455 | for (pin = SUNXI_GPE(4); pin <= SUNXI_GPD(9); pin++) { |
| 456 | sunxi_gpio_set_cfgpin(pin, SUN5I_GPE_SDC2); |
| 457 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 458 | sunxi_gpio_set_drv(pin, 2); |
| 459 | } |
| 460 | } else { |
| 461 | /* SDC2: PC6-PC15 */ |
| 462 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 463 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 464 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 465 | sunxi_gpio_set_drv(pin, 2); |
| 466 | } |
| 467 | } |
| 468 | #elif defined(CONFIG_MACH_SUN6I) |
| 469 | if (pins == SUNXI_GPIO_A) { |
| 470 | /* SDC2: PA9-PA14 */ |
| 471 | for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) { |
| 472 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC2); |
| 473 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 474 | sunxi_gpio_set_drv(pin, 2); |
| 475 | } |
| 476 | } else { |
| 477 | /* SDC2: PC6-PC15, PC24 */ |
| 478 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 479 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 480 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 481 | sunxi_gpio_set_drv(pin, 2); |
| 482 | } |
| 483 | |
| 484 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2); |
| 485 | sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP); |
| 486 | sunxi_gpio_set_drv(SUNXI_GPC(24), 2); |
| 487 | } |
Chen-Yu Tsai | 111bc59 | 2016-11-30 16:28:34 +0800 | [diff] [blame] | 488 | #elif defined(CONFIG_MACH_SUN8I_R40) |
| 489 | /* SDC2: PC6-PC15, PC24 */ |
| 490 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 491 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 492 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 493 | sunxi_gpio_set_drv(pin, 2); |
| 494 | } |
| 495 | |
| 496 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2); |
| 497 | sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP); |
| 498 | sunxi_gpio_set_drv(SUNXI_GPC(24), 2); |
Siarhei Siamashka | 26c50fb | 2016-03-29 17:29:10 +0200 | [diff] [blame] | 499 | #elif defined(CONFIG_MACH_SUN8I) || defined(CONFIG_MACH_SUN50I) |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 500 | /* SDC2: PC5-PC6, PC8-PC16 */ |
| 501 | for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) { |
| 502 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 503 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 504 | sunxi_gpio_set_drv(pin, 2); |
| 505 | } |
| 506 | |
| 507 | for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) { |
| 508 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 509 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 510 | sunxi_gpio_set_drv(pin, 2); |
| 511 | } |
Icenowy Zheng | a838a15 | 2018-07-21 16:20:29 +0800 | [diff] [blame] | 512 | #elif defined(CONFIG_MACH_SUN50I_H6) |
| 513 | /* SDC2: PC4-PC14 */ |
| 514 | for (pin = SUNXI_GPC(4); pin <= SUNXI_GPC(14); pin++) { |
| 515 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 516 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 517 | sunxi_gpio_set_drv(pin, 2); |
| 518 | } |
Philipp Tomsich | a0c7c71 | 2016-10-28 18:21:33 +0800 | [diff] [blame] | 519 | #elif defined(CONFIG_MACH_SUN9I) |
| 520 | /* SDC2: PC6-PC16 */ |
| 521 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(16); pin++) { |
| 522 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2); |
| 523 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 524 | sunxi_gpio_set_drv(pin, 2); |
| 525 | } |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 526 | #endif |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 527 | break; |
| 528 | |
| 529 | case 3: |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 530 | pins = sunxi_name_to_gpio_bank(CONFIG_MMC3_PINS); |
| 531 | |
Chen-Yu Tsai | 111bc59 | 2016-11-30 16:28:34 +0800 | [diff] [blame] | 532 | #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \ |
| 533 | defined(CONFIG_MACH_SUN8I_R40) |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 534 | /* SDC3: PI4-PI9 */ |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 535 | for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) { |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 536 | sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3); |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 537 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 538 | sunxi_gpio_set_drv(pin, 2); |
| 539 | } |
Paul Kocialkowski | d390d8c | 2015-03-22 18:12:23 +0100 | [diff] [blame] | 540 | #elif defined(CONFIG_MACH_SUN6I) |
| 541 | if (pins == SUNXI_GPIO_A) { |
| 542 | /* SDC3: PA9-PA14 */ |
| 543 | for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) { |
| 544 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC3); |
| 545 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 546 | sunxi_gpio_set_drv(pin, 2); |
| 547 | } |
| 548 | } else { |
| 549 | /* SDC3: PC6-PC15, PC24 */ |
| 550 | for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) { |
| 551 | sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3); |
| 552 | sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP); |
| 553 | sunxi_gpio_set_drv(pin, 2); |
| 554 | } |
| 555 | |
| 556 | sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3); |
| 557 | sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP); |
| 558 | sunxi_gpio_set_drv(SUNXI_GPC(24), 2); |
| 559 | } |
| 560 | #endif |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 561 | break; |
| 562 | |
| 563 | default: |
| 564 | printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc); |
| 565 | break; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | int board_mmc_init(bd_t *bis) |
| 570 | { |
Hans de Goede | 63deaa8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 571 | __maybe_unused struct mmc *mmc0, *mmc1; |
Hans de Goede | 63deaa8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 572 | |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 573 | mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT); |
Hans de Goede | 63deaa8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 574 | mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT); |
| 575 | if (!mmc0) |
| 576 | return -1; |
| 577 | |
Hans de Goede | af593e4 | 2014-10-02 20:43:50 +0200 | [diff] [blame] | 578 | #if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1 |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 579 | mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA); |
Hans de Goede | 63deaa8 | 2014-10-02 21:13:54 +0200 | [diff] [blame] | 580 | mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA); |
| 581 | if (!mmc1) |
| 582 | return -1; |
| 583 | #endif |
| 584 | |
Ian Campbell | b4e9f2f | 2014-05-05 14:42:31 +0100 | [diff] [blame] | 585 | return 0; |
| 586 | } |
| 587 | #endif |
| 588 | |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 589 | #ifdef CONFIG_SPL_BUILD |
Andre Przywara | 08ee1ba | 2018-10-25 17:23:07 +0800 | [diff] [blame] | 590 | |
| 591 | static void sunxi_spl_store_dram_size(phys_addr_t dram_size) |
| 592 | { |
| 593 | struct boot_file_head *spl = get_spl_header(SPL_DT_HEADER_VERSION); |
| 594 | |
| 595 | if (spl == INVALID_SPL_HEADER) |
| 596 | return; |
| 597 | |
| 598 | /* Promote the header version for U-Boot proper, if needed. */ |
| 599 | if (spl->spl_signature[3] < SPL_DRAM_HEADER_VERSION) |
| 600 | spl->spl_signature[3] = SPL_DRAM_HEADER_VERSION; |
| 601 | |
| 602 | spl->dram_size = dram_size >> 20; |
| 603 | } |
| 604 | |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 605 | void sunxi_board_init(void) |
| 606 | { |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 607 | int power_failed = 0; |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 608 | |
Jelle van der Waa | 3f3a309 | 2016-02-23 18:47:19 +0100 | [diff] [blame] | 609 | #ifdef CONFIG_SY8106A_POWER |
| 610 | power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT); |
| 611 | #endif |
| 612 | |
vishnupatekar | 1895dfd | 2015-11-29 01:07:22 +0800 | [diff] [blame] | 613 | #if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER || \ |
Chen-Yu Tsai | f1e66e7 | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 614 | defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 615 | defined CONFIG_AXP818_POWER |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 616 | power_failed = axp_init(); |
| 617 | |
Chen-Yu Tsai | f1e66e7 | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 618 | #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 619 | defined CONFIG_AXP818_POWER |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 620 | power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT); |
Hans de Goede | 1f24736 | 2014-06-13 22:55:51 +0200 | [diff] [blame] | 621 | #endif |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 622 | power_failed |= axp_set_dcdc2(CONFIG_AXP_DCDC2_VOLT); |
| 623 | power_failed |= axp_set_dcdc3(CONFIG_AXP_DCDC3_VOLT); |
vishnupatekar | 1895dfd | 2015-11-29 01:07:22 +0800 | [diff] [blame] | 624 | #if !defined(CONFIG_AXP209_POWER) && !defined(CONFIG_AXP818_POWER) |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 625 | power_failed |= axp_set_dcdc4(CONFIG_AXP_DCDC4_VOLT); |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 626 | #endif |
Chen-Yu Tsai | f1e66e7 | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 627 | #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 628 | defined CONFIG_AXP818_POWER |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 629 | power_failed |= axp_set_dcdc5(CONFIG_AXP_DCDC5_VOLT); |
Oliver Schinagl | d3a558d | 2013-07-26 12:56:58 +0200 | [diff] [blame] | 630 | #endif |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 631 | |
Chen-Yu Tsai | f1e66e7 | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 632 | #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \ |
| 633 | defined CONFIG_AXP818_POWER |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 634 | power_failed |= axp_set_aldo1(CONFIG_AXP_ALDO1_VOLT); |
| 635 | #endif |
| 636 | power_failed |= axp_set_aldo2(CONFIG_AXP_ALDO2_VOLT); |
Chen-Yu Tsai | c05aa39 | 2016-01-12 14:42:40 +0800 | [diff] [blame] | 637 | #if !defined(CONFIG_AXP152_POWER) |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 638 | power_failed |= axp_set_aldo3(CONFIG_AXP_ALDO3_VOLT); |
| 639 | #endif |
| 640 | #ifdef CONFIG_AXP209_POWER |
| 641 | power_failed |= axp_set_aldo4(CONFIG_AXP_ALDO4_VOLT); |
| 642 | #endif |
| 643 | |
Chen-Yu Tsai | f1e66e7 | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 644 | #if defined(CONFIG_AXP221_POWER) || defined(CONFIG_AXP809_POWER) || \ |
| 645 | defined(CONFIG_AXP818_POWER) |
Chen-Yu Tsai | 2e6911f | 2016-01-12 14:42:37 +0800 | [diff] [blame] | 646 | power_failed |= axp_set_dldo(1, CONFIG_AXP_DLDO1_VOLT); |
| 647 | power_failed |= axp_set_dldo(2, CONFIG_AXP_DLDO2_VOLT); |
Chen-Yu Tsai | f1e66e7 | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 648 | #if !defined CONFIG_AXP809_POWER |
Chen-Yu Tsai | 2e6911f | 2016-01-12 14:42:37 +0800 | [diff] [blame] | 649 | power_failed |= axp_set_dldo(3, CONFIG_AXP_DLDO3_VOLT); |
| 650 | power_failed |= axp_set_dldo(4, CONFIG_AXP_DLDO4_VOLT); |
Chen-Yu Tsai | f1e66e7 | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 651 | #endif |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 652 | power_failed |= axp_set_eldo(1, CONFIG_AXP_ELDO1_VOLT); |
| 653 | power_failed |= axp_set_eldo(2, CONFIG_AXP_ELDO2_VOLT); |
| 654 | power_failed |= axp_set_eldo(3, CONFIG_AXP_ELDO3_VOLT); |
| 655 | #endif |
Chen-Yu Tsai | d028fba | 2016-03-30 00:26:48 +0800 | [diff] [blame] | 656 | |
| 657 | #ifdef CONFIG_AXP818_POWER |
| 658 | power_failed |= axp_set_fldo(1, CONFIG_AXP_FLDO1_VOLT); |
| 659 | power_failed |= axp_set_fldo(2, CONFIG_AXP_FLDO2_VOLT); |
| 660 | power_failed |= axp_set_fldo(3, CONFIG_AXP_FLDO3_VOLT); |
Chen-Yu Tsai | f1e66e7 | 2016-05-02 10:28:15 +0800 | [diff] [blame] | 661 | #endif |
| 662 | |
| 663 | #if defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER |
Chen-Yu Tsai | 0e3efd3 | 2016-05-02 10:28:12 +0800 | [diff] [blame] | 664 | power_failed |= axp_set_sw(IS_ENABLED(CONFIG_AXP_SW_ON)); |
Chen-Yu Tsai | d028fba | 2016-03-30 00:26:48 +0800 | [diff] [blame] | 665 | #endif |
Hans de Goede | d9ee84b | 2015-10-03 15:18:33 +0200 | [diff] [blame] | 666 | #endif |
From: Karl Palsson | 0a0bcde | 2018-12-19 13:00:39 +0000 | [diff] [blame] | 667 | printf("DRAM:"); |
| 668 | gd->ram_size = sunxi_dram_init(); |
| 669 | printf(" %d MiB\n", (int)(gd->ram_size >> 20)); |
| 670 | if (!gd->ram_size) |
| 671 | hang(); |
| 672 | |
| 673 | sunxi_spl_store_dram_size(gd->ram_size); |
Andre Przywara | 08ee1ba | 2018-10-25 17:23:07 +0800 | [diff] [blame] | 674 | |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 675 | /* |
| 676 | * Only clock up the CPU to full speed if we are reasonably |
| 677 | * assured it's being powered with suitable core voltage |
| 678 | */ |
| 679 | if (!power_failed) |
Iain Paton | 630df14 | 2015-03-28 10:26:38 +0000 | [diff] [blame] | 680 | clock_set_pll1(CONFIG_SYS_CLK_FREQ); |
Henrik Nordstrom | aa382ad | 2014-06-13 22:55:50 +0200 | [diff] [blame] | 681 | else |
From: Karl Palsson | 0a0bcde | 2018-12-19 13:00:39 +0000 | [diff] [blame] | 682 | printf("Failed to set core voltage! Can't set CPU frequency\n"); |
Ian Campbell | 6efe369 | 2014-05-05 11:52:26 +0100 | [diff] [blame] | 683 | } |
| 684 | #endif |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 685 | |
Paul Kocialkowski | dbbccaf | 2015-03-22 18:07:13 +0100 | [diff] [blame] | 686 | #ifdef CONFIG_USB_GADGET |
| 687 | int g_dnl_board_usb_cable_connected(void) |
| 688 | { |
Jagan Teki | 73a3ecf | 2018-05-07 13:03:36 +0530 | [diff] [blame] | 689 | struct udevice *dev; |
| 690 | struct phy phy; |
| 691 | int ret; |
| 692 | |
Jean-Jacques Hiblot | 9dc0d5c | 2018-11-29 10:52:46 +0100 | [diff] [blame] | 693 | ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, 0, &dev); |
Jagan Teki | 73a3ecf | 2018-05-07 13:03:36 +0530 | [diff] [blame] | 694 | if (ret) { |
| 695 | pr_err("%s: Cannot find USB device\n", __func__); |
| 696 | return ret; |
| 697 | } |
| 698 | |
| 699 | ret = generic_phy_get_by_name(dev, "usb", &phy); |
| 700 | if (ret) { |
| 701 | pr_err("failed to get %s USB PHY\n", dev->name); |
| 702 | return ret; |
| 703 | } |
| 704 | |
| 705 | ret = generic_phy_init(&phy); |
| 706 | if (ret) { |
| 707 | pr_err("failed to init %s USB PHY\n", dev->name); |
| 708 | return ret; |
| 709 | } |
| 710 | |
| 711 | ret = sun4i_usb_phy_vbus_detect(&phy); |
| 712 | if (ret == 1) { |
| 713 | pr_err("A charger is plugged into the OTG\n"); |
| 714 | return -ENODEV; |
| 715 | } |
| 716 | |
| 717 | return ret; |
Paul Kocialkowski | dbbccaf | 2015-03-22 18:07:13 +0100 | [diff] [blame] | 718 | } |
| 719 | #endif |
| 720 | |
Paul Kocialkowski | 99ae0f6 | 2015-03-28 18:35:36 +0100 | [diff] [blame] | 721 | #ifdef CONFIG_SERIAL_TAG |
| 722 | void get_board_serial(struct tag_serialnr *serialnr) |
| 723 | { |
| 724 | char *serial_string; |
| 725 | unsigned long long serial; |
| 726 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 727 | serial_string = env_get("serial#"); |
Paul Kocialkowski | 99ae0f6 | 2015-03-28 18:35:36 +0100 | [diff] [blame] | 728 | |
| 729 | if (serial_string) { |
| 730 | serial = simple_strtoull(serial_string, NULL, 16); |
| 731 | |
| 732 | serialnr->high = (unsigned int) (serial >> 32); |
| 733 | serialnr->low = (unsigned int) (serial & 0xffffffff); |
| 734 | } else { |
| 735 | serialnr->high = 0; |
| 736 | serialnr->low = 0; |
| 737 | } |
| 738 | } |
| 739 | #endif |
| 740 | |
Bernhard Nortmann | ead498a | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 741 | /* |
| 742 | * Check the SPL header for the "sunxi" variant. If found: parse values |
| 743 | * that might have been passed by the loader ("fel" utility), and update |
| 744 | * the environment accordingly. |
| 745 | */ |
| 746 | static void parse_spl_header(const uint32_t spl_addr) |
| 747 | { |
Andre Przywara | 14a2539 | 2018-10-25 17:23:04 +0800 | [diff] [blame] | 748 | struct boot_file_head *spl = get_spl_header(SPL_ENV_HEADER_VERSION); |
Bernhard Nortmann | e9bbbe8 | 2016-06-09 07:37:35 +0200 | [diff] [blame] | 749 | |
Andre Przywara | 14a2539 | 2018-10-25 17:23:04 +0800 | [diff] [blame] | 750 | if (spl == INVALID_SPL_HEADER) |
Bernhard Nortmann | e9bbbe8 | 2016-06-09 07:37:35 +0200 | [diff] [blame] | 751 | return; |
Andre Przywara | 14a2539 | 2018-10-25 17:23:04 +0800 | [diff] [blame] | 752 | |
Bernhard Nortmann | e9bbbe8 | 2016-06-09 07:37:35 +0200 | [diff] [blame] | 753 | if (!spl->fel_script_address) |
| 754 | return; |
| 755 | |
| 756 | if (spl->fel_uEnv_length != 0) { |
| 757 | /* |
| 758 | * data is expected in uEnv.txt compatible format, so "env |
| 759 | * import -t" the string(s) at fel_script_address right away. |
| 760 | */ |
Andre Przywara | ac4e673 | 2016-09-05 01:32:41 +0100 | [diff] [blame] | 761 | himport_r(&env_htab, (char *)(uintptr_t)spl->fel_script_address, |
Bernhard Nortmann | e9bbbe8 | 2016-06-09 07:37:35 +0200 | [diff] [blame] | 762 | spl->fel_uEnv_length, '\n', H_NOCLEAR, 0, 0, NULL); |
| 763 | return; |
Bernhard Nortmann | ead498a | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 764 | } |
Bernhard Nortmann | e9bbbe8 | 2016-06-09 07:37:35 +0200 | [diff] [blame] | 765 | /* otherwise assume .scr format (mkimage-type script) */ |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 766 | env_set_hex("fel_scriptaddr", spl->fel_script_address); |
Bernhard Nortmann | ead498a | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 767 | } |
Bernhard Nortmann | ead498a | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 768 | |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 769 | /* |
| 770 | * Note this function gets called multiple times. |
| 771 | * It must not make any changes to env variables which already exist. |
| 772 | */ |
| 773 | static void setup_environment(const void *fdt) |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 774 | { |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 775 | char serial_string[17] = { 0 }; |
Hans de Goede | 11d7098 | 2014-11-26 00:04:24 +0100 | [diff] [blame] | 776 | unsigned int sid[4]; |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 777 | uint8_t mac_addr[6]; |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 778 | char ethaddr[16]; |
| 779 | int i, ret; |
Bernhard Nortmann | ead498a | 2015-09-17 18:52:52 +0200 | [diff] [blame] | 780 | |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 781 | ret = sunxi_get_sid(sid); |
Hans de Goede | e5fe548 | 2016-07-29 11:47:03 +0200 | [diff] [blame] | 782 | if (ret == 0 && sid[0] != 0) { |
| 783 | /* |
| 784 | * The single words 1 - 3 of the SID have quite a few bits |
| 785 | * which are the same on many models, so we take a crc32 |
| 786 | * of all 3 words, to get a more unique value. |
| 787 | * |
| 788 | * Note we only do this on newer SoCs as we cannot change |
| 789 | * the algorithm on older SoCs since those have been using |
| 790 | * fixed mac-addresses based on only using word 3 for a |
| 791 | * long time and changing a fixed mac-address with an |
| 792 | * u-boot update is not good. |
| 793 | */ |
| 794 | #if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \ |
| 795 | !defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \ |
| 796 | !defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33) |
| 797 | sid[3] = crc32(0, (unsigned char *)&sid[1], 12); |
| 798 | #endif |
| 799 | |
Hans de Goede | abca843 | 2016-07-27 17:58:06 +0200 | [diff] [blame] | 800 | /* Ensure the NIC specific bytes of the mac are not all 0 */ |
| 801 | if ((sid[3] & 0xffffff) == 0) |
| 802 | sid[3] |= 0x800000; |
| 803 | |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 804 | for (i = 0; i < 4; i++) { |
| 805 | sprintf(ethaddr, "ethernet%d", i); |
| 806 | if (!fdt_get_alias(fdt, ethaddr)) |
| 807 | continue; |
| 808 | |
| 809 | if (i == 0) |
| 810 | strcpy(ethaddr, "ethaddr"); |
| 811 | else |
| 812 | sprintf(ethaddr, "eth%daddr", i); |
| 813 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 814 | if (env_get(ethaddr)) |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 815 | continue; |
| 816 | |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 817 | /* Non OUI / registered MAC address */ |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 818 | mac_addr[0] = (i << 4) | 0x02; |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 819 | mac_addr[1] = (sid[0] >> 0) & 0xff; |
| 820 | mac_addr[2] = (sid[3] >> 24) & 0xff; |
| 821 | mac_addr[3] = (sid[3] >> 16) & 0xff; |
| 822 | mac_addr[4] = (sid[3] >> 8) & 0xff; |
| 823 | mac_addr[5] = (sid[3] >> 0) & 0xff; |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 824 | |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 825 | eth_env_set_enetaddr(ethaddr, mac_addr); |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 826 | } |
| 827 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 828 | if (!env_get("serial#")) { |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 829 | snprintf(serial_string, sizeof(serial_string), |
| 830 | "%08x%08x", sid[0], sid[3]); |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 831 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 832 | env_set("serial#", serial_string); |
Paul Kocialkowski | 9293594 | 2015-03-28 18:35:35 +0100 | [diff] [blame] | 833 | } |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 834 | } |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 835 | } |
| 836 | |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 837 | int misc_init_r(void) |
| 838 | { |
Maxime Ripard | ae56d97 | 2017-08-23 10:08:29 +0200 | [diff] [blame] | 839 | uint boot; |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 840 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 841 | env_set("fel_booted", NULL); |
| 842 | env_set("fel_scriptaddr", NULL); |
Maxime Ripard | 65cefba | 2017-08-23 10:12:22 +0200 | [diff] [blame] | 843 | env_set("mmc_bootdev", NULL); |
Maxime Ripard | ae56d97 | 2017-08-23 10:08:29 +0200 | [diff] [blame] | 844 | |
| 845 | boot = sunxi_get_boot_device(); |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 846 | /* determine if we are running in FEL mode */ |
Maxime Ripard | ae56d97 | 2017-08-23 10:08:29 +0200 | [diff] [blame] | 847 | if (boot == BOOT_DEVICE_BOARD) { |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 848 | env_set("fel_booted", "1"); |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 849 | parse_spl_header(SPL_ADDR); |
Maxime Ripard | 65cefba | 2017-08-23 10:12:22 +0200 | [diff] [blame] | 850 | /* or if we booted from MMC, and which one */ |
| 851 | } else if (boot == BOOT_DEVICE_MMC1) { |
| 852 | env_set("mmc_bootdev", "0"); |
| 853 | } else if (boot == BOOT_DEVICE_MMC2) { |
| 854 | env_set("mmc_bootdev", "1"); |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 855 | } |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 856 | |
| 857 | setup_environment(gd->fdt_blob); |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 858 | |
Icenowy Zheng | f4116b6 | 2017-09-28 22:16:38 +0800 | [diff] [blame] | 859 | #ifdef CONFIG_USB_ETHER |
Maxime Ripard | f54aba3 | 2017-09-06 22:25:03 +0200 | [diff] [blame] | 860 | usb_ether_init(); |
Icenowy Zheng | f4116b6 | 2017-09-28 22:16:38 +0800 | [diff] [blame] | 861 | #endif |
Maxime Ripard | f54aba3 | 2017-09-06 22:25:03 +0200 | [diff] [blame] | 862 | |
Jonathan Liu | abc1aae | 2014-06-14 08:59:09 +0200 | [diff] [blame] | 863 | return 0; |
| 864 | } |
Luc Verhaegen | 4869a8c | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 865 | |
Luc Verhaegen | 4869a8c | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 866 | int ft_board_setup(void *blob, bd_t *bd) |
| 867 | { |
Hans de Goede | 48a234a | 2016-03-22 22:51:52 +0100 | [diff] [blame] | 868 | int __maybe_unused r; |
| 869 | |
Hans de Goede | da0ff7c | 2016-06-26 13:34:42 +0200 | [diff] [blame] | 870 | /* |
| 871 | * Call setup_environment again in case the boot fdt has |
| 872 | * ethernet aliases the u-boot copy does not have. |
| 873 | */ |
| 874 | setup_environment(blob); |
| 875 | |
Luc Verhaegen | 4869a8c | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 876 | #ifdef CONFIG_VIDEO_DT_SIMPLEFB |
Hans de Goede | 48a234a | 2016-03-22 22:51:52 +0100 | [diff] [blame] | 877 | r = sunxi_simplefb_setup(blob); |
| 878 | if (r) |
| 879 | return r; |
Luc Verhaegen | 4869a8c | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 880 | #endif |
Hans de Goede | 48a234a | 2016-03-22 22:51:52 +0100 | [diff] [blame] | 881 | return 0; |
Luc Verhaegen | 4869a8c | 2014-08-13 07:55:07 +0200 | [diff] [blame] | 882 | } |
Andre Przywara | 1bd5ca3 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 883 | |
| 884 | #ifdef CONFIG_SPL_LOAD_FIT |
| 885 | int board_fit_config_name_match(const char *name) |
| 886 | { |
Andre Przywara | 14a2539 | 2018-10-25 17:23:04 +0800 | [diff] [blame] | 887 | struct boot_file_head *spl = get_spl_header(SPL_DT_HEADER_VERSION); |
| 888 | const char *cmp_str = (const char *)spl; |
Andre Przywara | 1bd5ca3 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 889 | |
Andre Przywara | 4f99ea6 | 2017-04-26 01:32:50 +0100 | [diff] [blame] | 890 | /* Check if there is a DT name stored in the SPL header and use that. */ |
Andre Przywara | 14a2539 | 2018-10-25 17:23:04 +0800 | [diff] [blame] | 891 | if (spl != INVALID_SPL_HEADER && spl->dt_name_offset) { |
Andre Przywara | 4f99ea6 | 2017-04-26 01:32:50 +0100 | [diff] [blame] | 892 | cmp_str += spl->dt_name_offset; |
| 893 | } else { |
Andre Przywara | 1bd5ca3 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 894 | #ifdef CONFIG_DEFAULT_DEVICE_TREE |
Andre Przywara | 4f99ea6 | 2017-04-26 01:32:50 +0100 | [diff] [blame] | 895 | cmp_str = CONFIG_DEFAULT_DEVICE_TREE; |
Andre Przywara | 1bd5ca3 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 896 | #else |
Andre Przywara | 4f99ea6 | 2017-04-26 01:32:50 +0100 | [diff] [blame] | 897 | return 0; |
Andre Przywara | 1bd5ca3 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 898 | #endif |
Andre Przywara | 4f99ea6 | 2017-04-26 01:32:50 +0100 | [diff] [blame] | 899 | }; |
Andre Przywara | 1bd5ca3 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 900 | |
Icenowy Zheng | 2a269d3 | 2018-10-25 17:23:02 +0800 | [diff] [blame] | 901 | #ifdef CONFIG_PINE64_DT_SELECTION |
Andre Przywara | 1bd5ca3 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 902 | /* Differentiate the two Pine64 board DTs by their DRAM size. */ |
| 903 | if (strstr(name, "-pine64") && strstr(cmp_str, "-pine64")) { |
| 904 | if ((gd->ram_size > 512 * 1024 * 1024)) |
| 905 | return !strstr(name, "plus"); |
| 906 | else |
| 907 | return !!strstr(name, "plus"); |
| 908 | } else { |
| 909 | return strcmp(name, cmp_str); |
| 910 | } |
Icenowy Zheng | 2a269d3 | 2018-10-25 17:23:02 +0800 | [diff] [blame] | 911 | #endif |
| 912 | return strcmp(name, cmp_str); |
Andre Przywara | 1bd5ca3 | 2017-04-26 01:32:44 +0100 | [diff] [blame] | 913 | } |
| 914 | #endif |