Version:  2.0.40 2.2.26 2.4.37 3.4 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

Linux/drivers/staging/comedi/drivers/adv_pci1723.c

  1 /*
  2  * adv_pci1723.c
  3  * Comedi driver for the Advantech PCI-1723 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: adv_pci1723
 21  * Description: Advantech PCI-1723
 22  * Author: yonggang <rsmgnu@gmail.com>, Ian Abbott <abbotti@mev.co.uk>
 23  * Devices: [Advantech] PCI-1723 (adv_pci1723)
 24  * Updated: Mon, 14 Apr 2008 15:12:56 +0100
 25  * Status: works
 26  *
 27  * Configuration Options: not applicable, uses comedi PCI auto config
 28  *
 29  * Subdevice 0 is 8-channel AO, 16-bit, range +/- 10 V.
 30  *
 31  * Subdevice 1 is 16-channel DIO.  The channels are configurable as
 32  * input or output in 2 groups (0 to 7, 8 to 15). Configuring any
 33  * channel implicitly configures all channels in the same group.
 34  *
 35  * TODO:
 36  * 1. Add the two milliamp ranges to the AO subdevice (0 to 20 mA,
 37  *    4 to 20 mA).
 38  * 2. Read the initial ranges and values of the AO subdevice at
 39  *    start-up instead of reinitializing them.
 40  * 3. Implement calibration.
 41  */
 42 
 43 #include <linux/module.h>
 44 #include <linux/pci.h>
 45 
 46 #include "../comedidev.h"
 47 
 48 /*
 49  * PCI Bar 2 I/O Register map (dev->iobase)
 50  */
 51 #define PCI1723_AO_REG(x)               (0x00 + ((x) * 2))
 52 #define PCI1723_BOARD_ID_REG            0x10
 53 #define PCI1723_BOARD_ID_MASK           (0xf << 0)
 54 #define PCI1723_SYNC_CTRL_REG           0x12
 55 #define PCI1723_SYNC_CTRL_ASYNC         (0 << 0)
 56 #define PCI1723_SYNC_CTRL_SYNC          (1 << 0)
 57 #define PCI1723_CTRL_REG                0x14
 58 #define PCI1723_CTRL_BUSY               (1 << 15)
 59 #define PCI1723_CTRL_INIT               (1 << 14)
 60 #define PCI1723_CTRL_SELF               (1 << 8)
 61 #define PCI1723_CTRL_IDX(x)             (((x) & 0x3) << 6)
 62 #define PCI1723_CTRL_RANGE(x)           (((x) & 0x3) << 4)
 63 #define PCI1723_CTRL_GAIN               (0 << 3)
 64 #define PCI1723_CTRL_OFFSET             (1 << 3)
 65 #define PCI1723_CTRL_CHAN(x)            (((x) & 0x7) << 0)
 66 #define PCI1723_CALIB_CTRL_REG          0x16
 67 #define PCI1723_CALIB_CTRL_CS           (1 << 2)
 68 #define PCI1723_CALIB_CTRL_DAT          (1 << 1)
 69 #define PCI1723_CALIB_CTRL_CLK          (1 << 0)
 70 #define PCI1723_CALIB_STROBE_REG        0x18
 71 #define PCI1723_DIO_CTRL_REG            0x1a
 72 #define PCI1723_DIO_CTRL_HDIO           (1 << 1)
 73 #define PCI1723_DIO_CTRL_LDIO           (1 << 0)
 74 #define PCI1723_DIO_DATA_REG            0x1c
 75 #define PCI1723_CALIB_DATA_REG          0x1e
 76 #define PCI1723_SYNC_STROBE_REG         0x20
 77 #define PCI1723_RESET_AO_STROBE_REG     0x22
 78 #define PCI1723_RESET_CALIB_STROBE_REG  0x24
 79 #define PCI1723_RANGE_STROBE_REG        0x26
 80 #define PCI1723_VREF_REG                0x28
 81 #define PCI1723_VREF_NEG10V             (0 << 0)
 82 #define PCI1723_VREF_0V                 (1 << 0)
 83 #define PCI1723_VREF_POS10V             (3 << 0)
 84 
 85 static int pci1723_ao_insn_write(struct comedi_device *dev,
 86                                  struct comedi_subdevice *s,
 87                                  struct comedi_insn *insn,
 88                                  unsigned int *data)
 89 {
 90         unsigned int chan = CR_CHAN(insn->chanspec);
 91         int i;
 92 
 93         for (i = 0; i < insn->n; i++) {
 94                 unsigned int val = data[i];
 95 
 96                 outw(val, dev->iobase + PCI1723_AO_REG(chan));
 97                 s->readback[chan] = val;
 98         }
 99 
100         return insn->n;
101 }
102 
103 static int pci1723_dio_insn_config(struct comedi_device *dev,
104                                    struct comedi_subdevice *s,
105                                    struct comedi_insn *insn,
106                                    unsigned int *data)
107 {
108         unsigned int chan = CR_CHAN(insn->chanspec);
109         unsigned int mask = (chan < 8) ? 0x00ff : 0xff00;
110         unsigned short mode = 0x0000;           /* assume output */
111         int ret;
112 
113         ret = comedi_dio_insn_config(dev, s, insn, data, mask);
114         if (ret)
115                 return ret;
116 
117         if (!(s->io_bits & 0x00ff))
118                 mode |= PCI1723_DIO_CTRL_LDIO;  /* low byte input */
119         if (!(s->io_bits & 0xff00))
120                 mode |= PCI1723_DIO_CTRL_HDIO;  /* high byte input */
121         outw(mode, dev->iobase + PCI1723_DIO_CTRL_REG);
122 
123         return insn->n;
124 }
125 
126 static int pci1723_dio_insn_bits(struct comedi_device *dev,
127                                  struct comedi_subdevice *s,
128                                  struct comedi_insn *insn,
129                                  unsigned int *data)
130 {
131         if (comedi_dio_update_state(s, data))
132                 outw(s->state, dev->iobase + PCI1723_DIO_DATA_REG);
133 
134         data[1] = inw(dev->iobase + PCI1723_DIO_DATA_REG);
135 
136         return insn->n;
137 }
138 
139 static int pci1723_auto_attach(struct comedi_device *dev,
140                                unsigned long context_unused)
141 {
142         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
143         struct comedi_subdevice *s;
144         unsigned int val;
145         int ret;
146         int i;
147 
148         ret = comedi_pci_enable(dev);
149         if (ret)
150                 return ret;
151         dev->iobase = pci_resource_start(pcidev, 2);
152 
153         ret = comedi_alloc_subdevices(dev, 2);
154         if (ret)
155                 return ret;
156 
157         s = &dev->subdevices[0];
158         s->type         = COMEDI_SUBD_AO;
159         s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
160         s->n_chan       = 8;
161         s->maxdata      = 0xffff;
162         s->range_table  = &range_bipolar10;
163         s->insn_write   = pci1723_ao_insn_write;
164 
165         ret = comedi_alloc_subdev_readback(s);
166         if (ret)
167                 return ret;
168 
169         /* synchronously reset all analog outputs to 0V, +/-10V range */
170         outw(PCI1723_SYNC_CTRL_SYNC, dev->iobase + PCI1723_SYNC_CTRL_REG);
171         for (i = 0; i < s->n_chan; i++) {
172                 outw(PCI1723_CTRL_RANGE(0) | PCI1723_CTRL_CHAN(i),
173                      PCI1723_CTRL_REG);
174                 outw(0, dev->iobase + PCI1723_RANGE_STROBE_REG);
175 
176                 outw(0x8000, dev->iobase + PCI1723_AO_REG(i));
177                 s->readback[i] = 0x8000;
178         }
179         outw(0, dev->iobase + PCI1723_SYNC_STROBE_REG);
180 
181         /* disable syncronous control */
182         outw(PCI1723_SYNC_CTRL_ASYNC, dev->iobase + PCI1723_SYNC_CTRL_REG);
183 
184         s = &dev->subdevices[1];
185         s->type         = COMEDI_SUBD_DIO;
186         s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
187         s->n_chan       = 16;
188         s->maxdata      = 1;
189         s->range_table  = &range_digital;
190         s->insn_config  = pci1723_dio_insn_config;
191         s->insn_bits    = pci1723_dio_insn_bits;
192 
193         /* get initial DIO direction and state */
194         val = inw(dev->iobase + PCI1723_DIO_CTRL_REG);
195         if (!(val & PCI1723_DIO_CTRL_LDIO))
196                 s->io_bits |= 0x00ff;   /* low byte output */
197         if (!(val & PCI1723_DIO_CTRL_HDIO))
198                 s->io_bits |= 0xff00;   /* high byte output */
199         s->state = inw(dev->iobase + PCI1723_DIO_DATA_REG);
200 
201         return 0;
202 }
203 
204 static struct comedi_driver adv_pci1723_driver = {
205         .driver_name    = "adv_pci1723",
206         .module         = THIS_MODULE,
207         .auto_attach    = pci1723_auto_attach,
208         .detach         = comedi_pci_detach,
209 };
210 
211 static int adv_pci1723_pci_probe(struct pci_dev *dev,
212                                  const struct pci_device_id *id)
213 {
214         return comedi_pci_auto_config(dev, &adv_pci1723_driver,
215                                       id->driver_data);
216 }
217 
218 static const struct pci_device_id adv_pci1723_pci_table[] = {
219         { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1723) },
220         { 0 }
221 };
222 MODULE_DEVICE_TABLE(pci, adv_pci1723_pci_table);
223 
224 static struct pci_driver adv_pci1723_pci_driver = {
225         .name           = "adv_pci1723",
226         .id_table       = adv_pci1723_pci_table,
227         .probe          = adv_pci1723_pci_probe,
228         .remove         = comedi_pci_auto_unconfig,
229 };
230 module_comedi_pci_driver(adv_pci1723_driver, adv_pci1723_pci_driver);
231 
232 MODULE_AUTHOR("Comedi http://www.comedi.org");
233 MODULE_DESCRIPTION("Advantech PCI-1723 Comedi driver");
234 MODULE_LICENSE("GPL");
235 

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