Merge branch 'for-3.11' of git://linux-nfs.org/~bfields/linux
[linux-2.6.git] / drivers / staging / comedi / drivers / addi_apci_2200.c
blobca1bd92ecb1748e269037a9675b9fc2f04138a6a
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
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
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.
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.
25 #include <linux/pci.h>
27 #include "../comedidev.h"
28 #include "addi_watchdog.h"
31 * I/O Register Map
33 #define APCI2200_DI_REG 0x00
34 #define APCI2200_DO_REG 0x04
35 #define APCI2200_WDOG_REG 0x08
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)
42 data[1] = inw(dev->iobase + APCI2200_DI_REG);
44 return insn->n;
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)
52 unsigned int mask = data[0];
53 unsigned int bits = data[1];
55 s->state = inw(dev->iobase + APCI2200_DO_REG);
56 if (mask) {
57 s->state &= ~mask;
58 s->state |= (bits & mask);
60 outw(s->state, dev->iobase + APCI2200_DO_REG);
63 data[1] = s->state;
65 return insn->n;
68 static int apci2200_reset(struct comedi_device *dev)
70 outw(0x0, dev->iobase + APCI2200_DO_REG);
72 addi_watchdog_reset(dev->iobase + APCI2200_WDOG_REG);
74 return 0;
77 static int apci2200_auto_attach(struct comedi_device *dev,
78 unsigned long context_unused)
80 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
81 struct comedi_subdevice *s;
82 int ret;
84 ret = comedi_pci_enable(dev);
85 if (ret)
86 return ret;
88 dev->iobase = pci_resource_start(pcidev, 1);
90 ret = comedi_alloc_subdevices(dev, 3);
91 if (ret)
92 return ret;
94 /* Initialize the digital input subdevice */
95 s = &dev->subdevices[0];
96 s->type = COMEDI_SUBD_DI;
97 s->subdev_flags = SDF_READABLE;
98 s->n_chan = 8;
99 s->maxdata = 1;
100 s->range_table = &range_digital;
101 s->insn_bits = apci2200_di_insn_bits;
103 /* Initialize the digital output subdevice */
104 s = &dev->subdevices[1];
105 s->type = COMEDI_SUBD_DO;
106 s->subdev_flags = SDF_WRITEABLE;
107 s->n_chan = 16;
108 s->maxdata = 1;
109 s->range_table = &range_digital;
110 s->insn_bits = apci2200_do_insn_bits;
112 /* Initialize the watchdog subdevice */
113 s = &dev->subdevices[2];
114 ret = addi_watchdog_init(s, dev->iobase + APCI2200_WDOG_REG);
115 if (ret)
116 return ret;
118 apci2200_reset(dev);
119 return 0;
122 static void apci2200_detach(struct comedi_device *dev)
124 if (dev->iobase)
125 apci2200_reset(dev);
126 comedi_pci_disable(dev);
129 static struct comedi_driver apci2200_driver = {
130 .driver_name = "addi_apci_2200",
131 .module = THIS_MODULE,
132 .auto_attach = apci2200_auto_attach,
133 .detach = apci2200_detach,
136 static int apci2200_pci_probe(struct pci_dev *dev,
137 const struct pci_device_id *id)
139 return comedi_pci_auto_config(dev, &apci2200_driver, id->driver_data);
142 static DEFINE_PCI_DEVICE_TABLE(apci2200_pci_table) = {
143 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1005) },
144 { 0 }
146 MODULE_DEVICE_TABLE(pci, apci2200_pci_table);
148 static struct pci_driver apci2200_pci_driver = {
149 .name = "addi_apci_2200",
150 .id_table = apci2200_pci_table,
151 .probe = apci2200_pci_probe,
152 .remove = comedi_pci_auto_unconfig,
154 module_comedi_pci_driver(apci2200_driver, apci2200_pci_driver);
156 MODULE_DESCRIPTION("ADDI-DATA APCI-2200 Relay board, optically isolated");
157 MODULE_AUTHOR("Comedi http://www.comedi.org");
158 MODULE_LICENSE("GPL");