staging: comedi: remove use of __devinit
[firefly-linux-kernel-4.4.55.git] / drivers / staging / comedi / drivers / ke_counter.c
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.
17
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.
21
22 */
23 /*
24 Driver: ke_counter
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
29 Status: tested
30
31 Configuration Options: not applicable, uses PCI auto config
32
33 This driver is a simple driver to read the counter values from
34 Kolter Electronic PCI Counter Card.
35 */
36
37 #include "../comedidev.h"
38
39 #define CNT_CARD_DEVICE_ID      0x0014
40
41 /*-- counter write ----------------------------------------------------------*/
42
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,
47                      unsigned int *data)
48 {
49         int chan = CR_CHAN(insn->chanspec);
50
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);
59
60         /* return the number of samples written */
61         return 1;
62 }
63
64 /*-- counter read -----------------------------------------------------------*/
65
66 static int cnt_rinsn(struct comedi_device *dev,
67                      struct comedi_subdevice *s, struct comedi_insn *insn,
68                      unsigned int *data)
69 {
70         unsigned char a0, a1, a2, a3, a4;
71         int chan = CR_CHAN(insn->chanspec);
72         int result;
73
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);
79
80         result = (a1 + (a2 * 256) + (a3 * 65536));
81         if (a4 > 0)
82                 result = result - s->maxdata;
83
84         *data = (unsigned int)result;
85
86         /* return the number of samples read */
87         return 1;
88 }
89
90 static int cnt_auto_attach(struct comedi_device *dev,
91                                      unsigned long context_unused)
92 {
93         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
94         struct comedi_subdevice *s;
95         int ret;
96
97         dev->board_name = dev->driver->driver_name;
98
99         ret = comedi_pci_enable(pcidev, dev->board_name);
100         if (ret)
101                 return ret;
102         dev->iobase = pci_resource_start(pcidev, 0);
103
104         ret = comedi_alloc_subdevices(dev, 1);
105         if (ret)
106                 return ret;
107
108         s = &dev->subdevices[0];
109         dev->read_subdev = s;
110
111         s->type = COMEDI_SUBD_COUNTER;
112         s->subdev_flags = SDF_READABLE /* | SDF_COMMON */ ;
113         s->n_chan = 3;
114         s->maxdata = 0x00ffffff;
115         s->insn_read = cnt_rinsn;
116         s->insn_write = cnt_winsn;
117
118         /*  select 20MHz clock */
119         outb(3, dev->iobase + 248);
120
121         /*  reset all counters */
122         outb(0, dev->iobase);
123         outb(0, dev->iobase + 0x20);
124         outb(0, dev->iobase + 0x40);
125
126         dev_info(dev->class_dev, "%s: %s attached\n",
127                 dev->driver->driver_name, dev->board_name);
128
129         return 0;
130 }
131
132 static void cnt_detach(struct comedi_device *dev)
133 {
134         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
135
136         if (pcidev) {
137                 if (dev->iobase)
138                         comedi_pci_disable(pcidev);
139         }
140 }
141
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,
147 };
148
149 static int ke_counter_pci_probe(struct pci_dev *dev,
150                                           const struct pci_device_id *ent)
151 {
152         return comedi_pci_auto_config(dev, &ke_counter_driver);
153 }
154
155 static void __devexit ke_counter_pci_remove(struct pci_dev *dev)
156 {
157         comedi_pci_auto_unconfig(dev);
158 }
159
160 static DEFINE_PCI_DEVICE_TABLE(ke_counter_pci_table) = {
161         { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, CNT_CARD_DEVICE_ID) },
162         { 0 }
163 };
164 MODULE_DEVICE_TABLE(pci, ke_counter_pci_table);
165
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,
171 };
172 module_comedi_pci_driver(ke_counter_driver, ke_counter_pci_driver);
173
174 MODULE_AUTHOR("Comedi http://www.comedi.org");
175 MODULE_DESCRIPTION("Comedi low-level driver");
176 MODULE_LICENSE("GPL");