Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Texas Instruments DA8xx/OMAP-L1x "glue layer" |
| 3 | * |
| 4 | * Copyright (c) 2008-2009 MontaVista Software, Inc. <source@mvista.com> |
| 5 | * |
| 6 | * Based on the DaVinci "glue layer" code. |
| 7 | * Copyright (C) 2005-2006 by Texas Instruments |
| 8 | * |
| 9 | * This file is part of the Inventra Controller Driver for Linux. |
| 10 | * |
| 11 | * The Inventra Controller Driver for Linux is free software; you |
| 12 | * can redistribute it and/or modify it under the terms of the GNU |
| 13 | * General Public License version 2 as published by the Free Software |
| 14 | * Foundation. |
| 15 | * |
| 16 | * The Inventra Controller Driver for Linux is distributed in |
| 17 | * the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 20 | * License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with The Inventra Controller Driver for Linux ; if not, |
| 24 | * write to the Free Software Foundation, Inc., 59 Temple Place, |
| 25 | * Suite 330, Boston, MA 02111-1307 USA |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/clk.h> |
| 31 | #include <linux/io.h> |
Felipe Balbi | 8ceae51 | 2010-12-02 09:19:35 +0200 | [diff] [blame^] | 32 | #include <linux/platform_device.h> |
| 33 | #include <linux/dma-mapping.h> |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 34 | |
| 35 | #include <mach/da8xx.h> |
| 36 | #include <mach/usb.h> |
| 37 | |
| 38 | #include "musb_core.h" |
| 39 | |
| 40 | /* |
| 41 | * DA8XX specific definitions |
| 42 | */ |
| 43 | |
| 44 | /* USB 2.0 OTG module registers */ |
| 45 | #define DA8XX_USB_REVISION_REG 0x00 |
| 46 | #define DA8XX_USB_CTRL_REG 0x04 |
| 47 | #define DA8XX_USB_STAT_REG 0x08 |
| 48 | #define DA8XX_USB_EMULATION_REG 0x0c |
| 49 | #define DA8XX_USB_MODE_REG 0x10 /* Transparent, CDC, [Generic] RNDIS */ |
| 50 | #define DA8XX_USB_AUTOREQ_REG 0x14 |
| 51 | #define DA8XX_USB_SRP_FIX_TIME_REG 0x18 |
| 52 | #define DA8XX_USB_TEARDOWN_REG 0x1c |
| 53 | #define DA8XX_USB_INTR_SRC_REG 0x20 |
| 54 | #define DA8XX_USB_INTR_SRC_SET_REG 0x24 |
| 55 | #define DA8XX_USB_INTR_SRC_CLEAR_REG 0x28 |
| 56 | #define DA8XX_USB_INTR_MASK_REG 0x2c |
| 57 | #define DA8XX_USB_INTR_MASK_SET_REG 0x30 |
| 58 | #define DA8XX_USB_INTR_MASK_CLEAR_REG 0x34 |
| 59 | #define DA8XX_USB_INTR_SRC_MASKED_REG 0x38 |
| 60 | #define DA8XX_USB_END_OF_INTR_REG 0x3c |
| 61 | #define DA8XX_USB_GENERIC_RNDIS_EP_SIZE_REG(n) (0x50 + (((n) - 1) << 2)) |
| 62 | |
| 63 | /* Control register bits */ |
| 64 | #define DA8XX_SOFT_RESET_MASK 1 |
| 65 | |
| 66 | #define DA8XX_USB_TX_EP_MASK 0x1f /* EP0 + 4 Tx EPs */ |
| 67 | #define DA8XX_USB_RX_EP_MASK 0x1e /* 4 Rx EPs */ |
| 68 | |
| 69 | /* USB interrupt register bits */ |
| 70 | #define DA8XX_INTR_USB_SHIFT 16 |
| 71 | #define DA8XX_INTR_USB_MASK (0x1ff << DA8XX_INTR_USB_SHIFT) /* 8 Mentor */ |
| 72 | /* interrupts and DRVVBUS interrupt */ |
| 73 | #define DA8XX_INTR_DRVVBUS 0x100 |
| 74 | #define DA8XX_INTR_RX_SHIFT 8 |
| 75 | #define DA8XX_INTR_RX_MASK (DA8XX_USB_RX_EP_MASK << DA8XX_INTR_RX_SHIFT) |
| 76 | #define DA8XX_INTR_TX_SHIFT 0 |
| 77 | #define DA8XX_INTR_TX_MASK (DA8XX_USB_TX_EP_MASK << DA8XX_INTR_TX_SHIFT) |
| 78 | |
| 79 | #define DA8XX_MENTOR_CORE_OFFSET 0x400 |
| 80 | |
| 81 | #define CFGCHIP2 IO_ADDRESS(DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP2_REG) |
| 82 | |
| 83 | /* |
| 84 | * REVISIT (PM): we should be able to keep the PHY in low power mode most |
| 85 | * of the time (24 MHz oscillator and PLL off, etc.) by setting POWER.D0 |
| 86 | * and, when in host mode, autosuspending idle root ports... PHY_PLLON |
| 87 | * (overriding SUSPENDM?) then likely needs to stay off. |
| 88 | */ |
| 89 | |
| 90 | static inline void phy_on(void) |
| 91 | { |
| 92 | u32 cfgchip2 = __raw_readl(CFGCHIP2); |
| 93 | |
| 94 | /* |
| 95 | * Start the on-chip PHY and its PLL. |
| 96 | */ |
| 97 | cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN); |
| 98 | cfgchip2 |= CFGCHIP2_PHY_PLLON; |
| 99 | __raw_writel(cfgchip2, CFGCHIP2); |
| 100 | |
| 101 | pr_info("Waiting for USB PHY clock good...\n"); |
| 102 | while (!(__raw_readl(CFGCHIP2) & CFGCHIP2_PHYCLKGD)) |
| 103 | cpu_relax(); |
| 104 | } |
| 105 | |
| 106 | static inline void phy_off(void) |
| 107 | { |
| 108 | u32 cfgchip2 = __raw_readl(CFGCHIP2); |
| 109 | |
| 110 | /* |
| 111 | * Ensure that USB 1.1 reference clock is not being sourced from |
| 112 | * USB 2.0 PHY. Otherwise do not power down the PHY. |
| 113 | */ |
| 114 | if (!(cfgchip2 & CFGCHIP2_USB1PHYCLKMUX) && |
| 115 | (cfgchip2 & CFGCHIP2_USB1SUSPENDM)) { |
| 116 | pr_warning("USB 1.1 clocked from USB 2.0 PHY -- " |
| 117 | "can't power it down\n"); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * Power down the on-chip PHY. |
| 123 | */ |
| 124 | cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN; |
| 125 | __raw_writel(cfgchip2, CFGCHIP2); |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * Because we don't set CTRL.UINT, it's "important" to: |
| 130 | * - not read/write INTRUSB/INTRUSBE (except during |
| 131 | * initial setup, as a workaround); |
| 132 | * - use INTSET/INTCLR instead. |
| 133 | */ |
| 134 | |
| 135 | /** |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 136 | * da8xx_musb_enable - enable interrupts |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 137 | */ |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 138 | static void da8xx_musb_enable(struct musb *musb) |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 139 | { |
| 140 | void __iomem *reg_base = musb->ctrl_base; |
| 141 | u32 mask; |
| 142 | |
| 143 | /* Workaround: setup IRQs through both register sets. */ |
| 144 | mask = ((musb->epmask & DA8XX_USB_TX_EP_MASK) << DA8XX_INTR_TX_SHIFT) | |
| 145 | ((musb->epmask & DA8XX_USB_RX_EP_MASK) << DA8XX_INTR_RX_SHIFT) | |
| 146 | DA8XX_INTR_USB_MASK; |
| 147 | musb_writel(reg_base, DA8XX_USB_INTR_MASK_SET_REG, mask); |
| 148 | |
| 149 | /* Force the DRVVBUS IRQ so we can start polling for ID change. */ |
| 150 | if (is_otg_enabled(musb)) |
| 151 | musb_writel(reg_base, DA8XX_USB_INTR_SRC_SET_REG, |
| 152 | DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT); |
| 153 | } |
| 154 | |
| 155 | /** |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 156 | * da8xx_musb_disable - disable HDRC and flush interrupts |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 157 | */ |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 158 | static void da8xx_musb_disable(struct musb *musb) |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 159 | { |
| 160 | void __iomem *reg_base = musb->ctrl_base; |
| 161 | |
| 162 | musb_writel(reg_base, DA8XX_USB_INTR_MASK_CLEAR_REG, |
| 163 | DA8XX_INTR_USB_MASK | |
| 164 | DA8XX_INTR_TX_MASK | DA8XX_INTR_RX_MASK); |
| 165 | musb_writeb(musb->mregs, MUSB_DEVCTL, 0); |
| 166 | musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0); |
| 167 | } |
| 168 | |
| 169 | #ifdef CONFIG_USB_MUSB_HDRC_HCD |
| 170 | #define portstate(stmt) stmt |
| 171 | #else |
| 172 | #define portstate(stmt) |
| 173 | #endif |
| 174 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 175 | static void da8xx_musb_set_vbus(struct musb *musb, int is_on) |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 176 | { |
| 177 | WARN_ON(is_on && is_peripheral_active(musb)); |
| 178 | } |
| 179 | |
| 180 | #define POLL_SECONDS 2 |
| 181 | |
| 182 | static struct timer_list otg_workaround; |
| 183 | |
| 184 | static void otg_timer(unsigned long _musb) |
| 185 | { |
| 186 | struct musb *musb = (void *)_musb; |
| 187 | void __iomem *mregs = musb->mregs; |
| 188 | u8 devctl; |
| 189 | unsigned long flags; |
| 190 | |
| 191 | /* |
| 192 | * We poll because DaVinci's won't expose several OTG-critical |
| 193 | * status change events (from the transceiver) otherwise. |
| 194 | */ |
| 195 | devctl = musb_readb(mregs, MUSB_DEVCTL); |
| 196 | DBG(7, "Poll devctl %02x (%s)\n", devctl, otg_state_string(musb)); |
| 197 | |
| 198 | spin_lock_irqsave(&musb->lock, flags); |
| 199 | switch (musb->xceiv->state) { |
| 200 | case OTG_STATE_A_WAIT_BCON: |
| 201 | devctl &= ~MUSB_DEVCTL_SESSION; |
| 202 | musb_writeb(musb->mregs, MUSB_DEVCTL, devctl); |
| 203 | |
| 204 | devctl = musb_readb(musb->mregs, MUSB_DEVCTL); |
| 205 | if (devctl & MUSB_DEVCTL_BDEVICE) { |
| 206 | musb->xceiv->state = OTG_STATE_B_IDLE; |
| 207 | MUSB_DEV_MODE(musb); |
| 208 | } else { |
| 209 | musb->xceiv->state = OTG_STATE_A_IDLE; |
| 210 | MUSB_HST_MODE(musb); |
| 211 | } |
| 212 | break; |
| 213 | case OTG_STATE_A_WAIT_VFALL: |
| 214 | /* |
| 215 | * Wait till VBUS falls below SessionEnd (~0.2 V); the 1.3 |
| 216 | * RTL seems to mis-handle session "start" otherwise (or in |
| 217 | * our case "recover"), in routine "VBUS was valid by the time |
| 218 | * VBUSERR got reported during enumeration" cases. |
| 219 | */ |
| 220 | if (devctl & MUSB_DEVCTL_VBUS) { |
| 221 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
| 222 | break; |
| 223 | } |
| 224 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; |
| 225 | musb_writel(musb->ctrl_base, DA8XX_USB_INTR_SRC_SET_REG, |
| 226 | MUSB_INTR_VBUSERROR << DA8XX_INTR_USB_SHIFT); |
| 227 | break; |
| 228 | case OTG_STATE_B_IDLE: |
| 229 | if (!is_peripheral_enabled(musb)) |
| 230 | break; |
| 231 | |
| 232 | /* |
| 233 | * There's no ID-changed IRQ, so we have no good way to tell |
| 234 | * when to switch to the A-Default state machine (by setting |
| 235 | * the DEVCTL.Session bit). |
| 236 | * |
| 237 | * Workaround: whenever we're in B_IDLE, try setting the |
| 238 | * session flag every few seconds. If it works, ID was |
| 239 | * grounded and we're now in the A-Default state machine. |
| 240 | * |
| 241 | * NOTE: setting the session flag is _supposed_ to trigger |
| 242 | * SRP but clearly it doesn't. |
| 243 | */ |
| 244 | musb_writeb(mregs, MUSB_DEVCTL, devctl | MUSB_DEVCTL_SESSION); |
| 245 | devctl = musb_readb(mregs, MUSB_DEVCTL); |
| 246 | if (devctl & MUSB_DEVCTL_BDEVICE) |
| 247 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
| 248 | else |
| 249 | musb->xceiv->state = OTG_STATE_A_IDLE; |
| 250 | break; |
| 251 | default: |
| 252 | break; |
| 253 | } |
| 254 | spin_unlock_irqrestore(&musb->lock, flags); |
| 255 | } |
| 256 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 257 | static void da8xx_musb_try_idle(struct musb *musb, unsigned long timeout) |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 258 | { |
| 259 | static unsigned long last_timer; |
| 260 | |
| 261 | if (!is_otg_enabled(musb)) |
| 262 | return; |
| 263 | |
| 264 | if (timeout == 0) |
| 265 | timeout = jiffies + msecs_to_jiffies(3); |
| 266 | |
| 267 | /* Never idle if active, or when VBUS timeout is not set as host */ |
| 268 | if (musb->is_active || (musb->a_wait_bcon == 0 && |
| 269 | musb->xceiv->state == OTG_STATE_A_WAIT_BCON)) { |
| 270 | DBG(4, "%s active, deleting timer\n", otg_state_string(musb)); |
| 271 | del_timer(&otg_workaround); |
| 272 | last_timer = jiffies; |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | if (time_after(last_timer, timeout) && timer_pending(&otg_workaround)) { |
| 277 | DBG(4, "Longer idle timer already pending, ignoring...\n"); |
| 278 | return; |
| 279 | } |
| 280 | last_timer = timeout; |
| 281 | |
| 282 | DBG(4, "%s inactive, starting idle timer for %u ms\n", |
| 283 | otg_state_string(musb), jiffies_to_msecs(timeout - jiffies)); |
| 284 | mod_timer(&otg_workaround, timeout); |
| 285 | } |
| 286 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 287 | static irqreturn_t da8xx_musb_interrupt(int irq, void *hci) |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 288 | { |
| 289 | struct musb *musb = hci; |
| 290 | void __iomem *reg_base = musb->ctrl_base; |
| 291 | unsigned long flags; |
| 292 | irqreturn_t ret = IRQ_NONE; |
| 293 | u32 status; |
| 294 | |
| 295 | spin_lock_irqsave(&musb->lock, flags); |
| 296 | |
| 297 | /* |
| 298 | * NOTE: DA8XX shadows the Mentor IRQs. Don't manage them through |
| 299 | * the Mentor registers (except for setup), use the TI ones and EOI. |
| 300 | */ |
| 301 | |
| 302 | /* Acknowledge and handle non-CPPI interrupts */ |
| 303 | status = musb_readl(reg_base, DA8XX_USB_INTR_SRC_MASKED_REG); |
| 304 | if (!status) |
| 305 | goto eoi; |
| 306 | |
| 307 | musb_writel(reg_base, DA8XX_USB_INTR_SRC_CLEAR_REG, status); |
| 308 | DBG(4, "USB IRQ %08x\n", status); |
| 309 | |
| 310 | musb->int_rx = (status & DA8XX_INTR_RX_MASK) >> DA8XX_INTR_RX_SHIFT; |
| 311 | musb->int_tx = (status & DA8XX_INTR_TX_MASK) >> DA8XX_INTR_TX_SHIFT; |
| 312 | musb->int_usb = (status & DA8XX_INTR_USB_MASK) >> DA8XX_INTR_USB_SHIFT; |
| 313 | |
| 314 | /* |
| 315 | * DRVVBUS IRQs are the only proxy we have (a very poor one!) for |
| 316 | * DA8xx's missing ID change IRQ. We need an ID change IRQ to |
| 317 | * switch appropriately between halves of the OTG state machine. |
| 318 | * Managing DEVCTL.Session per Mentor docs requires that we know its |
| 319 | * value but DEVCTL.BDevice is invalid without DEVCTL.Session set. |
| 320 | * Also, DRVVBUS pulses for SRP (but not at 5 V)... |
| 321 | */ |
| 322 | if (status & (DA8XX_INTR_DRVVBUS << DA8XX_INTR_USB_SHIFT)) { |
| 323 | int drvvbus = musb_readl(reg_base, DA8XX_USB_STAT_REG); |
| 324 | void __iomem *mregs = musb->mregs; |
| 325 | u8 devctl = musb_readb(mregs, MUSB_DEVCTL); |
| 326 | int err; |
| 327 | |
| 328 | err = is_host_enabled(musb) && (musb->int_usb & |
| 329 | MUSB_INTR_VBUSERROR); |
| 330 | if (err) { |
| 331 | /* |
| 332 | * The Mentor core doesn't debounce VBUS as needed |
| 333 | * to cope with device connect current spikes. This |
| 334 | * means it's not uncommon for bus-powered devices |
| 335 | * to get VBUS errors during enumeration. |
| 336 | * |
| 337 | * This is a workaround, but newer RTL from Mentor |
| 338 | * seems to allow a better one: "re"-starting sessions |
| 339 | * without waiting for VBUS to stop registering in |
| 340 | * devctl. |
| 341 | */ |
| 342 | musb->int_usb &= ~MUSB_INTR_VBUSERROR; |
| 343 | musb->xceiv->state = OTG_STATE_A_WAIT_VFALL; |
| 344 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
| 345 | WARNING("VBUS error workaround (delay coming)\n"); |
| 346 | } else if (is_host_enabled(musb) && drvvbus) { |
| 347 | MUSB_HST_MODE(musb); |
| 348 | musb->xceiv->default_a = 1; |
| 349 | musb->xceiv->state = OTG_STATE_A_WAIT_VRISE; |
| 350 | portstate(musb->port1_status |= USB_PORT_STAT_POWER); |
| 351 | del_timer(&otg_workaround); |
| 352 | } else { |
| 353 | musb->is_active = 0; |
| 354 | MUSB_DEV_MODE(musb); |
| 355 | musb->xceiv->default_a = 0; |
| 356 | musb->xceiv->state = OTG_STATE_B_IDLE; |
| 357 | portstate(musb->port1_status &= ~USB_PORT_STAT_POWER); |
| 358 | } |
| 359 | |
| 360 | DBG(2, "VBUS %s (%s)%s, devctl %02x\n", |
| 361 | drvvbus ? "on" : "off", |
| 362 | otg_state_string(musb), |
| 363 | err ? " ERROR" : "", |
| 364 | devctl); |
| 365 | ret = IRQ_HANDLED; |
| 366 | } |
| 367 | |
| 368 | if (musb->int_tx || musb->int_rx || musb->int_usb) |
| 369 | ret |= musb_interrupt(musb); |
| 370 | |
| 371 | eoi: |
| 372 | /* EOI needs to be written for the IRQ to be re-asserted. */ |
| 373 | if (ret == IRQ_HANDLED || status) |
| 374 | musb_writel(reg_base, DA8XX_USB_END_OF_INTR_REG, 0); |
| 375 | |
| 376 | /* Poll for ID change */ |
| 377 | if (is_otg_enabled(musb) && musb->xceiv->state == OTG_STATE_B_IDLE) |
| 378 | mod_timer(&otg_workaround, jiffies + POLL_SECONDS * HZ); |
| 379 | |
| 380 | spin_unlock_irqrestore(&musb->lock, flags); |
| 381 | |
| 382 | return ret; |
| 383 | } |
| 384 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 385 | static int da8xx_musb_set_mode(struct musb *musb, u8 musb_mode) |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 386 | { |
| 387 | u32 cfgchip2 = __raw_readl(CFGCHIP2); |
| 388 | |
| 389 | cfgchip2 &= ~CFGCHIP2_OTGMODE; |
| 390 | switch (musb_mode) { |
| 391 | #ifdef CONFIG_USB_MUSB_HDRC_HCD |
| 392 | case MUSB_HOST: /* Force VBUS valid, ID = 0 */ |
| 393 | cfgchip2 |= CFGCHIP2_FORCE_HOST; |
| 394 | break; |
| 395 | #endif |
| 396 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC |
| 397 | case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */ |
| 398 | cfgchip2 |= CFGCHIP2_FORCE_DEVICE; |
| 399 | break; |
| 400 | #endif |
| 401 | #ifdef CONFIG_USB_MUSB_OTG |
| 402 | case MUSB_OTG: /* Don't override the VBUS/ID comparators */ |
| 403 | cfgchip2 |= CFGCHIP2_NO_OVERRIDE; |
| 404 | break; |
| 405 | #endif |
| 406 | default: |
| 407 | DBG(2, "Trying to set unsupported mode %u\n", musb_mode); |
| 408 | } |
| 409 | |
| 410 | __raw_writel(cfgchip2, CFGCHIP2); |
| 411 | return 0; |
| 412 | } |
| 413 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 414 | static int da8xx_musb_init(struct musb *musb) |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 415 | { |
| 416 | void __iomem *reg_base = musb->ctrl_base; |
| 417 | u32 rev; |
| 418 | |
| 419 | musb->mregs += DA8XX_MENTOR_CORE_OFFSET; |
| 420 | |
| 421 | clk_enable(musb->clock); |
| 422 | |
| 423 | /* Returns zero if e.g. not clocked */ |
| 424 | rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG); |
| 425 | if (!rev) |
| 426 | goto fail; |
| 427 | |
| 428 | usb_nop_xceiv_register(); |
| 429 | musb->xceiv = otg_get_transceiver(); |
| 430 | if (!musb->xceiv) |
| 431 | goto fail; |
| 432 | |
| 433 | if (is_host_enabled(musb)) |
| 434 | setup_timer(&otg_workaround, otg_timer, (unsigned long)musb); |
| 435 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 436 | musb->board_set_vbus = da8xx_musb_set_vbus; |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 437 | |
| 438 | /* Reset the controller */ |
| 439 | musb_writel(reg_base, DA8XX_USB_CTRL_REG, DA8XX_SOFT_RESET_MASK); |
| 440 | |
| 441 | /* Start the on-chip PHY and its PLL. */ |
| 442 | phy_on(); |
| 443 | |
| 444 | msleep(5); |
| 445 | |
| 446 | /* NOTE: IRQs are in mixed mode, not bypass to pure MUSB */ |
| 447 | pr_debug("DA8xx OTG revision %08x, PHY %03x, control %02x\n", |
| 448 | rev, __raw_readl(CFGCHIP2), |
| 449 | musb_readb(reg_base, DA8XX_USB_CTRL_REG)); |
| 450 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 451 | musb->isr = da8xx_musb_interrupt; |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 452 | return 0; |
| 453 | fail: |
| 454 | clk_disable(musb->clock); |
| 455 | return -ENODEV; |
| 456 | } |
| 457 | |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 458 | static int da8xx_musb_exit(struct musb *musb) |
Sergei Shtylyov | 3ee076d | 2010-09-24 13:44:03 +0300 | [diff] [blame] | 459 | { |
| 460 | if (is_host_enabled(musb)) |
| 461 | del_timer_sync(&otg_workaround); |
| 462 | |
| 463 | phy_off(); |
| 464 | |
| 465 | otg_put_transceiver(musb->xceiv); |
| 466 | usb_nop_xceiv_unregister(); |
| 467 | |
| 468 | clk_disable(musb->clock); |
| 469 | |
| 470 | return 0; |
| 471 | } |
Felipe Balbi | 743411b | 2010-12-01 13:22:05 +0200 | [diff] [blame] | 472 | |
| 473 | const struct musb_platform_ops musb_ops = { |
| 474 | .init = da8xx_musb_init, |
| 475 | .exit = da8xx_musb_exit, |
| 476 | |
| 477 | .enable = da8xx_musb_enable, |
| 478 | .disable = da8xx_musb_disable, |
| 479 | |
| 480 | .set_mode = da8xx_musb_set_mode, |
| 481 | .try_idle = da8xx_musb_try_idle, |
| 482 | |
| 483 | .set_vbus = da8xx_musb_set_vbus, |
| 484 | }; |
Felipe Balbi | 8ceae51 | 2010-12-02 09:19:35 +0200 | [diff] [blame^] | 485 | |
| 486 | static u64 da8xx_dmamask = DMA_BIT_MASK(32); |
| 487 | |
| 488 | static int __init da8xx_probe(struct platform_device *pdev) |
| 489 | { |
| 490 | struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data; |
| 491 | struct platform_device *musb; |
| 492 | |
| 493 | int ret = -ENOMEM; |
| 494 | |
| 495 | musb = platform_device_alloc("musb-hdrc", -1); |
| 496 | if (!musb) { |
| 497 | dev_err(&pdev->dev, "failed to allocate musb device\n"); |
| 498 | goto err0; |
| 499 | } |
| 500 | |
| 501 | musb->dev.parent = &pdev->dev; |
| 502 | musb->dev.dma_mask = &da8xx_dmamask; |
| 503 | musb->dev.coherent_dma_mask = da8xx_dmamask; |
| 504 | |
| 505 | platform_set_drvdata(pdev, musb); |
| 506 | |
| 507 | ret = platform_device_add_resources(musb, pdev->resource, |
| 508 | pdev->num_resources); |
| 509 | if (ret) { |
| 510 | dev_err(&pdev->dev, "failed to add resources\n"); |
| 511 | goto err1; |
| 512 | } |
| 513 | |
| 514 | ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); |
| 515 | if (ret) { |
| 516 | dev_err(&pdev->dev, "failed to add platform_data\n"); |
| 517 | goto err1; |
| 518 | } |
| 519 | |
| 520 | ret = platform_device_add(musb); |
| 521 | if (ret) { |
| 522 | dev_err(&pdev->dev, "failed to register musb device\n"); |
| 523 | goto err1; |
| 524 | } |
| 525 | |
| 526 | return 0; |
| 527 | |
| 528 | err1: |
| 529 | platform_device_put(musb); |
| 530 | |
| 531 | err0: |
| 532 | return ret; |
| 533 | } |
| 534 | |
| 535 | static int __exit da8xx_remove(struct platform_device *pdev) |
| 536 | { |
| 537 | struct platform_device *musb = platform_get_drvdata(pdev); |
| 538 | |
| 539 | platform_device_del(musb); |
| 540 | platform_device_put(musb); |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static struct platform_driver da8xx_driver = { |
| 546 | .remove = __exit_p(da8xx_remove), |
| 547 | .driver = { |
| 548 | .name = "musb-da8xx", |
| 549 | }, |
| 550 | }; |
| 551 | |
| 552 | MODULE_DESCRIPTION("DA8xx/OMAP-L1x MUSB Glue Layer"); |
| 553 | MODULE_AUTHOR("Sergei Shtylyov <sshtylyov@ru.mvista.com>"); |
| 554 | MODULE_LICENSE("GPL v2"); |
| 555 | |
| 556 | static int __init da8xx_init(void) |
| 557 | { |
| 558 | return platform_driver_probe(&da8xx_driver, da8xx_probe); |
| 559 | } |
| 560 | subsys_initcall(da8xx_init); |
| 561 | |
| 562 | static void __exit da8xx_exit(void) |
| 563 | { |
| 564 | platform_driver_unregister(&da8xx_driver); |
| 565 | } |
| 566 | module_exit(da8xx_exit); |