Merge tag 'please-pull-pstore' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / comedi / drivers / amplc_pc263.c
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.
19
20     You should have received a copy of the GNU General Public License
21     along with this program; if not, write to the Free Software
22     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
24 */
25 /*
26 Driver: amplc_pc263
27 Description: Amplicon PC263
28 Author: Ian Abbott <abbotti@mev.co.uk>
29 Devices: [Amplicon] PC263 (pc263)
30 Updated: Fri, 12 Apr 2013 15:19:36 +0100
31 Status: works
32
33 Configuration options:
34   [0] - I/O port base address
35
36 The board appears as one subdevice, with 16 digital outputs, each
37 connected to a reed-relay. Relay contacts are closed when output is 1.
38 The state of the outputs can be read.
39 */
40
41 #include "../comedidev.h"
42
43 #define PC263_DRIVER_NAME       "amplc_pc263"
44
45 /* PC263 registers */
46 #define PC263_IO_SIZE   2
47
48 /*
49  * Board descriptions for Amplicon PC263.
50  */
51
52 struct pc263_board {
53         const char *name;
54 };
55
56 static const struct pc263_board pc263_boards[] = {
57         {
58                 .name = "pc263",
59         },
60 };
61
62 static int pc263_do_insn_bits(struct comedi_device *dev,
63                               struct comedi_subdevice *s,
64                               struct comedi_insn *insn, unsigned int *data)
65 {
66         /* The insn data is a mask in data[0] and the new data
67          * in data[1], each channel cooresponding to a bit. */
68         if (data[0]) {
69                 s->state &= ~data[0];
70                 s->state |= data[0] & data[1];
71                 /* Write out the new digital output lines */
72                 outb(s->state & 0xFF, dev->iobase);
73                 outb(s->state >> 8, dev->iobase + 1);
74         }
75         return insn->n;
76 }
77
78 static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
79 {
80         struct comedi_subdevice *s;
81         int ret;
82
83         ret = comedi_request_region(dev, it->options[0], PC263_IO_SIZE);
84         if (ret)
85                 return ret;
86
87         ret = comedi_alloc_subdevices(dev, 1);
88         if (ret)
89                 return ret;
90
91         s = &dev->subdevices[0];
92         /* digital output subdevice */
93         s->type = COMEDI_SUBD_DO;
94         s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
95         s->n_chan = 16;
96         s->maxdata = 1;
97         s->range_table = &range_digital;
98         s->insn_bits = pc263_do_insn_bits;
99         /* read initial relay state */
100         s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8);
101
102         dev_info(dev->class_dev, "%s (base %#lx) attached\n", dev->board_name,
103                  dev->iobase);
104         return 0;
105 }
106
107 static struct comedi_driver amplc_pc263_driver = {
108         .driver_name = PC263_DRIVER_NAME,
109         .module = THIS_MODULE,
110         .attach = pc263_attach,
111         .detach = comedi_legacy_detach,
112         .board_name = &pc263_boards[0].name,
113         .offset = sizeof(struct pc263_board),
114         .num_names = ARRAY_SIZE(pc263_boards),
115 };
116
117 module_comedi_driver(amplc_pc263_driver);
118
119 MODULE_AUTHOR("Comedi http://www.comedi.org");
120 MODULE_DESCRIPTION("Comedi driver for Amplicon PC263 relay board");
121 MODULE_LICENSE("GPL");