packaging: release out (3.8.3)
[profile/ivi/kernel-adaptation-intel-automotive.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     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 /*
24
25 Driver: aio_iiro_16
26 Description: Access I/O Products PC-104 IIRO16 Relay And Isolated Input Board
27 Author: Zachary Ware <zach.ware@cctechnol.com>
28 Devices:
29  [Access I/O] PC-104 AIO12-8
30 Status: experimental
31
32 Configuration Options:
33   [0] - I/O port base address
34
35 */
36
37 #include "../comedidev.h"
38 #include <linux/ioport.h>
39
40 #define AIO_IIRO_16_SIZE        0x08
41 #define AIO_IIRO_16_RELAY_0_7   0x00
42 #define AIO_IIRO_16_INPUT_0_7   0x01
43 #define AIO_IIRO_16_IRQ         0x02
44 #define AIO_IIRO_16_RELAY_8_15  0x04
45 #define AIO_IIRO_16_INPUT_8_15  0x05
46
47 static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
48                                            struct comedi_subdevice *s,
49                                            struct comedi_insn *insn,
50                                            unsigned int *data)
51 {
52         if (data[0]) {
53                 s->state &= ~data[0];
54                 s->state |= data[0] & data[1];
55                 outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
56                 outb((s->state >> 8) & 0xff,
57                      dev->iobase + AIO_IIRO_16_RELAY_8_15);
58         }
59
60         data[1] = s->state;
61
62         return insn->n;
63 }
64
65 static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,
66                                           struct comedi_subdevice *s,
67                                           struct comedi_insn *insn,
68                                           unsigned int *data)
69 {
70         data[1] = 0;
71         data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
72         data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
73
74         return insn->n;
75 }
76
77 static int aio_iiro_16_attach(struct comedi_device *dev,
78                               struct comedi_devconfig *it)
79 {
80         int iobase;
81         struct comedi_subdevice *s;
82         int ret;
83
84         printk(KERN_INFO "comedi%d: aio_iiro_16: ", dev->minor);
85
86         dev->board_name = dev->driver->driver_name;
87
88         iobase = it->options[0];
89
90         if (!request_region(iobase, AIO_IIRO_16_SIZE, dev->board_name)) {
91                 printk("I/O port conflict");
92                 return -EIO;
93         }
94
95         dev->iobase = iobase;
96
97         ret = comedi_alloc_subdevices(dev, 2);
98         if (ret)
99                 return ret;
100
101         s = &dev->subdevices[0];
102         s->type = COMEDI_SUBD_DIO;
103         s->subdev_flags = SDF_WRITABLE;
104         s->n_chan = 16;
105         s->maxdata = 1;
106         s->range_table = &range_digital;
107         s->insn_bits = aio_iiro_16_dio_insn_bits_write;
108
109         s = &dev->subdevices[1];
110         s->type = COMEDI_SUBD_DIO;
111         s->subdev_flags = SDF_READABLE;
112         s->n_chan = 16;
113         s->maxdata = 1;
114         s->range_table = &range_digital;
115         s->insn_bits = aio_iiro_16_dio_insn_bits_read;
116
117         printk("attached\n");
118
119         return 1;
120 }
121
122 static void aio_iiro_16_detach(struct comedi_device *dev)
123 {
124         if (dev->iobase)
125                 release_region(dev->iobase, AIO_IIRO_16_SIZE);
126 }
127
128 static struct comedi_driver aio_iiro_16_driver = {
129         .driver_name    = "aio_iiro_16",
130         .module         = THIS_MODULE,
131         .attach         = aio_iiro_16_attach,
132         .detach         = aio_iiro_16_detach,
133 };
134 module_comedi_driver(aio_iiro_16_driver);
135
136 MODULE_AUTHOR("Comedi http://www.comedi.org");
137 MODULE_DESCRIPTION("Comedi low-level driver");
138 MODULE_LICENSE("GPL");