xref: /freebsd/sys/dev/usb/controller/dwc3/dwc3.c (revision ca48e43ba9ee73a07cdbad8365117793b01273bb)
1fe75646aSEmmanuel Vadot /*-
2fe75646aSEmmanuel Vadot  * SPDX-License-Identifier: BSD-2-Clause
3fe75646aSEmmanuel Vadot  *
4fe75646aSEmmanuel Vadot  * Copyright (c) 2019 Emmanuel Vadot <manu@FreeBSD.Org>
5fe75646aSEmmanuel Vadot  * Copyright (c) 2021-2022 Bjoern A. Zeeb <bz@FreeBSD.ORG>
6fe75646aSEmmanuel Vadot  *
7fe75646aSEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
8fe75646aSEmmanuel Vadot  * modification, are permitted provided that the following conditions
9fe75646aSEmmanuel Vadot  * are met:
10fe75646aSEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
11fe75646aSEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
12fe75646aSEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
13fe75646aSEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
14fe75646aSEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
15fe75646aSEmmanuel Vadot  *
16fe75646aSEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17fe75646aSEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18fe75646aSEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19fe75646aSEmmanuel Vadot  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20fe75646aSEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21fe75646aSEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22fe75646aSEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23fe75646aSEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24fe75646aSEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25fe75646aSEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26fe75646aSEmmanuel Vadot  * SUCH DAMAGE.
27fe75646aSEmmanuel Vadot  */
28fe75646aSEmmanuel Vadot 
29fe75646aSEmmanuel Vadot #include "opt_platform.h"
30fe75646aSEmmanuel Vadot #include "opt_acpi.h"
31fe75646aSEmmanuel Vadot 
32fe75646aSEmmanuel Vadot #include <sys/param.h>
33fe75646aSEmmanuel Vadot #include <sys/systm.h>
34fe75646aSEmmanuel Vadot #include <sys/bus.h>
35fe75646aSEmmanuel Vadot #include <sys/rman.h>
36fe75646aSEmmanuel Vadot #include <sys/condvar.h>
37fe75646aSEmmanuel Vadot #include <sys/kernel.h>
38fe75646aSEmmanuel Vadot #include <sys/module.h>
39fe75646aSEmmanuel Vadot #include <sys/mutex.h>
40fe75646aSEmmanuel Vadot #ifdef FDT
41fe75646aSEmmanuel Vadot #include <sys/gpio.h>
42fe75646aSEmmanuel Vadot #endif
43fe75646aSEmmanuel Vadot 
44fe75646aSEmmanuel Vadot #include <machine/bus.h>
45fe75646aSEmmanuel Vadot 
46fe75646aSEmmanuel Vadot #include <dev/usb/usb.h>
47fe75646aSEmmanuel Vadot #include <dev/usb/usbdi.h>
48fe75646aSEmmanuel Vadot 
49fe75646aSEmmanuel Vadot #include <dev/usb/usb_core.h>
50fe75646aSEmmanuel Vadot #include <dev/usb/usb_busdma.h>
51fe75646aSEmmanuel Vadot #include <dev/usb/usb_process.h>
52fe75646aSEmmanuel Vadot 
53fe75646aSEmmanuel Vadot #include <dev/usb/usb_controller.h>
54fe75646aSEmmanuel Vadot #include <dev/usb/usb_bus.h>
55fe75646aSEmmanuel Vadot #include <dev/usb/controller/generic_xhci.h>
56fe75646aSEmmanuel Vadot #include <dev/usb/controller/xhci.h>
57fe75646aSEmmanuel Vadot #include <dev/usb/controller/dwc3/dwc3.h>
58fe75646aSEmmanuel Vadot 
59fe75646aSEmmanuel Vadot #ifdef FDT
60fe75646aSEmmanuel Vadot #include <dev/fdt/simplebus.h>
61fe75646aSEmmanuel Vadot 
62fe75646aSEmmanuel Vadot #include <dev/fdt/fdt_common.h>
63fe75646aSEmmanuel Vadot #include <dev/ofw/ofw_bus.h>
64fe75646aSEmmanuel Vadot #include <dev/ofw/ofw_bus_subr.h>
65fe75646aSEmmanuel Vadot #include <dev/ofw/ofw_subr.h>
66fe75646aSEmmanuel Vadot 
67be82b3a0SEmmanuel Vadot #include <dev/clk/clk.h>
68950a6087SEmmanuel Vadot #include <dev/phy/phy_usb.h>
69fe75646aSEmmanuel Vadot #endif
70fe75646aSEmmanuel Vadot 
71fe75646aSEmmanuel Vadot #ifdef DEV_ACPI
72fe75646aSEmmanuel Vadot #include <contrib/dev/acpica/include/acpi.h>
73fe75646aSEmmanuel Vadot #include <contrib/dev/acpica/include/accommon.h>
74fe75646aSEmmanuel Vadot #include <dev/acpica/acpivar.h>
75fe75646aSEmmanuel Vadot #endif
76fe75646aSEmmanuel Vadot 
77fe75646aSEmmanuel Vadot struct snps_dwc3_softc {
78fe75646aSEmmanuel Vadot 	struct xhci_softc	sc;
79fe75646aSEmmanuel Vadot 	device_t		dev;
80fe75646aSEmmanuel Vadot 	struct resource *	mem_res;
81fe75646aSEmmanuel Vadot 	bus_space_tag_t		bst;
82fe75646aSEmmanuel Vadot 	bus_space_handle_t	bsh;
83fe75646aSEmmanuel Vadot 	uint32_t		snpsid;
84fe75646aSEmmanuel Vadot 	uint32_t		snpsversion;
85fe75646aSEmmanuel Vadot 	uint32_t		snpsrevision;
86fe75646aSEmmanuel Vadot 	uint32_t		snpsversion_type;
87fe75646aSEmmanuel Vadot #ifdef FDT
88fe75646aSEmmanuel Vadot 	clk_t			clk_ref;
89fe75646aSEmmanuel Vadot 	clk_t			clk_suspend;
90fe75646aSEmmanuel Vadot 	clk_t			clk_bus;
91fe75646aSEmmanuel Vadot #endif
92fe75646aSEmmanuel Vadot };
93fe75646aSEmmanuel Vadot 
94fe75646aSEmmanuel Vadot #define	DWC3_WRITE(_sc, _off, _val)		\
95fe75646aSEmmanuel Vadot     bus_space_write_4(_sc->bst, _sc->bsh, _off, _val)
96fe75646aSEmmanuel Vadot #define	DWC3_READ(_sc, _off)		\
97fe75646aSEmmanuel Vadot     bus_space_read_4(_sc->bst, _sc->bsh, _off)
98fe75646aSEmmanuel Vadot 
99fe75646aSEmmanuel Vadot #define	IS_DMA_32B	1
100fe75646aSEmmanuel Vadot 
101fe75646aSEmmanuel Vadot static void
xhci_interrupt_poll(void * _sc)102fe75646aSEmmanuel Vadot xhci_interrupt_poll(void *_sc)
103fe75646aSEmmanuel Vadot {
104fe75646aSEmmanuel Vadot 	struct xhci_softc *sc = _sc;
105fe75646aSEmmanuel Vadot 
106fe75646aSEmmanuel Vadot 	USB_BUS_UNLOCK(&sc->sc_bus);
107fe75646aSEmmanuel Vadot 	xhci_interrupt(sc);
108fe75646aSEmmanuel Vadot 	USB_BUS_LOCK(&sc->sc_bus);
109fe75646aSEmmanuel Vadot 	usb_callout_reset(&sc->sc_callout, 1, (void *)&xhci_interrupt_poll, sc);
110fe75646aSEmmanuel Vadot }
111fe75646aSEmmanuel Vadot 
112fe75646aSEmmanuel Vadot static int
snps_dwc3_attach_xhci(device_t dev)113fe75646aSEmmanuel Vadot snps_dwc3_attach_xhci(device_t dev)
114fe75646aSEmmanuel Vadot {
115fe75646aSEmmanuel Vadot 	struct snps_dwc3_softc *snps_sc = device_get_softc(dev);
116fe75646aSEmmanuel Vadot 	struct xhci_softc *sc = &snps_sc->sc;
117fe75646aSEmmanuel Vadot 	int err = 0, rid = 0;
118fe75646aSEmmanuel Vadot 
119fe75646aSEmmanuel Vadot 	sc->sc_io_res = snps_sc->mem_res;
120fe75646aSEmmanuel Vadot 	sc->sc_io_tag = snps_sc->bst;
121fe75646aSEmmanuel Vadot 	sc->sc_io_hdl = snps_sc->bsh;
122fe75646aSEmmanuel Vadot 	sc->sc_io_size = rman_get_size(snps_sc->mem_res);
123fe75646aSEmmanuel Vadot 
124fe75646aSEmmanuel Vadot 	sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
125fe75646aSEmmanuel Vadot 	    RF_SHAREABLE | RF_ACTIVE);
126fe75646aSEmmanuel Vadot 	if (sc->sc_irq_res == NULL) {
127fe75646aSEmmanuel Vadot 		device_printf(dev, "Failed to allocate IRQ\n");
128fe75646aSEmmanuel Vadot 		return (ENXIO);
129fe75646aSEmmanuel Vadot 	}
130fe75646aSEmmanuel Vadot 
131*5b56413dSWarner Losh 	sc->sc_bus.bdev = device_add_child(dev, "usbus", DEVICE_UNIT_ANY);
132fe75646aSEmmanuel Vadot 	if (sc->sc_bus.bdev == NULL) {
133fe75646aSEmmanuel Vadot 		device_printf(dev, "Failed to add USB device\n");
134fe75646aSEmmanuel Vadot 		return (ENXIO);
135fe75646aSEmmanuel Vadot 	}
136fe75646aSEmmanuel Vadot 
137fe75646aSEmmanuel Vadot 	device_set_ivars(sc->sc_bus.bdev, &sc->sc_bus);
138fe75646aSEmmanuel Vadot 
139fe75646aSEmmanuel Vadot 	sprintf(sc->sc_vendor, "Synopsys");
140fe75646aSEmmanuel Vadot 	device_set_desc(sc->sc_bus.bdev, "Synopsys");
141fe75646aSEmmanuel Vadot 
142fe75646aSEmmanuel Vadot 	if (xhci_use_polling() == 0) {
143fe75646aSEmmanuel Vadot 		err = bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
144fe75646aSEmmanuel Vadot 		    NULL, (driver_intr_t *)xhci_interrupt, sc, &sc->sc_intr_hdl);
145fe75646aSEmmanuel Vadot 		if (err != 0) {
146fe75646aSEmmanuel Vadot 			device_printf(dev, "Failed to setup IRQ, %d\n", err);
147fe75646aSEmmanuel Vadot 			sc->sc_intr_hdl = NULL;
148fe75646aSEmmanuel Vadot 			return (err);
149fe75646aSEmmanuel Vadot 		}
150fe75646aSEmmanuel Vadot 	}
151fe75646aSEmmanuel Vadot 
152fe75646aSEmmanuel Vadot 	err = xhci_init(sc, dev, IS_DMA_32B);
153fe75646aSEmmanuel Vadot 	if (err != 0) {
154fe75646aSEmmanuel Vadot 		device_printf(dev, "Failed to init XHCI, with error %d\n", err);
155fe75646aSEmmanuel Vadot 		return (ENXIO);
156fe75646aSEmmanuel Vadot 	}
157fe75646aSEmmanuel Vadot 
158fe75646aSEmmanuel Vadot 	usb_callout_init_mtx(&sc->sc_callout, &sc->sc_bus.bus_mtx, 0);
159fe75646aSEmmanuel Vadot 
160fe75646aSEmmanuel Vadot 	if (xhci_use_polling() != 0) {
161fe75646aSEmmanuel Vadot 		device_printf(dev, "Interrupt polling at %dHz\n", hz);
162fe75646aSEmmanuel Vadot 		USB_BUS_LOCK(&sc->sc_bus);
163fe75646aSEmmanuel Vadot 		xhci_interrupt_poll(sc);
164fe75646aSEmmanuel Vadot 		USB_BUS_UNLOCK(&sc->sc_bus);
165fe75646aSEmmanuel Vadot 	}
166fe75646aSEmmanuel Vadot 
167fe75646aSEmmanuel Vadot 	err = xhci_start_controller(sc);
168fe75646aSEmmanuel Vadot 	if (err != 0) {
169fe75646aSEmmanuel Vadot 		device_printf(dev, "Failed to start XHCI controller, with error %d\n", err);
170fe75646aSEmmanuel Vadot 		return (ENXIO);
171fe75646aSEmmanuel Vadot 	}
172fe75646aSEmmanuel Vadot 
173fe75646aSEmmanuel Vadot 	device_printf(sc->sc_bus.bdev, "trying to attach\n");
174fe75646aSEmmanuel Vadot 	err = device_probe_and_attach(sc->sc_bus.bdev);
175fe75646aSEmmanuel Vadot 	if (err != 0) {
176fe75646aSEmmanuel Vadot 		device_printf(dev, "Failed to initialize USB, with error %d\n", err);
177fe75646aSEmmanuel Vadot 		return (ENXIO);
178fe75646aSEmmanuel Vadot 	}
179fe75646aSEmmanuel Vadot 
180fe75646aSEmmanuel Vadot 	return (0);
181fe75646aSEmmanuel Vadot }
182fe75646aSEmmanuel Vadot 
183fe75646aSEmmanuel Vadot #ifdef DWC3_DEBUG
184fe75646aSEmmanuel Vadot static void
snsp_dwc3_dump_regs(struct snps_dwc3_softc * sc,const char * msg)185fe75646aSEmmanuel Vadot snsp_dwc3_dump_regs(struct snps_dwc3_softc *sc, const char *msg)
186fe75646aSEmmanuel Vadot {
187fe75646aSEmmanuel Vadot 	struct xhci_softc *xsc;
188fe75646aSEmmanuel Vadot 	uint32_t reg;
189fe75646aSEmmanuel Vadot 
190fe75646aSEmmanuel Vadot 	if (!bootverbose)
191fe75646aSEmmanuel Vadot 		return;
192fe75646aSEmmanuel Vadot 
193fe75646aSEmmanuel Vadot 	device_printf(sc->dev, "%s: %s:\n", __func__, msg ? msg : "");
194fe75646aSEmmanuel Vadot 
195fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GCTL);
196fe75646aSEmmanuel Vadot 	device_printf(sc->dev, "GCTL: %#012x\n", reg);
197fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GUCTL);
198fe75646aSEmmanuel Vadot 	device_printf(sc->dev, "GUCTL: %#012x\n", reg);
199fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GUCTL1);
200fe75646aSEmmanuel Vadot 	device_printf(sc->dev, "GUCTL1: %#012x\n", reg);
201fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GUSB2PHYCFG0);
202fe75646aSEmmanuel Vadot 	device_printf(sc->dev, "GUSB2PHYCFG0: %#012x\n", reg);
203fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GUSB3PIPECTL0);
204fe75646aSEmmanuel Vadot 	device_printf(sc->dev, "GUSB3PIPECTL0: %#012x\n", reg);
205fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_DCFG);
206fe75646aSEmmanuel Vadot 	device_printf(sc->dev, "DCFG: %#012x\n", reg);
207fe75646aSEmmanuel Vadot 
208fe75646aSEmmanuel Vadot 	xsc = &sc->sc;
209fe75646aSEmmanuel Vadot 	device_printf(sc->dev, "xhci quirks: %#012x\n", xsc->sc_quirks);
210fe75646aSEmmanuel Vadot }
211fe75646aSEmmanuel Vadot 
212fe75646aSEmmanuel Vadot static void
snps_dwc3_dump_ctrlparams(struct snps_dwc3_softc * sc)213fe75646aSEmmanuel Vadot snps_dwc3_dump_ctrlparams(struct snps_dwc3_softc *sc)
214fe75646aSEmmanuel Vadot {
215fe75646aSEmmanuel Vadot 	const bus_size_t offs[] = {
216fe75646aSEmmanuel Vadot 	    DWC3_GHWPARAMS0, DWC3_GHWPARAMS1, DWC3_GHWPARAMS2, DWC3_GHWPARAMS3,
217fe75646aSEmmanuel Vadot 	    DWC3_GHWPARAMS4, DWC3_GHWPARAMS5, DWC3_GHWPARAMS6, DWC3_GHWPARAMS7,
218fe75646aSEmmanuel Vadot 	    DWC3_GHWPARAMS8,
219fe75646aSEmmanuel Vadot 	};
220fe75646aSEmmanuel Vadot 	uint32_t reg;
221fe75646aSEmmanuel Vadot 	int i;
222fe75646aSEmmanuel Vadot 
223fe75646aSEmmanuel Vadot 	for (i = 0; i < nitems(offs); i++) {
224fe75646aSEmmanuel Vadot 		reg = DWC3_READ(sc, offs[i]);
225fe75646aSEmmanuel Vadot 		if (bootverbose)
226fe75646aSEmmanuel Vadot 			device_printf(sc->dev, "hwparams[%d]: %#012x\n", i, reg);
227fe75646aSEmmanuel Vadot 	}
228fe75646aSEmmanuel Vadot }
229fe75646aSEmmanuel Vadot #endif
230fe75646aSEmmanuel Vadot 
231fe75646aSEmmanuel Vadot static void
snps_dwc3_reset(struct snps_dwc3_softc * sc)232fe75646aSEmmanuel Vadot snps_dwc3_reset(struct snps_dwc3_softc *sc)
233fe75646aSEmmanuel Vadot {
234fe75646aSEmmanuel Vadot 	uint32_t gctl, ghwp0, phy2, phy3;
235fe75646aSEmmanuel Vadot 
236fe75646aSEmmanuel Vadot 	ghwp0 = DWC3_READ(sc, DWC3_GHWPARAMS0);
237fe75646aSEmmanuel Vadot 
238fe75646aSEmmanuel Vadot 	gctl = DWC3_READ(sc, DWC3_GCTL);
239fe75646aSEmmanuel Vadot 	gctl |= DWC3_GCTL_CORESOFTRESET;
240fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GCTL, gctl);
241fe75646aSEmmanuel Vadot 
242fe75646aSEmmanuel Vadot 	phy2 = DWC3_READ(sc, DWC3_GUSB2PHYCFG0);
243fe75646aSEmmanuel Vadot 	phy2 |= DWC3_GUSB2PHYCFG0_PHYSOFTRST;
244fe75646aSEmmanuel Vadot 	if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) ==
245fe75646aSEmmanuel Vadot 	    DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE)
246fe75646aSEmmanuel Vadot 		phy2 &= ~DWC3_GUSB2PHYCFG0_SUSPENDUSB20;
247fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GUSB2PHYCFG0, phy2);
248fe75646aSEmmanuel Vadot 
249fe75646aSEmmanuel Vadot 	phy3 = DWC3_READ(sc, DWC3_GUSB3PIPECTL0);
250fe75646aSEmmanuel Vadot 	phy3 |= DWC3_GUSB3PIPECTL0_PHYSOFTRST;
251fe75646aSEmmanuel Vadot 	if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) ==
252fe75646aSEmmanuel Vadot 	    DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE)
253fe75646aSEmmanuel Vadot 		phy3 &= ~DWC3_GUSB3PIPECTL0_SUSPENDUSB3;
254fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GUSB3PIPECTL0, phy3);
255fe75646aSEmmanuel Vadot 
256fe75646aSEmmanuel Vadot 	DELAY(1000);
257fe75646aSEmmanuel Vadot 
258fe75646aSEmmanuel Vadot 	phy2 &= ~DWC3_GUSB2PHYCFG0_PHYSOFTRST;
259fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GUSB2PHYCFG0, phy2);
260fe75646aSEmmanuel Vadot 
261fe75646aSEmmanuel Vadot 	phy3 &= ~DWC3_GUSB3PIPECTL0_PHYSOFTRST;
262fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GUSB3PIPECTL0, phy3);
263fe75646aSEmmanuel Vadot 
264fe75646aSEmmanuel Vadot 	gctl &= ~DWC3_GCTL_CORESOFTRESET;
265fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GCTL, gctl);
266fe75646aSEmmanuel Vadot 
267fe75646aSEmmanuel Vadot }
268fe75646aSEmmanuel Vadot 
269fe75646aSEmmanuel Vadot static void
snps_dwc3_configure_host(struct snps_dwc3_softc * sc)270fe75646aSEmmanuel Vadot snps_dwc3_configure_host(struct snps_dwc3_softc *sc)
271fe75646aSEmmanuel Vadot {
272fe75646aSEmmanuel Vadot 	uint32_t reg;
273fe75646aSEmmanuel Vadot 
274fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GCTL);
275fe75646aSEmmanuel Vadot 	reg &= ~DWC3_GCTL_PRTCAPDIR_MASK;
276fe75646aSEmmanuel Vadot 	reg |= DWC3_GCTL_PRTCAPDIR_HOST;
277fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GCTL, reg);
278fe75646aSEmmanuel Vadot 
279fe75646aSEmmanuel Vadot 	/*
280fe75646aSEmmanuel Vadot 	 * Enable the Host IN Auto Retry feature, making the
281fe75646aSEmmanuel Vadot 	 * host respond with a non-terminating retry ACK.
282fe75646aSEmmanuel Vadot 	 * XXX If we ever support more than host mode this needs a dr_mode check.
283fe75646aSEmmanuel Vadot 	 */
284fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GUCTL);
285fe75646aSEmmanuel Vadot 	reg |= DWC3_GUCTL_HOST_AUTO_RETRY;
286fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GUCTL, reg);
287fe75646aSEmmanuel Vadot }
288fe75646aSEmmanuel Vadot 
289fe75646aSEmmanuel Vadot #ifdef FDT
290fe75646aSEmmanuel Vadot static void
snps_dwc3_configure_phy(struct snps_dwc3_softc * sc,phandle_t node)291fe75646aSEmmanuel Vadot snps_dwc3_configure_phy(struct snps_dwc3_softc *sc, phandle_t node)
292fe75646aSEmmanuel Vadot {
293fe75646aSEmmanuel Vadot 	char *phy_type;
294fe75646aSEmmanuel Vadot 	uint32_t reg;
295fe75646aSEmmanuel Vadot 	int nphy_types;
296fe75646aSEmmanuel Vadot 
297fe75646aSEmmanuel Vadot 	phy_type = NULL;
298fe75646aSEmmanuel Vadot 	nphy_types = OF_getprop_alloc(node, "phy_type", (void **)&phy_type);
299fe75646aSEmmanuel Vadot 	if (nphy_types <= 0)
300fe75646aSEmmanuel Vadot 		return;
301fe75646aSEmmanuel Vadot 
302fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GUSB2PHYCFG0);
303fe75646aSEmmanuel Vadot 	if (strncmp(phy_type, "utmi_wide", 9) == 0) {
304fe75646aSEmmanuel Vadot 		reg &= ~(DWC3_GUSB2PHYCFG0_PHYIF | DWC3_GUSB2PHYCFG0_USBTRDTIM(0xf));
305fe75646aSEmmanuel Vadot 		reg |= DWC3_GUSB2PHYCFG0_PHYIF |
306fe75646aSEmmanuel Vadot 			DWC3_GUSB2PHYCFG0_USBTRDTIM(DWC3_GUSB2PHYCFG0_USBTRDTIM_16BITS);
307fe75646aSEmmanuel Vadot 	} else {
308fe75646aSEmmanuel Vadot 		reg &= ~(DWC3_GUSB2PHYCFG0_PHYIF | DWC3_GUSB2PHYCFG0_USBTRDTIM(0xf));
309fe75646aSEmmanuel Vadot 		reg |= DWC3_GUSB2PHYCFG0_PHYIF |
310fe75646aSEmmanuel Vadot 			DWC3_GUSB2PHYCFG0_USBTRDTIM(DWC3_GUSB2PHYCFG0_USBTRDTIM_8BITS);
311fe75646aSEmmanuel Vadot 	}
312fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GUSB2PHYCFG0, reg);
313fe75646aSEmmanuel Vadot 	OF_prop_free(phy_type);
314fe75646aSEmmanuel Vadot }
315fe75646aSEmmanuel Vadot #endif
316fe75646aSEmmanuel Vadot 
317fe75646aSEmmanuel Vadot static void
snps_dwc3_do_quirks(struct snps_dwc3_softc * sc)318fe75646aSEmmanuel Vadot snps_dwc3_do_quirks(struct snps_dwc3_softc *sc)
319fe75646aSEmmanuel Vadot {
320fe75646aSEmmanuel Vadot 	struct xhci_softc *xsc;
321fe75646aSEmmanuel Vadot 	uint32_t ghwp0, reg;
322fe75646aSEmmanuel Vadot 
323fe75646aSEmmanuel Vadot 	ghwp0 = DWC3_READ(sc, DWC3_GHWPARAMS0);
324fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GUSB2PHYCFG0);
325fe75646aSEmmanuel Vadot 	if (device_has_property(sc->dev, "snps,dis-u2-freeclk-exists-quirk"))
326fe75646aSEmmanuel Vadot 		reg &= ~DWC3_GUSB2PHYCFG0_U2_FREECLK_EXISTS;
327fe75646aSEmmanuel Vadot 	else
328fe75646aSEmmanuel Vadot 		reg |= DWC3_GUSB2PHYCFG0_U2_FREECLK_EXISTS;
329fe75646aSEmmanuel Vadot 	if (device_has_property(sc->dev, "snps,dis_u2_susphy_quirk"))
330fe75646aSEmmanuel Vadot 		reg &= ~DWC3_GUSB2PHYCFG0_SUSPENDUSB20;
331fe75646aSEmmanuel Vadot 	else if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) ==
332fe75646aSEmmanuel Vadot 	    DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE)
333fe75646aSEmmanuel Vadot 		reg |= DWC3_GUSB2PHYCFG0_SUSPENDUSB20;
334fe75646aSEmmanuel Vadot 	if (device_has_property(sc->dev, "snps,dis_enblslpm_quirk"))
335fe75646aSEmmanuel Vadot 		reg &= ~DWC3_GUSB2PHYCFG0_ENBLSLPM;
336fe75646aSEmmanuel Vadot 	else
337fe75646aSEmmanuel Vadot 		reg |= DWC3_GUSB2PHYCFG0_ENBLSLPM;
338fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GUSB2PHYCFG0, reg);
339fe75646aSEmmanuel Vadot 
340fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GUCTL1);
341fe75646aSEmmanuel Vadot 	if (device_has_property(sc->dev, "snps,dis-tx-ipgap-linecheck-quirk"))
342fe75646aSEmmanuel Vadot 		reg |= DWC3_GUCTL1_TX_IPGAP_LINECHECK_DIS;
343fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GUCTL1, reg);
344fe75646aSEmmanuel Vadot 
345fe75646aSEmmanuel Vadot 	reg = DWC3_READ(sc, DWC3_GUSB3PIPECTL0);
346fe75646aSEmmanuel Vadot 	if (device_has_property(sc->dev, "snps,dis-del-phy-power-chg-quirk"))
347fe75646aSEmmanuel Vadot 		reg &= ~DWC3_GUSB3PIPECTL0_DELAYP1TRANS;
348fe75646aSEmmanuel Vadot 	if (device_has_property(sc->dev, "snps,dis_rxdet_inp3_quirk"))
349fe75646aSEmmanuel Vadot 		reg |= DWC3_GUSB3PIPECTL0_DISRXDETINP3;
350fe75646aSEmmanuel Vadot 	if (device_has_property(sc->dev, "snps,dis_u3_susphy_quirk"))
351fe75646aSEmmanuel Vadot 		reg &= ~DWC3_GUSB3PIPECTL0_SUSPENDUSB3;
352fe75646aSEmmanuel Vadot 	else if ((ghwp0 & DWC3_GHWPARAMS0_MODE_MASK) ==
353fe75646aSEmmanuel Vadot 	    DWC3_GHWPARAMS0_MODE_DUALROLEDEVICE)
354fe75646aSEmmanuel Vadot 		reg |= DWC3_GUSB3PIPECTL0_SUSPENDUSB3;
355fe75646aSEmmanuel Vadot 	DWC3_WRITE(sc, DWC3_GUSB3PIPECTL0, reg);
356fe75646aSEmmanuel Vadot 
357fe75646aSEmmanuel Vadot 	/* Port Disable does not work on <= 3.00a. Disable PORT_PED. */
358fe75646aSEmmanuel Vadot 	if ((sc->snpsid & 0xffff) <= 0x300a) {
359fe75646aSEmmanuel Vadot 		xsc = &sc->sc;
360fe75646aSEmmanuel Vadot 		xsc->sc_quirks |= XHCI_QUIRK_DISABLE_PORT_PED;
361fe75646aSEmmanuel Vadot 	}
362fe75646aSEmmanuel Vadot }
363fe75646aSEmmanuel Vadot 
364fe75646aSEmmanuel Vadot static int
snps_dwc3_probe_common(device_t dev)365fe75646aSEmmanuel Vadot snps_dwc3_probe_common(device_t dev)
366fe75646aSEmmanuel Vadot {
367fe75646aSEmmanuel Vadot 	char dr_mode[16] = { 0 };
368fe75646aSEmmanuel Vadot 	ssize_t s;
369fe75646aSEmmanuel Vadot 
370fe75646aSEmmanuel Vadot 	s = device_get_property(dev, "dr_mode", dr_mode, sizeof(dr_mode),
371fe75646aSEmmanuel Vadot 	    DEVICE_PROP_BUFFER);
372fe75646aSEmmanuel Vadot 	if (s == -1) {
373fe75646aSEmmanuel Vadot 		device_printf(dev, "Cannot determine dr_mode\n");
374fe75646aSEmmanuel Vadot 		return (ENXIO);
375fe75646aSEmmanuel Vadot 	}
376fe75646aSEmmanuel Vadot 	if (strcmp(dr_mode, "host") != 0) {
377fe75646aSEmmanuel Vadot 		device_printf(dev,
378fe75646aSEmmanuel Vadot 		    "Found dr_mode '%s' but only 'host' supported. s=%zd\n",
379fe75646aSEmmanuel Vadot 		    dr_mode, s);
380fe75646aSEmmanuel Vadot 		return (ENXIO);
381fe75646aSEmmanuel Vadot 	}
382fe75646aSEmmanuel Vadot 
383fe75646aSEmmanuel Vadot 	device_set_desc(dev, "Synopsys Designware DWC3");
384fe75646aSEmmanuel Vadot 	return (BUS_PROBE_DEFAULT);
385fe75646aSEmmanuel Vadot }
386fe75646aSEmmanuel Vadot 
387fe75646aSEmmanuel Vadot static int
snps_dwc3_common_attach(device_t dev,bool is_fdt)388fe75646aSEmmanuel Vadot snps_dwc3_common_attach(device_t dev, bool is_fdt)
389fe75646aSEmmanuel Vadot {
390fe75646aSEmmanuel Vadot 	struct snps_dwc3_softc *sc;
391fe75646aSEmmanuel Vadot #ifdef FDT
392fe75646aSEmmanuel Vadot 	phandle_t node;
393fe75646aSEmmanuel Vadot 	phy_t usb2_phy, usb3_phy;
394fe75646aSEmmanuel Vadot 	uint32_t reg;
395fe75646aSEmmanuel Vadot #endif
396fe75646aSEmmanuel Vadot 	int error, rid;
397fe75646aSEmmanuel Vadot 
398fe75646aSEmmanuel Vadot 	sc = device_get_softc(dev);
399fe75646aSEmmanuel Vadot 	sc->dev = dev;
400fe75646aSEmmanuel Vadot 
401fe75646aSEmmanuel Vadot 	rid = 0;
402fe75646aSEmmanuel Vadot 	sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
403fe75646aSEmmanuel Vadot 	    RF_ACTIVE);
404fe75646aSEmmanuel Vadot 	if (sc->mem_res == NULL) {
405fe75646aSEmmanuel Vadot 		device_printf(dev, "Failed to map memory\n");
406fe75646aSEmmanuel Vadot 		return (ENXIO);
407fe75646aSEmmanuel Vadot 	}
408fe75646aSEmmanuel Vadot 	sc->bst = rman_get_bustag(sc->mem_res);
409fe75646aSEmmanuel Vadot 	sc->bsh = rman_get_bushandle(sc->mem_res);
410fe75646aSEmmanuel Vadot 
411fe75646aSEmmanuel Vadot 	sc->snpsid = DWC3_READ(sc, DWC3_GSNPSID);
412fe75646aSEmmanuel Vadot 	sc->snpsversion = DWC3_VERSION(sc->snpsid);
413fe75646aSEmmanuel Vadot 	sc->snpsrevision = DWC3_REVISION(sc->snpsid);
414fe75646aSEmmanuel Vadot 	if (sc->snpsversion == DWC3_1_IP_ID ||
415fe75646aSEmmanuel Vadot 	    sc->snpsversion == DWC3_2_IP_ID) {
416fe75646aSEmmanuel Vadot 		sc->snpsrevision = DWC3_READ(sc, DWC3_1_VER_NUMBER);
417fe75646aSEmmanuel Vadot 		sc->snpsversion_type = DWC3_READ(sc, DWC3_1_VER_TYPE);
418fe75646aSEmmanuel Vadot 	}
419fe75646aSEmmanuel Vadot 	if (bootverbose) {
420fe75646aSEmmanuel Vadot 		switch (sc->snpsversion) {
421fe75646aSEmmanuel Vadot 		case DWC3_IP_ID:
422fe75646aSEmmanuel Vadot 			device_printf(sc->dev, "SNPS Version: DWC3 (%x %x)\n",
423fe75646aSEmmanuel Vadot 			    sc->snpsversion, sc->snpsrevision);
424fe75646aSEmmanuel Vadot 			break;
425fe75646aSEmmanuel Vadot 		case DWC3_1_IP_ID:
426fe75646aSEmmanuel Vadot 			device_printf(sc->dev, "SNPS Version: DWC3.1 (%x %x %x)\n",
427fe75646aSEmmanuel Vadot 			    sc->snpsversion, sc->snpsrevision,
428fe75646aSEmmanuel Vadot 			    sc->snpsversion_type);
429fe75646aSEmmanuel Vadot 			break;
430fe75646aSEmmanuel Vadot 		case DWC3_2_IP_ID:
431fe75646aSEmmanuel Vadot 			device_printf(sc->dev, "SNPS Version: DWC3.2 (%x %x %x)\n",
432fe75646aSEmmanuel Vadot 			    sc->snpsversion, sc->snpsrevision,
433fe75646aSEmmanuel Vadot 			    sc->snpsversion_type);
434fe75646aSEmmanuel Vadot 			break;
435fe75646aSEmmanuel Vadot 		}
436fe75646aSEmmanuel Vadot 	}
437fe75646aSEmmanuel Vadot #ifdef DWC3_DEBUG
438fe75646aSEmmanuel Vadot 	snps_dwc3_dump_ctrlparams(sc);
439fe75646aSEmmanuel Vadot #endif
440fe75646aSEmmanuel Vadot 
441fe75646aSEmmanuel Vadot #ifdef FDT
442fe75646aSEmmanuel Vadot 	if (!is_fdt)
443fe75646aSEmmanuel Vadot 		goto skip_phys;
444fe75646aSEmmanuel Vadot 
445fe75646aSEmmanuel Vadot 	node = ofw_bus_get_node(dev);
446fe75646aSEmmanuel Vadot 
447fe75646aSEmmanuel Vadot 	/* Get the clocks if any */
448fe75646aSEmmanuel Vadot 	if (ofw_bus_is_compatible(dev, "rockchip,rk3328-dwc3") == 1 ||
449fe75646aSEmmanuel Vadot 	    ofw_bus_is_compatible(dev, "rockchip,rk3568-dwc3") == 1) {
450fe75646aSEmmanuel Vadot 		if (clk_get_by_ofw_name(dev, node, "ref_clk", &sc->clk_ref) != 0)
451fe75646aSEmmanuel Vadot 			device_printf(dev, "Cannot get ref_clk\n");
452fe75646aSEmmanuel Vadot 		if (clk_get_by_ofw_name(dev, node, "suspend_clk", &sc->clk_suspend) != 0)
453fe75646aSEmmanuel Vadot 			device_printf(dev, "Cannot get suspend_clk\n");
454fe75646aSEmmanuel Vadot 		if (clk_get_by_ofw_name(dev, node, "bus_clk", &sc->clk_bus) != 0)
455fe75646aSEmmanuel Vadot 			device_printf(dev, "Cannot get bus_clk\n");
456fe75646aSEmmanuel Vadot 	}
457fe75646aSEmmanuel Vadot 
458fe75646aSEmmanuel Vadot 	if (sc->clk_ref != NULL) {
459fe75646aSEmmanuel Vadot 		if (clk_enable(sc->clk_ref) != 0)
460fe75646aSEmmanuel Vadot 			device_printf(dev, "Cannot enable ref_clk\n");
461fe75646aSEmmanuel Vadot 	}
462fe75646aSEmmanuel Vadot 	if (sc->clk_suspend != NULL) {
463fe75646aSEmmanuel Vadot 		if (clk_enable(sc->clk_suspend) != 0)
464fe75646aSEmmanuel Vadot 			device_printf(dev, "Cannot enable suspend_clk\n");
465fe75646aSEmmanuel Vadot 	}
466fe75646aSEmmanuel Vadot 	if (sc->clk_bus != NULL) {
467fe75646aSEmmanuel Vadot 		if (clk_enable(sc->clk_bus) != 0)
468fe75646aSEmmanuel Vadot 			device_printf(dev, "Cannot enable bus_clk\n");
469fe75646aSEmmanuel Vadot 	}
470fe75646aSEmmanuel Vadot 
471fe75646aSEmmanuel Vadot 	/* Get the phys */
472fe75646aSEmmanuel Vadot 	usb2_phy = usb3_phy = NULL;
473fe75646aSEmmanuel Vadot 	error = phy_get_by_ofw_name(dev, node, "usb2-phy", &usb2_phy);
474fe75646aSEmmanuel Vadot 	if (error == 0 && usb2_phy != NULL)
475fe75646aSEmmanuel Vadot 		phy_enable(usb2_phy);
476fe75646aSEmmanuel Vadot 	error = phy_get_by_ofw_name(dev, node, "usb3-phy", &usb3_phy);
477fe75646aSEmmanuel Vadot 	if (error == 0 && usb3_phy != NULL)
478fe75646aSEmmanuel Vadot 		phy_enable(usb3_phy);
479fe75646aSEmmanuel Vadot 	if (sc->snpsversion == DWC3_IP_ID) {
480fe75646aSEmmanuel Vadot 		if (sc->snpsrevision >= 0x290A) {
481fe75646aSEmmanuel Vadot 			uint32_t hwparams3;
482fe75646aSEmmanuel Vadot 
483fe75646aSEmmanuel Vadot 			hwparams3 = DWC3_READ(sc, DWC3_GHWPARAMS3);
484fe75646aSEmmanuel Vadot 			if (DWC3_HWPARAMS3_SSPHY(hwparams3) == DWC3_HWPARAMS3_SSPHY_DISABLE) {
485fe75646aSEmmanuel Vadot 				reg = DWC3_READ(sc, DWC3_GUCTL1);
486fe75646aSEmmanuel Vadot 				if (bootverbose)
487fe75646aSEmmanuel Vadot 					device_printf(dev, "Forcing USB2 clock only\n");
488fe75646aSEmmanuel Vadot 				reg |= DWC3_GUCTL1_DEV_FORCE_20_CLK_FOR_30_CLK;
489fe75646aSEmmanuel Vadot 				DWC3_WRITE(sc, DWC3_GUCTL1, reg);
490fe75646aSEmmanuel Vadot 			}
491fe75646aSEmmanuel Vadot 		}
492fe75646aSEmmanuel Vadot 	}
493fe75646aSEmmanuel Vadot 	snps_dwc3_configure_phy(sc, node);
494fe75646aSEmmanuel Vadot skip_phys:
495fe75646aSEmmanuel Vadot #endif
496fe75646aSEmmanuel Vadot 
497fe75646aSEmmanuel Vadot 	snps_dwc3_reset(sc);
498fe75646aSEmmanuel Vadot 	snps_dwc3_configure_host(sc);
499fe75646aSEmmanuel Vadot 	snps_dwc3_do_quirks(sc);
500fe75646aSEmmanuel Vadot 
501fe75646aSEmmanuel Vadot #ifdef DWC3_DEBUG
502fe75646aSEmmanuel Vadot 	snsp_dwc3_dump_regs(sc, "Pre XHCI init");
503fe75646aSEmmanuel Vadot #endif
504fe75646aSEmmanuel Vadot 	error = snps_dwc3_attach_xhci(dev);
505fe75646aSEmmanuel Vadot #ifdef DWC3_DEBUG
506fe75646aSEmmanuel Vadot 	snsp_dwc3_dump_regs(sc, "Post XHCI init");
507fe75646aSEmmanuel Vadot #endif
508fe75646aSEmmanuel Vadot 
509fe75646aSEmmanuel Vadot #ifdef FDT
510fe75646aSEmmanuel Vadot 	if (error) {
511fe75646aSEmmanuel Vadot 		if (sc->clk_ref != NULL)
512fe75646aSEmmanuel Vadot 			clk_disable(sc->clk_ref);
513fe75646aSEmmanuel Vadot 		if (sc->clk_suspend != NULL)
514fe75646aSEmmanuel Vadot 			clk_disable(sc->clk_suspend);
515fe75646aSEmmanuel Vadot 		if (sc->clk_bus != NULL)
516fe75646aSEmmanuel Vadot 			clk_disable(sc->clk_bus);
517fe75646aSEmmanuel Vadot 	}
518fe75646aSEmmanuel Vadot #endif
519fe75646aSEmmanuel Vadot 	return (error);
520fe75646aSEmmanuel Vadot }
521fe75646aSEmmanuel Vadot 
522fe75646aSEmmanuel Vadot #ifdef FDT
523fe75646aSEmmanuel Vadot static struct ofw_compat_data compat_data[] = {
524fe75646aSEmmanuel Vadot 	{ "snps,dwc3",	1 },
525fe75646aSEmmanuel Vadot 	{ NULL,		0 }
526fe75646aSEmmanuel Vadot };
527fe75646aSEmmanuel Vadot 
528fe75646aSEmmanuel Vadot static int
snps_dwc3_fdt_probe(device_t dev)529fe75646aSEmmanuel Vadot snps_dwc3_fdt_probe(device_t dev)
530fe75646aSEmmanuel Vadot {
531fe75646aSEmmanuel Vadot 
532fe75646aSEmmanuel Vadot 	if (!ofw_bus_status_okay(dev))
533fe75646aSEmmanuel Vadot 		return (ENXIO);
534fe75646aSEmmanuel Vadot 
535fe75646aSEmmanuel Vadot 	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
536fe75646aSEmmanuel Vadot 		return (ENXIO);
537fe75646aSEmmanuel Vadot 
538fe75646aSEmmanuel Vadot 	return (snps_dwc3_probe_common(dev));
539fe75646aSEmmanuel Vadot }
540fe75646aSEmmanuel Vadot 
541fe75646aSEmmanuel Vadot static int
snps_dwc3_fdt_attach(device_t dev)542fe75646aSEmmanuel Vadot snps_dwc3_fdt_attach(device_t dev)
543fe75646aSEmmanuel Vadot {
544fe75646aSEmmanuel Vadot 
545fe75646aSEmmanuel Vadot 	return (snps_dwc3_common_attach(dev, true));
546fe75646aSEmmanuel Vadot }
547fe75646aSEmmanuel Vadot 
548fe75646aSEmmanuel Vadot static device_method_t snps_dwc3_fdt_methods[] = {
549fe75646aSEmmanuel Vadot 	/* Device interface */
550fe75646aSEmmanuel Vadot 	DEVMETHOD(device_probe,		snps_dwc3_fdt_probe),
551fe75646aSEmmanuel Vadot 	DEVMETHOD(device_attach,	snps_dwc3_fdt_attach),
552fe75646aSEmmanuel Vadot 
553fe75646aSEmmanuel Vadot 	DEVMETHOD_END
554fe75646aSEmmanuel Vadot };
555fe75646aSEmmanuel Vadot 
556fe75646aSEmmanuel Vadot DEFINE_CLASS_1(snps_dwc3_fdt, snps_dwc3_fdt_driver, snps_dwc3_fdt_methods,
557fe75646aSEmmanuel Vadot     sizeof(struct snps_dwc3_softc), generic_xhci_driver);
558fe75646aSEmmanuel Vadot 
559fe75646aSEmmanuel Vadot DRIVER_MODULE(snps_dwc3_fdt, simplebus, snps_dwc3_fdt_driver, 0, 0);
560fe75646aSEmmanuel Vadot MODULE_DEPEND(snps_dwc3_fdt, xhci, 1, 1, 1);
561fe75646aSEmmanuel Vadot #endif
562fe75646aSEmmanuel Vadot 
563fe75646aSEmmanuel Vadot #ifdef DEV_ACPI
564fe75646aSEmmanuel Vadot static char *dwc3_acpi_ids[] = {
565fe75646aSEmmanuel Vadot 	"808622B7",	/* This was an Intel PCI Vendor/Device ID used. */
566fe75646aSEmmanuel Vadot 	"PNP0D10",	/* The generic XHCI PNP ID needing extra probe checks. */
567fe75646aSEmmanuel Vadot 	NULL
568fe75646aSEmmanuel Vadot };
569fe75646aSEmmanuel Vadot 
570fe75646aSEmmanuel Vadot static int
snps_dwc3_acpi_probe(device_t dev)571fe75646aSEmmanuel Vadot snps_dwc3_acpi_probe(device_t dev)
572fe75646aSEmmanuel Vadot {
573fe75646aSEmmanuel Vadot 	char *match;
574fe75646aSEmmanuel Vadot 	int error;
575fe75646aSEmmanuel Vadot 
576fe75646aSEmmanuel Vadot 	if (acpi_disabled("snps_dwc3"))
577fe75646aSEmmanuel Vadot 		return (ENXIO);
578fe75646aSEmmanuel Vadot 
579fe75646aSEmmanuel Vadot 	error = ACPI_ID_PROBE(device_get_parent(dev), dev, dwc3_acpi_ids, &match);
580fe75646aSEmmanuel Vadot 	if (error > 0)
581fe75646aSEmmanuel Vadot 		return (ENXIO);
582fe75646aSEmmanuel Vadot 
583fe75646aSEmmanuel Vadot 	/*
584fe75646aSEmmanuel Vadot 	 * If we found the Generic XHCI PNP ID we can only attach if we have
585fe75646aSEmmanuel Vadot 	 * some other means to identify the device as dwc3.
586fe75646aSEmmanuel Vadot 	 */
587fe75646aSEmmanuel Vadot 	if (strcmp(match, "PNP0D10") == 0) {
588fe75646aSEmmanuel Vadot 		/* This is needed in SolidRun's HoneyComb. */
589fe75646aSEmmanuel Vadot 		if (device_has_property(dev, "snps,dis_rxdet_inp3_quirk"))
590fe75646aSEmmanuel Vadot 			goto is_dwc3;
591fe75646aSEmmanuel Vadot 
592fe75646aSEmmanuel Vadot 		return (ENXIO);
593fe75646aSEmmanuel Vadot 	}
594fe75646aSEmmanuel Vadot 
595fe75646aSEmmanuel Vadot is_dwc3:
596fe75646aSEmmanuel Vadot 	return (snps_dwc3_probe_common(dev));
597fe75646aSEmmanuel Vadot }
598fe75646aSEmmanuel Vadot 
599fe75646aSEmmanuel Vadot static int
snps_dwc3_acpi_attach(device_t dev)600fe75646aSEmmanuel Vadot snps_dwc3_acpi_attach(device_t dev)
601fe75646aSEmmanuel Vadot {
602fe75646aSEmmanuel Vadot 
603fe75646aSEmmanuel Vadot 	return (snps_dwc3_common_attach(dev, false));
604fe75646aSEmmanuel Vadot }
605fe75646aSEmmanuel Vadot 
606fe75646aSEmmanuel Vadot static device_method_t snps_dwc3_acpi_methods[] = {
607fe75646aSEmmanuel Vadot 	/* Device interface */
608fe75646aSEmmanuel Vadot 	DEVMETHOD(device_probe,		snps_dwc3_acpi_probe),
609fe75646aSEmmanuel Vadot 	DEVMETHOD(device_attach,	snps_dwc3_acpi_attach),
610fe75646aSEmmanuel Vadot 
611fe75646aSEmmanuel Vadot 	DEVMETHOD_END
612fe75646aSEmmanuel Vadot };
613fe75646aSEmmanuel Vadot 
614fe75646aSEmmanuel Vadot DEFINE_CLASS_1(snps_dwc3_acpi, snps_dwc3_acpi_driver, snps_dwc3_acpi_methods,
615fe75646aSEmmanuel Vadot     sizeof(struct snps_dwc3_softc), generic_xhci_driver);
616fe75646aSEmmanuel Vadot 
617fe75646aSEmmanuel Vadot DRIVER_MODULE(snps_dwc3_acpi, acpi, snps_dwc3_acpi_driver, 0, 0);
618fe75646aSEmmanuel Vadot MODULE_DEPEND(snps_dwc3_acpi, usb, 1, 1, 1);
619fe75646aSEmmanuel Vadot #endif
620