blob: afed6a31cab6732f334d8dba2272730ee8306ac4 [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 Goede26a90052015-04-27 15:05:10 +020031#include <asm/arch/usb_phy.h>
Hans de Goeded9d05652015-04-23 23:23:50 +020032#include <asm/gpio.h>
Jonathan Liuabc1aae2014-06-14 08:59:09 +020033#include <asm/io.h>
34#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;
Hans de Goeded9d05652015-04-23 23:23:50 +020040
41static int soft_i2c_board_init(void)
42{
43 int ret;
44
45 soft_i2c_gpio_sda = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SDA);
46 if (soft_i2c_gpio_sda < 0) {
47 printf("Error invalid soft i2c sda pin: '%s', err %d\n",
48 CONFIG_VIDEO_LCD_PANEL_I2C_SDA, soft_i2c_gpio_sda);
49 return soft_i2c_gpio_sda;
50 }
51 ret = gpio_request(soft_i2c_gpio_sda, "soft-i2c-sda");
52 if (ret) {
53 printf("Error requesting soft i2c sda pin: '%s', err %d\n",
54 CONFIG_VIDEO_LCD_PANEL_I2C_SDA, ret);
55 return ret;
56 }
57
58 soft_i2c_gpio_scl = sunxi_name_to_gpio(CONFIG_VIDEO_LCD_PANEL_I2C_SCL);
59 if (soft_i2c_gpio_scl < 0) {
60 printf("Error invalid soft i2c scl pin: '%s', err %d\n",
61 CONFIG_VIDEO_LCD_PANEL_I2C_SCL, soft_i2c_gpio_scl);
62 return soft_i2c_gpio_scl;
63 }
64 ret = gpio_request(soft_i2c_gpio_scl, "soft-i2c-scl");
65 if (ret) {
66 printf("Error requesting soft i2c scl pin: '%s', err %d\n",
67 CONFIG_VIDEO_LCD_PANEL_I2C_SCL, ret);
68 return ret;
69 }
70
71 return 0;
72}
73#else
74static int soft_i2c_board_init(void) { return 0; }
Hans de Goedea5b4cfe2015-02-16 17:23:25 +010075#endif
76
Ian Campbell6efe3692014-05-05 11:52:26 +010077DECLARE_GLOBAL_DATA_PTR;
78
79/* add board specific code here */
80int board_init(void)
81{
Hans de Goede3ae1d132015-04-25 17:25:14 +020082 int id_pfr1, ret;
Ian Campbell6efe3692014-05-05 11:52:26 +010083
84 gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100);
85
86 asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1));
87 debug("id_pfr1: 0x%08x\n", id_pfr1);
88 /* Generic Timer Extension available? */
89 if ((id_pfr1 >> 16) & 0xf) {
90 debug("Setting CNTFRQ\n");
91 /* CNTFRQ == 24 MHz */
92 asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r"(24000000));
93 }
94
Hans de Goede3ae1d132015-04-25 17:25:14 +020095 ret = axp_gpio_init();
96 if (ret)
97 return ret;
98
Hans de Goeded9d05652015-04-23 23:23:50 +020099 /* Uses dm gpio code so do this here and not in i2c_init_board() */
100 return soft_i2c_board_init();
Ian Campbell6efe3692014-05-05 11:52:26 +0100101}
102
103int dram_init(void)
104{
105 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE);
106
107 return 0;
108}
109
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100110#ifdef CONFIG_GENERIC_MMC
111static void mmc_pinmux_setup(int sdc)
112{
113 unsigned int pin;
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100114 __maybe_unused int pins;
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100115
116 switch (sdc) {
117 case 0:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100118 /* SDC0: PF0-PF5 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100119 for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100120 sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100121 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
122 sunxi_gpio_set_drv(pin, 2);
123 }
124 break;
125
126 case 1:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100127 pins = sunxi_name_to_gpio_bank(CONFIG_MMC1_PINS);
128
129#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
130 if (pins == SUNXI_GPIO_H) {
131 /* SDC1: PH22-PH-27 */
132 for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) {
133 sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1);
134 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
135 sunxi_gpio_set_drv(pin, 2);
136 }
137 } else {
138 /* SDC1: PG0-PG5 */
139 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
140 sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1);
141 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
142 sunxi_gpio_set_drv(pin, 2);
143 }
144 }
145#elif defined(CONFIG_MACH_SUN5I)
146 /* SDC1: PG3-PG8 */
Hans de Goede4dccfd42014-10-03 16:44:57 +0200147 for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100148 sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100149 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
150 sunxi_gpio_set_drv(pin, 2);
151 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100152#elif defined(CONFIG_MACH_SUN6I)
153 /* SDC1: PG0-PG5 */
154 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
155 sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1);
156 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
157 sunxi_gpio_set_drv(pin, 2);
158 }
159#elif defined(CONFIG_MACH_SUN8I)
160 if (pins == SUNXI_GPIO_D) {
161 /* SDC1: PD2-PD7 */
162 for (pin = SUNXI_GPD(2); pin <= SUNXI_GPD(7); pin++) {
163 sunxi_gpio_set_cfgpin(pin, SUN8I_GPD_SDC1);
164 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
165 sunxi_gpio_set_drv(pin, 2);
166 }
167 } else {
168 /* SDC1: PG0-PG5 */
169 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
170 sunxi_gpio_set_cfgpin(pin, SUN8I_GPG_SDC1);
171 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
172 sunxi_gpio_set_drv(pin, 2);
173 }
174 }
175#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100176 break;
177
178 case 2:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100179 pins = sunxi_name_to_gpio_bank(CONFIG_MMC2_PINS);
180
181#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
182 /* SDC2: PC6-PC11 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100183 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100184 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100185 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
186 sunxi_gpio_set_drv(pin, 2);
187 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100188#elif defined(CONFIG_MACH_SUN5I)
189 if (pins == SUNXI_GPIO_E) {
190 /* SDC2: PE4-PE9 */
191 for (pin = SUNXI_GPE(4); pin <= SUNXI_GPD(9); pin++) {
192 sunxi_gpio_set_cfgpin(pin, SUN5I_GPE_SDC2);
193 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
194 sunxi_gpio_set_drv(pin, 2);
195 }
196 } else {
197 /* SDC2: PC6-PC15 */
198 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
199 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
200 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
201 sunxi_gpio_set_drv(pin, 2);
202 }
203 }
204#elif defined(CONFIG_MACH_SUN6I)
205 if (pins == SUNXI_GPIO_A) {
206 /* SDC2: PA9-PA14 */
207 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
208 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC2);
209 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
210 sunxi_gpio_set_drv(pin, 2);
211 }
212 } else {
213 /* SDC2: PC6-PC15, PC24 */
214 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
215 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
216 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
217 sunxi_gpio_set_drv(pin, 2);
218 }
219
220 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
221 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
222 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
223 }
224#elif defined(CONFIG_MACH_SUN8I)
225 /* SDC2: PC5-PC6, PC8-PC16 */
226 for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) {
227 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
228 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
229 sunxi_gpio_set_drv(pin, 2);
230 }
231
232 for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) {
233 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
234 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
235 sunxi_gpio_set_drv(pin, 2);
236 }
237#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100238 break;
239
240 case 3:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100241 pins = sunxi_name_to_gpio_bank(CONFIG_MMC3_PINS);
242
243#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
244 /* SDC3: PI4-PI9 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100245 for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) {
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100246 sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100247 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
248 sunxi_gpio_set_drv(pin, 2);
249 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100250#elif defined(CONFIG_MACH_SUN6I)
251 if (pins == SUNXI_GPIO_A) {
252 /* SDC3: PA9-PA14 */
253 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
254 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC3);
255 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
256 sunxi_gpio_set_drv(pin, 2);
257 }
258 } else {
259 /* SDC3: PC6-PC15, PC24 */
260 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
261 sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3);
262 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
263 sunxi_gpio_set_drv(pin, 2);
264 }
265
266 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3);
267 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
268 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
269 }
270#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100271 break;
272
273 default:
274 printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc);
275 break;
276 }
277}
278
279int board_mmc_init(bd_t *bis)
280{
Hans de Goede63deaa82014-10-02 21:13:54 +0200281 __maybe_unused struct mmc *mmc0, *mmc1;
282 __maybe_unused char buf[512];
283
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100284 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT);
Hans de Goede63deaa82014-10-02 21:13:54 +0200285 mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT);
286 if (!mmc0)
287 return -1;
288
Hans de Goedeaf593e42014-10-02 20:43:50 +0200289#if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100290 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA);
Hans de Goede63deaa82014-10-02 21:13:54 +0200291 mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA);
292 if (!mmc1)
293 return -1;
294#endif
295
Daniel Kochmański25d9a6d2015-05-29 17:21:00 +0200296#if !defined(CONFIG_SPL_BUILD) && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2
Hans de Goede63deaa82014-10-02 21:13:54 +0200297 /*
Daniel Kochmański25d9a6d2015-05-29 17:21:00 +0200298 * On systems with an emmc (mmc2), figure out if we are booting from
299 * the emmc and if we are make it "mmc dev 0" so that boot.scr, etc.
300 * are searched there first. Note we only do this for u-boot proper,
301 * not for the SPL, see spl_boot_device().
Hans de Goede63deaa82014-10-02 21:13:54 +0200302 */
Daniel Kochmański25d9a6d2015-05-29 17:21:00 +0200303 if (!sunxi_mmc_has_egon_boot_signature(mmc0) &&
304 sunxi_mmc_has_egon_boot_signature(mmc1)) {
305 /* Booting from emmc / mmc2, swap */
306 mmc0->block_dev.dev = 1;
307 mmc1->block_dev.dev = 0;
308 }
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100309#endif
310
311 return 0;
312}
313#endif
314
Hans de Goede3352b222014-06-13 22:55:49 +0200315void i2c_init_board(void)
316{
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200317#ifdef CONFIG_I2C0_ENABLE
318#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN5I) || defined(CONFIG_MACH_SUN7I)
319 sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0);
320 sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0);
321 clock_twi_onoff(0, 1);
322#elif defined(CONFIG_MACH_SUN6I)
323 sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0);
324 sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0);
325 clock_twi_onoff(0, 1);
326#elif defined(CONFIG_MACH_SUN8I)
327 sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0);
328 sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0);
Hans de Goede3352b222014-06-13 22:55:49 +0200329 clock_twi_onoff(0, 1);
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200330#endif
331#endif
332
333#ifdef CONFIG_I2C1_ENABLE
334#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
335 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1);
336 sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1);
337 clock_twi_onoff(1, 1);
338#elif defined(CONFIG_MACH_SUN5I)
339 sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1);
340 sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1);
341 clock_twi_onoff(1, 1);
342#elif defined(CONFIG_MACH_SUN6I)
343 sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1);
344 sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1);
345 clock_twi_onoff(1, 1);
346#elif defined(CONFIG_MACH_SUN8I)
347 sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1);
348 sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1);
349 clock_twi_onoff(1, 1);
350#endif
351#endif
352
353#ifdef CONFIG_I2C2_ENABLE
354#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
355 sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN4I_GPB_TWI2);
356 sunxi_gpio_set_cfgpin(SUNXI_GPB(21), SUN4I_GPB_TWI2);
357 clock_twi_onoff(2, 1);
358#elif defined(CONFIG_MACH_SUN5I)
359 sunxi_gpio_set_cfgpin(SUNXI_GPB(17), SUN5I_GPB_TWI2);
360 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN5I_GPB_TWI2);
361 clock_twi_onoff(2, 1);
362#elif defined(CONFIG_MACH_SUN6I)
363 sunxi_gpio_set_cfgpin(SUNXI_GPH(18), SUN6I_GPH_TWI2);
364 sunxi_gpio_set_cfgpin(SUNXI_GPH(19), SUN6I_GPH_TWI2);
365 clock_twi_onoff(2, 1);
366#elif defined(CONFIG_MACH_SUN8I)
367 sunxi_gpio_set_cfgpin(SUNXI_GPE(12), SUN8I_GPE_TWI2);
368 sunxi_gpio_set_cfgpin(SUNXI_GPE(13), SUN8I_GPE_TWI2);
369 clock_twi_onoff(2, 1);
370#endif
371#endif
372
373#ifdef CONFIG_I2C3_ENABLE
374#if defined(CONFIG_MACH_SUN6I)
375 sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUN6I_GPG_TWI3);
376 sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUN6I_GPG_TWI3);
377 clock_twi_onoff(3, 1);
378#elif defined(CONFIG_MACH_SUN7I)
379 sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUN7I_GPI_TWI3);
380 sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUN7I_GPI_TWI3);
381 clock_twi_onoff(3, 1);
382#endif
383#endif
384
385#ifdef CONFIG_I2C4_ENABLE
386#if defined(CONFIG_MACH_SUN7I)
387 sunxi_gpio_set_cfgpin(SUNXI_GPI(2), SUN7I_GPI_TWI4);
388 sunxi_gpio_set_cfgpin(SUNXI_GPI(3), SUN7I_GPI_TWI4);
389 clock_twi_onoff(4, 1);
390#endif
391#endif
Hans de Goede3352b222014-06-13 22:55:49 +0200392}
393
Ian Campbell6efe3692014-05-05 11:52:26 +0100394#ifdef CONFIG_SPL_BUILD
395void sunxi_board_init(void)
396{
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200397 int power_failed = 0;
Ian Campbell6efe3692014-05-05 11:52:26 +0100398 unsigned long ramsize;
399
Hans de Goede1f247362014-06-13 22:55:51 +0200400#ifdef CONFIG_AXP152_POWER
401 power_failed = axp152_init();
402 power_failed |= axp152_set_dcdc2(1400);
403 power_failed |= axp152_set_dcdc3(1500);
404 power_failed |= axp152_set_dcdc4(1250);
405 power_failed |= axp152_set_ldo2(3000);
406#endif
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200407#ifdef CONFIG_AXP209_POWER
408 power_failed |= axp209_init();
409 power_failed |= axp209_set_dcdc2(1400);
410 power_failed |= axp209_set_dcdc3(1250);
411 power_failed |= axp209_set_ldo2(3000);
412 power_failed |= axp209_set_ldo3(2800);
413 power_failed |= axp209_set_ldo4(2800);
414#endif
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200415#ifdef CONFIG_AXP221_POWER
416 power_failed = axp221_init();
Hans de Goede78655482014-12-13 14:12:06 +0100417 power_failed |= axp221_set_dcdc1(CONFIG_AXP221_DCDC1_VOLT);
Hans de Goede013c9ce2014-12-13 14:20:09 +0100418 power_failed |= axp221_set_dcdc2(1200); /* A31:VDD-GPU, A23:VDD-SYS */
419 power_failed |= axp221_set_dcdc3(1200); /* VDD-CPU */
420#ifdef CONFIG_MACH_SUN6I
421 power_failed |= axp221_set_dcdc4(1200); /* A31:VDD-SYS */
422#else
423 power_failed |= axp221_set_dcdc4(0); /* A23:unused */
424#endif
425 power_failed |= axp221_set_dcdc5(1500); /* VCC-DRAM */
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200426 power_failed |= axp221_set_dldo1(CONFIG_AXP221_DLDO1_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200427 power_failed |= axp221_set_dldo4(CONFIG_AXP221_DLDO4_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200428 power_failed |= axp221_set_aldo1(CONFIG_AXP221_ALDO1_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200429 power_failed |= axp221_set_aldo2(CONFIG_AXP221_ALDO2_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200430 power_failed |= axp221_set_aldo3(CONFIG_AXP221_ALDO3_VOLT);
Siarhei Siamashka7e4eb6c2015-01-19 05:23:30 +0200431 power_failed |= axp221_set_eldo(3, CONFIG_AXP221_ELDO3_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200432#endif
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200433
Ian Campbell6efe3692014-05-05 11:52:26 +0100434 printf("DRAM:");
435 ramsize = sunxi_dram_init();
436 printf(" %lu MiB\n", ramsize >> 20);
437 if (!ramsize)
438 hang();
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200439
440 /*
441 * Only clock up the CPU to full speed if we are reasonably
442 * assured it's being powered with suitable core voltage
443 */
444 if (!power_failed)
Iain Paton630df142015-03-28 10:26:38 +0000445 clock_set_pll1(CONFIG_SYS_CLK_FREQ);
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200446 else
447 printf("Failed to set core voltage! Can't set CPU frequency\n");
Ian Campbell6efe3692014-05-05 11:52:26 +0100448}
449#endif
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200450
Paul Kocialkowskidbbccaf2015-03-22 18:07:13 +0100451#ifdef CONFIG_USB_GADGET
452int g_dnl_board_usb_cable_connected(void)
453{
Paul Kocialkowski61c73ee2015-05-16 19:52:10 +0200454 return sunxi_usb_phy_vbus_detect(0);
Paul Kocialkowskidbbccaf2015-03-22 18:07:13 +0100455}
456#endif
457
Paul Kocialkowski99ae0f62015-03-28 18:35:36 +0100458#ifdef CONFIG_SERIAL_TAG
459void get_board_serial(struct tag_serialnr *serialnr)
460{
461 char *serial_string;
462 unsigned long long serial;
463
464 serial_string = getenv("serial#");
465
466 if (serial_string) {
467 serial = simple_strtoull(serial_string, NULL, 16);
468
469 serialnr->high = (unsigned int) (serial >> 32);
470 serialnr->low = (unsigned int) (serial & 0xffffffff);
471 } else {
472 serialnr->high = 0;
473 serialnr->low = 0;
474 }
475}
476#endif
477
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200478#ifdef CONFIG_MISC_INIT_R
479int misc_init_r(void)
480{
Paul Kocialkowski92935942015-03-28 18:35:35 +0100481 char serial_string[17] = { 0 };
Hans de Goede11d70982014-11-26 00:04:24 +0100482 unsigned int sid[4];
Paul Kocialkowski92935942015-03-28 18:35:35 +0100483 uint8_t mac_addr[6];
484 int ret;
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200485
Paul Kocialkowski92935942015-03-28 18:35:35 +0100486 ret = sunxi_get_sid(sid);
487 if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
488 if (!getenv("ethaddr")) {
489 /* Non OUI / registered MAC address */
490 mac_addr[0] = 0x02;
491 mac_addr[1] = (sid[0] >> 0) & 0xff;
492 mac_addr[2] = (sid[3] >> 24) & 0xff;
493 mac_addr[3] = (sid[3] >> 16) & 0xff;
494 mac_addr[4] = (sid[3] >> 8) & 0xff;
495 mac_addr[5] = (sid[3] >> 0) & 0xff;
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200496
Paul Kocialkowski92935942015-03-28 18:35:35 +0100497 eth_setenv_enetaddr("ethaddr", mac_addr);
498 }
499
500 if (!getenv("serial#")) {
501 snprintf(serial_string, sizeof(serial_string),
502 "%08x%08x", sid[0], sid[3]);
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200503
Paul Kocialkowski92935942015-03-28 18:35:35 +0100504 setenv("serial#", serial_string);
505 }
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200506 }
507
Hans de Goede7bfe2bb2015-01-13 19:25:06 +0100508#ifndef CONFIG_MACH_SUN9I
Hans de Goede1168e092015-04-27 16:50:04 +0200509 ret = sunxi_usb_phy_probe();
510 if (ret)
511 return ret;
Hans de Goede7bfe2bb2015-01-13 19:25:06 +0100512#endif
Hans de Goedeea059bf2015-06-17 15:49:26 +0200513 sunxi_musb_board_init();
514
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200515 return 0;
516}
517#endif
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200518
519#ifdef CONFIG_OF_BOARD_SETUP
520int ft_board_setup(void *blob, bd_t *bd)
521{
522#ifdef CONFIG_VIDEO_DT_SIMPLEFB
523 return sunxi_simplefb_setup(blob);
524#endif
525}
526#endif /* CONFIG_OF_BOARD_SETUP */