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/pci.h>
34 #include "../comedidev.h"
36 #define CNT_CARD_DEVICE_ID 0x0014
38 /*-- counter write ----------------------------------------------------------*/
40 /* This should be used only for resetting the counters; maybe it is better
41 to make a special command 'reset'. */
42 static int cnt_winsn(struct comedi_device *dev,
43 struct comedi_subdevice *s, struct comedi_insn *insn,
46 int chan = CR_CHAN(insn->chanspec);
48 outb((unsigned char)((data[0] >> 24) & 0xff),
49 dev->iobase + chan * 0x20 + 0x10);
50 outb((unsigned char)((data[0] >> 16) & 0xff),
51 dev->iobase + chan * 0x20 + 0x0c);
52 outb((unsigned char)((data[0] >> 8) & 0xff),
53 dev->iobase + chan * 0x20 + 0x08);
54 outb((unsigned char)((data[0] >> 0) & 0xff),
55 dev->iobase + chan * 0x20 + 0x04);
57 /* return the number of samples written */
61 /*-- counter read -----------------------------------------------------------*/
63 static int cnt_rinsn(struct comedi_device *dev,
64 struct comedi_subdevice *s, struct comedi_insn *insn,
67 unsigned char a0, a1, a2, a3, a4;
68 int chan = CR_CHAN(insn->chanspec);
71 a0 = inb(dev->iobase + chan * 0x20);
72 a1 = inb(dev->iobase + chan * 0x20 + 0x04);
73 a2 = inb(dev->iobase + chan * 0x20 + 0x08);
74 a3 = inb(dev->iobase + chan * 0x20 + 0x0c);
75 a4 = inb(dev->iobase + chan * 0x20 + 0x10);
77 result = (a1 + (a2 * 256) + (a3 * 65536));
79 result = result - s->maxdata;
81 *data = (unsigned int)result;
83 /* return the number of samples read */
87 static int cnt_auto_attach(struct comedi_device *dev,
88 unsigned long context_unused)
90 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
91 struct comedi_subdevice *s;
94 ret = comedi_pci_enable(dev);
97 dev->iobase = pci_resource_start(pcidev, 0);
99 ret = comedi_alloc_subdevices(dev, 1);
103 s = &dev->subdevices[0];
104 dev->read_subdev = s;
106 s->type = COMEDI_SUBD_COUNTER;
107 s->subdev_flags = SDF_READABLE /* | SDF_COMMON */ ;
109 s->maxdata = 0x00ffffff;
110 s->insn_read = cnt_rinsn;
111 s->insn_write = cnt_winsn;
113 /* select 20MHz clock */
114 outb(3, dev->iobase + 248);
116 /* reset all counters */
117 outb(0, dev->iobase);
118 outb(0, dev->iobase + 0x20);
119 outb(0, dev->iobase + 0x40);
121 dev_info(dev->class_dev, "%s: %s attached\n",
122 dev->driver->driver_name, dev->board_name);
127 static struct comedi_driver ke_counter_driver = {
128 .driver_name = "ke_counter",
129 .module = THIS_MODULE,
130 .auto_attach = cnt_auto_attach,
131 .detach = comedi_pci_disable,
134 static int ke_counter_pci_probe(struct pci_dev *dev,
135 const struct pci_device_id *id)
137 return comedi_pci_auto_config(dev, &ke_counter_driver,
141 static DEFINE_PCI_DEVICE_TABLE(ke_counter_pci_table) = {
142 { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID) },
145 MODULE_DEVICE_TABLE(pci, ke_counter_pci_table);
147 static struct pci_driver ke_counter_pci_driver = {
148 .name = "ke_counter",
149 .id_table = ke_counter_pci_table,
150 .probe = ke_counter_pci_probe,
151 .remove = comedi_pci_auto_unconfig,
153 module_comedi_pci_driver(ke_counter_driver, ke_counter_pci_driver);
155 MODULE_AUTHOR("Comedi http://www.comedi.org");
156 MODULE_DESCRIPTION("Comedi low-level driver");
157 MODULE_LICENSE("GPL");