]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/comedi/drivers/aio_iiro_16.c
arm: imx6: defconfig: update tx6 defconfigs
[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 (comedi_dio_update_state(s, data)) {
49                 outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
50                 outb((s->state >> 8) & 0xff,
51                      dev->iobase + AIO_IIRO_16_RELAY_8_15);
52         }
53
54         data[1] = s->state;
55
56         return insn->n;
57 }
58
59 static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,
60                                           struct comedi_subdevice *s,
61                                           struct comedi_insn *insn,
62                                           unsigned int *data)
63 {
64         data[1] = 0;
65         data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
66         data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
67
68         return insn->n;
69 }
70
71 static int aio_iiro_16_attach(struct comedi_device *dev,
72                               struct comedi_devconfig *it)
73 {
74         struct comedi_subdevice *s;
75         int ret;
76
77         ret = comedi_request_region(dev, it->options[0], AIO_IIRO_16_SIZE);
78         if (ret)
79                 return ret;
80
81         ret = comedi_alloc_subdevices(dev, 2);
82         if (ret)
83                 return ret;
84
85         s = &dev->subdevices[0];
86         s->type = COMEDI_SUBD_DIO;
87         s->subdev_flags = SDF_WRITABLE;
88         s->n_chan = 16;
89         s->maxdata = 1;
90         s->range_table = &range_digital;
91         s->insn_bits = aio_iiro_16_dio_insn_bits_write;
92
93         s = &dev->subdevices[1];
94         s->type = COMEDI_SUBD_DIO;
95         s->subdev_flags = SDF_READABLE;
96         s->n_chan = 16;
97         s->maxdata = 1;
98         s->range_table = &range_digital;
99         s->insn_bits = aio_iiro_16_dio_insn_bits_read;
100
101         return 1;
102 }
103
104 static struct comedi_driver aio_iiro_16_driver = {
105         .driver_name    = "aio_iiro_16",
106         .module         = THIS_MODULE,
107         .attach         = aio_iiro_16_attach,
108         .detach         = comedi_legacy_detach,
109 };
110 module_comedi_driver(aio_iiro_16_driver);
111
112 MODULE_AUTHOR("Comedi http://www.comedi.org");
113 MODULE_DESCRIPTION("Comedi low-level driver");
114 MODULE_LICENSE("GPL");