]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/ii_pci20kc.c
Merge tag 'late-omap' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[karo-tx-linux.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
27  *                             instead of 4 digital ports
28  *      di-port == Port 0
29  *      do-port == Port 1
30  *
31  *      The state of this driver is only a starting point for a complete
32  *      COMEDI-driver. The final driver should support all features of the
33  *      carrier board and modules.
34  *
35  *      The test configuration:
36  *
37  *      kernel 2.2.14 with RTAI v1.2  and patch-2.2.14rthal2
38  *      COMEDI 0.7.45
39  *      COMEDILIB 0.7.9
40  *
41  */
42 /*
43 Driver: ii_pci20kc
44 Description: Intelligent Instruments PCI-20001C carrier board
45 Author: Markus Kempf <kempf@matsci.uni-sb.de>
46 Devices: [Intelligent Instrumentation] PCI-20001C (ii_pci20kc)
47 Status: works
48
49 Supports the PCI-20001 C-2a Carrier board, and could probably support
50 the other carrier boards with small modifications.  Modules supported
51 are:
52         PCI-20006 M-2 16-bit analog output module
53         PCI-20341 M-1A 16-bit analog input module
54
55 Options:
56   0   Board base address
57   1   IRQ
58   2   first option for module 1
59   3   second option for module 1
60   4   first option for module 2
61   5   second option for module 2
62   6   first option for module 3
63   7   second option for module 3
64
65 options for PCI-20006M:
66   first:   Analog output channel 0 range configuration
67              0  bipolar 10  (-10V -- +10V)
68              1  unipolar 10  (0V -- +10V)
69              2  bipolar 5  (-5V -- 5V)
70   second:  Analog output channel 1 range configuration
71
72 options for PCI-20341M:
73   first:   Analog input gain configuration
74              0  1
75              1  10
76              2  100
77              3  200
78 */
79
80 /* XXX needs to use ioremap() for compatibility with 2.4 kernels.  Should also
81  * check_mem_region() etc. - fmhess */
82
83 #include "../comedidev.h"
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 & 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 & 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 union pci20xxx_subdev_private {
138         void __iomem *iobase;
139         struct {
140                 void __iomem *iobase;
141                 const struct comedi_lrange *ao_range_list[2];
142                                         /* range of channels of ao module */
143                 unsigned int last_data[2];
144         } pci20006;
145         struct {
146                 void __iomem *iobase;
147                 int timebase;
148                 int settling_time;
149                 int ai_gain;
150         } pci20341;
151 };
152
153 struct pci20xxx_private {
154
155         void __iomem *ioaddr;
156         union pci20xxx_subdev_private subdev_private[PCI20000_MODULES];
157 };
158
159 #define CHAN (CR_CHAN(it->chanlist[0]))
160
161 static int pci20006_init(struct comedi_device *dev, struct comedi_subdevice *s,
162                          int opt0, int opt1);
163 static int pci20341_init(struct comedi_device *dev, struct comedi_subdevice *s,
164                          int opt0, int opt1);
165 static int pci20xxx_dio_init(struct comedi_device *dev,
166                              struct comedi_subdevice *s);
167
168 /*
169   options[0]    Board base address
170   options[1]    IRQ
171   options[2]    first option for module 1
172   options[3]    second option for module 1
173   options[4]    first option for module 2
174   options[5]    second option for module 2
175   options[6]    first option for module 3
176   options[7]    second option for module 3
177
178   options for PCI-20341M:
179   first         Analog input gain configuration
180                 0 == 1
181                 1 == 10
182                 2 == 100
183                 3 == 200
184
185   options for PCI-20006M:
186   first         Analog output channel 0 range configuration
187                 0 == bipolar 10  (-10V -- +10V)
188                 1 == unipolar 10V  (0V -- +10V)
189                 2 == bipolar 5V  (-5V -- +5V)
190   second        Analog output channel 1 range configuration
191                 0 == bipolar 10  (-10V -- +10V)
192                 1 == unipolar 10V  (0V -- +10V)
193                 2 == bipolar 5V  (-5V -- +5V)
194 */
195 static int pci20xxx_attach(struct comedi_device *dev,
196                            struct comedi_devconfig *it)
197 {
198         struct pci20xxx_private *devpriv;
199         unsigned char i;
200         int ret;
201         int id;
202         struct comedi_subdevice *s;
203         union pci20xxx_subdev_private *sdp;
204
205         ret = comedi_alloc_subdevices(dev, 1 + PCI20000_MODULES);
206         if (ret)
207                 return ret;
208
209         devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
210         if (!devpriv)
211                 return -ENOMEM;
212         dev->private = devpriv;
213
214         devpriv->ioaddr = (void __iomem *)(unsigned long)it->options[0];
215         dev->board_name = "pci20kc";
216
217         /* Check PCI-20001 C-2A Carrier Board ID */
218         if ((readb(devpriv->ioaddr) & PCI20000_ID) != PCI20000_ID) {
219                 dev_warn(dev->class_dev,
220                          "PCI-20001 C-2A Carrier Board at base=0x%p not found !\n",
221                          devpriv->ioaddr);
222                 return -EINVAL;
223         }
224         dev_info(dev->class_dev, "PCI-20001 C-2A at base=0x%p\n",
225                  devpriv->ioaddr);
226
227         for (i = 0; i < PCI20000_MODULES; i++) {
228                 s = &dev->subdevices[i];
229                 id = readb(devpriv->ioaddr + (i + 1) * PCI20000_OFFSET);
230                 s->private = devpriv->subdev_private + i;
231                 sdp = s->private;
232                 switch (id) {
233                 case PCI20006_ID:
234                         sdp->pci20006.iobase =
235                             devpriv->ioaddr + (i + 1) * PCI20000_OFFSET;
236                         pci20006_init(dev, s, it->options[2 * i + 2],
237                                       it->options[2 * i + 3]);
238                         dev_info(dev->class_dev,
239                                  "PCI-20006 module in slot %d\n", i + 1);
240                         break;
241                 case PCI20341_ID:
242                         sdp->pci20341.iobase =
243                             devpriv->ioaddr + (i + 1) * PCI20000_OFFSET;
244                         pci20341_init(dev, s, it->options[2 * i + 2],
245                                       it->options[2 * i + 3]);
246                         dev_info(dev->class_dev,
247                                  "PCI-20341 module in slot %d\n", i + 1);
248                         break;
249                 default:
250                         dev_warn(dev->class_dev,
251                                  "unknown module code 0x%02x in slot %d: module disabled\n",
252                                  id, i); /* XXX this looks like a bug! i + 1 ?? */
253                         /* fall through */
254                 case PCI20xxx_EMPTY_ID:
255                         s->type = COMEDI_SUBD_UNUSED;
256                         break;
257                 }
258         }
259
260         /* initialize struct pci20xxx_private */
261         pci20xxx_dio_init(dev, &dev->subdevices[PCI20000_MODULES]);
262
263         return 1;
264 }
265
266 static void pci20xxx_detach(struct comedi_device *dev)
267 {
268         /* Nothing to cleanup */
269 }
270
271 /* pci20006m */
272
273 static int pci20006_insn_read(struct comedi_device *dev,
274                               struct comedi_subdevice *s,
275                               struct comedi_insn *insn, unsigned int *data);
276 static int pci20006_insn_write(struct comedi_device *dev,
277                                struct comedi_subdevice *s,
278                                struct comedi_insn *insn, unsigned int *data);
279
280 static const struct comedi_lrange *pci20006_range_list[] = {
281         &range_bipolar10,
282         &range_unipolar10,
283         &range_bipolar5,
284 };
285
286 static int pci20006_init(struct comedi_device *dev, struct comedi_subdevice *s,
287                          int opt0, int opt1)
288 {
289         union pci20xxx_subdev_private *sdp = s->private;
290
291         if (opt0 < 0 || opt0 > 2)
292                 opt0 = 0;
293         if (opt1 < 0 || opt1 > 2)
294                 opt1 = 0;
295
296         sdp->pci20006.ao_range_list[0] = pci20006_range_list[opt0];
297         sdp->pci20006.ao_range_list[1] = pci20006_range_list[opt1];
298
299         /* ao subdevice */
300         s->type = COMEDI_SUBD_AO;
301         s->subdev_flags = SDF_WRITABLE;
302         s->n_chan = 2;
303         s->len_chanlist = 2;
304         s->insn_read = pci20006_insn_read;
305         s->insn_write = pci20006_insn_write;
306         s->maxdata = 0xffff;
307         s->range_table_list = sdp->pci20006.ao_range_list;
308         return 0;
309 }
310
311 static int pci20006_insn_read(struct comedi_device *dev,
312                               struct comedi_subdevice *s,
313                               struct comedi_insn *insn, unsigned int *data)
314 {
315         union pci20xxx_subdev_private *sdp = s->private;
316
317         data[0] = sdp->pci20006.last_data[CR_CHAN(insn->chanspec)];
318
319         return 1;
320 }
321
322 static int pci20006_insn_write(struct comedi_device *dev,
323                                struct comedi_subdevice *s,
324                                struct comedi_insn *insn, unsigned int *data)
325 {
326         union pci20xxx_subdev_private *sdp = s->private;
327         int hi, lo;
328         unsigned int boarddata;
329
330         sdp->pci20006.last_data[CR_CHAN(insn->chanspec)] = data[0];
331         boarddata = (((unsigned int)data[0] + 0x8000) & 0xffff);
332                                                 /* 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                 dev_warn(dev->class_dev, "ao channel Error!\n");
349                 return -EINVAL;
350         }
351
352         return 1;
353 }
354
355 /* PCI20341M */
356
357 static int pci20341_insn_read(struct comedi_device *dev,
358                               struct comedi_subdevice *s,
359                               struct comedi_insn *insn, unsigned int *data);
360
361 static const int pci20341_timebase[] = { 0x00, 0x00, 0x00, 0x04 };
362 static const int pci20341_settling_time[] = { 0x58, 0x58, 0x93, 0x99 };
363
364 static const struct comedi_lrange range_bipolar0_5 = {
365         1,
366         {BIP_RANGE(0.5)}
367 };
368
369 static const struct comedi_lrange range_bipolar0_05 = {
370         1,
371         {BIP_RANGE(0.05)}
372 };
373
374 static const struct comedi_lrange range_bipolar0_025 = {
375         1,
376         {BIP_RANGE(0.025)}
377 };
378
379 static const struct comedi_lrange *const pci20341_ranges[] = {
380         &range_bipolar5,
381         &range_bipolar0_5,
382         &range_bipolar0_05,
383         &range_bipolar0_025,
384 };
385
386 static int pci20341_init(struct comedi_device *dev, struct comedi_subdevice *s,
387                          int opt0, int opt1)
388 {
389         union pci20xxx_subdev_private *sdp = s->private;
390         int option;
391
392         /* options handling */
393         if (opt0 < 0 || opt0 > 3)
394                 opt0 = 0;
395         sdp->pci20341.timebase = pci20341_timebase[opt0];
396         sdp->pci20341.settling_time = pci20341_settling_time[opt0];
397
398         /* ai subdevice */
399         s->type = COMEDI_SUBD_AI;
400         s->subdev_flags = SDF_READABLE;
401         s->n_chan = PCI20341_CHAN_NR;
402         s->len_chanlist = PCI20341_SCANLIST;
403         s->insn_read = pci20341_insn_read;
404         s->maxdata = 0xffff;
405         s->range_table = pci20341_ranges[opt0];
406
407         /* depends on gain, trigger, repetition mode */
408         option = sdp->pci20341.timebase | PCI20341_REPMODE;
409
410         /* initialize Module */
411         writeb(PCI20341_INIT, sdp->iobase + PCI20341_CONFIG_REG);
412         /* set Pacer */
413         writeb(PCI20341_PACER, sdp->iobase + PCI20341_MOD_STATUS);
414         /* option register */
415         writeb(option, sdp->iobase + PCI20341_OPT_REG);
416         /* settling time counter */
417         writeb(sdp->pci20341.settling_time,
418                 sdp->iobase + PCI20341_SET_TIME_REG);
419         /* trigger not implemented */
420         return 0;
421 }
422
423 static int pci20341_insn_read(struct comedi_device *dev,
424                               struct comedi_subdevice *s,
425                               struct comedi_insn *insn, unsigned int *data)
426 {
427         union pci20xxx_subdev_private *sdp = s->private;
428         unsigned int i = 0, j = 0;
429         int lo, hi;
430         unsigned char eoc;      /* end of conversion */
431         unsigned int clb;       /* channel list byte */
432         unsigned int boarddata;
433
434         /* write number of input channels */
435         writeb(1, sdp->iobase + PCI20341_LCHAN_ADDR_REG);
436         clb = PCI20341_DAISY_CHAIN | PCI20341_MUX | (sdp->pci20341.ai_gain << 3)
437             | CR_CHAN(insn->chanspec);
438         writeb(clb, sdp->iobase + PCI20341_CHAN_LIST);
439
440         /* reset settling time counter and trigger delay counter */
441         writeb(0x00, sdp->iobase + PCI20341_CC_RESET);
442
443         writeb(0x00, sdp->iobase + PCI20341_CHAN_RESET);
444
445         /* generate Pacer */
446
447         for (i = 0; i < insn->n; i++) {
448                 /* data polling isn't the niciest way to get the data, I know,
449                  * but there are only 6 cycles (mean) and it is easier than
450                  * the whole interrupt stuff
451                  */
452                 j = 0;
453                 /* generate Pacer */
454                 readb(sdp->iobase + PCI20341_SOFT_PACER);
455
456                 eoc = readb(sdp->iobase + PCI20341_STATUS_REG);
457                 /* poll Interrupt Flag */
458                 while ((eoc < 0x80) && j < 100) {
459                         j++;
460                         eoc = readb(sdp->iobase + PCI20341_STATUS_REG);
461                 }
462                 if (j >= 100) {
463                         dev_warn(dev->class_dev,
464                                  "AI interrupt channel %i polling exit !\n", i);
465                         return -EINVAL;
466                 }
467                 lo = readb(sdp->iobase + PCI20341_LDATA);
468                 hi = readb(sdp->iobase + PCI20341_LDATA + 1);
469                 boarddata = lo + 0x100 * hi;
470
471                 /* board-data -> comedi-data */
472                 data[i] = (short)((boarddata + 0x8000) & 0xffff);
473         }
474
475         return i;
476 }
477
478 /* native DIO */
479
480 static void pci20xxx_dio_config(struct comedi_device *dev,
481                                 struct comedi_subdevice *s);
482 static int pci20xxx_dio_insn_bits(struct comedi_device *dev,
483                                   struct comedi_subdevice *s,
484                                   struct comedi_insn *insn, unsigned int *data);
485 static int pci20xxx_dio_insn_config(struct comedi_device *dev,
486                                     struct comedi_subdevice *s,
487                                     struct comedi_insn *insn,
488                                     unsigned int *data);
489
490 /* initialize struct pci20xxx_private */
491 static int pci20xxx_dio_init(struct comedi_device *dev,
492                              struct comedi_subdevice *s)
493 {
494
495         s->type = COMEDI_SUBD_DIO;
496         s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
497         s->n_chan = 32;
498         s->insn_bits = pci20xxx_dio_insn_bits;
499         s->insn_config = pci20xxx_dio_insn_config;
500         s->maxdata = 1;
501         s->len_chanlist = 32;
502         s->range_table = &range_digital;
503         s->io_bits = 0;
504
505         /* digital I/O lines default to input on board reset. */
506         pci20xxx_dio_config(dev, s);
507
508         return 0;
509 }
510
511 static int pci20xxx_dio_insn_config(struct comedi_device *dev,
512                                     struct comedi_subdevice *s,
513                                     struct comedi_insn *insn,
514                                     unsigned int *data)
515 {
516         int mask, bits;
517
518         mask = 1 << CR_CHAN(insn->chanspec);
519         if (mask & 0x000000ff)
520                 bits = 0x000000ff;
521         else if (mask & 0x0000ff00)
522                 bits = 0x0000ff00;
523         else if (mask & 0x00ff0000)
524                 bits = 0x00ff0000;
525         else
526                 bits = 0xff000000;
527         if (data[0])
528                 s->io_bits |= bits;
529         else
530                 s->io_bits &= ~bits;
531         pci20xxx_dio_config(dev, s);
532
533         return 1;
534 }
535
536 static int pci20xxx_dio_insn_bits(struct comedi_device *dev,
537                                   struct comedi_subdevice *s,
538                                   struct comedi_insn *insn, unsigned int *data)
539 {
540         struct pci20xxx_private *devpriv = dev->private;
541         unsigned int mask = data[0];
542
543         s->state &= ~mask;
544         s->state |= (mask & data[1]);
545
546         mask &= s->io_bits;
547         if (mask & 0x000000ff)
548                 writeb((s->state >> 0) & 0xff,
549                        devpriv->ioaddr + PCI20000_DIO_0);
550         if (mask & 0x0000ff00)
551                 writeb((s->state >> 8) & 0xff,
552                        devpriv->ioaddr + PCI20000_DIO_1);
553         if (mask & 0x00ff0000)
554                 writeb((s->state >> 16) & 0xff,
555                        devpriv->ioaddr + PCI20000_DIO_2);
556         if (mask & 0xff000000)
557                 writeb((s->state >> 24) & 0xff,
558                        devpriv->ioaddr + PCI20000_DIO_3);
559
560         data[1] = readb(devpriv->ioaddr + PCI20000_DIO_0);
561         data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_1) << 8;
562         data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_2) << 16;
563         data[1] |= readb(devpriv->ioaddr + PCI20000_DIO_3) << 24;
564
565         return insn->n;
566 }
567
568 static void pci20xxx_dio_config(struct comedi_device *dev,
569                                 struct comedi_subdevice *s)
570 {
571         struct pci20xxx_private *devpriv = dev->private;
572         unsigned char control_01;
573         unsigned char control_23;
574         unsigned char buffer;
575
576         control_01 = readb(devpriv->ioaddr + PCI20000_DIO_CONTROL_01);
577         control_23 = readb(devpriv->ioaddr + PCI20000_DIO_CONTROL_23);
578         buffer = readb(devpriv->ioaddr + PCI20000_DIO_BUFFER);
579
580         if (s->io_bits & 0x000000ff) {
581                 /* output port 0 */
582                 control_01 &= PCI20000_DIO_EOC;
583                 buffer = (buffer & (~(DIO_BE << DIO_PS_0))) | (DIO_BO <<
584                                                                DIO_PS_0);
585         } else {
586                 /* input port 0 */
587                 control_01 = (control_01 & DIO_CAND) | PCI20000_DIO_EIC;
588                 buffer = (buffer & (~(DIO_BI << DIO_PS_0)));
589         }
590         if (s->io_bits & 0x0000ff00) {
591                 /* output port 1 */
592                 control_01 &= PCI20000_DIO_OOC;
593                 buffer = (buffer & (~(DIO_BE << DIO_PS_1))) | (DIO_BO <<
594                                                                DIO_PS_1);
595         } else {
596                 /* input port 1 */
597                 control_01 = (control_01 & DIO_CAND) | PCI20000_DIO_OIC;
598                 buffer = (buffer & (~(DIO_BI << DIO_PS_1)));
599         }
600         if (s->io_bits & 0x00ff0000) {
601                 /* output port 2 */
602                 control_23 &= PCI20000_DIO_EOC;
603                 buffer = (buffer & (~(DIO_BE << DIO_PS_2))) | (DIO_BO <<
604                                                                DIO_PS_2);
605         } else {
606                 /* input port 2 */
607                 control_23 = (control_23 & DIO_CAND) | PCI20000_DIO_EIC;
608                 buffer = (buffer & (~(DIO_BI << DIO_PS_2)));
609         }
610         if (s->io_bits & 0xff000000) {
611                 /* output port 3 */
612                 control_23 &= PCI20000_DIO_OOC;
613                 buffer = (buffer & (~(DIO_BE << DIO_PS_3))) | (DIO_BO <<
614                                                                DIO_PS_3);
615         } else {
616                 /* input port 3 */
617                 control_23 = (control_23 & DIO_CAND) | PCI20000_DIO_OIC;
618                 buffer = (buffer & (~(DIO_BI << DIO_PS_3)));
619         }
620         writeb(control_01, devpriv->ioaddr + PCI20000_DIO_CONTROL_01);
621         writeb(control_23, devpriv->ioaddr + PCI20000_DIO_CONTROL_23);
622         writeb(buffer, devpriv->ioaddr + PCI20000_DIO_BUFFER);
623 }
624
625 #if 0
626 static void pci20xxx_do(struct comedi_device *dev, struct comedi_subdevice *s)
627 {
628         struct pci20xxx_private *devpriv = dev->private;
629
630         /* XXX if the channel is configured for input, does this
631            do bad things? */
632         /* XXX it would be a good idea to only update the registers
633            that _need_ to be updated.  This requires changes to
634            comedi, however. */
635         writeb((s->state >> 0) & 0xff, devpriv->ioaddr + PCI20000_DIO_0);
636         writeb((s->state >> 8) & 0xff, devpriv->ioaddr + PCI20000_DIO_1);
637         writeb((s->state >> 16) & 0xff, devpriv->ioaddr + PCI20000_DIO_2);
638         writeb((s->state >> 24) & 0xff, devpriv->ioaddr + PCI20000_DIO_3);
639 }
640
641 static unsigned int pci20xxx_di(struct comedi_device *dev,
642                                 struct comedi_subdevice *s)
643 {
644         struct pci20xxx_private *devpriv = dev->private;
645         unsigned int bits;
646
647         /* XXX same note as above */
648         bits = readb(devpriv->ioaddr + PCI20000_DIO_0);
649         bits |= readb(devpriv->ioaddr + PCI20000_DIO_1) << 8;
650         bits |= readb(devpriv->ioaddr + PCI20000_DIO_2) << 16;
651         bits |= readb(devpriv->ioaddr + PCI20000_DIO_3) << 24;
652
653         return bits;
654 }
655 #endif
656
657 static struct comedi_driver pci20xxx_driver = {
658         .driver_name    = "ii_pci20kc",
659         .module         = THIS_MODULE,
660         .attach         = pci20xxx_attach,
661         .detach         = pci20xxx_detach,
662 };
663 module_comedi_driver(pci20xxx_driver);
664
665 MODULE_AUTHOR("Comedi http://www.comedi.org");
666 MODULE_DESCRIPTION("Comedi low-level driver");
667 MODULE_LICENSE("GPL");