blob: cbdefbb3d302c707540ab1e5d082c3d7ab072882 [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 Balbifa0ea132014-09-19 15:51:11 -050022#include <linux/version.h>
Felipe Balbia72e6582011-09-05 13:37:28 +030023#include <linux/module.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030024#include <linux/kernel.h>
25#include <linux/slab.h>
26#include <linux/spinlock.h>
27#include <linux/platform_device.h>
28#include <linux/pm_runtime.h>
29#include <linux/interrupt.h>
30#include <linux/ioport.h>
31#include <linux/io.h>
32#include <linux/list.h>
33#include <linux/delay.h>
34#include <linux/dma-mapping.h>
Felipe Balbi457e84b2012-01-18 18:04:09 +020035#include <linux/of.h>
Heikki Krogerus404905a2014-09-25 10:57:02 +030036#include <linux/acpi.h>
Sekhar Nori63444752015-08-31 21:09:08 +053037#include <linux/pinctrl/consumer.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030038
39#include <linux/usb/ch9.h>
40#include <linux/usb/gadget.h>
Felipe Balbif7e846f2013-06-30 14:29:51 +030041#include <linux/usb/of.h>
Ruchika Kharwara45c82b82013-07-06 07:52:49 -050042#include <linux/usb/otg.h>
Felipe Balbi72246da2011-08-19 18:10:58 +030043
Felipe Balbi6462cbd2013-06-30 14:19:33 +030044#include "platform_data.h"
Felipe Balbi72246da2011-08-19 18:10:58 +030045#include "core.h"
46#include "gadget.h"
47#include "io.h"
48
49#include "debug.h"
50
Felipe Balbi8300dd22011-10-18 13:54:01 +030051/* -------------------------------------------------------------------------- */
52
Sebastian Andrzej Siewior3140e8c2011-10-31 22:25:40 +010053void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
54{
55 u32 reg;
56
57 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
58 reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
59 reg |= DWC3_GCTL_PRTCAPDIR(mode);
60 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
61}
Felipe Balbi8300dd22011-10-18 13:54:01 +030062
Felipe Balbicf6d8672016-04-14 15:03:39 +030063u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
64{
65 struct dwc3 *dwc = dep->dwc;
66 u32 reg;
67
68 dwc3_writel(dwc->regs, DWC3_GDBGFIFOSPACE,
69 DWC3_GDBGFIFOSPACE_NUM(dep->number) |
70 DWC3_GDBGFIFOSPACE_TYPE(type));
71
72 reg = dwc3_readl(dwc->regs, DWC3_GDBGFIFOSPACE);
73
74 return DWC3_GDBGFIFOSPACE_SPACE_AVAILABLE(reg);
75}
76
Felipe Balbi72246da2011-08-19 18:10:58 +030077/**
78 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
79 * @dwc: pointer to our context structure
80 */
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +053081static int dwc3_core_soft_reset(struct dwc3 *dwc)
Felipe Balbi72246da2011-08-19 18:10:58 +030082{
83 u32 reg;
Felipe Balbif59dcab2016-03-11 10:51:52 +020084 int retries = 1000;
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +053085 int ret;
Felipe Balbi72246da2011-08-19 18:10:58 +030086
Felipe Balbi51e1e7b2012-07-19 14:09:48 +030087 usb_phy_init(dwc->usb2_phy);
88 usb_phy_init(dwc->usb3_phy);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +053089 ret = phy_init(dwc->usb2_generic_phy);
90 if (ret < 0)
91 return ret;
92
93 ret = phy_init(dwc->usb3_generic_phy);
94 if (ret < 0) {
95 phy_exit(dwc->usb2_generic_phy);
96 return ret;
97 }
Felipe Balbi72246da2011-08-19 18:10:58 +030098
Felipe Balbif59dcab2016-03-11 10:51:52 +020099 /*
100 * We're resetting only the device side because, if we're in host mode,
101 * XHCI driver will reset the host block. If dwc3 was configured for
102 * host-only mode, then we can return early.
103 */
104 if (dwc->dr_mode == USB_DR_MODE_HOST)
105 return 0;
Felipe Balbi72246da2011-08-19 18:10:58 +0300106
Felipe Balbif59dcab2016-03-11 10:51:52 +0200107 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
108 reg |= DWC3_DCTL_CSFTRST;
109 dwc3_writel(dwc->regs, DWC3_DCTL, reg);
Felipe Balbi72246da2011-08-19 18:10:58 +0300110
Felipe Balbif59dcab2016-03-11 10:51:52 +0200111 do {
112 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
113 if (!(reg & DWC3_DCTL_CSFTRST))
114 return 0;
Pratyush Anand45627ac2012-06-21 17:44:28 +0530115
Felipe Balbif59dcab2016-03-11 10:51:52 +0200116 udelay(1);
117 } while (--retries);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530118
Felipe Balbif59dcab2016-03-11 10:51:52 +0200119 return -ETIMEDOUT;
Felipe Balbi72246da2011-08-19 18:10:58 +0300120}
121
122/**
Heikki Krogerusc5cc74e2015-05-13 15:26:47 +0300123 * dwc3_soft_reset - Issue soft reset
124 * @dwc: Pointer to our controller context structure
125 */
126static int dwc3_soft_reset(struct dwc3 *dwc)
127{
128 unsigned long timeout;
129 u32 reg;
130
131 timeout = jiffies + msecs_to_jiffies(500);
132 dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
133 do {
134 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
135 if (!(reg & DWC3_DCTL_CSFTRST))
136 break;
137
138 if (time_after(jiffies, timeout)) {
139 dev_err(dwc->dev, "Reset Timed Out\n");
140 return -ETIMEDOUT;
141 }
142
143 cpu_relax();
144 } while (true);
145
146 return 0;
147}
148
Nikhil Badoladb2be4e2015-09-04 10:15:58 +0530149/*
150 * dwc3_frame_length_adjustment - Adjusts frame length if required
151 * @dwc3: Pointer to our controller context structure
Nikhil Badoladb2be4e2015-09-04 10:15:58 +0530152 */
Felipe Balbibcdb3272016-05-16 10:42:23 +0300153static void dwc3_frame_length_adjustment(struct dwc3 *dwc)
Nikhil Badoladb2be4e2015-09-04 10:15:58 +0530154{
155 u32 reg;
156 u32 dft;
157
158 if (dwc->revision < DWC3_REVISION_250A)
159 return;
160
Felipe Balbibcdb3272016-05-16 10:42:23 +0300161 if (dwc->fladj == 0)
Nikhil Badoladb2be4e2015-09-04 10:15:58 +0530162 return;
163
164 reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
165 dft = reg & DWC3_GFLADJ_30MHZ_MASK;
Felipe Balbibcdb3272016-05-16 10:42:23 +0300166 if (!dev_WARN_ONCE(dwc->dev, dft == dwc->fladj,
Nikhil Badoladb2be4e2015-09-04 10:15:58 +0530167 "request value same as default, ignoring\n")) {
168 reg &= ~DWC3_GFLADJ_30MHZ_MASK;
Felipe Balbibcdb3272016-05-16 10:42:23 +0300169 reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | dwc->fladj;
Nikhil Badoladb2be4e2015-09-04 10:15:58 +0530170 dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
171 }
172}
173
Heikki Krogerusc5cc74e2015-05-13 15:26:47 +0300174/**
Felipe Balbi72246da2011-08-19 18:10:58 +0300175 * dwc3_free_one_event_buffer - Frees one event buffer
176 * @dwc: Pointer to our controller context structure
177 * @evt: Pointer to event buffer to be freed
178 */
179static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
180 struct dwc3_event_buffer *evt)
181{
182 dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma);
Felipe Balbi72246da2011-08-19 18:10:58 +0300183}
184
185/**
Paul Zimmerman1d046792012-02-15 18:56:56 -0800186 * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
Felipe Balbi72246da2011-08-19 18:10:58 +0300187 * @dwc: Pointer to our controller context structure
188 * @length: size of the event buffer
189 *
Paul Zimmerman1d046792012-02-15 18:56:56 -0800190 * Returns a pointer to the allocated event buffer structure on success
Felipe Balbi72246da2011-08-19 18:10:58 +0300191 * otherwise ERR_PTR(errno).
192 */
Felipe Balbi67d0b502013-02-22 16:31:07 +0200193static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
194 unsigned length)
Felipe Balbi72246da2011-08-19 18:10:58 +0300195{
196 struct dwc3_event_buffer *evt;
197
Felipe Balbi380f0d22012-10-11 13:48:36 +0300198 evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL);
Felipe Balbi72246da2011-08-19 18:10:58 +0300199 if (!evt)
200 return ERR_PTR(-ENOMEM);
201
202 evt->dwc = dwc;
203 evt->length = length;
204 evt->buf = dma_alloc_coherent(dwc->dev, length,
205 &evt->dma, GFP_KERNEL);
Felipe Balbie32672f2012-11-08 15:26:41 +0200206 if (!evt->buf)
Felipe Balbi72246da2011-08-19 18:10:58 +0300207 return ERR_PTR(-ENOMEM);
Felipe Balbi72246da2011-08-19 18:10:58 +0300208
209 return evt;
210}
211
212/**
213 * dwc3_free_event_buffers - frees all allocated event buffers
214 * @dwc: Pointer to our controller context structure
215 */
216static void dwc3_free_event_buffers(struct dwc3 *dwc)
217{
218 struct dwc3_event_buffer *evt;
Felipe Balbi72246da2011-08-19 18:10:58 +0300219
Felipe Balbi696c8b12016-03-30 09:37:03 +0300220 evt = dwc->ev_buf;
Felipe Balbi660e9bd2016-03-30 09:26:24 +0300221 if (evt)
222 dwc3_free_one_event_buffer(dwc, evt);
Felipe Balbi72246da2011-08-19 18:10:58 +0300223}
224
225/**
226 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
Paul Zimmerman1d046792012-02-15 18:56:56 -0800227 * @dwc: pointer to our controller context structure
Felipe Balbi72246da2011-08-19 18:10:58 +0300228 * @length: size of event buffer
229 *
Paul Zimmerman1d046792012-02-15 18:56:56 -0800230 * Returns 0 on success otherwise negative errno. In the error case, dwc
Felipe Balbi72246da2011-08-19 18:10:58 +0300231 * may contain some buffers allocated but not all which were requested.
232 */
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500233static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
Felipe Balbi72246da2011-08-19 18:10:58 +0300234{
Felipe Balbi660e9bd2016-03-30 09:26:24 +0300235 struct dwc3_event_buffer *evt;
Felipe Balbi72246da2011-08-19 18:10:58 +0300236
Felipe Balbi660e9bd2016-03-30 09:26:24 +0300237 evt = dwc3_alloc_one_event_buffer(dwc, length);
238 if (IS_ERR(evt)) {
239 dev_err(dwc->dev, "can't allocate event buffer\n");
240 return PTR_ERR(evt);
Felipe Balbi72246da2011-08-19 18:10:58 +0300241 }
Felipe Balbi696c8b12016-03-30 09:37:03 +0300242 dwc->ev_buf = evt;
Felipe Balbi72246da2011-08-19 18:10:58 +0300243
244 return 0;
245}
246
247/**
248 * dwc3_event_buffers_setup - setup our allocated event buffers
Paul Zimmerman1d046792012-02-15 18:56:56 -0800249 * @dwc: pointer to our controller context structure
Felipe Balbi72246da2011-08-19 18:10:58 +0300250 *
251 * Returns 0 on success otherwise negative errno.
252 */
Paul Zimmerman7acd85e2012-04-27 14:28:02 +0300253static int dwc3_event_buffers_setup(struct dwc3 *dwc)
Felipe Balbi72246da2011-08-19 18:10:58 +0300254{
255 struct dwc3_event_buffer *evt;
Felipe Balbi72246da2011-08-19 18:10:58 +0300256
Felipe Balbi696c8b12016-03-30 09:37:03 +0300257 evt = dwc->ev_buf;
Felipe Balbi660e9bd2016-03-30 09:26:24 +0300258 dwc3_trace(trace_dwc3_core,
259 "Event buf %p dma %08llx length %d\n",
260 evt->buf, (unsigned long long) evt->dma,
261 evt->length);
Felipe Balbi72246da2011-08-19 18:10:58 +0300262
Felipe Balbi660e9bd2016-03-30 09:26:24 +0300263 evt->lpos = 0;
Paul Zimmerman7acd85e2012-04-27 14:28:02 +0300264
Felipe Balbi660e9bd2016-03-30 09:26:24 +0300265 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0),
266 lower_32_bits(evt->dma));
267 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0),
268 upper_32_bits(evt->dma));
269 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0),
270 DWC3_GEVNTSIZ_SIZE(evt->length));
271 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
Felipe Balbi72246da2011-08-19 18:10:58 +0300272
273 return 0;
274}
275
276static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
277{
278 struct dwc3_event_buffer *evt;
Felipe Balbi72246da2011-08-19 18:10:58 +0300279
Felipe Balbi696c8b12016-03-30 09:37:03 +0300280 evt = dwc->ev_buf;
Paul Zimmerman7acd85e2012-04-27 14:28:02 +0300281
Felipe Balbi660e9bd2016-03-30 09:26:24 +0300282 evt->lpos = 0;
Paul Zimmerman7acd85e2012-04-27 14:28:02 +0300283
Felipe Balbi660e9bd2016-03-30 09:26:24 +0300284 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(0), 0);
285 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(0), 0);
286 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(0), DWC3_GEVNTSIZ_INTMASK
287 | DWC3_GEVNTSIZ_SIZE(0));
288 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), 0);
Felipe Balbi72246da2011-08-19 18:10:58 +0300289}
290
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600291static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
292{
293 if (!dwc->has_hibernation)
294 return 0;
295
296 if (!dwc->nr_scratch)
297 return 0;
298
299 dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
300 DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
301 if (!dwc->scratchbuf)
302 return -ENOMEM;
303
304 return 0;
305}
306
307static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
308{
309 dma_addr_t scratch_addr;
310 u32 param;
311 int ret;
312
313 if (!dwc->has_hibernation)
314 return 0;
315
316 if (!dwc->nr_scratch)
317 return 0;
318
319 /* should never fall here */
320 if (!WARN_ON(dwc->scratchbuf))
321 return 0;
322
323 scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
324 dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
325 DMA_BIDIRECTIONAL);
326 if (dma_mapping_error(dwc->dev, scratch_addr)) {
327 dev_err(dwc->dev, "failed to map scratch buffer\n");
328 ret = -EFAULT;
329 goto err0;
330 }
331
332 dwc->scratch_addr = scratch_addr;
333
334 param = lower_32_bits(scratch_addr);
335
336 ret = dwc3_send_gadget_generic_command(dwc,
337 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param);
338 if (ret < 0)
339 goto err1;
340
341 param = upper_32_bits(scratch_addr);
342
343 ret = dwc3_send_gadget_generic_command(dwc,
344 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param);
345 if (ret < 0)
346 goto err1;
347
348 return 0;
349
350err1:
351 dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
352 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
353
354err0:
355 return ret;
356}
357
358static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
359{
360 if (!dwc->has_hibernation)
361 return;
362
363 if (!dwc->nr_scratch)
364 return;
365
366 /* should never fall here */
367 if (!WARN_ON(dwc->scratchbuf))
368 return;
369
370 dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
371 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
372 kfree(dwc->scratchbuf);
373}
374
Felipe Balbi789451f62011-05-05 15:53:10 +0300375static void dwc3_core_num_eps(struct dwc3 *dwc)
376{
377 struct dwc3_hwparams *parms = &dwc->hwparams;
378
379 dwc->num_in_eps = DWC3_NUM_IN_EPS(parms);
380 dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps;
381
Felipe Balbi73815282015-01-27 13:48:14 -0600382 dwc3_trace(trace_dwc3_core, "found %d IN and %d OUT endpoints",
Felipe Balbi789451f62011-05-05 15:53:10 +0300383 dwc->num_in_eps, dwc->num_out_eps);
384}
385
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500386static void dwc3_cache_hwparams(struct dwc3 *dwc)
Felipe Balbi26ceca92011-09-30 10:58:49 +0300387{
388 struct dwc3_hwparams *parms = &dwc->hwparams;
389
390 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0);
391 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1);
392 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2);
393 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
394 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4);
395 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5);
396 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
397 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
398 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
399}
400
Felipe Balbi72246da2011-08-19 18:10:58 +0300401/**
Huang Ruib5a65c42014-10-28 19:54:28 +0800402 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
403 * @dwc: Pointer to our controller context structure
Heikki Krogerus88bc9d12015-05-13 15:26:51 +0300404 *
405 * Returns 0 on success. The USB PHY interfaces are configured but not
406 * initialized. The PHY interfaces and the PHYs get initialized together with
407 * the core in dwc3_core_init.
Huang Ruib5a65c42014-10-28 19:54:28 +0800408 */
Heikki Krogerus88bc9d12015-05-13 15:26:51 +0300409static int dwc3_phy_setup(struct dwc3 *dwc)
Huang Ruib5a65c42014-10-28 19:54:28 +0800410{
411 u32 reg;
Heikki Krogerus88bc9d12015-05-13 15:26:51 +0300412 int ret;
Huang Ruib5a65c42014-10-28 19:54:28 +0800413
414 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
415
Huang Rui2164a472014-10-28 19:54:35 +0800416 /*
417 * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY
418 * to '0' during coreConsultant configuration. So default value
419 * will be '0' when the core is reset. Application needs to set it
420 * to '1' after the core initialization is completed.
421 */
422 if (dwc->revision > DWC3_REVISION_194A)
423 reg |= DWC3_GUSB3PIPECTL_SUSPHY;
424
Huang Ruib5a65c42014-10-28 19:54:28 +0800425 if (dwc->u2ss_inp3_quirk)
426 reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK;
427
Rajesh Bhagate58dd352016-03-14 14:40:50 +0530428 if (dwc->dis_rxdet_inp3_quirk)
429 reg |= DWC3_GUSB3PIPECTL_DISRXDETINP3;
430
Huang Ruidf31f5b2014-10-28 19:54:29 +0800431 if (dwc->req_p1p2p3_quirk)
432 reg |= DWC3_GUSB3PIPECTL_REQP1P2P3;
433
Huang Ruia2a1d0f2014-10-28 19:54:30 +0800434 if (dwc->del_p1p2p3_quirk)
435 reg |= DWC3_GUSB3PIPECTL_DEP1P2P3_EN;
436
Huang Rui41c06ff2014-10-28 19:54:31 +0800437 if (dwc->del_phy_power_chg_quirk)
438 reg |= DWC3_GUSB3PIPECTL_DEPOCHANGE;
439
Huang Ruifb67afc2014-10-28 19:54:32 +0800440 if (dwc->lfps_filter_quirk)
441 reg |= DWC3_GUSB3PIPECTL_LFPSFILT;
442
Huang Rui14f4ac52014-10-28 19:54:33 +0800443 if (dwc->rx_detect_poll_quirk)
444 reg |= DWC3_GUSB3PIPECTL_RX_DETOPOLL;
445
Huang Rui6b6a0c92014-10-31 11:11:12 +0800446 if (dwc->tx_de_emphasis_quirk)
447 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis);
448
Felipe Balbicd72f892014-11-06 11:31:00 -0600449 if (dwc->dis_u3_susphy_quirk)
Huang Rui59acfa22014-10-31 11:11:13 +0800450 reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
451
Huang Ruib5a65c42014-10-28 19:54:28 +0800452 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
453
Huang Rui2164a472014-10-28 19:54:35 +0800454 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
455
Heikki Krogerus3e10a2c2015-05-13 15:26:49 +0300456 /* Select the HS PHY interface */
457 switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) {
458 case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI:
Felipe Balbi43cacb02015-07-01 22:03:09 -0500459 if (dwc->hsphy_interface &&
460 !strncmp(dwc->hsphy_interface, "utmi", 4)) {
Heikki Krogerus3e10a2c2015-05-13 15:26:49 +0300461 reg &= ~DWC3_GUSB2PHYCFG_ULPI_UTMI;
Heikki Krogerus88bc9d12015-05-13 15:26:51 +0300462 break;
Felipe Balbi43cacb02015-07-01 22:03:09 -0500463 } else if (dwc->hsphy_interface &&
464 !strncmp(dwc->hsphy_interface, "ulpi", 4)) {
Heikki Krogerus3e10a2c2015-05-13 15:26:49 +0300465 reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI;
Heikki Krogerus88bc9d12015-05-13 15:26:51 +0300466 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
Heikki Krogerus3e10a2c2015-05-13 15:26:49 +0300467 } else {
Heikki Krogerus88bc9d12015-05-13 15:26:51 +0300468 /* Relying on default value. */
469 if (!(reg & DWC3_GUSB2PHYCFG_ULPI_UTMI))
470 break;
Heikki Krogerus3e10a2c2015-05-13 15:26:49 +0300471 }
472 /* FALLTHROUGH */
Heikki Krogerus88bc9d12015-05-13 15:26:51 +0300473 case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI:
474 /* Making sure the interface and PHY are operational */
475 ret = dwc3_soft_reset(dwc);
476 if (ret)
477 return ret;
478
479 udelay(1);
480
481 ret = dwc3_ulpi_init(dwc);
482 if (ret)
483 return ret;
484 /* FALLTHROUGH */
Heikki Krogerus3e10a2c2015-05-13 15:26:49 +0300485 default:
486 break;
487 }
488
Huang Rui2164a472014-10-28 19:54:35 +0800489 /*
490 * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
491 * '0' during coreConsultant configuration. So default value will
492 * be '0' when the core is reset. Application needs to set it to
493 * '1' after the core initialization is completed.
494 */
495 if (dwc->revision > DWC3_REVISION_194A)
496 reg |= DWC3_GUSB2PHYCFG_SUSPHY;
497
Felipe Balbicd72f892014-11-06 11:31:00 -0600498 if (dwc->dis_u2_susphy_quirk)
Huang Rui0effe0a2014-10-31 11:11:14 +0800499 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
500
John Younec791d12015-10-02 20:30:57 -0700501 if (dwc->dis_enblslpm_quirk)
502 reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
503
Huang Rui2164a472014-10-28 19:54:35 +0800504 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
Heikki Krogerus88bc9d12015-05-13 15:26:51 +0300505
506 return 0;
Huang Ruib5a65c42014-10-28 19:54:28 +0800507}
508
Felipe Balbic499ff72016-05-16 10:49:01 +0300509static void dwc3_core_exit(struct dwc3 *dwc)
510{
511 dwc3_event_buffers_cleanup(dwc);
512
513 usb_phy_shutdown(dwc->usb2_phy);
514 usb_phy_shutdown(dwc->usb3_phy);
515 phy_exit(dwc->usb2_generic_phy);
516 phy_exit(dwc->usb3_generic_phy);
517
518 usb_phy_set_suspend(dwc->usb2_phy, 1);
519 usb_phy_set_suspend(dwc->usb3_phy, 1);
520 phy_power_off(dwc->usb2_generic_phy);
521 phy_power_off(dwc->usb3_generic_phy);
522}
523
Huang Ruib5a65c42014-10-28 19:54:28 +0800524/**
Felipe Balbi72246da2011-08-19 18:10:58 +0300525 * dwc3_core_init - Low-level initialization of DWC3 Core
526 * @dwc: Pointer to our controller context structure
527 *
528 * Returns 0 on success otherwise negative errno.
529 */
Bill Pemberton41ac7b32012-11-19 13:21:48 -0500530static int dwc3_core_init(struct dwc3 *dwc)
Felipe Balbi72246da2011-08-19 18:10:58 +0300531{
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600532 u32 hwparams4 = dwc->hwparams.hwparams4;
Felipe Balbi72246da2011-08-19 18:10:58 +0300533 u32 reg;
534 int ret;
535
Sebastian Andrzej Siewior7650bd72011-08-29 13:56:36 +0200536 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
537 /* This should read as U3 followed by revision number */
John Youn690fb372015-09-04 19:15:10 -0700538 if ((reg & DWC3_GSNPSID_MASK) == 0x55330000) {
539 /* Detected DWC_usb3 IP */
540 dwc->revision = reg;
541 } else if ((reg & DWC3_GSNPSID_MASK) == 0x33310000) {
542 /* Detected DWC_usb31 IP */
543 dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER);
544 dwc->revision |= DWC3_REVISION_IS_DWC31;
545 } else {
Sebastian Andrzej Siewior7650bd72011-08-29 13:56:36 +0200546 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
547 ret = -ENODEV;
548 goto err0;
549 }
Sebastian Andrzej Siewior7650bd72011-08-29 13:56:36 +0200550
Felipe Balbifa0ea132014-09-19 15:51:11 -0500551 /*
552 * Write Linux Version Code to our GUID register so it's easy to figure
553 * out which kernel version a bug was found.
554 */
555 dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
556
Paul Zimmerman0e1e5c42014-05-23 11:39:24 -0700557 /* Handle USB2.0-only core configuration */
558 if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
559 DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
560 if (dwc->maximum_speed == USB_SPEED_SUPER)
561 dwc->maximum_speed = USB_SPEED_HIGH;
562 }
563
Felipe Balbi72246da2011-08-19 18:10:58 +0300564 /* issue device SoftReset too */
Heikki Krogerusc5cc74e2015-05-13 15:26:47 +0300565 ret = dwc3_soft_reset(dwc);
566 if (ret)
567 goto err0;
Felipe Balbi72246da2011-08-19 18:10:58 +0300568
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530569 ret = dwc3_core_soft_reset(dwc);
570 if (ret)
571 goto err0;
Pratyush Anand58a0f232012-06-21 17:44:29 +0530572
Felipe Balbic499ff72016-05-16 10:49:01 +0300573 ret = dwc3_phy_setup(dwc);
574 if (ret)
575 goto err0;
576
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100577 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
Paul Zimmerman3e87c422012-02-24 17:32:13 -0800578 reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100579
Sebastian Andrzej Siewior164d7732011-11-24 11:22:05 +0100580 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100581 case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
Felipe Balbi32a4a132014-02-25 14:00:13 -0600582 /**
583 * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an
584 * issue which would cause xHCI compliance tests to fail.
585 *
586 * Because of that we cannot enable clock gating on such
587 * configurations.
588 *
589 * Refers to:
590 *
591 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based
592 * SOF/ITP Mode Used
593 */
594 if ((dwc->dr_mode == USB_DR_MODE_HOST ||
595 dwc->dr_mode == USB_DR_MODE_OTG) &&
596 (dwc->revision >= DWC3_REVISION_210A &&
597 dwc->revision <= DWC3_REVISION_250A))
598 reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC;
599 else
600 reg &= ~DWC3_GCTL_DSBLCLKGTNG;
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100601 break;
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600602 case DWC3_GHWPARAMS1_EN_PWROPT_HIB:
603 /* enable hibernation here */
604 dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4);
Huang Rui2eac3992014-10-28 19:54:22 +0800605
606 /*
607 * REVISIT Enabling this bit so that host-mode hibernation
608 * will work. Device-mode hibernation is not yet implemented.
609 */
610 reg |= DWC3_GCTL_GBLHIBERNATIONEN;
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600611 break;
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100612 default:
Felipe Balbi1407bf12015-11-16 16:06:37 -0600613 dwc3_trace(trace_dwc3_core, "No power optimization available\n");
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100614 }
615
Huang Rui946bd572014-10-28 19:54:23 +0800616 /* check if current dwc3 is on simulation board */
617 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) {
Felipe Balbi1407bf12015-11-16 16:06:37 -0600618 dwc3_trace(trace_dwc3_core,
619 "running on FPGA platform\n");
Huang Rui946bd572014-10-28 19:54:23 +0800620 dwc->is_fpga = true;
621 }
622
Huang Rui3b812212014-10-28 19:54:25 +0800623 WARN_ONCE(dwc->disable_scramble_quirk && !dwc->is_fpga,
624 "disable_scramble cannot be used on non-FPGA builds\n");
625
626 if (dwc->disable_scramble_quirk && dwc->is_fpga)
627 reg |= DWC3_GCTL_DISSCRAMBLE;
628 else
629 reg &= ~DWC3_GCTL_DISSCRAMBLE;
630
Huang Rui9a5b2f32014-10-28 19:54:27 +0800631 if (dwc->u2exit_lfps_quirk)
632 reg |= DWC3_GCTL_U2EXIT_LFPS;
633
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100634 /*
635 * WORKAROUND: DWC3 revisions <1.90a have a bug
Paul Zimmerman1d046792012-02-15 18:56:56 -0800636 * where the device can fail to connect at SuperSpeed
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100637 * and falls back to high-speed mode which causes
Paul Zimmerman1d046792012-02-15 18:56:56 -0800638 * the device to enter a Connect/Disconnect loop
Sebastian Andrzej Siewior4878a022011-10-31 22:25:41 +0100639 */
640 if (dwc->revision < DWC3_REVISION_190A)
641 reg |= DWC3_GCTL_U2RSTECN;
642
643 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
644
Felipe Balbic499ff72016-05-16 10:49:01 +0300645 dwc3_core_num_eps(dwc);
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600646
647 ret = dwc3_setup_scratch_buffers(dwc);
648 if (ret)
Felipe Balbic499ff72016-05-16 10:49:01 +0300649 goto err1;
650
651 /* Adjust Frame Length */
652 dwc3_frame_length_adjustment(dwc);
653
654 usb_phy_set_suspend(dwc->usb2_phy, 0);
655 usb_phy_set_suspend(dwc->usb3_phy, 0);
656 ret = phy_power_on(dwc->usb2_generic_phy);
657 if (ret < 0)
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600658 goto err2;
659
Felipe Balbic499ff72016-05-16 10:49:01 +0300660 ret = phy_power_on(dwc->usb3_generic_phy);
661 if (ret < 0)
662 goto err3;
663
664 ret = dwc3_event_buffers_setup(dwc);
665 if (ret) {
666 dev_err(dwc->dev, "failed to setup event buffers\n");
667 goto err4;
668 }
669
Felipe Balbi72246da2011-08-19 18:10:58 +0300670 return 0;
671
Felipe Balbic499ff72016-05-16 10:49:01 +0300672err4:
673 phy_power_off(dwc->usb2_generic_phy);
674
675err3:
676 phy_power_off(dwc->usb3_generic_phy);
677
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600678err2:
Felipe Balbic499ff72016-05-16 10:49:01 +0300679 usb_phy_set_suspend(dwc->usb2_phy, 1);
680 usb_phy_set_suspend(dwc->usb3_phy, 1);
681 dwc3_core_exit(dwc);
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600682
683err1:
684 usb_phy_shutdown(dwc->usb2_phy);
685 usb_phy_shutdown(dwc->usb3_phy);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530686 phy_exit(dwc->usb2_generic_phy);
687 phy_exit(dwc->usb3_generic_phy);
Felipe Balbi0ffcaf32013-12-19 13:04:28 -0600688
Felipe Balbi72246da2011-08-19 18:10:58 +0300689err0:
690 return ret;
691}
692
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500693static int dwc3_core_get_phy(struct dwc3 *dwc)
Felipe Balbi72246da2011-08-19 18:10:58 +0300694{
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500695 struct device *dev = dwc->dev;
Felipe Balbi941ea362013-07-31 09:21:25 +0300696 struct device_node *node = dev->of_node;
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500697 int ret;
Felipe Balbi72246da2011-08-19 18:10:58 +0300698
Kishon Vijay Abraham I5088b6f2013-01-25 16:36:53 +0530699 if (node) {
700 dwc->usb2_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
701 dwc->usb3_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 1);
Felipe Balbibb674902013-08-14 13:21:23 -0500702 } else {
703 dwc->usb2_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
704 dwc->usb3_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB3);
Kishon Vijay Abraham I5088b6f2013-01-25 16:36:53 +0530705 }
706
Felipe Balbid105e7f2013-03-15 10:52:08 +0200707 if (IS_ERR(dwc->usb2_phy)) {
708 ret = PTR_ERR(dwc->usb2_phy);
Kishon Vijay Abraham I122f06e2014-03-03 17:08:10 +0530709 if (ret == -ENXIO || ret == -ENODEV) {
710 dwc->usb2_phy = NULL;
711 } else if (ret == -EPROBE_DEFER) {
Felipe Balbid105e7f2013-03-15 10:52:08 +0200712 return ret;
Kishon Vijay Abraham I122f06e2014-03-03 17:08:10 +0530713 } else {
714 dev_err(dev, "no usb2 phy configured\n");
715 return ret;
716 }
Felipe Balbi51e1e7b2012-07-19 14:09:48 +0300717 }
718
Felipe Balbid105e7f2013-03-15 10:52:08 +0200719 if (IS_ERR(dwc->usb3_phy)) {
Ruchika Kharwar315955d72013-07-04 00:59:34 -0500720 ret = PTR_ERR(dwc->usb3_phy);
Kishon Vijay Abraham I122f06e2014-03-03 17:08:10 +0530721 if (ret == -ENXIO || ret == -ENODEV) {
722 dwc->usb3_phy = NULL;
723 } else if (ret == -EPROBE_DEFER) {
Felipe Balbid105e7f2013-03-15 10:52:08 +0200724 return ret;
Kishon Vijay Abraham I122f06e2014-03-03 17:08:10 +0530725 } else {
726 dev_err(dev, "no usb3 phy configured\n");
727 return ret;
728 }
Felipe Balbi51e1e7b2012-07-19 14:09:48 +0300729 }
730
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +0530731 dwc->usb2_generic_phy = devm_phy_get(dev, "usb2-phy");
732 if (IS_ERR(dwc->usb2_generic_phy)) {
733 ret = PTR_ERR(dwc->usb2_generic_phy);
734 if (ret == -ENOSYS || ret == -ENODEV) {
735 dwc->usb2_generic_phy = NULL;
736 } else if (ret == -EPROBE_DEFER) {
737 return ret;
738 } else {
739 dev_err(dev, "no usb2 phy configured\n");
740 return ret;
741 }
742 }
743
744 dwc->usb3_generic_phy = devm_phy_get(dev, "usb3-phy");
745 if (IS_ERR(dwc->usb3_generic_phy)) {
746 ret = PTR_ERR(dwc->usb3_generic_phy);
747 if (ret == -ENOSYS || ret == -ENODEV) {
748 dwc->usb3_generic_phy = NULL;
749 } else if (ret == -EPROBE_DEFER) {
750 return ret;
751 } else {
752 dev_err(dev, "no usb3 phy configured\n");
753 return ret;
754 }
755 }
756
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500757 return 0;
758}
759
Felipe Balbi5f94adf2014-04-16 15:13:45 -0500760static int dwc3_core_init_mode(struct dwc3 *dwc)
761{
762 struct device *dev = dwc->dev;
763 int ret;
764
765 switch (dwc->dr_mode) {
766 case USB_DR_MODE_PERIPHERAL:
767 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
768 ret = dwc3_gadget_init(dwc);
769 if (ret) {
770 dev_err(dev, "failed to initialize gadget\n");
771 return ret;
772 }
773 break;
774 case USB_DR_MODE_HOST:
775 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
776 ret = dwc3_host_init(dwc);
777 if (ret) {
778 dev_err(dev, "failed to initialize host\n");
779 return ret;
780 }
781 break;
782 case USB_DR_MODE_OTG:
783 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
784 ret = dwc3_host_init(dwc);
785 if (ret) {
786 dev_err(dev, "failed to initialize host\n");
787 return ret;
788 }
789
790 ret = dwc3_gadget_init(dwc);
791 if (ret) {
792 dev_err(dev, "failed to initialize gadget\n");
793 return ret;
794 }
795 break;
796 default:
797 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
798 return -EINVAL;
799 }
800
801 return 0;
802}
803
804static void dwc3_core_exit_mode(struct dwc3 *dwc)
805{
806 switch (dwc->dr_mode) {
807 case USB_DR_MODE_PERIPHERAL:
808 dwc3_gadget_exit(dwc);
809 break;
810 case USB_DR_MODE_HOST:
811 dwc3_host_exit(dwc);
812 break;
813 case USB_DR_MODE_OTG:
814 dwc3_host_exit(dwc);
815 dwc3_gadget_exit(dwc);
816 break;
817 default:
818 /* do nothing */
819 break;
820 }
821}
822
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500823#define DWC3_ALIGN_MASK (16 - 1)
824
825static int dwc3_probe(struct platform_device *pdev)
826{
827 struct device *dev = &pdev->dev;
828 struct dwc3_platform_data *pdata = dev_get_platdata(dev);
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500829 struct resource *res;
830 struct dwc3 *dwc;
Huang Rui80caf7d2014-10-28 19:54:26 +0800831 u8 lpm_nyet_threshold;
Huang Rui6b6a0c92014-10-31 11:11:12 +0800832 u8 tx_de_emphasis;
Huang Rui460d0982014-10-31 11:11:18 +0800833 u8 hird_threshold;
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500834
Andy Shevchenkob09e99e2014-05-15 15:53:32 +0300835 int ret;
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500836
837 void __iomem *regs;
838 void *mem;
839
840 mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
Jingoo Han734d5a52014-07-17 12:45:11 +0900841 if (!mem)
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500842 return -ENOMEM;
Jingoo Han734d5a52014-07-17 12:45:11 +0900843
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500844 dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
845 dwc->mem = mem;
846 dwc->dev = dev;
847
848 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
849 if (!res) {
850 dev_err(dev, "missing IRQ\n");
851 return -ENODEV;
852 }
853 dwc->xhci_resources[1].start = res->start;
854 dwc->xhci_resources[1].end = res->end;
855 dwc->xhci_resources[1].flags = res->flags;
856 dwc->xhci_resources[1].name = res->name;
857
858 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
859 if (!res) {
860 dev_err(dev, "missing memory resource\n");
861 return -ENODEV;
862 }
863
Vivek Gautamf32a5e22014-06-04 14:34:52 +0530864 dwc->xhci_resources[0].start = res->start;
865 dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
866 DWC3_XHCI_REGS_END;
867 dwc->xhci_resources[0].flags = res->flags;
868 dwc->xhci_resources[0].name = res->name;
869
870 res->start += DWC3_GLOBALS_REGS_START;
871
872 /*
873 * Request memory region but exclude xHCI regs,
874 * since it will be requested by the xhci-plat driver.
875 */
876 regs = devm_ioremap_resource(dev, res);
Felipe Balbi3da1f6e2014-09-02 15:19:43 -0500877 if (IS_ERR(regs)) {
878 ret = PTR_ERR(regs);
879 goto err0;
880 }
Vivek Gautamf32a5e22014-06-04 14:34:52 +0530881
882 dwc->regs = regs;
883 dwc->regs_size = resource_size(res);
Vivek Gautamf32a5e22014-06-04 14:34:52 +0530884
Huang Rui80caf7d2014-10-28 19:54:26 +0800885 /* default to highest possible threshold */
886 lpm_nyet_threshold = 0xff;
887
Huang Rui6b6a0c92014-10-31 11:11:12 +0800888 /* default to -3.5dB de-emphasis */
889 tx_de_emphasis = 1;
890
Huang Rui460d0982014-10-31 11:11:18 +0800891 /*
892 * default to assert utmi_sleep_n and use maximum allowed HIRD
893 * threshold value of 0b1100
894 */
895 hird_threshold = 12;
896
Heikki Krogerus63863b92015-09-21 11:14:32 +0300897 dwc->maximum_speed = usb_get_maximum_speed(dev);
Heikki Krogerus06e71142015-09-21 11:14:34 +0300898 dwc->dr_mode = usb_get_dr_mode(dev);
Heikki Krogerus63863b92015-09-21 11:14:32 +0300899
Heikki Krogerus3d128912015-09-21 11:14:35 +0300900 dwc->has_lpm_erratum = device_property_read_bool(dev,
Huang Rui80caf7d2014-10-28 19:54:26 +0800901 "snps,has-lpm-erratum");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300902 device_property_read_u8(dev, "snps,lpm-nyet-threshold",
Huang Rui80caf7d2014-10-28 19:54:26 +0800903 &lpm_nyet_threshold);
Heikki Krogerus3d128912015-09-21 11:14:35 +0300904 dwc->is_utmi_l1_suspend = device_property_read_bool(dev,
Huang Rui460d0982014-10-31 11:11:18 +0800905 "snps,is-utmi-l1-suspend");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300906 device_property_read_u8(dev, "snps,hird-threshold",
Huang Rui460d0982014-10-31 11:11:18 +0800907 &hird_threshold);
Heikki Krogerus3d128912015-09-21 11:14:35 +0300908 dwc->usb3_lpm_capable = device_property_read_bool(dev,
Robert Baldygaeac68e82015-03-09 15:06:12 +0100909 "snps,usb3_lpm_capable");
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500910
Heikki Krogerus3d128912015-09-21 11:14:35 +0300911 dwc->disable_scramble_quirk = device_property_read_bool(dev,
Huang Rui3b812212014-10-28 19:54:25 +0800912 "snps,disable_scramble_quirk");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300913 dwc->u2exit_lfps_quirk = device_property_read_bool(dev,
Huang Rui9a5b2f32014-10-28 19:54:27 +0800914 "snps,u2exit_lfps_quirk");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300915 dwc->u2ss_inp3_quirk = device_property_read_bool(dev,
Huang Ruib5a65c42014-10-28 19:54:28 +0800916 "snps,u2ss_inp3_quirk");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300917 dwc->req_p1p2p3_quirk = device_property_read_bool(dev,
Huang Ruidf31f5b2014-10-28 19:54:29 +0800918 "snps,req_p1p2p3_quirk");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300919 dwc->del_p1p2p3_quirk = device_property_read_bool(dev,
Huang Ruia2a1d0f2014-10-28 19:54:30 +0800920 "snps,del_p1p2p3_quirk");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300921 dwc->del_phy_power_chg_quirk = device_property_read_bool(dev,
Huang Rui41c06ff2014-10-28 19:54:31 +0800922 "snps,del_phy_power_chg_quirk");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300923 dwc->lfps_filter_quirk = device_property_read_bool(dev,
Huang Ruifb67afc2014-10-28 19:54:32 +0800924 "snps,lfps_filter_quirk");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300925 dwc->rx_detect_poll_quirk = device_property_read_bool(dev,
Huang Rui14f4ac52014-10-28 19:54:33 +0800926 "snps,rx_detect_poll_quirk");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300927 dwc->dis_u3_susphy_quirk = device_property_read_bool(dev,
Huang Rui59acfa22014-10-31 11:11:13 +0800928 "snps,dis_u3_susphy_quirk");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300929 dwc->dis_u2_susphy_quirk = device_property_read_bool(dev,
Huang Rui0effe0a2014-10-31 11:11:14 +0800930 "snps,dis_u2_susphy_quirk");
John Younec791d12015-10-02 20:30:57 -0700931 dwc->dis_enblslpm_quirk = device_property_read_bool(dev,
932 "snps,dis_enblslpm_quirk");
Rajesh Bhagate58dd352016-03-14 14:40:50 +0530933 dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev,
934 "snps,dis_rxdet_inp3_quirk");
Huang Rui6b6a0c92014-10-31 11:11:12 +0800935
Heikki Krogerus3d128912015-09-21 11:14:35 +0300936 dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
Huang Rui6b6a0c92014-10-31 11:11:12 +0800937 "snps,tx_de_emphasis_quirk");
Heikki Krogerus3d128912015-09-21 11:14:35 +0300938 device_property_read_u8(dev, "snps,tx_de_emphasis",
Huang Rui6b6a0c92014-10-31 11:11:12 +0800939 &tx_de_emphasis);
Heikki Krogerus3d128912015-09-21 11:14:35 +0300940 device_property_read_string(dev, "snps,hsphy_interface",
941 &dwc->hsphy_interface);
942 device_property_read_u32(dev, "snps,quirk-frame-length-adjustment",
Felipe Balbibcdb3272016-05-16 10:42:23 +0300943 &dwc->fladj);
Heikki Krogerus3d128912015-09-21 11:14:35 +0300944
945 if (pdata) {
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500946 dwc->maximum_speed = pdata->maximum_speed;
Huang Rui80caf7d2014-10-28 19:54:26 +0800947 dwc->has_lpm_erratum = pdata->has_lpm_erratum;
948 if (pdata->lpm_nyet_threshold)
949 lpm_nyet_threshold = pdata->lpm_nyet_threshold;
Huang Rui460d0982014-10-31 11:11:18 +0800950 dwc->is_utmi_l1_suspend = pdata->is_utmi_l1_suspend;
951 if (pdata->hird_threshold)
952 hird_threshold = pdata->hird_threshold;
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500953
Robert Baldygaeac68e82015-03-09 15:06:12 +0100954 dwc->usb3_lpm_capable = pdata->usb3_lpm_capable;
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500955 dwc->dr_mode = pdata->dr_mode;
Huang Rui3b812212014-10-28 19:54:25 +0800956
957 dwc->disable_scramble_quirk = pdata->disable_scramble_quirk;
Huang Rui9a5b2f32014-10-28 19:54:27 +0800958 dwc->u2exit_lfps_quirk = pdata->u2exit_lfps_quirk;
Huang Ruib5a65c42014-10-28 19:54:28 +0800959 dwc->u2ss_inp3_quirk = pdata->u2ss_inp3_quirk;
Huang Ruidf31f5b2014-10-28 19:54:29 +0800960 dwc->req_p1p2p3_quirk = pdata->req_p1p2p3_quirk;
Huang Ruia2a1d0f2014-10-28 19:54:30 +0800961 dwc->del_p1p2p3_quirk = pdata->del_p1p2p3_quirk;
Huang Rui41c06ff2014-10-28 19:54:31 +0800962 dwc->del_phy_power_chg_quirk = pdata->del_phy_power_chg_quirk;
Huang Ruifb67afc2014-10-28 19:54:32 +0800963 dwc->lfps_filter_quirk = pdata->lfps_filter_quirk;
Huang Rui14f4ac52014-10-28 19:54:33 +0800964 dwc->rx_detect_poll_quirk = pdata->rx_detect_poll_quirk;
Huang Rui59acfa22014-10-31 11:11:13 +0800965 dwc->dis_u3_susphy_quirk = pdata->dis_u3_susphy_quirk;
Huang Rui0effe0a2014-10-31 11:11:14 +0800966 dwc->dis_u2_susphy_quirk = pdata->dis_u2_susphy_quirk;
John Younec791d12015-10-02 20:30:57 -0700967 dwc->dis_enblslpm_quirk = pdata->dis_enblslpm_quirk;
Rajesh Bhagate58dd352016-03-14 14:40:50 +0530968 dwc->dis_rxdet_inp3_quirk = pdata->dis_rxdet_inp3_quirk;
Huang Rui6b6a0c92014-10-31 11:11:12 +0800969
970 dwc->tx_de_emphasis_quirk = pdata->tx_de_emphasis_quirk;
971 if (pdata->tx_de_emphasis)
972 tx_de_emphasis = pdata->tx_de_emphasis;
Heikki Krogerus3e10a2c2015-05-13 15:26:49 +0300973
974 dwc->hsphy_interface = pdata->hsphy_interface;
Felipe Balbibcdb3272016-05-16 10:42:23 +0300975 dwc->fladj = pdata->fladj_value;
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500976 }
977
Huang Rui80caf7d2014-10-28 19:54:26 +0800978 dwc->lpm_nyet_threshold = lpm_nyet_threshold;
Huang Rui6b6a0c92014-10-31 11:11:12 +0800979 dwc->tx_de_emphasis = tx_de_emphasis;
Huang Rui80caf7d2014-10-28 19:54:26 +0800980
Huang Rui460d0982014-10-31 11:11:18 +0800981 dwc->hird_threshold = hird_threshold
982 | (dwc->is_utmi_l1_suspend << 4);
983
Heikki Krogerus6c89cce02015-05-13 15:26:45 +0300984 platform_set_drvdata(pdev, dwc);
Heikki Krogerus2917e712015-05-13 15:26:46 +0300985 dwc3_cache_hwparams(dwc);
Heikki Krogerus6c89cce02015-05-13 15:26:45 +0300986
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500987 ret = dwc3_core_get_phy(dwc);
988 if (ret)
Felipe Balbi3da1f6e2014-09-02 15:19:43 -0500989 goto err0;
Felipe Balbi3c9f94a2014-04-16 15:08:29 -0500990
Felipe Balbi72246da2011-08-19 18:10:58 +0300991 spin_lock_init(&dwc->lock);
Felipe Balbi72246da2011-08-19 18:10:58 +0300992
Heikki Krogerus19bacdc2014-09-24 11:00:38 +0300993 if (!dev->dma_mask) {
994 dev->dma_mask = dev->parent->dma_mask;
995 dev->dma_parms = dev->parent->dma_parms;
996 dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask);
997 }
Kishon Vijay Abraham Iddff14f2013-03-07 18:51:43 +0530998
Chanho Park802ca852012-02-15 18:27:55 +0900999 pm_runtime_enable(dev);
1000 pm_runtime_get_sync(dev);
1001 pm_runtime_forbid(dev);
Felipe Balbi72246da2011-08-19 18:10:58 +03001002
Felipe Balbi39214262012-10-11 13:54:36 +03001003 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
1004 if (ret) {
1005 dev_err(dwc->dev, "failed to allocate event buffers\n");
1006 ret = -ENOMEM;
Felipe Balbic499ff72016-05-16 10:49:01 +03001007 goto err0;
Felipe Balbi39214262012-10-11 13:54:36 +03001008 }
1009
Felipe Balbi32a4a132014-02-25 14:00:13 -06001010 if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
1011 dwc->dr_mode = USB_DR_MODE_HOST;
1012 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
1013 dwc->dr_mode = USB_DR_MODE_PERIPHERAL;
1014
1015 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
1016 dwc->dr_mode = USB_DR_MODE_OTG;
1017
Felipe Balbic499ff72016-05-16 10:49:01 +03001018 ret = dwc3_alloc_scratch_buffers(dwc);
1019 if (ret)
1020 goto err1;
1021
Felipe Balbi72246da2011-08-19 18:10:58 +03001022 ret = dwc3_core_init(dwc);
1023 if (ret) {
Chanho Park802ca852012-02-15 18:27:55 +09001024 dev_err(dev, "failed to initialize core\n");
Felipe Balbic499ff72016-05-16 10:49:01 +03001025 goto err2;
Felipe Balbi72246da2011-08-19 18:10:58 +03001026 }
1027
John Youn77966eb2016-02-19 17:31:01 -08001028 /* Check the maximum_speed parameter */
1029 switch (dwc->maximum_speed) {
1030 case USB_SPEED_LOW:
1031 case USB_SPEED_FULL:
1032 case USB_SPEED_HIGH:
1033 case USB_SPEED_SUPER:
1034 case USB_SPEED_SUPER_PLUS:
1035 break;
1036 default:
1037 dev_err(dev, "invalid maximum_speed parameter %d\n",
1038 dwc->maximum_speed);
1039 /* fall through */
1040 case USB_SPEED_UNKNOWN:
1041 /* default to superspeed */
John Youn2c7f1bd2016-02-05 17:08:59 -08001042 dwc->maximum_speed = USB_SPEED_SUPER;
1043
1044 /*
1045 * default to superspeed plus if we are capable.
1046 */
1047 if (dwc3_is_usb31(dwc) &&
1048 (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
1049 DWC3_GHWPARAMS3_SSPHY_IFC_GEN2))
1050 dwc->maximum_speed = USB_SPEED_SUPER_PLUS;
John Youn77966eb2016-02-19 17:31:01 -08001051
1052 break;
John Youn2c7f1bd2016-02-05 17:08:59 -08001053 }
1054
Felipe Balbi5f94adf2014-04-16 15:13:45 -05001055 ret = dwc3_core_init_mode(dwc);
1056 if (ret)
Felipe Balbic499ff72016-05-16 10:49:01 +03001057 goto err3;
Felipe Balbi72246da2011-08-19 18:10:58 +03001058
Du, Changbin4e9f3112016-04-12 19:10:18 +08001059 dwc3_debugfs_init(dwc);
Chanho Park802ca852012-02-15 18:27:55 +09001060 pm_runtime_allow(dev);
Felipe Balbi72246da2011-08-19 18:10:58 +03001061
1062 return 0;
1063
Felipe Balbic499ff72016-05-16 10:49:01 +03001064err3:
Felipe Balbif122d332013-02-08 15:15:11 +02001065 dwc3_event_buffers_cleanup(dwc);
1066
Felipe Balbi3da1f6e2014-09-02 15:19:43 -05001067err2:
Felipe Balbic499ff72016-05-16 10:49:01 +03001068 dwc3_free_scratch_buffers(dwc);
Felipe Balbi72246da2011-08-19 18:10:58 +03001069
Felipe Balbi3da1f6e2014-09-02 15:19:43 -05001070err1:
Felipe Balbi39214262012-10-11 13:54:36 +03001071 dwc3_free_event_buffers(dwc);
Heikki Krogerus88bc9d12015-05-13 15:26:51 +03001072 dwc3_ulpi_exit(dwc);
Felipe Balbi39214262012-10-11 13:54:36 +03001073
Felipe Balbi3da1f6e2014-09-02 15:19:43 -05001074err0:
1075 /*
1076 * restore res->start back to its original value so that, in case the
1077 * probe is deferred, we don't end up getting error in request the
1078 * memory region the next time probe is called.
1079 */
1080 res->start -= DWC3_GLOBALS_REGS_START;
1081
Felipe Balbi72246da2011-08-19 18:10:58 +03001082 return ret;
1083}
1084
Bill Pembertonfb4e98a2012-11-19 13:26:20 -05001085static int dwc3_remove(struct platform_device *pdev)
Felipe Balbi72246da2011-08-19 18:10:58 +03001086{
Felipe Balbi72246da2011-08-19 18:10:58 +03001087 struct dwc3 *dwc = platform_get_drvdata(pdev);
Felipe Balbi3da1f6e2014-09-02 15:19:43 -05001088 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1089
1090 /*
1091 * restore res->start back to its original value so that, in case the
1092 * probe is deferred, we don't end up getting error in request the
1093 * memory region the next time probe is called.
1094 */
1095 res->start -= DWC3_GLOBALS_REGS_START;
Felipe Balbi72246da2011-08-19 18:10:58 +03001096
Felipe Balbidc99f162014-09-03 16:13:37 -05001097 dwc3_debugfs_exit(dwc);
1098 dwc3_core_exit_mode(dwc);
Kishon Vijay Abraham I8ba007a2013-01-25 08:30:54 +05301099
Felipe Balbi72246da2011-08-19 18:10:58 +03001100 dwc3_core_exit(dwc);
Heikki Krogerus88bc9d12015-05-13 15:26:51 +03001101 dwc3_ulpi_exit(dwc);
Felipe Balbi72246da2011-08-19 18:10:58 +03001102
Felipe Balbic499ff72016-05-16 10:49:01 +03001103 dwc3_free_event_buffers(dwc);
1104 dwc3_free_scratch_buffers(dwc);
1105
Felipe Balbi7415f172012-04-30 14:56:33 +03001106 pm_runtime_put_sync(&pdev->dev);
1107 pm_runtime_disable(&pdev->dev);
1108
Felipe Balbi72246da2011-08-19 18:10:58 +03001109 return 0;
1110}
1111
Felipe Balbi7415f172012-04-30 14:56:33 +03001112#ifdef CONFIG_PM_SLEEP
Felipe Balbi7415f172012-04-30 14:56:33 +03001113static int dwc3_suspend(struct device *dev)
1114{
1115 struct dwc3 *dwc = dev_get_drvdata(dev);
1116 unsigned long flags;
1117
1118 spin_lock_irqsave(&dwc->lock, flags);
1119
Ruchika Kharwara45c82b82013-07-06 07:52:49 -05001120 switch (dwc->dr_mode) {
1121 case USB_DR_MODE_PERIPHERAL:
1122 case USB_DR_MODE_OTG:
Felipe Balbi7415f172012-04-30 14:56:33 +03001123 dwc3_gadget_suspend(dwc);
1124 /* FALLTHROUGH */
Ruchika Kharwara45c82b82013-07-06 07:52:49 -05001125 case USB_DR_MODE_HOST:
Felipe Balbi7415f172012-04-30 14:56:33 +03001126 default:
Felipe Balbi0b0231a2014-10-07 10:19:23 -05001127 dwc3_event_buffers_cleanup(dwc);
Felipe Balbi7415f172012-04-30 14:56:33 +03001128 break;
1129 }
1130
1131 dwc->gctl = dwc3_readl(dwc->regs, DWC3_GCTL);
1132 spin_unlock_irqrestore(&dwc->lock, flags);
1133
1134 usb_phy_shutdown(dwc->usb3_phy);
1135 usb_phy_shutdown(dwc->usb2_phy);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +05301136 phy_exit(dwc->usb2_generic_phy);
1137 phy_exit(dwc->usb3_generic_phy);
Felipe Balbi7415f172012-04-30 14:56:33 +03001138
Felipe Balbi5c4ad3182016-04-11 17:12:34 +03001139 usb_phy_set_suspend(dwc->usb2_phy, 1);
1140 usb_phy_set_suspend(dwc->usb3_phy, 1);
1141 WARN_ON(phy_power_off(dwc->usb2_generic_phy) < 0);
1142 WARN_ON(phy_power_off(dwc->usb3_generic_phy) < 0);
1143
Sekhar Nori63444752015-08-31 21:09:08 +05301144 pinctrl_pm_select_sleep_state(dev);
1145
Felipe Balbi7415f172012-04-30 14:56:33 +03001146 return 0;
1147}
1148
1149static int dwc3_resume(struct device *dev)
1150{
1151 struct dwc3 *dwc = dev_get_drvdata(dev);
1152 unsigned long flags;
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +05301153 int ret;
Felipe Balbi7415f172012-04-30 14:56:33 +03001154
Sekhar Nori63444752015-08-31 21:09:08 +05301155 pinctrl_pm_select_default_state(dev);
1156
Felipe Balbi5c4ad3182016-04-11 17:12:34 +03001157 usb_phy_set_suspend(dwc->usb2_phy, 0);
1158 usb_phy_set_suspend(dwc->usb3_phy, 0);
1159 ret = phy_power_on(dwc->usb2_generic_phy);
1160 if (ret < 0)
1161 return ret;
1162
1163 ret = phy_power_on(dwc->usb3_generic_phy);
1164 if (ret < 0)
1165 goto err_usb2phy_power;
1166
Felipe Balbi7415f172012-04-30 14:56:33 +03001167 usb_phy_init(dwc->usb3_phy);
1168 usb_phy_init(dwc->usb2_phy);
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +05301169 ret = phy_init(dwc->usb2_generic_phy);
1170 if (ret < 0)
Felipe Balbi5c4ad3182016-04-11 17:12:34 +03001171 goto err_usb3phy_power;
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +05301172
1173 ret = phy_init(dwc->usb3_generic_phy);
1174 if (ret < 0)
1175 goto err_usb2phy_init;
Felipe Balbi7415f172012-04-30 14:56:33 +03001176
1177 spin_lock_irqsave(&dwc->lock, flags);
1178
Felipe Balbi0b0231a2014-10-07 10:19:23 -05001179 dwc3_event_buffers_setup(dwc);
Felipe Balbi7415f172012-04-30 14:56:33 +03001180 dwc3_writel(dwc->regs, DWC3_GCTL, dwc->gctl);
1181
Ruchika Kharwara45c82b82013-07-06 07:52:49 -05001182 switch (dwc->dr_mode) {
1183 case USB_DR_MODE_PERIPHERAL:
1184 case USB_DR_MODE_OTG:
Felipe Balbi7415f172012-04-30 14:56:33 +03001185 dwc3_gadget_resume(dwc);
1186 /* FALLTHROUGH */
Ruchika Kharwara45c82b82013-07-06 07:52:49 -05001187 case USB_DR_MODE_HOST:
Felipe Balbi7415f172012-04-30 14:56:33 +03001188 default:
1189 /* do nothing */
1190 break;
1191 }
1192
1193 spin_unlock_irqrestore(&dwc->lock, flags);
1194
1195 pm_runtime_disable(dev);
1196 pm_runtime_set_active(dev);
1197 pm_runtime_enable(dev);
1198
1199 return 0;
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +05301200
1201err_usb2phy_init:
1202 phy_exit(dwc->usb2_generic_phy);
1203
Felipe Balbi5c4ad3182016-04-11 17:12:34 +03001204err_usb3phy_power:
1205 phy_power_off(dwc->usb3_generic_phy);
1206
1207err_usb2phy_power:
1208 phy_power_off(dwc->usb2_generic_phy);
1209
Kishon Vijay Abraham I57303482014-03-03 17:08:11 +05301210 return ret;
Felipe Balbi7415f172012-04-30 14:56:33 +03001211}
Felipe Balbi7f370ed2016-05-09 15:27:01 +03001212#endif /* CONFIG_PM_SLEEP */
Felipe Balbi7415f172012-04-30 14:56:33 +03001213
1214static const struct dev_pm_ops dwc3_dev_pm_ops = {
Felipe Balbi7415f172012-04-30 14:56:33 +03001215 SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
1216};
1217
Kishon Vijay Abraham I5088b6f2013-01-25 16:36:53 +05301218#ifdef CONFIG_OF
1219static const struct of_device_id of_dwc3_match[] = {
1220 {
Felipe Balbi22a5aa12013-07-02 21:20:24 +03001221 .compatible = "snps,dwc3"
1222 },
1223 {
Kishon Vijay Abraham I5088b6f2013-01-25 16:36:53 +05301224 .compatible = "synopsys,dwc3"
1225 },
1226 { },
1227};
1228MODULE_DEVICE_TABLE(of, of_dwc3_match);
1229#endif
1230
Heikki Krogerus404905a2014-09-25 10:57:02 +03001231#ifdef CONFIG_ACPI
1232
1233#define ACPI_ID_INTEL_BSW "808622B7"
1234
1235static const struct acpi_device_id dwc3_acpi_match[] = {
1236 { ACPI_ID_INTEL_BSW, 0 },
1237 { },
1238};
1239MODULE_DEVICE_TABLE(acpi, dwc3_acpi_match);
1240#endif
1241
Felipe Balbi72246da2011-08-19 18:10:58 +03001242static struct platform_driver dwc3_driver = {
1243 .probe = dwc3_probe,
Bill Pemberton76904172012-11-19 13:21:08 -05001244 .remove = dwc3_remove,
Felipe Balbi72246da2011-08-19 18:10:58 +03001245 .driver = {
1246 .name = "dwc3",
Kishon Vijay Abraham I5088b6f2013-01-25 16:36:53 +05301247 .of_match_table = of_match_ptr(of_dwc3_match),
Heikki Krogerus404905a2014-09-25 10:57:02 +03001248 .acpi_match_table = ACPI_PTR(dwc3_acpi_match),
Felipe Balbi7f370ed2016-05-09 15:27:01 +03001249 .pm = &dwc3_dev_pm_ops,
Felipe Balbi72246da2011-08-19 18:10:58 +03001250 },
Felipe Balbi72246da2011-08-19 18:10:58 +03001251};
1252
Tobias Klauserb1116dc2012-02-28 12:57:20 +01001253module_platform_driver(dwc3_driver);
1254
Sebastian Andrzej Siewior7ae4fc42011-10-19 19:39:50 +02001255MODULE_ALIAS("platform:dwc3");
Felipe Balbi72246da2011-08-19 18:10:58 +03001256MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
Felipe Balbi5945f782013-06-30 14:15:11 +03001257MODULE_LICENSE("GPL v2");
Felipe Balbi72246da2011-08-19 18:10:58 +03001258MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");