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