2 comedi/drivers/adl_pci8164.c
4 Hardware comedi driver fot PCI-8164 Adlink card
5 Copyright (C) 2004 Michel Lachine <mike@mikelachaine.ca>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 Description: Driver for the Adlink PCI-8164 4 Axes Motion Control board
25 Devices: [ADLink] PCI-8164 (adl_pci8164)
26 Author: Michel Lachaine <mike@mikelachaine.ca>
28 Updated: Mon, 14 Apr 2008 15:10:32 +0100
30 Configuration Options:
31 [0] - PCI bus of device (optional)
32 [1] - PCI slot of device (optional)
33 If bus/slot is not specified, the first supported
34 PCI device found will be used.
37 #include "../comedidev.h"
38 #include <linux/delay.h>
39 #include "comedi_fc.h"
40 #include "comedi_pci.h"
43 #define PCI8164_AXIS_X 0x00
44 #define PCI8164_AXIS_Y 0x08
45 #define PCI8164_AXIS_Z 0x10
46 #define PCI8164_AXIS_U 0x18
48 #define PCI8164_MSTS 0x00
49 #define PCI8164_SSTS 0x02
50 #define PCI8164_BUF0 0x04
51 #define PCI8164_BUF1 0x06
53 #define PCI8164_CMD 0x00
54 #define PCI8164_OTP 0x02
56 #define PCI_DEVICE_ID_PCI8164 0x8164
58 static DEFINE_PCI_DEVICE_TABLE(adl_pci8164_pci_table) = {
59 {PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164, PCI_ANY_ID, PCI_ANY_ID, 0,
64 MODULE_DEVICE_TABLE(pci, adl_pci8164_pci_table);
68 struct pci_dev *pci_dev;
69 } adl_pci8164_private;
71 #define devpriv ((adl_pci8164_private *)dev->private)
73 static int adl_pci8164_attach(struct comedi_device * dev, comedi_devconfig * it);
74 static int adl_pci8164_detach(struct comedi_device * dev);
75 static struct comedi_driver driver_adl_pci8164 = {
76 driver_name:"adl_pci8164",
78 attach:adl_pci8164_attach,
79 detach:adl_pci8164_detach,
82 static int adl_pci8164_insn_read_msts(struct comedi_device * dev, struct comedi_subdevice * s,
83 comedi_insn * insn, unsigned int * data);
85 static int adl_pci8164_insn_read_ssts(struct comedi_device * dev, struct comedi_subdevice * s,
86 comedi_insn * insn, unsigned int * data);
88 static int adl_pci8164_insn_read_buf0(struct comedi_device * dev, struct comedi_subdevice * s,
89 comedi_insn * insn, unsigned int * data);
91 static int adl_pci8164_insn_read_buf1(struct comedi_device * dev, struct comedi_subdevice * s,
92 comedi_insn * insn, unsigned int * data);
94 static int adl_pci8164_insn_write_cmd(struct comedi_device * dev, struct comedi_subdevice * s,
95 comedi_insn * insn, unsigned int * data);
97 static int adl_pci8164_insn_write_otp(struct comedi_device * dev, struct comedi_subdevice * s,
98 comedi_insn * insn, unsigned int * data);
100 static int adl_pci8164_insn_write_buf0(struct comedi_device * dev,
101 struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data);
103 static int adl_pci8164_insn_write_buf1(struct comedi_device * dev,
104 struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data);
106 static int adl_pci8164_attach(struct comedi_device * dev, comedi_devconfig * it)
108 struct pci_dev *pcidev;
109 struct comedi_subdevice *s;
112 printk("comedi: attempt to attach...\n");
113 printk("comedi%d: adl_pci8164\n", dev->minor);
115 dev->board_name = "pci8164";
116 bus = it->options[0];
117 slot = it->options[1];
119 if (alloc_private(dev, sizeof(adl_pci8164_private)) < 0)
122 if (alloc_subdevices(dev, 4) < 0)
125 for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
127 pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) {
129 if (pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
130 pcidev->device == PCI_DEVICE_ID_PCI8164) {
132 /* requested particular bus/slot */
133 if (pcidev->bus->number != bus
134 || PCI_SLOT(pcidev->devfn) != slot) {
138 devpriv->pci_dev = pcidev;
139 if (comedi_pci_enable(pcidev, "adl_pci8164") < 0) {
140 printk("comedi%d: Failed to enable PCI device and request regions\n", dev->minor);
143 dev->iobase = pci_resource_start(pcidev, 2);
144 printk("comedi: base addr %4lx\n", dev->iobase);
146 s = dev->subdevices + 0;
147 s->type = COMEDI_SUBD_PROC;
148 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
152 //s->range_table = &range_axis;
153 s->insn_read = adl_pci8164_insn_read_msts;
154 s->insn_write = adl_pci8164_insn_write_cmd;
156 s = dev->subdevices + 1;
157 s->type = COMEDI_SUBD_PROC;
158 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
162 //s->range_table = &range_axis;
163 s->insn_read = adl_pci8164_insn_read_ssts;
164 s->insn_write = adl_pci8164_insn_write_otp;
166 s = dev->subdevices + 2;
167 s->type = COMEDI_SUBD_PROC;
168 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
172 //s->range_table = &range_axis;
173 s->insn_read = adl_pci8164_insn_read_buf0;
174 s->insn_write = adl_pci8164_insn_write_buf0;
176 s = dev->subdevices + 3;
177 s->type = COMEDI_SUBD_PROC;
178 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
182 //s->range_table = &range_axis;
183 s->insn_read = adl_pci8164_insn_read_buf1;
184 s->insn_write = adl_pci8164_insn_write_buf1;
186 printk("comedi: attached\n");
192 printk("comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
193 dev->minor, bus, slot);
197 static int adl_pci8164_detach(struct comedi_device * dev)
199 printk("comedi%d: pci8164: remove\n", dev->minor);
201 if (devpriv && devpriv->pci_dev) {
203 comedi_pci_disable(devpriv->pci_dev);
205 pci_dev_put(devpriv->pci_dev);
211 static int adl_pci8164_insn_read_msts(struct comedi_device * dev, struct comedi_subdevice * s,
212 comedi_insn * insn, unsigned int * data)
217 axis = CR_CHAN(insn->chanspec);
221 axis_reg = PCI8164_AXIS_X;
225 axis_reg = PCI8164_AXIS_Y;
229 axis_reg = PCI8164_AXIS_Z;
233 axis_reg = PCI8164_AXIS_U;
237 axis_reg = PCI8164_AXIS_X;
241 data[0] = inw(dev->iobase + axis_reg + PCI8164_MSTS);
242 printk("comedi: pci8164 MSTS read -> %04X:%04X on axis %s\n", data[0],
248 static int adl_pci8164_insn_read_ssts(struct comedi_device * dev, struct comedi_subdevice * s,
249 comedi_insn * insn, unsigned int * data)
254 axis = CR_CHAN(insn->chanspec);
258 axis_reg = PCI8164_AXIS_X;
262 axis_reg = PCI8164_AXIS_Y;
266 axis_reg = PCI8164_AXIS_Z;
270 axis_reg = PCI8164_AXIS_U;
274 axis_reg = PCI8164_AXIS_X;
278 data[0] = inw(dev->iobase + axis_reg + PCI8164_SSTS);
279 printk("comedi: pci8164 SSTS read -> %04X:%04X on axis %s\n", data[0],
285 static int adl_pci8164_insn_read_buf0(struct comedi_device * dev, struct comedi_subdevice * s,
286 comedi_insn * insn, unsigned int * data)
291 axis = CR_CHAN(insn->chanspec);
295 axis_reg = PCI8164_AXIS_X;
299 axis_reg = PCI8164_AXIS_Y;
303 axis_reg = PCI8164_AXIS_Z;
307 axis_reg = PCI8164_AXIS_U;
311 axis_reg = PCI8164_AXIS_X;
315 data[0] = inw(dev->iobase + axis_reg + PCI8164_BUF0);
316 printk("comedi: pci8164 BUF0 read -> %04X:%04X on axis %s\n", data[0],
322 static int adl_pci8164_insn_read_buf1(struct comedi_device * dev, struct comedi_subdevice * s,
323 comedi_insn * insn, unsigned int * data)
329 axis = CR_CHAN(insn->chanspec);
333 axis_reg = PCI8164_AXIS_X;
337 axis_reg = PCI8164_AXIS_Y;
341 axis_reg = PCI8164_AXIS_Z;
345 axis_reg = PCI8164_AXIS_U;
349 axis_reg = PCI8164_AXIS_X;
353 data[0] = inw(dev->iobase + axis_reg + PCI8164_BUF1);
354 printk("comedi: pci8164 BUF1 read -> %04X:%04X on axis %s\n", data[0],
360 static int adl_pci8164_insn_write_cmd(struct comedi_device * dev, struct comedi_subdevice * s,
361 comedi_insn * insn, unsigned int * data)
363 unsigned int axis, axis_reg;
367 axis = CR_CHAN(insn->chanspec);
371 axis_reg = PCI8164_AXIS_X;
375 axis_reg = PCI8164_AXIS_Y;
379 axis_reg = PCI8164_AXIS_Z;
383 axis_reg = PCI8164_AXIS_U;
387 axis_reg = PCI8164_AXIS_X;
391 outw(data[0], dev->iobase + axis_reg + PCI8164_CMD);
392 printk("comedi: pci8164 CMD write -> %04X:%04X on axis %s\n", data[0],
398 static int adl_pci8164_insn_write_otp(struct comedi_device * dev, struct comedi_subdevice * s,
399 comedi_insn * insn, unsigned int * data)
405 axis = CR_CHAN(insn->chanspec);
409 axis_reg = PCI8164_AXIS_X;
413 axis_reg = PCI8164_AXIS_Y;
417 axis_reg = PCI8164_AXIS_Z;
421 axis_reg = PCI8164_AXIS_U;
425 axis_reg = PCI8164_AXIS_X;
429 outw(data[0], dev->iobase + axis_reg + PCI8164_OTP);
430 printk("comedi: pci8164 OTP write -> %04X:%04X on axis %s\n", data[0],
436 static int adl_pci8164_insn_write_buf0(struct comedi_device * dev,
437 struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data)
443 axis = CR_CHAN(insn->chanspec);
447 axis_reg = PCI8164_AXIS_X;
451 axis_reg = PCI8164_AXIS_Y;
455 axis_reg = PCI8164_AXIS_Z;
459 axis_reg = PCI8164_AXIS_U;
463 axis_reg = PCI8164_AXIS_X;
467 outw(data[0], dev->iobase + axis_reg + PCI8164_BUF0);
468 printk("comedi: pci8164 BUF0 write -> %04X:%04X on axis %s\n", data[0],
474 static int adl_pci8164_insn_write_buf1(struct comedi_device * dev,
475 struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data)
481 axis = CR_CHAN(insn->chanspec);
485 axis_reg = PCI8164_AXIS_X;
489 axis_reg = PCI8164_AXIS_Y;
493 axis_reg = PCI8164_AXIS_Z;
497 axis_reg = PCI8164_AXIS_U;
501 axis_reg = PCI8164_AXIS_X;
505 outw(data[0], dev->iobase + axis_reg + PCI8164_BUF1);
506 printk("comedi: pci8164 BUF1 write -> %04X:%04X on axis %s\n", data[0],
512 COMEDI_PCI_INITCLEANUP(driver_adl_pci8164, adl_pci8164_pci_table);