]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/aio_iiro_16.c
Merge branch 'next' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[karo-tx-linux.git] / drivers / staging / comedi / drivers / aio_iiro_16.c
1 /*
2
3     comedi/drivers/aio_iiro_16.c
4
5     Driver for Access I/O Products PC-104 AIO-IIRO-16 Digital I/O board
6     Copyright (C) 2006 C&C Technologies, Inc.
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17 */
18
19 /*
20
21 Driver: aio_iiro_16
22 Description: Access I/O Products PC-104 IIRO16 Relay And Isolated Input Board
23 Author: Zachary Ware <zach.ware@cctechnol.com>
24 Devices:
25  [Access I/O] PC-104 AIO12-8
26 Status: experimental
27
28 Configuration Options:
29   [0] - I/O port base address
30
31 */
32
33 #include <linux/module.h>
34 #include "../comedidev.h"
35
36 #define AIO_IIRO_16_SIZE        0x08
37 #define AIO_IIRO_16_RELAY_0_7   0x00
38 #define AIO_IIRO_16_INPUT_0_7   0x01
39 #define AIO_IIRO_16_IRQ         0x02
40 #define AIO_IIRO_16_RELAY_8_15  0x04
41 #define AIO_IIRO_16_INPUT_8_15  0x05
42
43 static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
44                                            struct comedi_subdevice *s,
45                                            struct comedi_insn *insn,
46                                            unsigned int *data)
47 {
48         if (data[0]) {
49                 s->state &= ~data[0];
50                 s->state |= data[0] & data[1];
51                 outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
52                 outb((s->state >> 8) & 0xff,
53                      dev->iobase + AIO_IIRO_16_RELAY_8_15);
54         }
55
56         data[1] = s->state;
57
58         return insn->n;
59 }
60
61 static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,
62                                           struct comedi_subdevice *s,
63                                           struct comedi_insn *insn,
64                                           unsigned int *data)
65 {
66         data[1] = 0;
67         data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
68         data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
69
70         return insn->n;
71 }
72
73 static int aio_iiro_16_attach(struct comedi_device *dev,
74                               struct comedi_devconfig *it)
75 {
76         struct comedi_subdevice *s;
77         int ret;
78
79         ret = comedi_request_region(dev, it->options[0], AIO_IIRO_16_SIZE);
80         if (ret)
81                 return ret;
82
83         ret = comedi_alloc_subdevices(dev, 2);
84         if (ret)
85                 return ret;
86
87         s = &dev->subdevices[0];
88         s->type = COMEDI_SUBD_DIO;
89         s->subdev_flags = SDF_WRITABLE;
90         s->n_chan = 16;
91         s->maxdata = 1;
92         s->range_table = &range_digital;
93         s->insn_bits = aio_iiro_16_dio_insn_bits_write;
94
95         s = &dev->subdevices[1];
96         s->type = COMEDI_SUBD_DIO;
97         s->subdev_flags = SDF_READABLE;
98         s->n_chan = 16;
99         s->maxdata = 1;
100         s->range_table = &range_digital;
101         s->insn_bits = aio_iiro_16_dio_insn_bits_read;
102
103         return 1;
104 }
105
106 static struct comedi_driver aio_iiro_16_driver = {
107         .driver_name    = "aio_iiro_16",
108         .module         = THIS_MODULE,
109         .attach         = aio_iiro_16_attach,
110         .detach         = comedi_legacy_detach,
111 };
112 module_comedi_driver(aio_iiro_16_driver);
113
114 MODULE_AUTHOR("Comedi http://www.comedi.org");
115 MODULE_DESCRIPTION("Comedi low-level driver");
116 MODULE_LICENSE("GPL");