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