~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/parport/ieee1284_ops.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* IEEE-1284 operations for parport.
  2  *
  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.
  8  *
  9  * Note: Make no assumptions about hardware or architecture in this file!
 10  *
 11  * Author: Tim Waugh <tim@cyberelk.demon.co.uk>
 12  * Fixed AUTOFD polarity in ecp_forward_to_reverse().  Fred Barnes, 1999
 13  */
 14 
 15 
 16 #include <linux/config.h>
 17 #include <linux/parport.h>
 18 #include <linux/delay.h>
 19 #include <asm/uaccess.h>
 20 
 21 #define DEBUG /* undef me for production */
 22 
 23 #ifdef CONFIG_LP_CONSOLE
 24 #undef DEBUG /* Don't want a garbled console */
 25 #endif
 26 
 27 #ifdef DEBUG
 28 #define DPRINTK(stuff...) printk (stuff)
 29 #else
 30 #define DPRINTK(stuff...)
 31 #endif
 32 
 33 /***                                *
 34  * One-way data transfer functions. *
 35  *                                ***/
 36 
 37 /* Compatibility mode. */
 38 size_t parport_ieee1284_write_compat (struct parport *port,
 39                                       const void *buffer, size_t len,
 40                                       int flags)
 41 {
 42         int no_irq = 1;
 43         ssize_t count = 0;
 44         const unsigned char *addr = buffer;
 45         unsigned char byte;
 46         struct pardevice *dev = port->physport->cad;
 47         unsigned char ctl = (PARPORT_CONTROL_SELECT
 48                              | PARPORT_CONTROL_INIT);
 49 
 50         if (port->irq != PARPORT_IRQ_NONE) {
 51                 parport_enable_irq (port);
 52                 no_irq = 0;
 53 
 54                 /* Clear out previous irqs. */
 55                 while (!down_trylock (&port->physport->ieee1284.irq));
 56         }
 57 
 58         port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
 59         parport_write_control (port, ctl);
 60         parport_data_forward (port);
 61         while (count < len) {
 62                 long expire = jiffies + dev->timeout;
 63                 long wait = (HZ + 99) / 100;
 64                 unsigned char mask = (PARPORT_STATUS_ERROR
 65                                       | PARPORT_STATUS_BUSY);
 66                 unsigned char val = (PARPORT_STATUS_ERROR
 67                                      | PARPORT_STATUS_BUSY);
 68 
 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;
 75 
 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;
 89 
 90                         /* Have we run out of time? */
 91                         if (!time_before (jiffies, expire))
 92                                 break;
 93 
 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);
103                         }
104                         else
105                                 /* We must have the device claimed here */
106                                 parport_wait_event (port, wait);
107 
108                         /* Is there a signal pending? */
109                         if (signal_pending (current))
110                                 break;
111 
112                         /* Wait longer next time. */
113                         wait *= 2;
114                 } while (time_before (jiffies, expire));
115 
116                 if (signal_pending (current))
117                         break;
118 
119                 DPRINTK (KERN_DEBUG "%s: Timed out\n", port->name);
120                 break;
121 
122         ready:
123                 /* Write the character to the data lines. */
124                 byte = *addr++;
125                 parport_write_data (port, byte);
126                 udelay (1);
127 
128                 /* Pulse strobe. */
129                 parport_write_control (port, ctl | PARPORT_CONTROL_STROBE);
130                 udelay (1); /* strobe */
131 
132                 parport_write_control (port, ctl);
133                 udelay (1); /* hold */
134 
135                 /* Assume the peripheral received it. */
136                 count++;
137 
138                 /* Let another process run if it needs to. */
139                 if (time_before (jiffies, expire))
140                         if (!parport_yield_blocking (dev)
141                             && current->need_resched)
142                                 schedule ();
143         }
144  stop:
145         port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
146 
147         return count;
148 }
149 
150 /* Nibble mode. */
151 size_t parport_ieee1284_read_nibble (struct parport *port, 
152                                      void *buffer, size_t len,
153                                      int flags)
154 {
155 #ifndef CONFIG_PARPORT_1284
156         return 0;
157 #else
158         unsigned char *buf = buffer;
159         int i;
160         unsigned char byte = 0;
161 
162         len *= 2; /* in nibbles */
163         for (i=0; i < len; i++) {
164                 unsigned char nibble;
165 
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);
173 
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;
180                 }
181 
182                 /* Event 7: Set nAutoFd low. */
183                 parport_frob_control (port,
184                                       PARPORT_CONTROL_AUTOFD,
185                                       PARPORT_CONTROL_AUTOFD);
186 
187                 /* Event 9: nAck goes low. */
188                 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
189                 if (parport_wait_peripheral (port,
190                                              PARPORT_STATUS_ACK, 0)) {
191                         /* Timeout -- no more data? */
192                         DPRINTK (KERN_DEBUG
193                                  "%s: Nibble timeout at event 9 (%d bytes)\n",
194                                  port->name, i/2);
195                         break;
196                 }
197 
198 
199                 /* Read a nibble. */
200                 nibble = parport_read_status (port) >> 3;
201                 nibble &= ~8;
202                 if ((nibble & 0x10) == 0)
203                         nibble |= 8;
204                 nibble &= 0xf;
205 
206                 /* Event 10: Set nAutoFd high. */
207                 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
208 
209                 /* Event 11: nAck goes high. */
210                 if (parport_wait_peripheral (port,
211                                              PARPORT_STATUS_ACK,
212                                              PARPORT_STATUS_ACK)) {
213                         /* Timeout -- no more data? */
214                         DPRINTK (KERN_DEBUG
215                                  "%s: Nibble timeout at event 11\n",
216                                  port->name);
217                         break;
218                 }
219 
220                 if (i & 1) {
221                         /* Second nibble */
222                         byte |= nibble << 4;
223                         *buf++ = byte;
224                 } else 
225                         byte = nibble;
226         }
227 
228         i /= 2; /* i is now in bytes */
229 
230         if (i == len) {
231                 /* Read the last nibble without checking data avail. */
232                 port = port->physport;
233                 if (parport_read_status (port) & PARPORT_STATUS_ERROR)
234                         port->ieee1284.phase = IEEE1284_PH_HBUSY_DNA;
235                 else
236                         port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
237         }
238 
239         return i;
240 #endif /* IEEE1284 support */
241 }
242 
243 /* Byte mode. */
244 size_t parport_ieee1284_read_byte (struct parport *port,
245                                    void *buffer, size_t len,
246                                    int flags)
247 {
248 #ifndef CONFIG_PARPORT_1284
249         return 0;
250 #else
251         unsigned char *buf = buffer;
252         ssize_t count = 0;
253 
254         for (count = 0; count < len; count++) {
255                 unsigned char byte;
256 
257                 /* Data available? */
258                 if (parport_read_status (port) & PARPORT_STATUS_ERROR) {
259                         port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DNA;
260                         DPRINTK (KERN_DEBUG
261                                  "%s: No more byte data (%Zd bytes)\n",
262                                  port->name, count);
263 
264                         /* Go to reverse idle phase. */
265                         parport_frob_control (port,
266                                               PARPORT_CONTROL_AUTOFD,
267                                               PARPORT_CONTROL_AUTOFD);
268                         port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE;
269                         break;
270                 }
271 
272                 /* Event 14: Place data bus in high impedance state. */
273                 parport_data_reverse (port);
274 
275                 /* Event 7: Set nAutoFd low. */
276                 parport_frob_control (port,
277                                       PARPORT_CONTROL_AUTOFD,
278                                       PARPORT_CONTROL_AUTOFD);
279 
280                 /* Event 9: nAck goes low. */
281                 port->physport->ieee1284.phase = IEEE1284_PH_REV_DATA;
282                 if (parport_wait_peripheral (port,
283                                              PARPORT_STATUS_ACK,
284                                              0)) {
285                         /* Timeout -- no more data? */
286                         parport_frob_control (port, PARPORT_CONTROL_AUTOFD,
287                                                  0);
288                         DPRINTK (KERN_DEBUG "%s: Byte timeout at event 9\n",
289                                  port->name);
290                         break;
291                 }
292 
293                 byte = parport_read_data (port);
294                 *buf++ = byte;
295 
296                 /* Event 10: Set nAutoFd high */
297                 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
298 
299                 /* Event 11: nAck goes high. */
300                 if (parport_wait_peripheral (port,
301                                              PARPORT_STATUS_ACK,
302                                              PARPORT_STATUS_ACK)) {
303                         /* Timeout -- no more data? */
304                         DPRINTK (KERN_DEBUG "%s: Byte timeout at event 11\n",
305                                  port->name);
306                         break;
307                 }
308 
309                 /* Event 16: Set nStrobe low. */
310                 parport_frob_control (port,
311                                       PARPORT_CONTROL_STROBE,
312                                       PARPORT_CONTROL_STROBE);
313                 udelay (5);
314 
315                 /* Event 17: Set nStrobe high. */
316                 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
317         }
318 
319         if (count == len) {
320                 /* Read the last byte without checking data avail. */
321                 port = port->physport;
322                 if (parport_read_status (port) & PARPORT_STATUS_ERROR)
323                         port->ieee1284.phase = IEEE1284_PH_HBUSY_DNA;
324                 else
325                         port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
326         }
327 
328         return count;
329 #endif /* IEEE1284 support */
330 }
331 
332 /***              *
333  * ECP Functions. *
334  *              ***/
335 
336 #ifdef CONFIG_PARPORT_1284
337 
338 static inline
339 int ecp_forward_to_reverse (struct parport *port)
340 {
341         int retval;
342 
343         /* Event 38: Set nAutoFd low */
344         parport_frob_control (port,
345                               PARPORT_CONTROL_AUTOFD,
346                               PARPORT_CONTROL_AUTOFD);
347         parport_data_reverse (port);
348         udelay (5);
349 
350         /* Event 39: Set nInit low to initiate bus reversal */
351         parport_frob_control (port,
352                               PARPORT_CONTROL_INIT,
353                               0);
354 
355         /* Event 40: PError goes low */
356         retval = parport_wait_peripheral (port,
357                                           PARPORT_STATUS_PAPEROUT, 0);
358 
359         if (!retval) {
360                 DPRINTK (KERN_DEBUG "%s: ECP direction: reverse\n",
361                          port->name);
362                 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
363         }
364 
365         return retval;
366 }
367 
368 static inline
369 int ecp_reverse_to_forward (struct parport *port)
370 {
371         int retval;
372 
373         /* Event 47: Set nInit high */
374         parport_frob_control (port,
375                               PARPORT_CONTROL_INIT
376                               | PARPORT_CONTROL_AUTOFD,
377                               PARPORT_CONTROL_INIT
378                               | PARPORT_CONTROL_AUTOFD);
379 
380         /* Event 49: PError goes high */
381         retval = parport_wait_peripheral (port,
382                                           PARPORT_STATUS_PAPEROUT,
383                                           PARPORT_STATUS_PAPEROUT);
384 
385         if (!retval) {
386                 parport_data_forward (port);
387                 DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n",
388                          port->name);
389                 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
390         }
391 
392         return retval;
393 }
394 
395 #endif /* IEEE1284 support */
396 
397 /* ECP mode, forward channel, data. */
398 size_t parport_ieee1284_ecp_write_data (struct parport *port,
399                                         const void *buffer, size_t len,
400                                         int flags)
401 {
402 #ifndef CONFIG_PARPORT_1284
403         return 0;
404 #else
405         const unsigned char *buf = buffer;
406         size_t written;
407         int retry;
408 
409         port = port->physport;
410 
411         if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE)
412                 if (ecp_reverse_to_forward (port))
413                         return 0;
414 
415         port->ieee1284.phase = IEEE1284_PH_FWD_DATA;
416 
417         /* HostAck high (data, not command) */
418         parport_frob_control (port,
419                               PARPORT_CONTROL_AUTOFD
420                               | PARPORT_CONTROL_STROBE
421                               | PARPORT_CONTROL_INIT,
422                               PARPORT_CONTROL_INIT);
423         for (written = 0; written < len; written++, buf++) {
424                 long expire = jiffies + port->cad->timeout;
425                 unsigned char byte;
426 
427                 byte = *buf;
428         try_again:
429                 parport_write_data (port, byte);
430                 parport_frob_control (port, PARPORT_CONTROL_STROBE,
431                                       PARPORT_CONTROL_STROBE);
432                 udelay (5);
433                 for (retry = 0; retry < 100; retry++) {
434                         if (!parport_wait_peripheral (port,
435                                                       PARPORT_STATUS_BUSY, 0))
436                                 goto success;
437 
438                         if (signal_pending (current)) {
439                                 parport_frob_control (port,
440                                                       PARPORT_CONTROL_STROBE,
441                                                       0);
442                                 break;
443                         }
444                 }
445 
446                 /* Time for Host Transfer Recovery (page 41 of IEEE1284) */
447                 DPRINTK (KERN_DEBUG "%s: ECP transfer stalled!\n", port->name);
448 
449                 parport_frob_control (port, PARPORT_CONTROL_INIT,
450                                       PARPORT_CONTROL_INIT);
451                 udelay (50);
452                 if (parport_read_status (port) & PARPORT_STATUS_PAPEROUT) {
453                         /* It's buggered. */
454                         parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
455                         break;
456                 }
457 
458                 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
459                 udelay (50);
460                 if (!(parport_read_status (port) & PARPORT_STATUS_PAPEROUT))
461                         break;
462 
463                 DPRINTK (KERN_DEBUG "%s: Host transfer recovered\n",
464                          port->name);
465 
466                 if (time_after_eq (jiffies, expire)) break;
467                 goto try_again;
468         success:
469                 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
470                 udelay (5);
471                 if (parport_wait_peripheral (port,
472                                              PARPORT_STATUS_BUSY,
473                                              PARPORT_STATUS_BUSY))
474                         /* Peripheral hasn't accepted the data. */
475                         break;
476         }
477 
478         port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
479 
480         return written;
481 #endif /* IEEE1284 support */
482 }
483 
484 /* ECP mode, reverse channel, data. */
485 size_t parport_ieee1284_ecp_read_data (struct parport *port,
486                                        void *buffer, size_t len, int flags)
487 {
488 #ifndef CONFIG_PARPORT_1284
489         return 0;
490 #else
491         struct pardevice *dev = port->cad;
492         unsigned char *buf = buffer;
493         int rle_count = 0; /* shut gcc up */
494         int rle = 0;
495         ssize_t count = 0;
496 
497         port = port->physport;
498 
499         if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE)
500                 if (ecp_forward_to_reverse (port))
501                         return 0;
502 
503         port->ieee1284.phase = IEEE1284_PH_REV_DATA;
504 
505         /* Set HostAck low to start accepting data. */
506         parport_frob_control (port,
507                               PARPORT_CONTROL_AUTOFD
508                               | PARPORT_CONTROL_STROBE
509                               | PARPORT_CONTROL_INIT,
510                               PARPORT_CONTROL_AUTOFD);
511         while (count < len) {
512                 long expire = jiffies + dev->timeout;
513                 unsigned char byte;
514                 int command;
515 
516                 /* Event 43: Peripheral sets nAck low. It can take as
517                    long as it wants. */
518                 while (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) {
519                         /* The peripheral hasn't given us data in
520                            35ms.  If we have data to give back to the
521                            caller, do it now. */
522                         if (count)
523                                 goto out;
524 
525                         /* If we've used up all the time we were allowed,
526                            give up altogether. */
527                         if (!time_before (jiffies, expire))
528                                 goto out;
529 
530                         /* Yield the port for a while. */
531                         if (count && dev->port->irq != PARPORT_IRQ_NONE) {
532                                 parport_release (dev);
533                                 __set_current_state (TASK_INTERRUPTIBLE);
534                                 schedule_timeout ((HZ + 24) / 25);
535                                 parport_claim_or_block (dev);
536                         }
537                         else
538                                 /* We must have the device claimed here. */
539                                 parport_wait_event (port, (HZ + 24) / 25);
540 
541                         /* Is there a signal pending? */
542                         if (signal_pending (current))
543                                 goto out;
544                 }
545 
546                 /* Is this a command? */
547                 if (rle)
548                         /* The last byte was a run-length count, so
549                            this can't be as well. */
550                         command = 0;
551                 else
552                         command = (parport_read_status (port) &
553                                    PARPORT_STATUS_BUSY) ? 1 : 0;
554 
555                 /* Read the data. */
556                 byte = parport_read_data (port);
557 
558                 /* If this is a channel command, rather than an RLE
559                    command or a normal data byte, don't accept it. */
560                 if (command) {
561                         if (byte & 0x80) {
562                                 DPRINTK (KERN_DEBUG "%s: stopping short at "
563                                          "channel command (%02x)\n",
564                                          port->name, byte);
565                                 goto out;
566                         }
567                         else if (port->ieee1284.mode != IEEE1284_MODE_ECPRLE)
568                                 DPRINTK (KERN_DEBUG "%s: device illegally "
569                                          "using RLE; accepting anyway\n",
570                                          port->name);
571 
572                         rle_count = byte + 1;
573 
574                         /* Are we allowed to read that many bytes? */
575                         if (rle_count > (len - count)) {
576                                 DPRINTK (KERN_DEBUG "%s: leaving %d RLE bytes "
577                                          "for next time\n", port->name,
578                                          rle_count);
579                                 break;
580                         }
581 
582                         rle = 1;
583                 }
584 
585                 /* Event 44: Set HostAck high, acknowledging handshake. */
586                 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
587 
588                 /* Event 45: The peripheral has 35ms to set nAck high. */
589                 if (parport_wait_peripheral (port, PARPORT_STATUS_ACK,
590                                              PARPORT_STATUS_ACK)) {
591                         /* It's gone wrong.  Return what data we have
592                            to the caller. */
593                         DPRINTK (KERN_DEBUG "ECP read timed out at 45\n");
594 
595                         if (command)
596                                 printk (KERN_WARNING
597                                         "%s: command ignored (%02x)\n",
598                                         port->name, byte);
599 
600                         break;
601                 }
602 
603                 /* Event 46: Set HostAck low and accept the data. */
604                 parport_frob_control (port,
605                                       PARPORT_CONTROL_AUTOFD,
606                                       PARPORT_CONTROL_AUTOFD);
607 
608                 /* If we just read a run-length count, fetch the data. */
609                 if (command)
610                         continue;
611 
612                 /* If this is the byte after a run-length count, decompress. */
613                 if (rle) {
614                         rle = 0;
615                         memset (buf, byte, rle_count);
616                         buf += rle_count;
617                         count += rle_count;
618                         DPRINTK (KERN_DEBUG "%s: decompressed to %d bytes\n",
619                                  port->name, rle_count);
620                 } else {
621                         /* Normal data byte. */
622                         *buf = byte;
623                         buf++, count++;
624                 }
625         }
626 
627  out:
628         port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
629         return count;
630 #endif /* IEEE1284 support */
631 }
632 
633 /* ECP mode, forward channel, commands. */
634 size_t parport_ieee1284_ecp_write_addr (struct parport *port,
635                                         const void *buffer, size_t len,
636                                         int flags)
637 {
638 #ifndef CONFIG_PARPORT_1284
639         return 0;
640 #else
641         const unsigned char *buf = buffer;
642         size_t written;
643         int retry;
644 
645         port = port->physport;
646 
647         if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE)
648                 if (ecp_reverse_to_forward (port))
649                         return 0;
650 
651         port->ieee1284.phase = IEEE1284_PH_FWD_DATA;
652 
653         /* HostAck low (command, not data) */
654         parport_frob_control (port,
655                               PARPORT_CONTROL_AUTOFD
656                               | PARPORT_CONTROL_STROBE
657                               | PARPORT_CONTROL_INIT,
658                               PARPORT_CONTROL_AUTOFD
659                               | PARPORT_CONTROL_INIT);
660         for (written = 0; written < len; written++, buf++) {
661                 long expire = jiffies + port->cad->timeout;
662                 unsigned char byte;
663 
664                 byte = *buf;
665         try_again:
666                 parport_write_data (port, byte);
667                 parport_frob_control (port, PARPORT_CONTROL_STROBE,
668                                       PARPORT_CONTROL_STROBE);
669                 udelay (5);
670                 for (retry = 0; retry < 100; retry++) {
671                         if (!parport_wait_peripheral (port,
672                                                       PARPORT_STATUS_BUSY, 0))
673                                 goto success;
674 
675                         if (signal_pending (current)) {
676                                 parport_frob_control (port,
677                                                       PARPORT_CONTROL_STROBE,
678                                                       0);
679                                 break;
680                         }
681                 }
682 
683                 /* Time for Host Transfer Recovery (page 41 of IEEE1284) */
684                 DPRINTK (KERN_DEBUG "%s: ECP transfer stalled!\n", port->name);
685 
686                 parport_frob_control (port, PARPORT_CONTROL_INIT,
687                                       PARPORT_CONTROL_INIT);
688                 udelay (50);
689                 if (parport_read_status (port) & PARPORT_STATUS_PAPEROUT) {
690                         /* It's buggered. */
691                         parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
692                         break;
693                 }
694 
695                 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
696                 udelay (50);
697                 if (!(parport_read_status (port) & PARPORT_STATUS_PAPEROUT))
698                         break;
699 
700                 DPRINTK (KERN_DEBUG "%s: Host transfer recovered\n",
701                          port->name);
702 
703                 if (time_after_eq (jiffies, expire)) break;
704                 goto try_again;
705         success:
706                 parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
707                 udelay (5);
708                 if (parport_wait_peripheral (port,
709                                              PARPORT_STATUS_BUSY,
710                                              PARPORT_STATUS_BUSY))
711                         /* Peripheral hasn't accepted the data. */
712                         break;
713         }
714 
715         port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
716 
717         return written;
718 #endif /* IEEE1284 support */
719 }
720 
721 /***              *
722  * EPP functions. *
723  *              ***/
724 
725 /* EPP mode, forward channel, data. */
726 size_t parport_ieee1284_epp_write_data (struct parport *port,
727                                         const void *buffer, size_t len,
728                                         int flags)
729 {
730         /* This is untested */
731         unsigned char *bp = (unsigned char *) buffer;
732         size_t ret = 0;
733 
734         parport_frob_control (port,
735                               PARPORT_CONTROL_STROBE |
736                               PARPORT_CONTROL_AUTOFD |
737                               PARPORT_CONTROL_SELECT,
738                               PARPORT_CONTROL_STROBE |
739                               PARPORT_CONTROL_SELECT);
740         port->ops->data_forward (port);
741         for (; len > 0; len--, bp++) {
742                 /* Event 62: Write data and strobe data */
743                 parport_write_data (port, *bp);
744                 parport_frob_control (port, PARPORT_CONTROL_AUTOFD,
745                                       PARPORT_CONTROL_AUTOFD);
746 
747                 /* Event 58 */
748                 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 10))
749                         break;
750 
751                 /* Event 63 */
752                 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
753 
754                 /* Event 60 */
755                 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
756                                              PARPORT_STATUS_BUSY, 5))
757                         break;
758 
759                 ret++;
760         }
761 
762         /* Event 61 */
763         parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
764 
765         return ret;
766 }
767 
768 /* EPP mode, reverse channel, data. */
769 size_t parport_ieee1284_epp_read_data (struct parport *port,
770                                        void *buffer, size_t len,
771                                        int flags)
772 {
773         /* This is untested. */
774         unsigned char *bp = (unsigned char *) buffer;
775         unsigned ret = 0;
776 
777         parport_frob_control (port,
778                               PARPORT_CONTROL_STROBE |
779                               PARPORT_CONTROL_SELECT, 0);
780         port->ops->data_reverse (port);
781         for (; len > 0; len--, bp++) {
782                 parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
783 
784                 /* Event 58 */
785                 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
786                                              PARPORT_STATUS_BUSY, 10))
787                         break;
788 
789                 *bp = parport_read_data (port);
790 
791                 parport_frob_control (port, PARPORT_CONTROL_AUTOFD,
792                                       PARPORT_CONTROL_AUTOFD);
793 
794                 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 5))
795                         break;
796 
797                 ret++;
798         }
799         port->ops->data_forward (port);
800 
801         return ret;
802 }
803 
804 /* EPP mode, forward channel, addresses. */
805 size_t parport_ieee1284_epp_write_addr (struct parport *port,
806                                         const void *buffer, size_t len,
807                                         int flags)
808 {
809         /* This is untested */
810         unsigned char *bp = (unsigned char *) buffer;
811         size_t ret = 0;
812 
813         parport_frob_control (port,
814                               PARPORT_CONTROL_STROBE |
815                               PARPORT_CONTROL_SELECT |
816                               PARPORT_CONTROL_AUTOFD,
817                               PARPORT_CONTROL_STROBE |
818                               PARPORT_CONTROL_SELECT);
819         port->ops->data_forward (port);
820         for (; len > 0; len--, bp++) {
821                 /* Write data and assert nAStrb. */
822                 parport_write_data (port, *bp);
823                 parport_frob_control (port, PARPORT_CONTROL_SELECT,
824                                       PARPORT_CONTROL_SELECT);
825 
826                 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
827                                              PARPORT_STATUS_BUSY, 10))
828                         break;
829 
830                 parport_frob_control (port, PARPORT_CONTROL_SELECT, 0);
831 
832                 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 5))
833                         break;
834 
835                 ret++;
836         }
837 
838         parport_frob_control (port, PARPORT_CONTROL_STROBE, 0);
839 
840         return ret;
841 }
842 
843 /* EPP mode, reverse channel, addresses. */
844 size_t parport_ieee1284_epp_read_addr (struct parport *port,
845                                        void *buffer, size_t len,
846                                        int flags)
847 {
848         /* This is untested. */
849         unsigned char *bp = (unsigned char *) buffer;
850         unsigned ret = 0;
851 
852         parport_frob_control (port,
853                               PARPORT_CONTROL_STROBE |
854                               PARPORT_CONTROL_AUTOFD, 0);
855         port->ops->data_reverse (port);
856         for (; len > 0; len--, bp++) {
857                 parport_frob_control (port, PARPORT_CONTROL_SELECT, 0);
858 
859                 /* Event 58 */
860                 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY,
861                                              PARPORT_STATUS_BUSY, 10))
862                         break;
863 
864                 *bp = parport_read_data (port);
865 
866                 parport_frob_control (port, PARPORT_CONTROL_SELECT,
867                                       PARPORT_CONTROL_SELECT);
868 
869                 if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 5))
870                         break;
871 
872                 ret++;
873         }
874         port->ops->data_forward (port);
875 
876         return ret;
877 }
878 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.