obio_ehci.c revision 1.2 1 1.2 matt /* $NetBSD: obio_ehci.c,v 1.2 2008/10/24 17:31:24 matt Exp $ */
2 1.1 matt
3 1.1 matt /*
4 1.1 matt * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Lennart Augustsson (lennart (at) augustsson.net).
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt *
19 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
30 1.1 matt */
31 1.1 matt
32 1.1 matt #include <sys/cdefs.h>
33 1.2 matt __KERNEL_RCSID(0, "$NetBSD: obio_ehci.c,v 1.2 2008/10/24 17:31:24 matt Exp $");
34 1.1 matt
35 1.1 matt #include "locators.h"
36 1.1 matt
37 1.1 matt #include <sys/param.h>
38 1.1 matt #include <sys/systm.h>
39 1.1 matt #include <sys/kernel.h>
40 1.1 matt #include <sys/device.h>
41 1.1 matt #include <sys/proc.h>
42 1.1 matt #include <sys/queue.h>
43 1.1 matt
44 1.1 matt #include <sys/bus.h>
45 1.1 matt
46 1.1 matt #include <arm/gemini/gemini_reg.h>
47 1.1 matt #include <arm/gemini/gemini_obiovar.h>
48 1.1 matt
49 1.1 matt #include <dev/pci/pcidevs.h>
50 1.1 matt
51 1.1 matt #include <dev/usb/usb.h>
52 1.1 matt #include <dev/usb/usbdi.h>
53 1.1 matt #include <dev/usb/usbdivar.h>
54 1.1 matt #include <dev/usb/usb_mem.h>
55 1.1 matt
56 1.1 matt #include <dev/usb/ehcireg.h>
57 1.1 matt #include <dev/usb/ehcivar.h>
58 1.1 matt
59 1.1 matt #ifdef EHCI_DEBUG
60 1.1 matt #define DPRINTF(x) if (ehcidebug) printf x
61 1.1 matt extern int ehcidebug;
62 1.1 matt #else
63 1.1 matt #define DPRINTF(x)
64 1.1 matt #endif
65 1.1 matt
66 1.1 matt #define EHCI_HCOTGDEV_INTR_STATUS 0xc0
67 1.1 matt #define EHCI_HCOTGDEV_INTR_MASK 0xc4
68 1.1 matt #define HC_INT 0x04
69 1.1 matt #define OTG_INT 0x02
70 1.1 matt #define DEV_INT 0x01
71 1.1 matt
72 1.1 matt static int
73 1.1 matt ehci_obio_intr(void *arg)
74 1.1 matt {
75 1.1 matt struct ehci_softc * const sc = arg;
76 1.1 matt int rv = 0;
77 1.1 matt uint32_t v;
78 1.1 matt
79 1.1 matt v = bus_space_read_4(sc->iot, sc->ioh, EHCI_HCOTGDEV_INTR_STATUS);
80 1.1 matt bus_space_write_4(sc->iot, sc->ioh, EHCI_HCOTGDEV_INTR_STATUS, v);
81 1.1 matt if (v & HC_INT)
82 1.1 matt rv = ehci_intr(sc);
83 1.1 matt return rv;
84 1.1 matt }
85 1.1 matt
86 1.1 matt static int
87 1.1 matt ehci_obio_match(device_t parent, cfdata_t match, void *aux)
88 1.1 matt {
89 1.1 matt struct obio_attach_args * const obio = aux;
90 1.1 matt
91 1.1 matt if (obio->obio_addr == GEMINI_USB0_BASE
92 1.1 matt || obio->obio_addr == GEMINI_USB1_BASE)
93 1.1 matt return 1;
94 1.1 matt
95 1.1 matt return 0;
96 1.1 matt }
97 1.1 matt
98 1.1 matt static void
99 1.1 matt ehci_obio_attach(device_t parent, device_t self, void *aux)
100 1.1 matt {
101 1.1 matt struct ehci_softc * const sc = device_private(self);
102 1.1 matt struct obio_attach_args * const obio = aux;
103 1.1 matt const char * const devname = device_xname(self);
104 1.1 matt usbd_status r;
105 1.1 matt
106 1.1 matt sc->sc_dev = self;
107 1.1 matt sc->sc_bus.hci_private = sc;
108 1.1 matt sc->iot = obio->obio_iot;
109 1.1 matt
110 1.1 matt aprint_naive(": EHCI USB controller\n");
111 1.2 matt aprint_normal(": EHCI USB controller\n");
112 1.1 matt
113 1.1 matt /* Map I/O registers */
114 1.1 matt if (bus_space_map(sc->iot, obio->obio_addr, obio->obio_size, 0,
115 1.1 matt &sc->ioh)) {
116 1.1 matt aprint_error("%s: can't map memory space\n", devname);
117 1.1 matt return;
118 1.1 matt }
119 1.1 matt
120 1.1 matt sc->sc_bus.dmatag = obio->obio_dmat;
121 1.1 matt
122 1.1 matt /* Disable interrupts, so we don't get any spurious ones. */
123 1.1 matt sc->sc_offs = EREAD1(sc, EHCI_CAPLENGTH);
124 1.1 matt DPRINTF(("%s: offs=%d\n", devname, sc->sc_offs));
125 1.1 matt EOWRITE2(sc, EHCI_USBINTR, 0);
126 1.1 matt bus_space_write_4(sc->iot, sc->ioh, EHCI_HCOTGDEV_INTR_MASK,
127 1.1 matt OTG_INT|DEV_INT);
128 1.1 matt
129 1.1 matt if (obio->obio_intr != OBIOCF_INTR_DEFAULT) {
130 1.1 matt intr_establish(obio->obio_intr, IPL_USB, IST_LEVEL,
131 1.1 matt ehci_obio_intr, sc);
132 1.1 matt }
133 1.1 matt
134 1.1 matt sc->sc_bus.usbrev = USBREV_2_0;
135 1.1 matt
136 1.1 matt /* Figure out vendor for root hub descriptor. */
137 1.1 matt sc->sc_id_vendor = PCI_VENDOR_FARADAY;
138 1.1 matt strlcpy(sc->sc_vendor, "SL351x", sizeof(sc->sc_vendor));
139 1.1 matt
140 1.1 matt r = ehci_init(sc);
141 1.1 matt if (r != USBD_NORMAL_COMPLETION) {
142 1.1 matt aprint_error("%s: init failed, error=%d\n", devname, r);
143 1.1 matt return;
144 1.1 matt }
145 1.1 matt
146 1.1 matt /* Attach usb device. */
147 1.1 matt sc->sc_child = config_found(self, &sc->sc_bus, usbctlprint);
148 1.1 matt }
149 1.1 matt
150 1.1 matt CFATTACH_DECL2_NEW(ehci_obio, sizeof(struct ehci_softc),
151 1.1 matt ehci_obio_match, ehci_obio_attach, NULL, NULL, NULL, ehci_childdet);
152