2 comedi/drivers/ke_counter.c
3 Comedi driver for Kolter-Electronic PCI Counter 1 Card
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 Description: Driver for Kolter Electronic Counter Card
21 Devices: [Kolter Electronic] PCI Counter Card (ke_counter)
22 Author: Michael Hillmann
23 Updated: Mon, 14 Apr 2008 15:42:42 +0100
26 Configuration Options: not applicable, uses PCI auto config
28 This driver is a simple driver to read the counter values from
29 Kolter Electronic PCI Counter Card.
32 #include <linux/module.h>
33 #include <linux/pci.h>
35 #include "../comedidev.h"
37 #define CNT_CARD_DEVICE_ID 0x0014
39 /*-- counter write ----------------------------------------------------------*/
41 /* This should be used only for resetting the counters; maybe it is better
42 to make a special command 'reset'. */
43 static int cnt_winsn(struct comedi_device *dev,
44 struct comedi_subdevice *s, struct comedi_insn *insn,
47 int chan = CR_CHAN(insn->chanspec);
49 outb((unsigned char)((data[0] >> 24) & 0xff),
50 dev->iobase + chan * 0x20 + 0x10);
51 outb((unsigned char)((data[0] >> 16) & 0xff),
52 dev->iobase + chan * 0x20 + 0x0c);
53 outb((unsigned char)((data[0] >> 8) & 0xff),
54 dev->iobase + chan * 0x20 + 0x08);
55 outb((unsigned char)((data[0] >> 0) & 0xff),
56 dev->iobase + chan * 0x20 + 0x04);
58 /* return the number of samples written */
62 /*-- counter read -----------------------------------------------------------*/
64 static int cnt_rinsn(struct comedi_device *dev,
65 struct comedi_subdevice *s, struct comedi_insn *insn,
68 unsigned char a0, a1, a2, a3, a4;
69 int chan = CR_CHAN(insn->chanspec);
72 a0 = inb(dev->iobase + chan * 0x20);
73 a1 = inb(dev->iobase + chan * 0x20 + 0x04);
74 a2 = inb(dev->iobase + chan * 0x20 + 0x08);
75 a3 = inb(dev->iobase + chan * 0x20 + 0x0c);
76 a4 = inb(dev->iobase + chan * 0x20 + 0x10);
78 result = (a1 + (a2 * 256) + (a3 * 65536));
80 result = result - s->maxdata;
82 *data = (unsigned int)result;
84 /* return the number of samples read */
88 static int cnt_auto_attach(struct comedi_device *dev,
89 unsigned long context_unused)
91 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
92 struct comedi_subdevice *s;
95 ret = comedi_pci_enable(dev);
98 dev->iobase = pci_resource_start(pcidev, 0);
100 ret = comedi_alloc_subdevices(dev, 1);
104 s = &dev->subdevices[0];
105 dev->read_subdev = s;
107 s->type = COMEDI_SUBD_COUNTER;
108 s->subdev_flags = SDF_READABLE /* | SDF_COMMON */ ;
110 s->maxdata = 0x00ffffff;
111 s->insn_read = cnt_rinsn;
112 s->insn_write = cnt_winsn;
114 /* select 20MHz clock */
115 outb(3, dev->iobase + 248);
117 /* reset all counters */
118 outb(0, dev->iobase);
119 outb(0, dev->iobase + 0x20);
120 outb(0, dev->iobase + 0x40);
122 dev_info(dev->class_dev, "%s: %s attached\n",
123 dev->driver->driver_name, dev->board_name);
128 static struct comedi_driver ke_counter_driver = {
129 .driver_name = "ke_counter",
130 .module = THIS_MODULE,
131 .auto_attach = cnt_auto_attach,
132 .detach = comedi_pci_disable,
135 static int ke_counter_pci_probe(struct pci_dev *dev,
136 const struct pci_device_id *id)
138 return comedi_pci_auto_config(dev, &ke_counter_driver,
142 static DEFINE_PCI_DEVICE_TABLE(ke_counter_pci_table) = {
143 { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID) },
146 MODULE_DEVICE_TABLE(pci, ke_counter_pci_table);
148 static struct pci_driver ke_counter_pci_driver = {
149 .name = "ke_counter",
150 .id_table = ke_counter_pci_table,
151 .probe = ke_counter_pci_probe,
152 .remove = comedi_pci_auto_unconfig,
154 module_comedi_pci_driver(ke_counter_driver, ke_counter_pci_driver);
156 MODULE_AUTHOR("Comedi http://www.comedi.org");
157 MODULE_DESCRIPTION("Comedi low-level driver");
158 MODULE_LICENSE("GPL");