2 * comedi/drivers/ni_labpc_pci.c
3 * Driver for National Instruments Lab-PC PCI-1200
4 * Copyright (C) 2001, 2002, 2003 Frank Mori Hess <fmhess@users.sourceforge.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Driver: ni_labpc_pci
23 * Description: National Instruments Lab-PC PCI-1200
24 * Devices: (National Instruments) PCI-1200 [ni_pci-1200]
25 * Author: Frank Mori Hess <fmhess@users.sourceforge.net>
28 * This is the PCI-specific support split off from the ni_labpc driver.
30 * Configuration Options: not applicable, uses PCI auto config
36 #include <linux/interrupt.h>
37 #include <linux/slab.h>
38 #include <linux/pci.h>
40 #include "../comedidev.h"
45 enum labpc_pci_boardid {
49 static const struct labpc_boardinfo labpc_pci_boards[] = {
50 [BOARD_NI_PCI1200] = {
51 .name = "ni_pci-1200",
53 .bustype = pci_bustype,
54 .register_layout = labpc_1200_layout,
56 .ai_range_table = &range_labpc_1200_ai,
57 .ai_range_code = labpc_1200_ai_gain_bits,
63 static int labpc_pci_auto_attach(struct comedi_device *dev,
64 unsigned long context)
66 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
67 const struct labpc_boardinfo *board = NULL;
68 struct labpc_private *devpriv;
71 if (context < ARRAY_SIZE(labpc_pci_boards))
72 board = &labpc_pci_boards[context];
75 dev->board_ptr = board;
76 dev->board_name = board->name;
78 ret = comedi_pci_enable(dev);
82 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
85 dev->private = devpriv;
87 devpriv->mite = mite_alloc(pcidev);
90 ret = mite_setup(devpriv->mite);
93 dev->iobase = (unsigned long)devpriv->mite->daq_io_addr;
95 return labpc_common_attach(dev, mite_irq(devpriv->mite), IRQF_SHARED);
98 static void labpc_pci_detach(struct comedi_device *dev)
100 struct labpc_private *devpriv = dev->private;
102 labpc_common_detach(dev);
104 if (devpriv && devpriv->mite) {
105 mite_unsetup(devpriv->mite);
106 mite_free(devpriv->mite);
109 free_irq(dev->irq, dev);
110 comedi_pci_disable(dev);
113 static struct comedi_driver labpc_pci_comedi_driver = {
114 .driver_name = "labpc_pci",
115 .module = THIS_MODULE,
116 .auto_attach = labpc_pci_auto_attach,
117 .detach = labpc_pci_detach,
120 static DEFINE_PCI_DEVICE_TABLE(labpc_pci_table) = {
121 { PCI_VDEVICE(NI, 0x161), BOARD_NI_PCI1200 },
124 MODULE_DEVICE_TABLE(pci, labpc_pci_table);
126 static int labpc_pci_probe(struct pci_dev *dev,
127 const struct pci_device_id *id)
129 return comedi_pci_auto_config(dev, &labpc_pci_comedi_driver,
133 static struct pci_driver labpc_pci_driver = {
135 .id_table = labpc_pci_table,
136 .probe = labpc_pci_probe,
137 .remove = comedi_pci_auto_unconfig,
139 module_comedi_pci_driver(labpc_pci_comedi_driver, labpc_pci_driver);
141 MODULE_DESCRIPTION("Comedi: National Instruments Lab-PC PCI-1200 driver");
142 MODULE_AUTHOR("Comedi http://www.comedi.org");
143 MODULE_LICENSE("GPL");