1 /* $NetBSD: obio_ehci.c,v 1.1 2008/10/24 16:48:29 matt Exp $ */
4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net).
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: obio_ehci.c,v 1.1 2008/10/24 16:48:29 matt Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/device.h>
42 #include <sys/queue.h>
46 #include <arm/gemini/gemini_reg.h>
47 #include <arm/gemini/gemini_obiovar.h>
49 #include <dev/pci/pcidevs.h>
51 #include <dev/usb/usb.h>
52 #include <dev/usb/usbdi.h>
53 #include <dev/usb/usbdivar.h>
54 #include <dev/usb/usb_mem.h>
56 #include <dev/usb/ehcireg.h>
57 #include <dev/usb/ehcivar.h>
60 #define DPRINTF(x) if (ehcidebug) printf x
66 #define EHCI_HCOTGDEV_INTR_STATUS 0xc0
67 #define EHCI_HCOTGDEV_INTR_MASK 0xc4
73 ehci_obio_intr(void *arg
)
75 struct ehci_softc
* const sc
= arg
;
79 v
= bus_space_read_4(sc
->iot
, sc
->ioh
, EHCI_HCOTGDEV_INTR_STATUS
);
80 bus_space_write_4(sc
->iot
, sc
->ioh
, EHCI_HCOTGDEV_INTR_STATUS
, v
);
87 ehci_obio_match(device_t parent
, cfdata_t match
, void *aux
)
89 struct obio_attach_args
* const obio
= aux
;
91 if (obio
->obio_addr
== GEMINI_USB0_BASE
92 || obio
->obio_addr
== GEMINI_USB1_BASE
)
99 ehci_obio_attach(device_t parent
, device_t self
, void *aux
)
101 struct ehci_softc
* const sc
= device_private(self
);
102 struct obio_attach_args
* const obio
= aux
;
103 const char * const devname
= device_xname(self
);
107 sc
->sc_bus
.hci_private
= sc
;
108 sc
->iot
= obio
->obio_iot
;
110 aprint_naive(": EHCI USB controller\n");
111 aprint_normal(": EHCI USB controller\n");
113 /* Map I/O registers */
114 if (bus_space_map(sc
->iot
, obio
->obio_addr
, obio
->obio_size
, 0,
116 aprint_error("%s: can't map memory space\n", devname
);
120 sc
->sc_bus
.dmatag
= obio
->obio_dmat
;
122 /* Disable interrupts, so we don't get any spurious ones. */
123 sc
->sc_offs
= EREAD1(sc
, EHCI_CAPLENGTH
);
124 DPRINTF(("%s: offs=%d\n", devname
, sc
->sc_offs
));
125 EOWRITE2(sc
, EHCI_USBINTR
, 0);
126 bus_space_write_4(sc
->iot
, sc
->ioh
, EHCI_HCOTGDEV_INTR_MASK
,
129 if (obio
->obio_intr
!= OBIOCF_INTR_DEFAULT
) {
130 intr_establish(obio
->obio_intr
, IPL_USB
, IST_LEVEL
,
134 sc
->sc_bus
.usbrev
= USBREV_2_0
;
136 /* Figure out vendor for root hub descriptor. */
137 sc
->sc_id_vendor
= PCI_VENDOR_FARADAY
;
138 strlcpy(sc
->sc_vendor
, "SL351x", sizeof(sc
->sc_vendor
));
141 if (r
!= USBD_NORMAL_COMPLETION
) {
142 aprint_error("%s: init failed, error=%d\n", devname
, r
);
146 /* Attach usb device. */
147 sc
->sc_child
= config_found(self
, &sc
->sc_bus
, usbctlprint
);
150 CFATTACH_DECL2_NEW(ehci_obio
, sizeof(struct ehci_softc
),
151 ehci_obio_match
, ehci_obio_attach
, NULL
, NULL
, NULL
, ehci_childdet
);