]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/staging/comedi/drivers/amplc_pc263.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[mirror_ubuntu-hirsute-kernel.git] / drivers / staging / comedi / drivers / amplc_pc263.c
CommitLineData
e184e2be 1// SPDX-License-Identifier: GPL-2.0+
cfd02b71 2/*
05380cde
HS
3 * Driver for Amplicon PC263 relay board.
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>
05380cde 9 */
cfd02b71 10
cfd02b71 11/*
05380cde
HS
12 * Driver: amplc_pc263
13 * Description: Amplicon PC263
14 * Author: Ian Abbott <abbotti@mev.co.uk>
15 * Devices: [Amplicon] PC263 (pc263)
16 * Updated: Fri, 12 Apr 2013 15:19:36 +0100
17 * Status: works
18 *
19 * Configuration options:
20 * [0] - I/O port base address
21 *
22 * The board appears as one subdevice, with 16 digital outputs, each
23 * connected to a reed-relay. Relay contacts are closed when output is 1.
24 * The state of the outputs can be read.
25 */
cfd02b71 26
ce157f80 27#include <linux/module.h>
cfd02b71
IA
28#include "../comedidev.h"
29
22691aec 30/* PC263 registers */
1b501671
HS
31#define PC263_DO_0_7_REG 0x00
32#define PC263_DO_8_15_REG 0x01
cfd02b71 33
4beb86c2 34struct pc263_board {
cfd02b71 35 const char *name;
4beb86c2 36};
22691aec 37
4beb86c2 38static const struct pc263_board pc263_boards[] = {
cfd02b71 39 {
b4843c19 40 .name = "pc263",
b4843c19 41 },
cfd02b71
IA
42};
43
ba7914cd
IA
44static int pc263_do_insn_bits(struct comedi_device *dev,
45 struct comedi_subdevice *s,
97f4289a
HS
46 struct comedi_insn *insn,
47 unsigned int *data)
ba7914cd 48{
97f4289a 49 if (comedi_dio_update_state(s, data)) {
1b501671
HS
50 outb(s->state & 0xff, dev->iobase + PC263_DO_0_7_REG);
51 outb((s->state >> 8) & 0xff, dev->iobase + PC263_DO_8_15_REG);
ba7914cd 52 }
97f4289a
HS
53
54 data[1] = s->state;
55
a2714e3e 56 return insn->n;
ba7914cd 57}
cfd02b71 58
22691aec 59static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
d8967b6e 60{
d8967b6e
IA
61 struct comedi_subdevice *s;
62 int ret;
63
862755ec 64 ret = comedi_request_region(dev, it->options[0], 0x2);
22691aec
IA
65 if (ret)
66 return ret;
d8967b6e 67
2f0b9d08 68 ret = comedi_alloc_subdevices(dev, 1);
8b6c5694 69 if (ret)
d8967b6e 70 return ret;
d8967b6e 71
9f37d399 72 /* Digital Output subdevice */
d8029dcf 73 s = &dev->subdevices[0];
9f37d399
HS
74 s->type = COMEDI_SUBD_DO;
75 s->subdev_flags = SDF_WRITABLE;
76 s->n_chan = 16;
77 s->maxdata = 1;
78 s->range_table = &range_digital;
79 s->insn_bits = pc263_do_insn_bits;
80
d8967b6e 81 /* read initial relay state */
1b501671
HS
82 s->state = inb(dev->iobase + PC263_DO_0_7_REG) |
83 (inb(dev->iobase + PC263_DO_8_15_REG) << 8);
d8967b6e 84
22691aec 85 return 0;
cfd02b71
IA
86}
87
ba7914cd 88static struct comedi_driver amplc_pc263_driver = {
d69917a6
HS
89 .driver_name = "amplc_pc263",
90 .module = THIS_MODULE,
91 .attach = pc263_attach,
92 .detach = comedi_legacy_detach,
93 .board_name = &pc263_boards[0].name,
94 .offset = sizeof(struct pc263_board),
95 .num_names = ARRAY_SIZE(pc263_boards),
ba7914cd 96};
cfd02b71 97
40372f5f 98module_comedi_driver(amplc_pc263_driver);
90f703d3
AT
99
100MODULE_AUTHOR("Comedi http://www.comedi.org");
22691aec 101MODULE_DESCRIPTION("Comedi driver for Amplicon PC263 relay board");
90f703d3 102MODULE_LICENSE("GPL");