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

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                         b <<= 1;
188                         outw(status1 | b | 0x0000, dev->iobase + DAS16CS_MISC1);
189                         udelay(1);
190                         outw(status1 | b | 0x0004, dev->iobase + DAS16CS_MISC1);
191                         udelay(1);
192                 }
193                 /*
194                  * Make both DAC0CS and DAC1CS high to load
195                  * the new data and update analog the output
196                  */
197                 outw(status1 | 0x9, dev->iobase + DAS16CS_MISC1);
198         }
199 
200         return i;
201 }
202 
203 static int das16cs_ao_rinsn(struct comedi_device *dev,
204                             struct comedi_subdevice *s,
205                             struct comedi_insn *insn, unsigned int *data)
206 {
207         struct das16cs_private *devpriv = dev->private;
208         int i;
209         int chan = CR_CHAN(insn->chanspec);
210 
211         for (i = 0; i < insn->n; i++)
212                 data[i] = devpriv->ao_readback[chan];
213 
214         return i;
215 }
216 
217 static int das16cs_dio_insn_bits(struct comedi_device *dev,
218                                  struct comedi_subdevice *s,
219                                  struct comedi_insn *insn,
220                                  unsigned int *data)
221 {
222         if (comedi_dio_update_state(s, data))
223                 outw(s->state, dev->iobase + DAS16CS_DIO);
224 
225         data[1] = inw(dev->iobase + DAS16CS_DIO);
226 
227         return insn->n;
228 }
229 
230 static int das16cs_dio_insn_config(struct comedi_device *dev,
231                                    struct comedi_subdevice *s,
232                                    struct comedi_insn *insn,
233                                    unsigned int *data)
234 {
235         struct das16cs_private *devpriv = dev->private;
236         unsigned int chan = CR_CHAN(insn->chanspec);
237         unsigned int mask;
238         int ret;
239 
240         if (chan < 4)
241                 mask = 0x0f;
242         else
243                 mask = 0xf0;
244 
245         ret = comedi_dio_insn_config(dev, s, insn, data, mask);
246         if (ret)
247                 return ret;
248 
249         devpriv->status2 &= ~0x00c0;
250         devpriv->status2 |= (s->io_bits & 0xf0) ? 0x0080 : 0;
251         devpriv->status2 |= (s->io_bits & 0x0f) ? 0x0040 : 0;
252 
253         outw(devpriv->status2, dev->iobase + DAS16CS_MISC2);
254 
255         return insn->n;
256 }
257 
258 static const void *das16cs_find_boardinfo(struct comedi_device *dev,
259                                           struct pcmcia_device *link)
260 {
261         const struct das16cs_board *board;
262         int i;
263 
264         for (i = 0; i < ARRAY_SIZE(das16cs_boards); i++) {
265                 board = &das16cs_boards[i];
266                 if (board->device_id == link->card_id)
267                         return board;
268         }
269 
270         return NULL;
271 }
272 
273 static int das16cs_auto_attach(struct comedi_device *dev,
274                                unsigned long context)
275 {
276         struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
277         const struct das16cs_board *board;
278         struct das16cs_private *devpriv;
279         struct comedi_subdevice *s;
280         int ret;
281 
282         board = das16cs_find_boardinfo(dev, link);
283         if (!board)
284                 return -ENODEV;
285         dev->board_ptr = board;
286         dev->board_name = board->name;
287 
288         link->config_flags |= CONF_AUTO_SET_IO | CONF_ENABLE_IRQ;
289         ret = comedi_pcmcia_enable(dev, NULL);
290         if (ret)
291                 return ret;
292         dev->iobase = link->resource[0]->start;
293 
294         link->priv = dev;
295 
296         devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
297         if (!devpriv)
298                 return -ENOMEM;
299 
300         ret = comedi_alloc_subdevices(dev, 3);
301         if (ret)
302                 return ret;
303 
304         s = &dev->subdevices[0];
305         /* analog input subdevice */
306         s->type         = COMEDI_SUBD_AI;
307         s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF | SDF_CMD_READ;
308         s->n_chan       = 16;
309         s->maxdata      = 0xffff;
310         s->range_table  = &das16cs_ai_range;
311         s->len_chanlist = 16;
312         s->insn_read    = das16cs_ai_rinsn;
313 
314         s = &dev->subdevices[1];
315         /* analog output subdevice */
316         if (board->n_ao_chans) {
317                 s->type         = COMEDI_SUBD_AO;
318                 s->subdev_flags = SDF_WRITABLE;
319                 s->n_chan       = board->n_ao_chans;
320                 s->maxdata      = 0xffff;
321                 s->range_table  = &range_bipolar10;
322                 s->insn_write   = &das16cs_ao_winsn;
323                 s->insn_read    = &das16cs_ao_rinsn;
324         } else {
325                 s->type         = COMEDI_SUBD_UNUSED;
326         }
327 
328         s = &dev->subdevices[2];
329         /* digital i/o subdevice */
330         s->type         = COMEDI_SUBD_DIO;
331         s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
332         s->n_chan       = 8;
333         s->maxdata      = 1;
334         s->range_table  = &range_digital;
335         s->insn_bits    = das16cs_dio_insn_bits;
336         s->insn_config  = das16cs_dio_insn_config;
337 
338         return 0;
339 }
340 
341 static struct comedi_driver driver_das16cs = {
342         .driver_name    = "cb_das16_cs",
343         .module         = THIS_MODULE,
344         .auto_attach    = das16cs_auto_attach,
345         .detach         = comedi_pcmcia_disable,
346 };
347 
348 static int das16cs_pcmcia_attach(struct pcmcia_device *link)
349 {
350         return comedi_pcmcia_auto_config(link, &driver_das16cs);
351 }
352 
353 static const struct pcmcia_device_id das16cs_id_table[] = {
354         PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x0039),
355         PCMCIA_DEVICE_MANF_CARD(0x01c5, 0x4009),
356         PCMCIA_DEVICE_NULL
357 };
358 MODULE_DEVICE_TABLE(pcmcia, das16cs_id_table);
359 
360 static struct pcmcia_driver das16cs_driver = {
361         .name           = "cb_das16_cs",
362         .owner          = THIS_MODULE,
363         .id_table       = das16cs_id_table,
364         .probe          = das16cs_pcmcia_attach,
365         .remove         = comedi_pcmcia_auto_unconfig,
366 };
367 module_comedi_pcmcia_driver(driver_das16cs, das16cs_driver);
368 
369 MODULE_AUTHOR("David A. Schleef <ds@schleef.org>");
370 MODULE_DESCRIPTION("Comedi driver for Computer Boards PC-CARD DAS16/16");
371 MODULE_LICENSE("GPL");
372 

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