Deleted Added
full compact
ppb_1284.c (50477) ppb_1284.c (55939)
1/*-
2 * Copyright (c) 1997 Nicolas Souchu
3 * All rights reserved.
4 *
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 unchanged lines hidden (view full) ---

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.
25 *
1/*-
2 * Copyright (c) 1997 Nicolas Souchu
3 * All rights reserved.
4 *
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 unchanged lines hidden (view full) ---

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.
25 *
26 * $FreeBSD: head/sys/dev/ppbus/ppb_1284.c 50477 1999-08-28 01:08:13Z peter $
26 * $FreeBSD: head/sys/dev/ppbus/ppb_1284.c 55939 2000-01-14 00:18:06Z nsouch $
27 *
28 */
29
30/*
31 * General purpose routines for the IEEE1284-1994 Standard
32 */
33
34#include "opt_ppb_1284.h"
35
36#include <sys/param.h>
37#include <sys/systm.h>
27 *
28 */
29
30/*
31 * General purpose routines for the IEEE1284-1994 Standard
32 */
33
34#include "opt_ppb_1284.h"
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/bus.h>
38
39#include <machine/clock.h>
40
41#include <dev/ppbus/ppbconf.h>
42#include <dev/ppbus/ppb_1284.h>
43
39
40#include <machine/clock.h>
41
42#include <dev/ppbus/ppbconf.h>
43#include <dev/ppbus/ppb_1284.h>
44
45#include "ppbus_if.h"
46
47#include <dev/ppbus/ppbio.h>
48
49#define DEVTOSOFTC(dev) ((struct ppb_data *)device_get_softc(dev))
50
44/*
45 * do_1284_wait()
46 *
47 * Wait for the peripherial up to 40ms
48 */
49static int
51/*
52 * do_1284_wait()
53 *
54 * Wait for the peripherial up to 40ms
55 */
56static int
50do_1284_wait(struct ppb_device *dev, char mask, char status)
57do_1284_wait(device_t bus, char mask, char status)
51{
58{
52 return (ppb_poll_device(dev, 4, mask, status, PPB_NOINTR | PPB_POLL));
59 return (ppb_poll_bus(bus, 4, mask, status, PPB_NOINTR | PPB_POLL));
53}
54
55static int
60}
61
62static int
56do_peripheral_wait(struct ppb_device *dev, char mask, char status)
63do_peripheral_wait(device_t bus, char mask, char status)
57{
64{
58 return (ppb_poll_device(dev, 100, mask, status, PPB_NOINTR | PPB_POLL));
65 return (ppb_poll_bus(bus, 100, mask, status, PPB_NOINTR | PPB_POLL));
59}
60
61#define nibble2char(s) (((s & ~nACK) >> 3) | (~s & nBUSY) >> 4)
62
63/*
64 * ppb_1284_reset_error()
65 *
66 * Unconditionaly reset the error field
67 */
68static int
66}
67
68#define nibble2char(s) (((s & ~nACK) >> 3) | (~s & nBUSY) >> 4)
69
70/*
71 * ppb_1284_reset_error()
72 *
73 * Unconditionaly reset the error field
74 */
75static int
69ppb_1284_reset_error(struct ppb_device *dev, int state)
76ppb_1284_reset_error(device_t bus, int state)
70{
77{
71 dev->ppb->error = PPB_NO_ERROR;
72 dev->ppb->state = state;
78 struct ppb_data *ppb = DEVTOSOFTC(bus);
73
79
80 ppb->error = PPB_NO_ERROR;
81 ppb->state = state;
82
74 return (0);
75}
76
77/*
78 * ppb_1284_get_state()
79 *
80 * Get IEEE1284 state
81 */
82static int
83 return (0);
84}
85
86/*
87 * ppb_1284_get_state()
88 *
89 * Get IEEE1284 state
90 */
91static int
83ppb_1284_get_state(struct ppb_device *dev)
92ppb_1284_get_state(device_t bus)
84{
93{
85 return (dev->ppb->state);
94 return (DEVTOSOFTC(bus)->state);
86}
87
88/*
89 * ppb_1284_set_state()
90 *
91 * Change IEEE1284 state if no error occured
92 */
93static int
95}
96
97/*
98 * ppb_1284_set_state()
99 *
100 * Change IEEE1284 state if no error occured
101 */
102static int
94ppb_1284_set_state(struct ppb_device *dev, int state)
103ppb_1284_set_state(device_t bus, int state)
95{
104{
105 struct ppb_data *ppb = DEVTOSOFTC(bus);
106
96 /* call ppb_1284_reset_error() if you absolutly want to change
97 * the state from PPB_ERROR to another */
107 /* call ppb_1284_reset_error() if you absolutly want to change
108 * the state from PPB_ERROR to another */
98 if ((dev->ppb->state != PPB_ERROR) &&
99 (dev->ppb->error == PPB_NO_ERROR)) {
100 dev->ppb->state = state;
101 dev->ppb->error = PPB_NO_ERROR;
109 if ((ppb->state != PPB_ERROR) &&
110 (ppb->error == PPB_NO_ERROR)) {
111 ppb->state = state;
112 ppb->error = PPB_NO_ERROR;
102 }
103
104 return (0);
105}
106
107static int
113 }
114
115 return (0);
116}
117
118static int
108ppb_1284_set_error(struct ppb_device *dev, int error, int event)
119ppb_1284_set_error(device_t bus, int error, int event)
109{
120{
121 struct ppb_data *ppb = DEVTOSOFTC(bus);
122
110 /* do not accumulate errors */
123 /* do not accumulate errors */
111 if ((dev->ppb->error == PPB_NO_ERROR) &&
112 (dev->ppb->state != PPB_ERROR)) {
113 dev->ppb->error = error;
114 dev->ppb->state = PPB_ERROR;
124 if ((ppb->error == PPB_NO_ERROR) &&
125 (ppb->state != PPB_ERROR)) {
126 ppb->error = error;
127 ppb->state = PPB_ERROR;
115 }
116
117#ifdef DEBUG_1284
118 printf("ppb1284: error=%d status=0x%x event=%d\n", error,
128 }
129
130#ifdef DEBUG_1284
131 printf("ppb1284: error=%d status=0x%x event=%d\n", error,
119 ppb_rstr(dev) & 0xff, event);
132 ppb_rstr(bus) & 0xff, event);
120#endif
121
122 return (0);
123}
124
125/*
126 * ppb_request_mode()
127 *

--- 41 unchanged lines hidden (view full) ---

169}
170
171/*
172 * ppb_peripheral_negociate()
173 *
174 * Negociate the peripheral side
175 */
176int
133#endif
134
135 return (0);
136}
137
138/*
139 * ppb_request_mode()
140 *

--- 41 unchanged lines hidden (view full) ---

182}
183
184/*
185 * ppb_peripheral_negociate()
186 *
187 * Negociate the peripheral side
188 */
189int
177ppb_peripheral_negociate(struct ppb_device *dev, int mode, int options)
190ppb_peripheral_negociate(device_t bus, int mode, int options)
178{
179 int spin, request_mode, error = 0;
180 char r;
181
191{
192 int spin, request_mode, error = 0;
193 char r;
194
182 ppb_set_mode(dev, PPB_COMPATIBLE);
183 ppb_1284_set_state(dev, PPB_PERIPHERAL_NEGOCIATION);
195 ppb_set_mode(bus, PPB_COMPATIBLE);
196 ppb_1284_set_state(bus, PPB_PERIPHERAL_NEGOCIATION);
184
185 /* compute ext. value */
186 request_mode = ppb_request_mode(mode, options);
187
188 /* wait host */
189 spin = 10;
197
198 /* compute ext. value */
199 request_mode = ppb_request_mode(mode, options);
200
201 /* wait host */
202 spin = 10;
190 while (spin-- && (ppb_rstr(dev) & nBUSY))
203 while (spin-- && (ppb_rstr(bus) & nBUSY))
191 DELAY(1);
192
193 /* check termination */
204 DELAY(1);
205
206 /* check termination */
194 if (!(ppb_rstr(dev) & SELECT) || !spin) {
207 if (!(ppb_rstr(bus) & SELECT) || !spin) {
195 error = ENODEV;
196 goto error;
197 }
198
199 /* Event 4 - read ext. value */
208 error = ENODEV;
209 goto error;
210 }
211
212 /* Event 4 - read ext. value */
200 r = ppb_rdtr(dev);
213 r = ppb_rdtr(bus);
201
202 /* nibble mode is not supported */
203 if ((r == (char)request_mode) ||
204 (r == NIBBLE_1284_NORMAL)) {
205
206 /* Event 5 - restore direction bit, no data avail */
214
215 /* nibble mode is not supported */
216 if ((r == (char)request_mode) ||
217 (r == NIBBLE_1284_NORMAL)) {
218
219 /* Event 5 - restore direction bit, no data avail */
207 ppb_wctr(dev, (STROBE | nINIT) & ~(SELECTIN));
220 ppb_wctr(bus, (STROBE | nINIT) & ~(SELECTIN));
208 DELAY(1);
209
210 /* Event 6 */
221 DELAY(1);
222
223 /* Event 6 */
211 ppb_wctr(dev, (nINIT) & ~(SELECTIN | STROBE));
224 ppb_wctr(bus, (nINIT) & ~(SELECTIN | STROBE));
212
213 if (r == NIBBLE_1284_NORMAL) {
214#ifdef DEBUG_1284
215 printf("R");
216#endif
225
226 if (r == NIBBLE_1284_NORMAL) {
227#ifdef DEBUG_1284
228 printf("R");
229#endif
217 ppb_1284_set_error(dev, PPB_MODE_UNSUPPORTED, 4);
230 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 4);
218 error = EINVAL;
219 goto error;
220 } else {
231 error = EINVAL;
232 goto error;
233 } else {
221 ppb_1284_set_state(dev, PPB_PERIPHERAL_IDLE);
234 ppb_1284_set_state(bus, PPB_PERIPHERAL_IDLE);
222 switch (r) {
223 case BYTE_1284_NORMAL:
235 switch (r) {
236 case BYTE_1284_NORMAL:
224 ppb_set_mode(dev, PPB_BYTE);
237 ppb_set_mode(bus, PPB_BYTE);
225 break;
226 default:
227 break;
228 }
229#ifdef DEBUG_1284
230 printf("A");
231#endif
232 /* negociation succeeds */
233 }
234 } else {
235 /* Event 5 - mode not supported */
238 break;
239 default:
240 break;
241 }
242#ifdef DEBUG_1284
243 printf("A");
244#endif
245 /* negociation succeeds */
246 }
247 } else {
248 /* Event 5 - mode not supported */
236 ppb_wctr(dev, SELECTIN);
249 ppb_wctr(bus, SELECTIN);
237 DELAY(1);
238
239 /* Event 6 */
250 DELAY(1);
251
252 /* Event 6 */
240 ppb_wctr(dev, (SELECTIN) & ~(STROBE | nINIT));
241 ppb_1284_set_error(dev, PPB_MODE_UNSUPPORTED, 4);
253 ppb_wctr(bus, (SELECTIN) & ~(STROBE | nINIT));
254 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 4);
242
243#ifdef DEBUG_1284
244 printf("r");
245#endif
246 error = EINVAL;
247 goto error;
248 }
249
250 return (0);
251
252error:
255
256#ifdef DEBUG_1284
257 printf("r");
258#endif
259 error = EINVAL;
260 goto error;
261 }
262
263 return (0);
264
265error:
253 ppb_peripheral_terminate(dev, PPB_WAIT);
266 ppb_peripheral_terminate(bus, PPB_WAIT);
254 return (error);
255}
256
257/*
258 * ppb_peripheral_terminate()
259 *
260 * Terminate peripheral transfer side
261 *
262 * Always return 0 in compatible mode
263 */
264int
267 return (error);
268}
269
270/*
271 * ppb_peripheral_terminate()
272 *
273 * Terminate peripheral transfer side
274 *
275 * Always return 0 in compatible mode
276 */
277int
265ppb_peripheral_terminate(struct ppb_device *dev, int how)
278ppb_peripheral_terminate(device_t bus, int how)
266{
267 int error = 0;
268
269#ifdef DEBUG_1284
270 printf("t");
271#endif
272
279{
280 int error = 0;
281
282#ifdef DEBUG_1284
283 printf("t");
284#endif
285
273 ppb_1284_set_state(dev, PPB_PERIPHERAL_TERMINATION);
286 ppb_1284_set_state(bus, PPB_PERIPHERAL_TERMINATION);
274
275 /* Event 22 - wait up to host response time (1s) */
287
288 /* Event 22 - wait up to host response time (1s) */
276 if ((error = do_peripheral_wait(dev, SELECT | nBUSY, 0))) {
277 ppb_1284_set_error(dev, PPB_TIMEOUT, 22);
289 if ((error = do_peripheral_wait(bus, SELECT | nBUSY, 0))) {
290 ppb_1284_set_error(bus, PPB_TIMEOUT, 22);
278 goto error;
279 }
280
281 /* Event 24 */
291 goto error;
292 }
293
294 /* Event 24 */
282 ppb_wctr(dev, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
295 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
283
284 /* Event 25 - wait up to host response time (1s) */
296
297 /* Event 25 - wait up to host response time (1s) */
285 if ((error = do_peripheral_wait(dev, nBUSY, nBUSY))) {
286 ppb_1284_set_error(dev, PPB_TIMEOUT, 25);
298 if ((error = do_peripheral_wait(bus, nBUSY, nBUSY))) {
299 ppb_1284_set_error(bus, PPB_TIMEOUT, 25);
287 goto error;
288 }
289
290 /* Event 26 */
300 goto error;
301 }
302
303 /* Event 26 */
291 ppb_wctr(dev, (SELECTIN | nINIT | STROBE) & ~(AUTOFEED));
304 ppb_wctr(bus, (SELECTIN | nINIT | STROBE) & ~(AUTOFEED));
292 DELAY(1);
293 /* Event 27 */
305 DELAY(1);
306 /* Event 27 */
294 ppb_wctr(dev, (SELECTIN | nINIT) & ~(STROBE | AUTOFEED));
307 ppb_wctr(bus, (SELECTIN | nINIT) & ~(STROBE | AUTOFEED));
295
296 /* Event 28 - wait up to host response time (1s) */
308
309 /* Event 28 - wait up to host response time (1s) */
297 if ((error = do_peripheral_wait(dev, nBUSY, 0))) {
298 ppb_1284_set_error(dev, PPB_TIMEOUT, 28);
310 if ((error = do_peripheral_wait(bus, nBUSY, 0))) {
311 ppb_1284_set_error(bus, PPB_TIMEOUT, 28);
299 goto error;
300 }
301
302error:
312 goto error;
313 }
314
315error:
303 ppb_set_mode(dev, PPB_COMPATIBLE);
304 ppb_1284_set_state(dev, PPB_FORWARD_IDLE);
316 ppb_set_mode(bus, PPB_COMPATIBLE);
317 ppb_1284_set_state(bus, PPB_FORWARD_IDLE);
305
306 return (0);
307}
308
309/*
310 * byte_peripheral_outbyte()
311 *
312 * Write 1 byte in BYTE mode
313 */
314static int
318
319 return (0);
320}
321
322/*
323 * byte_peripheral_outbyte()
324 *
325 * Write 1 byte in BYTE mode
326 */
327static int
315byte_peripheral_outbyte(struct ppb_device *dev, char *buffer, int last)
328byte_peripheral_outbyte(device_t bus, char *buffer, int last)
316{
317 int error = 0;
318
319 /* Event 7 */
329{
330 int error = 0;
331
332 /* Event 7 */
320 if ((error = do_1284_wait(dev, nBUSY, nBUSY))) {
321 ppb_1284_set_error(dev, PPB_TIMEOUT, 7);
333 if ((error = do_1284_wait(bus, nBUSY, nBUSY))) {
334 ppb_1284_set_error(bus, PPB_TIMEOUT, 7);
322 goto error;
323 }
324
325 /* check termination */
335 goto error;
336 }
337
338 /* check termination */
326 if (!(ppb_rstr(dev) & SELECT)) {
327 ppb_peripheral_terminate(dev, PPB_WAIT);
339 if (!(ppb_rstr(bus) & SELECT)) {
340 ppb_peripheral_terminate(bus, PPB_WAIT);
328 goto error;
329 }
330
331 /* Event 15 - put byte on data lines */
332#ifdef DEBUG_1284
333 printf("B");
334#endif
341 goto error;
342 }
343
344 /* Event 15 - put byte on data lines */
345#ifdef DEBUG_1284
346 printf("B");
347#endif
335 ppb_wdtr(dev, *buffer);
348 ppb_wdtr(bus, *buffer);
336
337 /* Event 9 */
349
350 /* Event 9 */
338 ppb_wctr(dev, (AUTOFEED | STROBE) & ~(nINIT | SELECTIN));
351 ppb_wctr(bus, (AUTOFEED | STROBE) & ~(nINIT | SELECTIN));
339
340 /* Event 10 - wait data read */
352
353 /* Event 10 - wait data read */
341 if ((error = do_peripheral_wait(dev, nBUSY, 0))) {
342 ppb_1284_set_error(dev, PPB_TIMEOUT, 16);
354 if ((error = do_peripheral_wait(bus, nBUSY, 0))) {
355 ppb_1284_set_error(bus, PPB_TIMEOUT, 16);
343 goto error;
344 }
345
346 /* Event 11 */
347 if (!last) {
356 goto error;
357 }
358
359 /* Event 11 */
360 if (!last) {
348 ppb_wctr(dev, (AUTOFEED) & ~(nINIT | STROBE | SELECTIN));
361 ppb_wctr(bus, (AUTOFEED) & ~(nINIT | STROBE | SELECTIN));
349 } else {
362 } else {
350 ppb_wctr(dev, (nINIT) & ~(STROBE | SELECTIN | AUTOFEED));
363 ppb_wctr(bus, (nINIT) & ~(STROBE | SELECTIN | AUTOFEED));
351 }
352
353#if 0
354 /* Event 16 - wait strobe */
364 }
365
366#if 0
367 /* Event 16 - wait strobe */
355 if ((error = do_peripheral_wait(dev, nACK | nBUSY, 0))) {
356 ppb_1284_set_error(dev, PPB_TIMEOUT, 16);
368 if ((error = do_peripheral_wait(bus, nACK | nBUSY, 0))) {
369 ppb_1284_set_error(bus, PPB_TIMEOUT, 16);
357 goto error;
358 }
359#endif
360
361 /* check termination */
370 goto error;
371 }
372#endif
373
374 /* check termination */
362 if (!(ppb_rstr(dev) & SELECT)) {
363 ppb_peripheral_terminate(dev, PPB_WAIT);
375 if (!(ppb_rstr(bus) & SELECT)) {
376 ppb_peripheral_terminate(bus, PPB_WAIT);
364 goto error;
365 }
366
367error:
368 return (error);
369}
370
371/*
372 * byte_peripheral_write()
373 *
374 * Write n bytes in BYTE mode
375 */
376int
377 goto error;
378 }
379
380error:
381 return (error);
382}
383
384/*
385 * byte_peripheral_write()
386 *
387 * Write n bytes in BYTE mode
388 */
389int
377byte_peripheral_write(struct ppb_device *dev, char *buffer, int len, int *sent)
390byte_peripheral_write(device_t bus, char *buffer, int len, int *sent)
378{
379 int error = 0, i;
380 char r;
381
391{
392 int error = 0, i;
393 char r;
394
382 ppb_1284_set_state(dev, PPB_PERIPHERAL_TRANSFER);
395 ppb_1284_set_state(bus, PPB_PERIPHERAL_TRANSFER);
383
384 /* wait forever, the remote host is master and should initiate
385 * termination
386 */
387 for (i=0; i<len; i++) {
388 /* force remote nFAULT low to release the remote waiting
389 * process, if any
390 */
396
397 /* wait forever, the remote host is master and should initiate
398 * termination
399 */
400 for (i=0; i<len; i++) {
401 /* force remote nFAULT low to release the remote waiting
402 * process, if any
403 */
391 r = ppb_rctr(dev);
392 ppb_wctr(dev, r & ~nINIT);
404 r = ppb_rctr(bus);
405 ppb_wctr(bus, r & ~nINIT);
393
394#ifdef DEBUG_1284
395 printf("y");
396#endif
397 /* Event 7 */
406
407#ifdef DEBUG_1284
408 printf("y");
409#endif
410 /* Event 7 */
398 error = ppb_poll_device(dev, PPB_FOREVER, nBUSY, nBUSY,
411 error = ppb_poll_bus(bus, PPB_FOREVER, nBUSY, nBUSY,
399 PPB_INTR);
400
401 if (error && error != EWOULDBLOCK)
402 goto error;
403
404#ifdef DEBUG_1284
405 printf("b");
406#endif
412 PPB_INTR);
413
414 if (error && error != EWOULDBLOCK)
415 goto error;
416
417#ifdef DEBUG_1284
418 printf("b");
419#endif
407 if ((error = byte_peripheral_outbyte(dev, buffer+i, (i == len-1))))
420 if ((error = byte_peripheral_outbyte(bus, buffer+i, (i == len-1))))
408 goto error;
409 }
410error:
411 if (!error)
421 goto error;
422 }
423error:
424 if (!error)
412 ppb_1284_set_state(dev, PPB_PERIPHERAL_IDLE);
425 ppb_1284_set_state(bus, PPB_PERIPHERAL_IDLE);
413
414 *sent = i;
415 return (error);
416}
417
418/*
419 * byte_1284_inbyte()
420 *
421 * Read 1 byte in BYTE mode
422 */
423int
426
427 *sent = i;
428 return (error);
429}
430
431/*
432 * byte_1284_inbyte()
433 *
434 * Read 1 byte in BYTE mode
435 */
436int
424byte_1284_inbyte(struct ppb_device *dev, char *buffer)
437byte_1284_inbyte(device_t bus, char *buffer)
425{
426 int error = 0;
427
428 /* Event 7 - ready to take data (nAUTO low) */
438{
439 int error = 0;
440
441 /* Event 7 - ready to take data (nAUTO low) */
429 ppb_wctr(dev, (PCD | nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
442 ppb_wctr(bus, (PCD | nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
430
431 /* Event 9 - peripheral set nAck low */
443
444 /* Event 9 - peripheral set nAck low */
432 if ((error = do_1284_wait(dev, nACK, 0))) {
433 ppb_1284_set_error(dev, PPB_TIMEOUT, 9);
445 if ((error = do_1284_wait(bus, nACK, 0))) {
446 ppb_1284_set_error(bus, PPB_TIMEOUT, 9);
434 goto error;
435 }
436
437 /* read the byte */
447 goto error;
448 }
449
450 /* read the byte */
438 *buffer = ppb_rdtr(dev);
451 *buffer = ppb_rdtr(bus);
439
440 /* Event 10 - data received, can't accept more */
452
453 /* Event 10 - data received, can't accept more */
441 ppb_wctr(dev, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN));
454 ppb_wctr(bus, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN));
442
443 /* Event 11 - peripheral ack */
455
456 /* Event 11 - peripheral ack */
444 if ((error = do_1284_wait(dev, nACK, nACK))) {
445 ppb_1284_set_error(dev, PPB_TIMEOUT, 11);
457 if ((error = do_1284_wait(bus, nACK, nACK))) {
458 ppb_1284_set_error(bus, PPB_TIMEOUT, 11);
446 goto error;
447 }
448
449 /* Event 16 - strobe */
459 goto error;
460 }
461
462 /* Event 16 - strobe */
450 ppb_wctr(dev, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
463 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
451 DELAY(3);
464 DELAY(3);
452 ppb_wctr(dev, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN));
465 ppb_wctr(bus, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN));
453
454error:
455 return (error);
456}
457
458/*
459 * nibble_1284_inbyte()
460 *
461 * Read 1 byte in NIBBLE mode
462 */
463int
466
467error:
468 return (error);
469}
470
471/*
472 * nibble_1284_inbyte()
473 *
474 * Read 1 byte in NIBBLE mode
475 */
476int
464nibble_1284_inbyte(struct ppb_device *dev, char *buffer)
477nibble_1284_inbyte(device_t bus, char *buffer)
465{
466 char nibble[2];
467 int i, error;
468
469 for (i = 0; i < 2; i++) {
470
471 /* Event 7 - ready to take data (nAUTO low) */
478{
479 char nibble[2];
480 int i, error;
481
482 for (i = 0; i < 2; i++) {
483
484 /* Event 7 - ready to take data (nAUTO low) */
472 ppb_wctr(dev, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
485 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
473
474 /* Event 8 - peripheral writes the first nibble */
475
476 /* Event 9 - peripheral set nAck low */
486
487 /* Event 8 - peripheral writes the first nibble */
488
489 /* Event 9 - peripheral set nAck low */
477 if ((error = do_1284_wait(dev, nACK, 0))) {
478 ppb_1284_set_error(dev, PPB_TIMEOUT, 9);
490 if ((error = do_1284_wait(bus, nACK, 0))) {
491 ppb_1284_set_error(bus, PPB_TIMEOUT, 9);
479 goto error;
480 }
481
482 /* read nibble */
492 goto error;
493 }
494
495 /* read nibble */
483 nibble[i] = ppb_rstr(dev);
496 nibble[i] = ppb_rstr(bus);
484
485 /* Event 10 - ack, nibble received */
497
498 /* Event 10 - ack, nibble received */
486 ppb_wctr(dev, nINIT & ~(AUTOFEED | STROBE | SELECTIN));
499 ppb_wctr(bus, nINIT & ~(AUTOFEED | STROBE | SELECTIN));
487
488 /* Event 11 - wait ack from peripherial */
500
501 /* Event 11 - wait ack from peripherial */
489 if ((error = do_1284_wait(dev, nACK, nACK))) {
490 ppb_1284_set_error(dev, PPB_TIMEOUT, 11);
502 if ((error = do_1284_wait(bus, nACK, nACK))) {
503 ppb_1284_set_error(bus, PPB_TIMEOUT, 11);
491 goto error;
492 }
493 }
494
495 *buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) |
496 (nibble2char(nibble[0]) & 0x0f);
497
498error:
499 return (error);
500}
501
502/*
503 * spp_1284_read()
504 *
505 * Read in IEEE1284 NIBBLE/BYTE mode
506 */
507int
504 goto error;
505 }
506 }
507
508 *buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) |
509 (nibble2char(nibble[0]) & 0x0f);
510
511error:
512 return (error);
513}
514
515/*
516 * spp_1284_read()
517 *
518 * Read in IEEE1284 NIBBLE/BYTE mode
519 */
520int
508spp_1284_read(struct ppb_device *dev, int mode, char *buffer, int max, int *read)
521spp_1284_read(device_t bus, int mode, char *buffer, int max, int *read)
509{
510 int error = 0, len = 0;
511 int terminate_after_transfer = 1;
512 int state;
513
514 *read = len = 0;
515
522{
523 int error = 0, len = 0;
524 int terminate_after_transfer = 1;
525 int state;
526
527 *read = len = 0;
528
516 state = ppb_1284_get_state(dev);
529 state = ppb_1284_get_state(bus);
517
518 switch (state) {
519 case PPB_FORWARD_IDLE:
530
531 switch (state) {
532 case PPB_FORWARD_IDLE:
520 if ((error = ppb_1284_negociate(dev, mode, 0)))
533 if ((error = ppb_1284_negociate(bus, mode, 0)))
521 return (error);
522 break;
523
524 case PPB_REVERSE_IDLE:
525 terminate_after_transfer = 0;
526 break;
527
528 default:
534 return (error);
535 break;
536
537 case PPB_REVERSE_IDLE:
538 terminate_after_transfer = 0;
539 break;
540
541 default:
529 ppb_1284_terminate(dev);
530 if ((error = ppb_1284_negociate(dev, mode, 0)))
542 ppb_1284_terminate(bus);
543 if ((error = ppb_1284_negociate(bus, mode, 0)))
531 return (error);
532 break;
533 }
534
544 return (error);
545 break;
546 }
547
535 while ((len < max) && !(ppb_rstr(dev) & (nFAULT))) {
548 while ((len < max) && !(ppb_rstr(bus) & (nFAULT))) {
536
549
537 ppb_1284_set_state(dev, PPB_REVERSE_TRANSFER);
550 ppb_1284_set_state(bus, PPB_REVERSE_TRANSFER);
538
539#ifdef DEBUG_1284
540 printf("B");
541#endif
542
543 switch (mode) {
544 case PPB_NIBBLE:
545 /* read a byte, error means no more data */
551
552#ifdef DEBUG_1284
553 printf("B");
554#endif
555
556 switch (mode) {
557 case PPB_NIBBLE:
558 /* read a byte, error means no more data */
546 if (nibble_1284_inbyte(dev, buffer+len))
559 if (nibble_1284_inbyte(bus, buffer+len))
547 goto end_while;
548 break;
549 case PPB_BYTE:
560 goto end_while;
561 break;
562 case PPB_BYTE:
550 if (byte_1284_inbyte(dev, buffer+len))
563 if (byte_1284_inbyte(bus, buffer+len))
551 goto end_while;
552 break;
553 default:
554 error = EINVAL;
555 goto end_while;
556 }
557 len ++;
558 }
559end_while:
560
561 if (!error)
564 goto end_while;
565 break;
566 default:
567 error = EINVAL;
568 goto end_while;
569 }
570 len ++;
571 }
572end_while:
573
574 if (!error)
562 ppb_1284_set_state(dev, PPB_REVERSE_IDLE);
575 ppb_1284_set_state(bus, PPB_REVERSE_IDLE);
563
564 *read = len;
565
566 if (terminate_after_transfer || error)
576
577 *read = len;
578
579 if (terminate_after_transfer || error)
567 ppb_1284_terminate(dev);
580 ppb_1284_terminate(bus);
568
569 return (error);
570}
571
572/*
573 * ppb_1284_read_id()
574 *
575 */
576int
581
582 return (error);
583}
584
585/*
586 * ppb_1284_read_id()
587 *
588 */
589int
577ppb_1284_read_id(struct ppb_device *dev, int mode, char *buffer,
590ppb_1284_read_id(device_t bus, int mode, char *buffer,
578 int max, int *read)
579{
580 int error = 0;
581
582 /* fill the buffer with 0s */
583 bzero(buffer, max);
584
585 switch (mode) {
586 case PPB_NIBBLE:
587 case PPB_ECP:
591 int max, int *read)
592{
593 int error = 0;
594
595 /* fill the buffer with 0s */
596 bzero(buffer, max);
597
598 switch (mode) {
599 case PPB_NIBBLE:
600 case PPB_ECP:
588 if ((error = ppb_1284_negociate(dev, PPB_NIBBLE, PPB_REQUEST_ID)))
601 if ((error = ppb_1284_negociate(bus, PPB_NIBBLE, PPB_REQUEST_ID)))
589 return (error);
602 return (error);
590 error = spp_1284_read(dev, PPB_NIBBLE, buffer, max, read);
603 error = spp_1284_read(bus, PPB_NIBBLE, buffer, max, read);
591 break;
592 case PPB_BYTE:
604 break;
605 case PPB_BYTE:
593 if ((error = ppb_1284_negociate(dev, PPB_BYTE, PPB_REQUEST_ID)))
606 if ((error = ppb_1284_negociate(bus, PPB_BYTE, PPB_REQUEST_ID)))
594 return (error);
607 return (error);
595 error = spp_1284_read(dev, PPB_BYTE, buffer, max, read);
608 error = spp_1284_read(bus, PPB_BYTE, buffer, max, read);
596 break;
597 default:
598 panic("%s: unsupported mode %d\n", __FUNCTION__, mode);
599 }
600
609 break;
610 default:
611 panic("%s: unsupported mode %d\n", __FUNCTION__, mode);
612 }
613
601 ppb_1284_terminate(dev);
614 ppb_1284_terminate(bus);
602 return (error);
603}
604
605/*
606 * ppb_1284_read()
607 *
608 * IEEE1284 read
609 */
610int
615 return (error);
616}
617
618/*
619 * ppb_1284_read()
620 *
621 * IEEE1284 read
622 */
623int
611ppb_1284_read(struct ppb_device *dev, int mode, char *buffer,
624ppb_1284_read(device_t bus, int mode, char *buffer,
612 int max, int *read)
613{
614 int error = 0;
615
616 switch (mode) {
617 case PPB_NIBBLE:
618 case PPB_BYTE:
625 int max, int *read)
626{
627 int error = 0;
628
629 switch (mode) {
630 case PPB_NIBBLE:
631 case PPB_BYTE:
619 error = spp_1284_read(dev, mode, buffer, max, read);
632 error = spp_1284_read(bus, mode, buffer, max, read);
620 break;
621 default:
622 return (EINVAL);
623 }
624
625 return (error);
626}
627
628/*
629 * ppb_1284_negociate()
630 *
631 * IEEE1284 negociation phase
632 *
633 * Normal nibble mode or request device id mode (see ppb_1284.h)
634 *
635 * After negociation, nFAULT is low if data is available
636 */
637int
633 break;
634 default:
635 return (EINVAL);
636 }
637
638 return (error);
639}
640
641/*
642 * ppb_1284_negociate()
643 *
644 * IEEE1284 negociation phase
645 *
646 * Normal nibble mode or request device id mode (see ppb_1284.h)
647 *
648 * After negociation, nFAULT is low if data is available
649 */
650int
638ppb_1284_negociate(struct ppb_device *dev, int mode, int options)
651ppb_1284_negociate(device_t bus, int mode, int options)
639{
640 int error;
641 int request_mode;
642
643#ifdef DEBUG_1284
644 printf("n");
645#endif
646
652{
653 int error;
654 int request_mode;
655
656#ifdef DEBUG_1284
657 printf("n");
658#endif
659
647 if (ppb_1284_get_state(dev) >= PPB_PERIPHERAL_NEGOCIATION)
648 ppb_peripheral_terminate(dev, PPB_WAIT);
660 if (ppb_1284_get_state(bus) >= PPB_PERIPHERAL_NEGOCIATION)
661 ppb_peripheral_terminate(bus, PPB_WAIT);
649
662
650 if (ppb_1284_get_state(dev) != PPB_FORWARD_IDLE)
651 ppb_1284_terminate(dev);
663 if (ppb_1284_get_state(bus) != PPB_FORWARD_IDLE)
664 ppb_1284_terminate(bus);
652
653#ifdef DEBUG_1284
654 printf("%d", mode);
655#endif
656
657 /* ensure the host is in compatible mode */
665
666#ifdef DEBUG_1284
667 printf("%d", mode);
668#endif
669
670 /* ensure the host is in compatible mode */
658 ppb_set_mode(dev, PPB_COMPATIBLE);
671 ppb_set_mode(bus, PPB_COMPATIBLE);
659
660 /* reset error to catch the actual negociation error */
672
673 /* reset error to catch the actual negociation error */
661 ppb_1284_reset_error(dev, PPB_FORWARD_IDLE);
674 ppb_1284_reset_error(bus, PPB_FORWARD_IDLE);
662
663 /* calculate ext. value */
664 request_mode = ppb_request_mode(mode, options);
665
666 /* default state */
675
676 /* calculate ext. value */
677 request_mode = ppb_request_mode(mode, options);
678
679 /* default state */
667 ppb_wctr(dev, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
680 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
668 DELAY(1);
669
670 /* enter negociation phase */
681 DELAY(1);
682
683 /* enter negociation phase */
671 ppb_1284_set_state(dev, PPB_NEGOCIATION);
684 ppb_1284_set_state(bus, PPB_NEGOCIATION);
672
673 /* Event 0 - put the exten. value on the data lines */
685
686 /* Event 0 - put the exten. value on the data lines */
674 ppb_wdtr(dev, request_mode);
687 ppb_wdtr(bus, request_mode);
675
676#ifdef PERIPH_1284
677 /* request remote host attention */
688
689#ifdef PERIPH_1284
690 /* request remote host attention */
678 ppb_wctr(dev, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
691 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
679 DELAY(1);
692 DELAY(1);
680 ppb_wctr(dev, (nINIT) & ~(STROBE | AUTOFEED | SELECTIN));
693 ppb_wctr(bus, (nINIT) & ~(STROBE | AUTOFEED | SELECTIN));
681#else
682 DELAY(1);
683
684#endif /* !PERIPH_1284 */
685
686 /* Event 1 - enter IEEE1284 mode */
694#else
695 DELAY(1);
696
697#endif /* !PERIPH_1284 */
698
699 /* Event 1 - enter IEEE1284 mode */
687 ppb_wctr(dev, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
700 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN));
688
689#ifdef PERIPH_1284
690 /* ignore the PError line, wait a bit more, remote host's
691 * interrupts don't respond fast enough */
701
702#ifdef PERIPH_1284
703 /* ignore the PError line, wait a bit more, remote host's
704 * interrupts don't respond fast enough */
692 if (ppb_poll_device(dev, 40, nACK | SELECT | nFAULT,
705 if (ppb_poll_bus(bus, 40, nACK | SELECT | nFAULT,
693 SELECT | nFAULT, PPB_NOINTR | PPB_POLL)) {
706 SELECT | nFAULT, PPB_NOINTR | PPB_POLL)) {
694 ppb_1284_set_error(dev, PPB_NOT_IEEE1284, 2);
707 ppb_1284_set_error(bus, PPB_NOT_IEEE1284, 2);
695 error = ENODEV;
696 goto error;
697 }
698#else
699 /* Event 2 - trying IEEE1284 dialog */
708 error = ENODEV;
709 goto error;
710 }
711#else
712 /* Event 2 - trying IEEE1284 dialog */
700 if (do_1284_wait(dev, nACK | PERROR | SELECT | nFAULT,
713 if (do_1284_wait(bus, nACK | PERROR | SELECT | nFAULT,
701 PERROR | SELECT | nFAULT)) {
714 PERROR | SELECT | nFAULT)) {
702 ppb_1284_set_error(dev, PPB_NOT_IEEE1284, 2);
715 ppb_1284_set_error(bus, PPB_NOT_IEEE1284, 2);
703 error = ENODEV;
704 goto error;
705 }
706#endif /* !PERIPH_1284 */
707
708 /* Event 3 - latch the ext. value to the peripheral */
716 error = ENODEV;
717 goto error;
718 }
719#endif /* !PERIPH_1284 */
720
721 /* Event 3 - latch the ext. value to the peripheral */
709 ppb_wctr(dev, (nINIT | STROBE | AUTOFEED) & ~SELECTIN);
722 ppb_wctr(bus, (nINIT | STROBE | AUTOFEED) & ~SELECTIN);
710 DELAY(1);
711
712 /* Event 4 - IEEE1284 device recognized */
723 DELAY(1);
724
725 /* Event 4 - IEEE1284 device recognized */
713 ppb_wctr(dev, nINIT & ~(SELECTIN | AUTOFEED | STROBE));
726 ppb_wctr(bus, nINIT & ~(SELECTIN | AUTOFEED | STROBE));
714
715 /* Event 6 - waiting for status lines */
727
728 /* Event 6 - waiting for status lines */
716 if (do_1284_wait(dev, nACK, nACK)) {
717 ppb_1284_set_error(dev, PPB_TIMEOUT, 6);
729 if (do_1284_wait(bus, nACK, nACK)) {
730 ppb_1284_set_error(bus, PPB_TIMEOUT, 6);
718 error = EBUSY;
719 goto error;
720 }
721
722 /* Event 7 - quering result consider nACK not to misunderstand
723 * a remote computer terminate sequence */
724 if (options & PPB_EXTENSIBILITY_LINK) {
725
726 /* XXX not fully supported yet */
731 error = EBUSY;
732 goto error;
733 }
734
735 /* Event 7 - quering result consider nACK not to misunderstand
736 * a remote computer terminate sequence */
737 if (options & PPB_EXTENSIBILITY_LINK) {
738
739 /* XXX not fully supported yet */
727 ppb_1284_terminate(dev);
740 ppb_1284_terminate(bus);
728 return (0);
729
730 }
731 if (request_mode == NIBBLE_1284_NORMAL) {
741 return (0);
742
743 }
744 if (request_mode == NIBBLE_1284_NORMAL) {
732 if (do_1284_wait(dev, nACK | SELECT, nACK)) {
733 ppb_1284_set_error(dev, PPB_MODE_UNSUPPORTED, 7);
745 if (do_1284_wait(bus, nACK | SELECT, nACK)) {
746 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 7);
734 error = ENODEV;
735 goto error;
736 }
737 } else {
747 error = ENODEV;
748 goto error;
749 }
750 } else {
738 if (do_1284_wait(dev, nACK | SELECT, SELECT | nACK)) {
739 ppb_1284_set_error(dev, PPB_MODE_UNSUPPORTED, 7);
751 if (do_1284_wait(bus, nACK | SELECT, SELECT | nACK)) {
752 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 7);
740 error = ENODEV;
741 goto error;
742 }
743 }
744
745 switch (mode) {
746 case PPB_NIBBLE:
747 case PPB_PS2:
748 /* enter reverse idle phase */
753 error = ENODEV;
754 goto error;
755 }
756 }
757
758 switch (mode) {
759 case PPB_NIBBLE:
760 case PPB_PS2:
761 /* enter reverse idle phase */
749 ppb_1284_set_state(dev, PPB_REVERSE_IDLE);
762 ppb_1284_set_state(bus, PPB_REVERSE_IDLE);
750 break;
751 case PPB_ECP:
752 /* negociation ok, now setup the communication */
763 break;
764 case PPB_ECP:
765 /* negociation ok, now setup the communication */
753 ppb_1284_set_state(dev, PPB_SETUP);
754 ppb_wctr(dev, (nINIT | AUTOFEED) & ~(SELECTIN | STROBE));
766 ppb_1284_set_state(bus, PPB_SETUP);
767 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(SELECTIN | STROBE));
755
756#ifdef PERIPH_1284
757 /* ignore PError line */
768
769#ifdef PERIPH_1284
770 /* ignore PError line */
758 if (do_1284_wait(dev, nACK | SELECT | nBUSY,
771 if (do_1284_wait(bus, nACK | SELECT | nBUSY,
759 nACK | SELECT | nBUSY)) {
772 nACK | SELECT | nBUSY)) {
760 ppb_1284_set_error(dev, PPB_TIMEOUT, 30);
773 ppb_1284_set_error(bus, PPB_TIMEOUT, 30);
761 error = ENODEV;
762 goto error;
763 }
764#else
774 error = ENODEV;
775 goto error;
776 }
777#else
765 if (do_1284_wait(dev, nACK | SELECT | PERROR | nBUSY,
778 if (do_1284_wait(bus, nACK | SELECT | PERROR | nBUSY,
766 nACK | SELECT | PERROR | nBUSY)) {
779 nACK | SELECT | PERROR | nBUSY)) {
767 ppb_1284_set_error(dev, PPB_TIMEOUT, 30);
780 ppb_1284_set_error(bus, PPB_TIMEOUT, 30);
768 error = ENODEV;
769 goto error;
770 }
771#endif /* !PERIPH_1284 */
772
773 /* ok, the host enters the ForwardIdle state */
781 error = ENODEV;
782 goto error;
783 }
784#endif /* !PERIPH_1284 */
785
786 /* ok, the host enters the ForwardIdle state */
774 ppb_1284_set_state(dev, PPB_ECP_FORWARD_IDLE);
787 ppb_1284_set_state(bus, PPB_ECP_FORWARD_IDLE);
775 break;
776 case PPB_EPP:
788 break;
789 case PPB_EPP:
777 ppb_1284_set_state(dev, PPB_EPP_IDLE);
790 ppb_1284_set_state(bus, PPB_EPP_IDLE);
778 break;
779
780 default:
781 panic("%s: unknown mode (%d)!", __FUNCTION__, mode);
782 }
791 break;
792
793 default:
794 panic("%s: unknown mode (%d)!", __FUNCTION__, mode);
795 }
783 ppb_set_mode(dev, mode);
796 ppb_set_mode(bus, mode);
784
785 return (0);
786
787error:
797
798 return (0);
799
800error:
788 ppb_1284_terminate(dev);
801 ppb_1284_terminate(bus);
789
790 return (error);
791}
792
793/*
794 * ppb_1284_terminate()
795 *
796 * IEEE1284 termination phase, return code should ignored since the host
797 * is _always_ in compatible mode after ppb_1284_terminate()
798 */
799int
802
803 return (error);
804}
805
806/*
807 * ppb_1284_terminate()
808 *
809 * IEEE1284 termination phase, return code should ignored since the host
810 * is _always_ in compatible mode after ppb_1284_terminate()
811 */
812int
800ppb_1284_terminate(struct ppb_device *dev)
813ppb_1284_terminate(device_t bus)
801{
802
803#ifdef DEBUG_1284
804 printf("T");
805#endif
806
807 /* do not reset error here to keep the error that
808 * may occured before the ppb_1284_terminate() call */
814{
815
816#ifdef DEBUG_1284
817 printf("T");
818#endif
819
820 /* do not reset error here to keep the error that
821 * may occured before the ppb_1284_terminate() call */
809 ppb_1284_set_state(dev, PPB_TERMINATION);
822 ppb_1284_set_state(bus, PPB_TERMINATION);
810
811#ifdef PERIPH_1284
812 /* request remote host attention */
823
824#ifdef PERIPH_1284
825 /* request remote host attention */
813 ppb_wctr(dev, (nINIT | STROBE | SELECTIN) & ~(AUTOFEED));
826 ppb_wctr(bus, (nINIT | STROBE | SELECTIN) & ~(AUTOFEED));
814 DELAY(1);
815#endif /* PERIPH_1284 */
816
817 /* Event 22 - set nSelectin low and nAutoFeed high */
827 DELAY(1);
828#endif /* PERIPH_1284 */
829
830 /* Event 22 - set nSelectin low and nAutoFeed high */
818 ppb_wctr(dev, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
831 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
819
820 /* Event 24 - waiting for peripheral, Xflag ignored */
832
833 /* Event 24 - waiting for peripheral, Xflag ignored */
821 if (do_1284_wait(dev, nACK | nBUSY | nFAULT, nFAULT)) {
822 ppb_1284_set_error(dev, PPB_TIMEOUT, 24);
834 if (do_1284_wait(bus, nACK | nBUSY | nFAULT, nFAULT)) {
835 ppb_1284_set_error(bus, PPB_TIMEOUT, 24);
823 goto error;
824 }
825
826 /* Event 25 - set nAutoFd low */
836 goto error;
837 }
838
839 /* Event 25 - set nAutoFd low */
827 ppb_wctr(dev, (nINIT | SELECTIN | AUTOFEED) & ~STROBE);
840 ppb_wctr(bus, (nINIT | SELECTIN | AUTOFEED) & ~STROBE);
828
829 /* Event 26 - compatible mode status is set */
830
831 /* Event 27 - peripheral set nAck high */
841
842 /* Event 26 - compatible mode status is set */
843
844 /* Event 27 - peripheral set nAck high */
832 if (do_1284_wait(dev, nACK, nACK)) {
833 ppb_1284_set_error(dev, PPB_TIMEOUT, 27);
845 if (do_1284_wait(bus, nACK, nACK)) {
846 ppb_1284_set_error(bus, PPB_TIMEOUT, 27);
834 }
835
836 /* Event 28 - end termination, return to idle phase */
847 }
848
849 /* Event 28 - end termination, return to idle phase */
837 ppb_wctr(dev, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
850 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED));
838
839error:
840 /* return to compatible mode */
851
852error:
853 /* return to compatible mode */
841 ppb_set_mode(dev, PPB_COMPATIBLE);
842 ppb_1284_set_state(dev, PPB_FORWARD_IDLE);
854 ppb_set_mode(bus, PPB_COMPATIBLE);
855 ppb_1284_set_state(bus, PPB_FORWARD_IDLE);
843
844 return (0);
845}
856
857 return (0);
858}