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.
17 * Driver: dyna_pci10xx
18 * Description: Dynalog India PCI DAQ Cards, http://www.dynalogindia.com/
19 * Devices: [Dynalog] PCI-1050 (dyna_pci1050)
20 * Author: Prashant Shah <pshah.mumbai@gmail.com>
23 * Developed at Automation Labs, Chemical Dept., IIT Bombay, India.
24 * Prof. Kannan Moudgalya <kannan@iitb.ac.in>
25 * http://www.iitb.ac.in
28 * - Dynalog India Pvt. Ltd. does not have a registered PCI Vendor ID and
29 * they are using the PLX Technlogies Vendor ID since that is the PCI Chip
31 * - Dynalog India Pvt. Ltd. has provided the internal register specification
32 * for their cards in their manuals.
35 #include <linux/module.h>
36 #include <linux/delay.h>
37 #include <linux/pci.h>
38 #include <linux/mutex.h>
40 #include "../comedidev.h"
42 #define READ_TIMEOUT 50
44 static const struct comedi_lrange range_pci1050_ai = {
52 static const char range_codes_pci1050_ai[] = { 0x00, 0x10, 0x30 };
54 struct dyna_pci10xx_private {
59 static int dyna_pci10xx_ai_eoc(struct comedi_device *dev,
60 struct comedi_subdevice *s,
61 struct comedi_insn *insn,
62 unsigned long context)
66 status = inw_p(dev->iobase);
67 if (status & (1 << 15))
72 static int dyna_pci10xx_insn_read_ai(struct comedi_device *dev,
73 struct comedi_subdevice *s,
74 struct comedi_insn *insn, unsigned int *data)
76 struct dyna_pci10xx_private *devpriv = dev->private;
80 unsigned int chan, range;
82 /* get the channel number and range */
83 chan = CR_CHAN(insn->chanspec);
84 range = range_codes_pci1050_ai[CR_RANGE((insn->chanspec))];
86 mutex_lock(&devpriv->mutex);
87 /* convert n samples */
88 for (n = 0; n < insn->n; n++) {
89 /* trigger conversion */
91 outw_p(0x0000 + range + chan, dev->iobase + 2);
94 ret = comedi_timeout(dev, s, insn, dyna_pci10xx_ai_eoc, 0);
99 d = inw_p(dev->iobase);
100 /* mask the first 4 bits - EOC bits */
104 mutex_unlock(&devpriv->mutex);
106 /* return the number of samples read/written */
107 return ret ? ret : n;
110 /* analog output callback */
111 static int dyna_pci10xx_insn_write_ao(struct comedi_device *dev,
112 struct comedi_subdevice *s,
113 struct comedi_insn *insn, unsigned int *data)
115 struct dyna_pci10xx_private *devpriv = dev->private;
117 unsigned int chan, range;
119 chan = CR_CHAN(insn->chanspec);
120 range = range_codes_pci1050_ai[CR_RANGE((insn->chanspec))];
122 mutex_lock(&devpriv->mutex);
123 for (n = 0; n < insn->n; n++) {
125 /* trigger conversion and write data */
126 outw_p(data[n], dev->iobase);
129 mutex_unlock(&devpriv->mutex);
133 /* digital input bit interface */
134 static int dyna_pci10xx_di_insn_bits(struct comedi_device *dev,
135 struct comedi_subdevice *s,
136 struct comedi_insn *insn, unsigned int *data)
138 struct dyna_pci10xx_private *devpriv = dev->private;
141 mutex_lock(&devpriv->mutex);
143 d = inw_p(devpriv->BADR3);
146 /* on return the data[0] contains output and data[1] contains input */
149 mutex_unlock(&devpriv->mutex);
153 static int dyna_pci10xx_do_insn_bits(struct comedi_device *dev,
154 struct comedi_subdevice *s,
155 struct comedi_insn *insn,
158 struct dyna_pci10xx_private *devpriv = dev->private;
160 mutex_lock(&devpriv->mutex);
161 if (comedi_dio_update_state(s, data)) {
163 outw_p(s->state, devpriv->BADR3);
168 mutex_unlock(&devpriv->mutex);
173 static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
174 unsigned long context_unused)
176 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
177 struct dyna_pci10xx_private *devpriv;
178 struct comedi_subdevice *s;
181 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
185 ret = comedi_pci_enable(dev);
188 dev->iobase = pci_resource_start(pcidev, 2);
189 devpriv->BADR3 = pci_resource_start(pcidev, 3);
191 mutex_init(&devpriv->mutex);
193 ret = comedi_alloc_subdevices(dev, 4);
198 s = &dev->subdevices[0];
199 s->type = COMEDI_SUBD_AI;
200 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
203 s->range_table = &range_pci1050_ai;
204 s->len_chanlist = 16;
205 s->insn_read = dyna_pci10xx_insn_read_ai;
208 s = &dev->subdevices[1];
209 s->type = COMEDI_SUBD_AO;
210 s->subdev_flags = SDF_WRITABLE;
213 s->range_table = &range_unipolar10;
214 s->len_chanlist = 16;
215 s->insn_write = dyna_pci10xx_insn_write_ao;
218 s = &dev->subdevices[2];
219 s->type = COMEDI_SUBD_DI;
220 s->subdev_flags = SDF_READABLE;
223 s->range_table = &range_digital;
224 s->len_chanlist = 16;
225 s->insn_bits = dyna_pci10xx_di_insn_bits;
228 s = &dev->subdevices[3];
229 s->type = COMEDI_SUBD_DO;
230 s->subdev_flags = SDF_WRITABLE;
233 s->range_table = &range_digital;
234 s->len_chanlist = 16;
236 s->insn_bits = dyna_pci10xx_do_insn_bits;
241 static void dyna_pci10xx_detach(struct comedi_device *dev)
243 struct dyna_pci10xx_private *devpriv = dev->private;
245 comedi_pci_detach(dev);
247 mutex_destroy(&devpriv->mutex);
250 static struct comedi_driver dyna_pci10xx_driver = {
251 .driver_name = "dyna_pci10xx",
252 .module = THIS_MODULE,
253 .auto_attach = dyna_pci10xx_auto_attach,
254 .detach = dyna_pci10xx_detach,
257 static int dyna_pci10xx_pci_probe(struct pci_dev *dev,
258 const struct pci_device_id *id)
260 return comedi_pci_auto_config(dev, &dyna_pci10xx_driver,
264 static const struct pci_device_id dyna_pci10xx_pci_table[] = {
265 { PCI_DEVICE(PCI_VENDOR_ID_PLX, 0x1050) },
268 MODULE_DEVICE_TABLE(pci, dyna_pci10xx_pci_table);
270 static struct pci_driver dyna_pci10xx_pci_driver = {
271 .name = "dyna_pci10xx",
272 .id_table = dyna_pci10xx_pci_table,
273 .probe = dyna_pci10xx_pci_probe,
274 .remove = comedi_pci_auto_unconfig,
276 module_comedi_pci_driver(dyna_pci10xx_driver, dyna_pci10xx_pci_driver);
278 MODULE_LICENSE("GPL");
279 MODULE_AUTHOR("Prashant Shah <pshah.mumbai@gmail.com>");
280 MODULE_DESCRIPTION("Comedi based drivers for Dynalog PCI DAQ cards");