2 * (C) Copyright 2012 Henrik Nordstrom <henrik@henriknordstrom.net>
4 * (C) Copyright 2007-2011
5 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
6 * Tom Cubie <tangliang@allwinnertech.com>
8 * Some init for sunxi platform.
10 * SPDX-License-Identifier: GPL-2.0+
18 #ifdef CONFIG_SPL_BUILD
23 #include <asm/arch/clock.h>
24 #include <asm/arch/gpio.h>
25 #include <asm/arch/sys_proto.h>
26 #include <asm/arch/timer.h>
28 #include <linux/compiler.h>
30 #ifdef CONFIG_SPL_BUILD
31 /* Pointer to the global data structure for SPL */
32 DECLARE_GLOBAL_DATA_PTR;
34 /* The sunxi internal brom will try to loader external bootloader
35 * from mmc0, nand flash, mmc2.
36 * Unfortunately we can't check how SPL was loaded so assume
37 * it's always the first SD/MMC controller
39 u32 spl_boot_device(void)
41 return BOOT_DEVICE_MMC1;
44 /* No confirmation data available in SPL yet. Hardcode bootmode */
45 u32 spl_boot_mode(void)
47 return MMCSD_MODE_RAW;
50 static int gpio_init(void)
52 #if CONFIG_CONS_INDEX == 1 && defined(CONFIG_UART0_PORT_F)
53 #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I)
54 /* disable GPB22,23 as uart0 tx,rx to avoid conflict */
55 sunxi_gpio_set_cfgpin(SUNXI_GPB(22), SUNXI_GPIO_INPUT);
56 sunxi_gpio_set_cfgpin(SUNXI_GPB(23), SUNXI_GPIO_INPUT);
58 sunxi_gpio_set_cfgpin(SUNXI_GPF(2), SUNXI_GPF2_UART0_TX);
59 sunxi_gpio_set_cfgpin(SUNXI_GPF(4), SUNXI_GPF4_UART0_RX);
60 sunxi_gpio_set_pull(SUNXI_GPF(4), 1);
61 #elif CONFIG_CONS_INDEX == 1 && (defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN7I))
62 sunxi_gpio_set_cfgpin(SUNXI_GPB(22), SUN4I_GPB22_UART0_TX);
63 sunxi_gpio_set_cfgpin(SUNXI_GPB(23), SUN4I_GPB23_UART0_RX);
64 sunxi_gpio_set_pull(SUNXI_GPB(23), SUNXI_GPIO_PULL_UP);
65 #elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_MACH_SUN5I)
66 sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN5I_GPB19_UART0_TX);
67 sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN5I_GPB20_UART0_RX);
68 sunxi_gpio_set_pull(SUNXI_GPB(20), SUNXI_GPIO_PULL_UP);
69 #elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_MACH_SUN6I)
70 sunxi_gpio_set_cfgpin(SUNXI_GPH(20), SUN6I_GPH20_UART0_TX);
71 sunxi_gpio_set_cfgpin(SUNXI_GPH(21), SUN6I_GPH21_UART0_RX);
72 sunxi_gpio_set_pull(SUNXI_GPH(21), SUNXI_GPIO_PULL_UP);
73 #elif CONFIG_CONS_INDEX == 2 && defined(CONFIG_MACH_SUN5I)
74 sunxi_gpio_set_cfgpin(SUNXI_GPG(3), SUN5I_GPG3_UART1_TX);
75 sunxi_gpio_set_cfgpin(SUNXI_GPG(4), SUN5I_GPG4_UART1_RX);
76 sunxi_gpio_set_pull(SUNXI_GPG(4), SUNXI_GPIO_PULL_UP);
77 #elif CONFIG_CONS_INDEX == 5 && defined(CONFIG_MACH_SUN8I)
78 sunxi_gpio_set_cfgpin(SUNXI_GPL(2), SUN8I_GPL2_R_UART_TX);
79 sunxi_gpio_set_cfgpin(SUNXI_GPL(3), SUN8I_GPL3_R_UART_RX);
80 sunxi_gpio_set_pull(SUNXI_GPL(3), SUNXI_GPIO_PULL_UP);
82 #error Unsupported console port number. Please fix pin mux settings in board.c
88 void board_init_f(ulong dummy)
90 #if defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I
91 /* Magic (undocmented) value taken from boot0, without this DRAM
92 * access gets messed up (seems cache related) */
93 setbits_le32(SUNXI_SRAMC_BASE + 0x44, 0x1800);
95 #if !defined CONFIG_SPL_BUILD && (defined CONFIG_MACH_SUN7I || \
96 defined CONFIG_MACH_SUN6I || defined CONFIG_MACH_SUN8I)
97 /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
99 "mrc p15, 0, r0, c1, c0, 1\n"
100 "orr r0, r0, #1 << 6\n"
101 "mcr p15, 0, r0, c1, c0, 1\n");
109 preloader_console_init();
111 #ifdef CONFIG_SPL_I2C_SUPPORT
112 /* Needed early by sunxi_board_init if PMU is enabled */
113 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
118 memset(__bss_start, 0, __bss_end - __bss_start);
120 board_init_r(NULL, 0);
124 void reset_cpu(ulong addr)
126 #if defined(CONFIG_MACH_SUN4I) || defined(CONFIG_MACH_SUN5I) || defined(CONFIG_MACH_SUN7I)
127 static const struct sunxi_wdog *wdog =
128 &((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog;
130 /* Set the watchdog for its shortest interval (.5s) and wait */
131 writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
132 writel(WDT_CTRL_KEY | WDT_CTRL_RESTART, &wdog->ctl);
135 /* sun5i sometimes gets stuck without this */
136 writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
138 #else /* CONFIG_MACH_SUN6I || CONFIG_MACH_SUN8I || .. */
139 static const struct sunxi_wdog *wdog =
140 ((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog;
142 /* Set the watchdog for its shortest interval (.5s) and wait */
143 writel(WDT_CFG_RESET, &wdog->cfg);
144 writel(WDT_MODE_EN, &wdog->mode);
145 writel(WDT_CTRL_KEY | WDT_CTRL_RESTART, &wdog->ctl);
149 #ifndef CONFIG_SYS_DCACHE_OFF
150 void enable_caches(void)
152 /* Enable D-cache. I-cache is already enabled in start.S */
157 #ifdef CONFIG_CMD_NET
159 * Initializes on-chip ethernet controllers.
160 * to override, implement board_eth_init()
162 int cpu_eth_init(bd_t *bis)
164 __maybe_unused int rc;
167 gpio_direction_output(CONFIG_MACPWR, 1);
171 #ifdef CONFIG_SUNXI_EMAC
172 rc = sunxi_emac_initialize(bis);
174 printf("sunxi: failed to initialize emac\n");
179 #ifdef CONFIG_SUNXI_GMAC
180 rc = sunxi_gmac_initialize(bis);
182 printf("sunxi: failed to initialize gmac\n");