blob: a8b5d13238a220a0ec012afe30f6bbd4d90c9b90 [file] [log] [blame]
Chandan Nath5289e832011-10-14 02:58:26 +00001/*
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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Chandan Nath5289e832011-10-14 02:58:26 +00009 */
10
11#include <common.h>
Simon Glassd12010b2014-10-22 21:37:10 -060012#include <dm.h>
Lokesh Vutla878d8852017-05-05 13:45:28 +053013#include <debug_uart.h>
Tom Rini973b6632012-07-30 16:13:10 -070014#include <errno.h>
Simon Glass4119e062014-10-22 21:37:11 -060015#include <ns16550.h>
Tom Rini47f7bca2012-08-13 12:03:19 -070016#include <spl.h>
Chandan Nath5289e832011-10-14 02:58:26 +000017#include <asm/arch/cpu.h>
18#include <asm/arch/hardware.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000019#include <asm/arch/omap.h>
Chandan Nath5289e832011-10-14 02:58:26 +000020#include <asm/arch/ddr_defs.h>
21#include <asm/arch/clock.h>
Steve Sakoman3b971522012-06-04 05:35:34 +000022#include <asm/arch/gpio.h>
Ilya Yanok8eb16b72012-11-06 13:06:30 +000023#include <asm/arch/mem.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000024#include <asm/arch/mmc_host_def.h>
Tom Rinidb7dd812012-07-31 10:50:01 -070025#include <asm/arch/sys_proto.h>
Chandan Nath5289e832011-10-14 02:58:26 +000026#include <asm/io.h>
Tom Rinifda35eb2012-07-03 08:51:34 -070027#include <asm/emif.h>
Tom Rini65d750b2012-07-31 08:55:01 -070028#include <asm/gpio.h>
Tom Rini973b6632012-07-30 16:13:10 -070029#include <i2c.h>
30#include <miiphy.h>
31#include <cpsw.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090032#include <linux/errno.h>
Tom Rini6a0d8032013-08-30 16:28:44 -040033#include <linux/compiler.h>
Ilya Yanok7df5cf32012-11-06 13:48:23 +000034#include <linux/usb/ch9.h>
35#include <linux/usb/gadget.h>
36#include <linux/usb/musb.h>
37#include <asm/omap_musb.h>
Tom Rini155d4242013-08-28 09:00:28 -040038#include <asm/davinci_rtc.h>
Chandan Nath5289e832011-10-14 02:58:26 +000039
40DECLARE_GLOBAL_DATA_PTR;
41
Tom Rini75507d52015-12-06 11:09:59 -050042#if !CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glass4119e062014-10-22 21:37:11 -060043static const struct ns16550_platdata am33xx_serial[] = {
Heiko Schocher17fa0322017-01-18 08:05:49 +010044 { .base = CONFIG_SYS_NS16550_COM1, .reg_shift = 2,
45 .clock = CONFIG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Tom Rini1480fdf2015-07-31 19:55:08 -040046# ifdef CONFIG_SYS_NS16550_COM2
Heiko Schocher17fa0322017-01-18 08:05:49 +010047 { .base = CONFIG_SYS_NS16550_COM2, .reg_shift = 2,
48 .clock = CONFIG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Tom Rini1480fdf2015-07-31 19:55:08 -040049# ifdef CONFIG_SYS_NS16550_COM3
Heiko Schocher17fa0322017-01-18 08:05:49 +010050 { .base = CONFIG_SYS_NS16550_COM3, .reg_shift = 2,
51 .clock = CONFIG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
52 { .base = CONFIG_SYS_NS16550_COM4, .reg_shift = 2,
53 .clock = CONFIG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
54 { .base = CONFIG_SYS_NS16550_COM5, .reg_shift = 2,
55 .clock = CONFIG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
56 { .base = CONFIG_SYS_NS16550_COM6, .reg_shift = 2,
57 .clock = CONFIG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Simon Glass4119e062014-10-22 21:37:11 -060058# endif
Tom Rini1480fdf2015-07-31 19:55:08 -040059# endif
Simon Glass4119e062014-10-22 21:37:11 -060060};
61
62U_BOOT_DEVICES(am33xx_uarts) = {
Tom Rini75507d52015-12-06 11:09:59 -050063 { "ns16550_serial", &am33xx_serial[0] },
Simon Glass4119e062014-10-22 21:37:11 -060064# ifdef CONFIG_SYS_NS16550_COM2
Tom Rini75507d52015-12-06 11:09:59 -050065 { "ns16550_serial", &am33xx_serial[1] },
Simon Glass4119e062014-10-22 21:37:11 -060066# ifdef CONFIG_SYS_NS16550_COM3
Tom Rini75507d52015-12-06 11:09:59 -050067 { "ns16550_serial", &am33xx_serial[2] },
68 { "ns16550_serial", &am33xx_serial[3] },
69 { "ns16550_serial", &am33xx_serial[4] },
70 { "ns16550_serial", &am33xx_serial[5] },
Simon Glass4119e062014-10-22 21:37:11 -060071# endif
72# endif
73};
Simon Glass4119e062014-10-22 21:37:11 -060074
Tom Rini90345c92016-01-05 12:17:15 -050075#ifdef CONFIG_DM_GPIO
76static const struct omap_gpio_platdata am33xx_gpio[] = {
77 { 0, AM33XX_GPIO0_BASE },
78 { 1, AM33XX_GPIO1_BASE },
79 { 2, AM33XX_GPIO2_BASE },
80 { 3, AM33XX_GPIO3_BASE },
81#ifdef CONFIG_AM43XX
82 { 4, AM33XX_GPIO4_BASE },
83 { 5, AM33XX_GPIO5_BASE },
84#endif
85};
86
87U_BOOT_DEVICES(am33xx_gpios) = {
88 { "gpio_omap", &am33xx_gpio[0] },
89 { "gpio_omap", &am33xx_gpio[1] },
90 { "gpio_omap", &am33xx_gpio[2] },
91 { "gpio_omap", &am33xx_gpio[3] },
92#ifdef CONFIG_AM43XX
93 { "gpio_omap", &am33xx_gpio[4] },
94 { "gpio_omap", &am33xx_gpio[5] },
95#endif
96};
97#endif
98#endif
Simon Glassd12010b2014-10-22 21:37:10 -060099
Tom Rini1480fdf2015-07-31 19:55:08 -0400100#ifndef CONFIG_DM_GPIO
Dave Gerlachcd8341b2014-02-10 11:41:49 -0500101static const struct gpio_bank gpio_bank_am33xx[] = {
Tom Rini0a9e3402015-07-31 19:55:09 -0400102 { (void *)AM33XX_GPIO0_BASE },
103 { (void *)AM33XX_GPIO1_BASE },
104 { (void *)AM33XX_GPIO2_BASE },
105 { (void *)AM33XX_GPIO3_BASE },
Dave Gerlachcd8341b2014-02-10 11:41:49 -0500106#ifdef CONFIG_AM43XX
Tom Rini0a9e3402015-07-31 19:55:09 -0400107 { (void *)AM33XX_GPIO4_BASE },
108 { (void *)AM33XX_GPIO5_BASE },
Dave Gerlachcd8341b2014-02-10 11:41:49 -0500109#endif
Steve Sakoman3b971522012-06-04 05:35:34 +0000110};
111
112const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
Simon Glassd12010b2014-10-22 21:37:10 -0600113#endif
114
Jean-Jacques Hiblotd5abcf92017-02-01 11:39:14 +0100115#if defined(CONFIG_MMC_OMAP_HS)
Peter Korsgaard75a23882012-10-18 01:21:10 +0000116int cpu_mmc_init(bd_t *bis)
Chandan Nath876bdd62012-01-09 20:38:58 +0000117{
Tom Rini0689a2e2012-08-08 10:31:08 -0700118 int ret;
Peter Korsgaard75a23882012-10-18 01:21:10 +0000119
Nikita Kiryanove3913f52012-12-03 02:19:47 +0000120 ret = omap_mmc_init(0, 0, 0, -1, -1);
Tom Rini0689a2e2012-08-08 10:31:08 -0700121 if (ret)
122 return ret;
123
Nikita Kiryanove3913f52012-12-03 02:19:47 +0000124 return omap_mmc_init(1, 0, 0, -1, -1);
Chandan Nath876bdd62012-01-09 20:38:58 +0000125}
126#endif
Chandan Nath8a8f0842012-01-09 20:38:59 +0000127
Ilya Yanok7df5cf32012-11-06 13:48:23 +0000128/* AM33XX has two MUSB controllers which can be host or gadget */
Paul Kocialkowski95de1e22015-08-04 17:04:06 +0200129#if (defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)) && \
Mugunthan V N19570222016-11-17 14:38:07 +0530130 (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1)) && \
131 (!defined(CONFIG_DM_USB))
Ilya Yanok7df5cf32012-11-06 13:48:23 +0000132static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
133
134/* USB 2.0 PHY Control */
135#define CM_PHY_PWRDN (1 << 0)
136#define CM_PHY_OTG_PWRDN (1 << 1)
137#define OTGVDET_EN (1 << 19)
138#define OTGSESSENDEN (1 << 20)
139
140static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
141{
142 if (on) {
143 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
144 OTGVDET_EN | OTGSESSENDEN);
145 } else {
146 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
147 }
148}
149
150static struct musb_hdrc_config musb_config = {
151 .multipoint = 1,
152 .dyn_fifo = 1,
153 .num_eps = 16,
154 .ram_bits = 12,
155};
156
157#ifdef CONFIG_AM335X_USB0
Mugunthan V N1cac34c2016-11-17 14:38:10 +0530158static void am33xx_otg0_set_phy_power(struct udevice *dev, u8 on)
Ilya Yanok7df5cf32012-11-06 13:48:23 +0000159{
160 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
161}
162
163struct omap_musb_board_data otg0_board_data = {
164 .set_phy_power = am33xx_otg0_set_phy_power,
165};
166
167static struct musb_hdrc_platform_data otg0_plat = {
168 .mode = CONFIG_AM335X_USB0_MODE,
169 .config = &musb_config,
170 .power = 50,
171 .platform_ops = &musb_dsps_ops,
172 .board_data = &otg0_board_data,
173};
174#endif
175
176#ifdef CONFIG_AM335X_USB1
Mugunthan V N1cac34c2016-11-17 14:38:10 +0530177static void am33xx_otg1_set_phy_power(struct udevice *dev, u8 on)
Ilya Yanok7df5cf32012-11-06 13:48:23 +0000178{
179 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
180}
181
182struct omap_musb_board_data otg1_board_data = {
183 .set_phy_power = am33xx_otg1_set_phy_power,
184};
185
186static struct musb_hdrc_platform_data otg1_plat = {
187 .mode = CONFIG_AM335X_USB1_MODE,
188 .config = &musb_config,
189 .power = 50,
190 .platform_ops = &musb_dsps_ops,
191 .board_data = &otg1_board_data,
192};
193#endif
194#endif
195
196int arch_misc_init(void)
197{
Mugunthan V N19570222016-11-17 14:38:07 +0530198#ifndef CONFIG_DM_USB
Ilya Yanok7df5cf32012-11-06 13:48:23 +0000199#ifdef CONFIG_AM335X_USB0
200 musb_register(&otg0_plat, &otg0_board_data,
Matt Porter81df2ba2013-03-15 10:07:02 +0000201 (void *)USB0_OTG_BASE);
Ilya Yanok7df5cf32012-11-06 13:48:23 +0000202#endif
203#ifdef CONFIG_AM335X_USB1
204 musb_register(&otg1_plat, &otg1_board_data,
Matt Porter81df2ba2013-03-15 10:07:02 +0000205 (void *)USB1_OTG_BASE);
Ilya Yanok7df5cf32012-11-06 13:48:23 +0000206#endif
Mugunthan V N3aec2642016-11-17 14:38:09 +0530207#else
208 struct udevice *dev;
209 int ret;
210
211 ret = uclass_first_device(UCLASS_MISC, &dev);
212 if (ret || !dev)
213 return ret;
Mugunthan V Nba7916c2016-11-17 14:38:13 +0530214
215#if defined(CONFIG_DM_ETH) && defined(CONFIG_USB_ETHER)
216 ret = usb_ether_init();
217 if (ret) {
218 error("USB ether init failed\n");
219 return ret;
220 }
221#endif
Mugunthan V N19570222016-11-17 14:38:07 +0530222#endif
Ilya Yanok7df5cf32012-11-06 13:48:23 +0000223 return 0;
224}
Heiko Schocher49f78362013-06-05 07:47:56 +0200225
Tom Rinid0e6d342014-04-09 08:25:57 -0400226#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Tom Rini6a0d8032013-08-30 16:28:44 -0400227/*
Tom Rini196311d2014-05-21 12:57:22 -0400228 * In the case of non-SPL based booting we'll want to call these
229 * functions a tiny bit later as it will require gd to be set and cleared
230 * and that's not true in s_init in this case so we cannot do it there.
231 */
232int board_early_init_f(void)
233{
234 prcm_init();
235 set_mux_conf_regs();
236
237 return 0;
238}
239
240/*
Tom Rini6a0d8032013-08-30 16:28:44 -0400241 * This function is the place to do per-board things such as ramp up the
242 * MPU clock frequency.
243 */
244__weak void am33xx_spl_board_init(void)
245{
246}
247
Heiko Schocher16678eb2013-11-04 14:05:00 +0100248#if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
Heiko Schocher06604812013-07-30 10:48:54 +0530249static void rtc32k_enable(void)
Heiko Schocher49f78362013-06-05 07:47:56 +0200250{
Tom Rini155d4242013-08-28 09:00:28 -0400251 struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
Heiko Schocher49f78362013-06-05 07:47:56 +0200252
253 /*
254 * Unlock the RTC's registers. For more details please see the
255 * RTC_SS section of the TRM. In order to unlock we need to
256 * write these specific values (keys) in this order.
257 */
Tom Rini155d4242013-08-28 09:00:28 -0400258 writel(RTC_KICK0R_WE, &rtc->kick0r);
259 writel(RTC_KICK1R_WE, &rtc->kick1r);
Heiko Schocher49f78362013-06-05 07:47:56 +0200260
261 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
262 writel((1 << 3) | (1 << 6), &rtc->osc);
263}
Heiko Schocher16678eb2013-11-04 14:05:00 +0100264#endif
Heiko Schocher7ea7f682013-06-04 11:00:57 +0200265
Heiko Schocher06604812013-07-30 10:48:54 +0530266static void uart_soft_reset(void)
Heiko Schocher7ea7f682013-06-04 11:00:57 +0200267{
268 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
269 u32 regval;
270
271 regval = readl(&uart_base->uartsyscfg);
272 regval |= UART_RESET;
273 writel(regval, &uart_base->uartsyscfg);
274 while ((readl(&uart_base->uartsyssts) &
275 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
276 ;
277
278 /* Disable smart idle */
279 regval = readl(&uart_base->uartsyscfg);
280 regval |= UART_SMART_IDLE_EN;
281 writel(regval, &uart_base->uartsyscfg);
282}
Heiko Schocher06604812013-07-30 10:48:54 +0530283
284static void watchdog_disable(void)
285{
286 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
287
288 writel(0xAAAA, &wdtimer->wdtwspr);
289 while (readl(&wdtimer->wdtwwps) != 0x0)
290 ;
291 writel(0x5555, &wdtimer->wdtwspr);
292 while (readl(&wdtimer->wdtwwps) != 0x0)
293 ;
294}
Heiko Schocher06604812013-07-30 10:48:54 +0530295
296void s_init(void)
297{
Lokesh Vutlac704a992016-10-14 10:35:23 +0530298}
299
300void early_system_init(void)
301{
Heiko Schocher06604812013-07-30 10:48:54 +0530302 /*
303 * The ROM will only have set up sufficient pinmux to allow for the
304 * first 4KiB NOR to be read, we must finish doing what we know of
305 * the NOR mux in this space in order to continue.
306 */
307#ifdef CONFIG_NOR_BOOT
308 enable_norboot_pin_mux();
309#endif
Heiko Schocher06604812013-07-30 10:48:54 +0530310 watchdog_disable();
Heiko Schocher06604812013-07-30 10:48:54 +0530311 set_uart_mux_conf();
Lokesh Vutlab64a7cb2016-10-14 10:35:24 +0530312 setup_early_clocks();
Heiko Schocher06604812013-07-30 10:48:54 +0530313 uart_soft_reset();
Lokesh Vutla878d8852017-05-05 13:45:28 +0530314#ifdef CONFIG_DEBUG_UART_OMAP
315 debug_uart_init();
316#endif
Lokesh Vutla140d76a2016-10-14 10:35:25 +0530317#ifdef CONFIG_TI_I2C_BOARD_DETECT
318 do_board_detect();
319#endif
Heiko Schocher16678eb2013-11-04 14:05:00 +0100320#if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
Heiko Schocher06604812013-07-30 10:48:54 +0530321 /* Enable RTC32K clock */
322 rtc32k_enable();
Heiko Schocher16678eb2013-11-04 14:05:00 +0100323#endif
Heiko Schocher06604812013-07-30 10:48:54 +0530324}
Lokesh Vutlac704a992016-10-14 10:35:23 +0530325
326#ifdef CONFIG_SPL_BUILD
327void board_init_f(ulong dummy)
328{
329 early_system_init();
330 board_early_init_f();
331 sdram_init();
Lokesh Vutla86282792017-04-18 17:27:24 +0530332 /* dram_init must store complete ramsize in gd->ram_size */
333 gd->ram_size = get_ram_size(
334 (void *)CONFIG_SYS_SDRAM_BASE,
335 CONFIG_MAX_RAM_BANK_SIZE);
Lokesh Vutlac704a992016-10-14 10:35:23 +0530336}
Tom Rinid73f38f2014-03-05 14:57:47 -0500337#endif
Lokesh Vutlac704a992016-10-14 10:35:23 +0530338
339#endif
340
341int arch_cpu_init_dm(void)
342{
343#ifndef CONFIG_SKIP_LOWLEVEL_INIT
344 early_system_init();
345#endif
346 return 0;
347}