]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/staging/comedi/drivers/addi_apci_2200.c
staging/comedi: Use comedi_pci_auto_unconfig directly for pci_driver.remove
[mirror_ubuntu-hirsute-kernel.git] / 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 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 * You should also find the complete GPL in the COPYING file accompanying
29 * this source code.
30 */
31
32 #include "../comedidev.h"
33 #include "addi_watchdog.h"
34
35 /*
36 * I/O Register Map
37 */
38 #define APCI2200_DI_REG 0x00
39 #define APCI2200_DO_REG 0x04
40 #define APCI2200_WDOG_REG 0x08
41
42 static int apci2200_di_insn_bits(struct comedi_device *dev,
43 struct comedi_subdevice *s,
44 struct comedi_insn *insn,
45 unsigned int *data)
46 {
47 data[1] = inw(dev->iobase + APCI2200_DI_REG);
48
49 return insn->n;
50 }
51
52 static int apci2200_do_insn_bits(struct comedi_device *dev,
53 struct comedi_subdevice *s,
54 struct comedi_insn *insn,
55 unsigned int *data)
56 {
57 unsigned int mask = data[0];
58 unsigned int bits = data[1];
59
60 s->state = inw(dev->iobase + APCI2200_DO_REG);
61 if (mask) {
62 s->state &= ~mask;
63 s->state |= (bits & mask);
64
65 outw(s->state, dev->iobase + APCI2200_DO_REG);
66 }
67
68 data[1] = s->state;
69
70 return insn->n;
71 }
72
73 static int apci2200_reset(struct comedi_device *dev)
74 {
75 outw(0x0, dev->iobase + APCI2200_DO_REG);
76
77 addi_watchdog_reset(dev->iobase + APCI2200_WDOG_REG);
78
79 return 0;
80 }
81
82 static int apci2200_auto_attach(struct comedi_device *dev,
83 unsigned long context_unused)
84 {
85 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
86 struct comedi_subdevice *s;
87 int ret;
88
89 dev->board_name = dev->driver->driver_name;
90
91 ret = comedi_pci_enable(pcidev, dev->board_name);
92 if (ret)
93 return ret;
94
95 dev->iobase = pci_resource_start(pcidev, 1);
96
97 ret = comedi_alloc_subdevices(dev, 3);
98 if (ret)
99 return ret;
100
101 /* Initialize the digital input subdevice */
102 s = &dev->subdevices[0];
103 s->type = COMEDI_SUBD_DI;
104 s->subdev_flags = SDF_READABLE;
105 s->n_chan = 8;
106 s->maxdata = 1;
107 s->range_table = &range_digital;
108 s->insn_bits = apci2200_di_insn_bits;
109
110 /* Initialize the digital output subdevice */
111 s = &dev->subdevices[1];
112 s->type = COMEDI_SUBD_DO;
113 s->subdev_flags = SDF_WRITEABLE;
114 s->n_chan = 16;
115 s->maxdata = 1;
116 s->range_table = &range_digital;
117 s->insn_bits = apci2200_do_insn_bits;
118
119 /* Initialize the watchdog subdevice */
120 s = &dev->subdevices[2];
121 ret = addi_watchdog_init(s, dev->iobase + APCI2200_WDOG_REG);
122 if (ret)
123 return ret;
124
125 apci2200_reset(dev);
126 return 0;
127 }
128
129 static void apci2200_detach(struct comedi_device *dev)
130 {
131 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
132
133 if (dev->iobase)
134 apci2200_reset(dev);
135 if (dev->subdevices)
136 addi_watchdog_cleanup(&dev->subdevices[2]);
137 if (pcidev) {
138 if (dev->iobase)
139 comedi_pci_disable(pcidev);
140 }
141 }
142
143 static struct comedi_driver apci2200_driver = {
144 .driver_name = "addi_apci_2200",
145 .module = THIS_MODULE,
146 .auto_attach = apci2200_auto_attach,
147 .detach = apci2200_detach,
148 };
149
150 static int apci2200_pci_probe(struct pci_dev *dev,
151 const struct pci_device_id *ent)
152 {
153 return comedi_pci_auto_config(dev, &apci2200_driver);
154 }
155
156 static DEFINE_PCI_DEVICE_TABLE(apci2200_pci_table) = {
157 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1005) },
158 { 0 }
159 };
160 MODULE_DEVICE_TABLE(pci, apci2200_pci_table);
161
162 static struct pci_driver apci2200_pci_driver = {
163 .name = "addi_apci_2200",
164 .id_table = apci2200_pci_table,
165 .probe = apci2200_pci_probe,
166 .remove = comedi_pci_auto_unconfig,
167 };
168 module_comedi_pci_driver(apci2200_driver, apci2200_pci_driver);
169
170 MODULE_DESCRIPTION("ADDI-DATA APCI-2200 Relay board, optically isolated");
171 MODULE_AUTHOR("Comedi http://www.comedi.org");
172 MODULE_LICENSE("GPL");