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 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | */ |
| 18 | |
| 19 | #include <common.h> |
Tom Rini | 59c2cc9 | 2012-07-30 16:13:10 -0700 | [diff] [blame] | 20 | #include <errno.h> |
Tom Rini | 28591df | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 21 | #include <spl.h> |
Chandan Nath | 7d74410 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 22 | #include <asm/arch/cpu.h> |
| 23 | #include <asm/arch/hardware.h> |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 24 | #include <asm/arch/omap.h> |
Chandan Nath | 7d74410 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 25 | #include <asm/arch/ddr_defs.h> |
| 26 | #include <asm/arch/clock.h> |
Steve Sakoman | 6229e33 | 2012-06-04 05:35:34 +0000 | [diff] [blame] | 27 | #include <asm/arch/gpio.h> |
Ilya Yanok | 2ebbb86 | 2012-11-06 13:06:30 +0000 | [diff] [blame] | 28 | #include <asm/arch/mem.h> |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 29 | #include <asm/arch/mmc_host_def.h> |
Tom Rini | 7a24772 | 2012-07-31 10:50:01 -0700 | [diff] [blame] | 30 | #include <asm/arch/sys_proto.h> |
Chandan Nath | 7d74410 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 31 | #include <asm/io.h> |
Tom Rini | 3fd4456 | 2012-07-03 08:51:34 -0700 | [diff] [blame] | 32 | #include <asm/emif.h> |
Tom Rini | 4b30240 | 2012-07-31 08:55:01 -0700 | [diff] [blame] | 33 | #include <asm/gpio.h> |
Tom Rini | 59c2cc9 | 2012-07-30 16:13:10 -0700 | [diff] [blame] | 34 | #include <i2c.h> |
| 35 | #include <miiphy.h> |
| 36 | #include <cpsw.h> |
Ilya Yanok | 7aa1a6e | 2012-11-06 13:48:23 +0000 | [diff] [blame] | 37 | #include <asm/errno.h> |
| 38 | #include <linux/usb/ch9.h> |
| 39 | #include <linux/usb/gadget.h> |
| 40 | #include <linux/usb/musb.h> |
| 41 | #include <asm/omap_musb.h> |
Chandan Nath | 7d74410 | 2011-10-14 02:58:26 +0000 | [diff] [blame] | 42 | |
| 43 | DECLARE_GLOBAL_DATA_PTR; |
| 44 | |
Steve Sakoman | 6229e33 | 2012-06-04 05:35:34 +0000 | [diff] [blame] | 45 | static const struct gpio_bank gpio_bank_am33xx[4] = { |
| 46 | { (void *)AM33XX_GPIO0_BASE, METHOD_GPIO_24XX }, |
| 47 | { (void *)AM33XX_GPIO1_BASE, METHOD_GPIO_24XX }, |
| 48 | { (void *)AM33XX_GPIO2_BASE, METHOD_GPIO_24XX }, |
| 49 | { (void *)AM33XX_GPIO3_BASE, METHOD_GPIO_24XX }, |
| 50 | }; |
| 51 | |
| 52 | const struct gpio_bank *const omap_gpio_bank = gpio_bank_am33xx; |
| 53 | |
Chandan Nath | d6e97f8 | 2012-01-09 20:38:58 +0000 | [diff] [blame] | 54 | #if defined(CONFIG_OMAP_HSMMC) && !defined(CONFIG_SPL_BUILD) |
Peter Korsgaard | aabb9f8 | 2012-10-18 01:21:10 +0000 | [diff] [blame] | 55 | int cpu_mmc_init(bd_t *bis) |
Chandan Nath | d6e97f8 | 2012-01-09 20:38:58 +0000 | [diff] [blame] | 56 | { |
Tom Rini | 0dc71d1 | 2012-08-08 10:31:08 -0700 | [diff] [blame] | 57 | int ret; |
Peter Korsgaard | aabb9f8 | 2012-10-18 01:21:10 +0000 | [diff] [blame] | 58 | |
Nikita Kiryanov | 4be9dbc | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 59 | ret = omap_mmc_init(0, 0, 0, -1, -1); |
Tom Rini | 0dc71d1 | 2012-08-08 10:31:08 -0700 | [diff] [blame] | 60 | if (ret) |
| 61 | return ret; |
| 62 | |
Nikita Kiryanov | 4be9dbc | 2012-12-03 02:19:47 +0000 | [diff] [blame] | 63 | return omap_mmc_init(1, 0, 0, -1, -1); |
Chandan Nath | d6e97f8 | 2012-01-09 20:38:58 +0000 | [diff] [blame] | 64 | } |
| 65 | #endif |
Chandan Nath | 77a73fe | 2012-01-09 20:38:59 +0000 | [diff] [blame] | 66 | |
| 67 | void setup_clocks_for_console(void) |
| 68 | { |
| 69 | /* Not yet implemented */ |
| 70 | return; |
| 71 | } |
Ilya Yanok | 7aa1a6e | 2012-11-06 13:48:23 +0000 | [diff] [blame] | 72 | |
| 73 | /* AM33XX has two MUSB controllers which can be host or gadget */ |
| 74 | #if (defined(CONFIG_MUSB_GADGET) || defined(CONFIG_MUSB_HOST)) && \ |
| 75 | (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1)) |
| 76 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 77 | |
| 78 | /* USB 2.0 PHY Control */ |
| 79 | #define CM_PHY_PWRDN (1 << 0) |
| 80 | #define CM_PHY_OTG_PWRDN (1 << 1) |
| 81 | #define OTGVDET_EN (1 << 19) |
| 82 | #define OTGSESSENDEN (1 << 20) |
| 83 | |
| 84 | static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr) |
| 85 | { |
| 86 | if (on) { |
| 87 | clrsetbits_le32(reg_addr, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN, |
| 88 | OTGVDET_EN | OTGSESSENDEN); |
| 89 | } else { |
| 90 | clrsetbits_le32(reg_addr, 0, CM_PHY_PWRDN | CM_PHY_OTG_PWRDN); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static struct musb_hdrc_config musb_config = { |
| 95 | .multipoint = 1, |
| 96 | .dyn_fifo = 1, |
| 97 | .num_eps = 16, |
| 98 | .ram_bits = 12, |
| 99 | }; |
| 100 | |
| 101 | #ifdef CONFIG_AM335X_USB0 |
| 102 | static void am33xx_otg0_set_phy_power(u8 on) |
| 103 | { |
| 104 | am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0); |
| 105 | } |
| 106 | |
| 107 | struct omap_musb_board_data otg0_board_data = { |
| 108 | .set_phy_power = am33xx_otg0_set_phy_power, |
| 109 | }; |
| 110 | |
| 111 | static struct musb_hdrc_platform_data otg0_plat = { |
| 112 | .mode = CONFIG_AM335X_USB0_MODE, |
| 113 | .config = &musb_config, |
| 114 | .power = 50, |
| 115 | .platform_ops = &musb_dsps_ops, |
| 116 | .board_data = &otg0_board_data, |
| 117 | }; |
| 118 | #endif |
| 119 | |
| 120 | #ifdef CONFIG_AM335X_USB1 |
| 121 | static void am33xx_otg1_set_phy_power(u8 on) |
| 122 | { |
| 123 | am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1); |
| 124 | } |
| 125 | |
| 126 | struct omap_musb_board_data otg1_board_data = { |
| 127 | .set_phy_power = am33xx_otg1_set_phy_power, |
| 128 | }; |
| 129 | |
| 130 | static struct musb_hdrc_platform_data otg1_plat = { |
| 131 | .mode = CONFIG_AM335X_USB1_MODE, |
| 132 | .config = &musb_config, |
| 133 | .power = 50, |
| 134 | .platform_ops = &musb_dsps_ops, |
| 135 | .board_data = &otg1_board_data, |
| 136 | }; |
| 137 | #endif |
| 138 | #endif |
| 139 | |
| 140 | int arch_misc_init(void) |
| 141 | { |
| 142 | #ifdef CONFIG_AM335X_USB0 |
| 143 | musb_register(&otg0_plat, &otg0_board_data, |
Matt Porter | e24646f | 2013-03-15 10:07:02 +0000 | [diff] [blame] | 144 | (void *)USB0_OTG_BASE); |
Ilya Yanok | 7aa1a6e | 2012-11-06 13:48:23 +0000 | [diff] [blame] | 145 | #endif |
| 146 | #ifdef CONFIG_AM335X_USB1 |
| 147 | musb_register(&otg1_plat, &otg1_board_data, |
Matt Porter | e24646f | 2013-03-15 10:07:02 +0000 | [diff] [blame] | 148 | (void *)USB1_OTG_BASE); |
Ilya Yanok | 7aa1a6e | 2012-11-06 13:48:23 +0000 | [diff] [blame] | 149 | #endif |
| 150 | return 0; |
| 151 | } |
Heiko Schocher | 8aa1da9 | 2013-06-05 07:47:56 +0200 | [diff] [blame] | 152 | |
| 153 | #ifdef CONFIG_SPL_BUILD |
| 154 | void rtc32k_enable(void) |
| 155 | { |
| 156 | struct rtc_regs *rtc = (struct rtc_regs *)RTC_BASE; |
| 157 | |
| 158 | /* |
| 159 | * Unlock the RTC's registers. For more details please see the |
| 160 | * RTC_SS section of the TRM. In order to unlock we need to |
| 161 | * write these specific values (keys) in this order. |
| 162 | */ |
| 163 | writel(0x83e70b13, &rtc->kick0r); |
| 164 | writel(0x95a4f1e0, &rtc->kick1r); |
| 165 | |
| 166 | /* Enable the RTC 32K OSC by setting bits 3 and 6. */ |
| 167 | writel((1 << 3) | (1 << 6), &rtc->osc); |
| 168 | } |
Heiko Schocher | 57004c5 | 2013-06-04 11:00:57 +0200 | [diff] [blame] | 169 | |
| 170 | #define UART_RESET (0x1 << 1) |
| 171 | #define UART_CLK_RUNNING_MASK 0x1 |
| 172 | #define UART_SMART_IDLE_EN (0x1 << 0x3) |
| 173 | |
| 174 | void uart_soft_reset(void) |
| 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 | 8aa1da9 | 2013-06-05 07:47:56 +0200 | [diff] [blame] | 191 | #endif |