[ARM] 3035/1: RISCOS compat code fix
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / parport / ieee1284.c
blob5b887ba5aaf9e613c39939afd62c6f82febef660
1 /* $Id: parport_ieee1284.c,v 1.4 1997/10/19 21:37:21 philip Exp $
2 * IEEE-1284 implementation for parport.
4 * Authors: Phil Blundell <philb@gnu.org>
5 * Carsten Gross <carsten@sol.wohnheim.uni-ulm.de>
6 * Jose Renau <renau@acm.org>
7 * Tim Waugh <tim@cyberelk.demon.co.uk> (largely rewritten)
9 * This file is responsible for IEEE 1284 negotiation, and for handing
10 * read/write requests to low-level drivers.
12 * Any part of this program may be used in documents licensed under
13 * the GNU Free Documentation License, Version 1.1 or any later version
14 * published by the Free Software Foundation.
16 * Various hacks, Fred Barnes <frmb2@ukc.ac.uk>, 04/2000
19 #include <linux/config.h>
20 #include <linux/module.h>
21 #include <linux/threads.h>
22 #include <linux/parport.h>
23 #include <linux/delay.h>
24 #include <linux/kernel.h>
25 #include <linux/interrupt.h>
26 #include <linux/timer.h>
27 #include <linux/sched.h>
29 #undef DEBUG /* undef me for production */
31 #ifdef CONFIG_LP_CONSOLE
32 #undef DEBUG /* Don't want a garbled console */
33 #endif
35 #ifdef DEBUG
36 #define DPRINTK(stuff...) printk (stuff)
37 #else
38 #define DPRINTK(stuff...)
39 #endif
41 /* Make parport_wait_peripheral wake up.
42 * It will be useful to call this from an interrupt handler. */
43 static void parport_ieee1284_wakeup (struct parport *port)
45 up (&port->physport->ieee1284.irq);
48 static struct parport *port_from_cookie[PARPORT_MAX];
49 static void timeout_waiting_on_port (unsigned long cookie)
51 parport_ieee1284_wakeup (port_from_cookie[cookie % PARPORT_MAX]);
54 /**
55 * parport_wait_event - wait for an event on a parallel port
56 * @port: port to wait on
57 * @timeout: time to wait (in jiffies)
59 * This function waits for up to @timeout jiffies for an
60 * interrupt to occur on a parallel port. If the port timeout is
61 * set to zero, it returns immediately.
63 * If an interrupt occurs before the timeout period elapses, this
64 * function returns one immediately. If it times out, it returns
65 * a value greater than zero. An error code less than zero
66 * indicates an error (most likely a pending signal), and the
67 * calling code should finish what it's doing as soon as it can.
70 int parport_wait_event (struct parport *port, signed long timeout)
72 int ret;
73 struct timer_list timer;
75 if (!port->physport->cad->timeout)
76 /* Zero timeout is special, and we can't down() the
77 semaphore. */
78 return 1;
80 init_timer (&timer);
81 timer.expires = jiffies + timeout;
82 timer.function = timeout_waiting_on_port;
83 port_from_cookie[port->number % PARPORT_MAX] = port;
84 timer.data = port->number;
86 add_timer (&timer);
87 ret = down_interruptible (&port->physport->ieee1284.irq);
88 if (!del_timer (&timer) && !ret)
89 /* Timed out. */
90 ret = 1;
92 return ret;
95 /**
96 * parport_poll_peripheral - poll status lines
97 * @port: port to watch
98 * @mask: status lines to watch
99 * @result: desired values of chosen status lines
100 * @usec: timeout
102 * This function busy-waits until the masked status lines have
103 * the desired values, or until the timeout period elapses. The
104 * @mask and @result parameters are bitmasks, with the bits
105 * defined by the constants in parport.h: %PARPORT_STATUS_BUSY,
106 * and so on.
108 * This function does not call schedule(); instead it busy-waits
109 * using udelay(). It currently has a resolution of 5usec.
111 * If the status lines take on the desired values before the
112 * timeout period elapses, parport_poll_peripheral() returns zero
113 * immediately. A zero return value greater than zero indicates
114 * a timeout. An error code (less than zero) indicates an error,
115 * most likely a signal that arrived, and the caller should
116 * finish what it is doing as soon as possible.
119 int parport_poll_peripheral(struct parport *port,
120 unsigned char mask,
121 unsigned char result,
122 int usec)
124 /* Zero return code is success, >0 is timeout. */
125 int count = usec / 5 + 2;
126 int i;
127 unsigned char status;
128 for (i = 0; i < count; i++) {
129 status = parport_read_status (port);
130 if ((status & mask) == result)
131 return 0;
132 if (signal_pending (current))
133 return -EINTR;
134 if (need_resched())
135 break;
136 if (i >= 2)
137 udelay (5);
140 return 1;
144 * parport_wait_peripheral - wait for status lines to change in 35ms
145 * @port: port to watch
146 * @mask: status lines to watch
147 * @result: desired values of chosen status lines
149 * This function waits until the masked status lines have the
150 * desired values, or until 35ms have elapsed (see IEEE 1284-1994
151 * page 24 to 25 for why this value in particular is hardcoded).
152 * The @mask and @result parameters are bitmasks, with the bits
153 * defined by the constants in parport.h: %PARPORT_STATUS_BUSY,
154 * and so on.
156 * The port is polled quickly to start off with, in anticipation
157 * of a fast response from the peripheral. This fast polling
158 * time is configurable (using /proc), and defaults to 500usec.
159 * If the timeout for this port (see parport_set_timeout()) is
160 * zero, the fast polling time is 35ms, and this function does
161 * not call schedule().
163 * If the timeout for this port is non-zero, after the fast
164 * polling fails it uses parport_wait_event() to wait for up to
165 * 10ms, waking up if an interrupt occurs.
168 int parport_wait_peripheral(struct parport *port,
169 unsigned char mask,
170 unsigned char result)
172 int ret;
173 int usec;
174 unsigned long deadline;
175 unsigned char status;
177 usec = port->physport->spintime; /* usecs of fast polling */
178 if (!port->physport->cad->timeout)
179 /* A zero timeout is "special": busy wait for the
180 entire 35ms. */
181 usec = 35000;
183 /* Fast polling.
185 * This should be adjustable.
186 * How about making a note (in the device structure) of how long
187 * it takes, so we know for next time?
189 ret = parport_poll_peripheral (port, mask, result, usec);
190 if (ret != 1)
191 return ret;
193 if (!port->physport->cad->timeout)
194 /* We may be in an interrupt handler, so we can't poll
195 * slowly anyway. */
196 return 1;
198 /* 40ms of slow polling. */
199 deadline = jiffies + msecs_to_jiffies(40);
200 while (time_before (jiffies, deadline)) {
201 int ret;
203 if (signal_pending (current))
204 return -EINTR;
206 /* Wait for 10ms (or until an interrupt occurs if
207 * the handler is set) */
208 if ((ret = parport_wait_event (port, msecs_to_jiffies(10))) < 0)
209 return ret;
211 status = parport_read_status (port);
212 if ((status & mask) == result)
213 return 0;
215 if (!ret) {
216 /* parport_wait_event didn't time out, but the
217 * peripheral wasn't actually ready either.
218 * Wait for another 10ms. */
219 schedule_timeout_interruptible(msecs_to_jiffies(10));
223 return 1;
226 #ifdef CONFIG_PARPORT_1284
227 /* Terminate a negotiated mode. */
228 static void parport_ieee1284_terminate (struct parport *port)
230 int r;
231 port = port->physport;
233 /* EPP terminates differently. */
234 switch (port->ieee1284.mode) {
235 case IEEE1284_MODE_EPP:
236 case IEEE1284_MODE_EPPSL:
237 case IEEE1284_MODE_EPPSWE:
238 /* Terminate from EPP mode. */
240 /* Event 68: Set nInit low */
241 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
242 udelay (50);
244 /* Event 69: Set nInit high, nSelectIn low */
245 parport_frob_control (port,
246 PARPORT_CONTROL_SELECT
247 | PARPORT_CONTROL_INIT,
248 PARPORT_CONTROL_SELECT
249 | PARPORT_CONTROL_INIT);
250 break;
252 case IEEE1284_MODE_ECP:
253 case IEEE1284_MODE_ECPRLE:
254 case IEEE1284_MODE_ECPSWE:
255 /* In ECP we can only terminate from fwd idle phase. */
256 if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
257 /* Event 47: Set nInit high */
258 parport_frob_control (port,
259 PARPORT_CONTROL_INIT
260 | PARPORT_CONTROL_AUTOFD,
261 PARPORT_CONTROL_INIT
262 | PARPORT_CONTROL_AUTOFD);
264 /* Event 49: PError goes high */
265 r = parport_wait_peripheral (port,
266 PARPORT_STATUS_PAPEROUT,
267 PARPORT_STATUS_PAPEROUT);
268 if (r)
269 DPRINTK (KERN_INFO "%s: Timeout at event 49\n",
270 port->name);
272 parport_data_forward (port);
273 DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n",
274 port->name);
275 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
278 /* fall-though.. */
280 default:
281 /* Terminate from all other modes. */
283 /* Event 22: Set nSelectIn low, nAutoFd high */
284 parport_frob_control (port,
285 PARPORT_CONTROL_SELECT
286 | PARPORT_CONTROL_AUTOFD,
287 PARPORT_CONTROL_SELECT);
289 /* Event 24: nAck goes low */
290 r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0);
291 if (r)
292 DPRINTK (KERN_INFO "%s: Timeout at event 24\n",
293 port->name);
295 /* Event 25: Set nAutoFd low */
296 parport_frob_control (port,
297 PARPORT_CONTROL_AUTOFD,
298 PARPORT_CONTROL_AUTOFD);
300 /* Event 27: nAck goes high */
301 r = parport_wait_peripheral (port,
302 PARPORT_STATUS_ACK,
303 PARPORT_STATUS_ACK);
304 if (r)
305 DPRINTK (KERN_INFO "%s: Timeout at event 27\n",
306 port->name);
308 /* Event 29: Set nAutoFd high */
309 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
312 port->ieee1284.mode = IEEE1284_MODE_COMPAT;
313 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
315 DPRINTK (KERN_DEBUG "%s: In compatibility (forward idle) mode\n",
316 port->name);
318 #endif /* IEEE1284 support */
321 * parport_negotiate - negotiate an IEEE 1284 mode
322 * @port: port to use
323 * @mode: mode to negotiate to
325 * Use this to negotiate to a particular IEEE 1284 transfer mode.
326 * The @mode parameter should be one of the constants in
327 * parport.h starting %IEEE1284_MODE_xxx.
329 * The return value is 0 if the peripheral has accepted the
330 * negotiation to the mode specified, -1 if the peripheral is not
331 * IEEE 1284 compliant (or not present), or 1 if the peripheral
332 * has rejected the negotiation.
335 int parport_negotiate (struct parport *port, int mode)
337 #ifndef CONFIG_PARPORT_1284
338 if (mode == IEEE1284_MODE_COMPAT)
339 return 0;
340 printk (KERN_ERR "parport: IEEE1284 not supported in this kernel\n");
341 return -1;
342 #else
343 int m = mode & ~IEEE1284_ADDR;
344 int r;
345 unsigned char xflag;
347 port = port->physport;
349 /* Is there anything to do? */
350 if (port->ieee1284.mode == mode)
351 return 0;
353 /* Is the difference just an address-or-not bit? */
354 if ((port->ieee1284.mode & ~IEEE1284_ADDR) == (mode & ~IEEE1284_ADDR)){
355 port->ieee1284.mode = mode;
356 return 0;
359 /* Go to compability forward idle mode */
360 if (port->ieee1284.mode != IEEE1284_MODE_COMPAT)
361 parport_ieee1284_terminate (port);
363 if (mode == IEEE1284_MODE_COMPAT)
364 /* Compatibility mode: no negotiation. */
365 return 0;
367 switch (mode) {
368 case IEEE1284_MODE_ECPSWE:
369 m = IEEE1284_MODE_ECP;
370 break;
371 case IEEE1284_MODE_EPPSL:
372 case IEEE1284_MODE_EPPSWE:
373 m = IEEE1284_MODE_EPP;
374 break;
375 case IEEE1284_MODE_BECP:
376 return -ENOSYS; /* FIXME (implement BECP) */
379 if (mode & IEEE1284_EXT_LINK)
380 m = 1<<7; /* request extensibility link */
382 port->ieee1284.phase = IEEE1284_PH_NEGOTIATION;
384 /* Start off with nStrobe and nAutoFd high, and nSelectIn low */
385 parport_frob_control (port,
386 PARPORT_CONTROL_STROBE
387 | PARPORT_CONTROL_AUTOFD
388 | PARPORT_CONTROL_SELECT,
389 PARPORT_CONTROL_SELECT);
390 udelay(1);
392 /* Event 0: Set data */
393 parport_data_forward (port);
394 parport_write_data (port, m);
395 udelay (400); /* Shouldn't need to wait this long. */
397 /* Event 1: Set nSelectIn high, nAutoFd low */
398 parport_frob_control (port,
399 PARPORT_CONTROL_SELECT
400 | PARPORT_CONTROL_AUTOFD,
401 PARPORT_CONTROL_AUTOFD);
403 /* Event 2: PError, Select, nFault go high, nAck goes low */
404 if (parport_wait_peripheral (port,
405 PARPORT_STATUS_ERROR
406 | PARPORT_STATUS_SELECT
407 | PARPORT_STATUS_PAPEROUT
408 | PARPORT_STATUS_ACK,
409 PARPORT_STATUS_ERROR
410 | PARPORT_STATUS_SELECT
411 | PARPORT_STATUS_PAPEROUT)) {
412 /* Timeout */
413 parport_frob_control (port,
414 PARPORT_CONTROL_SELECT
415 | PARPORT_CONTROL_AUTOFD,
416 PARPORT_CONTROL_SELECT);
417 DPRINTK (KERN_DEBUG
418 "%s: Peripheral not IEEE1284 compliant (0x%02X)\n",
419 port->name, parport_read_status (port));
420 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
421 return -1; /* Not IEEE1284 compliant */
424 /* Event 3: Set nStrobe low */
425 parport_frob_control (port,
426 PARPORT_CONTROL_STROBE,
427 PARPORT_CONTROL_STROBE);
429 /* Event 4: Set nStrobe and nAutoFd high */
430 udelay (5);
431 parport_frob_control (port,
432 PARPORT_CONTROL_STROBE
433 | PARPORT_CONTROL_AUTOFD,
436 /* Event 6: nAck goes high */
437 if (parport_wait_peripheral (port,
438 PARPORT_STATUS_ACK,
439 PARPORT_STATUS_ACK)) {
440 /* This shouldn't really happen with a compliant device. */
441 DPRINTK (KERN_DEBUG
442 "%s: Mode 0x%02x not supported? (0x%02x)\n",
443 port->name, mode, port->ops->read_status (port));
444 parport_ieee1284_terminate (port);
445 return 1;
448 xflag = parport_read_status (port) & PARPORT_STATUS_SELECT;
450 /* xflag should be high for all modes other than nibble (0). */
451 if (mode && !xflag) {
452 /* Mode not supported. */
453 DPRINTK (KERN_DEBUG "%s: Mode 0x%02x rejected by peripheral\n",
454 port->name, mode);
455 parport_ieee1284_terminate (port);
456 return 1;
459 /* More to do if we've requested extensibility link. */
460 if (mode & IEEE1284_EXT_LINK) {
461 m = mode & 0x7f;
462 udelay (1);
463 parport_write_data (port, m);
464 udelay (1);
466 /* Event 51: Set nStrobe low */
467 parport_frob_control (port,
468 PARPORT_CONTROL_STROBE,
469 PARPORT_CONTROL_STROBE);
471 /* Event 52: nAck goes low */
472 if (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) {
473 /* This peripheral is _very_ slow. */
474 DPRINTK (KERN_DEBUG
475 "%s: Event 52 didn't happen\n",
476 port->name);
477 parport_ieee1284_terminate (port);
478 return 1;
481 /* Event 53: Set nStrobe high */
482 parport_frob_control (port,
483 PARPORT_CONTROL_STROBE,
486 /* Event 55: nAck goes high */
487 if (parport_wait_peripheral (port,
488 PARPORT_STATUS_ACK,
489 PARPORT_STATUS_ACK)) {
490 /* This shouldn't really happen with a compliant
491 * device. */
492 DPRINTK (KERN_DEBUG
493 "%s: Mode 0x%02x not supported? (0x%02x)\n",
494 port->name, mode,
495 port->ops->read_status (port));
496 parport_ieee1284_terminate (port);
497 return 1;
500 /* Event 54: Peripheral sets XFlag to reflect support */
501 xflag = parport_read_status (port) & PARPORT_STATUS_SELECT;
503 /* xflag should be high. */
504 if (!xflag) {
505 /* Extended mode not supported. */
506 DPRINTK (KERN_DEBUG "%s: Extended mode 0x%02x not "
507 "supported\n", port->name, mode);
508 parport_ieee1284_terminate (port);
509 return 1;
512 /* Any further setup is left to the caller. */
515 /* Mode is supported */
516 DPRINTK (KERN_DEBUG "%s: In mode 0x%02x\n", port->name, mode);
517 port->ieee1284.mode = mode;
519 /* But ECP is special */
520 if (!(mode & IEEE1284_EXT_LINK) && (m & IEEE1284_MODE_ECP)) {
521 port->ieee1284.phase = IEEE1284_PH_ECP_SETUP;
523 /* Event 30: Set nAutoFd low */
524 parport_frob_control (port,
525 PARPORT_CONTROL_AUTOFD,
526 PARPORT_CONTROL_AUTOFD);
528 /* Event 31: PError goes high. */
529 r = parport_wait_peripheral (port,
530 PARPORT_STATUS_PAPEROUT,
531 PARPORT_STATUS_PAPEROUT);
532 if (r) {
533 DPRINTK (KERN_INFO "%s: Timeout at event 31\n",
534 port->name);
537 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
538 DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n",
539 port->name);
540 } else switch (mode) {
541 case IEEE1284_MODE_NIBBLE:
542 case IEEE1284_MODE_BYTE:
543 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
544 break;
545 default:
546 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
550 return 0;
551 #endif /* IEEE1284 support */
554 /* Acknowledge that the peripheral has data available.
555 * Events 18-20, in order to get from Reverse Idle phase
556 * to Host Busy Data Available.
557 * This will most likely be called from an interrupt.
558 * Returns zero if data was available.
560 #ifdef CONFIG_PARPORT_1284
561 static int parport_ieee1284_ack_data_avail (struct parport *port)
563 if (parport_read_status (port) & PARPORT_STATUS_ERROR)
564 /* Event 18 didn't happen. */
565 return -1;
567 /* Event 20: nAutoFd goes high. */
568 port->ops->frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
569 port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
570 return 0;
572 #endif /* IEEE1284 support */
574 /* Handle an interrupt. */
575 void parport_ieee1284_interrupt (int which, void *handle, struct pt_regs *regs)
577 struct parport *port = handle;
578 parport_ieee1284_wakeup (port);
580 #ifdef CONFIG_PARPORT_1284
581 if (port->ieee1284.phase == IEEE1284_PH_REV_IDLE) {
582 /* An interrupt in this phase means that data
583 * is now available. */
584 DPRINTK (KERN_DEBUG "%s: Data available\n", port->name);
585 parport_ieee1284_ack_data_avail (port);
587 #endif /* IEEE1284 support */
591 * parport_write - write a block of data to a parallel port
592 * @port: port to write to
593 * @buffer: data buffer (in kernel space)
594 * @len: number of bytes of data to transfer
596 * This will write up to @len bytes of @buffer to the port
597 * specified, using the IEEE 1284 transfer mode most recently
598 * negotiated to (using parport_negotiate()), as long as that
599 * mode supports forward transfers (host to peripheral).
601 * It is the caller's responsibility to ensure that the first
602 * @len bytes of @buffer are valid.
604 * This function returns the number of bytes transferred (if zero
605 * or positive), or else an error code.
608 ssize_t parport_write (struct parport *port, const void *buffer, size_t len)
610 #ifndef CONFIG_PARPORT_1284
611 return port->ops->compat_write_data (port, buffer, len, 0);
612 #else
613 ssize_t retval;
614 int mode = port->ieee1284.mode;
615 int addr = mode & IEEE1284_ADDR;
616 size_t (*fn) (struct parport *, const void *, size_t, int);
618 /* Ignore the device-ID-request bit and the address bit. */
619 mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
621 /* Use the mode we're in. */
622 switch (mode) {
623 case IEEE1284_MODE_NIBBLE:
624 case IEEE1284_MODE_BYTE:
625 parport_negotiate (port, IEEE1284_MODE_COMPAT);
626 case IEEE1284_MODE_COMPAT:
627 DPRINTK (KERN_DEBUG "%s: Using compatibility mode\n",
628 port->name);
629 fn = port->ops->compat_write_data;
630 break;
632 case IEEE1284_MODE_EPP:
633 DPRINTK (KERN_DEBUG "%s: Using EPP mode\n", port->name);
634 if (addr) {
635 fn = port->ops->epp_write_addr;
636 } else {
637 fn = port->ops->epp_write_data;
639 break;
640 case IEEE1284_MODE_EPPSWE:
641 DPRINTK (KERN_DEBUG "%s: Using software-emulated EPP mode\n",
642 port->name);
643 if (addr) {
644 fn = parport_ieee1284_epp_write_addr;
645 } else {
646 fn = parport_ieee1284_epp_write_data;
648 break;
649 case IEEE1284_MODE_ECP:
650 case IEEE1284_MODE_ECPRLE:
651 DPRINTK (KERN_DEBUG "%s: Using ECP mode\n", port->name);
652 if (addr) {
653 fn = port->ops->ecp_write_addr;
654 } else {
655 fn = port->ops->ecp_write_data;
657 break;
659 case IEEE1284_MODE_ECPSWE:
660 DPRINTK (KERN_DEBUG "%s: Using software-emulated ECP mode\n",
661 port->name);
662 /* The caller has specified that it must be emulated,
663 * even if we have ECP hardware! */
664 if (addr) {
665 fn = parport_ieee1284_ecp_write_addr;
666 } else {
667 fn = parport_ieee1284_ecp_write_data;
669 break;
671 default:
672 DPRINTK (KERN_DEBUG "%s: Unknown mode 0x%02x\n", port->name,
673 port->ieee1284.mode);
674 return -ENOSYS;
677 retval = (*fn) (port, buffer, len, 0);
678 DPRINTK (KERN_DEBUG "%s: wrote %d/%d bytes\n", port->name, retval, len);
679 return retval;
680 #endif /* IEEE1284 support */
684 * parport_read - read a block of data from a parallel port
685 * @port: port to read from
686 * @buffer: data buffer (in kernel space)
687 * @len: number of bytes of data to transfer
689 * This will read up to @len bytes of @buffer to the port
690 * specified, using the IEEE 1284 transfer mode most recently
691 * negotiated to (using parport_negotiate()), as long as that
692 * mode supports reverse transfers (peripheral to host).
694 * It is the caller's responsibility to ensure that the first
695 * @len bytes of @buffer are available to write to.
697 * This function returns the number of bytes transferred (if zero
698 * or positive), or else an error code.
701 ssize_t parport_read (struct parport *port, void *buffer, size_t len)
703 #ifndef CONFIG_PARPORT_1284
704 printk (KERN_ERR "parport: IEEE1284 not supported in this kernel\n");
705 return -ENODEV;
706 #else
707 int mode = port->physport->ieee1284.mode;
708 int addr = mode & IEEE1284_ADDR;
709 size_t (*fn) (struct parport *, void *, size_t, int);
711 /* Ignore the device-ID-request bit and the address bit. */
712 mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
714 /* Use the mode we're in. */
715 switch (mode) {
716 case IEEE1284_MODE_COMPAT:
717 /* if we can tri-state use BYTE mode instead of NIBBLE mode,
718 * if that fails, revert to NIBBLE mode -- ought to store somewhere
719 * the device's ability to do BYTE mode reverse transfers, so we don't
720 * end up needlessly calling negotiate(BYTE) repeately.. (fb)
722 if ((port->physport->modes & PARPORT_MODE_TRISTATE) &&
723 !parport_negotiate (port, IEEE1284_MODE_BYTE)) {
724 /* got into BYTE mode OK */
725 DPRINTK (KERN_DEBUG "%s: Using byte mode\n", port->name);
726 fn = port->ops->byte_read_data;
727 break;
729 if (parport_negotiate (port, IEEE1284_MODE_NIBBLE)) {
730 return -EIO;
732 /* fall through to NIBBLE */
733 case IEEE1284_MODE_NIBBLE:
734 DPRINTK (KERN_DEBUG "%s: Using nibble mode\n", port->name);
735 fn = port->ops->nibble_read_data;
736 break;
738 case IEEE1284_MODE_BYTE:
739 DPRINTK (KERN_DEBUG "%s: Using byte mode\n", port->name);
740 fn = port->ops->byte_read_data;
741 break;
743 case IEEE1284_MODE_EPP:
744 DPRINTK (KERN_DEBUG "%s: Using EPP mode\n", port->name);
745 if (addr) {
746 fn = port->ops->epp_read_addr;
747 } else {
748 fn = port->ops->epp_read_data;
750 break;
751 case IEEE1284_MODE_EPPSWE:
752 DPRINTK (KERN_DEBUG "%s: Using software-emulated EPP mode\n",
753 port->name);
754 if (addr) {
755 fn = parport_ieee1284_epp_read_addr;
756 } else {
757 fn = parport_ieee1284_epp_read_data;
759 break;
760 case IEEE1284_MODE_ECP:
761 case IEEE1284_MODE_ECPRLE:
762 DPRINTK (KERN_DEBUG "%s: Using ECP mode\n", port->name);
763 fn = port->ops->ecp_read_data;
764 break;
766 case IEEE1284_MODE_ECPSWE:
767 DPRINTK (KERN_DEBUG "%s: Using software-emulated ECP mode\n",
768 port->name);
769 fn = parport_ieee1284_ecp_read_data;
770 break;
772 default:
773 DPRINTK (KERN_DEBUG "%s: Unknown mode 0x%02x\n", port->name,
774 port->physport->ieee1284.mode);
775 return -ENOSYS;
778 return (*fn) (port, buffer, len, 0);
779 #endif /* IEEE1284 support */
783 * parport_set_timeout - set the inactivity timeout for a device
784 * @dev: device on a port
785 * @inactivity: inactivity timeout (in jiffies)
787 * This sets the inactivity timeout for a particular device on a
788 * port. This affects functions like parport_wait_peripheral().
789 * The special value 0 means not to call schedule() while dealing
790 * with this device.
792 * The return value is the previous inactivity timeout.
794 * Any callers of parport_wait_event() for this device are woken
795 * up.
798 long parport_set_timeout (struct pardevice *dev, long inactivity)
800 long int old = dev->timeout;
802 dev->timeout = inactivity;
804 if (dev->port->physport->cad == dev)
805 parport_ieee1284_wakeup (dev->port);
807 return old;
810 /* Exported symbols for modules. */
812 EXPORT_SYMBOL(parport_negotiate);
813 EXPORT_SYMBOL(parport_write);
814 EXPORT_SYMBOL(parport_read);
815 EXPORT_SYMBOL(parport_wait_peripheral);
816 EXPORT_SYMBOL(parport_wait_event);
817 EXPORT_SYMBOL(parport_set_timeout);
818 EXPORT_SYMBOL(parport_ieee1284_interrupt);