Chandan Nath | 7d74410 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 1 | /* |
| 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 Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
Chandan Nath | 7d74410 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Tom Rini | 59c2cc9 | 2012-07-30 16:13:10 -0700 | [diff] [blame] | 12 | #include <errno.h> |
Tom Rini | 28591df | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 13 | #include <spl.h> |
Chandan Nath | 7d74410 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 14 | #include <asm/arch/cpu.h> |
| 15 | #include <asm/arch/hardware.h> |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 16 | #include <asm/arch/omap.h> |
Chandan Nath | 7d74410 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 17 | #include <asm/arch/ddr_defs.h> |
| 18 | #include <asm/arch/clock.h> |
Steve Sakoman | 6229e33 | 2012-06-04 05:35:34 +0000 | [diff] [blame] | 19 | #include <asm/arch/gpio.h> |
Ilya Yanok | 2ebbb86 | 2012-11-06 13:06:30 +0000 | [diff] [blame] | 20 | #include <asm/arch/mem.h> |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 21 | #include <asm/arch/mmc_host_def.h> |
Tom Rini | 7a24772 | 2012-07-31 10:50:01 -0700 | [diff] [blame] | 22 | #include <asm/arch/sys_proto.h> |
Chandan Nath | 7d74410 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 23 | #include <asm/io.h> |
Tom Rini | 3fd4456 | 2012-07-03 08:51:34 -0700 | [diff] [blame] | 24 | #include <asm/emif.h> |
Tom Rini | 4b30240 | 2012-07-31 08:55:01 -0700 | [diff] [blame] | 25 | #include <asm/gpio.h> |
Tom Rini | 59c2cc9 | 2012-07-30 16:13:10 -0700 | [diff] [blame] | 26 | #include <i2c.h> |
| 27 | #include <miiphy.h> |
| 28 | #include <cpsw.h> |
Ilya Yanok | 7aa1a6e | 2012-11-06 13:48:23 +0000 | [diff] [blame] | 29 | #include <asm/errno.h> |
Tom Rini | ac8fdf9 | 2013-08-30 16:28:44 -0400 | [diff] [blame] | 30 | #include <linux/compiler.h> |
Ilya Yanok | 7aa1a6e | 2012-11-06 13:48:23 +0000 | [diff] [blame] | 31 | #include <linux/usb/ch9.h> |
| 32 | #include <linux/usb/gadget.h> |
| 33 | #include <linux/usb/musb.h> |
| 34 | #include <asm/omap_musb.h> |
Tom Rini | 56424eb | 2013-08-28 09:00:28 -0400 | [diff] [blame] | 35 | #include <asm/davinci_rtc.h> |
Chandan Nath | 7d74410 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
Dave Gerlach | 00822ca | 2014-02-10 11:41:49 -0500 | [diff] [blame] | 39 | static const struct gpio_bank gpio_bank_am33xx[] = { |
Steve Sakoman | 6229e33 | 2012-06-04 05:35:34 +0000 | [diff] [blame] | 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 }, |
Dave Gerlach | 00822ca | 2014-02-10 11:41:49 -0500 | [diff] [blame] | 44 | #ifdef CONFIG_AM43XX |
| 45 | { (void *)AM33XX_GPIO4_BASE, METHOD_GPIO_24XX }, |
| 46 | { (void *)AM33XX_GPIO5_BASE, METHOD_GPIO_24XX }, |
| 47 | #endif |
Steve Sakoman | 6229e33 | 2012-06-04 05:35:34 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx; |
| 51 | |
Chandan Nath | d6e97f8 | 2012-01-09 20:38:58 +0000 | [diff] [blame] | 52 | #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD) |
Peter Korsgaard | aabb9f8 | 2012-10-18 01:21:10 +0000 | [diff] [blame] | 53 | int cpu_mmc_init(bd_t *bis) |
Chandan Nath | d6e97f8 | 2012-01-09 20:38:58 +0000 | [diff] [blame] | 54 | { |
Tom Rini | 0dc71d1 | 2012-08-08 10:31:08 -0700 | [diff] [blame] | 55 | int ret; |
Peter Korsgaard | aabb9f8 | 2012-10-18 01:21:10 +0000 | [diff] [blame] | 56 | |
Nikita Kiryanov | 4be9dbc | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 57 | ret = omap_mmc_init(0, 0, 0, -1, -1); |
Tom Rini | 0dc71d1 | 2012-08-08 10:31:08 -0700 | [diff] [blame] | 58 | if (ret) |
| 59 | return ret; |
| 60 | |
Nikita Kiryanov | 4be9dbc | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 61 | return omap_mmc_init(1, 0, 0, -1, -1); |
Chandan Nath | d6e97f8 | 2012-01-09 20:38:58 +0000 | [diff] [blame] | 62 | } |
| 63 | #endif |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 64 | |
Ilya Yanok | 7aa1a6e | 2012-11-06 13:48:23 +0000 | [diff] [blame] | 65 | /* AM33XX has two MUSB controllers which can be host or gadget */ |
| 66 | #if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \ |
| 67 | (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1)) |
| 68 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 69 | |
| 70 | /* USB 2.0 PHY Control */ |
| 71 | #define CM_PHY_PWRDN (1 << 0) |
| 72 | #define CM_PHY_OTG_PWRDN (1 << 1) |
| 73 | #define OTGVDET_EN (1 << 19) |
| 74 | #define OTGSESSENDEN (1 << 20) |
| 75 | |
| 76 | static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr) |
| 77 | { |
| 78 | if (on) { |
| 79 | clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN, |
| 80 | OTGVDET_EN | OTGSESSENDEN); |
| 81 | } else { |
| 82 | clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | static struct musb_hdrc_config musb_config = { |
| 87 | .multipoint = 1, |
| 88 | .dyn_fifo = 1, |
| 89 | .num_eps = 16, |
| 90 | .ram_bits = 12, |
| 91 | }; |
| 92 | |
| 93 | #ifdef CONFIG_AM335X_USB0 |
| 94 | static void am33xx_otg0_set_phy_power(u8 on) |
| 95 | { |
| 96 | am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0); |
| 97 | } |
| 98 | |
| 99 | struct omap_musb_board_data otg0_board_data = { |
| 100 | .set_phy_power = am33xx_otg0_set_phy_power, |
| 101 | }; |
| 102 | |
| 103 | static struct musb_hdrc_platform_data otg0_plat = { |
| 104 | .mode = CONFIG_AM335X_USB0_MODE, |
| 105 | .config = &musb_config, |
| 106 | .power = 50, |
| 107 | .platform_ops = &musb_dsps_ops, |
| 108 | .board_data = &otg0_board_data, |
| 109 | }; |
| 110 | #endif |
| 111 | |
| 112 | #ifdef CONFIG_AM335X_USB1 |
| 113 | static void am33xx_otg1_set_phy_power(u8 on) |
| 114 | { |
| 115 | am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1); |
| 116 | } |
| 117 | |
| 118 | struct omap_musb_board_data otg1_board_data = { |
| 119 | .set_phy_power = am33xx_otg1_set_phy_power, |
| 120 | }; |
| 121 | |
| 122 | static struct musb_hdrc_platform_data otg1_plat = { |
| 123 | .mode = CONFIG_AM335X_USB1_MODE, |
| 124 | .config = &musb_config, |
| 125 | .power = 50, |
| 126 | .platform_ops = &musb_dsps_ops, |
| 127 | .board_data = &otg1_board_data, |
| 128 | }; |
| 129 | #endif |
| 130 | #endif |
| 131 | |
| 132 | int arch_misc_init(void) |
| 133 | { |
| 134 | #ifdef CONFIG_AM335X_USB0 |
| 135 | musb_register(&otg0_plat, &otg0_board_data, |
Matt Porter | e24646f | 2013-03-15 10:07:02 +0000 | [diff] [blame] | 136 | (void *)USB0_OTG_BASE); |
Ilya Yanok | 7aa1a6e | 2012-11-06 13:48:23 +0000 | [diff] [blame] | 137 | #endif |
| 138 | #ifdef CONFIG_AM335X_USB1 |
| 139 | musb_register(&otg1_plat, &otg1_board_data, |
Matt Porter | e24646f | 2013-03-15 10:07:02 +0000 | [diff] [blame] | 140 | (void *)USB1_OTG_BASE); |
Ilya Yanok | 7aa1a6e | 2012-11-06 13:48:23 +0000 | [diff] [blame] | 141 | #endif |
| 142 | return 0; |
| 143 | } |
Heiko Schocher | 8aa1da9 | 2013-06-05 07:47:56 +0200 | [diff] [blame] | 144 | |
Tom Rini | 8de09df | 2014-04-09 08:25:57 -0400 | [diff] [blame] | 145 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
Tom Rini | ac8fdf9 | 2013-08-30 16:28:44 -0400 | [diff] [blame] | 146 | /* |
| 147 | * This function is the place to do per-board things such as ramp up the |
| 148 | * MPU clock frequency. |
| 149 | */ |
| 150 | __weak void am33xx_spl_board_init(void) |
| 151 | { |
Steve Kipisz | 5adac35 | 2013-08-14 10:51:31 -0400 | [diff] [blame] | 152 | do_setup_dpll(&dpll_core_regs, &dpll_core_opp100); |
| 153 | do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100); |
Tom Rini | ac8fdf9 | 2013-08-30 16:28:44 -0400 | [diff] [blame] | 154 | } |
| 155 | |
Heiko Schocher | 2233e46 | 2013-11-04 14:05:00 +0100 | [diff] [blame] | 156 | #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC) |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 157 | static void rtc32k_enable(void) |
Heiko Schocher | 8aa1da9 | 2013-06-05 07:47:56 +0200 | [diff] [blame] | 158 | { |
Tom Rini | 56424eb | 2013-08-28 09:00:28 -0400 | [diff] [blame] | 159 | struct davinci_rtc *rtc = (struct davinci_rtc *)RTC_BASE; |
Heiko Schocher | 8aa1da9 | 2013-06-05 07:47:56 +0200 | [diff] [blame] | 160 | |
| 161 | /* |
| 162 | * Unlock the RTC's registers. For more details please see the |
| 163 | * RTC_SS section of the TRM. In order to unlock we need to |
| 164 | * write these specific values (keys) in this order. |
| 165 | */ |
Tom Rini | 56424eb | 2013-08-28 09:00:28 -0400 | [diff] [blame] | 166 | writel(RTC_KICK0R_WE, &rtc->kick0r); |
| 167 | writel(RTC_KICK1R_WE, &rtc->kick1r); |
Heiko Schocher | 8aa1da9 | 2013-06-05 07:47:56 +0200 | [diff] [blame] | 168 | |
| 169 | /* Enable the RTC 32K OSC by setting bits 3 and 6. */ |
| 170 | writel((1 << 3) | (1 << 6), &rtc->osc); |
| 171 | } |
Heiko Schocher | 2233e46 | 2013-11-04 14:05:00 +0100 | [diff] [blame] | 172 | #endif |
Heiko Schocher | 57004c5 | 2013-06-04 11:00:57 +0200 | [diff] [blame] | 173 | |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 174 | static void uart_soft_reset(void) |
Heiko Schocher | 57004c5 | 2013-06-04 11:00:57 +0200 | [diff] [blame] | 175 | { |
| 176 | struct uart_sys *uart_base = (struct uart_sys *)DEFAULT_UART_BASE; |
| 177 | u32 regval; |
| 178 | |
| 179 | regval = readl(&uart_base->uartsyscfg); |
| 180 | regval |= UART_RESET; |
| 181 | writel(regval, &uart_base->uartsyscfg); |
| 182 | while ((readl(&uart_base->uartsyssts) & |
| 183 | UART_CLK_RUNNING_MASK) != UART_CLK_RUNNING_MASK) |
| 184 | ; |
| 185 | |
| 186 | /* Disable smart idle */ |
| 187 | regval = readl(&uart_base->uartsyscfg); |
| 188 | regval |= UART_SMART_IDLE_EN; |
| 189 | writel(regval, &uart_base->uartsyscfg); |
| 190 | } |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 191 | |
| 192 | static void watchdog_disable(void) |
| 193 | { |
| 194 | struct wd_timer *wdtimer = (struct wd_timer *)WDT_BASE; |
| 195 | |
| 196 | writel(0xAAAA, &wdtimer->wdtwspr); |
| 197 | while (readl(&wdtimer->wdtwwps) != 0x0) |
| 198 | ; |
| 199 | writel(0x5555, &wdtimer->wdtwspr); |
| 200 | while (readl(&wdtimer->wdtwwps) != 0x0) |
| 201 | ; |
| 202 | } |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 203 | |
| 204 | void s_init(void) |
| 205 | { |
| 206 | /* |
| 207 | * The ROM will only have set up sufficient pinmux to allow for the |
| 208 | * first 4KiB NOR to be read, we must finish doing what we know of |
| 209 | * the NOR mux in this space in order to continue. |
| 210 | */ |
| 211 | #ifdef CONFIG_NOR_BOOT |
| 212 | enable_norboot_pin_mux(); |
| 213 | #endif |
| 214 | /* |
| 215 | * Save the boot parameters passed from romcode. |
| 216 | * We cannot delay the saving further than this, |
| 217 | * to prevent overwrites. |
| 218 | */ |
| 219 | #ifdef CONFIG_SPL_BUILD |
| 220 | save_omap_boot_params(); |
| 221 | #endif |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 222 | watchdog_disable(); |
| 223 | timer_init(); |
| 224 | set_uart_mux_conf(); |
| 225 | setup_clocks_for_console(); |
| 226 | uart_soft_reset(); |
Sourav Poddar | 5248bba | 2014-05-19 16:53:37 -0400 | [diff] [blame] | 227 | #if defined(CONFIG_NOR_BOOT) || defined(CONFIG_QSPI_BOOT) |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 228 | gd->baudrate = CONFIG_BAUDRATE; |
| 229 | serial_init(); |
| 230 | gd->have_console = 1; |
Tom Rini | 35c616c | 2014-03-05 14:57:47 -0500 | [diff] [blame] | 231 | #elif defined(CONFIG_SPL_BUILD) |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 232 | gd = &gdata; |
| 233 | preloader_console_init(); |
| 234 | #endif |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 235 | prcm_init(); |
| 236 | set_mux_conf_regs(); |
Heiko Schocher | 2233e46 | 2013-11-04 14:05:00 +0100 | [diff] [blame] | 237 | #if defined(CONFIG_SPL_AM33XX_ENABLE_RTC32K_OSC) |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 238 | /* Enable RTC32K clock */ |
| 239 | rtc32k_enable(); |
Heiko Schocher | 2233e46 | 2013-11-04 14:05:00 +0100 | [diff] [blame] | 240 | #endif |
Tom Rini | cb23d3d | 2014-05-21 12:57:21 -0400 | [diff] [blame^] | 241 | #ifdef CONFIG_SPL_BUILD |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 242 | sdram_init(); |
Tom Rini | cb23d3d | 2014-05-21 12:57:21 -0400 | [diff] [blame^] | 243 | #endif |
Heiko Schocher | b21f2ac | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 244 | } |
Tom Rini | 35c616c | 2014-03-05 14:57:47 -0500 | [diff] [blame] | 245 | #endif |
Tom Rini | e290d17 | 2013-08-23 12:26:49 -0400 | [diff] [blame] | 246 | |
| 247 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 248 | void enable_caches(void) |
| 249 | { |
| 250 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 251 | dcache_enable(); |
| 252 | } |
| 253 | #endif /* !CONFIG_SYS_DCACHE_OFF */ |