pq3ehci.c revision 1.3.2.2 1 1.3.2.2 rmind /* $NetBSD: pq3ehci.c,v 1.3.2.2 2011/03/05 20:51:34 rmind Exp $ */
2 1.3.2.2 rmind /*-
3 1.3.2.2 rmind * Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
4 1.3.2.2 rmind * All rights reserved.
5 1.3.2.2 rmind *
6 1.3.2.2 rmind * This code is derived from software contributed to The NetBSD Foundation
7 1.3.2.2 rmind * by Matt Thomas of 3am Software Foundry.
8 1.3.2.2 rmind *
9 1.3.2.2 rmind * Redistribution and use in source and binary forms, with or without
10 1.3.2.2 rmind * modification, are permitted provided that the following conditions
11 1.3.2.2 rmind * are met:
12 1.3.2.2 rmind * 1. Redistributions of source code must retain the above copyright
13 1.3.2.2 rmind * notice, this list of conditions and the following disclaimer.
14 1.3.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
15 1.3.2.2 rmind * notice, this list of conditions and the following disclaimer in the
16 1.3.2.2 rmind * documentation and/or other materials provided with the distribution.
17 1.3.2.2 rmind *
18 1.3.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 1.3.2.2 rmind * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.3.2.2 rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.3.2.2 rmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 1.3.2.2 rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.3.2.2 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.3.2.2 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.3.2.2 rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.3.2.2 rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.3.2.2 rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.3.2.2 rmind * POSSIBILITY OF SUCH DAMAGE.
29 1.3.2.2 rmind */
30 1.3.2.2 rmind
31 1.3.2.2 rmind #include <sys/cdefs.h>
32 1.3.2.2 rmind __KERNEL_RCSID(0, "$NetBSD: pq3ehci.c,v 1.3.2.2 2011/03/05 20:51:34 rmind Exp $");
33 1.3.2.2 rmind
34 1.3.2.2 rmind #include <sys/param.h>
35 1.3.2.2 rmind #include <sys/systm.h>
36 1.3.2.2 rmind #include <sys/device.h>
37 1.3.2.2 rmind #include <sys/kernel.h>
38 1.3.2.2 rmind #include <sys/proc.h>
39 1.3.2.2 rmind #include <sys/queue.h>
40 1.3.2.2 rmind
41 1.3.2.2 rmind #include <sys/bus.h>
42 1.3.2.2 rmind
43 1.3.2.2 rmind #include <powerpc/booke/cpuvar.h>
44 1.3.2.2 rmind #include <powerpc/booke/e500var.h>
45 1.3.2.2 rmind #include <powerpc/booke/e500reg.h>
46 1.3.2.2 rmind
47 1.3.2.2 rmind #include <dev/usb/usb.h>
48 1.3.2.2 rmind #include <dev/usb/usbdi.h>
49 1.3.2.2 rmind #include <dev/usb/usbdivar.h>
50 1.3.2.2 rmind #include <dev/usb/usb_mem.h>
51 1.3.2.2 rmind
52 1.3.2.2 rmind #include <dev/usb/ehcireg.h>
53 1.3.2.2 rmind #include <dev/usb/ehcivar.h>
54 1.3.2.2 rmind
55 1.3.2.2 rmind #ifdef EHCI_DEBUG
56 1.3.2.2 rmind #define DPRINTF(x) if (ehcidebug) printf x
57 1.3.2.2 rmind extern int ehcidebug;
58 1.3.2.2 rmind #else
59 1.3.2.2 rmind #define DPRINTF(x)
60 1.3.2.2 rmind #endif
61 1.3.2.2 rmind
62 1.3.2.2 rmind static int pq3ehci_match(device_t, cfdata_t, void *);
63 1.3.2.2 rmind static void pq3ehci_attach(device_t, device_t, void *);
64 1.3.2.2 rmind
65 1.3.2.2 rmind struct pq3ehci_softc {
66 1.3.2.2 rmind ehci_softc_t sc;
67 1.3.2.2 rmind void *sc_ih; /* interrupt vectoring */
68 1.3.2.2 rmind };
69 1.3.2.2 rmind
70 1.3.2.2 rmind CFATTACH_DECL_NEW(pq3ehci, sizeof(struct pq3ehci_softc),
71 1.3.2.2 rmind pq3ehci_match, pq3ehci_attach, NULL, NULL);
72 1.3.2.2 rmind
73 1.3.2.2 rmind static int
74 1.3.2.2 rmind pq3ehci_match(device_t parent, cfdata_t cf, void *aux)
75 1.3.2.2 rmind {
76 1.3.2.2 rmind
77 1.3.2.2 rmind if (!e500_cpunode_submatch(parent, cf, cf->cf_name, aux))
78 1.3.2.2 rmind return 0;
79 1.3.2.2 rmind
80 1.3.2.2 rmind return 1;
81 1.3.2.2 rmind }
82 1.3.2.2 rmind
83 1.3.2.2 rmind static void
84 1.3.2.2 rmind pq3ehci_attach(device_t parent, device_t self, void *aux)
85 1.3.2.2 rmind {
86 1.3.2.2 rmind struct cpunode_softc * const psc = device_private(parent);
87 1.3.2.2 rmind struct pq3ehci_softc * const sc = device_private(self);
88 1.3.2.2 rmind struct cpunode_attach_args * const cna = aux;
89 1.3.2.2 rmind struct cpunode_locators * const cnl = &cna->cna_locs;
90 1.3.2.2 rmind int error;
91 1.3.2.2 rmind
92 1.3.2.2 rmind psc->sc_children |= cna->cna_childmask;
93 1.3.2.2 rmind sc->sc.iot = cna->cna_le_memt; /* EHCI registers are little endian */
94 1.3.2.2 rmind sc->sc.sc_dev = self;
95 1.3.2.2 rmind sc->sc.sc_bus.dmatag = cna->cna_dmat;
96 1.3.2.2 rmind sc->sc.sc_bus.hci_private = sc;
97 1.3.2.2 rmind sc->sc.sc_bus.usbrev = USBREV_2_0;
98 1.3.2.2 rmind sc->sc.sc_ncomp = 0;
99 1.3.2.2 rmind sc->sc.sc_flags |= EHCIF_ETTF;
100 1.3.2.2 rmind
101 1.3.2.2 rmind aprint_naive(": USB controller\n");
102 1.3.2.2 rmind aprint_normal(": USB controller\n");
103 1.3.2.2 rmind
104 1.3.2.2 rmind error = bus_space_map(sc->sc.iot, cnl->cnl_addr, cnl->cnl_size, 0,
105 1.3.2.2 rmind &sc->sc.ioh);
106 1.3.2.2 rmind if (error) {
107 1.3.2.2 rmind aprint_error_dev(self,
108 1.3.2.2 rmind "can't map registers for %s#%u: %d\n",
109 1.3.2.2 rmind cnl->cnl_name, cnl->cnl_instance, error);
110 1.3.2.2 rmind return;
111 1.3.2.2 rmind }
112 1.3.2.2 rmind sc->sc.sc_size = cnl->cnl_size;
113 1.3.2.2 rmind
114 1.3.2.2 rmind /*
115 1.3.2.2 rmind * We need to tell the USB interface to snoop all off RAM starting
116 1.3.2.2 rmind * at 0. Since it can do it by powers of 2, get the highest RAM
117 1.3.2.2 rmind * address and roughly round it to the next power of 2 and find
118 1.3.2.2 rmind * the number of leading zero bits.
119 1.3.2.2 rmind */
120 1.3.2.2 rmind cpu_write_4(cnl->cnl_addr + USB_SNOOP1,
121 1.3.2.2 rmind SNOOP_2GB - __builtin_clz(curcpu()->ci_softc->cpu_highmem * 2 - 1));
122 1.3.2.2 rmind
123 1.3.2.2 rmind sc->sc_ih = intr_establish(cnl->cnl_intrs[0], IPL_USB, IST_ONCHIP,
124 1.3.2.2 rmind ehci_intr, sc);
125 1.3.2.2 rmind if (sc->sc_ih == NULL) {
126 1.3.2.2 rmind aprint_error_dev(self, "failed to establish interrupt %d\n",
127 1.3.2.2 rmind cnl->cnl_intrs[0]);
128 1.3.2.2 rmind goto fail;
129 1.3.2.2 rmind }
130 1.3.2.2 rmind aprint_normal_dev(self, "interrupting on irq %d\n",
131 1.3.2.2 rmind cnl->cnl_intrs[0]);
132 1.3.2.2 rmind
133 1.3.2.2 rmind /* offs is needed for EOWRITEx */
134 1.3.2.2 rmind sc->sc.sc_offs = EREAD1(&sc->sc, EHCI_CAPLENGTH);
135 1.3.2.2 rmind
136 1.3.2.2 rmind /* Disable interrupts, so we don't get any spurious ones. */
137 1.3.2.2 rmind DPRINTF(("%s: offs=%d\n", device_xname(self), sc->sc.sc_offs));
138 1.3.2.2 rmind EOWRITE2(&sc->sc, EHCI_USBINTR, 0);
139 1.3.2.2 rmind
140 1.3.2.2 rmind error = ehci_init(&sc->sc);
141 1.3.2.2 rmind if (error != USBD_NORMAL_COMPLETION) {
142 1.3.2.2 rmind aprint_error_dev(self, "init failed, error=%d\n", error);
143 1.3.2.2 rmind goto fail;
144 1.3.2.2 rmind }
145 1.3.2.2 rmind
146 1.3.2.2 rmind /* Attach usb device. */
147 1.3.2.2 rmind sc->sc.sc_child = config_found(self, &sc->sc.sc_bus, usbctlprint);
148 1.3.2.2 rmind return;
149 1.3.2.2 rmind
150 1.3.2.2 rmind fail:
151 1.3.2.2 rmind if (sc->sc_ih) {
152 1.3.2.2 rmind intr_disestablish(sc->sc_ih);
153 1.3.2.2 rmind sc->sc_ih = NULL;
154 1.3.2.2 rmind }
155 1.3.2.2 rmind if (sc->sc.sc_size) {
156 1.3.2.2 rmind bus_space_unmap(sc->sc.iot, sc->sc.ioh, sc->sc.sc_size);
157 1.3.2.2 rmind sc->sc.sc_size = 0;
158 1.3.2.2 rmind }
159 1.3.2.2 rmind return;
160 1.3.2.2 rmind }
161