Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / 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
30 #include "../comedi_pci.h"
31
32 /*
33  * Register map
34  */
35 #define PIO1616L_DI_REG         0x00
36 #define PIO1616L_DO_REG         0x02
37
38 static int contec_do_insn_bits(struct comedi_device *dev,
39                                struct comedi_subdevice *s,
40                                struct comedi_insn *insn,
41                                unsigned int *data)
42 {
43         if (comedi_dio_update_state(s, data))
44                 outw(s->state, dev->iobase + PIO1616L_DO_REG);
45
46         data[1] = s->state;
47
48         return insn->n;
49 }
50
51 static int contec_di_insn_bits(struct comedi_device *dev,
52                                struct comedi_subdevice *s,
53                                struct comedi_insn *insn, unsigned int *data)
54 {
55         data[1] = inw(dev->iobase + PIO1616L_DI_REG);
56
57         return insn->n;
58 }
59
60 static int contec_auto_attach(struct comedi_device *dev,
61                               unsigned long context_unused)
62 {
63         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
64         struct comedi_subdevice *s;
65         int ret;
66
67         ret = comedi_pci_enable(dev);
68         if (ret)
69                 return ret;
70         dev->iobase = pci_resource_start(pcidev, 0);
71
72         ret = comedi_alloc_subdevices(dev, 2);
73         if (ret)
74                 return ret;
75
76         s = &dev->subdevices[0];
77         s->type         = COMEDI_SUBD_DI;
78         s->subdev_flags = SDF_READABLE;
79         s->n_chan       = 16;
80         s->maxdata      = 1;
81         s->range_table  = &range_digital;
82         s->insn_bits    = contec_di_insn_bits;
83
84         s = &dev->subdevices[1];
85         s->type         = COMEDI_SUBD_DO;
86         s->subdev_flags = SDF_WRITABLE;
87         s->n_chan       = 16;
88         s->maxdata      = 1;
89         s->range_table  = &range_digital;
90         s->insn_bits    = contec_do_insn_bits;
91
92         return 0;
93 }
94
95 static struct comedi_driver contec_pci_dio_driver = {
96         .driver_name    = "contec_pci_dio",
97         .module         = THIS_MODULE,
98         .auto_attach    = contec_auto_attach,
99         .detach         = comedi_pci_detach,
100 };
101
102 static int contec_pci_dio_pci_probe(struct pci_dev *dev,
103                                     const struct pci_device_id *id)
104 {
105         return comedi_pci_auto_config(dev, &contec_pci_dio_driver,
106                                       id->driver_data);
107 }
108
109 static const struct pci_device_id contec_pci_dio_pci_table[] = {
110         { PCI_DEVICE(PCI_VENDOR_ID_CONTEC, 0x8172) },
111         { 0 }
112 };
113 MODULE_DEVICE_TABLE(pci, contec_pci_dio_pci_table);
114
115 static struct pci_driver contec_pci_dio_pci_driver = {
116         .name           = "contec_pci_dio",
117         .id_table       = contec_pci_dio_pci_table,
118         .probe          = contec_pci_dio_pci_probe,
119         .remove         = comedi_pci_auto_unconfig,
120 };
121 module_comedi_pci_driver(contec_pci_dio_driver, contec_pci_dio_pci_driver);
122
123 MODULE_AUTHOR("Comedi http://www.comedi.org");
124 MODULE_DESCRIPTION("Comedi low-level driver");
125 MODULE_LICENSE("GPL");