Merge git://git.infradead.org/users/eparis/audit
[cascardo/linux.git] / drivers / staging / comedi / drivers / contec_pci_dio.c
1 /*
2     comedi/drivers/contec_pci_dio.c
3
4     COMEDI - Linux Control and Measurement Device Interface
5     Copyright (C) 2000 David A. Schleef <ds@schleef.org>
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 */
17 /*
18 Driver: contec_pci_dio
19 Description: Contec PIO1616L digital I/O board
20 Devices: [Contec] PIO1616L (contec_pci_dio)
21 Author: Stefano Rivoir <s.rivoir@gts.it>
22 Updated: Wed, 27 Jun 2007 13:00:06 +0100
23 Status: works
24
25 Configuration Options: not applicable, uses comedi PCI auto config
26 */
27
28 #include <linux/module.h>
29 #include <linux/pci.h>
30
31 #include "../comedidev.h"
32
33 #define PCI_DEVICE_ID_PIO1616L 0x8172
34
35 /*
36  * Register map
37  */
38 #define PIO1616L_DI_REG         0x00
39 #define PIO1616L_DO_REG         0x02
40
41 static int contec_do_insn_bits(struct comedi_device *dev,
42                                struct comedi_subdevice *s,
43                                struct comedi_insn *insn,
44                                unsigned int *data)
45 {
46         if (comedi_dio_update_state(s, data))
47                 outw(s->state, dev->iobase + PIO1616L_DO_REG);
48
49         data[1] = s->state;
50
51         return insn->n;
52 }
53
54 static int contec_di_insn_bits(struct comedi_device *dev,
55                                struct comedi_subdevice *s,
56                                struct comedi_insn *insn, unsigned int *data)
57 {
58         data[1] = inw(dev->iobase + PIO1616L_DI_REG);
59
60         return insn->n;
61 }
62
63 static int contec_auto_attach(struct comedi_device *dev,
64                                         unsigned long context_unused)
65 {
66         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
67         struct comedi_subdevice *s;
68         int ret;
69
70         ret = comedi_pci_enable(dev);
71         if (ret)
72                 return ret;
73         dev->iobase = pci_resource_start(pcidev, 0);
74
75         ret = comedi_alloc_subdevices(dev, 2);
76         if (ret)
77                 return ret;
78
79         s = &dev->subdevices[0];
80         s->type         = COMEDI_SUBD_DI;
81         s->subdev_flags = SDF_READABLE;
82         s->n_chan       = 16;
83         s->maxdata      = 1;
84         s->range_table  = &range_digital;
85         s->insn_bits    = contec_di_insn_bits;
86
87         s = &dev->subdevices[1];
88         s->type         = COMEDI_SUBD_DO;
89         s->subdev_flags = SDF_WRITABLE;
90         s->n_chan       = 16;
91         s->maxdata      = 1;
92         s->range_table  = &range_digital;
93         s->insn_bits    = contec_do_insn_bits;
94
95         return 0;
96 }
97
98 static struct comedi_driver contec_pci_dio_driver = {
99         .driver_name    = "contec_pci_dio",
100         .module         = THIS_MODULE,
101         .auto_attach    = contec_auto_attach,
102         .detach         = comedi_pci_disable,
103 };
104
105 static int contec_pci_dio_pci_probe(struct pci_dev *dev,
106                                     const struct pci_device_id *id)
107 {
108         return comedi_pci_auto_config(dev, &contec_pci_dio_driver,
109                                       id->driver_data);
110 }
111
112 static const struct pci_device_id contec_pci_dio_pci_table[] = {
113         { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, PCI_DEVICE_ID_PIO1616L) },
114         { 0 }
115 };
116 MODULE_DEVICE_TABLE(pci, contec_pci_dio_pci_table);
117
118 static struct pci_driver contec_pci_dio_pci_driver = {
119         .name           = "contec_pci_dio",
120         .id_table       = contec_pci_dio_pci_table,
121         .probe          = contec_pci_dio_pci_probe,
122         .remove         = comedi_pci_auto_unconfig,
123 };
124 module_comedi_pci_driver(contec_pci_dio_driver, contec_pci_dio_pci_driver);
125
126 MODULE_AUTHOR("Comedi http://www.comedi.org");
127 MODULE_DESCRIPTION("Comedi low-level driver");
128 MODULE_LICENSE("GPL");