4 * Common board functions for AM33XX based boards
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
8 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/arch/cpu.h>
15 #include <asm/arch/hardware.h>
16 #include <asm/arch/omap.h>
17 #include <asm/arch/ddr_defs.h>
18 #include <asm/arch/clock.h>
19 #include <asm/arch/gpio.h>
20 #include <asm/arch/mem.h>
21 #include <asm/arch/mmc_host_def.h>
22 #include <asm/arch/sys_proto.h>
29 #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>
35 DECLARE_GLOBAL_DATA_PTR;
37 static 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 },
44 const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
46 #ifdef CONFIG_HW_WATCHDOG
47 void hw_watchdog_reset(void)
49 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
50 static int trg __attribute__((section(".data")));
55 if (readl(&wdtimer->wdtwwps) & (1 << 4))
57 writel(trg ? 0x5555 : 0xaaaa, &wdtimer->wdtwspr);
60 if (readl(&wdtimer->wdtwwps) & (1 << 2))
63 writel(-32768 * 10, &wdtimer->wdtwldr);
65 if (readl(&wdtimer->wdtwwps) & (1 << 0))
68 writel(0, &wdtimer->wdtwclr);
74 if (readl(&wdtimer->wdtwwps) & (1 << 4))
76 writel((trg & 1) ? 0xBBBB : 0x4444, &wdtimer->wdtwspr);
80 /* retrigger watchdog */
81 if (readl(&wdtimer->wdtwwps) & (1 << 3))
84 writel(trg, &wdtimer->wdtwtgr);
92 #ifndef CONFIG_SYS_DCACHE_OFF
93 void enable_caches(void)
95 /* Enable D-cache. I-cache is already enabled in start.S */
100 #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
101 int __cpu_mmc_init(bd_t *bis)
105 ret = omap_mmc_init(0, 0, 0, -1, -1);
109 return omap_mmc_init(1, 0, 0, -1, -1);
111 /* let platform code be able to override this! */
112 int cpu_mmc_init(bd_t *bis) __attribute__((weak, alias("__cpu_mmc_init")));
115 void setup_clocks_for_console(void)
117 /* Not yet implemented */
121 /* AM33XX has two MUSB controllers which can be host or gadget */
122 #if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \
123 (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
124 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
126 /* USB 2.0 PHY Control */
127 #define CM_PHY_PWRDN (1 << 0)
128 #define CM_PHY_OTG_PWRDN (1 << 1)
129 #define OTGVDET_EN (1 << 19)
130 #define OTGSESSENDEN (1 << 20)
132 static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
135 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
136 OTGVDET_EN | OTGSESSENDEN);
138 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
142 static struct musb_hdrc_config musb_config = {
149 #ifdef CONFIG_AM335X_USB0
150 static void am33xx_otg0_set_phy_power(u8 on)
152 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
155 struct omap_musb_board_data otg0_board_data = {
156 .set_phy_power = am33xx_otg0_set_phy_power,
159 static struct musb_hdrc_platform_data otg0_plat = {
160 .mode = CONFIG_AM335X_USB0_MODE,
161 .config = &musb_config,
163 .platform_ops = &musb_dsps_ops,
164 .board_data = &otg0_board_data,
168 #ifdef CONFIG_AM335X_USB1
169 static void am33xx_otg1_set_phy_power(u8 on)
171 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
174 struct omap_musb_board_data otg1_board_data = {
175 .set_phy_power = am33xx_otg1_set_phy_power,
178 static struct musb_hdrc_platform_data otg1_plat = {
179 .mode = CONFIG_AM335X_USB1_MODE,
180 .config = &musb_config,
182 .platform_ops = &musb_dsps_ops,
183 .board_data = &otg1_board_data,
188 int arch_misc_init(void)
190 #ifdef CONFIG_AM335X_USB0
191 musb_register(&otg0_plat, &otg0_board_data,
192 (void *)USB0_OTG_BASE);
194 #ifdef CONFIG_AM335X_USB1
195 musb_register(&otg1_plat, &otg1_board_data,
196 (void *)USB1_OTG_BASE);
201 #ifdef CONFIG_SPL_BUILD
202 void rtc32k_enable(void)
204 struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE;
207 * Unlock the RTC's registers. For more details please see the
208 * RTC_SS section of the TRM. In order to unlock we need to
209 * write these specific values (keys) in this order.
211 writel(0x83e70b13, &rtc->kick0r);
212 writel(0x95a4f1e0, &rtc->kick1r);
214 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
215 writel((1 << 3) | (1 << 6), &rtc->osc);
218 #define UART_RESET (0x1 << 1)
219 #define UART_CLK_RUNNING_MASK 0x1
220 #define UART_SMART_IDLE_EN (0x1 << 0x3)
222 void uart_soft_reset(void)
224 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
227 regval = readl(&uart_base->uartsyscfg);
228 regval |= UART_RESET;
229 writel(regval, &uart_base->uartsyscfg);
230 while ((readl(&uart_base->uartsyssts) &
231 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
234 /* Disable smart idle */
235 regval = readl(&uart_base->uartsyscfg);
236 regval |= UART_SMART_IDLE_EN;
237 writel(regval, &uart_base->uartsyscfg);