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 unknow (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 unknow (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 unknow (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 "../comedidev.h"
112 #include <linux/delay.h>
113 #include <linux/ioport.h>
118 #undef PCL812_EXTDEBUG /* if this is defined then a lot of messages is printed */
120 // hardware types of the cards
121 #define boardPCL812PG 0 /* and ACL-8112PG */
122 #define boardPCL813B 1
123 #define boardPCL812 2
124 #define boardPCL813 3
125 #define boardISO813 5
126 #define boardACL8113 6
127 #define boardACL8112 7 /* ACL-8112DG/HG, A-822PGL/PGH, A-823PGL/PGH */
128 #define boardACL8216 8 /* and ICP DAS A-826PG */
129 #define boardA821 9 /* PGH, PGL, PGL/NDA versions */
131 #define PCLx1x_IORANGE 16
133 #define PCL812_CTR0 0
134 #define PCL812_CTR1 1
135 #define PCL812_CTR2 2
136 #define PCL812_CTRCTL 3
137 #define PCL812_AD_LO 4
138 #define PCL812_DA1_LO 4
139 #define PCL812_AD_HI 5
140 #define PCL812_DA1_HI 5
141 #define PCL812_DA2_LO 6
142 #define PCL812_DI_LO 6
143 #define PCL812_DA2_HI 7
144 #define PCL812_DI_HI 7
145 #define PCL812_CLRINT 8
146 #define PCL812_GAIN 9
147 #define PCL812_MUX 10
148 #define PCL812_MODE 11
149 #define PCL812_CNTENABLE 10
150 #define PCL812_SOFTTRIG 12
151 #define PCL812_DO_LO 13
152 #define PCL812_DO_HI 14
154 #define PCL812_DRDY 0x10 /* =0 data ready */
156 #define ACL8216_STATUS 8 /* 5. bit signalize data ready */
158 #define ACL8216_DRDY 0x20 /* =0 data ready */
160 #define MAX_CHANLIST_LEN 256 /* length of scan list */
162 static const comedi_lrange range_pcl812pg_ai = { 5, {
170 static const comedi_lrange range_pcl812pg2_ai = { 5, {
178 static const comedi_lrange range812_bipolar1_25 = { 1, {
182 static const comedi_lrange range812_bipolar0_625 = { 1, {
186 static const comedi_lrange range812_bipolar0_3125 = { 1, {
190 static const comedi_lrange range_pcl813b_ai = { 4, {
197 static const comedi_lrange range_pcl813b2_ai = { 4, {
204 static const comedi_lrange range_iso813_1_ai = { 5, {
212 static const comedi_lrange range_iso813_1_2_ai = { 5, {
220 static const comedi_lrange range_iso813_2_ai = { 4, {
227 static const comedi_lrange range_iso813_2_2_ai = { 4, {
234 static const comedi_lrange range_acl8113_1_ai = { 4, {
241 static const comedi_lrange range_acl8113_1_2_ai = { 4, {
248 static const comedi_lrange range_acl8113_2_ai = { 3, {
254 static const comedi_lrange range_acl8113_2_2_ai = { 3, {
260 static const comedi_lrange range_acl8112dg_ai = { 9, {
272 static const comedi_lrange range_acl8112hg_ai = { 12, {
287 static const comedi_lrange range_a821pgh_ai = { 4, {
295 static int pcl812_attach(comedi_device * dev, comedi_devconfig * it);
296 static int pcl812_detach(comedi_device * dev);
299 const char *name; // board name
300 int board_type; // type of this board
301 int n_aichan; // num of AI chans in S.E.
302 int n_aichan_diff; // DIFF num of chans
303 int n_aochan; // num of DA chans
304 int n_dichan; // DI and DO chans
306 int ai_maxdata; // AI resolution
307 unsigned int ai_ns_min; // max sample speed of card v ns
308 unsigned int i8254_osc_base; // clock base
309 const comedi_lrange *rangelist_ai; // rangelist for A/D
310 const comedi_lrange *rangelist_ao; // rangelist for D/A
311 unsigned int IRQbits; // allowed IRQ
312 unsigned char DMAbits; // allowed DMA chans
313 unsigned char io_range; // iorange for this board
314 unsigned char haveMPC508; // 1=board use MPC508A multiplexor
317 static const boardtype boardtypes[] = {
318 {"pcl812", boardPCL812, 16, 0, 2, 16, 16, 0x0fff,
319 33000, 500, &range_bipolar10, &range_unipolar5,
320 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
321 {"pcl812pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
322 33000, 500, &range_pcl812pg_ai, &range_unipolar5,
323 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
324 {"acl8112pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
325 10000, 500, &range_pcl812pg_ai, &range_unipolar5,
326 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
327 {"acl8112dg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
328 10000, 500, &range_acl8112dg_ai, &range_unipolar5,
329 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
330 {"acl8112hg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
331 10000, 500, &range_acl8112hg_ai, &range_unipolar5,
332 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
333 {"a821pgl", boardA821, 16, 8, 1, 16, 16, 0x0fff,
334 10000, 500, &range_pcl813b_ai, &range_unipolar5,
335 0x000c, 0x00, PCLx1x_IORANGE, 0},
336 {"a821pglnda", boardA821, 16, 8, 0, 0, 0, 0x0fff,
337 10000, 500, &range_pcl813b_ai, NULL,
338 0x000c, 0x00, PCLx1x_IORANGE, 0},
339 {"a821pgh", boardA821, 16, 8, 1, 16, 16, 0x0fff,
340 10000, 500, &range_a821pgh_ai, &range_unipolar5,
341 0x000c, 0x00, PCLx1x_IORANGE, 0},
342 {"a822pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
343 10000, 500, &range_acl8112dg_ai, &range_unipolar5,
344 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
345 {"a822pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
346 10000, 500, &range_acl8112hg_ai, &range_unipolar5,
347 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
348 {"a823pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
349 8000, 500, &range_acl8112dg_ai, &range_unipolar5,
350 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
351 {"a823pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
352 8000, 500, &range_acl8112hg_ai, &range_unipolar5,
353 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
354 {"pcl813", boardPCL813, 32, 0, 0, 0, 0, 0x0fff,
355 0, 0, &range_pcl813b_ai, NULL,
356 0x0000, 0x00, PCLx1x_IORANGE, 0},
357 {"pcl813b", boardPCL813B, 32, 0, 0, 0, 0, 0x0fff,
358 0, 0, &range_pcl813b_ai, NULL,
359 0x0000, 0x00, PCLx1x_IORANGE, 0},
360 {"acl8113", boardACL8113, 32, 0, 0, 0, 0, 0x0fff,
361 0, 0, &range_acl8113_1_ai, NULL,
362 0x0000, 0x00, PCLx1x_IORANGE, 0},
363 {"iso813", boardISO813, 32, 0, 0, 0, 0, 0x0fff,
364 0, 0, &range_iso813_1_ai, NULL,
365 0x0000, 0x00, PCLx1x_IORANGE, 0},
366 {"acl8216", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
367 10000, 500, &range_pcl813b2_ai, &range_unipolar5,
368 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
369 {"a826pg", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
370 10000, 500, &range_pcl813b2_ai, &range_unipolar5,
371 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
374 #define n_boardtypes (sizeof(boardtypes)/sizeof(boardtype))
375 #define this_board ((const boardtype *)dev->board_ptr)
377 static comedi_driver driver_pcl812 = {
378 driver_name:"pcl812",
380 attach:pcl812_attach,
381 detach:pcl812_detach,
382 board_name:&boardtypes[0].name,
383 num_names:n_boardtypes,
384 offset:sizeof(boardtype),
387 COMEDI_INITCLEANUP(driver_pcl812);
390 unsigned char valid; // =1 device is OK
391 unsigned char dma; // >0 use dma ( usedDMA channel)
392 unsigned char use_diff; // =1 diff inputs
393 unsigned char use_MPC; // 1=board uses MPC508A multiplexor
394 unsigned char use_ext_trg; // 1=board uses external trigger
395 unsigned char range_correction; // =1 we must add 1 to range number
396 unsigned char old_chan_reg; // lastly used chan/gain pair
397 unsigned char old_gain_reg;
398 unsigned char mode_reg_int; // there is stored INT number for some card
399 unsigned char ai_neverending; // =1 we do unlimited AI
400 unsigned char ai_eos; // 1=EOS wake up
401 unsigned char ai_dma; // =1 we use DMA
402 unsigned int ai_poll_ptr; // how many sampes transfer poll
403 unsigned int ai_scans; // len of scanlist
404 unsigned int ai_act_scan; // how many scans we finished
405 unsigned int ai_chanlist[MAX_CHANLIST_LEN]; // our copy of channel/range list
406 unsigned int ai_n_chan; // how many channels is measured
407 unsigned int ai_flags; // flaglist
408 unsigned int ai_data_len; // len of data buffer
409 sampl_t *ai_data; // data buffer
410 unsigned int ai_is16b; // =1 we have 16 bit card
411 unsigned long dmabuf[2]; // PTR to DMA buf
412 unsigned int dmapages[2]; // how many pages we have allocated
413 unsigned int hwdmaptr[2]; // HW PTR to DMA buf
414 unsigned int hwdmasize[2]; // DMA buf size in bytes
415 unsigned int dmabytestomove[2]; // how many bytes DMA transfer
416 int next_dma_buf; // which buffer is next to use
417 unsigned int dma_runs_to_end; // how many times we must switch DMA buffers
418 unsigned int last_dma_run; // how many bytes to transfer on last DMA buffer
419 unsigned int max_812_ai_mode0_rangewait; // setling time for gain
420 lsampl_t ao_readback[2]; // data for AO readback
423 #define devpriv ((pcl812_private *)dev->private)
426 ==============================================================================
428 static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1,
429 unsigned int divisor2);
430 static void setup_range_channel(comedi_device * dev, comedi_subdevice * s,
431 unsigned int rangechan, char wait);
432 static int pcl812_ai_cancel(comedi_device * dev, comedi_subdevice * s);
434 ==============================================================================
436 static int pcl812_ai_insn_read(comedi_device * dev, comedi_subdevice * s,
437 comedi_insn * insn, lsampl_t * data)
442 outb(devpriv->mode_reg_int | 1, dev->iobase + PCL812_MODE); /* select software trigger */
443 setup_range_channel(dev, s, insn->chanspec, 1); // select channel and renge
444 for (n = 0; n < insn->n; n++) {
445 outb(255, dev->iobase + PCL812_SOFTTRIG); /* start conversion */
447 timeout = 50; /* wait max 50us, it must finish under 33us */
449 hi = inb(dev->iobase + PCL812_AD_HI);
450 if (!(hi & PCL812_DRDY))
455 ("comedi%d: pcl812: (%s at 0x%lx) A/D insn read timeout\n",
456 dev->minor, dev->board_name, dev->iobase);
457 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
461 data[n] = ((hi & 0xf) << 8) | inb(dev->iobase + PCL812_AD_LO);
463 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
468 ==============================================================================
470 static int acl8216_ai_insn_read(comedi_device * dev, comedi_subdevice * s,
471 comedi_insn * insn, lsampl_t * data)
476 outb(1, dev->iobase + PCL812_MODE); /* select software trigger */
477 setup_range_channel(dev, s, insn->chanspec, 1); // select channel and renge
478 for (n = 0; n < insn->n; n++) {
479 outb(255, dev->iobase + PCL812_SOFTTRIG); /* start conversion */
481 timeout = 50; /* wait max 50us, it must finish under 33us */
483 if (!(inb(dev->iobase + ACL8216_STATUS) & ACL8216_DRDY))
488 ("comedi%d: pcl812: (%s at 0x%lx) A/D insn read timeout\n",
489 dev->minor, dev->board_name, dev->iobase);
490 outb(0, dev->iobase + PCL812_MODE);
496 PCL812_AD_HI) << 8) | inb(dev->iobase +
499 outb(0, dev->iobase + PCL812_MODE);
504 ==============================================================================
506 static int pcl812_ao_insn_write(comedi_device * dev, comedi_subdevice * s,
507 comedi_insn * insn, lsampl_t * data)
509 int chan = CR_CHAN(insn->chanspec);
512 for (i = 0; i < insn->n; i++) {
513 outb((data[i] & 0xff),
514 dev->iobase + (chan ? PCL812_DA2_LO : PCL812_DA1_LO));
515 outb((data[i] >> 8) & 0x0f,
516 dev->iobase + (chan ? PCL812_DA2_HI : PCL812_DA1_HI));
517 devpriv->ao_readback[chan] = data[i];
524 ==============================================================================
526 static int pcl812_ao_insn_read(comedi_device * dev, comedi_subdevice * s,
527 comedi_insn * insn, lsampl_t * data)
529 int chan = CR_CHAN(insn->chanspec);
532 for (i = 0; i < insn->n; i++) {
533 data[i] = devpriv->ao_readback[chan];
540 ==============================================================================
542 static int pcl812_di_insn_bits(comedi_device * dev, comedi_subdevice * s,
543 comedi_insn * insn, lsampl_t * data)
548 data[1] = inb(dev->iobase + PCL812_DI_LO);
549 data[1] |= inb(dev->iobase + PCL812_DI_HI) << 8;
555 ==============================================================================
557 static int pcl812_do_insn_bits(comedi_device * dev, comedi_subdevice * s,
558 comedi_insn * insn, lsampl_t * data)
564 s->state &= ~data[0];
565 s->state |= data[0] & data[1];
566 outb(s->state & 0xff, dev->iobase + PCL812_DO_LO);
567 outb((s->state >> 8), dev->iobase + PCL812_DO_HI);
574 #ifdef PCL812_EXTDEBUG
576 ==============================================================================
578 static void pcl812_cmdtest_out(int e, comedi_cmd * cmd)
580 rt_printk("pcl812 e=%d startsrc=%x scansrc=%x convsrc=%x\n", e,
581 cmd->start_src, cmd->scan_begin_src, cmd->convert_src);
582 rt_printk("pcl812 e=%d startarg=%d scanarg=%d convarg=%d\n", e,
583 cmd->start_arg, cmd->scan_begin_arg, cmd->convert_arg);
584 rt_printk("pcl812 e=%d stopsrc=%x scanend=%x\n", e, cmd->stop_src,
586 rt_printk("pcl812 e=%d stoparg=%d scanendarg=%d chanlistlen=%d\n", e,
587 cmd->stop_arg, cmd->scan_end_arg, cmd->chanlist_len);
592 ==============================================================================
594 static int pcl812_ai_cmdtest(comedi_device * dev, comedi_subdevice * s,
598 int tmp, divisor1, divisor2;
600 #ifdef PCL812_EXTDEBUG
601 rt_printk("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...)\n");
602 pcl812_cmdtest_out(-1, cmd);
604 /* step 1: make sure trigger sources are trivially valid */
606 tmp = cmd->start_src;
607 cmd->start_src &= TRIG_NOW;
608 if (!cmd->start_src || tmp != cmd->start_src)
611 tmp = cmd->scan_begin_src;
612 cmd->scan_begin_src &= TRIG_FOLLOW;
613 if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
616 tmp = cmd->convert_src;
617 if (devpriv->use_ext_trg) {
618 cmd->convert_src &= TRIG_EXT;
620 cmd->convert_src &= TRIG_TIMER;
622 if (!cmd->convert_src || tmp != cmd->convert_src)
625 tmp = cmd->scan_end_src;
626 cmd->scan_end_src &= TRIG_COUNT;
627 if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
631 cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
632 if (!cmd->stop_src || tmp != cmd->stop_src)
636 #ifdef PCL812_EXTDEBUG
637 pcl812_cmdtest_out(1, cmd);
639 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=1\n",
645 /* step 2: make sure trigger sources are unique and mutually compatible */
647 if (cmd->start_src != TRIG_NOW) {
648 cmd->start_src = TRIG_NOW;
652 if (cmd->scan_begin_src != TRIG_FOLLOW) {
653 cmd->scan_begin_src = TRIG_FOLLOW;
657 if (devpriv->use_ext_trg) {
658 if (cmd->convert_src != TRIG_EXT) {
659 cmd->convert_src = TRIG_EXT;
663 if (cmd->convert_src != TRIG_TIMER) {
664 cmd->convert_src = TRIG_TIMER;
669 if (cmd->scan_end_src != TRIG_COUNT) {
670 cmd->scan_end_src = TRIG_COUNT;
674 if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT)
678 #ifdef PCL812_EXTDEBUG
679 pcl812_cmdtest_out(2, cmd);
681 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=2\n",
687 /* step 3: make sure arguments are trivially compatible */
689 if (cmd->start_arg != 0) {
694 if (cmd->scan_begin_arg != 0) {
695 cmd->scan_begin_arg = 0;
699 if (cmd->convert_src == TRIG_TIMER) {
700 if (cmd->convert_arg < this_board->ai_ns_min) {
701 cmd->convert_arg = this_board->ai_ns_min;
704 } else { /* TRIG_EXT */
705 if (cmd->convert_arg != 0) {
706 cmd->convert_arg = 0;
711 if (!cmd->chanlist_len) {
712 cmd->chanlist_len = 1;
715 if (cmd->chanlist_len > MAX_CHANLIST_LEN) {
716 cmd->chanlist_len = this_board->n_aichan;
719 if (cmd->scan_end_arg != cmd->chanlist_len) {
720 cmd->scan_end_arg = cmd->chanlist_len;
723 if (cmd->stop_src == TRIG_COUNT) {
724 if (!cmd->stop_arg) {
728 } else { /* TRIG_NONE */
729 if (cmd->stop_arg != 0) {
736 #ifdef PCL812_EXTDEBUG
737 pcl812_cmdtest_out(3, cmd);
739 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=3\n",
745 /* step 4: fix up any arguments */
747 if (cmd->convert_src == TRIG_TIMER) {
748 tmp = cmd->convert_arg;
749 i8253_cascade_ns_to_timer(this_board->i8254_osc_base, &divisor1,
750 &divisor2, &cmd->convert_arg,
751 cmd->flags & TRIG_ROUND_MASK);
752 if (cmd->convert_arg < this_board->ai_ns_min)
753 cmd->convert_arg = this_board->ai_ns_min;
754 if (tmp != cmd->convert_arg)
759 #ifdef PCL812_EXTDEBUG
761 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=4\n",
771 ==============================================================================
773 static int pcl812_ai_cmd(comedi_device * dev, comedi_subdevice * s)
775 unsigned int divisor1 = 0, divisor2 = 0, i, dma_flags, bytes;
776 comedi_cmd *cmd = &s->async->cmd;
778 #ifdef PCL812_EXTDEBUG
779 rt_printk("pcl812 EDBG: BGN: pcl812_ai_cmd(...)\n");
782 if (cmd->start_src != TRIG_NOW)
784 if (cmd->scan_begin_src != TRIG_FOLLOW)
786 if (devpriv->use_ext_trg) {
787 if (cmd->convert_src != TRIG_EXT)
790 if (cmd->convert_src != TRIG_TIMER)
793 if (cmd->scan_end_src != TRIG_COUNT)
795 if (cmd->scan_end_arg != cmd->chanlist_len)
797 if (cmd->chanlist_len > MAX_CHANLIST_LEN)
800 if (cmd->convert_src == TRIG_TIMER) {
801 if (cmd->convert_arg < this_board->ai_ns_min)
802 cmd->convert_arg = this_board->ai_ns_min;
803 i8253_cascade_ns_to_timer(this_board->i8254_osc_base,
804 &divisor1, &divisor2, &cmd->convert_arg,
805 cmd->flags & TRIG_ROUND_MASK);
808 start_pacer(dev, -1, 0, 0); // stop pacer
810 devpriv->ai_n_chan = cmd->chanlist_len;
811 memcpy(devpriv->ai_chanlist, cmd->chanlist,
812 sizeof(unsigned int) * cmd->scan_end_arg);
813 setup_range_channel(dev, s, devpriv->ai_chanlist[0], 1); // select first channel and range
815 if (devpriv->dma) { // check if we can use DMA transfer
817 for (i = 1; i < devpriv->ai_n_chan; i++)
818 if (devpriv->ai_chanlist[0] != devpriv->ai_chanlist[i]) {
819 devpriv->ai_dma = 0; // we cann't use DMA :-(
825 devpriv->ai_flags = cmd->flags;
826 devpriv->ai_data_len = s->async->prealloc_bufsz;
827 devpriv->ai_data = s->async->prealloc_buf;
828 if (cmd->stop_src == TRIG_COUNT) {
829 devpriv->ai_scans = cmd->stop_arg;
830 devpriv->ai_neverending = 0;
832 devpriv->ai_scans = 0;
833 devpriv->ai_neverending = 1;
836 devpriv->ai_act_scan = 0;
837 devpriv->ai_poll_ptr = 0;
838 s->async->cur_chan = 0;
840 if ((devpriv->ai_flags & TRIG_WAKE_EOS)) { // don't we want wake up every scan?
842 if (devpriv->ai_n_chan == 1)
843 devpriv->ai_dma = 0; // DMA is useless for this situation
846 if (devpriv->ai_dma) {
847 if (devpriv->ai_eos) { // we use EOS, so adapt DMA buffer to one scan
848 devpriv->dmabytestomove[0] =
849 devpriv->ai_n_chan * sizeof(sampl_t);
850 devpriv->dmabytestomove[1] =
851 devpriv->ai_n_chan * sizeof(sampl_t);
852 devpriv->dma_runs_to_end = 1;
854 devpriv->dmabytestomove[0] = devpriv->hwdmasize[0];
855 devpriv->dmabytestomove[1] = devpriv->hwdmasize[1];
856 if (devpriv->ai_data_len < devpriv->hwdmasize[0])
857 devpriv->dmabytestomove[0] =
858 devpriv->ai_data_len;
859 if (devpriv->ai_data_len < devpriv->hwdmasize[1])
860 devpriv->dmabytestomove[1] =
861 devpriv->ai_data_len;
862 if (devpriv->ai_neverending) {
863 devpriv->dma_runs_to_end = 1;
865 bytes = devpriv->ai_n_chan * devpriv->ai_scans * sizeof(sampl_t); // how many samples we must transfer?
866 devpriv->dma_runs_to_end = bytes / devpriv->dmabytestomove[0]; // how many DMA pages we must fill
867 devpriv->last_dma_run = bytes % devpriv->dmabytestomove[0]; //on last dma transfer must be moved
868 if (devpriv->dma_runs_to_end == 0)
869 devpriv->dmabytestomove[0] =
870 devpriv->last_dma_run;
871 devpriv->dma_runs_to_end--;
874 if (devpriv->dmabytestomove[0] > devpriv->hwdmasize[0]) {
875 devpriv->dmabytestomove[0] = devpriv->hwdmasize[0];
878 if (devpriv->dmabytestomove[1] > devpriv->hwdmasize[1]) {
879 devpriv->dmabytestomove[1] = devpriv->hwdmasize[1];
882 devpriv->next_dma_buf = 0;
883 set_dma_mode(devpriv->dma, DMA_MODE_READ);
884 dma_flags = claim_dma_lock();
885 clear_dma_ff(devpriv->dma);
886 set_dma_addr(devpriv->dma, devpriv->hwdmaptr[0]);
887 set_dma_count(devpriv->dma, devpriv->dmabytestomove[0]);
888 release_dma_lock(dma_flags);
889 enable_dma(devpriv->dma);
890 #ifdef PCL812_EXTDEBUG
892 ("pcl812 EDBG: DMA %d PTR 0x%0x/0x%0x LEN %u/%u EOS %d\n",
893 devpriv->dma, devpriv->hwdmaptr[0],
894 devpriv->hwdmaptr[1], devpriv->dmabytestomove[0],
895 devpriv->dmabytestomove[1], devpriv->ai_eos);
899 switch (cmd->convert_src) {
901 start_pacer(dev, 1, divisor1, divisor2);
905 if (devpriv->ai_dma) {
906 outb(devpriv->mode_reg_int | 2, dev->iobase + PCL812_MODE); // let's go!
908 outb(devpriv->mode_reg_int | 6, dev->iobase + PCL812_MODE); // let's go!
911 #ifdef PCL812_EXTDEBUG
912 rt_printk("pcl812 EDBG: END: pcl812_ai_cmd(...)\n");
919 ==============================================================================
921 static irqreturn_t interrupt_pcl812_ai_int(int irq, void *d)
924 unsigned int mask, timeout;
925 comedi_device *dev = d;
926 comedi_subdevice *s = dev->subdevices + 0;
928 s->async->events = 0;
930 timeout = 50; /* wait max 50us, it must finish under 33us */
931 if (devpriv->ai_is16b) {
934 if (!(inb(dev->iobase + ACL8216_STATUS) & ACL8216_DRDY)) {
943 if (!(inb(dev->iobase + PCL812_AD_HI) & PCL812_DRDY)) {
953 ("comedi%d: pcl812: (%s at 0x%lx) A/D cmd IRQ without DRDY!\n",
954 dev->minor, dev->board_name, dev->iobase);
955 pcl812_ai_cancel(dev, s);
956 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
957 comedi_event(dev, s);
961 comedi_buf_put(s->async,
962 ((inb(dev->iobase + PCL812_AD_HI) << 8) | inb(dev->iobase +
963 PCL812_AD_LO)) & mask);
965 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
967 if (s->async->cur_chan == 0) { /* one scan done */
968 devpriv->ai_act_scan++;
969 if (!(devpriv->ai_neverending))
970 if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */
971 pcl812_ai_cancel(dev, s);
972 s->async->events |= COMEDI_CB_EOA;
976 comedi_event(dev, s);
981 ==============================================================================
983 static void transfer_from_dma_buf(comedi_device * dev, comedi_subdevice * s,
984 sampl_t * ptr, unsigned int bufptr, unsigned int len)
988 s->async->events = 0;
989 for (i = len; i; i--) {
990 comedi_buf_put(s->async, ptr[bufptr++]); // get one sample
992 if (s->async->cur_chan == 0) {
993 devpriv->ai_act_scan++;
994 if (!devpriv->ai_neverending)
995 if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */
996 pcl812_ai_cancel(dev, s);
997 s->async->events |= COMEDI_CB_EOA;
1003 comedi_event(dev, s);
1007 ==============================================================================
1009 static irqreturn_t interrupt_pcl812_ai_dma(int irq, void *d)
1011 comedi_device *dev = d;
1012 comedi_subdevice *s = dev->subdevices + 0;
1013 unsigned long dma_flags;
1017 #ifdef PCL812_EXTDEBUG
1018 rt_printk("pcl812 EDBG: BGN: interrupt_pcl812_ai_dma(...)\n");
1020 ptr = (sampl_t *) devpriv->dmabuf[devpriv->next_dma_buf];
1021 len = (devpriv->dmabytestomove[devpriv->next_dma_buf] >> 1) -
1022 devpriv->ai_poll_ptr;
1024 devpriv->next_dma_buf = 1 - devpriv->next_dma_buf;
1025 disable_dma(devpriv->dma);
1026 set_dma_mode(devpriv->dma, DMA_MODE_READ);
1027 dma_flags = claim_dma_lock();
1028 set_dma_addr(devpriv->dma, devpriv->hwdmaptr[devpriv->next_dma_buf]);
1029 if (devpriv->ai_eos) {
1030 set_dma_count(devpriv->dma,
1031 devpriv->dmabytestomove[devpriv->next_dma_buf]);
1033 if (devpriv->dma_runs_to_end) {
1034 set_dma_count(devpriv->dma,
1035 devpriv->dmabytestomove[devpriv->next_dma_buf]);
1037 set_dma_count(devpriv->dma, devpriv->last_dma_run);
1039 devpriv->dma_runs_to_end--;
1041 release_dma_lock(dma_flags);
1042 enable_dma(devpriv->dma);
1044 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
1046 bufptr = devpriv->ai_poll_ptr;
1047 devpriv->ai_poll_ptr = 0;
1049 transfer_from_dma_buf(dev, s, ptr, bufptr, len);
1051 #ifdef PCL812_EXTDEBUG
1052 rt_printk("pcl812 EDBG: END: interrupt_pcl812_ai_dma(...)\n");
1058 ==============================================================================
1060 static irqreturn_t interrupt_pcl812(int irq, void *d PT_REGS_ARG)
1062 comedi_device *dev = d;
1064 if (!dev->attached) {
1065 comedi_error(dev, "spurious interrupt");
1068 if (devpriv->ai_dma) {
1069 return interrupt_pcl812_ai_dma(irq, d);
1071 return interrupt_pcl812_ai_int(irq, d);
1076 ==============================================================================
1078 static int pcl812_ai_poll(comedi_device * dev, comedi_subdevice * s)
1080 unsigned long flags;
1081 unsigned int top1, top2, i;
1083 if (!devpriv->ai_dma)
1084 return 0; // poll is valid only for DMA transfer
1086 comedi_spin_lock_irqsave(&dev->spinlock, flags);
1088 for (i = 0; i < 10; i++) {
1089 top1 = get_dma_residue(devpriv->ai_dma); // where is now DMA
1090 top2 = get_dma_residue(devpriv->ai_dma);
1096 comedi_spin_unlock_irqrestore(&dev->spinlock, flags);
1100 top1 = devpriv->dmabytestomove[1 - devpriv->next_dma_buf] - top1; // where is now DMA in buffer
1101 top1 >>= 1; // sample position
1102 top2 = top1 - devpriv->ai_poll_ptr;
1103 if (top2 < 1) { // no new samples
1104 comedi_spin_unlock_irqrestore(&dev->spinlock, flags);
1108 transfer_from_dma_buf(dev, s,
1109 (void *)devpriv->dmabuf[1 - devpriv->next_dma_buf],
1110 devpriv->ai_poll_ptr, top2);
1112 devpriv->ai_poll_ptr = top1; // new buffer position
1114 comedi_spin_unlock_irqrestore(&dev->spinlock, flags);
1116 return s->async->buf_write_count - s->async->buf_read_count;
1120 ==============================================================================
1122 static void setup_range_channel(comedi_device * dev, comedi_subdevice * s,
1123 unsigned int rangechan, char wait)
1125 unsigned char chan_reg = CR_CHAN(rangechan); // normal board
1126 unsigned char gain_reg = CR_RANGE(rangechan) + devpriv->range_correction; // gain index
1128 if ((chan_reg == devpriv->old_chan_reg)
1129 && (gain_reg == devpriv->old_gain_reg))
1130 return; // we can return, no change
1132 devpriv->old_chan_reg = chan_reg;
1133 devpriv->old_gain_reg = gain_reg;
1135 if (devpriv->use_MPC) {
1136 if (devpriv->use_diff) {
1137 chan_reg = chan_reg | 0x30; // DIFF inputs
1139 if (chan_reg & 0x80) {
1140 chan_reg = chan_reg | 0x20; // SE inputs 8-15
1142 chan_reg = chan_reg | 0x10; // SE inputs 0-7
1147 outb(chan_reg, dev->iobase + PCL812_MUX); /* select channel */
1148 outb(gain_reg, dev->iobase + PCL812_GAIN); /* select gain */
1151 comedi_udelay(devpriv->max_812_ai_mode0_rangewait); // XXX this depends on selected range and can be very long for some high gain ranges!
1156 ==============================================================================
1158 static void start_pacer(comedi_device * dev, int mode, unsigned int divisor1,
1159 unsigned int divisor2)
1161 #ifdef PCL812_EXTDEBUG
1162 rt_printk("pcl812 EDBG: BGN: start_pacer(%d,%u,%u)\n", mode, divisor1,
1165 outb(0xb4, dev->iobase + PCL812_CTRCTL);
1166 outb(0x74, dev->iobase + PCL812_CTRCTL);
1170 outb(divisor2 & 0xff, dev->iobase + PCL812_CTR2);
1171 outb((divisor2 >> 8) & 0xff, dev->iobase + PCL812_CTR2);
1172 outb(divisor1 & 0xff, dev->iobase + PCL812_CTR1);
1173 outb((divisor1 >> 8) & 0xff, dev->iobase + PCL812_CTR1);
1175 #ifdef PCL812_EXTDEBUG
1176 rt_printk("pcl812 EDBG: END: start_pacer(...)\n");
1181 ==============================================================================
1183 static void free_resources(comedi_device * dev)
1187 if (devpriv->dmabuf[0])
1188 free_pages(devpriv->dmabuf[0], devpriv->dmapages[0]);
1189 if (devpriv->dmabuf[1])
1190 free_pages(devpriv->dmabuf[1], devpriv->dmapages[1]);
1192 free_dma(devpriv->dma);
1195 comedi_free_irq(dev->irq, dev);
1197 release_region(dev->iobase, this_board->io_range);
1201 ==============================================================================
1203 static int pcl812_ai_cancel(comedi_device * dev, comedi_subdevice * s)
1205 #ifdef PCL812_EXTDEBUG
1206 rt_printk("pcl812 EDBG: BGN: pcl812_ai_cancel(...)\n");
1208 if (devpriv->ai_dma)
1209 disable_dma(devpriv->dma);
1210 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
1211 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE); /* Stop A/D */
1212 start_pacer(dev, -1, 0, 0); // stop 8254
1213 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
1214 #ifdef PCL812_EXTDEBUG
1215 rt_printk("pcl812 EDBG: END: pcl812_ai_cancel(...)\n");
1221 ==============================================================================
1223 static void pcl812_reset(comedi_device * dev)
1225 #ifdef PCL812_EXTDEBUG
1226 rt_printk("pcl812 EDBG: BGN: pcl812_reset(...)\n");
1228 outb(0, dev->iobase + PCL812_MUX);
1229 outb(0 + devpriv->range_correction, dev->iobase + PCL812_GAIN);
1230 devpriv->old_chan_reg = -1; // invalidate chain/gain memory
1231 devpriv->old_gain_reg = -1;
1233 switch (this_board->board_type) {
1238 outb(0, dev->iobase + PCL812_DA2_LO);
1239 outb(0, dev->iobase + PCL812_DA2_HI);
1241 outb(0, dev->iobase + PCL812_DA1_LO);
1242 outb(0, dev->iobase + PCL812_DA1_HI);
1243 start_pacer(dev, -1, 0, 0); // stop 8254
1244 outb(0, dev->iobase + PCL812_DO_HI);
1245 outb(0, dev->iobase + PCL812_DO_LO);
1246 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
1247 outb(0, dev->iobase + PCL812_CLRINT);
1257 #ifdef PCL812_EXTDEBUG
1258 rt_printk("pcl812 EDBG: END: pcl812_reset(...)\n");
1263 ==============================================================================
1265 static int pcl812_attach(comedi_device * dev, comedi_devconfig * it)
1268 unsigned long iobase;
1271 unsigned long pages;
1272 comedi_subdevice *s;
1275 iobase = it->options[0];
1276 printk("comedi%d: pcl812: board=%s, ioport=0x%03lx", dev->minor,
1277 this_board->name, iobase);
1279 if (!request_region(iobase, this_board->io_range, "pcl812")) {
1280 printk("I/O port conflict\n");
1283 dev->iobase = iobase;
1285 if ((ret = alloc_private(dev, sizeof(pcl812_private))) < 0) {
1286 free_resources(dev);
1287 return ret; /* Can't alloc mem */
1290 dev->board_name = this_board->name;
1293 if (this_board->IRQbits != 0) { /* board support IRQ */
1294 irq = it->options[1];
1295 if (irq) { /* we want to use IRQ */
1296 if (((1 << irq) & this_board->IRQbits) == 0) {
1297 printk(", IRQ %u is out of allowed range, DISABLING IT", irq);
1298 irq = 0; /* Bad IRQ */
1300 if (comedi_request_irq(irq, interrupt_pcl812, 0,
1302 printk(", unable to allocate IRQ %u, DISABLING IT", irq);
1303 irq = 0; /* Can't use IRQ */
1305 printk(", irq=%u", irq);
1316 goto no_dma; /* if we haven't IRQ, we can't use DMA */
1317 if (this_board->DMAbits != 0) { /* board support DMA */
1318 dma = it->options[2];
1319 if (((1 << dma) & this_board->DMAbits) == 0) {
1320 printk(", DMA is out of allowed range, FAIL!\n");
1321 return -EINVAL; /* Bad DMA */
1323 ret = request_dma(dma, "pcl812");
1325 printk(", unable to allocate DMA %u, FAIL!\n", dma);
1326 return -EBUSY; /* DMA isn't free */
1329 printk(", dma=%u", dma);
1330 pages = 1; /* we want 8KB */
1331 devpriv->dmabuf[0] = __get_dma_pages(GFP_KERNEL, pages);
1332 if (!devpriv->dmabuf[0]) {
1333 printk(", unable to allocate DMA buffer, FAIL!\n");
1334 /* maybe experiment with try_to_free_pages() will help .... */
1335 free_resources(dev);
1336 return -EBUSY; /* no buffer :-( */
1338 devpriv->dmapages[0] = pages;
1339 devpriv->hwdmaptr[0] = virt_to_bus((void *)devpriv->dmabuf[0]);
1340 devpriv->hwdmasize[0] = PAGE_SIZE * (1 << pages);
1341 devpriv->dmabuf[1] = __get_dma_pages(GFP_KERNEL, pages);
1342 if (!devpriv->dmabuf[1]) {
1343 printk(", unable to allocate DMA buffer, FAIL!\n");
1344 free_resources(dev);
1347 devpriv->dmapages[1] = pages;
1348 devpriv->hwdmaptr[1] = virt_to_bus((void *)devpriv->dmabuf[1]);
1349 devpriv->hwdmasize[1] = PAGE_SIZE * (1 << pages);
1354 if (this_board->n_aichan > 0)
1356 if (this_board->n_aochan > 0)
1358 if (this_board->n_dichan > 0)
1360 if (this_board->n_dochan > 0)
1363 if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) {
1364 free_resources(dev);
1371 if (this_board->n_aichan > 0) {
1372 s = dev->subdevices + subdev;
1373 s->type = COMEDI_SUBD_AI;
1374 s->subdev_flags = SDF_READABLE;
1375 switch (this_board->board_type) {
1377 if (it->options[2] == 1) {
1378 s->n_chan = this_board->n_aichan_diff;
1379 s->subdev_flags |= SDF_DIFF;
1380 devpriv->use_diff = 1;
1382 s->n_chan = this_board->n_aichan;
1383 s->subdev_flags |= SDF_GROUND;
1388 if (it->options[4] == 1) {
1389 s->n_chan = this_board->n_aichan_diff;
1390 s->subdev_flags |= SDF_DIFF;
1391 devpriv->use_diff = 1;
1393 s->n_chan = this_board->n_aichan;
1394 s->subdev_flags |= SDF_GROUND;
1398 s->n_chan = this_board->n_aichan;
1399 s->subdev_flags |= SDF_GROUND;
1402 s->maxdata = this_board->ai_maxdata;
1403 s->len_chanlist = MAX_CHANLIST_LEN;
1404 s->range_table = this_board->rangelist_ai;
1405 if (this_board->board_type == boardACL8216) {
1406 s->insn_read = acl8216_ai_insn_read;
1408 s->insn_read = pcl812_ai_insn_read;
1410 devpriv->use_MPC = this_board->haveMPC508;
1411 s->cancel = pcl812_ai_cancel;
1413 dev->read_subdev = s;
1414 s->subdev_flags |= SDF_CMD_READ;
1415 s->do_cmdtest = pcl812_ai_cmdtest;
1416 s->do_cmd = pcl812_ai_cmd;
1417 s->poll = pcl812_ai_poll;
1419 switch (this_board->board_type) {
1421 if (it->options[4] == 1)
1422 s->range_table = &range_pcl812pg2_ai;
1425 switch (it->options[4]) {
1427 s->range_table = &range_bipolar10;
1430 s->range_table = &range_bipolar5;
1433 s->range_table = &range_bipolar2_5;
1436 s->range_table = &range812_bipolar1_25;
1439 s->range_table = &range812_bipolar0_625;
1442 s->range_table = &range812_bipolar0_3125;
1445 s->range_table = &range_bipolar10;
1447 printk(", incorrect range number %d, changing to 0 (+/-10V)", it->options[4]);
1453 if (it->options[1] == 1)
1454 s->range_table = &range_pcl813b2_ai;
1457 switch (it->options[1]) {
1459 s->range_table = &range_iso813_1_ai;
1462 s->range_table = &range_iso813_1_2_ai;
1465 s->range_table = &range_iso813_2_ai;
1466 devpriv->range_correction = 1;
1469 s->range_table = &range_iso813_2_2_ai;
1470 devpriv->range_correction = 1;
1473 s->range_table = &range_iso813_1_ai;
1475 printk(", incorrect range number %d, changing to 0 ", it->options[1]);
1480 switch (it->options[1]) {
1482 s->range_table = &range_acl8113_1_ai;
1485 s->range_table = &range_acl8113_1_2_ai;
1488 s->range_table = &range_acl8113_2_ai;
1489 devpriv->range_correction = 1;
1492 s->range_table = &range_acl8113_2_2_ai;
1493 devpriv->range_correction = 1;
1496 s->range_table = &range_acl8113_1_ai;
1498 printk(", incorrect range number %d, changing to 0 ", it->options[1]);
1507 if (this_board->n_aochan > 0) {
1508 s = dev->subdevices + subdev;
1509 s->type = COMEDI_SUBD_AO;
1510 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
1511 s->n_chan = this_board->n_aochan;
1513 s->len_chanlist = 1;
1514 s->range_table = this_board->rangelist_ao;
1515 s->insn_read = pcl812_ao_insn_read;
1516 s->insn_write = pcl812_ao_insn_write;
1517 switch (this_board->board_type) {
1519 if (it->options[3] == 1)
1520 s->range_table = &range_unipolar10;
1526 if (it->options[5] == 1)
1527 s->range_table = &range_unipolar10;
1528 if (it->options[5] == 2)
1529 s->range_table = &range_unknown;
1536 if (this_board->n_dichan > 0) {
1537 s = dev->subdevices + subdev;
1538 s->type = COMEDI_SUBD_DI;
1539 s->subdev_flags = SDF_READABLE;
1540 s->n_chan = this_board->n_dichan;
1542 s->len_chanlist = this_board->n_dichan;
1543 s->range_table = &range_digital;
1544 s->insn_bits = pcl812_di_insn_bits;
1548 /* digital output */
1549 if (this_board->n_dochan > 0) {
1550 s = dev->subdevices + subdev;
1551 s->type = COMEDI_SUBD_DO;
1552 s->subdev_flags = SDF_WRITABLE;
1553 s->n_chan = this_board->n_dochan;
1555 s->len_chanlist = this_board->n_dochan;
1556 s->range_table = &range_digital;
1557 s->insn_bits = pcl812_do_insn_bits;
1561 switch (this_board->board_type) {
1563 devpriv->ai_is16b = 1;
1567 devpriv->max_812_ai_mode0_rangewait = 1;
1568 if (it->options[3] > 0)
1569 devpriv->use_ext_trg = 1; // we use external trigger
1571 devpriv->max_812_ai_mode0_rangewait = 1;
1572 devpriv->mode_reg_int = (irq << 4) & 0xf0;
1578 devpriv->max_812_ai_mode0_rangewait = 5; /* maybe there must by greatest timeout */
1591 ==============================================================================
1593 static int pcl812_detach(comedi_device * dev)
1596 #ifdef PCL812_EXTDEBUG
1597 rt_printk("comedi%d: pcl812: remove\n", dev->minor);
1599 free_resources(dev);