2 comedi/drivers/comedi_parport.c
3 hardware driver for standard parallel port
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1998,2001 David A. Schleef <ds@schleef.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 Driver: comedi_parport
25 Description: Standard PC parallel port
27 Status: works in immediate mode
28 Devices: [standard] parallel port (comedi_parport)
29 Updated: Tue, 30 Apr 2002 21:11:45 -0700
31 A cheap and easy way to get a few more digital I/O lines. Steal
32 additional parallel ports from old computers or your neighbors'
36 0: I/O port base for the parallel port.
55 13 1 1 printer selected
64 Subdevices 0 is digital I/O, subdevice 1 is digital input, and
65 subdevice 2 is digital output. Unlike other Comedi devices,
66 subdevice 0 defaults to output.
68 Pins 13 and 14 are inverted once by Comedi and once by the
69 hardware, thus cancelling the effect.
71 Pin 1 is a strobe, thus acts like one. There's no way in software
72 to change this, at least on a standard parallel port.
74 Subdevice 3 pretends to be a digital input subdevice, but it always
75 returns 0 when read. However, if you run a command with
76 scan_begin_src=TRIG_EXT, it uses pin 10 as a external triggering
77 pin, which can be used to wake up tasks.
80 see http://www.beyondlogic.org/ for information.
81 or http://www.linux-magazin.de/ausgabe/1999/10/IO/io.html
84 #include "../comedidev.h"
85 #include <linux/ioport.h>
87 #define PARPORT_SIZE 3
93 static int parport_attach(comedi_device
*dev
, comedi_devconfig
*it
);
94 static int parport_detach(comedi_device
*dev
);
95 static comedi_driver driver_parport
= {
96 .driver_name
= "comedi_parport",
97 .module
= THIS_MODULE
,
98 .attach
= parport_attach
,
99 .detach
= parport_detach
,
102 COMEDI_INITCLEANUP(driver_parport
);
104 struct parport_private
{
109 #define devpriv ((struct parport_private *)(dev->private))
111 static int parport_insn_a(comedi_device
*dev
, comedi_subdevice
*s
,
112 comedi_insn
*insn
, lsampl_t
*data
)
115 devpriv
->a_data
&= ~data
[0];
116 devpriv
->a_data
|= (data
[0] & data
[1]);
118 outb(devpriv
->a_data
, dev
->iobase
+ PARPORT_A
);
121 data
[1] = inb(dev
->iobase
+ PARPORT_A
);
126 static int parport_insn_config_a(comedi_device
*dev
, comedi_subdevice
*s
,
127 comedi_insn
*insn
, lsampl_t
*data
)
131 devpriv
->c_data
&= ~(1 << 5);
134 devpriv
->c_data
|= (1 << 5);
136 outb(devpriv
->c_data
, dev
->iobase
+ PARPORT_C
);
141 static int parport_insn_b(comedi_device
*dev
, comedi_subdevice
*s
,
142 comedi_insn
*insn
, lsampl_t
*data
)
145 /* should writes be ignored? */
149 data
[1] = (inb(dev
->iobase
+ PARPORT_B
) >> 3);
154 static int parport_insn_c(comedi_device
*dev
, comedi_subdevice
*s
,
155 comedi_insn
*insn
, lsampl_t
*data
)
159 devpriv
->c_data
&= ~data
[0];
160 devpriv
->c_data
|= (data
[0] & data
[1]);
162 outb(devpriv
->c_data
, dev
->iobase
+ PARPORT_C
);
165 data
[1] = devpriv
->c_data
& 0xf;
170 static int parport_intr_insn(comedi_device
*dev
, comedi_subdevice
*s
,
171 comedi_insn
*insn
, lsampl_t
*data
)
180 static int parport_intr_cmdtest(comedi_device
*dev
, comedi_subdevice
*s
,
188 tmp
= cmd
->start_src
;
189 cmd
->start_src
&= TRIG_NOW
;
190 if (!cmd
->start_src
|| tmp
!= cmd
->start_src
)
193 tmp
= cmd
->scan_begin_src
;
194 cmd
->scan_begin_src
&= TRIG_EXT
;
195 if (!cmd
->scan_begin_src
|| tmp
!= cmd
->scan_begin_src
)
198 tmp
= cmd
->convert_src
;
199 cmd
->convert_src
&= TRIG_FOLLOW
;
200 if (!cmd
->convert_src
|| tmp
!= cmd
->convert_src
)
203 tmp
= cmd
->scan_end_src
;
204 cmd
->scan_end_src
&= TRIG_COUNT
;
205 if (!cmd
->scan_end_src
|| tmp
!= cmd
->scan_end_src
)
209 cmd
->stop_src
&= TRIG_NONE
;
210 if (!cmd
->stop_src
|| tmp
!= cmd
->stop_src
)
216 /* step 2: ignored */
223 if (cmd
->start_arg
!= 0) {
227 if (cmd
->scan_begin_arg
!= 0) {
228 cmd
->scan_begin_arg
= 0;
231 if (cmd
->convert_arg
!= 0) {
232 cmd
->convert_arg
= 0;
235 if (cmd
->scan_end_arg
!= 1) {
236 cmd
->scan_end_arg
= 1;
239 if (cmd
->stop_arg
!= 0) {
247 /* step 4: ignored */
255 static int parport_intr_cmd(comedi_device
*dev
, comedi_subdevice
*s
)
257 devpriv
->c_data
|= 0x10;
258 outb(devpriv
->c_data
, dev
->iobase
+ PARPORT_C
);
260 devpriv
->enable_irq
= 1;
265 static int parport_intr_cancel(comedi_device
*dev
, comedi_subdevice
*s
)
267 printk(KERN_DEBUG
"parport_intr_cancel()\n");
269 devpriv
->c_data
&= ~0x10;
270 outb(devpriv
->c_data
, dev
->iobase
+ PARPORT_C
);
272 devpriv
->enable_irq
= 0;
277 static irqreturn_t
parport_interrupt(int irq
, void *d PT_REGS_ARG
)
279 comedi_device
*dev
= d
;
280 comedi_subdevice
*s
= dev
->subdevices
+ 3;
282 if (!devpriv
->enable_irq
) {
283 printk(KERN_ERR
"comedi_parport: bogus irq, ignored\n");
287 comedi_buf_put(s
->async
, 0);
288 s
->async
->events
|= COMEDI_CB_BLOCK
| COMEDI_CB_EOS
;
290 comedi_event(dev
, s
);
294 static int parport_attach(comedi_device
*dev
, comedi_devconfig
*it
)
298 unsigned long iobase
;
301 iobase
= it
->options
[0];
302 printk(KERN_INFO
"comedi%d: parport: 0x%04lx ", dev
->minor
, iobase
);
303 if (!request_region(iobase
, PARPORT_SIZE
, "parport (comedi)")) {
304 printk("I/O port conflict\n");
307 dev
->iobase
= iobase
;
309 irq
= it
->options
[1];
311 printk(" irq=%u", irq
);
312 ret
= comedi_request_irq(irq
, parport_interrupt
, 0,
313 "comedi_parport", dev
);
315 printk(" irq not available\n");
320 dev
->board_name
= "parport";
322 ret
= alloc_subdevices(dev
, 4);
325 ret
= alloc_private(dev
, sizeof(struct parport_private
));
329 s
= dev
->subdevices
+ 0;
330 s
->type
= COMEDI_SUBD_DIO
;
331 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
;
334 s
->range_table
= &range_digital
;
335 s
->insn_bits
= parport_insn_a
;
336 s
->insn_config
= parport_insn_config_a
;
338 s
= dev
->subdevices
+ 1;
339 s
->type
= COMEDI_SUBD_DI
;
340 s
->subdev_flags
= SDF_READABLE
;
343 s
->range_table
= &range_digital
;
344 s
->insn_bits
= parport_insn_b
;
346 s
= dev
->subdevices
+ 2;
347 s
->type
= COMEDI_SUBD_DO
;
348 s
->subdev_flags
= SDF_WRITABLE
;
351 s
->range_table
= &range_digital
;
352 s
->insn_bits
= parport_insn_c
;
354 s
= dev
->subdevices
+ 3;
356 dev
->read_subdev
= s
;
357 s
->type
= COMEDI_SUBD_DI
;
358 s
->subdev_flags
= SDF_READABLE
| SDF_CMD_READ
;
361 s
->range_table
= &range_digital
;
362 s
->insn_bits
= parport_intr_insn
;
363 s
->do_cmdtest
= parport_intr_cmdtest
;
364 s
->do_cmd
= parport_intr_cmd
;
365 s
->cancel
= parport_intr_cancel
;
367 s
->type
= COMEDI_SUBD_UNUSED
;
371 outb(devpriv
->a_data
, dev
->iobase
+ PARPORT_A
);
373 outb(devpriv
->c_data
, dev
->iobase
+ PARPORT_C
);
379 static int parport_detach(comedi_device
*dev
)
381 printk("comedi%d: parport: remove\n", dev
->minor
);
384 release_region(dev
->iobase
, PARPORT_SIZE
);
387 comedi_free_irq(dev
->irq
, dev
);