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: not applicable, uses PCI auto config
33 #include "../comedidev.h"
34 #include <linux/kernel.h>
35 #include <linux/delay.h>
36 #include "comedi_fc.h"
39 #define PCI8164_AXIS_X 0x00
40 #define PCI8164_AXIS_Y 0x08
41 #define PCI8164_AXIS_Z 0x10
42 #define PCI8164_AXIS_U 0x18
44 #define PCI8164_MSTS 0x00
45 #define PCI8164_SSTS 0x02
46 #define PCI8164_BUF0 0x04
47 #define PCI8164_BUF1 0x06
49 #define PCI8164_CMD 0x00
50 #define PCI8164_OTP 0x02
52 #define PCI_DEVICE_ID_PCI8164 0x8164
55 all the read commands are the same except for the addition a constant
56 * const to the data for inw()
58 static void adl_pci8164_insn_read(struct comedi_device *dev,
59 struct comedi_subdevice *s,
60 struct comedi_insn *insn,
62 char *action, unsigned short offset)
67 axis = CR_CHAN(insn->chanspec);
71 axis_reg = PCI8164_AXIS_X;
75 axis_reg = PCI8164_AXIS_Y;
79 axis_reg = PCI8164_AXIS_Z;
83 axis_reg = PCI8164_AXIS_U;
87 axis_reg = PCI8164_AXIS_X;
91 data[0] = inw(dev->iobase + axis_reg + offset);
92 printk(KERN_DEBUG "comedi: pci8164 %s read -> "
93 "%04X:%04X on axis %s\n",
94 action, data[0], data[1], axisname);
97 static int adl_pci8164_insn_read_msts(struct comedi_device *dev,
98 struct comedi_subdevice *s,
99 struct comedi_insn *insn,
102 adl_pci8164_insn_read(dev, s, insn, data, "MSTS", PCI8164_MSTS);
106 static int adl_pci8164_insn_read_ssts(struct comedi_device *dev,
107 struct comedi_subdevice *s,
108 struct comedi_insn *insn,
111 adl_pci8164_insn_read(dev, s, insn, data, "SSTS", PCI8164_SSTS);
115 static int adl_pci8164_insn_read_buf0(struct comedi_device *dev,
116 struct comedi_subdevice *s,
117 struct comedi_insn *insn,
120 adl_pci8164_insn_read(dev, s, insn, data, "BUF0", PCI8164_BUF0);
124 static int adl_pci8164_insn_read_buf1(struct comedi_device *dev,
125 struct comedi_subdevice *s,
126 struct comedi_insn *insn,
129 adl_pci8164_insn_read(dev, s, insn, data, "BUF1", PCI8164_BUF1);
134 all the write commands are the same except for the addition a constant
135 * const to the data for outw()
137 static void adl_pci8164_insn_out(struct comedi_device *dev,
138 struct comedi_subdevice *s,
139 struct comedi_insn *insn,
141 char *action, unsigned short offset)
143 unsigned int axis, axis_reg;
147 axis = CR_CHAN(insn->chanspec);
151 axis_reg = PCI8164_AXIS_X;
155 axis_reg = PCI8164_AXIS_Y;
159 axis_reg = PCI8164_AXIS_Z;
163 axis_reg = PCI8164_AXIS_U;
167 axis_reg = PCI8164_AXIS_X;
171 outw(data[0], dev->iobase + axis_reg + offset);
173 printk(KERN_DEBUG "comedi: pci8164 %s write -> "
174 "%04X:%04X on axis %s\n",
175 action, data[0], data[1], axisname);
179 static int adl_pci8164_insn_write_cmd(struct comedi_device *dev,
180 struct comedi_subdevice *s,
181 struct comedi_insn *insn,
184 adl_pci8164_insn_out(dev, s, insn, data, "CMD", PCI8164_CMD);
188 static int adl_pci8164_insn_write_otp(struct comedi_device *dev,
189 struct comedi_subdevice *s,
190 struct comedi_insn *insn,
193 adl_pci8164_insn_out(dev, s, insn, data, "OTP", PCI8164_OTP);
197 static int adl_pci8164_insn_write_buf0(struct comedi_device *dev,
198 struct comedi_subdevice *s,
199 struct comedi_insn *insn,
202 adl_pci8164_insn_out(dev, s, insn, data, "BUF0", PCI8164_BUF0);
206 static int adl_pci8164_insn_write_buf1(struct comedi_device *dev,
207 struct comedi_subdevice *s,
208 struct comedi_insn *insn,
211 adl_pci8164_insn_out(dev, s, insn, data, "BUF1", PCI8164_BUF1);
215 static int adl_pci8164_attach_pci(struct comedi_device *dev,
216 struct pci_dev *pcidev)
218 struct comedi_subdevice *s;
221 comedi_set_hw_dev(dev, &pcidev->dev);
223 dev->board_name = dev->driver->driver_name;
225 ret = comedi_pci_enable(pcidev, dev->board_name);
228 dev->iobase = pci_resource_start(pcidev, 2);
230 ret = comedi_alloc_subdevices(dev, 4);
234 s = &dev->subdevices[0];
235 s->type = COMEDI_SUBD_PROC;
236 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
240 /* s->range_table = &range_axis; */
241 s->insn_read = adl_pci8164_insn_read_msts;
242 s->insn_write = adl_pci8164_insn_write_cmd;
244 s = &dev->subdevices[1];
245 s->type = COMEDI_SUBD_PROC;
246 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
250 /* s->range_table = &range_axis; */
251 s->insn_read = adl_pci8164_insn_read_ssts;
252 s->insn_write = adl_pci8164_insn_write_otp;
254 s = &dev->subdevices[2];
255 s->type = COMEDI_SUBD_PROC;
256 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
260 /* s->range_table = &range_axis; */
261 s->insn_read = adl_pci8164_insn_read_buf0;
262 s->insn_write = adl_pci8164_insn_write_buf0;
264 s = &dev->subdevices[3];
265 s->type = COMEDI_SUBD_PROC;
266 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
270 /* s->range_table = &range_axis; */
271 s->insn_read = adl_pci8164_insn_read_buf1;
272 s->insn_write = adl_pci8164_insn_write_buf1;
274 dev_info(dev->class_dev, "%s attached\n", dev->board_name);
279 static void adl_pci8164_detach(struct comedi_device *dev)
281 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
285 comedi_pci_disable(pcidev);
289 static struct comedi_driver adl_pci8164_driver = {
290 .driver_name = "adl_pci8164",
291 .module = THIS_MODULE,
292 .attach_pci = adl_pci8164_attach_pci,
293 .detach = adl_pci8164_detach,
296 static int __devinit adl_pci8164_pci_probe(struct pci_dev *dev,
297 const struct pci_device_id *ent)
299 return comedi_pci_auto_config(dev, &adl_pci8164_driver);
302 static void __devexit adl_pci8164_pci_remove(struct pci_dev *dev)
304 comedi_pci_auto_unconfig(dev);
307 static DEFINE_PCI_DEVICE_TABLE(adl_pci8164_pci_table) = {
308 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI8164) },
311 MODULE_DEVICE_TABLE(pci, adl_pci8164_pci_table);
313 static struct pci_driver adl_pci8164_pci_driver = {
314 .name = "adl_pci8164",
315 .id_table = adl_pci8164_pci_table,
316 .probe = adl_pci8164_pci_probe,
317 .remove = __devexit_p(adl_pci8164_pci_remove),
319 module_comedi_pci_driver(adl_pci8164_driver, adl_pci8164_pci_driver);
321 MODULE_AUTHOR("Comedi http://www.comedi.org");
322 MODULE_DESCRIPTION("Comedi low-level driver");
323 MODULE_LICENSE("GPL");