1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* |
3 | * Driver for Amplicon PC263 relay board. |
4 | * |
5 | * Copyright (C) 2002 MEV Ltd. <https://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 | |
11 | /* |
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 | */ |
26 | |
27 | #include <linux/module.h> |
28 | #include <linux/comedi/comedidev.h> |
29 | |
30 | /* PC263 registers */ |
31 | #define PC263_DO_0_7_REG 0x00 |
32 | #define PC263_DO_8_15_REG 0x01 |
33 | |
34 | struct pc263_board { |
35 | const char *name; |
36 | }; |
37 | |
38 | static const struct pc263_board pc263_boards[] = { |
39 | { |
40 | .name = "pc263" , |
41 | }, |
42 | }; |
43 | |
44 | static int pc263_do_insn_bits(struct comedi_device *dev, |
45 | struct comedi_subdevice *s, |
46 | struct comedi_insn *insn, |
47 | unsigned int *data) |
48 | { |
49 | if (comedi_dio_update_state(s, data)) { |
50 | outb(value: s->state & 0xff, port: dev->iobase + PC263_DO_0_7_REG); |
51 | outb(value: (s->state >> 8) & 0xff, port: dev->iobase + PC263_DO_8_15_REG); |
52 | } |
53 | |
54 | data[1] = s->state; |
55 | |
56 | return insn->n; |
57 | } |
58 | |
59 | static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it) |
60 | { |
61 | struct comedi_subdevice *s; |
62 | int ret; |
63 | |
64 | ret = comedi_request_region(dev, start: it->options[0], len: 0x2); |
65 | if (ret) |
66 | return ret; |
67 | |
68 | ret = comedi_alloc_subdevices(dev, num_subdevices: 1); |
69 | if (ret) |
70 | return ret; |
71 | |
72 | /* Digital Output subdevice */ |
73 | s = &dev->subdevices[0]; |
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 | |
81 | /* read initial relay state */ |
82 | s->state = inb(port: dev->iobase + PC263_DO_0_7_REG) | |
83 | (inb(port: dev->iobase + PC263_DO_8_15_REG) << 8); |
84 | |
85 | return 0; |
86 | } |
87 | |
88 | static struct comedi_driver amplc_pc263_driver = { |
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), |
96 | }; |
97 | |
98 | module_comedi_driver(amplc_pc263_driver); |
99 | |
100 | MODULE_AUTHOR("Comedi https://www.comedi.org" ); |
101 | MODULE_DESCRIPTION("Comedi driver for Amplicon PC263 relay board" ); |
102 | MODULE_LICENSE("GPL" ); |
103 | |