Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 1 | /* |
| 2 | * ehci-omap.c - driver for USBHOST on OMAP 34xx processor |
| 3 | * |
| 4 | * Bus Glue for OMAP34xx USBHOST 3 port EHCI controller |
| 5 | * Tested on OMAP3430 ES2.0 SDP |
| 6 | * |
| 7 | * Copyright (C) 2007-2008 Texas Instruments, Inc. |
| 8 | * Author: Vikram Pandita <vikram.pandita@ti.com> |
| 9 | * |
| 10 | * Copyright (C) 2009 Nokia Corporation |
| 11 | * Contact: Felipe Balbi <felipe.balbi@nokia.com> |
| 12 | * |
| 13 | * Based on "ehci-fsl.c" and "ehci-au1xxx.c" ehci glue layers |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation; either version 2 of the License, or |
| 18 | * (at your option) any later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program; if not, write to the Free Software |
| 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 | * |
Anand Gadiyar | bdee2d8 | 2010-02-12 17:49:00 +0530 | [diff] [blame] | 29 | * TODO (last updated Feb 12, 2010): |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 30 | * - add kernel-doc |
| 31 | * - enable AUTOIDLE |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 32 | * - add suspend/resume |
| 33 | * - move workarounds to board-files |
| 34 | */ |
| 35 | |
| 36 | #include <linux/platform_device.h> |
| 37 | #include <linux/clk.h> |
| 38 | #include <linux/gpio.h> |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 39 | #include <linux/regulator/consumer.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 40 | #include <linux/slab.h> |
Ajay Kumar Gupta | 5aa4af2 | 2010-07-08 14:03:02 +0530 | [diff] [blame] | 41 | #include <linux/usb/ulpi.h> |
Thomas Weber | c76f782 | 2009-12-15 10:38:05 -0800 | [diff] [blame] | 42 | #include <plat/usb.h> |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * OMAP USBHOST Register addresses: VIRTUAL ADDRESSES |
| 46 | * Use ehci_omap_readl()/ehci_omap_writel() functions |
| 47 | */ |
| 48 | |
| 49 | /* TLL Register Set */ |
| 50 | #define OMAP_USBTLL_REVISION (0x00) |
| 51 | #define OMAP_USBTLL_SYSCONFIG (0x10) |
| 52 | #define OMAP_USBTLL_SYSCONFIG_CACTIVITY (1 << 8) |
| 53 | #define OMAP_USBTLL_SYSCONFIG_SIDLEMODE (1 << 3) |
| 54 | #define OMAP_USBTLL_SYSCONFIG_ENAWAKEUP (1 << 2) |
| 55 | #define OMAP_USBTLL_SYSCONFIG_SOFTRESET (1 << 1) |
| 56 | #define OMAP_USBTLL_SYSCONFIG_AUTOIDLE (1 << 0) |
| 57 | |
| 58 | #define OMAP_USBTLL_SYSSTATUS (0x14) |
| 59 | #define OMAP_USBTLL_SYSSTATUS_RESETDONE (1 << 0) |
| 60 | |
| 61 | #define OMAP_USBTLL_IRQSTATUS (0x18) |
| 62 | #define OMAP_USBTLL_IRQENABLE (0x1C) |
| 63 | |
| 64 | #define OMAP_TLL_SHARED_CONF (0x30) |
| 65 | #define OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN (1 << 6) |
| 66 | #define OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN (1 << 5) |
| 67 | #define OMAP_TLL_SHARED_CONF_USB_DIVRATION (1 << 2) |
| 68 | #define OMAP_TLL_SHARED_CONF_FCLK_REQ (1 << 1) |
| 69 | #define OMAP_TLL_SHARED_CONF_FCLK_IS_ON (1 << 0) |
| 70 | |
| 71 | #define OMAP_TLL_CHANNEL_CONF(num) (0x040 + 0x004 * num) |
| 72 | #define OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF (1 << 11) |
| 73 | #define OMAP_TLL_CHANNEL_CONF_ULPI_ULPIAUTOIDLE (1 << 10) |
| 74 | #define OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE (1 << 9) |
| 75 | #define OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE (1 << 8) |
| 76 | #define OMAP_TLL_CHANNEL_CONF_CHANEN (1 << 0) |
| 77 | |
| 78 | #define OMAP_TLL_ULPI_FUNCTION_CTRL(num) (0x804 + 0x100 * num) |
| 79 | #define OMAP_TLL_ULPI_INTERFACE_CTRL(num) (0x807 + 0x100 * num) |
| 80 | #define OMAP_TLL_ULPI_OTG_CTRL(num) (0x80A + 0x100 * num) |
| 81 | #define OMAP_TLL_ULPI_INT_EN_RISE(num) (0x80D + 0x100 * num) |
| 82 | #define OMAP_TLL_ULPI_INT_EN_FALL(num) (0x810 + 0x100 * num) |
| 83 | #define OMAP_TLL_ULPI_INT_STATUS(num) (0x813 + 0x100 * num) |
| 84 | #define OMAP_TLL_ULPI_INT_LATCH(num) (0x814 + 0x100 * num) |
| 85 | #define OMAP_TLL_ULPI_DEBUG(num) (0x815 + 0x100 * num) |
| 86 | #define OMAP_TLL_ULPI_SCRATCH_REGISTER(num) (0x816 + 0x100 * num) |
| 87 | |
| 88 | #define OMAP_TLL_CHANNEL_COUNT 3 |
| 89 | #define OMAP_TLL_CHANNEL_1_EN_MASK (1 << 1) |
| 90 | #define OMAP_TLL_CHANNEL_2_EN_MASK (1 << 2) |
| 91 | #define OMAP_TLL_CHANNEL_3_EN_MASK (1 << 4) |
| 92 | |
| 93 | /* UHH Register Set */ |
| 94 | #define OMAP_UHH_REVISION (0x00) |
| 95 | #define OMAP_UHH_SYSCONFIG (0x10) |
| 96 | #define OMAP_UHH_SYSCONFIG_MIDLEMODE (1 << 12) |
| 97 | #define OMAP_UHH_SYSCONFIG_CACTIVITY (1 << 8) |
| 98 | #define OMAP_UHH_SYSCONFIG_SIDLEMODE (1 << 3) |
| 99 | #define OMAP_UHH_SYSCONFIG_ENAWAKEUP (1 << 2) |
| 100 | #define OMAP_UHH_SYSCONFIG_SOFTRESET (1 << 1) |
| 101 | #define OMAP_UHH_SYSCONFIG_AUTOIDLE (1 << 0) |
| 102 | |
| 103 | #define OMAP_UHH_SYSSTATUS (0x14) |
| 104 | #define OMAP_UHH_HOSTCONFIG (0x40) |
| 105 | #define OMAP_UHH_HOSTCONFIG_ULPI_BYPASS (1 << 0) |
| 106 | #define OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS (1 << 0) |
| 107 | #define OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS (1 << 11) |
| 108 | #define OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS (1 << 12) |
| 109 | #define OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN (1 << 2) |
| 110 | #define OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN (1 << 3) |
| 111 | #define OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN (1 << 4) |
| 112 | #define OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN (1 << 5) |
| 113 | #define OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS (1 << 8) |
| 114 | #define OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS (1 << 9) |
| 115 | #define OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS (1 << 10) |
| 116 | |
| 117 | #define OMAP_UHH_DEBUG_CSR (0x44) |
| 118 | |
| 119 | /* EHCI Register Set */ |
Anand Gadiyar | 572538d | 2010-05-06 20:09:48 +0530 | [diff] [blame] | 120 | #define EHCI_INSNREG04 (0xA0) |
| 121 | #define EHCI_INSNREG04_DISABLE_UNSUSPEND (1 << 5) |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 122 | #define EHCI_INSNREG05_ULPI (0xA4) |
| 123 | #define EHCI_INSNREG05_ULPI_CONTROL_SHIFT 31 |
| 124 | #define EHCI_INSNREG05_ULPI_PORTSEL_SHIFT 24 |
| 125 | #define EHCI_INSNREG05_ULPI_OPSEL_SHIFT 22 |
| 126 | #define EHCI_INSNREG05_ULPI_REGADD_SHIFT 16 |
| 127 | #define EHCI_INSNREG05_ULPI_EXTREGADD_SHIFT 8 |
| 128 | #define EHCI_INSNREG05_ULPI_WRDATA_SHIFT 0 |
| 129 | |
Anand Gadiyar | a42ccdc | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 130 | #define is_ehci_phy_mode(x) (x == EHCI_HCD_OMAP_MODE_PHY) |
| 131 | #define is_ehci_tll_mode(x) (x == EHCI_HCD_OMAP_MODE_TLL) |
| 132 | |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 133 | /*-------------------------------------------------------------------------*/ |
| 134 | |
| 135 | static inline void ehci_omap_writel(void __iomem *base, u32 reg, u32 val) |
| 136 | { |
| 137 | __raw_writel(val, base + reg); |
| 138 | } |
| 139 | |
| 140 | static inline u32 ehci_omap_readl(void __iomem *base, u32 reg) |
| 141 | { |
| 142 | return __raw_readl(base + reg); |
| 143 | } |
| 144 | |
| 145 | static inline void ehci_omap_writeb(void __iomem *base, u8 reg, u8 val) |
| 146 | { |
| 147 | __raw_writeb(val, base + reg); |
| 148 | } |
| 149 | |
| 150 | static inline u8 ehci_omap_readb(void __iomem *base, u8 reg) |
| 151 | { |
| 152 | return __raw_readb(base + reg); |
| 153 | } |
| 154 | |
| 155 | /*-------------------------------------------------------------------------*/ |
| 156 | |
| 157 | struct ehci_hcd_omap { |
| 158 | struct ehci_hcd *ehci; |
| 159 | struct device *dev; |
| 160 | |
| 161 | struct clk *usbhost_ick; |
Keshava Munegowda | 6dba39e | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 162 | struct clk *usbhost_hs_fck; |
| 163 | struct clk *usbhost_fs_fck; |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 164 | struct clk *usbtll_fck; |
| 165 | struct clk *usbtll_ick; |
| 166 | |
| 167 | /* FIXME the following two workarounds are |
| 168 | * board specific not silicon-specific so these |
| 169 | * should be moved to board-file instead. |
| 170 | * |
| 171 | * Maybe someone from TI will know better which |
| 172 | * board is affected and needs the workarounds |
| 173 | * to be applied |
| 174 | */ |
| 175 | |
| 176 | /* gpio for resetting phy */ |
| 177 | int reset_gpio_port[OMAP3_HS_USB_PORTS]; |
| 178 | |
| 179 | /* phy reset workaround */ |
| 180 | int phy_reset; |
| 181 | |
| 182 | /* desired phy_mode: TLL, PHY */ |
| 183 | enum ehci_hcd_omap_mode port_mode[OMAP3_HS_USB_PORTS]; |
| 184 | |
| 185 | void __iomem *uhh_base; |
| 186 | void __iomem *tll_base; |
| 187 | void __iomem *ehci_base; |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 188 | |
| 189 | /* Regulators for USB PHYs. |
Anand Gadiyar | a8cd456 | 2010-05-10 14:51:19 +0530 | [diff] [blame] | 190 | * Each PHY can have a separate regulator. |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 191 | */ |
| 192 | struct regulator *regulator[OMAP3_HS_USB_PORTS]; |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | /*-------------------------------------------------------------------------*/ |
| 196 | |
Keshava Munegowda | c072604 | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 197 | static void omap_usb_utmi_init(struct ehci_hcd_omap *omap, u8 tll_channel_mask, |
| 198 | u8 tll_channel_count) |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 199 | { |
| 200 | unsigned reg; |
| 201 | int i; |
| 202 | |
| 203 | /* Program the 3 TLL channels upfront */ |
Keshava Munegowda | c072604 | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 204 | for (i = 0; i < tll_channel_count; i++) { |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 205 | reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i)); |
| 206 | |
| 207 | /* Disable AutoIdle, BitStuffing and use SDR Mode */ |
| 208 | reg &= ~(OMAP_TLL_CHANNEL_CONF_UTMIAUTOIDLE |
| 209 | | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF |
| 210 | | OMAP_TLL_CHANNEL_CONF_ULPIDDRMODE); |
| 211 | ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg); |
| 212 | } |
| 213 | |
| 214 | /* Program Common TLL register */ |
| 215 | reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_SHARED_CONF); |
| 216 | reg |= (OMAP_TLL_SHARED_CONF_FCLK_IS_ON |
| 217 | | OMAP_TLL_SHARED_CONF_USB_DIVRATION |
| 218 | | OMAP_TLL_SHARED_CONF_USB_180D_SDR_EN); |
| 219 | reg &= ~OMAP_TLL_SHARED_CONF_USB_90D_DDR_EN; |
| 220 | |
| 221 | ehci_omap_writel(omap->tll_base, OMAP_TLL_SHARED_CONF, reg); |
| 222 | |
| 223 | /* Enable channels now */ |
Keshava Munegowda | c072604 | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 224 | for (i = 0; i < tll_channel_count; i++) { |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 225 | reg = ehci_omap_readl(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i)); |
| 226 | |
| 227 | /* Enable only the reg that is needed */ |
| 228 | if (!(tll_channel_mask & 1<<i)) |
| 229 | continue; |
| 230 | |
| 231 | reg |= OMAP_TLL_CHANNEL_CONF_CHANEN; |
| 232 | ehci_omap_writel(omap->tll_base, OMAP_TLL_CHANNEL_CONF(i), reg); |
| 233 | |
| 234 | ehci_omap_writeb(omap->tll_base, |
| 235 | OMAP_TLL_ULPI_SCRATCH_REGISTER(i), 0xbe); |
| 236 | dev_dbg(omap->dev, "ULPI_SCRATCH_REG[ch=%d]= 0x%02x\n", |
| 237 | i+1, ehci_omap_readb(omap->tll_base, |
| 238 | OMAP_TLL_ULPI_SCRATCH_REGISTER(i))); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | /*-------------------------------------------------------------------------*/ |
| 243 | |
Ajay Kumar Gupta | 5aa4af2 | 2010-07-08 14:03:02 +0530 | [diff] [blame] | 244 | static void omap_ehci_soft_phy_reset(struct ehci_hcd_omap *omap, u8 port) |
| 245 | { |
| 246 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
| 247 | unsigned reg = 0; |
| 248 | |
| 249 | reg = ULPI_FUNC_CTRL_RESET |
| 250 | /* FUNCTION_CTRL_SET register */ |
| 251 | | (ULPI_SET(ULPI_FUNC_CTRL) << EHCI_INSNREG05_ULPI_REGADD_SHIFT) |
| 252 | /* Write */ |
| 253 | | (2 << EHCI_INSNREG05_ULPI_OPSEL_SHIFT) |
| 254 | /* PORTn */ |
| 255 | | ((port + 1) << EHCI_INSNREG05_ULPI_PORTSEL_SHIFT) |
| 256 | /* start ULPI access*/ |
| 257 | | (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT); |
| 258 | |
| 259 | ehci_omap_writel(omap->ehci_base, EHCI_INSNREG05_ULPI, reg); |
| 260 | |
| 261 | /* Wait for ULPI access completion */ |
| 262 | while ((ehci_omap_readl(omap->ehci_base, EHCI_INSNREG05_ULPI) |
| 263 | & (1 << EHCI_INSNREG05_ULPI_CONTROL_SHIFT))) { |
| 264 | cpu_relax(); |
| 265 | |
| 266 | if (time_after(jiffies, timeout)) { |
| 267 | dev_dbg(omap->dev, "phy reset operation timed out\n"); |
| 268 | break; |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 273 | /* omap_start_ehc |
| 274 | * - Start the TI USBHOST controller |
| 275 | */ |
| 276 | static int omap_start_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd) |
| 277 | { |
| 278 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
| 279 | u8 tll_ch_mask = 0; |
| 280 | unsigned reg = 0; |
| 281 | int ret = 0; |
| 282 | |
| 283 | dev_dbg(omap->dev, "starting TI EHCI USB Controller\n"); |
| 284 | |
| 285 | /* Enable Clocks for USBHOST */ |
| 286 | omap->usbhost_ick = clk_get(omap->dev, "usbhost_ick"); |
| 287 | if (IS_ERR(omap->usbhost_ick)) { |
| 288 | ret = PTR_ERR(omap->usbhost_ick); |
| 289 | goto err_host_ick; |
| 290 | } |
| 291 | clk_enable(omap->usbhost_ick); |
| 292 | |
Anand Gadiyar | c5dff55 | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 293 | omap->usbhost_hs_fck = clk_get(omap->dev, "hs_fck"); |
Keshava Munegowda | 6dba39e | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 294 | if (IS_ERR(omap->usbhost_hs_fck)) { |
| 295 | ret = PTR_ERR(omap->usbhost_hs_fck); |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 296 | goto err_host_120m_fck; |
| 297 | } |
Keshava Munegowda | 6dba39e | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 298 | clk_enable(omap->usbhost_hs_fck); |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 299 | |
Anand Gadiyar | c5dff55 | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 300 | omap->usbhost_fs_fck = clk_get(omap->dev, "fs_fck"); |
Keshava Munegowda | 6dba39e | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 301 | if (IS_ERR(omap->usbhost_fs_fck)) { |
| 302 | ret = PTR_ERR(omap->usbhost_fs_fck); |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 303 | goto err_host_48m_fck; |
| 304 | } |
Keshava Munegowda | 6dba39e | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 305 | clk_enable(omap->usbhost_fs_fck); |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 306 | |
| 307 | if (omap->phy_reset) { |
| 308 | /* Refer: ISSUE1 */ |
| 309 | if (gpio_is_valid(omap->reset_gpio_port[0])) { |
| 310 | gpio_request(omap->reset_gpio_port[0], |
| 311 | "USB1 PHY reset"); |
| 312 | gpio_direction_output(omap->reset_gpio_port[0], 0); |
| 313 | } |
| 314 | |
| 315 | if (gpio_is_valid(omap->reset_gpio_port[1])) { |
| 316 | gpio_request(omap->reset_gpio_port[1], |
| 317 | "USB2 PHY reset"); |
| 318 | gpio_direction_output(omap->reset_gpio_port[1], 0); |
| 319 | } |
| 320 | |
| 321 | /* Hold the PHY in RESET for enough time till DIR is high */ |
| 322 | udelay(10); |
| 323 | } |
| 324 | |
| 325 | /* Configure TLL for 60Mhz clk for ULPI */ |
| 326 | omap->usbtll_fck = clk_get(omap->dev, "usbtll_fck"); |
| 327 | if (IS_ERR(omap->usbtll_fck)) { |
| 328 | ret = PTR_ERR(omap->usbtll_fck); |
| 329 | goto err_tll_fck; |
| 330 | } |
| 331 | clk_enable(omap->usbtll_fck); |
| 332 | |
| 333 | omap->usbtll_ick = clk_get(omap->dev, "usbtll_ick"); |
| 334 | if (IS_ERR(omap->usbtll_ick)) { |
| 335 | ret = PTR_ERR(omap->usbtll_ick); |
| 336 | goto err_tll_ick; |
| 337 | } |
| 338 | clk_enable(omap->usbtll_ick); |
| 339 | |
| 340 | /* perform TLL soft reset, and wait until reset is complete */ |
| 341 | ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, |
| 342 | OMAP_USBTLL_SYSCONFIG_SOFTRESET); |
| 343 | |
| 344 | /* Wait for TLL reset to complete */ |
| 345 | while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS) |
| 346 | & OMAP_USBTLL_SYSSTATUS_RESETDONE)) { |
| 347 | cpu_relax(); |
| 348 | |
| 349 | if (time_after(jiffies, timeout)) { |
| 350 | dev_dbg(omap->dev, "operation timed out\n"); |
| 351 | ret = -EINVAL; |
| 352 | goto err_sys_status; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | dev_dbg(omap->dev, "TLL RESET DONE\n"); |
| 357 | |
| 358 | /* (1<<3) = no idle mode only for initial debugging */ |
| 359 | ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, |
| 360 | OMAP_USBTLL_SYSCONFIG_ENAWAKEUP | |
| 361 | OMAP_USBTLL_SYSCONFIG_SIDLEMODE | |
| 362 | OMAP_USBTLL_SYSCONFIG_CACTIVITY); |
| 363 | |
| 364 | |
| 365 | /* Put UHH in NoIdle/NoStandby mode */ |
| 366 | reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSCONFIG); |
| 367 | reg |= (OMAP_UHH_SYSCONFIG_ENAWAKEUP |
| 368 | | OMAP_UHH_SYSCONFIG_SIDLEMODE |
| 369 | | OMAP_UHH_SYSCONFIG_CACTIVITY |
| 370 | | OMAP_UHH_SYSCONFIG_MIDLEMODE); |
| 371 | reg &= ~OMAP_UHH_SYSCONFIG_AUTOIDLE; |
| 372 | |
| 373 | ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, reg); |
| 374 | |
| 375 | reg = ehci_omap_readl(omap->uhh_base, OMAP_UHH_HOSTCONFIG); |
| 376 | |
| 377 | /* setup ULPI bypass and burst configurations */ |
| 378 | reg |= (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN |
| 379 | | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN |
| 380 | | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN); |
| 381 | reg &= ~OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN; |
| 382 | |
| 383 | if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_UNKNOWN) |
| 384 | reg &= ~OMAP_UHH_HOSTCONFIG_P1_CONNECT_STATUS; |
| 385 | if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_UNKNOWN) |
| 386 | reg &= ~OMAP_UHH_HOSTCONFIG_P2_CONNECT_STATUS; |
| 387 | if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_UNKNOWN) |
| 388 | reg &= ~OMAP_UHH_HOSTCONFIG_P3_CONNECT_STATUS; |
| 389 | |
| 390 | /* Bypass the TLL module for PHY mode operation */ |
Ajay Kumar Gupta | 97dc7c6 | 2010-05-04 13:15:23 +0530 | [diff] [blame] | 391 | if (cpu_is_omap3430() && (omap_rev() <= OMAP3430_REV_ES2_1)) { |
| 392 | dev_dbg(omap->dev, "OMAP3 ES version <= ES2.1\n"); |
Anand Gadiyar | a42ccdc | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 393 | if (is_ehci_phy_mode(omap->port_mode[0]) || |
| 394 | is_ehci_phy_mode(omap->port_mode[1]) || |
| 395 | is_ehci_phy_mode(omap->port_mode[2])) |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 396 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_BYPASS; |
| 397 | else |
| 398 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_BYPASS; |
| 399 | } else { |
| 400 | dev_dbg(omap->dev, "OMAP3 ES version > ES2.1\n"); |
Anand Gadiyar | a42ccdc | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 401 | if (is_ehci_phy_mode(omap->port_mode[0])) |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 402 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS; |
Anand Gadiyar | a42ccdc | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 403 | else if (is_ehci_tll_mode(omap->port_mode[0])) |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 404 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS; |
| 405 | |
Anand Gadiyar | a42ccdc | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 406 | if (is_ehci_phy_mode(omap->port_mode[1])) |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 407 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS; |
Anand Gadiyar | a42ccdc | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 408 | else if (is_ehci_tll_mode(omap->port_mode[1])) |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 409 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS; |
| 410 | |
Anand Gadiyar | a42ccdc | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 411 | if (is_ehci_phy_mode(omap->port_mode[2])) |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 412 | reg &= ~OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS; |
Anand Gadiyar | a42ccdc | 2010-11-21 23:23:41 +0530 | [diff] [blame] | 413 | else if (is_ehci_tll_mode(omap->port_mode[2])) |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 414 | reg |= OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS; |
| 415 | |
| 416 | } |
| 417 | ehci_omap_writel(omap->uhh_base, OMAP_UHH_HOSTCONFIG, reg); |
| 418 | dev_dbg(omap->dev, "UHH setup done, uhh_hostconfig=%x\n", reg); |
| 419 | |
| 420 | |
Anand Gadiyar | 572538d | 2010-05-06 20:09:48 +0530 | [diff] [blame] | 421 | /* |
| 422 | * An undocumented "feature" in the OMAP3 EHCI controller, |
| 423 | * causes suspended ports to be taken out of suspend when |
| 424 | * the USBCMD.Run/Stop bit is cleared (for example when |
| 425 | * we do ehci_bus_suspend). |
| 426 | * This breaks suspend-resume if the root-hub is allowed |
| 427 | * to suspend. Writing 1 to this undocumented register bit |
| 428 | * disables this feature and restores normal behavior. |
| 429 | */ |
| 430 | ehci_omap_writel(omap->ehci_base, EHCI_INSNREG04, |
| 431 | EHCI_INSNREG04_DISABLE_UNSUSPEND); |
| 432 | |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 433 | if ((omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) || |
| 434 | (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) || |
| 435 | (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL)) { |
| 436 | |
| 437 | if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_TLL) |
| 438 | tll_ch_mask |= OMAP_TLL_CHANNEL_1_EN_MASK; |
| 439 | if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_TLL) |
| 440 | tll_ch_mask |= OMAP_TLL_CHANNEL_2_EN_MASK; |
| 441 | if (omap->port_mode[2] == EHCI_HCD_OMAP_MODE_TLL) |
| 442 | tll_ch_mask |= OMAP_TLL_CHANNEL_3_EN_MASK; |
| 443 | |
| 444 | /* Enable UTMI mode for required TLL channels */ |
Keshava Munegowda | c072604 | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 445 | omap_usb_utmi_init(omap, tll_ch_mask, OMAP_TLL_CHANNEL_COUNT); |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | if (omap->phy_reset) { |
| 449 | /* Refer ISSUE1: |
| 450 | * Hold the PHY in RESET for enough time till |
| 451 | * PHY is settled and ready |
| 452 | */ |
| 453 | udelay(10); |
| 454 | |
| 455 | if (gpio_is_valid(omap->reset_gpio_port[0])) |
| 456 | gpio_set_value(omap->reset_gpio_port[0], 1); |
| 457 | |
| 458 | if (gpio_is_valid(omap->reset_gpio_port[1])) |
| 459 | gpio_set_value(omap->reset_gpio_port[1], 1); |
| 460 | } |
| 461 | |
Ajay Kumar Gupta | 5aa4af2 | 2010-07-08 14:03:02 +0530 | [diff] [blame] | 462 | /* Soft reset the PHY using PHY reset command over ULPI */ |
| 463 | if (omap->port_mode[0] == EHCI_HCD_OMAP_MODE_PHY) |
| 464 | omap_ehci_soft_phy_reset(omap, 0); |
| 465 | if (omap->port_mode[1] == EHCI_HCD_OMAP_MODE_PHY) |
| 466 | omap_ehci_soft_phy_reset(omap, 1); |
| 467 | |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 468 | return 0; |
| 469 | |
| 470 | err_sys_status: |
| 471 | clk_disable(omap->usbtll_ick); |
| 472 | clk_put(omap->usbtll_ick); |
| 473 | |
| 474 | err_tll_ick: |
| 475 | clk_disable(omap->usbtll_fck); |
| 476 | clk_put(omap->usbtll_fck); |
| 477 | |
| 478 | err_tll_fck: |
Keshava Munegowda | 6dba39e | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 479 | clk_disable(omap->usbhost_fs_fck); |
| 480 | clk_put(omap->usbhost_fs_fck); |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 481 | |
| 482 | if (omap->phy_reset) { |
| 483 | if (gpio_is_valid(omap->reset_gpio_port[0])) |
| 484 | gpio_free(omap->reset_gpio_port[0]); |
| 485 | |
| 486 | if (gpio_is_valid(omap->reset_gpio_port[1])) |
| 487 | gpio_free(omap->reset_gpio_port[1]); |
| 488 | } |
| 489 | |
| 490 | err_host_48m_fck: |
Keshava Munegowda | 6dba39e | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 491 | clk_disable(omap->usbhost_hs_fck); |
| 492 | clk_put(omap->usbhost_hs_fck); |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 493 | |
| 494 | err_host_120m_fck: |
| 495 | clk_disable(omap->usbhost_ick); |
| 496 | clk_put(omap->usbhost_ick); |
| 497 | |
| 498 | err_host_ick: |
| 499 | return ret; |
| 500 | } |
| 501 | |
| 502 | static void omap_stop_ehc(struct ehci_hcd_omap *omap, struct usb_hcd *hcd) |
| 503 | { |
| 504 | unsigned long timeout = jiffies + msecs_to_jiffies(100); |
| 505 | |
| 506 | dev_dbg(omap->dev, "stopping TI EHCI USB Controller\n"); |
| 507 | |
| 508 | /* Reset OMAP modules for insmod/rmmod to work */ |
| 509 | ehci_omap_writel(omap->uhh_base, OMAP_UHH_SYSCONFIG, |
| 510 | OMAP_UHH_SYSCONFIG_SOFTRESET); |
| 511 | while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS) |
| 512 | & (1 << 0))) { |
| 513 | cpu_relax(); |
| 514 | |
| 515 | if (time_after(jiffies, timeout)) |
| 516 | dev_dbg(omap->dev, "operation timed out\n"); |
| 517 | } |
| 518 | |
| 519 | while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS) |
| 520 | & (1 << 1))) { |
| 521 | cpu_relax(); |
| 522 | |
| 523 | if (time_after(jiffies, timeout)) |
| 524 | dev_dbg(omap->dev, "operation timed out\n"); |
| 525 | } |
| 526 | |
| 527 | while (!(ehci_omap_readl(omap->uhh_base, OMAP_UHH_SYSSTATUS) |
| 528 | & (1 << 2))) { |
| 529 | cpu_relax(); |
| 530 | |
| 531 | if (time_after(jiffies, timeout)) |
| 532 | dev_dbg(omap->dev, "operation timed out\n"); |
| 533 | } |
| 534 | |
| 535 | ehci_omap_writel(omap->tll_base, OMAP_USBTLL_SYSCONFIG, (1 << 1)); |
| 536 | |
| 537 | while (!(ehci_omap_readl(omap->tll_base, OMAP_USBTLL_SYSSTATUS) |
| 538 | & (1 << 0))) { |
| 539 | cpu_relax(); |
| 540 | |
| 541 | if (time_after(jiffies, timeout)) |
| 542 | dev_dbg(omap->dev, "operation timed out\n"); |
| 543 | } |
| 544 | |
| 545 | if (omap->usbtll_fck != NULL) { |
| 546 | clk_disable(omap->usbtll_fck); |
| 547 | clk_put(omap->usbtll_fck); |
| 548 | omap->usbtll_fck = NULL; |
| 549 | } |
| 550 | |
| 551 | if (omap->usbhost_ick != NULL) { |
| 552 | clk_disable(omap->usbhost_ick); |
| 553 | clk_put(omap->usbhost_ick); |
| 554 | omap->usbhost_ick = NULL; |
| 555 | } |
| 556 | |
Keshava Munegowda | 6dba39e | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 557 | if (omap->usbhost_fs_fck != NULL) { |
| 558 | clk_disable(omap->usbhost_fs_fck); |
| 559 | clk_put(omap->usbhost_fs_fck); |
| 560 | omap->usbhost_fs_fck = NULL; |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 561 | } |
| 562 | |
Keshava Munegowda | 6dba39e | 2010-11-21 23:23:40 +0530 | [diff] [blame] | 563 | if (omap->usbhost_hs_fck != NULL) { |
| 564 | clk_disable(omap->usbhost_hs_fck); |
| 565 | clk_put(omap->usbhost_hs_fck); |
| 566 | omap->usbhost_hs_fck = NULL; |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | if (omap->usbtll_ick != NULL) { |
| 570 | clk_disable(omap->usbtll_ick); |
| 571 | clk_put(omap->usbtll_ick); |
| 572 | omap->usbtll_ick = NULL; |
| 573 | } |
| 574 | |
| 575 | if (omap->phy_reset) { |
| 576 | if (gpio_is_valid(omap->reset_gpio_port[0])) |
| 577 | gpio_free(omap->reset_gpio_port[0]); |
| 578 | |
| 579 | if (gpio_is_valid(omap->reset_gpio_port[1])) |
| 580 | gpio_free(omap->reset_gpio_port[1]); |
| 581 | } |
| 582 | |
| 583 | dev_dbg(omap->dev, "Clock to USB host has been disabled\n"); |
| 584 | } |
| 585 | |
| 586 | /*-------------------------------------------------------------------------*/ |
| 587 | |
| 588 | static const struct hc_driver ehci_omap_hc_driver; |
| 589 | |
| 590 | /* configure so an HC device and id are always provided */ |
| 591 | /* always called with process context; sleeping is OK */ |
| 592 | |
| 593 | /** |
| 594 | * ehci_hcd_omap_probe - initialize TI-based HCDs |
| 595 | * |
| 596 | * Allocates basic resources for this USB host controller, and |
| 597 | * then invokes the start() method for the HCD associated with it |
| 598 | * through the hotplug entry's driver_data. |
| 599 | */ |
| 600 | static int ehci_hcd_omap_probe(struct platform_device *pdev) |
| 601 | { |
| 602 | struct ehci_hcd_omap_platform_data *pdata = pdev->dev.platform_data; |
| 603 | struct ehci_hcd_omap *omap; |
| 604 | struct resource *res; |
| 605 | struct usb_hcd *hcd; |
| 606 | |
| 607 | int irq = platform_get_irq(pdev, 0); |
| 608 | int ret = -ENODEV; |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 609 | int i; |
| 610 | char supply[7]; |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 611 | |
| 612 | if (!pdata) { |
| 613 | dev_dbg(&pdev->dev, "missing platform_data\n"); |
| 614 | goto err_pdata; |
| 615 | } |
| 616 | |
| 617 | if (usb_disabled()) |
| 618 | goto err_disabled; |
| 619 | |
| 620 | omap = kzalloc(sizeof(*omap), GFP_KERNEL); |
| 621 | if (!omap) { |
| 622 | ret = -ENOMEM; |
Julia Lawall | b2b6080 | 2009-11-21 12:52:17 +0100 | [diff] [blame] | 623 | goto err_disabled; |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev, |
| 627 | dev_name(&pdev->dev)); |
| 628 | if (!hcd) { |
| 629 | dev_dbg(&pdev->dev, "failed to create hcd with err %d\n", ret); |
| 630 | ret = -ENOMEM; |
| 631 | goto err_create_hcd; |
| 632 | } |
| 633 | |
| 634 | platform_set_drvdata(pdev, omap); |
| 635 | omap->dev = &pdev->dev; |
| 636 | omap->phy_reset = pdata->phy_reset; |
| 637 | omap->reset_gpio_port[0] = pdata->reset_gpio_port[0]; |
| 638 | omap->reset_gpio_port[1] = pdata->reset_gpio_port[1]; |
| 639 | omap->reset_gpio_port[2] = pdata->reset_gpio_port[2]; |
| 640 | omap->port_mode[0] = pdata->port_mode[0]; |
| 641 | omap->port_mode[1] = pdata->port_mode[1]; |
| 642 | omap->port_mode[2] = pdata->port_mode[2]; |
| 643 | omap->ehci = hcd_to_ehci(hcd); |
| 644 | omap->ehci->sbrn = 0x20; |
| 645 | |
| 646 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 647 | |
| 648 | hcd->rsrc_start = res->start; |
| 649 | hcd->rsrc_len = resource_size(res); |
| 650 | |
| 651 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 652 | if (!hcd->regs) { |
| 653 | dev_err(&pdev->dev, "EHCI ioremap failed\n"); |
| 654 | ret = -ENOMEM; |
| 655 | goto err_ioremap; |
| 656 | } |
| 657 | |
| 658 | /* we know this is the memory we want, no need to ioremap again */ |
| 659 | omap->ehci->caps = hcd->regs; |
| 660 | omap->ehci_base = hcd->regs; |
| 661 | |
| 662 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 663 | omap->uhh_base = ioremap(res->start, resource_size(res)); |
| 664 | if (!omap->uhh_base) { |
| 665 | dev_err(&pdev->dev, "UHH ioremap failed\n"); |
| 666 | ret = -ENOMEM; |
| 667 | goto err_uhh_ioremap; |
| 668 | } |
| 669 | |
| 670 | res = platform_get_resource(pdev, IORESOURCE_MEM, 2); |
| 671 | omap->tll_base = ioremap(res->start, resource_size(res)); |
| 672 | if (!omap->tll_base) { |
| 673 | dev_err(&pdev->dev, "TLL ioremap failed\n"); |
| 674 | ret = -ENOMEM; |
| 675 | goto err_tll_ioremap; |
| 676 | } |
| 677 | |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 678 | /* get ehci regulator and enable */ |
| 679 | for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) { |
| 680 | if (omap->port_mode[i] != EHCI_HCD_OMAP_MODE_PHY) { |
| 681 | omap->regulator[i] = NULL; |
| 682 | continue; |
| 683 | } |
| 684 | snprintf(supply, sizeof(supply), "hsusb%d", i); |
| 685 | omap->regulator[i] = regulator_get(omap->dev, supply); |
Ajay Kumar Gupta | 18f9119 | 2010-03-18 16:58:35 +0530 | [diff] [blame] | 686 | if (IS_ERR(omap->regulator[i])) { |
| 687 | omap->regulator[i] = NULL; |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 688 | dev_dbg(&pdev->dev, |
| 689 | "failed to get ehci port%d regulator\n", i); |
Ajay Kumar Gupta | 18f9119 | 2010-03-18 16:58:35 +0530 | [diff] [blame] | 690 | } else { |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 691 | regulator_enable(omap->regulator[i]); |
Ajay Kumar Gupta | 18f9119 | 2010-03-18 16:58:35 +0530 | [diff] [blame] | 692 | } |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 693 | } |
| 694 | |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 695 | ret = omap_start_ehc(omap, hcd); |
| 696 | if (ret) { |
| 697 | dev_dbg(&pdev->dev, "failed to start ehci\n"); |
| 698 | goto err_start; |
| 699 | } |
| 700 | |
| 701 | omap->ehci->regs = hcd->regs |
| 702 | + HC_LENGTH(readl(&omap->ehci->caps->hc_capbase)); |
| 703 | |
Anand Gadiyar | bdb581b | 2010-02-12 17:54:59 +0530 | [diff] [blame] | 704 | dbg_hcs_params(omap->ehci, "reset"); |
| 705 | dbg_hcc_params(omap->ehci, "reset"); |
| 706 | |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 707 | /* cache this readonly data; minimize chip reads */ |
| 708 | omap->ehci->hcs_params = readl(&omap->ehci->caps->hcs_params); |
| 709 | |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 710 | ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); |
| 711 | if (ret) { |
| 712 | dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); |
| 713 | goto err_add_hcd; |
| 714 | } |
| 715 | |
Ajay Kumar Gupta | 289621c | 2010-05-04 19:53:09 +0530 | [diff] [blame] | 716 | /* root ports should always stay powered */ |
| 717 | ehci_port_power(omap->ehci, 1); |
| 718 | |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 719 | return 0; |
| 720 | |
| 721 | err_add_hcd: |
| 722 | omap_stop_ehc(omap, hcd); |
| 723 | |
| 724 | err_start: |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 725 | for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) { |
| 726 | if (omap->regulator[i]) { |
| 727 | regulator_disable(omap->regulator[i]); |
| 728 | regulator_put(omap->regulator[i]); |
| 729 | } |
| 730 | } |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 731 | iounmap(omap->tll_base); |
| 732 | |
| 733 | err_tll_ioremap: |
| 734 | iounmap(omap->uhh_base); |
| 735 | |
| 736 | err_uhh_ioremap: |
| 737 | iounmap(hcd->regs); |
| 738 | |
| 739 | err_ioremap: |
| 740 | usb_put_hcd(hcd); |
| 741 | |
| 742 | err_create_hcd: |
Julia Lawall | b2b6080 | 2009-11-21 12:52:17 +0100 | [diff] [blame] | 743 | kfree(omap); |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 744 | err_disabled: |
| 745 | err_pdata: |
| 746 | return ret; |
| 747 | } |
| 748 | |
| 749 | /* may be called without controller electrically present */ |
| 750 | /* may be called with controller, bus, and devices active */ |
| 751 | |
| 752 | /** |
| 753 | * ehci_hcd_omap_remove - shutdown processing for EHCI HCDs |
| 754 | * @pdev: USB Host Controller being removed |
| 755 | * |
| 756 | * Reverses the effect of usb_ehci_hcd_omap_probe(), first invoking |
| 757 | * the HCD's stop() method. It is always called from a thread |
| 758 | * context, normally "rmmod", "apmd", or something similar. |
| 759 | */ |
| 760 | static int ehci_hcd_omap_remove(struct platform_device *pdev) |
| 761 | { |
| 762 | struct ehci_hcd_omap *omap = platform_get_drvdata(pdev); |
| 763 | struct usb_hcd *hcd = ehci_to_hcd(omap->ehci); |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 764 | int i; |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 765 | |
| 766 | usb_remove_hcd(hcd); |
| 767 | omap_stop_ehc(omap, hcd); |
| 768 | iounmap(hcd->regs); |
Ajay Kumar Gupta | 8811426 | 2009-12-28 13:40:46 +0200 | [diff] [blame] | 769 | for (i = 0 ; i < OMAP3_HS_USB_PORTS ; i++) { |
| 770 | if (omap->regulator[i]) { |
| 771 | regulator_disable(omap->regulator[i]); |
| 772 | regulator_put(omap->regulator[i]); |
| 773 | } |
| 774 | } |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 775 | iounmap(omap->tll_base); |
| 776 | iounmap(omap->uhh_base); |
| 777 | usb_put_hcd(hcd); |
Ajay Kumar Gupta | d3ae856 | 2009-12-28 13:40:45 +0200 | [diff] [blame] | 778 | kfree(omap); |
Felipe Balbi | 54ab2b0 | 2009-10-14 11:44:14 +0300 | [diff] [blame] | 779 | |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | static void ehci_hcd_omap_shutdown(struct platform_device *pdev) |
| 784 | { |
| 785 | struct ehci_hcd_omap *omap = platform_get_drvdata(pdev); |
| 786 | struct usb_hcd *hcd = ehci_to_hcd(omap->ehci); |
| 787 | |
| 788 | if (hcd->driver->shutdown) |
| 789 | hcd->driver->shutdown(hcd); |
| 790 | } |
| 791 | |
| 792 | static struct platform_driver ehci_hcd_omap_driver = { |
| 793 | .probe = ehci_hcd_omap_probe, |
| 794 | .remove = ehci_hcd_omap_remove, |
| 795 | .shutdown = ehci_hcd_omap_shutdown, |
| 796 | /*.suspend = ehci_hcd_omap_suspend, */ |
| 797 | /*.resume = ehci_hcd_omap_resume, */ |
| 798 | .driver = { |
| 799 | .name = "ehci-omap", |
| 800 | } |
| 801 | }; |
| 802 | |
| 803 | /*-------------------------------------------------------------------------*/ |
| 804 | |
| 805 | static const struct hc_driver ehci_omap_hc_driver = { |
| 806 | .description = hcd_name, |
| 807 | .product_desc = "OMAP-EHCI Host Controller", |
| 808 | .hcd_priv_size = sizeof(struct ehci_hcd), |
| 809 | |
| 810 | /* |
| 811 | * generic hardware linkage |
| 812 | */ |
| 813 | .irq = ehci_irq, |
| 814 | .flags = HCD_MEMORY | HCD_USB2, |
| 815 | |
| 816 | /* |
| 817 | * basic lifecycle operations |
| 818 | */ |
| 819 | .reset = ehci_init, |
| 820 | .start = ehci_run, |
| 821 | .stop = ehci_stop, |
| 822 | .shutdown = ehci_shutdown, |
| 823 | |
| 824 | /* |
| 825 | * managing i/o requests and associated device resources |
| 826 | */ |
| 827 | .urb_enqueue = ehci_urb_enqueue, |
| 828 | .urb_dequeue = ehci_urb_dequeue, |
| 829 | .endpoint_disable = ehci_endpoint_disable, |
| 830 | .endpoint_reset = ehci_endpoint_reset, |
| 831 | |
| 832 | /* |
| 833 | * scheduling support |
| 834 | */ |
| 835 | .get_frame_number = ehci_get_frame, |
| 836 | |
| 837 | /* |
| 838 | * root hub support |
| 839 | */ |
| 840 | .hub_status_data = ehci_hub_status_data, |
| 841 | .hub_control = ehci_hub_control, |
| 842 | .bus_suspend = ehci_bus_suspend, |
| 843 | .bus_resume = ehci_bus_resume, |
| 844 | |
| 845 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 846 | }; |
| 847 | |
| 848 | MODULE_ALIAS("platform:omap-ehci"); |
| 849 | MODULE_AUTHOR("Texas Instruments, Inc."); |
| 850 | MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>"); |
| 851 | |