]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/am33xx/board.c
am33xx: Update DT files, add am335x_gp_evm_config target
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / am33xx / board.c
1 /*
2  * board.c
3  *
4  * Common board functions for AM33XX based boards
5  *
6  * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
7  *
8  * SPDX-License-Identifier:     GPL-2.0+
9  */
10
11 #include <common.h>
12 #include <dm.h>
13 #include <errno.h>
14 #include <ns16550.h>
15 #include <spl.h>
16 #include <asm/arch/cpu.h>
17 #include <asm/arch/hardware.h>
18 #include <asm/arch/omap.h>
19 #include <asm/arch/ddr_defs.h>
20 #include <asm/arch/clock.h>
21 #include <asm/arch/gpio.h>
22 #include <asm/arch/mem.h>
23 #include <asm/arch/mmc_host_def.h>
24 #include <asm/arch/sys_proto.h>
25 #include <asm/io.h>
26 #include <asm/emif.h>
27 #include <asm/gpio.h>
28 #include <i2c.h>
29 #include <miiphy.h>
30 #include <cpsw.h>
31 #include <asm/errno.h>
32 #include <linux/compiler.h>
33 #include <linux/usb/ch9.h>
34 #include <linux/usb/gadget.h>
35 #include <linux/usb/musb.h>
36 #include <asm/omap_musb.h>
37 #include <asm/davinci_rtc.h>
38
39 DECLARE_GLOBAL_DATA_PTR;
40
41 #if defined(CONFIG_DM_SERIAL) && !defined(CONFIG_OF_CONTROL)
42 /*
43  * TODO(sjg@chromium.org): When we can move SPL serial to DM, we can remove
44  * the CONFIGs. At the same time, we should move this to the board files.
45  */
46 static const struct ns16550_platdata am33xx_serial[] = {
47         { CONFIG_SYS_NS16550_COM1, 2, CONFIG_SYS_NS16550_CLK },
48 # ifdef CONFIG_SYS_NS16550_COM2
49         { CONFIG_SYS_NS16550_COM2, 2, CONFIG_SYS_NS16550_CLK },
50 #  ifdef CONFIG_SYS_NS16550_COM3
51         { CONFIG_SYS_NS16550_COM3, 2, CONFIG_SYS_NS16550_CLK },
52         { CONFIG_SYS_NS16550_COM4, 2, CONFIG_SYS_NS16550_CLK },
53         { CONFIG_SYS_NS16550_COM5, 2, CONFIG_SYS_NS16550_CLK },
54         { CONFIG_SYS_NS16550_COM6, 2, CONFIG_SYS_NS16550_CLK },
55 #  endif
56 # endif
57 };
58
59 U_BOOT_DEVICES(am33xx_uarts) = {
60         { "serial_omap", &am33xx_serial[0] },
61 #  ifdef CONFIG_SYS_NS16550_COM2
62         { "serial_omap", &am33xx_serial[1] },
63 #   ifdef CONFIG_SYS_NS16550_COM3
64         { "serial_omap", &am33xx_serial[2] },
65         { "serial_omap", &am33xx_serial[3] },
66         { "serial_omap", &am33xx_serial[4] },
67         { "serial_omap", &am33xx_serial[5] },
68 #   endif
69 #  endif
70 };
71 #endif
72
73
74 #ifndef CONFIG_DM_GPIO
75 static const struct gpio_bank gpio_bank_am33xx[] = {
76         { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
77         { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
78         { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
79         { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
80 #ifdef CONFIG_AM43XX
81         { (void *)AM33XX_GPIO4_BASE, METHOD_GPIO_24XX },
82         { (void *)AM33XX_GPIO5_BASE, METHOD_GPIO_24XX },
83 #endif
84 };
85
86 const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
87 #endif
88
89 #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
90 int __cpu_mmc_init(bd_t *bis)
91 {
92         int ret;
93
94         ret = omap_mmc_init(0, 0, 0, -1, -1);
95         if (ret)
96                 return ret;
97
98         return omap_mmc_init(1, 0, 0, -1, -1);
99 }
100 /* let platform code be able to override this! */
101 int cpu_mmc_init(bd_t *bis) __attribute__((weak, alias("__cpu_mmc_init")));
102 #endif
103
104 /* AM33XX has two MUSB controllers which can be host or gadget */
105 #if (defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)) && \
106         (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
107 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
108
109 /* USB 2.0 PHY Control */
110 #define CM_PHY_PWRDN                    (1 << 0)
111 #define CM_PHY_OTG_PWRDN                (1 << 1)
112 #define OTGVDET_EN                      (1 << 19)
113 #define OTGSESSENDEN                    (1 << 20)
114
115 static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
116 {
117         if (on) {
118                 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
119                                 OTGVDET_EN | OTGSESSENDEN);
120         } else {
121                 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
122         }
123 }
124
125 static struct musb_hdrc_config musb_config = {
126         .multipoint     = 1,
127         .dyn_fifo       = 1,
128         .num_eps        = 16,
129         .ram_bits       = 12,
130 };
131
132 #ifdef CONFIG_AM335X_USB0
133 static void am33xx_otg0_set_phy_power(u8 on)
134 {
135         am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
136 }
137
138 struct omap_musb_board_data otg0_board_data = {
139         .set_phy_power = am33xx_otg0_set_phy_power,
140 };
141
142 static struct musb_hdrc_platform_data otg0_plat = {
143         .mode           = CONFIG_AM335X_USB0_MODE,
144         .config         = &musb_config,
145         .power          = 50,
146         .platform_ops   = &musb_dsps_ops,
147         .board_data     = &otg0_board_data,
148 };
149 #endif
150
151 #ifdef CONFIG_AM335X_USB1
152 static void am33xx_otg1_set_phy_power(u8 on)
153 {
154         am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
155 }
156
157 struct omap_musb_board_data otg1_board_data = {
158         .set_phy_power = am33xx_otg1_set_phy_power,
159 };
160
161 static struct musb_hdrc_platform_data otg1_plat = {
162         .mode           = CONFIG_AM335X_USB1_MODE,
163         .config         = &musb_config,
164         .power          = 50,
165         .platform_ops   = &musb_dsps_ops,
166         .board_data     = &otg1_board_data,
167 };
168 #endif
169 #endif
170
171 int arch_misc_init(void)
172 {
173 #ifdef CONFIG_AM335X_USB0
174         musb_register(&otg0_plat, &otg0_board_data,
175                 (void *)USB0_OTG_BASE);
176 #endif
177 #ifdef CONFIG_AM335X_USB1
178         musb_register(&otg1_plat, &otg1_board_data,
179                 (void *)USB1_OTG_BASE);
180 #endif
181         return 0;
182 }
183
184 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
185 /*
186  * In the case of non-SPL based booting we'll want to call these
187  * functions a tiny bit later as it will require gd to be set and cleared
188  * and that's not true in s_init in this case so we cannot do it there.
189  */
190 int board_early_init_f(void)
191 {
192         prcm_init();
193         set_mux_conf_regs();
194
195         return 0;
196 }
197
198 /*
199  * This function is the place to do per-board things such as ramp up the
200  * MPU clock frequency.
201  */
202 __weak void am33xx_spl_board_init(void)
203 {
204         do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
205         do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
206 }
207
208 #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
209 static void rtc32k_enable(void)
210 {
211         struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
212
213         /*
214          * Unlock the RTC's registers.  For more details please see the
215          * RTC_SS section of the TRM.  In order to unlock we need to
216          * write these specific values (keys) in this order.
217          */
218         writel(RTC_KICK0R_WE, &rtc->kick0r);
219         writel(RTC_KICK1R_WE, &rtc->kick1r);
220
221         /* Enable the RTC 32K OSC by setting bits 3 and 6. */
222         writel((1 << 3) | (1 << 6), &rtc->osc);
223 }
224 #endif
225
226 static void uart_soft_reset(void)
227 {
228         struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
229         u32 regval;
230
231         regval = readl(&uart_base->uartsyscfg);
232         regval |= UART_RESET;
233         writel(regval, &uart_base->uartsyscfg);
234         while ((readl(&uart_base->uartsyssts) &
235                 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
236                 ;
237
238         /* Disable smart idle */
239         regval = readl(&uart_base->uartsyscfg);
240         regval |= UART_SMART_IDLE_EN;
241         writel(regval, &uart_base->uartsyscfg);
242 }
243
244 static void watchdog_disable(void)
245 {
246         struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
247
248         writel(0xAAAA, &wdtimer->wdtwspr);
249         while (readl(&wdtimer->wdtwwps) != 0x0)
250                 ;
251         writel(0x5555, &wdtimer->wdtwspr);
252         while (readl(&wdtimer->wdtwwps) != 0x0)
253                 ;
254 }
255
256 #ifdef CONFIG_SPL_BUILD
257 void board_init_f(ulong dummy)
258 {
259         board_early_init_f();
260         sdram_init();
261 }
262 #endif
263
264 void s_init(void)
265 {
266         /*
267          * The ROM will only have set up sufficient pinmux to allow for the
268          * first 4KiB NOR to be read, we must finish doing what we know of
269          * the NOR mux in this space in order to continue.
270          */
271 #ifdef CONFIG_NOR_BOOT
272         enable_norboot_pin_mux();
273 #endif
274         watchdog_disable();
275         set_uart_mux_conf();
276         setup_clocks_for_console();
277         uart_soft_reset();
278 #if defined(CONFIG_NOR_BOOT) || defined(CONFIG_QSPI_BOOT)
279         /* TODO: This does not work, gd is not available yet */
280         gd->baudrate = CONFIG_BAUDRATE;
281         serial_init();
282         gd->have_console = 1;
283 #endif
284 #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
285         /* Enable RTC32K clock */
286         rtc32k_enable();
287 #endif
288 }
289 #endif