3 * Comedi driver for standard parallel port
5 * For more information see:
6 * http://retired.beyondlogic.org/spp/parallel.htm
8 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1998,2001 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.
23 * Driver: comedi_parport
24 * Description: Standard PC parallel port
26 * Status: works in immediate mode
27 * Devices: [standard] parallel port (comedi_parport)
28 * Updated: Tue, 30 Apr 2002 21:11:45 -0700
30 * A cheap and easy way to get a few more digital I/O lines. Steal
31 * additional parallel ports from old computers or your neighbors'
35 * 0: I/O port base for the parallel port.
38 * Parallel Port Lines:
40 * pin subdev chan type name
41 * ----- ------ ---- ---- --------------
58 * 17 2 3 DO select printer
61 * When an IRQ is configured subdevice 3 pretends to be a digital
62 * input subdevice, but it always returns 0 when read. However, if
63 * you run a command with scan_begin_src=TRIG_EXT, it uses pin 10
64 * as a external trigger, which can be used to wake up tasks.
67 #include <linux/module.h>
68 #include <linux/interrupt.h>
70 #include "../comedidev.h"
75 #define PARPORT_DATA_REG 0x00
76 #define PARPORT_STATUS_REG 0x01
77 #define PARPORT_CTRL_REG 0x02
78 #define PARPORT_CTRL_IRQ_ENA (1 << 4)
79 #define PARPORT_CTRL_BIDIR_ENA (1 << 5)
81 static int parport_data_reg_insn_bits(struct comedi_device *dev,
82 struct comedi_subdevice *s,
83 struct comedi_insn *insn,
86 if (comedi_dio_update_state(s, data))
87 outb(s->state, dev->iobase + PARPORT_DATA_REG);
89 data[1] = inb(dev->iobase + PARPORT_DATA_REG);
94 static int parport_data_reg_insn_config(struct comedi_device *dev,
95 struct comedi_subdevice *s,
96 struct comedi_insn *insn,
102 ret = comedi_dio_insn_config(dev, s, insn, data, 0xff);
106 ctrl = inb(dev->iobase + PARPORT_CTRL_REG);
108 ctrl &= ~PARPORT_CTRL_BIDIR_ENA;
110 ctrl |= PARPORT_CTRL_BIDIR_ENA;
111 outb(ctrl, dev->iobase + PARPORT_CTRL_REG);
116 static int parport_status_reg_insn_bits(struct comedi_device *dev,
117 struct comedi_subdevice *s,
118 struct comedi_insn *insn,
121 data[1] = inb(dev->iobase + PARPORT_STATUS_REG) >> 3;
126 static int parport_ctrl_reg_insn_bits(struct comedi_device *dev,
127 struct comedi_subdevice *s,
128 struct comedi_insn *insn,
133 if (comedi_dio_update_state(s, data)) {
134 ctrl = inb(dev->iobase + PARPORT_CTRL_REG);
135 ctrl &= (PARPORT_CTRL_IRQ_ENA | PARPORT_CTRL_BIDIR_ENA);
137 outb(ctrl, dev->iobase + PARPORT_CTRL_REG);
145 static int parport_intr_insn_bits(struct comedi_device *dev,
146 struct comedi_subdevice *s,
147 struct comedi_insn *insn,
154 static int parport_intr_cmdtest(struct comedi_device *dev,
155 struct comedi_subdevice *s,
156 struct comedi_cmd *cmd)
160 /* Step 1 : check if triggers are trivially valid */
162 err |= comedi_check_trigger_src(&cmd->start_src, TRIG_NOW);
163 err |= comedi_check_trigger_src(&cmd->scan_begin_src, TRIG_EXT);
164 err |= comedi_check_trigger_src(&cmd->convert_src, TRIG_FOLLOW);
165 err |= comedi_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
166 err |= comedi_check_trigger_src(&cmd->stop_src, TRIG_NONE);
171 /* Step 2a : make sure trigger sources are unique */
172 /* Step 2b : and mutually compatible */
174 /* Step 3: check if arguments are trivially valid */
176 err |= comedi_check_trigger_arg_is(&cmd->start_arg, 0);
177 err |= comedi_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
178 err |= comedi_check_trigger_arg_is(&cmd->convert_arg, 0);
179 err |= comedi_check_trigger_arg_is(&cmd->scan_end_arg,
181 err |= comedi_check_trigger_arg_is(&cmd->stop_arg, 0);
186 /* Step 4: fix up any arguments */
188 /* Step 5: check channel list if it exists */
193 static int parport_intr_cmd(struct comedi_device *dev,
194 struct comedi_subdevice *s)
198 ctrl = inb(dev->iobase + PARPORT_CTRL_REG);
199 ctrl |= PARPORT_CTRL_IRQ_ENA;
200 outb(ctrl, dev->iobase + PARPORT_CTRL_REG);
205 static int parport_intr_cancel(struct comedi_device *dev,
206 struct comedi_subdevice *s)
210 ctrl = inb(dev->iobase + PARPORT_CTRL_REG);
211 ctrl &= ~PARPORT_CTRL_IRQ_ENA;
212 outb(ctrl, dev->iobase + PARPORT_CTRL_REG);
217 static irqreturn_t parport_interrupt(int irq, void *d)
219 struct comedi_device *dev = d;
220 struct comedi_subdevice *s = dev->read_subdev;
223 ctrl = inb(dev->iobase + PARPORT_CTRL_REG);
224 if (!(ctrl & PARPORT_CTRL_IRQ_ENA))
227 comedi_buf_write_samples(s, &s->state, 1);
228 comedi_handle_events(dev, s);
233 static int parport_attach(struct comedi_device *dev,
234 struct comedi_devconfig *it)
236 struct comedi_subdevice *s;
239 ret = comedi_request_region(dev, it->options[0], 0x03);
243 if (it->options[1]) {
244 ret = request_irq(it->options[1], parport_interrupt, 0,
245 dev->board_name, dev);
247 dev->irq = it->options[1];
250 ret = comedi_alloc_subdevices(dev, dev->irq ? 4 : 3);
254 /* Digial I/O subdevice - Parallel port DATA register */
255 s = &dev->subdevices[0];
256 s->type = COMEDI_SUBD_DIO;
257 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
260 s->range_table = &range_digital;
261 s->insn_bits = parport_data_reg_insn_bits;
262 s->insn_config = parport_data_reg_insn_config;
264 /* Digial Input subdevice - Parallel port STATUS register */
265 s = &dev->subdevices[1];
266 s->type = COMEDI_SUBD_DI;
267 s->subdev_flags = SDF_READABLE;
270 s->range_table = &range_digital;
271 s->insn_bits = parport_status_reg_insn_bits;
273 /* Digial Output subdevice - Parallel port CONTROL register */
274 s = &dev->subdevices[2];
275 s->type = COMEDI_SUBD_DO;
276 s->subdev_flags = SDF_WRITABLE;
279 s->range_table = &range_digital;
280 s->insn_bits = parport_ctrl_reg_insn_bits;
283 /* Digial Input subdevice - Interrupt support */
284 s = &dev->subdevices[3];
285 dev->read_subdev = s;
286 s->type = COMEDI_SUBD_DI;
287 s->subdev_flags = SDF_READABLE | SDF_CMD_READ;
290 s->range_table = &range_digital;
291 s->insn_bits = parport_intr_insn_bits;
293 s->do_cmdtest = parport_intr_cmdtest;
294 s->do_cmd = parport_intr_cmd;
295 s->cancel = parport_intr_cancel;
298 outb(0, dev->iobase + PARPORT_DATA_REG);
299 outb(0, dev->iobase + PARPORT_CTRL_REG);
304 static struct comedi_driver parport_driver = {
305 .driver_name = "comedi_parport",
306 .module = THIS_MODULE,
307 .attach = parport_attach,
308 .detach = comedi_legacy_detach,
310 module_comedi_driver(parport_driver);
312 MODULE_AUTHOR("Comedi http://www.comedi.org");
313 MODULE_DESCRIPTION("Comedi: Standard parallel port driver");
314 MODULE_LICENSE("GPL");