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