Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
aio_iiro_16.c
Go to the documentation of this file.
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 <[email protected]>
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 
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 static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
61  struct comedi_subdevice *s,
62  struct comedi_insn *insn,
63  unsigned int *data)
64 {
65  if (data[0]) {
66  s->state &= ~data[0];
67  s->state |= data[0] & data[1];
68  outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
69  outb((s->state >> 8) & 0xff,
71  }
72 
73  data[1] = s->state;
74 
75  return insn->n;
76 }
77 
78 static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,
79  struct comedi_subdevice *s,
80  struct comedi_insn *insn,
81  unsigned int *data)
82 {
83  data[1] = 0;
84  data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
85  data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
86 
87  return insn->n;
88 }
89 
90 static int aio_iiro_16_attach(struct comedi_device *dev,
91  struct comedi_devconfig *it)
92 {
93  const struct aio_iiro_16_board *board = comedi_board(dev);
94  int iobase;
95  struct comedi_subdevice *s;
96  int ret;
97 
98  printk(KERN_INFO "comedi%d: aio_iiro_16: ", dev->minor);
99 
100  dev->board_name = board->name;
101 
102  iobase = it->options[0];
103 
104  if (!request_region(iobase, AIO_IIRO_16_SIZE, dev->board_name)) {
105  printk("I/O port conflict");
106  return -EIO;
107  }
108 
109  dev->iobase = iobase;
110 
111  ret = comedi_alloc_subdevices(dev, 2);
112  if (ret)
113  return ret;
114 
115  s = &dev->subdevices[0];
116  s->type = COMEDI_SUBD_DIO;
118  s->n_chan = 16;
119  s->maxdata = 1;
121  s->insn_bits = aio_iiro_16_dio_insn_bits_write;
122 
123  s = &dev->subdevices[1];
124  s->type = COMEDI_SUBD_DIO;
126  s->n_chan = 16;
127  s->maxdata = 1;
129  s->insn_bits = aio_iiro_16_dio_insn_bits_read;
130 
131  printk("attached\n");
132 
133  return 1;
134 }
135 
136 static void aio_iiro_16_detach(struct comedi_device *dev)
137 {
138  if (dev->iobase)
140 }
141 
142 static struct comedi_driver aio_iiro_16_driver = {
143  .driver_name = "aio_iiro_16",
144  .module = THIS_MODULE,
145  .attach = aio_iiro_16_attach,
146  .detach = aio_iiro_16_detach,
147  .board_name = &aio_iiro_16_boards[0].name,
148  .offset = sizeof(struct aio_iiro_16_board),
149  .num_names = ARRAY_SIZE(aio_iiro_16_boards),
150 };
151 module_comedi_driver(aio_iiro_16_driver);
152 
153 MODULE_AUTHOR("Comedi http://www.comedi.org");
154 MODULE_DESCRIPTION("Comedi low-level driver");
155 MODULE_LICENSE("GPL");