Version:  2.0.40 2.2.26 2.4.37 3.0 3.1 3.2 3.3 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

Linux/drivers/staging/comedi/drivers/cb_das16_cs.c

  1 /*
  2     comedi/drivers/das16cs.c
  3     Driver for Computer Boards PC-CARD DAS16/16.
  4 
  5     COMEDI - Linux Control and Measurement Device Interface
  6     Copyright (C) 2000, 2001, 2002 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     PCMCIA support code for this driver is adapted from the dummy_cs.c
 19     driver of the Linux PCMCIA Card Services package.
 20 
 21     The initial developer of the original code is David A. Hinds
 22     <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
 23     are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
 24 
 25 */
 26 /*
 27 Driver: cb_das16_cs
 28 Description: Computer Boards PC-CARD DAS16/16
 29 Devices: [ComputerBoards] PC-CARD DAS16/16 (cb_das16_cs), PC-CARD DAS16/16-AO
 30 Author: ds
 31 Updated: Mon, 04 Nov 2002 20:04:21 -0800
 32 Status: experimental
 33 
 34 
 35 */
 36 
 37 #include <linux/module.h>
 38 #include <linux/interrupt.h>
 39 #include <linux/delay.h>
 40 
 41 #include "../comedidev.h"
 42 
 43 #include <pcmcia/cistpl.h>
 44 #include <pcmcia/ds.h>
 45 
 46 #include "comedi_fc.h"
 47 #include "8253.h"
 48 
 49 #define DAS16CS_SIZE                    18
 50 
 51 #define DAS16CS_ADC_DATA                0
 52 #define DAS16CS_DIO_MUX                 2
 53 #define DAS16CS_MISC1                   4
 54 #define DAS16CS_MISC2                   6
 55 #define DAS16CS_CTR0                    8
 56 #define DAS16CS_CTR1                    10
 57 #define DAS16CS_CTR2                    12
 58 #define DAS16CS_CTR_CONTROL             14
 59 #define DAS16CS_DIO                     16
 60 
 61 struct das16cs_board {
 62         const char *name;
 63         int device_id;
 64         int n_ao_chans;
 65 };
 66 
 67 static const struct das16cs_board das16cs_boards[] = {
 68         {
 69                 .name           = "PC-CARD DAS16/16-AO",
 70                 .device_id      = 0x0039,
 71                 .n_ao_chans     = 2,
 72         }, {
 73                 .name           = "PCM-DAS16s/16",
 74                 .device_id      = 0x4009,
 75                 .n_ao_chans     = 0,
 76         }, {
 77                 .name           = "PC-CARD DAS16/16",
 78                 .device_id      = 0x0000,       /* unknown */
 79                 .n_ao_chans     = 0,
 80         },
 81 };
 82 
 83 struct das16cs_private {
 84         unsigned int ao_readback[2];
 85         unsigned short status1;
 86         unsigned short status2;
 87 };
 88 
 89 static const struct comedi_lrange das16cs_ai_range = {
 90         4, {
 91                 BIP_RANGE(10),
 92                 BIP_RANGE(5),
 93                 BIP_RANGE(2.5),
 94                 BIP_RANGE(1.25),
 95         }
 96 };
 97 
 98 static int das16cs_ai_eoc(struct comedi_device *dev,
 99                           struct comedi_subdevice *s,
100                           struct comedi_insn *insn,
101                           unsigned long context)
102 {
103         unsigned int status;
104 
105         status = inw(dev->iobase + DAS16CS_MISC1);
106         if (status & 0x0080)
107                 return 0;
108         return -EBUSY;
109 }
110 
111 static int das16cs_ai_rinsn(struct comedi_device *dev,
112                             struct comedi_subdevice *s,
113                             struct comedi_insn *insn, unsigned int *data)
114 {
115         struct das16cs_private *devpriv = dev->private;
116         int chan = CR_CHAN(insn->chanspec);
117         int range = CR_RANGE(insn->chanspec);
118         int aref = CR_AREF(insn->chanspec);
119         int ret;
120         int i;
121 
122         outw(chan, dev->iobase + DAS16CS_DIO_MUX);
123 
124         devpriv->status1 &= ~0xf320;
125         devpriv->status1 |= (aref == AREF_DIFF) ? 0 : 0x0020;
126         outw(devpriv->status1, dev->iobase + DAS16CS_MISC1);
127 
128         devpriv->status2 &= ~0xff00;
129         switch (range) {
130         case 0:
131                 devpriv->status2 |= 0x800;
132                 break;
133         case 1:
134                 devpriv->status2 |= 0x000;
135                 break;
136         case 2:
137                 devpriv->status2 |= 0x100;
138                 break;
139         case 3:
140                 devpriv->status2 |= 0x200;
141                 break;
142         }
143         outw(devpriv->status2, dev->iobase + DAS16CS_MISC2);
144 
145         for (i = 0; i < insn->n; i++) {
146                 outw(0, dev->iobase + DAS16CS_ADC_DATA);
147 
148                 ret = comedi_timeout(dev, s, insn, das16cs_ai_eoc, 0);
149                 if (ret)
150                         return ret;
151 
152                 data[i] = inw(dev->iobase + DAS16CS_ADC_DATA);
153         }
154 
155         return i;
156 }
157 
158 static int das16cs_ao_winsn(struct comedi_device *dev,
159                             struct comedi_subdevice *s,
160                             struct comedi_insn *insn, unsigned int *data)
161 {
162         struct das16cs_private *devpriv = dev->private;
163         int i;
164         int chan = CR_CHAN(insn->chanspec);
165         unsigned short status1;
166         unsigned short d;
167         int bit;
168 
169         for (i = 0; i < insn->n; i++) {
170                 devpriv->ao_readback[chan] = data[i];
171                 d = data[i];
172 
173                 outw(devpriv->status1, dev->iobase + DAS16CS_MISC1);
174                 udelay(1);
175 
176                 status1 = devpriv->status1 & ~0xf;
177                 if (chan)
178                         status1 |= 0x0001;
179                 else
180                         status1 |= 0x0008;
181 
182                 outw(status1, dev->iobase + DAS16CS_MISC1);
183                 udelay(1);
184 
185                 for (bit = 15; bit >= 0; bit--) {
186                         int b = (d >> bit) & 0x1;
187 
188                         b <<= 1;
189                         outw(status1 | b | 0x0000, dev->iobase + DAS16CS_MISC1);
190                         udelay(1);
191                         outw(status1 | b | 0x0004, dev->iobase + DAS16CS_MISC1);
192                         udelay(1);
193                 }
194                 /*
195                  * Make both DAC0CS and DAC1CS high to load
196                  * the new data and update analog the output
197                  */
198                 outw(status1 | 0x9, dev->iobase + DAS16CS_MISC1);
199         }
200 
201         return i;
202 }
203 
204 static int das16cs_ao_rinsn(struct comedi_device *dev,
205                             struct comedi_subdevice *s,
206                             struct comedi_insn *insn, unsigned int *data)
207 {
208         struct das16cs_private *devpriv = dev->private;
209         int i;
210         int chan = CR_CHAN(insn->chanspec);
211 
212         for (i = 0; i < insn->n; i++)
213                 data[i] = devpriv->ao_readback[chan];
214 
215         return i;
216 }
217 
218 static int das16cs_dio_insn_bits(struct comedi_device *dev,
219                                  struct comedi_subdevice *s,
220                                  struct comedi_insn *insn,
221                                  unsigned int *data)
222 {
223         if (comedi_dio_update_state(s, data))
224                 outw(s->state, dev->iobase + DAS16CS_DIO);
225 
226         data[1] = inw(dev->iobase + DAS16CS_DIO);
227 
228         return insn->n;
229 }
230 
231 static int das16cs_dio_insn_config(struct comedi_device *dev,
232                                    struct comedi_subdevice *s,
233                                    struct comedi_insn *insn,
234                                    unsigned int *data)
235 {
236         struct das16cs_private *devpriv = dev->private;
237         unsigned int chan = CR_CHAN(insn->chanspec);
238         unsigned int mask;
239         int ret;
240 
241         if (chan < 4)
242                 mask = 0x0f;
243         else
244                 mask = 0xf0;
245 
246         ret = comedi_dio_insn_config(dev, s, insn, data, mask);
247         if (ret)
248                 return ret;
249 
250         devpriv->status2 &= ~0x00c0;
251         devpriv->status2 |= (s->io_bits & 0xf0) ? 0x0080 : 0;
252         devpriv->status2 |= (s->io_bits & 0x0f) ? 0x0040 : 0;
253 
254         outw(devpriv->status2, dev->iobase + DAS16CS_MISC2);
255 
256         return insn->n;
257 }
258 
259 static const void *das16cs_find_boardinfo(struct comedi_device *dev,
260                                           struct pcmcia_device *link)
261 {
262         const struct das16cs_board *board;
263         int i;
264 
265         for (i = 0; i < ARRAY_SIZE(das16cs_boards); i++) {
266                 board = &das16cs_boards[i];
267                 if (board->device_id == link->card_id)
268                         return board;
269         }
270 
271         return NULL;
272 }
273 
274 static int das16cs_auto_attach(struct comedi_device *dev,
275                                unsigned long context)
276 {
277         struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
278         const struct das16cs_board *board;
279         struct das16cs_private *devpriv;
280         struct comedi_subdevice *s;
281         int ret;
282 
283         board = das16cs_find_boardinfo(dev, link);
284         if (!board)
285                 return -ENODEV;
286         dev->board_ptr = board;
287         dev->board_name = board->name;
288 
289         link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
290         ret = comedi_pcmcia_enable(dev, NULL);
291         if (ret)
292                 return ret;
293         dev->iobase = link->resource[0]->start;
294 
295         link->priv = dev;
296 
297         devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
298         if (!devpriv)
299                 return -ENOMEM;
300 
301         ret = comedi_alloc_subdevices(dev, 3);
302         if (ret)
303                 return ret;
304 
305         s = &dev->subdevices[0];
306         /* analog input subdevice */
307         s->type         = COMEDI_SUBD_AI;
308         s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ;
309         s->n_chan       = 16;
310         s->maxdata      = 0xffff;
311         s->range_table  = &das16cs_ai_range;
312         s->len_chanlist = 16;
313         s->insn_read    = das16cs_ai_rinsn;
314 
315         s = &dev->subdevices[1];
316         /* analog output subdevice */
317         if (board->n_ao_chans) {
318                 s->type         = COMEDI_SUBD_AO;
319                 s->subdev_flags = SDF_WRITABLE;
320                 s->n_chan       = board->n_ao_chans;
321                 s->maxdata      = 0xffff;
322                 s->range_table  = &range_bipolar10;
323                 s->insn_write   = &das16cs_ao_winsn;
324                 s->insn_read    = &das16cs_ao_rinsn;
325         } else {
326                 s->type         = COMEDI_SUBD_UNUSED;
327         }
328 
329         s = &dev->subdevices[2];
330         /* digital i/o subdevice */
331         s->type         = COMEDI_SUBD_DIO;
332         s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
333         s->n_chan       = 8;
334         s->maxdata      = 1;
335         s->range_table  = &range_digital;
336         s->insn_bits    = das16cs_dio_insn_bits;
337         s->insn_config  = das16cs_dio_insn_config;
338 
339         return 0;
340 }
341 
342 static struct comedi_driver driver_das16cs = {
343         .driver_name    = "cb_das16_cs",
344         .module         = THIS_MODULE,
345         .auto_attach    = das16cs_auto_attach,
346         .detach         = comedi_pcmcia_disable,
347 };
348 
349 static int das16cs_pcmcia_attach(struct pcmcia_device *link)
350 {
351         return comedi_pcmcia_auto_config(link, &driver_das16cs);
352 }
353 
354 static const struct pcmcia_device_id das16cs_id_table[] = {
355         PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x0039),
356         PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x4009),
357         PCMCIA_DEVICE_NULL
358 };
359 MODULE_DEVICE_TABLE(pcmcia, das16cs_id_table);
360 
361 static struct pcmcia_driver das16cs_driver = {
362         .name           = "cb_das16_cs",
363         .owner          = THIS_MODULE,
364         .id_table       = das16cs_id_table,
365         .probe          = das16cs_pcmcia_attach,
366         .remove         = comedi_pcmcia_auto_unconfig,
367 };
368 module_comedi_pcmcia_driver(driver_das16cs, das16cs_driver);
369 
370 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
371 MODULE_DESCRIPTION("Comedi driver for Computer Boards PC-CARD DAS16/16");
372 MODULE_LICENSE("GPL");
373 

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