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