]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/sunxi/board.c
538ffa70a3a6f376722ad024d94569e073017a6c
[karo-tx-uboot.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 #include <linux/compiler.h>
28
29 #ifdef CONFIG_SPL_BUILD
30 /* Pointer to the global data structure for SPL */
31 DECLARE_GLOBAL_DATA_PTR;
32
33 /* The sunxi internal brom will try to loader external bootloader
34  * from mmc0, nand flash, mmc2.
35  * Unfortunately we can't check how SPL was loaded so assume
36  * it's always the first SD/MMC controller
37  */
38 u32 spl_boot_device(void)
39 {
40         return BOOT_DEVICE_MMC1;
41 }
42
43 /* No confirmation data available in SPL yet. Hardcode bootmode */
44 u32 spl_boot_mode(void)
45 {
46         return MMCSD_MODE_RAW;
47 }
48 #endif
49
50 int gpio_init(void)
51 {
52 #if CONFIG_CONS_INDEX == 1 && (defined(CONFIG_SUN4I) || defined(CONFIG_SUN7I))
53         sunxi_gpio_set_cfgpin(SUNXI_GPB(22), SUN4I_GPB22_UART0_TX);
54         sunxi_gpio_set_cfgpin(SUNXI_GPB(23), SUN4I_GPB23_UART0_RX);
55         sunxi_gpio_set_pull(SUNXI_GPB(23), 1);
56 #elif CONFIG_CONS_INDEX == 1 && defined(CONFIG_SUN5I)
57         sunxi_gpio_set_cfgpin(SUNXI_GPB(19), SUN5I_GPB19_UART0_TX);
58         sunxi_gpio_set_cfgpin(SUNXI_GPB(20), SUN5I_GPB20_UART0_RX);
59         sunxi_gpio_set_pull(SUNXI_GPB(20), 1);
60 #elif CONFIG_CONS_INDEX == 2 && defined(CONFIG_SUN5I)
61         sunxi_gpio_set_cfgpin(SUNXI_GPG(3), SUN5I_GPG3_UART1_TX);
62         sunxi_gpio_set_cfgpin(SUNXI_GPG(4), SUN5I_GPG4_UART1_RX);
63         sunxi_gpio_set_pull(SUNXI_GPG(4), 1);
64 #else
65 #error Unsupported console port number. Please fix pin mux settings in board.c
66 #endif
67
68         return 0;
69 }
70
71 void reset_cpu(ulong addr)
72 {
73         static const struct sunxi_wdog *wdog =
74                  &((struct sunxi_timer_reg *)SUNXI_TIMER_BASE)->wdog;
75
76         /* Set the watchdog for its shortest interval (.5s) and wait */
77         writel(WDT_MODE_RESET_EN | WDT_MODE_EN, &wdog->mode);
78         writel(WDT_CTRL_KEY | WDT_CTRL_RESTART, &wdog->ctl);
79         while (1);
80 }
81
82 /* do some early init */
83 void s_init(void)
84 {
85 #if !defined CONFIG_SPL_BUILD && (defined CONFIG_SUN7I || defined CONFIG_SUN6I)
86         /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
87         asm volatile(
88                 "mrc p15, 0, r0, c1, c0, 1\n"
89                 "orr r0, r0, #1 << 6\n"
90                 "mcr p15, 0, r0, c1, c0, 1\n");
91 #endif
92
93         clock_init();
94         timer_init();
95         gpio_init();
96
97 #ifdef CONFIG_SPL_BUILD
98         gd = &gdata;
99         preloader_console_init();
100
101         sunxi_board_init();
102 #endif
103 }
104
105 #ifndef CONFIG_SYS_DCACHE_OFF
106 void enable_caches(void)
107 {
108         /* Enable D-cache. I-cache is already enabled in start.S */
109         dcache_enable();
110 }
111 #endif
112
113 #ifdef CONFIG_CMD_NET
114 /*
115  * Initializes on-chip ethernet controllers.
116  * to override, implement board_eth_init()
117  */
118 int cpu_eth_init(bd_t *bis)
119 {
120         __maybe_unused int rc;
121
122 #ifdef CONFIG_SUNXI_EMAC
123         rc = sunxi_emac_initialize(bis);
124         if (rc < 0) {
125                 printf("sunxi: failed to initialize emac\n");
126                 return rc;
127         }
128 #endif
129
130 #ifdef CONFIG_SUNXI_GMAC
131         rc = sunxi_gmac_initialize(bis);
132         if (rc < 0) {
133                 printf("sunxi: failed to initialize gmac\n");
134                 return rc;
135         }
136 #endif
137
138         return 0;
139 }
140 #endif