Home | History | Annotate | Line # | Download | only in pci
fwohci_pci.c revision 1.21.4.4
      1  1.21.4.4      yamt /*	$NetBSD: fwohci_pci.c,v 1.21.4.4 2007/11/15 11:44:19 yamt Exp $	*/
      2       1.5     enami 
      3       1.1      matt /*-
      4       1.1      matt  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5       1.1      matt  * All rights reserved.
      6       1.1      matt  *
      7       1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      matt  * by Matt Thomas of 3am Software Foundry.
      9       1.1      matt  *
     10       1.1      matt  * Redistribution and use in source and binary forms, with or without
     11       1.1      matt  * modification, are permitted provided that the following conditions
     12       1.1      matt  * are met:
     13       1.1      matt  * 1. Redistributions of source code must retain the above copyright
     14       1.1      matt  *    notice, this list of conditions and the following disclaimer.
     15       1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      matt  *    documentation and/or other materials provided with the distribution.
     18       1.1      matt  * 3. All advertising materials mentioning features or use of this software
     19       1.1      matt  *    must display the following acknowledgement:
     20       1.1      matt  *        This product includes software developed by the NetBSD
     21       1.1      matt  *        Foundation, Inc. and its contributors.
     22       1.1      matt  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1      matt  *    contributors may be used to endorse or promote products derived
     24       1.1      matt  *    from this software without specific prior written permission.
     25       1.1      matt  *
     26       1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1      matt  */
     38      1.11     lukem 
     39      1.11     lukem #include <sys/cdefs.h>
     40  1.21.4.4      yamt __KERNEL_RCSID(0, "$NetBSD: fwohci_pci.c,v 1.21.4.4 2007/11/15 11:44:19 yamt Exp $");
     41       1.1      matt 
     42       1.1      matt #include <sys/param.h>
     43       1.2  augustss #include <sys/systm.h>
     44       1.1      matt #include <sys/socket.h>
     45       1.1      matt #include <sys/device.h>
     46      1.17      haya #include <sys/select.h>
     47       1.1      matt 
     48  1.21.4.3      yamt #include <sys/bus.h>
     49  1.21.4.3      yamt #include <sys/intr.h>
     50       1.1      matt 
     51       1.1      matt #include <dev/pci/pcireg.h>
     52       1.1      matt #include <dev/pci/pcivar.h>
     53  1.21.4.1      yamt #include <dev/ieee1394/fw_port.h>
     54  1.21.4.1      yamt #include <dev/ieee1394/firewire.h>
     55  1.21.4.1      yamt #include <dev/ieee1394/firewirereg.h>
     56  1.21.4.1      yamt #include <dev/ieee1394/fwdma.h>
     57       1.1      matt #include <dev/ieee1394/fwohcireg.h>
     58       1.1      matt #include <dev/ieee1394/fwohcivar.h>
     59       1.1      matt 
     60       1.1      matt struct fwohci_pci_softc {
     61       1.1      matt 	struct fwohci_softc psc_sc;
     62  1.21.4.4      yamt 
     63       1.1      matt 	pci_chipset_tag_t psc_pc;
     64  1.21.4.4      yamt 	pcitag_t psc_tag;
     65  1.21.4.4      yamt 	struct pci_conf_state psc_pciconf;
     66  1.21.4.4      yamt 
     67       1.1      matt 	void *psc_ih;
     68  1.21.4.4      yamt 	void *psc_shutdownhook;
     69  1.21.4.4      yamt 	void *psc_powerhook;
     70       1.1      matt };
     71       1.1      matt 
     72      1.20     perry static int fwohci_pci_match(struct device *, struct cfdata *, void *);
     73      1.20     perry static void fwohci_pci_attach(struct device *, struct device *, void *);
     74  1.21.4.4      yamt static void fwohci_pci_shutdown(void *);
     75  1.21.4.4      yamt static void fwohci_pci_power(int, void *);
     76       1.1      matt 
     77      1.15   thorpej CFATTACH_DECL(fwohci_pci, sizeof(struct fwohci_pci_softc),
     78      1.16   thorpej     fwohci_pci_match, fwohci_pci_attach, NULL, NULL);
     79       1.1      matt 
     80       1.1      matt static int
     81  1.21.4.2      yamt fwohci_pci_match(struct device *parent, struct cfdata *match,
     82  1.21.4.2      yamt     void *aux)
     83       1.1      matt {
     84       1.7     enami 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
     85       1.1      matt 
     86       1.7     enami 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_SERIALBUS &&
     87       1.7     enami 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_SERIALBUS_FIREWIRE &&
     88       1.7     enami 	    PCI_INTERFACE(pa->pa_class) == PCI_INTERFACE_OHCI)
     89       1.7     enami 		return 1;
     90      1.21     perry 
     91       1.7     enami 	return 0;
     92       1.1      matt }
     93       1.1      matt 
     94       1.1      matt static void
     95  1.21.4.2      yamt fwohci_pci_attach(struct device *parent, struct device *self,
     96  1.21.4.2      yamt     void *aux)
     97       1.1      matt {
     98       1.7     enami 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
     99       1.1      matt 	struct fwohci_pci_softc *psc = (struct fwohci_pci_softc *) self;
    100       1.7     enami 	char devinfo[256];
    101       1.1      matt 	char const *intrstr;
    102       1.1      matt 	pci_intr_handle_t ih;
    103       1.1      matt 	u_int32_t csr;
    104       1.1      matt 
    105      1.18   thorpej 	aprint_naive(": IEEE 1394 Controller\n");
    106      1.18   thorpej 
    107      1.19    itojun 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
    108      1.18   thorpej 	aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
    109      1.18   thorpej 	    PCI_REVISION(pa->pa_class));
    110       1.1      matt 
    111  1.21.4.1      yamt 	psc->psc_sc.fc.dmat = pa->pa_dmat;
    112       1.1      matt 	psc->psc_pc = pa->pa_pc;
    113  1.21.4.4      yamt 	psc->psc_tag = pa->pa_tag;
    114       1.1      matt 
    115       1.7     enami 	/* Map I/O registers */
    116       1.7     enami 	if (pci_mapreg_map(pa, PCI_OHCI_MAP_REGISTER, PCI_MAPREG_TYPE_MEM, 0,
    117  1.21.4.1      yamt 	    &psc->psc_sc.bst, &psc->psc_sc.bsh,
    118  1.21.4.1      yamt 	    NULL, &psc->psc_sc.bssize)) {
    119      1.18   thorpej 		aprint_error("%s: can't map OHCI register space\n",
    120      1.18   thorpej 		    self->dv_xname);
    121       1.7     enami 		return;
    122       1.7     enami 	}
    123       1.7     enami 
    124       1.7     enami 	/* Disable interrupts, so we don't get any spurious ones. */
    125  1.21.4.1      yamt 	OHCI_CSR_WRITE(&psc->psc_sc, FWOHCI_INTMASKCLR, OHCI_INT_EN);
    126       1.7     enami 
    127       1.7     enami 	/* Enable the device. */
    128       1.7     enami 	csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
    129       1.7     enami 	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    130       1.7     enami 	    csr | PCI_COMMAND_MASTER_ENABLE);
    131       1.8     enami 
    132       1.1      matt 	/* Map and establish the interrupt. */
    133       1.6  sommerfe 	if (pci_intr_map(pa, &ih)) {
    134      1.18   thorpej 		aprint_error("%s: couldn't map interrupt\n", self->dv_xname);
    135       1.1      matt 		return;
    136       1.1      matt 	}
    137       1.1      matt 	intrstr = pci_intr_string(pa->pa_pc, ih);
    138  1.21.4.4      yamt 	psc->psc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO, fwohci_filt,
    139       1.7     enami 	    &psc->psc_sc);
    140       1.1      matt 	if (psc->psc_ih == NULL) {
    141      1.18   thorpej 		aprint_error("%s: couldn't establish interrupt",
    142      1.18   thorpej 		    self->dv_xname);
    143       1.1      matt 		if (intrstr != NULL)
    144      1.18   thorpej 			aprint_normal(" at %s", intrstr);
    145      1.18   thorpej 		aprint_normal("\n");
    146       1.1      matt 		return;
    147       1.1      matt 	}
    148      1.18   thorpej 	aprint_normal("%s: interrupting at %s\n", self->dv_xname, intrstr);
    149       1.1      matt 
    150  1.21.4.4      yamt 	psc->psc_shutdownhook =
    151  1.21.4.4      yamt 	    shutdownhook_establish(fwohci_pci_shutdown, psc);
    152  1.21.4.4      yamt 	psc->psc_powerhook =
    153  1.21.4.4      yamt 	    powerhook_establish(self->dv_xname, fwohci_pci_power, psc);
    154  1.21.4.4      yamt 
    155  1.21.4.1      yamt 	if (fwohci_init(&(psc->psc_sc), &(psc->psc_sc.fc._dev)) != 0) {
    156       1.3      onoe 		pci_intr_disestablish(pa->pa_pc, psc->psc_ih);
    157  1.21.4.1      yamt 		bus_space_unmap(psc->psc_sc.bst, psc->psc_sc.bsh,
    158  1.21.4.1      yamt 		    psc->psc_sc.bssize);
    159       1.3      onoe 	}
    160       1.1      matt }
    161  1.21.4.4      yamt 
    162  1.21.4.4      yamt static void
    163  1.21.4.4      yamt fwohci_pci_shutdown(void *arg)
    164  1.21.4.4      yamt {
    165  1.21.4.4      yamt 	struct fwohci_pci_softc *psc = arg;
    166  1.21.4.4      yamt 
    167  1.21.4.4      yamt 	fwohci_stop(&psc->psc_sc, psc->psc_sc.fc.dev);
    168  1.21.4.4      yamt }
    169  1.21.4.4      yamt 
    170  1.21.4.4      yamt static void
    171  1.21.4.4      yamt fwohci_pci_power(int why, void *arg)
    172  1.21.4.4      yamt {
    173  1.21.4.4      yamt 	struct fwohci_pci_softc *psc = arg;
    174  1.21.4.4      yamt 	int s;
    175  1.21.4.4      yamt 
    176  1.21.4.4      yamt 	s = splbio();
    177  1.21.4.4      yamt 	switch (why) {
    178  1.21.4.4      yamt 	case PWR_SUSPEND:
    179  1.21.4.4      yamt 	case PWR_STANDBY:
    180  1.21.4.4      yamt 		printf("%s: suspending...\n", psc->psc_sc.fc._dev.dv_xname);
    181  1.21.4.4      yamt 
    182  1.21.4.4      yamt 		pci_conf_capture(psc->psc_pc, psc->psc_tag, &psc->psc_pciconf);
    183  1.21.4.4      yamt 		fwohci_stop(&psc->psc_sc, psc->psc_sc.fc.dev);
    184  1.21.4.4      yamt 		break;
    185  1.21.4.4      yamt 
    186  1.21.4.4      yamt 	case PWR_RESUME:
    187  1.21.4.4      yamt 		printf("%s: resuming...\n", psc->psc_sc.fc._dev.dv_xname);
    188  1.21.4.4      yamt 
    189  1.21.4.4      yamt 		pci_conf_restore(psc->psc_pc, psc->psc_tag, &psc->psc_pciconf);
    190  1.21.4.4      yamt 		fwohci_resume(&psc->psc_sc, psc->psc_sc.fc.dev);
    191  1.21.4.4      yamt 		break;
    192  1.21.4.4      yamt 
    193  1.21.4.4      yamt 	case PWR_SOFTSUSPEND:
    194  1.21.4.4      yamt 	case PWR_SOFTSTANDBY:
    195  1.21.4.4      yamt 	case PWR_SOFTRESUME:
    196  1.21.4.4      yamt 		break;
    197  1.21.4.4      yamt 	}
    198  1.21.4.4      yamt 	splx(s);
    199  1.21.4.4      yamt }
    200