blob: dcacdf3e626db2fc454a708a2f35d8910cf8556c [file] [log] [blame]
Ian Campbell6efe3692014-05-05 11:52:26 +01001/*
2 * (C) Copyright 2012-2013 Henrik Nordstrom <henrik@henriknordstrom.net>
3 * (C) Copyright 2013 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
4 *
5 * (C) Copyright 2007-2011
6 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
7 * Tom Cubie <tangliang@allwinnertech.com>
8 *
9 * Some board init for the Allwinner A10-evb board.
10 *
11 * SPDX-License-Identifier: GPL-2.0+
12 */
13
14#include <common.h>
Hans de Goede63deaa82014-10-02 21:13:54 +020015#include <mmc.h>
Hans de Goeded9ee84b2015-10-03 15:18:33 +020016#include <axp_pmic.h>
Ian Campbell6efe3692014-05-05 11:52:26 +010017#include <asm/arch/clock.h>
Jonathan Liuabc1aae2014-06-14 08:59:09 +020018#include <asm/arch/cpu.h>
Luc Verhaegen4869a8c2014-08-13 07:55:07 +020019#include <asm/arch/display.h>
Ian Campbell6efe3692014-05-05 11:52:26 +010020#include <asm/arch/dram.h>
Ian Campbellb4e9f2f2014-05-05 14:42:31 +010021#include <asm/arch/gpio.h>
22#include <asm/arch/mmc.h>
Hans de Goedea146c502016-07-09 09:56:56 +020023#include <asm/arch/spl.h>
Hans de Goede26a90052015-04-27 15:05:10 +020024#include <asm/arch/usb_phy.h>
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +020025#ifndef CONFIG_ARM64
26#include <asm/armv7.h>
27#endif
Hans de Goeded9d05652015-04-23 23:23:50 +020028#include <asm/gpio.h>
Jonathan Liuabc1aae2014-06-14 08:59:09 +020029#include <asm/io.h>
Hans de Goedee5fe5482016-07-29 11:47:03 +020030#include <crc.h>
Hans de Goedea146c502016-07-09 09:56:56 +020031#include <environment.h>
Hans de Goededa0ff7c2016-06-26 13:34:42 +020032#include <libfdt.h>
Hans de Goede5ed52f62015-08-15 11:55:26 +020033#include <nand.h>
Jonathan Liuabc1aae2014-06-14 08:59:09 +020034#include <net.h>
Maxime Ripardae56d972017-08-23 10:08:29 +020035#include <spl.h>
Jelle van der Waa3f3a3092016-02-23 18:47:19 +010036#include <sy8106a.h>
Simon Glassd9a766f2017-05-17 08:23:00 -060037#include <asm/setup.h>
Ian Campbell6efe3692014-05-05 11:52:26 +010038
Hans de Goedea5b4cfe2015-02-16 17:23:25 +010039#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
40/* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
41int soft_i2c_gpio_sda;
42int soft_i2c_gpio_scl;
Hans de Goeded9d05652015-04-23 23:23:50 +020043
44static int soft_i2c_board_init(void)
45{
46 int ret;
47
48 soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA);
49 if (soft_i2c_gpio_sda < 0) {
50 printf("Error invalid soft i2c sda pin: '%s', err %d\n",
51 CONFIG_VIDEO_LCD_PANEL_I2C_SDA, soft_i2c_gpio_sda);
52 return soft_i2c_gpio_sda;
53 }
54 ret = gpio_request(soft_i2c_gpio_sda, "soft-i2c-sda");
55 if (ret) {
56 printf("Error requesting soft i2c sda pin: '%s', err %d\n",
57 CONFIG_VIDEO_LCD_PANEL_I2C_SDA, ret);
58 return ret;
59 }
60
61 soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL);
62 if (soft_i2c_gpio_scl < 0) {
63 printf("Error invalid soft i2c scl pin: '%s', err %d\n",
64 CONFIG_VIDEO_LCD_PANEL_I2C_SCL, soft_i2c_gpio_scl);
65 return soft_i2c_gpio_scl;
66 }
67 ret = gpio_request(soft_i2c_gpio_scl, "soft-i2c-scl");
68 if (ret) {
69 printf("Error requesting soft i2c scl pin: '%s', err %d\n",
70 CONFIG_VIDEO_LCD_PANEL_I2C_SCL, ret);
71 return ret;
72 }
73
74 return 0;
75}
76#else
77static int soft_i2c_board_init(void) { return 0; }
Hans de Goedea5b4cfe2015-02-16 17:23:25 +010078#endif
79
Ian Campbell6efe3692014-05-05 11:52:26 +010080DECLARE_GLOBAL_DATA_PTR;
81
Jernej Skrabec07da8802017-04-27 00:03:35 +020082void i2c_init_board(void)
83{
84#ifdef CONFIG_I2C0_ENABLE
85#if defined(CONFIG_MACH_SUN4I) || \
86 defined(CONFIG_MACH_SUN5I) || \
87 defined(CONFIG_MACH_SUN7I) || \
88 defined(CONFIG_MACH_SUN8I_R40)
89 sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0);
90 sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0);
91 clock_twi_onoff(0, 1);
92#elif defined(CONFIG_MACH_SUN6I)
93 sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0);
94 sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0);
95 clock_twi_onoff(0, 1);
96#elif defined(CONFIG_MACH_SUN8I)
97 sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0);
98 sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0);
99 clock_twi_onoff(0, 1);
100#endif
101#endif
102
103#ifdef CONFIG_I2C1_ENABLE
104#if defined(CONFIG_MACH_SUN4I) || \
105 defined(CONFIG_MACH_SUN7I) || \
106 defined(CONFIG_MACH_SUN8I_R40)
107 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1);
108 sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1);
109 clock_twi_onoff(1, 1);
110#elif defined(CONFIG_MACH_SUN5I)
111 sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1);
112 sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1);
113 clock_twi_onoff(1, 1);
114#elif defined(CONFIG_MACH_SUN6I)
115 sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1);
116 sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1);
117 clock_twi_onoff(1, 1);
118#elif defined(CONFIG_MACH_SUN8I)
119 sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1);
120 sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1);
121 clock_twi_onoff(1, 1);
122#endif
123#endif
124
125#ifdef CONFIG_I2C2_ENABLE
126#if defined(CONFIG_MACH_SUN4I) || \
127 defined(CONFIG_MACH_SUN7I) || \
128 defined(CONFIG_MACH_SUN8I_R40)
129 sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN4I_GPB_TWI2);
130 sunxi_gpio_set_cfgpin(SUNXI_GPB(21), SUN4I_GPB_TWI2);
131 clock_twi_onoff(2, 1);
132#elif defined(CONFIG_MACH_SUN5I)
133 sunxi_gpio_set_cfgpin(SUNXI_GPB(17), SUN5I_GPB_TWI2);
134 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN5I_GPB_TWI2);
135 clock_twi_onoff(2, 1);
136#elif defined(CONFIG_MACH_SUN6I)
137 sunxi_gpio_set_cfgpin(SUNXI_GPH(18), SUN6I_GPH_TWI2);
138 sunxi_gpio_set_cfgpin(SUNXI_GPH(19), SUN6I_GPH_TWI2);
139 clock_twi_onoff(2, 1);
140#elif defined(CONFIG_MACH_SUN8I)
141 sunxi_gpio_set_cfgpin(SUNXI_GPE(12), SUN8I_GPE_TWI2);
142 sunxi_gpio_set_cfgpin(SUNXI_GPE(13), SUN8I_GPE_TWI2);
143 clock_twi_onoff(2, 1);
144#endif
145#endif
146
147#ifdef CONFIG_I2C3_ENABLE
148#if defined(CONFIG_MACH_SUN6I)
149 sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUN6I_GPG_TWI3);
150 sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUN6I_GPG_TWI3);
151 clock_twi_onoff(3, 1);
152#elif defined(CONFIG_MACH_SUN7I) || \
153 defined(CONFIG_MACH_SUN8I_R40)
154 sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUN7I_GPI_TWI3);
155 sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUN7I_GPI_TWI3);
156 clock_twi_onoff(3, 1);
157#endif
158#endif
159
160#ifdef CONFIG_I2C4_ENABLE
161#if defined(CONFIG_MACH_SUN7I) || \
162 defined(CONFIG_MACH_SUN8I_R40)
163 sunxi_gpio_set_cfgpin(SUNXI_GPI(2), SUN7I_GPI_TWI4);
164 sunxi_gpio_set_cfgpin(SUNXI_GPI(3), SUN7I_GPI_TWI4);
165 clock_twi_onoff(4, 1);
166#endif
167#endif
168
169#ifdef CONFIG_R_I2C_ENABLE
170 clock_twi_onoff(5, 1);
171 sunxi_gpio_set_cfgpin(SUNXI_GPL(0), SUN8I_H3_GPL_R_TWI);
172 sunxi_gpio_set_cfgpin(SUNXI_GPL(1), SUN8I_H3_GPL_R_TWI);
173#endif
174}
175
Ian Campbell6efe3692014-05-05 11:52:26 +0100176/* add board specific code here */
177int board_init(void)
178{
Mylène Josserand147c6062017-04-02 12:59:10 +0200179 __maybe_unused int id_pfr1, ret, satapwr_pin, macpwr_pin;
Ian Campbell6efe3692014-05-05 11:52:26 +0100180
181 gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100);
182
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200183#ifndef CONFIG_ARM64
Ian Campbell6efe3692014-05-05 11:52:26 +0100184 asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1));
185 debug("id_pfr1: 0x%08x\n", id_pfr1);
186 /* Generic Timer Extension available? */
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200187 if ((id_pfr1 >> CPUID_ARM_GENTIMER_SHIFT) & 0xf) {
188 uint32_t freq;
189
Ian Campbell6efe3692014-05-05 11:52:26 +0100190 debug("Setting CNTFRQ\n");
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200191
192 /*
193 * CNTFRQ is a secure register, so we will crash if we try to
194 * write this from the non-secure world (read is OK, though).
195 * In case some bootcode has already set the correct value,
196 * we avoid the risk of writing to it.
197 */
198 asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r"(freq));
Andre Przywara70c78932017-02-16 01:20:19 +0000199 if (freq != COUNTER_FREQUENCY) {
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200200 debug("arch timer frequency is %d Hz, should be %d, fixing ...\n",
Andre Przywara70c78932017-02-16 01:20:19 +0000201 freq, COUNTER_FREQUENCY);
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200202#ifdef CONFIG_NON_SECURE
203 printf("arch timer frequency is wrong, but cannot adjust it\n");
204#else
205 asm volatile("mcr p15, 0, %0, c14, c0, 0"
Andre Przywara70c78932017-02-16 01:20:19 +0000206 : : "r"(COUNTER_FREQUENCY));
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200207#endif
208 }
Ian Campbell6efe3692014-05-05 11:52:26 +0100209 }
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200210#endif /* !CONFIG_ARM64 */
Ian Campbell6efe3692014-05-05 11:52:26 +0100211
Hans de Goede3ae1d132015-04-25 17:25:14 +0200212 ret = axp_gpio_init();
213 if (ret)
214 return ret;
215
Hans de Goede9c34c3e2016-03-22 20:10:30 +0100216#ifdef CONFIG_SATAPWR
Mylène Josserand628426a2017-04-02 12:59:09 +0200217 satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR);
218 gpio_request(satapwr_pin, "satapwr");
219 gpio_direction_output(satapwr_pin, 1);
Werner Böllmanne58f8302017-11-10 19:14:20 +0530220 /* Give attached sata device time to power-up to avoid link timeouts */
221 mdelay(500);
Hans de Goede9c34c3e2016-03-22 20:10:30 +0100222#endif
Hans de Goede42cbbe32016-03-17 13:53:03 +0100223#ifdef CONFIG_MACPWR
Mylène Josserand147c6062017-04-02 12:59:10 +0200224 macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR);
225 gpio_request(macpwr_pin, "macpwr");
226 gpio_direction_output(macpwr_pin, 1);
Hans de Goede42cbbe32016-03-17 13:53:03 +0100227#endif
228
Jernej Skrabec9220d502017-04-27 00:03:36 +0200229#ifdef CONFIG_DM_I2C
230 /*
231 * Temporary workaround for enabling I2C clocks until proper sunxi DM
232 * clk, reset and pinctrl drivers land.
233 */
234 i2c_init_board();
235#endif
236
Hans de Goeded9d05652015-04-23 23:23:50 +0200237 /* Uses dm gpio code so do this here and not in i2c_init_board() */
238 return soft_i2c_board_init();
Ian Campbell6efe3692014-05-05 11:52:26 +0100239}
240
241int dram_init(void)
242{
243 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE);
244
245 return 0;
246}
247
Boris Brezillon57f20382016-06-15 21:09:23 +0200248#if defined(CONFIG_NAND_SUNXI)
Karol Gugala7bea8932015-07-23 14:33:01 +0200249static void nand_pinmux_setup(void)
250{
251 unsigned int pin;
Karol Gugala7bea8932015-07-23 14:33:01 +0200252
Hans de Goeded2236782015-08-15 13:17:49 +0200253 for (pin = SUNXI_GPC(0); pin <= SUNXI_GPC(19); pin++)
Karol Gugala7bea8932015-07-23 14:33:01 +0200254 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND);
255
Hans de Goeded2236782015-08-15 13:17:49 +0200256#if defined CONFIG_MACH_SUN4I || defined CONFIG_MACH_SUN7I
257 for (pin = SUNXI_GPC(20); pin <= SUNXI_GPC(22); pin++)
258 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND);
259#endif
260 /* sun4i / sun7i do have a PC23, but it is not used for nand,
261 * only sun7i has a PC24 */
262#ifdef CONFIG_MACH_SUN7I
Karol Gugala7bea8932015-07-23 14:33:01 +0200263 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_NAND);
Hans de Goeded2236782015-08-15 13:17:49 +0200264#endif
Karol Gugala7bea8932015-07-23 14:33:01 +0200265}
266
267static void nand_clock_setup(void)
268{
269 struct sunxi_ccm_reg *const ccm =
270 (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
Hans de Goedee5561a82015-08-15 11:58:03 +0200271
Karol Gugala7bea8932015-07-23 14:33:01 +0200272 setbits_le32(&ccm->ahb_gate0, (CLK_GATE_OPEN << AHB_GATE_OFFSET_NAND0));
Hans de Goedee5561a82015-08-15 11:58:03 +0200273#ifdef CONFIG_MACH_SUN9I
274 setbits_le32(&ccm->ahb_gate1, (1 << AHB_GATE_OFFSET_DMA));
275#else
276 setbits_le32(&ccm->ahb_gate0, (1 << AHB_GATE_OFFSET_DMA));
277#endif
Karol Gugala7bea8932015-07-23 14:33:01 +0200278 setbits_le32(&ccm->nand0_clk_cfg, CCM_NAND_CTRL_ENABLE | AHB_DIV_1);
279}
Hans de Goede5ed52f62015-08-15 11:55:26 +0200280
281void board_nand_init(void)
282{
283 nand_pinmux_setup();
284 nand_clock_setup();
Boris Brezillon57f20382016-06-15 21:09:23 +0200285#ifndef CONFIG_SPL_BUILD
286 sunxi_nand_init();
287#endif
Hans de Goede5ed52f62015-08-15 11:55:26 +0200288}
Karol Gugala7bea8932015-07-23 14:33:01 +0200289#endif
290
Masahiro Yamada0a780172017-05-09 20:31:39 +0900291#ifdef CONFIG_MMC
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100292static void mmc_pinmux_setup(int sdc)
293{
294 unsigned int pin;
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100295 __maybe_unused int pins;
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100296
297 switch (sdc) {
298 case 0:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100299 /* SDC0: PF0-PF5 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100300 for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100301 sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100302 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
303 sunxi_gpio_set_drv(pin, 2);
304 }
305 break;
306
307 case 1:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100308 pins = sunxi_name_to_gpio_bank(CONFIG_MMC1_PINS);
309
Chen-Yu Tsai111bc592016-11-30 16:28:34 +0800310#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \
311 defined(CONFIG_MACH_SUN8I_R40)
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100312 if (pins == SUNXI_GPIO_H) {
313 /* SDC1: PH22-PH-27 */
314 for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) {
315 sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1);
316 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
317 sunxi_gpio_set_drv(pin, 2);
318 }
319 } else {
320 /* SDC1: PG0-PG5 */
321 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
322 sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1);
323 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
324 sunxi_gpio_set_drv(pin, 2);
325 }
326 }
327#elif defined(CONFIG_MACH_SUN5I)
328 /* SDC1: PG3-PG8 */
Hans de Goede4dccfd42014-10-03 16:44:57 +0200329 for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100330 sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100331 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
332 sunxi_gpio_set_drv(pin, 2);
333 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100334#elif defined(CONFIG_MACH_SUN6I)
335 /* SDC1: PG0-PG5 */
336 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
337 sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1);
338 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
339 sunxi_gpio_set_drv(pin, 2);
340 }
341#elif defined(CONFIG_MACH_SUN8I)
342 if (pins == SUNXI_GPIO_D) {
343 /* SDC1: PD2-PD7 */
344 for (pin = SUNXI_GPD(2); pin <= SUNXI_GPD(7); pin++) {
345 sunxi_gpio_set_cfgpin(pin, SUN8I_GPD_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, SUN8I_GPG_SDC1);
353 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
354 sunxi_gpio_set_drv(pin, 2);
355 }
356 }
357#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100358 break;
359
360 case 2:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100361 pins = sunxi_name_to_gpio_bank(CONFIG_MMC2_PINS);
362
363#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
364 /* SDC2: PC6-PC11 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100365 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100366 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100367 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
368 sunxi_gpio_set_drv(pin, 2);
369 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100370#elif defined(CONFIG_MACH_SUN5I)
371 if (pins == SUNXI_GPIO_E) {
372 /* SDC2: PE4-PE9 */
373 for (pin = SUNXI_GPE(4); pin <= SUNXI_GPD(9); pin++) {
374 sunxi_gpio_set_cfgpin(pin, SUN5I_GPE_SDC2);
375 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
376 sunxi_gpio_set_drv(pin, 2);
377 }
378 } else {
379 /* SDC2: PC6-PC15 */
380 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
381 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
382 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
383 sunxi_gpio_set_drv(pin, 2);
384 }
385 }
386#elif defined(CONFIG_MACH_SUN6I)
387 if (pins == SUNXI_GPIO_A) {
388 /* SDC2: PA9-PA14 */
389 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
390 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC2);
391 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
392 sunxi_gpio_set_drv(pin, 2);
393 }
394 } else {
395 /* SDC2: PC6-PC15, PC24 */
396 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
397 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
398 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
399 sunxi_gpio_set_drv(pin, 2);
400 }
401
402 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
403 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
404 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
405 }
Chen-Yu Tsai111bc592016-11-30 16:28:34 +0800406#elif defined(CONFIG_MACH_SUN8I_R40)
407 /* SDC2: PC6-PC15, PC24 */
408 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
409 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
410 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
411 sunxi_gpio_set_drv(pin, 2);
412 }
413
414 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
415 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
416 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200417#elif defined(CONFIG_MACH_SUN8I) || defined(CONFIG_MACH_SUN50I)
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100418 /* SDC2: PC5-PC6, PC8-PC16 */
419 for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) {
420 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
421 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
422 sunxi_gpio_set_drv(pin, 2);
423 }
424
425 for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) {
426 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
427 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
428 sunxi_gpio_set_drv(pin, 2);
429 }
Philipp Tomsicha0c7c712016-10-28 18:21:33 +0800430#elif defined(CONFIG_MACH_SUN9I)
431 /* SDC2: PC6-PC16 */
432 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(16); pin++) {
433 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
434 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
435 sunxi_gpio_set_drv(pin, 2);
436 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100437#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100438 break;
439
440 case 3:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100441 pins = sunxi_name_to_gpio_bank(CONFIG_MMC3_PINS);
442
Chen-Yu Tsai111bc592016-11-30 16:28:34 +0800443#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \
444 defined(CONFIG_MACH_SUN8I_R40)
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100445 /* SDC3: PI4-PI9 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100446 for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) {
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100447 sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100448 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
449 sunxi_gpio_set_drv(pin, 2);
450 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100451#elif defined(CONFIG_MACH_SUN6I)
452 if (pins == SUNXI_GPIO_A) {
453 /* SDC3: PA9-PA14 */
454 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
455 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC3);
456 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
457 sunxi_gpio_set_drv(pin, 2);
458 }
459 } else {
460 /* SDC3: PC6-PC15, PC24 */
461 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
462 sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3);
463 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
464 sunxi_gpio_set_drv(pin, 2);
465 }
466
467 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3);
468 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
469 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
470 }
471#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100472 break;
473
474 default:
475 printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc);
476 break;
477 }
478}
479
480int board_mmc_init(bd_t *bis)
481{
Hans de Goede63deaa82014-10-02 21:13:54 +0200482 __maybe_unused struct mmc *mmc0, *mmc1;
483 __maybe_unused char buf[512];
484
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100485 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT);
Hans de Goede63deaa82014-10-02 21:13:54 +0200486 mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT);
487 if (!mmc0)
488 return -1;
489
Hans de Goedeaf593e42014-10-02 20:43:50 +0200490#if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100491 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA);
Hans de Goede63deaa82014-10-02 21:13:54 +0200492 mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA);
493 if (!mmc1)
494 return -1;
495#endif
496
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100497 return 0;
498}
499#endif
500
Ian Campbell6efe3692014-05-05 11:52:26 +0100501#ifdef CONFIG_SPL_BUILD
502void sunxi_board_init(void)
503{
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200504 int power_failed = 0;
Ian Campbell6efe3692014-05-05 11:52:26 +0100505
Jelle van der Waa3f3a3092016-02-23 18:47:19 +0100506#ifdef CONFIG_SY8106A_POWER
507 power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT);
508#endif
509
vishnupatekar1895dfd2015-11-29 01:07:22 +0800510#if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER || \
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800511 defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
512 defined CONFIG_AXP818_POWER
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200513 power_failed = axp_init();
514
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800515#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
516 defined CONFIG_AXP818_POWER
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200517 power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT);
Hans de Goede1f247362014-06-13 22:55:51 +0200518#endif
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200519 power_failed |= axp_set_dcdc2(CONFIG_AXP_DCDC2_VOLT);
520 power_failed |= axp_set_dcdc3(CONFIG_AXP_DCDC3_VOLT);
vishnupatekar1895dfd2015-11-29 01:07:22 +0800521#if !defined(CONFIG_AXP209_POWER) && !defined(CONFIG_AXP818_POWER)
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200522 power_failed |= axp_set_dcdc4(CONFIG_AXP_DCDC4_VOLT);
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200523#endif
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800524#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
525 defined CONFIG_AXP818_POWER
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200526 power_failed |= axp_set_dcdc5(CONFIG_AXP_DCDC5_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200527#endif
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200528
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800529#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
530 defined CONFIG_AXP818_POWER
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200531 power_failed |= axp_set_aldo1(CONFIG_AXP_ALDO1_VOLT);
532#endif
533 power_failed |= axp_set_aldo2(CONFIG_AXP_ALDO2_VOLT);
Chen-Yu Tsaic05aa392016-01-12 14:42:40 +0800534#if !defined(CONFIG_AXP152_POWER)
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200535 power_failed |= axp_set_aldo3(CONFIG_AXP_ALDO3_VOLT);
536#endif
537#ifdef CONFIG_AXP209_POWER
538 power_failed |= axp_set_aldo4(CONFIG_AXP_ALDO4_VOLT);
539#endif
540
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800541#if defined(CONFIG_AXP221_POWER) || defined(CONFIG_AXP809_POWER) || \
542 defined(CONFIG_AXP818_POWER)
Chen-Yu Tsai2e6911f2016-01-12 14:42:37 +0800543 power_failed |= axp_set_dldo(1, CONFIG_AXP_DLDO1_VOLT);
544 power_failed |= axp_set_dldo(2, CONFIG_AXP_DLDO2_VOLT);
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800545#if !defined CONFIG_AXP809_POWER
Chen-Yu Tsai2e6911f2016-01-12 14:42:37 +0800546 power_failed |= axp_set_dldo(3, CONFIG_AXP_DLDO3_VOLT);
547 power_failed |= axp_set_dldo(4, CONFIG_AXP_DLDO4_VOLT);
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800548#endif
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200549 power_failed |= axp_set_eldo(1, CONFIG_AXP_ELDO1_VOLT);
550 power_failed |= axp_set_eldo(2, CONFIG_AXP_ELDO2_VOLT);
551 power_failed |= axp_set_eldo(3, CONFIG_AXP_ELDO3_VOLT);
552#endif
Chen-Yu Tsaid028fba2016-03-30 00:26:48 +0800553
554#ifdef CONFIG_AXP818_POWER
555 power_failed |= axp_set_fldo(1, CONFIG_AXP_FLDO1_VOLT);
556 power_failed |= axp_set_fldo(2, CONFIG_AXP_FLDO2_VOLT);
557 power_failed |= axp_set_fldo(3, CONFIG_AXP_FLDO3_VOLT);
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800558#endif
559
560#if defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
Chen-Yu Tsai0e3efd32016-05-02 10:28:12 +0800561 power_failed |= axp_set_sw(IS_ENABLED(CONFIG_AXP_SW_ON));
Chen-Yu Tsaid028fba2016-03-30 00:26:48 +0800562#endif
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200563#endif
Ian Campbell6efe3692014-05-05 11:52:26 +0100564 printf("DRAM:");
Andre Przywara52f48662017-04-26 01:32:43 +0100565 gd->ram_size = sunxi_dram_init();
566 printf(" %d MiB\n", (int)(gd->ram_size >> 20));
567 if (!gd->ram_size)
Ian Campbell6efe3692014-05-05 11:52:26 +0100568 hang();
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200569
570 /*
571 * Only clock up the CPU to full speed if we are reasonably
572 * assured it's being powered with suitable core voltage
573 */
574 if (!power_failed)
Iain Paton630df142015-03-28 10:26:38 +0000575 clock_set_pll1(CONFIG_SYS_CLK_FREQ);
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200576 else
577 printf("Failed to set core voltage! Can't set CPU frequency\n");
Ian Campbell6efe3692014-05-05 11:52:26 +0100578}
579#endif
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200580
Paul Kocialkowskidbbccaf2015-03-22 18:07:13 +0100581#ifdef CONFIG_USB_GADGET
582int g_dnl_board_usb_cable_connected(void)
583{
Paul Kocialkowski61c73ee2015-05-16 19:52:10 +0200584 return sunxi_usb_phy_vbus_detect(0);
Paul Kocialkowskidbbccaf2015-03-22 18:07:13 +0100585}
586#endif
587
Paul Kocialkowski99ae0f62015-03-28 18:35:36 +0100588#ifdef CONFIG_SERIAL_TAG
589void get_board_serial(struct tag_serialnr *serialnr)
590{
591 char *serial_string;
592 unsigned long long serial;
593
Simon Glass64b723f2017-08-03 12:22:12 -0600594 serial_string = env_get("serial#");
Paul Kocialkowski99ae0f62015-03-28 18:35:36 +0100595
596 if (serial_string) {
597 serial = simple_strtoull(serial_string, NULL, 16);
598
599 serialnr->high = (unsigned int) (serial >> 32);
600 serialnr->low = (unsigned int) (serial & 0xffffffff);
601 } else {
602 serialnr->high = 0;
603 serialnr->low = 0;
604 }
605}
606#endif
607
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200608/*
609 * Check the SPL header for the "sunxi" variant. If found: parse values
610 * that might have been passed by the loader ("fel" utility), and update
611 * the environment accordingly.
612 */
613static void parse_spl_header(const uint32_t spl_addr)
614{
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200615 struct boot_file_head *spl = (void *)(ulong)spl_addr;
Bernhard Nortmanne9bbbe82016-06-09 07:37:35 +0200616 if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0)
617 return; /* signature mismatch, no usable header */
618
619 uint8_t spl_header_version = spl->spl_signature[3];
620 if (spl_header_version != SPL_HEADER_VERSION) {
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200621 printf("sunxi SPL version mismatch: expected %u, got %u\n",
622 SPL_HEADER_VERSION, spl_header_version);
Bernhard Nortmanne9bbbe82016-06-09 07:37:35 +0200623 return;
624 }
625 if (!spl->fel_script_address)
626 return;
627
628 if (spl->fel_uEnv_length != 0) {
629 /*
630 * data is expected in uEnv.txt compatible format, so "env
631 * import -t" the string(s) at fel_script_address right away.
632 */
Andre Przywaraac4e6732016-09-05 01:32:41 +0100633 himport_r(&env_htab, (char *)(uintptr_t)spl->fel_script_address,
Bernhard Nortmanne9bbbe82016-06-09 07:37:35 +0200634 spl->fel_uEnv_length, '\n', H_NOCLEAR, 0, 0, NULL);
635 return;
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200636 }
Bernhard Nortmanne9bbbe82016-06-09 07:37:35 +0200637 /* otherwise assume .scr format (mkimage-type script) */
Simon Glass4d949a22017-08-03 12:22:10 -0600638 env_set_hex("fel_scriptaddr", spl->fel_script_address);
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200639}
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200640
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200641/*
642 * Note this function gets called multiple times.
643 * It must not make any changes to env variables which already exist.
644 */
645static void setup_environment(const void *fdt)
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200646{
Paul Kocialkowski92935942015-03-28 18:35:35 +0100647 char serial_string[17] = { 0 };
Hans de Goede11d70982014-11-26 00:04:24 +0100648 unsigned int sid[4];
Paul Kocialkowski92935942015-03-28 18:35:35 +0100649 uint8_t mac_addr[6];
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200650 char ethaddr[16];
651 int i, ret;
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200652
Paul Kocialkowski92935942015-03-28 18:35:35 +0100653 ret = sunxi_get_sid(sid);
Hans de Goedee5fe5482016-07-29 11:47:03 +0200654 if (ret == 0 && sid[0] != 0) {
655 /*
656 * The single words 1 - 3 of the SID have quite a few bits
657 * which are the same on many models, so we take a crc32
658 * of all 3 words, to get a more unique value.
659 *
660 * Note we only do this on newer SoCs as we cannot change
661 * the algorithm on older SoCs since those have been using
662 * fixed mac-addresses based on only using word 3 for a
663 * long time and changing a fixed mac-address with an
664 * u-boot update is not good.
665 */
666#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \
667 !defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \
668 !defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33)
669 sid[3] = crc32(0, (unsigned char *)&sid[1], 12);
670#endif
671
Hans de Goedeabca8432016-07-27 17:58:06 +0200672 /* Ensure the NIC specific bytes of the mac are not all 0 */
673 if ((sid[3] & 0xffffff) == 0)
674 sid[3] |= 0x800000;
675
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200676 for (i = 0; i < 4; i++) {
677 sprintf(ethaddr, "ethernet%d", i);
678 if (!fdt_get_alias(fdt, ethaddr))
679 continue;
680
681 if (i == 0)
682 strcpy(ethaddr, "ethaddr");
683 else
684 sprintf(ethaddr, "eth%daddr", i);
685
Simon Glass64b723f2017-08-03 12:22:12 -0600686 if (env_get(ethaddr))
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200687 continue;
688
Paul Kocialkowski92935942015-03-28 18:35:35 +0100689 /* Non OUI / registered MAC address */
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200690 mac_addr[0] = (i << 4) | 0x02;
Paul Kocialkowski92935942015-03-28 18:35:35 +0100691 mac_addr[1] = (sid[0] >> 0) & 0xff;
692 mac_addr[2] = (sid[3] >> 24) & 0xff;
693 mac_addr[3] = (sid[3] >> 16) & 0xff;
694 mac_addr[4] = (sid[3] >> 8) & 0xff;
695 mac_addr[5] = (sid[3] >> 0) & 0xff;
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200696
Simon Glass8551d552017-08-03 12:22:11 -0600697 eth_env_set_enetaddr(ethaddr, mac_addr);
Paul Kocialkowski92935942015-03-28 18:35:35 +0100698 }
699
Simon Glass64b723f2017-08-03 12:22:12 -0600700 if (!env_get("serial#")) {
Paul Kocialkowski92935942015-03-28 18:35:35 +0100701 snprintf(serial_string, sizeof(serial_string),
702 "%08x%08x", sid[0], sid[3]);
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200703
Simon Glass6a38e412017-08-03 12:22:09 -0600704 env_set("serial#", serial_string);
Paul Kocialkowski92935942015-03-28 18:35:35 +0100705 }
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200706 }
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200707}
708
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200709int misc_init_r(void)
710{
711 __maybe_unused int ret;
Maxime Ripardae56d972017-08-23 10:08:29 +0200712 uint boot;
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200713
Simon Glass6a38e412017-08-03 12:22:09 -0600714 env_set("fel_booted", NULL);
715 env_set("fel_scriptaddr", NULL);
Maxime Ripard65cefba2017-08-23 10:12:22 +0200716 env_set("mmc_bootdev", NULL);
Maxime Ripardae56d972017-08-23 10:08:29 +0200717
718 boot = sunxi_get_boot_device();
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200719 /* determine if we are running in FEL mode */
Maxime Ripardae56d972017-08-23 10:08:29 +0200720 if (boot == BOOT_DEVICE_BOARD) {
Simon Glass6a38e412017-08-03 12:22:09 -0600721 env_set("fel_booted", "1");
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200722 parse_spl_header(SPL_ADDR);
Maxime Ripard65cefba2017-08-23 10:12:22 +0200723 /* or if we booted from MMC, and which one */
724 } else if (boot == BOOT_DEVICE_MMC1) {
725 env_set("mmc_bootdev", "0");
726 } else if (boot == BOOT_DEVICE_MMC2) {
727 env_set("mmc_bootdev", "1");
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200728 }
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200729
730 setup_environment(gd->fdt_blob);
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200731
Hans de Goede7bfe2bb2015-01-13 19:25:06 +0100732#ifndef CONFIG_MACH_SUN9I
Hans de Goede1168e092015-04-27 16:50:04 +0200733 ret = sunxi_usb_phy_probe();
734 if (ret)
735 return ret;
Hans de Goede7bfe2bb2015-01-13 19:25:06 +0100736#endif
Hans de Goedeea059bf2015-06-17 15:49:26 +0200737
Icenowy Zhengf4116b62017-09-28 22:16:38 +0800738#ifdef CONFIG_USB_ETHER
Maxime Ripardf54aba32017-09-06 22:25:03 +0200739 usb_ether_init();
Icenowy Zhengf4116b62017-09-28 22:16:38 +0800740#endif
Maxime Ripardf54aba32017-09-06 22:25:03 +0200741
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200742 return 0;
743}
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200744
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200745int ft_board_setup(void *blob, bd_t *bd)
746{
Hans de Goede48a234a2016-03-22 22:51:52 +0100747 int __maybe_unused r;
748
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200749 /*
750 * Call setup_environment again in case the boot fdt has
751 * ethernet aliases the u-boot copy does not have.
752 */
753 setup_environment(blob);
754
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200755#ifdef CONFIG_VIDEO_DT_SIMPLEFB
Hans de Goede48a234a2016-03-22 22:51:52 +0100756 r = sunxi_simplefb_setup(blob);
757 if (r)
758 return r;
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200759#endif
Hans de Goede48a234a2016-03-22 22:51:52 +0100760 return 0;
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200761}
Andre Przywara1bd5ca32017-04-26 01:32:44 +0100762
763#ifdef CONFIG_SPL_LOAD_FIT
764int board_fit_config_name_match(const char *name)
765{
Andre Przywara4f99ea62017-04-26 01:32:50 +0100766 struct boot_file_head *spl = (void *)(ulong)SPL_ADDR;
767 const char *cmp_str = (void *)(ulong)SPL_ADDR;
Andre Przywara1bd5ca32017-04-26 01:32:44 +0100768
Andre Przywara4f99ea62017-04-26 01:32:50 +0100769 /* Check if there is a DT name stored in the SPL header and use that. */
770 if (spl->dt_name_offset) {
771 cmp_str += spl->dt_name_offset;
772 } else {
Andre Przywara1bd5ca32017-04-26 01:32:44 +0100773#ifdef CONFIG_DEFAULT_DEVICE_TREE
Andre Przywara4f99ea62017-04-26 01:32:50 +0100774 cmp_str = CONFIG_DEFAULT_DEVICE_TREE;
Andre Przywara1bd5ca32017-04-26 01:32:44 +0100775#else
Andre Przywara4f99ea62017-04-26 01:32:50 +0100776 return 0;
Andre Przywara1bd5ca32017-04-26 01:32:44 +0100777#endif
Andre Przywara4f99ea62017-04-26 01:32:50 +0100778 };
Andre Przywara1bd5ca32017-04-26 01:32:44 +0100779
780/* Differentiate the two Pine64 board DTs by their DRAM size. */
781 if (strstr(name, "-pine64") && strstr(cmp_str, "-pine64")) {
782 if ((gd->ram_size > 512 * 1024 * 1024))
783 return !strstr(name, "plus");
784 else
785 return !!strstr(name, "plus");
786 } else {
787 return strcmp(name, cmp_str);
788 }
789}
790#endif