blob: 9c855f604d62908e9983523c40a25ff0fd449750 [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>
Hans de Goede5ed52f62015-08-15 11:55:26 +020034#include <nand.h>
Jonathan Liuabc1aae2014-06-14 08:59:09 +020035#include <net.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{
Hans de Goede3ae1d132015-04-25 17:25:14 +020083 int id_pfr1, ret;
Ian Campbell6efe3692014-05-05 11:52:26 +010084
85 gd->bd->bi_boot_params = (PHYS_SDRAM_0 + 0x100);
86
87 asm volatile("mrc p15, 0, %0, c0, c1, 1" : "=r"(id_pfr1));
88 debug("id_pfr1: 0x%08x\n", id_pfr1);
89 /* Generic Timer Extension available? */
90 if ((id_pfr1 >> 16) & 0xf) {
91 debug("Setting CNTFRQ\n");
92 /* CNTFRQ == 24 MHz */
93 asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r"(24000000));
94 }
95
Hans de Goede3ae1d132015-04-25 17:25:14 +020096 ret = axp_gpio_init();
97 if (ret)
98 return ret;
99
Hans de Goeded9d05652015-04-23 23:23:50 +0200100 /* Uses dm gpio code so do this here and not in i2c_init_board() */
101 return soft_i2c_board_init();
Ian Campbell6efe3692014-05-05 11:52:26 +0100102}
103
104int dram_init(void)
105{
106 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_0, PHYS_SDRAM_0_SIZE);
107
108 return 0;
109}
110
Hans de Goede3ce35f92015-08-16 14:48:22 +0200111#if defined(CONFIG_NAND_SUNXI) && defined(CONFIG_SPL_BUILD)
Karol Gugala7bea8932015-07-23 14:33:01 +0200112static void nand_pinmux_setup(void)
113{
114 unsigned int pin;
Karol Gugala7bea8932015-07-23 14:33:01 +0200115
Hans de Goeded2236782015-08-15 13:17:49 +0200116 for (pin = SUNXI_GPC(0); pin <= SUNXI_GPC(19); pin++)
Karol Gugala7bea8932015-07-23 14:33:01 +0200117 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND);
118
Hans de Goeded2236782015-08-15 13:17:49 +0200119#if defined CONFIG_MACH_SUN4I || defined CONFIG_MACH_SUN7I
120 for (pin = SUNXI_GPC(20); pin <= SUNXI_GPC(22); pin++)
121 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_NAND);
122#endif
123 /* sun4i / sun7i do have a PC23, but it is not used for nand,
124 * only sun7i has a PC24 */
125#ifdef CONFIG_MACH_SUN7I
Karol Gugala7bea8932015-07-23 14:33:01 +0200126 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_NAND);
Hans de Goeded2236782015-08-15 13:17:49 +0200127#endif
Karol Gugala7bea8932015-07-23 14:33:01 +0200128}
129
130static void nand_clock_setup(void)
131{
132 struct sunxi_ccm_reg *const ccm =
133 (struct sunxi_ccm_reg *)SUNXI_CCM_BASE;
Hans de Goedee5561a82015-08-15 11:58:03 +0200134
Karol Gugala7bea8932015-07-23 14:33:01 +0200135 setbits_le32(&ccm->ahb_gate0, (CLK_GATE_OPEN << AHB_GATE_OFFSET_NAND0));
Hans de Goedee5561a82015-08-15 11:58:03 +0200136#ifdef CONFIG_MACH_SUN9I
137 setbits_le32(&ccm->ahb_gate1, (1 << AHB_GATE_OFFSET_DMA));
138#else
139 setbits_le32(&ccm->ahb_gate0, (1 << AHB_GATE_OFFSET_DMA));
140#endif
Karol Gugala7bea8932015-07-23 14:33:01 +0200141 setbits_le32(&ccm->nand0_clk_cfg, CCM_NAND_CTRL_ENABLE | AHB_DIV_1);
142}
Hans de Goede5ed52f62015-08-15 11:55:26 +0200143
144void board_nand_init(void)
145{
146 nand_pinmux_setup();
147 nand_clock_setup();
148}
Karol Gugala7bea8932015-07-23 14:33:01 +0200149#endif
150
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100151#ifdef CONFIG_GENERIC_MMC
152static void mmc_pinmux_setup(int sdc)
153{
154 unsigned int pin;
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100155 __maybe_unused int pins;
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100156
157 switch (sdc) {
158 case 0:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100159 /* SDC0: PF0-PF5 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100160 for (pin = SUNXI_GPF(0); pin <= SUNXI_GPF(5); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100161 sunxi_gpio_set_cfgpin(pin, SUNXI_GPF_SDC0);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100162 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
163 sunxi_gpio_set_drv(pin, 2);
164 }
165 break;
166
167 case 1:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100168 pins = sunxi_name_to_gpio_bank(CONFIG_MMC1_PINS);
169
170#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
171 if (pins == SUNXI_GPIO_H) {
172 /* SDC1: PH22-PH-27 */
173 for (pin = SUNXI_GPH(22); pin <= SUNXI_GPH(27); pin++) {
174 sunxi_gpio_set_cfgpin(pin, SUN4I_GPH_SDC1);
175 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
176 sunxi_gpio_set_drv(pin, 2);
177 }
178 } else {
179 /* SDC1: PG0-PG5 */
180 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
181 sunxi_gpio_set_cfgpin(pin, SUN4I_GPG_SDC1);
182 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
183 sunxi_gpio_set_drv(pin, 2);
184 }
185 }
186#elif defined(CONFIG_MACH_SUN5I)
187 /* SDC1: PG3-PG8 */
Hans de Goede4dccfd42014-10-03 16:44:57 +0200188 for (pin = SUNXI_GPG(3); pin <= SUNXI_GPG(8); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100189 sunxi_gpio_set_cfgpin(pin, SUN5I_GPG_SDC1);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100190 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
191 sunxi_gpio_set_drv(pin, 2);
192 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100193#elif defined(CONFIG_MACH_SUN6I)
194 /* SDC1: PG0-PG5 */
195 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
196 sunxi_gpio_set_cfgpin(pin, SUN6I_GPG_SDC1);
197 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
198 sunxi_gpio_set_drv(pin, 2);
199 }
200#elif defined(CONFIG_MACH_SUN8I)
201 if (pins == SUNXI_GPIO_D) {
202 /* SDC1: PD2-PD7 */
203 for (pin = SUNXI_GPD(2); pin <= SUNXI_GPD(7); pin++) {
204 sunxi_gpio_set_cfgpin(pin, SUN8I_GPD_SDC1);
205 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
206 sunxi_gpio_set_drv(pin, 2);
207 }
208 } else {
209 /* SDC1: PG0-PG5 */
210 for (pin = SUNXI_GPG(0); pin <= SUNXI_GPG(5); pin++) {
211 sunxi_gpio_set_cfgpin(pin, SUN8I_GPG_SDC1);
212 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
213 sunxi_gpio_set_drv(pin, 2);
214 }
215 }
216#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100217 break;
218
219 case 2:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100220 pins = sunxi_name_to_gpio_bank(CONFIG_MMC2_PINS);
221
222#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
223 /* SDC2: PC6-PC11 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100224 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(11); pin++) {
Paul Kocialkowskiae358a42015-03-22 18:12:22 +0100225 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100226 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
227 sunxi_gpio_set_drv(pin, 2);
228 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100229#elif defined(CONFIG_MACH_SUN5I)
230 if (pins == SUNXI_GPIO_E) {
231 /* SDC2: PE4-PE9 */
232 for (pin = SUNXI_GPE(4); pin <= SUNXI_GPD(9); pin++) {
233 sunxi_gpio_set_cfgpin(pin, SUN5I_GPE_SDC2);
234 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
235 sunxi_gpio_set_drv(pin, 2);
236 }
237 } else {
238 /* SDC2: PC6-PC15 */
239 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
240 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
241 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
242 sunxi_gpio_set_drv(pin, 2);
243 }
244 }
245#elif defined(CONFIG_MACH_SUN6I)
246 if (pins == SUNXI_GPIO_A) {
247 /* SDC2: PA9-PA14 */
248 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
249 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC2);
250 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
251 sunxi_gpio_set_drv(pin, 2);
252 }
253 } else {
254 /* SDC2: PC6-PC15, PC24 */
255 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
256 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
257 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
258 sunxi_gpio_set_drv(pin, 2);
259 }
260
261 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUNXI_GPC_SDC2);
262 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
263 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
264 }
265#elif defined(CONFIG_MACH_SUN8I)
266 /* SDC2: PC5-PC6, PC8-PC16 */
267 for (pin = SUNXI_GPC(5); pin <= SUNXI_GPC(6); pin++) {
268 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
269 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
270 sunxi_gpio_set_drv(pin, 2);
271 }
272
273 for (pin = SUNXI_GPC(8); pin <= SUNXI_GPC(16); pin++) {
274 sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SDC2);
275 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
276 sunxi_gpio_set_drv(pin, 2);
277 }
278#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100279 break;
280
281 case 3:
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100282 pins = sunxi_name_to_gpio_bank(CONFIG_MMC3_PINS);
283
284#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
285 /* SDC3: PI4-PI9 */
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100286 for (pin = SUNXI_GPI(4); pin <= SUNXI_GPI(9); pin++) {
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100287 sunxi_gpio_set_cfgpin(pin, SUNXI_GPI_SDC3);
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100288 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
289 sunxi_gpio_set_drv(pin, 2);
290 }
Paul Kocialkowskid390d8c2015-03-22 18:12:23 +0100291#elif defined(CONFIG_MACH_SUN6I)
292 if (pins == SUNXI_GPIO_A) {
293 /* SDC3: PA9-PA14 */
294 for (pin = SUNXI_GPA(9); pin <= SUNXI_GPA(14); pin++) {
295 sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_SDC3);
296 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
297 sunxi_gpio_set_drv(pin, 2);
298 }
299 } else {
300 /* SDC3: PC6-PC15, PC24 */
301 for (pin = SUNXI_GPC(6); pin <= SUNXI_GPC(15); pin++) {
302 sunxi_gpio_set_cfgpin(pin, SUN6I_GPC_SDC3);
303 sunxi_gpio_set_pull(pin, SUNXI_GPIO_PULL_UP);
304 sunxi_gpio_set_drv(pin, 2);
305 }
306
307 sunxi_gpio_set_cfgpin(SUNXI_GPC(24), SUN6I_GPC_SDC3);
308 sunxi_gpio_set_pull(SUNXI_GPC(24), SUNXI_GPIO_PULL_UP);
309 sunxi_gpio_set_drv(SUNXI_GPC(24), 2);
310 }
311#endif
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100312 break;
313
314 default:
315 printf("sunxi: invalid MMC slot %d for pinmux setup\n", sdc);
316 break;
317 }
318}
319
320int board_mmc_init(bd_t *bis)
321{
Hans de Goede63deaa82014-10-02 21:13:54 +0200322 __maybe_unused struct mmc *mmc0, *mmc1;
323 __maybe_unused char buf[512];
324
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100325 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT);
Hans de Goede63deaa82014-10-02 21:13:54 +0200326 mmc0 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT);
327 if (!mmc0)
328 return -1;
329
Hans de Goedeaf593e42014-10-02 20:43:50 +0200330#if CONFIG_MMC_SUNXI_SLOT_EXTRA != -1
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100331 mmc_pinmux_setup(CONFIG_MMC_SUNXI_SLOT_EXTRA);
Hans de Goede63deaa82014-10-02 21:13:54 +0200332 mmc1 = sunxi_mmc_init(CONFIG_MMC_SUNXI_SLOT_EXTRA);
333 if (!mmc1)
334 return -1;
335#endif
336
Daniel Kochmański25d9a6d2015-05-29 17:21:00 +0200337#if !defined(CONFIG_SPL_BUILD) && CONFIG_MMC_SUNXI_SLOT_EXTRA == 2
Hans de Goede63deaa82014-10-02 21:13:54 +0200338 /*
Daniel Kochmański25d9a6d2015-05-29 17:21:00 +0200339 * On systems with an emmc (mmc2), figure out if we are booting from
340 * the emmc and if we are make it "mmc dev 0" so that boot.scr, etc.
341 * are searched there first. Note we only do this for u-boot proper,
342 * not for the SPL, see spl_boot_device().
Hans de Goede63deaa82014-10-02 21:13:54 +0200343 */
Daniel Kochmański25d9a6d2015-05-29 17:21:00 +0200344 if (!sunxi_mmc_has_egon_boot_signature(mmc0) &&
345 sunxi_mmc_has_egon_boot_signature(mmc1)) {
346 /* Booting from emmc / mmc2, swap */
347 mmc0->block_dev.dev = 1;
348 mmc1->block_dev.dev = 0;
349 }
Ian Campbellb4e9f2f2014-05-05 14:42:31 +0100350#endif
351
352 return 0;
353}
354#endif
355
Hans de Goede3352b222014-06-13 22:55:49 +0200356void i2c_init_board(void)
357{
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200358#ifdef CONFIG_I2C0_ENABLE
359#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN5I) || defined(CONFIG_MACH_SUN7I)
360 sunxi_gpio_set_cfgpin(SUNXI_GPB(0), SUN4I_GPB_TWI0);
361 sunxi_gpio_set_cfgpin(SUNXI_GPB(1), SUN4I_GPB_TWI0);
362 clock_twi_onoff(0, 1);
363#elif defined(CONFIG_MACH_SUN6I)
364 sunxi_gpio_set_cfgpin(SUNXI_GPH(14), SUN6I_GPH_TWI0);
365 sunxi_gpio_set_cfgpin(SUNXI_GPH(15), SUN6I_GPH_TWI0);
366 clock_twi_onoff(0, 1);
367#elif defined(CONFIG_MACH_SUN8I)
368 sunxi_gpio_set_cfgpin(SUNXI_GPH(2), SUN8I_GPH_TWI0);
369 sunxi_gpio_set_cfgpin(SUNXI_GPH(3), SUN8I_GPH_TWI0);
Hans de Goede3352b222014-06-13 22:55:49 +0200370 clock_twi_onoff(0, 1);
Paul Kocialkowski0a3ec0a2015-04-10 23:09:52 +0200371#endif
372#endif
373
374#ifdef CONFIG_I2C1_ENABLE
375#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
376 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN4I_GPB_TWI1);
377 sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN4I_GPB_TWI1);
378 clock_twi_onoff(1, 1);
379#elif defined(CONFIG_MACH_SUN5I)
380 sunxi_gpio_set_cfgpin(SUNXI_GPB(15), SUN5I_GPB_TWI1);
381 sunxi_gpio_set_cfgpin(SUNXI_GPB(16), SUN5I_GPB_TWI1);
382 clock_twi_onoff(1, 1);
383#elif defined(CONFIG_MACH_SUN6I)
384 sunxi_gpio_set_cfgpin(SUNXI_GPH(16), SUN6I_GPH_TWI1);
385 sunxi_gpio_set_cfgpin(SUNXI_GPH(17), SUN6I_GPH_TWI1);
386 clock_twi_onoff(1, 1);
387#elif defined(CONFIG_MACH_SUN8I)
388 sunxi_gpio_set_cfgpin(SUNXI_GPH(4), SUN8I_GPH_TWI1);
389 sunxi_gpio_set_cfgpin(SUNXI_GPH(5), SUN8I_GPH_TWI1);
390 clock_twi_onoff(1, 1);
391#endif
392#endif
393
394#ifdef CONFIG_I2C2_ENABLE
395#if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
396 sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN4I_GPB_TWI2);
397 sunxi_gpio_set_cfgpin(SUNXI_GPB(21), SUN4I_GPB_TWI2);
398 clock_twi_onoff(2, 1);
399#elif defined(CONFIG_MACH_SUN5I)
400 sunxi_gpio_set_cfgpin(SUNXI_GPB(17), SUN5I_GPB_TWI2);
401 sunxi_gpio_set_cfgpin(SUNXI_GPB(18), SUN5I_GPB_TWI2);
402 clock_twi_onoff(2, 1);
403#elif defined(CONFIG_MACH_SUN6I)
404 sunxi_gpio_set_cfgpin(SUNXI_GPH(18), SUN6I_GPH_TWI2);
405 sunxi_gpio_set_cfgpin(SUNXI_GPH(19), SUN6I_GPH_TWI2);
406 clock_twi_onoff(2, 1);
407#elif defined(CONFIG_MACH_SUN8I)
408 sunxi_gpio_set_cfgpin(SUNXI_GPE(12), SUN8I_GPE_TWI2);
409 sunxi_gpio_set_cfgpin(SUNXI_GPE(13), SUN8I_GPE_TWI2);
410 clock_twi_onoff(2, 1);
411#endif
412#endif
413
414#ifdef CONFIG_I2C3_ENABLE
415#if defined(CONFIG_MACH_SUN6I)
416 sunxi_gpio_set_cfgpin(SUNXI_GPG(10), SUN6I_GPG_TWI3);
417 sunxi_gpio_set_cfgpin(SUNXI_GPG(11), SUN6I_GPG_TWI3);
418 clock_twi_onoff(3, 1);
419#elif defined(CONFIG_MACH_SUN7I)
420 sunxi_gpio_set_cfgpin(SUNXI_GPI(0), SUN7I_GPI_TWI3);
421 sunxi_gpio_set_cfgpin(SUNXI_GPI(1), SUN7I_GPI_TWI3);
422 clock_twi_onoff(3, 1);
423#endif
424#endif
425
426#ifdef CONFIG_I2C4_ENABLE
427#if defined(CONFIG_MACH_SUN7I)
428 sunxi_gpio_set_cfgpin(SUNXI_GPI(2), SUN7I_GPI_TWI4);
429 sunxi_gpio_set_cfgpin(SUNXI_GPI(3), SUN7I_GPI_TWI4);
430 clock_twi_onoff(4, 1);
431#endif
432#endif
Hans de Goede3352b222014-06-13 22:55:49 +0200433}
434
Ian Campbell6efe3692014-05-05 11:52:26 +0100435#ifdef CONFIG_SPL_BUILD
436void sunxi_board_init(void)
437{
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200438 int power_failed = 0;
Ian Campbell6efe3692014-05-05 11:52:26 +0100439 unsigned long ramsize;
440
Hans de Goede1f247362014-06-13 22:55:51 +0200441#ifdef CONFIG_AXP152_POWER
442 power_failed = axp152_init();
443 power_failed |= axp152_set_dcdc2(1400);
444 power_failed |= axp152_set_dcdc3(1500);
445 power_failed |= axp152_set_dcdc4(1250);
446 power_failed |= axp152_set_ldo2(3000);
447#endif
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200448#ifdef CONFIG_AXP209_POWER
449 power_failed |= axp209_init();
450 power_failed |= axp209_set_dcdc2(1400);
451 power_failed |= axp209_set_dcdc3(1250);
452 power_failed |= axp209_set_ldo2(3000);
453 power_failed |= axp209_set_ldo3(2800);
454 power_failed |= axp209_set_ldo4(2800);
455#endif
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200456#ifdef CONFIG_AXP221_POWER
457 power_failed = axp221_init();
Hans de Goede78655482014-12-13 14:12:06 +0100458 power_failed |= axp221_set_dcdc1(CONFIG_AXP221_DCDC1_VOLT);
Hans de Goedec6c47c22015-08-14 16:19:34 +0200459 power_failed |= axp221_set_dcdc2(CONFIG_AXP221_DCDC2_VOLT);
Hans de Goede013c9ce2014-12-13 14:20:09 +0100460 power_failed |= axp221_set_dcdc3(1200); /* VDD-CPU */
461#ifdef CONFIG_MACH_SUN6I
462 power_failed |= axp221_set_dcdc4(1200); /* A31:VDD-SYS */
463#else
464 power_failed |= axp221_set_dcdc4(0); /* A23:unused */
465#endif
466 power_failed |= axp221_set_dcdc5(1500); /* VCC-DRAM */
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200467 power_failed |= axp221_set_dldo1(CONFIG_AXP221_DLDO1_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200468 power_failed |= axp221_set_dldo4(CONFIG_AXP221_DLDO4_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200469 power_failed |= axp221_set_aldo1(CONFIG_AXP221_ALDO1_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200470 power_failed |= axp221_set_aldo2(CONFIG_AXP221_ALDO2_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200471 power_failed |= axp221_set_aldo3(CONFIG_AXP221_ALDO3_VOLT);
Siarhei Siamashka7e4eb6c2015-01-19 05:23:30 +0200472 power_failed |= axp221_set_eldo(3, CONFIG_AXP221_ELDO3_VOLT);
Oliver Schinagld3a558d2013-07-26 12:56:58 +0200473#endif
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200474
Ian Campbell6efe3692014-05-05 11:52:26 +0100475 printf("DRAM:");
476 ramsize = sunxi_dram_init();
477 printf(" %lu MiB\n", ramsize >> 20);
478 if (!ramsize)
479 hang();
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200480
481 /*
482 * Only clock up the CPU to full speed if we are reasonably
483 * assured it's being powered with suitable core voltage
484 */
485 if (!power_failed)
Iain Paton630df142015-03-28 10:26:38 +0000486 clock_set_pll1(CONFIG_SYS_CLK_FREQ);
Henrik Nordstromaa382ad2014-06-13 22:55:50 +0200487 else
488 printf("Failed to set core voltage! Can't set CPU frequency\n");
Ian Campbell6efe3692014-05-05 11:52:26 +0100489}
490#endif
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200491
Paul Kocialkowskidbbccaf2015-03-22 18:07:13 +0100492#ifdef CONFIG_USB_GADGET
493int g_dnl_board_usb_cable_connected(void)
494{
Paul Kocialkowski61c73ee2015-05-16 19:52:10 +0200495 return sunxi_usb_phy_vbus_detect(0);
Paul Kocialkowskidbbccaf2015-03-22 18:07:13 +0100496}
497#endif
498
Paul Kocialkowski99ae0f62015-03-28 18:35:36 +0100499#ifdef CONFIG_SERIAL_TAG
500void get_board_serial(struct tag_serialnr *serialnr)
501{
502 char *serial_string;
503 unsigned long long serial;
504
505 serial_string = getenv("serial#");
506
507 if (serial_string) {
508 serial = simple_strtoull(serial_string, NULL, 16);
509
510 serialnr->high = (unsigned int) (serial >> 32);
511 serialnr->low = (unsigned int) (serial & 0xffffffff);
512 } else {
513 serialnr->high = 0;
514 serialnr->low = 0;
515 }
516}
517#endif
518
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200519#ifdef CONFIG_MISC_INIT_R
520int misc_init_r(void)
521{
Paul Kocialkowski92935942015-03-28 18:35:35 +0100522 char serial_string[17] = { 0 };
Hans de Goede11d70982014-11-26 00:04:24 +0100523 unsigned int sid[4];
Paul Kocialkowski92935942015-03-28 18:35:35 +0100524 uint8_t mac_addr[6];
525 int ret;
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200526
Paul Kocialkowski92935942015-03-28 18:35:35 +0100527 ret = sunxi_get_sid(sid);
528 if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
529 if (!getenv("ethaddr")) {
530 /* Non OUI / registered MAC address */
531 mac_addr[0] = 0x02;
532 mac_addr[1] = (sid[0] >> 0) & 0xff;
533 mac_addr[2] = (sid[3] >> 24) & 0xff;
534 mac_addr[3] = (sid[3] >> 16) & 0xff;
535 mac_addr[4] = (sid[3] >> 8) & 0xff;
536 mac_addr[5] = (sid[3] >> 0) & 0xff;
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200537
Paul Kocialkowski92935942015-03-28 18:35:35 +0100538 eth_setenv_enetaddr("ethaddr", mac_addr);
539 }
540
541 if (!getenv("serial#")) {
542 snprintf(serial_string, sizeof(serial_string),
543 "%08x%08x", sid[0], sid[3]);
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200544
Paul Kocialkowski92935942015-03-28 18:35:35 +0100545 setenv("serial#", serial_string);
546 }
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200547 }
548
Hans de Goede7bfe2bb2015-01-13 19:25:06 +0100549#ifndef CONFIG_MACH_SUN9I
Hans de Goede1168e092015-04-27 16:50:04 +0200550 ret = sunxi_usb_phy_probe();
551 if (ret)
552 return ret;
Hans de Goede7bfe2bb2015-01-13 19:25:06 +0100553#endif
Hans de Goedeea059bf2015-06-17 15:49:26 +0200554 sunxi_musb_board_init();
555
Jonathan Liuabc1aae2014-06-14 08:59:09 +0200556 return 0;
557}
558#endif
Luc Verhaegen4869a8c2014-08-13 07:55:07 +0200559
560#ifdef CONFIG_OF_BOARD_SETUP
561int ft_board_setup(void *blob, bd_t *bd)
562{
563#ifdef CONFIG_VIDEO_DT_SIMPLEFB
564 return sunxi_simplefb_setup(blob);
565#endif
566}
567#endif /* CONFIG_OF_BOARD_SETUP */