Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
[pandora-kernel.git] / drivers / staging / comedi / drivers / ii_pci20kc.c
1 /*
2  *      comedi/drivers/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
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 "../comedidev.h"
83
84 #define PCI20000_ID                     0x1d
85 #define PCI20341_ID                     0x77
86 #define PCI20006_ID                     0xe3
87 #define PCI20xxx_EMPTY_ID               0xff
88
89 #define PCI20000_OFFSET                 0x100
90 #define PCI20000_MODULES                3
91
92 #define PCI20000_DIO_0                  0x80
93 #define PCI20000_DIO_1                  0x81
94 #define PCI20000_DIO_2                  0xc0
95 #define PCI20000_DIO_3                  0xc1
96 #define PCI20000_DIO_CONTROL_01         0x83    /* port 0, 1 control */
97 #define PCI20000_DIO_CONTROL_23         0xc3    /* port 2, 3 control */
98 #define PCI20000_DIO_BUFFER             0x82    /* buffer direction and enable */
99 #define PCI20000_DIO_EOC                0xef    /* even port, control output */
100 #define PCI20000_DIO_OOC                0xfd    /* odd port, control output */
101 #define PCI20000_DIO_EIC                0x90    /* even port, control input */
102 #define PCI20000_DIO_OIC                0x82    /* odd port, control input */
103 #define DIO_CAND                        0x12    /* and bit 1, bit 4 of control */
104 #define DIO_BE                          0x01    /* buffer: port enable */
105 #define DIO_BO                          0x04    /* buffer: output */
106 #define DIO_BI                          0x05    /* buffer: input */
107 #define DIO_PS_0                        0x00    /* buffer: port shift 0 */
108 #define DIO_PS_1                        0x01    /* buffer: port shift 1 */
109 #define DIO_PS_2                        0x04    /* buffer: port shift 2 */
110 #define DIO_PS_3                        0x05    /* buffer: port shift 3 */
111
112 #define PCI20006_LCHAN0                 0x0d
113 #define PCI20006_STROBE0                0x0b
114 #define PCI20006_LCHAN1                 0x15
115 #define PCI20006_STROBE1                0x13
116
117 #define PCI20341_INIT                   0x04
118 #define PCI20341_REPMODE                0x00    /* single shot mode */
119 #define PCI20341_PACER                  0x00    /* Hardware Pacer disabled */
120 #define PCI20341_CHAN_NR                0x04    /* number of input channels */
121 #define PCI20341_CONFIG_REG             0x10
122 #define PCI20341_MOD_STATUS             0x01
123 #define PCI20341_OPT_REG                0x11
124 #define PCI20341_SET_TIME_REG           0x15
125 #define PCI20341_LCHAN_ADDR_REG         0x13
126 #define PCI20341_CHAN_LIST              0x80
127 #define PCI20341_CC_RESET               0x1b
128 #define PCI20341_CHAN_RESET             0x19
129 #define PCI20341_SOFT_PACER             0x04
130 #define PCI20341_STATUS_REG             0x12
131 #define PCI20341_LDATA                  0x02
132 #define PCI20341_DAISY_CHAIN            0x20    /* On-board inputs only */
133 #define PCI20341_MUX                    0x04    /* Enable on-board MUX */
134 #define PCI20341_SCANLIST               0x80    /* Channel/Gain Scan List */
135
136 union pci20xxx_subdev_private {
137         void *iobase;
138         struct {
139                 void *iobase;
140                 const struct comedi_lrange *ao_range_list[2];   /* range of channels of ao module */
141                 unsigned int last_data[2];
142         } pci20006;
143         struct {
144                 void *iobase;
145                 int timebase;
146                 int settling_time;
147                 int ai_gain;
148         } pci20341;
149 };
150
151 struct pci20xxx_private {
152
153         void *ioaddr;
154         union pci20xxx_subdev_private subdev_private[PCI20000_MODULES];
155 };
156
157
158 #define devpriv ((struct pci20xxx_private *)dev->private)
159 #define CHAN (CR_CHAN(it->chanlist[0]))
160
161 static int pci20xxx_attach(struct comedi_device *dev, struct comedi_devconfig *it);
162 static int pci20xxx_detach(struct comedi_device *dev);
163
164 static struct comedi_driver driver_pci20xxx = {
165         .driver_name = "ii_pci20kc",
166         .module = THIS_MODULE,
167         .attach = pci20xxx_attach,
168         .detach = pci20xxx_detach,
169 };
170
171 static int pci20006_init(struct comedi_device *dev, struct comedi_subdevice *s,
172         int opt0, int opt1);
173 static int pci20341_init(struct comedi_device *dev, struct comedi_subdevice *s,
174         int opt0, int opt1);
175 static int pci20xxx_dio_init(struct comedi_device *dev, struct comedi_subdevice *s);
176
177 /*
178   options[0]    Board base address
179   options[1]    IRQ
180   options[2]    first option for module 1
181   options[3]    second option for module 1
182   options[4]    first option for module 2
183   options[5]    second option for module 2
184   options[6]    first option for module 3
185   options[7]    second option for module 3
186
187   options for PCI-20341M:
188   first         Analog input gain configuration
189                 0 == 1
190                 1 == 10
191                 2 == 100
192                 3 == 200
193
194   options for PCI-20006M:
195   first         Analog output channel 0 range configuration
196                 0 == bipolar 10  (-10V -- +10V)
197                 1 == unipolar 10V  (0V -- +10V)
198                 2 == bipolar 5V  (-5V -- +5V)
199   second        Analog output channel 1 range configuration
200                 0 == bipolar 10  (-10V -- +10V)
201                 1 == unipolar 10V  (0V -- +10V)
202                 2 == bipolar 5V  (-5V -- +5V)
203 */
204 static int pci20xxx_attach(struct comedi_device *dev, struct comedi_devconfig *it)
205 {
206         unsigned char i;
207         int ret;
208         int id;
209         struct comedi_subdevice *s;
210         union pci20xxx_subdev_private *sdp;
211
212         ret = alloc_subdevices(dev, 1 + PCI20000_MODULES);
213         if (ret < 0)
214                 return ret;
215
216         ret = alloc_private(dev, sizeof(struct pci20xxx_private));
217         if (ret < 0)
218                 return ret;
219
220         devpriv->ioaddr = (void *)(unsigned long)it->options[0];
221         dev->board_name = "pci20kc";
222
223         /* Check PCI-20001 C-2A Carrier Board ID */
224         if ((readb(devpriv->ioaddr) & PCI20000_ID) != PCI20000_ID) {
225                 printk("comedi%d: ii_pci20kc", dev->minor);
226                 printk(" PCI-20001 C-2A Carrier Board at base=0x%p not found !\n", devpriv->ioaddr);
227                 return -EINVAL;
228         }
229         printk("comedi%d:\n", dev->minor);
230         printk("ii_pci20kc: PCI-20001 C-2A at base=0x%p\n", devpriv->ioaddr);
231
232         for (i = 0; i < PCI20000_MODULES; i++) {
233                 s = dev->subdevices + i;
234                 id = readb(devpriv->ioaddr + (i + 1) * PCI20000_OFFSET);
235                 s->private = devpriv->subdev_private + i;
236                 sdp = s->private;
237                 switch (id) {
238                 case PCI20006_ID:
239                         sdp->pci20006.iobase =
240                                 devpriv->ioaddr + (i + 1) * PCI20000_OFFSET;
241                         pci20006_init(dev, s, it->options[2 * i + 2],
242                                 it->options[2 * i + 3]);
243                         printk("comedi%d: ii_pci20kc", dev->minor);
244                         printk(" PCI-20006 module in slot %d \n", i + 1);
245                         break;
246                 case PCI20341_ID:
247                         sdp->pci20341.iobase =
248                                 devpriv->ioaddr + (i + 1) * PCI20000_OFFSET;
249                         pci20341_init(dev, s, it->options[2 * i + 2],
250                                 it->options[2 * i + 3]);
251                         printk("comedi%d: ii_pci20kc", dev->minor);
252                         printk(" PCI-20341 module in slot %d \n", i + 1);
253                         break;
254                 default:
255                         printk("ii_pci20kc: unknown module code 0x%02x in slot %d: module disabled\n", id, i);
256                         /* fall through */
257                 case PCI20xxx_EMPTY_ID:
258                         s->type = COMEDI_SUBD_UNUSED;
259                         break;
260                 }
261         }
262
263         /* initialize struct pci20xxx_private */
264         pci20xxx_dio_init(dev, dev->subdevices + PCI20000_MODULES);
265
266         return 1;
267 }
268
269 static int pci20xxx_detach(struct comedi_device *dev)
270 {
271         printk("comedi%d: pci20xxx: remove\n", dev->minor);
272
273         return 0;
274 }
275
276 /* pci20006m */
277
278 static int pci20006_insn_read(struct comedi_device *dev, struct comedi_subdevice *s,
279         struct comedi_insn *insn, unsigned int *data);
280 static int pci20006_insn_write(struct comedi_device *dev, struct comedi_subdevice *s,
281         struct comedi_insn *insn, unsigned int *data);
282
283 static const struct comedi_lrange *pci20006_range_list[] = {
284         &range_bipolar10,
285         &range_unipolar10,
286         &range_bipolar5,
287 };
288
289 static int pci20006_init(struct comedi_device *dev, struct comedi_subdevice *s,
290         int opt0, int opt1)
291 {
292         union pci20xxx_subdev_private *sdp = s->private;
293
294         if (opt0 < 0 || opt0 > 2)
295                 opt0 = 0;
296         if (opt1 < 0 || opt1 > 2)
297                 opt1 = 0;
298
299         sdp->pci20006.ao_range_list[0] = pci20006_range_list[opt0];
300         sdp->pci20006.ao_range_list[1] = pci20006_range_list[opt1];
301
302         /* ao subdevice */
303         s->type = COMEDI_SUBD_AO;
304         s->subdev_flags = SDF_WRITABLE;
305         s->n_chan = 2;
306         s->len_chanlist = 2;
307         s->insn_read = pci20006_insn_read;
308         s->insn_write = pci20006_insn_write;
309         s->maxdata = 0xffff;
310         s->range_table_list = sdp->pci20006.ao_range_list;
311         return 0;
312 }
313
314 static int pci20006_insn_read(struct comedi_device *dev, struct comedi_subdevice *s,
315         struct comedi_insn *insn, unsigned int *data)
316 {
317         union pci20xxx_subdev_private *sdp = s->private;
318
319         data[0] = sdp->pci20006.last_data[CR_CHAN(insn->chanspec)];
320
321         return 1;
322 }
323
324 static int pci20006_insn_write(struct comedi_device *dev, struct comedi_subdevice *s,
325         struct comedi_insn *insn, unsigned int *data)
326 {
327         union pci20xxx_subdev_private *sdp = s->private;
328         int hi, lo;
329         unsigned int boarddata;
330
331         sdp->pci20006.last_data[CR_CHAN(insn->chanspec)] = data[0];
332         boarddata = (((unsigned int)data[0] + 0x8000) & 0xffff);        /* comedi-data -> board-data */
333         lo = (boarddata & 0xff);
334         hi = ((boarddata >> 8) & 0xff);
335
336         switch (CR_CHAN(insn->chanspec)) {
337         case 0:
338                 writeb(lo, sdp->iobase + PCI20006_LCHAN0);
339                 writeb(hi, sdp->iobase + PCI20006_LCHAN0 + 1);
340                 writeb(0x00, sdp->iobase + PCI20006_STROBE0);
341                 break;
342         case 1:
343                 writeb(lo, sdp->iobase + PCI20006_LCHAN1);
344                 writeb(hi, sdp->iobase + PCI20006_LCHAN1 + 1);
345                 writeb(0x00, sdp->iobase + PCI20006_STROBE1);
346                 break;
347         default:
348                 printk(" comedi%d: pci20xxx: ao channel Error!\n", dev->minor);
349                 return -EINVAL;
350         }
351
352         return 1;
353 }
354
355 /* PCI20341M */
356
357 static int pci20341_insn_read(struct comedi_device *dev, struct comedi_subdevice *s,
358         struct comedi_insn *insn, unsigned int *data);
359
360 static const int pci20341_timebase[] = { 0x00, 0x00, 0x00, 0x04 };
361 static const int pci20341_settling_time[] = { 0x58, 0x58, 0x93, 0x99 };
362
363 static const struct comedi_lrange range_bipolar0_5 = { 1, {BIP_RANGE(0.5)} };
364 static const struct comedi_lrange range_bipolar0_05 = { 1, {BIP_RANGE(0.05)} };
365 static const struct comedi_lrange range_bipolar0_025 = { 1, {BIP_RANGE(0.025)} };
366
367 static const struct comedi_lrange *const pci20341_ranges[] = {
368         &range_bipolar5,
369         &range_bipolar0_5,
370         &range_bipolar0_05,
371         &range_bipolar0_025,
372 };
373
374 static int pci20341_init(struct comedi_device *dev, struct comedi_subdevice *s,
375         int opt0, int opt1)
376 {
377         union pci20xxx_subdev_private *sdp = s->private;
378         int option;
379
380         /* options handling */
381         if (opt0 < 0 || opt0 > 3)
382                 opt0 = 0;
383         sdp->pci20341.timebase = pci20341_timebase[opt0];
384         sdp->pci20341.settling_time = pci20341_settling_time[opt0];
385
386         /* ai subdevice */
387         s->type = COMEDI_SUBD_AI;
388         s->subdev_flags = SDF_READABLE;
389         s->n_chan = PCI20341_CHAN_NR;
390         s->len_chanlist = PCI20341_SCANLIST;
391         s->insn_read = pci20341_insn_read;
392         s->maxdata = 0xffff;
393         s->range_table = pci20341_ranges[opt0];
394
395         option = sdp->pci20341.timebase | PCI20341_REPMODE;     /* depends on gain, trigger, repetition mode */
396
397         writeb(PCI20341_INIT, sdp->iobase + PCI20341_CONFIG_REG);       /* initialize Module */
398         writeb(PCI20341_PACER, sdp->iobase + PCI20341_MOD_STATUS);      /* set Pacer */
399         writeb(option, sdp->iobase + PCI20341_OPT_REG); /* option register */
400         writeb(sdp->pci20341.settling_time, sdp->iobase + PCI20341_SET_TIME_REG);       /* settling time counter */
401         /* trigger not implemented */
402         return 0;
403 }
404
405 static int pci20341_insn_read(struct comedi_device *dev, struct comedi_subdevice *s,
406         struct comedi_insn *insn, unsigned int *data)
407 {
408         union pci20xxx_subdev_private *sdp = s->private;
409         unsigned int i = 0, j = 0;
410         int lo, hi;
411         unsigned char eoc;      /* end of conversion */
412         unsigned int clb;       /* channel list byte */
413         unsigned int boarddata;
414
415         writeb(1, sdp->iobase + PCI20341_LCHAN_ADDR_REG);       /* write number of input channels */
416         clb = PCI20341_DAISY_CHAIN | PCI20341_MUX | (sdp->pci20341.ai_gain << 3)
417                 | CR_CHAN(insn->chanspec);
418         writeb(clb, sdp->iobase + PCI20341_CHAN_LIST);
419         writeb(0x00, sdp->iobase + PCI20341_CC_RESET);  /* reset settling time counter and trigger delay counter */
420         writeb(0x00, sdp->iobase + PCI20341_CHAN_RESET);
421
422         /* generate Pacer */
423
424         for (i = 0; i < insn->n; i++) {
425                 /* data polling isn't the niciest way to get the data, I know,
426                  * but there are only 6 cycles (mean) and it is easier than
427                  * the whole interrupt stuff
428                  */
429                 j = 0;
430                 readb(sdp->iobase + PCI20341_SOFT_PACER);       /* generate Pacer */
431                 eoc = readb(sdp->iobase + PCI20341_STATUS_REG);
432                 while ((eoc < 0x80) && j < 100) {       /* poll Interrupt Flag */
433                         j++;
434                         eoc = readb(sdp->iobase + PCI20341_STATUS_REG);
435                 }
436                 if (j >= 100) {
437                         printk("comedi%d:  pci20xxx: AI interrupt channel %i polling exit !\n", dev->minor, i);
438                         return -EINVAL;
439                 }
440                 lo = readb(sdp->iobase + PCI20341_LDATA);
441                 hi = readb(sdp->iobase + PCI20341_LDATA + 1);
442                 boarddata = lo + 0x100 * hi;
443                 data[i] = (short) ((boarddata + 0x8000) & 0xffff);      /* board-data -> comedi-data */
444         }
445
446         return i;
447 }
448
449 /* native DIO */
450
451 static void pci20xxx_dio_config(struct comedi_device *dev, struct comedi_subdevice *s);
452 static int pci20xxx_dio_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s,
453         struct comedi_insn *insn, unsigned int *data);
454 static int pci20xxx_dio_insn_config(struct comedi_device *dev, struct comedi_subdevice *s,
455         struct comedi_insn *insn, unsigned int *data);
456
457 /* initialize struct pci20xxx_private */
458 static int pci20xxx_dio_init(struct comedi_device *dev, struct comedi_subdevice *s)
459 {
460
461         s->type = COMEDI_SUBD_DIO;
462         s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
463         s->n_chan = 32;
464         s->insn_bits = pci20xxx_dio_insn_bits;
465         s->insn_config = pci20xxx_dio_insn_config;
466         s->maxdata = 1;
467         s->len_chanlist = 32;
468         s->range_table = &range_digital;
469         s->io_bits = 0;
470
471         /* digital I/O lines default to input on board reset. */
472         pci20xxx_dio_config(dev, s);
473
474         return 0;
475 }
476
477 static int pci20xxx_dio_insn_config(struct comedi_device *dev, struct comedi_subdevice *s,
478         struct comedi_insn *insn, unsigned int *data)
479 {
480         int mask, bits;
481
482         mask = 1 << CR_CHAN(insn->chanspec);
483         if (mask & 0x000000ff) {
484                 bits = 0x000000ff;
485         } else if (mask & 0x0000ff00) {
486                 bits = 0x0000ff00;
487         } else if (mask & 0x00ff0000) {
488                 bits = 0x00ff0000;
489         } else {
490                 bits = 0xff000000;
491         }
492         if (data[0]) {
493                 s->io_bits |= bits;
494         } else {
495                 s->io_bits &= ~bits;
496         }
497         pci20xxx_dio_config(dev, s);
498
499         return 1;
500 }
501
502 static int pci20xxx_dio_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s,
503         struct comedi_insn *insn, unsigned int *data)
504 {
505         unsigned int mask = data[0];
506
507         s->state &= ~mask;
508         s->state |= (mask & data[1]);
509
510         mask &= s->io_bits;
511         if (mask & 0x000000ff)
512                 writeb((s->state >> 0) & 0xff,
513                         devpriv->ioaddr + PCI20000_DIO_0);
514         if (mask & 0x0000ff00)
515                 writeb((s->state >> 8) & 0xff,
516                         devpriv->ioaddr + PCI20000_DIO_1);
517         if (mask & 0x00ff0000)
518                 writeb((s->state >> 16) & 0xff,
519                         devpriv->ioaddr + PCI20000_DIO_2);
520         if (mask & 0xff000000)
521                 writeb((s->state >> 24) & 0xff,
522                         devpriv->ioaddr + PCI20000_DIO_3);
523
524         data[1] = readb(devpriv->ioaddr + PCI20000_DIO_0);
525         data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_1) << 8;
526         data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_2) << 16;
527         data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_3) << 24;
528
529         return 2;
530 }
531
532 static void pci20xxx_dio_config(struct comedi_device *dev, struct comedi_subdevice *s)
533 {
534         unsigned char control_01;
535         unsigned char control_23;
536         unsigned char buffer;
537
538         control_01 = readb(devpriv->ioaddr + PCI20000_DIO_CONTROL_01);
539         control_23 = readb(devpriv->ioaddr + PCI20000_DIO_CONTROL_23);
540         buffer = readb(devpriv->ioaddr + PCI20000_DIO_BUFFER);
541
542         if (s->io_bits & 0x000000ff) {
543                 /* output port 0 */
544                 control_01 &= PCI20000_DIO_EOC;
545                 buffer = (buffer & (~(DIO_BE << DIO_PS_0))) | (DIO_BO <<
546                         DIO_PS_0);
547         } else {
548                 /* input port 0 */
549                 control_01 = (control_01 & DIO_CAND) | PCI20000_DIO_EIC;
550                 buffer = (buffer & (~(DIO_BI << DIO_PS_0)));
551         }
552         if (s->io_bits & 0x0000ff00) {
553                 /* output port 1 */
554                 control_01 &= PCI20000_DIO_OOC;
555                 buffer = (buffer & (~(DIO_BE << DIO_PS_1))) | (DIO_BO <<
556                         DIO_PS_1);
557         } else {
558                 /* input port 1 */
559                 control_01 = (control_01 & DIO_CAND) | PCI20000_DIO_OIC;
560                 buffer = (buffer & (~(DIO_BI << DIO_PS_1)));
561         }
562         if (s->io_bits & 0x00ff0000) {
563                 /* output port 2 */
564                 control_23 &= PCI20000_DIO_EOC;
565                 buffer = (buffer & (~(DIO_BE << DIO_PS_2))) | (DIO_BO <<
566                         DIO_PS_2);
567         } else {
568                 /* input port 2 */
569                 control_23 = (control_23 & DIO_CAND) | PCI20000_DIO_EIC;
570                 buffer = (buffer & (~(DIO_BI << DIO_PS_2)));
571         }
572         if (s->io_bits & 0xff000000) {
573                 /* output port 3 */
574                 control_23 &= PCI20000_DIO_OOC;
575                 buffer = (buffer & (~(DIO_BE << DIO_PS_3))) | (DIO_BO <<
576                         DIO_PS_3);
577         } else {
578                 /* input port 3 */
579                 control_23 = (control_23 & DIO_CAND) | PCI20000_DIO_OIC;
580                 buffer = (buffer & (~(DIO_BI << DIO_PS_3)));
581         }
582         writeb(control_01, devpriv->ioaddr + PCI20000_DIO_CONTROL_01);
583         writeb(control_23, devpriv->ioaddr + PCI20000_DIO_CONTROL_23);
584         writeb(buffer, devpriv->ioaddr + PCI20000_DIO_BUFFER);
585 }
586
587 #if 0
588 static void pci20xxx_do(struct comedi_device *dev, struct comedi_subdevice *s)
589 {
590         /* XXX if the channel is configured for input, does this
591            do bad things? */
592         /* XXX it would be a good idea to only update the registers
593            that _need_ to be updated.  This requires changes to
594            comedi, however. */
595         writeb((s->state >> 0) & 0xff, devpriv->ioaddr + PCI20000_DIO_0);
596         writeb((s->state >> 8) & 0xff, devpriv->ioaddr + PCI20000_DIO_1);
597         writeb((s->state >> 16) & 0xff, devpriv->ioaddr + PCI20000_DIO_2);
598         writeb((s->state >> 24) & 0xff, devpriv->ioaddr + PCI20000_DIO_3);
599 }
600
601 static unsigned int pci20xxx_di(struct comedi_device *dev, struct comedi_subdevice *s)
602 {
603         /* XXX same note as above */
604         unsigned int bits;
605
606         bits = readb(devpriv->ioaddr + PCI20000_DIO_0);
607         bits |= readb(devpriv->ioaddr + PCI20000_DIO_1) << 8;
608         bits |= readb(devpriv->ioaddr + PCI20000_DIO_2) << 16;
609         bits |= readb(devpriv->ioaddr + PCI20000_DIO_3) << 24;
610
611         return bits;
612 }
613 #endif
614
615 COMEDI_INITCLEANUP(driver_pci20xxx);