2 * comedi/drivers/dyna_pci10xx.c
3 * Copyright (C) 2011 Prashant Shah, pshah.mumbai@gmail.com
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
18 Devices: Dynalog India PCI DAQ Cards, http://www.dynalogindia.com/
19 Author: Prashant Shah <pshah.mumbai@gmail.com>
20 Developed at Automation Labs, Chemical Dept., IIT Bombay, India.
21 Prof. Kannan Moudgalya <kannan@iitb.ac.in>
29 - Dynalog India Pvt. Ltd. does not have a registered PCI Vendor ID and
30 they are using the PLX Technlogies Vendor ID since that is the PCI Chip used
32 - Dynalog India Pvt. Ltd. has provided the internal register specification for
33 their cards in their manuals.
36 #include <linux/module.h>
37 #include <linux/delay.h>
38 #include <linux/pci.h>
39 #include <linux/mutex.h>
41 #include "../comedidev.h"
43 #define READ_TIMEOUT 50
45 static const struct comedi_lrange range_pci1050_ai = {
53 static const char range_codes_pci1050_ai[] = { 0x00, 0x10, 0x30 };
55 struct dyna_pci10xx_private {
60 static int dyna_pci10xx_ai_eoc(struct comedi_device *dev,
61 struct comedi_subdevice *s,
62 struct comedi_insn *insn,
63 unsigned long context)
67 status = inw_p(dev->iobase);
68 if (status & (1 << 15))
73 static int dyna_pci10xx_insn_read_ai(struct comedi_device *dev,
74 struct comedi_subdevice *s,
75 struct comedi_insn *insn, unsigned int *data)
77 struct dyna_pci10xx_private *devpriv = dev->private;
81 unsigned int chan, range;
83 /* get the channel number and range */
84 chan = CR_CHAN(insn->chanspec);
85 range = range_codes_pci1050_ai[CR_RANGE((insn->chanspec))];
87 mutex_lock(&devpriv->mutex);
88 /* convert n samples */
89 for (n = 0; n < insn->n; n++) {
90 /* trigger conversion */
92 outw_p(0x0000 + range + chan, dev->iobase + 2);
95 ret = comedi_timeout(dev, s, insn, dyna_pci10xx_ai_eoc, 0);
100 d = inw_p(dev->iobase);
101 /* mask the first 4 bits - EOC bits */
105 mutex_unlock(&devpriv->mutex);
107 /* return the number of samples read/written */
108 return ret ? ret : n;
111 /* analog output callback */
112 static int dyna_pci10xx_insn_write_ao(struct comedi_device *dev,
113 struct comedi_subdevice *s,
114 struct comedi_insn *insn, unsigned int *data)
116 struct dyna_pci10xx_private *devpriv = dev->private;
118 unsigned int chan, range;
120 chan = CR_CHAN(insn->chanspec);
121 range = range_codes_pci1050_ai[CR_RANGE((insn->chanspec))];
123 mutex_lock(&devpriv->mutex);
124 for (n = 0; n < insn->n; n++) {
126 /* trigger conversion and write data */
127 outw_p(data[n], dev->iobase);
130 mutex_unlock(&devpriv->mutex);
134 /* digital input bit interface */
135 static int dyna_pci10xx_di_insn_bits(struct comedi_device *dev,
136 struct comedi_subdevice *s,
137 struct comedi_insn *insn, unsigned int *data)
139 struct dyna_pci10xx_private *devpriv = dev->private;
142 mutex_lock(&devpriv->mutex);
144 d = inw_p(devpriv->BADR3);
147 /* on return the data[0] contains output and data[1] contains input */
150 mutex_unlock(&devpriv->mutex);
154 static int dyna_pci10xx_do_insn_bits(struct comedi_device *dev,
155 struct comedi_subdevice *s,
156 struct comedi_insn *insn,
159 struct dyna_pci10xx_private *devpriv = dev->private;
161 mutex_lock(&devpriv->mutex);
162 if (comedi_dio_update_state(s, data)) {
164 outw_p(s->state, devpriv->BADR3);
169 mutex_unlock(&devpriv->mutex);
174 static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
175 unsigned long context_unused)
177 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
178 struct dyna_pci10xx_private *devpriv;
179 struct comedi_subdevice *s;
182 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
186 ret = comedi_pci_enable(dev);
189 dev->iobase = pci_resource_start(pcidev, 2);
190 devpriv->BADR3 = pci_resource_start(pcidev, 3);
192 mutex_init(&devpriv->mutex);
194 ret = comedi_alloc_subdevices(dev, 4);
199 s = &dev->subdevices[0];
200 s->type = COMEDI_SUBD_AI;
201 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
204 s->range_table = &range_pci1050_ai;
205 s->len_chanlist = 16;
206 s->insn_read = dyna_pci10xx_insn_read_ai;
209 s = &dev->subdevices[1];
210 s->type = COMEDI_SUBD_AO;
211 s->subdev_flags = SDF_WRITABLE;
214 s->range_table = &range_unipolar10;
215 s->len_chanlist = 16;
216 s->insn_write = dyna_pci10xx_insn_write_ao;
219 s = &dev->subdevices[2];
220 s->type = COMEDI_SUBD_DI;
221 s->subdev_flags = SDF_READABLE | SDF_GROUND;
224 s->range_table = &range_digital;
225 s->len_chanlist = 16;
226 s->insn_bits = dyna_pci10xx_di_insn_bits;
229 s = &dev->subdevices[3];
230 s->type = COMEDI_SUBD_DO;
231 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
234 s->range_table = &range_digital;
235 s->len_chanlist = 16;
237 s->insn_bits = dyna_pci10xx_do_insn_bits;
242 static void dyna_pci10xx_detach(struct comedi_device *dev)
244 struct dyna_pci10xx_private *devpriv = dev->private;
247 mutex_destroy(&devpriv->mutex);
248 comedi_pci_disable(dev);
251 static struct comedi_driver dyna_pci10xx_driver = {
252 .driver_name = "dyna_pci10xx",
253 .module = THIS_MODULE,
254 .auto_attach = dyna_pci10xx_auto_attach,
255 .detach = dyna_pci10xx_detach,
258 static int dyna_pci10xx_pci_probe(struct pci_dev *dev,
259 const struct pci_device_id *id)
261 return comedi_pci_auto_config(dev, &dyna_pci10xx_driver,
265 static const struct pci_device_id dyna_pci10xx_pci_table[] = {
266 { PCI_DEVICE(PCI_VENDOR_ID_PLX, 0x1050) },
269 MODULE_DEVICE_TABLE(pci, dyna_pci10xx_pci_table);
271 static struct pci_driver dyna_pci10xx_pci_driver = {
272 .name = "dyna_pci10xx",
273 .id_table = dyna_pci10xx_pci_table,
274 .probe = dyna_pci10xx_pci_probe,
275 .remove = comedi_pci_auto_unconfig,
277 module_comedi_pci_driver(dyna_pci10xx_driver, dyna_pci10xx_pci_driver);
279 MODULE_LICENSE("GPL");
280 MODULE_AUTHOR("Prashant Shah <pshah.mumbai@gmail.com>");
281 MODULE_DESCRIPTION("Comedi based drivers for Dynalog PCI DAQ cards");