staging: comedi: remove FSF address from boilerplate text
[deliverable/linux.git] / drivers / staging / comedi / drivers / ke_counter.c
CommitLineData
2f82613d
MH
1/*
2 comedi/drivers/ke_counter.c
3 Comedi driver for Kolter-Electronic PCI Counter 1 Card
4
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7
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.
12
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.
2f82613d
MH
17*/
18/*
19Driver: ke_counter
20Description: Driver for Kolter Electronic Counter Card
21Devices: [Kolter Electronic] PCI Counter Card (ke_counter)
22Author: Michael Hillmann
23Updated: Mon, 14 Apr 2008 15:42:42 +0100
24Status: tested
25
5afbfa63 26Configuration Options: not applicable, uses PCI auto config
2f82613d
MH
27
28This driver is a simple driver to read the counter values from
29Kolter Electronic PCI Counter Card.
30*/
31
33782dd5
HS
32#include <linux/pci.h>
33
2f82613d
MH
34#include "../comedidev.h"
35
2f82613d
MH
36#define CNT_CARD_DEVICE_ID 0x0014
37
2f82613d
MH
38/*-- counter write ----------------------------------------------------------*/
39
40/* This should be used only for resetting the counters; maybe it is better
41 to make a special command 'reset'. */
da91b269 42static int cnt_winsn(struct comedi_device *dev,
0a85b6f0
MT
43 struct comedi_subdevice *s, struct comedi_insn *insn,
44 unsigned int *data)
2f82613d
MH
45{
46 int chan = CR_CHAN(insn->chanspec);
47
48 outb((unsigned char)((data[0] >> 24) & 0xff),
0a85b6f0 49 dev->iobase + chan * 0x20 + 0x10);
2f82613d 50 outb((unsigned char)((data[0] >> 16) & 0xff),
0a85b6f0 51 dev->iobase + chan * 0x20 + 0x0c);
2f82613d 52 outb((unsigned char)((data[0] >> 8) & 0xff),
0a85b6f0 53 dev->iobase + chan * 0x20 + 0x08);
2f82613d 54 outb((unsigned char)((data[0] >> 0) & 0xff),
0a85b6f0 55 dev->iobase + chan * 0x20 + 0x04);
2f82613d
MH
56
57 /* return the number of samples written */
58 return 1;
59}
60
61/*-- counter read -----------------------------------------------------------*/
62
da91b269 63static int cnt_rinsn(struct comedi_device *dev,
0a85b6f0
MT
64 struct comedi_subdevice *s, struct comedi_insn *insn,
65 unsigned int *data)
2f82613d
MH
66{
67 unsigned char a0, a1, a2, a3, a4;
68 int chan = CR_CHAN(insn->chanspec);
69 int result;
70
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);
76
77 result = (a1 + (a2 * 256) + (a3 * 65536));
78 if (a4 > 0)
79 result = result - s->maxdata;
80
0a85b6f0 81 *data = (unsigned int)result;
2f82613d
MH
82
83 /* return the number of samples read */
84 return 1;
85}
86
a690b7e5 87static int cnt_auto_attach(struct comedi_device *dev,
750af5e5 88 unsigned long context_unused)
bd8a9bc1 89{
750af5e5 90 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
30c4d3b8 91 struct comedi_subdevice *s;
5afbfa63 92 int ret;
bd8a9bc1 93
818f569f 94 ret = comedi_pci_enable(dev);
5afbfa63
HS
95 if (ret)
96 return ret;
97 dev->iobase = pci_resource_start(pcidev, 0);
2f82613d 98
5afbfa63
HS
99 ret = comedi_alloc_subdevices(dev, 1);
100 if (ret)
101 return ret;
2f82613d 102
bce27067 103 s = &dev->subdevices[0];
30c4d3b8 104 dev->read_subdev = s;
2f82613d 105
30c4d3b8
HS
106 s->type = COMEDI_SUBD_COUNTER;
107 s->subdev_flags = SDF_READABLE /* | SDF_COMMON */ ;
c9378767
HS
108 s->n_chan = 3;
109 s->maxdata = 0x00ffffff;
30c4d3b8
HS
110 s->insn_read = cnt_rinsn;
111 s->insn_write = cnt_winsn;
2f82613d 112
2696fb57 113 /* select 20MHz clock */
2f82613d
MH
114 outb(3, dev->iobase + 248);
115
2696fb57 116 /* reset all counters */
2f82613d
MH
117 outb(0, dev->iobase);
118 outb(0, dev->iobase + 0x20);
119 outb(0, dev->iobase + 0x40);
120
5afbfa63
HS
121 dev_info(dev->class_dev, "%s: %s attached\n",
122 dev->driver->driver_name, dev->board_name);
123
2f82613d
MH
124 return 0;
125}
126
75e6301b
HS
127static struct comedi_driver ke_counter_driver = {
128 .driver_name = "ke_counter",
236788fc 129 .module = THIS_MODULE,
750af5e5 130 .auto_attach = cnt_auto_attach,
7f072f54 131 .detach = comedi_pci_disable,
236788fc
HS
132};
133
a690b7e5 134static int ke_counter_pci_probe(struct pci_dev *dev,
b8f4ac23 135 const struct pci_device_id *id)
236788fc 136{
b8f4ac23
HS
137 return comedi_pci_auto_config(dev, &ke_counter_driver,
138 id->driver_data);
236788fc
HS
139}
140
75e6301b 141static DEFINE_PCI_DEVICE_TABLE(ke_counter_pci_table) = {
236788fc
HS
142 { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID) },
143 { 0 }
144};
75e6301b 145MODULE_DEVICE_TABLE(pci, ke_counter_pci_table);
236788fc 146
75e6301b
HS
147static struct pci_driver ke_counter_pci_driver = {
148 .name = "ke_counter",
149 .id_table = ke_counter_pci_table,
150 .probe = ke_counter_pci_probe,
9901a4d7 151 .remove = comedi_pci_auto_unconfig,
236788fc 152};
75e6301b 153module_comedi_pci_driver(ke_counter_driver, ke_counter_pci_driver);
236788fc 154
90f703d3
AT
155MODULE_AUTHOR("Comedi http://www.comedi.org");
156MODULE_DESCRIPTION("Comedi low-level driver");
157MODULE_LICENSE("GPL");
This page took 0.676813 seconds and 5 git commands to generate.