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);
102 d = inw_p(dev->iobase);
103 /* mask the first 4 bits - EOC bits */
107 mutex_unlock(&devpriv->mutex);
109 /* return the number of samples read/written */
110 return ret ? ret : n;
113 /* analog output callback */
114 static int dyna_pci10xx_insn_write_ao(struct comedi_device *dev,
115 struct comedi_subdevice *s,
116 struct comedi_insn *insn, unsigned int *data)
118 struct dyna_pci10xx_private *devpriv = dev->private;
120 unsigned int chan, range;
122 chan = CR_CHAN(insn->chanspec);
123 range = range_codes_pci1050_ai[CR_RANGE((insn->chanspec))];
125 mutex_lock(&devpriv->mutex);
126 for (n = 0; n < insn->n; n++) {
128 /* trigger conversion and write data */
129 outw_p(data[n], dev->iobase);
132 mutex_unlock(&devpriv->mutex);
136 /* digital input bit interface */
137 static int dyna_pci10xx_di_insn_bits(struct comedi_device *dev,
138 struct comedi_subdevice *s,
139 struct comedi_insn *insn, unsigned int *data)
141 struct dyna_pci10xx_private *devpriv = dev->private;
144 mutex_lock(&devpriv->mutex);
146 d = inw_p(devpriv->BADR3);
149 /* on return the data[0] contains output and data[1] contains input */
152 mutex_unlock(&devpriv->mutex);
156 static int dyna_pci10xx_do_insn_bits(struct comedi_device *dev,
157 struct comedi_subdevice *s,
158 struct comedi_insn *insn,
161 struct dyna_pci10xx_private *devpriv = dev->private;
163 mutex_lock(&devpriv->mutex);
164 if (comedi_dio_update_state(s, data)) {
166 outw_p(s->state, devpriv->BADR3);
171 mutex_unlock(&devpriv->mutex);
176 static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
177 unsigned long context_unused)
179 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
180 struct dyna_pci10xx_private *devpriv;
181 struct comedi_subdevice *s;
184 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
188 ret = comedi_pci_enable(dev);
191 dev->iobase = pci_resource_start(pcidev, 2);
192 devpriv->BADR3 = pci_resource_start(pcidev, 3);
194 mutex_init(&devpriv->mutex);
196 ret = comedi_alloc_subdevices(dev, 4);
201 s = &dev->subdevices[0];
202 s->type = COMEDI_SUBD_AI;
203 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
206 s->range_table = &range_pci1050_ai;
207 s->len_chanlist = 16;
208 s->insn_read = dyna_pci10xx_insn_read_ai;
211 s = &dev->subdevices[1];
212 s->type = COMEDI_SUBD_AO;
213 s->subdev_flags = SDF_WRITABLE;
216 s->range_table = &range_unipolar10;
217 s->len_chanlist = 16;
218 s->insn_write = dyna_pci10xx_insn_write_ao;
221 s = &dev->subdevices[2];
222 s->type = COMEDI_SUBD_DI;
223 s->subdev_flags = SDF_READABLE | SDF_GROUND;
226 s->range_table = &range_digital;
227 s->len_chanlist = 16;
228 s->insn_bits = dyna_pci10xx_di_insn_bits;
231 s = &dev->subdevices[3];
232 s->type = COMEDI_SUBD_DO;
233 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
236 s->range_table = &range_digital;
237 s->len_chanlist = 16;
239 s->insn_bits = dyna_pci10xx_do_insn_bits;
244 static void dyna_pci10xx_detach(struct comedi_device *dev)
246 struct dyna_pci10xx_private *devpriv = dev->private;
249 mutex_destroy(&devpriv->mutex);
250 comedi_pci_disable(dev);
253 static struct comedi_driver dyna_pci10xx_driver = {
254 .driver_name = "dyna_pci10xx",
255 .module = THIS_MODULE,
256 .auto_attach = dyna_pci10xx_auto_attach,
257 .detach = dyna_pci10xx_detach,
260 static int dyna_pci10xx_pci_probe(struct pci_dev *dev,
261 const struct pci_device_id *id)
263 return comedi_pci_auto_config(dev, &dyna_pci10xx_driver,
267 static const struct pci_device_id dyna_pci10xx_pci_table[] = {
268 { PCI_DEVICE(PCI_VENDOR_ID_PLX, 0x1050) },
271 MODULE_DEVICE_TABLE(pci, dyna_pci10xx_pci_table);
273 static struct pci_driver dyna_pci10xx_pci_driver = {
274 .name = "dyna_pci10xx",
275 .id_table = dyna_pci10xx_pci_table,
276 .probe = dyna_pci10xx_pci_probe,
277 .remove = comedi_pci_auto_unconfig,
279 module_comedi_pci_driver(dyna_pci10xx_driver, dyna_pci10xx_pci_driver);
281 MODULE_LICENSE("GPL");
282 MODULE_AUTHOR("Prashant Shah <pshah.mumbai@gmail.com>");
283 MODULE_DESCRIPTION("Comedi based drivers for Dynalog PCI DAQ cards");