Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / pci / fwlynx_pci.c
blob03e797d74702e5df169e28d3aa354e3c39c9d79c
1 /* $NetBSD: fwlynx_pci.c,v 1.17 2009/05/12 08:23:00 cegger Exp $ */
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Matt Thomas of 3am Software Foundry.
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: fwlynx_pci.c,v 1.17 2009/05/12 08:23:00 cegger Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/socket.h>
38 #include <sys/device.h>
40 #include <sys/bus.h>
41 #include <sys/intr.h>
43 #include <dev/pci/pcireg.h>
44 #include <dev/pci/pcivar.h>
45 #include <dev/ieee1394/ieee1394reg.h>
46 #include <dev/ieee1394/ieee1394var.h>
47 #include <dev/ieee1394/fwlynxreg.h>
48 #include <dev/ieee1394/fwlynxvar.h>
50 struct fwlynx_pci_softc {
51 struct fwlynx_softc psc_sc;
52 pci_chipset_tag_t psc_pc;
53 void *psc_ih;
56 static int fwlynx_pci_match(device_t, cfdata_t, void *);
57 static void fwlynx_pci_attach(device_t, device_t, void *);
59 CFATTACH_DECL(fwlynx_pci, sizeof(struct fwlynx_pci_softc),
60 fwlynx_pci_match, fwlynx_pci_attach, NULL, NULL);
62 static int
63 fwlynx_pci_match(device_t parent, cfdata_t match, void *aux)
65 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
67 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_TI &&
68 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_TI_TSB12LV21)
69 return 1;
71 return 0;
74 static void
75 fwlynx_pci_attach(device_t parent, device_t self, void *aux)
77 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
78 struct fwlynx_pci_softc *psc = device_private(self);
79 char devinfo[256];
80 char const *intrstr;
81 pci_intr_handle_t ih;
82 u_int32_t csr;
84 aprint_naive(": IEEE 1394 Controller\n");
86 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
87 aprint_normal(": %s (rev. 0x%02x)\n", devinfo,
88 PCI_REVISION(pa->pa_class));
90 psc->psc_sc.sc_dmat = pa->pa_dmat;
91 psc->psc_pc = pa->pa_pc;
92 psc->psc_tag = pa->pa_tag;
94 /* Map I/O registers */
95 if (pci_mapreg_map(pa, PCI_LYNX_MAP_REGISTER, PCI_MAPREG_TYPE_MEM, 0,
96 &psc->psc_sc.sc_memt, &psc->psc_sc.sc_memh,
97 NULL, &psc->psc_sc.sc_memsize)) {
98 aprint_error_dev(self, "can't map register space\n");
99 return;
102 /* Disable interrupts, so we don't get any spurious ones. */
103 pci_conf_write(psc->psc_pc, psc->psc_tag, 0);
105 /* Enable the device. */
106 csr = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
107 pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
108 csr | PCI_COMMAND_MASTER_ENABLE);
110 /* Map and establish the interrupt. */
111 if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
112 pa->pa_intrline, &ih)) {
113 aprint_error_dev(self, "couldn't map interrupt\n");
114 return;
116 intrstr = pci_intr_string(pa->pa_pc, ih);
117 psc->psc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_BIO,
118 fwlynx_intr, &psc->psc_sc);
119 if (psc->psc_ih == NULL) {
120 aprint_error_dev(self, "couldn't establish interrupt");
121 if (intrstr != NULL)
122 aprint_error(" at %s", intrstr);
123 aprint_error("\n");
124 return;
126 aprint_normal_dev(self, "interrupting at %s\n", intrstr);
128 if (fwlynx_init(&psc->psc_sc, pci_intr_evcnt(pa->pa_pc, ih)) != 0) {
129 pci_intr_disestablish(pa->pa_pc, psc->psc_ih);
130 bus_space_unmap(psc->psc_sc.sc_memt, psc->psc_sc.sc_memh,
131 psc->psc_sc.sc_memsize);