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+
15 #include <asm/arch/cpu.h>
16 #include <asm/arch/hardware.h>
17 #include <asm/arch/omap.h>
18 #include <asm/arch/ddr_defs.h>
19 #include <asm/arch/clock.h>
20 #include <asm/arch/gpio.h>
21 #include <asm/arch/mem.h>
22 #include <asm/arch/mmc_host_def.h>
23 #include <asm/arch/sys_proto.h>
30 #include <asm/errno.h>
31 #include <linux/compiler.h>
32 #include <linux/usb/ch9.h>
33 #include <linux/usb/gadget.h>
34 #include <linux/usb/musb.h>
35 #include <asm/omap_musb.h>
36 #include <asm/davinci_rtc.h>
38 DECLARE_GLOBAL_DATA_PTR;
41 static const struct omap_gpio_platdata am33xx_gpio[] = {
42 { 0, AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
43 { 1, AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
44 { 2, AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
45 { 3, AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
47 { 4, AM33XX_GPIO4_BASE, METHOD_GPIO_24XX },
48 { 5, AM33XX_GPIO5_BASE, METHOD_GPIO_24XX },
52 U_BOOT_DEVICES(am33xx_gpios) = {
53 { "gpio_omap", &am33xx_gpio[0] },
54 { "gpio_omap", &am33xx_gpio[1] },
55 { "gpio_omap", &am33xx_gpio[2] },
56 { "gpio_omap", &am33xx_gpio[3] },
58 { "gpio_omap", &am33xx_gpio[4] },
59 { "gpio_omap", &am33xx_gpio[5] },
65 static const struct gpio_bank gpio_bank_am33xx[] = {
66 { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX },
67 { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX },
68 { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX },
69 { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX },
71 { (void *)AM33XX_GPIO4_BASE, METHOD_GPIO_24XX },
72 { (void *)AM33XX_GPIO5_BASE, METHOD_GPIO_24XX },
76 const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx;
80 #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD)
81 int cpu_mmc_init(bd_t *bis)
85 ret = omap_mmc_init(0, 0, 0, -1, -1);
89 return omap_mmc_init(1, 0, 0, -1, -1);
93 /* AM33XX has two MUSB controllers which can be host or gadget */
94 #if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \
95 (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1))
96 static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
98 /* USB 2.0 PHY Control */
99 #define CM_PHY_PWRDN (1 << 0)
100 #define CM_PHY_OTG_PWRDN (1 << 1)
101 #define OTGVDET_EN (1 << 19)
102 #define OTGSESSENDEN (1 << 20)
104 static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr)
107 clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN,
108 OTGVDET_EN | OTGSESSENDEN);
110 clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN);
114 static struct musb_hdrc_config musb_config = {
121 #ifdef CONFIG_AM335X_USB0
122 static void am33xx_otg0_set_phy_power(u8 on)
124 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0);
127 struct omap_musb_board_data otg0_board_data = {
128 .set_phy_power = am33xx_otg0_set_phy_power,
131 static struct musb_hdrc_platform_data otg0_plat = {
132 .mode = CONFIG_AM335X_USB0_MODE,
133 .config = &musb_config,
135 .platform_ops = &musb_dsps_ops,
136 .board_data = &otg0_board_data,
140 #ifdef CONFIG_AM335X_USB1
141 static void am33xx_otg1_set_phy_power(u8 on)
143 am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1);
146 struct omap_musb_board_data otg1_board_data = {
147 .set_phy_power = am33xx_otg1_set_phy_power,
150 static struct musb_hdrc_platform_data otg1_plat = {
151 .mode = CONFIG_AM335X_USB1_MODE,
152 .config = &musb_config,
154 .platform_ops = &musb_dsps_ops,
155 .board_data = &otg1_board_data,
160 int arch_misc_init(void)
162 #ifdef CONFIG_AM335X_USB0
163 musb_register(&otg0_plat, &otg0_board_data,
164 (void *)USB0_OTG_BASE);
166 #ifdef CONFIG_AM335X_USB1
167 musb_register(&otg1_plat, &otg1_board_data,
168 (void *)USB1_OTG_BASE);
173 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
175 * In the case of non-SPL based booting we'll want to call these
176 * functions a tiny bit later as it will require gd to be set and cleared
177 * and that's not true in s_init in this case so we cannot do it there.
179 int board_early_init_f(void)
188 * This function is the place to do per-board things such as ramp up the
189 * MPU clock frequency.
191 __weak void am33xx_spl_board_init(void)
193 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
194 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
197 #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
198 static void rtc32k_enable(void)
200 struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE;
203 * Unlock the RTC's registers. For more details please see the
204 * RTC_SS section of the TRM. In order to unlock we need to
205 * write these specific values (keys) in this order.
207 writel(RTC_KICK0R_WE, &rtc->kick0r);
208 writel(RTC_KICK1R_WE, &rtc->kick1r);
210 /* Enable the RTC 32K OSC by setting bits 3 and 6. */
211 writel((1 << 3) | (1 << 6), &rtc->osc);
215 static void uart_soft_reset(void)
217 struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE;
220 regval = readl(&uart_base->uartsyscfg);
221 regval |= UART_RESET;
222 writel(regval, &uart_base->uartsyscfg);
223 while ((readl(&uart_base->uartsyssts) &
224 UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK)
227 /* Disable smart idle */
228 regval = readl(&uart_base->uartsyscfg);
229 regval |= UART_SMART_IDLE_EN;
230 writel(regval, &uart_base->uartsyscfg);
233 static void watchdog_disable(void)
235 struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE;
237 writel(0xAAAA, &wdtimer->wdtwspr);
238 while (readl(&wdtimer->wdtwwps) != 0x0)
240 writel(0x5555, &wdtimer->wdtwspr);
241 while (readl(&wdtimer->wdtwwps) != 0x0)
248 * The ROM will only have set up sufficient pinmux to allow for the
249 * first 4KiB NOR to be read, we must finish doing what we know of
250 * the NOR mux in this space in order to continue.
252 #ifdef CONFIG_NOR_BOOT
253 enable_norboot_pin_mux();
256 * Save the boot parameters passed from romcode.
257 * We cannot delay the saving further than this,
258 * to prevent overwrites.
260 #ifdef CONFIG_SPL_BUILD
261 save_omap_boot_params();
266 setup_clocks_for_console();
268 #if defined(CONFIG_NOR_BOOT) || defined(CONFIG_QSPI_BOOT)
269 gd->baudrate = CONFIG_BAUDRATE;
271 gd->have_console = 1;
272 #elif defined(CONFIG_SPL_BUILD)
274 preloader_console_init();
276 #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC)
277 /* Enable RTC32K clock */
280 #ifdef CONFIG_SPL_BUILD
281 board_early_init_f();