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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 Description: Driver for Kolter Electronic Counter Card
26 Devices: [Kolter Electronic] PCI Counter Card (ke_counter)
27 Author: Michael Hillmann
28 Updated: Mon, 14 Apr 2008 15:42:42 +0100
31 Configuration Options: not applicable, uses PCI auto config
33 This driver is a simple driver to read the counter values from
34 Kolter Electronic PCI Counter Card.
37 #include "../comedidev.h"
39 #define CNT_CARD_DEVICE_ID 0x0014
41 /*-- counter write ----------------------------------------------------------*/
43 /* This should be used only for resetting the counters; maybe it is better
44 to make a special command 'reset'. */
45 static int cnt_winsn(struct comedi_device *dev,
46 struct comedi_subdevice *s, struct comedi_insn *insn,
49 int chan = CR_CHAN(insn->chanspec);
51 outb((unsigned char)((data[0] >> 24) & 0xff),
52 dev->iobase + chan * 0x20 + 0x10);
53 outb((unsigned char)((data[0] >> 16) & 0xff),
54 dev->iobase + chan * 0x20 + 0x0c);
55 outb((unsigned char)((data[0] >> 8) & 0xff),
56 dev->iobase + chan * 0x20 + 0x08);
57 outb((unsigned char)((data[0] >> 0) & 0xff),
58 dev->iobase + chan * 0x20 + 0x04);
60 /* return the number of samples written */
64 /*-- counter read -----------------------------------------------------------*/
66 static int cnt_rinsn(struct comedi_device *dev,
67 struct comedi_subdevice *s, struct comedi_insn *insn,
70 unsigned char a0, a1, a2, a3, a4;
71 int chan = CR_CHAN(insn->chanspec);
74 a0 = inb(dev->iobase + chan * 0x20);
75 a1 = inb(dev->iobase + chan * 0x20 + 0x04);
76 a2 = inb(dev->iobase + chan * 0x20 + 0x08);
77 a3 = inb(dev->iobase + chan * 0x20 + 0x0c);
78 a4 = inb(dev->iobase + chan * 0x20 + 0x10);
80 result = (a1 + (a2 * 256) + (a3 * 65536));
82 result = result - s->maxdata;
84 *data = (unsigned int)result;
86 /* return the number of samples read */
90 static int cnt_auto_attach(struct comedi_device *dev,
91 unsigned long context_unused)
93 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
94 struct comedi_subdevice *s;
97 dev->board_name = dev->driver->driver_name;
99 ret = comedi_pci_enable(pcidev, dev->board_name);
102 dev->iobase = pci_resource_start(pcidev, 0);
104 ret = comedi_alloc_subdevices(dev, 1);
108 s = &dev->subdevices[0];
109 dev->read_subdev = s;
111 s->type = COMEDI_SUBD_COUNTER;
112 s->subdev_flags = SDF_READABLE /* | SDF_COMMON */ ;
114 s->maxdata = 0x00ffffff;
115 s->insn_read = cnt_rinsn;
116 s->insn_write = cnt_winsn;
118 /* select 20MHz clock */
119 outb(3, dev->iobase + 248);
121 /* reset all counters */
122 outb(0, dev->iobase);
123 outb(0, dev->iobase + 0x20);
124 outb(0, dev->iobase + 0x40);
126 dev_info(dev->class_dev, "%s: %s attached\n",
127 dev->driver->driver_name, dev->board_name);
132 static void cnt_detach(struct comedi_device *dev)
134 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
138 comedi_pci_disable(pcidev);
142 static struct comedi_driver ke_counter_driver = {
143 .driver_name = "ke_counter",
144 .module = THIS_MODULE,
145 .auto_attach = cnt_auto_attach,
146 .detach = cnt_detach,
149 static int ke_counter_pci_probe(struct pci_dev *dev,
150 const struct pci_device_id *ent)
152 return comedi_pci_auto_config(dev, &ke_counter_driver);
155 static void ke_counter_pci_remove(struct pci_dev *dev)
157 comedi_pci_auto_unconfig(dev);
160 static DEFINE_PCI_DEVICE_TABLE(ke_counter_pci_table) = {
161 { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID) },
164 MODULE_DEVICE_TABLE(pci, ke_counter_pci_table);
166 static struct pci_driver ke_counter_pci_driver = {
167 .name = "ke_counter",
168 .id_table = ke_counter_pci_table,
169 .probe = ke_counter_pci_probe,
170 .remove = ke_counter_pci_remove,
172 module_comedi_pci_driver(ke_counter_driver, ke_counter_pci_driver);
174 MODULE_AUTHOR("Comedi http://www.comedi.org");
175 MODULE_DESCRIPTION("Comedi low-level driver");
176 MODULE_LICENSE("GPL");