2 * core.c - DesignWare USB3 DRD Controller Core file
4 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
6 * Authors: Felipe Balbi <balbi@ti.com>,
7 * Sebastian Andrzej Siewior <bigeasy@linutronix.de>
9 * Taken from Linux Kernel v3.19-rc1 (drivers/usb/dwc3/core.c) and ported
12 * commit cd72f890d2 : usb: dwc3: core: enable phy suspend quirk on non-FPGA
14 * SPDX-License-Identifier: GPL-2.0
19 #include <asm/dma-mapping.h>
20 #include <linux/ioport.h>
22 #include <linux/usb/ch9.h>
23 #include <linux/usb/gadget.h>
29 #include "linux-compat.h"
31 /* -------------------------------------------------------------------------- */
33 void dwc3_set_mode(struct dwc3
*dwc
, u32 mode
)
37 reg
= dwc3_readl(dwc
->regs
, DWC3_GCTL
);
38 reg
&= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG
));
39 reg
|= DWC3_GCTL_PRTCAPDIR(mode
);
40 dwc3_writel(dwc
->regs
, DWC3_GCTL
, reg
);
44 * dwc3_core_soft_reset - Issues core soft reset and PHY reset
45 * @dwc: pointer to our context structure
47 static int dwc3_core_soft_reset(struct dwc3
*dwc
)
51 /* Before Resetting PHY, put Core in Reset */
52 reg
= dwc3_readl(dwc
->regs
, DWC3_GCTL
);
53 reg
|= DWC3_GCTL_CORESOFTRESET
;
54 dwc3_writel(dwc
->regs
, DWC3_GCTL
, reg
);
56 /* Assert USB3 PHY reset */
57 reg
= dwc3_readl(dwc
->regs
, DWC3_GUSB3PIPECTL(0));
58 reg
|= DWC3_GUSB3PIPECTL_PHYSOFTRST
;
59 dwc3_writel(dwc
->regs
, DWC3_GUSB3PIPECTL(0), reg
);
61 /* Assert USB2 PHY reset */
62 reg
= dwc3_readl(dwc
->regs
, DWC3_GUSB2PHYCFG(0));
63 reg
|= DWC3_GUSB2PHYCFG_PHYSOFTRST
;
64 dwc3_writel(dwc
->regs
, DWC3_GUSB2PHYCFG(0), reg
);
68 /* Clear USB3 PHY reset */
69 reg
= dwc3_readl(dwc
->regs
, DWC3_GUSB3PIPECTL(0));
70 reg
&= ~DWC3_GUSB3PIPECTL_PHYSOFTRST
;
71 dwc3_writel(dwc
->regs
, DWC3_GUSB3PIPECTL(0), reg
);
73 /* Clear USB2 PHY reset */
74 reg
= dwc3_readl(dwc
->regs
, DWC3_GUSB2PHYCFG(0));
75 reg
&= ~DWC3_GUSB2PHYCFG_PHYSOFTRST
;
76 dwc3_writel(dwc
->regs
, DWC3_GUSB2PHYCFG(0), reg
);
80 /* After PHYs are stable we can take Core out of reset state */
81 reg
= dwc3_readl(dwc
->regs
, DWC3_GCTL
);
82 reg
&= ~DWC3_GCTL_CORESOFTRESET
;
83 dwc3_writel(dwc
->regs
, DWC3_GCTL
, reg
);
89 * dwc3_free_one_event_buffer - Frees one event buffer
90 * @dwc: Pointer to our controller context structure
91 * @evt: Pointer to event buffer to be freed
93 static void dwc3_free_one_event_buffer(struct dwc3
*dwc
,
94 struct dwc3_event_buffer
*evt
)
96 dma_free_coherent(evt
->buf
);
100 * dwc3_alloc_one_event_buffer - Allocates one event buffer structure
101 * @dwc: Pointer to our controller context structure
102 * @length: size of the event buffer
104 * Returns a pointer to the allocated event buffer structure on success
105 * otherwise ERR_PTR(errno).
107 static struct dwc3_event_buffer
*dwc3_alloc_one_event_buffer(struct dwc3
*dwc
,
110 struct dwc3_event_buffer
*evt
;
112 evt
= devm_kzalloc(dwc
->dev
, sizeof(*evt
), GFP_KERNEL
);
114 return ERR_PTR(-ENOMEM
);
117 evt
->length
= length
;
118 evt
->buf
= dma_alloc_coherent(length
,
119 (unsigned long *)&evt
->dma
);
121 return ERR_PTR(-ENOMEM
);
127 * dwc3_free_event_buffers - frees all allocated event buffers
128 * @dwc: Pointer to our controller context structure
130 static void dwc3_free_event_buffers(struct dwc3
*dwc
)
132 struct dwc3_event_buffer
*evt
;
135 for (i
= 0; i
< dwc
->num_event_buffers
; i
++) {
136 evt
= dwc
->ev_buffs
[i
];
138 dwc3_free_one_event_buffer(dwc
, evt
);
143 * dwc3_alloc_event_buffers - Allocates @num event buffers of size @length
144 * @dwc: pointer to our controller context structure
145 * @length: size of event buffer
147 * Returns 0 on success otherwise negative errno. In the error case, dwc
148 * may contain some buffers allocated but not all which were requested.
150 static int dwc3_alloc_event_buffers(struct dwc3
*dwc
, unsigned length
)
155 num
= DWC3_NUM_INT(dwc
->hwparams
.hwparams1
);
156 dwc
->num_event_buffers
= num
;
158 dwc
->ev_buffs
= devm_kzalloc(dwc
->dev
, sizeof(*dwc
->ev_buffs
) * num
,
163 for (i
= 0; i
< num
; i
++) {
164 struct dwc3_event_buffer
*evt
;
166 evt
= dwc3_alloc_one_event_buffer(dwc
, length
);
168 dev_err(dwc
->dev
, "can't allocate event buffer\n");
171 dwc
->ev_buffs
[i
] = evt
;
178 * dwc3_event_buffers_setup - setup our allocated event buffers
179 * @dwc: pointer to our controller context structure
181 * Returns 0 on success otherwise negative errno.
183 static int dwc3_event_buffers_setup(struct dwc3
*dwc
)
185 struct dwc3_event_buffer
*evt
;
188 for (n
= 0; n
< dwc
->num_event_buffers
; n
++) {
189 evt
= dwc
->ev_buffs
[n
];
190 dev_dbg(dwc
->dev
, "Event buf %p dma %08llx length %d\n",
191 evt
->buf
, (unsigned long long) evt
->dma
,
196 dwc3_writel(dwc
->regs
, DWC3_GEVNTADRLO(n
),
197 lower_32_bits(evt
->dma
));
198 dwc3_writel(dwc
->regs
, DWC3_GEVNTADRHI(n
),
199 upper_32_bits(evt
->dma
));
200 dwc3_writel(dwc
->regs
, DWC3_GEVNTSIZ(n
),
201 DWC3_GEVNTSIZ_SIZE(evt
->length
));
202 dwc3_writel(dwc
->regs
, DWC3_GEVNTCOUNT(n
), 0);
208 static void dwc3_event_buffers_cleanup(struct dwc3
*dwc
)
210 struct dwc3_event_buffer
*evt
;
213 for (n
= 0; n
< dwc
->num_event_buffers
; n
++) {
214 evt
= dwc
->ev_buffs
[n
];
218 dwc3_writel(dwc
->regs
, DWC3_GEVNTADRLO(n
), 0);
219 dwc3_writel(dwc
->regs
, DWC3_GEVNTADRHI(n
), 0);
220 dwc3_writel(dwc
->regs
, DWC3_GEVNTSIZ(n
), DWC3_GEVNTSIZ_INTMASK
221 | DWC3_GEVNTSIZ_SIZE(0));
222 dwc3_writel(dwc
->regs
, DWC3_GEVNTCOUNT(n
), 0);
226 static int dwc3_alloc_scratch_buffers(struct dwc3
*dwc
)
228 if (!dwc
->has_hibernation
)
231 if (!dwc
->nr_scratch
)
234 dwc
->scratchbuf
= kmalloc_array(dwc
->nr_scratch
,
235 DWC3_SCRATCHBUF_SIZE
, GFP_KERNEL
);
236 if (!dwc
->scratchbuf
)
242 static int dwc3_setup_scratch_buffers(struct dwc3
*dwc
)
244 dma_addr_t scratch_addr
;
248 if (!dwc
->has_hibernation
)
251 if (!dwc
->nr_scratch
)
254 scratch_addr
= dma_map_single(dwc
->scratchbuf
,
255 dwc
->nr_scratch
* DWC3_SCRATCHBUF_SIZE
,
257 if (dma_mapping_error(dwc
->dev
, scratch_addr
)) {
258 dev_err(dwc
->dev
, "failed to map scratch buffer\n");
263 dwc
->scratch_addr
= scratch_addr
;
265 param
= lower_32_bits(scratch_addr
);
267 ret
= dwc3_send_gadget_generic_command(dwc
,
268 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO
, param
);
272 param
= upper_32_bits(scratch_addr
);
274 ret
= dwc3_send_gadget_generic_command(dwc
,
275 DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI
, param
);
282 dma_unmap_single((void *)dwc
->scratch_addr
, dwc
->nr_scratch
*
283 DWC3_SCRATCHBUF_SIZE
, DMA_BIDIRECTIONAL
);
289 static void dwc3_free_scratch_buffers(struct dwc3
*dwc
)
291 if (!dwc
->has_hibernation
)
294 if (!dwc
->nr_scratch
)
297 dma_unmap_single((void *)dwc
->scratch_addr
, dwc
->nr_scratch
*
298 DWC3_SCRATCHBUF_SIZE
, DMA_BIDIRECTIONAL
);
299 kfree(dwc
->scratchbuf
);
302 static void dwc3_core_num_eps(struct dwc3
*dwc
)
304 struct dwc3_hwparams
*parms
= &dwc
->hwparams
;
306 dwc
->num_in_eps
= DWC3_NUM_IN_EPS(parms
);
307 dwc
->num_out_eps
= DWC3_NUM_EPS(parms
) - dwc
->num_in_eps
;
309 dev_vdbg(dwc
->dev
, "found %d IN and %d OUT endpoints\n",
310 dwc
->num_in_eps
, dwc
->num_out_eps
);
313 static void dwc3_cache_hwparams(struct dwc3
*dwc
)
315 struct dwc3_hwparams
*parms
= &dwc
->hwparams
;
317 parms
->hwparams0
= dwc3_readl(dwc
->regs
, DWC3_GHWPARAMS0
);
318 parms
->hwparams1
= dwc3_readl(dwc
->regs
, DWC3_GHWPARAMS1
);
319 parms
->hwparams2
= dwc3_readl(dwc
->regs
, DWC3_GHWPARAMS2
);
320 parms
->hwparams3
= dwc3_readl(dwc
->regs
, DWC3_GHWPARAMS3
);
321 parms
->hwparams4
= dwc3_readl(dwc
->regs
, DWC3_GHWPARAMS4
);
322 parms
->hwparams5
= dwc3_readl(dwc
->regs
, DWC3_GHWPARAMS5
);
323 parms
->hwparams6
= dwc3_readl(dwc
->regs
, DWC3_GHWPARAMS6
);
324 parms
->hwparams7
= dwc3_readl(dwc
->regs
, DWC3_GHWPARAMS7
);
325 parms
->hwparams8
= dwc3_readl(dwc
->regs
, DWC3_GHWPARAMS8
);
329 * dwc3_phy_setup - Configure USB PHY Interface of DWC3 Core
330 * @dwc: Pointer to our controller context structure
332 static void dwc3_phy_setup(struct dwc3
*dwc
)
336 reg
= dwc3_readl(dwc
->regs
, DWC3_GUSB3PIPECTL(0));
339 * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY
340 * to '0' during coreConsultant configuration. So default value
341 * will be '0' when the core is reset. Application needs to set it
342 * to '1' after the core initialization is completed.
344 if (dwc
->revision
> DWC3_REVISION_194A
)
345 reg
|= DWC3_GUSB3PIPECTL_SUSPHY
;
347 if (dwc
->u2ss_inp3_quirk
)
348 reg
|= DWC3_GUSB3PIPECTL_U2SSINP3OK
;
350 if (dwc
->req_p1p2p3_quirk
)
351 reg
|= DWC3_GUSB3PIPECTL_REQP1P2P3
;
353 if (dwc
->del_p1p2p3_quirk
)
354 reg
|= DWC3_GUSB3PIPECTL_DEP1P2P3_EN
;
356 if (dwc
->del_phy_power_chg_quirk
)
357 reg
|= DWC3_GUSB3PIPECTL_DEPOCHANGE
;
359 if (dwc
->lfps_filter_quirk
)
360 reg
|= DWC3_GUSB3PIPECTL_LFPSFILT
;
362 if (dwc
->rx_detect_poll_quirk
)
363 reg
|= DWC3_GUSB3PIPECTL_RX_DETOPOLL
;
365 if (dwc
->tx_de_emphasis_quirk
)
366 reg
|= DWC3_GUSB3PIPECTL_TX_DEEPH(dwc
->tx_de_emphasis
);
368 if (dwc
->dis_u3_susphy_quirk
)
369 reg
&= ~DWC3_GUSB3PIPECTL_SUSPHY
;
371 dwc3_writel(dwc
->regs
, DWC3_GUSB3PIPECTL(0), reg
);
375 reg
= dwc3_readl(dwc
->regs
, DWC3_GUSB2PHYCFG(0));
378 * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
379 * '0' during coreConsultant configuration. So default value will
380 * be '0' when the core is reset. Application needs to set it to
381 * '1' after the core initialization is completed.
383 if (dwc
->revision
> DWC3_REVISION_194A
)
384 reg
|= DWC3_GUSB2PHYCFG_SUSPHY
;
386 if (dwc
->dis_u2_susphy_quirk
)
387 reg
&= ~DWC3_GUSB2PHYCFG_SUSPHY
;
389 dwc3_writel(dwc
->regs
, DWC3_GUSB2PHYCFG(0), reg
);
395 * dwc3_core_init - Low-level initialization of DWC3 Core
396 * @dwc: Pointer to our controller context structure
398 * Returns 0 on success otherwise negative errno.
400 static int dwc3_core_init(struct dwc3
*dwc
)
402 unsigned long timeout
;
403 u32 hwparams4
= dwc
->hwparams
.hwparams4
;
407 reg
= dwc3_readl(dwc
->regs
, DWC3_GSNPSID
);
408 /* This should read as U3 followed by revision number */
409 if ((reg
& DWC3_GSNPSID_MASK
) != 0x55330000) {
410 dev_err(dwc
->dev
, "this is not a DesignWare USB3 DRD Core\n");
416 /* Handle USB2.0-only core configuration */
417 if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc
->hwparams
.hwparams3
) ==
418 DWC3_GHWPARAMS3_SSPHY_IFC_DIS
) {
419 if (dwc
->maximum_speed
== USB_SPEED_SUPER
)
420 dwc
->maximum_speed
= USB_SPEED_HIGH
;
423 /* issue device SoftReset too */
425 dwc3_writel(dwc
->regs
, DWC3_DCTL
, DWC3_DCTL_CSFTRST
);
427 reg
= dwc3_readl(dwc
->regs
, DWC3_DCTL
);
428 if (!(reg
& DWC3_DCTL_CSFTRST
))
433 dev_err(dwc
->dev
, "Reset Timed Out\n");
438 ret
= dwc3_core_soft_reset(dwc
);
442 reg
= dwc3_readl(dwc
->regs
, DWC3_GCTL
);
443 reg
&= ~DWC3_GCTL_SCALEDOWN_MASK
;
445 switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc
->hwparams
.hwparams1
)) {
446 case DWC3_GHWPARAMS1_EN_PWROPT_CLK
:
448 * WORKAROUND: DWC3 revisions between 2.10a and 2.50a have an
449 * issue which would cause xHCI compliance tests to fail.
451 * Because of that we cannot enable clock gating on such
456 * STAR#9000588375: Clock Gating, SOF Issues when ref_clk-Based
459 if ((dwc
->dr_mode
== USB_DR_MODE_HOST
||
460 dwc
->dr_mode
== USB_DR_MODE_OTG
) &&
461 (dwc
->revision
>= DWC3_REVISION_210A
&&
462 dwc
->revision
<= DWC3_REVISION_250A
))
463 reg
|= DWC3_GCTL_DSBLCLKGTNG
| DWC3_GCTL_SOFITPSYNC
;
465 reg
&= ~DWC3_GCTL_DSBLCLKGTNG
;
467 case DWC3_GHWPARAMS1_EN_PWROPT_HIB
:
468 /* enable hibernation here */
469 dwc
->nr_scratch
= DWC3_GHWPARAMS4_HIBER_SCRATCHBUFS(hwparams4
);
472 * REVISIT Enabling this bit so that host-mode hibernation
473 * will work. Device-mode hibernation is not yet implemented.
475 reg
|= DWC3_GCTL_GBLHIBERNATIONEN
;
478 dev_dbg(dwc
->dev
, "No power optimization available\n");
481 /* check if current dwc3 is on simulation board */
482 if (dwc
->hwparams
.hwparams6
& DWC3_GHWPARAMS6_EN_FPGA
) {
483 dev_dbg(dwc
->dev
, "it is on FPGA board\n");
487 if(dwc
->disable_scramble_quirk
&& !dwc
->is_fpga
)
489 "disable_scramble cannot be used on non-FPGA builds\n");
491 if (dwc
->disable_scramble_quirk
&& dwc
->is_fpga
)
492 reg
|= DWC3_GCTL_DISSCRAMBLE
;
494 reg
&= ~DWC3_GCTL_DISSCRAMBLE
;
496 if (dwc
->u2exit_lfps_quirk
)
497 reg
|= DWC3_GCTL_U2EXIT_LFPS
;
500 * WORKAROUND: DWC3 revisions <1.90a have a bug
501 * where the device can fail to connect at SuperSpeed
502 * and falls back to high-speed mode which causes
503 * the device to enter a Connect/Disconnect loop
505 if (dwc
->revision
< DWC3_REVISION_190A
)
506 reg
|= DWC3_GCTL_U2RSTECN
;
508 dwc3_core_num_eps(dwc
);
510 dwc3_writel(dwc
->regs
, DWC3_GCTL
, reg
);
514 ret
= dwc3_alloc_scratch_buffers(dwc
);
518 ret
= dwc3_setup_scratch_buffers(dwc
);
525 dwc3_free_scratch_buffers(dwc
);
531 static void dwc3_core_exit(struct dwc3
*dwc
)
533 dwc3_free_scratch_buffers(dwc
);
536 static int dwc3_core_init_mode(struct dwc3
*dwc
)
540 switch (dwc
->dr_mode
) {
541 case USB_DR_MODE_PERIPHERAL
:
542 dwc3_set_mode(dwc
, DWC3_GCTL_PRTCAP_DEVICE
);
543 ret
= dwc3_gadget_init(dwc
);
545 dev_err(dev
, "failed to initialize gadget\n");
549 case USB_DR_MODE_HOST
:
550 dwc3_set_mode(dwc
, DWC3_GCTL_PRTCAP_HOST
);
551 ret
= dwc3_host_init(dwc
);
553 dev_err(dev
, "failed to initialize host\n");
557 case USB_DR_MODE_OTG
:
558 dwc3_set_mode(dwc
, DWC3_GCTL_PRTCAP_OTG
);
559 ret
= dwc3_host_init(dwc
);
561 dev_err(dev
, "failed to initialize host\n");
565 ret
= dwc3_gadget_init(dwc
);
567 dev_err(dev
, "failed to initialize gadget\n");
572 dev_err(dev
, "Unsupported mode of operation %d\n", dwc
->dr_mode
);
579 static void dwc3_core_exit_mode(struct dwc3
*dwc
)
581 switch (dwc
->dr_mode
) {
582 case USB_DR_MODE_PERIPHERAL
:
583 dwc3_gadget_exit(dwc
);
585 case USB_DR_MODE_HOST
:
588 case USB_DR_MODE_OTG
:
590 dwc3_gadget_exit(dwc
);
598 #define DWC3_ALIGN_MASK (16 - 1)
600 static int dwc3_probe(struct platform_device
*pdev
)
602 struct device
*dev
= &pdev
->dev
;
603 struct dwc3_platform_data
*pdata
= dev_get_platdata(dev
);
604 struct device_node
*node
= dev
->of_node
;
605 struct resource
*res
;
607 u8 lpm_nyet_threshold
;
616 mem
= devm_kzalloc(dev
, sizeof(*dwc
) + DWC3_ALIGN_MASK
, GFP_KERNEL
);
620 dwc
= PTR_ALIGN(mem
, DWC3_ALIGN_MASK
+ 1);
624 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
626 dev_err(dev
, "missing IRQ\n");
629 dwc
->xhci_resources
[1].start
= res
->start
;
630 dwc
->xhci_resources
[1].end
= res
->end
;
631 dwc
->xhci_resources
[1].flags
= res
->flags
;
632 dwc
->xhci_resources
[1].name
= res
->name
;
634 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
636 dev_err(dev
, "missing memory resource\n");
640 dwc
->xhci_resources
[0].start
= res
->start
;
641 dwc
->xhci_resources
[0].end
= dwc
->xhci_resources
[0].start
+
643 dwc
->xhci_resources
[0].flags
= res
->flags
;
644 dwc
->xhci_resources
[0].name
= res
->name
;
646 res
->start
+= DWC3_GLOBALS_REGS_START
;
649 * Request memory region but exclude xHCI regs,
650 * since it will be requested by the xhci-plat driver.
652 regs
= devm_ioremap_resource(dev
, res
);
654 return PTR_ERR(regs
);
657 dwc
->regs_size
= resource_size(res
);
659 * restore res->start back to its original value so that,
660 * in case the probe is deferred, we don't end up getting error in
661 * request the memory region the next time probe is called.
663 res
->start
-= DWC3_GLOBALS_REGS_START
;
665 /* default to highest possible threshold */
666 lpm_nyet_threshold
= 0xff;
668 /* default to -3.5dB de-emphasis */
672 * default to assert utmi_sleep_n and use maximum allowed HIRD
673 * threshold value of 0b1100
678 dwc
->maximum_speed
= of_usb_get_maximum_speed(node
);
679 dwc
->has_lpm_erratum
= of_property_read_bool(node
,
680 "snps,has-lpm-erratum");
681 of_property_read_u8(node
, "snps,lpm-nyet-threshold",
682 &lpm_nyet_threshold
);
683 dwc
->is_utmi_l1_suspend
= of_property_read_bool(node
,
684 "snps,is-utmi-l1-suspend");
685 of_property_read_u8(node
, "snps,hird-threshold",
688 dwc
->needs_fifo_resize
= of_property_read_bool(node
,
690 dwc
->dr_mode
= of_usb_get_dr_mode(node
);
692 dwc
->disable_scramble_quirk
= of_property_read_bool(node
,
693 "snps,disable_scramble_quirk");
694 dwc
->u2exit_lfps_quirk
= of_property_read_bool(node
,
695 "snps,u2exit_lfps_quirk");
696 dwc
->u2ss_inp3_quirk
= of_property_read_bool(node
,
697 "snps,u2ss_inp3_quirk");
698 dwc
->req_p1p2p3_quirk
= of_property_read_bool(node
,
699 "snps,req_p1p2p3_quirk");
700 dwc
->del_p1p2p3_quirk
= of_property_read_bool(node
,
701 "snps,del_p1p2p3_quirk");
702 dwc
->del_phy_power_chg_quirk
= of_property_read_bool(node
,
703 "snps,del_phy_power_chg_quirk");
704 dwc
->lfps_filter_quirk
= of_property_read_bool(node
,
705 "snps,lfps_filter_quirk");
706 dwc
->rx_detect_poll_quirk
= of_property_read_bool(node
,
707 "snps,rx_detect_poll_quirk");
708 dwc
->dis_u3_susphy_quirk
= of_property_read_bool(node
,
709 "snps,dis_u3_susphy_quirk");
710 dwc
->dis_u2_susphy_quirk
= of_property_read_bool(node
,
711 "snps,dis_u2_susphy_quirk");
713 dwc
->tx_de_emphasis_quirk
= of_property_read_bool(node
,
714 "snps,tx_de_emphasis_quirk");
715 of_property_read_u8(node
, "snps,tx_de_emphasis",
718 dwc
->maximum_speed
= pdata
->maximum_speed
;
719 dwc
->has_lpm_erratum
= pdata
->has_lpm_erratum
;
720 if (pdata
->lpm_nyet_threshold
)
721 lpm_nyet_threshold
= pdata
->lpm_nyet_threshold
;
722 dwc
->is_utmi_l1_suspend
= pdata
->is_utmi_l1_suspend
;
723 if (pdata
->hird_threshold
)
724 hird_threshold
= pdata
->hird_threshold
;
726 dwc
->needs_fifo_resize
= pdata
->tx_fifo_resize
;
727 dwc
->dr_mode
= pdata
->dr_mode
;
729 dwc
->disable_scramble_quirk
= pdata
->disable_scramble_quirk
;
730 dwc
->u2exit_lfps_quirk
= pdata
->u2exit_lfps_quirk
;
731 dwc
->u2ss_inp3_quirk
= pdata
->u2ss_inp3_quirk
;
732 dwc
->req_p1p2p3_quirk
= pdata
->req_p1p2p3_quirk
;
733 dwc
->del_p1p2p3_quirk
= pdata
->del_p1p2p3_quirk
;
734 dwc
->del_phy_power_chg_quirk
= pdata
->del_phy_power_chg_quirk
;
735 dwc
->lfps_filter_quirk
= pdata
->lfps_filter_quirk
;
736 dwc
->rx_detect_poll_quirk
= pdata
->rx_detect_poll_quirk
;
737 dwc
->dis_u3_susphy_quirk
= pdata
->dis_u3_susphy_quirk
;
738 dwc
->dis_u2_susphy_quirk
= pdata
->dis_u2_susphy_quirk
;
740 dwc
->tx_de_emphasis_quirk
= pdata
->tx_de_emphasis_quirk
;
741 if (pdata
->tx_de_emphasis
)
742 tx_de_emphasis
= pdata
->tx_de_emphasis
;
745 /* default to superspeed if no maximum_speed passed */
746 if (dwc
->maximum_speed
== USB_SPEED_UNKNOWN
)
747 dwc
->maximum_speed
= USB_SPEED_SUPER
;
749 dwc
->lpm_nyet_threshold
= lpm_nyet_threshold
;
750 dwc
->tx_de_emphasis
= tx_de_emphasis
;
752 dwc
->hird_threshold
= hird_threshold
753 | (dwc
->is_utmi_l1_suspend
<< 4);
755 spin_lock_init(&dwc
->lock
);
756 platform_set_drvdata(pdev
, dwc
);
758 if (!dev
->dma_mask
) {
759 dev
->dma_mask
= dev
->parent
->dma_mask
;
760 dev
->dma_parms
= dev
->parent
->dma_parms
;
761 dma_set_coherent_mask(dev
, dev
->parent
->coherent_dma_mask
);
764 dwc3_cache_hwparams(dwc
);
766 ret
= dwc3_alloc_event_buffers(dwc
, DWC3_EVENT_BUFFERS_SIZE
);
768 dev_err(dwc
->dev
, "failed to allocate event buffers\n");
772 if (IS_ENABLED(CONFIG_USB_DWC3_HOST
))
773 dwc
->dr_mode
= USB_DR_MODE_HOST
;
774 else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET
))
775 dwc
->dr_mode
= USB_DR_MODE_PERIPHERAL
;
777 if (dwc
->dr_mode
== USB_DR_MODE_UNKNOWN
)
778 dwc
->dr_mode
= USB_DR_MODE_OTG
;
780 ret
= dwc3_core_init(dwc
);
782 dev_err(dev
, "failed to initialize core\n");
786 ret
= dwc3_event_buffers_setup(dwc
);
788 dev_err(dwc
->dev
, "failed to setup event buffers\n");
792 ret
= dwc3_core_init_mode(dwc
);
799 dwc3_event_buffers_cleanup(dwc
);
805 dwc3_free_event_buffers(dwc
);
810 static int dwc3_remove(struct platform_device
*pdev
)
812 struct dwc3
*dwc
= platform_get_drvdata(pdev
);
814 dwc3_core_exit_mode(dwc
);
815 dwc3_event_buffers_cleanup(dwc
);
816 dwc3_free_event_buffers(dwc
);
824 static const struct of_device_id of_dwc3_match
[] = {
826 .compatible
= "snps,dwc3"
829 .compatible
= "synopsys,dwc3"
833 MODULE_DEVICE_TABLE(of
, of_dwc3_match
);
838 #define ACPI_ID_INTEL_BSW "808622B7"
840 static const struct acpi_device_id dwc3_acpi_match
[] = {
841 { ACPI_ID_INTEL_BSW
, 0 },
844 MODULE_DEVICE_TABLE(acpi
, dwc3_acpi_match
);
847 static struct platform_driver dwc3_driver
= {
849 .remove
= dwc3_remove
,
852 .of_match_table
= of_match_ptr(of_dwc3_match
),
853 .acpi_match_table
= ACPI_PTR(dwc3_acpi_match
),
857 module_platform_driver(dwc3_driver
);
859 MODULE_ALIAS("platform:dwc3");
860 MODULE_AUTHOR("Felipe Balbi <balbi@ti.com>");
861 MODULE_LICENSE("GPL v2");
862 MODULE_DESCRIPTION("DesignWare USB3 DRD Controller Driver");