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 struct comedi_lrange range_pcl812pg_ai = { 5, {
170 static const struct comedi_lrange range_pcl812pg2_ai = { 5, {
178 static const struct comedi_lrange range812_bipolar1_25 = { 1, {
182 static const struct comedi_lrange range812_bipolar0_625 = { 1, {
186 static const struct comedi_lrange range812_bipolar0_3125 = { 1, {
190 static const struct comedi_lrange range_pcl813b_ai = { 4, {
197 static const struct comedi_lrange range_pcl813b2_ai = { 4, {
204 static const struct comedi_lrange range_iso813_1_ai = { 5, {
212 static const struct comedi_lrange range_iso813_1_2_ai = { 5, {
220 static const struct comedi_lrange range_iso813_2_ai = { 4, {
227 static const struct comedi_lrange range_iso813_2_2_ai = { 4, {
234 static const struct comedi_lrange range_acl8113_1_ai = { 4, {
241 static const struct comedi_lrange range_acl8113_1_2_ai = { 4, {
248 static const struct comedi_lrange range_acl8113_2_ai = { 3, {
254 static const struct comedi_lrange range_acl8113_2_2_ai = { 3, {
260 static const struct comedi_lrange range_acl8112dg_ai = { 9, {
272 static const struct comedi_lrange range_acl8112hg_ai = { 12, {
287 static const struct comedi_lrange range_a821pgh_ai = { 4, {
295 static int pcl812_attach(struct comedi_device * dev, struct comedi_devconfig * it);
296 static int pcl812_detach(struct comedi_device * dev);
298 struct pcl812_board {
300 const char *name; // board name
301 int board_type; // type of this board
302 int n_aichan; // num of AI chans in S.E.
303 int n_aichan_diff; // DIFF num of chans
304 int n_aochan; // num of DA chans
305 int n_dichan; // DI and DO chans
307 int ai_maxdata; // AI resolution
308 unsigned int ai_ns_min; // max sample speed of card v ns
309 unsigned int i8254_osc_base; // clock base
310 const struct comedi_lrange *rangelist_ai; // rangelist for A/D
311 const struct comedi_lrange *rangelist_ao; // rangelist for D/A
312 unsigned int IRQbits; // allowed IRQ
313 unsigned char DMAbits; // allowed DMA chans
314 unsigned char io_range; // iorange for this board
315 unsigned char haveMPC508; // 1=board use MPC508A multiplexor
319 static const struct pcl812_board boardtypes[] = {
320 {"pcl812", boardPCL812, 16, 0, 2, 16, 16, 0x0fff,
321 33000, 500, &range_bipolar10, &range_unipolar5,
322 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
323 {"pcl812pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
324 33000, 500, &range_pcl812pg_ai, &range_unipolar5,
325 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
326 {"acl8112pg", boardPCL812PG, 16, 0, 2, 16, 16, 0x0fff,
327 10000, 500, &range_pcl812pg_ai, &range_unipolar5,
328 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
329 {"acl8112dg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
330 10000, 500, &range_acl8112dg_ai, &range_unipolar5,
331 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
332 {"acl8112hg", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
333 10000, 500, &range_acl8112hg_ai, &range_unipolar5,
334 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
335 {"a821pgl", boardA821, 16, 8, 1, 16, 16, 0x0fff,
336 10000, 500, &range_pcl813b_ai, &range_unipolar5,
337 0x000c, 0x00, PCLx1x_IORANGE, 0},
338 {"a821pglnda", boardA821, 16, 8, 0, 0, 0, 0x0fff,
339 10000, 500, &range_pcl813b_ai, NULL,
340 0x000c, 0x00, PCLx1x_IORANGE, 0},
341 {"a821pgh", boardA821, 16, 8, 1, 16, 16, 0x0fff,
342 10000, 500, &range_a821pgh_ai, &range_unipolar5,
343 0x000c, 0x00, PCLx1x_IORANGE, 0},
344 {"a822pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
345 10000, 500, &range_acl8112dg_ai, &range_unipolar5,
346 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
347 {"a822pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
348 10000, 500, &range_acl8112hg_ai, &range_unipolar5,
349 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
350 {"a823pgl", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
351 8000, 500, &range_acl8112dg_ai, &range_unipolar5,
352 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
353 {"a823pgh", boardACL8112, 16, 8, 2, 16, 16, 0x0fff,
354 8000, 500, &range_acl8112hg_ai, &range_unipolar5,
355 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
356 {"pcl813", boardPCL813, 32, 0, 0, 0, 0, 0x0fff,
357 0, 0, &range_pcl813b_ai, NULL,
358 0x0000, 0x00, PCLx1x_IORANGE, 0},
359 {"pcl813b", boardPCL813B, 32, 0, 0, 0, 0, 0x0fff,
360 0, 0, &range_pcl813b_ai, NULL,
361 0x0000, 0x00, PCLx1x_IORANGE, 0},
362 {"acl8113", boardACL8113, 32, 0, 0, 0, 0, 0x0fff,
363 0, 0, &range_acl8113_1_ai, NULL,
364 0x0000, 0x00, PCLx1x_IORANGE, 0},
365 {"iso813", boardISO813, 32, 0, 0, 0, 0, 0x0fff,
366 0, 0, &range_iso813_1_ai, NULL,
367 0x0000, 0x00, PCLx1x_IORANGE, 0},
368 {"acl8216", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
369 10000, 500, &range_pcl813b2_ai, &range_unipolar5,
370 0xdcfc, 0x0a, PCLx1x_IORANGE, 1},
371 {"a826pg", boardACL8216, 16, 8, 2, 16, 16, 0xffff,
372 10000, 500, &range_pcl813b2_ai, &range_unipolar5,
373 0xdcfc, 0x0a, PCLx1x_IORANGE, 0},
376 #define n_boardtypes (sizeof(boardtypes)/sizeof(struct pcl812_board))
377 #define this_board ((const struct pcl812_board *)dev->board_ptr)
379 static struct comedi_driver driver_pcl812 = {
380 driver_name:"pcl812",
382 attach:pcl812_attach,
383 detach:pcl812_detach,
384 board_name:&boardtypes[0].name,
385 num_names:n_boardtypes,
386 offset:sizeof(struct pcl812_board),
389 COMEDI_INITCLEANUP(driver_pcl812);
391 struct pcl812_private {
393 unsigned char valid; // =1 device is OK
394 unsigned char dma; // >0 use dma ( usedDMA channel)
395 unsigned char use_diff; // =1 diff inputs
396 unsigned char use_MPC; // 1=board uses MPC508A multiplexor
397 unsigned char use_ext_trg; // 1=board uses external trigger
398 unsigned char range_correction; // =1 we must add 1 to range number
399 unsigned char old_chan_reg; // lastly used chan/gain pair
400 unsigned char old_gain_reg;
401 unsigned char mode_reg_int; // there is stored INT number for some card
402 unsigned char ai_neverending; // =1 we do unlimited AI
403 unsigned char ai_eos; // 1=EOS wake up
404 unsigned char ai_dma; // =1 we use DMA
405 unsigned int ai_poll_ptr; // how many sampes transfer poll
406 unsigned int ai_scans; // len of scanlist
407 unsigned int ai_act_scan; // how many scans we finished
408 unsigned int ai_chanlist[MAX_CHANLIST_LEN]; // our copy of channel/range list
409 unsigned int ai_n_chan; // how many channels is measured
410 unsigned int ai_flags; // flaglist
411 unsigned int ai_data_len; // len of data buffer
412 short *ai_data; // data buffer
413 unsigned int ai_is16b; // =1 we have 16 bit card
414 unsigned long dmabuf[2]; // PTR to DMA buf
415 unsigned int dmapages[2]; // how many pages we have allocated
416 unsigned int hwdmaptr[2]; // HW PTR to DMA buf
417 unsigned int hwdmasize[2]; // DMA buf size in bytes
418 unsigned int dmabytestomove[2]; // how many bytes DMA transfer
419 int next_dma_buf; // which buffer is next to use
420 unsigned int dma_runs_to_end; // how many times we must switch DMA buffers
421 unsigned int last_dma_run; // how many bytes to transfer on last DMA buffer
422 unsigned int max_812_ai_mode0_rangewait; // setling time for gain
423 unsigned int ao_readback[2]; // data for AO readback
427 #define devpriv ((struct pcl812_private *)dev->private)
430 ==============================================================================
432 static void start_pacer(struct comedi_device * dev, int mode, unsigned int divisor1,
433 unsigned int divisor2);
434 static void setup_range_channel(struct comedi_device * dev, struct comedi_subdevice * s,
435 unsigned int rangechan, char wait);
436 static int pcl812_ai_cancel(struct comedi_device * dev, struct comedi_subdevice * s);
438 ==============================================================================
440 static int pcl812_ai_insn_read(struct comedi_device * dev, struct comedi_subdevice * s,
441 struct comedi_insn * insn, unsigned int * data)
446 outb(devpriv->mode_reg_int | 1, dev->iobase + PCL812_MODE); /* select software trigger */
447 setup_range_channel(dev, s, insn->chanspec, 1); // select channel and renge
448 for (n = 0; n < insn->n; n++) {
449 outb(255, dev->iobase + PCL812_SOFTTRIG); /* start conversion */
451 timeout = 50; /* wait max 50us, it must finish under 33us */
453 hi = inb(dev->iobase + PCL812_AD_HI);
454 if (!(hi & PCL812_DRDY))
459 ("comedi%d: pcl812: (%s at 0x%lx) A/D insn read timeout\n",
460 dev->minor, dev->board_name, dev->iobase);
461 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
465 data[n] = ((hi & 0xf) << 8) | inb(dev->iobase + PCL812_AD_LO);
467 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
472 ==============================================================================
474 static int acl8216_ai_insn_read(struct comedi_device * dev, struct comedi_subdevice * s,
475 struct comedi_insn * insn, unsigned int * data)
480 outb(1, dev->iobase + PCL812_MODE); /* select software trigger */
481 setup_range_channel(dev, s, insn->chanspec, 1); // select channel and renge
482 for (n = 0; n < insn->n; n++) {
483 outb(255, dev->iobase + PCL812_SOFTTRIG); /* start conversion */
485 timeout = 50; /* wait max 50us, it must finish under 33us */
487 if (!(inb(dev->iobase + ACL8216_STATUS) & ACL8216_DRDY))
492 ("comedi%d: pcl812: (%s at 0x%lx) A/D insn read timeout\n",
493 dev->minor, dev->board_name, dev->iobase);
494 outb(0, dev->iobase + PCL812_MODE);
500 PCL812_AD_HI) << 8) | inb(dev->iobase +
503 outb(0, dev->iobase + PCL812_MODE);
508 ==============================================================================
510 static int pcl812_ao_insn_write(struct comedi_device * dev, struct comedi_subdevice * s,
511 struct comedi_insn * insn, unsigned int * data)
513 int chan = CR_CHAN(insn->chanspec);
516 for (i = 0; i < insn->n; i++) {
517 outb((data[i] & 0xff),
518 dev->iobase + (chan ? PCL812_DA2_LO : PCL812_DA1_LO));
519 outb((data[i] >> 8) & 0x0f,
520 dev->iobase + (chan ? PCL812_DA2_HI : PCL812_DA1_HI));
521 devpriv->ao_readback[chan] = data[i];
528 ==============================================================================
530 static int pcl812_ao_insn_read(struct comedi_device * dev, struct comedi_subdevice * s,
531 struct comedi_insn * insn, unsigned int * data)
533 int chan = CR_CHAN(insn->chanspec);
536 for (i = 0; i < insn->n; i++) {
537 data[i] = devpriv->ao_readback[chan];
544 ==============================================================================
546 static int pcl812_di_insn_bits(struct comedi_device * dev, struct comedi_subdevice * s,
547 struct comedi_insn * insn, unsigned int * data)
552 data[1] = inb(dev->iobase + PCL812_DI_LO);
553 data[1] |= inb(dev->iobase + PCL812_DI_HI) << 8;
559 ==============================================================================
561 static int pcl812_do_insn_bits(struct comedi_device * dev, struct comedi_subdevice * s,
562 struct comedi_insn * insn, unsigned int * data)
568 s->state &= ~data[0];
569 s->state |= data[0] & data[1];
570 outb(s->state & 0xff, dev->iobase + PCL812_DO_LO);
571 outb((s->state >> 8), dev->iobase + PCL812_DO_HI);
578 #ifdef PCL812_EXTDEBUG
580 ==============================================================================
582 static void pcl812_cmdtest_out(int e, struct comedi_cmd * cmd)
584 rt_printk("pcl812 e=%d startsrc=%x scansrc=%x convsrc=%x\n", e,
585 cmd->start_src, cmd->scan_begin_src, cmd->convert_src);
586 rt_printk("pcl812 e=%d startarg=%d scanarg=%d convarg=%d\n", e,
587 cmd->start_arg, cmd->scan_begin_arg, cmd->convert_arg);
588 rt_printk("pcl812 e=%d stopsrc=%x scanend=%x\n", e, cmd->stop_src,
590 rt_printk("pcl812 e=%d stoparg=%d scanendarg=%d chanlistlen=%d\n", e,
591 cmd->stop_arg, cmd->scan_end_arg, cmd->chanlist_len);
596 ==============================================================================
598 static int pcl812_ai_cmdtest(struct comedi_device * dev, struct comedi_subdevice * s,
599 struct comedi_cmd * cmd)
602 int tmp, divisor1, divisor2;
604 #ifdef PCL812_EXTDEBUG
605 rt_printk("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...)\n");
606 pcl812_cmdtest_out(-1, cmd);
608 /* step 1: make sure trigger sources are trivially valid */
610 tmp = cmd->start_src;
611 cmd->start_src &= TRIG_NOW;
612 if (!cmd->start_src || tmp != cmd->start_src)
615 tmp = cmd->scan_begin_src;
616 cmd->scan_begin_src &= TRIG_FOLLOW;
617 if (!cmd->scan_begin_src || tmp != cmd->scan_begin_src)
620 tmp = cmd->convert_src;
621 if (devpriv->use_ext_trg) {
622 cmd->convert_src &= TRIG_EXT;
624 cmd->convert_src &= TRIG_TIMER;
626 if (!cmd->convert_src || tmp != cmd->convert_src)
629 tmp = cmd->scan_end_src;
630 cmd->scan_end_src &= TRIG_COUNT;
631 if (!cmd->scan_end_src || tmp != cmd->scan_end_src)
635 cmd->stop_src &= TRIG_COUNT | TRIG_NONE;
636 if (!cmd->stop_src || tmp != cmd->stop_src)
640 #ifdef PCL812_EXTDEBUG
641 pcl812_cmdtest_out(1, cmd);
643 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=1\n",
649 /* step 2: make sure trigger sources are unique and mutually compatible */
651 if (cmd->start_src != TRIG_NOW) {
652 cmd->start_src = TRIG_NOW;
656 if (cmd->scan_begin_src != TRIG_FOLLOW) {
657 cmd->scan_begin_src = TRIG_FOLLOW;
661 if (devpriv->use_ext_trg) {
662 if (cmd->convert_src != TRIG_EXT) {
663 cmd->convert_src = TRIG_EXT;
667 if (cmd->convert_src != TRIG_TIMER) {
668 cmd->convert_src = TRIG_TIMER;
673 if (cmd->scan_end_src != TRIG_COUNT) {
674 cmd->scan_end_src = TRIG_COUNT;
678 if (cmd->stop_src != TRIG_NONE && cmd->stop_src != TRIG_COUNT)
682 #ifdef PCL812_EXTDEBUG
683 pcl812_cmdtest_out(2, cmd);
685 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=2\n",
691 /* step 3: make sure arguments are trivially compatible */
693 if (cmd->start_arg != 0) {
698 if (cmd->scan_begin_arg != 0) {
699 cmd->scan_begin_arg = 0;
703 if (cmd->convert_src == TRIG_TIMER) {
704 if (cmd->convert_arg < this_board->ai_ns_min) {
705 cmd->convert_arg = this_board->ai_ns_min;
708 } else { /* TRIG_EXT */
709 if (cmd->convert_arg != 0) {
710 cmd->convert_arg = 0;
715 if (!cmd->chanlist_len) {
716 cmd->chanlist_len = 1;
719 if (cmd->chanlist_len > MAX_CHANLIST_LEN) {
720 cmd->chanlist_len = this_board->n_aichan;
723 if (cmd->scan_end_arg != cmd->chanlist_len) {
724 cmd->scan_end_arg = cmd->chanlist_len;
727 if (cmd->stop_src == TRIG_COUNT) {
728 if (!cmd->stop_arg) {
732 } else { /* TRIG_NONE */
733 if (cmd->stop_arg != 0) {
740 #ifdef PCL812_EXTDEBUG
741 pcl812_cmdtest_out(3, cmd);
743 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=3\n",
749 /* step 4: fix up any arguments */
751 if (cmd->convert_src == TRIG_TIMER) {
752 tmp = cmd->convert_arg;
753 i8253_cascade_ns_to_timer(this_board->i8254_osc_base, &divisor1,
754 &divisor2, &cmd->convert_arg,
755 cmd->flags & TRIG_ROUND_MASK);
756 if (cmd->convert_arg < this_board->ai_ns_min)
757 cmd->convert_arg = this_board->ai_ns_min;
758 if (tmp != cmd->convert_arg)
763 #ifdef PCL812_EXTDEBUG
765 ("pcl812 EDBG: BGN: pcl812_ai_cmdtest(...) err=%d ret=4\n",
775 ==============================================================================
777 static int pcl812_ai_cmd(struct comedi_device * dev, struct comedi_subdevice * s)
779 unsigned int divisor1 = 0, divisor2 = 0, i, dma_flags, bytes;
780 struct comedi_cmd *cmd = &s->async->cmd;
782 #ifdef PCL812_EXTDEBUG
783 rt_printk("pcl812 EDBG: BGN: pcl812_ai_cmd(...)\n");
786 if (cmd->start_src != TRIG_NOW)
788 if (cmd->scan_begin_src != TRIG_FOLLOW)
790 if (devpriv->use_ext_trg) {
791 if (cmd->convert_src != TRIG_EXT)
794 if (cmd->convert_src != TRIG_TIMER)
797 if (cmd->scan_end_src != TRIG_COUNT)
799 if (cmd->scan_end_arg != cmd->chanlist_len)
801 if (cmd->chanlist_len > MAX_CHANLIST_LEN)
804 if (cmd->convert_src == TRIG_TIMER) {
805 if (cmd->convert_arg < this_board->ai_ns_min)
806 cmd->convert_arg = this_board->ai_ns_min;
807 i8253_cascade_ns_to_timer(this_board->i8254_osc_base,
808 &divisor1, &divisor2, &cmd->convert_arg,
809 cmd->flags & TRIG_ROUND_MASK);
812 start_pacer(dev, -1, 0, 0); // stop pacer
814 devpriv->ai_n_chan = cmd->chanlist_len;
815 memcpy(devpriv->ai_chanlist, cmd->chanlist,
816 sizeof(unsigned int) * cmd->scan_end_arg);
817 setup_range_channel(dev, s, devpriv->ai_chanlist[0], 1); // select first channel and range
819 if (devpriv->dma) { // check if we can use DMA transfer
821 for (i = 1; i < devpriv->ai_n_chan; i++)
822 if (devpriv->ai_chanlist[0] != devpriv->ai_chanlist[i]) {
823 devpriv->ai_dma = 0; // we cann't use DMA :-(
829 devpriv->ai_flags = cmd->flags;
830 devpriv->ai_data_len = s->async->prealloc_bufsz;
831 devpriv->ai_data = s->async->prealloc_buf;
832 if (cmd->stop_src == TRIG_COUNT) {
833 devpriv->ai_scans = cmd->stop_arg;
834 devpriv->ai_neverending = 0;
836 devpriv->ai_scans = 0;
837 devpriv->ai_neverending = 1;
840 devpriv->ai_act_scan = 0;
841 devpriv->ai_poll_ptr = 0;
842 s->async->cur_chan = 0;
844 if ((devpriv->ai_flags & TRIG_WAKE_EOS)) { // don't we want wake up every scan?
846 if (devpriv->ai_n_chan == 1)
847 devpriv->ai_dma = 0; // DMA is useless for this situation
850 if (devpriv->ai_dma) {
851 if (devpriv->ai_eos) { // we use EOS, so adapt DMA buffer to one scan
852 devpriv->dmabytestomove[0] =
853 devpriv->ai_n_chan * sizeof(short);
854 devpriv->dmabytestomove[1] =
855 devpriv->ai_n_chan * sizeof(short);
856 devpriv->dma_runs_to_end = 1;
858 devpriv->dmabytestomove[0] = devpriv->hwdmasize[0];
859 devpriv->dmabytestomove[1] = devpriv->hwdmasize[1];
860 if (devpriv->ai_data_len < devpriv->hwdmasize[0])
861 devpriv->dmabytestomove[0] =
862 devpriv->ai_data_len;
863 if (devpriv->ai_data_len < devpriv->hwdmasize[1])
864 devpriv->dmabytestomove[1] =
865 devpriv->ai_data_len;
866 if (devpriv->ai_neverending) {
867 devpriv->dma_runs_to_end = 1;
869 bytes = devpriv->ai_n_chan * devpriv->ai_scans * sizeof(short); // how many samples we must transfer?
870 devpriv->dma_runs_to_end = bytes / devpriv->dmabytestomove[0]; // how many DMA pages we must fill
871 devpriv->last_dma_run = bytes % devpriv->dmabytestomove[0]; //on last dma transfer must be moved
872 if (devpriv->dma_runs_to_end == 0)
873 devpriv->dmabytestomove[0] =
874 devpriv->last_dma_run;
875 devpriv->dma_runs_to_end--;
878 if (devpriv->dmabytestomove[0] > devpriv->hwdmasize[0]) {
879 devpriv->dmabytestomove[0] = devpriv->hwdmasize[0];
882 if (devpriv->dmabytestomove[1] > devpriv->hwdmasize[1]) {
883 devpriv->dmabytestomove[1] = devpriv->hwdmasize[1];
886 devpriv->next_dma_buf = 0;
887 set_dma_mode(devpriv->dma, DMA_MODE_READ);
888 dma_flags = claim_dma_lock();
889 clear_dma_ff(devpriv->dma);
890 set_dma_addr(devpriv->dma, devpriv->hwdmaptr[0]);
891 set_dma_count(devpriv->dma, devpriv->dmabytestomove[0]);
892 release_dma_lock(dma_flags);
893 enable_dma(devpriv->dma);
894 #ifdef PCL812_EXTDEBUG
896 ("pcl812 EDBG: DMA %d PTR 0x%0x/0x%0x LEN %u/%u EOS %d\n",
897 devpriv->dma, devpriv->hwdmaptr[0],
898 devpriv->hwdmaptr[1], devpriv->dmabytestomove[0],
899 devpriv->dmabytestomove[1], devpriv->ai_eos);
903 switch (cmd->convert_src) {
905 start_pacer(dev, 1, divisor1, divisor2);
909 if (devpriv->ai_dma) {
910 outb(devpriv->mode_reg_int | 2, dev->iobase + PCL812_MODE); // let's go!
912 outb(devpriv->mode_reg_int | 6, dev->iobase + PCL812_MODE); // let's go!
915 #ifdef PCL812_EXTDEBUG
916 rt_printk("pcl812 EDBG: END: pcl812_ai_cmd(...)\n");
923 ==============================================================================
925 static irqreturn_t interrupt_pcl812_ai_int(int irq, void *d)
928 unsigned int mask, timeout;
929 struct comedi_device *dev = d;
930 struct comedi_subdevice *s = dev->subdevices + 0;
932 s->async->events = 0;
934 timeout = 50; /* wait max 50us, it must finish under 33us */
935 if (devpriv->ai_is16b) {
938 if (!(inb(dev->iobase + ACL8216_STATUS) & ACL8216_DRDY)) {
947 if (!(inb(dev->iobase + PCL812_AD_HI) & PCL812_DRDY)) {
957 ("comedi%d: pcl812: (%s at 0x%lx) A/D cmd IRQ without DRDY!\n",
958 dev->minor, dev->board_name, dev->iobase);
959 pcl812_ai_cancel(dev, s);
960 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
961 comedi_event(dev, s);
965 comedi_buf_put(s->async,
966 ((inb(dev->iobase + PCL812_AD_HI) << 8) | inb(dev->iobase +
967 PCL812_AD_LO)) & mask);
969 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
971 if (s->async->cur_chan == 0) { /* one scan done */
972 devpriv->ai_act_scan++;
973 if (!(devpriv->ai_neverending))
974 if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */
975 pcl812_ai_cancel(dev, s);
976 s->async->events |= COMEDI_CB_EOA;
980 comedi_event(dev, s);
985 ==============================================================================
987 static void transfer_from_dma_buf(struct comedi_device * dev, struct comedi_subdevice * s,
988 short * ptr, unsigned int bufptr, unsigned int len)
992 s->async->events = 0;
993 for (i = len; i; i--) {
994 comedi_buf_put(s->async, ptr[bufptr++]); // get one sample
996 if (s->async->cur_chan == 0) {
997 devpriv->ai_act_scan++;
998 if (!devpriv->ai_neverending)
999 if (devpriv->ai_act_scan >= devpriv->ai_scans) { /* all data sampled */
1000 pcl812_ai_cancel(dev, s);
1001 s->async->events |= COMEDI_CB_EOA;
1007 comedi_event(dev, s);
1011 ==============================================================================
1013 static irqreturn_t interrupt_pcl812_ai_dma(int irq, void *d)
1015 struct comedi_device *dev = d;
1016 struct comedi_subdevice *s = dev->subdevices + 0;
1017 unsigned long dma_flags;
1021 #ifdef PCL812_EXTDEBUG
1022 rt_printk("pcl812 EDBG: BGN: interrupt_pcl812_ai_dma(...)\n");
1024 ptr = (short *) devpriv->dmabuf[devpriv->next_dma_buf];
1025 len = (devpriv->dmabytestomove[devpriv->next_dma_buf] >> 1) -
1026 devpriv->ai_poll_ptr;
1028 devpriv->next_dma_buf = 1 - devpriv->next_dma_buf;
1029 disable_dma(devpriv->dma);
1030 set_dma_mode(devpriv->dma, DMA_MODE_READ);
1031 dma_flags = claim_dma_lock();
1032 set_dma_addr(devpriv->dma, devpriv->hwdmaptr[devpriv->next_dma_buf]);
1033 if (devpriv->ai_eos) {
1034 set_dma_count(devpriv->dma,
1035 devpriv->dmabytestomove[devpriv->next_dma_buf]);
1037 if (devpriv->dma_runs_to_end) {
1038 set_dma_count(devpriv->dma,
1039 devpriv->dmabytestomove[devpriv->next_dma_buf]);
1041 set_dma_count(devpriv->dma, devpriv->last_dma_run);
1043 devpriv->dma_runs_to_end--;
1045 release_dma_lock(dma_flags);
1046 enable_dma(devpriv->dma);
1048 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
1050 bufptr = devpriv->ai_poll_ptr;
1051 devpriv->ai_poll_ptr = 0;
1053 transfer_from_dma_buf(dev, s, ptr, bufptr, len);
1055 #ifdef PCL812_EXTDEBUG
1056 rt_printk("pcl812 EDBG: END: interrupt_pcl812_ai_dma(...)\n");
1062 ==============================================================================
1064 static irqreturn_t interrupt_pcl812(int irq, void *d PT_REGS_ARG)
1066 struct comedi_device *dev = d;
1068 if (!dev->attached) {
1069 comedi_error(dev, "spurious interrupt");
1072 if (devpriv->ai_dma) {
1073 return interrupt_pcl812_ai_dma(irq, d);
1075 return interrupt_pcl812_ai_int(irq, d);
1080 ==============================================================================
1082 static int pcl812_ai_poll(struct comedi_device * dev, struct comedi_subdevice * s)
1084 unsigned long flags;
1085 unsigned int top1, top2, i;
1087 if (!devpriv->ai_dma)
1088 return 0; // poll is valid only for DMA transfer
1090 comedi_spin_lock_irqsave(&dev->spinlock, flags);
1092 for (i = 0; i < 10; i++) {
1093 top1 = get_dma_residue(devpriv->ai_dma); // where is now DMA
1094 top2 = get_dma_residue(devpriv->ai_dma);
1100 comedi_spin_unlock_irqrestore(&dev->spinlock, flags);
1104 top1 = devpriv->dmabytestomove[1 - devpriv->next_dma_buf] - top1; // where is now DMA in buffer
1105 top1 >>= 1; // sample position
1106 top2 = top1 - devpriv->ai_poll_ptr;
1107 if (top2 < 1) { // no new samples
1108 comedi_spin_unlock_irqrestore(&dev->spinlock, flags);
1112 transfer_from_dma_buf(dev, s,
1113 (void *)devpriv->dmabuf[1 - devpriv->next_dma_buf],
1114 devpriv->ai_poll_ptr, top2);
1116 devpriv->ai_poll_ptr = top1; // new buffer position
1118 comedi_spin_unlock_irqrestore(&dev->spinlock, flags);
1120 return s->async->buf_write_count - s->async->buf_read_count;
1124 ==============================================================================
1126 static void setup_range_channel(struct comedi_device * dev, struct comedi_subdevice * s,
1127 unsigned int rangechan, char wait)
1129 unsigned char chan_reg = CR_CHAN(rangechan); // normal board
1130 unsigned char gain_reg = CR_RANGE(rangechan) + devpriv->range_correction; // gain index
1132 if ((chan_reg == devpriv->old_chan_reg)
1133 && (gain_reg == devpriv->old_gain_reg))
1134 return; // we can return, no change
1136 devpriv->old_chan_reg = chan_reg;
1137 devpriv->old_gain_reg = gain_reg;
1139 if (devpriv->use_MPC) {
1140 if (devpriv->use_diff) {
1141 chan_reg = chan_reg | 0x30; // DIFF inputs
1143 if (chan_reg & 0x80) {
1144 chan_reg = chan_reg | 0x20; // SE inputs 8-15
1146 chan_reg = chan_reg | 0x10; // SE inputs 0-7
1151 outb(chan_reg, dev->iobase + PCL812_MUX); /* select channel */
1152 outb(gain_reg, dev->iobase + PCL812_GAIN); /* select gain */
1155 comedi_udelay(devpriv->max_812_ai_mode0_rangewait); // XXX this depends on selected range and can be very long for some high gain ranges!
1160 ==============================================================================
1162 static void start_pacer(struct comedi_device * dev, int mode, unsigned int divisor1,
1163 unsigned int divisor2)
1165 #ifdef PCL812_EXTDEBUG
1166 rt_printk("pcl812 EDBG: BGN: start_pacer(%d,%u,%u)\n", mode, divisor1,
1169 outb(0xb4, dev->iobase + PCL812_CTRCTL);
1170 outb(0x74, dev->iobase + PCL812_CTRCTL);
1174 outb(divisor2 & 0xff, dev->iobase + PCL812_CTR2);
1175 outb((divisor2 >> 8) & 0xff, dev->iobase + PCL812_CTR2);
1176 outb(divisor1 & 0xff, dev->iobase + PCL812_CTR1);
1177 outb((divisor1 >> 8) & 0xff, dev->iobase + PCL812_CTR1);
1179 #ifdef PCL812_EXTDEBUG
1180 rt_printk("pcl812 EDBG: END: start_pacer(...)\n");
1185 ==============================================================================
1187 static void free_resources(struct comedi_device * dev)
1191 if (devpriv->dmabuf[0])
1192 free_pages(devpriv->dmabuf[0], devpriv->dmapages[0]);
1193 if (devpriv->dmabuf[1])
1194 free_pages(devpriv->dmabuf[1], devpriv->dmapages[1]);
1196 free_dma(devpriv->dma);
1199 comedi_free_irq(dev->irq, dev);
1201 release_region(dev->iobase, this_board->io_range);
1205 ==============================================================================
1207 static int pcl812_ai_cancel(struct comedi_device * dev, struct comedi_subdevice * s)
1209 #ifdef PCL812_EXTDEBUG
1210 rt_printk("pcl812 EDBG: BGN: pcl812_ai_cancel(...)\n");
1212 if (devpriv->ai_dma)
1213 disable_dma(devpriv->dma);
1214 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
1215 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE); /* Stop A/D */
1216 start_pacer(dev, -1, 0, 0); // stop 8254
1217 outb(0, dev->iobase + PCL812_CLRINT); /* clear INT request */
1218 #ifdef PCL812_EXTDEBUG
1219 rt_printk("pcl812 EDBG: END: pcl812_ai_cancel(...)\n");
1225 ==============================================================================
1227 static void pcl812_reset(struct comedi_device * dev)
1229 #ifdef PCL812_EXTDEBUG
1230 rt_printk("pcl812 EDBG: BGN: pcl812_reset(...)\n");
1232 outb(0, dev->iobase + PCL812_MUX);
1233 outb(0 + devpriv->range_correction, dev->iobase + PCL812_GAIN);
1234 devpriv->old_chan_reg = -1; // invalidate chain/gain memory
1235 devpriv->old_gain_reg = -1;
1237 switch (this_board->board_type) {
1242 outb(0, dev->iobase + PCL812_DA2_LO);
1243 outb(0, dev->iobase + PCL812_DA2_HI);
1245 outb(0, dev->iobase + PCL812_DA1_LO);
1246 outb(0, dev->iobase + PCL812_DA1_HI);
1247 start_pacer(dev, -1, 0, 0); // stop 8254
1248 outb(0, dev->iobase + PCL812_DO_HI);
1249 outb(0, dev->iobase + PCL812_DO_LO);
1250 outb(devpriv->mode_reg_int | 0, dev->iobase + PCL812_MODE);
1251 outb(0, dev->iobase + PCL812_CLRINT);
1261 #ifdef PCL812_EXTDEBUG
1262 rt_printk("pcl812 EDBG: END: pcl812_reset(...)\n");
1267 ==============================================================================
1269 static int pcl812_attach(struct comedi_device * dev, struct comedi_devconfig * it)
1272 unsigned long iobase;
1275 unsigned long pages;
1276 struct comedi_subdevice *s;
1279 iobase = it->options[0];
1280 printk("comedi%d: pcl812: board=%s, ioport=0x%03lx", dev->minor,
1281 this_board->name, iobase);
1283 if (!request_region(iobase, this_board->io_range, "pcl812")) {
1284 printk("I/O port conflict\n");
1287 dev->iobase = iobase;
1289 if ((ret = alloc_private(dev, sizeof(struct pcl812_private))) < 0) {
1290 free_resources(dev);
1291 return ret; /* Can't alloc mem */
1294 dev->board_name = this_board->name;
1297 if (this_board->IRQbits != 0) { /* board support IRQ */
1298 irq = it->options[1];
1299 if (irq) { /* we want to use IRQ */
1300 if (((1 << irq) & this_board->IRQbits) == 0) {
1301 printk(", IRQ %u is out of allowed range, DISABLING IT", irq);
1302 irq = 0; /* Bad IRQ */
1304 if (comedi_request_irq(irq, interrupt_pcl812, 0,
1306 printk(", unable to allocate IRQ %u, DISABLING IT", irq);
1307 irq = 0; /* Can't use IRQ */
1309 printk(", irq=%u", irq);
1320 goto no_dma; /* if we haven't IRQ, we can't use DMA */
1321 if (this_board->DMAbits != 0) { /* board support DMA */
1322 dma = it->options[2];
1323 if (((1 << dma) & this_board->DMAbits) == 0) {
1324 printk(", DMA is out of allowed range, FAIL!\n");
1325 return -EINVAL; /* Bad DMA */
1327 ret = request_dma(dma, "pcl812");
1329 printk(", unable to allocate DMA %u, FAIL!\n", dma);
1330 return -EBUSY; /* DMA isn't free */
1333 printk(", dma=%u", dma);
1334 pages = 1; /* we want 8KB */
1335 devpriv->dmabuf[0] = __get_dma_pages(GFP_KERNEL, pages);
1336 if (!devpriv->dmabuf[0]) {
1337 printk(", unable to allocate DMA buffer, FAIL!\n");
1338 /* maybe experiment with try_to_free_pages() will help .... */
1339 free_resources(dev);
1340 return -EBUSY; /* no buffer :-( */
1342 devpriv->dmapages[0] = pages;
1343 devpriv->hwdmaptr[0] = virt_to_bus((void *)devpriv->dmabuf[0]);
1344 devpriv->hwdmasize[0] = PAGE_SIZE * (1 << pages);
1345 devpriv->dmabuf[1] = __get_dma_pages(GFP_KERNEL, pages);
1346 if (!devpriv->dmabuf[1]) {
1347 printk(", unable to allocate DMA buffer, FAIL!\n");
1348 free_resources(dev);
1351 devpriv->dmapages[1] = pages;
1352 devpriv->hwdmaptr[1] = virt_to_bus((void *)devpriv->dmabuf[1]);
1353 devpriv->hwdmasize[1] = PAGE_SIZE * (1 << pages);
1358 if (this_board->n_aichan > 0)
1360 if (this_board->n_aochan > 0)
1362 if (this_board->n_dichan > 0)
1364 if (this_board->n_dochan > 0)
1367 if ((ret = alloc_subdevices(dev, n_subdevices)) < 0) {
1368 free_resources(dev);
1375 if (this_board->n_aichan > 0) {
1376 s = dev->subdevices + subdev;
1377 s->type = COMEDI_SUBD_AI;
1378 s->subdev_flags = SDF_READABLE;
1379 switch (this_board->board_type) {
1381 if (it->options[2] == 1) {
1382 s->n_chan = this_board->n_aichan_diff;
1383 s->subdev_flags |= SDF_DIFF;
1384 devpriv->use_diff = 1;
1386 s->n_chan = this_board->n_aichan;
1387 s->subdev_flags |= SDF_GROUND;
1392 if (it->options[4] == 1) {
1393 s->n_chan = this_board->n_aichan_diff;
1394 s->subdev_flags |= SDF_DIFF;
1395 devpriv->use_diff = 1;
1397 s->n_chan = this_board->n_aichan;
1398 s->subdev_flags |= SDF_GROUND;
1402 s->n_chan = this_board->n_aichan;
1403 s->subdev_flags |= SDF_GROUND;
1406 s->maxdata = this_board->ai_maxdata;
1407 s->len_chanlist = MAX_CHANLIST_LEN;
1408 s->range_table = this_board->rangelist_ai;
1409 if (this_board->board_type == boardACL8216) {
1410 s->insn_read = acl8216_ai_insn_read;
1412 s->insn_read = pcl812_ai_insn_read;
1414 devpriv->use_MPC = this_board->haveMPC508;
1415 s->cancel = pcl812_ai_cancel;
1417 dev->read_subdev = s;
1418 s->subdev_flags |= SDF_CMD_READ;
1419 s->do_cmdtest = pcl812_ai_cmdtest;
1420 s->do_cmd = pcl812_ai_cmd;
1421 s->poll = pcl812_ai_poll;
1423 switch (this_board->board_type) {
1425 if (it->options[4] == 1)
1426 s->range_table = &range_pcl812pg2_ai;
1429 switch (it->options[4]) {
1431 s->range_table = &range_bipolar10;
1434 s->range_table = &range_bipolar5;
1437 s->range_table = &range_bipolar2_5;
1440 s->range_table = &range812_bipolar1_25;
1443 s->range_table = &range812_bipolar0_625;
1446 s->range_table = &range812_bipolar0_3125;
1449 s->range_table = &range_bipolar10;
1451 printk(", incorrect range number %d, changing to 0 (+/-10V)", it->options[4]);
1457 if (it->options[1] == 1)
1458 s->range_table = &range_pcl813b2_ai;
1461 switch (it->options[1]) {
1463 s->range_table = &range_iso813_1_ai;
1466 s->range_table = &range_iso813_1_2_ai;
1469 s->range_table = &range_iso813_2_ai;
1470 devpriv->range_correction = 1;
1473 s->range_table = &range_iso813_2_2_ai;
1474 devpriv->range_correction = 1;
1477 s->range_table = &range_iso813_1_ai;
1479 printk(", incorrect range number %d, changing to 0 ", it->options[1]);
1484 switch (it->options[1]) {
1486 s->range_table = &range_acl8113_1_ai;
1489 s->range_table = &range_acl8113_1_2_ai;
1492 s->range_table = &range_acl8113_2_ai;
1493 devpriv->range_correction = 1;
1496 s->range_table = &range_acl8113_2_2_ai;
1497 devpriv->range_correction = 1;
1500 s->range_table = &range_acl8113_1_ai;
1502 printk(", incorrect range number %d, changing to 0 ", it->options[1]);
1511 if (this_board->n_aochan > 0) {
1512 s = dev->subdevices + subdev;
1513 s->type = COMEDI_SUBD_AO;
1514 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
1515 s->n_chan = this_board->n_aochan;
1517 s->len_chanlist = 1;
1518 s->range_table = this_board->rangelist_ao;
1519 s->insn_read = pcl812_ao_insn_read;
1520 s->insn_write = pcl812_ao_insn_write;
1521 switch (this_board->board_type) {
1523 if (it->options[3] == 1)
1524 s->range_table = &range_unipolar10;
1530 if (it->options[5] == 1)
1531 s->range_table = &range_unipolar10;
1532 if (it->options[5] == 2)
1533 s->range_table = &range_unknown;
1540 if (this_board->n_dichan > 0) {
1541 s = dev->subdevices + subdev;
1542 s->type = COMEDI_SUBD_DI;
1543 s->subdev_flags = SDF_READABLE;
1544 s->n_chan = this_board->n_dichan;
1546 s->len_chanlist = this_board->n_dichan;
1547 s->range_table = &range_digital;
1548 s->insn_bits = pcl812_di_insn_bits;
1552 /* digital output */
1553 if (this_board->n_dochan > 0) {
1554 s = dev->subdevices + subdev;
1555 s->type = COMEDI_SUBD_DO;
1556 s->subdev_flags = SDF_WRITABLE;
1557 s->n_chan = this_board->n_dochan;
1559 s->len_chanlist = this_board->n_dochan;
1560 s->range_table = &range_digital;
1561 s->insn_bits = pcl812_do_insn_bits;
1565 switch (this_board->board_type) {
1567 devpriv->ai_is16b = 1;
1571 devpriv->max_812_ai_mode0_rangewait = 1;
1572 if (it->options[3] > 0)
1573 devpriv->use_ext_trg = 1; // we use external trigger
1575 devpriv->max_812_ai_mode0_rangewait = 1;
1576 devpriv->mode_reg_int = (irq << 4) & 0xf0;
1582 devpriv->max_812_ai_mode0_rangewait = 5; /* maybe there must by greatest timeout */
1595 ==============================================================================
1597 static int pcl812_detach(struct comedi_device * dev)
1600 #ifdef PCL812_EXTDEBUG
1601 rt_printk("comedi%d: pcl812: remove\n", dev->minor);
1603 free_resources(dev);