2 comedi/drivers/amplc_dio200.c
4 Driver for Amplicon PC212E, PC214E, PC215E, PC218E, PC272E.
6 Copyright (C) 2005-2013 MEV Ltd. <http://www.mev.co.uk/>
8 COMEDI - Linux Control and Measurement Device Interface
9 Copyright (C) 1998,2000 David A. Schleef <ds@schleef.org>
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * Driver: amplc_dio200
28 * Description: Amplicon 200 Series ISA Digital I/O
29 * Author: Ian Abbott <abbotti@mev.co.uk>
30 * Devices: [Amplicon] PC212E (pc212e), PC214E (pc214e), PC215E (pc215e),
31 * PC218E (pc218e), PC272E (pc272e)
32 * Updated: Mon, 18 Mar 2013 14:40:41 +0000
36 * Configuration options:
37 * [0] - I/O port base address
38 * [1] - IRQ (optional, but commands won't work without it)
40 * Passing a zero for an option is the same as leaving it unspecified.
44 * PC212E PC214E PC215E
45 * ------------- ------------- -------------
48 * 1 CTR-Y1 PPI-Y PPI-Y
49 * 2 CTR-Y2 CTR-Z1* CTR-Z1
50 * 3 CTR-Z1 INTERRUPT* CTR-Z2
55 * ------------- -------------
65 * Each PPI is a 8255 chip providing 24 DIO channels. The DIO channels
66 * are configurable as inputs or outputs in four groups:
68 * Port A - channels 0 to 7
69 * Port B - channels 8 to 15
70 * Port CL - channels 16 to 19
71 * Port CH - channels 20 to 23
73 * Only mode 0 of the 8255 chips is supported.
75 * Each CTR is a 8254 chip providing 3 16-bit counter channels. Each
76 * channel is configured individually with INSN_CONFIG instructions. The
77 * specific type of configuration instruction is specified in data[0].
78 * Some configuration instructions expect an additional parameter in
79 * data[1]; others return a value in data[1]. The following configuration
80 * instructions are supported:
82 * INSN_CONFIG_SET_COUNTER_MODE. Sets the counter channel's mode and
83 * BCD/binary setting specified in data[1].
85 * INSN_CONFIG_8254_READ_STATUS. Reads the status register value for the
86 * counter channel into data[1].
88 * INSN_CONFIG_SET_CLOCK_SRC. Sets the counter channel's clock source as
89 * specified in data[1] (this is a hardware-specific value). Not
90 * supported on PC214E. For the other boards, valid clock sources are
93 * 0. CLK n, the counter channel's dedicated CLK input from the SK1
94 * connector. (N.B. for other values, the counter channel's CLKn
95 * pin on the SK1 connector is an output!)
96 * 1. Internal 10 MHz clock.
97 * 2. Internal 1 MHz clock.
98 * 3. Internal 100 kHz clock.
99 * 4. Internal 10 kHz clock.
100 * 5. Internal 1 kHz clock.
101 * 6. OUT n-1, the output of counter channel n-1 (see note 1 below).
102 * 7. Ext Clock, the counter chip's dedicated Ext Clock input from
103 * the SK1 connector. This pin is shared by all three counter
104 * channels on the chip.
106 * INSN_CONFIG_GET_CLOCK_SRC. Returns the counter channel's current
107 * clock source in data[1]. For internal clock sources, data[2] is set
108 * to the period in ns.
110 * INSN_CONFIG_SET_GATE_SRC. Sets the counter channel's gate source as
111 * specified in data[2] (this is a hardware-specific value). Not
112 * supported on PC214E. For the other boards, valid gate sources are 0
115 * 0. VCC (internal +5V d.c.), i.e. gate permanently enabled.
116 * 1. GND (internal 0V d.c.), i.e. gate permanently disabled.
117 * 2. GAT n, the counter channel's dedicated GAT input from the SK1
118 * connector. (N.B. for other values, the counter channel's GATn
119 * pin on the SK1 connector is an output!)
120 * 3. /OUT n-2, the inverted output of counter channel n-2 (see note
127 * INSN_CONFIG_GET_GATE_SRC. Returns the counter channel's current gate
130 * Clock and gate interconnection notes:
132 * 1. Clock source OUT n-1 is the output of the preceding channel on the
133 * same counter subdevice if n > 0, or the output of channel 2 on the
134 * preceding counter subdevice (see note 3) if n = 0.
136 * 2. Gate source /OUT n-2 is the inverted output of channel 0 on the
137 * same counter subdevice if n = 2, or the inverted output of channel n+1
138 * on the preceding counter subdevice (see note 3) if n < 2.
140 * 3. The counter subdevices are connected in a ring, so the highest
141 * counter subdevice precedes the lowest.
143 * The 'INTERRUPT' subdevice pretends to be a digital input subdevice. The
144 * digital inputs come from the interrupt status register. The number of
145 * channels matches the number of interrupt sources. The PC214E does not
146 * have an interrupt status register; see notes on 'INTERRUPT SOURCES'
151 * PC212E PC214E PC215E
152 * ------------- ------------- -------------
154 * 0 PPI-X-C0 JUMPER-J5 PPI-X-C0
155 * 1 PPI-X-C3 PPI-X-C3
156 * 2 CTR-Y1-OUT1 PPI-Y-C0
157 * 3 CTR-Y2-OUT1 PPI-Y-C3
158 * 4 CTR-Z1-OUT1 CTR-Z1-OUT1
159 * 5 CTR-Z2-OUT1 CTR-Z2-OUT1
162 * ------------- -------------
164 * 0 CTR-X1-OUT1 PPI-X-C0
165 * 1 CTR-X2-OUT1 PPI-X-C3
166 * 2 CTR-Y1-OUT1 PPI-Y-C0
167 * 3 CTR-Y2-OUT1 PPI-Y-C3
168 * 4 CTR-Z1-OUT1 PPI-Z-C0
169 * 5 CTR-Z2-OUT1 PPI-Z-C3
171 * When an interrupt source is enabled in the interrupt source enable
172 * register, a rising edge on the source signal latches the corresponding
173 * bit to 1 in the interrupt status register.
175 * When the interrupt status register value as a whole (actually, just the
176 * 6 least significant bits) goes from zero to non-zero, the board will
177 * generate an interrupt. No further interrupts will occur until the
178 * interrupt status register is cleared to zero. To clear a bit to zero in
179 * the interrupt status register, the corresponding interrupt source must
180 * be disabled in the interrupt source enable register (there is no
181 * separate interrupt clear register).
183 * The PC214E does not have an interrupt source enable register or an
184 * interrupt status register; its 'INTERRUPT' subdevice has a single
185 * channel and its interrupt source is selected by the position of jumper
190 * The driver supports a read streaming acquisition command on the
191 * 'INTERRUPT' subdevice. The channel list selects the interrupt sources
192 * to be enabled. All channels will be sampled together (convert_src ==
193 * TRIG_NOW). The scan begins a short time after the hardware interrupt
194 * occurs, subject to interrupt latencies (scan_begin_src == TRIG_EXT,
195 * scan_begin_arg == 0). The value read from the interrupt status register
196 * is packed into a short value, one bit per requested channel, in the
197 * order they appear in the channel list.
200 #include <linux/slab.h>
202 #include "../comedidev.h"
204 #include "amplc_dio200.h"
207 * Board descriptions.
209 static const struct dio200_board dio200_isa_boards[] = {
212 .bustype = isa_bustype,
213 .mainsize = DIO200_IO_SIZE,
216 .sdtype = {sd_8255, sd_8254, sd_8254, sd_8254, sd_8254,
218 .sdinfo = {0x00, 0x08, 0x0C, 0x10, 0x14, 0x3F},
220 .has_clk_gat_sce = true,
225 .bustype = isa_bustype,
226 .mainsize = DIO200_IO_SIZE,
229 .sdtype = {sd_8255, sd_8255, sd_8254, sd_intr},
230 .sdinfo = {0x00, 0x08, 0x10, 0x01},
235 .bustype = isa_bustype,
236 .mainsize = DIO200_IO_SIZE,
239 .sdtype = {sd_8255, sd_8255, sd_8254, sd_8254, sd_intr},
240 .sdinfo = {0x00, 0x08, 0x10, 0x14, 0x3F},
242 .has_clk_gat_sce = true,
247 .bustype = isa_bustype,
248 .mainsize = DIO200_IO_SIZE,
251 .sdtype = {sd_8254, sd_8254, sd_8255, sd_8254, sd_8254,
253 .sdinfo = {0x00, 0x04, 0x08, 0x0C, 0x10, 0x14, 0x3F},
255 .has_clk_gat_sce = true,
260 .bustype = isa_bustype,
261 .mainsize = DIO200_IO_SIZE,
264 .sdtype = {sd_8255, sd_8255, sd_8255, sd_intr},
265 .sdinfo = {0x00, 0x08, 0x10, 0x3F},
271 static int dio200_attach(struct comedi_device *dev, struct comedi_devconfig *it)
273 const struct dio200_board *thisboard = comedi_board(dev);
274 struct dio200_private *devpriv;
278 irq = it->options[1];
280 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
283 dev->private = devpriv;
285 ret = comedi_request_region(dev, it->options[0], thisboard->mainsize);
288 devpriv->io.u.iobase = dev->iobase;
289 devpriv->io.regtype = io_regtype;
290 return amplc_dio200_common_attach(dev, irq, 0);
293 static void dio200_detach(struct comedi_device *dev)
295 amplc_dio200_common_detach(dev);
296 comedi_legacy_detach(dev);
299 static struct comedi_driver amplc_dio200_driver = {
300 .driver_name = "amplc_dio200",
301 .module = THIS_MODULE,
302 .attach = dio200_attach,
303 .detach = dio200_detach,
304 .board_name = &dio200_isa_boards[0].name,
305 .offset = sizeof(struct dio200_board),
306 .num_names = ARRAY_SIZE(dio200_isa_boards),
308 module_comedi_driver(amplc_dio200_driver);
310 MODULE_AUTHOR("Comedi http://www.comedi.org");
311 MODULE_DESCRIPTION("Comedi driver for Amplicon 200 Series ISA DIO boards");
312 MODULE_LICENSE("GPL");