]> Git Repo - J-u-boot.git/blame - board/sunxi/board.c
Merge tag 'u-boot-imx-master-20250127' of https://gitlab.denx.de/u-boot/custodians...
[J-u-boot.git] / board / sunxi / board.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
cba69eee
IC
2/*
3 * (C) Copyright 2012-2013 Henrik Nordstrom <[email protected]>
4 * (C) Copyright 2013 Luke Kenneth Casson Leighton <[email protected]>
5 *
6 * (C) Copyright 2007-2011
7 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
8 * Tom Cubie <[email protected]>
9 *
10 * Some board init for the Allwinner A10-evb board.
cba69eee
IC
11 */
12
2f8a6db5 13#include <clock_legacy.h>
237050fc 14#include <dm.h>
c7694dd4 15#include <env.h>
db41d65a 16#include <hang.h>
a4fc1e3e 17#include <i2c.h>
4d72caa5 18#include <image.h>
9b4a205f 19#include <init.h>
f7ae49fc 20#include <log.h>
e79c7c88 21#include <mmc.h>
6944aff1 22#include <axp_pmic.h>
237050fc
JT
23#include <generic-phy.h>
24#include <phy-sun4i-usb.h>
cba69eee 25#include <asm/arch/clock.h>
b41d7d05 26#include <asm/arch/cpu.h>
2d7a084b 27#include <asm/arch/display.h>
cba69eee 28#include <asm/arch/dram.h>
e24ea55c 29#include <asm/arch/mmc.h>
8a8b73b6 30#include <asm/arch/prcm.h>
52bcc4f0 31#include <asm/arch/pmic_bus.h>
4a8c7c1f 32#include <asm/arch/spl.h>
e943753d 33#include <asm/arch/sys_proto.h>
401d1c4f 34#include <asm/global_data.h>
c05ed00a 35#include <linux/delay.h>
1e94b46f 36#include <linux/printk.h>
f054f120 37#include <linux/types.h>
d96ebc46
SS
38#ifndef CONFIG_ARM64
39#include <asm/armv7.h>
40#endif
4f7e01c9 41#include <asm/gpio.h>
207ed0a3 42#include <sunxi_gpio.h>
b41d7d05 43#include <asm/io.h>
a740ee91 44#include <u-boot/crc.h>
f3998fdc 45#include <env_internal.h>
b08c8c48 46#include <linux/libfdt.h>
9267ff89 47#include <fdt_support.h>
f62bfa56 48#include <nand.h>
b41d7d05 49#include <net.h>
f4c3523c 50#include <spl.h>
0d8382ae 51#include <sy8106a.h>
5d982856 52#include <asm/setup.h>
8f872bb3 53#include <status_led.h>
cba69eee
IC
54
55DECLARE_GLOBAL_DATA_PTR;
56
acbc7e0a
JS
57void i2c_init_board(void)
58{
59#ifdef CONFIG_I2C0_ENABLE
60#if defined(CONFIG_MACH_SUN4I) || \
61 defined(CONFIG_MACH_SUN5I) || \
62 defined(CONFIG_MACH_SUN7I) || \
63 defined(CONFIG_MACH_SUN8I_R40)
64 sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0);
65 sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0);
66 clock_twi_onoff(0, 1);
67#elif defined(CONFIG_MACH_SUN6I)
68 sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0);
69 sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0);
70 clock_twi_onoff(0, 1);
8c51c652
IZ
71#elif defined(CONFIG_MACH_SUN8I_V3S)
72 sunxi_gpio_set_cfgpin(SUNXI_GPB(6), SUN8I_V3S_GPB_TWI0);
73 sunxi_gpio_set_cfgpin(SUNXI_GPB(7), SUN8I_V3S_GPB_TWI0);
74 clock_twi_onoff(0, 1);
acbc7e0a
JS
75#elif defined(CONFIG_MACH_SUN8I)
76 sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0);
77 sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0);
78 clock_twi_onoff(0, 1);
da1ae590
SM
79#elif defined(CONFIG_MACH_SUN50I)
80 sunxi_gpio_set_cfgpin(SUNXI_GPH(0), SUN50I_GPH_TWI0);
81 sunxi_gpio_set_cfgpin(SUNXI_GPH(1), SUN50I_GPH_TWI0);
82 clock_twi_onoff(0, 1);
acbc7e0a
JS
83#endif
84#endif
85
86#ifdef CONFIG_I2C1_ENABLE
87#if defined(CONFIG_MACH_SUN4I) || \
88 defined(CONFIG_MACH_SUN7I) || \
89 defined(CONFIG_MACH_SUN8I_R40)
90 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1);
91 sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1);
92 clock_twi_onoff(1, 1);
93#elif defined(CONFIG_MACH_SUN5I)
94 sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1);
95 sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1);
96 clock_twi_onoff(1, 1);
97#elif defined(CONFIG_MACH_SUN6I)
98 sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1);
99 sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1);
100 clock_twi_onoff(1, 1);
101#elif defined(CONFIG_MACH_SUN8I)
102 sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1);
103 sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1);
104 clock_twi_onoff(1, 1);
da1ae590
SM
105#elif defined(CONFIG_MACH_SUN50I)
106 sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN50I_GPH_TWI1);
107 sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN50I_GPH_TWI1);
108 clock_twi_onoff(1, 1);
acbc7e0a
JS
109#endif
110#endif
111
acbc7e0a 112#ifdef CONFIG_R_I2C_ENABLE
31a4ac4d
VK
113#ifdef CONFIG_MACH_SUN50I
114 clock_twi_onoff(5, 1);
115 sunxi_gpio_set_cfgpin(SUNXI_GPL(8), SUN50I_GPL_R_TWI);
116 sunxi_gpio_set_cfgpin(SUNXI_GPL(9), SUN50I_GPL_R_TWI);
d0b07c15
JS
117#elif CONFIG_MACH_SUN50I_H616
118 clock_twi_onoff(5, 1);
119 sunxi_gpio_set_cfgpin(SUNXI_GPL(0), SUN50I_H616_GPL_R_TWI);
120 sunxi_gpio_set_cfgpin(SUNXI_GPL(1), SUN50I_H616_GPL_R_TWI);
31a4ac4d 121#else
acbc7e0a
JS
122 clock_twi_onoff(5, 1);
123 sunxi_gpio_set_cfgpin(SUNXI_GPL(0), SUN8I_H3_GPL_R_TWI);
124 sunxi_gpio_set_cfgpin(SUNXI_GPL(1), SUN8I_H3_GPL_R_TWI);
125#endif
31a4ac4d 126#endif
acbc7e0a
JS
127}
128
e42dad41
AP
129/*
130 * Try to use the environment from the boot source first.
131 * For MMC, this means a FAT partition on the boot device (SD or eMMC).
132 * If the raw MMC environment is also enabled, this is tried next.
e008e513 133 * When booting from NAND we try UBI first, then NAND directly.
e42dad41
AP
134 * SPI flash falls back to FAT (on SD card).
135 */
b39117ca
MR
136enum env_location env_get_location(enum env_operation op, int prio)
137{
e008e513
SH
138 if (prio > 1)
139 return ENVL_UNKNOWN;
e42dad41 140
e008e513
SH
141 /* NOWHERE is exclusive, no other option can be defined. */
142 if (IS_ENABLED(CONFIG_ENV_IS_NOWHERE))
143 return ENVL_NOWHERE;
e42dad41
AP
144
145 switch (sunxi_get_boot_device()) {
146 case BOOT_DEVICE_MMC1:
147 case BOOT_DEVICE_MMC2:
e008e513
SH
148 if (prio == 0 && IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
149 return ENVL_FAT;
150 if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC))
151 return ENVL_MMC;
e42dad41
AP
152 break;
153 case BOOT_DEVICE_NAND:
e008e513
SH
154 if (prio == 0 && IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
155 return ENVL_UBI;
e42dad41 156 if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND))
e008e513 157 return ENVL_NAND;
e42dad41
AP
158 break;
159 case BOOT_DEVICE_SPI:
e008e513
SH
160 if (prio == 0 && IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH))
161 return ENVL_SPI_FLASH;
162 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
163 return ENVL_FAT;
e42dad41
AP
164 break;
165 case BOOT_DEVICE_BOARD:
166 break;
b39117ca 167 default:
e42dad41 168 break;
b39117ca 169 }
e42dad41 170
e008e513
SH
171 /*
172 * If we come here for the first time, we *must* return a valid
173 * environment location other than ENVL_UNKNOWN, or the setup sequence
174 * in board_f() will silently hang. This is arguably a bug in
175 * env_init(), but for now pick one environment for which we know for
176 * sure to have a driver for. For all defconfigs this is either FAT
177 * or UBI, or NOWHERE, which is already handled above.
178 */
179 if (prio == 0) {
180 if (IS_ENABLED(CONFIG_ENV_IS_IN_FAT))
e42dad41 181 return ENVL_FAT;
e008e513
SH
182 if (IS_ENABLED(CONFIG_ENV_IS_IN_UBI))
183 return ENVL_UBI;
e42dad41
AP
184 }
185
186 return ENVL_UNKNOWN;
b39117ca 187}
b39117ca 188
1a6828d0 189/* called only from U-Boot proper */
cba69eee
IC
190int board_init(void)
191{
5ad98c57 192 __maybe_unused int id_pfr1, ret;
cba69eee
IC
193
194 gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100);
195
116e1ed1 196#if !defined(CONFIG_ARM64) && !defined(CONFIG_MACH_SUNIV)
cba69eee
IC
197 asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1));
198 debug("id_pfr1: 0x%08x\n", id_pfr1);
199 /* Generic Timer Extension available? */
d96ebc46
SS
200 if ((id_pfr1 >> CPUID_ARM_GENTIMER_SHIFT) & 0xf) {
201 uint32_t freq;
202
cba69eee 203 debug("Setting CNTFRQ\n");
d96ebc46
SS
204
205 /*
206 * CNTFRQ is a secure register, so we will crash if we try to
207 * write this from the non-secure world (read is OK, though).
208 * In case some bootcode has already set the correct value,
209 * we avoid the risk of writing to it.
210 */
211 asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r"(freq));
151a0300 212 if (freq != CONFIG_COUNTER_FREQUENCY) {
d96ebc46 213 debug("arch timer frequency is %d Hz, should be %d, fixing ...\n",
151a0300 214 freq, CONFIG_COUNTER_FREQUENCY);
d96ebc46
SS
215#ifdef CONFIG_NON_SECURE
216 printf("arch timer frequency is wrong, but cannot adjust it\n");
217#else
218 asm volatile("mcr p15, 0, %0, c14, c0, 0"
151a0300 219 : : "r"(CONFIG_COUNTER_FREQUENCY));
d96ebc46
SS
220#endif
221 }
cba69eee 222 }
116e1ed1 223#endif /* !CONFIG_ARM64 && !CONFIG_MACH_SUNIV */
cba69eee 224
2fcf033d
HG
225 ret = axp_gpio_init();
226 if (ret)
227 return ret;
228
e943753d
AP
229 eth_init_board();
230
2421497c 231 return 0;
cba69eee
IC
232}
233
cff5c138
AP
234/*
235 * On older SoCs the SPL is actually at address zero, so using NULL as
236 * an error value does not work.
237 */
238#define INVALID_SPL_HEADER ((void *)~0UL)
239
240static struct boot_file_head * get_spl_header(uint8_t req_version)
241{
242 struct boot_file_head *spl = (void *)(ulong)SPL_ADDR;
243 uint8_t spl_header_version = spl->spl_signature[3];
244
245 /* Is there really the SPL header (still) there? */
246 if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0)
247 return INVALID_SPL_HEADER;
248
249 if (spl_header_version < req_version) {
250 printf("sunxi SPL version mismatch: expected %u, got %u\n",
251 req_version, spl_header_version);
252 return INVALID_SPL_HEADER;
253 }
254
255 return spl;
256}
257
467b7e52
SH
258static const char *get_spl_dt_name(void)
259{
260 struct boot_file_head *spl = get_spl_header(SPL_DT_HEADER_VERSION);
261
262 /* Check if there is a DT name stored in the SPL header. */
263 if (spl != INVALID_SPL_HEADER && spl->dt_name_offset)
264 return (char *)spl + spl->dt_name_offset;
265
266 return NULL;
267}
467b7e52 268
cba69eee
IC
269int dram_init(void)
270{
5776610e
AP
271 struct boot_file_head *spl = get_spl_header(SPL_DRAM_HEADER_VERSION);
272
273 if (spl == INVALID_SPL_HEADER)
274 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0,
275 PHYS_SDRAM_0_SIZE);
276 else
277 gd->ram_size = (phys_addr_t)spl->dram_size << 20;
278
279 if (gd->ram_size > CONFIG_SUNXI_DRAM_MAX_SIZE)
280 gd->ram_size = CONFIG_SUNXI_DRAM_MAX_SIZE;
cba69eee
IC
281
282 return 0;
283}
284
dac3ce97 285#if defined(CONFIG_NAND_SUNXI) && defined(CONFIG_XPL_BUILD)
ad008299
KG
286static void nand_pinmux_setup(void)
287{
288 unsigned int pin;
ad008299 289
022a99d8 290 for (pin = SUNXI_GPC(0); pin <= SUNXI_GPC(19); pin++)
ad008299
KG
291 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND);
292
022a99d8
HG
293#if defined CONFIG_MACH_SUN4I || defined CONFIG_MACH_SUN7I
294 for (pin = SUNXI_GPC(20); pin <= SUNXI_GPC(22); pin++)
295 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND);
296#endif
297 /* sun4i / sun7i do have a PC23, but it is not used for nand,
298 * only sun7i has a PC24 */
299#ifdef CONFIG_MACH_SUN7I
ad008299 300 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_NAND);
022a99d8 301#endif
ad008299
KG
302}
303
304static void nand_clock_setup(void)
305{
306 struct sunxi_ccm_reg *const ccm =
307 (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
31c21471 308
ad008299 309 setbits_le32(&ccm->ahb_gate0, (CLK_GATE_OPEN << AHB_GATE_OFFSET_NAND0));
ba1c98ba
MR
310#if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I || \
311 defined CONFIG_MACH_SUN9I || defined CONFIG_MACH_SUN50I
312 setbits_le32(&ccm->ahb_reset0_cfg, (1 << AHB_GATE_OFFSET_NAND0));
31c21471 313#endif
ad008299
KG
314 setbits_le32(&ccm->nand0_clk_cfg, CCM_NAND_CTRL_ENABLE | AHB_DIV_1);
315}
f62bfa56
HG
316
317void board_nand_init(void)
318{
319 nand_pinmux_setup();
320 nand_clock_setup();
321}
64531496 322#endif /* CONFIG_NAND_SUNXI */
ad008299 323
4aa2ba3a 324#ifdef CONFIG_MMC
e24ea55c
IC
325static void mmc_pinmux_setup(int sdc)
326{
327 unsigned int pin;
328
329 switch (sdc) {
330 case 0:
8deacca9 331 /* SDC0: PF0-PF5 */
e24ea55c 332 for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) {
487b3277 333 sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0);
e24ea55c
IC
334 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
335 sunxi_gpio_set_drv(pin, 2);
336 }
337 break;
338
339 case 1:
8094a4a2
CYT
340#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \
341 defined(CONFIG_MACH_SUN8I_R40)
dda9fa73 342 if (IS_ENABLED(CONFIG_MMC1_PINS_PH)) {
8deacca9
PK
343 /* SDC1: PH22-PH-27 */
344 for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) {
345 sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1);
346 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
347 sunxi_gpio_set_drv(pin, 2);
348 }
349 } else {
350 /* SDC1: PG0-PG5 */
351 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
352 sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1);
353 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
354 sunxi_gpio_set_drv(pin, 2);
355 }
356 }
357#elif defined(CONFIG_MACH_SUN5I)
358 /* SDC1: PG3-PG8 */
bbff84b3 359 for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) {
487b3277 360 sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1);
e24ea55c
IC
361 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
362 sunxi_gpio_set_drv(pin, 2);
363 }
8deacca9
PK
364#elif defined(CONFIG_MACH_SUN6I)
365 /* SDC1: PG0-PG5 */
366 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
367 sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1);
368 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
369 sunxi_gpio_set_drv(pin, 2);
370 }
371#elif defined(CONFIG_MACH_SUN8I)
dda9fa73
SH
372 /* SDC1: PG0-PG5 */
373 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
374 sunxi_gpio_set_cfgpin(pin, SUN8I_GPG_SDC1);
375 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
376 sunxi_gpio_set_drv(pin, 2);
8deacca9
PK
377 }
378#endif
e24ea55c
IC
379 break;
380
381 case 2:
8deacca9
PK
382#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
383 /* SDC2: PC6-PC11 */
e24ea55c 384 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) {
487b3277 385 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
e24ea55c
IC
386 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
387 sunxi_gpio_set_drv(pin, 2);
388 }
8deacca9 389#elif defined(CONFIG_MACH_SUN5I)
dda9fa73
SH
390 /* SDC2: PC6-PC15 */
391 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
392 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
393 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
394 sunxi_gpio_set_drv(pin, 2);
8deacca9
PK
395 }
396#elif defined(CONFIG_MACH_SUN6I)
dda9fa73
SH
397 /* SDC2: PC6-PC15, PC24 */
398 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
399 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
400 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
401 sunxi_gpio_set_drv(pin, 2);
8deacca9 402 }
dda9fa73
SH
403
404 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
405 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
406 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
8094a4a2
CYT
407#elif defined(CONFIG_MACH_SUN8I_R40)
408 /* SDC2: PC6-PC15, PC24 */
409 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
410 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
411 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
412 sunxi_gpio_set_drv(pin, 2);
413 }
414
415 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
416 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
417 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
d96ebc46 418#elif defined(CONFIG_MACH_SUN8I) || defined(CONFIG_MACH_SUN50I)
8deacca9
PK
419 /* SDC2: PC5-PC6, PC8-PC16 */
420 for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) {
421 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
422 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
423 sunxi_gpio_set_drv(pin, 2);
424 }
425
426 for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) {
427 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
428 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
429 sunxi_gpio_set_drv(pin, 2);
42956f1b
IZ
430 }
431#elif defined(CONFIG_MACH_SUN50I_H6)
432 /* SDC2: PC4-PC14 */
433 for (pin = SUNXI_GPC(4); pin <= SUNXI_GPC(14); pin++) {
434 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
435 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
436 sunxi_gpio_set_drv(pin, 2);
8deacca9 437 }
212224ed
AP
438#elif defined(CONFIG_MACH_SUN50I_H616)
439 /* SDC2: PC0-PC1, PC5-PC6, PC8-PC11, PC13-PC16 */
440 for (pin = SUNXI_GPC(0); pin <= SUNXI_GPC(16); pin++) {
441 if (pin > SUNXI_GPC(1) && pin < SUNXI_GPC(5))
442 continue;
443 if (pin == SUNXI_GPC(7) || pin == SUNXI_GPC(12))
444 continue;
445 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
446 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
447 sunxi_gpio_set_drv(pin, 3);
448 }
3ebb4567
PT
449#elif defined(CONFIG_MACH_SUN9I)
450 /* SDC2: PC6-PC16 */
451 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(16); pin++) {
452 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
453 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
454 sunxi_gpio_set_drv(pin, 2);
455 }
5b7c58fb
OS
456#elif defined(CONFIG_MACH_SUN8I_R528)
457 /* SDC2: PC2-PC7 */
458 for (pin = SUNXI_GPC(2); pin <= SUNXI_GPC(7); pin++) {
459 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
460 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
461 sunxi_gpio_set_drv(pin, 2);
462 }
212224ed
AP
463#else
464 puts("ERROR: No pinmux setup defined for MMC2!\n");
8deacca9 465#endif
e24ea55c
IC
466 break;
467
468 case 3:
8094a4a2
CYT
469#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \
470 defined(CONFIG_MACH_SUN8I_R40)
8deacca9 471 /* SDC3: PI4-PI9 */
e24ea55c 472 for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) {
8deacca9 473 sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3);
e24ea55c
IC
474 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
475 sunxi_gpio_set_drv(pin, 2);
476 }
8deacca9 477#elif defined(CONFIG_MACH_SUN6I)
dda9fa73
SH
478 /* SDC3: PC6-PC15, PC24 */
479 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
480 sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3);
481 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
482 sunxi_gpio_set_drv(pin, 2);
8deacca9 483 }
dda9fa73
SH
484
485 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3);
486 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
487 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
8deacca9 488#endif
e24ea55c
IC
489 break;
490
491 default:
492 printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc);
493 break;
494 }
495}
496
b75d8dc5 497int board_mmc_init(struct bd_info *bis)
e24ea55c 498{
ed82586c
AP
499 /*
500 * The BROM always accesses MMC port 0 (typically an SD card), and
501 * most boards seem to have such a slot. The others haven't reported
502 * any problem with unconditionally enabling this in the SPL.
503 */
3ba0a25c 504 if (!IS_ENABLED(CONFIG_UART0_PORT_F)) {
ed82586c
AP
505 mmc_pinmux_setup(0);
506 if (!sunxi_mmc_init(0))
3ba0a25c
SH
507 return -1;
508 }
e79c7c88 509
3ba0a25c
SH
510 if (CONFIG_MMC_SUNXI_SLOT_EXTRA != -1) {
511 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA);
512 if (!sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA))
513 return -1;
514 }
e79c7c88 515
e24ea55c
IC
516 return 0;
517}
1011ebc7 518
bbac4aeb 519#ifdef CONFIG_SYS_MMC_ENV_DEV
1011ebc7
SH
520int mmc_get_env_dev(void)
521{
522 switch (sunxi_get_boot_device()) {
523 case BOOT_DEVICE_MMC1:
524 return 0;
525 case BOOT_DEVICE_MMC2:
526 return 1;
527 default:
528 return CONFIG_SYS_MMC_ENV_DEV;
529 }
530}
531#endif
64531496 532#endif /* CONFIG_MMC */
e24ea55c 533
dac3ce97 534#ifdef CONFIG_XPL_BUILD
5776610e
AP
535
536static void sunxi_spl_store_dram_size(phys_addr_t dram_size)
537{
538 struct boot_file_head *spl = get_spl_header(SPL_DT_HEADER_VERSION);
539
540 if (spl == INVALID_SPL_HEADER)
541 return;
542
543 /* Promote the header version for U-Boot proper, if needed. */
544 if (spl->spl_signature[3] < SPL_DRAM_HEADER_VERSION)
545 spl->spl_signature[3] = SPL_DRAM_HEADER_VERSION;
546
547 spl->dram_size = dram_size >> 20;
548}
549
cba69eee
IC
550void sunxi_board_init(void)
551{
14bc66bd 552 int power_failed = 0;
cba69eee 553
8f872bb3
AF
554#ifdef CONFIG_LED_STATUS
555 if (IS_ENABLED(CONFIG_SPL_DRIVERS_MISC))
556 status_led_init();
557#endif
558
0d8382ae
JW
559#ifdef CONFIG_SY8106A_POWER
560 power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT);
561#endif
562
95ab8fee 563#if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER || \
fbd37d8d 564 defined CONFIG_AXP221_POWER || defined CONFIG_AXP305_POWER || \
d17d051c 565 defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER || \
51bee9b5 566 defined CONFIG_AXP313_POWER || defined CONFIG_AXP717_POWER
6944aff1
HG
567 power_failed = axp_init();
568
52bcc4f0
CM
569 if (IS_ENABLED(CONFIG_AXP_DISABLE_BOOT_ON_POWERON) && !power_failed) {
570 u8 boot_reason;
571
572 pmic_bus_read(AXP_POWER_STATUS, &boot_reason);
573 if (boot_reason & AXP_POWER_STATUS_ALDO_IN) {
574 printf("Power on by plug-in, shutting down.\n");
575 pmic_bus_write(0x32, BIT(7));
576 }
577 }
578
ffb02942 579#ifdef CONFIG_AXP_DCDC1_VOLT
6944aff1 580 power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT);
24289208 581#endif
ffb02942 582#ifdef CONFIG_AXP_DCDC2_VOLT
6944aff1
HG
583 power_failed |= axp_set_dcdc2(CONFIG_AXP_DCDC2_VOLT);
584 power_failed |= axp_set_dcdc3(CONFIG_AXP_DCDC3_VOLT);
fbd37d8d 585#endif
ffb02942 586#ifdef CONFIG_AXP_DCDC4_VOLT
6944aff1 587 power_failed |= axp_set_dcdc4(CONFIG_AXP_DCDC4_VOLT);
5c7f10fd 588#endif
1dadb246
AP
589#ifdef CONFIG_AXP_DCDC5_VOLT
590 power_failed |= axp_set_dcdc5(CONFIG_AXP_DCDC5_VOLT);
591#endif
14bc66bd 592
ffb02942 593#ifdef CONFIG_AXP_ALDO1_VOLT
6944aff1
HG
594 power_failed |= axp_set_aldo1(CONFIG_AXP_ALDO1_VOLT);
595#endif
ffb02942 596#ifdef CONFIG_AXP_ALDO2_VOLT
6944aff1 597 power_failed |= axp_set_aldo2(CONFIG_AXP_ALDO2_VOLT);
fbd37d8d 598#endif
ffb02942 599#ifdef CONFIG_AXP_ALDO3_VOLT
6944aff1
HG
600 power_failed |= axp_set_aldo3(CONFIG_AXP_ALDO3_VOLT);
601#endif
ffb02942 602#ifdef CONFIG_AXP_ALDO4_VOLT
6944aff1
HG
603 power_failed |= axp_set_aldo4(CONFIG_AXP_ALDO4_VOLT);
604#endif
605
ffb02942 606#ifdef CONFIG_AXP_DLDO1_VOLT
3517a27d
CYT
607 power_failed |= axp_set_dldo(1, CONFIG_AXP_DLDO1_VOLT);
608 power_failed |= axp_set_dldo(2, CONFIG_AXP_DLDO2_VOLT);
ffb02942
AP
609#endif
610#ifdef CONFIG_AXP_DLDO3_VOLT
3517a27d
CYT
611 power_failed |= axp_set_dldo(3, CONFIG_AXP_DLDO3_VOLT);
612 power_failed |= axp_set_dldo(4, CONFIG_AXP_DLDO4_VOLT);
795857df 613#endif
ffb02942 614#ifdef CONFIG_AXP_ELDO1_VOLT
6944aff1
HG
615 power_failed |= axp_set_eldo(1, CONFIG_AXP_ELDO1_VOLT);
616 power_failed |= axp_set_eldo(2, CONFIG_AXP_ELDO2_VOLT);
617 power_failed |= axp_set_eldo(3, CONFIG_AXP_ELDO3_VOLT);
618#endif
38491d9c 619
ffb02942 620#ifdef CONFIG_AXP_FLDO1_VOLT
38491d9c
CYT
621 power_failed |= axp_set_fldo(1, CONFIG_AXP_FLDO1_VOLT);
622 power_failed |= axp_set_fldo(2, CONFIG_AXP_FLDO2_VOLT);
623 power_failed |= axp_set_fldo(3, CONFIG_AXP_FLDO3_VOLT);
795857df
CYT
624#endif
625
626#if defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
15278ccb 627 power_failed |= axp_set_sw(IS_ENABLED(CONFIG_AXP_SW_ON));
38491d9c 628#endif
ffb02942 629#endif /* CONFIG_AXPxxx_POWER */
44c214dc
FKP
630 printf("DRAM:");
631 gd->ram_size = sunxi_dram_init();
632 printf(" %d MiB\n", (int)(gd->ram_size >> 20));
633 if (!gd->ram_size)
634 hang();
635
636 sunxi_spl_store_dram_size(gd->ram_size);
5776610e 637
14bc66bd
HN
638 /*
639 * Only clock up the CPU to full speed if we are reasonably
640 * assured it's being powered with suitable core voltage
641 */
642 if (!power_failed)
2f8a6db5 643 clock_set_pll1(get_board_sys_clk());
14bc66bd 644 else
44c214dc 645 printf("Failed to set core voltage! Can't set CPU frequency\n");
cba69eee 646}
dac3ce97 647#endif /* CONFIG_XPL_BUILD */
b41d7d05 648
f1df758d
PK
649#ifdef CONFIG_USB_GADGET
650int g_dnl_board_usb_cable_connected(void)
651{
237050fc
JT
652 struct udevice *dev;
653 struct phy phy;
654 int ret;
655
01311624 656 ret = uclass_get_device(UCLASS_USB_GADGET_GENERIC, 0, &dev);
237050fc
JT
657 if (ret) {
658 pr_err("%s: Cannot find USB device\n", __func__);
659 return ret;
660 }
661
662 ret = generic_phy_get_by_name(dev, "usb", &phy);
663 if (ret) {
664 pr_err("failed to get %s USB PHY\n", dev->name);
665 return ret;
666 }
667
668 ret = generic_phy_init(&phy);
669 if (ret) {
f286e37c 670 pr_debug("failed to init %s USB PHY\n", dev->name);
237050fc
JT
671 return ret;
672 }
673
fbd9207e 674 return sun4i_usb_phy_vbus_detect(&phy);
f1df758d 675}
64531496 676#endif /* CONFIG_USB_GADGET */
f1df758d 677
9f852211
PK
678#ifdef CONFIG_SERIAL_TAG
679void get_board_serial(struct tag_serialnr *serialnr)
680{
681 char *serial_string;
682 unsigned long long serial;
683
00caae6d 684 serial_string = env_get("serial#");
9f852211
PK
685
686 if (serial_string) {
687 serial = simple_strtoull(serial_string, NULL, 16);
688
689 serialnr->high = (unsigned int) (serial >> 32);
690 serialnr->low = (unsigned int) (serial & 0xffffffff);
691 } else {
692 serialnr->high = 0;
693 serialnr->low = 0;
694 }
695}
696#endif
697
af654d14
BN
698/*
699 * Check the SPL header for the "sunxi" variant. If found: parse values
700 * that might have been passed by the loader ("fel" utility), and update
701 * the environment accordingly.
702 */
703static void parse_spl_header(const uint32_t spl_addr)
704{
cff5c138 705 struct boot_file_head *spl = get_spl_header(SPL_ENV_HEADER_VERSION);
320e0570 706
cff5c138 707 if (spl == INVALID_SPL_HEADER)
320e0570 708 return;
cff5c138 709
320e0570
BN
710 if (!spl->fel_script_address)
711 return;
712
713 if (spl->fel_uEnv_length != 0) {
714 /*
715 * data is expected in uEnv.txt compatible format, so "env
716 * import -t" the string(s) at fel_script_address right away.
717 */
5a74a391 718 himport_r(&env_htab, (char *)(uintptr_t)spl->fel_script_address,
320e0570
BN
719 spl->fel_uEnv_length, '\n', H_NOCLEAR, 0, 0, NULL);
720 return;
af654d14 721 }
320e0570 722 /* otherwise assume .scr format (mkimage-type script) */
018f5303 723 env_set_hex("fel_scriptaddr", spl->fel_script_address);
af654d14 724}
af654d14 725
928f4f48
AH
726static bool get_unique_sid(unsigned int *sid)
727{
728 if (sunxi_get_sid(sid) != 0)
729 return false;
730
731 if (!sid[0])
732 return false;
733
734 /*
735 * The single words 1 - 3 of the SID have quite a few bits
736 * which are the same on many models, so we take a crc32
737 * of all 3 words, to get a more unique value.
738 *
739 * Note we only do this on newer SoCs as we cannot change
740 * the algorithm on older SoCs since those have been using
741 * fixed mac-addresses based on only using word 3 for a
742 * long time and changing a fixed mac-address with an
743 * u-boot update is not good.
744 */
745#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \
746 !defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \
747 !defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33)
748 sid[3] = crc32(0, (unsigned char *)&sid[1], 12);
749#endif
750
751 /* Ensure the NIC specific bytes of the mac are not all 0 */
752 if ((sid[3] & 0xffffff) == 0)
753 sid[3] |= 0x800000;
754
755 return true;
756}
757
f221961e
HG
758/*
759 * Note this function gets called multiple times.
760 * It must not make any changes to env variables which already exist.
761 */
762static void setup_environment(const void *fdt)
b41d7d05 763{
8c816573 764 char serial_string[17] = { 0 };
cac5b1cc 765 unsigned int sid[4];
8c816573 766 uint8_t mac_addr[6];
f221961e 767 char ethaddr[16];
928f4f48 768 int i;
3f8ea3b0 769
928f4f48
AH
770 if (!get_unique_sid(sid))
771 return;
97322c3e 772
928f4f48
AH
773 for (i = 0; i < 4; i++) {
774 sprintf(ethaddr, "ethernet%d", i);
775 if (!fdt_get_alias(fdt, ethaddr))
776 continue;
f221961e 777
928f4f48
AH
778 if (i == 0)
779 strcpy(ethaddr, "ethaddr");
780 else
781 sprintf(ethaddr, "eth%daddr", i);
f221961e 782
928f4f48
AH
783 if (env_get(ethaddr))
784 continue;
f221961e 785
928f4f48
AH
786 /* Non OUI / registered MAC address */
787 mac_addr[0] = (i << 4) | 0x02;
788 mac_addr[1] = (sid[0] >> 0) & 0xff;
789 mac_addr[2] = (sid[3] >> 24) & 0xff;
790 mac_addr[3] = (sid[3] >> 16) & 0xff;
791 mac_addr[4] = (sid[3] >> 8) & 0xff;
792 mac_addr[5] = (sid[3] >> 0) & 0xff;
8c816573 793
928f4f48
AH
794 eth_env_set_enetaddr(ethaddr, mac_addr);
795 }
b41d7d05 796
928f4f48
AH
797 if (!env_get("serial#")) {
798 snprintf(serial_string, sizeof(serial_string),
799 "%08x%08x", sid[0], sid[3]);
b41d7d05 800
928f4f48 801 env_set("serial#", serial_string);
b41d7d05 802 }
f221961e
HG
803}
804
f221961e
HG
805int misc_init_r(void)
806{
20f3ee31 807 const char *spl_dt_name;
f4c3523c 808 uint boot;
f221961e 809
382bee57
SG
810 env_set("fel_booted", NULL);
811 env_set("fel_scriptaddr", NULL);
de86fc38 812 env_set("mmc_bootdev", NULL);
f4c3523c
MR
813
814 boot = sunxi_get_boot_device();
f221961e 815 /* determine if we are running in FEL mode */
f4c3523c 816 if (boot == BOOT_DEVICE_BOARD) {
382bee57 817 env_set("fel_booted", "1");
f221961e 818 parse_spl_header(SPL_ADDR);
de86fc38
MR
819 /* or if we booted from MMC, and which one */
820 } else if (boot == BOOT_DEVICE_MMC1) {
821 env_set("mmc_bootdev", "0");
822 } else if (boot == BOOT_DEVICE_MMC2) {
823 env_set("mmc_bootdev", "1");
f221961e 824 }
f221961e 825
20f3ee31
SH
826 /* Set fdtfile to match the FIT configuration chosen in SPL. */
827 spl_dt_name = get_spl_dt_name();
828 if (spl_dt_name) {
829 char *prefix = IS_ENABLED(CONFIG_ARM64) ? "allwinner/" : "";
830 char str[64];
831
832 snprintf(str, sizeof(str), "%s%s.dtb", prefix, spl_dt_name);
833 env_set("fdtfile", str);
834 }
835
f221961e 836 setup_environment(gd->fdt_blob);
b41d7d05 837
92600edb
AS
838 return 0;
839}
840
841int board_late_init(void)
842{
e6ee85a6 843#ifdef CONFIG_USB_ETHER
90dd2f19 844 usb_ether_init();
e6ee85a6 845#endif
90dd2f19 846
b41d7d05
JL
847 return 0;
848}
2d7a084b 849
9267ff89
AH
850static void bluetooth_dt_fixup(void *blob)
851{
852 /* Some devices ship with a Bluetooth controller default address.
853 * Set a valid address through the device tree.
854 */
855 uchar tmp[ETH_ALEN], bdaddr[ETH_ALEN];
856 unsigned int sid[4];
857 int i;
858
859 if (!CONFIG_BLUETOOTH_DT_DEVICE_FIXUP[0])
860 return;
861
862 if (eth_env_get_enetaddr("bdaddr", tmp)) {
863 /* Convert between the binary formats of the corresponding stacks */
864 for (i = 0; i < ETH_ALEN; ++i)
865 bdaddr[i] = tmp[ETH_ALEN - i - 1];
866 } else {
867 if (!get_unique_sid(sid))
868 return;
869
870 bdaddr[0] = ((sid[3] >> 0) & 0xff) ^ 1;
871 bdaddr[1] = (sid[3] >> 8) & 0xff;
872 bdaddr[2] = (sid[3] >> 16) & 0xff;
873 bdaddr[3] = (sid[3] >> 24) & 0xff;
874 bdaddr[4] = (sid[0] >> 0) & 0xff;
875 bdaddr[5] = 0x02;
876 }
877
878 do_fixup_by_compat(blob, CONFIG_BLUETOOTH_DT_DEVICE_FIXUP,
879 "local-bd-address", bdaddr, ETH_ALEN, 1);
880}
881
a4fc1e3e
AS
882#define PINEPHONE_LIS3MDL_I2C_ADDR 0x1e
883#define PINEPHONE_LIS3MDL_I2C_BUS 1 /* I2C1 */
884
885static void board_dt_fixup(void *blob)
886{
887 struct udevice *bus, *dev;
888
889 if (IS_ENABLED(CONFIG_PINEPHONE_DT_SELECTION) &&
890 !fdt_node_check_compatible(blob, 0, "pine64,pinephone-1.2")) {
891 if (!uclass_get_device_by_seq(UCLASS_I2C,
892 PINEPHONE_LIS3MDL_I2C_BUS,
893 &bus)) {
894 dm_i2c_probe(bus, PINEPHONE_LIS3MDL_I2C_ADDR, 0, &dev);
895 fdt_set_status_by_compatible(blob, "st,lis3mdl-magn",
896 dev ? FDT_STATUS_OKAY : FDT_STATUS_DISABLED);
897 fdt_set_status_by_compatible(blob, "voltafield,af8133j",
898 dev ? FDT_STATUS_DISABLED : FDT_STATUS_OKAY);
899 }
900 }
901}
902
b75d8dc5 903int ft_board_setup(void *blob, struct bd_info *bd)
2d7a084b 904{
d75111a7
HG
905 int __maybe_unused r;
906
f221961e 907 /*
2753b072
IZ
908 * Call setup_environment and fdt_fixup_ethernet again
909 * in case the boot fdt has ethernet aliases the u-boot
910 * copy does not have.
f221961e
HG
911 */
912 setup_environment(blob);
2753b072 913 fdt_fixup_ethernet(blob);
f221961e 914
9267ff89 915 bluetooth_dt_fixup(blob);
a4fc1e3e 916 board_dt_fixup(blob);
9267ff89 917
2d7a084b 918#ifdef CONFIG_VIDEO_DT_SIMPLEFB
d75111a7
HG
919 r = sunxi_simplefb_setup(blob);
920 if (r)
921 return r;
2d7a084b 922#endif
d75111a7 923 return 0;
2d7a084b 924}
9ea3c35a
AP
925
926#ifdef CONFIG_SPL_LOAD_FIT
41530cf6
SH
927static void set_spl_dt_name(const char *name)
928{
929 struct boot_file_head *spl = get_spl_header(SPL_ENV_HEADER_VERSION);
930
931 if (spl == INVALID_SPL_HEADER)
932 return;
933
934 /* Promote the header version for U-Boot proper, if needed. */
935 if (spl->spl_signature[3] < SPL_DT_HEADER_VERSION)
936 spl->spl_signature[3] = SPL_DT_HEADER_VERSION;
937
938 strcpy((char *)&spl->string_pool, name);
939 spl->dt_name_offset = offsetof(struct boot_file_head, string_pool);
940}
941
9ea3c35a
AP
942int board_fit_config_name_match(const char *name)
943{
467b7e52 944 const char *best_dt_name = get_spl_dt_name();
41530cf6 945 int ret;
9ea3c35a
AP
946
947#ifdef CONFIG_DEFAULT_DEVICE_TREE
467b7e52 948 if (best_dt_name == NULL)
2fcd7489 949 best_dt_name = CONFIG_DEFAULT_DEVICE_TREE;
9ea3c35a
AP
950#endif
951
467b7e52
SH
952 if (best_dt_name == NULL) {
953 /* No DT name was provided, so accept the first config. */
954 return 0;
955 }
c6c2c85e 956#ifdef CONFIG_PINE64_DT_SELECTION
54ac5aa1
SH
957 if (strstr(best_dt_name, "-pine64-plus")) {
958 /* Differentiate the Pine A64 boards by their DRAM size. */
f054f120 959 if (gd->ram_size == SZ_512M)
54ac5aa1 960 best_dt_name = "sun50i-a64-pine64";
9ea3c35a 961 }
c6c2c85e 962#endif
8a8b73b6
SH
963#ifdef CONFIG_PINEPHONE_DT_SELECTION
964 if (strstr(best_dt_name, "-pinephone")) {
965 /* Differentiate the PinePhone revisions by GPIO inputs. */
966 prcm_apb0_enable(PRCM_APB0_GATE_PIO);
967 sunxi_gpio_set_pull(SUNXI_GPL(6), SUNXI_GPIO_PULL_UP);
968 sunxi_gpio_set_cfgpin(SUNXI_GPL(6), SUNXI_GPIO_INPUT);
969 udelay(100);
970
971 /* PL6 is pulled low by the modem on v1.2. */
972 if (gpio_get_value(SUNXI_GPL(6)) == 0)
973 best_dt_name = "sun50i-a64-pinephone-1.2";
974 else
975 best_dt_name = "sun50i-a64-pinephone-1.1";
976
977 sunxi_gpio_set_cfgpin(SUNXI_GPL(6), SUNXI_GPIO_DISABLE);
978 sunxi_gpio_set_pull(SUNXI_GPL(6), SUNXI_GPIO_PULL_DISABLE);
979 prcm_apb0_disable(PRCM_APB0_GATE_PIO);
980 }
981#endif
982
41530cf6
SH
983 ret = strcmp(name, best_dt_name);
984
985 /*
986 * If one of the FIT configurations matches the most accurate DT name,
987 * update the SPL header to provide that DT name to U-Boot proper.
988 */
989 if (ret == 0)
990 set_spl_dt_name(best_dt_name);
991
992 return ret;
9ea3c35a 993}
64531496 994#endif /* CONFIG_SPL_LOAD_FIT */
This page took 0.717601 seconds and 5 git commands to generate.