blob: 1e506b5176e0cf40ce493c709fe24dbfc48892bb [file] [log] [blame]
Ian Campbellcba69ee2014-05-05 11:52:26 +01001/*
2 * (C) Copyright 2012 Henrik Nordstrom <henrik@henriknordstrom.net>
3 *
4 * (C) Copyright 2007-2011
5 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
6 * Tom Cubie <tangliang@allwinnertech.com>
7 *
8 * Some init for sunxi platform.
9 *
10 * SPDX-License-Identifier: GPL-2.0+
11 */
12
13#include <common.h>
Ian Campbell58358232014-05-05 11:52:28 +010014#include <netdev.h>
15#include <miiphy.h>
Ian Campbellcba69ee2014-05-05 11:52:26 +010016#include <serial.h>
17#ifdef CONFIG_SPL_BUILD
18#include <spl.h>
19#endif
20#include <asm/gpio.h>
21#include <asm/io.h>
22#include <asm/arch/clock.h>
23#include <asm/arch/gpio.h>
24#include <asm/arch/sys_proto.h>
25#include <asm/arch/timer.h>
26
27#ifdef CONFIG_SPL_BUILD
28/* Pointer to the global data structure for SPL */
29DECLARE_GLOBAL_DATA_PTR;
30
31/* The sunxi internal brom will try to loader external bootloader
32 * from mmc0, nand flash, mmc2.
33 * Unfortunately we can't check how SPL was loaded so assume
34 * it's always the first SD/MMC controller
35 */
36u32 spl_boot_device(void)
37{
38 return BOOT_DEVICE_MMC1;
39}
40
41/* No confirmation data available in SPL yet. Hardcode bootmode */
42u32 spl_boot_mode(void)
43{
44 return MMCSD_MODE_RAW;
45}
46#endif
47
48int gpio_init(void)
49{
Hans de Goedef84269c2014-06-09 11:36:58 +020050#if CONFIG_CONS_INDEX == 1 && (defined(CONFIG_SUN4I) || defined(CONFIG_SUN7I))
Ian Campbellcba69ee2014-05-05 11:52:26 +010051 sunxi_gpio_set_cfgpin(SUNXI_GPB(22), SUN4I_GPB22_UART0_TX);
52 sunxi_gpio_set_cfgpin(SUNXI_GPB(23), SUN4I_GPB23_UART0_RX);
53 sunxi_gpio_set_pull(SUNXI_GPB(23), 1);
Hans de Goedef84269c2014-06-09 11:36:58 +020054#elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_SUN5I)
55 sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN5I_GPB19_UART0_TX);
56 sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN5I_GPB20_UART0_RX);
57 sunxi_gpio_set_pull(SUNXI_GPB(20), 1);
58#elif CONFIG_CONS_INDEX == 2 && defined(CONFIG_SUN5I)
59 sunxi_gpio_set_cfgpin(SUNXI_GPG(3), SUN5I_GPG3_UART1_TX);
60 sunxi_gpio_set_cfgpin(SUNXI_GPG(4), SUN5I_GPG4_UART1_RX);
61 sunxi_gpio_set_pull(SUNXI_GPG(4), 1);
62#else
63#error Unsupported console port number. Please fix pin mux settings in board.c
64#endif
Ian Campbellcba69ee2014-05-05 11:52:26 +010065
66 return 0;
67}
68
69void reset_cpu(ulong addr)
70{
Hans de Goedec7e79de2014-06-09 11:36:56 +020071 static const struct sunxi_wdog *wdog =
72 &((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog;
73
74 /* Set the watchdog for its shortest interval (.5s) and wait */
75 writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
76 writel(WDT_CTRL_KEY | WDT_CTRL_RESTART, &wdog->ctl);
77 while (1);
Ian Campbellcba69ee2014-05-05 11:52:26 +010078}
79
80/* do some early init */
81void s_init(void)
82{
83#if !defined CONFIG_SPL_BUILD && (defined CONFIG_SUN7I || defined CONFIG_SUN6I)
84 /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
85 asm volatile(
86 "mrc p15, 0, r0, c1, c0, 1\n"
87 "orr r0, r0, #1 << 6\n"
88 "mcr p15, 0, r0, c1, c0, 1\n");
89#endif
90
91 clock_init();
92 timer_init();
93 gpio_init();
94
95#ifdef CONFIG_SPL_BUILD
96 gd = &gdata;
97 preloader_console_init();
98
99 sunxi_board_init();
100#endif
101}
102
103#ifndef CONFIG_SYS_DCACHE_OFF
104void enable_caches(void)
105{
106 /* Enable D-cache. I-cache is already enabled in start.S */
107 dcache_enable();
108}
109#endif
Ian Campbell58358232014-05-05 11:52:28 +0100110
111#ifdef CONFIG_CMD_NET
112/*
113 * Initializes on-chip ethernet controllers.
114 * to override, implement board_eth_init()
115 */
116int cpu_eth_init(bd_t *bis)
117{
118 int rc;
119
Hans de Goedec26fb9d2014-06-09 11:37:00 +0200120#ifdef CONFIG_SUNXI_EMAC
121 rc = sunxi_emac_initialize(bis);
122 if (rc < 0) {
123 printf("sunxi: failed to initialize emac\n");
124 return rc;
125 }
126#endif
127
Ian Campbell58358232014-05-05 11:52:28 +0100128#ifdef CONFIG_SUNXI_GMAC
129 rc = sunxi_gmac_initialize(bis);
130 if (rc < 0) {
131 printf("sunxi: failed to initialize gmac\n");
132 return rc;
133 }
134#endif
135
136 return 0;
137}
138#endif