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