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 .register_layout = labpc_1200_layout,
55 .ai_range_table = &range_labpc_1200_ai,
56 .ai_range_code = labpc_1200_ai_gain_bits,
62 static int labpc_pci_auto_attach(struct comedi_device *dev,
63 unsigned long context)
65 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
66 const struct labpc_boardinfo *board = NULL;
67 struct labpc_private *devpriv;
70 if (context < ARRAY_SIZE(labpc_pci_boards))
71 board = &labpc_pci_boards[context];
74 dev->board_ptr = board;
75 dev->board_name = board->name;
77 ret = comedi_pci_enable(dev);
81 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
84 dev->private = devpriv;
86 devpriv->mite = mite_alloc(pcidev);
89 ret = mite_setup(devpriv->mite);
92 dev->iobase = (unsigned long)devpriv->mite->daq_io_addr;
94 return labpc_common_attach(dev, mite_irq(devpriv->mite), IRQF_SHARED);
97 static void labpc_pci_detach(struct comedi_device *dev)
99 struct labpc_private *devpriv = dev->private;
101 labpc_common_detach(dev);
103 if (devpriv && devpriv->mite) {
104 mite_unsetup(devpriv->mite);
105 mite_free(devpriv->mite);
108 free_irq(dev->irq, dev);
109 comedi_pci_disable(dev);
112 static struct comedi_driver labpc_pci_comedi_driver = {
113 .driver_name = "labpc_pci",
114 .module = THIS_MODULE,
115 .auto_attach = labpc_pci_auto_attach,
116 .detach = labpc_pci_detach,
119 static DEFINE_PCI_DEVICE_TABLE(labpc_pci_table) = {
120 { PCI_VDEVICE(NI, 0x161), BOARD_NI_PCI1200 },
123 MODULE_DEVICE_TABLE(pci, labpc_pci_table);
125 static int labpc_pci_probe(struct pci_dev *dev,
126 const struct pci_device_id *id)
128 return comedi_pci_auto_config(dev, &labpc_pci_comedi_driver,
132 static struct pci_driver labpc_pci_driver = {
134 .id_table = labpc_pci_table,
135 .probe = labpc_pci_probe,
136 .remove = comedi_pci_auto_unconfig,
138 module_comedi_pci_driver(labpc_pci_comedi_driver, labpc_pci_driver);
140 MODULE_DESCRIPTION("Comedi: National Instruments Lab-PC PCI-1200 driver");
141 MODULE_AUTHOR("Comedi http://www.comedi.org");
142 MODULE_LICENSE("GPL");