blob: a31bf40e5b3664567a9a722918c489d836c8587a [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>
Chandan Nath7d744102011-10-14 02:58:26 +000035
36DECLARE_GLOBAL_DATA_PTR;
37
Steve Sakoman6229e332012-06-04 05:35:34 +000038static const struct gpio_bank gpio_bank_am33xx[4] = {
39 { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
40 { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
41 { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
42 { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
43};
44
45const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
46
Chandan Nathd6e97f82012-01-09 20:38:58 +000047#if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
Peter Korsgaardaabb9f82012-10-18 01:21:10 +000048int cpu_mmc_init(bd_t *bis)
Chandan Nathd6e97f82012-01-09 20:38:58 +000049{
Tom Rini0dc71d12012-08-08 10:31:08 -070050 int ret;
Peter Korsgaardaabb9f82012-10-18 01:21:10 +000051
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +000052 ret = omap_mmc_init(0, 0, 0, -1, -1);
Tom Rini0dc71d12012-08-08 10:31:08 -070053 if (ret)
54 return ret;
55
Nikita Kiryanov4be9dbc2012-12-03 02:19:47 +000056 return omap_mmc_init(1, 0, 0, -1, -1);
Chandan Nathd6e97f82012-01-09 20:38:58 +000057}
58#endif
Chandan Nath77a73fe2012-01-09 20:38:59 +000059
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +000060/* AM33XX has two MUSB controllers which can be host or gadget */
61#if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \
62 (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
63static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
64
65/* USB 2.0 PHY Control */
66#define CM_PHY_PWRDN (1 << 0)
67#define CM_PHY_OTG_PWRDN (1 << 1)
68#define OTGVDET_EN (1 << 19)
69#define OTGSESSENDEN (1 << 20)
70
71static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
72{
73 if (on) {
74 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
75 OTGVDET_EN | OTGSESSENDEN);
76 } else {
77 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
78 }
79}
80
81static struct musb_hdrc_config musb_config = {
82 .multipoint = 1,
83 .dyn_fifo = 1,
84 .num_eps = 16,
85 .ram_bits = 12,
86};
87
88#ifdef CONFIG_AM335X_USB0
89static void am33xx_otg0_set_phy_power(u8 on)
90{
91 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
92}
93
94struct omap_musb_board_data otg0_board_data = {
95 .set_phy_power = am33xx_otg0_set_phy_power,
96};
97
98static struct musb_hdrc_platform_data otg0_plat = {
99 .mode = CONFIG_AM335X_USB0_MODE,
100 .config = &musb_config,
101 .power = 50,
102 .platform_ops = &musb_dsps_ops,
103 .board_data = &otg0_board_data,
104};
105#endif
106
107#ifdef CONFIG_AM335X_USB1
108static void am33xx_otg1_set_phy_power(u8 on)
109{
110 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
111}
112
113struct omap_musb_board_data otg1_board_data = {
114 .set_phy_power = am33xx_otg1_set_phy_power,
115};
116
117static struct musb_hdrc_platform_data otg1_plat = {
118 .mode = CONFIG_AM335X_USB1_MODE,
119 .config = &musb_config,
120 .power = 50,
121 .platform_ops = &musb_dsps_ops,
122 .board_data = &otg1_board_data,
123};
124#endif
125#endif
126
127int arch_misc_init(void)
128{
129#ifdef CONFIG_AM335X_USB0
130 musb_register(&otg0_plat, &otg0_board_data,
Matt Portere24646f2013-03-15 10:07:02 +0000131 (void *)USB0_OTG_BASE);
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000132#endif
133#ifdef CONFIG_AM335X_USB1
134 musb_register(&otg1_plat, &otg1_board_data,
Matt Portere24646f2013-03-15 10:07:02 +0000135 (void *)USB1_OTG_BASE);
Ilya Yanok7aa1a6e2012-11-06 13:48:23 +0000136#endif
137 return 0;
138}
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200139
Steve Kipiszc1399b42013-07-18 15:13:04 -0400140#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
Tom Riniac8fdf92013-08-30 16:28:44 -0400141/*
142 * This function is the place to do per-board things such as ramp up the
143 * MPU clock frequency.
144 */
145__weak void am33xx_spl_board_init(void)
146{
Steve Kipisz5adac352013-08-14 10:51:31 -0400147 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
148 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
Tom Riniac8fdf92013-08-30 16:28:44 -0400149}
150
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530151static void rtc32k_enable(void)
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200152{
153 struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE;
154
155 /*
156 * Unlock the RTC's registers. For more details please see the
157 * RTC_SS section of the TRM. In order to unlock we need to
158 * write these specific values (keys) in this order.
159 */
160 writel(0x83e70b13, &rtc->kick0r);
161 writel(0x95a4f1e0, &rtc->kick1r);
162
163 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
164 writel((1 << 3) | (1 << 6), &rtc->osc);
165}
Heiko Schocher57004c52013-06-04 11:00:57 +0200166
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530167static void uart_soft_reset(void)
Heiko Schocher57004c52013-06-04 11:00:57 +0200168{
169 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
170 u32 regval;
171
172 regval = readl(&uart_base->uartsyscfg);
173 regval |= UART_RESET;
174 writel(regval, &uart_base->uartsyscfg);
175 while ((readl(&uart_base->uartsyssts) &
176 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
177 ;
178
179 /* Disable smart idle */
180 regval = readl(&uart_base->uartsyscfg);
181 regval |= UART_SMART_IDLE_EN;
182 writel(regval, &uart_base->uartsyscfg);
183}
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530184
185static void watchdog_disable(void)
186{
187 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
188
189 writel(0xAAAA, &wdtimer->wdtwspr);
190 while (readl(&wdtimer->wdtwwps) != 0x0)
191 ;
192 writel(0x5555, &wdtimer->wdtwspr);
193 while (readl(&wdtimer->wdtwwps) != 0x0)
194 ;
195}
Heiko Schocher8aa1da92013-06-05 07:47:56 +0200196#endif
Heiko Schocherb21f2ac2013-07-30 10:48:54 +0530197
198void s_init(void)
199{
200 /*
201 * The ROM will only have set up sufficient pinmux to allow for the
202 * first 4KiB NOR to be read, we must finish doing what we know of
203 * the NOR mux in this space in order to continue.
204 */
205#ifdef CONFIG_NOR_BOOT
206 enable_norboot_pin_mux();
207#endif
208 /*
209 * Save the boot parameters passed from romcode.
210 * We cannot delay the saving further than this,
211 * to prevent overwrites.
212 */
213#ifdef CONFIG_SPL_BUILD
214 save_omap_boot_params();
215#endif
216#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
217 watchdog_disable();
218 timer_init();
219 set_uart_mux_conf();
220 setup_clocks_for_console();
221 uart_soft_reset();
222#endif
223#ifdef CONFIG_NOR_BOOT
224 gd->baudrate = CONFIG_BAUDRATE;
225 serial_init();
226 gd->have_console = 1;
227#else
228 gd = &gdata;
229 preloader_console_init();
230#endif
231#if defined(CONFIG_SPL_BUILD) || defined(CONFIG_NOR_BOOT)
232 prcm_init();
233 set_mux_conf_regs();
234 /* Enable RTC32K clock */
235 rtc32k_enable();
236 sdram_init();
237#endif
238}