gcscehci.c revision 1.1 1 1.1 jmcneill /* $NetBSD: gcscehci.c,v 1.1 2007/07/08 01:13:26 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*
4 1.1 jmcneill * Copyright (c) 2001, 2002, 2007 The NetBSD Foundation, Inc.
5 1.1 jmcneill * All rights reserved.
6 1.1 jmcneill *
7 1.1 jmcneill * This code is derived from software contributed to The NetBSD Foundation
8 1.1 jmcneill * by Lennart Augustsson (lennart (at) augustsson.net)
9 1.1 jmcneill * and Jared D. McNeill (jmcneill (at) invisible.ca)
10 1.1 jmcneill *
11 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
12 1.1 jmcneill * modification, are permitted provided that the following conditions
13 1.1 jmcneill * are met:
14 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
15 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
16 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
18 1.1 jmcneill * documentation and/or other materials provided with the distribution.
19 1.1 jmcneill * 3. All advertising materials mentioning features or use of this software
20 1.1 jmcneill * must display the following acknowledgement:
21 1.1 jmcneill * This product includes software developed by the NetBSD
22 1.1 jmcneill * Foundation, Inc. and its contributors.
23 1.1 jmcneill * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 jmcneill * contributors may be used to endorse or promote products derived
25 1.1 jmcneill * from this software without specific prior written permission.
26 1.1 jmcneill *
27 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 jmcneill * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 jmcneill * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 jmcneill * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 jmcneill * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 jmcneill * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 jmcneill * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 jmcneill * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 jmcneill * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 jmcneill * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 jmcneill * POSSIBILITY OF SUCH DAMAGE.
38 1.1 jmcneill */
39 1.1 jmcneill
40 1.1 jmcneill #include <sys/cdefs.h>
41 1.1 jmcneill __KERNEL_RCSID(0, "$NetBSD: gcscehci.c,v 1.1 2007/07/08 01:13:26 jmcneill Exp $");
42 1.1 jmcneill
43 1.1 jmcneill #include <sys/param.h>
44 1.1 jmcneill #include <sys/systm.h>
45 1.1 jmcneill #include <sys/kernel.h>
46 1.1 jmcneill #include <sys/device.h>
47 1.1 jmcneill #include <sys/proc.h>
48 1.1 jmcneill #include <sys/queue.h>
49 1.1 jmcneill
50 1.1 jmcneill #include <machine/bus.h>
51 1.1 jmcneill #include <machine/cpufunc.h>
52 1.1 jmcneill
53 1.1 jmcneill #include <dev/pci/pcidevs.h>
54 1.1 jmcneill #include <dev/pci/pcivar.h>
55 1.1 jmcneill #include <dev/pci/usb_pci.h>
56 1.1 jmcneill
57 1.1 jmcneill #include <dev/usb/usb.h>
58 1.1 jmcneill #include <dev/usb/usbdi.h>
59 1.1 jmcneill #include <dev/usb/usbdivar.h>
60 1.1 jmcneill #include <dev/usb/usb_mem.h>
61 1.1 jmcneill
62 1.1 jmcneill #include <dev/usb/ehcireg.h>
63 1.1 jmcneill #include <dev/usb/ehcivar.h>
64 1.1 jmcneill
65 1.1 jmcneill #ifdef EHCI_DEBUG
66 1.1 jmcneill #define DPRINTF(x) if (ehcidebug) printf x
67 1.1 jmcneill extern int ehcidebug;
68 1.1 jmcneill #else
69 1.1 jmcneill #define DPRINTF(x)
70 1.1 jmcneill #endif
71 1.1 jmcneill
72 1.1 jmcneill #define GCSCUSB_MSR_BASE 0x51200000
73 1.1 jmcneill #define GCSCUSB_MSR_EHCB (GCSCUSB_MSR_BASE + 0x09)
74 1.1 jmcneill
75 1.1 jmcneill struct gcscehci_softc {
76 1.1 jmcneill ehci_softc_t sc;
77 1.1 jmcneill pci_chipset_tag_t sc_pc;
78 1.1 jmcneill pcitag_t sc_tag;
79 1.1 jmcneill void *sc_ih; /* interrupt vectoring */
80 1.1 jmcneill };
81 1.1 jmcneill
82 1.1 jmcneill static int
83 1.1 jmcneill gcscehci_match(struct device *parent, struct cfdata *match, void *aux)
84 1.1 jmcneill {
85 1.1 jmcneill struct pci_attach_args *pa = (struct pci_attach_args *) aux;
86 1.1 jmcneill
87 1.1 jmcneill if (PCI_CLASS(pa->pa_class) == PCI_CLASS_SERIALBUS &&
88 1.1 jmcneill PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_SERIALBUS_USB &&
89 1.1 jmcneill PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_EHCI &&
90 1.1 jmcneill PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD &&
91 1.1 jmcneill PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_CS5536_EHCI)
92 1.1 jmcneill return (10); /* beat ehci_pci */
93 1.1 jmcneill
94 1.1 jmcneill return (0);
95 1.1 jmcneill }
96 1.1 jmcneill
97 1.1 jmcneill static void
98 1.1 jmcneill gcscehci_attach(struct device *parent, struct device *self, void *aux)
99 1.1 jmcneill {
100 1.1 jmcneill struct gcscehci_softc *sc = (struct gcscehci_softc *)self;
101 1.1 jmcneill struct pci_attach_args *pa = (struct pci_attach_args *)aux;
102 1.1 jmcneill pci_chipset_tag_t pc = pa->pa_pc;
103 1.1 jmcneill pcitag_t tag = pa->pa_tag;
104 1.1 jmcneill char const *intrstr;
105 1.1 jmcneill pci_intr_handle_t ih;
106 1.1 jmcneill const char *vendor;
107 1.1 jmcneill const char *devname = sc->sc.sc_bus.bdev.dv_xname;
108 1.1 jmcneill char devinfo[256];
109 1.1 jmcneill usbd_status r;
110 1.1 jmcneill bus_addr_t ehcibase;
111 1.1 jmcneill int ncomp;
112 1.1 jmcneill struct usb_pci *up;
113 1.1 jmcneill
114 1.1 jmcneill aprint_naive(": USB controller\n");
115 1.1 jmcneill
116 1.1 jmcneill pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
117 1.1 jmcneill aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
118 1.1 jmcneill PCI_REVISION(pa->pa_class));
119 1.1 jmcneill
120 1.1 jmcneill /* Map I/O registers */
121 1.1 jmcneill ehcibase = rdmsr(GCSCUSB_MSR_EHCB) & 0xffffff00;
122 1.1 jmcneill sc->sc.iot = pa->pa_memt;
123 1.1 jmcneill sc->sc.sc_size = 256;
124 1.1 jmcneill if (bus_space_map(sc->sc.iot, ehcibase, 256, 0, &sc->sc.ioh)) {
125 1.1 jmcneill aprint_error("%s: can't map memory space\n", devname);
126 1.1 jmcneill return;
127 1.1 jmcneill }
128 1.1 jmcneill
129 1.1 jmcneill sc->sc_pc = pc;
130 1.1 jmcneill sc->sc_tag = tag;
131 1.1 jmcneill sc->sc.sc_bus.dmatag = pa->pa_dmat;
132 1.1 jmcneill
133 1.1 jmcneill /* Disable interrupts, so we don't get any spurious ones. */
134 1.1 jmcneill sc->sc.sc_offs = EREAD1(&sc->sc, EHCI_CAPLENGTH);
135 1.1 jmcneill DPRINTF(("%s: offs=%d\n", devname, sc->sc.sc_offs));
136 1.1 jmcneill EOWRITE2(&sc->sc, EHCI_USBINTR, 0);
137 1.1 jmcneill
138 1.1 jmcneill /* Map and establish the interrupt. */
139 1.1 jmcneill if (pci_intr_map(pa, &ih)) {
140 1.1 jmcneill aprint_error("%s: couldn't map interrupt\n", devname);
141 1.1 jmcneill return;
142 1.1 jmcneill }
143 1.1 jmcneill intrstr = pci_intr_string(pc, ih);
144 1.1 jmcneill sc->sc_ih = pci_intr_establish(pc, ih, IPL_USB, ehci_intr, sc);
145 1.1 jmcneill if (sc->sc_ih == NULL) {
146 1.1 jmcneill aprint_error("%s: couldn't establish interrupt", devname);
147 1.1 jmcneill if (intrstr != NULL)
148 1.1 jmcneill aprint_normal(" at %s", intrstr);
149 1.1 jmcneill aprint_normal("\n");
150 1.1 jmcneill return;
151 1.1 jmcneill }
152 1.1 jmcneill aprint_normal("%s: interrupting at %s\n", devname, intrstr);
153 1.1 jmcneill
154 1.1 jmcneill sc->sc.sc_bus.usbrev = USBREV_2_0;
155 1.1 jmcneill
156 1.1 jmcneill /* Figure out vendor for root hub descriptor. */
157 1.1 jmcneill vendor = pci_findvendor(pa->pa_id);
158 1.1 jmcneill sc->sc.sc_id_vendor = PCI_VENDOR(pa->pa_id);
159 1.1 jmcneill if (vendor)
160 1.1 jmcneill strlcpy(sc->sc.sc_vendor, vendor, sizeof(sc->sc.sc_vendor));
161 1.1 jmcneill else
162 1.1 jmcneill snprintf(sc->sc.sc_vendor, sizeof(sc->sc.sc_vendor),
163 1.1 jmcneill "vendor 0x%04x", PCI_VENDOR(pa->pa_id));
164 1.1 jmcneill
165 1.1 jmcneill /*
166 1.1 jmcneill * Find companion controllers. According to the spec they always
167 1.1 jmcneill * have lower function numbers so they should be enumerated already.
168 1.1 jmcneill */
169 1.1 jmcneill ncomp = 0;
170 1.1 jmcneill TAILQ_FOREACH(up, &ehci_pci_alldevs, next) {
171 1.1 jmcneill if (up->bus == pa->pa_bus && up->device == pa->pa_device) {
172 1.1 jmcneill DPRINTF(("gcscehci_attach: companion %s\n",
173 1.1 jmcneill USBDEVNAME(up->usb->bdev)));
174 1.1 jmcneill sc->sc.sc_comps[ncomp++] = up->usb;
175 1.1 jmcneill if (ncomp >= EHCI_COMPANION_MAX)
176 1.1 jmcneill break;
177 1.1 jmcneill }
178 1.1 jmcneill }
179 1.1 jmcneill sc->sc.sc_ncomp = ncomp;
180 1.1 jmcneill
181 1.1 jmcneill r = ehci_init(&sc->sc);
182 1.1 jmcneill if (r != USBD_NORMAL_COMPLETION) {
183 1.1 jmcneill aprint_error("%s: init failed, error=%d\n", devname, r);
184 1.1 jmcneill return;
185 1.1 jmcneill }
186 1.1 jmcneill
187 1.1 jmcneill /* Attach usb device. */
188 1.1 jmcneill sc->sc.sc_child = config_found((void *)sc, &sc->sc.sc_bus,
189 1.1 jmcneill usbctlprint);
190 1.1 jmcneill }
191 1.1 jmcneill
192 1.1 jmcneill CFATTACH_DECL(gcscehci, sizeof(struct gcscehci_softc),
193 1.1 jmcneill gcscehci_match, gcscehci_attach, NULL, ehci_activate);
194