Version:  2.0.40 2.2.26 2.4.37 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1

Linux/drivers/staging/comedi/drivers/ke_counter.c

  1 /*
  2  * 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 
 19 /*
 20  * Driver: ke_counter
 21  * Description: Driver for Kolter Electronic Counter Card
 22  * Devices: [Kolter Electronic] PCI Counter Card (ke_counter)
 23  * Author: Michael Hillmann
 24  * Updated: Mon, 14 Apr 2008 15:42:42 +0100
 25  * Status: tested
 26  *
 27  * Configuration Options: not applicable, uses PCI auto config
 28  */
 29 
 30 #include <linux/module.h>
 31 
 32 #include "../comedi_pci.h"
 33 
 34 /*
 35  * PCI BAR 0 Register I/O map
 36  */
 37 #define KE_RESET_REG(x)                 (0x00 + ((x) * 0x20))
 38 #define KE_LATCH_REG(x)                 (0x00 + ((x) * 0x20))
 39 #define KE_LSB_REG(x)                   (0x04 + ((x) * 0x20))
 40 #define KE_MID_REG(x)                   (0x08 + ((x) * 0x20))
 41 #define KE_MSB_REG(x)                   (0x0c + ((x) * 0x20))
 42 #define KE_SIGN_REG(x)                  (0x10 + ((x) * 0x20))
 43 #define KE_OSC_SEL_REG                  0xf8
 44 #define KE_OSC_SEL_EXT                  (1 << 0)
 45 #define KE_OSC_SEL_4MHZ                 (2 << 0)
 46 #define KE_OSC_SEL_20MHZ                (3 << 0)
 47 #define KE_DO_REG                       0xfc
 48 
 49 static int ke_counter_insn_write(struct comedi_device *dev,
 50                                  struct comedi_subdevice *s,
 51                                  struct comedi_insn *insn,
 52                                  unsigned int *data)
 53 {
 54         unsigned int chan = CR_CHAN(insn->chanspec);
 55         unsigned int val;
 56         int i;
 57 
 58         for (i = 0; i < insn->n; i++) {
 59                 val = data[0];
 60 
 61                 /* Order matters */
 62                 outb((val >> 24) & 0xff, dev->iobase + KE_SIGN_REG(chan));
 63                 outb((val >> 16) & 0xff, dev->iobase + KE_MSB_REG(chan));
 64                 outb((val >> 8) & 0xff, dev->iobase + KE_MID_REG(chan));
 65                 outb((val >> 0) & 0xff, dev->iobase + KE_LSB_REG(chan));
 66         }
 67 
 68         return insn->n;
 69 }
 70 
 71 static int ke_counter_insn_read(struct comedi_device *dev,
 72                                 struct comedi_subdevice *s,
 73                                 struct comedi_insn *insn,
 74                                 unsigned int *data)
 75 {
 76         unsigned int chan = CR_CHAN(insn->chanspec);
 77         unsigned int val;
 78         int i;
 79 
 80         for (i = 0; i < insn->n; i++) {
 81                 /* Order matters */
 82                 inb(dev->iobase + KE_LATCH_REG(chan));
 83 
 84                 val = inb(dev->iobase + KE_LSB_REG(chan));
 85                 val |= (inb(dev->iobase + KE_MID_REG(chan)) << 8);
 86                 val |= (inb(dev->iobase + KE_MSB_REG(chan)) << 16);
 87                 val |= (inb(dev->iobase + KE_SIGN_REG(chan)) << 24);
 88 
 89                 data[i] = val;
 90         }
 91 
 92         return insn->n;
 93 }
 94 
 95 static void ke_counter_reset(struct comedi_device *dev)
 96 {
 97         unsigned int chan;
 98 
 99         for (chan = 0; chan < 3; chan++)
100                 outb(0, dev->iobase + KE_RESET_REG(chan));
101 }
102 
103 static int ke_counter_insn_config(struct comedi_device *dev,
104                                   struct comedi_subdevice *s,
105                                   struct comedi_insn *insn,
106                                   unsigned int *data)
107 {
108         unsigned char src;
109 
110         switch (data[0]) {
111         case INSN_CONFIG_SET_CLOCK_SRC:
112                 switch (data[1]) {
113                 case KE_CLK_20MHZ:      /* default */
114                         src = KE_OSC_SEL_20MHZ;
115                         break;
116                 case KE_CLK_4MHZ:       /* option */
117                         src = KE_OSC_SEL_4MHZ;
118                         break;
119                 case KE_CLK_EXT:        /* Pin 21 on D-sub */
120                         src = KE_OSC_SEL_EXT;
121                         break;
122                 default:
123                         return -EINVAL;
124                 }
125                 outb(src, dev->iobase + KE_OSC_SEL_REG);
126                 break;
127         case INSN_CONFIG_GET_CLOCK_SRC:
128                 src = inb(dev->iobase + KE_OSC_SEL_REG);
129                 switch (src) {
130                 case KE_OSC_SEL_20MHZ:
131                         data[1] = KE_CLK_20MHZ;
132                         data[2] = 50;   /* 50ns */
133                         break;
134                 case KE_OSC_SEL_4MHZ:
135                         data[1] = KE_CLK_4MHZ;
136                         data[2] = 250;  /* 250ns */
137                         break;
138                 case KE_OSC_SEL_EXT:
139                         data[1] = KE_CLK_EXT;
140                         data[2] = 0;    /* Unknown */
141                         break;
142                 default:
143                         return -EINVAL;
144                 }
145                 break;
146         case INSN_CONFIG_RESET:
147                 ke_counter_reset(dev);
148                 break;
149         default:
150                 return -EINVAL;
151         }
152 
153         return insn->n;
154 }
155 
156 static int ke_counter_do_insn_bits(struct comedi_device *dev,
157                                    struct comedi_subdevice *s,
158                                    struct comedi_insn *insn,
159                                    unsigned int *data)
160 {
161         if (comedi_dio_update_state(s, data))
162                 outb(s->state, dev->iobase + KE_DO_REG);
163 
164         data[1] = s->state;
165 
166         return insn->n;
167 }
168 
169 static int ke_counter_auto_attach(struct comedi_device *dev,
170                                   unsigned long context_unused)
171 {
172         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
173         struct comedi_subdevice *s;
174         int ret;
175 
176         ret = comedi_pci_enable(dev);
177         if (ret)
178                 return ret;
179         dev->iobase = pci_resource_start(pcidev, 0);
180 
181         ret = comedi_alloc_subdevices(dev, 2);
182         if (ret)
183                 return ret;
184 
185         s = &dev->subdevices[0];
186         s->type         = COMEDI_SUBD_COUNTER;
187         s->subdev_flags = SDF_READABLE;
188         s->n_chan       = 3;
189         s->maxdata      = 0x01ffffff;
190         s->range_table  = &range_unknown;
191         s->insn_read    = ke_counter_insn_read;
192         s->insn_write   = ke_counter_insn_write;
193         s->insn_config  = ke_counter_insn_config;
194 
195         s = &dev->subdevices[1];
196         s->type         = COMEDI_SUBD_DO;
197         s->subdev_flags = SDF_WRITABLE;
198         s->n_chan       = 3;
199         s->maxdata      = 1;
200         s->range_table  = &range_digital;
201         s->insn_bits    = ke_counter_do_insn_bits;
202 
203         outb(KE_OSC_SEL_20MHZ, dev->iobase + KE_OSC_SEL_REG);
204 
205         ke_counter_reset(dev);
206 
207         return 0;
208 }
209 
210 static struct comedi_driver ke_counter_driver = {
211         .driver_name    = "ke_counter",
212         .module         = THIS_MODULE,
213         .auto_attach    = ke_counter_auto_attach,
214         .detach         = comedi_pci_detach,
215 };
216 
217 static int ke_counter_pci_probe(struct pci_dev *dev,
218                                 const struct pci_device_id *id)
219 {
220         return comedi_pci_auto_config(dev, &ke_counter_driver,
221                                       id->driver_data);
222 }
223 
224 static const struct pci_device_id ke_counter_pci_table[] = {
225         { PCI_DEVICE(PCI_VENDOR_ID_KOLTER, 0x0014) },
226         { 0 }
227 };
228 MODULE_DEVICE_TABLE(pci, ke_counter_pci_table);
229 
230 static struct pci_driver ke_counter_pci_driver = {
231         .name           = "ke_counter",
232         .id_table       = ke_counter_pci_table,
233         .probe          = ke_counter_pci_probe,
234         .remove         = comedi_pci_auto_unconfig,
235 };
236 module_comedi_pci_driver(ke_counter_driver, ke_counter_pci_driver);
237 
238 MODULE_AUTHOR("Comedi http://www.comedi.org");
239 MODULE_DESCRIPTION("Comedi driver for Kolter Electronic Counter Card");
240 MODULE_LICENSE("GPL");
241 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us