blob: 2ea3d698fb2cae43f92c4e9f2071fcee01d0c698 [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>
Tom Rini973b6632012-07-30 16:13:10 -070012#include <errno.h>
Tom Rini47f7bca2012-08-13 12:03:19 -070013#include <spl.h>
Chandan Nath5289e832011-10-14 02:58:26 +000014#include <asm/arch/cpu.h>
15#include <asm/arch/hardware.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000016#include <asm/arch/omap.h>
Chandan Nath5289e832011-10-14 02:58:26 +000017#include <asm/arch/ddr_defs.h>
18#include <asm/arch/clock.h>
Steve Sakoman3b971522012-06-04 05:35:34 +000019#include <asm/arch/gpio.h>
Ilya Yanok8eb16b72012-11-06 13:06:30 +000020#include <asm/arch/mem.h>
Chandan Nath8a8f0842012-01-09 20:38:59 +000021#include <asm/arch/mmc_host_def.h>
Tom Rinidb7dd812012-07-31 10:50:01 -070022#include <asm/arch/sys_proto.h>
Chandan Nath5289e832011-10-14 02:58:26 +000023#include <asm/io.h>
Tom Rinifda35eb2012-07-03 08:51:34 -070024#include <asm/emif.h>
Tom Rini65d750b2012-07-31 08:55:01 -070025#include <asm/gpio.h>
Tom Rini973b6632012-07-30 16:13:10 -070026#include <i2c.h>
27#include <miiphy.h>
28#include <cpsw.h>
Ilya Yanok7df5cf32012-11-06 13:48:23 +000029#include <asm/errno.h>
30#include <linux/usb/ch9.h>
31#include <linux/usb/gadget.h>
32#include <linux/usb/musb.h>
33#include <asm/omap_musb.h>
Chandan Nath5289e832011-10-14 02:58:26 +000034
35DECLARE_GLOBAL_DATA_PTR;
36
Steve Sakoman3b971522012-06-04 05:35:34 +000037static const struct gpio_bank gpio_bank_am33xx[4] = {
38 { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
39 { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
40 { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
41 { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
42};
43
44const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
45
Chandan Nath876bdd62012-01-09 20:38:58 +000046#if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
Peter Korsgaard75a23882012-10-18 01:21:10 +000047int cpu_mmc_init(bd_t *bis)
Chandan Nath876bdd62012-01-09 20:38:58 +000048{
Tom Rini0689a2e2012-08-08 10:31:08 -070049 int ret;
Peter Korsgaard75a23882012-10-18 01:21:10 +000050
Nikita Kiryanove3913f52012-12-03 02:19:47 +000051 ret = omap_mmc_init(0, 0, 0, -1, -1);
Tom Rini0689a2e2012-08-08 10:31:08 -070052 if (ret)
53 return ret;
54
Nikita Kiryanove3913f52012-12-03 02:19:47 +000055 return omap_mmc_init(1, 0, 0, -1, -1);
Chandan Nath876bdd62012-01-09 20:38:58 +000056}
57#endif
Chandan Nath8a8f0842012-01-09 20:38:59 +000058
Ilya Yanok7df5cf32012-11-06 13:48:23 +000059/* AM33XX has two MUSB controllers which can be host or gadget */
60#if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \
61 (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
62static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
63
64/* USB 2.0 PHY Control */
65#define CM_PHY_PWRDN (1 << 0)
66#define CM_PHY_OTG_PWRDN (1 << 1)
67#define OTGVDET_EN (1 << 19)
68#define OTGSESSENDEN (1 << 20)
69
70static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
71{
72 if (on) {
73 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
74 OTGVDET_EN | OTGSESSENDEN);
75 } else {
76 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
77 }
78}
79
80static struct musb_hdrc_config musb_config = {
81 .multipoint = 1,
82 .dyn_fifo = 1,
83 .num_eps = 16,
84 .ram_bits = 12,
85};
86
87#ifdef CONFIG_AM335X_USB0
88static void am33xx_otg0_set_phy_power(u8 on)
89{
90 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
91}
92
93struct omap_musb_board_data otg0_board_data = {
94 .set_phy_power = am33xx_otg0_set_phy_power,
95};
96
97static struct musb_hdrc_platform_data otg0_plat = {
98 .mode = CONFIG_AM335X_USB0_MODE,
99 .config = &musb_config,
100 .power = 50,
101 .platform_ops = &musb_dsps_ops,
102 .board_data = &otg0_board_data,
103};
104#endif
105
106#ifdef CONFIG_AM335X_USB1
107static void am33xx_otg1_set_phy_power(u8 on)
108{
109 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
110}
111
112struct omap_musb_board_data otg1_board_data = {
113 .set_phy_power = am33xx_otg1_set_phy_power,
114};
115
116static struct musb_hdrc_platform_data otg1_plat = {
117 .mode = CONFIG_AM335X_USB1_MODE,
118 .config = &musb_config,
119 .power = 50,
120 .platform_ops = &musb_dsps_ops,
121 .board_data = &otg1_board_data,
122};
123#endif
124#endif
125
126int arch_misc_init(void)
127{
128#ifdef CONFIG_AM335X_USB0
129 musb_register(&otg0_plat, &otg0_board_data,
Matt Porter81df2ba2013-03-15 10:07:02 +0000130 (void *)USB0_OTG_BASE);
Ilya Yanok7df5cf32012-11-06 13:48:23 +0000131#endif
132#ifdef CONFIG_AM335X_USB1
133 musb_register(&otg1_plat, &otg1_board_data,
Matt Porter81df2ba2013-03-15 10:07:02 +0000134 (void *)USB1_OTG_BASE);
Ilya Yanok7df5cf32012-11-06 13:48:23 +0000135#endif
136 return 0;
137}
Heiko Schocher49f78362013-06-05 07:47:56 +0200138
Steve Kipiszc5c7a7c2013-07-18 15:13:04 -0400139#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
Heiko Schocher06604812013-07-30 10:48:54 +0530140static void rtc32k_enable(void)
Heiko Schocher49f78362013-06-05 07:47:56 +0200141{
142 struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE;
143
144 /*
145 * Unlock the RTC's registers. For more details please see the
146 * RTC_SS section of the TRM. In order to unlock we need to
147 * write these specific values (keys) in this order.
148 */
149 writel(0x83e70b13, &rtc->kick0r);
150 writel(0x95a4f1e0, &rtc->kick1r);
151
152 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
153 writel((1 << 3) | (1 << 6), &rtc->osc);
154}
Heiko Schocher7ea7f682013-06-04 11:00:57 +0200155
Heiko Schocher06604812013-07-30 10:48:54 +0530156static void uart_soft_reset(void)
Heiko Schocher7ea7f682013-06-04 11:00:57 +0200157{
158 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
159 u32 regval;
160
161 regval = readl(&uart_base->uartsyscfg);
162 regval |= UART_RESET;
163 writel(regval, &uart_base->uartsyscfg);
164 while ((readl(&uart_base->uartsyssts) &
165 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
166 ;
167
168 /* Disable smart idle */
169 regval = readl(&uart_base->uartsyscfg);
170 regval |= UART_SMART_IDLE_EN;
171 writel(regval, &uart_base->uartsyscfg);
172}
Heiko Schocher06604812013-07-30 10:48:54 +0530173
174static void watchdog_disable(void)
175{
176 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
177
178 writel(0xAAAA, &wdtimer->wdtwspr);
179 while (readl(&wdtimer->wdtwwps) != 0x0)
180 ;
181 writel(0x5555, &wdtimer->wdtwspr);
182 while (readl(&wdtimer->wdtwwps) != 0x0)
183 ;
184}
Heiko Schocher49f78362013-06-05 07:47:56 +0200185#endif
Heiko Schocher06604812013-07-30 10:48:54 +0530186
187void s_init(void)
188{
189 /*
190 * The ROM will only have set up sufficient pinmux to allow for the
191 * first 4KiB NOR to be read, we must finish doing what we know of
192 * the NOR mux in this space in order to continue.
193 */
194#ifdef CONFIG_NOR_BOOT
195 enable_norboot_pin_mux();
196#endif
197 /*
198 * Save the boot parameters passed from romcode.
199 * We cannot delay the saving further than this,
200 * to prevent overwrites.
201 */
202#ifdef CONFIG_SPL_BUILD
203 save_omap_boot_params();
204#endif
205#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
206 watchdog_disable();
207 timer_init();
208 set_uart_mux_conf();
209 setup_clocks_for_console();
210 uart_soft_reset();
211#endif
212#ifdef CONFIG_NOR_BOOT
213 gd->baudrate = CONFIG_BAUDRATE;
214 serial_init();
215 gd->have_console = 1;
216#else
217 gd = &gdata;
218 preloader_console_init();
219#endif
220#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
221 prcm_init();
222 set_mux_conf_regs();
223 /* Enable RTC32K clock */
224 rtc32k_enable();
225 sdram_init();
226#endif
227}