Linux 2.4.0-test7pre1
[davej-history.git] / drivers / parport / ieee1284_ops.c
blobcf5c5fb03c03fd508791e036b80c2d826b5e8225
1 /* IEEE-1284 operations for parport.
3 * This file is for generic IEEE 1284 operations. The idea is that
4 * they are used by the low-level drivers. If they have a special way
5 * of doing something, they can provide their own routines (and put
6 * the function pointers in port->ops); if not, they can just use these
7 * as a fallback.
9 * Note: Make no assumptions about hardware or architecture in this file!
11 * Author: Tim Waugh <tim@cyberelk.demon.co.uk>
12 * Fixed AUTOFD polarity in ecp_forward_to_reverse(). Fred Barnes, 1999
16 #include <linux/config.h>
17 #include <linux/parport.h>
18 #include <linux/delay.h>
19 #include <asm/uaccess.h>
21 #define DEBUG /* undef me for production */
23 #ifdef CONFIG_LP_CONSOLE
24 #undef DEBUG /* Don't want a garbled console */
25 #endif
27 #ifdef DEBUG
28 #define DPRINTK(stuff...) printk (stuff)
29 #else
30 #define DPRINTK(stuff...)
31 #endif
33 /*** *
34 * One-way data transfer functions. *
35 * ***/
37 /* Compatibility mode. */
38 size_t parport_ieee1284_write_compat (struct parport *port,
39 const void *buffer, size_t len,
40 int flags)
42 int no_irq = 1;
43 ssize_t count = 0;
44 const unsigned char *addr = buffer;
45 unsigned char byte;
46 struct pardevice *dev = port->physport->cad;
47 unsigned char ctl = (PARPORT_CONTROL_SELECT
48 | PARPORT_CONTROL_INIT);
50 if (port->irq != PARPORT_IRQ_NONE) {
51 parport_enable_irq (port);
52 no_irq = 0;
54 /* Clear out previous irqs. */
55 while (!down_trylock (&port->physport->ieee1284.irq));
58 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
59 parport_write_control (port, ctl);
60 parport_data_forward (port);
61 while (count < len) {
62 long expire = jiffies + dev->timeout;
63 long wait = (HZ + 99) / 100;
64 unsigned char mask = (PARPORT_STATUS_ERROR
65 | PARPORT_STATUS_BUSY);
66 unsigned char val = (PARPORT_STATUS_ERROR
67 | PARPORT_STATUS_BUSY);
69 /* Wait until the peripheral's ready */
70 do {
71 /* Is the peripheral ready yet? */
72 if (!parport_wait_peripheral (port, mask, val))
73 /* Skip the loop */
74 goto ready;
76 /* Is the peripheral upset? */
77 if ((parport_read_status (port) &
78 (PARPORT_STATUS_PAPEROUT |
79 PARPORT_STATUS_SELECT |
80 PARPORT_STATUS_ERROR))
81 != (PARPORT_STATUS_SELECT |
82 PARPORT_STATUS_ERROR))
83 /* If nFault is asserted (i.e. no
84 * error) and PAPEROUT and SELECT are
85 * just red herrings, give the driver
86 * a chance to check it's happy with
87 * that before continuing. */
88 goto stop;
90 /* Have we run out of time? */
91 if (!time_before (jiffies, expire))
92 break;
94 /* Yield the port for a while. If this is the
95 first time around the loop, don't let go of
96 the port. This way, we find out if we have
97 our interrupt handler called. */
98 if (count && no_irq) {
99 parport_release (dev);
100 __set_current_state (TASK_INTERRUPTIBLE);
101 schedule_timeout (wait);
102 parport_claim_or_block (dev);
104 else
105 /* We must have the device claimed here */
106 parport_wait_event (port, wait);
108 /* Is there a signal pending? */
109 if (signal_pending (current))
110 break;
112 /* Wait longer next time. */
113 wait *= 2;
114 } while (time_before (jiffies, expire));
116 if (signal_pending (current))
117 break;
119 DPRINTK (KERN_DEBUG "%s: Timed out\n", port->name);
120 break;
122 ready:
123 /* Write the character to the data lines. */
124 byte = *addr++;
125 parport_write_data (port, byte);
126 udelay (1);
128 /* Pulse strobe. */
129 parport_write_control (port, ctl | PARPORT_CONTROL_STROBE);
130 udelay (1); /* strobe */
132 parport_write_control (port, ctl);
133 udelay (1); /* hold */
135 /* Assume the peripheral received it. */
136 count++;
138 /* Let another process run if it needs to. */
139 if (time_before (jiffies, expire))
140 if (!parport_yield_blocking (dev)
141 && current->need_resched)
142 schedule ();
144 stop:
145 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
147 return count;
150 /* Nibble mode. */
151 size_t parport_ieee1284_read_nibble (struct parport *port,
152 void *buffer, size_t len,
153 int flags)
155 #ifndef CONFIG_PARPORT_1284
156 return 0;
157 #else
158 unsigned char *buf = buffer;
159 int i;
160 unsigned char byte = 0;
162 len *= 2; /* in nibbles */
163 for (i=0; i < len; i++) {
164 unsigned char nibble;
166 /* Does the error line indicate end of data? */
167 if (((i & 1) == 0) &&
168 (parport_read_status(port) & PARPORT_STATUS_ERROR)) {
169 port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DNA;
170 DPRINTK (KERN_DEBUG
171 "%s: No more nibble data (%d bytes)\n",
172 port->name, i/2);
174 /* Go to reverse idle phase. */
175 parport_frob_control (port,
176 PARPORT_CONTROL_AUTOFD,
177 PARPORT_CONTROL_AUTOFD);
178 port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE;
179 break;
182 /* Event 7: Set nAutoFd low. */
183 parport_frob_control (port,
184 PARPORT_CONTROL_AUTOFD,
185 PARPORT_CONTROL_AUTOFD);
187 /* Event 9: nAck goes low. */
188 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
189 if (parport_wait_peripheral (port,
190 PARPORT_STATUS_ACK, 0)) {
191 /* Timeout -- no more data? */
192 DPRINTK (KERN_DEBUG
193 "%s: Nibble timeout at event 9 (%d bytes)\n",
194 port->name, i/2);
195 break;
199 /* Read a nibble. */
200 nibble = parport_read_status (port) >> 3;
201 nibble &= ~8;
202 if ((nibble & 0x10) == 0)
203 nibble |= 8;
204 nibble &= 0xf;
206 /* Event 10: Set nAutoFd high. */
207 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
209 /* Event 11: nAck goes high. */
210 if (parport_wait_peripheral (port,
211 PARPORT_STATUS_ACK,
212 PARPORT_STATUS_ACK)) {
213 /* Timeout -- no more data? */
214 DPRINTK (KERN_DEBUG
215 "%s: Nibble timeout at event 11\n",
216 port->name);
217 break;
220 if (i & 1) {
221 /* Second nibble */
222 byte |= nibble << 4;
223 *buf++ = byte;
224 } else
225 byte = nibble;
228 i /= 2; /* i is now in bytes */
230 if (i == len) {
231 /* Read the last nibble without checking data avail. */
232 port = port->physport;
233 if (parport_read_status (port) & PARPORT_STATUS_ERROR)
234 port->ieee1284.phase = IEEE1284_PH_HBUSY_DNA;
235 else
236 port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
239 return i;
240 #endif /* IEEE1284 support */
243 /* Byte mode. */
244 size_t parport_ieee1284_read_byte (struct parport *port,
245 void *buffer, size_t len,
246 int flags)
248 #ifndef CONFIG_PARPORT_1284
249 return 0;
250 #else
251 unsigned char *buf = buffer;
252 ssize_t count = 0;
254 for (count = 0; count < len; count++) {
255 unsigned char byte;
257 /* Data available? */
258 if (parport_read_status (port) & PARPORT_STATUS_ERROR) {
259 port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DNA;
260 DPRINTK (KERN_DEBUG
261 "%s: No more byte data (%Zd bytes)\n",
262 port->name, count);
264 /* Go to reverse idle phase. */
265 parport_frob_control (port,
266 PARPORT_CONTROL_AUTOFD,
267 PARPORT_CONTROL_AUTOFD);
268 port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE;
269 break;
272 /* Event 14: Place data bus in high impedance state. */
273 parport_data_reverse (port);
275 /* Event 7: Set nAutoFd low. */
276 parport_frob_control (port,
277 PARPORT_CONTROL_AUTOFD,
278 PARPORT_CONTROL_AUTOFD);
280 /* Event 9: nAck goes low. */
281 port->physport->ieee1284.phase = IEEE1284_PH_REV_DATA;
282 if (parport_wait_peripheral (port,
283 PARPORT_STATUS_ACK,
284 0)) {
285 /* Timeout -- no more data? */
286 parport_frob_control (port, PARPORT_CONTROL_AUTOFD,
288 DPRINTK (KERN_DEBUG "%s: Byte timeout at event 9\n",
289 port->name);
290 break;
293 byte = parport_read_data (port);
294 *buf++ = byte;
296 /* Event 10: Set nAutoFd high */
297 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
299 /* Event 11: nAck goes high. */
300 if (parport_wait_peripheral (port,
301 PARPORT_STATUS_ACK,
302 PARPORT_STATUS_ACK)) {
303 /* Timeout -- no more data? */
304 DPRINTK (KERN_DEBUG "%s: Byte timeout at event 11\n",
305 port->name);
306 break;
309 /* Event 16: Set nStrobe low. */
310 parport_frob_control (port,
311 PARPORT_CONTROL_STROBE,
312 PARPORT_CONTROL_STROBE);
313 udelay (5);
315 /* Event 17: Set nStrobe high. */
316 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
319 if (count == len) {
320 /* Read the last byte without checking data avail. */
321 port = port->physport;
322 if (parport_read_status (port) & PARPORT_STATUS_ERROR)
323 port->ieee1284.phase = IEEE1284_PH_HBUSY_DNA;
324 else
325 port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
328 return count;
329 #endif /* IEEE1284 support */
332 /*** *
333 * ECP Functions. *
334 * ***/
336 #ifdef CONFIG_PARPORT_1284
338 static inline
339 int ecp_forward_to_reverse (struct parport *port)
341 int retval;
343 /* Event 38: Set nAutoFd low */
344 parport_frob_control (port,
345 PARPORT_CONTROL_AUTOFD,
346 PARPORT_CONTROL_AUTOFD);
347 parport_data_reverse (port);
348 udelay (5);
350 /* Event 39: Set nInit low to initiate bus reversal */
351 parport_frob_control (port,
352 PARPORT_CONTROL_INIT,
355 /* Event 40: PError goes low */
356 retval = parport_wait_peripheral (port,
357 PARPORT_STATUS_PAPEROUT, 0);
359 if (!retval) {
360 DPRINTK (KERN_DEBUG "%s: ECP direction: reverse\n",
361 port->name);
362 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
365 return retval;
368 static inline
369 int ecp_reverse_to_forward (struct parport *port)
371 int retval;
373 /* Event 47: Set nInit high */
374 parport_frob_control (port,
375 PARPORT_CONTROL_INIT
376 | PARPORT_CONTROL_AUTOFD,
377 PARPORT_CONTROL_INIT
378 | PARPORT_CONTROL_AUTOFD);
380 /* Event 49: PError goes high */
381 retval = parport_wait_peripheral (port,
382 PARPORT_STATUS_PAPEROUT,
383 PARPORT_STATUS_PAPEROUT);
385 if (!retval) {
386 parport_data_forward (port);
387 DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n",
388 port->name);
389 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
392 return retval;
395 #endif /* IEEE1284 support */
397 /* ECP mode, forward channel, data. */
398 size_t parport_ieee1284_ecp_write_data (struct parport *port,
399 const void *buffer, size_t len,
400 int flags)
402 #ifndef CONFIG_PARPORT_1284
403 return 0;
404 #else
405 const unsigned char *buf = buffer;
406 size_t written;
407 int retry;
409 port = port->physport;
411 if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE)
412 if (ecp_reverse_to_forward (port))
413 return 0;
415 port->ieee1284.phase = IEEE1284_PH_FWD_DATA;
417 /* HostAck high (data, not command) */
418 parport_frob_control (port,
419 PARPORT_CONTROL_AUTOFD
420 | PARPORT_CONTROL_STROBE
421 | PARPORT_CONTROL_INIT,
422 PARPORT_CONTROL_INIT);
423 for (written = 0; written < len; written++, buf++) {
424 long expire = jiffies + port->cad->timeout;
425 unsigned char byte;
427 byte = *buf;
428 try_again:
429 parport_write_data (port, byte);
430 parport_frob_control (port, PARPORT_CONTROL_STROBE,
431 PARPORT_CONTROL_STROBE);
432 udelay (5);
433 for (retry = 0; retry < 100; retry++) {
434 if (!parport_wait_peripheral (port,
435 PARPORT_STATUS_BUSY, 0))
436 goto success;
438 if (signal_pending (current)) {
439 parport_frob_control (port,
440 PARPORT_CONTROL_STROBE,
442 break;
446 /* Time for Host Transfer Recovery (page 41 of IEEE1284) */
447 DPRINTK (KERN_DEBUG "%s: ECP transfer stalled!\n", port->name);
449 parport_frob_control (port, PARPORT_CONTROL_INIT,
450 PARPORT_CONTROL_INIT);
451 udelay (50);
452 if (parport_read_status (port) & PARPORT_STATUS_PAPEROUT) {
453 /* It's buggered. */
454 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
455 break;
458 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
459 udelay (50);
460 if (!(parport_read_status (port) & PARPORT_STATUS_PAPEROUT))
461 break;
463 DPRINTK (KERN_DEBUG "%s: Host transfer recovered\n",
464 port->name);
466 if (time_after_eq (jiffies, expire)) break;
467 goto try_again;
468 success:
469 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
470 udelay (5);
471 if (parport_wait_peripheral (port,
472 PARPORT_STATUS_BUSY,
473 PARPORT_STATUS_BUSY))
474 /* Peripheral hasn't accepted the data. */
475 break;
478 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
480 return written;
481 #endif /* IEEE1284 support */
484 /* ECP mode, reverse channel, data. */
485 size_t parport_ieee1284_ecp_read_data (struct parport *port,
486 void *buffer, size_t len, int flags)
488 #ifndef CONFIG_PARPORT_1284
489 return 0;
490 #else
491 struct pardevice *dev = port->cad;
492 unsigned char *buf = buffer;
493 int rle_count = 0; /* shut gcc up */
494 int rle = 0;
495 ssize_t count = 0;
497 port = port->physport;
499 if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE)
500 if (ecp_forward_to_reverse (port))
501 return 0;
503 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
505 /* Set HostAck low to start accepting data. */
506 parport_frob_control (port,
507 PARPORT_CONTROL_AUTOFD
508 | PARPORT_CONTROL_STROBE
509 | PARPORT_CONTROL_INIT,
510 PARPORT_CONTROL_AUTOFD);
511 while (count < len) {
512 long expire = jiffies + dev->timeout;
513 unsigned char byte;
514 int command;
516 /* Event 43: Peripheral sets nAck low. It can take as
517 long as it wants. */
518 while (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) {
519 /* The peripheral hasn't given us data in
520 35ms. If we have data to give back to the
521 caller, do it now. */
522 if (count)
523 goto out;
525 /* If we've used up all the time we were allowed,
526 give up altogether. */
527 if (!time_before (jiffies, expire))
528 goto out;
530 /* Yield the port for a while. */
531 if (count && dev->port->irq != PARPORT_IRQ_NONE) {
532 parport_release (dev);
533 __set_current_state (TASK_INTERRUPTIBLE);
534 schedule_timeout ((HZ + 24) / 25);
535 parport_claim_or_block (dev);
537 else
538 /* We must have the device claimed here. */
539 parport_wait_event (port, (HZ + 24) / 25);
541 /* Is there a signal pending? */
542 if (signal_pending (current))
543 goto out;
546 /* Is this a command? */
547 if (rle)
548 /* The last byte was a run-length count, so
549 this can't be as well. */
550 command = 0;
551 else
552 command = (parport_read_status (port) &
553 PARPORT_STATUS_BUSY) ? 1 : 0;
555 /* Read the data. */
556 byte = parport_read_data (port);
558 /* If this is a channel command, rather than an RLE
559 command or a normal data byte, don't accept it. */
560 if (command) {
561 if (byte & 0x80) {
562 DPRINTK (KERN_DEBUG "%s: stopping short at "
563 "channel command (%02x)\n",
564 port->name, byte);
565 goto out;
567 else if (port->ieee1284.mode != IEEE1284_MODE_ECPRLE)
568 DPRINTK (KERN_DEBUG "%s: device illegally "
569 "using RLE; accepting anyway\n",
570 port->name);
572 rle_count = byte + 1;
574 /* Are we allowed to read that many bytes? */
575 if (rle_count > (len - count)) {
576 DPRINTK (KERN_DEBUG "%s: leaving %d RLE bytes "
577 "for next time\n", port->name,
578 rle_count);
579 break;
582 rle = 1;
585 /* Event 44: Set HostAck high, acknowledging handshake. */
586 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
588 /* Event 45: The peripheral has 35ms to set nAck high. */
589 if (parport_wait_peripheral (port, PARPORT_STATUS_ACK,
590 PARPORT_STATUS_ACK)) {
591 /* It's gone wrong. Return what data we have
592 to the caller. */
593 DPRINTK (KERN_DEBUG "ECP read timed out at 45\n");
595 if (command)
596 printk (KERN_WARNING
597 "%s: command ignored (%02x)\n",
598 port->name, byte);
600 break;
603 /* Event 46: Set HostAck low and accept the data. */
604 parport_frob_control (port,
605 PARPORT_CONTROL_AUTOFD,
606 PARPORT_CONTROL_AUTOFD);
608 /* If we just read a run-length count, fetch the data. */
609 if (command)
610 continue;
612 /* If this is the byte after a run-length count, decompress. */
613 if (rle) {
614 rle = 0;
615 memset (buf, byte, rle_count);
616 buf += rle_count;
617 count += rle_count;
618 DPRINTK (KERN_DEBUG "%s: decompressed to %d bytes\n",
619 port->name, rle_count);
620 } else {
621 /* Normal data byte. */
622 *buf = byte;
623 buf++, count++;
627 out:
628 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
629 return count;
630 #endif /* IEEE1284 support */
633 /* ECP mode, forward channel, commands. */
634 size_t parport_ieee1284_ecp_write_addr (struct parport *port,
635 const void *buffer, size_t len,
636 int flags)
638 #ifndef CONFIG_PARPORT_1284
639 return 0;
640 #else
641 const unsigned char *buf = buffer;
642 size_t written;
643 int retry;
645 port = port->physport;
647 if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE)
648 if (ecp_reverse_to_forward (port))
649 return 0;
651 port->ieee1284.phase = IEEE1284_PH_FWD_DATA;
653 /* HostAck low (command, not data) */
654 parport_frob_control (port,
655 PARPORT_CONTROL_AUTOFD
656 | PARPORT_CONTROL_STROBE
657 | PARPORT_CONTROL_INIT,
658 PARPORT_CONTROL_AUTOFD
659 | PARPORT_CONTROL_INIT);
660 for (written = 0; written < len; written++, buf++) {
661 long expire = jiffies + port->cad->timeout;
662 unsigned char byte;
664 byte = *buf;
665 try_again:
666 parport_write_data (port, byte);
667 parport_frob_control (port, PARPORT_CONTROL_STROBE,
668 PARPORT_CONTROL_STROBE);
669 udelay (5);
670 for (retry = 0; retry < 100; retry++) {
671 if (!parport_wait_peripheral (port,
672 PARPORT_STATUS_BUSY, 0))
673 goto success;
675 if (signal_pending (current)) {
676 parport_frob_control (port,
677 PARPORT_CONTROL_STROBE,
679 break;
683 /* Time for Host Transfer Recovery (page 41 of IEEE1284) */
684 DPRINTK (KERN_DEBUG "%s: ECP transfer stalled!\n", port->name);
686 parport_frob_control (port, PARPORT_CONTROL_INIT,
687 PARPORT_CONTROL_INIT);
688 udelay (50);
689 if (parport_read_status (port) & PARPORT_STATUS_PAPEROUT) {
690 /* It's buggered. */
691 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
692 break;
695 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
696 udelay (50);
697 if (!(parport_read_status (port) & PARPORT_STATUS_PAPEROUT))
698 break;
700 DPRINTK (KERN_DEBUG "%s: Host transfer recovered\n",
701 port->name);
703 if (time_after_eq (jiffies, expire)) break;
704 goto try_again;
705 success:
706 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
707 udelay (5);
708 if (parport_wait_peripheral (port,
709 PARPORT_STATUS_BUSY,
710 PARPORT_STATUS_BUSY))
711 /* Peripheral hasn't accepted the data. */
712 break;
715 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
717 return written;
718 #endif /* IEEE1284 support */
721 /*** *
722 * EPP functions. *
723 * ***/
725 /* EPP mode, forward channel, data. */
726 size_t parport_ieee1284_epp_write_data (struct parport *port,
727 const void *buffer, size_t len,
728 int flags)
730 /* This is untested */
731 unsigned char *bp = (unsigned char *) buffer;
732 size_t ret = 0;
734 parport_frob_control (port,
735 PARPORT_CONTROL_STROBE |
736 PARPORT_CONTROL_AUTOFD |
737 PARPORT_CONTROL_SELECT,
738 PARPORT_CONTROL_STROBE |
739 PARPORT_CONTROL_SELECT);
740 port->ops->data_forward (port);
741 for (; len > 0; len--, bp++) {
742 /* Event 62: Write data and strobe data */
743 parport_write_data (port, *bp);
744 parport_frob_control (port, PARPORT_CONTROL_AUTOFD,
745 PARPORT_CONTROL_AUTOFD);
747 /* Event 58 */
748 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 10))
749 break;
751 /* Event 63 */
752 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
754 /* Event 60 */
755 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
756 PARPORT_STATUS_BUSY, 5))
757 break;
759 ret++;
762 /* Event 61 */
763 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
765 return ret;
768 /* EPP mode, reverse channel, data. */
769 size_t parport_ieee1284_epp_read_data (struct parport *port,
770 void *buffer, size_t len,
771 int flags)
773 /* This is untested. */
774 unsigned char *bp = (unsigned char *) buffer;
775 unsigned ret = 0;
777 parport_frob_control (port,
778 PARPORT_CONTROL_STROBE |
779 PARPORT_CONTROL_SELECT, 0);
780 port->ops->data_reverse (port);
781 for (; len > 0; len--, bp++) {
782 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
784 /* Event 58 */
785 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
786 PARPORT_STATUS_BUSY, 10))
787 break;
789 *bp = parport_read_data (port);
791 parport_frob_control (port, PARPORT_CONTROL_AUTOFD,
792 PARPORT_CONTROL_AUTOFD);
794 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 5))
795 break;
797 ret++;
799 port->ops->data_forward (port);
801 return ret;
804 /* EPP mode, forward channel, addresses. */
805 size_t parport_ieee1284_epp_write_addr (struct parport *port,
806 const void *buffer, size_t len,
807 int flags)
809 /* This is untested */
810 unsigned char *bp = (unsigned char *) buffer;
811 size_t ret = 0;
813 parport_frob_control (port,
814 PARPORT_CONTROL_STROBE |
815 PARPORT_CONTROL_SELECT |
816 PARPORT_CONTROL_AUTOFD,
817 PARPORT_CONTROL_STROBE |
818 PARPORT_CONTROL_SELECT);
819 port->ops->data_forward (port);
820 for (; len > 0; len--, bp++) {
821 /* Write data and assert nAStrb. */
822 parport_write_data (port, *bp);
823 parport_frob_control (port, PARPORT_CONTROL_SELECT,
824 PARPORT_CONTROL_SELECT);
826 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
827 PARPORT_STATUS_BUSY, 10))
828 break;
830 parport_frob_control (port, PARPORT_CONTROL_SELECT, 0);
832 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 5))
833 break;
835 ret++;
838 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
840 return ret;
843 /* EPP mode, reverse channel, addresses. */
844 size_t parport_ieee1284_epp_read_addr (struct parport *port,
845 void *buffer, size_t len,
846 int flags)
848 /* This is untested. */
849 unsigned char *bp = (unsigned char *) buffer;
850 unsigned ret = 0;
852 parport_frob_control (port,
853 PARPORT_CONTROL_STROBE |
854 PARPORT_CONTROL_AUTOFD, 0);
855 port->ops->data_reverse (port);
856 for (; len > 0; len--, bp++) {
857 parport_frob_control (port, PARPORT_CONTROL_SELECT, 0);
859 /* Event 58 */
860 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
861 PARPORT_STATUS_BUSY, 10))
862 break;
864 *bp = parport_read_data (port);
866 parport_frob_control (port, PARPORT_CONTROL_SELECT,
867 PARPORT_CONTROL_SELECT);
869 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 5))
870 break;
872 ret++;
874 port->ops->data_forward (port);
876 return ret;