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