blob: bd14326cf4799aa99f8fab4a96c199c7ff46bb83 [file] [log] [blame]
Chandan Nath7d744102011-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 Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Chandan Nath7d744102011-10-14 02:58:26 +00009 */
10
11#include <common.h>
Simon Glass91d03902014-10-22 21:37:10 -060012#include <dm.h>
Tom Rini59c2cc92012-07-30 16:13:10 -070013#include <errno.h>
Simon Glassccc03a72014-10-22 21:37:11 -060014#include <ns16550.h>
Tom Rini28591df2012-08-13 12:03:19 -070015#include <spl.h>
Chandan Nath7d744102011-10-14 02:58:26 +000016#include <asm/arch/cpu.h>
17#include <asm/arch/hardware.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000018#include <asm/arch/omap.h>
Chandan Nath7d744102011-10-14 02:58:26 +000019#include <asm/arch/ddr_defs.h>
20#include <asm/arch/clock.h>
Steve Sakoman6229e332012-06-04 05:35:34 +000021#include <asm/arch/gpio.h>
Ilya Yanok2ebbb862012-11-06 13:06:30 +000022#include <asm/arch/mem.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000023#include <asm/arch/mmc_host_def.h>
Tom Rini7a247722012-07-31 10:50:01 -070024#include <asm/arch/sys_proto.h>
Chandan Nath7d744102011-10-14 02:58:26 +000025#include <asm/io.h>
Tom Rini3fd44562012-07-03 08:51:34 -070026#include <asm/emif.h>
Tom Rini4b302402012-07-31 08:55:01 -070027#include <asm/gpio.h>
Tom Rini59c2cc92012-07-30 16:13:10 -070028#include <i2c.h>
29#include <miiphy.h>
30#include <cpsw.h>
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +000031#include <asm/errno.h>
Tom Riniac8fdf92013-08-30 16:28:44 -040032#include <linux/compiler.h>
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +000033#include <linux/usb/ch9.h>
34#include <linux/usb/gadget.h>
35#include <linux/usb/musb.h>
36#include <asm/omap_musb.h>
Tom Rini56424eb2013-08-28 09:00:28 -040037#include <asm/davinci_rtc.h>
Chandan Nath7d744102011-10-14 02:58:26 +000038
39DECLARE_GLOBAL_DATA_PTR;
40
Tom Rini5ba15962015-07-31 19:55:08 -040041#if defined(CONFIG_DM_SERIAL) && !defined(CONFIG_OF_CONTROL)
Simon Glassccc03a72014-10-22 21:37:11 -060042/*
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 */
46static const struct ns16550_platdata am33xx_serial[] = {
47 { CONFIG_SYS_NS16550_COM1, 2, CONFIG_SYS_NS16550_CLK },
Tom Rini5ba15962015-07-31 19:55:08 -040048# ifdef CONFIG_SYS_NS16550_COM2
Simon Glassccc03a72014-10-22 21:37:11 -060049 { CONFIG_SYS_NS16550_COM2, 2, CONFIG_SYS_NS16550_CLK },
Tom Rini5ba15962015-07-31 19:55:08 -040050# ifdef CONFIG_SYS_NS16550_COM3
Simon Glassccc03a72014-10-22 21:37:11 -060051 { 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 },
Simon Glassccc03a72014-10-22 21:37:11 -060055# endif
Tom Rini5ba15962015-07-31 19:55:08 -040056# endif
Simon Glassccc03a72014-10-22 21:37:11 -060057};
58
59U_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};
Tom Rini5ba15962015-07-31 19:55:08 -040071#endif
Simon Glassccc03a72014-10-22 21:37:11 -060072
Simon Glass91d03902014-10-22 21:37:10 -060073
Tom Rini5ba15962015-07-31 19:55:08 -040074#ifndef CONFIG_DM_GPIO
Dave Gerlach00822ca2014-02-10 11:41:49 -050075static const struct gpio_bank gpio_bank_am33xx[] = {
Tom Rini7bc2bca2015-07-31 19:55:09 -040076 { (void *)AM33XX_GPIO0_BASE },
77 { (void *)AM33XX_GPIO1_BASE },
78 { (void *)AM33XX_GPIO2_BASE },
79 { (void *)AM33XX_GPIO3_BASE },
Dave Gerlach00822ca2014-02-10 11:41:49 -050080#ifdef CONFIG_AM43XX
Tom Rini7bc2bca2015-07-31 19:55:09 -040081 { (void *)AM33XX_GPIO4_BASE },
82 { (void *)AM33XX_GPIO5_BASE },
Dave Gerlach00822ca2014-02-10 11:41:49 -050083#endif
Steve Sakoman6229e332012-06-04 05:35:34 +000084};
85
86const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
Simon Glass91d03902014-10-22 21:37:10 -060087#endif
88
Chandan Nathd6e97f82012-01-09 20:38:58 +000089#if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
Peter Korsgaardaabb9f82012-10-18 01:21:10 +000090int cpu_mmc_init(bd_t *bis)
Chandan Nathd6e97f82012-01-09 20:38:58 +000091{
Tom Rini0dc71d12012-08-08 10:31:08 -070092 int ret;
Peter Korsgaardaabb9f82012-10-18 01:21:10 +000093
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +000094 ret = omap_mmc_init(0, 0, 0, -1, -1);
Tom Rini0dc71d12012-08-08 10:31:08 -070095 if (ret)
96 return ret;
97
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +000098 return omap_mmc_init(1, 0, 0, -1, -1);
Chandan Nathd6e97f82012-01-09 20:38:58 +000099}
100#endif
Chandan Nath77a73fe2012-01-09 20:38:59 +0000101
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000102/* AM33XX has two MUSB controllers which can be host or gadget */
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +0200103#if (defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)) && \
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000104 (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
105static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
106
107/* USB 2.0 PHY Control */
108#define CM_PHY_PWRDN (1 << 0)
109#define CM_PHY_OTG_PWRDN (1 << 1)
110#define OTGVDET_EN (1 << 19)
111#define OTGSESSENDEN (1 << 20)
112
113static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
114{
115 if (on) {
116 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
117 OTGVDET_EN | OTGSESSENDEN);
118 } else {
119 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
120 }
121}
122
123static struct musb_hdrc_config musb_config = {
124 .multipoint = 1,
125 .dyn_fifo = 1,
126 .num_eps = 16,
127 .ram_bits = 12,
128};
129
130#ifdef CONFIG_AM335X_USB0
131static void am33xx_otg0_set_phy_power(u8 on)
132{
133 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
134}
135
136struct omap_musb_board_data otg0_board_data = {
137 .set_phy_power = am33xx_otg0_set_phy_power,
138};
139
140static struct musb_hdrc_platform_data otg0_plat = {
141 .mode = CONFIG_AM335X_USB0_MODE,
142 .config = &musb_config,
143 .power = 50,
144 .platform_ops = &musb_dsps_ops,
145 .board_data = &otg0_board_data,
146};
147#endif
148
149#ifdef CONFIG_AM335X_USB1
150static void am33xx_otg1_set_phy_power(u8 on)
151{
152 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
153}
154
155struct omap_musb_board_data otg1_board_data = {
156 .set_phy_power = am33xx_otg1_set_phy_power,
157};
158
159static struct musb_hdrc_platform_data otg1_plat = {
160 .mode = CONFIG_AM335X_USB1_MODE,
161 .config = &musb_config,
162 .power = 50,
163 .platform_ops = &musb_dsps_ops,
164 .board_data = &otg1_board_data,
165};
166#endif
167#endif
168
169int arch_misc_init(void)
170{
171#ifdef CONFIG_AM335X_USB0
172 musb_register(&otg0_plat, &otg0_board_data,
Matt Portere24646f2013-03-15 10:07:02 +0000173 (void *)USB0_OTG_BASE);
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000174#endif
175#ifdef CONFIG_AM335X_USB1
176 musb_register(&otg1_plat, &otg1_board_data,
Matt Portere24646f2013-03-15 10:07:02 +0000177 (void *)USB1_OTG_BASE);
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000178#endif
179 return 0;
180}
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200181
Tom Rini8de09df2014-04-09 08:25:57 -0400182#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Tom Riniac8fdf92013-08-30 16:28:44 -0400183/*
Tom Rini9fec9ae2014-05-21 12:57:22 -0400184 * In the case of non-SPL based booting we'll want to call these
185 * functions a tiny bit later as it will require gd to be set and cleared
186 * and that's not true in s_init in this case so we cannot do it there.
187 */
188int board_early_init_f(void)
189{
190 prcm_init();
191 set_mux_conf_regs();
192
193 return 0;
194}
195
196/*
Tom Riniac8fdf92013-08-30 16:28:44 -0400197 * This function is the place to do per-board things such as ramp up the
198 * MPU clock frequency.
199 */
200__weak void am33xx_spl_board_init(void)
201{
Steve Kipisz5adac352013-08-14 10:51:31 -0400202 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
203 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
Tom Riniac8fdf92013-08-30 16:28:44 -0400204}
205
Heiko Schocher2233e462013-11-04 14:05:00 +0100206#if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530207static void rtc32k_enable(void)
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200208{
Tom Rini56424eb2013-08-28 09:00:28 -0400209 struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200210
211 /*
212 * Unlock the RTC's registers. For more details please see the
213 * RTC_SS section of the TRM. In order to unlock we need to
214 * write these specific values (keys) in this order.
215 */
Tom Rini56424eb2013-08-28 09:00:28 -0400216 writel(RTC_KICK0R_WE, &rtc->kick0r);
217 writel(RTC_KICK1R_WE, &rtc->kick1r);
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200218
219 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
220 writel((1 << 3) | (1 << 6), &rtc->osc);
221}
Heiko Schocher2233e462013-11-04 14:05:00 +0100222#endif
Heiko Schocher57004c52013-06-04 11:00:57 +0200223
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530224static void uart_soft_reset(void)
Heiko Schocher57004c52013-06-04 11:00:57 +0200225{
226 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
227 u32 regval;
228
229 regval = readl(&uart_base->uartsyscfg);
230 regval |= UART_RESET;
231 writel(regval, &uart_base->uartsyscfg);
232 while ((readl(&uart_base->uartsyssts) &
233 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
234 ;
235
236 /* Disable smart idle */
237 regval = readl(&uart_base->uartsyscfg);
238 regval |= UART_SMART_IDLE_EN;
239 writel(regval, &uart_base->uartsyscfg);
240}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530241
242static void watchdog_disable(void)
243{
244 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
245
246 writel(0xAAAA, &wdtimer->wdtwspr);
247 while (readl(&wdtimer->wdtwwps) != 0x0)
248 ;
249 writel(0x5555, &wdtimer->wdtwspr);
250 while (readl(&wdtimer->wdtwwps) != 0x0)
251 ;
252}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530253
Simon Glass0c078ea2015-03-03 08:03:02 -0700254#ifdef CONFIG_SPL_BUILD
255void board_init_f(ulong dummy)
256{
257 board_early_init_f();
258 sdram_init();
259}
260#endif
261
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530262void s_init(void)
263{
264 /*
265 * The ROM will only have set up sufficient pinmux to allow for the
266 * first 4KiB NOR to be read, we must finish doing what we know of
267 * the NOR mux in this space in order to continue.
268 */
269#ifdef CONFIG_NOR_BOOT
270 enable_norboot_pin_mux();
271#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530272 watchdog_disable();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530273 set_uart_mux_conf();
274 setup_clocks_for_console();
275 uart_soft_reset();
Sourav Poddar5248bba2014-05-19 16:53:37 -0400276#if defined(CONFIG_NOR_BOOT) || defined(CONFIG_QSPI_BOOT)
Simon Glass0c078ea2015-03-03 08:03:02 -0700277 /* TODO: This does not work, gd is not available yet */
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530278 gd->baudrate = CONFIG_BAUDRATE;
279 serial_init();
280 gd->have_console = 1;
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530281#endif
Heiko Schocher2233e462013-11-04 14:05:00 +0100282#if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530283 /* Enable RTC32K clock */
284 rtc32k_enable();
Heiko Schocher2233e462013-11-04 14:05:00 +0100285#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530286}
Tom Rini35c616c2014-03-05 14:57:47 -0500287#endif