1 /* $Id: parport_ieee1284.c,v 1.4 1997/10/19 21:37:21 philip Exp $
2 * IEEE-1284 implementation for parport.
3 *
4 * Authors: Phil Blundell <Philip.Blundell@pobox.com>
5 * Carsten Gross <carsten@sol.wohnheim.uni-ulm.de>
6 * Jose Renau <renau@acm.org>
7 * Tim Waugh <tim@cyberelk.demon.co.uk> (largely rewritten)
8 *
9 * This file is responsible for IEEE 1284 negotiation, and for handing
10 * read/write requests to low-level drivers.
11 *
12 * Any part of this program may be used in documents licensed under
13 * the GNU Free Documentation License, Version 1.1 or any later version
14 * published by the Free Software Foundation.
15 */
16
17 #include <linux/config.h>
18 #include <linux/threads.h>
19 #include <linux/parport.h>
20 #include <linux/delay.h>
21 #include <linux/kernel.h>
22 #include <linux/interrupt.h>
23
24 #undef DEBUG /* undef me for production */
25
26 #ifdef CONFIG_LP_CONSOLE
27 #undef DEBUG /* Don't want a garbled console */
28 #endif
29
30 #ifdef DEBUG
31 #define DPRINTK(stuff...) printk (stuff)
32 #else
33 #define DPRINTK(stuff...)
34 #endif
35
36 /* Make parport_wait_peripheral wake up.
37 * It will be useful to call this from an interrupt handler. */
38 void parport_ieee1284_wakeup (struct parport *port)
39 {
40 up (&port->physport->ieee1284.irq);
41 }
42
43 static struct parport *port_from_cookie[PARPORT_MAX];
44 static void timeout_waiting_on_port (unsigned long cookie)
45 {
46 parport_ieee1284_wakeup (port_from_cookie[cookie % PARPORT_MAX]);
47 }
48
49 /**
50 * parport_wait_event - wait for an event on a parallel port
51 * @port: port to wait on
52 * @timeout: time to wait (in jiffies)
53 *
54 * This function waits for up to @timeout jiffies for an
55 * interrupt to occur on a parallel port. If the port timeout is
56 * set to zero, it returns immediately.
57 *
58 * If an interrupt occurs before the timeout period elapses, this
59 * function returns one immediately. If it times out, it returns
60 * a value greater than zero. An error code less than zero
61 * indicates an error (most likely a pending signal), and the
62 * calling code should finish what it's doing as soon as it can.
63 */
64
65 int parport_wait_event (struct parport *port, signed long timeout)
66 {
67 int ret;
68 struct timer_list timer;
69
70 if (!port->physport->cad->timeout)
71 /* Zero timeout is special, and we can't down() the
72 semaphore. */
73 return 1;
74
75 init_timer (&timer);
76 timer.expires = jiffies + timeout;
77 timer.function = timeout_waiting_on_port;
78 port_from_cookie[port->number % PARPORT_MAX] = port;
79 timer.data = port->number;
80
81 add_timer (&timer);
82 ret = down_interruptible (&port->physport->ieee1284.irq);
83 if (!del_timer (&timer) && !ret)
84 /* Timed out. */
85 ret = 1;
86
87 return ret;
88 }
89
90 /**
91 * parport_poll_peripheral - poll status lines
92 * @port: port to watch
93 * @mask: status lines to watch
94 * @result: desired values of chosen status lines
95 * @usec: timeout
96 *
97 * This function busy-waits until the masked status lines have
98 * the desired values, or until the timeout period elapses. The
99 * @mask and @result parameters are bitmasks, with the bits
100 * defined by the constants in parport.h: %PARPORT_STATUS_BUSY,
101 * and so on.
102 *
103 * This function does not call schedule(); instead it busy-waits
104 * using udelay(). It currently has a resolution of 5usec.
105 *
106 * If the status lines take on the desired values before the
107 * timeout period elapses, parport_poll_peripheral() returns zero
108 * immediately. A zero return value greater than zero indicates
109 * a timeout. An error code (less than zero) indicates an error,
110 * most likely a signal that arrived, and the caller should
111 * finish what it is doing as soon as possible.
112 */
113
114 int parport_poll_peripheral(struct parport *port,
115 unsigned char mask,
116 unsigned char result,
117 int usec)
118 {
119 /* Zero return code is success, >0 is timeout. */
120 int counter = usec / 5;
121 unsigned char status;
122 for (; counter > 0; counter--) {
123 status = parport_read_status (port);
124 if ((status & mask) == result)
125 return 0;
126 if (signal_pending (current))
127 return -EINTR;
128 if (current->need_resched)
129 break;
130 udelay (5);
131 }
132
133 return 1;
134 }
135
136 /**
137 * parport_wait_peripheral - wait for status lines to change in 35ms
138 * @port: port to watch
139 * @mask: status lines to watch
140 * @result: desired values of chosen status lines
141 *
142 * This function waits until the masked status lines have the
143 * desired values, or until 35ms have elapsed (see IEEE 1284-1994
144 * page 24 to 25 for why this value in particular is hardcoded).
145 * The @mask and @result parameters are bitmasks, with the bits
146 * defined by the constants in parport.h: %PARPORT_STATUS_BUSY,
147 * and so on.
148 *
149 * The port is polled quickly to start off with, in anticipation
150 * of a fast response from the peripheral. This fast polling
151 * time is configurable (using /proc), and defaults to 500usec.
152 * If the timeout for this port (see parport_set_timeout()) is
153 * zero, the fast polling time is 35ms, and this function does
154 * not call schedule().
155 *
156 * If the timeout for this port is non-zero, after the fast
157 * polling fails it uses parport_wait_event() to wait for up to
158 * 10ms, waking up if an interrupt occurs.
159 */
160
161 int parport_wait_peripheral(struct parport *port,
162 unsigned char mask,
163 unsigned char result)
164 {
165 int ret;
166 int usec;
167 long deadline;
168 unsigned char status;
169
170 usec = port->physport->spintime; /* usecs of fast polling */
171 if (!port->physport->cad->timeout)
172 /* A zero timeout is "special": busy wait for the
173 entire 35ms. */
174 usec = 35000;
175
176 /* Fast polling.
177 *
178 * This should be adjustable.
179 * How about making a note (in the device structure) of how long
180 * it takes, so we know for next time?
181 */
182 ret = parport_poll_peripheral (port, mask, result, usec);
183 if (ret != 1)
184 return ret;
185
186 if (!port->physport->cad->timeout)
187 /* We may be in an interrupt handler, so we can't poll
188 * slowly anyway. */
189 return 1;
190
191 /* 40ms of slow polling. */
192 deadline = jiffies + (HZ + 24) / 25;
193 while (time_before (jiffies, deadline)) {
194 int ret;
195
196 if (signal_pending (current))
197 return -EINTR;
198
199 /* Wait for 10ms (or until an interrupt occurs if
200 * the handler is set) */
201 if ((ret = parport_wait_event (port, (HZ + 99) / 100)) < 0)
202 return ret;
203
204 status = parport_read_status (port);
205 if ((status & mask) == result)
206 return 0;
207
208 if (!ret) {
209 /* parport_wait_event didn't time out, but the
210 * peripheral wasn't actually ready either.
211 * Wait for another 10ms. */
212 __set_current_state (TASK_INTERRUPTIBLE);
213 schedule_timeout ((HZ+ 99) / 100);
214 }
215 }
216
217 return 1;
218 }
219
220 #ifdef CONFIG_PARPORT_1284
221 /* Terminate a negotiated mode. */
222 static void parport_ieee1284_terminate (struct parport *port)
223 {
224 int r;
225 port = port->physport;
226
227 /* EPP terminates differently. */
228 switch (port->ieee1284.mode) {
229 case IEEE1284_MODE_EPP:
230 case IEEE1284_MODE_EPPSL:
231 case IEEE1284_MODE_EPPSWE:
232 /* Terminate from EPP mode. */
233
234 /* Event 68: Set nInit low */
235 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
236 udelay (50);
237
238 /* Event 69: Set nInit high, nSelectIn low */
239 parport_frob_control (port,
240 PARPORT_CONTROL_SELECT
241 | PARPORT_CONTROL_INIT,
242 PARPORT_CONTROL_SELECT
243 | PARPORT_CONTROL_INIT);
244 break;
245
246 case IEEE1284_MODE_ECP:
247 case IEEE1284_MODE_ECPRLE:
248 case IEEE1284_MODE_ECPSWE:
249 /* In ECP we can only terminate from fwd idle phase. */
250 if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
251 /* Event 47: Set nInit high */
252 parport_frob_control (port,
253 PARPORT_CONTROL_INIT
254 | PARPORT_CONTROL_AUTOFD,
255 PARPORT_CONTROL_INIT
256 | PARPORT_CONTROL_AUTOFD);
257
258 /* Event 49: PError goes high */
259 r = parport_wait_peripheral (port,
260 PARPORT_STATUS_PAPEROUT,
261 PARPORT_STATUS_PAPEROUT);
262 if (r)
263 DPRINTK (KERN_INFO "%s: Timeout at event 49\n",
264 port->name);
265
266 parport_data_forward (port);
267 DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n",
268 port->name);
269 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
270 }
271
272 /* fall-though.. */
273
274 default:
275 /* Terminate from all other modes. */
276
277 /* Event 22: Set nSelectIn low, nAutoFd high */
278 parport_frob_control (port,
279 PARPORT_CONTROL_SELECT
280 | PARPORT_CONTROL_AUTOFD,
281 PARPORT_CONTROL_SELECT);
282
283 /* Event 24: nAck goes low */
284 r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0);
285 if (r)
286 DPRINTK (KERN_INFO "%s: Timeout at event 24\n",
287 port->name);
288
289 /* Event 25: Set nAutoFd low */
290 parport_frob_control (port,
291 PARPORT_CONTROL_AUTOFD,
292 PARPORT_CONTROL_AUTOFD);
293
294 /* Event 27: nAck goes high */
295 r = parport_wait_peripheral (port,
296 PARPORT_STATUS_ACK,
297 PARPORT_STATUS_ACK);
298 if (r)
299 DPRINTK (KERN_INFO "%s: Timeout at event 27\n",
300 port->name);
301
302 /* Event 29: Set nAutoFd high */
303 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
304 }
305
306 port->ieee1284.mode = IEEE1284_MODE_COMPAT;
307 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
308
309 DPRINTK (KERN_DEBUG "%s: In compatibility (forward idle) mode\n",
310 port->name);
311 }
312 #endif /* IEEE1284 support */
313
314 /**
315 * parport_negotiate - negotiate an IEEE 1284 mode
316 * @port: port to use
317 * @mode: mode to negotiate to
318 *
319 * Use this to negotiate to a particular IEEE 1284 transfer mode.
320 * The @mode parameter should be one of the constants in
321 * parport.h starting %IEEE1284_MODE_xxx.
322 *
323 * The return value is 0 if the peripheral has accepted the
324 * negotiation to the mode specified, -1 if the peripheral is not
325 * IEEE 1284 compliant (or not present), or 1 if the peripheral
326 * has rejected the negotiation.
327 */
328
329 int parport_negotiate (struct parport *port, int mode)
330 {
331 #ifndef CONFIG_PARPORT_1284
332 if (mode == IEEE1284_MODE_COMPAT)
333 return 0;
334 printk (KERN_ERR "parport: IEEE1284 not supported in this kernel\n");
335 return -1;
336 #else
337 int m = mode & ~IEEE1284_ADDR;
338 int r;
339 unsigned char xflag;
340
341 port = port->physport;
342
343 /* Is there anything to do? */
344 if (port->ieee1284.mode == mode)
345 return 0;
346
347 /* Is the difference just an address-or-not bit? */
348 if ((port->ieee1284.mode & ~IEEE1284_ADDR) == (mode & ~IEEE1284_ADDR)){
349 port->ieee1284.mode = mode;
350 return 0;
351 }
352
353 /* Go to compability forward idle mode */
354 if (port->ieee1284.mode != IEEE1284_MODE_COMPAT)
355 parport_ieee1284_terminate (port);
356
357 if (mode == IEEE1284_MODE_COMPAT)
358 /* Compatibility mode: no negotiation. */
359 return 0;
360
361 switch (mode) {
362 case IEEE1284_MODE_ECPSWE:
363 m = IEEE1284_MODE_ECP;
364 break;
365 case IEEE1284_MODE_EPPSL:
366 case IEEE1284_MODE_EPPSWE:
367 m = IEEE1284_MODE_EPP;
368 break;
369 case IEEE1284_MODE_BECP:
370 return -ENOSYS; /* FIXME (implement BECP) */
371 }
372
373 if (mode & IEEE1284_EXT_LINK)
374 m = 1<<7; /* request extensibility link */
375
376 port->ieee1284.phase = IEEE1284_PH_NEGOTIATION;
377
378 /* Start off with nStrobe and nAutoFd high, and nSelectIn low */
379 parport_frob_control (port,
380 PARPORT_CONTROL_STROBE
381 | PARPORT_CONTROL_AUTOFD
382 | PARPORT_CONTROL_SELECT,
383 PARPORT_CONTROL_SELECT);
384 udelay(1);
385
386 /* Event 0: Set data */
387 parport_data_forward (port);
388 parport_write_data (port, m);
389 udelay (400); /* Shouldn't need to wait this long. */
390
391 /* Event 1: Set nSelectIn high, nAutoFd low */
392 parport_frob_control (port,
393 PARPORT_CONTROL_SELECT
394 | PARPORT_CONTROL_AUTOFD,
395 PARPORT_CONTROL_AUTOFD);
396
397 /* Event 2: PError, Select, nFault go high, nAck goes low */
398 if (parport_wait_peripheral (port,
399 PARPORT_STATUS_ERROR
400 | PARPORT_STATUS_SELECT
401 | PARPORT_STATUS_PAPEROUT
402 | PARPORT_STATUS_ACK,
403 PARPORT_STATUS_ERROR
404 | PARPORT_STATUS_SELECT
405 | PARPORT_STATUS_PAPEROUT)) {
406 /* Timeout */
407 parport_frob_control (port,
408 PARPORT_CONTROL_SELECT
409 | PARPORT_CONTROL_AUTOFD,
410 PARPORT_CONTROL_SELECT);
411 DPRINTK (KERN_DEBUG
412 "%s: Peripheral not IEEE1284 compliant (0x%02X)\n",
413 port->name, parport_read_status (port));
414 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
415 return -1; /* Not IEEE1284 compliant */
416 }
417
418 /* Event 3: Set nStrobe low */
419 parport_frob_control (port,
420 PARPORT_CONTROL_STROBE,
421 PARPORT_CONTROL_STROBE);
422
423 /* Event 4: Set nStrobe and nAutoFd high */
424 udelay (5);
425 parport_frob_control (port,
426 PARPORT_CONTROL_STROBE
427 | PARPORT_CONTROL_AUTOFD,
428 0);
429
430 /* Event 6: nAck goes high */
431 if (parport_wait_peripheral (port,
432 PARPORT_STATUS_ACK,
433 PARPORT_STATUS_ACK)) {
434 /* This shouldn't really happen with a compliant device. */
435 DPRINTK (KERN_DEBUG
436 "%s: Mode 0x%02x not supported? (0x%02x)\n",
437 port->name, mode, port->ops->read_status (port));
438 parport_ieee1284_terminate (port);
439 return 1;
440 }
441
442 xflag = parport_read_status (port) & PARPORT_STATUS_SELECT;
443
444 /* xflag should be high for all modes other than nibble (0). */
445 if (mode && !xflag) {
446 /* Mode not supported. */
447 DPRINTK (KERN_DEBUG "%s: Mode 0x%02x rejected by peripheral\n",
448 port->name, mode);
449 parport_ieee1284_terminate (port);
450 return 1;
451 }
452
453 /* More to do if we've requested extensibility link. */
454 if (mode & IEEE1284_EXT_LINK) {
455 m = mode & 0x7f;
456 udelay (1);
457 parport_write_data (port, m);
458 udelay (1);
459
460 /* Event 51: Set nStrobe low */
461 parport_frob_control (port,
462 PARPORT_CONTROL_STROBE,
463 PARPORT_CONTROL_STROBE);
464
465 /* Event 52: nAck goes low */
466 if (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) {
467 /* This peripheral is _very_ slow. */
468 DPRINTK (KERN_DEBUG
469 "%s: Event 52 didn't happen\n",
470 port->name);
471 parport_ieee1284_terminate (port);
472 return 1;
473 }
474
475 /* Event 53: Set nStrobe high */
476 parport_frob_control (port,
477 PARPORT_CONTROL_STROBE,
478 0);
479
480 /* Event 55: nAck goes high */
481 if (parport_wait_peripheral (port,
482 PARPORT_STATUS_ACK,
483 PARPORT_STATUS_ACK)) {
484 /* This shouldn't really happen with a compliant
485 * device. */
486 DPRINTK (KERN_DEBUG
487 "%s: Mode 0x%02x not supported? (0x%02x)\n",
488 port->name, mode,
489 port->ops->read_status (port));
490 parport_ieee1284_terminate (port);
491 return 1;
492 }
493
494 /* Event 54: Peripheral sets XFlag to reflect support */
495 xflag = parport_read_status (port) & PARPORT_STATUS_SELECT;
496
497 /* xflag should be high. */
498 if (!xflag) {
499 /* Extended mode not supported. */
500 DPRINTK (KERN_DEBUG "%s: Extended mode 0x%02x not "
501 "supported\n", port->name, mode);
502 parport_ieee1284_terminate (port);
503 return 1;
504 }
505
506 /* Any further setup is left to the caller. */
507 }
508
509 /* Mode is supported */
510 DPRINTK (KERN_DEBUG "%s: In mode 0x%02x\n", port->name, mode);
511 port->ieee1284.mode = mode;
512
513 /* But ECP is special */
514 if (!(mode & IEEE1284_EXT_LINK) && (m & IEEE1284_MODE_ECP)) {
515 port->ieee1284.phase = IEEE1284_PH_ECP_SETUP;
516
517 /* Event 30: Set nAutoFd low */
518 parport_frob_control (port,
519 PARPORT_CONTROL_AUTOFD,
520 PARPORT_CONTROL_AUTOFD);
521
522 /* Event 31: PError goes high. */
523 r = parport_wait_peripheral (port,
524 PARPORT_STATUS_PAPEROUT,
525 PARPORT_STATUS_PAPEROUT);
526 if (r)
527 DPRINTK (KERN_INFO "%s: Timeout at event 31\n",
528 port->name);
529
530 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
531 DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n",
532 port->name);
533 } else switch (mode) {
534 case IEEE1284_MODE_NIBBLE:
535 case IEEE1284_MODE_BYTE:
536 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
537 break;
538 default:
539 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
540 }
541
542
543 return 0;
544 #endif /* IEEE1284 support */
545 }
546
547 /* Acknowledge that the peripheral has data available.
548 * Events 18-20, in order to get from Reverse Idle phase
549 * to Host Busy Data Available.
550 * This will most likely be called from an interrupt.
551 * Returns zero if data was available.
552 */
553 #ifdef CONFIG_PARPORT_1284
554 static int parport_ieee1284_ack_data_avail (struct parport *port)
555 {
556 if (parport_read_status (port) & PARPORT_STATUS_ERROR)
557 /* Event 18 didn't happen. */
558 return -1;
559
560 /* Event 20: nAutoFd goes high. */
561 port->ops->frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
562 port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
563 return 0;
564 }
565 #endif /* IEEE1284 support */
566
567 /* Handle an interrupt. */
568 void parport_ieee1284_interrupt (int which, void *handle, struct pt_regs *regs)
569 {
570 struct parport *port = handle;
571 parport_ieee1284_wakeup (port);
572
573 #ifdef CONFIG_PARPORT_1284
574 if (port->ieee1284.phase == IEEE1284_PH_REV_IDLE) {
575 /* An interrupt in this phase means that data
576 * is now available. */
577 DPRINTK (KERN_DEBUG "%s: Data available\n", port->name);
578 parport_ieee1284_ack_data_avail (port);
579 }
580 #endif /* IEEE1284 support */
581 }
582
583 /**
584 * parport_write - write a block of data to a parallel port
585 * @port: port to write to
586 * @buffer: data buffer (in kernel space)
587 * @len: number of bytes of data to transfer
588 *
589 * This will write up to @len bytes of @buffer to the port
590 * specified, using the IEEE 1284 transfer mode most recently
591 * negotiated to (using parport_negotiate()), as long as that
592 * mode supports forward transfers (host to peripheral).
593 *
594 * It is the caller's responsibility to ensure that the first
595 * @len bytes of @buffer are valid.
596 *
597 * This function returns the number of bytes transferred (if zero
598 * or positive), or else an error code.
599 */
600
601 ssize_t parport_write (struct parport *port, const void *buffer, size_t len)
602 {
603 #ifndef CONFIG_PARPORT_1284
604 return port->ops->compat_write_data (port, buffer, len, 0);
605 #else
606 ssize_t retval;
607 int mode = port->ieee1284.mode;
608 int addr = mode & IEEE1284_ADDR;
609 size_t (*fn) (struct parport *, const void *, size_t, int);
610
611 /* Ignore the device-ID-request bit and the address bit. */
612 mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
613
614 /* Use the mode we're in. */
615 switch (mode) {
616 case IEEE1284_MODE_NIBBLE:
617 parport_negotiate (port, IEEE1284_MODE_COMPAT);
618 case IEEE1284_MODE_COMPAT:
619 DPRINTK (KERN_DEBUG "%s: Using compatibility mode\n",
620 port->name);
621 fn = port->ops->compat_write_data;
622 break;
623
624 case IEEE1284_MODE_EPP:
625 DPRINTK (KERN_DEBUG "%s: Using EPP mode\n", port->name);
626 if (addr)
627 fn = port->ops->epp_write_addr;
628 else
629 fn = port->ops->epp_write_data;
630 break;
631
632 case IEEE1284_MODE_ECP:
633 case IEEE1284_MODE_ECPRLE:
634 DPRINTK (KERN_DEBUG "%s: Using ECP mode\n", port->name);
635 if (addr)
636 fn = port->ops->ecp_write_addr;
637 else
638 fn = port->ops->ecp_write_data;
639 break;
640
641 case IEEE1284_MODE_ECPSWE:
642 DPRINTK (KERN_DEBUG "%s: Using software-emulated ECP mode\n",
643 port->name);
644 /* The caller has specified that it must be emulated,
645 * even if we have ECP hardware! */
646 if (addr)
647 fn = parport_ieee1284_ecp_write_addr;
648 else
649 fn = parport_ieee1284_ecp_write_data;
650 break;
651
652 default:
653 DPRINTK (KERN_DEBUG "%s: Unknown mode 0x%02x\n", port->name,
654 port->ieee1284.mode);
655 return -ENOSYS;
656 }
657
658 retval = (*fn) (port, buffer, len, 0);
659 DPRINTK (KERN_DEBUG "%s: wrote %d/%d bytes\n", port->name, retval,
660 len);
661 return retval;
662 #endif /* IEEE1284 support */
663 }
664
665 /**
666 * parport_read - read a block of data from a parallel port
667 * @port: port to read from
668 * @buffer: data buffer (in kernel space)
669 * @len: number of bytes of data to transfer
670 *
671 * This will read up to @len bytes of @buffer to the port
672 * specified, using the IEEE 1284 transfer mode most recently
673 * negotiated to (using parport_negotiate()), as long as that
674 * mode supports reverse transfers (peripheral to host).
675 *
676 * It is the caller's responsibility to ensure that the first
677 * @len bytes of @buffer are available to write to.
678 *
679 * This function returns the number of bytes transferred (if zero
680 * or positive), or else an error code.
681 */
682
683 ssize_t parport_read (struct parport *port, void *buffer, size_t len)
684 {
685 #ifndef CONFIG_PARPORT_1284
686 printk (KERN_ERR "parport: IEEE1284 not supported in this kernel\n");
687 return -ENODEV;
688 #else
689 int mode = port->physport->ieee1284.mode;
690 int addr = mode & IEEE1284_ADDR;
691 size_t (*fn) (struct parport *, void *, size_t, int);
692
693 /* Ignore the device-ID-request bit and the address bit. */
694 mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
695
696 /* Use the mode we're in. */
697 switch (mode) {
698 case IEEE1284_MODE_COMPAT:
699 if (parport_negotiate (port, IEEE1284_MODE_NIBBLE))
700 return -EIO;
701 case IEEE1284_MODE_NIBBLE:
702 DPRINTK (KERN_DEBUG "%s: Using nibble mode\n", port->name);
703 fn = port->ops->nibble_read_data;
704 break;
705
706 case IEEE1284_MODE_BYTE:
707 DPRINTK (KERN_DEBUG "%s: Using byte mode\n", port->name);
708 fn = port->ops->byte_read_data;
709 break;
710
711 case IEEE1284_MODE_EPP:
712 DPRINTK (KERN_DEBUG "%s: Using EPP mode\n", port->name);
713 if (addr)
714 fn = port->ops->epp_read_addr;
715 else
716 fn = port->ops->epp_read_data;
717 break;
718
719 case IEEE1284_MODE_ECP:
720 case IEEE1284_MODE_ECPRLE:
721 DPRINTK (KERN_DEBUG "%s: Using ECP mode\n", port->name);
722 fn = port->ops->ecp_read_data;
723 break;
724
725 case IEEE1284_MODE_ECPSWE:
726 DPRINTK (KERN_DEBUG "%s: Using software-emulated ECP mode\n",
727 port->name);
728 fn = parport_ieee1284_ecp_read_data;
729 break;
730
731 default:
732 DPRINTK (KERN_DEBUG "%s: Unknown mode 0x%02x\n", port->name,
733 port->physport->ieee1284.mode);
734 return -ENOSYS;
735 }
736
737 return (*fn) (port, buffer, len, 0);
738 #endif /* IEEE1284 support */
739 }
740
741 /**
742 * parport_set_timeout - set the inactivity timeout for a device
743 * @dev: device on a port
744 * @inactivity: inactivity timeout (in jiffies)
745 *
746 * This sets the inactivity timeout for a particular device on a
747 * port. This affects functions like parport_wait_peripheral().
748 * The special value 0 means not to call schedule() while dealing
749 * with this device.
750 *
751 * The return value is the previous inactivity timeout.
752 *
753 * Any callers of parport_wait_event() for this device are woken
754 * up.
755 */
756
757 long parport_set_timeout (struct pardevice *dev, long inactivity)
758 {
759 long int old = dev->timeout;
760
761 dev->timeout = inactivity;
762
763 if (dev->port->physport->cad == dev)
764 parport_ieee1284_wakeup (dev->port);
765
766 return old;
767 }
768
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.