blob: 6ad1000c9af63f1bb7c332e2b21575037354f149 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +05302/**
3 * core.c - DesignWare USB3 DRD Controller Core file
4 *
Kishon Vijay Abraham Id1e431a2015-02-23 18:39:52 +05305 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +05306 *
7 * Authors: Felipe Balbi <balbi@ti.com>,
8 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
9 *
Kishon Vijay Abraham Id1e431a2015-02-23 18:39:52 +053010 * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/core.c) and ported
11 * to uboot.
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053012 *
Kishon Vijay Abraham Id1e431a2015-02-23 18:39:52 +053013 * commit cd72f890d2 : usb: dwc3: core: enable phy suspend quirk on non-FPGA
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053014 */
15
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +053016#include <common.h>
Simon Glass63334482019-11-14 12:57:39 -070017#include <cpu_func.h>
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +053018#include <malloc.h>
Kishon Vijay Abraham Ibfbf05d2015-02-23 18:40:04 +053019#include <dwc3-uboot.h>
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +053020#include <asm/dma-mapping.h>
Simon Glass9bc15642020-02-03 07:36:16 -070021#include <dm/device_compat.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070022#include <dm/devres.h>
23#include <linux/err.h>
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053024#include <linux/ioport.h>
Mugunthan V N121f93c2018-05-18 13:10:27 +020025#include <dm.h>
Jean-Jacques Hiblot3de978a2018-11-29 10:52:45 +010026#include <generic-phy.h>
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053027#include <linux/usb/ch9.h>
28#include <linux/usb/gadget.h>
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053029
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053030#include "core.h"
31#include "gadget.h"
32#include "io.h"
33
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +053034#include "linux-compat.h"
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053035
Kishon Vijay Abraham Idc5c6532015-02-23 18:40:05 +053036static LIST_HEAD(dwc3_list);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053037/* -------------------------------------------------------------------------- */
38
Joonyoung Shimbf35c602015-03-03 17:32:09 +010039static void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053040{
41 u32 reg;
42
43 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
44 reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
45 reg |= DWC3_GCTL_PRTCAPDIR(mode);
46 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
47}
48
49/**
50 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
51 * @dwc: pointer to our context structure
52 */
53static int dwc3_core_soft_reset(struct dwc3 *dwc)
54{
55 u32 reg;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053056
57 /* Before Resetting PHY, put Core in Reset */
58 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
59 reg |= DWC3_GCTL_CORESOFTRESET;
60 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
61
62 /* Assert USB3 PHY reset */
63 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
64 reg |= DWC3_GUSB3PIPECTL_PHYSOFTRST;
65 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
66
67 /* Assert USB2 PHY reset */
68 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
69 reg |= DWC3_GUSB2PHYCFG_PHYSOFTRST;
70 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
71
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +053072 mdelay(100);
73
74 /* Clear 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 /* Clear 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
84 mdelay(100);
85
86 /* After PHYs are stable we can take Core out of reset state */
87 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
88 reg &= ~DWC3_GCTL_CORESOFTRESET;
89 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
90
91 return 0;
92}
93
94/**
95 * dwc3_free_one_event_buffer - Frees one event buffer
96 * @dwc: Pointer to our controller context structure
97 * @evt: Pointer to event buffer to be freed
98 */
99static void dwc3_free_one_event_buffer(struct dwc3 *dwc,
100 struct dwc3_event_buffer *evt)
101{
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530102 dma_free_coherent(evt->buf);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530103}
104
105/**
106 * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
107 * @dwc: Pointer to our controller context structure
108 * @length: size of the event buffer
109 *
110 * Returns a pointer to the allocated event buffer structure on success
111 * otherwise ERR_PTR(errno).
112 */
113static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
114 unsigned length)
115{
116 struct dwc3_event_buffer *evt;
117
Mugunthan V N121f93c2018-05-18 13:10:27 +0200118 evt = devm_kzalloc((struct udevice *)dwc->dev, sizeof(*evt),
119 GFP_KERNEL);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530120 if (!evt)
121 return ERR_PTR(-ENOMEM);
122
123 evt->dwc = dwc;
124 evt->length = length;
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530125 evt->buf = dma_alloc_coherent(length,
126 (unsigned long *)&evt->dma);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530127 if (!evt->buf)
128 return ERR_PTR(-ENOMEM);
129
Philipp Tomsich8e17c162017-04-06 16:58:53 +0200130 dwc3_flush_cache((uintptr_t)evt->buf, evt->length);
131
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530132 return evt;
133}
134
135/**
136 * dwc3_free_event_buffers - frees all allocated event buffers
137 * @dwc: Pointer to our controller context structure
138 */
139static void dwc3_free_event_buffers(struct dwc3 *dwc)
140{
141 struct dwc3_event_buffer *evt;
142 int i;
143
144 for (i = 0; i < dwc->num_event_buffers; i++) {
145 evt = dwc->ev_buffs[i];
146 if (evt)
147 dwc3_free_one_event_buffer(dwc, evt);
148 }
149}
150
151/**
152 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
153 * @dwc: pointer to our controller context structure
154 * @length: size of event buffer
155 *
156 * Returns 0 on success otherwise negative errno. In the error case, dwc
157 * may contain some buffers allocated but not all which were requested.
158 */
159static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length)
160{
161 int num;
162 int i;
163
164 num = DWC3_NUM_INT(dwc->hwparams.hwparams1);
165 dwc->num_event_buffers = num;
166
Kishon Vijay Abraham Ic7bdfe32015-02-23 18:40:13 +0530167 dwc->ev_buffs = memalign(CONFIG_SYS_CACHELINE_SIZE,
168 sizeof(*dwc->ev_buffs) * num);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530169 if (!dwc->ev_buffs)
170 return -ENOMEM;
171
172 for (i = 0; i < num; i++) {
173 struct dwc3_event_buffer *evt;
174
175 evt = dwc3_alloc_one_event_buffer(dwc, length);
176 if (IS_ERR(evt)) {
177 dev_err(dwc->dev, "can't allocate event buffer\n");
178 return PTR_ERR(evt);
179 }
180 dwc->ev_buffs[i] = evt;
181 }
182
183 return 0;
184}
185
186/**
187 * dwc3_event_buffers_setup - setup our allocated event buffers
188 * @dwc: pointer to our controller context structure
189 *
190 * Returns 0 on success otherwise negative errno.
191 */
192static int dwc3_event_buffers_setup(struct dwc3 *dwc)
193{
194 struct dwc3_event_buffer *evt;
195 int n;
196
197 for (n = 0; n < dwc->num_event_buffers; n++) {
198 evt = dwc->ev_buffs[n];
199 dev_dbg(dwc->dev, "Event buf %p dma %08llx length %d\n",
200 evt->buf, (unsigned long long) evt->dma,
201 evt->length);
202
203 evt->lpos = 0;
204
205 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n),
206 lower_32_bits(evt->dma));
207 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n),
208 upper_32_bits(evt->dma));
209 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n),
210 DWC3_GEVNTSIZ_SIZE(evt->length));
211 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
212 }
213
214 return 0;
215}
216
217static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
218{
219 struct dwc3_event_buffer *evt;
220 int n;
221
222 for (n = 0; n < dwc->num_event_buffers; n++) {
223 evt = dwc->ev_buffs[n];
224
225 evt->lpos = 0;
226
227 dwc3_writel(dwc->regs, DWC3_GEVNTADRLO(n), 0);
228 dwc3_writel(dwc->regs, DWC3_GEVNTADRHI(n), 0);
229 dwc3_writel(dwc->regs, DWC3_GEVNTSIZ(n), DWC3_GEVNTSIZ_INTMASK
230 | DWC3_GEVNTSIZ_SIZE(0));
231 dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(n), 0);
232 }
233}
234
235static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
236{
237 if (!dwc->has_hibernation)
238 return 0;
239
240 if (!dwc->nr_scratch)
241 return 0;
242
243 dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
244 DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
245 if (!dwc->scratchbuf)
246 return -ENOMEM;
247
248 return 0;
249}
250
251static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
252{
253 dma_addr_t scratch_addr;
254 u32 param;
255 int ret;
256
257 if (!dwc->has_hibernation)
258 return 0;
259
260 if (!dwc->nr_scratch)
261 return 0;
262
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530263 scratch_addr = dma_map_single(dwc->scratchbuf,
264 dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
265 DMA_BIDIRECTIONAL);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530266 if (dma_mapping_error(dwc->dev, scratch_addr)) {
267 dev_err(dwc->dev, "failed to map scratch buffer\n");
268 ret = -EFAULT;
269 goto err0;
270 }
271
272 dwc->scratch_addr = scratch_addr;
273
274 param = lower_32_bits(scratch_addr);
275
276 ret = dwc3_send_gadget_generic_command(dwc,
277 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param);
278 if (ret < 0)
279 goto err1;
280
281 param = upper_32_bits(scratch_addr);
282
283 ret = dwc3_send_gadget_generic_command(dwc,
284 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param);
285 if (ret < 0)
286 goto err1;
287
288 return 0;
289
290err1:
Masahiro Yamada05a5dba2020-02-14 16:40:18 +0900291 dma_unmap_single(scratch_addr, dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
292 DMA_BIDIRECTIONAL);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530293
294err0:
295 return ret;
296}
297
298static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
299{
300 if (!dwc->has_hibernation)
301 return;
302
303 if (!dwc->nr_scratch)
304 return;
305
Masahiro Yamada05a5dba2020-02-14 16:40:18 +0900306 dma_unmap_single(dwc->scratch_addr, dwc->nr_scratch *
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530307 DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530308 kfree(dwc->scratchbuf);
309}
310
311static void dwc3_core_num_eps(struct dwc3 *dwc)
312{
313 struct dwc3_hwparams *parms = &dwc->hwparams;
314
315 dwc->num_in_eps = DWC3_NUM_IN_EPS(parms);
316 dwc->num_out_eps = DWC3_NUM_EPS(parms) - dwc->num_in_eps;
317
318 dev_vdbg(dwc->dev, "found %d IN and %d OUT endpoints\n",
319 dwc->num_in_eps, dwc->num_out_eps);
320}
321
322static void dwc3_cache_hwparams(struct dwc3 *dwc)
323{
324 struct dwc3_hwparams *parms = &dwc->hwparams;
325
326 parms->hwparams0 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS0);
327 parms->hwparams1 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS1);
328 parms->hwparams2 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS2);
329 parms->hwparams3 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
330 parms->hwparams4 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS4);
331 parms->hwparams5 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS5);
332 parms->hwparams6 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS6);
333 parms->hwparams7 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS7);
334 parms->hwparams8 = dwc3_readl(dwc->regs, DWC3_GHWPARAMS8);
335}
336
337/**
338 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
339 * @dwc: Pointer to our controller context structure
340 */
341static void dwc3_phy_setup(struct dwc3 *dwc)
342{
343 u32 reg;
344
345 reg = dwc3_readl(dwc->regs, DWC3_GUSB3PIPECTL(0));
346
347 /*
348 * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY
349 * to '0' during coreConsultant configuration. So default value
350 * will be '0' when the core is reset. Application needs to set it
351 * to '1' after the core initialization is completed.
352 */
353 if (dwc->revision > DWC3_REVISION_194A)
354 reg |= DWC3_GUSB3PIPECTL_SUSPHY;
355
356 if (dwc->u2ss_inp3_quirk)
357 reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK;
358
359 if (dwc->req_p1p2p3_quirk)
360 reg |= DWC3_GUSB3PIPECTL_REQP1P2P3;
361
362 if (dwc->del_p1p2p3_quirk)
363 reg |= DWC3_GUSB3PIPECTL_DEP1P2P3_EN;
364
365 if (dwc->del_phy_power_chg_quirk)
366 reg |= DWC3_GUSB3PIPECTL_DEPOCHANGE;
367
368 if (dwc->lfps_filter_quirk)
369 reg |= DWC3_GUSB3PIPECTL_LFPSFILT;
370
371 if (dwc->rx_detect_poll_quirk)
372 reg |= DWC3_GUSB3PIPECTL_RX_DETOPOLL;
373
374 if (dwc->tx_de_emphasis_quirk)
375 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc->tx_de_emphasis);
376
377 if (dwc->dis_u3_susphy_quirk)
378 reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
379
380 dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
381
382 mdelay(100);
383
384 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
385
386 /*
387 * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
388 * '0' during coreConsultant configuration. So default value will
389 * be '0' when the core is reset. Application needs to set it to
390 * '1' after the core initialization is completed.
391 */
392 if (dwc->revision > DWC3_REVISION_194A)
393 reg |= DWC3_GUSB2PHYCFG_SUSPHY;
394
395 if (dwc->dis_u2_susphy_quirk)
396 reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
397
398 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
399
400 mdelay(100);
401}
402
403/**
404 * dwc3_core_init - Low-level initialization of DWC3 Core
405 * @dwc: Pointer to our controller context structure
406 *
407 * Returns 0 on success otherwise negative errno.
408 */
409static int dwc3_core_init(struct dwc3 *dwc)
410{
411 unsigned long timeout;
412 u32 hwparams4 = dwc->hwparams.hwparams4;
413 u32 reg;
414 int ret;
415
416 reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
417 /* This should read as U3 followed by revision number */
418 if ((reg & DWC3_GSNPSID_MASK) != 0x55330000) {
419 dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
420 ret = -ENODEV;
421 goto err0;
422 }
423 dwc->revision = reg;
424
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530425 /* Handle USB2.0-only core configuration */
426 if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
427 DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
428 if (dwc->maximum_speed == USB_SPEED_SUPER)
429 dwc->maximum_speed = USB_SPEED_HIGH;
430 }
431
432 /* issue device SoftReset too */
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530433 timeout = 5000;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530434 dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST);
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530435 while (timeout--) {
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530436 reg = dwc3_readl(dwc->regs, DWC3_DCTL);
437 if (!(reg & DWC3_DCTL_CSFTRST))
438 break;
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530439 };
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530440
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530441 if (!timeout) {
442 dev_err(dwc->dev, "Reset Timed Out\n");
443 ret = -ETIMEDOUT;
444 goto err0;
445 }
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530446
T Karthik Reddy7bb245a2019-05-01 10:14:49 +0530447 dwc3_phy_setup(dwc);
448
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530449 ret = dwc3_core_soft_reset(dwc);
450 if (ret)
451 goto err0;
452
453 reg = dwc3_readl(dwc->regs, DWC3_GCTL);
454 reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
455
456 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc->hwparams.hwparams1)) {
457 case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
458 /**
459 * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an
460 * issue which would cause xHCI compliance tests to fail.
461 *
462 * Because of that we cannot enable clock gating on such
463 * configurations.
464 *
465 * Refers to:
466 *
467 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based
468 * SOF/ITP Mode Used
469 */
470 if ((dwc->dr_mode == USB_DR_MODE_HOST ||
471 dwc->dr_mode == USB_DR_MODE_OTG) &&
472 (dwc->revision >= DWC3_REVISION_210A &&
473 dwc->revision <= DWC3_REVISION_250A))
474 reg |= DWC3_GCTL_DSBLCLKGTNG | DWC3_GCTL_SOFITPSYNC;
475 else
476 reg &= ~DWC3_GCTL_DSBLCLKGTNG;
477 break;
478 case DWC3_GHWPARAMS1_EN_PWROPT_HIB:
479 /* enable hibernation here */
480 dwc->nr_scratch = DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4);
481
482 /*
483 * REVISIT Enabling this bit so that host-mode hibernation
484 * will work. Device-mode hibernation is not yet implemented.
485 */
486 reg |= DWC3_GCTL_GBLHIBERNATIONEN;
487 break;
488 default:
489 dev_dbg(dwc->dev, "No power optimization available\n");
490 }
491
492 /* check if current dwc3 is on simulation board */
493 if (dwc->hwparams.hwparams6 & DWC3_GHWPARAMS6_EN_FPGA) {
494 dev_dbg(dwc->dev, "it is on FPGA board\n");
495 dwc->is_fpga = true;
496 }
497
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530498 if(dwc->disable_scramble_quirk && !dwc->is_fpga)
499 WARN(true,
500 "disable_scramble cannot be used on non-FPGA builds\n");
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530501
502 if (dwc->disable_scramble_quirk && dwc->is_fpga)
503 reg |= DWC3_GCTL_DISSCRAMBLE;
504 else
505 reg &= ~DWC3_GCTL_DISSCRAMBLE;
506
507 if (dwc->u2exit_lfps_quirk)
508 reg |= DWC3_GCTL_U2EXIT_LFPS;
509
510 /*
511 * WORKAROUND: DWC3 revisions <1.90a have a bug
512 * where the device can fail to connect at SuperSpeed
513 * and falls back to high-speed mode which causes
514 * the device to enter a Connect/Disconnect loop
515 */
516 if (dwc->revision < DWC3_REVISION_190A)
517 reg |= DWC3_GCTL_U2RSTECN;
518
519 dwc3_core_num_eps(dwc);
520
521 dwc3_writel(dwc->regs, DWC3_GCTL, reg);
522
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530523 ret = dwc3_alloc_scratch_buffers(dwc);
524 if (ret)
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530525 goto err0;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530526
527 ret = dwc3_setup_scratch_buffers(dwc);
528 if (ret)
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530529 goto err1;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530530
531 return 0;
532
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530533err1:
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530534 dwc3_free_scratch_buffers(dwc);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530535
536err0:
537 return ret;
538}
539
540static void dwc3_core_exit(struct dwc3 *dwc)
541{
542 dwc3_free_scratch_buffers(dwc);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530543}
544
545static int dwc3_core_init_mode(struct dwc3 *dwc)
546{
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530547 int ret;
548
549 switch (dwc->dr_mode) {
550 case USB_DR_MODE_PERIPHERAL:
551 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
552 ret = dwc3_gadget_init(dwc);
553 if (ret) {
554 dev_err(dev, "failed to initialize gadget\n");
555 return ret;
556 }
557 break;
558 case USB_DR_MODE_HOST:
559 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
560 ret = dwc3_host_init(dwc);
561 if (ret) {
562 dev_err(dev, "failed to initialize host\n");
563 return ret;
564 }
565 break;
566 case USB_DR_MODE_OTG:
567 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
568 ret = dwc3_host_init(dwc);
569 if (ret) {
570 dev_err(dev, "failed to initialize host\n");
571 return ret;
572 }
573
574 ret = dwc3_gadget_init(dwc);
575 if (ret) {
576 dev_err(dev, "failed to initialize gadget\n");
577 return ret;
578 }
579 break;
580 default:
581 dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
582 return -EINVAL;
583 }
584
585 return 0;
586}
587
Jean-Jacques Hiblot73a1b8b2019-09-11 11:33:45 +0200588static void dwc3_gadget_run(struct dwc3 *dwc)
589{
590 dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_RUN_STOP);
591 mdelay(100);
592}
593
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530594static void dwc3_core_exit_mode(struct dwc3 *dwc)
595{
596 switch (dwc->dr_mode) {
597 case USB_DR_MODE_PERIPHERAL:
598 dwc3_gadget_exit(dwc);
599 break;
600 case USB_DR_MODE_HOST:
601 dwc3_host_exit(dwc);
602 break;
603 case USB_DR_MODE_OTG:
604 dwc3_host_exit(dwc);
605 dwc3_gadget_exit(dwc);
606 break;
607 default:
608 /* do nothing */
609 break;
610 }
Jean-Jacques Hiblot73a1b8b2019-09-11 11:33:45 +0200611
612 /*
613 * switch back to peripheral mode
614 * This enables the phy to enter idle and then, if enabled, suspend.
615 */
616 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
617 dwc3_gadget_run(dwc);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530618}
619
Jagan Teki106c71f2019-11-19 13:56:20 +0530620static void dwc3_uboot_hsphy_mode(struct dwc3_device *dwc3_dev,
621 struct dwc3 *dwc)
622{
623 enum usb_phy_interface hsphy_mode = dwc3_dev->hsphy_mode;
624 u32 reg;
625
626 /* Set dwc3 usb2 phy config */
627 reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
Jagan Teki106c71f2019-11-19 13:56:20 +0530628
629 switch (hsphy_mode) {
630 case USBPHY_INTERFACE_MODE_UTMI:
Jagan Teki5abcf942019-12-18 13:00:02 +0530631 reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
632 DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
633 reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) |
634 DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT);
Jagan Teki106c71f2019-11-19 13:56:20 +0530635 break;
636 case USBPHY_INTERFACE_MODE_UTMIW:
Jagan Teki5abcf942019-12-18 13:00:02 +0530637 reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
638 DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
639 reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_16_BIT) |
640 DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_16_BIT);
Jagan Teki106c71f2019-11-19 13:56:20 +0530641 break;
642 default:
643 break;
644 }
645
646 dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
647}
648
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530649#define DWC3_ALIGN_MASK (16 - 1)
650
Kishon Vijay Abraham Ibfbf05d2015-02-23 18:40:04 +0530651/**
652 * dwc3_uboot_init - dwc3 core uboot initialization code
653 * @dwc3_dev: struct dwc3_device containing initialization data
654 *
655 * Entry point for dwc3 driver (equivalent to dwc3_probe in linux
656 * kernel driver). Pointer to dwc3_device should be passed containing
657 * base address and other initialization data. Returns '0' on success and
658 * a negative value on failure.
659 *
660 * Generally called from board_usb_init() implemented in board file.
661 */
662int dwc3_uboot_init(struct dwc3_device *dwc3_dev)
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530663{
Kishon Vijay Abraham Idc5c6532015-02-23 18:40:05 +0530664 struct dwc3 *dwc;
Felipe Balbi424305f2015-10-01 14:22:18 -0500665 struct device *dev = NULL;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530666 u8 lpm_nyet_threshold;
667 u8 tx_de_emphasis;
668 u8 hird_threshold;
669
670 int ret;
671
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530672 void *mem;
673
Mugunthan V N121f93c2018-05-18 13:10:27 +0200674 mem = devm_kzalloc((struct udevice *)dev,
675 sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530676 if (!mem)
677 return -ENOMEM;
678
679 dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
680 dwc->mem = mem;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530681
Michal Simek698cd6f2015-10-30 16:24:06 +0100682 dwc->regs = (void *)(uintptr_t)(dwc3_dev->base +
683 DWC3_GLOBALS_REGS_START);
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530684
685 /* default to highest possible threshold */
686 lpm_nyet_threshold = 0xff;
687
688 /* default to -3.5dB de-emphasis */
689 tx_de_emphasis = 1;
690
691 /*
692 * default to assert utmi_sleep_n and use maximum allowed HIRD
693 * threshold value of 0b1100
694 */
695 hird_threshold = 12;
696
Kishon Vijay Abraham Ibfbf05d2015-02-23 18:40:04 +0530697 dwc->maximum_speed = dwc3_dev->maximum_speed;
698 dwc->has_lpm_erratum = dwc3_dev->has_lpm_erratum;
699 if (dwc3_dev->lpm_nyet_threshold)
700 lpm_nyet_threshold = dwc3_dev->lpm_nyet_threshold;
701 dwc->is_utmi_l1_suspend = dwc3_dev->is_utmi_l1_suspend;
702 if (dwc3_dev->hird_threshold)
703 hird_threshold = dwc3_dev->hird_threshold;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530704
Kishon Vijay Abraham Ibfbf05d2015-02-23 18:40:04 +0530705 dwc->needs_fifo_resize = dwc3_dev->tx_fifo_resize;
706 dwc->dr_mode = dwc3_dev->dr_mode;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530707
Kishon Vijay Abraham Ibfbf05d2015-02-23 18:40:04 +0530708 dwc->disable_scramble_quirk = dwc3_dev->disable_scramble_quirk;
709 dwc->u2exit_lfps_quirk = dwc3_dev->u2exit_lfps_quirk;
710 dwc->u2ss_inp3_quirk = dwc3_dev->u2ss_inp3_quirk;
711 dwc->req_p1p2p3_quirk = dwc3_dev->req_p1p2p3_quirk;
712 dwc->del_p1p2p3_quirk = dwc3_dev->del_p1p2p3_quirk;
713 dwc->del_phy_power_chg_quirk = dwc3_dev->del_phy_power_chg_quirk;
714 dwc->lfps_filter_quirk = dwc3_dev->lfps_filter_quirk;
715 dwc->rx_detect_poll_quirk = dwc3_dev->rx_detect_poll_quirk;
716 dwc->dis_u3_susphy_quirk = dwc3_dev->dis_u3_susphy_quirk;
717 dwc->dis_u2_susphy_quirk = dwc3_dev->dis_u2_susphy_quirk;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530718
Kishon Vijay Abraham Ibfbf05d2015-02-23 18:40:04 +0530719 dwc->tx_de_emphasis_quirk = dwc3_dev->tx_de_emphasis_quirk;
720 if (dwc3_dev->tx_de_emphasis)
721 tx_de_emphasis = dwc3_dev->tx_de_emphasis;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530722
723 /* default to superspeed if no maximum_speed passed */
724 if (dwc->maximum_speed == USB_SPEED_UNKNOWN)
725 dwc->maximum_speed = USB_SPEED_SUPER;
726
727 dwc->lpm_nyet_threshold = lpm_nyet_threshold;
728 dwc->tx_de_emphasis = tx_de_emphasis;
729
730 dwc->hird_threshold = hird_threshold
731 | (dwc->is_utmi_l1_suspend << 4);
732
Kishon Vijay Abraham Idc5c6532015-02-23 18:40:05 +0530733 dwc->index = dwc3_dev->index;
734
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530735 dwc3_cache_hwparams(dwc);
736
737 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
738 if (ret) {
739 dev_err(dwc->dev, "failed to allocate event buffers\n");
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530740 return -ENOMEM;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530741 }
742
Jean-Jacques Hiblot731a2a32019-09-11 11:33:53 +0200743 if (!IS_ENABLED(CONFIG_USB_DWC3_GADGET))
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530744 dwc->dr_mode = USB_DR_MODE_HOST;
Jean-Jacques Hiblot731a2a32019-09-11 11:33:53 +0200745 else if (!IS_ENABLED(CONFIG_USB_HOST))
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530746 dwc->dr_mode = USB_DR_MODE_PERIPHERAL;
747
748 if (dwc->dr_mode == USB_DR_MODE_UNKNOWN)
749 dwc->dr_mode = USB_DR_MODE_OTG;
750
751 ret = dwc3_core_init(dwc);
752 if (ret) {
753 dev_err(dev, "failed to initialize core\n");
754 goto err0;
755 }
756
Jagan Teki106c71f2019-11-19 13:56:20 +0530757 dwc3_uboot_hsphy_mode(dwc3_dev, dwc);
758
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530759 ret = dwc3_event_buffers_setup(dwc);
760 if (ret) {
761 dev_err(dwc->dev, "failed to setup event buffers\n");
Kishon Vijay Abraham I99030d72015-02-23 18:40:02 +0530762 goto err1;
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530763 }
764
765 ret = dwc3_core_init_mode(dwc);
766 if (ret)
767 goto err2;
768
Kishon Vijay Abraham Idc5c6532015-02-23 18:40:05 +0530769 list_add_tail(&dwc->list, &dwc3_list);
770
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530771 return 0;
772
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530773err2:
774 dwc3_event_buffers_cleanup(dwc);
775
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530776err1:
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530777 dwc3_core_exit(dwc);
778
779err0:
780 dwc3_free_event_buffers(dwc);
781
782 return ret;
783}
784
Kishon Vijay Abraham Ibfbf05d2015-02-23 18:40:04 +0530785/**
786 * dwc3_uboot_exit - dwc3 core uboot cleanup code
787 * @index: index of this controller
788 *
789 * Performs cleanup of memory allocated in dwc3_uboot_init and other misc
Kishon Vijay Abraham Idc5c6532015-02-23 18:40:05 +0530790 * cleanups (equivalent to dwc3_remove in linux). index of _this_ controller
791 * should be passed and should match with the index passed in
792 * dwc3_device during init.
Kishon Vijay Abraham Ibfbf05d2015-02-23 18:40:04 +0530793 *
794 * Generally called from board file.
795 */
Kishon Vijay Abraham Idc5c6532015-02-23 18:40:05 +0530796void dwc3_uboot_exit(int index)
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530797{
Kishon Vijay Abraham Idc5c6532015-02-23 18:40:05 +0530798 struct dwc3 *dwc;
799
800 list_for_each_entry(dwc, &dwc3_list, list) {
801 if (dwc->index != index)
802 continue;
803
804 dwc3_core_exit_mode(dwc);
805 dwc3_event_buffers_cleanup(dwc);
806 dwc3_free_event_buffers(dwc);
807 dwc3_core_exit(dwc);
808 list_del(&dwc->list);
809 kfree(dwc->mem);
810 break;
811 }
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530812}
813
Kishon Vijay Abraham I1cee7b12015-02-23 18:40:06 +0530814/**
815 * dwc3_uboot_handle_interrupt - handle dwc3 core interrupt
816 * @index: index of this controller
817 *
818 * Invokes dwc3 gadget interrupts.
819 *
820 * Generally called from board file.
821 */
822void dwc3_uboot_handle_interrupt(int index)
823{
824 struct dwc3 *dwc = NULL;
825
826 list_for_each_entry(dwc, &dwc3_list, list) {
827 if (dwc->index != index)
828 continue;
829
830 dwc3_gadget_uboot_handle_interrupt(dwc);
831 break;
832 }
833}
834
Kishon Vijay Abraham I1530fe32015-02-23 18:39:50 +0530835MODULE_ALIAS("platform:dwc3");
836MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
837MODULE_LICENSE("GPL v2");
838MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");
Mugunthan V N5f7ff712018-05-18 13:15:04 +0200839
Jean-Jacques Hiblot3de978a2018-11-29 10:52:45 +0100840#if CONFIG_IS_ENABLED(PHY) && CONFIG_IS_ENABLED(DM_USB)
841int dwc3_setup_phy(struct udevice *dev, struct phy **array, int *num_phys)
842{
843 int i, ret, count;
844 struct phy *usb_phys;
845
846 /* Return if no phy declared */
847 if (!dev_read_prop(dev, "phys", NULL))
848 return 0;
849 count = dev_count_phandle_with_args(dev, "phys", "#phy-cells");
850 if (count <= 0)
851 return count;
852
853 usb_phys = devm_kcalloc(dev, count, sizeof(struct phy),
854 GFP_KERNEL);
855 if (!usb_phys)
856 return -ENOMEM;
857
858 for (i = 0; i < count; i++) {
859 ret = generic_phy_get_by_index(dev, i, &usb_phys[i]);
860 if (ret && ret != -ENOENT) {
861 pr_err("Failed to get USB PHY%d for %s\n",
862 i, dev->name);
863 return ret;
864 }
865 }
866
867 for (i = 0; i < count; i++) {
868 ret = generic_phy_init(&usb_phys[i]);
869 if (ret) {
870 pr_err("Can't init USB PHY%d for %s\n",
871 i, dev->name);
872 goto phys_init_err;
873 }
874 }
875
876 for (i = 0; i < count; i++) {
877 ret = generic_phy_power_on(&usb_phys[i]);
878 if (ret) {
879 pr_err("Can't power USB PHY%d for %s\n",
880 i, dev->name);
881 goto phys_poweron_err;
882 }
883 }
884
885 *array = usb_phys;
886 *num_phys = count;
887 return 0;
888
889phys_poweron_err:
890 for (i = count - 1; i >= 0; i--)
891 generic_phy_power_off(&usb_phys[i]);
892
893 for (i = 0; i < count; i++)
894 generic_phy_exit(&usb_phys[i]);
895
896 return ret;
897
898phys_init_err:
899 for (; i >= 0; i--)
900 generic_phy_exit(&usb_phys[i]);
901
902 return ret;
903}
904
905int dwc3_shutdown_phy(struct udevice *dev, struct phy *usb_phys, int num_phys)
906{
907 int i, ret;
908
909 for (i = 0; i < num_phys; i++) {
910 if (!generic_phy_valid(&usb_phys[i]))
911 continue;
912
913 ret = generic_phy_power_off(&usb_phys[i]);
914 ret |= generic_phy_exit(&usb_phys[i]);
915 if (ret) {
916 pr_err("Can't shutdown USB PHY%d for %s\n",
917 i, dev->name);
918 }
919 }
920
921 return 0;
922}
923#endif
924
Jean-Jacques Hiblot175cd7c2019-09-11 11:33:50 +0200925#if CONFIG_IS_ENABLED(DM_USB)
Jean-Jacques Hiblotce868d02019-09-11 11:33:52 +0200926void dwc3_of_parse(struct dwc3 *dwc)
927{
928 const u8 *tmp;
929 struct udevice *dev = dwc->dev;
930 u8 lpm_nyet_threshold;
931 u8 tx_de_emphasis;
932 u8 hird_threshold;
933
934 /* default to highest possible threshold */
935 lpm_nyet_threshold = 0xff;
936
937 /* default to -3.5dB de-emphasis */
938 tx_de_emphasis = 1;
939
940 /*
941 * default to assert utmi_sleep_n and use maximum allowed HIRD
942 * threshold value of 0b1100
943 */
944 hird_threshold = 12;
945
946 dwc->has_lpm_erratum = dev_read_bool(dev,
947 "snps,has-lpm-erratum");
948 tmp = dev_read_u8_array_ptr(dev, "snps,lpm-nyet-threshold", 1);
949 if (tmp)
950 lpm_nyet_threshold = *tmp;
951
952 dwc->is_utmi_l1_suspend = dev_read_bool(dev,
953 "snps,is-utmi-l1-suspend");
954 tmp = dev_read_u8_array_ptr(dev, "snps,hird-threshold", 1);
955 if (tmp)
956 hird_threshold = *tmp;
957
958 dwc->disable_scramble_quirk = dev_read_bool(dev,
959 "snps,disable_scramble_quirk");
960 dwc->u2exit_lfps_quirk = dev_read_bool(dev,
961 "snps,u2exit_lfps_quirk");
962 dwc->u2ss_inp3_quirk = dev_read_bool(dev,
963 "snps,u2ss_inp3_quirk");
964 dwc->req_p1p2p3_quirk = dev_read_bool(dev,
965 "snps,req_p1p2p3_quirk");
966 dwc->del_p1p2p3_quirk = dev_read_bool(dev,
967 "snps,del_p1p2p3_quirk");
968 dwc->del_phy_power_chg_quirk = dev_read_bool(dev,
969 "snps,del_phy_power_chg_quirk");
970 dwc->lfps_filter_quirk = dev_read_bool(dev,
971 "snps,lfps_filter_quirk");
972 dwc->rx_detect_poll_quirk = dev_read_bool(dev,
973 "snps,rx_detect_poll_quirk");
974 dwc->dis_u3_susphy_quirk = dev_read_bool(dev,
975 "snps,dis_u3_susphy_quirk");
976 dwc->dis_u2_susphy_quirk = dev_read_bool(dev,
977 "snps,dis_u2_susphy_quirk");
978 dwc->tx_de_emphasis_quirk = dev_read_bool(dev,
979 "snps,tx_de_emphasis_quirk");
980 tmp = dev_read_u8_array_ptr(dev, "snps,tx_de_emphasis", 1);
981 if (tmp)
982 tx_de_emphasis = *tmp;
983
984 dwc->lpm_nyet_threshold = lpm_nyet_threshold;
985 dwc->tx_de_emphasis = tx_de_emphasis;
986
987 dwc->hird_threshold = hird_threshold
988 | (dwc->is_utmi_l1_suspend << 4);
989}
990
Mugunthan V N5f7ff712018-05-18 13:15:04 +0200991int dwc3_init(struct dwc3 *dwc)
992{
993 int ret;
994
995 dwc3_cache_hwparams(dwc);
996
997 ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
998 if (ret) {
999 dev_err(dwc->dev, "failed to allocate event buffers\n");
1000 return -ENOMEM;
1001 }
1002
1003 ret = dwc3_core_init(dwc);
1004 if (ret) {
1005 dev_err(dev, "failed to initialize core\n");
1006 goto core_fail;
1007 }
1008
1009 ret = dwc3_event_buffers_setup(dwc);
1010 if (ret) {
1011 dev_err(dwc->dev, "failed to setup event buffers\n");
1012 goto event_fail;
1013 }
1014
1015 ret = dwc3_core_init_mode(dwc);
1016 if (ret)
1017 goto mode_fail;
1018
1019 return 0;
1020
1021mode_fail:
1022 dwc3_event_buffers_cleanup(dwc);
1023
1024event_fail:
1025 dwc3_core_exit(dwc);
1026
1027core_fail:
1028 dwc3_free_event_buffers(dwc);
1029
1030 return ret;
1031}
1032
1033void dwc3_remove(struct dwc3 *dwc)
1034{
1035 dwc3_core_exit_mode(dwc);
1036 dwc3_event_buffers_cleanup(dwc);
1037 dwc3_free_event_buffers(dwc);
1038 dwc3_core_exit(dwc);
1039 kfree(dwc->mem);
1040}
Mugunthan V N5f7ff712018-05-18 13:15:04 +02001041#endif