ohci_pci.c revision 1.14
11.14Saugustss/* $NetBSD: ohci_pci.c,v 1.14 1999/10/12 11:21:24 augustss Exp $ */ 21.1Saugustss 31.1Saugustss/* 41.1Saugustss * Copyright (c) 1998 The NetBSD Foundation, Inc. 51.1Saugustss * All rights reserved. 61.1Saugustss * 71.5Saugustss * This code is derived from software contributed to The NetBSD Foundation 81.5Saugustss * by Lennart Augustsson (augustss@carlstedt.se) at 91.5Saugustss * Carlstedt Research & Technology. 101.1Saugustss * 111.1Saugustss * Redistribution and use in source and binary forms, with or without 121.1Saugustss * modification, are permitted provided that the following conditions 131.1Saugustss * are met: 141.1Saugustss * 1. Redistributions of source code must retain the above copyright 151.1Saugustss * notice, this list of conditions and the following disclaimer. 161.1Saugustss * 2. Redistributions in binary form must reproduce the above copyright 171.1Saugustss * notice, this list of conditions and the following disclaimer in the 181.1Saugustss * documentation and/or other materials provided with the distribution. 191.1Saugustss * 3. All advertising materials mentioning features or use of this software 201.1Saugustss * must display the following acknowledgement: 211.1Saugustss * This product includes software developed by the NetBSD 221.1Saugustss * Foundation, Inc. and its contributors. 231.1Saugustss * 4. Neither the name of The NetBSD Foundation nor the names of its 241.1Saugustss * contributors may be used to endorse or promote products derived 251.1Saugustss * from this software without specific prior written permission. 261.1Saugustss * 271.1Saugustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 281.1Saugustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 291.1Saugustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 301.1Saugustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 311.1Saugustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 321.1Saugustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 331.1Saugustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 341.1Saugustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 351.1Saugustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 361.1Saugustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 371.1Saugustss * POSSIBILITY OF SUCH DAMAGE. 381.1Saugustss */ 391.1Saugustss 401.1Saugustss/* 411.1Saugustss * USB Open Host Controller driver. 421.1Saugustss * 431.1Saugustss * OHCI spec: http://www.intel.com/design/usb/ohci11d.pdf 441.1Saugustss * USB spec: http://www.teleport.com/cgi-bin/mailmerge.cgi/~usb/cgiform.tpl 451.1Saugustss */ 461.1Saugustss 471.1Saugustss#include <sys/param.h> 481.1Saugustss#include <sys/systm.h> 491.1Saugustss#include <sys/kernel.h> 501.1Saugustss#include <sys/device.h> 511.1Saugustss#include <sys/proc.h> 521.1Saugustss#include <sys/queue.h> 531.1Saugustss 541.3Saugustss#include <machine/bus.h> 551.3Saugustss 561.1Saugustss#include <dev/pci/pcivar.h> 571.1Saugustss 581.1Saugustss#include <dev/usb/usb.h> 591.1Saugustss#include <dev/usb/usbdi.h> 601.1Saugustss#include <dev/usb/usbdivar.h> 611.3Saugustss#include <dev/usb/usb_mem.h> 621.3Saugustss 631.1Saugustss#include <dev/usb/ohcireg.h> 641.1Saugustss#include <dev/usb/ohcivar.h> 651.1Saugustss 661.1Saugustssint ohci_pci_match __P((struct device *, struct cfdata *, void *)); 671.1Saugustssvoid ohci_pci_attach __P((struct device *, struct device *, void *)); 681.14Saugustssint ohci_pci_detach __P((device_ptr_t, int)); 691.14Saugustss 701.14Saugustssstruct ohci_pci_softc { 711.14Saugustss ohci_softc_t sc; 721.14Saugustss pci_chipset_tag_t sc_pc; 731.14Saugustss bus_size_t sc_size; 741.14Saugustss void *sc_ih; /* interrupt vectoring */ 751.14Saugustss}; 761.1Saugustss 771.1Saugustssstruct cfattach ohci_pci_ca = { 781.14Saugustss sizeof(struct ohci_pci_softc), ohci_pci_match, ohci_pci_attach, 791.14Saugustss ohci_pci_detach, ohci_activate 801.1Saugustss}; 811.1Saugustss 821.1Saugustssint 831.1Saugustssohci_pci_match(parent, match, aux) 841.1Saugustss struct device *parent; 851.1Saugustss struct cfdata *match; 861.1Saugustss void *aux; 871.1Saugustss{ 881.1Saugustss struct pci_attach_args *pa = (struct pci_attach_args *) aux; 891.1Saugustss 901.4Saugustss if (PCI_CLASS(pa->pa_class) == PCI_CLASS_SERIALBUS && 911.4Saugustss PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_SERIALBUS_USB && 921.4Saugustss PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_OHCI) 931.14Saugustss return (1); 941.2Saugustss 951.14Saugustss return (0); 961.1Saugustss} 971.1Saugustss 981.1Saugustssvoid 991.1Saugustssohci_pci_attach(parent, self, aux) 1001.1Saugustss struct device *parent; 1011.1Saugustss struct device *self; 1021.1Saugustss void *aux; 1031.1Saugustss{ 1041.14Saugustss struct ohci_pci_softc *sc = (struct ohci_pci_softc *)self; 1051.1Saugustss struct pci_attach_args *pa = (struct pci_attach_args *)aux; 1061.1Saugustss pci_chipset_tag_t pc = pa->pa_pc; 1071.1Saugustss char const *intrstr; 1081.1Saugustss pci_intr_handle_t ih; 1091.1Saugustss pcireg_t csr; 1101.1Saugustss char devinfo[256]; 1111.1Saugustss usbd_status r; 1121.1Saugustss char *vendor; 1131.14Saugustss char *devname = sc->sc.sc_bus.bdev.dv_xname; 1141.1Saugustss 1151.1Saugustss pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo); 1161.1Saugustss printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class)); 1171.10Saugustss 1181.1Saugustss /* Map I/O registers */ 1191.1Saugustss if (pci_mapreg_map(pa, PCI_CBMEM, PCI_MAPREG_TYPE_MEM, 0, 1201.14Saugustss &sc->sc.iot, &sc->sc.ioh, NULL, &sc->sc_size)) { 1211.14Saugustss printf("%s: can't map mem space\n", devname); 1221.1Saugustss return; 1231.1Saugustss } 1241.11Saugustss 1251.14Saugustss /* Disable interrupts, so we don't get any spurious ones. */ 1261.14Saugustss bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE, 1271.14Saugustss OHCI_ALL_INTRS); 1281.1Saugustss 1291.14Saugustss sc->sc_pc = pc; 1301.14Saugustss sc->sc.sc_bus.dmatag = pa->pa_dmat; 1311.1Saugustss 1321.1Saugustss /* Enable the device. */ 1331.1Saugustss csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); 1341.1Saugustss pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 1351.1Saugustss csr | PCI_COMMAND_MASTER_ENABLE); 1361.1Saugustss 1371.1Saugustss /* Map and establish the interrupt. */ 1381.1Saugustss if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, 1391.1Saugustss pa->pa_intrline, &ih)) { 1401.14Saugustss printf("%s: couldn't map interrupt\n", devname); 1411.1Saugustss return; 1421.1Saugustss } 1431.1Saugustss intrstr = pci_intr_string(pc, ih); 1441.1Saugustss sc->sc_ih = pci_intr_establish(pc, ih, IPL_USB, ohci_intr, sc); 1451.1Saugustss if (sc->sc_ih == NULL) { 1461.14Saugustss printf("%s: couldn't establish interrupt", devname); 1471.1Saugustss if (intrstr != NULL) 1481.1Saugustss printf(" at %s", intrstr); 1491.1Saugustss printf("\n"); 1501.1Saugustss return; 1511.1Saugustss } 1521.14Saugustss printf("%s: interrupting at %s\n", devname, intrstr); 1531.1Saugustss 1541.1Saugustss /* Figure out vendor for root hub descriptor. */ 1551.1Saugustss vendor = pci_findvendor(pa->pa_id); 1561.14Saugustss sc->sc.sc_id_vendor = PCI_VENDOR(pa->pa_id); 1571.1Saugustss if (vendor) 1581.14Saugustss strncpy(sc->sc.sc_vendor, vendor, 1591.14Saugustss sizeof(sc->sc.sc_vendor) - 1); 1601.1Saugustss else 1611.14Saugustss sprintf(sc->sc.sc_vendor, "vendor 0x%04x", 1621.14Saugustss PCI_VENDOR(pa->pa_id)); 1631.1Saugustss 1641.14Saugustss r = ohci_init(&sc->sc); 1651.1Saugustss if (r != USBD_NORMAL_COMPLETION) { 1661.14Saugustss printf("%s: init failed, error=%d\n", devname, r); 1671.1Saugustss return; 1681.1Saugustss } 1691.1Saugustss 1701.1Saugustss /* Attach usb device. */ 1711.14Saugustss sc->sc.sc_child = config_found((void *)sc, &sc->sc.sc_bus, 1721.14Saugustss usbctlprint); 1731.14Saugustss} 1741.14Saugustss 1751.14Saugustssint 1761.14Saugustssohci_pci_detach(self, flags) 1771.14Saugustss device_ptr_t self; 1781.14Saugustss int flags; 1791.14Saugustss{ 1801.14Saugustss struct ohci_pci_softc *sc = (struct ohci_pci_softc *)self; 1811.14Saugustss int rv; 1821.14Saugustss 1831.14Saugustss rv = ohci_detach(&sc->sc, flags); 1841.14Saugustss if (rv) 1851.14Saugustss return (rv); 1861.14Saugustss if (sc->sc_ih) { 1871.14Saugustss pci_intr_disestablish(sc->sc_pc, sc->sc_ih); 1881.14Saugustss sc->sc_ih = 0; 1891.14Saugustss } 1901.14Saugustss if (sc->sc_size) { 1911.14Saugustss bus_space_unmap(sc->sc.iot, sc->sc.ioh, sc->sc_size); 1921.14Saugustss sc->sc_size = 0; 1931.14Saugustss } 1941.14Saugustss return (0); 1951.1Saugustss} 196