3 * driver for Intelligent Instruments PCI-20001C carrier board
6 * Copyright (C) 2000 Markus Kempf <kempf@matsci.uni-sb.de>
7 * with suggestions from David Schleef
10 * Linux device driver for COMEDI
11 * Intelligent Instrumentation
12 * PCI-20001 C-2A Carrier Board
13 * PCI-20341 M-1A 16-Bit analog input module
17 * PCI-20006 M-2 16-Bit analog output module
18 * - ranges (-10V - +10V) (0V - +10V) (-5V - +5V)
21 * only ONE PCI-20341 module possible
22 * only ONE PCI-20006 module possible
23 * no extern trigger implemented
25 * NOT WORKING (but soon) only 4 on-board differential channels supported
26 * NOT WORKING (but soon) only ONE di-port and ONE do-port supported instead of 4 digital ports
30 * The state of this driver is only a starting point for a complete
31 * COMEDI-driver. The final driver should support all features of the
32 * carrier board and modules.
34 * The test configuration:
36 * kernel 2.2.14 with RTAI v1.2 and patch-2.2.14rthal2
43 Description: Intelligent Instruments PCI-20001C carrier board
44 Author: Markus Kempf <kempf@matsci.uni-sb.de>
45 Devices: [Intelligent Instrumentation] PCI-20001C (ii_pci20kc)
48 Supports the PCI-20001 C-2a Carrier board, and could probably support
49 the other carrier boards with small modifications. Modules supported
51 PCI-20006 M-2 16-bit analog output module
52 PCI-20341 M-1A 16-bit analog input module
57 2 first option for module 1
58 3 second option for module 1
59 4 first option for module 2
60 5 second option for module 2
61 6 first option for module 3
62 7 second option for module 3
64 options for PCI-20006M:
65 first: Analog output channel 0 range configuration
66 0 bipolar 10 (-10V -- +10V)
67 1 unipolar 10 (0V -- +10V)
68 2 bipolar 5 (-5V -- 5V)
69 second: Analog output channel 1 range configuration
71 options for PCI-20341M:
72 first: Analog input gain configuration
79 /* XXX needs to use ioremap() for compatibility with 2.4 kernels. Should also
80 * check_mem_region() etc. - fmhess */
82 #include <linux/comedidev.h>
85 #define PCI20000_ID 0x1d
86 #define PCI20341_ID 0x77
87 #define PCI20006_ID 0xe3
88 #define PCI20xxx_EMPTY_ID 0xff
90 #define PCI20000_OFFSET 0x100
91 #define PCI20000_MODULES 3
93 #define PCI20000_DIO_0 0x80
94 #define PCI20000_DIO_1 0x81
95 #define PCI20000_DIO_2 0xc0
96 #define PCI20000_DIO_3 0xc1
97 #define PCI20000_DIO_CONTROL_01 0x83 /* port 0, 1 control */
98 #define PCI20000_DIO_CONTROL_23 0xc3 /* port 2, 3 control */
99 #define PCI20000_DIO_BUFFER 0x82 /* buffer direction and enable */
100 #define PCI20000_DIO_EOC 0xef /* even port, control output */
101 #define PCI20000_DIO_OOC 0xfd /* odd port, control output */
102 #define PCI20000_DIO_EIC 0x90 /* even port, control input */
103 #define PCI20000_DIO_OIC 0x82 /* odd port, control input */
104 #define DIO_CAND 0x12 /* and bit 1, bit 4 of control */
105 #define DIO_BE 0x01 /* buffer: port enable */
106 #define DIO_BO 0x04 /* buffer: output */
107 #define DIO_BI 0x05 /* buffer: input */
108 #define DIO_PS_0 0x00 /* buffer: port shift 0 */
109 #define DIO_PS_1 0x01 /* buffer: port shift 1 */
110 #define DIO_PS_2 0x04 /* buffer: port shift 2 */
111 #define DIO_PS_3 0x05 /* buffer: port shift 3 */
113 #define PCI20006_LCHAN0 0x0d
114 #define PCI20006_STROBE0 0x0b
115 #define PCI20006_LCHAN1 0x15
116 #define PCI20006_STROBE1 0x13
118 #define PCI20341_INIT 0x04
119 #define PCI20341_REPMODE 0x00 /* single shot mode */
120 #define PCI20341_PACER 0x00 /* Hardware Pacer disabled */
121 #define PCI20341_CHAN_NR 0x04 /* number of input channels */
122 #define PCI20341_CONFIG_REG 0x10
123 #define PCI20341_MOD_STATUS 0x01
124 #define PCI20341_OPT_REG 0x11
125 #define PCI20341_SET_TIME_REG 0x15
126 #define PCI20341_LCHAN_ADDR_REG 0x13
127 #define PCI20341_CHAN_LIST 0x80
128 #define PCI20341_CC_RESET 0x1b
129 #define PCI20341_CHAN_RESET 0x19
130 #define PCI20341_SOFT_PACER 0x04
131 #define PCI20341_STATUS_REG 0x12
132 #define PCI20341_LDATA 0x02
133 #define PCI20341_DAISY_CHAIN 0x20 /* On-board inputs only */
134 #define PCI20341_MUX 0x04 /* Enable on-board MUX */
135 #define PCI20341_SCANLIST 0x80 /* Channel/Gain Scan List */
143 comedi_lrange *ao_range_list[2]; /* range of channels of ao module */
144 lsampl_t last_data[2];
152 } pci20xxx_subdev_private;
156 pci20xxx_subdev_private subdev_private[PCI20000_MODULES];
159 #define devpriv ((pci20xxx_private *)dev->private)
160 #define CHAN (CR_CHAN(it->chanlist[0]))
162 static int pci20xxx_attach(comedi_device * dev, comedi_devconfig * it);
163 static int pci20xxx_detach(comedi_device * dev);
165 static comedi_driver driver_pci20xxx = {
166 driver_name: "ii_pci20kc",
168 attach: pci20xxx_attach,
169 detach: pci20xxx_detach,
172 static int pci20006_init(comedi_device * dev,comedi_subdevice *s,
174 static int pci20341_init(comedi_device * dev,comedi_subdevice *s,
176 static int pci20xxx_dio_init(comedi_device * dev,comedi_subdevice *s);
179 options[0] Board base address
181 options[2] first option for module 1
182 options[3] second option for module 1
183 options[4] first option for module 2
184 options[5] second option for module 2
185 options[6] first option for module 3
186 options[7] second option for module 3
188 options for PCI-20341M:
189 first Analog input gain configuration
195 options for PCI-20006M:
196 first Analog output channel 0 range configuration
197 0 == bipolar 10 (-10V -- +10V)
198 1 == unipolar 10V (0V -- +10V)
199 2 == bipolar 5V (-5V -- +5V)
200 second Analog output channel 1 range configuration
201 0 == bipolar 10 (-10V -- +10V)
202 1 == unipolar 10V (0V -- +10V)
203 2 == bipolar 5V (-5V -- +5V)
205 static int pci20xxx_attach(comedi_device * dev, comedi_devconfig * it)
211 pci20xxx_subdev_private *sdp;
213 if ((ret = alloc_subdevices(dev, 1 + PCI20000_MODULES)) < 0)
215 if ((ret = alloc_private(dev, sizeof(pci20xxx_private))) < 0)
218 devpriv->ioaddr = (void*) it->options[0];
219 dev->board_name = "pci20kc";
221 /* Check PCI-20001 C-2A Carrier Board ID */
222 if ((readb(devpriv->ioaddr) & PCI20000_ID) != PCI20000_ID) {
223 printk("comedi%d: ii_pci20kc", dev->minor);
224 printk(" PCI-20001 C-2A Carrier Board at base=0x%p not found !\n", devpriv->ioaddr);
227 printk("comedi%d:\n", dev->minor);
228 printk("ii_pci20kc: PCI-20001 C-2A at base=0x%p\n", devpriv->ioaddr);
230 for (i = 0; i < PCI20000_MODULES; i++) {
231 s = dev->subdevices + i;
232 id = readb(devpriv->ioaddr + (i+1) * PCI20000_OFFSET);
233 s->private = devpriv->subdev_private +i;
237 sdp->pci20006.iobase = devpriv->ioaddr + (i+1) * PCI20000_OFFSET;
238 pci20006_init(dev,s,it->options[2*i+2],it->options[2*i+3]);
239 printk("comedi%d: ii_pci20kc", dev->minor);
240 printk(" PCI-20006 module in slot %d \n", i+1);
243 sdp->pci20341.iobase = devpriv->ioaddr + (i+1) * PCI20000_OFFSET;
244 pci20341_init(dev,s,it->options[2*i+2],it->options[2*i+3]);
245 printk("comedi%d: ii_pci20kc", dev->minor);
246 printk(" PCI-20341 module in slot %d \n", i+1);
249 printk("ii_pci20kc: unknown module code 0x%02x in slot %d: module disabled\n",
252 case PCI20xxx_EMPTY_ID:
253 s->type = COMEDI_SUBD_UNUSED;
258 /* initialize pci20xxx_private */
259 pci20xxx_dio_init(dev,dev->subdevices + PCI20000_MODULES);
264 static int pci20xxx_detach(comedi_device * dev)
266 printk("comedi%d: pci20xxx: remove\n", dev->minor);
273 static int pci20006_insn_read(comedi_device * dev, comedi_subdevice * s,
274 comedi_insn *insn, lsampl_t *data);
275 static int pci20006_insn_write(comedi_device * dev, comedi_subdevice * s,
276 comedi_insn *insn, lsampl_t *data);
278 static comedi_lrange *pci20006_range_list[] = {
284 static int pci20006_init(comedi_device * dev,comedi_subdevice *s,
287 pci20xxx_subdev_private *sdp = s->private;
289 if(opt0<0 || opt0>2) opt0=0;
290 if(opt1<0 || opt1>2) opt1=0;
292 sdp->pci20006.ao_range_list[0] = pci20006_range_list[opt0];
293 sdp->pci20006.ao_range_list[1] = pci20006_range_list[opt1];
296 s->type = COMEDI_SUBD_AO;
297 s->subdev_flags = SDF_WRITABLE;
300 s->insn_read = pci20006_insn_read;
301 s->insn_write = pci20006_insn_write;
303 s->range_table_list = sdp->pci20006.ao_range_list;
307 static int pci20006_insn_read(comedi_device * dev, comedi_subdevice * s,
308 comedi_insn *insn, lsampl_t *data)
310 pci20xxx_subdev_private *sdp = s->private;
312 data[0] = sdp->pci20006.last_data[CR_CHAN(insn->chanspec)];
317 static int pci20006_insn_write(comedi_device * dev, comedi_subdevice * s,
318 comedi_insn *insn, lsampl_t *data)
320 pci20xxx_subdev_private *sdp = s->private;
322 unsigned int boarddata;
324 sdp->pci20006.last_data[CR_CHAN(insn->chanspec)] = data[0];
325 boarddata = (((unsigned int)data[0]+0x8000) & 0xffff); /* comedi-data -> board-data */
326 lo = (boarddata & 0xff);
327 hi = ((boarddata >> 8) & 0xff);
329 switch ( CR_CHAN(insn->chanspec)) {
331 writeb(lo, sdp->iobase + PCI20006_LCHAN0);
332 writeb(hi, sdp->iobase + PCI20006_LCHAN0 + 1);
333 writeb(0x00, sdp->iobase + PCI20006_STROBE0);
336 writeb(lo, sdp->iobase + PCI20006_LCHAN1);
337 writeb(hi, sdp->iobase + PCI20006_LCHAN1 + 1);
338 writeb(0x00, sdp->iobase + PCI20006_STROBE1);
341 printk(" comedi%d: pci20xxx: ao channel Error!\n", dev->minor);
350 static int pci20341_insn_read(comedi_device * dev, comedi_subdevice * s,
351 comedi_insn *insn, lsampl_t *data);
353 static int pci20341_timebase[] = { 0x00, 0x00, 0x00, 0x04 };
354 static int pci20341_settling_time[] = { 0x58, 0x58, 0x93, 0x99 };
356 static comedi_lrange range_bipolar0_5 = { 1, { BIP_RANGE(0.5) }};
357 static comedi_lrange range_bipolar0_05 = { 1, { BIP_RANGE(0.05) }};
358 static comedi_lrange range_bipolar0_025 = { 1, { BIP_RANGE(0.025) }};
360 static comedi_lrange *pci20341_ranges[] = {
367 static int pci20341_init(comedi_device * dev,comedi_subdevice *s,
370 pci20xxx_subdev_private *sdp = s->private;
373 /* options handling */
374 if(opt0<0 || opt0>3)opt0=0;
375 sdp->pci20341.timebase = pci20341_timebase[opt0];
376 sdp->pci20341.settling_time = pci20341_settling_time[opt0];
379 s->type = COMEDI_SUBD_AI;
380 s->subdev_flags = SDF_READABLE;
381 s->n_chan = PCI20341_CHAN_NR;
382 s->len_chanlist = PCI20341_SCANLIST;
383 s->insn_read = pci20341_insn_read;
385 s->range_table = pci20341_ranges[opt0];
387 option = sdp->pci20341.timebase | PCI20341_REPMODE; /* depends on gain, trigger, repetition mode */
389 writeb(PCI20341_INIT, sdp->iobase + PCI20341_CONFIG_REG); /* initialize Module */
390 writeb(PCI20341_PACER, sdp->iobase + PCI20341_MOD_STATUS); /* set Pacer */
391 writeb(option, sdp->iobase + PCI20341_OPT_REG); /* option register */
392 writeb(sdp->pci20341.settling_time, sdp->iobase + PCI20341_SET_TIME_REG); /* settling time counter */
393 /* trigger not implemented */
397 static int pci20341_insn_read(comedi_device * dev, comedi_subdevice * s,
398 comedi_insn *insn, lsampl_t *data)
400 pci20xxx_subdev_private *sdp = s->private;
401 unsigned int i = 0, j = 0;
403 unsigned char eoc; /* end of conversion */
404 unsigned int clb; /* channel list byte */
405 unsigned int boarddata;
407 writeb(1, sdp->iobase + PCI20341_LCHAN_ADDR_REG); /* write number of input channels */
408 clb = PCI20341_DAISY_CHAIN
410 | (sdp->pci20341.ai_gain << 3)
411 | CR_CHAN(insn->chanspec);
412 writeb(clb, sdp->iobase + PCI20341_CHAN_LIST);
413 writeb(0x00, sdp->iobase + PCI20341_CC_RESET); /* reset settling time counter and trigger delay counter */
414 writeb(0x00, sdp->iobase + PCI20341_CHAN_RESET);
418 for (i=0; i < insn->n; i++) {
419 /* data polling isn't the niciest way to get the data, I know,
420 * but there are only 6 cycles (mean) and it is easier than
421 * the whole interrupt stuff
424 readb(sdp->iobase + PCI20341_SOFT_PACER); /* generate Pacer */
425 eoc = readb(sdp->iobase + PCI20341_STATUS_REG);
426 while ((eoc < 0x80) && j < 100) { /* poll Interrupt Flag */
428 eoc = readb(sdp->iobase + PCI20341_STATUS_REG);
431 printk("comedi%d: pci20xxx: AI interrupt channel %i polling exit !\n", dev->minor, i);
434 lo = readb(sdp->iobase + PCI20341_LDATA);
435 hi = readb(sdp->iobase + PCI20341_LDATA + 1);
436 boarddata = lo + 0x100 * hi;
437 data[i] = (sampl_t)((boarddata + 0x8000) & 0xffff); /* board-data -> comedi-data */
445 static void pci20xxx_dio_config(comedi_device * dev,comedi_subdevice *s);
446 static int pci20xxx_dio_insn_bits(comedi_device *dev,comedi_subdevice *s,
447 comedi_insn *insn, lsampl_t *data);
448 static int pci20xxx_dio_insn_config(comedi_device *dev,comedi_subdevice *s,
449 comedi_insn *insn, lsampl_t *data);
451 /* initialize pci20xxx_private */
452 static int pci20xxx_dio_init(comedi_device * dev,comedi_subdevice *s)
455 s->type = COMEDI_SUBD_DIO;
456 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
458 s->insn_bits = pci20xxx_dio_insn_bits;
459 s->insn_config = pci20xxx_dio_insn_config;
461 s->len_chanlist = 32;
462 s->range_table = &range_digital;
465 /* digital I/O lines default to input on board reset. */
466 pci20xxx_dio_config(dev,s);
471 static int pci20xxx_dio_insn_config(comedi_device *dev,comedi_subdevice *s,
472 comedi_insn *insn, lsampl_t *data)
476 mask = 1<<CR_CHAN(insn->chanspec);
479 }else if(mask & 0x0000ff00){
481 }else if(mask & 0x00ff0000){
491 pci20xxx_dio_config(dev,s);
496 static int pci20xxx_dio_insn_bits(comedi_device *dev,comedi_subdevice *s,
497 comedi_insn *insn, lsampl_t *data)
499 unsigned int mask = data[0];
502 s->state |= (mask&data[1]);
506 writeb((s->state>>0)&0xff, devpriv->ioaddr + PCI20000_DIO_0 );
508 writeb((s->state>>8)&0xff, devpriv->ioaddr + PCI20000_DIO_1 );
510 writeb((s->state>>16)&0xff, devpriv->ioaddr + PCI20000_DIO_2 );
512 writeb((s->state>>24)&0xff, devpriv->ioaddr + PCI20000_DIO_3 );
514 data[1] = readb(devpriv->ioaddr + PCI20000_DIO_0 );
515 data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_1 )<<8;
516 data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_2 )<<16;
517 data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_3 )<<24;
522 static void pci20xxx_dio_config(comedi_device * dev,comedi_subdevice *s)
524 unsigned char control_01;
525 unsigned char control_23;
526 unsigned char buffer;
528 control_01 = readb(devpriv->ioaddr + PCI20000_DIO_CONTROL_01);
529 control_23 = readb(devpriv->ioaddr + PCI20000_DIO_CONTROL_23);
530 buffer = readb(devpriv->ioaddr + PCI20000_DIO_BUFFER);
532 if(s->io_bits & 0x000000ff ){
534 control_01 &= PCI20000_DIO_EOC;
535 buffer = (buffer &(~(DIO_BE<<DIO_PS_0)))|(DIO_BO<<DIO_PS_0);
538 control_01 = (control_01 & DIO_CAND) | PCI20000_DIO_EIC;
539 buffer = (buffer &(~(DIO_BI<<DIO_PS_0)));
541 if(s->io_bits & 0x0000ff00 ){
543 control_01 &= PCI20000_DIO_OOC;
544 buffer = (buffer &(~(DIO_BE<<DIO_PS_1)))|(DIO_BO<<DIO_PS_1);
547 control_01 = (control_01 & DIO_CAND) | PCI20000_DIO_OIC;
548 buffer = (buffer &(~(DIO_BI<<DIO_PS_1)));
550 if(s->io_bits & 0x00ff0000 ){
552 control_23 &= PCI20000_DIO_EOC;
553 buffer = (buffer &(~(DIO_BE<<DIO_PS_2)))|(DIO_BO<<DIO_PS_2);
556 control_23 = (control_23 & DIO_CAND) | PCI20000_DIO_EIC;
557 buffer = (buffer &(~(DIO_BI<<DIO_PS_2)));
559 if(s->io_bits & 0xff000000 ){
561 control_23 &= PCI20000_DIO_OOC;
562 buffer = (buffer &(~(DIO_BE<<DIO_PS_3)))|(DIO_BO<<DIO_PS_3);
565 control_23 = (control_23 & DIO_CAND) | PCI20000_DIO_OIC;
566 buffer = (buffer &(~(DIO_BI<<DIO_PS_3)));
568 writeb(control_01, devpriv->ioaddr + PCI20000_DIO_CONTROL_01);
569 writeb(control_23, devpriv->ioaddr + PCI20000_DIO_CONTROL_23);
570 writeb(buffer, devpriv->ioaddr + PCI20000_DIO_BUFFER);
574 static void pci20xxx_do(comedi_device * dev, comedi_subdevice * s)
576 /* XXX if the channel is configured for input, does this
578 /* XXX it would be a good idea to only update the registers
579 that _need_ to be updated. This requires changes to
581 writeb((s->state>>0)&0xff, devpriv->ioaddr + PCI20000_DIO_0 );
582 writeb((s->state>>8)&0xff, devpriv->ioaddr + PCI20000_DIO_1 );
583 writeb((s->state>>16)&0xff, devpriv->ioaddr + PCI20000_DIO_2 );
584 writeb((s->state>>24)&0xff, devpriv->ioaddr + PCI20000_DIO_3 );
587 static unsigned int pci20xxx_di(comedi_device * dev, comedi_subdevice * s)
589 /* XXX same note as above */
592 bits = readb(devpriv->ioaddr + PCI20000_DIO_0 );
593 bits |= readb(devpriv->ioaddr + PCI20000_DIO_1 )<<8;
594 bits |= readb(devpriv->ioaddr + PCI20000_DIO_2 )<<16;
595 bits |= readb(devpriv->ioaddr + PCI20000_DIO_3 )<<24;
601 COMEDI_INITCLEANUP(driver_pci20xxx);