1248557Sray/*-
2248557Sray * Copyright (c) 2010-2012 Semihalf
3248557Sray * Copyright (c) 2012 The FreeBSD Foundation
4257393Sian * Copyright (c) 2013 Ian Lepore <ian@freebsd.org>
5248557Sray * All rights reserved.
6248557Sray *
7248557Sray * Portions of this software were developed by Oleksandr Rybalko
8248557Sray * under sponsorship from the FreeBSD Foundation.
9248557Sray *
10248557Sray * Redistribution and use in source and binary forms, with or without
11248557Sray * modification, are permitted provided that the following conditions
12248557Sray * are met:
13248557Sray * 1. Redistributions of source code must retain the above copyright
14248557Sray *    notice, this list of conditions and the following disclaimer.
15248557Sray * 2. Redistributions in binary form must reproduce the above copyright
16248557Sray *    notice, this list of conditions and the following disclaimer in the
17248557Sray *    documentation and/or other materials provided with the distribution.
18248557Sray *
19248557Sray * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20248557Sray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21248557Sray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22248557Sray * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23248557Sray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24248557Sray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25248557Sray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26248557Sray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27248557Sray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28248557Sray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29248557Sray * SUCH DAMAGE.
30248557Sray */
31248557Sray
32248557Sray#include <sys/cdefs.h>
33248557Sray__FBSDID("$FreeBSD: stable/11/sys/dev/usb/controller/ehci_imx.c 346520 2019-04-22 04:07:51Z ian $");
34248557Sray
35257393Sian/*
36257393Sian * EHCI driver for Freescale i.MX SoCs which incorporate the USBOH3 controller.
37257393Sian */
38248557Sray
39248557Sray#include <sys/param.h>
40248557Sray#include <sys/systm.h>
41248557Sray#include <sys/kernel.h>
42248557Sray#include <sys/module.h>
43248557Sray#include <sys/bus.h>
44248557Sray#include <sys/condvar.h>
45248557Sray#include <sys/rman.h>
46248557Sray
47248557Sray#include <dev/ofw/ofw_bus.h>
48248557Sray#include <dev/ofw/ofw_bus_subr.h>
49248557Sray
50248557Sray#include <dev/usb/usb.h>
51248557Sray#include <dev/usb/usbdi.h>
52248557Sray#include <dev/usb/usb_busdma.h>
53248557Sray#include <dev/usb/usb_process.h>
54248557Sray#include <dev/usb/usb_controller.h>
55248557Sray#include <dev/usb/usb_bus.h>
56248557Sray#include <dev/usb/controller/ehci.h>
57248557Sray#include <dev/usb/controller/ehcireg.h>
58257393Sian#include "usbdevs.h"
59248557Sray
60248557Sray#include <machine/bus.h>
61248557Sray#include <machine/resource.h>
62248557Sray
63264977Sian#include <arm/freescale/imx/imx_ccmvar.h>
64257393Sian
65248557Sray#include "opt_platform.h"
66248557Sray
67257393Sian/*
68257393Sian * Notes on the hardware and related FDT data seen in the wild.
69257393Sian *
70257393Sian * There are two sets of registers in the USBOH3 implementation; documentation
71257393Sian * refers to them as "core" and "non-core" registers.  A set of core register
72257393Sian * exists for each OTG or EHCI device.  There is a single set of non-core
73257393Sian * registers per USBOH3, and they control aspects of operation not directly
74257393Sian * related to the USB specs, such as whether interrupts from each of the core
75257393Sian * devices are able to generate a SoC wakeup event.
76257393Sian *
77257393Sian * In the FreeBSD universe we might be inclined to describe the core and
78257393Sian * non-core registers by using a pair of resource address/size values (two
79257393Sian * entries in the reg property for each core).  However, we have to work with
80257393Sian * existing FDT data (which mostly comes from the linux universe), and the way
81257393Sian * they've chosen to represent this is with an entry for a "usbmisc" device
82257393Sian * whose reg property describes the non-core registers. The way we handle FDT
83257393Sian * data, this means that the resources (memory-mapped register range) for the
84257393Sian * non-core registers belongs to a device other than the echi devices.
85257393Sian *
86323422Sian * Because the main ehci device cannot access registers in a range that's
87323422Sian * defined in the fdt data as belonging to another device, we implement a teeny
88323422Sian * little "usbmisc" driver which exists only to provide access to the usbmisc
89323422Sian * control register for each of the 4 usb controller instances.  That little
90323422Sian * driver is implemented here in this file, before the main driver.
91257393Sian *
92257393Sian * In addition to the single usbmisc device, the existing FDT data defines a
93257393Sian * separate device for each of the OTG or EHCI cores within the USBOH3.  Each of
94257393Sian * those devices has a set of core registers described by the reg property.
95257393Sian *
96257393Sian * The core registers for each of the four cores in the USBOH3 are divided into
97257393Sian * two parts: a set of imx-specific registers at an offset of 0 from the
98257393Sian * beginning of the register range, and the standard USB (EHCI or OTG) registers
99257393Sian * at an offset of 0x100 from the beginning of the register range.  The FreeBSD
100257393Sian * way of dealing with this might be to map out two ranges in the reg property,
101257393Sian * but that's not what the alternate universe has done.  To work with existing
102257393Sian * FDT data, we acquire the resource that maps all the core registers, then use
103257393Sian * bus_space_subregion() to create another resource that maps just the standard
104257393Sian * USB registers, which we provide to the standard USB code in the ehci_softc.
105257393Sian *
106257393Sian * The following compat strings have been seen for the OTG and EHCI cores.  The
107257393Sian * FDT compat table in this driver contains all these strings, but as of this
108257393Sian * writing, not all of these SoCs have been tested with the driver.  The fact
109257393Sian * that imx27 is common to all of them gives some hope that the driver will work
110257393Sian * on all these SoCs.
111257393Sian *   - "fsl,imx23-usb", "fsl,imx27-usb";
112257393Sian *   - "fsl,imx25-usb", "fsl,imx27-usb";
113257393Sian *   - "fsl,imx28-usb", "fsl,imx27-usb";
114257393Sian *   - "fsl,imx51-usb", "fsl,imx27-usb";
115257393Sian *   - "fsl,imx53-usb", "fsl,imx27-usb";
116257393Sian *   - "fsl,imx6q-usb", "fsl,imx27-usb";
117257393Sian *
118257393Sian * The FDT data for some SoCs contains the following properties, which we don't
119257393Sian * currently do anything with:
120257393Sian *   - fsl,usbmisc = <&usbmisc 0>;
121257393Sian *   - fsl,usbphy = <&usbphy0>;
122257393Sian *
123257393Sian * Some imx SoCs have FDT data related to USB PHY, some don't.  We have separate
124257393Sian * usbphy drivers where needed; this data is mentioned here just to keep all the
125257393Sian * imx-FDT-usb-related info in one place.  Here are the usbphy compat strings
126257393Sian * known to exist:
127257393Sian *   - "nop-usbphy"
128257393Sian *   - "usb-nop-xceiv";
129257393Sian *   - "fsl,imx23-usbphy"
130257393Sian *   - "fsl,imx28-usbphy", "fsl,imx23-usbphy";
131257393Sian *   - "fsl,imx6q-usbphy", "fsl,imx23-usbphy";
132257393Sian *
133257393Sian */
134248557Sray
135323422Sian/*-----------------------------------------------------------------------------
136323422Sian * imx_usbmisc driver
137323422Sian *---------------------------------------------------------------------------*/
138323422Sian
139323422Sian#define	USBNC_OVER_CUR_POL	  (1u << 8)
140323422Sian#define	USBNC_OVER_CUR_DIS	  (1u << 7)
141323422Sian
142323422Sianstruct imx_usbmisc_softc {
143323422Sian	device_t	dev;
144323422Sian	struct resource	*mmio;
145248557Sray};
146248557Sray
147323422Sianstatic struct ofw_compat_data usbmisc_compat_data[] = {
148323422Sian	{"fsl,imx6q-usbmisc",	true},
149323422Sian	{"fsl,imx51-usbmisc",	true},
150323422Sian	{"fsl,imx25-usbmisc",	true},
151323422Sian	{NULL, 			false},
152323422Sian};
153323422Sian
154323422Sianstatic void
155323422Sianimx_usbmisc_set_ctrl(device_t dev, u_int index, uint32_t bits)
156323422Sian{
157323422Sian	struct imx_usbmisc_softc *sc;
158323422Sian	uint32_t reg;
159323422Sian
160323422Sian	sc = device_get_softc(dev);
161323422Sian	reg = bus_read_4(sc->mmio, index * sizeof(uint32_t));
162323422Sian	bus_write_4(sc->mmio, index * sizeof(uint32_t), reg | bits);
163323422Sian}
164323422Sian
165323422Sian#ifdef notyet
166323422Sianstatic void
167323422Sianimx_usbmisc_clr_ctrl(device_t dev, u_int index, uint32_t bits)
168323422Sian{
169323422Sian	struct imx_usbmisc_softc *sc;
170323422Sian	uint32_t reg;
171323422Sian
172323422Sian	sc = device_get_softc(dev);
173323422Sian	reg = bus_read_4(sc->mmio, index * sizeof(uint32_t));
174323422Sian	bus_write_4(sc->mmio, index * sizeof(uint32_t), reg & ~bits);
175323422Sian}
176323422Sian#endif
177323422Sian
178323422Sianstatic int
179323422Sianimx_usbmisc_probe(device_t dev)
180323422Sian{
181323422Sian
182323422Sian	if (!ofw_bus_status_okay(dev))
183323422Sian		return (ENXIO);
184323422Sian
185323422Sian	if (ofw_bus_search_compatible(dev, usbmisc_compat_data)->ocd_data) {
186323422Sian		device_set_desc(dev, "i.MX USB Misc Control");
187323422Sian		return (BUS_PROBE_DEFAULT);
188323422Sian	}
189323422Sian	return (ENXIO);
190323422Sian}
191323422Sian
192323422Sianstatic int
193323422Sianimx_usbmisc_detach(device_t dev)
194323422Sian{
195323422Sian	struct imx_usbmisc_softc *sc;
196323422Sian
197323422Sian	sc = device_get_softc(dev);
198323422Sian
199323422Sian	if (sc->mmio != NULL)
200323422Sian		bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mmio);
201323422Sian
202323422Sian	return (0);
203323422Sian}
204323422Sian
205323422Sianstatic int
206323422Sianimx_usbmisc_attach(device_t dev)
207323422Sian{
208323422Sian	struct imx_usbmisc_softc *sc;
209323422Sian	int err, rid;
210323422Sian
211323422Sian	sc = device_get_softc(dev);
212323422Sian	err = 0;
213323422Sian
214323422Sian	/* Allocate bus_space resources. */
215323422Sian	rid = 0;
216323422Sian	sc->mmio = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
217323422Sian	    RF_ACTIVE);
218323422Sian	if (sc->mmio == NULL) {
219323422Sian		device_printf(dev, "Cannot allocate memory resources\n");
220323422Sian		return (ENXIO);
221323422Sian	}
222323422Sian
223323422Sian	OF_device_register_xref(OF_xref_from_node(ofw_bus_get_node(dev)), dev);
224323422Sian
225323422Sian	return (0);
226323422Sian}
227323422Sian
228323422Sianstatic device_method_t imx_usbmisc_methods[] = {
229323422Sian	/* Device interface */
230323422Sian	DEVMETHOD(device_probe, 	imx_usbmisc_probe),
231323422Sian	DEVMETHOD(device_attach,	imx_usbmisc_attach),
232323422Sian	DEVMETHOD(device_detach,	imx_usbmisc_detach),
233323422Sian
234323422Sian	DEVMETHOD_END
235323422Sian};
236323422Sian
237323422Sianstatic driver_t imx_usbmisc_driver = {
238323422Sian	"imx_usbmisc",
239323422Sian	imx_usbmisc_methods,
240323422Sian	sizeof(struct imx_usbmisc_softc)
241323422Sian};
242323422Sian
243323422Sianstatic devclass_t imx_usbmisc_devclass;
244323422Sian
245257393Sian/*
246323422Sian * This driver needs to start before the ehci driver, but later than the usual
247323422Sian * "special" drivers like clocks and cpu.  Ehci starts at DEFAULT so
248323422Sian * DEFAULT-1000 seems good.
249323422Sian */
250323422SianEARLY_DRIVER_MODULE(imx_usbmisc, simplebus, imx_usbmisc_driver,
251323422Sian    imx_usbmisc_devclass, 0, 0, BUS_PASS_DEFAULT - 1000);
252323422Sian
253323422Sian/*-----------------------------------------------------------------------------
254323422Sian * imx_ehci driver...
255323422Sian *---------------------------------------------------------------------------*/
256323422Sian
257323422Sian/*
258257393Sian * Each EHCI device in the SoC has some SoC-specific per-device registers at an
259257393Sian * offset of 0, then the standard EHCI registers begin at an offset of 0x100.
260257393Sian */
261257393Sian#define	IMX_EHCI_REG_OFF	0x100
262257393Sian#define	IMX_EHCI_REG_SIZE	0x100
263257393Sian
264257393Sianstruct imx_ehci_softc {
265257393Sian	ehci_softc_t	ehci_softc;
266323422Sian	device_t	dev;
267257393Sian	struct resource	*ehci_mem_res;	/* EHCI core regs. */
268257393Sian	struct resource	*ehci_irq_res;	/* EHCI core IRQ. */
269248557Sray};
270248557Sray
271323422Sianstatic struct ofw_compat_data compat_data[] = {
272323422Sian	{"fsl,imx6q-usb",	1},
273323422Sian	{"fsl,imx53-usb",	1},
274323422Sian	{"fsl,imx51-usb",	1},
275323422Sian	{"fsl,imx28-usb",	1},
276323422Sian	{"fsl,imx27-usb",	1},
277323422Sian	{"fsl,imx25-usb",	1},
278323422Sian	{"fsl,imx23-usb",	1},
279323422Sian	{NULL,		 	0},
280323422Sian};
281323422Sian
282313649Sianstatic void
283313649Sianimx_ehci_post_reset(struct ehci_softc *ehci_softc)
284313649Sian{
285313649Sian        uint32_t usbmode;
286313649Sian
287313649Sian        /* Force HOST mode */
288313649Sian        usbmode = EOREAD4(ehci_softc, EHCI_USBMODE_NOLPM);
289313649Sian        usbmode &= ~EHCI_UM_CM;
290313649Sian        usbmode |= EHCI_UM_CM_HOST;
291313649Sian        EOWRITE4(ehci_softc, EHCI_USBMODE_NOLPM, usbmode);
292313649Sian}
293313649Sian
294257393Sianstatic int
295257393Sianimx_ehci_probe(device_t dev)
296257393Sian{
297248557Sray
298261410Sian	if (!ofw_bus_status_okay(dev))
299261410Sian		return (ENXIO);
300261410Sian
301257393Sian	if (ofw_bus_search_compatible(dev, compat_data)->ocd_data != 0) {
302257393Sian		device_set_desc(dev, "Freescale i.MX integrated USB controller");
303257393Sian		return (BUS_PROBE_DEFAULT);
304257393Sian	}
305257393Sian	return (ENXIO);
306257393Sian}
307248557Sray
308257393Sianstatic int
309257393Sianimx_ehci_detach(device_t dev)
310257393Sian{
311257393Sian	struct imx_ehci_softc *sc;
312257393Sian	ehci_softc_t *esc;
313346520Sian	int err;
314248557Sray
315257393Sian	sc = device_get_softc(dev);
316248557Sray
317257393Sian	esc = &sc->ehci_softc;
318248557Sray
319346520Sian	/* First detach all children; we can't detach if that fails. */
320346520Sian	if ((err = device_delete_children(dev)) != 0)
321346520Sian		return (err);
322346520Sian
323257393Sian	if (esc->sc_flags & EHCI_SCFLG_DONEINIT)
324257393Sian		ehci_detach(esc);
325257393Sian	if (esc->sc_intr_hdl != NULL)
326257393Sian		bus_teardown_intr(dev, esc->sc_irq_res,
327257393Sian		    esc->sc_intr_hdl);
328257393Sian	if (sc->ehci_irq_res != NULL)
329257393Sian		bus_release_resource(dev, SYS_RES_IRQ, 0,
330257393Sian		    sc->ehci_irq_res);
331257393Sian	if (sc->ehci_mem_res != NULL)
332257393Sian		bus_release_resource(dev, SYS_RES_MEMORY, 0,
333257393Sian		    sc->ehci_mem_res);
334248557Sray
335346520Sian	usb_bus_mem_free_all(&esc->sc_bus, &ehci_iterate_hw_softc);
336248557Sray
337257393Sian	return (0);
338248557Sray}
339248557Sray
340323422Sianstatic void
341323422Sianimx_ehci_disable_oc(struct imx_ehci_softc *sc)
342323422Sian{
343323422Sian	device_t usbmdev;
344323422Sian	pcell_t usbmprops[2];
345323422Sian	phandle_t node;
346323422Sian	ssize_t size;
347323422Sian	int index;
348323422Sian
349323422Sian	/* Get the reference to the usbmisc driver from the fdt data */
350323422Sian	node = ofw_bus_get_node(sc->dev);
351323422Sian	size = OF_getencprop(node, "fsl,usbmisc", usbmprops,
352323422Sian	    sizeof(usbmprops));
353323422Sian	if (size < sizeof(usbmprops)) {
354323422Sian		device_printf(sc->dev, "failed to retrieve fsl,usbmisc "
355323422Sian		   "property, cannot disable overcurrent protection");
356323422Sian		return;
357323422Sian	}
358323422Sian	/* Retrieve the device_t via the xref handle. */
359323422Sian	usbmdev = OF_device_from_xref(usbmprops[0]);
360323422Sian	if (usbmdev == NULL) {
361323422Sian		device_printf(sc->dev, "usbmisc device not found, "
362323422Sian		    "cannot disable overcurrent protection");
363323422Sian		return;
364323422Sian	}
365323422Sian	/* Call the device routine to set the overcurrent disable bit. */
366323422Sian	index = usbmprops[1];
367323422Sian	imx_usbmisc_set_ctrl(usbmdev, index, USBNC_OVER_CUR_DIS);
368323422Sian}
369323422Sian
370248557Sraystatic int
371257393Sianimx_ehci_attach(device_t dev)
372248557Sray{
373248557Sray	struct imx_ehci_softc *sc;
374248557Sray	ehci_softc_t *esc;
375257393Sian	int err, rid;
376248557Sray
377257393Sian	sc = device_get_softc(dev);
378323422Sian	sc->dev = dev;
379257393Sian	esc = &sc->ehci_softc;
380257393Sian	err = 0;
381257393Sian
382257393Sian	/* Allocate bus_space resources. */
383248557Sray	rid = 0;
384257393Sian	sc->ehci_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
385257393Sian	    RF_ACTIVE);
386257393Sian	if (sc->ehci_mem_res == NULL) {
387257393Sian		device_printf(dev, "Cannot allocate memory resources\n");
388257393Sian		err = ENXIO;
389257393Sian		goto out;
390257393Sian	}
391248557Sray
392257393Sian	rid = 0;
393257393Sian	sc->ehci_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
394257393Sian	    RF_ACTIVE);
395257393Sian	if (sc->ehci_irq_res == NULL) {
396257393Sian		device_printf(dev, "Cannot allocate IRQ resources\n");
397257393Sian		err = ENXIO;
398257393Sian		goto out;
399248557Sray	}
400248557Sray
401257393Sian	esc->sc_io_tag = rman_get_bustag(sc->ehci_mem_res);
402257393Sian	esc->sc_bus.parent = dev;
403257393Sian	esc->sc_bus.devices = esc->sc_devices;
404257393Sian	esc->sc_bus.devices_max = EHCI_MAX_DEVICES;
405276717Shselasky	esc->sc_bus.dma_bits = 32;
406248557Sray
407276717Shselasky	/* allocate all DMA memory */
408257393Sian	if (usb_bus_mem_alloc_all(&esc->sc_bus, USB_GET_DMA_TAG(dev),
409257393Sian	    &ehci_iterate_hw_softc) != 0) {
410257393Sian		device_printf(dev, "usb_bus_mem_alloc_all() failed\n");
411257393Sian		err = ENOMEM;
412257393Sian		goto out;
413257393Sian	}
414248557Sray
415257393Sian	/*
416257393Sian	 * Set handle to USB related registers subregion used by
417257393Sian	 * generic EHCI driver.
418257393Sian	 */
419257393Sian	err = bus_space_subregion(esc->sc_io_tag,
420257393Sian	    rman_get_bushandle(sc->ehci_mem_res),
421257393Sian	    IMX_EHCI_REG_OFF, IMX_EHCI_REG_SIZE, &esc->sc_io_hdl);
422257393Sian	if (err != 0) {
423257393Sian		device_printf(dev, "bus_space_subregion() failed\n");
424257393Sian		err = ENXIO;
425257393Sian		goto out;
426257393Sian	}
427248557Sray
428257393Sian	/* Setup interrupt handler. */
429297579Smmel	err = bus_setup_intr(dev, sc->ehci_irq_res, INTR_TYPE_BIO | INTR_MPSAFE,
430297579Smmel	    NULL, (driver_intr_t *)ehci_interrupt, esc, &esc->sc_intr_hdl);
431257393Sian	if (err != 0) {
432257393Sian		device_printf(dev, "Could not setup IRQ\n");
433257393Sian		goto out;
434257393Sian	}
435248557Sray
436257393Sian	/* Turn on clocks. */
437257393Sian	imx_ccm_usb_enable(dev);
438248557Sray
439323422Sian	/* Disable overcurrent detection, if configured to do so. */
440323422Sian	if (OF_hasprop(ofw_bus_get_node(sc->dev), "disable-over-current"))
441323422Sian		imx_ehci_disable_oc(sc);
442323422Sian
443257393Sian	/* Add USB bus device. */
444257393Sian	esc->sc_bus.bdev = device_add_child(dev, "usbus", -1);
445257393Sian	if (esc->sc_bus.bdev == NULL) {
446257393Sian		device_printf(dev, "Could not add USB device\n");
447257393Sian		goto out;
448257393Sian	}
449257393Sian	device_set_ivars(esc->sc_bus.bdev, &esc->sc_bus);
450248557Sray
451257393Sian	esc->sc_id_vendor = USB_VENDOR_FREESCALE;
452257393Sian	strlcpy(esc->sc_vendor, "Freescale", sizeof(esc->sc_vendor));
453248557Sray
454313649Sian	/*
455313649Sian	 * Set flags that affect ehci_init() behavior, and hook our post-reset
456313649Sian	 * code into the standard controller code.
457313649Sian	 */
458314513Sian	esc->sc_flags |= EHCI_SCFLG_NORESTERM | EHCI_SCFLG_TT;
459313649Sian	esc->sc_vendor_post_reset = imx_ehci_post_reset;
460314513Sian	esc->sc_vendor_get_port_speed = ehci_get_port_speed_portsc;
461313649Sian
462257393Sian	err = ehci_init(esc);
463257393Sian	if (err != 0) {
464257393Sian		device_printf(dev, "USB init failed, usb_err_t=%d\n",
465257393Sian		    err);
466257393Sian		goto out;
467257393Sian	}
468257393Sian	esc->sc_flags |= EHCI_SCFLG_DONEINIT;
469248557Sray
470257393Sian	/* Probe the bus. */
471257393Sian	err = device_probe_and_attach(esc->sc_bus.bdev);
472257393Sian	if (err != 0) {
473257393Sian		device_printf(dev,
474257393Sian		    "device_probe_and_attach() failed\n");
475257393Sian		goto out;
476257393Sian	}
477248557Sray
478257393Sian	err = 0;
479248557Sray
480257393Sianout:
481248557Sray
482257393Sian	if (err != 0)
483257393Sian		imx_ehci_detach(dev);
484248557Sray
485257393Sian	return (err);
486248557Sray}
487248557Sray
488257393Sianstatic device_method_t ehci_methods[] = {
489257393Sian	/* Device interface */
490257393Sian	DEVMETHOD(device_probe, imx_ehci_probe),
491257393Sian	DEVMETHOD(device_attach, imx_ehci_attach),
492257393Sian	DEVMETHOD(device_detach, imx_ehci_detach),
493257393Sian	DEVMETHOD(device_suspend, bus_generic_suspend),
494257393Sian	DEVMETHOD(device_resume, bus_generic_resume),
495257393Sian	DEVMETHOD(device_shutdown, bus_generic_shutdown),
496248557Sray
497257393Sian	/* Bus interface */
498257393Sian	DEVMETHOD(bus_print_child, bus_generic_print_child),
499248557Sray
500257393Sian	DEVMETHOD_END
501257393Sian};
502248557Sray
503257393Sianstatic driver_t ehci_driver = {
504257393Sian	"ehci",
505257393Sian	ehci_methods,
506257393Sian	sizeof(struct imx_ehci_softc)
507257393Sian};
508248557Sray
509257393Sianstatic devclass_t ehci_devclass;
510248557Sray
511257393SianDRIVER_MODULE(ehci, simplebus, ehci_driver, ehci_devclass, 0, 0);
512257393SianMODULE_DEPEND(ehci, usb, 1, 1, 1);
513