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 = { 3, {
52 static const char range_codes_pci1050_ai[] = { 0x00, 0x10, 0x30 };
54 struct dyna_pci10xx_private {
59 /******************************************************************************/
60 /************************** READ WRITE FUNCTIONS ******************************/
61 /******************************************************************************/
63 /* analog input callback */
64 static int dyna_pci10xx_insn_read_ai(struct comedi_device *dev,
65 struct comedi_subdevice *s,
66 struct comedi_insn *insn, unsigned int *data)
68 struct dyna_pci10xx_private *devpriv = dev->private;
71 unsigned int chan, range;
73 /* get the channel number and range */
74 chan = CR_CHAN(insn->chanspec);
75 range = range_codes_pci1050_ai[CR_RANGE((insn->chanspec))];
77 mutex_lock(&devpriv->mutex);
78 /* convert n samples */
79 for (n = 0; n < insn->n; n++) {
80 /* trigger conversion */
82 outw_p(0x0000 + range + chan, dev->iobase + 2);
85 for (counter = 0; counter < READ_TIMEOUT; counter++) {
86 d = inw_p(dev->iobase);
88 /* check if read is successful if the EOC bit is set */
93 dev_dbg(dev->class_dev, "timeout reading analog input\n");
96 /* mask the first 4 bits - EOC bits */
100 mutex_unlock(&devpriv->mutex);
102 /* return the number of samples read/written */
106 /* analog output callback */
107 static int dyna_pci10xx_insn_write_ao(struct comedi_device *dev,
108 struct comedi_subdevice *s,
109 struct comedi_insn *insn, unsigned int *data)
111 struct dyna_pci10xx_private *devpriv = dev->private;
113 unsigned int chan, range;
115 chan = CR_CHAN(insn->chanspec);
116 range = range_codes_pci1050_ai[CR_RANGE((insn->chanspec))];
118 mutex_lock(&devpriv->mutex);
119 for (n = 0; n < insn->n; n++) {
121 /* trigger conversion and write data */
122 outw_p(data[n], dev->iobase);
125 mutex_unlock(&devpriv->mutex);
129 /* digital input bit interface */
130 static int dyna_pci10xx_di_insn_bits(struct comedi_device *dev,
131 struct comedi_subdevice *s,
132 struct comedi_insn *insn, unsigned int *data)
134 struct dyna_pci10xx_private *devpriv = dev->private;
137 mutex_lock(&devpriv->mutex);
139 d = inw_p(devpriv->BADR3);
142 /* on return the data[0] contains output and data[1] contains input */
145 mutex_unlock(&devpriv->mutex);
149 static int dyna_pci10xx_do_insn_bits(struct comedi_device *dev,
150 struct comedi_subdevice *s,
151 struct comedi_insn *insn,
154 struct dyna_pci10xx_private *devpriv = dev->private;
156 mutex_lock(&devpriv->mutex);
157 if (comedi_dio_update_state(s, data)) {
159 outw_p(s->state, devpriv->BADR3);
164 mutex_unlock(&devpriv->mutex);
169 static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
170 unsigned long context_unused)
172 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
173 struct dyna_pci10xx_private *devpriv;
174 struct comedi_subdevice *s;
177 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
181 ret = comedi_pci_enable(dev);
184 dev->iobase = pci_resource_start(pcidev, 2);
185 devpriv->BADR3 = pci_resource_start(pcidev, 3);
187 mutex_init(&devpriv->mutex);
189 ret = comedi_alloc_subdevices(dev, 4);
194 s = &dev->subdevices[0];
195 s->type = COMEDI_SUBD_AI;
196 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
199 s->range_table = &range_pci1050_ai;
200 s->len_chanlist = 16;
201 s->insn_read = dyna_pci10xx_insn_read_ai;
204 s = &dev->subdevices[1];
205 s->type = COMEDI_SUBD_AO;
206 s->subdev_flags = SDF_WRITABLE;
209 s->range_table = &range_unipolar10;
210 s->len_chanlist = 16;
211 s->insn_write = dyna_pci10xx_insn_write_ao;
214 s = &dev->subdevices[2];
215 s->type = COMEDI_SUBD_DI;
216 s->subdev_flags = SDF_READABLE | SDF_GROUND;
219 s->range_table = &range_digital;
220 s->len_chanlist = 16;
221 s->insn_bits = dyna_pci10xx_di_insn_bits;
224 s = &dev->subdevices[3];
225 s->type = COMEDI_SUBD_DO;
226 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
229 s->range_table = &range_digital;
230 s->len_chanlist = 16;
232 s->insn_bits = dyna_pci10xx_do_insn_bits;
234 dev_info(dev->class_dev, "%s attached\n", dev->board_name);
239 static void dyna_pci10xx_detach(struct comedi_device *dev)
241 struct dyna_pci10xx_private *devpriv = dev->private;
244 mutex_destroy(&devpriv->mutex);
245 comedi_pci_disable(dev);
248 static struct comedi_driver dyna_pci10xx_driver = {
249 .driver_name = "dyna_pci10xx",
250 .module = THIS_MODULE,
251 .auto_attach = dyna_pci10xx_auto_attach,
252 .detach = dyna_pci10xx_detach,
255 static int dyna_pci10xx_pci_probe(struct pci_dev *dev,
256 const struct pci_device_id *id)
258 return comedi_pci_auto_config(dev, &dyna_pci10xx_driver,
262 static const struct pci_device_id dyna_pci10xx_pci_table[] = {
263 { PCI_DEVICE(PCI_VENDOR_ID_PLX, 0x1050) },
266 MODULE_DEVICE_TABLE(pci, dyna_pci10xx_pci_table);
268 static struct pci_driver dyna_pci10xx_pci_driver = {
269 .name = "dyna_pci10xx",
270 .id_table = dyna_pci10xx_pci_table,
271 .probe = dyna_pci10xx_pci_probe,
272 .remove = comedi_pci_auto_unconfig,
274 module_comedi_pci_driver(dyna_pci10xx_driver, dyna_pci10xx_pci_driver);
276 MODULE_LICENSE("GPL");
277 MODULE_AUTHOR("Prashant Shah <pshah.mumbai@gmail.com>");
278 MODULE_DESCRIPTION("Comedi based drivers for Dynalog PCI DAQ cards");