Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / staging / comedi / drivers / addi_apci_2200.c
1 /*
2  * addi_apci_2200.c
3  * Copyright (C) 2004,2005  ADDI-DATA GmbH for the source code of this module.
4  * Project manager: Eric Stolz
5  *
6  *      ADDI-DATA GmbH
7  *      Dieselstrasse 3
8  *      D-77833 Ottersweier
9  *      Tel: +19(0)7223/9493-0
10  *      Fax: +49(0)7223/9493-92
11  *      http://www.addi-data.com
12  *      info@addi-data.com
13  *
14  * This program is free software; you can redistribute it and/or modify it
15  * under the terms of the GNU General Public License as published by the
16  * Free Software Foundation; either version 2 of the License, or (at your
17  * option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but WITHOUT
20  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22  * more details.
23  */
24
25 #include <linux/module.h>
26
27 #include "../comedi_pci.h"
28 #include "addi_watchdog.h"
29
30 /*
31  * I/O Register Map
32  */
33 #define APCI2200_DI_REG                 0x00
34 #define APCI2200_DO_REG                 0x04
35 #define APCI2200_WDOG_REG               0x08
36
37 static int apci2200_di_insn_bits(struct comedi_device *dev,
38                                  struct comedi_subdevice *s,
39                                  struct comedi_insn *insn,
40                                  unsigned int *data)
41 {
42         data[1] = inw(dev->iobase + APCI2200_DI_REG);
43
44         return insn->n;
45 }
46
47 static int apci2200_do_insn_bits(struct comedi_device *dev,
48                                  struct comedi_subdevice *s,
49                                  struct comedi_insn *insn,
50                                  unsigned int *data)
51 {
52         s->state = inw(dev->iobase + APCI2200_DO_REG);
53
54         if (comedi_dio_update_state(s, data))
55                 outw(s->state, dev->iobase + APCI2200_DO_REG);
56
57         data[1] = s->state;
58
59         return insn->n;
60 }
61
62 static int apci2200_reset(struct comedi_device *dev)
63 {
64         outw(0x0, dev->iobase + APCI2200_DO_REG);
65
66         addi_watchdog_reset(dev->iobase + APCI2200_WDOG_REG);
67
68         return 0;
69 }
70
71 static int apci2200_auto_attach(struct comedi_device *dev,
72                                 unsigned long context_unused)
73 {
74         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
75         struct comedi_subdevice *s;
76         int ret;
77
78         ret = comedi_pci_enable(dev);
79         if (ret)
80                 return ret;
81
82         dev->iobase = pci_resource_start(pcidev, 1);
83
84         ret = comedi_alloc_subdevices(dev, 3);
85         if (ret)
86                 return ret;
87
88         /* Initialize the digital input subdevice */
89         s = &dev->subdevices[0];
90         s->type         = COMEDI_SUBD_DI;
91         s->subdev_flags = SDF_READABLE;
92         s->n_chan       = 8;
93         s->maxdata      = 1;
94         s->range_table  = &range_digital;
95         s->insn_bits    = apci2200_di_insn_bits;
96
97         /* Initialize the digital output subdevice */
98         s = &dev->subdevices[1];
99         s->type         = COMEDI_SUBD_DO;
100         s->subdev_flags = SDF_WRITABLE;
101         s->n_chan       = 16;
102         s->maxdata      = 1;
103         s->range_table  = &range_digital;
104         s->insn_bits    = apci2200_do_insn_bits;
105
106         /* Initialize the watchdog subdevice */
107         s = &dev->subdevices[2];
108         ret = addi_watchdog_init(s, dev->iobase + APCI2200_WDOG_REG);
109         if (ret)
110                 return ret;
111
112         apci2200_reset(dev);
113         return 0;
114 }
115
116 static void apci2200_detach(struct comedi_device *dev)
117 {
118         if (dev->iobase)
119                 apci2200_reset(dev);
120         comedi_pci_detach(dev);
121 }
122
123 static struct comedi_driver apci2200_driver = {
124         .driver_name    = "addi_apci_2200",
125         .module         = THIS_MODULE,
126         .auto_attach    = apci2200_auto_attach,
127         .detach         = apci2200_detach,
128 };
129
130 static int apci2200_pci_probe(struct pci_dev *dev,
131                               const struct pci_device_id *id)
132 {
133         return comedi_pci_auto_config(dev, &apci2200_driver, id->driver_data);
134 }
135
136 static const struct pci_device_id apci2200_pci_table[] = {
137         { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1005) },
138         { 0 }
139 };
140 MODULE_DEVICE_TABLE(pci, apci2200_pci_table);
141
142 static struct pci_driver apci2200_pci_driver = {
143         .name           = "addi_apci_2200",
144         .id_table       = apci2200_pci_table,
145         .probe          = apci2200_pci_probe,
146         .remove         = comedi_pci_auto_unconfig,
147 };
148 module_comedi_pci_driver(apci2200_driver, apci2200_pci_driver);
149
150 MODULE_DESCRIPTION("ADDI-DATA APCI-2200 Relay board, optically isolated");
151 MODULE_AUTHOR("Comedi http://www.comedi.org");
152 MODULE_LICENSE("GPL");