]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/das16.c
staging: comedi: das16: remove reg_dump()
[karo-tx-linux.git] / drivers / staging / comedi / drivers / das16.c
1 /*
2     comedi/drivers/das16.c
3     DAS16 driver
4
5     COMEDI - Linux Control and Measurement Device Interface
6     Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7     Copyright (C) 2000 Chris R. Baugher <baugher@enteract.com>
8     Copyright (C) 2001,2002 Frank Mori Hess <fmhess@users.sourceforge.net>
9
10     This program is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19 */
20 /*
21 Driver: das16
22 Description: DAS16 compatible boards
23 Author: Sam Moore, Warren Jasper, ds, Chris Baugher, Frank Hess, Roman Fietze
24 Devices: [Keithley Metrabyte] DAS-16 (das-16), DAS-16G (das-16g),
25   DAS-16F (das-16f), DAS-1201 (das-1201), DAS-1202 (das-1202),
26   DAS-1401 (das-1401), DAS-1402 (das-1402), DAS-1601 (das-1601),
27   DAS-1602 (das-1602),
28   [ComputerBoards] PC104-DAS16/JR (pc104-das16jr),
29   PC104-DAS16JR/16 (pc104-das16jr/16),
30   CIO-DAS16JR/16 (cio-das16jr/16),
31   CIO-DAS16/JR (cio-das16/jr), CIO-DAS1401/12 (cio-das1401/12),
32   CIO-DAS1402/12 (cio-das1402/12), CIO-DAS1402/16 (cio-das1402/16),
33   CIO-DAS1601/12 (cio-das1601/12), CIO-DAS1602/12 (cio-das1602/12),
34   CIO-DAS1602/16 (cio-das1602/16), CIO-DAS16/330 (cio-das16/330)
35 Status: works
36 Updated: 2003-10-12
37
38 A rewrite of the das16 and das1600 drivers.
39 Options:
40         [0] - base io address
41         [1] - irq (does nothing, irq is not used anymore)
42         [2] - dma (optional, required for comedi_command support)
43         [3] - master clock speed in MHz (optional, 1 or 10, ignored if
44                 board can probe clock, defaults to 1)
45         [4] - analog input range lowest voltage in microvolts (optional,
46                 only useful if your board does not have software
47                 programmable gain)
48         [5] - analog input range highest voltage in microvolts (optional,
49                 only useful if board does not have software programmable
50                 gain)
51         [6] - analog output range lowest voltage in microvolts (optional)
52         [7] - analog output range highest voltage in microvolts (optional)
53         [8] - use timer mode for DMA.  Timer mode is needed e.g. for
54                 buggy DMA controllers in NS CS5530A (Geode Companion), and for
55                 'jr' cards that lack a hardware fifo.  This option is no
56                 longer needed, since timer mode is _always_ used.
57
58 Passing a zero for an option is the same as leaving it unspecified.
59
60 */
61 /*
62
63 Testing and debugging help provided by Daniel Koch.
64
65 Keithley Manuals:
66         2309.PDF (das16)
67         4919.PDF (das1400, 1600)
68         4922.PDF (das-1400)
69         4923.PDF (das1200, 1400, 1600)
70
71 Computer boards manuals also available from their website
72 www.measurementcomputing.com
73
74 */
75
76 #include <linux/module.h>
77 #include <linux/delay.h>
78 #include <linux/pci.h>
79 #include <linux/interrupt.h>
80
81 #include <asm/dma.h>
82
83 #include "../comedidev.h"
84
85 #include "8253.h"
86 #include "8255.h"
87 #include "comedi_fc.h"
88
89 #undef DEBUG
90 /* #define DEBUG */
91
92 #ifdef DEBUG
93 #define DEBUG_PRINT(format, args...)    \
94         printk(KERN_DEBUG "das16: " format, ## args)
95 #else
96 #define DEBUG_PRINT(format, args...)
97 #endif
98
99 #define DAS16_SIZE 20           /*  number of ioports */
100 #define DAS16_DMA_SIZE 0xff00   /*  size in bytes of allocated dma buffer */
101
102 /*
103     cio-das16.pdf
104
105     "das16"
106     "das16/f"
107
108   0     a/d bits 0-3            start 12 bit
109   1     a/d bits 4-11           unused
110   2     mux read                mux set
111   3     di 4 bit                do 4 bit
112   4     unused                  ao0_lsb
113   5     unused                  ao0_msb
114   6     unused                  ao1_lsb
115   7     unused                  ao1_msb
116   8     status eoc uni/bip      interrupt reset
117   9     dma, int, trig ctrl     set dma, int
118   a     pacer control           unused
119   b     reserved                reserved
120   cdef  8254
121   0123  8255
122
123 */
124
125 /*
126     cio-das16jr.pdf
127
128     "das16jr"
129
130   0     a/d bits 0-3            start 12 bit
131   1     a/d bits 4-11           unused
132   2     mux read                mux set
133   3     di 4 bit                do 4 bit
134   4567  unused                  unused
135   8     status eoc uni/bip      interrupt reset
136   9     dma, int, trig ctrl     set dma, int
137   a     pacer control           unused
138   b     gain status             gain control
139   cdef  8254
140
141 */
142
143 /*
144     cio-das16jr_16.pdf
145
146     "das16jr_16"
147
148   0     a/d bits 0-7            start 16 bit
149   1     a/d bits 8-15           unused
150   2     mux read                mux set
151   3     di 4 bit                do 4 bit
152   4567  unused                  unused
153   8     status eoc uni/bip      interrupt reset
154   9     dma, int, trig ctrl     set dma, int
155   a     pacer control           unused
156   b     gain status             gain control
157   cdef  8254
158
159 */
160 /*
161     cio-das160x-1x.pdf
162
163     "das1601/12"
164     "das1602/12"
165     "das1602/16"
166
167   0     a/d bits 0-3            start 12 bit
168   1     a/d bits 4-11           unused
169   2     mux read                mux set
170   3     di 4 bit                do 4 bit
171   4     unused                  ao0_lsb
172   5     unused                  ao0_msb
173   6     unused                  ao1_lsb
174   7     unused                  ao1_msb
175   8     status eoc uni/bip      interrupt reset
176   9     dma, int, trig ctrl     set dma, int
177   a     pacer control           unused
178   b     gain status             gain control
179   cdef  8254
180   400   8255
181   404   unused                  conversion enable
182   405   unused                  burst enable
183   406   unused                  das1600 enable
184   407   status
185
186 */
187
188 /*  size in bytes of a sample from board */
189 static const int sample_size = 2;
190
191 #define DAS16_TRIG              0
192 #define DAS16_AI_LSB            0
193 #define DAS16_AI_MSB            1
194 #define DAS16_MUX               2
195 #define DAS16_DIO               3
196 #define DAS16_AO_LSB(x) ((x) ? 6 : 4)
197 #define DAS16_AO_MSB(x) ((x) ? 7 : 5)
198 #define DAS16_STATUS            8
199 #define   BUSY                  (1<<7)
200 #define   UNIPOLAR                      (1<<6)
201 #define   DAS16_MUXBIT                  (1<<5)
202 #define   DAS16_INT                     (1<<4)
203 #define DAS16_CONTROL           9
204 #define   DAS16_INTE                    (1<<7)
205 #define   DAS16_IRQ(x)                  (((x) & 0x7) << 4)
206 #define   DMA_ENABLE                    (1<<2)
207 #define   PACING_MASK   0x3
208 #define   INT_PACER             0x03
209 #define   EXT_PACER                     0x02
210 #define   DAS16_SOFT            0x00
211 #define DAS16_PACER             0x0A
212 #define   DAS16_CTR0                    (1<<1)
213 #define   DAS16_TRIG0                   (1<<0)
214 #define   BURST_LEN_BITS(x)                     (((x) & 0xf) << 4)
215 #define DAS16_GAIN              0x0B
216 #define DAS16_CNTR0_DATA                0x0C
217 #define DAS16_CNTR1_DATA                0x0D
218 #define DAS16_CNTR2_DATA                0x0E
219 #define DAS16_CNTR_CONTROL      0x0F
220 #define   DAS16_TERM_CNT        0x00
221 #define   DAS16_ONE_SHOT        0x02
222 #define   DAS16_RATE_GEN        0x04
223 #define   DAS16_CNTR_LSB_MSB    0x30
224 #define   DAS16_CNTR0           0x00
225 #define   DAS16_CNTR1           0x40
226 #define   DAS16_CNTR2           0x80
227
228 #define DAS1600_CONV            0x404
229 #define   DAS1600_CONV_DISABLE          0x40
230 #define DAS1600_BURST           0x405
231 #define   DAS1600_BURST_VAL             0x40
232 #define DAS1600_ENABLE          0x406
233 #define   DAS1600_ENABLE_VAL            0x40
234 #define DAS1600_STATUS_B        0x407
235 #define   DAS1600_BME           0x40
236 #define   DAS1600_ME            0x20
237 #define   DAS1600_CD                    0x10
238 #define   DAS1600_WS                    0x02
239 #define   DAS1600_CLK_10MHZ             0x01
240
241 static const struct comedi_lrange range_das1x01_bip = {
242         4, {
243                 BIP_RANGE(10),
244                 BIP_RANGE(1),
245                 BIP_RANGE(0.1),
246                 BIP_RANGE(0.01)
247         }
248 };
249
250 static const struct comedi_lrange range_das1x01_unip = {
251         4, {
252                 UNI_RANGE(10),
253                 UNI_RANGE(1),
254                 UNI_RANGE(0.1),
255                 UNI_RANGE(0.01)
256         }
257 };
258
259 static const struct comedi_lrange range_das1x02_bip = {
260         4, {
261                 BIP_RANGE(10),
262                 BIP_RANGE(5),
263                 BIP_RANGE(2.5),
264                 BIP_RANGE(1.25)
265         }
266 };
267
268 static const struct comedi_lrange range_das1x02_unip = {
269         4, {
270                 UNI_RANGE(10),
271                 UNI_RANGE(5),
272                 UNI_RANGE(2.5),
273                 UNI_RANGE(1.25)
274         }
275 };
276
277 static const struct comedi_lrange range_das16jr = {
278         9, {
279                 BIP_RANGE(10),
280                 BIP_RANGE(5),
281                 BIP_RANGE(2.5),
282                 BIP_RANGE(1.25),
283                 BIP_RANGE(0.625),
284                 UNI_RANGE(10),
285                 UNI_RANGE(5),
286                 UNI_RANGE(2.5),
287                 UNI_RANGE(1.25)
288         }
289 };
290
291 static const struct comedi_lrange range_das16jr_16 = {
292         8, {
293                 BIP_RANGE(10),
294                 BIP_RANGE(5),
295                 BIP_RANGE(2.5),
296                 BIP_RANGE(1.25),
297                 UNI_RANGE(10),
298                 UNI_RANGE(5),
299                 UNI_RANGE(2.5),
300                 UNI_RANGE(1.25)
301         }
302 };
303
304 static const int das16jr_gainlist[] = { 8, 0, 1, 2, 3, 4, 5, 6, 7 };
305 static const int das16jr_16_gainlist[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
306 static const int das1600_gainlist[] = { 0, 1, 2, 3 };
307
308 enum {
309         das16_pg_none = 0,
310         das16_pg_16jr,
311         das16_pg_16jr_16,
312         das16_pg_1601,
313         das16_pg_1602,
314 };
315 static const int *const das16_gainlists[] = {
316         NULL,
317         das16jr_gainlist,
318         das16jr_16_gainlist,
319         das1600_gainlist,
320         das1600_gainlist,
321 };
322
323 static const struct comedi_lrange *const das16_ai_uni_lranges[] = {
324         &range_unknown,
325         &range_das16jr,
326         &range_das16jr_16,
327         &range_das1x01_unip,
328         &range_das1x02_unip,
329 };
330
331 static const struct comedi_lrange *const das16_ai_bip_lranges[] = {
332         &range_unknown,
333         &range_das16jr,
334         &range_das16jr_16,
335         &range_das1x01_bip,
336         &range_das1x02_bip,
337 };
338
339 struct das16_board {
340         const char *name;
341         unsigned int ai_maxdata;
342         unsigned int ai_speed;  /*  max conversion speed in nanosec */
343         unsigned int ai_pg;
344         unsigned int has_ao:1;
345
346         unsigned int i8255_offset;
347         unsigned int i8254_offset;
348
349         unsigned int size;
350         unsigned int id;
351 };
352
353 #define DAS16_TIMEOUT 1000
354
355 /* Period for timer interrupt in jiffies.  It's a function
356  * to deal with possibility of dynamic HZ patches  */
357 static inline int timer_period(void)
358 {
359         return HZ / 20;
360 }
361
362 struct das16_private_struct {
363         unsigned int clockbase; /*  master clock speed in ns */
364         volatile unsigned int control_state;    /*  dma, interrupt and trigger control bits */
365         volatile unsigned long adc_byte_count;  /*  number of bytes remaining */
366         /*  divisor dividing master clock to get conversion frequency */
367         unsigned int divisor1;
368         /*  divisor dividing master clock to get conversion frequency */
369         unsigned int divisor2;
370         unsigned int dma_chan;  /*  dma channel */
371         uint16_t *dma_buffer[2];
372         dma_addr_t dma_buffer_addr[2];
373         unsigned int current_buffer;
374         volatile unsigned int dma_transfer_size;        /*  target number of bytes to transfer per dma shot */
375         /**
376          * user-defined analog input and output ranges
377          * defined from config options
378          */
379         struct comedi_lrange *user_ai_range_table;
380         struct comedi_lrange *user_ao_range_table;
381
382         struct timer_list timer;        /*  for timed interrupt */
383         volatile short timer_running;
384
385         unsigned long extra_iobase;
386 };
387
388 static int das16_cmd_test(struct comedi_device *dev, struct comedi_subdevice *s,
389                           struct comedi_cmd *cmd)
390 {
391         const struct das16_board *board = comedi_board(dev);
392         struct das16_private_struct *devpriv = dev->private;
393         int err = 0, tmp;
394         int gain, start_chan, i;
395         int mask;
396
397         /* Step 1 : check if triggers are trivially valid */
398
399         err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
400
401         mask = TRIG_FOLLOW;
402         /*  if board supports burst mode */
403         if (board->size > 0x400)
404                 mask |= TRIG_TIMER | TRIG_EXT;
405         err |= cfc_check_trigger_src(&cmd->scan_begin_src, mask);
406
407         tmp = cmd->convert_src;
408         mask = TRIG_TIMER | TRIG_EXT;
409         /*  if board supports burst mode */
410         if (board->size > 0x400)
411                 mask |= TRIG_NOW;
412         err |= cfc_check_trigger_src(&cmd->convert_src, mask);
413
414         err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
415         err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
416
417         if (err)
418                 return 1;
419
420         /* Step 2a : make sure trigger sources are unique */
421
422         err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
423         err |= cfc_check_trigger_is_unique(cmd->convert_src);
424         err |= cfc_check_trigger_is_unique(cmd->stop_src);
425
426         /* Step 2b : and mutually compatible */
427
428         /*  make sure scan_begin_src and convert_src dont conflict */
429         if (cmd->scan_begin_src == TRIG_FOLLOW && cmd->convert_src == TRIG_NOW)
430                 err |= -EINVAL;
431         if (cmd->scan_begin_src != TRIG_FOLLOW && cmd->convert_src != TRIG_NOW)
432                 err |= -EINVAL;
433
434         if (err)
435                 return 2;
436
437         /* Step 3: check if arguments are trivially valid */
438
439         err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
440
441         if (cmd->scan_begin_src == TRIG_FOLLOW) /* internal trigger */
442                 err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
443
444         err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
445
446         /* check against maximum frequency */
447         if (cmd->scan_begin_src == TRIG_TIMER)
448                 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
449                                         board->ai_speed * cmd->chanlist_len);
450
451         if (cmd->convert_src == TRIG_TIMER)
452                 err |= cfc_check_trigger_arg_min(&cmd->convert_arg,
453                                                  board->ai_speed);
454
455         if (cmd->stop_src == TRIG_NONE)
456                 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
457
458         if (err)
459                 return 3;
460
461         /*  step 4: fix up arguments */
462         if (cmd->scan_begin_src == TRIG_TIMER) {
463                 unsigned int tmp = cmd->scan_begin_arg;
464                 /*  set divisors, correct timing arguments */
465                 i8253_cascade_ns_to_timer_2div(devpriv->clockbase,
466                                                &(devpriv->divisor1),
467                                                &(devpriv->divisor2),
468                                                &(cmd->scan_begin_arg),
469                                                cmd->flags & TRIG_ROUND_MASK);
470                 err += (tmp != cmd->scan_begin_arg);
471         }
472         if (cmd->convert_src == TRIG_TIMER) {
473                 unsigned int tmp = cmd->convert_arg;
474                 /*  set divisors, correct timing arguments */
475                 i8253_cascade_ns_to_timer_2div(devpriv->clockbase,
476                                                &(devpriv->divisor1),
477                                                &(devpriv->divisor2),
478                                                &(cmd->convert_arg),
479                                                cmd->flags & TRIG_ROUND_MASK);
480                 err += (tmp != cmd->convert_arg);
481         }
482         if (err)
483                 return 4;
484
485         /*  check channel/gain list against card's limitations */
486         if (cmd->chanlist) {
487                 gain = CR_RANGE(cmd->chanlist[0]);
488                 start_chan = CR_CHAN(cmd->chanlist[0]);
489                 for (i = 1; i < cmd->chanlist_len; i++) {
490                         if (CR_CHAN(cmd->chanlist[i]) !=
491                             (start_chan + i) % s->n_chan) {
492                                 comedi_error(dev,
493                                                 "entries in chanlist must be "
494                                                 "consecutive channels, "
495                                                 "counting upwards\n");
496                                 err++;
497                         }
498                         if (CR_RANGE(cmd->chanlist[i]) != gain) {
499                                 comedi_error(dev,
500                                                 "entries in chanlist must all "
501                                                 "have the same gain\n");
502                                 err++;
503                         }
504                 }
505         }
506         if (err)
507                 return 5;
508
509         return 0;
510 }
511
512 static unsigned int das16_set_pacer(struct comedi_device *dev, unsigned int ns,
513                                     int rounding_flags)
514 {
515         struct das16_private_struct *devpriv = dev->private;
516
517         i8253_cascade_ns_to_timer_2div(devpriv->clockbase, &(devpriv->divisor1),
518                                        &(devpriv->divisor2), &ns,
519                                        rounding_flags & TRIG_ROUND_MASK);
520
521         /* Write the values of ctr1 and ctr2 into counters 1 and 2 */
522         i8254_load(dev->iobase + DAS16_CNTR0_DATA, 0, 1, devpriv->divisor1, 2);
523         i8254_load(dev->iobase + DAS16_CNTR0_DATA, 0, 2, devpriv->divisor2, 2);
524
525         return ns;
526 }
527
528 static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s)
529 {
530         const struct das16_board *board = comedi_board(dev);
531         struct das16_private_struct *devpriv = dev->private;
532         struct comedi_async *async = s->async;
533         struct comedi_cmd *cmd = &async->cmd;
534         unsigned int byte;
535         unsigned long flags;
536         int range;
537
538         if (cmd->flags & TRIG_RT) {
539                 comedi_error(dev, "isa dma transfers cannot be performed with "
540                                                         "TRIG_RT, aborting");
541                 return -1;
542         }
543
544         devpriv->adc_byte_count =
545             cmd->stop_arg * cmd->chanlist_len * sizeof(uint16_t);
546
547         /*  disable conversions for das1600 mode */
548         if (board->size > 0x400)
549                 outb(DAS1600_CONV_DISABLE, dev->iobase + DAS1600_CONV);
550
551         /*  set scan limits */
552         byte = CR_CHAN(cmd->chanlist[0]);
553         byte |= CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]) << 4;
554         outb(byte, dev->iobase + DAS16_MUX);
555
556         /* set gain (this is also burst rate register but according to
557          * computer boards manual, burst rate does nothing, even on
558          * keithley cards) */
559         if (board->ai_pg != das16_pg_none) {
560                 range = CR_RANGE(cmd->chanlist[0]);
561                 outb((das16_gainlists[board->ai_pg])[range],
562                      dev->iobase + DAS16_GAIN);
563         }
564
565         /* set counter mode and counts */
566         cmd->convert_arg =
567             das16_set_pacer(dev, cmd->convert_arg,
568                             cmd->flags & TRIG_ROUND_MASK);
569         DEBUG_PRINT("pacer period: %d ns\n", cmd->convert_arg);
570
571         /* enable counters */
572         byte = 0;
573         /* Enable burst mode if appropriate. */
574         if (board->size > 0x400) {
575                 if (cmd->convert_src == TRIG_NOW) {
576                         outb(DAS1600_BURST_VAL, dev->iobase + DAS1600_BURST);
577                         /*  set burst length */
578                         byte |= BURST_LEN_BITS(cmd->chanlist_len - 1);
579                 } else {
580                         outb(0, dev->iobase + DAS1600_BURST);
581                 }
582         }
583         outb(byte, dev->iobase + DAS16_PACER);
584
585         /*  set up dma transfer */
586         flags = claim_dma_lock();
587         disable_dma(devpriv->dma_chan);
588         /* clear flip-flop to make sure 2-byte registers for
589          * count and address get set correctly */
590         clear_dma_ff(devpriv->dma_chan);
591         devpriv->current_buffer = 0;
592         set_dma_addr(devpriv->dma_chan,
593                      devpriv->dma_buffer_addr[devpriv->current_buffer]);
594         devpriv->dma_transfer_size = DAS16_DMA_SIZE;
595         set_dma_count(devpriv->dma_chan, devpriv->dma_transfer_size);
596         enable_dma(devpriv->dma_chan);
597         release_dma_lock(flags);
598
599         /*  set up interrupt */
600         devpriv->timer_running = 1;
601         devpriv->timer.expires = jiffies + timer_period();
602         add_timer(&devpriv->timer);
603         devpriv->control_state &= ~DAS16_INTE;
604         devpriv->control_state |= DMA_ENABLE;
605         devpriv->control_state &= ~PACING_MASK;
606         if (cmd->convert_src == TRIG_EXT)
607                 devpriv->control_state |= EXT_PACER;
608         else
609                 devpriv->control_state |= INT_PACER;
610         outb(devpriv->control_state, dev->iobase + DAS16_CONTROL);
611
612         /* Enable conversions if using das1600 mode */
613         if (board->size > 0x400)
614                 outb(0, dev->iobase + DAS1600_CONV);
615
616
617         return 0;
618 }
619
620 static int das16_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
621 {
622         const struct das16_board *board = comedi_board(dev);
623         struct das16_private_struct *devpriv = dev->private;
624         unsigned long flags;
625
626         spin_lock_irqsave(&dev->spinlock, flags);
627         /* disable interrupts, dma and pacer clocked conversions */
628         devpriv->control_state &= ~DAS16_INTE & ~PACING_MASK & ~DMA_ENABLE;
629         outb(devpriv->control_state, dev->iobase + DAS16_CONTROL);
630         disable_dma(devpriv->dma_chan);
631
632         /*  disable SW timer */
633         if (devpriv->timer_running) {
634                 devpriv->timer_running = 0;
635                 del_timer(&devpriv->timer);
636         }
637
638         /* disable burst mode */
639         if (board->size > 0x400)
640                 outb(0, dev->iobase + DAS1600_BURST);
641
642
643         spin_unlock_irqrestore(&dev->spinlock, flags);
644
645         return 0;
646 }
647
648 static void das16_reset(struct comedi_device *dev)
649 {
650         outb(0, dev->iobase + DAS16_STATUS);
651         outb(0, dev->iobase + DAS16_CONTROL);
652         outb(0, dev->iobase + DAS16_PACER);
653         outb(0, dev->iobase + DAS16_CNTR_CONTROL);
654 }
655
656 static int das16_ai_insn_read(struct comedi_device *dev,
657                               struct comedi_subdevice *s,
658                               struct comedi_insn *insn,
659                               unsigned int *data)
660 {
661         const struct das16_board *board = comedi_board(dev);
662         struct das16_private_struct *devpriv = dev->private;
663         int i, n;
664         int range;
665         int chan;
666
667         /*  disable interrupts and pacing */
668         devpriv->control_state &= ~DAS16_INTE & ~DMA_ENABLE & ~PACING_MASK;
669         outb(devpriv->control_state, dev->iobase + DAS16_CONTROL);
670
671         /* set multiplexer */
672         chan = CR_CHAN(insn->chanspec);
673         chan |= CR_CHAN(insn->chanspec) << 4;
674         outb(chan, dev->iobase + DAS16_MUX);
675
676         /* set gain */
677         if (board->ai_pg != das16_pg_none) {
678                 range = CR_RANGE(insn->chanspec);
679                 outb((das16_gainlists[board->ai_pg])[range],
680                      dev->iobase + DAS16_GAIN);
681         }
682
683         for (n = 0; n < insn->n; n++) {
684                 unsigned int val;
685
686                 /* trigger conversion */
687                 outb_p(0, dev->iobase + DAS16_TRIG);
688
689                 for (i = 0; i < DAS16_TIMEOUT; i++) {
690                         if (!(inb(dev->iobase + DAS16_STATUS) & BUSY))
691                                 break;
692                 }
693                 if (i == DAS16_TIMEOUT) {
694                         printk("das16: timeout\n");
695                         return -ETIME;
696                 }
697
698                 val = inb(dev->iobase + DAS16_AI_MSB) << 8;
699                 val |= inb(dev->iobase + DAS16_AI_LSB);
700                 if (s->maxdata == 0x0fff)
701                         data[n] >>= 4;
702                 val &= s->maxdata;
703
704                 data[n] = val;
705         }
706
707         return n;
708 }
709
710 static int das16_di_insn_bits(struct comedi_device *dev,
711                               struct comedi_subdevice *s,
712                               struct comedi_insn *insn,
713                               unsigned int *data)
714 {
715         data[1] = inb(dev->iobase + DAS16_DIO) & 0xf;
716
717         return insn->n;
718 }
719
720 static int das16_do_insn_bits(struct comedi_device *dev,
721                               struct comedi_subdevice *s,
722                               struct comedi_insn *insn,
723                               unsigned int *data)
724 {
725         unsigned int mask = data[0];
726         unsigned int bits = data[1];
727
728         if (mask) {
729                 s->state &= ~mask;
730                 s->state |= (bits & mask);
731
732                 outb(s->state, dev->iobase + DAS16_DIO);
733         }
734
735         data[1] = s->state;
736
737         return insn->n;
738 }
739
740 static int das16_ao_insn_write(struct comedi_device *dev,
741                                struct comedi_subdevice *s,
742                                struct comedi_insn *insn,
743                                unsigned int *data)
744 {
745         unsigned int chan = CR_CHAN(insn->chanspec);
746         unsigned int val;
747         int i;
748
749         for (i = 0; i < insn->n; i++) {
750                 val = data[i];
751                 val <<= 4;
752
753                 outb(val & 0xff, dev->iobase + DAS16_AO_LSB(chan));
754                 outb((val >> 8) & 0xff, dev->iobase + DAS16_AO_MSB(chan));
755         }
756
757         return insn->n;
758 }
759
760 /* the pc104-das16jr (at least) has problems if the dma
761         transfer is interrupted in the middle of transferring
762         a 16 bit sample, so this function takes care to get
763         an even transfer count after disabling dma
764         channel.
765 */
766 static int disable_dma_on_even(struct comedi_device *dev)
767 {
768         struct das16_private_struct *devpriv = dev->private;
769         int residue;
770         int i;
771         static const int disable_limit = 100;
772         static const int enable_timeout = 100;
773
774         disable_dma(devpriv->dma_chan);
775         residue = get_dma_residue(devpriv->dma_chan);
776         for (i = 0; i < disable_limit && (residue % 2); ++i) {
777                 int j;
778                 enable_dma(devpriv->dma_chan);
779                 for (j = 0; j < enable_timeout; ++j) {
780                         int new_residue;
781                         udelay(2);
782                         new_residue = get_dma_residue(devpriv->dma_chan);
783                         if (new_residue != residue)
784                                 break;
785                 }
786                 disable_dma(devpriv->dma_chan);
787                 residue = get_dma_residue(devpriv->dma_chan);
788         }
789         if (i == disable_limit) {
790                 comedi_error(dev, "failed to get an even dma transfer, "
791                                                         "could be trouble.");
792         }
793         return residue;
794 }
795
796 static void das16_interrupt(struct comedi_device *dev)
797 {
798         struct das16_private_struct *devpriv = dev->private;
799         unsigned long dma_flags, spin_flags;
800         struct comedi_subdevice *s = dev->read_subdev;
801         struct comedi_async *async;
802         struct comedi_cmd *cmd;
803         int num_bytes, residue;
804         int buffer_index;
805
806         if (!dev->attached) {
807                 comedi_error(dev, "premature interrupt");
808                 return;
809         }
810         /*  initialize async here to make sure it is not NULL */
811         async = s->async;
812         cmd = &async->cmd;
813
814         spin_lock_irqsave(&dev->spinlock, spin_flags);
815         if ((devpriv->control_state & DMA_ENABLE) == 0) {
816                 spin_unlock_irqrestore(&dev->spinlock, spin_flags);
817                 DEBUG_PRINT("interrupt while dma disabled?\n");
818                 return;
819         }
820
821         dma_flags = claim_dma_lock();
822         clear_dma_ff(devpriv->dma_chan);
823         residue = disable_dma_on_even(dev);
824
825         /*  figure out how many points to read */
826         if (residue > devpriv->dma_transfer_size) {
827                 comedi_error(dev, "residue > transfer size!\n");
828                 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
829                 num_bytes = 0;
830         } else
831                 num_bytes = devpriv->dma_transfer_size - residue;
832
833         if (cmd->stop_src == TRIG_COUNT &&
834                                         num_bytes >= devpriv->adc_byte_count) {
835                 num_bytes = devpriv->adc_byte_count;
836                 async->events |= COMEDI_CB_EOA;
837         }
838
839         buffer_index = devpriv->current_buffer;
840         devpriv->current_buffer = (devpriv->current_buffer + 1) % 2;
841         devpriv->adc_byte_count -= num_bytes;
842
843         /*  re-enable  dma */
844         if ((async->events & COMEDI_CB_EOA) == 0) {
845                 set_dma_addr(devpriv->dma_chan,
846                              devpriv->dma_buffer_addr[devpriv->current_buffer]);
847                 set_dma_count(devpriv->dma_chan, devpriv->dma_transfer_size);
848                 enable_dma(devpriv->dma_chan);
849         }
850         release_dma_lock(dma_flags);
851
852         spin_unlock_irqrestore(&dev->spinlock, spin_flags);
853
854         cfc_write_array_to_buffer(s,
855                                   devpriv->dma_buffer[buffer_index], num_bytes);
856
857         cfc_handle_events(dev, s);
858 }
859
860 static void das16_timer_interrupt(unsigned long arg)
861 {
862         struct comedi_device *dev = (struct comedi_device *)arg;
863         struct das16_private_struct *devpriv = dev->private;
864
865         das16_interrupt(dev);
866
867         if (devpriv->timer_running)
868                 mod_timer(&devpriv->timer, jiffies + timer_period());
869 }
870
871 static int das16_probe(struct comedi_device *dev, struct comedi_devconfig *it)
872 {
873         const struct das16_board *board = comedi_board(dev);
874         int diobits;
875
876         /* diobits indicates boards */
877         diobits = inb(dev->iobase + DAS16_DIO) & 0xf0;
878
879         printk(KERN_INFO " id bits are 0x%02x\n", diobits);
880         if (board->id != diobits) {
881                 printk(KERN_INFO " requested board's id bits are 0x%x (ignore)\n",
882                        board->id);
883         }
884
885         return 0;
886 }
887
888 static int das1600_mode_detect(struct comedi_device *dev)
889 {
890         struct das16_private_struct *devpriv = dev->private;
891         int status = 0;
892
893         status = inb(dev->iobase + DAS1600_STATUS_B);
894
895         if (status & DAS1600_CLK_10MHZ) {
896                 devpriv->clockbase = 100;
897                 printk(KERN_INFO " 10MHz pacer clock\n");
898         } else {
899                 devpriv->clockbase = 1000;
900                 printk(KERN_INFO " 1MHz pacer clock\n");
901         }
902
903         return 0;
904 }
905
906 static void das16_ai_munge(struct comedi_device *dev,
907                            struct comedi_subdevice *s, void *array,
908                            unsigned int num_bytes,
909                            unsigned int start_chan_index)
910 {
911         unsigned int i, num_samples = num_bytes / sizeof(short);
912         short *data = array;
913
914         for (i = 0; i < num_samples; i++) {
915                 data[i] = le16_to_cpu(data[i]);
916                 if (s->maxdata == 0x0fff)
917                         data[i] >>= 4;
918                 data[i] &= s->maxdata;
919         }
920 }
921
922 /*
923  *
924  * Options list:
925  *   0  I/O base
926  *   1  IRQ
927  *   2  DMA
928  *   3  Clock speed (in MHz)
929  */
930 static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it)
931 {
932         const struct das16_board *board = comedi_board(dev);
933         struct das16_private_struct *devpriv;
934         struct comedi_subdevice *s;
935         struct comedi_krange *user_ai_range;
936         struct comedi_krange *user_ao_range;
937         unsigned int dma_chan = it->options[2];
938         unsigned int status;
939         int ret;
940
941         /*  check that clock setting is valid */
942         if (it->options[3]) {
943                 if (it->options[3] != 0 &&
944                     it->options[3] != 1 && it->options[3] != 10) {
945                         printk
946                             ("\n Invalid option.  Master clock must be set "
947                                                         "to 1 or 10 (MHz)\n");
948                         return -EINVAL;
949                 }
950         }
951
952         devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
953         if (!devpriv)
954                 return -ENOMEM;
955
956         if (board->size < 0x400) {
957                 ret = comedi_request_region(dev, it->options[0], board->size);
958                 if (ret)
959                         return ret;
960         } else {
961                 ret = comedi_request_region(dev, it->options[0], 0x10);
962                 if (ret)
963                         return ret;
964                 /* Request an additional region for the 8255 */
965                 ret = __comedi_request_region(dev, dev->iobase + 0x400,
966                                               board->size & 0x3ff);
967                 if (ret)
968                         return ret;
969                 devpriv->extra_iobase = dev->iobase + 0x400;
970         }
971
972         /*  probe id bits to make sure they are consistent */
973         if (das16_probe(dev, it)) {
974                 printk(KERN_ERR " id bits do not match selected board, aborting\n");
975                 return -EINVAL;
976         }
977
978         /*  get master clock speed */
979         if (board->size < 0x400) {
980                 if (it->options[3])
981                         devpriv->clockbase = 1000 / it->options[3];
982                 else
983                         devpriv->clockbase = 1000;      /*  1 MHz default */
984         } else {
985                 das1600_mode_detect(dev);
986         }
987
988         /* initialize dma */
989         if (dma_chan == 1 || dma_chan == 3) {
990                 unsigned long flags;
991                 int i;
992
993                 if (request_dma(dma_chan, dev->board_name)) {
994                         dev_err(dev->class_dev,
995                                 "failed to request dma channel %i\n",
996                                 dma_chan);
997                         return -EINVAL;
998                 }
999                 devpriv->dma_chan = dma_chan;
1000
1001                 /* allocate dma buffers */
1002                 for (i = 0; i < 2; i++) {
1003                         void *p;
1004
1005                         p = pci_alloc_consistent(NULL, DAS16_DMA_SIZE,
1006                                                  &devpriv->dma_buffer_addr[i]);
1007                         if (!p)
1008                                 return -ENOMEM;
1009                         devpriv->dma_buffer[i] = p;
1010                 }
1011
1012                 flags = claim_dma_lock();
1013                 disable_dma(devpriv->dma_chan);
1014                 set_dma_mode(devpriv->dma_chan, DMA_MODE_READ);
1015                 release_dma_lock(flags);
1016
1017                 init_timer(&(devpriv->timer));
1018                 devpriv->timer.function = das16_timer_interrupt;
1019                 devpriv->timer.data = (unsigned long)dev;
1020         }
1021
1022         /*  get any user-defined input range */
1023         if (board->ai_pg == das16_pg_none &&
1024             (it->options[4] || it->options[5])) {
1025                 /*  allocate single-range range table */
1026                 devpriv->user_ai_range_table =
1027                     kmalloc(sizeof(struct comedi_lrange) +
1028                             sizeof(struct comedi_krange), GFP_KERNEL);
1029                 /*  initialize ai range */
1030                 devpriv->user_ai_range_table->length = 1;
1031                 user_ai_range = devpriv->user_ai_range_table->range;
1032                 user_ai_range->min = it->options[4];
1033                 user_ai_range->max = it->options[5];
1034                 user_ai_range->flags = UNIT_volt;
1035         }
1036         /*  get any user-defined output range */
1037         if (it->options[6] || it->options[7]) {
1038                 /*  allocate single-range range table */
1039                 devpriv->user_ao_range_table =
1040                     kmalloc(sizeof(struct comedi_lrange) +
1041                             sizeof(struct comedi_krange), GFP_KERNEL);
1042                 /*  initialize ao range */
1043                 devpriv->user_ao_range_table->length = 1;
1044                 user_ao_range = devpriv->user_ao_range_table->range;
1045                 user_ao_range->min = it->options[6];
1046                 user_ao_range->max = it->options[7];
1047                 user_ao_range->flags = UNIT_volt;
1048         }
1049
1050         ret = comedi_alloc_subdevices(dev, 5);
1051         if (ret)
1052                 return ret;
1053
1054         status = inb(dev->iobase + DAS16_STATUS);
1055
1056         /* Analog Input subdevice */
1057         s = &dev->subdevices[0];
1058         s->type         = COMEDI_SUBD_AI;
1059         s->subdev_flags = SDF_READABLE;
1060         if (status & DAS16_MUXBIT) {
1061                 s->subdev_flags |= SDF_GROUND;
1062                 s->n_chan       = 16;
1063         } else {
1064                 s->subdev_flags |= SDF_DIFF;
1065                 s->n_chan       = 8;
1066         }
1067         s->len_chanlist = s->n_chan;
1068         s->maxdata      = board->ai_maxdata;
1069         if (devpriv->user_ai_range_table) { /*  user defined ai range */
1070                 s->range_table  = devpriv->user_ai_range_table;
1071         } else if (status & UNIPOLAR) {
1072                 s->range_table  = das16_ai_uni_lranges[board->ai_pg];
1073         } else {
1074                 s->range_table  = das16_ai_bip_lranges[board->ai_pg];
1075         }
1076         s->insn_read    = das16_ai_insn_read;
1077         if (devpriv->dma_chan) {
1078                 dev->read_subdev = s;
1079                 s->subdev_flags |= SDF_CMD_READ;
1080                 s->do_cmdtest   = das16_cmd_test;
1081                 s->do_cmd       = das16_cmd_exec;
1082                 s->cancel       = das16_cancel;
1083                 s->munge        = das16_ai_munge;
1084         }
1085
1086         /* Analog Output subdevice */
1087         s = &dev->subdevices[1];
1088         if (board->has_ao) {
1089                 s->type         = COMEDI_SUBD_AO;
1090                 s->subdev_flags = SDF_WRITABLE;
1091                 s->n_chan       = 2;
1092                 s->maxdata      = 0x0fff;
1093                 if (devpriv->user_ao_range_table)
1094                         s->range_table  = devpriv->user_ao_range_table;
1095                 else
1096                         s->range_table  = &range_unknown;
1097
1098                 s->insn_write   = das16_ao_insn_write;
1099         } else {
1100                 s->type         = COMEDI_SUBD_UNUSED;
1101         }
1102
1103         /* Digital Input subdevice */
1104         s = &dev->subdevices[2];
1105         s->type         = COMEDI_SUBD_DI;
1106         s->subdev_flags = SDF_READABLE;
1107         s->n_chan       = 4;
1108         s->maxdata      = 1;
1109         s->range_table  = &range_digital;
1110         s->insn_bits    = das16_di_insn_bits;
1111
1112         /* Digital Output subdevice */
1113         s = &dev->subdevices[3];
1114         s->type         = COMEDI_SUBD_DO;
1115         s->subdev_flags = SDF_WRITABLE;
1116         s->n_chan       = 4;
1117         s->maxdata      = 1;
1118         s->range_table  = &range_digital;
1119         s->insn_bits    = das16_do_insn_bits;
1120
1121         /* initialize digital output lines */
1122         outb(s->state, dev->iobase + DAS16_DIO);
1123
1124         s = &dev->subdevices[4];
1125         /* 8255 */
1126         if (board->i8255_offset != 0) {
1127                 subdev_8255_init(dev, s, NULL, (dev->iobase +
1128                                                 board->i8255_offset));
1129         } else {
1130                 s->type = COMEDI_SUBD_UNUSED;
1131         }
1132
1133         das16_reset(dev);
1134         /* set the interrupt level */
1135         devpriv->control_state = DAS16_IRQ(dev->irq);
1136         outb(devpriv->control_state, dev->iobase + DAS16_CONTROL);
1137
1138         /*  turn on das1600 mode if available */
1139         if (board->size > 0x400) {
1140                 outb(DAS1600_ENABLE_VAL, dev->iobase + DAS1600_ENABLE);
1141                 outb(0, dev->iobase + DAS1600_CONV);
1142                 outb(0, dev->iobase + DAS1600_BURST);
1143         }
1144
1145         return 0;
1146 }
1147
1148 static void das16_detach(struct comedi_device *dev)
1149 {
1150         const struct das16_board *board = comedi_board(dev);
1151         struct das16_private_struct *devpriv = dev->private;
1152
1153         das16_reset(dev);
1154         if (devpriv) {
1155                 int i;
1156                 for (i = 0; i < 2; i++) {
1157                         if (devpriv->dma_buffer[i])
1158                                 pci_free_consistent(NULL, DAS16_DMA_SIZE,
1159                                                     devpriv->dma_buffer[i],
1160                                                     devpriv->
1161                                                     dma_buffer_addr[i]);
1162                 }
1163                 if (devpriv->dma_chan)
1164                         free_dma(devpriv->dma_chan);
1165                 kfree(devpriv->user_ai_range_table);
1166                 kfree(devpriv->user_ao_range_table);
1167         }
1168         if (devpriv->extra_iobase)
1169                 release_region(devpriv->extra_iobase, board->size & 0x3ff);
1170         comedi_legacy_detach(dev);
1171 }
1172
1173 static const struct das16_board das16_boards[] = {
1174         {
1175                 .name           = "das-16",
1176                 .ai_maxdata     = 0x0fff,
1177                 .ai_speed       = 15000,
1178                 .ai_pg          = das16_pg_none,
1179                 .has_ao         = 1,
1180                 .i8255_offset   = 0x10,
1181                 .i8254_offset   = 0x0c,
1182                 .size           = 0x14,
1183                 .id             = 0x00,
1184         }, {
1185                 .name           = "das-16g",
1186                 .ai_maxdata     = 0x0fff,
1187                 .ai_speed       = 15000,
1188                 .ai_pg          = das16_pg_none,
1189                 .has_ao         = 1,
1190                 .i8255_offset   = 0x10,
1191                 .i8254_offset   = 0x0c,
1192                 .size           = 0x14,
1193                 .id             = 0x00,
1194         }, {
1195                 .name           = "das-16f",
1196                 .ai_maxdata     = 0x0fff,
1197                 .ai_speed       = 8500,
1198                 .ai_pg          = das16_pg_none,
1199                 .has_ao         = 1,
1200                 .i8255_offset   = 0x10,
1201                 .i8254_offset   = 0x0c,
1202                 .size           = 0x14,
1203                 .id             = 0x00,
1204         }, {
1205                 .name           = "cio-das16",
1206                 .ai_maxdata     = 0x0fff,
1207                 .ai_speed       = 20000,
1208                 .ai_pg          = das16_pg_none,
1209                 .has_ao         = 1,
1210                 .i8255_offset   = 0x10,
1211                 .i8254_offset   = 0x0c,
1212                 .size           = 0x14,
1213                 .id             = 0x80,
1214         }, {
1215                 .name           = "cio-das16/f",
1216                 .ai_maxdata     = 0x0fff,
1217                 .ai_speed       = 10000,
1218                 .ai_pg          = das16_pg_none,
1219                 .has_ao         = 1,
1220                 .i8255_offset   = 0x10,
1221                 .i8254_offset   = 0x0c,
1222                 .size           = 0x14,
1223                 .id             = 0x80,
1224         }, {
1225                 .name           = "cio-das16/jr",
1226                 .ai_maxdata     = 0x0fff,
1227                 .ai_speed       = 7692,
1228                 .ai_pg          = das16_pg_16jr,
1229                 .i8255_offset   = 0,
1230                 .i8254_offset   = 0x0c,
1231                 .size           = 0x10,
1232                 .id             = 0x00,
1233         }, {
1234                 .name           = "pc104-das16jr",
1235                 .ai_maxdata     = 0x0fff,
1236                 .ai_speed       = 3300,
1237                 .ai_pg          = das16_pg_16jr,
1238                 .i8255_offset   = 0,
1239                 .i8254_offset   = 0x0c,
1240                 .size           = 0x10,
1241                 .id             = 0x00,
1242         }, {
1243                 .name           = "cio-das16jr/16",
1244                 .ai_maxdata     = 0xffff,
1245                 .ai_speed       = 10000,
1246                 .ai_pg          = das16_pg_16jr_16,
1247                 .i8255_offset   = 0,
1248                 .i8254_offset   = 0x0c,
1249                 .size           = 0x10,
1250                 .id             = 0x00,
1251         }, {
1252                 .name           = "pc104-das16jr/16",
1253                 .ai_maxdata     = 0xffff,
1254                 .ai_speed       = 10000,
1255                 .ai_pg          = das16_pg_16jr_16,
1256                 .i8255_offset   = 0,
1257                 .i8254_offset   = 0x0c,
1258                 .size           = 0x10,
1259                 .id             = 0x00,
1260         }, {
1261                 .name           = "das-1201",
1262                 .ai_maxdata     = 0x0fff,
1263                 .ai_speed       = 20000,
1264                 .ai_pg          = das16_pg_none,
1265                 .i8255_offset   = 0x400,
1266                 .i8254_offset   = 0x0c,
1267                 .size           = 0x408,
1268                 .id             = 0x20,
1269         }, {
1270                 .name           = "das-1202",
1271                 .ai_maxdata     = 0x0fff,
1272                 .ai_speed       = 10000,
1273                 .ai_pg          = das16_pg_none,
1274                 .i8255_offset   = 0x400,
1275                 .i8254_offset   = 0x0c,
1276                 .size           = 0x408,
1277                 .id             = 0x20,
1278         }, {
1279                 .name           = "das-1401",
1280                 .ai_maxdata     = 0x0fff,
1281                 .ai_speed       = 10000,
1282                 .ai_pg          = das16_pg_1601,
1283                 .i8255_offset   = 0x0,
1284                 .i8254_offset   = 0x0c,
1285                 .size           = 0x408,
1286                 .id             = 0xc0,
1287         }, {
1288                 .name           = "das-1402",
1289                 .ai_maxdata     = 0x0fff,
1290                 .ai_speed       = 10000,
1291                 .ai_pg          = das16_pg_1602,
1292                 .i8255_offset   = 0x0,
1293                 .i8254_offset   = 0x0c,
1294                 .size           = 0x408,
1295                 .id             = 0xc0,
1296         }, {
1297                 .name           = "das-1601",
1298                 .ai_maxdata     = 0x0fff,
1299                 .ai_speed       = 10000,
1300                 .ai_pg          = das16_pg_1601,
1301                 .has_ao         = 1,
1302                 .i8255_offset   = 0x400,
1303                 .i8254_offset   = 0x0c,
1304                 .size           = 0x408,
1305                 .id             = 0xc0,
1306         }, {
1307                 .name           = "das-1602",
1308                 .ai_maxdata     = 0x0fff,
1309                 .ai_speed       = 10000,
1310                 .ai_pg          = das16_pg_1602,
1311                 .has_ao         = 1,
1312                 .i8255_offset   = 0x400,
1313                 .i8254_offset   = 0x0c,
1314                 .size           = 0x408,
1315                 .id             = 0xc0,
1316         }, {
1317                 .name           = "cio-das1401/12",
1318                 .ai_maxdata     = 0x0fff,
1319                 .ai_speed       = 6250,
1320                 .ai_pg          = das16_pg_1601,
1321                 .i8255_offset   = 0,
1322                 .i8254_offset   = 0x0c,
1323                 .size           = 0x408,
1324                 .id             = 0xc0,
1325         }, {
1326                 .name           = "cio-das1402/12",
1327                 .ai_maxdata     = 0x0fff,
1328                 .ai_speed       = 6250,
1329                 .ai_pg          = das16_pg_1602,
1330                 .i8255_offset   = 0,
1331                 .i8254_offset   = 0x0c,
1332                 .size           = 0x408,
1333                 .id             = 0xc0,
1334         }, {
1335                 .name           = "cio-das1402/16",
1336                 .ai_maxdata     = 0xffff,
1337                 .ai_speed       = 10000,
1338                 .ai_pg          = das16_pg_1602,
1339                 .i8255_offset   = 0,
1340                 .i8254_offset   = 0x0c,
1341                 .size           = 0x408,
1342                 .id             = 0xc0,
1343         }, {
1344                 .name           = "cio-das1601/12",
1345                 .ai_maxdata     = 0x0fff,
1346                 .ai_speed       = 6250,
1347                 .ai_pg          = das16_pg_1601,
1348                 .has_ao         = 1,
1349                 .i8255_offset   = 0x400,
1350                 .i8254_offset   = 0x0c,
1351                 .size           = 0x408,
1352                 .id             = 0xc0,
1353         }, {
1354                 .name           = "cio-das1602/12",
1355                 .ai_maxdata     = 0x0fff,
1356                 .ai_speed       = 10000,
1357                 .ai_pg          = das16_pg_1602,
1358                 .has_ao         = 1,
1359                 .i8255_offset   = 0x400,
1360                 .i8254_offset   = 0x0c,
1361                 .size           = 0x408,
1362                 .id             = 0xc0,
1363         }, {
1364                 .name           = "cio-das1602/16",
1365                 .ai_maxdata     = 0xffff,
1366                 .ai_speed       = 10000,
1367                 .ai_pg          = das16_pg_1602,
1368                 .has_ao         = 1,
1369                 .i8255_offset   = 0x400,
1370                 .i8254_offset   = 0x0c,
1371                 .size           = 0x408,
1372                 .id             = 0xc0,
1373         }, {
1374                 .name           = "cio-das16/330",
1375                 .ai_maxdata     = 0x0fff,
1376                 .ai_speed       = 3030,
1377                 .ai_pg          = das16_pg_16jr,
1378                 .i8255_offset   = 0,
1379                 .i8254_offset   = 0x0c,
1380                 .size           = 0x14,
1381                 .id             = 0xf0,
1382         },
1383 };
1384
1385 static struct comedi_driver das16_driver = {
1386         .driver_name    = "das16",
1387         .module         = THIS_MODULE,
1388         .attach         = das16_attach,
1389         .detach         = das16_detach,
1390         .board_name     = &das16_boards[0].name,
1391         .num_names      = ARRAY_SIZE(das16_boards),
1392         .offset         = sizeof(das16_boards[0]),
1393 };
1394 module_comedi_driver(das16_driver);
1395
1396 MODULE_AUTHOR("Comedi http://www.comedi.org");
1397 MODULE_DESCRIPTION("Comedi low-level driver");
1398 MODULE_LICENSE("GPL");