[go: nahoru, domu]

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
21Driver: aio_iiro_16
22Description: Access I/O Products PC-104 IIRO16 Relay And Isolated Input Board
23Author: Zachary Ware <zach.ware@cctechnol.com>
24Devices:
25 [Access I/O] PC-104 AIO12-8
26Status: experimental
27
28Configuration 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_RELAY_0_7	0x00
37#define AIO_IIRO_16_INPUT_0_7	0x01
38#define AIO_IIRO_16_IRQ		0x02
39#define AIO_IIRO_16_RELAY_8_15	0x04
40#define AIO_IIRO_16_INPUT_8_15	0x05
41
42static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
43					   struct comedi_subdevice *s,
44					   struct comedi_insn *insn,
45					   unsigned int *data)
46{
47	if (comedi_dio_update_state(s, data)) {
48		outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
49		outb((s->state >> 8) & 0xff,
50		     dev->iobase + AIO_IIRO_16_RELAY_8_15);
51	}
52
53	data[1] = s->state;
54
55	return insn->n;
56}
57
58static int aio_iiro_16_dio_insn_bits_read(struct comedi_device *dev,
59					  struct comedi_subdevice *s,
60					  struct comedi_insn *insn,
61					  unsigned int *data)
62{
63	data[1] = 0;
64	data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
65	data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
66
67	return insn->n;
68}
69
70static int aio_iiro_16_attach(struct comedi_device *dev,
71			      struct comedi_devconfig *it)
72{
73	struct comedi_subdevice *s;
74	int ret;
75
76	ret = comedi_request_region(dev, it->options[0], 0x8);
77	if (ret)
78		return ret;
79
80	ret = comedi_alloc_subdevices(dev, 2);
81	if (ret)
82		return ret;
83
84	s = &dev->subdevices[0];
85	s->type = COMEDI_SUBD_DIO;
86	s->subdev_flags = SDF_WRITABLE;
87	s->n_chan = 16;
88	s->maxdata = 1;
89	s->range_table = &range_digital;
90	s->insn_bits = aio_iiro_16_dio_insn_bits_write;
91
92	s = &dev->subdevices[1];
93	s->type = COMEDI_SUBD_DIO;
94	s->subdev_flags = SDF_READABLE;
95	s->n_chan = 16;
96	s->maxdata = 1;
97	s->range_table = &range_digital;
98	s->insn_bits = aio_iiro_16_dio_insn_bits_read;
99
100	return 0;
101}
102
103static struct comedi_driver aio_iiro_16_driver = {
104	.driver_name	= "aio_iiro_16",
105	.module		= THIS_MODULE,
106	.attach		= aio_iiro_16_attach,
107	.detach		= comedi_legacy_detach,
108};
109module_comedi_driver(aio_iiro_16_driver);
110
111MODULE_AUTHOR("Comedi http://www.comedi.org");
112MODULE_DESCRIPTION("Comedi low-level driver");
113MODULE_LICENSE("GPL");
114