Linux 4.16.11
[linux/fpc-iii.git] / drivers / parport / ieee1284.c
blob2d1a5c737c6ef53070ff9cacacc805e5d1903599
1 /*
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/module.h>
20 #include <linux/threads.h>
21 #include <linux/parport.h>
22 #include <linux/delay.h>
23 #include <linux/kernel.h>
24 #include <linux/interrupt.h>
25 #include <linux/timer.h>
26 #include <linux/sched/signal.h>
28 #undef DEBUG /* undef me for production */
30 #ifdef CONFIG_LP_CONSOLE
31 #undef DEBUG /* Don't want a garbled console */
32 #endif
34 #ifdef DEBUG
35 #define DPRINTK(stuff...) printk (stuff)
36 #else
37 #define DPRINTK(stuff...)
38 #endif
40 /* Make parport_wait_peripheral wake up.
41 * It will be useful to call this from an interrupt handler. */
42 static void parport_ieee1284_wakeup (struct parport *port)
44 up (&port->physport->ieee1284.irq);
47 static void timeout_waiting_on_port (struct timer_list *t)
49 struct parport *port = from_timer(port, t, timer);
51 parport_ieee1284_wakeup (port);
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 zero immediately. If it times out, it returns
65 * one. An error code less than zero indicates an error (most
66 * likely a pending signal), and the calling code should finish
67 * what it's doing as soon as it can.
70 int parport_wait_event (struct parport *port, signed long timeout)
72 int ret;
74 if (!port->physport->cad->timeout)
75 /* Zero timeout is special, and we can't down() the
76 semaphore. */
77 return 1;
79 timer_setup(&port->timer, timeout_waiting_on_port, 0);
80 mod_timer(&port->timer, jiffies + timeout);
81 ret = down_interruptible (&port->physport->ieee1284.irq);
82 if (!del_timer_sync(&port->timer) && !ret)
83 /* Timed out. */
84 ret = 1;
86 return ret;
89 /**
90 * parport_poll_peripheral - poll status lines
91 * @port: port to watch
92 * @mask: status lines to watch
93 * @result: desired values of chosen status lines
94 * @usec: timeout
96 * This function busy-waits until the masked status lines have
97 * the desired values, or until the timeout period elapses. The
98 * @mask and @result parameters are bitmasks, with the bits
99 * defined by the constants in parport.h: %PARPORT_STATUS_BUSY,
100 * and so on.
102 * This function does not call schedule(); instead it busy-waits
103 * using udelay(). It currently has a resolution of 5usec.
105 * If the status lines take on the desired values before the
106 * timeout period elapses, parport_poll_peripheral() returns zero
107 * immediately. A return value greater than zero indicates
108 * a timeout. An error code (less than zero) indicates an error,
109 * most likely a signal that arrived, and the caller should
110 * finish what it is doing as soon as possible.
113 int parport_poll_peripheral(struct parport *port,
114 unsigned char mask,
115 unsigned char result,
116 int usec)
118 /* Zero return code is success, >0 is timeout. */
119 int count = usec / 5 + 2;
120 int i;
121 unsigned char status;
122 for (i = 0; i < count; i++) {
123 status = parport_read_status (port);
124 if ((status & mask) == result)
125 return 0;
126 if (signal_pending (current))
127 return -EINTR;
128 if (need_resched())
129 break;
130 if (i >= 2)
131 udelay (5);
134 return 1;
138 * parport_wait_peripheral - wait for status lines to change in 35ms
139 * @port: port to watch
140 * @mask: status lines to watch
141 * @result: desired values of chosen status lines
143 * This function waits until the masked status lines have the
144 * desired values, or until 35ms have elapsed (see IEEE 1284-1994
145 * page 24 to 25 for why this value in particular is hardcoded).
146 * The @mask and @result parameters are bitmasks, with the bits
147 * defined by the constants in parport.h: %PARPORT_STATUS_BUSY,
148 * and so on.
150 * The port is polled quickly to start off with, in anticipation
151 * of a fast response from the peripheral. This fast polling
152 * time is configurable (using /proc), and defaults to 500usec.
153 * If the timeout for this port (see parport_set_timeout()) is
154 * zero, the fast polling time is 35ms, and this function does
155 * not call schedule().
157 * If the timeout for this port is non-zero, after the fast
158 * polling fails it uses parport_wait_event() to wait for up to
159 * 10ms, waking up if an interrupt occurs.
162 int parport_wait_peripheral(struct parport *port,
163 unsigned char mask,
164 unsigned char result)
166 int ret;
167 int usec;
168 unsigned long deadline;
169 unsigned char status;
171 usec = port->physport->spintime; /* usecs of fast polling */
172 if (!port->physport->cad->timeout)
173 /* A zero timeout is "special": busy wait for the
174 entire 35ms. */
175 usec = 35000;
177 /* Fast polling.
179 * This should be adjustable.
180 * How about making a note (in the device structure) of how long
181 * it takes, so we know for next time?
183 ret = parport_poll_peripheral (port, mask, result, usec);
184 if (ret != 1)
185 return ret;
187 if (!port->physport->cad->timeout)
188 /* We may be in an interrupt handler, so we can't poll
189 * slowly anyway. */
190 return 1;
192 /* 40ms of slow polling. */
193 deadline = jiffies + msecs_to_jiffies(40);
194 while (time_before (jiffies, deadline)) {
195 if (signal_pending (current))
196 return -EINTR;
198 /* Wait for 10ms (or until an interrupt occurs if
199 * the handler is set) */
200 if ((ret = parport_wait_event (port, msecs_to_jiffies(10))) < 0)
201 return ret;
203 status = parport_read_status (port);
204 if ((status & mask) == result)
205 return 0;
207 if (!ret) {
208 /* parport_wait_event didn't time out, but the
209 * peripheral wasn't actually ready either.
210 * Wait for another 10ms. */
211 schedule_timeout_interruptible(msecs_to_jiffies(10));
215 return 1;
218 #ifdef CONFIG_PARPORT_1284
219 /* Terminate a negotiated mode. */
220 static void parport_ieee1284_terminate (struct parport *port)
222 int r;
223 port = port->physport;
225 /* EPP terminates differently. */
226 switch (port->ieee1284.mode) {
227 case IEEE1284_MODE_EPP:
228 case IEEE1284_MODE_EPPSL:
229 case IEEE1284_MODE_EPPSWE:
230 /* Terminate from EPP mode. */
232 /* Event 68: Set nInit low */
233 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
234 udelay (50);
236 /* Event 69: Set nInit high, nSelectIn low */
237 parport_frob_control (port,
238 PARPORT_CONTROL_SELECT
239 | PARPORT_CONTROL_INIT,
240 PARPORT_CONTROL_SELECT
241 | PARPORT_CONTROL_INIT);
242 break;
244 case IEEE1284_MODE_ECP:
245 case IEEE1284_MODE_ECPRLE:
246 case IEEE1284_MODE_ECPSWE:
247 /* In ECP we can only terminate from fwd idle phase. */
248 if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
249 /* Event 47: Set nInit high */
250 parport_frob_control (port,
251 PARPORT_CONTROL_INIT
252 | PARPORT_CONTROL_AUTOFD,
253 PARPORT_CONTROL_INIT
254 | PARPORT_CONTROL_AUTOFD);
256 /* Event 49: PError goes high */
257 r = parport_wait_peripheral (port,
258 PARPORT_STATUS_PAPEROUT,
259 PARPORT_STATUS_PAPEROUT);
260 if (r)
261 DPRINTK (KERN_INFO "%s: Timeout at event 49\n",
262 port->name);
264 parport_data_forward (port);
265 DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n",
266 port->name);
267 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
270 /* fall-though.. */
272 default:
273 /* Terminate from all other modes. */
275 /* Event 22: Set nSelectIn low, nAutoFd high */
276 parport_frob_control (port,
277 PARPORT_CONTROL_SELECT
278 | PARPORT_CONTROL_AUTOFD,
279 PARPORT_CONTROL_SELECT);
281 /* Event 24: nAck goes low */
282 r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0);
283 if (r)
284 DPRINTK (KERN_INFO "%s: Timeout at event 24\n",
285 port->name);
287 /* Event 25: Set nAutoFd low */
288 parport_frob_control (port,
289 PARPORT_CONTROL_AUTOFD,
290 PARPORT_CONTROL_AUTOFD);
292 /* Event 27: nAck goes high */
293 r = parport_wait_peripheral (port,
294 PARPORT_STATUS_ACK,
295 PARPORT_STATUS_ACK);
296 if (r)
297 DPRINTK (KERN_INFO "%s: Timeout at event 27\n",
298 port->name);
300 /* Event 29: Set nAutoFd high */
301 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
304 port->ieee1284.mode = IEEE1284_MODE_COMPAT;
305 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
307 DPRINTK (KERN_DEBUG "%s: In compatibility (forward idle) mode\n",
308 port->name);
310 #endif /* IEEE1284 support */
313 * parport_negotiate - negotiate an IEEE 1284 mode
314 * @port: port to use
315 * @mode: mode to negotiate to
317 * Use this to negotiate to a particular IEEE 1284 transfer mode.
318 * The @mode parameter should be one of the constants in
319 * parport.h starting %IEEE1284_MODE_xxx.
321 * The return value is 0 if the peripheral has accepted the
322 * negotiation to the mode specified, -1 if the peripheral is not
323 * IEEE 1284 compliant (or not present), or 1 if the peripheral
324 * has rejected the negotiation.
327 int parport_negotiate (struct parport *port, int mode)
329 #ifndef CONFIG_PARPORT_1284
330 if (mode == IEEE1284_MODE_COMPAT)
331 return 0;
332 printk (KERN_ERR "parport: IEEE1284 not supported in this kernel\n");
333 return -1;
334 #else
335 int m = mode & ~IEEE1284_ADDR;
336 int r;
337 unsigned char xflag;
339 port = port->physport;
341 /* Is there anything to do? */
342 if (port->ieee1284.mode == mode)
343 return 0;
345 /* Is the difference just an address-or-not bit? */
346 if ((port->ieee1284.mode & ~IEEE1284_ADDR) == (mode & ~IEEE1284_ADDR)){
347 port->ieee1284.mode = mode;
348 return 0;
351 /* Go to compatibility forward idle mode */
352 if (port->ieee1284.mode != IEEE1284_MODE_COMPAT)
353 parport_ieee1284_terminate (port);
355 if (mode == IEEE1284_MODE_COMPAT)
356 /* Compatibility mode: no negotiation. */
357 return 0;
359 switch (mode) {
360 case IEEE1284_MODE_ECPSWE:
361 m = IEEE1284_MODE_ECP;
362 break;
363 case IEEE1284_MODE_EPPSL:
364 case IEEE1284_MODE_EPPSWE:
365 m = IEEE1284_MODE_EPP;
366 break;
367 case IEEE1284_MODE_BECP:
368 return -ENOSYS; /* FIXME (implement BECP) */
371 if (mode & IEEE1284_EXT_LINK)
372 m = 1<<7; /* request extensibility link */
374 port->ieee1284.phase = IEEE1284_PH_NEGOTIATION;
376 /* Start off with nStrobe and nAutoFd high, and nSelectIn low */
377 parport_frob_control (port,
378 PARPORT_CONTROL_STROBE
379 | PARPORT_CONTROL_AUTOFD
380 | PARPORT_CONTROL_SELECT,
381 PARPORT_CONTROL_SELECT);
382 udelay(1);
384 /* Event 0: Set data */
385 parport_data_forward (port);
386 parport_write_data (port, m);
387 udelay (400); /* Shouldn't need to wait this long. */
389 /* Event 1: Set nSelectIn high, nAutoFd low */
390 parport_frob_control (port,
391 PARPORT_CONTROL_SELECT
392 | PARPORT_CONTROL_AUTOFD,
393 PARPORT_CONTROL_AUTOFD);
395 /* Event 2: PError, Select, nFault go high, nAck goes low */
396 if (parport_wait_peripheral (port,
397 PARPORT_STATUS_ERROR
398 | PARPORT_STATUS_SELECT
399 | PARPORT_STATUS_PAPEROUT
400 | PARPORT_STATUS_ACK,
401 PARPORT_STATUS_ERROR
402 | PARPORT_STATUS_SELECT
403 | PARPORT_STATUS_PAPEROUT)) {
404 /* Timeout */
405 parport_frob_control (port,
406 PARPORT_CONTROL_SELECT
407 | PARPORT_CONTROL_AUTOFD,
408 PARPORT_CONTROL_SELECT);
409 DPRINTK (KERN_DEBUG
410 "%s: Peripheral not IEEE1284 compliant (0x%02X)\n",
411 port->name, parport_read_status (port));
412 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
413 return -1; /* Not IEEE1284 compliant */
416 /* Event 3: Set nStrobe low */
417 parport_frob_control (port,
418 PARPORT_CONTROL_STROBE,
419 PARPORT_CONTROL_STROBE);
421 /* Event 4: Set nStrobe and nAutoFd high */
422 udelay (5);
423 parport_frob_control (port,
424 PARPORT_CONTROL_STROBE
425 | PARPORT_CONTROL_AUTOFD,
428 /* Event 6: nAck goes high */
429 if (parport_wait_peripheral (port,
430 PARPORT_STATUS_ACK,
431 PARPORT_STATUS_ACK)) {
432 /* This shouldn't really happen with a compliant device. */
433 DPRINTK (KERN_DEBUG
434 "%s: Mode 0x%02x not supported? (0x%02x)\n",
435 port->name, mode, port->ops->read_status (port));
436 parport_ieee1284_terminate (port);
437 return 1;
440 xflag = parport_read_status (port) & PARPORT_STATUS_SELECT;
442 /* xflag should be high for all modes other than nibble (0). */
443 if (mode && !xflag) {
444 /* Mode not supported. */
445 DPRINTK (KERN_DEBUG "%s: Mode 0x%02x rejected by peripheral\n",
446 port->name, mode);
447 parport_ieee1284_terminate (port);
448 return 1;
451 /* More to do if we've requested extensibility link. */
452 if (mode & IEEE1284_EXT_LINK) {
453 m = mode & 0x7f;
454 udelay (1);
455 parport_write_data (port, m);
456 udelay (1);
458 /* Event 51: Set nStrobe low */
459 parport_frob_control (port,
460 PARPORT_CONTROL_STROBE,
461 PARPORT_CONTROL_STROBE);
463 /* Event 52: nAck goes low */
464 if (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) {
465 /* This peripheral is _very_ slow. */
466 DPRINTK (KERN_DEBUG
467 "%s: Event 52 didn't happen\n",
468 port->name);
469 parport_ieee1284_terminate (port);
470 return 1;
473 /* Event 53: Set nStrobe high */
474 parport_frob_control (port,
475 PARPORT_CONTROL_STROBE,
478 /* Event 55: nAck goes high */
479 if (parport_wait_peripheral (port,
480 PARPORT_STATUS_ACK,
481 PARPORT_STATUS_ACK)) {
482 /* This shouldn't really happen with a compliant
483 * device. */
484 DPRINTK (KERN_DEBUG
485 "%s: Mode 0x%02x not supported? (0x%02x)\n",
486 port->name, mode,
487 port->ops->read_status (port));
488 parport_ieee1284_terminate (port);
489 return 1;
492 /* Event 54: Peripheral sets XFlag to reflect support */
493 xflag = parport_read_status (port) & PARPORT_STATUS_SELECT;
495 /* xflag should be high. */
496 if (!xflag) {
497 /* Extended mode not supported. */
498 DPRINTK (KERN_DEBUG "%s: Extended mode 0x%02x not "
499 "supported\n", port->name, mode);
500 parport_ieee1284_terminate (port);
501 return 1;
504 /* Any further setup is left to the caller. */
507 /* Mode is supported */
508 DPRINTK (KERN_DEBUG "%s: In mode 0x%02x\n", port->name, mode);
509 port->ieee1284.mode = mode;
511 /* But ECP is special */
512 if (!(mode & IEEE1284_EXT_LINK) && (m & IEEE1284_MODE_ECP)) {
513 port->ieee1284.phase = IEEE1284_PH_ECP_SETUP;
515 /* Event 30: Set nAutoFd low */
516 parport_frob_control (port,
517 PARPORT_CONTROL_AUTOFD,
518 PARPORT_CONTROL_AUTOFD);
520 /* Event 31: PError goes high. */
521 r = parport_wait_peripheral (port,
522 PARPORT_STATUS_PAPEROUT,
523 PARPORT_STATUS_PAPEROUT);
524 if (r) {
525 DPRINTK (KERN_INFO "%s: Timeout at event 31\n",
526 port->name);
529 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
530 DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n",
531 port->name);
532 } else switch (mode) {
533 case IEEE1284_MODE_NIBBLE:
534 case IEEE1284_MODE_BYTE:
535 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
536 break;
537 default:
538 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
542 return 0;
543 #endif /* IEEE1284 support */
546 /* Acknowledge that the peripheral has data available.
547 * Events 18-20, in order to get from Reverse Idle phase
548 * to Host Busy Data Available.
549 * This will most likely be called from an interrupt.
550 * Returns zero if data was available.
552 #ifdef CONFIG_PARPORT_1284
553 static int parport_ieee1284_ack_data_avail (struct parport *port)
555 if (parport_read_status (port) & PARPORT_STATUS_ERROR)
556 /* Event 18 didn't happen. */
557 return -1;
559 /* Event 20: nAutoFd goes high. */
560 port->ops->frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
561 port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
562 return 0;
564 #endif /* IEEE1284 support */
566 /* Handle an interrupt. */
567 void parport_ieee1284_interrupt (void *handle)
569 struct parport *port = handle;
570 parport_ieee1284_wakeup (port);
572 #ifdef CONFIG_PARPORT_1284
573 if (port->ieee1284.phase == IEEE1284_PH_REV_IDLE) {
574 /* An interrupt in this phase means that data
575 * is now available. */
576 DPRINTK (KERN_DEBUG "%s: Data available\n", port->name);
577 parport_ieee1284_ack_data_avail (port);
579 #endif /* IEEE1284 support */
583 * parport_write - write a block of data to a parallel port
584 * @port: port to write to
585 * @buffer: data buffer (in kernel space)
586 * @len: number of bytes of data to transfer
588 * This will write up to @len bytes of @buffer to the port
589 * specified, using the IEEE 1284 transfer mode most recently
590 * negotiated to (using parport_negotiate()), as long as that
591 * mode supports forward transfers (host to peripheral).
593 * It is the caller's responsibility to ensure that the first
594 * @len bytes of @buffer are valid.
596 * This function returns the number of bytes transferred (if zero
597 * or positive), or else an error code.
600 ssize_t parport_write (struct parport *port, const void *buffer, size_t len)
602 #ifndef CONFIG_PARPORT_1284
603 return port->ops->compat_write_data (port, buffer, len, 0);
604 #else
605 ssize_t retval;
606 int mode = port->ieee1284.mode;
607 int addr = mode & IEEE1284_ADDR;
608 size_t (*fn) (struct parport *, const void *, size_t, int);
610 /* Ignore the device-ID-request bit and the address bit. */
611 mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
613 /* Use the mode we're in. */
614 switch (mode) {
615 case IEEE1284_MODE_NIBBLE:
616 case IEEE1284_MODE_BYTE:
617 parport_negotiate (port, IEEE1284_MODE_COMPAT);
618 case IEEE1284_MODE_COMPAT:
619 DPRINTK (KERN_DEBUG "%s: Using compatibility mode\n",
620 port->name);
621 fn = port->ops->compat_write_data;
622 break;
624 case IEEE1284_MODE_EPP:
625 DPRINTK (KERN_DEBUG "%s: Using EPP mode\n", port->name);
626 if (addr) {
627 fn = port->ops->epp_write_addr;
628 } else {
629 fn = port->ops->epp_write_data;
631 break;
632 case IEEE1284_MODE_EPPSWE:
633 DPRINTK (KERN_DEBUG "%s: Using software-emulated EPP mode\n",
634 port->name);
635 if (addr) {
636 fn = parport_ieee1284_epp_write_addr;
637 } else {
638 fn = parport_ieee1284_epp_write_data;
640 break;
641 case IEEE1284_MODE_ECP:
642 case IEEE1284_MODE_ECPRLE:
643 DPRINTK (KERN_DEBUG "%s: Using ECP mode\n", port->name);
644 if (addr) {
645 fn = port->ops->ecp_write_addr;
646 } else {
647 fn = port->ops->ecp_write_data;
649 break;
651 case IEEE1284_MODE_ECPSWE:
652 DPRINTK (KERN_DEBUG "%s: Using software-emulated ECP mode\n",
653 port->name);
654 /* The caller has specified that it must be emulated,
655 * even if we have ECP hardware! */
656 if (addr) {
657 fn = parport_ieee1284_ecp_write_addr;
658 } else {
659 fn = parport_ieee1284_ecp_write_data;
661 break;
663 default:
664 DPRINTK (KERN_DEBUG "%s: Unknown mode 0x%02x\n", port->name,
665 port->ieee1284.mode);
666 return -ENOSYS;
669 retval = (*fn) (port, buffer, len, 0);
670 DPRINTK (KERN_DEBUG "%s: wrote %d/%d bytes\n", port->name, retval, len);
671 return retval;
672 #endif /* IEEE1284 support */
676 * parport_read - read a block of data from a parallel port
677 * @port: port to read from
678 * @buffer: data buffer (in kernel space)
679 * @len: number of bytes of data to transfer
681 * This will read up to @len bytes of @buffer to the port
682 * specified, using the IEEE 1284 transfer mode most recently
683 * negotiated to (using parport_negotiate()), as long as that
684 * mode supports reverse transfers (peripheral to host).
686 * It is the caller's responsibility to ensure that the first
687 * @len bytes of @buffer are available to write to.
689 * This function returns the number of bytes transferred (if zero
690 * or positive), or else an error code.
693 ssize_t parport_read (struct parport *port, void *buffer, size_t len)
695 #ifndef CONFIG_PARPORT_1284
696 printk (KERN_ERR "parport: IEEE1284 not supported in this kernel\n");
697 return -ENODEV;
698 #else
699 int mode = port->physport->ieee1284.mode;
700 int addr = mode & IEEE1284_ADDR;
701 size_t (*fn) (struct parport *, void *, size_t, int);
703 /* Ignore the device-ID-request bit and the address bit. */
704 mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
706 /* Use the mode we're in. */
707 switch (mode) {
708 case IEEE1284_MODE_COMPAT:
709 /* if we can tri-state use BYTE mode instead of NIBBLE mode,
710 * if that fails, revert to NIBBLE mode -- ought to store somewhere
711 * the device's ability to do BYTE mode reverse transfers, so we don't
712 * end up needlessly calling negotiate(BYTE) repeately.. (fb)
714 if ((port->physport->modes & PARPORT_MODE_TRISTATE) &&
715 !parport_negotiate (port, IEEE1284_MODE_BYTE)) {
716 /* got into BYTE mode OK */
717 DPRINTK (KERN_DEBUG "%s: Using byte mode\n", port->name);
718 fn = port->ops->byte_read_data;
719 break;
721 if (parport_negotiate (port, IEEE1284_MODE_NIBBLE)) {
722 return -EIO;
724 /* fall through to NIBBLE */
725 case IEEE1284_MODE_NIBBLE:
726 DPRINTK (KERN_DEBUG "%s: Using nibble mode\n", port->name);
727 fn = port->ops->nibble_read_data;
728 break;
730 case IEEE1284_MODE_BYTE:
731 DPRINTK (KERN_DEBUG "%s: Using byte mode\n", port->name);
732 fn = port->ops->byte_read_data;
733 break;
735 case IEEE1284_MODE_EPP:
736 DPRINTK (KERN_DEBUG "%s: Using EPP mode\n", port->name);
737 if (addr) {
738 fn = port->ops->epp_read_addr;
739 } else {
740 fn = port->ops->epp_read_data;
742 break;
743 case IEEE1284_MODE_EPPSWE:
744 DPRINTK (KERN_DEBUG "%s: Using software-emulated EPP mode\n",
745 port->name);
746 if (addr) {
747 fn = parport_ieee1284_epp_read_addr;
748 } else {
749 fn = parport_ieee1284_epp_read_data;
751 break;
752 case IEEE1284_MODE_ECP:
753 case IEEE1284_MODE_ECPRLE:
754 DPRINTK (KERN_DEBUG "%s: Using ECP mode\n", port->name);
755 fn = port->ops->ecp_read_data;
756 break;
758 case IEEE1284_MODE_ECPSWE:
759 DPRINTK (KERN_DEBUG "%s: Using software-emulated ECP mode\n",
760 port->name);
761 fn = parport_ieee1284_ecp_read_data;
762 break;
764 default:
765 DPRINTK (KERN_DEBUG "%s: Unknown mode 0x%02x\n", port->name,
766 port->physport->ieee1284.mode);
767 return -ENOSYS;
770 return (*fn) (port, buffer, len, 0);
771 #endif /* IEEE1284 support */
775 * parport_set_timeout - set the inactivity timeout for a device
776 * @dev: device on a port
777 * @inactivity: inactivity timeout (in jiffies)
779 * This sets the inactivity timeout for a particular device on a
780 * port. This affects functions like parport_wait_peripheral().
781 * The special value 0 means not to call schedule() while dealing
782 * with this device.
784 * The return value is the previous inactivity timeout.
786 * Any callers of parport_wait_event() for this device are woken
787 * up.
790 long parport_set_timeout (struct pardevice *dev, long inactivity)
792 long int old = dev->timeout;
794 dev->timeout = inactivity;
796 if (dev->port->physport->cad == dev)
797 parport_ieee1284_wakeup (dev->port);
799 return old;
802 /* Exported symbols for modules. */
804 EXPORT_SYMBOL(parport_negotiate);
805 EXPORT_SYMBOL(parport_write);
806 EXPORT_SYMBOL(parport_read);
807 EXPORT_SYMBOL(parport_wait_peripheral);
808 EXPORT_SYMBOL(parport_wait_event);
809 EXPORT_SYMBOL(parport_set_timeout);
810 EXPORT_SYMBOL(parport_ieee1284_interrupt);