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