Merge tag 'spi-v4.0-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
[linux-2.6-block.git] / drivers / staging / comedi / drivers / amplc_pc263.c
CommitLineData
cfd02b71
IA
1/*
2 comedi/drivers/amplc_pc263.c
3 Driver for Amplicon PC263 and PCI263 relay boards.
4
5 Copyright (C) 2002 MEV Ltd. <http://www.mev.co.uk/>
6
7 COMEDI - Linux Control and Measurement Device Interface
8 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
9
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.
14
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.
cfd02b71
IA
19*/
20/*
21Driver: amplc_pc263
22691aec 22Description: Amplicon PC263
cfd02b71 23Author: Ian Abbott <abbotti@mev.co.uk>
22691aec
IA
24Devices: [Amplicon] PC263 (pc263)
25Updated: Fri, 12 Apr 2013 15:19:36 +0100
cfd02b71
IA
26Status: works
27
22691aec 28Configuration options:
cfd02b71
IA
29 [0] - I/O port base address
30
22691aec 31The board appears as one subdevice, with 16 digital outputs, each
cfd02b71
IA
32connected to a reed-relay. Relay contacts are closed when output is 1.
33The state of the outputs can be read.
34*/
35
ce157f80 36#include <linux/module.h>
cfd02b71
IA
37#include "../comedidev.h"
38
22691aec 39/* PC263 registers */
cfd02b71
IA
40
41/*
22691aec 42 * Board descriptions for Amplicon PC263.
cfd02b71
IA
43 */
44
4beb86c2 45struct pc263_board {
cfd02b71 46 const char *name;
4beb86c2 47};
22691aec 48
4beb86c2 49static const struct pc263_board pc263_boards[] = {
cfd02b71 50 {
b4843c19 51 .name = "pc263",
b4843c19 52 },
cfd02b71
IA
53};
54
ba7914cd
IA
55static int pc263_do_insn_bits(struct comedi_device *dev,
56 struct comedi_subdevice *s,
97f4289a
HS
57 struct comedi_insn *insn,
58 unsigned int *data)
ba7914cd 59{
97f4289a
HS
60 if (comedi_dio_update_state(s, data)) {
61 outb(s->state & 0xff, dev->iobase);
62 outb((s->state >> 8) & 0xff, dev->iobase + 1);
ba7914cd 63 }
97f4289a
HS
64
65 data[1] = s->state;
66
a2714e3e 67 return insn->n;
ba7914cd 68}
cfd02b71 69
22691aec 70static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
d8967b6e 71{
d8967b6e
IA
72 struct comedi_subdevice *s;
73 int ret;
74
862755ec 75 ret = comedi_request_region(dev, it->options[0], 0x2);
22691aec
IA
76 if (ret)
77 return ret;
d8967b6e 78
2f0b9d08 79 ret = comedi_alloc_subdevices(dev, 1);
8b6c5694 80 if (ret)
d8967b6e 81 return ret;
d8967b6e 82
d8029dcf 83 s = &dev->subdevices[0];
d8967b6e
IA
84 /* digital output subdevice */
85 s->type = COMEDI_SUBD_DO;
453fd2b3 86 s->subdev_flags = SDF_WRITABLE;
d8967b6e
IA
87 s->n_chan = 16;
88 s->maxdata = 1;
89 s->range_table = &range_digital;
90 s->insn_bits = pc263_do_insn_bits;
91 /* read initial relay state */
92 s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8);
93
22691aec 94 return 0;
cfd02b71
IA
95}
96
ba7914cd 97static struct comedi_driver amplc_pc263_driver = {
3d03cfca 98 .driver_name = "amplc_pc263",
ba7914cd
IA
99 .module = THIS_MODULE,
100 .attach = pc263_attach,
21208519 101 .detach = comedi_legacy_detach,
ba7914cd
IA
102 .board_name = &pc263_boards[0].name,
103 .offset = sizeof(struct pc263_board),
104 .num_names = ARRAY_SIZE(pc263_boards),
105};
cfd02b71 106
40372f5f 107module_comedi_driver(amplc_pc263_driver);
90f703d3
AT
108
109MODULE_AUTHOR("Comedi http://www.comedi.org");
22691aec 110MODULE_DESCRIPTION("Comedi driver for Amplicon PC263 relay board");
90f703d3 111MODULE_LICENSE("GPL");