1 /* $NetBSD: uhci_pci.c,v 1.3 1998/07/25 23:23:01 augustss Exp $ */ 2 3 /* 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Author: Lennart Augustsson <augustss@carlstedt.se> 8 * Carlstedt Research & Technology 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/kernel.h> 42 #include <sys/device.h> 43 #include <sys/proc.h> 44 #include <sys/queue.h> 45 46 #include <machine/bus.h> 47 48 #include <dev/pci/pcivar.h> 49 50 #include <dev/usb/usb.h> 51 #include <dev/usb/usbdi.h> 52 #include <dev/usb/usbdivar.h> 53 #include <dev/usb/usb_mem.h> 54 55 #include <dev/usb/uhcireg.h> 56 #include <dev/usb/uhcivar.h> 57 58 int uhci_pci_match __P((struct device *, struct cfdata *, void *)); 59 void uhci_pci_attach __P((struct device *, struct device *, void *)); 60 61 struct cfattach uhci_pci_ca = { 62 sizeof(uhci_softc_t), uhci_pci_match, uhci_pci_attach 63 }; 64 65 int 66 uhci_pci_match(parent, match, aux) 67 struct device *parent; 68 struct cfdata *match; 69 void *aux; 70 { 71 struct pci_attach_args *pa = (struct pci_attach_args *) aux; 72 73 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_SERIALBUS && 74 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_SERIALBUS_USB && 75 PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_UHCI) 76 return 1; 77 78 return 0; 79 } 80 81 void 82 uhci_pci_attach(parent, self, aux) 83 struct device *parent; 84 struct device *self; 85 void *aux; 86 { 87 uhci_softc_t *sc = (uhci_softc_t *)self; 88 struct pci_attach_args *pa = (struct pci_attach_args *)aux; 89 pci_chipset_tag_t pc = pa->pa_pc; 90 char const *intrstr; 91 pci_intr_handle_t ih; 92 pcireg_t csr; 93 char *typestr, *vendor; 94 char devinfo[256]; 95 usbd_status r; 96 97 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo); 98 printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class)); 99 100 /* Map I/O registers */ 101 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, 102 &sc->iot, &sc->ioh, NULL, NULL)) { 103 printf("%s: can't map i/o space\n", sc->sc_bus.bdev.dv_xname); 104 return; 105 } 106 107 sc->sc_dmatag = pa->pa_dmat; 108 109 /* Enable the device. */ 110 csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); 111 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 112 csr | PCI_COMMAND_MASTER_ENABLE); 113 114 /* Map and establish the interrupt. */ 115 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, 116 pa->pa_intrline, &ih)) { 117 printf("%s: couldn't map interrupt\n", 118 sc->sc_bus.bdev.dv_xname); 119 return; 120 } 121 intrstr = pci_intr_string(pc, ih); 122 sc->sc_ih = pci_intr_establish(pc, ih, IPL_USB, uhci_intr, sc); 123 if (sc->sc_ih == NULL) { 124 printf("%s: couldn't establish interrupt", 125 sc->sc_bus.bdev.dv_xname); 126 if (intrstr != NULL) 127 printf(" at %s", intrstr); 128 printf("\n"); 129 return; 130 } 131 printf("%s: interrupting at %s\n", sc->sc_bus.bdev.dv_xname, intrstr); 132 133 switch(pci_conf_read(pc, pa->pa_tag, PCI_USBREV) & PCI_USBREV_MASK) { 134 case PCI_USBREV_PRE_1_0: 135 typestr = "pre 1.0"; 136 break; 137 case PCI_USBREV_1_0: 138 typestr = "1.0"; 139 break; 140 default: 141 typestr = "unknown"; 142 break; 143 } 144 printf("%s: USB version %s\n", sc->sc_bus.bdev.dv_xname, typestr); 145 146 /* Figure out vendor for root hub descriptor. */ 147 vendor = pci_findvendor(pa->pa_id); 148 if (vendor) 149 strncpy(sc->sc_vendor, vendor, sizeof(sc->sc_vendor)); 150 else 151 sprintf(sc->sc_vendor, "vendor 0x%04x", PCI_VENDOR(pa->pa_id)); 152 153 r = uhci_init(sc); 154 if (r != USBD_NORMAL_COMPLETION) { 155 printf("%s: init failed, error=%d\n", 156 sc->sc_bus.bdev.dv_xname, r); 157 return; 158 } 159 160 /* Attach usb device. */ 161 config_found((void *)sc, &sc->sc_bus, usbctlprint); 162 } 163