staging: comedi: propogate error code from comedi_alloc_subdevices
[deliverable/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 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 struct aio_iiro_16_board {
48 const char *name;
49 int do_;
50 int di;
51 };
52
53 static const struct aio_iiro_16_board aio_iiro_16_boards[] = {
54 {
55 .name = "aio_iiro_16",
56 .di = 16,
57 .do_ = 16},
58 };
59
60 struct aio_iiro_16_private {
61 int data;
62 struct pci_dev *pci_dev;
63 unsigned int ao_readback[2];
64 };
65
66 #define devpriv ((struct aio_iiro_16_private *) dev->private)
67
68 static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
69 struct comedi_subdevice *s,
70 struct comedi_insn *insn,
71 unsigned int *data)
72 {
73 if (insn->n != 2)
74 return -EINVAL;
75
76 if (data[0]) {
77 s->state &= ~data[0];
78 s->state |= data[0] & data[1];
79 outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
80 outb((s->state >> 8) & 0xff,
81 dev->iobase + AIO_IIRO_16_RELAY_8_15);
82 }
83
84 data[1] = s->state;
85
86 return 2;
87 }
88
89 static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,
90 struct comedi_subdevice *s,
91 struct comedi_insn *insn,
92 unsigned int *data)
93 {
94 if (insn->n != 2)
95 return -EINVAL;
96
97 data[1] = 0;
98 data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
99 data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
100
101 return 2;
102 }
103
104 static int aio_iiro_16_attach(struct comedi_device *dev,
105 struct comedi_devconfig *it)
106 {
107 const struct aio_iiro_16_board *board = comedi_board(dev);
108 int iobase;
109 struct comedi_subdevice *s;
110 int ret;
111
112 printk(KERN_INFO "comedi%d: aio_iiro_16: ", dev->minor);
113
114 dev->board_name = board->name;
115
116 iobase = it->options[0];
117
118 if (!request_region(iobase, AIO_IIRO_16_SIZE, dev->board_name)) {
119 printk("I/O port conflict");
120 return -EIO;
121 }
122
123 dev->iobase = iobase;
124
125 if (alloc_private(dev, sizeof(struct aio_iiro_16_private)) < 0)
126 return -ENOMEM;
127
128 ret = comedi_alloc_subdevices(dev, 2);
129 if (ret)
130 return ret;
131
132 s = dev->subdevices + 0;
133 s->type = COMEDI_SUBD_DIO;
134 s->subdev_flags = SDF_WRITABLE;
135 s->n_chan = 16;
136 s->maxdata = 1;
137 s->range_table = &range_digital;
138 s->insn_bits = aio_iiro_16_dio_insn_bits_write;
139
140 s = dev->subdevices + 1;
141 s->type = COMEDI_SUBD_DIO;
142 s->subdev_flags = SDF_READABLE;
143 s->n_chan = 16;
144 s->maxdata = 1;
145 s->range_table = &range_digital;
146 s->insn_bits = aio_iiro_16_dio_insn_bits_read;
147
148 printk("attached\n");
149
150 return 1;
151 }
152
153 static void aio_iiro_16_detach(struct comedi_device *dev)
154 {
155 if (dev->iobase)
156 release_region(dev->iobase, AIO_IIRO_16_SIZE);
157 }
158
159 static struct comedi_driver aio_iiro_16_driver = {
160 .driver_name = "aio_iiro_16",
161 .module = THIS_MODULE,
162 .attach = aio_iiro_16_attach,
163 .detach = aio_iiro_16_detach,
164 .board_name = &aio_iiro_16_boards[0].name,
165 .offset = sizeof(struct aio_iiro_16_board),
166 .num_names = ARRAY_SIZE(aio_iiro_16_boards),
167 };
168 module_comedi_driver(aio_iiro_16_driver);
169
170 MODULE_AUTHOR("Comedi http://www.comedi.org");
171 MODULE_DESCRIPTION("Comedi low-level driver");
172 MODULE_LICENSE("GPL");
This page took 0.035159 seconds and 5 git commands to generate.