Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 1 | /** |
| 2 | * core.c - DesignWare USB3 DRD Controller Core file |
| 3 | * |
| 4 | * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 5 | * |
| 6 | * Authors: Felipe Balbi <balbi@ti.com>, |
| 7 | * Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| 8 | * |
| 9 | * Redistribution and use in source and binary forms, with or without |
| 10 | * modification, are permitted provided that the following conditions |
| 11 | * are met: |
| 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions, and the following disclaimer, |
| 14 | * without modification. |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in the |
| 17 | * documentation and/or other materials provided with the distribution. |
| 18 | * 3. The names of the above-listed copyright holders may not be used |
| 19 | * to endorse or promote products derived from this software without |
| 20 | * specific prior written permission. |
| 21 | * |
| 22 | * ALTERNATIVELY, this software may be distributed under the terms of the |
| 23 | * GNU General Public License ("GPL") version 2, as published by the Free |
| 24 | * Software Foundation. |
| 25 | * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 27 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 28 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 29 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 30 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 32 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 33 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 36 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 37 | */ |
| 38 | |
Felipe Balbi | a72e658 | 2011-09-05 13:37:28 +0300 | [diff] [blame] | 39 | #include <linux/module.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 40 | #include <linux/kernel.h> |
| 41 | #include <linux/slab.h> |
| 42 | #include <linux/spinlock.h> |
| 43 | #include <linux/platform_device.h> |
| 44 | #include <linux/pm_runtime.h> |
| 45 | #include <linux/interrupt.h> |
| 46 | #include <linux/ioport.h> |
| 47 | #include <linux/io.h> |
| 48 | #include <linux/list.h> |
| 49 | #include <linux/delay.h> |
| 50 | #include <linux/dma-mapping.h> |
Felipe Balbi | 457e84b | 2012-01-18 18:04:09 +0200 | [diff] [blame] | 51 | #include <linux/of.h> |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 52 | |
| 53 | #include <linux/usb/ch9.h> |
| 54 | #include <linux/usb/gadget.h> |
| 55 | |
| 56 | #include "core.h" |
| 57 | #include "gadget.h" |
| 58 | #include "io.h" |
| 59 | |
| 60 | #include "debug.h" |
| 61 | |
Felipe Balbi | 6c167fc | 2011-10-07 22:55:04 +0300 | [diff] [blame] | 62 | static char *maximum_speed = "super"; |
| 63 | module_param(maximum_speed, charp, 0); |
| 64 | MODULE_PARM_DESC(maximum_speed, "Maximum supported speed."); |
| 65 | |
Felipe Balbi | 8300dd2 | 2011-10-18 13:54:01 +0300 | [diff] [blame] | 66 | /* -------------------------------------------------------------------------- */ |
| 67 | |
| 68 | #define DWC3_DEVS_POSSIBLE 32 |
| 69 | |
| 70 | static DECLARE_BITMAP(dwc3_devs, DWC3_DEVS_POSSIBLE); |
| 71 | |
| 72 | int dwc3_get_device_id(void) |
| 73 | { |
| 74 | int id; |
| 75 | |
| 76 | again: |
| 77 | id = find_first_zero_bit(dwc3_devs, DWC3_DEVS_POSSIBLE); |
| 78 | if (id < DWC3_DEVS_POSSIBLE) { |
| 79 | int old; |
| 80 | |
| 81 | old = test_and_set_bit(id, dwc3_devs); |
| 82 | if (old) |
| 83 | goto again; |
| 84 | } else { |
| 85 | pr_err("dwc3: no space for new device\n"); |
| 86 | id = -ENOMEM; |
| 87 | } |
| 88 | |
Dan Carpenter | 075cd14 | 2012-02-04 16:37:14 +0300 | [diff] [blame] | 89 | return id; |
Felipe Balbi | 8300dd2 | 2011-10-18 13:54:01 +0300 | [diff] [blame] | 90 | } |
| 91 | EXPORT_SYMBOL_GPL(dwc3_get_device_id); |
| 92 | |
| 93 | void dwc3_put_device_id(int id) |
| 94 | { |
| 95 | int ret; |
| 96 | |
| 97 | if (id < 0) |
| 98 | return; |
| 99 | |
| 100 | ret = test_bit(id, dwc3_devs); |
| 101 | WARN(!ret, "dwc3: ID %d not in use\n", id); |
Oliver Neukum | 5fdeeb8 | 2012-08-26 21:34:19 +0200 | [diff] [blame] | 102 | smp_mb__before_clear_bit(); |
Felipe Balbi | 8300dd2 | 2011-10-18 13:54:01 +0300 | [diff] [blame] | 103 | clear_bit(id, dwc3_devs); |
| 104 | } |
| 105 | EXPORT_SYMBOL_GPL(dwc3_put_device_id); |
| 106 | |
Sebastian Andrzej Siewior | 3140e8c | 2011-10-31 22:25:40 +0100 | [diff] [blame] | 107 | void dwc3_set_mode(struct dwc3 *dwc, u32 mode) |
| 108 | { |
| 109 | u32 reg; |
| 110 | |
| 111 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
| 112 | reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG)); |
| 113 | reg |= DWC3_GCTL_PRTCAPDIR(mode); |
| 114 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
| 115 | } |
Felipe Balbi | 8300dd2 | 2011-10-18 13:54:01 +0300 | [diff] [blame] | 116 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 117 | /** |
| 118 | * dwc3_core_soft_reset - Issues core soft reset and PHY reset |
| 119 | * @dwc: pointer to our context structure |
| 120 | */ |
| 121 | static void dwc3_core_soft_reset(struct dwc3 *dwc) |
| 122 | { |
| 123 | u32 reg; |
| 124 | |
| 125 | /* Before Resetting PHY, put Core in Reset */ |
| 126 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
| 127 | reg |= DWC3_GCTL_CORESOFTRESET; |
| 128 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
| 129 | |
| 130 | /* Assert USB3 PHY reset */ |
| 131 | reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); |
| 132 | reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST; |
| 133 | dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); |
| 134 | |
| 135 | /* Assert USB2 PHY reset */ |
| 136 | reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); |
| 137 | reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST; |
| 138 | dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); |
| 139 | |
| 140 | mdelay(100); |
| 141 | |
| 142 | /* Clear USB3 PHY reset */ |
| 143 | reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); |
| 144 | reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST; |
| 145 | dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); |
| 146 | |
| 147 | /* Clear USB2 PHY reset */ |
| 148 | reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); |
| 149 | reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST; |
| 150 | dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg); |
| 151 | |
Pratyush Anand | 38a535c | 2012-06-21 17:44:28 +0530 | [diff] [blame] | 152 | mdelay(100); |
| 153 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 154 | /* After PHYs are stable we can take Core out of reset state */ |
| 155 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
| 156 | reg &= ~DWC3_GCTL_CORESOFTRESET; |
| 157 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * dwc3_free_one_event_buffer - Frees one event buffer |
| 162 | * @dwc: Pointer to our controller context structure |
| 163 | * @evt: Pointer to event buffer to be freed |
| 164 | */ |
| 165 | static void dwc3_free_one_event_buffer(struct dwc3 *dwc, |
| 166 | struct dwc3_event_buffer *evt) |
| 167 | { |
| 168 | dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma); |
| 169 | kfree(evt); |
| 170 | } |
| 171 | |
| 172 | /** |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 173 | * dwc3_alloc_one_event_buffer - Allocates one event buffer structure |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 174 | * @dwc: Pointer to our controller context structure |
| 175 | * @length: size of the event buffer |
| 176 | * |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 177 | * Returns a pointer to the allocated event buffer structure on success |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 178 | * otherwise ERR_PTR(errno). |
| 179 | */ |
| 180 | static struct dwc3_event_buffer *__devinit |
| 181 | dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned length) |
| 182 | { |
| 183 | struct dwc3_event_buffer *evt; |
| 184 | |
| 185 | evt = kzalloc(sizeof(*evt), GFP_KERNEL); |
| 186 | if (!evt) |
| 187 | return ERR_PTR(-ENOMEM); |
| 188 | |
| 189 | evt->dwc = dwc; |
| 190 | evt->length = length; |
| 191 | evt->buf = dma_alloc_coherent(dwc->dev, length, |
| 192 | &evt->dma, GFP_KERNEL); |
| 193 | if (!evt->buf) { |
| 194 | kfree(evt); |
| 195 | return ERR_PTR(-ENOMEM); |
| 196 | } |
| 197 | |
| 198 | return evt; |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * dwc3_free_event_buffers - frees all allocated event buffers |
| 203 | * @dwc: Pointer to our controller context structure |
| 204 | */ |
| 205 | static void dwc3_free_event_buffers(struct dwc3 *dwc) |
| 206 | { |
| 207 | struct dwc3_event_buffer *evt; |
| 208 | int i; |
| 209 | |
Felipe Balbi | 9f622b2 | 2011-10-12 10:31:04 +0300 | [diff] [blame] | 210 | for (i = 0; i < dwc->num_event_buffers; i++) { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 211 | evt = dwc->ev_buffs[i]; |
Anton Tikhomirov | 64b6c8a | 2012-03-06 17:05:15 +0900 | [diff] [blame] | 212 | if (evt) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 213 | dwc3_free_one_event_buffer(dwc, evt); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 214 | } |
Anton Tikhomirov | 64b6c8a | 2012-03-06 17:05:15 +0900 | [diff] [blame] | 215 | |
| 216 | kfree(dwc->ev_buffs); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /** |
| 220 | * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 221 | * @dwc: pointer to our controller context structure |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 222 | * @length: size of event buffer |
| 223 | * |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 224 | * Returns 0 on success otherwise negative errno. In the error case, dwc |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 225 | * may contain some buffers allocated but not all which were requested. |
| 226 | */ |
Felipe Balbi | 9f622b2 | 2011-10-12 10:31:04 +0300 | [diff] [blame] | 227 | static int __devinit dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 228 | { |
Felipe Balbi | 9f622b2 | 2011-10-12 10:31:04 +0300 | [diff] [blame] | 229 | int num; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 230 | int i; |
| 231 | |
Felipe Balbi | 9f622b2 | 2011-10-12 10:31:04 +0300 | [diff] [blame] | 232 | num = DWC3_NUM_INT(dwc->hwparams.hwparams1); |
| 233 | dwc->num_event_buffers = num; |
| 234 | |
Felipe Balbi | 457d3f2 | 2011-10-24 12:03:13 +0300 | [diff] [blame] | 235 | dwc->ev_buffs = kzalloc(sizeof(*dwc->ev_buffs) * num, GFP_KERNEL); |
| 236 | if (!dwc->ev_buffs) { |
| 237 | dev_err(dwc->dev, "can't allocate event buffers array\n"); |
| 238 | return -ENOMEM; |
| 239 | } |
| 240 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 241 | for (i = 0; i < num; i++) { |
| 242 | struct dwc3_event_buffer *evt; |
| 243 | |
| 244 | evt = dwc3_alloc_one_event_buffer(dwc, length); |
| 245 | if (IS_ERR(evt)) { |
| 246 | dev_err(dwc->dev, "can't allocate event buffer\n"); |
| 247 | return PTR_ERR(evt); |
| 248 | } |
| 249 | dwc->ev_buffs[i] = evt; |
| 250 | } |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * dwc3_event_buffers_setup - setup our allocated event buffers |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 257 | * @dwc: pointer to our controller context structure |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 258 | * |
| 259 | * Returns 0 on success otherwise negative errno. |
| 260 | */ |
Paul Zimmerman | 43fa01a | 2012-04-27 14:28:02 +0300 | [diff] [blame] | 261 | static int dwc3_event_buffers_setup(struct dwc3 *dwc) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 262 | { |
| 263 | struct dwc3_event_buffer *evt; |
| 264 | int n; |
| 265 | |
Felipe Balbi | 9f622b2 | 2011-10-12 10:31:04 +0300 | [diff] [blame] | 266 | for (n = 0; n < dwc->num_event_buffers; n++) { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 267 | evt = dwc->ev_buffs[n]; |
| 268 | dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n", |
| 269 | evt->buf, (unsigned long long) evt->dma, |
| 270 | evt->length); |
| 271 | |
Paul Zimmerman | 43fa01a | 2012-04-27 14:28:02 +0300 | [diff] [blame] | 272 | evt->lpos = 0; |
| 273 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 274 | dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), |
| 275 | lower_32_bits(evt->dma)); |
| 276 | dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), |
| 277 | upper_32_bits(evt->dma)); |
| 278 | dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), |
| 279 | evt->length & 0xffff); |
| 280 | dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0); |
| 281 | } |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | static void dwc3_event_buffers_cleanup(struct dwc3 *dwc) |
| 287 | { |
| 288 | struct dwc3_event_buffer *evt; |
| 289 | int n; |
| 290 | |
Felipe Balbi | 9f622b2 | 2011-10-12 10:31:04 +0300 | [diff] [blame] | 291 | for (n = 0; n < dwc->num_event_buffers; n++) { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 292 | evt = dwc->ev_buffs[n]; |
Paul Zimmerman | 43fa01a | 2012-04-27 14:28:02 +0300 | [diff] [blame] | 293 | |
| 294 | evt->lpos = 0; |
| 295 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 296 | dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0); |
| 297 | dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0); |
| 298 | dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), 0); |
| 299 | dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0); |
| 300 | } |
| 301 | } |
| 302 | |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 303 | static void dwc3_cache_hwparams(struct dwc3 *dwc) |
Felipe Balbi | 26ceca9 | 2011-09-30 10:58:49 +0300 | [diff] [blame] | 304 | { |
| 305 | struct dwc3_hwparams *parms = &dwc->hwparams; |
| 306 | |
| 307 | parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0); |
| 308 | parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1); |
| 309 | parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2); |
| 310 | parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3); |
| 311 | parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4); |
| 312 | parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5); |
| 313 | parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6); |
| 314 | parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7); |
| 315 | parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8); |
| 316 | } |
| 317 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 318 | /** |
| 319 | * dwc3_core_init - Low-level initialization of DWC3 Core |
| 320 | * @dwc: Pointer to our controller context structure |
| 321 | * |
| 322 | * Returns 0 on success otherwise negative errno. |
| 323 | */ |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 324 | static int dwc3_core_init(struct dwc3 *dwc) |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 325 | { |
| 326 | unsigned long timeout; |
| 327 | u32 reg; |
| 328 | int ret; |
| 329 | |
Sebastian Andrzej Siewior | 7650bd7 | 2011-08-29 13:56:36 +0200 | [diff] [blame] | 330 | reg = dwc3_readl(dwc->regs, DWC3_GSNPSID); |
| 331 | /* This should read as U3 followed by revision number */ |
| 332 | if ((reg & DWC3_GSNPSID_MASK) != 0x55330000) { |
| 333 | dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n"); |
| 334 | ret = -ENODEV; |
| 335 | goto err0; |
| 336 | } |
Felipe Balbi | 248b122 | 2011-12-14 21:59:30 +0200 | [diff] [blame] | 337 | dwc->revision = reg; |
Sebastian Andrzej Siewior | 7650bd7 | 2011-08-29 13:56:36 +0200 | [diff] [blame] | 338 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 339 | /* issue device SoftReset too */ |
| 340 | timeout = jiffies + msecs_to_jiffies(500); |
| 341 | dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); |
| 342 | do { |
| 343 | reg = dwc3_readl(dwc->regs, DWC3_DCTL); |
| 344 | if (!(reg & DWC3_DCTL_CSFTRST)) |
| 345 | break; |
| 346 | |
| 347 | if (time_after(jiffies, timeout)) { |
| 348 | dev_err(dwc->dev, "Reset Timed Out\n"); |
| 349 | ret = -ETIMEDOUT; |
| 350 | goto err0; |
| 351 | } |
| 352 | |
| 353 | cpu_relax(); |
| 354 | } while (true); |
| 355 | |
Pratyush Anand | 99d4da8 | 2012-06-21 17:44:29 +0530 | [diff] [blame] | 356 | dwc3_core_soft_reset(dwc); |
| 357 | |
Felipe Balbi | 9f622b2 | 2011-10-12 10:31:04 +0300 | [diff] [blame] | 358 | dwc3_cache_hwparams(dwc); |
| 359 | |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 360 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
Paul Zimmerman | 3e87c42 | 2012-02-24 17:32:13 -0800 | [diff] [blame] | 361 | reg &= ~DWC3_GCTL_SCALEDOWN_MASK; |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 362 | reg &= ~DWC3_GCTL_DISSCRAMBLE; |
| 363 | |
Sebastian Andrzej Siewior | 164d773 | 2011-11-24 11:22:05 +0100 | [diff] [blame] | 364 | switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) { |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 365 | case DWC3_GHWPARAMS1_EN_PWROPT_CLK: |
| 366 | reg &= ~DWC3_GCTL_DSBLCLKGTNG; |
| 367 | break; |
| 368 | default: |
| 369 | dev_dbg(dwc->dev, "No power optimization available\n"); |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * WORKAROUND: DWC3 revisions <1.90a have a bug |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 374 | * where the device can fail to connect at SuperSpeed |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 375 | * and falls back to high-speed mode which causes |
Paul Zimmerman | 1d04679 | 2012-02-15 18:56:56 -0800 | [diff] [blame] | 376 | * the device to enter a Connect/Disconnect loop |
Sebastian Andrzej Siewior | 4878a02 | 2011-10-31 22:25:41 +0100 | [diff] [blame] | 377 | */ |
| 378 | if (dwc->revision < DWC3_REVISION_190A) |
| 379 | reg |= DWC3_GCTL_U2RSTECN; |
| 380 | |
| 381 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
| 382 | |
Pavankumar Kondeti | fe2c063 | 2012-06-12 15:21:13 +0530 | [diff] [blame] | 383 | /* |
Pavankumar Kondeti | c6e15aa | 2012-07-16 11:37:15 +0530 | [diff] [blame] | 384 | * The default value of GUCTL[31:22] should be 0x8. But on cores |
| 385 | * revision < 2.30a, the default value is mistakenly overridden |
| 386 | * with 0x0. Restore the correct default value. |
| 387 | */ |
| 388 | if (dwc->revision < DWC3_REVISION_230A) { |
| 389 | reg = dwc3_readl(dwc->regs, DWC3_GUCTL); |
| 390 | reg &= ~DWC3_GUCTL_REFCLKPER; |
| 391 | reg |= 0x8 << __ffs(DWC3_GUCTL_REFCLKPER); |
| 392 | dwc3_writel(dwc->regs, DWC3_GUCTL, reg); |
| 393 | } |
| 394 | /* |
Pavankumar Kondeti | fe2c063 | 2012-06-12 15:21:13 +0530 | [diff] [blame] | 395 | * Currently, the default and the recommended value for GUSB3PIPECTL |
| 396 | * [21:19] in the RTL is 3'b100 or 32 consecutive errors. Based on |
| 397 | * analysis and experiments in the lab, it is found that there is a |
| 398 | * relatively low probability of getting 32 consecutive word errors |
| 399 | * in the presence of random recovered noise (during electrical idle). |
| 400 | * This can delay the entry to a low power state such that for |
| 401 | * applications where the link stays in a non-U0 state for a short |
| 402 | * duration (< 1 microsecond), the local PHY does not enter the low |
| 403 | * power state prior to receiving a potential LFPS wakeup. This causes |
| 404 | * the PHY CDR (Clock and Data Recovery) operation to be unstable for |
| 405 | * some Synopsys PHYs. |
| 406 | * |
| 407 | * The proposal now is to change the default and the recommended value |
| 408 | * for GUSB3PIPECTL[21:19] in the RTL from 3'b100 to a minimum of |
| 409 | * 3'b001. Perform the same in software for controllers prior to 2.30a |
| 410 | * revision. |
| 411 | */ |
| 412 | |
| 413 | if (dwc->revision < DWC3_REVISION_230A) { |
| 414 | reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0)); |
| 415 | reg &= ~DWC3_GUSB3PIPECTL_DELAY_P1P2P3; |
| 416 | reg |= 1 << __ffs(DWC3_GUSB3PIPECTL_DELAY_P1P2P3); |
Pavankumar Kondeti | 5acb4ba | 2012-07-16 11:44:46 +0530 | [diff] [blame] | 417 | /* |
| 418 | * Receiver Detection in U3/Rx.Det is mistakenly disabled in |
| 419 | * cores < 2.30a. Fix it here. |
| 420 | */ |
| 421 | reg &= ~DWC3_GUSB3PIPECTL_DIS_RXDET_U3_RXDET; |
Pavankumar Kondeti | fe2c063 | 2012-06-12 15:21:13 +0530 | [diff] [blame] | 422 | dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg); |
| 423 | } |
| 424 | |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 425 | if (!dwc->ev_buffs) { |
| 426 | ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); |
| 427 | if (ret) { |
| 428 | dev_err(dwc->dev, "failed to allocate event buffers\n"); |
| 429 | ret = -ENOMEM; |
| 430 | goto err1; |
| 431 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | ret = dwc3_event_buffers_setup(dwc); |
| 435 | if (ret) { |
| 436 | dev_err(dwc->dev, "failed to setup event buffers\n"); |
| 437 | goto err1; |
| 438 | } |
| 439 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 440 | return 0; |
| 441 | |
| 442 | err1: |
| 443 | dwc3_free_event_buffers(dwc); |
| 444 | |
| 445 | err0: |
| 446 | return ret; |
| 447 | } |
| 448 | |
| 449 | static void dwc3_core_exit(struct dwc3 *dwc) |
| 450 | { |
| 451 | dwc3_event_buffers_cleanup(dwc); |
| 452 | dwc3_free_event_buffers(dwc); |
| 453 | } |
| 454 | |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 455 | /* XHCI reset, resets other CORE registers as well, re-init those */ |
| 456 | void dwc3_post_host_reset_core_init(struct dwc3 *dwc) |
| 457 | { |
| 458 | dwc3_core_init(dwc); |
| 459 | dwc3_gadget_restart(dwc); |
| 460 | } |
| 461 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 462 | #define DWC3_ALIGN_MASK (16 - 1) |
| 463 | |
| 464 | static int __devinit dwc3_probe(struct platform_device *pdev) |
| 465 | { |
Felipe Balbi | 457e84b | 2012-01-18 18:04:09 +0200 | [diff] [blame] | 466 | struct device_node *node = pdev->dev.of_node; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 467 | struct resource *res; |
| 468 | struct dwc3 *dwc; |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 469 | struct device *dev = &pdev->dev; |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 470 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 471 | int ret = -ENOMEM; |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 472 | |
| 473 | void __iomem *regs; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 474 | void *mem; |
| 475 | |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 476 | u8 mode; |
| 477 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 478 | mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 479 | if (!mem) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 480 | dev_err(dev, "not enough memory\n"); |
| 481 | return -ENOMEM; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 482 | } |
| 483 | dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); |
| 484 | dwc->mem = mem; |
| 485 | |
Ido Shayevitz | 4a18733 | 2012-04-23 14:53:37 +0200 | [diff] [blame] | 486 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 487 | if (!res) { |
Ido Shayevitz | 4a18733 | 2012-04-23 14:53:37 +0200 | [diff] [blame] | 488 | dev_err(dev, "missing IRQ\n"); |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 489 | return -ENODEV; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 490 | } |
Kishon Vijay Abraham I | 2f8ae02 | 2012-08-21 14:56:16 +0530 | [diff] [blame] | 491 | dwc->xhci_resources[1].start = res->start; |
| 492 | dwc->xhci_resources[1].end = res->end; |
| 493 | dwc->xhci_resources[1].flags = res->flags; |
| 494 | dwc->xhci_resources[1].name = res->name; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 495 | |
Ido Shayevitz | 4a18733 | 2012-04-23 14:53:37 +0200 | [diff] [blame] | 496 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 497 | if (!res) { |
| 498 | dev_err(dev, "missing memory resource\n"); |
| 499 | return -ENODEV; |
| 500 | } |
Kishon Vijay Abraham I | 2f8ae02 | 2012-08-21 14:56:16 +0530 | [diff] [blame] | 501 | dwc->xhci_resources[0].start = res->start; |
Ido Shayevitz | 4a18733 | 2012-04-23 14:53:37 +0200 | [diff] [blame] | 502 | dwc->xhci_resources[0].end = dwc->xhci_resources[0].start + |
| 503 | DWC3_XHCI_REGS_END; |
Kishon Vijay Abraham I | 2f8ae02 | 2012-08-21 14:56:16 +0530 | [diff] [blame] | 504 | dwc->xhci_resources[0].flags = res->flags; |
| 505 | dwc->xhci_resources[0].name = res->name; |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 506 | |
Ido Shayevitz | 4a18733 | 2012-04-23 14:53:37 +0200 | [diff] [blame] | 507 | /* |
| 508 | * Request memory region but exclude xHCI regs, |
| 509 | * since it will be requested by the xhci-plat driver. |
| 510 | */ |
| 511 | res = devm_request_mem_region(dev, res->start + DWC3_GLOBALS_REGS_START, |
| 512 | resource_size(res) - DWC3_GLOBALS_REGS_START, |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 513 | dev_name(dev)); |
Ido Shayevitz | 4a18733 | 2012-04-23 14:53:37 +0200 | [diff] [blame] | 514 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 515 | if (!res) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 516 | dev_err(dev, "can't request mem region\n"); |
| 517 | return -ENOMEM; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 518 | } |
| 519 | |
Felipe Balbi | 497a2a3 | 2012-08-10 09:16:43 +0300 | [diff] [blame] | 520 | regs = devm_ioremap_nocache(dev, res->start, resource_size(res)); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 521 | if (!regs) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 522 | dev_err(dev, "ioremap failed\n"); |
| 523 | return -ENOMEM; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 524 | } |
| 525 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 526 | spin_lock_init(&dwc->lock); |
| 527 | platform_set_drvdata(pdev, dwc); |
| 528 | |
| 529 | dwc->regs = regs; |
| 530 | dwc->regs_size = resource_size(res); |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 531 | dwc->dev = dev; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 532 | |
Felipe Balbi | 6c167fc | 2011-10-07 22:55:04 +0300 | [diff] [blame] | 533 | if (!strncmp("super", maximum_speed, 5)) |
| 534 | dwc->maximum_speed = DWC3_DCFG_SUPERSPEED; |
| 535 | else if (!strncmp("high", maximum_speed, 4)) |
| 536 | dwc->maximum_speed = DWC3_DCFG_HIGHSPEED; |
| 537 | else if (!strncmp("full", maximum_speed, 4)) |
| 538 | dwc->maximum_speed = DWC3_DCFG_FULLSPEED1; |
| 539 | else if (!strncmp("low", maximum_speed, 3)) |
| 540 | dwc->maximum_speed = DWC3_DCFG_LOWSPEED; |
| 541 | else |
| 542 | dwc->maximum_speed = DWC3_DCFG_SUPERSPEED; |
| 543 | |
Felipe Balbi | 457e84b | 2012-01-18 18:04:09 +0200 | [diff] [blame] | 544 | if (of_get_property(node, "tx-fifo-resize", NULL)) |
| 545 | dwc->needs_fifo_resize = true; |
| 546 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 547 | pm_runtime_no_callbacks(dev); |
| 548 | pm_runtime_set_active(dev); |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 549 | pm_runtime_enable(dev); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 550 | |
| 551 | ret = dwc3_core_init(dwc); |
| 552 | if (ret) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 553 | dev_err(dev, "failed to initialize core\n"); |
| 554 | return ret; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 555 | } |
| 556 | |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 557 | mode = DWC3_MODE(dwc->hwparams.hwparams0); |
| 558 | |
| 559 | switch (mode) { |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 560 | case DWC3_MODE_DEVICE: |
Sebastian Andrzej Siewior | 3140e8c | 2011-10-31 22:25:40 +0100 | [diff] [blame] | 561 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 562 | ret = dwc3_gadget_init(dwc); |
| 563 | if (ret) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 564 | dev_err(dev, "failed to initialize gadget\n"); |
| 565 | goto err1; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 566 | } |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 567 | break; |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 568 | case DWC3_MODE_HOST: |
Sebastian Andrzej Siewior | 3140e8c | 2011-10-31 22:25:40 +0100 | [diff] [blame] | 569 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 570 | ret = dwc3_host_init(dwc); |
| 571 | if (ret) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 572 | dev_err(dev, "failed to initialize host\n"); |
| 573 | goto err1; |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 574 | } |
| 575 | break; |
| 576 | case DWC3_MODE_DRD: |
Sebastian Andrzej Siewior | 3140e8c | 2011-10-31 22:25:40 +0100 | [diff] [blame] | 577 | dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); |
Ido Shayevitz | cdeef4c | 2012-05-29 13:17:41 +0200 | [diff] [blame] | 578 | ret = dwc3_otg_init(dwc); |
| 579 | if (ret) { |
| 580 | dev_err(dev, "failed to initialize otg\n"); |
| 581 | goto err1; |
| 582 | } |
| 583 | |
Manu Gautam | f1fceddf | 2012-10-12 14:02:50 +0530 | [diff] [blame] | 584 | ret = dwc3_host_init(dwc); |
| 585 | if (ret) { |
| 586 | dev_err(dev, "failed to initialize host\n"); |
| 587 | dwc3_otg_exit(dwc); |
| 588 | goto err1; |
| 589 | } |
| 590 | |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 591 | ret = dwc3_gadget_init(dwc); |
| 592 | if (ret) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 593 | dev_err(dev, "failed to initialize gadget\n"); |
Ido Shayevitz | cdeef4c | 2012-05-29 13:17:41 +0200 | [diff] [blame] | 594 | dwc3_host_exit(dwc); |
| 595 | dwc3_otg_exit(dwc); |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 596 | goto err1; |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 597 | } |
| 598 | break; |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 599 | default: |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 600 | dev_err(dev, "Unsupported mode of operation %d\n", mode); |
| 601 | goto err1; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 602 | } |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 603 | dwc->mode = mode; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 604 | |
| 605 | ret = dwc3_debugfs_init(dwc); |
| 606 | if (ret) { |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 607 | dev_err(dev, "failed to initialize debugfs\n"); |
| 608 | goto err2; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 609 | } |
| 610 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 611 | return 0; |
| 612 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 613 | err2: |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 614 | switch (mode) { |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 615 | case DWC3_MODE_DEVICE: |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 616 | dwc3_gadget_exit(dwc); |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 617 | break; |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 618 | case DWC3_MODE_HOST: |
| 619 | dwc3_host_exit(dwc); |
| 620 | break; |
| 621 | case DWC3_MODE_DRD: |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 622 | dwc3_gadget_exit(dwc); |
Ido Shayevitz | cdeef4c | 2012-05-29 13:17:41 +0200 | [diff] [blame] | 623 | dwc3_host_exit(dwc); |
| 624 | dwc3_otg_exit(dwc); |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 625 | break; |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 626 | default: |
| 627 | /* do nothing */ |
| 628 | break; |
| 629 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 630 | |
Chanho Park | 802ca85 | 2012-02-15 18:27:55 +0900 | [diff] [blame] | 631 | err1: |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 632 | dwc3_core_exit(dwc); |
| 633 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 634 | return ret; |
| 635 | } |
| 636 | |
| 637 | static int __devexit dwc3_remove(struct platform_device *pdev) |
| 638 | { |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 639 | struct dwc3 *dwc = platform_get_drvdata(pdev); |
| 640 | struct resource *res; |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 641 | |
| 642 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 643 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 644 | pm_runtime_disable(&pdev->dev); |
| 645 | |
| 646 | dwc3_debugfs_exit(dwc); |
| 647 | |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 648 | switch (dwc->mode) { |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 649 | case DWC3_MODE_DEVICE: |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 650 | dwc3_gadget_exit(dwc); |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 651 | break; |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 652 | case DWC3_MODE_HOST: |
| 653 | dwc3_host_exit(dwc); |
| 654 | break; |
| 655 | case DWC3_MODE_DRD: |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 656 | dwc3_gadget_exit(dwc); |
Ido Shayevitz | cdeef4c | 2012-05-29 13:17:41 +0200 | [diff] [blame] | 657 | dwc3_host_exit(dwc); |
| 658 | dwc3_otg_exit(dwc); |
Felipe Balbi | d07e881 | 2011-10-12 14:08:26 +0300 | [diff] [blame] | 659 | break; |
Felipe Balbi | 0949e99 | 2011-10-12 10:44:56 +0300 | [diff] [blame] | 660 | default: |
| 661 | /* do nothing */ |
| 662 | break; |
| 663 | } |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 664 | |
| 665 | dwc3_core_exit(dwc); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 666 | |
| 667 | return 0; |
| 668 | } |
| 669 | |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 670 | static struct platform_driver dwc3_driver = { |
| 671 | .probe = dwc3_probe, |
| 672 | .remove = __devexit_p(dwc3_remove), |
| 673 | .driver = { |
| 674 | .name = "dwc3", |
| 675 | }, |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 676 | }; |
| 677 | |
Tobias Klauser | b1116dc | 2012-02-28 12:57:20 +0100 | [diff] [blame] | 678 | module_platform_driver(dwc3_driver); |
| 679 | |
Sebastian Andrzej Siewior | 7ae4fc4 | 2011-10-19 19:39:50 +0200 | [diff] [blame] | 680 | MODULE_ALIAS("platform:dwc3"); |
Felipe Balbi | 72246da | 2011-08-19 18:10:58 +0300 | [diff] [blame] | 681 | MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>"); |
| 682 | MODULE_LICENSE("Dual BSD/GPL"); |
| 683 | MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver"); |