Added some ack'ing of b interrupts, and do acks before handling
[comedi.git] / comedi / drivers / ii_pci20kc.c
1 /*
2  *      ii_pci20kc.c
3  *      driver for Intelligent Instruments PCI-20001C carrier board
4  *      and modules
5  *
6  *      Copyright (C) 2000 Markus Kempf <kempf@matsci.uni-sb.de>
7  *      with suggestions from David Schleef   
8  *                      16.06.2000      
9  *
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
14  *                              - differential
15  *                              - range (-5V - +5V)
16  *                              - 16 bit
17  *      PCI-20006 M-2 16-Bit analog output module
18  *                              - ranges (-10V - +10V) (0V - +10V) (-5V - +5V)
19  *                              - 16 bit
20  *      
21  *      only ONE PCI-20341 module possible
22  *      only ONE PCI-20006 module possible
23  *      no extern trigger implemented
24  *
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
27  *      di-port == Port 0
28  *      do-port == Port 1
29  *
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.
33  *
34  *      The test configuration:
35  *
36  *      kernel 2.2.14 with RTAI v1.2  and patch-2.2.14rthal2
37  *      COMEDI 0.7.45
38  *      COMEDILIB 0.7.9
39  *
40  */
41 /*
42 Driver: ii_pci20kc.o
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)
46 Status: works
47
48 Supports the PCI-20001 C-2a Carrier board, and could probably support
49 the other carrier boards with small modifications.  Modules supported
50 are:
51         PCI-20006 M-2 16-bit analog output module
52         PCI-20341 M-1A 16-bit analog input module
53
54 Options:
55   0   Board base address
56   1   IRQ
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
63
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
70
71 options for PCI-20341M:
72   first:   Analog input gain configuration
73              0  1
74              1  10
75              2  100
76              3  200
77 */
78
79 /* XXX needs to use ioremap() for compatibility with 2.4 kernels.  Should also
80  * check_mem_region() etc. - fmhess */
81
82 #include <linux/comedidev.h>
83
84
85 #define PCI20000_ID                     0x1d
86 #define PCI20341_ID                     0x77
87 #define PCI20006_ID                     0xe3
88 #define PCI20xxx_EMPTY_ID               0xff
89
90 #define PCI20000_OFFSET                 0x100
91 #define PCI20000_MODULES                3
92
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 */
112
113 #define PCI20006_LCHAN0                 0x0d
114 #define PCI20006_STROBE0                0x0b
115 #define PCI20006_LCHAN1                 0x15
116 #define PCI20006_STROBE1                0x13
117
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 */
136
137
138
139 typedef union {
140         void *iobase;
141         struct {
142                 void *iobase;
143                 comedi_lrange *ao_range_list[2];        /* range of channels of ao module */
144                 lsampl_t last_data[2];
145         }pci20006;
146         struct {
147                 void *iobase;
148                 int timebase;
149                 int settling_time;
150                 int ai_gain;
151         }pci20341;
152 } pci20xxx_subdev_private;
153
154 typedef struct {
155         void *ioaddr;
156         pci20xxx_subdev_private subdev_private[PCI20000_MODULES];
157 } pci20xxx_private;
158
159 #define devpriv ((pci20xxx_private *)dev->private)
160 #define CHAN (CR_CHAN(it->chanlist[0]))
161
162 static int pci20xxx_attach(comedi_device * dev, comedi_devconfig * it);
163 static int pci20xxx_detach(comedi_device * dev);
164
165 static comedi_driver driver_pci20xxx = {
166         driver_name:    "ii_pci20kc",
167         module:         THIS_MODULE,
168         attach:         pci20xxx_attach,
169         detach:         pci20xxx_detach,
170 };
171
172 static int pci20006_init(comedi_device * dev,comedi_subdevice *s,
173         int opt0,int opt1);
174 static int pci20341_init(comedi_device * dev,comedi_subdevice *s,
175         int opt0,int opt1);
176 static int pci20xxx_dio_init(comedi_device * dev,comedi_subdevice *s);
177
178 /*
179   options[0]    Board base address
180   options[1]    IRQ
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
187
188   options for PCI-20341M:
189   first         Analog input gain configuration
190                 0 == 1
191                 1 == 10
192                 2 == 100
193                 3 == 200
194
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)
204 */
205 static int pci20xxx_attach(comedi_device * dev, comedi_devconfig * it)
206 {
207         unsigned char i;
208         int ret;
209         int id;
210         comedi_subdevice *s;
211         pci20xxx_subdev_private *sdp;
212
213         if ((ret = alloc_subdevices(dev, 1 + PCI20000_MODULES)) < 0)
214                 return ret;
215         if ((ret = alloc_private(dev, sizeof(pci20xxx_private))) < 0)
216                 return ret;
217
218         devpriv->ioaddr = (void*) it->options[0];
219         dev->board_name = "pci20kc";
220
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);
225                 return -EINVAL;
226         }
227         printk("comedi%d:\n", dev->minor);
228         printk("ii_pci20kc: PCI-20001 C-2A at base=0x%p\n", devpriv->ioaddr);
229
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;
234                 sdp = s->private;
235                 switch(id){
236                 case PCI20006_ID:
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);
241                         break;
242                 case PCI20341_ID:
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);
247                         break;
248                 default:
249                         printk("ii_pci20kc: unknown module code 0x%02x in slot %d: module disabled\n",
250                                 id,i);
251                         /* fall through */
252                 case PCI20xxx_EMPTY_ID:
253                         s->type = COMEDI_SUBD_UNUSED;
254                         break;
255                 }
256         }
257
258         /* initialize pci20xxx_private */
259         pci20xxx_dio_init(dev,dev->subdevices + PCI20000_MODULES);
260
261         return 1;
262 }
263
264 static int pci20xxx_detach(comedi_device * dev)
265 {
266         printk("comedi%d: pci20xxx: remove\n", dev->minor);
267
268         return 0;
269 }
270
271 /* pci20006m */
272
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);
277
278 static comedi_lrange *pci20006_range_list[] = {
279         &range_bipolar10,
280         &range_unipolar10,
281         &range_bipolar5,
282 };
283
284 static int pci20006_init(comedi_device * dev,comedi_subdevice *s,
285         int opt0,int opt1)
286 {
287         pci20xxx_subdev_private *sdp = s->private;
288
289         if(opt0<0 || opt0>2) opt0=0;
290         if(opt1<0 || opt1>2) opt1=0;
291
292         sdp->pci20006.ao_range_list[0] = pci20006_range_list[opt0];
293         sdp->pci20006.ao_range_list[1] = pci20006_range_list[opt1];
294
295         /* ao subdevice */
296         s->type = COMEDI_SUBD_AO;
297         s->subdev_flags = SDF_WRITABLE;
298         s->n_chan = 2;
299         s->len_chanlist = 2;
300         s->insn_read = pci20006_insn_read;
301         s->insn_write = pci20006_insn_write;
302         s->maxdata = 0xffff;
303         s->range_table_list = sdp->pci20006.ao_range_list;
304         return 0;
305 }
306
307 static int pci20006_insn_read(comedi_device * dev, comedi_subdevice * s,
308         comedi_insn *insn, lsampl_t *data)
309 {
310         pci20xxx_subdev_private *sdp = s->private;
311
312         data[0] = sdp->pci20006.last_data[CR_CHAN(insn->chanspec)];
313
314         return 1;
315 }
316
317 static int pci20006_insn_write(comedi_device * dev, comedi_subdevice * s,
318         comedi_insn *insn, lsampl_t *data)
319 {
320         pci20xxx_subdev_private *sdp = s->private;
321         int hi, lo;
322         unsigned int boarddata;
323
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);
328
329         switch ( CR_CHAN(insn->chanspec)) {
330         case 0:
331                 writeb(lo, sdp->iobase + PCI20006_LCHAN0);
332                 writeb(hi, sdp->iobase + PCI20006_LCHAN0 + 1);
333                 writeb(0x00, sdp->iobase + PCI20006_STROBE0);
334                 break;
335         case 1:
336                 writeb(lo, sdp->iobase + PCI20006_LCHAN1);
337                 writeb(hi, sdp->iobase + PCI20006_LCHAN1 + 1);
338                 writeb(0x00, sdp->iobase + PCI20006_STROBE1);
339                 break;
340         default:
341                 printk(" comedi%d: pci20xxx: ao channel Error!\n", dev->minor);
342                 return -EINVAL;
343         }
344
345         return 1;
346 }
347
348 /* PCI20341M */
349
350 static int pci20341_insn_read(comedi_device * dev, comedi_subdevice * s,
351         comedi_insn *insn, lsampl_t *data);
352
353 static int pci20341_timebase[] = { 0x00, 0x00, 0x00, 0x04 };
354 static int pci20341_settling_time[] = { 0x58, 0x58, 0x93, 0x99 };
355
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) }};
359
360 static comedi_lrange *pci20341_ranges[] = {
361         &range_bipolar5,
362         &range_bipolar0_5,
363         &range_bipolar0_05,
364         &range_bipolar0_025,
365         };
366
367 static int pci20341_init(comedi_device * dev,comedi_subdevice *s,
368         int opt0,int opt1)
369 {
370         pci20xxx_subdev_private *sdp = s->private;
371         int option;     
372
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];
377
378         /* ai subdevice */
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;
384         s->maxdata = 0xffff;
385         s->range_table = pci20341_ranges[opt0];
386
387         option = sdp->pci20341.timebase | PCI20341_REPMODE;     /* depends on gain, trigger, repetition mode */
388
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 */
394         return 0;
395 }
396
397 static int pci20341_insn_read(comedi_device * dev, comedi_subdevice * s,
398         comedi_insn *insn, lsampl_t *data)
399 {
400         pci20xxx_subdev_private *sdp = s->private;
401         unsigned int i = 0, j = 0;
402         int lo, hi;
403         unsigned char eoc;              /* end of conversion */
404         unsigned int clb;               /* channel list byte */
405         unsigned int boarddata;
406
407         writeb(1, sdp->iobase + PCI20341_LCHAN_ADDR_REG);               /* write number of input channels */
408         clb     = PCI20341_DAISY_CHAIN
409                 | PCI20341_MUX
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);
415
416         /* generate Pacer */
417
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 
422                  */
423                 j=0;
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 */
427                         j++;
428                         eoc = readb(sdp->iobase + PCI20341_STATUS_REG);
429                 }
430                 if (j >= 100) {
431                         printk("comedi%d:  pci20xxx: AI interrupt channel %i polling exit !\n", dev->minor, i);
432                         return -EINVAL;
433                 }
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 */
438         }
439
440         return i;
441 }
442
443 /* native DIO */
444
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);
450
451 /* initialize pci20xxx_private */
452 static int pci20xxx_dio_init(comedi_device * dev,comedi_subdevice *s)
453 {
454
455         s->type = COMEDI_SUBD_DIO;
456         s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
457         s->n_chan = 32;
458         s->insn_bits = pci20xxx_dio_insn_bits;
459         s->insn_config = pci20xxx_dio_insn_config;
460         s->maxdata = 1;
461         s->len_chanlist = 32;
462         s->range_table = &range_digital;
463         s->io_bits = 0;
464
465         /* digital I/O lines default to input on board reset. */
466         pci20xxx_dio_config(dev,s);
467
468         return 0;
469 }
470
471 static int pci20xxx_dio_insn_config(comedi_device *dev,comedi_subdevice *s,
472         comedi_insn *insn, lsampl_t *data)
473 {
474         int mask,bits;
475
476         mask = 1<<CR_CHAN(insn->chanspec);
477         if(mask&0x000000ff){
478                 bits = 0x000000ff;
479         }else if(mask & 0x0000ff00){
480                 bits = 0x0000ff00;
481         }else if(mask & 0x00ff0000){
482                 bits = 0x00ff0000;
483         }else {
484                 bits = 0xff000000;
485         }
486         if(data[0]){
487                 s->io_bits |= bits;
488         }else{
489                 s->io_bits &= ~bits;
490         }
491         pci20xxx_dio_config(dev,s);
492
493         return 1;
494 }
495
496 static int pci20xxx_dio_insn_bits(comedi_device *dev,comedi_subdevice *s,
497         comedi_insn *insn, lsampl_t *data)
498 {
499         unsigned int mask = data[0];
500
501         s->state &= ~mask;
502         s->state |= (mask&data[1]);
503
504         mask &= s->io_bits;
505         if(mask&0x000000ff)
506                 writeb((s->state>>0)&0xff, devpriv->ioaddr + PCI20000_DIO_0 );
507         if(mask&0x0000ff00)
508                 writeb((s->state>>8)&0xff, devpriv->ioaddr + PCI20000_DIO_1 );
509         if(mask&0x00ff0000)
510                 writeb((s->state>>16)&0xff, devpriv->ioaddr + PCI20000_DIO_2 );
511         if(mask&0xff000000)
512                 writeb((s->state>>24)&0xff, devpriv->ioaddr + PCI20000_DIO_3 );
513
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;
518
519         return 2;
520 }
521
522 static void pci20xxx_dio_config(comedi_device * dev,comedi_subdevice *s)
523 {
524         unsigned char control_01;
525         unsigned char control_23;
526         unsigned char buffer;
527
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);          
531
532         if(s->io_bits & 0x000000ff ){
533                 /* output port 0 */
534                 control_01 &= PCI20000_DIO_EOC;
535                 buffer = (buffer &(~(DIO_BE<<DIO_PS_0)))|(DIO_BO<<DIO_PS_0);
536         }else{
537                 /* input port 0 */
538                 control_01 = (control_01 & DIO_CAND) | PCI20000_DIO_EIC;
539                 buffer = (buffer &(~(DIO_BI<<DIO_PS_0)));
540         }
541         if(s->io_bits & 0x0000ff00 ){
542                 /* output port 1 */
543                 control_01 &= PCI20000_DIO_OOC;
544                 buffer = (buffer &(~(DIO_BE<<DIO_PS_1)))|(DIO_BO<<DIO_PS_1);
545         }else{
546                 /* input port 1 */
547                 control_01 = (control_01 & DIO_CAND) | PCI20000_DIO_OIC;                
548                 buffer = (buffer &(~(DIO_BI<<DIO_PS_1)));
549         }
550         if(s->io_bits & 0x00ff0000 ){
551                 /* output port 2 */
552                 control_23 &= PCI20000_DIO_EOC;
553                 buffer = (buffer &(~(DIO_BE<<DIO_PS_2)))|(DIO_BO<<DIO_PS_2);
554         }else{
555                 /* input port 2 */
556                 control_23 = (control_23 & DIO_CAND) | PCI20000_DIO_EIC;
557                 buffer = (buffer &(~(DIO_BI<<DIO_PS_2)));
558         }
559         if(s->io_bits & 0xff000000 ){
560                 /* output port 3 */
561                 control_23 &= PCI20000_DIO_OOC;
562                 buffer = (buffer &(~(DIO_BE<<DIO_PS_3)))|(DIO_BO<<DIO_PS_3);
563         }else{
564                 /* input port 3 */
565                 control_23 = (control_23 & DIO_CAND) | PCI20000_DIO_OIC;
566                 buffer = (buffer &(~(DIO_BI<<DIO_PS_3)));
567         }
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);  
571 }
572
573 #if 0
574 static void pci20xxx_do(comedi_device * dev, comedi_subdevice * s)
575 {
576         /* XXX if the channel is configured for input, does this
577            do bad things? */
578         /* XXX it would be a good idea to only update the registers
579            that _need_ to be updated.  This requires changes to
580            comedi, however. */
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 );
585 }
586
587 static unsigned int pci20xxx_di(comedi_device * dev, comedi_subdevice * s)
588 {
589         /* XXX same note as above */
590         unsigned int bits;
591         
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;
596
597         return bits;
598 }
599 #endif
600
601 COMEDI_INITCLEANUP(driver_pci20xxx);
602