]> Pileus Git - ~andy/linux/blob - drivers/staging/comedi/drivers/ni_labpc_pci.c
staging: comedi: ni_labpc: cleanup true/false flags in boardinfo
[~andy/linux] / drivers / staging / comedi / drivers / ni_labpc_pci.c
1 /*
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>
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 /*
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>
26  * Status: works
27  *
28  * This is the PCI-specific support split off from the ni_labpc driver.
29  *
30  * Configuration Options: not applicable, uses PCI auto config
31  *
32  * NI manuals:
33  * 340914a (pci-1200)
34  */
35
36 #include <linux/interrupt.h>
37 #include <linux/slab.h>
38 #include <linux/pci.h>
39
40 #include "../comedidev.h"
41
42 #include "mite.h"
43 #include "ni_labpc.h"
44
45 enum labpc_pci_boardid {
46         BOARD_NI_PCI1200,
47 };
48
49 static const struct labpc_boardinfo labpc_pci_boards[] = {
50         [BOARD_NI_PCI1200] = {
51                 .name                   = "ni_pci-1200",
52                 .ai_range_table         = &range_labpc_1200_ai,
53                 .ai_range_code          = labpc_1200_ai_gain_bits,
54                 .ai_speed               = 10000,
55                 .ai_scan_up             = 1,
56                 .has_ao                 = 1,
57                 .is_labpc1200           = 1,
58                 .has_mmio               = 1,
59         },
60 };
61
62 static int labpc_pci_auto_attach(struct comedi_device *dev,
63                                  unsigned long context)
64 {
65         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
66         const struct labpc_boardinfo *board = NULL;
67         struct labpc_private *devpriv;
68         int ret;
69
70         if (context < ARRAY_SIZE(labpc_pci_boards))
71                 board = &labpc_pci_boards[context];
72         if (!board)
73                 return -ENODEV;
74         dev->board_ptr = board;
75         dev->board_name = board->name;
76
77         ret = comedi_pci_enable(dev);
78         if (ret)
79                 return ret;
80
81         devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
82         if (!devpriv)
83                 return -ENOMEM;
84         dev->private = devpriv;
85
86         devpriv->mite = mite_alloc(pcidev);
87         if (!devpriv->mite)
88                 return -ENOMEM;
89         ret = mite_setup(devpriv->mite);
90         if (ret < 0)
91                 return ret;
92         dev->iobase = (unsigned long)devpriv->mite->daq_io_addr;
93
94         return labpc_common_attach(dev, mite_irq(devpriv->mite), IRQF_SHARED);
95 }
96
97 static void labpc_pci_detach(struct comedi_device *dev)
98 {
99         struct labpc_private *devpriv = dev->private;
100
101         labpc_common_detach(dev);
102
103         if (devpriv && devpriv->mite) {
104                 mite_unsetup(devpriv->mite);
105                 mite_free(devpriv->mite);
106         }
107         if (dev->irq)
108                 free_irq(dev->irq, dev);
109         comedi_pci_disable(dev);
110 }
111
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,
117 };
118
119 static DEFINE_PCI_DEVICE_TABLE(labpc_pci_table) = {
120         { PCI_VDEVICE(NI, 0x161), BOARD_NI_PCI1200 },
121         { 0 }
122 };
123 MODULE_DEVICE_TABLE(pci, labpc_pci_table);
124
125 static int labpc_pci_probe(struct pci_dev *dev,
126                            const struct pci_device_id *id)
127 {
128         return comedi_pci_auto_config(dev, &labpc_pci_comedi_driver,
129                                       id->driver_data);
130 }
131
132 static struct pci_driver labpc_pci_driver = {
133         .name           = "labpc_pci",
134         .id_table       = labpc_pci_table,
135         .probe          = labpc_pci_probe,
136         .remove         = comedi_pci_auto_unconfig,
137 };
138 module_comedi_pci_driver(labpc_pci_comedi_driver, labpc_pci_driver);
139
140 MODULE_DESCRIPTION("Comedi: National Instruments Lab-PC PCI-1200 driver");
141 MODULE_AUTHOR("Comedi http://www.comedi.org");
142 MODULE_LICENSE("GPL");