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