2 * comedi/drivers/pcl812.c
4 * Author: Michal Dobes <dobes@tesnet.cz>
6 * hardware driver for Advantech cards
7 * card: PCL-812, PCL-812PG, PCL-813, PCL-813B
8 * driver: pcl812, pcl812pg, pcl813, pcl813b
10 * card: ACL-8112DG, ACL-8112HG, ACL-8112PG, ACL-8113, ACL-8216
11 * driver: acl8112dg, acl8112hg, acl8112pg, acl8113, acl8216
12 * and for ICP DAS cards
13 * card: ISO-813, A-821PGH, A-821PGL, A-821PGL-NDA, A-822PGH, A-822PGL,
14 * driver: iso813, a821pgh, a-821pgl, a-821pglnda, a822pgh, a822pgl,
15 * card: A-823PGH, A-823PGL, A-826PG
16 * driver: a823pgh, a823pgl, a826pg
20 Description: Advantech PCL-812/PG, PCL-813/B,
21 ADLink ACL-8112DG/HG/PG, ACL-8113, ACL-8216,
22 ICP DAS A-821PGH/PGL/PGL-NDA, A-822PGH/PGL, A-823PGH/PGL, A-826PG,
24 Author: Michal Dobes <dobes@tesnet.cz>
25 Devices: [Advantech] PCL-812 (pcl812), PCL-812PG (pcl812pg),
26 PCL-813 (pcl813), PCL-813B (pcl813b), [ADLink] ACL-8112DG (acl8112dg),
27 ACL-8112HG (acl8112hg), ACL-8113 (acl-8113), ACL-8216 (acl8216),
28 [ICP] ISO-813 (iso813), A-821PGH (a821pgh), A-821PGL (a821pgl),
29 A-821PGL-NDA (a821pclnda), A-822PGH (a822pgh), A-822PGL (a822pgl),
30 A-823PGH (a823pgh), A-823PGL (a823pgl), A-826PG (a826pg)
31 Updated: Mon, 06 Aug 2007 12:03:15 +0100
32 Status: works (I hope. My board fire up under my hands
33 and I cann't test all features.)
35 This driver supports insn and cmd interfaces. Some boards support only insn
36 becouse their hardware don't allow more (PCL-813/B, ACL-8113, ISO-813).
37 Data transfer over DMA is supported only when you measure only one
38 channel, this is too hardware limitation of these boards.
42 [1] - IRQ (0=disable, 2, 3, 4, 5, 6, 7; 10, 11, 12, 14, 15)
43 [2] - DMA (0=disable, 1, 3)
44 [3] - 0=trigger source is internal 8253 with 2MHz clock
45 1=trigger source is external
46 [4] - 0=A/D input range is +/-10V
47 1=A/D input range is +/-5V
48 2=A/D input range is +/-2.5V
49 3=A/D input range is +/-1.25V
50 4=A/D input range is +/-0.625V
51 5=A/D input range is +/-0.3125V
52 [5] - 0=D/A outputs 0-5V (internal reference -5V)
53 1=D/A outputs 0-10V (internal reference -10V)
54 2=D/A outputs unknown (external reference)
56 Options for PCL-812PG, ACL-8112PG:
58 [1] - IRQ (0=disable, 2, 3, 4, 5, 6, 7; 10, 11, 12, 14, 15)
59 [2] - DMA (0=disable, 1, 3)
60 [3] - 0=trigger source is internal 8253 with 2MHz clock
61 1=trigger source is external
62 [4] - 0=A/D have max +/-5V input
63 1=A/D have max +/-10V input
64 [5] - 0=D/A outputs 0-5V (internal reference -5V)
65 1=D/A outputs 0-10V (internal reference -10V)
66 2=D/A outputs unknown (external reference)
68 Options for ACL-8112DG/HG, A-822PGL/PGH, A-823PGL/PGH, ACL-8216, A-826PG:
70 [1] - IRQ (0=disable, 2, 3, 4, 5, 6, 7; 10, 11, 12, 14, 15)
71 [2] - DMA (0=disable, 1, 3)
72 [3] - 0=trigger source is internal 8253 with 2MHz clock
73 1=trigger source is external
74 [4] - 0=A/D channels are S.E.
75 1=A/D channels are DIFF
76 [5] - 0=D/A outputs 0-5V (internal reference -5V)
77 1=D/A outputs 0-10V (internal reference -10V)
78 2=D/A outputs unknown (external reference)
80 Options for A-821PGL/PGH:
82 [1] - IRQ (0=disable, 2, 3, 4, 5, 6, 7)
83 [2] - 0=A/D channels are S.E.
84 1=A/D channels are DIFF
85 [3] - 0=D/A output 0-5V (internal reference -5V)
86 1=D/A output 0-10V (internal reference -10V)
88 Options for A-821PGL-NDA:
90 [1] - IRQ (0=disable, 2, 3, 4, 5, 6, 7)
91 [2] - 0=A/D channels are S.E.
92 1=A/D channels are DIFF
99 [1] - 0= bipolar inputs
102 Options for ACL-8113, ISO-813:
104 [1] - 0= 10V bipolar inputs
105 1= 10V unipolar inputs
106 2= 20V bipolar inputs
107 3= 20V unipolar inputs
110 #include <linux/interrupt.h>
111 #include <linux/gfp.h>
112 #include "../comedidev.h"
114 #include <linux/delay.h>
115 #include <linux/ioport.h>
120 #undef PCL812_EXTDEBUG /* if this is defined then a lot of messages is printed */
122 /* hardware types of the cards */
123 #define boardPCL812PG 0 /* and ACL-8112PG */
124 #define boardPCL813B 1
125 #define boardPCL812 2
126 #define boardPCL813 3
127 #define boardISO813 5
128 #define boardACL8113 6
129 #define boardACL8112 7 /* ACL-8112DG/HG, A-822PGL/PGH, A-823PGL/PGH */
130 #define boardACL8216 8 /* and ICP DAS A-826PG */
131 #define boardA821 9 /* PGH, PGL, PGL/NDA versions */
133 #define PCLx1x_IORANGE 16
135 #define PCL812_CTR0 0
136 #define PCL812_CTR1 1
137 #define PCL812_CTR2 2
138 #define PCL812_CTRCTL 3
139 #define PCL812_AD_LO 4
140 #define PCL812_DA1_LO 4
141 #define PCL812_AD_HI 5
142 #define PCL812_DA1_HI 5
143 #define PCL812_DA2_LO 6
144 #define PCL812_DI_LO 6
145 #define PCL812_DA2_HI 7
146 #define PCL812_DI_HI 7
147 #define PCL812_CLRINT 8
148 #define PCL812_GAIN 9
149 #define PCL812_MUX 10
150 #define PCL812_MODE 11
151 #define PCL812_CNTENABLE 10
152 #define PCL812_SOFTTRIG 12
153 #define PCL812_DO_LO 13
154 #define PCL812_DO_HI 14
156 #define PCL812_DRDY 0x10 /* =0 data ready */
158 #define ACL8216_STATUS 8 /* 5. bit signalize data ready */
160 #define ACL8216_DRDY 0x20 /* =0 data ready */
162 #define MAX_CHANLIST_LEN 256 /* length of scan list */
164 static const struct comedi_lrange range_pcl812pg_ai = { 5, {
173 static const struct comedi_lrange range_pcl812pg2_ai = { 5, {
182 static const struct comedi_lrange range812_bipolar1_25 = { 1, {
187 static const struct comedi_lrange range812_bipolar0_625 = { 1, {
193 static const struct comedi_lrange range812_bipolar0_3125 = { 1, {
199 static const struct comedi_lrange range_pcl813b_ai = { 4, {
207 static const struct comedi_lrange range_pcl813b2_ai = { 4, {
215 static const struct comedi_lrange range_iso813_1_ai = { 5, {
224 static const struct comedi_lrange range_iso813_1_2_ai = { 5, {
233 static const struct comedi_lrange range_iso813_2_ai = { 4, {
241 static const struct comedi_lrange range_iso813_2_2_ai = { 4, {
249 static const struct comedi_lrange range_acl8113_1_ai = { 4, {
257 static const struct comedi_lrange range_acl8113_1_2_ai = { 4, {
265 static const struct comedi_lrange range_acl8113_2_ai = { 3, {
272 static const struct comedi_lrange range_acl8113_2_2_ai = { 3, {
279 static const struct comedi_lrange range_acl8112dg_ai = { 9, {
292 static const struct comedi_lrange range_acl8112hg_ai = { 12, {
308 static const struct comedi_lrange range_a821pgh_ai = { 4, {
316 static int pcl812_attach(struct comedi_device *dev,
317 struct comedi_devconfig *it);
318 static int pcl812_detach(struct comedi_device *dev);
320 struct pcl812_board {
322 const char *name; /* board name */
323 int board_type; /* type of this board */
324 int n_aichan; /* num of AI chans in S.E. */
325 int n_aichan_diff; /* DIFF num of chans */
326 int n_aochan; /* num of DA chans */
327 int n_dichan; /* DI and DO chans */
329 int ai_maxdata; /* AI resolution */
330 unsigned int ai_ns_min; /* max sample speed of card v ns */
331 unsigned int i8254_osc_base; /* clock base */
332 const struct comedi_lrange *rangelist_ai; /* rangelist for A/D */
333 const struct comedi_lrange *rangelist_ao; /* rangelist for D/A */
334 unsigned int IRQbits; /* allowed IRQ */
335 unsigned char DMAbits; /* allowed DMA chans */
336 unsigned char io_range; /* iorange for this board */
337 unsigned char haveMPC508; /* 1=board use MPC508A multiplexor */
340 static const struct pcl812_board boardtypes[] = {
341 {"pcl812", boardPCL812, 16, 0, 2, 16, 16, 0x0fff,
342 33000, 500, &range_bipolar10, &range_unipolar5,
343 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
344 {"pcl812pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
345 33000, 500, &range_pcl812pg_ai, &range_unipolar5,
346 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
347 {"acl8112pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
348 10000, 500, &range_pcl812pg_ai, &range_unipolar5,
349 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
350 {"acl8112dg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
351 10000, 500, &range_acl8112dg_ai, &range_unipolar5,
352 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
353 {"acl8112hg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
354 10000, 500, &range_acl8112hg_ai, &range_unipolar5,
355 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
356 {"a821pgl", boardA821, 16, 8, 1, 16, 16, 0x0fff,
357 10000, 500, &range_pcl813b_ai, &range_unipolar5,
358 0x000c, 0x00, PCLx1x_IORANGE, 0},
359 {"a821pglnda", boardA821, 16, 8, 0, 0, 0, 0x0fff,
360 10000, 500, &range_pcl813b_ai, NULL,
361 0x000c, 0x00, PCLx1x_IORANGE, 0},
362 {"a821pgh", boardA821, 16, 8, 1, 16, 16, 0x0fff,
363 10000, 500, &range_a821pgh_ai, &range_unipolar5,
364 0x000c, 0x00, PCLx1x_IORANGE, 0},
365 {"a822pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
366 10000, 500, &range_acl8112dg_ai, &range_unipolar5,
367 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
368 {"a822pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
369 10000, 500, &range_acl8112hg_ai, &range_unipolar5,
370 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
371 {"a823pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
372 8000, 500, &range_acl8112dg_ai, &range_unipolar5,
373 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
374 {"a823pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
375 8000, 500, &range_acl8112hg_ai, &range_unipolar5,
376 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
377 {"pcl813", boardPCL813, 32, 0, 0, 0, 0, 0x0fff,
378 0, 0, &range_pcl813b_ai, NULL,
379 0x0000, 0x00, PCLx1x_IORANGE, 0},
380 {"pcl813b", boardPCL813B, 32, 0, 0, 0, 0, 0x0fff,
381 0, 0, &range_pcl813b_ai, NULL,
382 0x0000, 0x00, PCLx1x_IORANGE, 0},
383 {"acl8113", boardACL8113, 32, 0, 0, 0, 0, 0x0fff,
384 0, 0, &range_acl8113_1_ai, NULL,
385 0x0000, 0x00, PCLx1x_IORANGE, 0},
386 {"iso813", boardISO813, 32, 0, 0, 0, 0, 0x0fff,
387 0, 0, &range_iso813_1_ai, NULL,
388 0x0000, 0x00, PCLx1x_IORANGE, 0},
389 {"acl8216", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
390 10000, 500, &range_pcl813b2_ai, &range_unipolar5,
391 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
392 {"a826pg", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
393 10000, 500, &range_pcl813b2_ai, &range_unipolar5,
394 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
397 #define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl812_board))
398 #define this_board ((const struct pcl812_board *)dev->board_ptr)
400 static struct comedi_driver driver_pcl812 = {
401 .driver_name = "pcl812",
402 .module = THIS_MODULE,
403 .attach = pcl812_attach,
404 .detach = pcl812_detach,
405 .board_name = &boardtypes[0].name,
406 .num_names = n_boardtypes,
407 .offset = sizeof(struct pcl812_board),
410 COMEDI_INITCLEANUP(driver_pcl812);
412 struct pcl812_private {
414 unsigned char valid; /* =1 device is OK */
415 unsigned char dma; /* >0 use dma ( usedDMA channel) */
416 unsigned char use_diff; /* =1 diff inputs */
417 unsigned char use_MPC; /* 1=board uses MPC508A multiplexor */
418 unsigned char use_ext_trg; /* 1=board uses external trigger */
419 unsigned char range_correction; /* =1 we must add 1 to range number */
420 unsigned char old_chan_reg; /* lastly used chan/gain pair */
421 unsigned char old_gain_reg;
422 unsigned char mode_reg_int; /* there is stored INT number for some card */
423 unsigned char ai_neverending; /* =1 we do unlimited AI */
424 unsigned char ai_eos; /* 1=EOS wake up */
425 unsigned char ai_dma; /* =1 we use DMA */
426 unsigned int ai_poll_ptr; /* how many sampes transfer poll */
427 unsigned int ai_scans; /* len of scanlist */
428 unsigned int ai_act_scan; /* how many scans we finished */
429 unsigned int ai_chanlist[MAX_CHANLIST_LEN]; /* our copy of channel/range list */
430 unsigned int ai_n_chan; /* how many channels is measured */
431 unsigned int ai_flags; /* flaglist */
432 unsigned int ai_data_len; /* len of data buffer */
433 short *ai_data; /* data buffer */
434 unsigned int ai_is16b; /* =1 we have 16 bit card */
435 unsigned long dmabuf[2]; /* PTR to DMA buf */
436 unsigned int dmapages[2]; /* how many pages we have allocated */
437 unsigned int hwdmaptr[2]; /* HW PTR to DMA buf */
438 unsigned int hwdmasize[2]; /* DMA buf size in bytes */
439 unsigned int dmabytestomove[2]; /* how many bytes DMA transfer */
440 int next_dma_buf; /* which buffer is next to use */
441 unsigned int dma_runs_to_end; /* how many times we must switch DMA buffers */
442 unsigned int last_dma_run; /* how many bytes to transfer on last DMA buffer */
443 unsigned int max_812_ai_mode0_rangewait; /* setling time for gain */
444 unsigned int ao_readback[2]; /* data for AO readback */
447 #define devpriv ((struct pcl812_private *)dev->private)
450 ==============================================================================
452 static void start_pacer(struct comedi_device *dev, int mode,
453 unsigned int divisor1, unsigned int divisor2);
454 static void setup_range_channel(struct comedi_device *dev,
455 struct comedi_subdevice *s,
456 unsigned int rangechan, char wait);
457 static int pcl812_ai_cancel(struct comedi_device *dev,
458 struct comedi_subdevice *s);
460 ==============================================================================
462 static int pcl812_ai_insn_read(struct comedi_device *dev,
463 struct comedi_subdevice *s,
464 struct comedi_insn *insn, unsigned int *data)
469 outb(devpriv->mode_reg_int | 1, dev->iobase + PCL812_MODE); /* select software trigger */
470 setup_range_channel(dev, s, insn->chanspec, 1); /* select channel and renge */
471 for (n = 0; n < insn->n; n++) {
472 outb(255, dev->iobase + PCL812_SOFTTRIG); /* start conversion */
474 timeout = 50; /* wait max 50us, it must finish under 33us */
476 hi = inb(dev->iobase + PCL812_AD_HI);
477 if (!(hi & PCL812_DRDY))
482 ("comedi%d: pcl812: (%s at 0x%lx) A/D insn read timeout\n",
483 dev->minor, dev->board_name, dev->iobase);
484 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
488 data[n] = ((hi & 0xf) << 8) | inb(dev->iobase + PCL812_AD_LO);
490 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
495 ==============================================================================
497 static int acl8216_ai_insn_read(struct comedi_device *dev,
498 struct comedi_subdevice *s,
499 struct comedi_insn *insn, unsigned int *data)
504 outb(1, dev->iobase + PCL812_MODE); /* select software trigger */
505 setup_range_channel(dev, s, insn->chanspec, 1); /* select channel and renge */
506 for (n = 0; n < insn->n; n++) {
507 outb(255, dev->iobase + PCL812_SOFTTRIG); /* start conversion */
509 timeout = 50; /* wait max 50us, it must finish under 33us */
511 if (!(inb(dev->iobase + ACL8216_STATUS) & ACL8216_DRDY))
516 ("comedi%d: pcl812: (%s at 0x%lx) A/D insn read timeout\n",
517 dev->minor, dev->board_name, dev->iobase);
518 outb(0, dev->iobase + PCL812_MODE);
524 PCL812_AD_HI) << 8) | inb(dev->iobase + PCL812_AD_LO);
526 outb(0, dev->iobase + PCL812_MODE);
531 ==============================================================================
533 static int pcl812_ao_insn_write(struct comedi_device *dev,
534 struct comedi_subdevice *s,
535 struct comedi_insn *insn, unsigned int *data)
537 int chan = CR_CHAN(insn->chanspec);
540 for (i = 0; i < insn->n; i++) {
541 outb((data[i] & 0xff),
542 dev->iobase + (chan ? PCL812_DA2_LO : PCL812_DA1_LO));
543 outb((data[i] >> 8) & 0x0f,
544 dev->iobase + (chan ? PCL812_DA2_HI : PCL812_DA1_HI));
545 devpriv->ao_readback[chan] = data[i];
552 ==============================================================================
554 static int pcl812_ao_insn_read(struct comedi_device *dev,
555 struct comedi_subdevice *s,
556 struct comedi_insn *insn, unsigned int *data)
558 int chan = CR_CHAN(insn->chanspec);
561 for (i = 0; i < insn->n; i++) {
562 data[i] = devpriv->ao_readback[chan];
569 ==============================================================================
571 static int pcl812_di_insn_bits(struct comedi_device *dev,
572 struct comedi_subdevice *s,
573 struct comedi_insn *insn, unsigned int *data)
578 data[1] = inb(dev->iobase + PCL812_DI_LO);
579 data[1] |= inb(dev->iobase + PCL812_DI_HI) << 8;
585 ==============================================================================
587 static int pcl812_do_insn_bits(struct comedi_device *dev,
588 struct comedi_subdevice *s,
589 struct comedi_insn *insn, unsigned int *data)
595 s->state &= ~data[0];
596 s->state |= data[0] & data[1];
597 outb(s->state & 0xff, dev->iobase + PCL812_DO_LO);
598 outb((s->state >> 8), dev->iobase + PCL812_DO_HI);
605 #ifdef PCL812_EXTDEBUG
607 ==============================================================================
609 static void pcl812_cmdtest_out(int e, struct comedi_cmd *cmd)
611 printk("pcl812 e=%d startsrc=%x scansrc=%x convsrc=%x\n", e,
612 cmd->start_src, cmd->scan_begin_src, cmd->convert_src);
613 printk("pcl812 e=%d startarg=%d scanarg=%d convarg=%d\n", e,
614 cmd->start_arg, cmd->scan_begin_arg, cmd->convert_arg);
615 printk("pcl812 e=%d stopsrc=%x scanend=%x\n", e, cmd->stop_src,
617 printk("pcl812 e=%d stoparg=%d scanendarg=%d chanlistlen=%d\n", e,
618 cmd->stop_arg, cmd->scan_end_arg, cmd->chanlist_len);
623 ==============================================================================
625 static int pcl812_ai_cmdtest(struct comedi_device *dev,
626 struct comedi_subdevice *s, struct comedi_cmd *cmd)
629 int tmp, divisor1, divisor2;
631 #ifdef PCL812_EXTDEBUG
632 printk("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...)\n");
633 pcl812_cmdtest_out(-1, cmd);
635 /* step 1: make sure trigger sources are trivially valid */
637 tmp = cmd->start_src;
638 cmd->start_src &= TRIG_NOW;
639 if (!cmd->start_src || tmp != cmd->start_src)
642 tmp = cmd->scan_begin_src;
643 cmd->scan_begin_src &= TRIG_FOLLOW;
644 if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
647 tmp = cmd->convert_src;
648 if (devpriv->use_ext_trg) {
649 cmd->convert_src &= TRIG_EXT;
651 cmd->convert_src &= TRIG_TIMER;
653 if (!cmd->convert_src || tmp != cmd->convert_src)
656 tmp = cmd->scan_end_src;
657 cmd->scan_end_src &= TRIG_COUNT;
658 if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
662 cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
663 if (!cmd->stop_src || tmp != cmd->stop_src)
667 #ifdef PCL812_EXTDEBUG
668 pcl812_cmdtest_out(1, cmd);
670 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=1\n",
676 /* step 2: make sure trigger sources are unique and mutually compatible */
678 if (cmd->start_src != TRIG_NOW) {
679 cmd->start_src = TRIG_NOW;
683 if (cmd->scan_begin_src != TRIG_FOLLOW) {
684 cmd->scan_begin_src = TRIG_FOLLOW;
688 if (devpriv->use_ext_trg) {
689 if (cmd->convert_src != TRIG_EXT) {
690 cmd->convert_src = TRIG_EXT;
694 if (cmd->convert_src != TRIG_TIMER) {
695 cmd->convert_src = TRIG_TIMER;
700 if (cmd->scan_end_src != TRIG_COUNT) {
701 cmd->scan_end_src = TRIG_COUNT;
705 if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT)
709 #ifdef PCL812_EXTDEBUG
710 pcl812_cmdtest_out(2, cmd);
712 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=2\n",
718 /* step 3: make sure arguments are trivially compatible */
720 if (cmd->start_arg != 0) {
725 if (cmd->scan_begin_arg != 0) {
726 cmd->scan_begin_arg = 0;
730 if (cmd->convert_src == TRIG_TIMER) {
731 if (cmd->convert_arg < this_board->ai_ns_min) {
732 cmd->convert_arg = this_board->ai_ns_min;
735 } else { /* TRIG_EXT */
736 if (cmd->convert_arg != 0) {
737 cmd->convert_arg = 0;
742 if (!cmd->chanlist_len) {
743 cmd->chanlist_len = 1;
746 if (cmd->chanlist_len > MAX_CHANLIST_LEN) {
747 cmd->chanlist_len = this_board->n_aichan;
750 if (cmd->scan_end_arg != cmd->chanlist_len) {
751 cmd->scan_end_arg = cmd->chanlist_len;
754 if (cmd->stop_src == TRIG_COUNT) {
755 if (!cmd->stop_arg) {
759 } else { /* TRIG_NONE */
760 if (cmd->stop_arg != 0) {
767 #ifdef PCL812_EXTDEBUG
768 pcl812_cmdtest_out(3, cmd);
770 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=3\n",
776 /* step 4: fix up any arguments */
778 if (cmd->convert_src == TRIG_TIMER) {
779 tmp = cmd->convert_arg;
780 i8253_cascade_ns_to_timer(this_board->i8254_osc_base, &divisor1,
781 &divisor2, &cmd->convert_arg,
782 cmd->flags & TRIG_ROUND_MASK);
783 if (cmd->convert_arg < this_board->ai_ns_min)
784 cmd->convert_arg = this_board->ai_ns_min;
785 if (tmp != cmd->convert_arg)
790 #ifdef PCL812_EXTDEBUG
792 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=4\n",
802 ==============================================================================
804 static int pcl812_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
806 unsigned int divisor1 = 0, divisor2 = 0, i, dma_flags, bytes;
807 struct comedi_cmd *cmd = &s->async->cmd;
809 #ifdef PCL812_EXTDEBUG
810 printk("pcl812 EDBG: BGN: pcl812_ai_cmd(...)\n");
813 if (cmd->start_src != TRIG_NOW)
815 if (cmd->scan_begin_src != TRIG_FOLLOW)
817 if (devpriv->use_ext_trg) {
818 if (cmd->convert_src != TRIG_EXT)
821 if (cmd->convert_src != TRIG_TIMER)
824 if (cmd->scan_end_src != TRIG_COUNT)
826 if (cmd->scan_end_arg != cmd->chanlist_len)
828 if (cmd->chanlist_len > MAX_CHANLIST_LEN)
831 if (cmd->convert_src == TRIG_TIMER) {
832 if (cmd->convert_arg < this_board->ai_ns_min)
833 cmd->convert_arg = this_board->ai_ns_min;
834 i8253_cascade_ns_to_timer(this_board->i8254_osc_base,
835 &divisor1, &divisor2,
837 cmd->flags & TRIG_ROUND_MASK);
840 start_pacer(dev, -1, 0, 0); /* stop pacer */
842 devpriv->ai_n_chan = cmd->chanlist_len;
843 memcpy(devpriv->ai_chanlist, cmd->chanlist,
844 sizeof(unsigned int) * cmd->scan_end_arg);
845 setup_range_channel(dev, s, devpriv->ai_chanlist[0], 1); /* select first channel and range */
847 if (devpriv->dma) { /* check if we can use DMA transfer */
849 for (i = 1; i < devpriv->ai_n_chan; i++)
850 if (devpriv->ai_chanlist[0] != devpriv->ai_chanlist[i]) {
851 devpriv->ai_dma = 0; /* we cann't use DMA :-( */
857 devpriv->ai_flags = cmd->flags;
858 devpriv->ai_data_len = s->async->prealloc_bufsz;
859 devpriv->ai_data = s->async->prealloc_buf;
860 if (cmd->stop_src == TRIG_COUNT) {
861 devpriv->ai_scans = cmd->stop_arg;
862 devpriv->ai_neverending = 0;
864 devpriv->ai_scans = 0;
865 devpriv->ai_neverending = 1;
868 devpriv->ai_act_scan = 0;
869 devpriv->ai_poll_ptr = 0;
870 s->async->cur_chan = 0;
872 if ((devpriv->ai_flags & TRIG_WAKE_EOS)) { /* don't we want wake up every scan? */
874 if (devpriv->ai_n_chan == 1)
875 devpriv->ai_dma = 0; /* DMA is useless for this situation */
878 if (devpriv->ai_dma) {
879 if (devpriv->ai_eos) { /* we use EOS, so adapt DMA buffer to one scan */
880 devpriv->dmabytestomove[0] =
881 devpriv->ai_n_chan * sizeof(short);
882 devpriv->dmabytestomove[1] =
883 devpriv->ai_n_chan * sizeof(short);
884 devpriv->dma_runs_to_end = 1;
886 devpriv->dmabytestomove[0] = devpriv->hwdmasize[0];
887 devpriv->dmabytestomove[1] = devpriv->hwdmasize[1];
888 if (devpriv->ai_data_len < devpriv->hwdmasize[0])
889 devpriv->dmabytestomove[0] =
890 devpriv->ai_data_len;
891 if (devpriv->ai_data_len < devpriv->hwdmasize[1])
892 devpriv->dmabytestomove[1] =
893 devpriv->ai_data_len;
894 if (devpriv->ai_neverending) {
895 devpriv->dma_runs_to_end = 1;
897 bytes = devpriv->ai_n_chan * devpriv->ai_scans * sizeof(short); /* how many samples we must transfer? */
898 devpriv->dma_runs_to_end = bytes / devpriv->dmabytestomove[0]; /* how many DMA pages we must fill */
899 devpriv->last_dma_run = bytes % devpriv->dmabytestomove[0]; /* on last dma transfer must be moved */
900 if (devpriv->dma_runs_to_end == 0)
901 devpriv->dmabytestomove[0] =
902 devpriv->last_dma_run;
903 devpriv->dma_runs_to_end--;
906 if (devpriv->dmabytestomove[0] > devpriv->hwdmasize[0]) {
907 devpriv->dmabytestomove[0] = devpriv->hwdmasize[0];
910 if (devpriv->dmabytestomove[1] > devpriv->hwdmasize[1]) {
911 devpriv->dmabytestomove[1] = devpriv->hwdmasize[1];
914 devpriv->next_dma_buf = 0;
915 set_dma_mode(devpriv->dma, DMA_MODE_READ);
916 dma_flags = claim_dma_lock();
917 clear_dma_ff(devpriv->dma);
918 set_dma_addr(devpriv->dma, devpriv->hwdmaptr[0]);
919 set_dma_count(devpriv->dma, devpriv->dmabytestomove[0]);
920 release_dma_lock(dma_flags);
921 enable_dma(devpriv->dma);
922 #ifdef PCL812_EXTDEBUG
924 ("pcl812 EDBG: DMA %d PTR 0x%0x/0x%0x LEN %u/%u EOS %d\n",
925 devpriv->dma, devpriv->hwdmaptr[0],
926 devpriv->hwdmaptr[1], devpriv->dmabytestomove[0],
927 devpriv->dmabytestomove[1], devpriv->ai_eos);
931 switch (cmd->convert_src) {
933 start_pacer(dev, 1, divisor1, divisor2);
937 if (devpriv->ai_dma) {
938 outb(devpriv->mode_reg_int | 2, dev->iobase + PCL812_MODE); /* let's go! */
940 outb(devpriv->mode_reg_int | 6, dev->iobase + PCL812_MODE); /* let's go! */
943 #ifdef PCL812_EXTDEBUG
944 printk("pcl812 EDBG: END: pcl812_ai_cmd(...)\n");
951 ==============================================================================
953 static irqreturn_t interrupt_pcl812_ai_int(int irq, void *d)
956 unsigned int mask, timeout;
957 struct comedi_device *dev = d;
958 struct comedi_subdevice *s = dev->subdevices + 0;
959 unsigned int next_chan;
961 s->async->events = 0;
963 timeout = 50; /* wait max 50us, it must finish under 33us */
964 if (devpriv->ai_is16b) {
967 if (!(inb(dev->iobase + ACL8216_STATUS) & ACL8216_DRDY)) {
976 if (!(inb(dev->iobase + PCL812_AD_HI) & PCL812_DRDY)) {
986 ("comedi%d: pcl812: (%s at 0x%lx) A/D cmd IRQ without DRDY!\n",
987 dev->minor, dev->board_name, dev->iobase);
988 pcl812_ai_cancel(dev, s);
989 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
990 comedi_event(dev, s);
994 comedi_buf_put(s->async,
995 ((inb(dev->iobase + PCL812_AD_HI) << 8) |
996 inb(dev->iobase + PCL812_AD_LO)) & mask);
998 /* Set up next channel. Added by abbotti 2010-01-20, but untested. */
999 next_chan = s->async->cur_chan + 1;
1000 if (next_chan >= devpriv->ai_n_chan)
1002 if (devpriv->ai_chanlist[s->async->cur_chan] !=
1003 devpriv->ai_chanlist[next_chan])
1004 setup_range_channel(dev, s, devpriv->ai_chanlist[next_chan], 0);
1006 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
1008 s->async->cur_chan = next_chan;
1009 if (next_chan == 0) { /* one scan done */
1010 devpriv->ai_act_scan++;
1011 if (!(devpriv->ai_neverending))
1012 if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */
1013 pcl812_ai_cancel(dev, s);
1014 s->async->events |= COMEDI_CB_EOA;
1018 comedi_event(dev, s);
1023 ==============================================================================
1025 static void transfer_from_dma_buf(struct comedi_device *dev,
1026 struct comedi_subdevice *s, short *ptr,
1027 unsigned int bufptr, unsigned int len)
1031 s->async->events = 0;
1032 for (i = len; i; i--) {
1033 comedi_buf_put(s->async, ptr[bufptr++]); /* get one sample */
1035 s->async->cur_chan++;
1036 if (s->async->cur_chan >= devpriv->ai_n_chan) {
1037 s->async->cur_chan = 0;
1038 devpriv->ai_act_scan++;
1039 if (!devpriv->ai_neverending)
1040 if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */
1041 pcl812_ai_cancel(dev, s);
1042 s->async->events |= COMEDI_CB_EOA;
1048 comedi_event(dev, s);
1052 ==============================================================================
1054 static irqreturn_t interrupt_pcl812_ai_dma(int irq, void *d)
1056 struct comedi_device *dev = d;
1057 struct comedi_subdevice *s = dev->subdevices + 0;
1058 unsigned long dma_flags;
1062 #ifdef PCL812_EXTDEBUG
1063 printk("pcl812 EDBG: BGN: interrupt_pcl812_ai_dma(...)\n");
1065 ptr = (short *)devpriv->dmabuf[devpriv->next_dma_buf];
1066 len = (devpriv->dmabytestomove[devpriv->next_dma_buf] >> 1) -
1067 devpriv->ai_poll_ptr;
1069 devpriv->next_dma_buf = 1 - devpriv->next_dma_buf;
1070 disable_dma(devpriv->dma);
1071 set_dma_mode(devpriv->dma, DMA_MODE_READ);
1072 dma_flags = claim_dma_lock();
1073 set_dma_addr(devpriv->dma, devpriv->hwdmaptr[devpriv->next_dma_buf]);
1074 if (devpriv->ai_eos) {
1075 set_dma_count(devpriv->dma,
1076 devpriv->dmabytestomove[devpriv->next_dma_buf]);
1078 if (devpriv->dma_runs_to_end) {
1079 set_dma_count(devpriv->dma,
1080 devpriv->dmabytestomove[devpriv->
1083 set_dma_count(devpriv->dma, devpriv->last_dma_run);
1085 devpriv->dma_runs_to_end--;
1087 release_dma_lock(dma_flags);
1088 enable_dma(devpriv->dma);
1090 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
1092 bufptr = devpriv->ai_poll_ptr;
1093 devpriv->ai_poll_ptr = 0;
1095 transfer_from_dma_buf(dev, s, ptr, bufptr, len);
1097 #ifdef PCL812_EXTDEBUG
1098 printk("pcl812 EDBG: END: interrupt_pcl812_ai_dma(...)\n");
1104 ==============================================================================
1106 static irqreturn_t interrupt_pcl812(int irq, void *d)
1108 struct comedi_device *dev = d;
1110 if (!dev->attached) {
1111 comedi_error(dev, "spurious interrupt");
1114 if (devpriv->ai_dma) {
1115 return interrupt_pcl812_ai_dma(irq, d);
1117 return interrupt_pcl812_ai_int(irq, d);
1122 ==============================================================================
1124 static int pcl812_ai_poll(struct comedi_device *dev, struct comedi_subdevice *s)
1126 unsigned long flags;
1127 unsigned int top1, top2, i;
1129 if (!devpriv->ai_dma)
1130 return 0; /* poll is valid only for DMA transfer */
1132 spin_lock_irqsave(&dev->spinlock, flags);
1134 for (i = 0; i < 10; i++) {
1135 top1 = get_dma_residue(devpriv->ai_dma); /* where is now DMA */
1136 top2 = get_dma_residue(devpriv->ai_dma);
1142 spin_unlock_irqrestore(&dev->spinlock, flags);
1146 top1 = devpriv->dmabytestomove[1 - devpriv->next_dma_buf] - top1; /* where is now DMA in buffer */
1147 top1 >>= 1; /* sample position */
1148 top2 = top1 - devpriv->ai_poll_ptr;
1149 if (top2 < 1) { /* no new samples */
1150 spin_unlock_irqrestore(&dev->spinlock, flags);
1154 transfer_from_dma_buf(dev, s,
1155 (void *)devpriv->dmabuf[1 -
1156 devpriv->next_dma_buf],
1157 devpriv->ai_poll_ptr, top2);
1159 devpriv->ai_poll_ptr = top1; /* new buffer position */
1161 spin_unlock_irqrestore(&dev->spinlock, flags);
1163 return s->async->buf_write_count - s->async->buf_read_count;
1167 ==============================================================================
1169 static void setup_range_channel(struct comedi_device *dev,
1170 struct comedi_subdevice *s,
1171 unsigned int rangechan, char wait)
1173 unsigned char chan_reg = CR_CHAN(rangechan); /* normal board */
1174 unsigned char gain_reg = CR_RANGE(rangechan) + devpriv->range_correction; /* gain index */
1176 if ((chan_reg == devpriv->old_chan_reg)
1177 && (gain_reg == devpriv->old_gain_reg))
1178 return; /* we can return, no change */
1180 devpriv->old_chan_reg = chan_reg;
1181 devpriv->old_gain_reg = gain_reg;
1183 if (devpriv->use_MPC) {
1184 if (devpriv->use_diff) {
1185 chan_reg = chan_reg | 0x30; /* DIFF inputs */
1187 if (chan_reg & 0x80) {
1188 chan_reg = chan_reg | 0x20; /* SE inputs 8-15 */
1190 chan_reg = chan_reg | 0x10; /* SE inputs 0-7 */
1195 outb(chan_reg, dev->iobase + PCL812_MUX); /* select channel */
1196 outb(gain_reg, dev->iobase + PCL812_GAIN); /* select gain */
1199 udelay(devpriv->max_812_ai_mode0_rangewait); /* XXX this depends on selected range and can be very long for some high gain ranges! */
1204 ==============================================================================
1206 static void start_pacer(struct comedi_device *dev, int mode,
1207 unsigned int divisor1, unsigned int divisor2)
1209 #ifdef PCL812_EXTDEBUG
1210 printk("pcl812 EDBG: BGN: start_pacer(%d,%u,%u)\n", mode, divisor1,
1213 outb(0xb4, dev->iobase + PCL812_CTRCTL);
1214 outb(0x74, dev->iobase + PCL812_CTRCTL);
1218 outb(divisor2 & 0xff, dev->iobase + PCL812_CTR2);
1219 outb((divisor2 >> 8) & 0xff, dev->iobase + PCL812_CTR2);
1220 outb(divisor1 & 0xff, dev->iobase + PCL812_CTR1);
1221 outb((divisor1 >> 8) & 0xff, dev->iobase + PCL812_CTR1);
1223 #ifdef PCL812_EXTDEBUG
1224 printk("pcl812 EDBG: END: start_pacer(...)\n");
1229 ==============================================================================
1231 static void free_resources(struct comedi_device *dev)
1235 if (devpriv->dmabuf[0])
1236 free_pages(devpriv->dmabuf[0], devpriv->dmapages[0]);
1237 if (devpriv->dmabuf[1])
1238 free_pages(devpriv->dmabuf[1], devpriv->dmapages[1]);
1240 free_dma(devpriv->dma);
1243 free_irq(dev->irq, dev);
1245 release_region(dev->iobase, this_board->io_range);
1249 ==============================================================================
1251 static int pcl812_ai_cancel(struct comedi_device *dev,
1252 struct comedi_subdevice *s)
1254 #ifdef PCL812_EXTDEBUG
1255 printk("pcl812 EDBG: BGN: pcl812_ai_cancel(...)\n");
1257 if (devpriv->ai_dma)
1258 disable_dma(devpriv->dma);
1259 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
1260 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE); /* Stop A/D */
1261 start_pacer(dev, -1, 0, 0); /* stop 8254 */
1262 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
1263 #ifdef PCL812_EXTDEBUG
1264 printk("pcl812 EDBG: END: pcl812_ai_cancel(...)\n");
1270 ==============================================================================
1272 static void pcl812_reset(struct comedi_device *dev)
1274 #ifdef PCL812_EXTDEBUG
1275 printk("pcl812 EDBG: BGN: pcl812_reset(...)\n");
1277 outb(0, dev->iobase + PCL812_MUX);
1278 outb(0 + devpriv->range_correction, dev->iobase + PCL812_GAIN);
1279 devpriv->old_chan_reg = -1; /* invalidate chain/gain memory */
1280 devpriv->old_gain_reg = -1;
1282 switch (this_board->board_type) {
1287 outb(0, dev->iobase + PCL812_DA2_LO);
1288 outb(0, dev->iobase + PCL812_DA2_HI);
1290 outb(0, dev->iobase + PCL812_DA1_LO);
1291 outb(0, dev->iobase + PCL812_DA1_HI);
1292 start_pacer(dev, -1, 0, 0); /* stop 8254 */
1293 outb(0, dev->iobase + PCL812_DO_HI);
1294 outb(0, dev->iobase + PCL812_DO_LO);
1295 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
1296 outb(0, dev->iobase + PCL812_CLRINT);
1306 #ifdef PCL812_EXTDEBUG
1307 printk("pcl812 EDBG: END: pcl812_reset(...)\n");
1312 ==============================================================================
1314 static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1317 unsigned long iobase;
1320 unsigned long pages;
1321 struct comedi_subdevice *s;
1324 iobase = it->options[0];
1325 printk("comedi%d: pcl812: board=%s, ioport=0x%03lx", dev->minor,
1326 this_board->name, iobase);
1328 if (!request_region(iobase, this_board->io_range, "pcl812")) {
1329 printk("I/O port conflict\n");
1332 dev->iobase = iobase;
1334 ret = alloc_private(dev, sizeof(struct pcl812_private));
1336 free_resources(dev);
1337 return ret; /* Can't alloc mem */
1340 dev->board_name = this_board->name;
1343 if (this_board->IRQbits != 0) { /* board support IRQ */
1344 irq = it->options[1];
1345 if (irq) { /* we want to use IRQ */
1346 if (((1 << irq) & this_board->IRQbits) == 0) {
1348 (", IRQ %u is out of allowed range, DISABLING IT",
1350 irq = 0; /* Bad IRQ */
1353 (irq, interrupt_pcl812, 0, "pcl812", dev)) {
1355 (", unable to allocate IRQ %u, DISABLING IT",
1357 irq = 0; /* Can't use IRQ */
1359 printk(", irq=%u", irq);
1370 goto no_dma; /* if we haven't IRQ, we can't use DMA */
1371 if (this_board->DMAbits != 0) { /* board support DMA */
1372 dma = it->options[2];
1373 if (((1 << dma) & this_board->DMAbits) == 0) {
1374 printk(", DMA is out of allowed range, FAIL!\n");
1375 return -EINVAL; /* Bad DMA */
1377 ret = request_dma(dma, "pcl812");
1379 printk(", unable to allocate DMA %u, FAIL!\n", dma);
1380 return -EBUSY; /* DMA isn't free */
1383 printk(", dma=%u", dma);
1384 pages = 1; /* we want 8KB */
1385 devpriv->dmabuf[0] = __get_dma_pages(GFP_KERNEL, pages);
1386 if (!devpriv->dmabuf[0]) {
1387 printk(", unable to allocate DMA buffer, FAIL!\n");
1388 /* maybe experiment with try_to_free_pages() will help .... */
1389 free_resources(dev);
1390 return -EBUSY; /* no buffer :-( */
1392 devpriv->dmapages[0] = pages;
1393 devpriv->hwdmaptr[0] = virt_to_bus((void *)devpriv->dmabuf[0]);
1394 devpriv->hwdmasize[0] = PAGE_SIZE * (1 << pages);
1395 devpriv->dmabuf[1] = __get_dma_pages(GFP_KERNEL, pages);
1396 if (!devpriv->dmabuf[1]) {
1397 printk(", unable to allocate DMA buffer, FAIL!\n");
1398 free_resources(dev);
1401 devpriv->dmapages[1] = pages;
1402 devpriv->hwdmaptr[1] = virt_to_bus((void *)devpriv->dmabuf[1]);
1403 devpriv->hwdmasize[1] = PAGE_SIZE * (1 << pages);
1408 if (this_board->n_aichan > 0)
1410 if (this_board->n_aochan > 0)
1412 if (this_board->n_dichan > 0)
1414 if (this_board->n_dochan > 0)
1417 ret = alloc_subdevices(dev, n_subdevices);
1419 free_resources(dev);
1426 if (this_board->n_aichan > 0) {
1427 s = dev->subdevices + subdev;
1428 s->type = COMEDI_SUBD_AI;
1429 s->subdev_flags = SDF_READABLE;
1430 switch (this_board->board_type) {
1432 if (it->options[2] == 1) {
1433 s->n_chan = this_board->n_aichan_diff;
1434 s->subdev_flags |= SDF_DIFF;
1435 devpriv->use_diff = 1;
1437 s->n_chan = this_board->n_aichan;
1438 s->subdev_flags |= SDF_GROUND;
1443 if (it->options[4] == 1) {
1444 s->n_chan = this_board->n_aichan_diff;
1445 s->subdev_flags |= SDF_DIFF;
1446 devpriv->use_diff = 1;
1448 s->n_chan = this_board->n_aichan;
1449 s->subdev_flags |= SDF_GROUND;
1453 s->n_chan = this_board->n_aichan;
1454 s->subdev_flags |= SDF_GROUND;
1457 s->maxdata = this_board->ai_maxdata;
1458 s->len_chanlist = MAX_CHANLIST_LEN;
1459 s->range_table = this_board->rangelist_ai;
1460 if (this_board->board_type == boardACL8216) {
1461 s->insn_read = acl8216_ai_insn_read;
1463 s->insn_read = pcl812_ai_insn_read;
1465 devpriv->use_MPC = this_board->haveMPC508;
1466 s->cancel = pcl812_ai_cancel;
1468 dev->read_subdev = s;
1469 s->subdev_flags |= SDF_CMD_READ;
1470 s->do_cmdtest = pcl812_ai_cmdtest;
1471 s->do_cmd = pcl812_ai_cmd;
1472 s->poll = pcl812_ai_poll;
1474 switch (this_board->board_type) {
1476 if (it->options[4] == 1)
1477 s->range_table = &range_pcl812pg2_ai;
1480 switch (it->options[4]) {
1482 s->range_table = &range_bipolar10;
1485 s->range_table = &range_bipolar5;
1488 s->range_table = &range_bipolar2_5;
1491 s->range_table = &range812_bipolar1_25;
1494 s->range_table = &range812_bipolar0_625;
1497 s->range_table = &range812_bipolar0_3125;
1500 s->range_table = &range_bipolar10;
1503 (", incorrect range number %d, changing to 0 (+/-10V)",
1510 if (it->options[1] == 1)
1511 s->range_table = &range_pcl813b2_ai;
1514 switch (it->options[1]) {
1516 s->range_table = &range_iso813_1_ai;
1519 s->range_table = &range_iso813_1_2_ai;
1522 s->range_table = &range_iso813_2_ai;
1523 devpriv->range_correction = 1;
1526 s->range_table = &range_iso813_2_2_ai;
1527 devpriv->range_correction = 1;
1530 s->range_table = &range_iso813_1_ai;
1533 (", incorrect range number %d, changing to 0 ",
1539 switch (it->options[1]) {
1541 s->range_table = &range_acl8113_1_ai;
1544 s->range_table = &range_acl8113_1_2_ai;
1547 s->range_table = &range_acl8113_2_ai;
1548 devpriv->range_correction = 1;
1551 s->range_table = &range_acl8113_2_2_ai;
1552 devpriv->range_correction = 1;
1555 s->range_table = &range_acl8113_1_ai;
1558 (", incorrect range number %d, changing to 0 ",
1568 if (this_board->n_aochan > 0) {
1569 s = dev->subdevices + subdev;
1570 s->type = COMEDI_SUBD_AO;
1571 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
1572 s->n_chan = this_board->n_aochan;
1574 s->len_chanlist = 1;
1575 s->range_table = this_board->rangelist_ao;
1576 s->insn_read = pcl812_ao_insn_read;
1577 s->insn_write = pcl812_ao_insn_write;
1578 switch (this_board->board_type) {
1580 if (it->options[3] == 1)
1581 s->range_table = &range_unipolar10;
1587 if (it->options[5] == 1)
1588 s->range_table = &range_unipolar10;
1589 if (it->options[5] == 2)
1590 s->range_table = &range_unknown;
1597 if (this_board->n_dichan > 0) {
1598 s = dev->subdevices + subdev;
1599 s->type = COMEDI_SUBD_DI;
1600 s->subdev_flags = SDF_READABLE;
1601 s->n_chan = this_board->n_dichan;
1603 s->len_chanlist = this_board->n_dichan;
1604 s->range_table = &range_digital;
1605 s->insn_bits = pcl812_di_insn_bits;
1609 /* digital output */
1610 if (this_board->n_dochan > 0) {
1611 s = dev->subdevices + subdev;
1612 s->type = COMEDI_SUBD_DO;
1613 s->subdev_flags = SDF_WRITABLE;
1614 s->n_chan = this_board->n_dochan;
1616 s->len_chanlist = this_board->n_dochan;
1617 s->range_table = &range_digital;
1618 s->insn_bits = pcl812_do_insn_bits;
1622 switch (this_board->board_type) {
1624 devpriv->ai_is16b = 1;
1628 devpriv->max_812_ai_mode0_rangewait = 1;
1629 if (it->options[3] > 0)
1630 devpriv->use_ext_trg = 1; /* we use external trigger */
1632 devpriv->max_812_ai_mode0_rangewait = 1;
1633 devpriv->mode_reg_int = (irq << 4) & 0xf0;
1639 devpriv->max_812_ai_mode0_rangewait = 5; /* maybe there must by greatest timeout */
1652 ==============================================================================
1654 static int pcl812_detach(struct comedi_device *dev)
1657 #ifdef PCL812_EXTDEBUG
1658 printk("comedi%d: pcl812: remove\n", dev->minor);
1660 free_resources(dev);