Staging: comedi: Remove comedi_subdevice typedef
[pandora-kernel.git] / drivers / staging / comedi / drivers / aio_iiro_16.c
1 /*
2
3     comedi/drivers/aio_iiro_16.c
4
5     Driver for Acces 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: Acces I/O Products PC-104 IIRO16 Relay And Isolated Input Board
27 Author: Zachary Ware <zach.ware@cctechnol.com>
28 Devices:
29  [Acces 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 typedef struct aio_iiro_16_board_struct {
48         const char *name;
49         int do_;
50         int di;
51 } aio_iiro_16_board;
52
53 static const aio_iiro_16_board aio_iiro_16_boards[] = {
54         {
55               name:     "aio_iiro_16",
56               di:       16,
57       do_:      16},
58 };
59
60 #define thisboard       ((const aio_iiro_16_board *) dev->board_ptr)
61
62 typedef struct {
63         int data;
64         struct pci_dev *pci_dev;
65         unsigned int ao_readback[2];
66 } aio_iiro_16_private;
67
68 #define devpriv ((aio_iiro_16_private *) dev->private)
69
70 static int aio_iiro_16_attach(struct comedi_device * dev, comedi_devconfig * it);
71
72 static int aio_iiro_16_detach(struct comedi_device * dev);
73
74 static comedi_driver driver_aio_iiro_16 = {
75       driver_name:"aio_iiro_16",
76       module:THIS_MODULE,
77       attach:aio_iiro_16_attach,
78       detach:aio_iiro_16_detach,
79       board_name:&aio_iiro_16_boards[0].name,
80       offset:sizeof(aio_iiro_16_board),
81       num_names:sizeof(aio_iiro_16_boards) / sizeof(aio_iiro_16_board),
82 };
83
84 static int aio_iiro_16_dio_insn_bits_read(struct comedi_device * dev,
85         struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data);
86
87 static int aio_iiro_16_dio_insn_bits_write(struct comedi_device * dev,
88         struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data);
89
90 static int aio_iiro_16_attach(struct comedi_device * dev, comedi_devconfig * it)
91 {
92         int iobase;
93         struct comedi_subdevice *s;
94
95         printk("comedi%d: aio_iiro_16: ", dev->minor);
96
97         dev->board_name = thisboard->name;
98
99         iobase = it->options[0];
100
101         if (!request_region(iobase, AIO_IIRO_16_SIZE, dev->board_name)) {
102                 printk("I/O port conflict");
103                 return -EIO;
104         }
105
106         dev->iobase = iobase;
107
108         if (alloc_private(dev, sizeof(aio_iiro_16_private)) < 0)
109                 return -ENOMEM;
110
111         if (alloc_subdevices(dev, 2) < 0)
112                 return -ENOMEM;
113
114         s = dev->subdevices + 0;
115         s->type = COMEDI_SUBD_DIO;
116         s->subdev_flags = SDF_WRITABLE;
117         s->n_chan = 16;
118         s->maxdata = 1;
119         s->range_table = &range_digital;
120         s->insn_bits = aio_iiro_16_dio_insn_bits_write;
121
122         s = dev->subdevices + 1;
123         s->type = COMEDI_SUBD_DIO;
124         s->subdev_flags = SDF_READABLE;
125         s->n_chan = 16;
126         s->maxdata = 1;
127         s->range_table = &range_digital;
128         s->insn_bits = aio_iiro_16_dio_insn_bits_read;
129
130         printk("attached\n");
131
132         return 1;
133 }
134
135 static int aio_iiro_16_detach(struct comedi_device * dev)
136 {
137         printk("comedi%d: aio_iiro_16: remove\n", dev->minor);
138
139         if (dev->iobase)
140                 release_region(dev->iobase, AIO_IIRO_16_SIZE);
141
142         return 0;
143 }
144
145 static int aio_iiro_16_dio_insn_bits_write(struct comedi_device * dev,
146         struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data)
147 {
148         if (insn->n != 2)
149                 return -EINVAL;
150
151         if (data[0]) {
152                 s->state &= ~data[0];
153                 s->state |= data[0] & data[1];
154                 outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
155                 outb((s->state >> 8) & 0xff,
156                         dev->iobase + AIO_IIRO_16_RELAY_8_15);
157         }
158
159         data[1] = s->state;
160
161         return 2;
162 }
163
164 static int aio_iiro_16_dio_insn_bits_read(struct comedi_device * dev,
165         struct comedi_subdevice * s, comedi_insn * insn, unsigned int * data)
166 {
167         if (insn->n != 2)
168                 return -EINVAL;
169
170         data[1] = 0;
171         data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
172         data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
173
174         return 2;
175 }
176
177 COMEDI_INITCLEANUP(driver_aio_iiro_16);