4beadfeabf8737f51353dffadd725986e3f18952
[platform/adaptation/renesas_rcar/renesas_kernel.git] / 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_speed               = 10000,
53                 .bustype                = pci_bustype,
54                 .register_layout        = labpc_1200_layout,
55                 .has_ao                 = 1,
56                 .ai_range_table         = &range_labpc_1200_ai,
57                 .ai_range_code          = labpc_1200_ai_gain_bits,
58                 .ai_scan_up             = 1,
59                 .has_mmio               = 1,
60         },
61 };
62
63 static int labpc_pci_auto_attach(struct comedi_device *dev,
64                                  unsigned long context)
65 {
66         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
67         const struct labpc_boardinfo *board = NULL;
68         struct labpc_private *devpriv;
69         int ret;
70
71         if (context < ARRAY_SIZE(labpc_pci_boards))
72                 board = &labpc_pci_boards[context];
73         if (!board)
74                 return -ENODEV;
75         dev->board_ptr = board;
76         dev->board_name = board->name;
77
78         ret = comedi_pci_enable(dev);
79         if (ret)
80                 return ret;
81
82         devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
83         if (!devpriv)
84                 return -ENOMEM;
85         dev->private = devpriv;
86
87         devpriv->mite = mite_alloc(pcidev);
88         if (!devpriv->mite)
89                 return -ENOMEM;
90         ret = mite_setup(devpriv->mite);
91         if (ret < 0)
92                 return ret;
93         dev->iobase = (unsigned long)devpriv->mite->daq_io_addr;
94
95         return labpc_common_attach(dev, mite_irq(devpriv->mite), IRQF_SHARED);
96 }
97
98 static void labpc_pci_detach(struct comedi_device *dev)
99 {
100         struct labpc_private *devpriv = dev->private;
101
102         labpc_common_detach(dev);
103
104         if (devpriv && devpriv->mite) {
105                 mite_unsetup(devpriv->mite);
106                 mite_free(devpriv->mite);
107         }
108         if (dev->irq)
109                 free_irq(dev->irq, dev);
110         comedi_pci_disable(dev);
111 }
112
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,
118 };
119
120 static DEFINE_PCI_DEVICE_TABLE(labpc_pci_table) = {
121         { PCI_VDEVICE(NI, 0x161), BOARD_NI_PCI1200 },
122         { 0 }
123 };
124 MODULE_DEVICE_TABLE(pci, labpc_pci_table);
125
126 static int labpc_pci_probe(struct pci_dev *dev,
127                            const struct pci_device_id *id)
128 {
129         return comedi_pci_auto_config(dev, &labpc_pci_comedi_driver,
130                                       id->driver_data);
131 }
132
133 static struct pci_driver labpc_pci_driver = {
134         .name           = "labpc_pci",
135         .id_table       = labpc_pci_table,
136         .probe          = labpc_pci_probe,
137         .remove         = comedi_pci_auto_unconfig,
138 };
139 module_comedi_pci_driver(labpc_pci_comedi_driver, labpc_pci_driver);
140
141 MODULE_DESCRIPTION("Comedi: National Instruments Lab-PC PCI-1200 driver");
142 MODULE_AUTHOR("Comedi http://www.comedi.org");
143 MODULE_LICENSE("GPL");