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/kernel.h>
39 #include <linux/delay.h>
40 #include "comedi_fc.h"
41 #include "comedi_pci.h"
44 #define PCI8164_AXIS_X 0x00
45 #define PCI8164_AXIS_Y 0x08
46 #define PCI8164_AXIS_Z 0x10
47 #define PCI8164_AXIS_U 0x18
49 #define PCI8164_MSTS 0x00
50 #define PCI8164_SSTS 0x02
51 #define PCI8164_BUF0 0x04
52 #define PCI8164_BUF1 0x06
54 #define PCI8164_CMD 0x00
55 #define PCI8164_OTP 0x02
57 #define PCI_DEVICE_ID_PCI8164 0x8164
59 static DEFINE_PCI_DEVICE_TABLE(adl_pci8164_pci_table) = {
61 PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164, PCI_ANY_ID,
62 PCI_ANY_ID, 0, 0, 0}, {
66 MODULE_DEVICE_TABLE(pci, adl_pci8164_pci_table);
68 struct adl_pci8164_private {
70 struct pci_dev *pci_dev;
73 #define devpriv ((struct adl_pci8164_private *)dev->private)
75 static int adl_pci8164_attach(struct comedi_device *dev,
76 struct comedi_devconfig *it);
77 static int adl_pci8164_detach(struct comedi_device *dev);
78 static struct comedi_driver driver_adl_pci8164 = {
79 .driver_name = "adl_pci8164",
80 .module = THIS_MODULE,
81 .attach = adl_pci8164_attach,
82 .detach = adl_pci8164_detach,
85 static int adl_pci8164_insn_read_msts(struct comedi_device *dev,
86 struct comedi_subdevice *s,
87 struct comedi_insn *insn,
90 static int adl_pci8164_insn_read_ssts(struct comedi_device *dev,
91 struct comedi_subdevice *s,
92 struct comedi_insn *insn,
95 static int adl_pci8164_insn_read_buf0(struct comedi_device *dev,
96 struct comedi_subdevice *s,
97 struct comedi_insn *insn,
100 static int adl_pci8164_insn_read_buf1(struct comedi_device *dev,
101 struct comedi_subdevice *s,
102 struct comedi_insn *insn,
105 static int adl_pci8164_insn_write_cmd(struct comedi_device *dev,
106 struct comedi_subdevice *s,
107 struct comedi_insn *insn,
110 static int adl_pci8164_insn_write_otp(struct comedi_device *dev,
111 struct comedi_subdevice *s,
112 struct comedi_insn *insn,
115 static int adl_pci8164_insn_write_buf0(struct comedi_device *dev,
116 struct comedi_subdevice *s,
117 struct comedi_insn *insn,
120 static int adl_pci8164_insn_write_buf1(struct comedi_device *dev,
121 struct comedi_subdevice *s,
122 struct comedi_insn *insn,
125 static int adl_pci8164_attach(struct comedi_device *dev,
126 struct comedi_devconfig *it)
128 struct pci_dev *pcidev;
129 struct comedi_subdevice *s;
132 printk(KERN_INFO "comedi: attempt to attach...\n");
133 printk(KERN_INFO "comedi%d: adl_pci8164\n", dev->minor);
135 dev->board_name = "pci8164";
136 bus = it->options[0];
137 slot = it->options[1];
139 if (alloc_private(dev, sizeof(struct adl_pci8164_private)) < 0)
142 if (alloc_subdevices(dev, 4) < 0)
145 for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
147 pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) {
149 if (pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
150 pcidev->device == PCI_DEVICE_ID_PCI8164) {
152 /* requested particular bus/slot */
153 if (pcidev->bus->number != bus
154 || PCI_SLOT(pcidev->devfn) != slot)
157 devpriv->pci_dev = pcidev;
158 if (comedi_pci_enable(pcidev, "adl_pci8164") < 0) {
159 printk(KERN_ERR "comedi%d: Failed to enable "
160 "PCI device and request regions\n", dev->minor);
163 dev->iobase = pci_resource_start(pcidev, 2);
164 printk(KERN_DEBUG "comedi: base addr %4lx\n",
167 s = dev->subdevices + 0;
168 s->type = COMEDI_SUBD_PROC;
169 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
173 /* s->range_table = &range_axis; */
174 s->insn_read = adl_pci8164_insn_read_msts;
175 s->insn_write = adl_pci8164_insn_write_cmd;
177 s = dev->subdevices + 1;
178 s->type = COMEDI_SUBD_PROC;
179 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
183 /* s->range_table = &range_axis; */
184 s->insn_read = adl_pci8164_insn_read_ssts;
185 s->insn_write = adl_pci8164_insn_write_otp;
187 s = dev->subdevices + 2;
188 s->type = COMEDI_SUBD_PROC;
189 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
193 /* s->range_table = &range_axis; */
194 s->insn_read = adl_pci8164_insn_read_buf0;
195 s->insn_write = adl_pci8164_insn_write_buf0;
197 s = dev->subdevices + 3;
198 s->type = COMEDI_SUBD_PROC;
199 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
203 /* s->range_table = &range_axis; */
204 s->insn_read = adl_pci8164_insn_read_buf1;
205 s->insn_write = adl_pci8164_insn_write_buf1;
207 printk(KERN_INFO "comedi: attached\n");
213 printk(KERN_ERR "comedi%d: no supported board found!"
214 "(req. bus/slot : %d/%d)\n", dev->minor, bus, slot);
218 static int adl_pci8164_detach(struct comedi_device *dev)
220 printk(KERN_INFO "comedi%d: pci8164: remove\n", dev->minor);
222 if (devpriv && devpriv->pci_dev) {
224 comedi_pci_disable(devpriv->pci_dev);
225 pci_dev_put(devpriv->pci_dev);
232 all the read commands are the same except for the addition a constant
233 * const to the data for inw()
235 static void adl_pci8164_insn_read(struct comedi_device *dev,
236 struct comedi_subdevice *s,
237 struct comedi_insn *insn,
239 char *action, unsigned short offset)
244 axis = CR_CHAN(insn->chanspec);
248 axis_reg = PCI8164_AXIS_X;
252 axis_reg = PCI8164_AXIS_Y;
256 axis_reg = PCI8164_AXIS_Z;
260 axis_reg = PCI8164_AXIS_U;
264 axis_reg = PCI8164_AXIS_X;
268 data[0] = inw(dev->iobase + axis_reg + offset);
269 printk(KERN_DEBUG "comedi: pci8164 %s read -> "
270 "%04X:%04X on axis %s\n",
271 action, data[0], data[1], axisname);
274 static int adl_pci8164_insn_read_msts(struct comedi_device *dev,
275 struct comedi_subdevice *s,
276 struct comedi_insn *insn,
279 adl_pci8164_insn_read(dev, s, insn, data, "MSTS", PCI8164_MSTS);
283 static int adl_pci8164_insn_read_ssts(struct comedi_device *dev,
284 struct comedi_subdevice *s,
285 struct comedi_insn *insn,
288 adl_pci8164_insn_read(dev, s, insn, data, "SSTS", PCI8164_SSTS);
292 static int adl_pci8164_insn_read_buf0(struct comedi_device *dev,
293 struct comedi_subdevice *s,
294 struct comedi_insn *insn,
297 adl_pci8164_insn_read(dev, s, insn, data, "BUF0", PCI8164_BUF0);
301 static int adl_pci8164_insn_read_buf1(struct comedi_device *dev,
302 struct comedi_subdevice *s,
303 struct comedi_insn *insn,
306 adl_pci8164_insn_read(dev, s, insn, data, "BUF1", PCI8164_BUF1);
311 all the write commands are the same except for the addition a constant
312 * const to the data for outw()
314 static void adl_pci8164_insn_out(struct comedi_device *dev,
315 struct comedi_subdevice *s,
316 struct comedi_insn *insn,
318 char *action, unsigned short offset)
320 unsigned int axis, axis_reg;
324 axis = CR_CHAN(insn->chanspec);
328 axis_reg = PCI8164_AXIS_X;
332 axis_reg = PCI8164_AXIS_Y;
336 axis_reg = PCI8164_AXIS_Z;
340 axis_reg = PCI8164_AXIS_U;
344 axis_reg = PCI8164_AXIS_X;
348 outw(data[0], dev->iobase + axis_reg + offset);
350 printk(KERN_DEBUG "comedi: pci8164 %s write -> "
351 "%04X:%04X on axis %s\n",
352 action, data[0], data[1], axisname);
356 static int adl_pci8164_insn_write_cmd(struct comedi_device *dev,
357 struct comedi_subdevice *s,
358 struct comedi_insn *insn,
361 adl_pci8164_insn_out(dev, s, insn, data, "CMD", PCI8164_CMD);
365 static int adl_pci8164_insn_write_otp(struct comedi_device *dev,
366 struct comedi_subdevice *s,
367 struct comedi_insn *insn,
370 adl_pci8164_insn_out(dev, s, insn, data, "OTP", PCI8164_OTP);
374 static int adl_pci8164_insn_write_buf0(struct comedi_device *dev,
375 struct comedi_subdevice *s,
376 struct comedi_insn *insn,
379 adl_pci8164_insn_out(dev, s, insn, data, "BUF0", PCI8164_BUF0);
383 static int adl_pci8164_insn_write_buf1(struct comedi_device *dev,
384 struct comedi_subdevice *s,
385 struct comedi_insn *insn,
388 adl_pci8164_insn_out(dev, s, insn, data, "BUF1", PCI8164_BUF1);
392 COMEDI_PCI_INITCLEANUP(driver_adl_pci8164, adl_pci8164_pci_table);