c80b42121c29c2b5e3c905b1509405c86e67a4f9
[oweals/u-boot.git] / arch / arm / cpu / armv7 / sunxi / board.c
1 /*
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>
14 #include <netdev.h>
15 #include <miiphy.h>
16 #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 */
29 DECLARE_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  */
36 u32 spl_boot_device(void)
37 {
38         return BOOT_DEVICE_MMC1;
39 }
40
41 /* No confirmation data available in SPL yet. Hardcode bootmode */
42 u32 spl_boot_mode(void)
43 {
44         return MMCSD_MODE_RAW;
45 }
46 #endif
47
48 int gpio_init(void)
49 {
50         sunxi_gpio_set_cfgpin(SUNXI_GPB(22), SUN4I_GPB22_UART0_TX);
51         sunxi_gpio_set_cfgpin(SUNXI_GPB(23), SUN4I_GPB23_UART0_RX);
52         sunxi_gpio_set_pull(SUNXI_GPB(23), 1);
53
54         return 0;
55 }
56
57 void reset_cpu(ulong addr)
58 {
59         static const struct sunxi_wdog *wdog =
60                  &((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog;
61
62         /* Set the watchdog for its shortest interval (.5s) and wait */
63         writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
64         writel(WDT_CTRL_KEY | WDT_CTRL_RESTART, &wdog->ctl);
65         while (1);
66 }
67
68 /* do some early init */
69 void s_init(void)
70 {
71 #if !defined CONFIG_SPL_BUILD && (defined CONFIG_SUN7I || defined CONFIG_SUN6I)
72         /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
73         asm volatile(
74                 "mrc p15, 0, r0, c1, c0, 1\n"
75                 "orr r0, r0, #1 << 6\n"
76                 "mcr p15, 0, r0, c1, c0, 1\n");
77 #endif
78
79         clock_init();
80         timer_init();
81         gpio_init();
82
83 #ifdef CONFIG_SPL_BUILD
84         gd = &gdata;
85         preloader_console_init();
86
87         sunxi_board_init();
88 #endif
89 }
90
91 #ifndef CONFIG_SYS_DCACHE_OFF
92 void enable_caches(void)
93 {
94         /* Enable D-cache. I-cache is already enabled in start.S */
95         dcache_enable();
96 }
97 #endif
98
99 #ifdef CONFIG_CMD_NET
100 /*
101  * Initializes on-chip ethernet controllers.
102  * to override, implement board_eth_init()
103  */
104 int cpu_eth_init(bd_t *bis)
105 {
106         int rc;
107
108 #ifdef CONFIG_SUNXI_GMAC
109         rc = sunxi_gmac_initialize(bis);
110         if (rc < 0) {
111                 printf("sunxi: failed to initialize gmac\n");
112                 return rc;
113         }
114 #endif
115
116         return 0;
117 }
118 #endif