blob: c7dad6681d14a2201562633de6a58a8dfb657b7a [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>
Tom Rini59c2cc92012-07-30 16:13:10 -070012#include <errno.h>
Tom Rini28591df2012-08-13 12:03:19 -070013#include <spl.h>
Chandan Nath7d744102011-10-14 02:58:26 +000014#include <asm/arch/cpu.h>
15#include <asm/arch/hardware.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000016#include <asm/arch/omap.h>
Chandan Nath7d744102011-10-14 02:58:26 +000017#include <asm/arch/ddr_defs.h>
18#include <asm/arch/clock.h>
Steve Sakoman6229e332012-06-04 05:35:34 +000019#include <asm/arch/gpio.h>
Ilya Yanok2ebbb862012-11-06 13:06:30 +000020#include <asm/arch/mem.h>
Chandan Nath77a73fe2012-01-09 20:38:59 +000021#include <asm/arch/mmc_host_def.h>
Tom Rini7a247722012-07-31 10:50:01 -070022#include <asm/arch/sys_proto.h>
Chandan Nath7d744102011-10-14 02:58:26 +000023#include <asm/io.h>
Tom Rini3fd44562012-07-03 08:51:34 -070024#include <asm/emif.h>
Tom Rini4b302402012-07-31 08:55:01 -070025#include <asm/gpio.h>
Tom Rini59c2cc92012-07-30 16:13:10 -070026#include <i2c.h>
27#include <miiphy.h>
28#include <cpsw.h>
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +000029#include <asm/errno.h>
Tom Riniac8fdf92013-08-30 16:28:44 -040030#include <linux/compiler.h>
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +000031#include <linux/usb/ch9.h>
32#include <linux/usb/gadget.h>
33#include <linux/usb/musb.h>
34#include <asm/omap_musb.h>
Tom Rini56424eb2013-08-28 09:00:28 -040035#include <asm/davinci_rtc.h>
Chandan Nath7d744102011-10-14 02:58:26 +000036
37DECLARE_GLOBAL_DATA_PTR;
38
Steve Sakoman6229e332012-06-04 05:35:34 +000039static const struct gpio_bank gpio_bank_am33xx[4] = {
40 { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
41 { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
42 { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
43 { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
44};
45
46const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
47
Chandan Nathd6e97f82012-01-09 20:38:58 +000048#if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
Peter Korsgaardaabb9f82012-10-18 01:21:10 +000049int cpu_mmc_init(bd_t *bis)
Chandan Nathd6e97f82012-01-09 20:38:58 +000050{
Tom Rini0dc71d12012-08-08 10:31:08 -070051 int ret;
Peter Korsgaardaabb9f82012-10-18 01:21:10 +000052
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +000053 ret = omap_mmc_init(0, 0, 0, -1, -1);
Tom Rini0dc71d12012-08-08 10:31:08 -070054 if (ret)
55 return ret;
56
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +000057 return omap_mmc_init(1, 0, 0, -1, -1);
Chandan Nathd6e97f82012-01-09 20:38:58 +000058}
59#endif
Chandan Nath77a73fe2012-01-09 20:38:59 +000060
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +000061/* AM33XX has two MUSB controllers which can be host or gadget */
62#if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \
63 (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
64static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
65
66/* USB 2.0 PHY Control */
67#define CM_PHY_PWRDN (1 << 0)
68#define CM_PHY_OTG_PWRDN (1 << 1)
69#define OTGVDET_EN (1 << 19)
70#define OTGSESSENDEN (1 << 20)
71
72static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
73{
74 if (on) {
75 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
76 OTGVDET_EN | OTGSESSENDEN);
77 } else {
78 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
79 }
80}
81
82static struct musb_hdrc_config musb_config = {
83 .multipoint = 1,
84 .dyn_fifo = 1,
85 .num_eps = 16,
86 .ram_bits = 12,
87};
88
89#ifdef CONFIG_AM335X_USB0
90static void am33xx_otg0_set_phy_power(u8 on)
91{
92 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
93}
94
95struct omap_musb_board_data otg0_board_data = {
96 .set_phy_power = am33xx_otg0_set_phy_power,
97};
98
99static struct musb_hdrc_platform_data otg0_plat = {
100 .mode = CONFIG_AM335X_USB0_MODE,
101 .config = &musb_config,
102 .power = 50,
103 .platform_ops = &musb_dsps_ops,
104 .board_data = &otg0_board_data,
105};
106#endif
107
108#ifdef CONFIG_AM335X_USB1
109static void am33xx_otg1_set_phy_power(u8 on)
110{
111 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
112}
113
114struct omap_musb_board_data otg1_board_data = {
115 .set_phy_power = am33xx_otg1_set_phy_power,
116};
117
118static struct musb_hdrc_platform_data otg1_plat = {
119 .mode = CONFIG_AM335X_USB1_MODE,
120 .config = &musb_config,
121 .power = 50,
122 .platform_ops = &musb_dsps_ops,
123 .board_data = &otg1_board_data,
124};
125#endif
126#endif
127
128int arch_misc_init(void)
129{
130#ifdef CONFIG_AM335X_USB0
131 musb_register(&otg0_plat, &otg0_board_data,
Matt Portere24646f2013-03-15 10:07:02 +0000132 (void *)USB0_OTG_BASE);
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000133#endif
134#ifdef CONFIG_AM335X_USB1
135 musb_register(&otg1_plat, &otg1_board_data,
Matt Portere24646f2013-03-15 10:07:02 +0000136 (void *)USB1_OTG_BASE);
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000137#endif
138 return 0;
139}
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200140
Steve Kipiszc1399b42013-07-18 15:13:04 -0400141#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
Tom Riniac8fdf92013-08-30 16:28:44 -0400142/*
143 * This function is the place to do per-board things such as ramp up the
144 * MPU clock frequency.
145 */
146__weak void am33xx_spl_board_init(void)
147{
Steve Kipisz5adac352013-08-14 10:51:31 -0400148 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
149 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
Tom Riniac8fdf92013-08-30 16:28:44 -0400150}
151
Heiko Schocher2233e462013-11-04 14:05:00 +0100152#if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530153static void rtc32k_enable(void)
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200154{
Tom Rini56424eb2013-08-28 09:00:28 -0400155 struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200156
157 /*
158 * Unlock the RTC's registers. For more details please see the
159 * RTC_SS section of the TRM. In order to unlock we need to
160 * write these specific values (keys) in this order.
161 */
Tom Rini56424eb2013-08-28 09:00:28 -0400162 writel(RTC_KICK0R_WE, &rtc->kick0r);
163 writel(RTC_KICK1R_WE, &rtc->kick1r);
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200164
165 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
166 writel((1 << 3) | (1 << 6), &rtc->osc);
167}
Heiko Schocher2233e462013-11-04 14:05:00 +0100168#endif
Heiko Schocher57004c52013-06-04 11:00:57 +0200169
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530170static void uart_soft_reset(void)
Heiko Schocher57004c52013-06-04 11:00:57 +0200171{
172 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
173 u32 regval;
174
175 regval = readl(&uart_base->uartsyscfg);
176 regval |= UART_RESET;
177 writel(regval, &uart_base->uartsyscfg);
178 while ((readl(&uart_base->uartsyssts) &
179 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
180 ;
181
182 /* Disable smart idle */
183 regval = readl(&uart_base->uartsyscfg);
184 regval |= UART_SMART_IDLE_EN;
185 writel(regval, &uart_base->uartsyscfg);
186}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530187
188static void watchdog_disable(void)
189{
190 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
191
192 writel(0xAAAA, &wdtimer->wdtwspr);
193 while (readl(&wdtimer->wdtwwps) != 0x0)
194 ;
195 writel(0x5555, &wdtimer->wdtwspr);
196 while (readl(&wdtimer->wdtwwps) != 0x0)
197 ;
198}
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200199#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530200
201void s_init(void)
202{
203 /*
204 * The ROM will only have set up sufficient pinmux to allow for the
205 * first 4KiB NOR to be read, we must finish doing what we know of
206 * the NOR mux in this space in order to continue.
207 */
208#ifdef CONFIG_NOR_BOOT
209 enable_norboot_pin_mux();
210#endif
211 /*
212 * Save the boot parameters passed from romcode.
213 * We cannot delay the saving further than this,
214 * to prevent overwrites.
215 */
216#ifdef CONFIG_SPL_BUILD
217 save_omap_boot_params();
218#endif
219#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
220 watchdog_disable();
221 timer_init();
222 set_uart_mux_conf();
223 setup_clocks_for_console();
224 uart_soft_reset();
225#endif
226#ifdef CONFIG_NOR_BOOT
227 gd->baudrate = CONFIG_BAUDRATE;
228 serial_init();
229 gd->have_console = 1;
230#else
231 gd = &gdata;
232 preloader_console_init();
233#endif
234#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
235 prcm_init();
236 set_mux_conf_regs();
Heiko Schocher2233e462013-11-04 14:05:00 +0100237#if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530238 /* Enable RTC32K clock */
239 rtc32k_enable();
Heiko Schocher2233e462013-11-04 14:05:00 +0100240#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530241 sdram_init();
242#endif
243}
Tom Rinie290d172013-08-23 12:26:49 -0400244
245#ifndef CONFIG_SYS_DCACHE_OFF
246void enable_caches(void)
247{
248 /* Enable D-cache. I-cache is already enabled in start.S */
249 dcache_enable();
250}
251#endif /* !CONFIG_SYS_DCACHE_OFF */