]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - drivers/staging/comedi/drivers/aio_iiro_16.c
Staging: comedi: fix "foo * bar" should be "foo *bar"
[mirror_ubuntu-kernels.git] / drivers / staging / comedi / drivers / aio_iiro_16.c
CommitLineData
56af390d
ZW
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
25Driver: aio_iiro_16
26Description: Acces I/O Products PC-104 IIRO16 Relay And Isolated Input Board
27Author: Zachary Ware <zach.ware@cctechnol.com>
28Devices:
29 [Acces I/O] PC-104 AIO12-8
30Status: experimental
31
32Configuration 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
28fa7754 47struct aio_iiro_16_board {
56af390d
ZW
48 const char *name;
49 int do_;
50 int di;
28fa7754 51};
56af390d 52
28fa7754 53static const struct aio_iiro_16_board aio_iiro_16_boards[] = {
56af390d
ZW
54 {
55 name: "aio_iiro_16",
56 di: 16,
57 do_: 16},
58};
59
28fa7754 60#define thisboard ((const struct aio_iiro_16_board *) dev->board_ptr)
56af390d 61
55d99639 62struct aio_iiro_16_private {
56af390d
ZW
63 int data;
64 struct pci_dev *pci_dev;
790c5541 65 unsigned int ao_readback[2];
55d99639 66};
56af390d 67
55d99639 68#define devpriv ((struct aio_iiro_16_private *) dev->private)
56af390d 69
da91b269 70static int aio_iiro_16_attach(struct comedi_device *dev, struct comedi_devconfig *it);
56af390d 71
da91b269 72static int aio_iiro_16_detach(struct comedi_device *dev);
56af390d 73
139dfbdf 74static struct comedi_driver driver_aio_iiro_16 = {
56af390d
ZW
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,
28fa7754
BP
80 offset:sizeof(struct aio_iiro_16_board),
81 num_names:sizeof(aio_iiro_16_boards) / sizeof(struct aio_iiro_16_board),
56af390d
ZW
82};
83
da91b269
BP
84static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,
85 struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data);
56af390d 86
da91b269
BP
87static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
88 struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data);
56af390d 89
da91b269 90static int aio_iiro_16_attach(struct comedi_device *dev, struct comedi_devconfig *it)
56af390d
ZW
91{
92 int iobase;
34c43922 93 struct comedi_subdevice *s;
56af390d
ZW
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
55d99639 108 if (alloc_private(dev, sizeof(struct aio_iiro_16_private)) < 0)
56af390d
ZW
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
da91b269 135static int aio_iiro_16_detach(struct comedi_device *dev)
56af390d
ZW
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
da91b269
BP
145static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
146 struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data)
56af390d
ZW
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
da91b269
BP
164static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,
165 struct comedi_subdevice *s, struct comedi_insn *insn, unsigned int *data)
56af390d
ZW
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
177COMEDI_INITCLEANUP(driver_aio_iiro_16);