obio_ehci.c revision 1.4 1 /* $NetBSD: obio_ehci.c,v 1.4 2016/04/23 10:15:28 skrll Exp $ */
2
3 /*
4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart (at) augustsson.net).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 *
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.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: obio_ehci.c,v 1.4 2016/04/23 10:15:28 skrll Exp $");
34
35 #include "locators.h"
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/device.h>
41 #include <sys/proc.h>
42 #include <sys/queue.h>
43
44 #include <sys/bus.h>
45
46 #include <arm/gemini/gemini_reg.h>
47 #include <arm/gemini/gemini_obiovar.h>
48
49 #include <dev/pci/pcidevs.h>
50
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>
55
56 #include <dev/usb/ehcireg.h>
57 #include <dev/usb/ehcivar.h>
58
59 #ifdef EHCI_DEBUG
60 #define DPRINTF(x) if (ehcidebug) printf x
61 extern int ehcidebug;
62 #else
63 #define DPRINTF(x)
64 #endif
65
66 #define EHCI_HCOTGDEV_INTR_STATUS 0xc0
67 #define EHCI_HCOTGDEV_INTR_MASK 0xc4
68 #define HC_INT 0x04
69 #define OTG_INT 0x02
70 #define DEV_INT 0x01
71
72 static int
73 ehci_obio_intr(void *arg)
74 {
75 struct ehci_softc * const sc = arg;
76 int rv = 0;
77 uint32_t v;
78
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);
81 if (v & HC_INT)
82 rv = ehci_intr(sc);
83 return rv;
84 }
85
86 static int
87 ehci_obio_match(device_t parent, cfdata_t match, void *aux)
88 {
89 struct obio_attach_args * const obio = aux;
90
91 if (obio->obio_addr == GEMINI_USB0_BASE
92 || obio->obio_addr == GEMINI_USB1_BASE)
93 return 1;
94
95 return 0;
96 }
97
98 static void
99 ehci_obio_attach(device_t parent, device_t self, void *aux)
100 {
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);
104
105 sc->sc_dev = self;
106 sc->sc_bus.ub_hcpriv = sc;
107 sc->iot = obio->obio_iot;
108
109 aprint_naive(": EHCI USB controller\n");
110 aprint_normal(": EHCI USB controller\n");
111
112 /* Map I/O registers */
113 if (bus_space_map(sc->iot, obio->obio_addr, obio->obio_size, 0,
114 &sc->ioh)) {
115 aprint_error("%s: can't map memory space\n", devname);
116 return;
117 }
118
119 sc->sc_bus.ub_dmatag = obio->obio_dmat;
120
121 /* Disable interrupts, so we don't get any spurious ones. */
122 sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH);
123 DPRINTF(("%s: offs=%d\n", devname, sc->sc_offs));
124 EOWRITE4(sc, EHCI_USBINTR, 0);
125 bus_space_write_4(sc->iot, sc->ioh, EHCI_HCOTGDEV_INTR_MASK,
126 OTG_INT|DEV_INT);
127
128 if (obio->obio_intr != OBIOCF_INTR_DEFAULT) {
129 intr_establish(obio->obio_intr, IPL_USB, IST_LEVEL,
130 ehci_obio_intr, sc);
131 }
132
133 sc->sc_bus.ub_revision = USBREV_2_0;
134
135 /* Figure out vendor for root hub descriptor. */
136 sc->sc_id_vendor = PCI_VENDOR_FARADAY;
137 strlcpy(sc->sc_vendor, "SL351x", sizeof(sc->sc_vendor));
138
139 int err = ehci_init(sc);
140 if (err) {
141 aprint_error("%s: init failed, error=%d\n", devname, err);
142 return;
143 }
144
145 /* Attach usb device. */
146 sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
147 }
148
149 CFATTACH_DECL2_NEW(ehci_obio, sizeof(struct ehci_softc),
150 ehci_obio_match, ehci_obio_attach, NULL, NULL, NULL, ehci_childdet);
151