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