kernel: Don't include <sys/mutex.h> in some drivers that don't need it.
[dragonfly.git] / sys / bus / ppbus / ppb_1284.c
blobc238a6b7773bc566fdef88035675f5ca76373972
1 /*-
2 * Copyright (c) 1997 Nicolas Souchu
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
26 * $FreeBSD: src/sys/dev/ppbus/ppb_1284.c,v 1.11 2000/01/14 08:03:14 nsouch Exp $
30 * General purpose routines for the IEEE1284-1994 Standard
33 #include "opt_ppb_1284.h"
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/bus.h>
39 #include <machine/clock.h>
41 #include "ppbconf.h"
42 #include "ppb_1284.h"
44 #include "ppbus_if.h"
46 #include "ppbio.h"
48 #define DEVTOSOFTC(dev) ((struct ppb_data *)device_get_softc(dev))
51 * do_1284_wait()
53 * Wait for the peripherial up to 40ms
55 static int
56 do_1284_wait(device_t bus, char mask, char status)
58 return (ppb_poll_bus(bus, 4, mask, status, PPB_NOINTR | PPB_POLL));
61 static int
62 do_peripheral_wait(device_t bus, char mask, char status)
64 return (ppb_poll_bus(bus, 100, mask, status, PPB_NOINTR | PPB_POLL));
67 #define nibble2char(s) (((s & ~nACK) >> 3) | (~s & nBUSY) >> 4)
70 * ppb_1284_reset_error()
72 * Unconditionaly reset the error field
74 static int
75 ppb_1284_reset_error(device_t bus, int state)
77 struct ppb_data *ppb = DEVTOSOFTC(bus);
79 ppb->error = PPB_NO_ERROR;
80 ppb->state = state;
82 return (0);
86 * ppb_1284_get_state()
88 * Get IEEE1284 state
90 int
91 ppb_1284_get_state(device_t bus)
93 return (DEVTOSOFTC(bus)->state);
97 * ppb_1284_set_state()
99 * Change IEEE1284 state if no error occured
102 ppb_1284_set_state(device_t bus, int state)
104 struct ppb_data *ppb = DEVTOSOFTC(bus);
106 /* call ppb_1284_reset_error() if you absolutly want to change
107 * the state from PPB_ERROR to another */
108 if ((ppb->state != PPB_ERROR) &&
109 (ppb->error == PPB_NO_ERROR)) {
110 ppb->state = state;
111 ppb->error = PPB_NO_ERROR;
114 return (0);
117 static int
118 ppb_1284_set_error(device_t bus, int error, int event)
120 struct ppb_data *ppb = DEVTOSOFTC(bus);
122 /* do not accumulate errors */
123 if ((ppb->error == PPB_NO_ERROR) &&
124 (ppb->state != PPB_ERROR)) {
125 ppb->error = error;
126 ppb->state = PPB_ERROR;
129 #ifdef DEBUG_1284
130 kprintf("ppb1284: error=%d status=0x%x event=%d\n", error,
131 ppb_rstr(bus) & 0xff, event);
132 #endif
134 return (0);
138 * ppb_request_mode()
140 * Converts mode+options into ext. value
142 static int
143 ppb_request_mode(int mode, int options)
145 int request_mode = 0;
147 if (options & PPB_EXTENSIBILITY_LINK) {
148 request_mode = EXT_LINK_1284_NORMAL;
150 } else {
151 switch (mode) {
152 case PPB_NIBBLE:
153 request_mode = (options & PPB_REQUEST_ID) ?
154 NIBBLE_1284_REQUEST_ID :
155 NIBBLE_1284_NORMAL;
156 break;
157 case PPB_PS2:
158 request_mode = (options & PPB_REQUEST_ID) ?
159 BYTE_1284_REQUEST_ID :
160 BYTE_1284_NORMAL;
161 break;
162 case PPB_ECP:
163 if (options & PPB_USE_RLE)
164 request_mode = (options & PPB_REQUEST_ID) ?
165 ECP_1284_RLE_REQUEST_ID :
166 ECP_1284_RLE;
167 else
168 request_mode = (options & PPB_REQUEST_ID) ?
169 ECP_1284_REQUEST_ID :
170 ECP_1284_NORMAL;
171 break;
172 case PPB_EPP:
173 request_mode = EPP_1284_NORMAL;
174 break;
175 default:
176 panic("%s: unsupported mode %d", __func__, mode);
180 return (request_mode);
184 * ppb_peripheral_negociate()
186 * Negociate the peripheral side
189 ppb_peripheral_negociate(device_t bus, int mode, int options)
191 int spin, request_mode, error = 0;
192 char r;
194 ppb_set_mode(bus, PPB_COMPATIBLE);
195 ppb_1284_set_state(bus, PPB_PERIPHERAL_NEGOCIATION);
197 /* compute ext. value */
198 request_mode = ppb_request_mode(mode, options);
200 /* wait host */
201 spin = 10;
202 while (spin-- && (ppb_rstr(bus) & nBUSY))
203 DELAY(1);
205 /* check termination */
206 if (!(ppb_rstr(bus) & SELECT) || !spin) {
207 error = ENODEV;
208 goto error;
211 /* Event 4 - read ext. value */
212 r = ppb_rdtr(bus);
214 /* nibble mode is not supported */
215 if ((r == (char)request_mode) ||
216 (r == NIBBLE_1284_NORMAL)) {
218 /* Event 5 - restore direction bit, no data avail */
219 ppb_wctr(bus, (STROBE | nINIT) & ~(SELECTIN));
220 DELAY(1);
222 /* Event 6 */
223 ppb_wctr(bus, (nINIT) & ~(SELECTIN | STROBE));
225 if (r == NIBBLE_1284_NORMAL) {
226 #ifdef DEBUG_1284
227 kprintf("R");
228 #endif
229 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 4);
230 error = EINVAL;
231 goto error;
232 } else {
233 ppb_1284_set_state(bus, PPB_PERIPHERAL_IDLE);
234 switch (r) {
235 case BYTE_1284_NORMAL:
236 ppb_set_mode(bus, PPB_BYTE);
237 break;
238 default:
239 break;
241 #ifdef DEBUG_1284
242 kprintf("A");
243 #endif
244 /* negociation succeeds */
246 } else {
247 /* Event 5 - mode not supported */
248 ppb_wctr(bus, SELECTIN);
249 DELAY(1);
251 /* Event 6 */
252 ppb_wctr(bus, (SELECTIN) & ~(STROBE | nINIT));
253 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 4);
255 #ifdef DEBUG_1284
256 kprintf("r");
257 #endif
258 error = EINVAL;
259 goto error;
262 return (0);
264 error:
265 ppb_peripheral_terminate(bus, PPB_WAIT);
266 return (error);
270 * ppb_peripheral_terminate()
272 * Terminate peripheral transfer side
274 * Always return 0 in compatible mode
277 ppb_peripheral_terminate(device_t bus, int how)
279 int error = 0;
281 #ifdef DEBUG_1284
282 kprintf("t");
283 #endif
285 ppb_1284_set_state(bus, PPB_PERIPHERAL_TERMINATION);
287 /* Event 22 - wait up to host response time (1s) */
288 if ((error = do_peripheral_wait(bus, SELECT | nBUSY, 0))) {
289 ppb_1284_set_error(bus, PPB_TIMEOUT, 22);
290 goto error;
293 /* Event 24 */
294 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
296 /* Event 25 - wait up to host response time (1s) */
297 if ((error = do_peripheral_wait(bus, nBUSY, nBUSY))) {
298 ppb_1284_set_error(bus, PPB_TIMEOUT, 25);
299 goto error;
302 /* Event 26 */
303 ppb_wctr(bus, (SELECTIN | nINIT | STROBE) & ~(AUTOFEED));
304 DELAY(1);
305 /* Event 27 */
306 ppb_wctr(bus, (SELECTIN | nINIT) & ~(STROBE | AUTOFEED));
308 /* Event 28 - wait up to host response time (1s) */
309 if ((error = do_peripheral_wait(bus, nBUSY, 0))) {
310 ppb_1284_set_error(bus, PPB_TIMEOUT, 28);
311 goto error;
314 error:
315 ppb_set_mode(bus, PPB_COMPATIBLE);
316 ppb_1284_set_state(bus, PPB_FORWARD_IDLE);
318 return (0);
322 * byte_peripheral_outbyte()
324 * Write 1 byte in BYTE mode
326 static int
327 byte_peripheral_outbyte(device_t bus, char *buffer, int last)
329 int error = 0;
331 /* Event 7 */
332 if ((error = do_1284_wait(bus, nBUSY, nBUSY))) {
333 ppb_1284_set_error(bus, PPB_TIMEOUT, 7);
334 goto error;
337 /* check termination */
338 if (!(ppb_rstr(bus) & SELECT)) {
339 ppb_peripheral_terminate(bus, PPB_WAIT);
340 goto error;
343 /* Event 15 - put byte on data lines */
344 #ifdef DEBUG_1284
345 kprintf("B");
346 #endif
347 ppb_wdtr(bus, *buffer);
349 /* Event 9 */
350 ppb_wctr(bus, (AUTOFEED | STROBE) & ~(nINIT | SELECTIN));
352 /* Event 10 - wait data read */
353 if ((error = do_peripheral_wait(bus, nBUSY, 0))) {
354 ppb_1284_set_error(bus, PPB_TIMEOUT, 16);
355 goto error;
358 /* Event 11 */
359 if (!last) {
360 ppb_wctr(bus, (AUTOFEED) & ~(nINIT | STROBE | SELECTIN));
361 } else {
362 ppb_wctr(bus, (nINIT) & ~(STROBE | SELECTIN | AUTOFEED));
365 #if 0
366 /* Event 16 - wait strobe */
367 if ((error = do_peripheral_wait(bus, nACK | nBUSY, 0))) {
368 ppb_1284_set_error(bus, PPB_TIMEOUT, 16);
369 goto error;
371 #endif
373 /* check termination */
374 if (!(ppb_rstr(bus) & SELECT)) {
375 ppb_peripheral_terminate(bus, PPB_WAIT);
376 goto error;
379 error:
380 return (error);
384 * byte_peripheral_write()
386 * Write n bytes in BYTE mode
389 byte_peripheral_write(device_t bus, char *buffer, int len, int *sent)
391 int error = 0, i;
392 char r;
394 ppb_1284_set_state(bus, PPB_PERIPHERAL_TRANSFER);
396 /* wait forever, the remote host is master and should initiate
397 * termination
399 for (i=0; i<len; i++) {
400 /* force remote nFAULT low to release the remote waiting
401 * process, if any
403 r = ppb_rctr(bus);
404 ppb_wctr(bus, r & ~nINIT);
406 #ifdef DEBUG_1284
407 kprintf("y");
408 #endif
409 /* Event 7 */
410 error = ppb_poll_bus(bus, PPB_FOREVER, nBUSY, nBUSY,
411 PPB_INTR);
413 if (error && error != EWOULDBLOCK)
414 goto error;
416 #ifdef DEBUG_1284
417 kprintf("b");
418 #endif
419 if ((error = byte_peripheral_outbyte(bus, buffer+i, (i == len-1))))
420 goto error;
422 error:
423 if (!error)
424 ppb_1284_set_state(bus, PPB_PERIPHERAL_IDLE);
426 *sent = i;
427 return (error);
431 * byte_1284_inbyte()
433 * Read 1 byte in BYTE mode
436 byte_1284_inbyte(device_t bus, char *buffer)
438 int error = 0;
440 /* Event 7 - ready to take data (nAUTO low) */
441 ppb_wctr(bus, (PCD | nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
443 /* Event 9 - peripheral set nAck low */
444 if ((error = do_1284_wait(bus, nACK, 0))) {
445 ppb_1284_set_error(bus, PPB_TIMEOUT, 9);
446 goto error;
449 /* read the byte */
450 *buffer = ppb_rdtr(bus);
452 /* Event 10 - data received, can't accept more */
453 ppb_wctr(bus, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN));
455 /* Event 11 - peripheral ack */
456 if ((error = do_1284_wait(bus, nACK, nACK))) {
457 ppb_1284_set_error(bus, PPB_TIMEOUT, 11);
458 goto error;
461 /* Event 16 - strobe */
462 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
463 DELAY(3);
464 ppb_wctr(bus, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN));
466 error:
467 return (error);
471 * nibble_1284_inbyte()
473 * Read 1 byte in NIBBLE mode
476 nibble_1284_inbyte(device_t bus, char *buffer)
478 char nibble[2];
479 int i, error;
481 for (i = 0; i < 2; i++) {
483 /* Event 7 - ready to take data (nAUTO low) */
484 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
486 /* Event 8 - peripheral writes the first nibble */
488 /* Event 9 - peripheral set nAck low */
489 if ((error = do_1284_wait(bus, nACK, 0))) {
490 ppb_1284_set_error(bus, PPB_TIMEOUT, 9);
491 goto error;
494 /* read nibble */
495 nibble[i] = ppb_rstr(bus);
497 /* Event 10 - ack, nibble received */
498 ppb_wctr(bus, nINIT & ~(AUTOFEED | STROBE | SELECTIN));
500 /* Event 11 - wait ack from peripherial */
501 if ((error = do_1284_wait(bus, nACK, nACK))) {
502 ppb_1284_set_error(bus, PPB_TIMEOUT, 11);
503 goto error;
507 *buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) |
508 (nibble2char(nibble[0]) & 0x0f);
510 error:
511 return (error);
515 * spp_1284_read()
517 * Read in IEEE1284 NIBBLE/BYTE mode
520 spp_1284_read(device_t bus, int mode, char *buffer, int max, int *read)
522 int error = 0, len = 0;
523 int terminate_after_transfer = 1;
524 int state;
526 *read = len = 0;
528 state = ppb_1284_get_state(bus);
530 switch (state) {
531 case PPB_FORWARD_IDLE:
532 if ((error = ppb_1284_negociate(bus, mode, 0)))
533 return (error);
534 break;
536 case PPB_REVERSE_IDLE:
537 terminate_after_transfer = 0;
538 break;
540 default:
541 ppb_1284_terminate(bus);
542 if ((error = ppb_1284_negociate(bus, mode, 0)))
543 return (error);
544 break;
547 while ((len < max) && !(ppb_rstr(bus) & (nFAULT))) {
549 ppb_1284_set_state(bus, PPB_REVERSE_TRANSFER);
551 #ifdef DEBUG_1284
552 kprintf("B");
553 #endif
555 switch (mode) {
556 case PPB_NIBBLE:
557 /* read a byte, error means no more data */
558 if (nibble_1284_inbyte(bus, buffer+len))
559 goto end_while;
560 break;
561 case PPB_BYTE:
562 if (byte_1284_inbyte(bus, buffer+len))
563 goto end_while;
564 break;
565 default:
566 error = EINVAL;
567 goto end_while;
569 len ++;
571 end_while:
573 if (!error)
574 ppb_1284_set_state(bus, PPB_REVERSE_IDLE);
576 *read = len;
578 if (terminate_after_transfer || error)
579 ppb_1284_terminate(bus);
581 return (error);
585 * ppb_1284_read_id()
589 ppb_1284_read_id(device_t bus, int mode, char *buffer,
590 int max, int *read)
592 int error = 0;
594 /* fill the buffer with 0s */
595 bzero(buffer, max);
597 switch (mode) {
598 case PPB_NIBBLE:
599 case PPB_ECP:
600 if ((error = ppb_1284_negociate(bus, PPB_NIBBLE, PPB_REQUEST_ID)))
601 return (error);
602 error = spp_1284_read(bus, PPB_NIBBLE, buffer, max, read);
603 break;
604 case PPB_BYTE:
605 if ((error = ppb_1284_negociate(bus, PPB_BYTE, PPB_REQUEST_ID)))
606 return (error);
607 error = spp_1284_read(bus, PPB_BYTE, buffer, max, read);
608 break;
609 default:
610 panic("%s: unsupported mode %d", __func__, mode);
613 ppb_1284_terminate(bus);
614 return (error);
618 * ppb_1284_read()
620 * IEEE1284 read
623 ppb_1284_read(device_t bus, int mode, char *buffer,
624 int max, int *read)
626 int error = 0;
628 switch (mode) {
629 case PPB_NIBBLE:
630 case PPB_BYTE:
631 error = spp_1284_read(bus, mode, buffer, max, read);
632 break;
633 default:
634 return (EINVAL);
637 return (error);
641 * ppb_1284_negociate()
643 * IEEE1284 negociation phase
645 * Normal nibble mode or request device id mode (see ppb_1284.h)
647 * After negociation, nFAULT is low if data is available
650 ppb_1284_negociate(device_t bus, int mode, int options)
652 int error;
653 int request_mode;
655 #ifdef DEBUG_1284
656 kprintf("n");
657 #endif
659 if (ppb_1284_get_state(bus) >= PPB_PERIPHERAL_NEGOCIATION)
660 ppb_peripheral_terminate(bus, PPB_WAIT);
662 if (ppb_1284_get_state(bus) != PPB_FORWARD_IDLE)
663 ppb_1284_terminate(bus);
665 #ifdef DEBUG_1284
666 kprintf("%d", mode);
667 #endif
669 /* ensure the host is in compatible mode */
670 ppb_set_mode(bus, PPB_COMPATIBLE);
672 /* reset error to catch the actual negociation error */
673 ppb_1284_reset_error(bus, PPB_FORWARD_IDLE);
675 /* calculate ext. value */
676 request_mode = ppb_request_mode(mode, options);
678 /* default state */
679 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
680 DELAY(1);
682 /* enter negociation phase */
683 ppb_1284_set_state(bus, PPB_NEGOCIATION);
685 /* Event 0 - put the exten. value on the data lines */
686 ppb_wdtr(bus, request_mode);
688 #ifdef PERIPH_1284
689 /* request remote host attention */
690 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
691 DELAY(1);
692 ppb_wctr(bus, (nINIT) & ~(STROBE | AUTOFEED | SELECTIN));
693 #else
694 DELAY(1);
696 #endif /* !PERIPH_1284 */
698 /* Event 1 - enter IEEE1284 mode */
699 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
701 #ifdef PERIPH_1284
702 /* ignore the PError line, wait a bit more, remote host's
703 * interrupts don't respond fast enough */
704 if (ppb_poll_bus(bus, 40, nACK | SELECT | nFAULT,
705 SELECT | nFAULT, PPB_NOINTR | PPB_POLL)) {
706 ppb_1284_set_error(bus, PPB_NOT_IEEE1284, 2);
707 error = ENODEV;
708 goto error;
710 #else
711 /* Event 2 - trying IEEE1284 dialog */
712 if (do_1284_wait(bus, nACK | PERROR | SELECT | nFAULT,
713 PERROR | SELECT | nFAULT)) {
714 ppb_1284_set_error(bus, PPB_NOT_IEEE1284, 2);
715 error = ENODEV;
716 goto error;
718 #endif /* !PERIPH_1284 */
720 /* Event 3 - latch the ext. value to the peripheral */
721 ppb_wctr(bus, (nINIT | STROBE | AUTOFEED) & ~SELECTIN);
722 DELAY(1);
724 /* Event 4 - IEEE1284 device recognized */
725 ppb_wctr(bus, nINIT & ~(SELECTIN | AUTOFEED | STROBE));
727 /* Event 6 - waiting for status lines */
728 if (do_1284_wait(bus, nACK, nACK)) {
729 ppb_1284_set_error(bus, PPB_TIMEOUT, 6);
730 error = EBUSY;
731 goto error;
734 /* Event 7 - quering result consider nACK not to misunderstand
735 * a remote computer terminate sequence */
736 if (options & PPB_EXTENSIBILITY_LINK) {
738 /* XXX not fully supported yet */
739 ppb_1284_terminate(bus);
740 return (0);
743 if (request_mode == NIBBLE_1284_NORMAL) {
744 if (do_1284_wait(bus, nACK | SELECT, nACK)) {
745 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 7);
746 error = ENODEV;
747 goto error;
749 } else {
750 if (do_1284_wait(bus, nACK | SELECT, SELECT | nACK)) {
751 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 7);
752 error = ENODEV;
753 goto error;
757 switch (mode) {
758 case PPB_NIBBLE:
759 case PPB_PS2:
760 /* enter reverse idle phase */
761 ppb_1284_set_state(bus, PPB_REVERSE_IDLE);
762 break;
763 case PPB_ECP:
764 /* negociation ok, now setup the communication */
765 ppb_1284_set_state(bus, PPB_SETUP);
766 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(SELECTIN | STROBE));
768 #ifdef PERIPH_1284
769 /* ignore PError line */
770 if (do_1284_wait(bus, nACK | SELECT | nBUSY,
771 nACK | SELECT | nBUSY)) {
772 ppb_1284_set_error(bus, PPB_TIMEOUT, 30);
773 error = ENODEV;
774 goto error;
776 #else
777 if (do_1284_wait(bus, nACK | SELECT | PERROR | nBUSY,
778 nACK | SELECT | PERROR | nBUSY)) {
779 ppb_1284_set_error(bus, PPB_TIMEOUT, 30);
780 error = ENODEV;
781 goto error;
783 #endif /* !PERIPH_1284 */
785 /* ok, the host enters the ForwardIdle state */
786 ppb_1284_set_state(bus, PPB_ECP_FORWARD_IDLE);
787 break;
788 case PPB_EPP:
789 ppb_1284_set_state(bus, PPB_EPP_IDLE);
790 break;
792 default:
793 panic("%s: unknown mode (%d)!", __func__, mode);
795 ppb_set_mode(bus, mode);
797 return (0);
799 error:
800 ppb_1284_terminate(bus);
802 return (error);
806 * ppb_1284_terminate()
808 * IEEE1284 termination phase, return code should ignored since the host
809 * is _always_ in compatible mode after ppb_1284_terminate()
812 ppb_1284_terminate(device_t bus)
815 #ifdef DEBUG_1284
816 kprintf("T");
817 #endif
819 /* do not reset error here to keep the error that
820 * may occured before the ppb_1284_terminate() call */
821 ppb_1284_set_state(bus, PPB_TERMINATION);
823 #ifdef PERIPH_1284
824 /* request remote host attention */
825 ppb_wctr(bus, (nINIT | STROBE | SELECTIN) & ~(AUTOFEED));
826 DELAY(1);
827 #endif /* PERIPH_1284 */
829 /* Event 22 - set nSelectin low and nAutoFeed high */
830 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
832 /* Event 24 - waiting for peripheral, Xflag ignored */
833 if (do_1284_wait(bus, nACK | nBUSY | nFAULT, nFAULT)) {
834 ppb_1284_set_error(bus, PPB_TIMEOUT, 24);
835 goto error;
838 /* Event 25 - set nAutoFd low */
839 ppb_wctr(bus, (nINIT | SELECTIN | AUTOFEED) & ~STROBE);
841 /* Event 26 - compatible mode status is set */
843 /* Event 27 - peripheral set nAck high */
844 if (do_1284_wait(bus, nACK, nACK)) {
845 ppb_1284_set_error(bus, PPB_TIMEOUT, 27);
848 /* Event 28 - end termination, return to idle phase */
849 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
851 error:
852 /* return to compatible mode */
853 ppb_set_mode(bus, PPB_COMPATIBLE);
854 ppb_1284_set_state(bus, PPB_FORWARD_IDLE);
856 return (0);