blob: dda50b55a50be5438a182ded6c6d157ee9340c24 [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 Goede1f247362014-06-13 22:55:51 +020016#ifdef CONFIG_AXP152_POWER
17#include <axp152.h>
18#endif
Henrik Nordstromaa382ad2014-06-13 22:55:50 +020019#ifdef CONFIG_AXP209_POWER
20#include <axp209.h>
21#endif
Oliver Schinagld3a558d2013-07-26 12:56:58 +020022#ifdef CONFIG_AXP221_POWER
23#include <axp221.h>
24#endif
Ian Campbell6efe3692014-05-05 11:52:26 +010025#include <asm/arch/clock.h>
Jonathan Liuabc1aae2014-06-14 08:59:09 +020026#include <asm/arch/cpu.h>
Luc Verhaegen4869a8c2014-08-13 07:55:07 +020027#include <asm/arch/display.h>
Ian Campbell6efe3692014-05-05 11:52:26 +010028#include <asm/arch/dram.h>
Ian Campbellb4e9f2f2014-05-05 14:42:31 +010029#include <asm/arch/gpio.h>
30#include <asm/arch/mmc.h>
Hans de Goedef494cad2015-01-11 17:17:00 +010031#include <asm/arch/usbc.h>
Jonathan Liuabc1aae2014-06-14 08:59:09 +020032#include <asm/io.h>
Hans de Goedef494cad2015-01-11 17:17:00 +010033#include <linux/usb/musb.h>
Jonathan Liuabc1aae2014-06-14 08:59:09 +020034#include <net.h>
Ian Campbell6efe3692014-05-05 11:52:26 +010035
Hans de Goedea5b4cfe2015-02-16 17:23:25 +010036#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
37/* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */
38int soft_i2c_gpio_sda;
39int soft_i2c_gpio_scl;
40#endif
41
Ian Campbell6efe3692014-05-05 11:52:26 +010042DECLARE_GLOBAL_DATA_PTR;
43
44/* add board specific code here */
45int board_init(void)
46{
47 int id_pfr1;
48
49 gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100);
50
51 asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1));
52 debug("id_pfr1: 0x%08x\n", id_pfr1);
53 /* Generic Timer Extension available? */
54 if ((id_pfr1 >> 16) & 0xf) {
55 debug("Setting CNTFRQ\n");
56 /* CNTFRQ == 24 MHz */
57 asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r"(24000000));
58 }
59
60 return 0;
61}
62
63int dram_init(void)
64{
65 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE);
66
67 return 0;
68}
69
Ian Campbellb4e9f2f2014-05-05 14:42:31 +010070#ifdef CONFIG_GENERIC_MMC
71static void mmc_pinmux_setup(int sdc)
72{
73 unsigned int pin;
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +010074 __maybe_unused int pins;
Ian Campbellb4e9f2f2014-05-05 14:42:31 +010075
76 switch (sdc) {
77 case 0:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +010078 /* SDC0: PF0-PF5 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +010079 for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +010080 sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +010081 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
82 sunxi_gpio_set_drv(pin, 2);
83 }
84 break;
85
86 case 1:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +010087 pins = sunxi_name_to_gpio_bank(CONFIG_MMC1_PINS);
88
89#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
90 if (pins == SUNXI_GPIO_H) {
91 /* SDC1: PH22-PH-27 */
92 for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) {
93 sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1);
94 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
95 sunxi_gpio_set_drv(pin, 2);
96 }
97 } else {
98 /* SDC1: PG0-PG5 */
99 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
100 sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1);
101 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
102 sunxi_gpio_set_drv(pin, 2);
103 }
104 }
105#elif defined(CONFIG_MACH_SUN5I)
106 /* SDC1: PG3-PG8 */
Hans de Goede4dccfd42014-10-03 16:44:57 +0200107 for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100108 sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100109 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
110 sunxi_gpio_set_drv(pin, 2);
111 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100112#elif defined(CONFIG_MACH_SUN6I)
113 /* SDC1: PG0-PG5 */
114 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
115 sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1);
116 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
117 sunxi_gpio_set_drv(pin, 2);
118 }
119#elif defined(CONFIG_MACH_SUN8I)
120 if (pins == SUNXI_GPIO_D) {
121 /* SDC1: PD2-PD7 */
122 for (pin = SUNXI_GPD(2); pin <= SUNXI_GPD(7); pin++) {
123 sunxi_gpio_set_cfgpin(pin, SUN8I_GPD_SDC1);
124 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
125 sunxi_gpio_set_drv(pin, 2);
126 }
127 } else {
128 /* SDC1: PG0-PG5 */
129 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
130 sunxi_gpio_set_cfgpin(pin, SUN8I_GPG_SDC1);
131 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
132 sunxi_gpio_set_drv(pin, 2);
133 }
134 }
135#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100136 break;
137
138 case 2:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100139 pins = sunxi_name_to_gpio_bank(CONFIG_MMC2_PINS);
140
141#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
142 /* SDC2: PC6-PC11 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100143 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100144 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100145 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
146 sunxi_gpio_set_drv(pin, 2);
147 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100148#elif defined(CONFIG_MACH_SUN5I)
149 if (pins == SUNXI_GPIO_E) {
150 /* SDC2: PE4-PE9 */
151 for (pin = SUNXI_GPE(4); pin <= SUNXI_GPD(9); pin++) {
152 sunxi_gpio_set_cfgpin(pin, SUN5I_GPE_SDC2);
153 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
154 sunxi_gpio_set_drv(pin, 2);
155 }
156 } else {
157 /* SDC2: PC6-PC15 */
158 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
159 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
160 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
161 sunxi_gpio_set_drv(pin, 2);
162 }
163 }
164#elif defined(CONFIG_MACH_SUN6I)
165 if (pins == SUNXI_GPIO_A) {
166 /* SDC2: PA9-PA14 */
167 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
168 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC2);
169 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
170 sunxi_gpio_set_drv(pin, 2);
171 }
172 } else {
173 /* SDC2: PC6-PC15, PC24 */
174 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
175 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
176 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
177 sunxi_gpio_set_drv(pin, 2);
178 }
179
180 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
181 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
182 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
183 }
184#elif defined(CONFIG_MACH_SUN8I)
185 /* SDC2: PC5-PC6, PC8-PC16 */
186 for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) {
187 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
188 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
189 sunxi_gpio_set_drv(pin, 2);
190 }
191
192 for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) {
193 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
194 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
195 sunxi_gpio_set_drv(pin, 2);
196 }
197#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100198 break;
199
200 case 3:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100201 pins = sunxi_name_to_gpio_bank(CONFIG_MMC3_PINS);
202
203#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
204 /* SDC3: PI4-PI9 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100205 for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) {
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100206 sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100207 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
208 sunxi_gpio_set_drv(pin, 2);
209 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100210#elif defined(CONFIG_MACH_SUN6I)
211 if (pins == SUNXI_GPIO_A) {
212 /* SDC3: PA9-PA14 */
213 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
214 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC3);
215 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
216 sunxi_gpio_set_drv(pin, 2);
217 }
218 } else {
219 /* SDC3: PC6-PC15, PC24 */
220 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
221 sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3);
222 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
223 sunxi_gpio_set_drv(pin, 2);
224 }
225
226 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3);
227 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
228 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
229 }
230#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100231 break;
232
233 default:
234 printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc);
235 break;
236 }
237}
238
239int board_mmc_init(bd_t *bis)
240{
Hans de Goede63deaa82014-10-02 21:13:54 +0200241 __maybe_unused struct mmc *mmc0, *mmc1;
242 __maybe_unused char buf[512];
243
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100244 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT);
Hans de Goede63deaa82014-10-02 21:13:54 +0200245 mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT);
246 if (!mmc0)
247 return -1;
248
Hans de Goedeaf593e42014-10-02 20:43:50 +0200249#if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100250 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA);
Hans de Goede63deaa82014-10-02 21:13:54 +0200251 mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA);
252 if (!mmc1)
253 return -1;
254#endif
255
256#if CONFIG_MMC_SUNXI_SLOT == 0 && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2
257 /*
258 * Both mmc0 and mmc2 are bootable, figure out where we're booting
259 * from. Try mmc0 first, just like the brom does.
260 */
261 if (mmc_getcd(mmc0) && mmc_init(mmc0) == 0 &&
262 mmc0->block_dev.block_read(0, 16, 1, buf) == 1) {
263 buf[12] = 0;
264 if (strcmp(&buf[4], "eGON.BT0") == 0)
265 return 0;
266 }
267
268 /* no bootable card in mmc0, so we must be booting from mmc2, swap */
269 mmc0->block_dev.dev = 1;
270 mmc1->block_dev.dev = 0;
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100271#endif
272
273 return 0;
274}
275#endif
276
Hans de Goede3352b222014-06-13 22:55:49 +0200277void i2c_init_board(void)
278{
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200279#ifdef CONFIG_I2C0_ENABLE
280#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN5I) || defined(CONFIG_MACH_SUN7I)
281 sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0);
282 sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0);
283 clock_twi_onoff(0, 1);
284#elif defined(CONFIG_MACH_SUN6I)
285 sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0);
286 sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0);
287 clock_twi_onoff(0, 1);
288#elif defined(CONFIG_MACH_SUN8I)
289 sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0);
290 sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0);
Hans de Goede3352b222014-06-13 22:55:49 +0200291 clock_twi_onoff(0, 1);
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200292#endif
293#endif
294
295#ifdef CONFIG_I2C1_ENABLE
296#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
297 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1);
298 sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1);
299 clock_twi_onoff(1, 1);
300#elif defined(CONFIG_MACH_SUN5I)
301 sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1);
302 sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1);
303 clock_twi_onoff(1, 1);
304#elif defined(CONFIG_MACH_SUN6I)
305 sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1);
306 sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1);
307 clock_twi_onoff(1, 1);
308#elif defined(CONFIG_MACH_SUN8I)
309 sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1);
310 sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1);
311 clock_twi_onoff(1, 1);
312#endif
313#endif
314
315#ifdef CONFIG_I2C2_ENABLE
316#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
317 sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN4I_GPB_TWI2);
318 sunxi_gpio_set_cfgpin(SUNXI_GPB(21), SUN4I_GPB_TWI2);
319 clock_twi_onoff(2, 1);
320#elif defined(CONFIG_MACH_SUN5I)
321 sunxi_gpio_set_cfgpin(SUNXI_GPB(17), SUN5I_GPB_TWI2);
322 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN5I_GPB_TWI2);
323 clock_twi_onoff(2, 1);
324#elif defined(CONFIG_MACH_SUN6I)
325 sunxi_gpio_set_cfgpin(SUNXI_GPH(18), SUN6I_GPH_TWI2);
326 sunxi_gpio_set_cfgpin(SUNXI_GPH(19), SUN6I_GPH_TWI2);
327 clock_twi_onoff(2, 1);
328#elif defined(CONFIG_MACH_SUN8I)
329 sunxi_gpio_set_cfgpin(SUNXI_GPE(12), SUN8I_GPE_TWI2);
330 sunxi_gpio_set_cfgpin(SUNXI_GPE(13), SUN8I_GPE_TWI2);
331 clock_twi_onoff(2, 1);
332#endif
333#endif
334
335#ifdef CONFIG_I2C3_ENABLE
336#if defined(CONFIG_MACH_SUN6I)
337 sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUN6I_GPG_TWI3);
338 sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUN6I_GPG_TWI3);
339 clock_twi_onoff(3, 1);
340#elif defined(CONFIG_MACH_SUN7I)
341 sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUN7I_GPI_TWI3);
342 sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUN7I_GPI_TWI3);
343 clock_twi_onoff(3, 1);
344#endif
345#endif
346
347#ifdef CONFIG_I2C4_ENABLE
348#if defined(CONFIG_MACH_SUN7I)
349 sunxi_gpio_set_cfgpin(SUNXI_GPI(2), SUN7I_GPI_TWI4);
350 sunxi_gpio_set_cfgpin(SUNXI_GPI(3), SUN7I_GPI_TWI4);
351 clock_twi_onoff(4, 1);
352#endif
353#endif
354
Hans de Goedea5b4cfe2015-02-16 17:23:25 +0100355#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD)
356 soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA);
357 soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL);
358#endif
Hans de Goede3352b222014-06-13 22:55:49 +0200359}
360
Ian Campbell6efe3692014-05-05 11:52:26 +0100361#ifdef CONFIG_SPL_BUILD
362void sunxi_board_init(void)
363{
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200364 int power_failed = 0;
Ian Campbell6efe3692014-05-05 11:52:26 +0100365 unsigned long ramsize;
366
Hans de Goede1f247362014-06-13 22:55:51 +0200367#ifdef CONFIG_AXP152_POWER
368 power_failed = axp152_init();
369 power_failed |= axp152_set_dcdc2(1400);
370 power_failed |= axp152_set_dcdc3(1500);
371 power_failed |= axp152_set_dcdc4(1250);
372 power_failed |= axp152_set_ldo2(3000);
373#endif
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200374#ifdef CONFIG_AXP209_POWER
375 power_failed |= axp209_init();
376 power_failed |= axp209_set_dcdc2(1400);
377 power_failed |= axp209_set_dcdc3(1250);
378 power_failed |= axp209_set_ldo2(3000);
379 power_failed |= axp209_set_ldo3(2800);
380 power_failed |= axp209_set_ldo4(2800);
381#endif
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200382#ifdef CONFIG_AXP221_POWER
383 power_failed = axp221_init();
Hans de Goede78655482014-12-13 14:12:06 +0100384 power_failed |= axp221_set_dcdc1(CONFIG_AXP221_DCDC1_VOLT);
Hans de Goede013c9ce2014-12-13 14:20:09 +0100385 power_failed |= axp221_set_dcdc2(1200); /* A31:VDD-GPU, A23:VDD-SYS */
386 power_failed |= axp221_set_dcdc3(1200); /* VDD-CPU */
387#ifdef CONFIG_MACH_SUN6I
388 power_failed |= axp221_set_dcdc4(1200); /* A31:VDD-SYS */
389#else
390 power_failed |= axp221_set_dcdc4(0); /* A23:unused */
391#endif
392 power_failed |= axp221_set_dcdc5(1500); /* VCC-DRAM */
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200393 power_failed |= axp221_set_dldo1(CONFIG_AXP221_DLDO1_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200394 power_failed |= axp221_set_dldo4(CONFIG_AXP221_DLDO4_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200395 power_failed |= axp221_set_aldo1(CONFIG_AXP221_ALDO1_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200396 power_failed |= axp221_set_aldo2(CONFIG_AXP221_ALDO2_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200397 power_failed |= axp221_set_aldo3(CONFIG_AXP221_ALDO3_VOLT);
Siarhei Siamashka7e4eb6c2015-01-19 05:23:30 +0200398 power_failed |= axp221_set_eldo(3, CONFIG_AXP221_ELDO3_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200399#endif
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200400
Ian Campbell6efe3692014-05-05 11:52:26 +0100401 printf("DRAM:");
402 ramsize = sunxi_dram_init();
403 printf(" %lu MiB\n", ramsize >> 20);
404 if (!ramsize)
405 hang();
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200406
407 /*
408 * Only clock up the CPU to full speed if we are reasonably
409 * assured it's being powered with suitable core voltage
410 */
411 if (!power_failed)
Iain Paton630df142015-03-28 10:26:38 +0000412 clock_set_pll1(CONFIG_SYS_CLK_FREQ);
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200413 else
414 printf("Failed to set core voltage! Can't set CPU frequency\n");
Ian Campbell6efe3692014-05-05 11:52:26 +0100415}
416#endif
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200417
Hans de Goedef494cad2015-01-11 17:17:00 +0100418#if defined(CONFIG_MUSB_HOST) || defined(CONFIG_MUSB_GADGET)
419static struct musb_hdrc_config musb_config = {
420 .multipoint = 1,
421 .dyn_fifo = 1,
422 .num_eps = 6,
423 .ram_bits = 11,
424};
425
426static struct musb_hdrc_platform_data musb_plat = {
427#if defined(CONFIG_MUSB_HOST)
428 .mode = MUSB_HOST,
429#else
430 .mode = MUSB_PERIPHERAL,
431#endif
432 .config = &musb_config,
433 .power = 250,
434 .platform_ops = &sunxi_musb_ops,
435};
436#endif
437
Paul Kocialkowskidbbccaf2015-03-22 18:07:13 +0100438#ifdef CONFIG_USB_GADGET
439int g_dnl_board_usb_cable_connected(void)
440{
441 return sunxi_usbc_vbus_detect(0);
442}
443#endif
444
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200445#ifdef CONFIG_MISC_INIT_R
446int misc_init_r(void)
447{
Paul Kocialkowski92935942015-03-28 18:35:35 +0100448 char serial_string[17] = { 0 };
Hans de Goede11d70982014-11-26 00:04:24 +0100449 unsigned int sid[4];
Paul Kocialkowski92935942015-03-28 18:35:35 +0100450 uint8_t mac_addr[6];
451 int ret;
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200452
Paul Kocialkowski92935942015-03-28 18:35:35 +0100453 ret = sunxi_get_sid(sid);
454 if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
455 if (!getenv("ethaddr")) {
456 /* Non OUI / registered MAC address */
457 mac_addr[0] = 0x02;
458 mac_addr[1] = (sid[0] >> 0) & 0xff;
459 mac_addr[2] = (sid[3] >> 24) & 0xff;
460 mac_addr[3] = (sid[3] >> 16) & 0xff;
461 mac_addr[4] = (sid[3] >> 8) & 0xff;
462 mac_addr[5] = (sid[3] >> 0) & 0xff;
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200463
Paul Kocialkowski92935942015-03-28 18:35:35 +0100464 eth_setenv_enetaddr("ethaddr", mac_addr);
465 }
466
467 if (!getenv("serial#")) {
468 snprintf(serial_string, sizeof(serial_string),
469 "%08x%08x", sid[0], sid[3]);
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200470
Paul Kocialkowski92935942015-03-28 18:35:35 +0100471 setenv("serial#", serial_string);
472 }
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200473 }
474
Hans de Goedef494cad2015-01-11 17:17:00 +0100475#if defined(CONFIG_MUSB_HOST) || defined(CONFIG_MUSB_GADGET)
476 musb_register(&musb_plat, NULL, (void *)SUNXI_USB0_BASE);
477#endif
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200478 return 0;
479}
480#endif
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200481
482#ifdef CONFIG_OF_BOARD_SETUP
483int ft_board_setup(void *blob, bd_t *bd)
484{
485#ifdef CONFIG_VIDEO_DT_SIMPLEFB
486 return sunxi_simplefb_setup(blob);
487#endif
488}
489#endif /* CONFIG_OF_BOARD_SETUP */