Merge branch 'for-3.11' of git://linux-nfs.org/~bfields/linux
[linux-2.6.git] / drivers / staging / comedi / drivers / amplc_pc263.c
blob6546095e7a45bec5ed4ec54a78bbd8db36d01f88
1 /*
2 comedi/drivers/amplc_pc263.c
3 Driver for Amplicon PC263 and PCI263 relay boards.
5 Copyright (C) 2002 MEV Ltd. <http://www.mev.co.uk/>
7 COMEDI - Linux Control and Measurement Device Interface
8 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
21 Driver: amplc_pc263
22 Description: Amplicon PC263
23 Author: Ian Abbott <abbotti@mev.co.uk>
24 Devices: [Amplicon] PC263 (pc263)
25 Updated: Fri, 12 Apr 2013 15:19:36 +0100
26 Status: works
28 Configuration options:
29 [0] - I/O port base address
31 The board appears as one subdevice, with 16 digital outputs, each
32 connected to a reed-relay. Relay contacts are closed when output is 1.
33 The state of the outputs can be read.
36 #include "../comedidev.h"
38 #define PC263_DRIVER_NAME "amplc_pc263"
40 /* PC263 registers */
41 #define PC263_IO_SIZE 2
44 * Board descriptions for Amplicon PC263.
47 struct pc263_board {
48 const char *name;
51 static const struct pc263_board pc263_boards[] = {
53 .name = "pc263",
57 static int pc263_do_insn_bits(struct comedi_device *dev,
58 struct comedi_subdevice *s,
59 struct comedi_insn *insn, unsigned int *data)
61 /* The insn data is a mask in data[0] and the new data
62 * in data[1], each channel cooresponding to a bit. */
63 if (data[0]) {
64 s->state &= ~data[0];
65 s->state |= data[0] & data[1];
66 /* Write out the new digital output lines */
67 outb(s->state & 0xFF, dev->iobase);
68 outb(s->state >> 8, dev->iobase + 1);
70 return insn->n;
73 static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
75 struct comedi_subdevice *s;
76 int ret;
78 ret = comedi_request_region(dev, it->options[0], PC263_IO_SIZE);
79 if (ret)
80 return ret;
82 ret = comedi_alloc_subdevices(dev, 1);
83 if (ret)
84 return ret;
86 s = &dev->subdevices[0];
87 /* digital output subdevice */
88 s->type = COMEDI_SUBD_DO;
89 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
90 s->n_chan = 16;
91 s->maxdata = 1;
92 s->range_table = &range_digital;
93 s->insn_bits = pc263_do_insn_bits;
94 /* read initial relay state */
95 s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8);
97 dev_info(dev->class_dev, "%s (base %#lx) attached\n", dev->board_name,
98 dev->iobase);
99 return 0;
102 static struct comedi_driver amplc_pc263_driver = {
103 .driver_name = PC263_DRIVER_NAME,
104 .module = THIS_MODULE,
105 .attach = pc263_attach,
106 .detach = comedi_legacy_detach,
107 .board_name = &pc263_boards[0].name,
108 .offset = sizeof(struct pc263_board),
109 .num_names = ARRAY_SIZE(pc263_boards),
112 module_comedi_driver(amplc_pc263_driver);
114 MODULE_AUTHOR("Comedi http://www.comedi.org");
115 MODULE_DESCRIPTION("Comedi driver for Amplicon PC263 relay board");
116 MODULE_LICENSE("GPL");