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