blob: b6d63dbb40934dbe2aa5fba52d162d1115216602 [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>
Hans de Goede66203772014-06-13 22:55:49 +020014#include <i2c.h>
Ian Campbell58358232014-05-05 11:52:28 +010015#include <netdev.h>
16#include <miiphy.h>
Ian Campbellcba69ee2014-05-05 11:52:26 +010017#include <serial.h>
18#ifdef CONFIG_SPL_BUILD
19#include <spl.h>
20#endif
21#include <asm/gpio.h>
22#include <asm/io.h>
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>
27
Ian Campbell799aff32014-07-06 20:03:20 +010028#include <linux/compiler.h>
29
Ian Campbellcba69ee2014-05-05 11:52:26 +010030#ifdef CONFIG_SPL_BUILD
31/* Pointer to the global data structure for SPL */
32DECLARE_GLOBAL_DATA_PTR;
33
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
38 */
39u32 spl_boot_device(void)
40{
41 return BOOT_DEVICE_MMC1;
42}
43
44/* No confirmation data available in SPL yet. Hardcode bootmode */
45u32 spl_boot_mode(void)
46{
47 return MMCSD_MODE_RAW;
48}
49#endif
50
51int gpio_init(void)
52{
Hans de Goedef84269c2014-06-09 11:36:58 +020053#if CONFIG_CONS_INDEX == 1 && (defined(CONFIG_SUN4I) || defined(CONFIG_SUN7I))
Ian Campbellcba69ee2014-05-05 11:52:26 +010054 sunxi_gpio_set_cfgpin(SUNXI_GPB(22), SUN4I_GPB22_UART0_TX);
55 sunxi_gpio_set_cfgpin(SUNXI_GPB(23), SUN4I_GPB23_UART0_RX);
Chen-Yu Tsaiea520942014-10-03 20:16:21 +080056 sunxi_gpio_set_pull(SUNXI_GPB(23), SUNXI_GPIO_PULL_UP);
Hans de Goedef84269c2014-06-09 11:36:58 +020057#elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_SUN5I)
58 sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN5I_GPB19_UART0_TX);
59 sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN5I_GPB20_UART0_RX);
Chen-Yu Tsaiea520942014-10-03 20:16:21 +080060 sunxi_gpio_set_pull(SUNXI_GPB(20), SUNXI_GPIO_PULL_UP);
Maxime Ripard77115392014-10-03 20:16:28 +080061#elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_SUN6I)
62 sunxi_gpio_set_cfgpin(SUNXI_GPH(20), SUN6I_GPH20_UART0_TX);
63 sunxi_gpio_set_cfgpin(SUNXI_GPH(21), SUN6I_GPH21_UART0_RX);
64 sunxi_gpio_set_pull(SUNXI_GPH(21), SUNXI_GPIO_PULL_UP);
Hans de Goedef84269c2014-06-09 11:36:58 +020065#elif CONFIG_CONS_INDEX == 2 && defined(CONFIG_SUN5I)
66 sunxi_gpio_set_cfgpin(SUNXI_GPG(3), SUN5I_GPG3_UART1_TX);
67 sunxi_gpio_set_cfgpin(SUNXI_GPG(4), SUN5I_GPG4_UART1_RX);
Chen-Yu Tsaiea520942014-10-03 20:16:21 +080068 sunxi_gpio_set_pull(SUNXI_GPG(4), SUNXI_GPIO_PULL_UP);
Hans de Goedef84269c2014-06-09 11:36:58 +020069#else
70#error Unsupported console port number. Please fix pin mux settings in board.c
71#endif
Ian Campbellcba69ee2014-05-05 11:52:26 +010072
73 return 0;
74}
75
76void reset_cpu(ulong addr)
77{
Hans de Goedec7e79de2014-06-09 11:36:56 +020078 static const struct sunxi_wdog *wdog =
79 &((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog;
80
81 /* Set the watchdog for its shortest interval (.5s) and wait */
82 writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
83 writel(WDT_CTRL_KEY | WDT_CTRL_RESTART, &wdog->ctl);
Hans de Goedeae5de5a2014-06-13 22:55:52 +020084
85 while (1) {
86 /* sun5i sometimes gets stuck without this */
87 writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
88 }
Ian Campbellcba69ee2014-05-05 11:52:26 +010089}
90
91/* do some early init */
92void s_init(void)
93{
94#if !defined CONFIG_SPL_BUILD && (defined CONFIG_SUN7I || defined CONFIG_SUN6I)
95 /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
96 asm volatile(
97 "mrc p15, 0, r0, c1, c0, 1\n"
98 "orr r0, r0, #1 << 6\n"
99 "mcr p15, 0, r0, c1, c0, 1\n");
100#endif
101
102 clock_init();
103 timer_init();
104 gpio_init();
Hans de Goede66203772014-06-13 22:55:49 +0200105 i2c_init_board();
Ian Campbellcba69ee2014-05-05 11:52:26 +0100106
107#ifdef CONFIG_SPL_BUILD
108 gd = &gdata;
109 preloader_console_init();
110
Hans de Goede66203772014-06-13 22:55:49 +0200111#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);
114#endif
Ian Campbellcba69ee2014-05-05 11:52:26 +0100115 sunxi_board_init();
116#endif
117}
118
119#ifndef CONFIG_SYS_DCACHE_OFF
120void enable_caches(void)
121{
122 /* Enable D-cache. I-cache is already enabled in start.S */
123 dcache_enable();
124}
125#endif
Ian Campbell58358232014-05-05 11:52:28 +0100126
127#ifdef CONFIG_CMD_NET
128/*
129 * Initializes on-chip ethernet controllers.
130 * to override, implement board_eth_init()
131 */
132int cpu_eth_init(bd_t *bis)
133{
Ian Campbell799aff32014-07-06 20:03:20 +0100134 __maybe_unused int rc;
Ian Campbell58358232014-05-05 11:52:28 +0100135
Hans de Goedefc703002014-07-26 17:09:13 +0200136#ifdef CONFIG_MACPWR
137 gpio_direction_output(CONFIG_MACPWR, 1);
138 mdelay(200);
139#endif
140
Hans de Goedec26fb9d2014-06-09 11:37:00 +0200141#ifdef CONFIG_SUNXI_EMAC
142 rc = sunxi_emac_initialize(bis);
143 if (rc < 0) {
144 printf("sunxi: failed to initialize emac\n");
145 return rc;
146 }
147#endif
148
Ian Campbell58358232014-05-05 11:52:28 +0100149#ifdef CONFIG_SUNXI_GMAC
150 rc = sunxi_gmac_initialize(bis);
151 if (rc < 0) {
152 printf("sunxi: failed to initialize gmac\n");
153 return rc;
154 }
155#endif
156
157 return 0;
158}
159#endif