blob: 466348f9402d2a23f4eacecd26e09ada6b34ed9a [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 Rini18dc02e2015-12-06 11:09:59 -050041#if !CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glassccc03a72014-10-22 21:37:11 -060042static const struct ns16550_platdata am33xx_serial[] = {
43 { CONFIG_SYS_NS16550_COM1, 2, CONFIG_SYS_NS16550_CLK },
Tom Rini5ba15962015-07-31 19:55:08 -040044# ifdef CONFIG_SYS_NS16550_COM2
Simon Glassccc03a72014-10-22 21:37:11 -060045 { CONFIG_SYS_NS16550_COM2, 2, CONFIG_SYS_NS16550_CLK },
Tom Rini5ba15962015-07-31 19:55:08 -040046# ifdef CONFIG_SYS_NS16550_COM3
Simon Glassccc03a72014-10-22 21:37:11 -060047 { CONFIG_SYS_NS16550_COM3, 2, CONFIG_SYS_NS16550_CLK },
48 { CONFIG_SYS_NS16550_COM4, 2, CONFIG_SYS_NS16550_CLK },
49 { CONFIG_SYS_NS16550_COM5, 2, CONFIG_SYS_NS16550_CLK },
50 { CONFIG_SYS_NS16550_COM6, 2, CONFIG_SYS_NS16550_CLK },
Simon Glassccc03a72014-10-22 21:37:11 -060051# endif
Tom Rini5ba15962015-07-31 19:55:08 -040052# endif
Simon Glassccc03a72014-10-22 21:37:11 -060053};
54
55U_BOOT_DEVICES(am33xx_uarts) = {
Tom Rini18dc02e2015-12-06 11:09:59 -050056 { "ns16550_serial", &am33xx_serial[0] },
Simon Glassccc03a72014-10-22 21:37:11 -060057# ifdef CONFIG_SYS_NS16550_COM2
Tom Rini18dc02e2015-12-06 11:09:59 -050058 { "ns16550_serial", &am33xx_serial[1] },
Simon Glassccc03a72014-10-22 21:37:11 -060059# ifdef CONFIG_SYS_NS16550_COM3
Tom Rini18dc02e2015-12-06 11:09:59 -050060 { "ns16550_serial", &am33xx_serial[2] },
61 { "ns16550_serial", &am33xx_serial[3] },
62 { "ns16550_serial", &am33xx_serial[4] },
63 { "ns16550_serial", &am33xx_serial[5] },
Simon Glassccc03a72014-10-22 21:37:11 -060064# endif
65# endif
66};
Tom Rini5ba15962015-07-31 19:55:08 -040067#endif
Simon Glassccc03a72014-10-22 21:37:11 -060068
Simon Glass91d03902014-10-22 21:37:10 -060069
Tom Rini5ba15962015-07-31 19:55:08 -040070#ifndef CONFIG_DM_GPIO
Dave Gerlach00822ca2014-02-10 11:41:49 -050071static const struct gpio_bank gpio_bank_am33xx[] = {
Tom Rini7bc2bca2015-07-31 19:55:09 -040072 { (void *)AM33XX_GPIO0_BASE },
73 { (void *)AM33XX_GPIO1_BASE },
74 { (void *)AM33XX_GPIO2_BASE },
75 { (void *)AM33XX_GPIO3_BASE },
Dave Gerlach00822ca2014-02-10 11:41:49 -050076#ifdef CONFIG_AM43XX
Tom Rini7bc2bca2015-07-31 19:55:09 -040077 { (void *)AM33XX_GPIO4_BASE },
78 { (void *)AM33XX_GPIO5_BASE },
Dave Gerlach00822ca2014-02-10 11:41:49 -050079#endif
Steve Sakoman6229e332012-06-04 05:35:34 +000080};
81
82const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
Simon Glass91d03902014-10-22 21:37:10 -060083#endif
84
Chandan Nathd6e97f82012-01-09 20:38:58 +000085#if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
Peter Korsgaardaabb9f82012-10-18 01:21:10 +000086int cpu_mmc_init(bd_t *bis)
Chandan Nathd6e97f82012-01-09 20:38:58 +000087{
Tom Rini0dc71d12012-08-08 10:31:08 -070088 int ret;
Peter Korsgaardaabb9f82012-10-18 01:21:10 +000089
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +000090 ret = omap_mmc_init(0, 0, 0, -1, -1);
Tom Rini0dc71d12012-08-08 10:31:08 -070091 if (ret)
92 return ret;
93
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +000094 return omap_mmc_init(1, 0, 0, -1, -1);
Chandan Nathd6e97f82012-01-09 20:38:58 +000095}
96#endif
Chandan Nath77a73fe2012-01-09 20:38:59 +000097
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +000098/* AM33XX has two MUSB controllers which can be host or gadget */
Paul Kocialkowskif34dfcb2015-08-04 17:04:06 +020099#if (defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)) && \
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000100 (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
101static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
102
103/* USB 2.0 PHY Control */
104#define CM_PHY_PWRDN (1 << 0)
105#define CM_PHY_OTG_PWRDN (1 << 1)
106#define OTGVDET_EN (1 << 19)
107#define OTGSESSENDEN (1 << 20)
108
109static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
110{
111 if (on) {
112 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
113 OTGVDET_EN | OTGSESSENDEN);
114 } else {
115 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
116 }
117}
118
119static struct musb_hdrc_config musb_config = {
120 .multipoint = 1,
121 .dyn_fifo = 1,
122 .num_eps = 16,
123 .ram_bits = 12,
124};
125
126#ifdef CONFIG_AM335X_USB0
127static void am33xx_otg0_set_phy_power(u8 on)
128{
129 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
130}
131
132struct omap_musb_board_data otg0_board_data = {
133 .set_phy_power = am33xx_otg0_set_phy_power,
134};
135
136static struct musb_hdrc_platform_data otg0_plat = {
137 .mode = CONFIG_AM335X_USB0_MODE,
138 .config = &musb_config,
139 .power = 50,
140 .platform_ops = &musb_dsps_ops,
141 .board_data = &otg0_board_data,
142};
143#endif
144
145#ifdef CONFIG_AM335X_USB1
146static void am33xx_otg1_set_phy_power(u8 on)
147{
148 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
149}
150
151struct omap_musb_board_data otg1_board_data = {
152 .set_phy_power = am33xx_otg1_set_phy_power,
153};
154
155static struct musb_hdrc_platform_data otg1_plat = {
156 .mode = CONFIG_AM335X_USB1_MODE,
157 .config = &musb_config,
158 .power = 50,
159 .platform_ops = &musb_dsps_ops,
160 .board_data = &otg1_board_data,
161};
162#endif
163#endif
164
165int arch_misc_init(void)
166{
167#ifdef CONFIG_AM335X_USB0
168 musb_register(&otg0_plat, &otg0_board_data,
Matt Portere24646f2013-03-15 10:07:02 +0000169 (void *)USB0_OTG_BASE);
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000170#endif
171#ifdef CONFIG_AM335X_USB1
172 musb_register(&otg1_plat, &otg1_board_data,
Matt Portere24646f2013-03-15 10:07:02 +0000173 (void *)USB1_OTG_BASE);
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000174#endif
175 return 0;
176}
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200177
Tom Rini8de09df2014-04-09 08:25:57 -0400178#ifndef CONFIG_SKIP_LOWLEVEL_INIT
Tom Riniac8fdf92013-08-30 16:28:44 -0400179/*
Tom Rini9fec9ae2014-05-21 12:57:22 -0400180 * In the case of non-SPL based booting we'll want to call these
181 * functions a tiny bit later as it will require gd to be set and cleared
182 * and that's not true in s_init in this case so we cannot do it there.
183 */
184int board_early_init_f(void)
185{
186 prcm_init();
187 set_mux_conf_regs();
188
189 return 0;
190}
191
192/*
Tom Riniac8fdf92013-08-30 16:28:44 -0400193 * This function is the place to do per-board things such as ramp up the
194 * MPU clock frequency.
195 */
196__weak void am33xx_spl_board_init(void)
197{
Steve Kipisz5adac352013-08-14 10:51:31 -0400198 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
199 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
Tom Riniac8fdf92013-08-30 16:28:44 -0400200}
201
Heiko Schocher2233e462013-11-04 14:05:00 +0100202#if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530203static void rtc32k_enable(void)
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200204{
Tom Rini56424eb2013-08-28 09:00:28 -0400205 struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200206
207 /*
208 * Unlock the RTC's registers. For more details please see the
209 * RTC_SS section of the TRM. In order to unlock we need to
210 * write these specific values (keys) in this order.
211 */
Tom Rini56424eb2013-08-28 09:00:28 -0400212 writel(RTC_KICK0R_WE, &rtc->kick0r);
213 writel(RTC_KICK1R_WE, &rtc->kick1r);
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200214
215 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
216 writel((1 << 3) | (1 << 6), &rtc->osc);
217}
Heiko Schocher2233e462013-11-04 14:05:00 +0100218#endif
Heiko Schocher57004c52013-06-04 11:00:57 +0200219
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530220static void uart_soft_reset(void)
Heiko Schocher57004c52013-06-04 11:00:57 +0200221{
222 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
223 u32 regval;
224
225 regval = readl(&uart_base->uartsyscfg);
226 regval |= UART_RESET;
227 writel(regval, &uart_base->uartsyscfg);
228 while ((readl(&uart_base->uartsyssts) &
229 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
230 ;
231
232 /* Disable smart idle */
233 regval = readl(&uart_base->uartsyscfg);
234 regval |= UART_SMART_IDLE_EN;
235 writel(regval, &uart_base->uartsyscfg);
236}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530237
238static void watchdog_disable(void)
239{
240 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
241
242 writel(0xAAAA, &wdtimer->wdtwspr);
243 while (readl(&wdtimer->wdtwwps) != 0x0)
244 ;
245 writel(0x5555, &wdtimer->wdtwspr);
246 while (readl(&wdtimer->wdtwwps) != 0x0)
247 ;
248}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530249
Simon Glass0c078ea2015-03-03 08:03:02 -0700250#ifdef CONFIG_SPL_BUILD
251void board_init_f(ulong dummy)
252{
253 board_early_init_f();
254 sdram_init();
255}
256#endif
257
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530258void s_init(void)
259{
260 /*
261 * The ROM will only have set up sufficient pinmux to allow for the
262 * first 4KiB NOR to be read, we must finish doing what we know of
263 * the NOR mux in this space in order to continue.
264 */
265#ifdef CONFIG_NOR_BOOT
266 enable_norboot_pin_mux();
267#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530268 watchdog_disable();
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530269 set_uart_mux_conf();
270 setup_clocks_for_console();
271 uart_soft_reset();
Heiko Schocher2233e462013-11-04 14:05:00 +0100272#if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530273 /* Enable RTC32K clock */
274 rtc32k_enable();
Heiko Schocher2233e462013-11-04 14:05:00 +0100275#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530276}
Tom Rini35c616c2014-03-05 14:57:47 -0500277#endif