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/adl_pci6208.c

  1 /*
  2  * adl_pci6208.c
  3  * Comedi driver for ADLink 6208 series cards
  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: adl_pci6208
 21  * Description: ADLink PCI-6208/6216 Series Multi-channel Analog Output Cards
 22  * Devices: [ADLink] PCI-6208 (adl_pci6208), PCI-6216 (adl_pci6216)
 23  * Author: nsyeow <nsyeow@pd.jaring.my>
 24  * Updated: Fri, 30 Jan 2004 14:44:27 +0800
 25  * Status: untested
 26  *
 27  * Configuration Options: not applicable, uses PCI auto config
 28  */
 29 
 30 #include <linux/module.h>
 31 #include <linux/delay.h>
 32 #include <linux/pci.h>
 33 
 34 #include "../comedidev.h"
 35 
 36 /*
 37  * PCI-6208/6216-GL register map
 38  */
 39 #define PCI6208_AO_CONTROL(x)           (0x00 + (2 * (x)))
 40 #define PCI6208_AO_STATUS               0x00
 41 #define PCI6208_AO_STATUS_DATA_SEND     (1 << 0)
 42 #define PCI6208_DIO                     0x40
 43 #define PCI6208_DIO_DO_MASK             (0x0f)
 44 #define PCI6208_DIO_DO_SHIFT            (0)
 45 #define PCI6208_DIO_DI_MASK             (0xf0)
 46 #define PCI6208_DIO_DI_SHIFT            (4)
 47 
 48 enum pci6208_boardid {
 49         BOARD_PCI6208,
 50         BOARD_PCI6216,
 51 };
 52 
 53 struct pci6208_board {
 54         const char *name;
 55         int ao_chans;
 56 };
 57 
 58 static const struct pci6208_board pci6208_boards[] = {
 59         [BOARD_PCI6208] = {
 60                 .name           = "adl_pci6208",
 61                 .ao_chans       = 8,
 62         },
 63         [BOARD_PCI6216] = {
 64                 .name           = "adl_pci6216",
 65                 .ao_chans       = 16,
 66         },
 67 };
 68 
 69 static int pci6208_ao_eoc(struct comedi_device *dev,
 70                           struct comedi_subdevice *s,
 71                           struct comedi_insn *insn,
 72                           unsigned long context)
 73 {
 74         unsigned int status;
 75 
 76         status = inw(dev->iobase + PCI6208_AO_STATUS);
 77         if ((status & PCI6208_AO_STATUS_DATA_SEND) == 0)
 78                 return 0;
 79         return -EBUSY;
 80 }
 81 
 82 static int pci6208_ao_insn_write(struct comedi_device *dev,
 83                                  struct comedi_subdevice *s,
 84                                  struct comedi_insn *insn,
 85                                  unsigned int *data)
 86 {
 87         unsigned int chan = CR_CHAN(insn->chanspec);
 88         unsigned int val = s->readback[chan];
 89         int ret;
 90         int i;
 91 
 92         for (i = 0; i < insn->n; i++) {
 93                 val = data[i];
 94 
 95                 /* D/A transfer rate is 2.2us */
 96                 ret = comedi_timeout(dev, s, insn, pci6208_ao_eoc, 0);
 97                 if (ret)
 98                         return ret;
 99 
100                 /* the hardware expects two's complement values */
101                 outw(comedi_offset_munge(s, val),
102                      dev->iobase + PCI6208_AO_CONTROL(chan));
103 
104                 s->readback[chan] = val;
105         }
106 
107         return insn->n;
108 }
109 
110 static int pci6208_di_insn_bits(struct comedi_device *dev,
111                                 struct comedi_subdevice *s,
112                                 struct comedi_insn *insn,
113                                 unsigned int *data)
114 {
115         unsigned int val;
116 
117         val = inw(dev->iobase + PCI6208_DIO);
118         val = (val & PCI6208_DIO_DI_MASK) >> PCI6208_DIO_DI_SHIFT;
119 
120         data[1] = val;
121 
122         return insn->n;
123 }
124 
125 static int pci6208_do_insn_bits(struct comedi_device *dev,
126                                 struct comedi_subdevice *s,
127                                 struct comedi_insn *insn,
128                                 unsigned int *data)
129 {
130         if (comedi_dio_update_state(s, data))
131                 outw(s->state, dev->iobase + PCI6208_DIO);
132 
133         data[1] = s->state;
134 
135         return insn->n;
136 }
137 
138 static int pci6208_auto_attach(struct comedi_device *dev,
139                                unsigned long context)
140 {
141         struct pci_dev *pcidev = comedi_to_pci_dev(dev);
142         const struct pci6208_board *boardinfo = NULL;
143         struct comedi_subdevice *s;
144         unsigned int val;
145         int ret;
146 
147         if (context < ARRAY_SIZE(pci6208_boards))
148                 boardinfo = &pci6208_boards[context];
149         if (!boardinfo)
150                 return -ENODEV;
151         dev->board_ptr = boardinfo;
152         dev->board_name = boardinfo->name;
153 
154         ret = comedi_pci_enable(dev);
155         if (ret)
156                 return ret;
157         dev->iobase = pci_resource_start(pcidev, 2);
158 
159         ret = comedi_alloc_subdevices(dev, 3);
160         if (ret)
161                 return ret;
162 
163         s = &dev->subdevices[0];
164         /* analog output subdevice */
165         s->type         = COMEDI_SUBD_AO;
166         s->subdev_flags = SDF_WRITABLE;
167         s->n_chan       = boardinfo->ao_chans;
168         s->maxdata      = 0xffff;
169         s->range_table  = &range_bipolar10;
170         s->insn_write   = pci6208_ao_insn_write;
171 
172         ret = comedi_alloc_subdev_readback(s);
173         if (ret)
174                 return ret;
175 
176         s = &dev->subdevices[1];
177         /* digital input subdevice */
178         s->type         = COMEDI_SUBD_DI;
179         s->subdev_flags = SDF_READABLE;
180         s->n_chan       = 4;
181         s->maxdata      = 1;
182         s->range_table  = &range_digital;
183         s->insn_bits    = pci6208_di_insn_bits;
184 
185         s = &dev->subdevices[2];
186         /* digital output subdevice */
187         s->type         = COMEDI_SUBD_DO;
188         s->subdev_flags = SDF_WRITABLE;
189         s->n_chan       = 4;
190         s->maxdata      = 1;
191         s->range_table  = &range_digital;
192         s->insn_bits    = pci6208_do_insn_bits;
193 
194         /*
195          * Get the read back signals from the digital outputs
196          * and save it as the initial state for the subdevice.
197          */
198         val = inw(dev->iobase + PCI6208_DIO);
199         val = (val & PCI6208_DIO_DO_MASK) >> PCI6208_DIO_DO_SHIFT;
200         s->state        = val;
201 
202         return 0;
203 }
204 
205 static struct comedi_driver adl_pci6208_driver = {
206         .driver_name    = "adl_pci6208",
207         .module         = THIS_MODULE,
208         .auto_attach    = pci6208_auto_attach,
209         .detach         = comedi_pci_detach,
210 };
211 
212 static int adl_pci6208_pci_probe(struct pci_dev *dev,
213                                  const struct pci_device_id *id)
214 {
215         return comedi_pci_auto_config(dev, &adl_pci6208_driver,
216                                       id->driver_data);
217 }
218 
219 static const struct pci_device_id adl_pci6208_pci_table[] = {
220         { PCI_VDEVICE(ADLINK, 0x6208), BOARD_PCI6208 },
221         { PCI_VDEVICE(ADLINK, 0x6216), BOARD_PCI6216 },
222         { 0 }
223 };
224 MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
225 
226 static struct pci_driver adl_pci6208_pci_driver = {
227         .name           = "adl_pci6208",
228         .id_table       = adl_pci6208_pci_table,
229         .probe          = adl_pci6208_pci_probe,
230         .remove         = comedi_pci_auto_unconfig,
231 };
232 module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
233 
234 MODULE_AUTHOR("Comedi http://www.comedi.org");
235 MODULE_DESCRIPTION("Comedi driver for ADLink 6208 series cards");
236 MODULE_LICENSE("GPL");
237 

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