ohci_pci.c revision 1.1
11.1Saugustss/*	$NetBSD: ohci_pci.c,v 1.1 1998/07/12 19:51:58 augustss Exp $	*/
21.1Saugustss
31.1Saugustss/*
41.1Saugustss * Copyright (c) 1998 The NetBSD Foundation, Inc.
51.1Saugustss * All rights reserved.
61.1Saugustss *
71.1Saugustss * Author: Lennart Augustsson <augustss@carlstedt.se>
81.1Saugustss *         Carlstedt Research & Technology
91.1Saugustss *
101.1Saugustss * Redistribution and use in source and binary forms, with or without
111.1Saugustss * modification, are permitted provided that the following conditions
121.1Saugustss * are met:
131.1Saugustss * 1. Redistributions of source code must retain the above copyright
141.1Saugustss *    notice, this list of conditions and the following disclaimer.
151.1Saugustss * 2. Redistributions in binary form must reproduce the above copyright
161.1Saugustss *    notice, this list of conditions and the following disclaimer in the
171.1Saugustss *    documentation and/or other materials provided with the distribution.
181.1Saugustss * 3. All advertising materials mentioning features or use of this software
191.1Saugustss *    must display the following acknowledgement:
201.1Saugustss *        This product includes software developed by the NetBSD
211.1Saugustss *        Foundation, Inc. and its contributors.
221.1Saugustss * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Saugustss *    contributors may be used to endorse or promote products derived
241.1Saugustss *    from this software without specific prior written permission.
251.1Saugustss *
261.1Saugustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Saugustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Saugustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Saugustss * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Saugustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Saugustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Saugustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Saugustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Saugustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Saugustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Saugustss * POSSIBILITY OF SUCH DAMAGE.
371.1Saugustss */
381.1Saugustss
391.1Saugustss/*
401.1Saugustss * USB Open Host Controller driver.
411.1Saugustss *
421.1Saugustss * OHCI spec: http://www.intel.com/design/usb/ohci11d.pdf
431.1Saugustss * USB spec: http://www.teleport.com/cgi-bin/mailmerge.cgi/~usb/cgiform.tpl
441.1Saugustss */
451.1Saugustss
461.1Saugustss#include <sys/param.h>
471.1Saugustss#include <sys/systm.h>
481.1Saugustss#include <sys/kernel.h>
491.1Saugustss#include <sys/device.h>
501.1Saugustss#include <sys/proc.h>
511.1Saugustss#include <sys/queue.h>
521.1Saugustss
531.1Saugustss#include <dev/pci/pcidevs.h>
541.1Saugustss#include <dev/pci/pcivar.h>
551.1Saugustss
561.1Saugustss#include <dev/usb/usb.h>
571.1Saugustss#include <dev/usb/usbdi.h>
581.1Saugustss#include <dev/usb/usbdivar.h>
591.1Saugustss#include <dev/usb/ohcireg.h>
601.1Saugustss#include <dev/usb/ohcivar.h>
611.1Saugustss
621.1Saugustss#include <machine/bus.h>
631.1Saugustss
641.1Saugustssint	ohci_pci_match __P((struct device *, struct cfdata *, void *));
651.1Saugustssvoid	ohci_pci_attach __P((struct device *, struct device *, void *));
661.1Saugustss
671.1Saugustssstruct cfattach ohci_pci_ca = {
681.1Saugustss	sizeof(struct ohci_softc), ohci_pci_match, ohci_pci_attach
691.1Saugustss};
701.1Saugustss
711.1Saugustssint
721.1Saugustssohci_pci_match(parent, match, aux)
731.1Saugustss	struct device *parent;
741.1Saugustss	struct cfdata *match;
751.1Saugustss	void *aux;
761.1Saugustss{
771.1Saugustss	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
781.1Saugustss
791.1Saugustss	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_OPTI &&
801.1Saugustss	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_OPTI_RM861HA)
811.1Saugustss		return 1;
821.1Saugustss
831.1Saugustss	return 0;
841.1Saugustss}
851.1Saugustss
861.1Saugustssvoid
871.1Saugustssohci_pci_attach(parent, self, aux)
881.1Saugustss	struct device *parent;
891.1Saugustss	struct device *self;
901.1Saugustss	void *aux;
911.1Saugustss{
921.1Saugustss	struct ohci_softc *sc = (struct ohci_softc *)self;
931.1Saugustss	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
941.1Saugustss	pci_chipset_tag_t pc = pa->pa_pc;
951.1Saugustss	char const *intrstr;
961.1Saugustss	pci_intr_handle_t ih;
971.1Saugustss	pcireg_t csr;
981.1Saugustss	char devinfo[256];
991.1Saugustss	usbd_status r;
1001.1Saugustss	char *vendor;
1011.1Saugustss
1021.1Saugustss	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
1031.1Saugustss	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
1041.1Saugustss
1051.1Saugustss	/* Map I/O registers */
1061.1Saugustss	if (pci_mapreg_map(pa, PCI_CBMEM, PCI_MAPREG_TYPE_MEM, 0,
1071.1Saugustss			   &sc->iot, &sc->ioh, NULL, NULL)) {
1081.1Saugustss		printf("%s: can't map mem space\n", sc->sc_bus.bdev.dv_xname);
1091.1Saugustss		return;
1101.1Saugustss	}
1111.1Saugustss
1121.1Saugustss	sc->sc_dmatag = pa->pa_dmat;
1131.1Saugustss
1141.1Saugustss	/* Enable the device. */
1151.1Saugustss	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
1161.1Saugustss	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
1171.1Saugustss		       csr | PCI_COMMAND_MASTER_ENABLE);
1181.1Saugustss
1191.1Saugustss	/* Map and establish the interrupt. */
1201.1Saugustss	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
1211.1Saugustss	    pa->pa_intrline, &ih)) {
1221.1Saugustss		printf("%s: couldn't map interrupt\n", sc->sc_bus.bdev.dv_xname);
1231.1Saugustss		return;
1241.1Saugustss	}
1251.1Saugustss	intrstr = pci_intr_string(pc, ih);
1261.1Saugustss	sc->sc_ih = pci_intr_establish(pc, ih, IPL_USB, ohci_intr, sc);
1271.1Saugustss	if (sc->sc_ih == NULL) {
1281.1Saugustss		printf("%s: couldn't establish interrupt",
1291.1Saugustss		    sc->sc_bus.bdev.dv_xname);
1301.1Saugustss		if (intrstr != NULL)
1311.1Saugustss			printf(" at %s", intrstr);
1321.1Saugustss		printf("\n");
1331.1Saugustss		return;
1341.1Saugustss	}
1351.1Saugustss	printf("%s: interrupting at %s\n", sc->sc_bus.bdev.dv_xname, intrstr);
1361.1Saugustss
1371.1Saugustss	/* Figure out vendor for root hub descriptor. */
1381.1Saugustss	vendor = pci_findvendor(pa->pa_id);
1391.1Saugustss	if (vendor)
1401.1Saugustss		strncpy(sc->sc_vendor, vendor, sizeof(sc->sc_vendor));
1411.1Saugustss	else
1421.1Saugustss		sprintf(sc->sc_vendor, "vendor 0x%04x", PCI_VENDOR(pa->pa_id));
1431.1Saugustss
1441.1Saugustss	r = ohci_init(sc);
1451.1Saugustss	if (r != USBD_NORMAL_COMPLETION) {
1461.1Saugustss		printf("%s: init failed, error=%d\n", sc->sc_bus.bdev.dv_xname,
1471.1Saugustss		       r);
1481.1Saugustss		return;
1491.1Saugustss	}
1501.1Saugustss
1511.1Saugustss	/* Attach usb device. */
1521.1Saugustss	config_found((void *)sc, &sc->sc_bus, usbctlprint);
1531.1Saugustss}
154