blob: b0f4d52b7f04a023b6d743c686a54eace4797047 [file] [log] [blame]
Felipe Balbi72246da2011-08-19 18:10:58 +03001/**
2 * core.c - DesignWare USB3 DRD Controller Core file
3 *
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com
Felipe Balbi72246da2011-08-19 18:10:58 +03005 *
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
8 *
Felipe Balbi5945f782013-06-30 14:15:11 +03009 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 of
11 * the License as published by the Free Software Foundation.
Felipe Balbi72246da2011-08-19 18:10:58 +030012 *
Felipe Balbi5945f782013-06-30 14:15:11 +030013 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Felipe Balbi72246da2011-08-19 18:10:58 +030017 *
Felipe Balbi5945f782013-06-30 14:15:11 +030018 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Felipe Balbi72246da2011-08-19 18:10:58 +030020 */
21
Felipe Balbia72e6582011-09-05 13:37:28 +030022#include <linux/module.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030023#include <linux/kernel.h>
24#include <linux/slab.h>
25#include <linux/spinlock.h>
26#include <linux/platform_device.h>
27#include <linux/pm_runtime.h>
28#include <linux/interrupt.h>
29#include <linux/ioport.h>
30#include <linux/io.h>
31#include <linux/list.h>
32#include <linux/delay.h>
33#include <linux/dma-mapping.h>
Felipe Balbi457e84b2012-01-18 18:04:09 +020034#include <linux/of.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030035
36#include <linux/usb/ch9.h>
37#include <linux/usb/gadget.h>
Felipe Balbif7e846f2013-06-30 14:29:51 +030038#include <linux/usb/of.h>
Ruchika Kharwara45c82b82013-07-06 07:52:49 -050039#include <linux/usb/otg.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030040
Felipe Balbi6462cbd2013-06-30 14:19:33 +030041#include "platform_data.h"
Felipe Balbi72246da2011-08-19 18:10:58 +030042#include "core.h"
43#include "gadget.h"
44#include "io.h"
45
46#include "debug.h"
47
Felipe Balbi8300dd22011-10-18 13:54:01 +030048/* -------------------------------------------------------------------------- */
49
Sebastian Andrzej Siewior3140e8c2011-10-31 22:25:40 +010050void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
51{
52 u32 reg;
53
54 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
55 reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
56 reg |= DWC3_GCTL_PRTCAPDIR(mode);
57 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
58}
Felipe Balbi8300dd22011-10-18 13:54:01 +030059
Felipe Balbi72246da2011-08-19 18:10:58 +030060/**
61 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
62 * @dwc: pointer to our context structure
63 */
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +053064static int dwc3_core_soft_reset(struct dwc3 *dwc)
Felipe Balbi72246da2011-08-19 18:10:58 +030065{
66 u32 reg;
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +053067 int ret;
Felipe Balbi72246da2011-08-19 18:10:58 +030068
69 /* Before Resetting PHY, put Core in Reset */
70 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
71 reg |= DWC3_GCTL_CORESOFTRESET;
72 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
73
74 /* Assert USB3 PHY reset */
75 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
76 reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
77 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
78
79 /* Assert USB2 PHY reset */
80 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
81 reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
82 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
83
Felipe Balbi51e1e7b2012-07-19 14:09:48 +030084 usb_phy_init(dwc->usb2_phy);
85 usb_phy_init(dwc->usb3_phy);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +053086 ret = phy_init(dwc->usb2_generic_phy);
87 if (ret < 0)
88 return ret;
89
90 ret = phy_init(dwc->usb3_generic_phy);
91 if (ret < 0) {
92 phy_exit(dwc->usb2_generic_phy);
93 return ret;
94 }
Felipe Balbi72246da2011-08-19 18:10:58 +030095 mdelay(100);
96
97 /* Clear USB3 PHY reset */
98 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
99 reg &= ~DWC3_GUSB3PIPECTL_PHYSOFTRST;
100 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
101
102 /* Clear USB2 PHY reset */
103 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
104 reg &= ~DWC3_GUSB2PHYCFG_PHYSOFTRST;
105 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
106
Pratyush Anand45627ac2012-06-21 17:44:28 +0530107 mdelay(100);
108
Felipe Balbi72246da2011-08-19 18:10:58 +0300109 /* After PHYs are stable we can take Core out of reset state */
110 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
111 reg &= ~DWC3_GCTL_CORESOFTRESET;
112 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530113
114 return 0;
Felipe Balbi72246da2011-08-19 18:10:58 +0300115}
116
117/**
118 * dwc3_free_one_event_buffer - Frees one event buffer
119 * @dwc: Pointer to our controller context structure
120 * @evt: Pointer to event buffer to be freed
121 */
122static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
123 struct dwc3_event_buffer *evt)
124{
125 dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
Felipe Balbi72246da2011-08-19 18:10:58 +0300126}
127
128/**
Paul Zimmerman1d046792012-02-15 18:56:56 -0800129 * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
Felipe Balbi72246da2011-08-19 18:10:58 +0300130 * @dwc: Pointer to our controller context structure
131 * @length: size of the event buffer
132 *
Paul Zimmerman1d046792012-02-15 18:56:56 -0800133 * Returns a pointer to the allocated event buffer structure on success
Felipe Balbi72246da2011-08-19 18:10:58 +0300134 * otherwise ERR_PTR(errno).
135 */
Felipe Balbi67d0b502013-02-22 16:31:07 +0200136static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
137 unsigned length)
Felipe Balbi72246da2011-08-19 18:10:58 +0300138{
139 struct dwc3_event_buffer *evt;
140
Felipe Balbi380f0d22012-10-11 13:48:36 +0300141 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL);
Felipe Balbi72246da2011-08-19 18:10:58 +0300142 if (!evt)
143 return ERR_PTR(-ENOMEM);
144
145 evt->dwc = dwc;
146 evt->length = length;
147 evt->buf = dma_alloc_coherent(dwc->dev, length,
148 &evt->dma, GFP_KERNEL);
Felipe Balbie32672f2012-11-08 15:26:41 +0200149 if (!evt->buf)
Felipe Balbi72246da2011-08-19 18:10:58 +0300150 return ERR_PTR(-ENOMEM);
Felipe Balbi72246da2011-08-19 18:10:58 +0300151
152 return evt;
153}
154
155/**
156 * dwc3_free_event_buffers - frees all allocated event buffers
157 * @dwc: Pointer to our controller context structure
158 */
159static void dwc3_free_event_buffers(struct dwc3 *dwc)
160{
161 struct dwc3_event_buffer *evt;
162 int i;
163
Felipe Balbi9f622b22011-10-12 10:31:04 +0300164 for (i = 0; i < dwc->num_event_buffers; i++) {
Felipe Balbi72246da2011-08-19 18:10:58 +0300165 evt = dwc->ev_buffs[i];
Anton Tikhomirov64b6c8a2012-03-06 17:05:15 +0900166 if (evt)
Felipe Balbi72246da2011-08-19 18:10:58 +0300167 dwc3_free_one_event_buffer(dwc, evt);
Felipe Balbi72246da2011-08-19 18:10:58 +0300168 }
169}
170
171/**
172 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
Paul Zimmerman1d046792012-02-15 18:56:56 -0800173 * @dwc: pointer to our controller context structure
Felipe Balbi72246da2011-08-19 18:10:58 +0300174 * @length: size of event buffer
175 *
Paul Zimmerman1d046792012-02-15 18:56:56 -0800176 * Returns 0 on success otherwise negative errno. In the error case, dwc
Felipe Balbi72246da2011-08-19 18:10:58 +0300177 * may contain some buffers allocated but not all which were requested.
178 */
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500179static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
Felipe Balbi72246da2011-08-19 18:10:58 +0300180{
Felipe Balbi9f622b22011-10-12 10:31:04 +0300181 int num;
Felipe Balbi72246da2011-08-19 18:10:58 +0300182 int i;
183
Felipe Balbi9f622b22011-10-12 10:31:04 +0300184 num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
185 dwc->num_event_buffers = num;
186
Felipe Balbi380f0d22012-10-11 13:48:36 +0300187 dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num,
188 GFP_KERNEL);
Jingoo Han734d5a52014-07-17 12:45:11 +0900189 if (!dwc->ev_buffs)
Felipe Balbi457d3f22011-10-24 12:03:13 +0300190 return -ENOMEM;
Felipe Balbi457d3f22011-10-24 12:03:13 +0300191
Felipe Balbi72246da2011-08-19 18:10:58 +0300192 for (i = 0; i < num; i++) {
193 struct dwc3_event_buffer *evt;
194
195 evt = dwc3_alloc_one_event_buffer(dwc, length);
196 if (IS_ERR(evt)) {
197 dev_err(dwc->dev, "can't allocate event buffer\n");
198 return PTR_ERR(evt);
199 }
200 dwc->ev_buffs[i] = evt;
201 }
202
203 return 0;
204}
205
206/**
207 * dwc3_event_buffers_setup - setup our allocated event buffers
Paul Zimmerman1d046792012-02-15 18:56:56 -0800208 * @dwc: pointer to our controller context structure
Felipe Balbi72246da2011-08-19 18:10:58 +0300209 *
210 * Returns 0 on success otherwise negative errno.
211 */
Paul Zimmerman7acd85e2012-04-27 14:28:02 +0300212static int dwc3_event_buffers_setup(struct dwc3 *dwc)
Felipe Balbi72246da2011-08-19 18:10:58 +0300213{
214 struct dwc3_event_buffer *evt;
215 int n;
216
Felipe Balbi9f622b22011-10-12 10:31:04 +0300217 for (n = 0; n < dwc->num_event_buffers; n++) {
Felipe Balbi72246da2011-08-19 18:10:58 +0300218 evt = dwc->ev_buffs[n];
219 dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n",
220 evt->buf, (unsigned long long) evt->dma,
221 evt->length);
222
Paul Zimmerman7acd85e2012-04-27 14:28:02 +0300223 evt->lpos = 0;
224
Felipe Balbi72246da2011-08-19 18:10:58 +0300225 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n),
226 lower_32_bits(evt->dma));
227 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
228 upper_32_bits(evt->dma));
229 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n),
Felipe Balbi68d6a012013-06-12 21:09:26 +0300230 DWC3_GEVNTSIZ_SIZE(evt->length));
Felipe Balbi72246da2011-08-19 18:10:58 +0300231 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
232 }
233
234 return 0;
235}
236
237static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
238{
239 struct dwc3_event_buffer *evt;
240 int n;
241
Felipe Balbi9f622b22011-10-12 10:31:04 +0300242 for (n = 0; n < dwc->num_event_buffers; n++) {
Felipe Balbi72246da2011-08-19 18:10:58 +0300243 evt = dwc->ev_buffs[n];
Paul Zimmerman7acd85e2012-04-27 14:28:02 +0300244
245 evt->lpos = 0;
246
Felipe Balbi72246da2011-08-19 18:10:58 +0300247 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
248 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
Felipe Balbi68d6a012013-06-12 21:09:26 +0300249 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), DWC3_GEVNTSIZ_INTMASK
250 | DWC3_GEVNTSIZ_SIZE(0));
Felipe Balbi72246da2011-08-19 18:10:58 +0300251 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
252 }
253}
254
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600255static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
256{
257 if (!dwc->has_hibernation)
258 return 0;
259
260 if (!dwc->nr_scratch)
261 return 0;
262
263 dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
264 DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
265 if (!dwc->scratchbuf)
266 return -ENOMEM;
267
268 return 0;
269}
270
271static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
272{
273 dma_addr_t scratch_addr;
274 u32 param;
275 int ret;
276
277 if (!dwc->has_hibernation)
278 return 0;
279
280 if (!dwc->nr_scratch)
281 return 0;
282
283 /* should never fall here */
284 if (!WARN_ON(dwc->scratchbuf))
285 return 0;
286
287 scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
288 dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
289 DMA_BIDIRECTIONAL);
290 if (dma_mapping_error(dwc->dev, scratch_addr)) {
291 dev_err(dwc->dev, "failed to map scratch buffer\n");
292 ret = -EFAULT;
293 goto err0;
294 }
295
296 dwc->scratch_addr = scratch_addr;
297
298 param = lower_32_bits(scratch_addr);
299
300 ret = dwc3_send_gadget_generic_command(dwc,
301 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param);
302 if (ret < 0)
303 goto err1;
304
305 param = upper_32_bits(scratch_addr);
306
307 ret = dwc3_send_gadget_generic_command(dwc,
308 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param);
309 if (ret < 0)
310 goto err1;
311
312 return 0;
313
314err1:
315 dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
316 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
317
318err0:
319 return ret;
320}
321
322static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
323{
324 if (!dwc->has_hibernation)
325 return;
326
327 if (!dwc->nr_scratch)
328 return;
329
330 /* should never fall here */
331 if (!WARN_ON(dwc->scratchbuf))
332 return;
333
334 dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
335 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
336 kfree(dwc->scratchbuf);
337}
338
Felipe Balbi789451f62011-05-05 15:53:10 +0300339static void dwc3_core_num_eps(struct dwc3 *dwc)
340{
341 struct dwc3_hwparams *parms = &dwc->hwparams;
342
343 dwc->num_in_eps = DWC3_NUM_IN_EPS(parms);
344 dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps;
345
346 dev_vdbg(dwc->dev, "found %d IN and %d OUT endpoints\n",
347 dwc->num_in_eps, dwc->num_out_eps);
348}
349
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500350static void dwc3_cache_hwparams(struct dwc3 *dwc)
Felipe Balbi26ceca92011-09-30 10:58:49 +0300351{
352 struct dwc3_hwparams *parms = &dwc->hwparams;
353
354 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0);
355 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1);
356 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2);
357 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
358 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4);
359 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5);
360 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
361 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
362 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
363}
364
Felipe Balbi72246da2011-08-19 18:10:58 +0300365/**
366 * dwc3_core_init - Low-level initialization of DWC3 Core
367 * @dwc: Pointer to our controller context structure
368 *
369 * Returns 0 on success otherwise negative errno.
370 */
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500371static int dwc3_core_init(struct dwc3 *dwc)
Felipe Balbi72246da2011-08-19 18:10:58 +0300372{
373 unsigned long timeout;
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600374 u32 hwparams4 = dwc->hwparams.hwparams4;
Felipe Balbi72246da2011-08-19 18:10:58 +0300375 u32 reg;
376 int ret;
377
Sebastian Andrzej Siewior7650bd72011-08-29 13:56:36 +0200378 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
379 /* This should read as U3 followed by revision number */
380 if ((reg & DWC3_GSNPSID_MASK) != 0x55330000) {
381 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
382 ret = -ENODEV;
383 goto err0;
384 }
Felipe Balbi248b1222011-12-14 21:59:30 +0200385 dwc->revision = reg;
Sebastian Andrzej Siewior7650bd72011-08-29 13:56:36 +0200386
Paul Zimmerman0e1e5c42014-05-23 11:39:24 -0700387 /* Handle USB2.0-only core configuration */
388 if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
389 DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
390 if (dwc->maximum_speed == USB_SPEED_SUPER)
391 dwc->maximum_speed = USB_SPEED_HIGH;
392 }
393
Felipe Balbi72246da2011-08-19 18:10:58 +0300394 /* issue device SoftReset too */
395 timeout = jiffies + msecs_to_jiffies(500);
396 dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
397 do {
398 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
399 if (!(reg & DWC3_DCTL_CSFTRST))
400 break;
401
402 if (time_after(jiffies, timeout)) {
403 dev_err(dwc->dev, "Reset Timed Out\n");
404 ret = -ETIMEDOUT;
405 goto err0;
406 }
407
408 cpu_relax();
409 } while (true);
410
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530411 ret = dwc3_core_soft_reset(dwc);
412 if (ret)
413 goto err0;
Pratyush Anand58a0f232012-06-21 17:44:29 +0530414
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100415 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
Paul Zimmerman3e87c422012-02-24 17:32:13 -0800416 reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100417 reg &= ~DWC3_GCTL_DISSCRAMBLE;
418
Sebastian Andrzej Siewior164d7732011-11-24 11:22:05 +0100419 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100420 case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
Felipe Balbi32a4a132014-02-25 14:00:13 -0600421 /**
422 * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an
423 * issue which would cause xHCI compliance tests to fail.
424 *
425 * Because of that we cannot enable clock gating on such
426 * configurations.
427 *
428 * Refers to:
429 *
430 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based
431 * SOF/ITP Mode Used
432 */
433 if ((dwc->dr_mode == USB_DR_MODE_HOST ||
434 dwc->dr_mode == USB_DR_MODE_OTG) &&
435 (dwc->revision >= DWC3_REVISION_210A &&
436 dwc->revision <= DWC3_REVISION_250A))
437 reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC;
438 else
439 reg &= ~DWC3_GCTL_DSBLCLKGTNG;
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100440 break;
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600441 case DWC3_GHWPARAMS1_EN_PWROPT_HIB:
442 /* enable hibernation here */
443 dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4);
444 break;
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100445 default:
446 dev_dbg(dwc->dev, "No power optimization available\n");
447 }
448
449 /*
450 * WORKAROUND: DWC3 revisions <1.90a have a bug
Paul Zimmerman1d046792012-02-15 18:56:56 -0800451 * where the device can fail to connect at SuperSpeed
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100452 * and falls back to high-speed mode which causes
Paul Zimmerman1d046792012-02-15 18:56:56 -0800453 * the device to enter a Connect/Disconnect loop
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100454 */
455 if (dwc->revision < DWC3_REVISION_190A)
456 reg |= DWC3_GCTL_U2RSTECN;
457
Felipe Balbi789451f62011-05-05 15:53:10 +0300458 dwc3_core_num_eps(dwc);
459
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100460 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
461
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600462 ret = dwc3_alloc_scratch_buffers(dwc);
463 if (ret)
464 goto err1;
465
466 ret = dwc3_setup_scratch_buffers(dwc);
467 if (ret)
468 goto err2;
469
Felipe Balbi72246da2011-08-19 18:10:58 +0300470 return 0;
471
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600472err2:
473 dwc3_free_scratch_buffers(dwc);
474
475err1:
476 usb_phy_shutdown(dwc->usb2_phy);
477 usb_phy_shutdown(dwc->usb3_phy);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530478 phy_exit(dwc->usb2_generic_phy);
479 phy_exit(dwc->usb3_generic_phy);
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600480
Felipe Balbi72246da2011-08-19 18:10:58 +0300481err0:
482 return ret;
483}
484
485static void dwc3_core_exit(struct dwc3 *dwc)
486{
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600487 dwc3_free_scratch_buffers(dwc);
Vivek Gautam01b8daf2012-10-13 19:20:18 +0530488 usb_phy_shutdown(dwc->usb2_phy);
489 usb_phy_shutdown(dwc->usb3_phy);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530490 phy_exit(dwc->usb2_generic_phy);
491 phy_exit(dwc->usb3_generic_phy);
Felipe Balbi72246da2011-08-19 18:10:58 +0300492}
493
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500494static int dwc3_core_get_phy(struct dwc3 *dwc)
Felipe Balbi72246da2011-08-19 18:10:58 +0300495{
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500496 struct device *dev = dwc->dev;
Felipe Balbi941ea362013-07-31 09:21:25 +0300497 struct device_node *node = dev->of_node;
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500498 int ret;
Felipe Balbi72246da2011-08-19 18:10:58 +0300499
Kishon Vijay Abraham I5088b6f2013-01-25 16:36:53 +0530500 if (node) {
501 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
502 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
Felipe Balbibb674902013-08-14 13:21:23 -0500503 } else {
504 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
505 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
Kishon Vijay Abraham I5088b6f2013-01-25 16:36:53 +0530506 }
507
Felipe Balbid105e7f2013-03-15 10:52:08 +0200508 if (IS_ERR(dwc->usb2_phy)) {
509 ret = PTR_ERR(dwc->usb2_phy);
Kishon Vijay Abraham I122f06e2014-03-03 17:08:10 +0530510 if (ret == -ENXIO || ret == -ENODEV) {
511 dwc->usb2_phy = NULL;
512 } else if (ret == -EPROBE_DEFER) {
Felipe Balbid105e7f2013-03-15 10:52:08 +0200513 return ret;
Kishon Vijay Abraham I122f06e2014-03-03 17:08:10 +0530514 } else {
515 dev_err(dev, "no usb2 phy configured\n");
516 return ret;
517 }
Felipe Balbi51e1e7b2012-07-19 14:09:48 +0300518 }
519
Felipe Balbid105e7f2013-03-15 10:52:08 +0200520 if (IS_ERR(dwc->usb3_phy)) {
Ruchika Kharwar315955d72013-07-04 00:59:34 -0500521 ret = PTR_ERR(dwc->usb3_phy);
Kishon Vijay Abraham I122f06e2014-03-03 17:08:10 +0530522 if (ret == -ENXIO || ret == -ENODEV) {
523 dwc->usb3_phy = NULL;
524 } else if (ret == -EPROBE_DEFER) {
Felipe Balbid105e7f2013-03-15 10:52:08 +0200525 return ret;
Kishon Vijay Abraham I122f06e2014-03-03 17:08:10 +0530526 } else {
527 dev_err(dev, "no usb3 phy configured\n");
528 return ret;
529 }
Felipe Balbi51e1e7b2012-07-19 14:09:48 +0300530 }
531
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530532 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
533 if (IS_ERR(dwc->usb2_generic_phy)) {
534 ret = PTR_ERR(dwc->usb2_generic_phy);
535 if (ret == -ENOSYS || ret == -ENODEV) {
536 dwc->usb2_generic_phy = NULL;
537 } else if (ret == -EPROBE_DEFER) {
538 return ret;
539 } else {
540 dev_err(dev, "no usb2 phy configured\n");
541 return ret;
542 }
543 }
544
545 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
546 if (IS_ERR(dwc->usb3_generic_phy)) {
547 ret = PTR_ERR(dwc->usb3_generic_phy);
548 if (ret == -ENOSYS || ret == -ENODEV) {
549 dwc->usb3_generic_phy = NULL;
550 } else if (ret == -EPROBE_DEFER) {
551 return ret;
552 } else {
553 dev_err(dev, "no usb3 phy configured\n");
554 return ret;
555 }
556 }
557
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500558 return 0;
559}
560
Felipe Balbi5f94adf2014-04-16 15:13:45 -0500561static int dwc3_core_init_mode(struct dwc3 *dwc)
562{
563 struct device *dev = dwc->dev;
564 int ret;
565
566 switch (dwc->dr_mode) {
567 case USB_DR_MODE_PERIPHERAL:
568 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
569 ret = dwc3_gadget_init(dwc);
570 if (ret) {
571 dev_err(dev, "failed to initialize gadget\n");
572 return ret;
573 }
574 break;
575 case USB_DR_MODE_HOST:
576 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
577 ret = dwc3_host_init(dwc);
578 if (ret) {
579 dev_err(dev, "failed to initialize host\n");
580 return ret;
581 }
582 break;
583 case USB_DR_MODE_OTG:
584 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
585 ret = dwc3_host_init(dwc);
586 if (ret) {
587 dev_err(dev, "failed to initialize host\n");
588 return ret;
589 }
590
591 ret = dwc3_gadget_init(dwc);
592 if (ret) {
593 dev_err(dev, "failed to initialize gadget\n");
594 return ret;
595 }
596 break;
597 default:
598 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
599 return -EINVAL;
600 }
601
602 return 0;
603}
604
605static void dwc3_core_exit_mode(struct dwc3 *dwc)
606{
607 switch (dwc->dr_mode) {
608 case USB_DR_MODE_PERIPHERAL:
609 dwc3_gadget_exit(dwc);
610 break;
611 case USB_DR_MODE_HOST:
612 dwc3_host_exit(dwc);
613 break;
614 case USB_DR_MODE_OTG:
615 dwc3_host_exit(dwc);
616 dwc3_gadget_exit(dwc);
617 break;
618 default:
619 /* do nothing */
620 break;
621 }
622}
623
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500624#define DWC3_ALIGN_MASK (16 - 1)
625
626static int dwc3_probe(struct platform_device *pdev)
627{
628 struct device *dev = &pdev->dev;
629 struct dwc3_platform_data *pdata = dev_get_platdata(dev);
630 struct device_node *node = dev->of_node;
631 struct resource *res;
632 struct dwc3 *dwc;
633
Andy Shevchenkob09e99e2014-05-15 15:53:32 +0300634 int ret;
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500635
636 void __iomem *regs;
637 void *mem;
638
639 mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
Jingoo Han734d5a52014-07-17 12:45:11 +0900640 if (!mem)
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500641 return -ENOMEM;
Jingoo Han734d5a52014-07-17 12:45:11 +0900642
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500643 dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
644 dwc->mem = mem;
645 dwc->dev = dev;
646
647 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
648 if (!res) {
649 dev_err(dev, "missing IRQ\n");
650 return -ENODEV;
651 }
652 dwc->xhci_resources[1].start = res->start;
653 dwc->xhci_resources[1].end = res->end;
654 dwc->xhci_resources[1].flags = res->flags;
655 dwc->xhci_resources[1].name = res->name;
656
657 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
658 if (!res) {
659 dev_err(dev, "missing memory resource\n");
660 return -ENODEV;
661 }
662
Vivek Gautamf32a5e22014-06-04 14:34:52 +0530663 dwc->xhci_resources[0].start = res->start;
664 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
665 DWC3_XHCI_REGS_END;
666 dwc->xhci_resources[0].flags = res->flags;
667 dwc->xhci_resources[0].name = res->name;
668
669 res->start += DWC3_GLOBALS_REGS_START;
670
671 /*
672 * Request memory region but exclude xHCI regs,
673 * since it will be requested by the xhci-plat driver.
674 */
675 regs = devm_ioremap_resource(dev, res);
676 if (IS_ERR(regs))
677 return PTR_ERR(regs);
678
679 dwc->regs = regs;
680 dwc->regs_size = resource_size(res);
681 /*
682 * restore res->start back to its original value so that,
683 * in case the probe is deferred, we don't end up getting error in
684 * request the memory region the next time probe is called.
685 */
686 res->start -= DWC3_GLOBALS_REGS_START;
687
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500688 if (node) {
689 dwc->maximum_speed = of_usb_get_maximum_speed(node);
690
691 dwc->needs_fifo_resize = of_property_read_bool(node, "tx-fifo-resize");
692 dwc->dr_mode = of_usb_get_dr_mode(node);
693 } else if (pdata) {
694 dwc->maximum_speed = pdata->maximum_speed;
695
696 dwc->needs_fifo_resize = pdata->tx_fifo_resize;
697 dwc->dr_mode = pdata->dr_mode;
698 }
699
700 /* default to superspeed if no maximum_speed passed */
701 if (dwc->maximum_speed == USB_SPEED_UNKNOWN)
702 dwc->maximum_speed = USB_SPEED_SUPER;
703
704 ret = dwc3_core_get_phy(dwc);
705 if (ret)
706 return ret;
707
Felipe Balbi72246da2011-08-19 18:10:58 +0300708 spin_lock_init(&dwc->lock);
709 platform_set_drvdata(pdev, dwc);
710
Kishon Vijay Abraham Iddff14f2013-03-07 18:51:43 +0530711 dev->dma_mask = dev->parent->dma_mask;
712 dev->dma_parms = dev->parent->dma_parms;
713 dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
714
Chanho Park802ca852012-02-15 18:27:55 +0900715 pm_runtime_enable(dev);
716 pm_runtime_get_sync(dev);
717 pm_runtime_forbid(dev);
Felipe Balbi72246da2011-08-19 18:10:58 +0300718
Kishon Vijay Abraham I4fd24482012-11-16 12:07:54 +0530719 dwc3_cache_hwparams(dwc);
720
Felipe Balbi39214262012-10-11 13:54:36 +0300721 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
722 if (ret) {
723 dev_err(dwc->dev, "failed to allocate event buffers\n");
724 ret = -ENOMEM;
725 goto err0;
726 }
727
Felipe Balbi32a4a132014-02-25 14:00:13 -0600728 if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
729 dwc->dr_mode = USB_DR_MODE_HOST;
730 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
731 dwc->dr_mode = USB_DR_MODE_PERIPHERAL;
732
733 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
734 dwc->dr_mode = USB_DR_MODE_OTG;
735
Felipe Balbi72246da2011-08-19 18:10:58 +0300736 ret = dwc3_core_init(dwc);
737 if (ret) {
Chanho Park802ca852012-02-15 18:27:55 +0900738 dev_err(dev, "failed to initialize core\n");
Felipe Balbi39214262012-10-11 13:54:36 +0300739 goto err0;
Felipe Balbi72246da2011-08-19 18:10:58 +0300740 }
741
Kishon Vijay Abraham I3088f102013-11-25 15:31:21 +0530742 usb_phy_set_suspend(dwc->usb2_phy, 0);
743 usb_phy_set_suspend(dwc->usb3_phy, 0);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530744 ret = phy_power_on(dwc->usb2_generic_phy);
745 if (ret < 0)
746 goto err1;
747
748 ret = phy_power_on(dwc->usb3_generic_phy);
749 if (ret < 0)
750 goto err_usb2phy_power;
Kishon Vijay Abraham I3088f102013-11-25 15:31:21 +0530751
Felipe Balbif122d332013-02-08 15:15:11 +0200752 ret = dwc3_event_buffers_setup(dwc);
753 if (ret) {
754 dev_err(dwc->dev, "failed to setup event buffers\n");
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530755 goto err_usb3phy_power;
Felipe Balbif122d332013-02-08 15:15:11 +0200756 }
757
Felipe Balbi5f94adf2014-04-16 15:13:45 -0500758 ret = dwc3_core_init_mode(dwc);
759 if (ret)
Felipe Balbif122d332013-02-08 15:15:11 +0200760 goto err2;
Felipe Balbi72246da2011-08-19 18:10:58 +0300761
762 ret = dwc3_debugfs_init(dwc);
763 if (ret) {
Chanho Park802ca852012-02-15 18:27:55 +0900764 dev_err(dev, "failed to initialize debugfs\n");
Felipe Balbif122d332013-02-08 15:15:11 +0200765 goto err3;
Felipe Balbi72246da2011-08-19 18:10:58 +0300766 }
767
Chanho Park802ca852012-02-15 18:27:55 +0900768 pm_runtime_allow(dev);
Felipe Balbi72246da2011-08-19 18:10:58 +0300769
770 return 0;
771
Felipe Balbif122d332013-02-08 15:15:11 +0200772err3:
Felipe Balbi5f94adf2014-04-16 15:13:45 -0500773 dwc3_core_exit_mode(dwc);
Felipe Balbi72246da2011-08-19 18:10:58 +0300774
Felipe Balbif122d332013-02-08 15:15:11 +0200775err2:
776 dwc3_event_buffers_cleanup(dwc);
777
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530778err_usb3phy_power:
779 phy_power_off(dwc->usb3_generic_phy);
780
781err_usb2phy_power:
782 phy_power_off(dwc->usb2_generic_phy);
783
Chanho Park802ca852012-02-15 18:27:55 +0900784err1:
Kishon Vijay Abraham I501fae52013-11-25 15:31:22 +0530785 usb_phy_set_suspend(dwc->usb2_phy, 1);
786 usb_phy_set_suspend(dwc->usb3_phy, 1);
Felipe Balbi72246da2011-08-19 18:10:58 +0300787 dwc3_core_exit(dwc);
788
Felipe Balbi39214262012-10-11 13:54:36 +0300789err0:
790 dwc3_free_event_buffers(dwc);
791
Felipe Balbi72246da2011-08-19 18:10:58 +0300792 return ret;
793}
794
Bill Pembertonfb4e98a2012-11-19 13:26:20 -0500795static int dwc3_remove(struct platform_device *pdev)
Felipe Balbi72246da2011-08-19 18:10:58 +0300796{
Felipe Balbi72246da2011-08-19 18:10:58 +0300797 struct dwc3 *dwc = platform_get_drvdata(pdev);
Felipe Balbi72246da2011-08-19 18:10:58 +0300798
Felipe Balbidc99f162014-09-03 16:13:37 -0500799 dwc3_debugfs_exit(dwc);
800 dwc3_core_exit_mode(dwc);
801 dwc3_event_buffers_cleanup(dwc);
802 dwc3_free_event_buffers(dwc);
803
Kishon Vijay Abraham I8ba007a2013-01-25 08:30:54 +0530804 usb_phy_set_suspend(dwc->usb2_phy, 1);
805 usb_phy_set_suspend(dwc->usb3_phy, 1);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530806 phy_power_off(dwc->usb2_generic_phy);
807 phy_power_off(dwc->usb3_generic_phy);
Kishon Vijay Abraham I8ba007a2013-01-25 08:30:54 +0530808
Felipe Balbi72246da2011-08-19 18:10:58 +0300809 dwc3_core_exit(dwc);
Felipe Balbi72246da2011-08-19 18:10:58 +0300810
Felipe Balbi7415f172012-04-30 14:56:33 +0300811 pm_runtime_put_sync(&pdev->dev);
812 pm_runtime_disable(&pdev->dev);
813
Felipe Balbi72246da2011-08-19 18:10:58 +0300814 return 0;
815}
816
Felipe Balbi7415f172012-04-30 14:56:33 +0300817#ifdef CONFIG_PM_SLEEP
818static int dwc3_prepare(struct device *dev)
819{
820 struct dwc3 *dwc = dev_get_drvdata(dev);
821 unsigned long flags;
822
823 spin_lock_irqsave(&dwc->lock, flags);
824
Ruchika Kharwara45c82b82013-07-06 07:52:49 -0500825 switch (dwc->dr_mode) {
826 case USB_DR_MODE_PERIPHERAL:
827 case USB_DR_MODE_OTG:
Felipe Balbi7415f172012-04-30 14:56:33 +0300828 dwc3_gadget_prepare(dwc);
829 /* FALLTHROUGH */
Ruchika Kharwara45c82b82013-07-06 07:52:49 -0500830 case USB_DR_MODE_HOST:
Felipe Balbi7415f172012-04-30 14:56:33 +0300831 default:
832 dwc3_event_buffers_cleanup(dwc);
833 break;
834 }
835
836 spin_unlock_irqrestore(&dwc->lock, flags);
837
838 return 0;
839}
840
841static void dwc3_complete(struct device *dev)
842{
843 struct dwc3 *dwc = dev_get_drvdata(dev);
844 unsigned long flags;
845
846 spin_lock_irqsave(&dwc->lock, flags);
847
Roger Quadrosf45e5f02014-03-26 11:43:09 +0200848 dwc3_event_buffers_setup(dwc);
Ruchika Kharwara45c82b82013-07-06 07:52:49 -0500849 switch (dwc->dr_mode) {
850 case USB_DR_MODE_PERIPHERAL:
851 case USB_DR_MODE_OTG:
Felipe Balbi7415f172012-04-30 14:56:33 +0300852 dwc3_gadget_complete(dwc);
853 /* FALLTHROUGH */
Ruchika Kharwara45c82b82013-07-06 07:52:49 -0500854 case USB_DR_MODE_HOST:
Felipe Balbi7415f172012-04-30 14:56:33 +0300855 default:
Felipe Balbi7415f172012-04-30 14:56:33 +0300856 break;
857 }
858
859 spin_unlock_irqrestore(&dwc->lock, flags);
860}
861
862static int dwc3_suspend(struct device *dev)
863{
864 struct dwc3 *dwc = dev_get_drvdata(dev);
865 unsigned long flags;
866
867 spin_lock_irqsave(&dwc->lock, flags);
868
Ruchika Kharwara45c82b82013-07-06 07:52:49 -0500869 switch (dwc->dr_mode) {
870 case USB_DR_MODE_PERIPHERAL:
871 case USB_DR_MODE_OTG:
Felipe Balbi7415f172012-04-30 14:56:33 +0300872 dwc3_gadget_suspend(dwc);
873 /* FALLTHROUGH */
Ruchika Kharwara45c82b82013-07-06 07:52:49 -0500874 case USB_DR_MODE_HOST:
Felipe Balbi7415f172012-04-30 14:56:33 +0300875 default:
876 /* do nothing */
877 break;
878 }
879
880 dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL);
881 spin_unlock_irqrestore(&dwc->lock, flags);
882
883 usb_phy_shutdown(dwc->usb3_phy);
884 usb_phy_shutdown(dwc->usb2_phy);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530885 phy_exit(dwc->usb2_generic_phy);
886 phy_exit(dwc->usb3_generic_phy);
Felipe Balbi7415f172012-04-30 14:56:33 +0300887
888 return 0;
889}
890
891static int dwc3_resume(struct device *dev)
892{
893 struct dwc3 *dwc = dev_get_drvdata(dev);
894 unsigned long flags;
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530895 int ret;
Felipe Balbi7415f172012-04-30 14:56:33 +0300896
897 usb_phy_init(dwc->usb3_phy);
898 usb_phy_init(dwc->usb2_phy);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530899 ret = phy_init(dwc->usb2_generic_phy);
900 if (ret < 0)
901 return ret;
902
903 ret = phy_init(dwc->usb3_generic_phy);
904 if (ret < 0)
905 goto err_usb2phy_init;
Felipe Balbi7415f172012-04-30 14:56:33 +0300906
907 spin_lock_irqsave(&dwc->lock, flags);
908
909 dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
910
Ruchika Kharwara45c82b82013-07-06 07:52:49 -0500911 switch (dwc->dr_mode) {
912 case USB_DR_MODE_PERIPHERAL:
913 case USB_DR_MODE_OTG:
Felipe Balbi7415f172012-04-30 14:56:33 +0300914 dwc3_gadget_resume(dwc);
915 /* FALLTHROUGH */
Ruchika Kharwara45c82b82013-07-06 07:52:49 -0500916 case USB_DR_MODE_HOST:
Felipe Balbi7415f172012-04-30 14:56:33 +0300917 default:
918 /* do nothing */
919 break;
920 }
921
922 spin_unlock_irqrestore(&dwc->lock, flags);
923
924 pm_runtime_disable(dev);
925 pm_runtime_set_active(dev);
926 pm_runtime_enable(dev);
927
928 return 0;
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530929
930err_usb2phy_init:
931 phy_exit(dwc->usb2_generic_phy);
932
933 return ret;
Felipe Balbi7415f172012-04-30 14:56:33 +0300934}
935
936static const struct dev_pm_ops dwc3_dev_pm_ops = {
937 .prepare = dwc3_prepare,
938 .complete = dwc3_complete,
939
940 SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
941};
942
943#define DWC3_PM_OPS &(dwc3_dev_pm_ops)
944#else
945#define DWC3_PM_OPS NULL
946#endif
947
Kishon Vijay Abraham I5088b6f2013-01-25 16:36:53 +0530948#ifdef CONFIG_OF
949static const struct of_device_id of_dwc3_match[] = {
950 {
Felipe Balbi22a5aa12013-07-02 21:20:24 +0300951 .compatible = "snps,dwc3"
952 },
953 {
Kishon Vijay Abraham I5088b6f2013-01-25 16:36:53 +0530954 .compatible = "synopsys,dwc3"
955 },
956 { },
957};
958MODULE_DEVICE_TABLE(of, of_dwc3_match);
959#endif
960
Felipe Balbi72246da2011-08-19 18:10:58 +0300961static struct platform_driver dwc3_driver = {
962 .probe = dwc3_probe,
Bill Pemberton76904172012-11-19 13:21:08 -0500963 .remove = dwc3_remove,
Felipe Balbi72246da2011-08-19 18:10:58 +0300964 .driver = {
965 .name = "dwc3",
Kishon Vijay Abraham I5088b6f2013-01-25 16:36:53 +0530966 .of_match_table = of_match_ptr(of_dwc3_match),
Felipe Balbi7415f172012-04-30 14:56:33 +0300967 .pm = DWC3_PM_OPS,
Felipe Balbi72246da2011-08-19 18:10:58 +0300968 },
Felipe Balbi72246da2011-08-19 18:10:58 +0300969};
970
Tobias Klauserb1116dc2012-02-28 12:57:20 +0100971module_platform_driver(dwc3_driver);
972
Sebastian Andrzej Siewior7ae4fc42011-10-19 19:39:50 +0200973MODULE_ALIAS("platform:dwc3");
Felipe Balbi72246da2011-08-19 18:10:58 +0300974MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
Felipe Balbi5945f782013-06-30 14:15:11 +0300975MODULE_LICENSE("GPL v2");
Felipe Balbi72246da2011-08-19 18:10:58 +0300976MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");