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