[PATCH] kprobes: Allow multiple kprobes at the same address
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / parport / ieee1284_ops.c
blob6624278c6ed86e494d04f53345b1154fcb1c7c79
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
13 * Software emulated EPP fixes, Fred Barnes, 04/2001.
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/parport.h>
20 #include <linux/delay.h>
21 #include <linux/sched.h>
22 #include <asm/uaccess.h>
24 #undef DEBUG /* undef me for production */
26 #ifdef CONFIG_LP_CONSOLE
27 #undef DEBUG /* Don't want a garbled console */
28 #endif
30 #ifdef DEBUG
31 #define DPRINTK(stuff...) printk (stuff)
32 #else
33 #define DPRINTK(stuff...)
34 #endif
36 /*** *
37 * One-way data transfer functions. *
38 * ***/
40 /* Compatibility mode. */
41 size_t parport_ieee1284_write_compat (struct parport *port,
42 const void *buffer, size_t len,
43 int flags)
45 int no_irq = 1;
46 ssize_t count = 0;
47 const unsigned char *addr = buffer;
48 unsigned char byte;
49 struct pardevice *dev = port->physport->cad;
50 unsigned char ctl = (PARPORT_CONTROL_SELECT
51 | PARPORT_CONTROL_INIT);
53 if (port->irq != PARPORT_IRQ_NONE) {
54 parport_enable_irq (port);
55 no_irq = 0;
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 unsigned 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 && 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 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
196 break;
200 /* Read a nibble. */
201 nibble = parport_read_status (port) >> 3;
202 nibble &= ~8;
203 if ((nibble & 0x10) == 0)
204 nibble |= 8;
205 nibble &= 0xf;
207 /* Event 10: Set nAutoFd high. */
208 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
210 /* Event 11: nAck goes high. */
211 if (parport_wait_peripheral (port,
212 PARPORT_STATUS_ACK,
213 PARPORT_STATUS_ACK)) {
214 /* Timeout -- no more data? */
215 DPRINTK (KERN_DEBUG
216 "%s: Nibble timeout at event 11\n",
217 port->name);
218 break;
221 if (i & 1) {
222 /* Second nibble */
223 byte |= nibble << 4;
224 *buf++ = byte;
225 } else
226 byte = nibble;
229 i /= 2; /* i is now in bytes */
231 if (i == len) {
232 /* Read the last nibble without checking data avail. */
233 port = port->physport;
234 if (parport_read_status (port) & PARPORT_STATUS_ERROR)
235 port->ieee1284.phase = IEEE1284_PH_HBUSY_DNA;
236 else
237 port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
240 return i;
241 #endif /* IEEE1284 support */
244 /* Byte mode. */
245 size_t parport_ieee1284_read_byte (struct parport *port,
246 void *buffer, size_t len,
247 int flags)
249 #ifndef CONFIG_PARPORT_1284
250 return 0;
251 #else
252 unsigned char *buf = buffer;
253 ssize_t count = 0;
255 for (count = 0; count < len; count++) {
256 unsigned char byte;
258 /* Data available? */
259 if (parport_read_status (port) & PARPORT_STATUS_ERROR) {
260 port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DNA;
261 DPRINTK (KERN_DEBUG
262 "%s: No more byte data (%Zd bytes)\n",
263 port->name, count);
265 /* Go to reverse idle phase. */
266 parport_frob_control (port,
267 PARPORT_CONTROL_AUTOFD,
268 PARPORT_CONTROL_AUTOFD);
269 port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE;
270 break;
273 /* Event 14: Place data bus in high impedance state. */
274 parport_data_reverse (port);
276 /* Event 7: Set nAutoFd low. */
277 parport_frob_control (port,
278 PARPORT_CONTROL_AUTOFD,
279 PARPORT_CONTROL_AUTOFD);
281 /* Event 9: nAck goes low. */
282 port->physport->ieee1284.phase = IEEE1284_PH_REV_DATA;
283 if (parport_wait_peripheral (port,
284 PARPORT_STATUS_ACK,
285 0)) {
286 /* Timeout -- no more data? */
287 parport_frob_control (port, PARPORT_CONTROL_AUTOFD,
289 DPRINTK (KERN_DEBUG "%s: Byte timeout at event 9\n",
290 port->name);
291 break;
294 byte = parport_read_data (port);
295 *buf++ = byte;
297 /* Event 10: Set nAutoFd high */
298 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
300 /* Event 11: nAck goes high. */
301 if (parport_wait_peripheral (port,
302 PARPORT_STATUS_ACK,
303 PARPORT_STATUS_ACK)) {
304 /* Timeout -- no more data? */
305 DPRINTK (KERN_DEBUG "%s: Byte timeout at event 11\n",
306 port->name);
307 break;
310 /* Event 16: Set nStrobe low. */
311 parport_frob_control (port,
312 PARPORT_CONTROL_STROBE,
313 PARPORT_CONTROL_STROBE);
314 udelay (5);
316 /* Event 17: Set nStrobe high. */
317 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
320 if (count == len) {
321 /* Read the last byte without checking data avail. */
322 port = port->physport;
323 if (parport_read_status (port) & PARPORT_STATUS_ERROR)
324 port->ieee1284.phase = IEEE1284_PH_HBUSY_DNA;
325 else
326 port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
329 return count;
330 #endif /* IEEE1284 support */
333 /*** *
334 * ECP Functions. *
335 * ***/
337 #ifdef CONFIG_PARPORT_1284
339 static inline
340 int ecp_forward_to_reverse (struct parport *port)
342 int retval;
344 /* Event 38: Set nAutoFd low */
345 parport_frob_control (port,
346 PARPORT_CONTROL_AUTOFD,
347 PARPORT_CONTROL_AUTOFD);
348 parport_data_reverse (port);
349 udelay (5);
351 /* Event 39: Set nInit low to initiate bus reversal */
352 parport_frob_control (port,
353 PARPORT_CONTROL_INIT,
356 /* Event 40: PError goes low */
357 retval = parport_wait_peripheral (port,
358 PARPORT_STATUS_PAPEROUT, 0);
360 if (!retval) {
361 DPRINTK (KERN_DEBUG "%s: ECP direction: reverse\n",
362 port->name);
363 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
364 } else {
365 DPRINTK (KERN_DEBUG "%s: ECP direction: failed to reverse\n",
366 port->name);
367 port->ieee1284.phase = IEEE1284_PH_ECP_DIR_UNKNOWN;
370 return retval;
373 static inline
374 int ecp_reverse_to_forward (struct parport *port)
376 int retval;
378 /* Event 47: Set nInit high */
379 parport_frob_control (port,
380 PARPORT_CONTROL_INIT
381 | PARPORT_CONTROL_AUTOFD,
382 PARPORT_CONTROL_INIT
383 | PARPORT_CONTROL_AUTOFD);
385 /* Event 49: PError goes high */
386 retval = parport_wait_peripheral (port,
387 PARPORT_STATUS_PAPEROUT,
388 PARPORT_STATUS_PAPEROUT);
390 if (!retval) {
391 parport_data_forward (port);
392 DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n",
393 port->name);
394 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
395 } else {
396 DPRINTK (KERN_DEBUG
397 "%s: ECP direction: failed to switch forward\n",
398 port->name);
399 port->ieee1284.phase = IEEE1284_PH_ECP_DIR_UNKNOWN;
403 return retval;
406 #endif /* IEEE1284 support */
408 /* ECP mode, forward channel, data. */
409 size_t parport_ieee1284_ecp_write_data (struct parport *port,
410 const void *buffer, size_t len,
411 int flags)
413 #ifndef CONFIG_PARPORT_1284
414 return 0;
415 #else
416 const unsigned char *buf = buffer;
417 size_t written;
418 int retry;
420 port = port->physport;
422 if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE)
423 if (ecp_reverse_to_forward (port))
424 return 0;
426 port->ieee1284.phase = IEEE1284_PH_FWD_DATA;
428 /* HostAck high (data, not command) */
429 parport_frob_control (port,
430 PARPORT_CONTROL_AUTOFD
431 | PARPORT_CONTROL_STROBE
432 | PARPORT_CONTROL_INIT,
433 PARPORT_CONTROL_INIT);
434 for (written = 0; written < len; written++, buf++) {
435 unsigned long expire = jiffies + port->cad->timeout;
436 unsigned char byte;
438 byte = *buf;
439 try_again:
440 parport_write_data (port, byte);
441 parport_frob_control (port, PARPORT_CONTROL_STROBE,
442 PARPORT_CONTROL_STROBE);
443 udelay (5);
444 for (retry = 0; retry < 100; retry++) {
445 if (!parport_wait_peripheral (port,
446 PARPORT_STATUS_BUSY, 0))
447 goto success;
449 if (signal_pending (current)) {
450 parport_frob_control (port,
451 PARPORT_CONTROL_STROBE,
453 break;
457 /* Time for Host Transfer Recovery (page 41 of IEEE1284) */
458 DPRINTK (KERN_DEBUG "%s: ECP transfer stalled!\n", port->name);
460 parport_frob_control (port, PARPORT_CONTROL_INIT,
461 PARPORT_CONTROL_INIT);
462 udelay (50);
463 if (parport_read_status (port) & PARPORT_STATUS_PAPEROUT) {
464 /* It's buggered. */
465 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
466 break;
469 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
470 udelay (50);
471 if (!(parport_read_status (port) & PARPORT_STATUS_PAPEROUT))
472 break;
474 DPRINTK (KERN_DEBUG "%s: Host transfer recovered\n",
475 port->name);
477 if (time_after_eq (jiffies, expire)) break;
478 goto try_again;
479 success:
480 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
481 udelay (5);
482 if (parport_wait_peripheral (port,
483 PARPORT_STATUS_BUSY,
484 PARPORT_STATUS_BUSY))
485 /* Peripheral hasn't accepted the data. */
486 break;
489 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
491 return written;
492 #endif /* IEEE1284 support */
495 /* ECP mode, reverse channel, data. */
496 size_t parport_ieee1284_ecp_read_data (struct parport *port,
497 void *buffer, size_t len, int flags)
499 #ifndef CONFIG_PARPORT_1284
500 return 0;
501 #else
502 struct pardevice *dev = port->cad;
503 unsigned char *buf = buffer;
504 int rle_count = 0; /* shut gcc up */
505 unsigned char ctl;
506 int rle = 0;
507 ssize_t count = 0;
509 port = port->physport;
511 if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE)
512 if (ecp_forward_to_reverse (port))
513 return 0;
515 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
517 /* Set HostAck low to start accepting data. */
518 ctl = parport_read_control (port);
519 ctl &= ~(PARPORT_CONTROL_STROBE | PARPORT_CONTROL_INIT |
520 PARPORT_CONTROL_AUTOFD);
521 parport_write_control (port,
522 ctl | PARPORT_CONTROL_AUTOFD);
523 while (count < len) {
524 unsigned long expire = jiffies + dev->timeout;
525 unsigned char byte;
526 int command;
528 /* Event 43: Peripheral sets nAck low. It can take as
529 long as it wants. */
530 while (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) {
531 /* The peripheral hasn't given us data in
532 35ms. If we have data to give back to the
533 caller, do it now. */
534 if (count)
535 goto out;
537 /* If we've used up all the time we were allowed,
538 give up altogether. */
539 if (!time_before (jiffies, expire))
540 goto out;
542 /* Yield the port for a while. */
543 if (count && dev->port->irq != PARPORT_IRQ_NONE) {
544 parport_release (dev);
545 __set_current_state (TASK_INTERRUPTIBLE);
546 schedule_timeout ((HZ + 24) / 25);
547 parport_claim_or_block (dev);
549 else
550 /* We must have the device claimed here. */
551 parport_wait_event (port, (HZ + 24) / 25);
553 /* Is there a signal pending? */
554 if (signal_pending (current))
555 goto out;
558 /* Is this a command? */
559 if (rle)
560 /* The last byte was a run-length count, so
561 this can't be as well. */
562 command = 0;
563 else
564 command = (parport_read_status (port) &
565 PARPORT_STATUS_BUSY) ? 1 : 0;
567 /* Read the data. */
568 byte = parport_read_data (port);
570 /* If this is a channel command, rather than an RLE
571 command or a normal data byte, don't accept it. */
572 if (command) {
573 if (byte & 0x80) {
574 DPRINTK (KERN_DEBUG "%s: stopping short at "
575 "channel command (%02x)\n",
576 port->name, byte);
577 goto out;
579 else if (port->ieee1284.mode != IEEE1284_MODE_ECPRLE)
580 DPRINTK (KERN_DEBUG "%s: device illegally "
581 "using RLE; accepting anyway\n",
582 port->name);
584 rle_count = byte + 1;
586 /* Are we allowed to read that many bytes? */
587 if (rle_count > (len - count)) {
588 DPRINTK (KERN_DEBUG "%s: leaving %d RLE bytes "
589 "for next time\n", port->name,
590 rle_count);
591 break;
594 rle = 1;
597 /* Event 44: Set HostAck high, acknowledging handshake. */
598 parport_write_control (port, ctl);
600 /* Event 45: The peripheral has 35ms to set nAck high. */
601 if (parport_wait_peripheral (port, PARPORT_STATUS_ACK,
602 PARPORT_STATUS_ACK)) {
603 /* It's gone wrong. Return what data we have
604 to the caller. */
605 DPRINTK (KERN_DEBUG "ECP read timed out at 45\n");
607 if (command)
608 printk (KERN_WARNING
609 "%s: command ignored (%02x)\n",
610 port->name, byte);
612 break;
615 /* Event 46: Set HostAck low and accept the data. */
616 parport_write_control (port,
617 ctl | PARPORT_CONTROL_AUTOFD);
619 /* If we just read a run-length count, fetch the data. */
620 if (command)
621 continue;
623 /* If this is the byte after a run-length count, decompress. */
624 if (rle) {
625 rle = 0;
626 memset (buf, byte, rle_count);
627 buf += rle_count;
628 count += rle_count;
629 DPRINTK (KERN_DEBUG "%s: decompressed to %d bytes\n",
630 port->name, rle_count);
631 } else {
632 /* Normal data byte. */
633 *buf = byte;
634 buf++, count++;
638 out:
639 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
640 return count;
641 #endif /* IEEE1284 support */
644 /* ECP mode, forward channel, commands. */
645 size_t parport_ieee1284_ecp_write_addr (struct parport *port,
646 const void *buffer, size_t len,
647 int flags)
649 #ifndef CONFIG_PARPORT_1284
650 return 0;
651 #else
652 const unsigned char *buf = buffer;
653 size_t written;
654 int retry;
656 port = port->physport;
658 if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE)
659 if (ecp_reverse_to_forward (port))
660 return 0;
662 port->ieee1284.phase = IEEE1284_PH_FWD_DATA;
664 /* HostAck low (command, not data) */
665 parport_frob_control (port,
666 PARPORT_CONTROL_AUTOFD
667 | PARPORT_CONTROL_STROBE
668 | PARPORT_CONTROL_INIT,
669 PARPORT_CONTROL_AUTOFD
670 | PARPORT_CONTROL_INIT);
671 for (written = 0; written < len; written++, buf++) {
672 unsigned long expire = jiffies + port->cad->timeout;
673 unsigned char byte;
675 byte = *buf;
676 try_again:
677 parport_write_data (port, byte);
678 parport_frob_control (port, PARPORT_CONTROL_STROBE,
679 PARPORT_CONTROL_STROBE);
680 udelay (5);
681 for (retry = 0; retry < 100; retry++) {
682 if (!parport_wait_peripheral (port,
683 PARPORT_STATUS_BUSY, 0))
684 goto success;
686 if (signal_pending (current)) {
687 parport_frob_control (port,
688 PARPORT_CONTROL_STROBE,
690 break;
694 /* Time for Host Transfer Recovery (page 41 of IEEE1284) */
695 DPRINTK (KERN_DEBUG "%s: ECP transfer stalled!\n", port->name);
697 parport_frob_control (port, PARPORT_CONTROL_INIT,
698 PARPORT_CONTROL_INIT);
699 udelay (50);
700 if (parport_read_status (port) & PARPORT_STATUS_PAPEROUT) {
701 /* It's buggered. */
702 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
703 break;
706 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
707 udelay (50);
708 if (!(parport_read_status (port) & PARPORT_STATUS_PAPEROUT))
709 break;
711 DPRINTK (KERN_DEBUG "%s: Host transfer recovered\n",
712 port->name);
714 if (time_after_eq (jiffies, expire)) break;
715 goto try_again;
716 success:
717 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
718 udelay (5);
719 if (parport_wait_peripheral (port,
720 PARPORT_STATUS_BUSY,
721 PARPORT_STATUS_BUSY))
722 /* Peripheral hasn't accepted the data. */
723 break;
726 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
728 return written;
729 #endif /* IEEE1284 support */
732 /*** *
733 * EPP functions. *
734 * ***/
736 /* EPP mode, forward channel, data. */
737 size_t parport_ieee1284_epp_write_data (struct parport *port,
738 const void *buffer, size_t len,
739 int flags)
741 unsigned char *bp = (unsigned char *) buffer;
742 size_t ret = 0;
744 /* set EPP idle state (just to make sure) with strobe low */
745 parport_frob_control (port,
746 PARPORT_CONTROL_STROBE |
747 PARPORT_CONTROL_AUTOFD |
748 PARPORT_CONTROL_SELECT |
749 PARPORT_CONTROL_INIT,
750 PARPORT_CONTROL_STROBE |
751 PARPORT_CONTROL_INIT);
752 port->ops->data_forward (port);
753 for (; len > 0; len--, bp++) {
754 /* Event 62: Write data and set autofd low */
755 parport_write_data (port, *bp);
756 parport_frob_control (port, PARPORT_CONTROL_AUTOFD,
757 PARPORT_CONTROL_AUTOFD);
759 /* Event 58: wait for busy (nWait) to go high */
760 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 10))
761 break;
763 /* Event 63: set nAutoFd (nDStrb) high */
764 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
766 /* Event 60: wait for busy (nWait) to go low */
767 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
768 PARPORT_STATUS_BUSY, 5))
769 break;
771 ret++;
774 /* Event 61: set strobe (nWrite) high */
775 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
777 return ret;
780 /* EPP mode, reverse channel, data. */
781 size_t parport_ieee1284_epp_read_data (struct parport *port,
782 void *buffer, size_t len,
783 int flags)
785 unsigned char *bp = (unsigned char *) buffer;
786 unsigned ret = 0;
788 /* set EPP idle state (just to make sure) with strobe high */
789 parport_frob_control (port,
790 PARPORT_CONTROL_STROBE |
791 PARPORT_CONTROL_AUTOFD |
792 PARPORT_CONTROL_SELECT |
793 PARPORT_CONTROL_INIT,
794 PARPORT_CONTROL_INIT);
795 port->ops->data_reverse (port);
796 for (; len > 0; len--, bp++) {
797 /* Event 67: set nAutoFd (nDStrb) low */
798 parport_frob_control (port,
799 PARPORT_CONTROL_AUTOFD,
800 PARPORT_CONTROL_AUTOFD);
801 /* Event 58: wait for Busy to go high */
802 if (parport_wait_peripheral (port, PARPORT_STATUS_BUSY, 0)) {
803 break;
806 *bp = parport_read_data (port);
808 /* Event 63: set nAutoFd (nDStrb) high */
809 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
811 /* Event 60: wait for Busy to go low */
812 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
813 PARPORT_STATUS_BUSY, 5)) {
814 break;
817 ret++;
819 port->ops->data_forward (port);
821 return ret;
824 /* EPP mode, forward channel, addresses. */
825 size_t parport_ieee1284_epp_write_addr (struct parport *port,
826 const void *buffer, size_t len,
827 int flags)
829 unsigned char *bp = (unsigned char *) buffer;
830 size_t ret = 0;
832 /* set EPP idle state (just to make sure) with strobe low */
833 parport_frob_control (port,
834 PARPORT_CONTROL_STROBE |
835 PARPORT_CONTROL_AUTOFD |
836 PARPORT_CONTROL_SELECT |
837 PARPORT_CONTROL_INIT,
838 PARPORT_CONTROL_STROBE |
839 PARPORT_CONTROL_INIT);
840 port->ops->data_forward (port);
841 for (; len > 0; len--, bp++) {
842 /* Event 56: Write data and set nAStrb low. */
843 parport_write_data (port, *bp);
844 parport_frob_control (port, PARPORT_CONTROL_SELECT,
845 PARPORT_CONTROL_SELECT);
847 /* Event 58: wait for busy (nWait) to go high */
848 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 10))
849 break;
851 /* Event 59: set nAStrb high */
852 parport_frob_control (port, PARPORT_CONTROL_SELECT, 0);
854 /* Event 60: wait for busy (nWait) to go low */
855 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
856 PARPORT_STATUS_BUSY, 5))
857 break;
859 ret++;
862 /* Event 61: set strobe (nWrite) high */
863 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
865 return ret;
868 /* EPP mode, reverse channel, addresses. */
869 size_t parport_ieee1284_epp_read_addr (struct parport *port,
870 void *buffer, size_t len,
871 int flags)
873 unsigned char *bp = (unsigned char *) buffer;
874 unsigned ret = 0;
876 /* Set EPP idle state (just to make sure) with strobe high */
877 parport_frob_control (port,
878 PARPORT_CONTROL_STROBE |
879 PARPORT_CONTROL_AUTOFD |
880 PARPORT_CONTROL_SELECT |
881 PARPORT_CONTROL_INIT,
882 PARPORT_CONTROL_INIT);
883 port->ops->data_reverse (port);
884 for (; len > 0; len--, bp++) {
885 /* Event 64: set nSelectIn (nAStrb) low */
886 parport_frob_control (port, PARPORT_CONTROL_SELECT,
887 PARPORT_CONTROL_SELECT);
889 /* Event 58: wait for Busy to go high */
890 if (parport_wait_peripheral (port, PARPORT_STATUS_BUSY, 0)) {
891 break;
894 *bp = parport_read_data (port);
896 /* Event 59: set nSelectIn (nAStrb) high */
897 parport_frob_control (port, PARPORT_CONTROL_SELECT,
898 PARPORT_CONTROL_SELECT);
900 /* Event 60: wait for Busy to go low */
901 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
902 PARPORT_STATUS_BUSY, 5))
903 break;
905 ret++;
907 port->ops->data_forward (port);
909 return ret;
912 EXPORT_SYMBOL(parport_ieee1284_ecp_write_data);
913 EXPORT_SYMBOL(parport_ieee1284_ecp_read_data);
914 EXPORT_SYMBOL(parport_ieee1284_ecp_write_addr);
915 EXPORT_SYMBOL(parport_ieee1284_write_compat);
916 EXPORT_SYMBOL(parport_ieee1284_read_nibble);
917 EXPORT_SYMBOL(parport_ieee1284_read_byte);
918 EXPORT_SYMBOL(parport_ieee1284_epp_write_data);
919 EXPORT_SYMBOL(parport_ieee1284_epp_read_data);
920 EXPORT_SYMBOL(parport_ieee1284_epp_write_addr);
921 EXPORT_SYMBOL(parport_ieee1284_epp_read_addr);