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