blob: 04a629125e0f429e5fc0be5f2d5d8260ece56b98 [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>
Jelle van der Waa3f3a3092016-02-23 18:47:19 +010035#include <sy8106a.h>
Ian Campbell6efe3692014-05-05 11:52:26 +010036
Hans de Goedea5b4cfe2015-02-16 17:23:25 +010037#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
38/* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
39int soft_i2c_gpio_sda;
40int soft_i2c_gpio_scl;
Hans de Goeded9d05652015-04-23 23:23:50 +020041
42static int soft_i2c_board_init(void)
43{
44 int ret;
45
46 soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA);
47 if (soft_i2c_gpio_sda < 0) {
48 printf("Error invalid soft i2c sda pin: '%s', err %d\n",
49 CONFIG_VIDEO_LCD_PANEL_I2C_SDA, soft_i2c_gpio_sda);
50 return soft_i2c_gpio_sda;
51 }
52 ret = gpio_request(soft_i2c_gpio_sda, "soft-i2c-sda");
53 if (ret) {
54 printf("Error requesting soft i2c sda pin: '%s', err %d\n",
55 CONFIG_VIDEO_LCD_PANEL_I2C_SDA, ret);
56 return ret;
57 }
58
59 soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL);
60 if (soft_i2c_gpio_scl < 0) {
61 printf("Error invalid soft i2c scl pin: '%s', err %d\n",
62 CONFIG_VIDEO_LCD_PANEL_I2C_SCL, soft_i2c_gpio_scl);
63 return soft_i2c_gpio_scl;
64 }
65 ret = gpio_request(soft_i2c_gpio_scl, "soft-i2c-scl");
66 if (ret) {
67 printf("Error requesting soft i2c scl pin: '%s', err %d\n",
68 CONFIG_VIDEO_LCD_PANEL_I2C_SCL, ret);
69 return ret;
70 }
71
72 return 0;
73}
74#else
75static int soft_i2c_board_init(void) { return 0; }
Hans de Goedea5b4cfe2015-02-16 17:23:25 +010076#endif
77
Ian Campbell6efe3692014-05-05 11:52:26 +010078DECLARE_GLOBAL_DATA_PTR;
79
80/* add board specific code here */
81int board_init(void)
82{
Mylène Josserand147c6062017-04-02 12:59:10 +020083 __maybe_unused int id_pfr1, ret, satapwr_pin, macpwr_pin;
Ian Campbell6efe3692014-05-05 11:52:26 +010084
85 gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100);
86
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +020087#ifndef CONFIG_ARM64
Ian Campbell6efe3692014-05-05 11:52:26 +010088 asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1));
89 debug("id_pfr1: 0x%08x\n", id_pfr1);
90 /* Generic Timer Extension available? */
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +020091 if ((id_pfr1 >> CPUID_ARM_GENTIMER_SHIFT) & 0xf) {
92 uint32_t freq;
93
Ian Campbell6efe3692014-05-05 11:52:26 +010094 debug("Setting CNTFRQ\n");
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +020095
96 /*
97 * CNTFRQ is a secure register, so we will crash if we try to
98 * write this from the non-secure world (read is OK, though).
99 * In case some bootcode has already set the correct value,
100 * we avoid the risk of writing to it.
101 */
102 asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r"(freq));
Andre Przywara70c78932017-02-16 01:20:19 +0000103 if (freq != COUNTER_FREQUENCY) {
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200104 debug("arch timer frequency is %d Hz, should be %d, fixing ...\n",
Andre Przywara70c78932017-02-16 01:20:19 +0000105 freq, COUNTER_FREQUENCY);
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200106#ifdef CONFIG_NON_SECURE
107 printf("arch timer frequency is wrong, but cannot adjust it\n");
108#else
109 asm volatile("mcr p15, 0, %0, c14, c0, 0"
Andre Przywara70c78932017-02-16 01:20:19 +0000110 : : "r"(COUNTER_FREQUENCY));
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200111#endif
112 }
Ian Campbell6efe3692014-05-05 11:52:26 +0100113 }
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200114#endif /* !CONFIG_ARM64 */
Ian Campbell6efe3692014-05-05 11:52:26 +0100115
Hans de Goede3ae1d132015-04-25 17:25:14 +0200116 ret = axp_gpio_init();
117 if (ret)
118 return ret;
119
Hans de Goede9c34c3e2016-03-22 20:10:30 +0100120#ifdef CONFIG_SATAPWR
Mylène Josserand628426a2017-04-02 12:59:09 +0200121 satapwr_pin = sunxi_name_to_gpio(CONFIG_SATAPWR);
122 gpio_request(satapwr_pin, "satapwr");
123 gpio_direction_output(satapwr_pin, 1);
Hans de Goede9c34c3e2016-03-22 20:10:30 +0100124#endif
Hans de Goede42cbbe32016-03-17 13:53:03 +0100125#ifdef CONFIG_MACPWR
Mylène Josserand147c6062017-04-02 12:59:10 +0200126 macpwr_pin = sunxi_name_to_gpio(CONFIG_MACPWR);
127 gpio_request(macpwr_pin, "macpwr");
128 gpio_direction_output(macpwr_pin, 1);
Hans de Goede42cbbe32016-03-17 13:53:03 +0100129#endif
130
Hans de Goeded9d05652015-04-23 23:23:50 +0200131 /* Uses dm gpio code so do this here and not in i2c_init_board() */
132 return soft_i2c_board_init();
Ian Campbell6efe3692014-05-05 11:52:26 +0100133}
134
135int dram_init(void)
136{
137 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE);
138
139 return 0;
140}
141
Boris Brezillon57f20382016-06-15 21:09:23 +0200142#if defined(CONFIG_NAND_SUNXI)
Karol Gugala7bea8932015-07-23 14:33:01 +0200143static void nand_pinmux_setup(void)
144{
145 unsigned int pin;
Karol Gugala7bea8932015-07-23 14:33:01 +0200146
Hans de Goeded2236782015-08-15 13:17:49 +0200147 for (pin = SUNXI_GPC(0); pin <= SUNXI_GPC(19); pin++)
Karol Gugala7bea8932015-07-23 14:33:01 +0200148 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND);
149
Hans de Goeded2236782015-08-15 13:17:49 +0200150#if defined CONFIG_MACH_SUN4I || defined CONFIG_MACH_SUN7I
151 for (pin = SUNXI_GPC(20); pin <= SUNXI_GPC(22); pin++)
152 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND);
153#endif
154 /* sun4i / sun7i do have a PC23, but it is not used for nand,
155 * only sun7i has a PC24 */
156#ifdef CONFIG_MACH_SUN7I
Karol Gugala7bea8932015-07-23 14:33:01 +0200157 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_NAND);
Hans de Goeded2236782015-08-15 13:17:49 +0200158#endif
Karol Gugala7bea8932015-07-23 14:33:01 +0200159}
160
161static void nand_clock_setup(void)
162{
163 struct sunxi_ccm_reg *const ccm =
164 (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
Hans de Goedee5561a82015-08-15 11:58:03 +0200165
Karol Gugala7bea8932015-07-23 14:33:01 +0200166 setbits_le32(&ccm->ahb_gate0, (CLK_GATE_OPEN << AHB_GATE_OFFSET_NAND0));
Hans de Goedee5561a82015-08-15 11:58:03 +0200167#ifdef CONFIG_MACH_SUN9I
168 setbits_le32(&ccm->ahb_gate1, (1 << AHB_GATE_OFFSET_DMA));
169#else
170 setbits_le32(&ccm->ahb_gate0, (1 << AHB_GATE_OFFSET_DMA));
171#endif
Karol Gugala7bea8932015-07-23 14:33:01 +0200172 setbits_le32(&ccm->nand0_clk_cfg, CCM_NAND_CTRL_ENABLE | AHB_DIV_1);
173}
Hans de Goede5ed52f62015-08-15 11:55:26 +0200174
175void board_nand_init(void)
176{
177 nand_pinmux_setup();
178 nand_clock_setup();
Boris Brezillon57f20382016-06-15 21:09:23 +0200179#ifndef CONFIG_SPL_BUILD
180 sunxi_nand_init();
181#endif
Hans de Goede5ed52f62015-08-15 11:55:26 +0200182}
Karol Gugala7bea8932015-07-23 14:33:01 +0200183#endif
184
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100185#ifdef CONFIG_GENERIC_MMC
186static void mmc_pinmux_setup(int sdc)
187{
188 unsigned int pin;
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100189 __maybe_unused int pins;
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100190
191 switch (sdc) {
192 case 0:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100193 /* SDC0: PF0-PF5 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100194 for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100195 sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100196 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
197 sunxi_gpio_set_drv(pin, 2);
198 }
199 break;
200
201 case 1:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100202 pins = sunxi_name_to_gpio_bank(CONFIG_MMC1_PINS);
203
Chen-Yu Tsai111bc592016-11-30 16:28:34 +0800204#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \
205 defined(CONFIG_MACH_SUN8I_R40)
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100206 if (pins == SUNXI_GPIO_H) {
207 /* SDC1: PH22-PH-27 */
208 for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) {
209 sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1);
210 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
211 sunxi_gpio_set_drv(pin, 2);
212 }
213 } else {
214 /* SDC1: PG0-PG5 */
215 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
216 sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1);
217 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
218 sunxi_gpio_set_drv(pin, 2);
219 }
220 }
221#elif defined(CONFIG_MACH_SUN5I)
222 /* SDC1: PG3-PG8 */
Hans de Goede4dccfd42014-10-03 16:44:57 +0200223 for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100224 sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100225 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
226 sunxi_gpio_set_drv(pin, 2);
227 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100228#elif defined(CONFIG_MACH_SUN6I)
229 /* SDC1: PG0-PG5 */
230 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
231 sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1);
232 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
233 sunxi_gpio_set_drv(pin, 2);
234 }
235#elif defined(CONFIG_MACH_SUN8I)
236 if (pins == SUNXI_GPIO_D) {
237 /* SDC1: PD2-PD7 */
238 for (pin = SUNXI_GPD(2); pin <= SUNXI_GPD(7); pin++) {
239 sunxi_gpio_set_cfgpin(pin, SUN8I_GPD_SDC1);
240 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
241 sunxi_gpio_set_drv(pin, 2);
242 }
243 } else {
244 /* SDC1: PG0-PG5 */
245 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
246 sunxi_gpio_set_cfgpin(pin, SUN8I_GPG_SDC1);
247 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
248 sunxi_gpio_set_drv(pin, 2);
249 }
250 }
251#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100252 break;
253
254 case 2:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100255 pins = sunxi_name_to_gpio_bank(CONFIG_MMC2_PINS);
256
257#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
258 /* SDC2: PC6-PC11 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100259 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100260 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100261 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
262 sunxi_gpio_set_drv(pin, 2);
263 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100264#elif defined(CONFIG_MACH_SUN5I)
265 if (pins == SUNXI_GPIO_E) {
266 /* SDC2: PE4-PE9 */
267 for (pin = SUNXI_GPE(4); pin <= SUNXI_GPD(9); pin++) {
268 sunxi_gpio_set_cfgpin(pin, SUN5I_GPE_SDC2);
269 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
270 sunxi_gpio_set_drv(pin, 2);
271 }
272 } else {
273 /* SDC2: PC6-PC15 */
274 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
275 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
276 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
277 sunxi_gpio_set_drv(pin, 2);
278 }
279 }
280#elif defined(CONFIG_MACH_SUN6I)
281 if (pins == SUNXI_GPIO_A) {
282 /* SDC2: PA9-PA14 */
283 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
284 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC2);
285 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
286 sunxi_gpio_set_drv(pin, 2);
287 }
288 } else {
289 /* SDC2: PC6-PC15, PC24 */
290 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
291 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
292 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
293 sunxi_gpio_set_drv(pin, 2);
294 }
295
296 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
297 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
298 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
299 }
Chen-Yu Tsai111bc592016-11-30 16:28:34 +0800300#elif defined(CONFIG_MACH_SUN8I_R40)
301 /* SDC2: PC6-PC15, PC24 */
302 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
303 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
304 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
305 sunxi_gpio_set_drv(pin, 2);
306 }
307
308 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
309 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
310 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200311#elif defined(CONFIG_MACH_SUN8I) || defined(CONFIG_MACH_SUN50I)
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100312 /* SDC2: PC5-PC6, PC8-PC16 */
313 for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) {
314 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
315 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
316 sunxi_gpio_set_drv(pin, 2);
317 }
318
319 for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) {
320 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
321 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
322 sunxi_gpio_set_drv(pin, 2);
323 }
Philipp Tomsicha0c7c712016-10-28 18:21:33 +0800324#elif defined(CONFIG_MACH_SUN9I)
325 /* SDC2: PC6-PC16 */
326 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(16); pin++) {
327 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
328 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
329 sunxi_gpio_set_drv(pin, 2);
330 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100331#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100332 break;
333
334 case 3:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100335 pins = sunxi_name_to_gpio_bank(CONFIG_MMC3_PINS);
336
Chen-Yu Tsai111bc592016-11-30 16:28:34 +0800337#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I) || \
338 defined(CONFIG_MACH_SUN8I_R40)
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100339 /* SDC3: PI4-PI9 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100340 for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) {
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100341 sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100342 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
343 sunxi_gpio_set_drv(pin, 2);
344 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100345#elif defined(CONFIG_MACH_SUN6I)
346 if (pins == SUNXI_GPIO_A) {
347 /* SDC3: PA9-PA14 */
348 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
349 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC3);
350 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
351 sunxi_gpio_set_drv(pin, 2);
352 }
353 } else {
354 /* SDC3: PC6-PC15, PC24 */
355 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
356 sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3);
357 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
358 sunxi_gpio_set_drv(pin, 2);
359 }
360
361 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3);
362 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
363 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
364 }
365#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100366 break;
367
368 default:
369 printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc);
370 break;
371 }
372}
373
374int board_mmc_init(bd_t *bis)
375{
Hans de Goede63deaa82014-10-02 21:13:54 +0200376 __maybe_unused struct mmc *mmc0, *mmc1;
377 __maybe_unused char buf[512];
378
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100379 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT);
Hans de Goede63deaa82014-10-02 21:13:54 +0200380 mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT);
381 if (!mmc0)
382 return -1;
383
Hans de Goedeaf593e42014-10-02 20:43:50 +0200384#if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100385 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA);
Hans de Goede63deaa82014-10-02 21:13:54 +0200386 mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA);
387 if (!mmc1)
388 return -1;
389#endif
390
Daniel Kochmański25d9a6d2015-05-29 17:21:00 +0200391#if !defined(CONFIG_SPL_BUILD) && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2
Hans de Goede63deaa82014-10-02 21:13:54 +0200392 /*
Daniel Kochmański25d9a6d2015-05-29 17:21:00 +0200393 * On systems with an emmc (mmc2), figure out if we are booting from
394 * the emmc and if we are make it "mmc dev 0" so that boot.scr, etc.
395 * are searched there first. Note we only do this for u-boot proper,
396 * not for the SPL, see spl_boot_device().
Hans de Goede63deaa82014-10-02 21:13:54 +0200397 */
Hans de Goede6527fa22016-07-09 15:31:47 +0200398 if (readb(SPL_ADDR + 0x28) == SUNXI_BOOTED_FROM_MMC2) {
Daniel Kochmański25d9a6d2015-05-29 17:21:00 +0200399 /* Booting from emmc / mmc2, swap */
Simon Glass2f26fff2016-02-29 15:25:51 -0700400 mmc0->block_dev.devnum = 1;
401 mmc1->block_dev.devnum = 0;
Daniel Kochmański25d9a6d2015-05-29 17:21:00 +0200402 }
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100403#endif
404
405 return 0;
406}
407#endif
408
Hans de Goede3352b222014-06-13 22:55:49 +0200409void i2c_init_board(void)
410{
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200411#ifdef CONFIG_I2C0_ENABLE
Chen-Yu Tsaicc2605e2016-11-30 14:57:32 +0800412#if defined(CONFIG_MACH_SUN4I) || \
413 defined(CONFIG_MACH_SUN5I) || \
414 defined(CONFIG_MACH_SUN7I) || \
415 defined(CONFIG_MACH_SUN8I_R40)
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200416 sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0);
417 sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0);
418 clock_twi_onoff(0, 1);
419#elif defined(CONFIG_MACH_SUN6I)
420 sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0);
421 sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0);
422 clock_twi_onoff(0, 1);
423#elif defined(CONFIG_MACH_SUN8I)
424 sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0);
425 sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0);
Hans de Goede3352b222014-06-13 22:55:49 +0200426 clock_twi_onoff(0, 1);
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200427#endif
428#endif
429
430#ifdef CONFIG_I2C1_ENABLE
Chen-Yu Tsaicc2605e2016-11-30 14:57:32 +0800431#if defined(CONFIG_MACH_SUN4I) || \
432 defined(CONFIG_MACH_SUN7I) || \
433 defined(CONFIG_MACH_SUN8I_R40)
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200434 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1);
435 sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1);
436 clock_twi_onoff(1, 1);
437#elif defined(CONFIG_MACH_SUN5I)
438 sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1);
439 sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1);
440 clock_twi_onoff(1, 1);
441#elif defined(CONFIG_MACH_SUN6I)
442 sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1);
443 sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1);
444 clock_twi_onoff(1, 1);
445#elif defined(CONFIG_MACH_SUN8I)
446 sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1);
447 sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1);
448 clock_twi_onoff(1, 1);
449#endif
450#endif
451
452#ifdef CONFIG_I2C2_ENABLE
Chen-Yu Tsaicc2605e2016-11-30 14:57:32 +0800453#if defined(CONFIG_MACH_SUN4I) || \
454 defined(CONFIG_MACH_SUN7I) || \
455 defined(CONFIG_MACH_SUN8I_R40)
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200456 sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN4I_GPB_TWI2);
457 sunxi_gpio_set_cfgpin(SUNXI_GPB(21), SUN4I_GPB_TWI2);
458 clock_twi_onoff(2, 1);
459#elif defined(CONFIG_MACH_SUN5I)
460 sunxi_gpio_set_cfgpin(SUNXI_GPB(17), SUN5I_GPB_TWI2);
461 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN5I_GPB_TWI2);
462 clock_twi_onoff(2, 1);
463#elif defined(CONFIG_MACH_SUN6I)
464 sunxi_gpio_set_cfgpin(SUNXI_GPH(18), SUN6I_GPH_TWI2);
465 sunxi_gpio_set_cfgpin(SUNXI_GPH(19), SUN6I_GPH_TWI2);
466 clock_twi_onoff(2, 1);
467#elif defined(CONFIG_MACH_SUN8I)
468 sunxi_gpio_set_cfgpin(SUNXI_GPE(12), SUN8I_GPE_TWI2);
469 sunxi_gpio_set_cfgpin(SUNXI_GPE(13), SUN8I_GPE_TWI2);
470 clock_twi_onoff(2, 1);
471#endif
472#endif
473
474#ifdef CONFIG_I2C3_ENABLE
475#if defined(CONFIG_MACH_SUN6I)
476 sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUN6I_GPG_TWI3);
477 sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUN6I_GPG_TWI3);
478 clock_twi_onoff(3, 1);
Chen-Yu Tsaicc2605e2016-11-30 14:57:32 +0800479#elif defined(CONFIG_MACH_SUN7I) || \
480 defined(CONFIG_MACH_SUN8I_R40)
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200481 sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUN7I_GPI_TWI3);
482 sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUN7I_GPI_TWI3);
483 clock_twi_onoff(3, 1);
484#endif
485#endif
486
487#ifdef CONFIG_I2C4_ENABLE
Chen-Yu Tsaicc2605e2016-11-30 14:57:32 +0800488#if defined(CONFIG_MACH_SUN7I) || \
489 defined(CONFIG_MACH_SUN8I_R40)
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200490 sunxi_gpio_set_cfgpin(SUNXI_GPI(2), SUN7I_GPI_TWI4);
491 sunxi_gpio_set_cfgpin(SUNXI_GPI(3), SUN7I_GPI_TWI4);
492 clock_twi_onoff(4, 1);
493#endif
494#endif
Jelle van der Waa8d3d7c12016-01-14 14:06:26 +0100495
496#ifdef CONFIG_R_I2C_ENABLE
497 clock_twi_onoff(5, 1);
498 sunxi_gpio_set_cfgpin(SUNXI_GPL(0), SUN8I_H3_GPL_R_TWI);
499 sunxi_gpio_set_cfgpin(SUNXI_GPL(1), SUN8I_H3_GPL_R_TWI);
500#endif
Hans de Goede3352b222014-06-13 22:55:49 +0200501}
502
Ian Campbell6efe3692014-05-05 11:52:26 +0100503#ifdef CONFIG_SPL_BUILD
504void sunxi_board_init(void)
505{
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200506 int power_failed = 0;
Ian Campbell6efe3692014-05-05 11:52:26 +0100507 unsigned long ramsize;
508
Jelle van der Waa3f3a3092016-02-23 18:47:19 +0100509#ifdef CONFIG_SY8106A_POWER
510 power_failed = sy8106a_set_vout1(CONFIG_SY8106A_VOUT1_VOLT);
511#endif
512
vishnupatekar1895dfd2015-11-29 01:07:22 +0800513#if defined CONFIG_AXP152_POWER || defined CONFIG_AXP209_POWER || \
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800514 defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
515 defined CONFIG_AXP818_POWER
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200516 power_failed = axp_init();
517
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800518#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
519 defined CONFIG_AXP818_POWER
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200520 power_failed |= axp_set_dcdc1(CONFIG_AXP_DCDC1_VOLT);
Hans de Goede1f247362014-06-13 22:55:51 +0200521#endif
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200522 power_failed |= axp_set_dcdc2(CONFIG_AXP_DCDC2_VOLT);
523 power_failed |= axp_set_dcdc3(CONFIG_AXP_DCDC3_VOLT);
vishnupatekar1895dfd2015-11-29 01:07:22 +0800524#if !defined(CONFIG_AXP209_POWER) && !defined(CONFIG_AXP818_POWER)
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200525 power_failed |= axp_set_dcdc4(CONFIG_AXP_DCDC4_VOLT);
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200526#endif
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800527#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
528 defined CONFIG_AXP818_POWER
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200529 power_failed |= axp_set_dcdc5(CONFIG_AXP_DCDC5_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200530#endif
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200531
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800532#if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || \
533 defined CONFIG_AXP818_POWER
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200534 power_failed |= axp_set_aldo1(CONFIG_AXP_ALDO1_VOLT);
535#endif
536 power_failed |= axp_set_aldo2(CONFIG_AXP_ALDO2_VOLT);
Chen-Yu Tsaic05aa392016-01-12 14:42:40 +0800537#if !defined(CONFIG_AXP152_POWER)
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200538 power_failed |= axp_set_aldo3(CONFIG_AXP_ALDO3_VOLT);
539#endif
540#ifdef CONFIG_AXP209_POWER
541 power_failed |= axp_set_aldo4(CONFIG_AXP_ALDO4_VOLT);
542#endif
543
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800544#if defined(CONFIG_AXP221_POWER) || defined(CONFIG_AXP809_POWER) || \
545 defined(CONFIG_AXP818_POWER)
Chen-Yu Tsai2e6911f2016-01-12 14:42:37 +0800546 power_failed |= axp_set_dldo(1, CONFIG_AXP_DLDO1_VOLT);
547 power_failed |= axp_set_dldo(2, CONFIG_AXP_DLDO2_VOLT);
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800548#if !defined CONFIG_AXP809_POWER
Chen-Yu Tsai2e6911f2016-01-12 14:42:37 +0800549 power_failed |= axp_set_dldo(3, CONFIG_AXP_DLDO3_VOLT);
550 power_failed |= axp_set_dldo(4, CONFIG_AXP_DLDO4_VOLT);
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800551#endif
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200552 power_failed |= axp_set_eldo(1, CONFIG_AXP_ELDO1_VOLT);
553 power_failed |= axp_set_eldo(2, CONFIG_AXP_ELDO2_VOLT);
554 power_failed |= axp_set_eldo(3, CONFIG_AXP_ELDO3_VOLT);
555#endif
Chen-Yu Tsaid028fba2016-03-30 00:26:48 +0800556
557#ifdef CONFIG_AXP818_POWER
558 power_failed |= axp_set_fldo(1, CONFIG_AXP_FLDO1_VOLT);
559 power_failed |= axp_set_fldo(2, CONFIG_AXP_FLDO2_VOLT);
560 power_failed |= axp_set_fldo(3, CONFIG_AXP_FLDO3_VOLT);
Chen-Yu Tsaif1e66e72016-05-02 10:28:15 +0800561#endif
562
563#if defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER
Chen-Yu Tsai0e3efd32016-05-02 10:28:12 +0800564 power_failed |= axp_set_sw(IS_ENABLED(CONFIG_AXP_SW_ON));
Chen-Yu Tsaid028fba2016-03-30 00:26:48 +0800565#endif
Hans de Goeded9ee84b2015-10-03 15:18:33 +0200566#endif
Ian Campbell6efe3692014-05-05 11:52:26 +0100567 printf("DRAM:");
568 ramsize = sunxi_dram_init();
Hans de Goede42ad8c52016-06-26 13:56:01 +0200569 printf(" %d MiB\n", (int)(ramsize >> 20));
Ian Campbell6efe3692014-05-05 11:52:26 +0100570 if (!ramsize)
571 hang();
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200572
573 /*
574 * Only clock up the CPU to full speed if we are reasonably
575 * assured it's being powered with suitable core voltage
576 */
577 if (!power_failed)
Iain Paton630df142015-03-28 10:26:38 +0000578 clock_set_pll1(CONFIG_SYS_CLK_FREQ);
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200579 else
580 printf("Failed to set core voltage! Can't set CPU frequency\n");
Ian Campbell6efe3692014-05-05 11:52:26 +0100581}
582#endif
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200583
Paul Kocialkowskidbbccaf2015-03-22 18:07:13 +0100584#ifdef CONFIG_USB_GADGET
585int g_dnl_board_usb_cable_connected(void)
586{
Paul Kocialkowski61c73ee2015-05-16 19:52:10 +0200587 return sunxi_usb_phy_vbus_detect(0);
Paul Kocialkowskidbbccaf2015-03-22 18:07:13 +0100588}
589#endif
590
Paul Kocialkowski99ae0f62015-03-28 18:35:36 +0100591#ifdef CONFIG_SERIAL_TAG
592void get_board_serial(struct tag_serialnr *serialnr)
593{
594 char *serial_string;
595 unsigned long long serial;
596
597 serial_string = getenv("serial#");
598
599 if (serial_string) {
600 serial = simple_strtoull(serial_string, NULL, 16);
601
602 serialnr->high = (unsigned int) (serial >> 32);
603 serialnr->low = (unsigned int) (serial & 0xffffffff);
604 } else {
605 serialnr->high = 0;
606 serialnr->low = 0;
607 }
608}
609#endif
610
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200611/*
612 * Check the SPL header for the "sunxi" variant. If found: parse values
613 * that might have been passed by the loader ("fel" utility), and update
614 * the environment accordingly.
615 */
616static void parse_spl_header(const uint32_t spl_addr)
617{
Siarhei Siamashka26c50fb2016-03-29 17:29:10 +0200618 struct boot_file_head *spl = (void *)(ulong)spl_addr;
Bernhard Nortmanne9bbbe82016-06-09 07:37:35 +0200619 if (memcmp(spl->spl_signature, SPL_SIGNATURE, 3) != 0)
620 return; /* signature mismatch, no usable header */
621
622 uint8_t spl_header_version = spl->spl_signature[3];
623 if (spl_header_version != SPL_HEADER_VERSION) {
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200624 printf("sunxi SPL version mismatch: expected %u, got %u\n",
625 SPL_HEADER_VERSION, spl_header_version);
Bernhard Nortmanne9bbbe82016-06-09 07:37:35 +0200626 return;
627 }
628 if (!spl->fel_script_address)
629 return;
630
631 if (spl->fel_uEnv_length != 0) {
632 /*
633 * data is expected in uEnv.txt compatible format, so "env
634 * import -t" the string(s) at fel_script_address right away.
635 */
Andre Przywaraac4e6732016-09-05 01:32:41 +0100636 himport_r(&env_htab, (char *)(uintptr_t)spl->fel_script_address,
Bernhard Nortmanne9bbbe82016-06-09 07:37:35 +0200637 spl->fel_uEnv_length, '\n', H_NOCLEAR, 0, 0, NULL);
638 return;
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200639 }
Bernhard Nortmanne9bbbe82016-06-09 07:37:35 +0200640 /* otherwise assume .scr format (mkimage-type script) */
641 setenv_hex("fel_scriptaddr", spl->fel_script_address);
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200642}
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200643
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200644/*
645 * Note this function gets called multiple times.
646 * It must not make any changes to env variables which already exist.
647 */
648static void setup_environment(const void *fdt)
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200649{
Paul Kocialkowski92935942015-03-28 18:35:35 +0100650 char serial_string[17] = { 0 };
Hans de Goede11d70982014-11-26 00:04:24 +0100651 unsigned int sid[4];
Paul Kocialkowski92935942015-03-28 18:35:35 +0100652 uint8_t mac_addr[6];
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200653 char ethaddr[16];
654 int i, ret;
Bernhard Nortmannead498a2015-09-17 18:52:52 +0200655
Paul Kocialkowski92935942015-03-28 18:35:35 +0100656 ret = sunxi_get_sid(sid);
Hans de Goedee5fe5482016-07-29 11:47:03 +0200657 if (ret == 0 && sid[0] != 0) {
658 /*
659 * The single words 1 - 3 of the SID have quite a few bits
660 * which are the same on many models, so we take a crc32
661 * of all 3 words, to get a more unique value.
662 *
663 * Note we only do this on newer SoCs as we cannot change
664 * the algorithm on older SoCs since those have been using
665 * fixed mac-addresses based on only using word 3 for a
666 * long time and changing a fixed mac-address with an
667 * u-boot update is not good.
668 */
669#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \
670 !defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \
671 !defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33)
672 sid[3] = crc32(0, (unsigned char *)&sid[1], 12);
673#endif
674
Hans de Goedeabca8432016-07-27 17:58:06 +0200675 /* Ensure the NIC specific bytes of the mac are not all 0 */
676 if ((sid[3] & 0xffffff) == 0)
677 sid[3] |= 0x800000;
678
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200679 for (i = 0; i < 4; i++) {
680 sprintf(ethaddr, "ethernet%d", i);
681 if (!fdt_get_alias(fdt, ethaddr))
682 continue;
683
684 if (i == 0)
685 strcpy(ethaddr, "ethaddr");
686 else
687 sprintf(ethaddr, "eth%daddr", i);
688
689 if (getenv(ethaddr))
690 continue;
691
Paul Kocialkowski92935942015-03-28 18:35:35 +0100692 /* Non OUI / registered MAC address */
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200693 mac_addr[0] = (i << 4) | 0x02;
Paul Kocialkowski92935942015-03-28 18:35:35 +0100694 mac_addr[1] = (sid[0] >> 0) & 0xff;
695 mac_addr[2] = (sid[3] >> 24) & 0xff;
696 mac_addr[3] = (sid[3] >> 16) & 0xff;
697 mac_addr[4] = (sid[3] >> 8) & 0xff;
698 mac_addr[5] = (sid[3] >> 0) & 0xff;
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200699
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200700 eth_setenv_enetaddr(ethaddr, mac_addr);
Paul Kocialkowski92935942015-03-28 18:35:35 +0100701 }
702
703 if (!getenv("serial#")) {
704 snprintf(serial_string, sizeof(serial_string),
705 "%08x%08x", sid[0], sid[3]);
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200706
Paul Kocialkowski92935942015-03-28 18:35:35 +0100707 setenv("serial#", serial_string);
708 }
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200709 }
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200710}
711
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200712int misc_init_r(void)
713{
714 __maybe_unused int ret;
715
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200716 setenv("fel_booted", NULL);
717 setenv("fel_scriptaddr", NULL);
718 /* determine if we are running in FEL mode */
719 if (!is_boot0_magic(SPL_ADDR + 4)) { /* eGON.BT0 */
720 setenv("fel_booted", "1");
721 parse_spl_header(SPL_ADDR);
722 }
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200723
724 setup_environment(gd->fdt_blob);
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200725
Hans de Goede7bfe2bb2015-01-13 19:25:06 +0100726#ifndef CONFIG_MACH_SUN9I
Hans de Goede1168e092015-04-27 16:50:04 +0200727 ret = sunxi_usb_phy_probe();
728 if (ret)
729 return ret;
Hans de Goede7bfe2bb2015-01-13 19:25:06 +0100730#endif
Hans de Goedeea059bf2015-06-17 15:49:26 +0200731 sunxi_musb_board_init();
732
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200733 return 0;
734}
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200735
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200736int ft_board_setup(void *blob, bd_t *bd)
737{
Hans de Goede48a234a2016-03-22 22:51:52 +0100738 int __maybe_unused r;
739
Hans de Goededa0ff7c2016-06-26 13:34:42 +0200740 /*
741 * Call setup_environment again in case the boot fdt has
742 * ethernet aliases the u-boot copy does not have.
743 */
744 setup_environment(blob);
745
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200746#ifdef CONFIG_VIDEO_DT_SIMPLEFB
Hans de Goede48a234a2016-03-22 22:51:52 +0100747 r = sunxi_simplefb_setup(blob);
748 if (r)
749 return r;
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200750#endif
Hans de Goede48a234a2016-03-22 22:51:52 +0100751 return 0;
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200752}