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

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

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

  1 /* Low-level parallel-port routines for 8255-based PC-style hardware.
  2  * 
  3  * Authors: Phil Blundell <Philip.Blundell@pobox.com>
  4  *          Tim Waugh <tim@cyberelk.demon.co.uk>
  5  *          Jose Renau <renau@acm.org>
  6  *          David Campbell <campbell@torque.net>
  7  *          Andrea Arcangeli
  8  *
  9  * based on work by Grant Guenther <grant@torque.net> and Phil Blundell.
 10  *
 11  * Cleaned up include files - Russell King <linux@arm.uk.linux.org>
 12  * DMA support - Bert De Jonghe <bert@sophis.be>
 13  * Many ECP bugs fixed.  Fred Barnes & Jamie Lokier, 1999
 14  */
 15 
 16 /* This driver should work with any hardware that is broadly compatible
 17  * with that in the IBM PC.  This applies to the majority of integrated
 18  * I/O chipsets that are commonly available.  The expected register
 19  * layout is:
 20  *
 21  *      base+0          data
 22  *      base+1          status
 23  *      base+2          control
 24  *
 25  * In addition, there are some optional registers:
 26  *
 27  *      base+3          EPP address
 28  *      base+4          EPP data
 29  *      base+0x400      ECP config A
 30  *      base+0x401      ECP config B
 31  *      base+0x402      ECP control
 32  *
 33  * All registers are 8 bits wide and read/write.  If your hardware differs
 34  * only in register addresses (eg because your registers are on 32-bit
 35  * word boundaries) then you can alter the constants in parport_pc.h to
 36  * accomodate this.
 37  *
 38  * Note that the ECP registers may not start at offset 0x400 for PCI cards,
 39  * but rather will start at port->base_hi.
 40  */
 41 
 42 #include <linux/config.h>
 43 #include <linux/module.h>
 44 #include <linux/init.h>
 45 #include <linux/sched.h>
 46 #include <linux/delay.h>
 47 #include <linux/errno.h>
 48 #include <linux/interrupt.h>
 49 #include <linux/ioport.h>
 50 #include <linux/kernel.h>
 51 #include <linux/malloc.h>
 52 #include <linux/pci.h>
 53 #include <linux/sysctl.h>
 54 
 55 #include <asm/io.h>
 56 #include <asm/dma.h>
 57 #include <asm/uaccess.h>
 58 
 59 #include <linux/parport.h>
 60 #include <linux/parport_pc.h>
 61 #include <asm/parport.h>
 62 
 63 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
 64 
 65 /* ECR modes */
 66 #define ECR_SPP 00
 67 #define ECR_PS2 01
 68 #define ECR_PPF 02
 69 #define ECR_ECP 03
 70 #define ECR_EPP 04
 71 #define ECR_VND 05
 72 #define ECR_TST 06
 73 #define ECR_CNF 07
 74 
 75 #undef DEBUG
 76 
 77 #ifdef DEBUG
 78 #define DPRINTK  printk
 79 #else
 80 #define DPRINTK(stuff...)
 81 #endif
 82 
 83 
 84 #define NR_SUPERIOS 3
 85 static struct superio_struct {  /* For Super-IO chips autodetection */
 86         int io;
 87         int irq;
 88         int dma;
 89 } superios[NR_SUPERIOS] __devinitdata = { {0,},};
 90 
 91 static int user_specified __devinitdata = 0;
 92 
 93 /* frob_control, but for ECR */
 94 static void frob_econtrol (struct parport *pb, unsigned char m,
 95                            unsigned char v)
 96 {
 97         unsigned char ectr = inb (ECONTROL (pb));
 98         DPRINTK (KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n",
 99                 m, v, ectr, (ectr & ~m) ^ v);
100 
101         outb ((ectr & ~m) ^ v, ECONTROL (pb));
102 }
103 
104 #ifdef CONFIG_PARPORT_PC_FIFO
105 /* Safely change the mode bits in the ECR 
106    Returns:
107             0    : Success
108            -EBUSY: Could not drain FIFO in some finite amount of time,
109                    mode not changed!
110  */
111 static int change_mode(struct parport *p, int m)
112 {
113         const struct parport_pc_private *priv = p->physport->private_data;
114         int ecr = ECONTROL(p);
115         unsigned char oecr;
116         int mode;
117 
118         DPRINTK("parport change_mode ECP-ISA to mode 0x%02x\n",m);
119 
120         if (!priv->ecr) {
121                 printk (KERN_DEBUG "change_mode: but there's no ECR!\n");
122                 return 0;
123         }
124 
125         /* Bits <7:5> contain the mode. */
126         oecr = inb (ecr);
127         mode = (oecr >> 5) & 0x7;
128         if (mode == m) return 0;
129 
130         if (mode >= 2 && !(priv->ctr & 0x20)) {
131                 /* This mode resets the FIFO, so we may
132                  * have to wait for it to drain first. */
133                 long expire = jiffies + p->physport->cad->timeout;
134                 int counter;
135                 switch (mode) {
136                 case ECR_PPF: /* Parallel Port FIFO mode */
137                 case ECR_ECP: /* ECP Parallel Port mode */
138                         /* Busy wait for 200us */
139                         for (counter = 0; counter < 40; counter++) {
140                                 if (inb (ECONTROL (p)) & 0x01)
141                                         break;
142                                 if (signal_pending (current)) break;
143                                 udelay (5);
144                         }
145 
146                         /* Poll slowly. */
147                         while (!(inb (ECONTROL (p)) & 0x01)) {
148                                 if (time_after_eq (jiffies, expire))
149                                         /* The FIFO is stuck. */
150                                         return -EBUSY;
151                                 __set_current_state (TASK_INTERRUPTIBLE);
152                                 schedule_timeout ((HZ + 99) / 100);
153                                 if (signal_pending (current))
154                                         break;
155                         }
156                 }
157         }
158 
159         if (mode >= 2 && m >= 2) {
160                 /* We have to go through mode 001 */
161                 oecr &= ~(7 << 5);
162                 oecr |= ECR_PS2 << 5;
163                 outb (oecr, ecr);
164         }
165 
166         /* Set the mode. */
167         oecr &= ~(7 << 5);
168         oecr |= m << 5;
169         outb (oecr, ecr);
170         return 0;
171 }
172 
173 #ifdef CONFIG_PARPORT_1284
174 /* Find FIFO lossage; FIFO is reset */
175 static int get_fifo_residue (struct parport *p)
176 {
177         int residue;
178         int cnfga;
179         const struct parport_pc_private *priv = p->physport->private_data;
180 
181         /* Adjust for the contents of the FIFO. */
182         for (residue = priv->fifo_depth; ; residue--) {
183                 if (inb (ECONTROL (p)) & 0x2)
184                                 /* Full up. */
185                         break;
186 
187                 outb (0, FIFO (p));
188         }
189 
190         printk (KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name,
191                 residue);
192 
193         /* Reset the FIFO. */
194         frob_econtrol (p, 0xe0, ECR_PS2 << 5);
195 
196         /* Now change to config mode and clean up. FIXME */
197         frob_econtrol (p, 0xe0, ECR_CNF << 5);
198         cnfga = inb (CONFIGA (p));
199         printk (KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga);
200 
201         if (!(cnfga & (1<<2))) {
202                 printk (KERN_DEBUG "%s: Accounting for extra byte\n", p->name);
203                 residue++;
204         }
205 
206         /* Don't care about partial PWords until support is added for
207          * PWord != 1 byte. */
208 
209         /* Back to PS2 mode. */
210         frob_econtrol (p, 0xe0, ECR_PS2 << 5);
211 
212         return residue;
213 }
214 #endif /* IEEE 1284 support */
215 #endif /* FIFO support */
216 
217 /*
218  * Clear TIMEOUT BIT in EPP MODE
219  *
220  * This is also used in SPP detection.
221  */
222 static int clear_epp_timeout(struct parport *pb)
223 {
224         unsigned char r;
225 
226         if (!(parport_pc_read_status(pb) & 0x01))
227                 return 1;
228 
229         /* To clear timeout some chips require double read */
230         parport_pc_read_status(pb);
231         r = parport_pc_read_status(pb);
232         outb (r | 0x01, STATUS (pb)); /* Some reset by writing 1 */
233         outb (r & 0xfe, STATUS (pb)); /* Others by writing 0 */
234         r = parport_pc_read_status(pb);
235 
236         return !(r & 0x01);
237 }
238 
239 /*
240  * Access functions.
241  *
242  * Most of these aren't static because they may be used by the
243  * parport_xxx_yyy macros.  extern __inline__ versions of several
244  * of these are in parport_pc.h.
245  */
246 
247 static void parport_pc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
248 {
249         parport_generic_irq(irq, (struct parport *) dev_id, regs);
250 }
251 
252 void parport_pc_write_data(struct parport *p, unsigned char d)
253 {
254         outb (d, DATA (p));
255 }
256 
257 unsigned char parport_pc_read_data(struct parport *p)
258 {
259         return inb (DATA (p));
260 }
261 
262 void parport_pc_write_control(struct parport *p, unsigned char d)
263 {
264         const unsigned char wm = (PARPORT_CONTROL_STROBE |
265                                   PARPORT_CONTROL_AUTOFD |
266                                   PARPORT_CONTROL_INIT |
267                                   PARPORT_CONTROL_SELECT);
268 
269         /* Take this out when drivers have adapted to the newer interface. */
270         if (d & 0x20) {
271                 printk (KERN_DEBUG "%s (%s): use data_reverse for this!\n",
272                         p->name, p->cad->name);
273                 parport_pc_data_reverse (p);
274         }
275 
276         __parport_pc_frob_control (p, wm, d & wm);
277 }
278 
279 unsigned char parport_pc_read_control(struct parport *p)
280 {
281         const unsigned char wm = (PARPORT_CONTROL_STROBE |
282                                   PARPORT_CONTROL_AUTOFD |
283                                   PARPORT_CONTROL_INIT |
284                                   PARPORT_CONTROL_SELECT);
285         const struct parport_pc_private *priv = p->physport->private_data;
286         return priv->ctr & wm; /* Use soft copy */
287 }
288 
289 unsigned char parport_pc_frob_control (struct parport *p, unsigned char mask,
290                                        unsigned char val)
291 {
292         const unsigned char wm = (PARPORT_CONTROL_STROBE |
293                                   PARPORT_CONTROL_AUTOFD |
294                                   PARPORT_CONTROL_INIT |
295                                   PARPORT_CONTROL_SELECT);
296 
297         /* Take this out when drivers have adapted to the newer interface. */
298         if (mask & 0x20) {
299                 printk (KERN_DEBUG "%s (%s): use data_%s for this!\n",
300                         p->name, p->cad->name,
301                         (val & 0x20) ? "reverse" : "forward");
302                 if (val & 0x20)
303                         parport_pc_data_reverse (p);
304                 else
305                         parport_pc_data_forward (p);
306         }
307 
308         /* Restrict mask and val to control lines. */
309         mask &= wm;
310         val &= wm;
311 
312         return __parport_pc_frob_control (p, mask, val);
313 }
314 
315 unsigned char parport_pc_read_status(struct parport *p)
316 {
317         return inb (STATUS (p));
318 }
319 
320 void parport_pc_disable_irq(struct parport *p)
321 {
322         __parport_pc_frob_control (p, 0x10, 0);
323 }
324 
325 void parport_pc_enable_irq(struct parport *p)
326 {
327         __parport_pc_frob_control (p, 0x10, 0x10);
328 }
329 
330 void parport_pc_data_forward (struct parport *p)
331 {
332         __parport_pc_frob_control (p, 0x20, 0);
333 }
334 
335 void parport_pc_data_reverse (struct parport *p)
336 {
337         __parport_pc_frob_control (p, 0x20, 0x20);
338 }
339 
340 void parport_pc_init_state(struct pardevice *dev, struct parport_state *s)
341 {
342         s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0);
343         s->u.pc.ecr = 0x24;
344 }
345 
346 void parport_pc_save_state(struct parport *p, struct parport_state *s)
347 {
348         const struct parport_pc_private *priv = p->physport->private_data;
349         s->u.pc.ctr = inb (CONTROL (p));
350         if (priv->ecr)
351                 s->u.pc.ecr = inb (ECONTROL (p));
352 }
353 
354 void parport_pc_restore_state(struct parport *p, struct parport_state *s)
355 {
356         const struct parport_pc_private *priv = p->physport->private_data;
357         outb (s->u.pc.ctr, CONTROL (p));
358         if (priv->ecr)
359                 outb (s->u.pc.ecr, ECONTROL (p));
360 }
361 
362 #ifdef CONFIG_PARPORT_1284
363 static size_t parport_pc_epp_read_data (struct parport *port, void *buf,
364                                         size_t length, int flags)
365 {
366         size_t got = 0;
367         for (; got < length; got++) {
368                 *((char*)buf)++ = inb (EPPDATA(port));
369                 if (inb (STATUS(port)) & 0x01) {
370                         clear_epp_timeout (port);
371                         break;
372                 }
373         }
374 
375         return got;
376 }
377 
378 static size_t parport_pc_epp_write_data (struct parport *port, const void *buf,
379                                          size_t length, int flags)
380 {
381         size_t written = 0;
382         for (; written < length; written++) {
383                 outb (*((char*)buf)++, EPPDATA(port));
384                 if (inb (STATUS(port)) & 0x01) {
385                         clear_epp_timeout (port);
386                         break;
387                 }
388         }
389 
390         return written;
391 }
392 
393 static size_t parport_pc_epp_read_addr (struct parport *port, void *buf,
394                                         size_t length, int flags)
395 {
396         size_t got = 0;
397         for (; got < length; got++) {
398                 *((char*)buf)++ = inb (EPPADDR (port));
399                 if (inb (STATUS (port)) & 0x01) {
400                         clear_epp_timeout (port);
401                         break;
402                 }
403         }
404 
405         return got;
406 }
407 
408 static size_t parport_pc_epp_write_addr (struct parport *port,
409                                          const void *buf, size_t length,
410                                          int flags)
411 {
412         size_t written = 0;
413         for (; written < length; written++) {
414                 outb (*((char*)buf)++, EPPADDR (port));
415                 if (inb (STATUS (port)) & 0x01) {
416                         clear_epp_timeout (port);
417                         break;
418                 }
419         }
420 
421         return written;
422 }
423 
424 static size_t parport_pc_ecpepp_read_data (struct parport *port, void *buf,
425                                            size_t length, int flags)
426 {
427         size_t got;
428 
429         frob_econtrol (port, 0xe0, ECR_EPP << 5);
430         parport_pc_data_reverse (port);
431         parport_pc_write_control (port, 0x4);
432         got = parport_pc_epp_read_data (port, buf, length, flags);
433         frob_econtrol (port, 0xe0, ECR_PS2 << 5);
434 
435         return got;
436 }
437 
438 static size_t parport_pc_ecpepp_write_data (struct parport *port,
439                                             const void *buf, size_t length,
440                                             int flags)
441 {
442         size_t written;
443 
444         frob_econtrol (port, 0xe0, ECR_EPP << 5);
445         parport_pc_write_control (port, 0x4);
446         parport_pc_data_forward (port);
447         written = parport_pc_epp_write_data (port, buf, length, flags);
448         frob_econtrol (port, 0xe0, ECR_PS2 << 5);
449 
450         return written;
451 }
452 
453 static size_t parport_pc_ecpepp_read_addr (struct parport *port, void *buf,
454                                            size_t length, int flags)
455 {
456         size_t got;
457 
458         frob_econtrol (port, 0xe0, ECR_EPP << 5);
459         parport_pc_data_reverse (port);
460         parport_pc_write_control (port, 0x4);
461         got = parport_pc_epp_read_addr (port, buf, length, flags);
462         frob_econtrol (port, 0xe0, ECR_PS2 << 5);
463 
464         return got;
465 }
466 
467 static size_t parport_pc_ecpepp_write_addr (struct parport *port,
468                                             const void *buf, size_t length,
469                                             int flags)
470 {
471         size_t written;
472 
473         frob_econtrol (port, 0xe0, ECR_EPP << 5);
474         parport_pc_write_control (port, 0x4);
475         parport_pc_data_forward (port);
476         written = parport_pc_epp_write_addr (port, buf, length, flags);
477         frob_econtrol (port, 0xe0, ECR_PS2 << 5);
478 
479         return written;
480 }
481 #endif /* IEEE 1284 support */
482 
483 #ifdef CONFIG_PARPORT_PC_FIFO
484 static size_t parport_pc_fifo_write_block_pio (struct parport *port,
485                                                const void *buf, size_t length)
486 {
487         int ret = 0;
488         const unsigned char *bufp = buf;
489         size_t left = length;
490         long expire = jiffies + port->physport->cad->timeout;
491         const int fifo = FIFO (port);
492         int poll_for = 8; /* 80 usecs */
493         const struct parport_pc_private *priv = port->physport->private_data;
494         const int fifo_depth = priv->fifo_depth;
495 
496         port = port->physport;
497 
498         /* We don't want to be interrupted every character. */
499         parport_pc_disable_irq (port);
500         frob_econtrol (port, (1<<4), (1<<4)); /* nErrIntrEn */
501 
502         /* Forward mode. */
503         parport_pc_data_forward (port); /* Must be in PS2 mode */
504 
505         while (left) {
506                 unsigned char byte;
507                 unsigned char ecrval = inb (ECONTROL (port));
508                 int i = 0;
509 
510                 if (current->need_resched && time_before (jiffies, expire))
511                         /* Can't yield the port. */
512                         schedule ();
513 
514                 /* Anyone else waiting for the port? */
515                 if (port->waithead) {
516                         printk (KERN_DEBUG "Somebody wants the port\n");
517                         break;
518                 }
519 
520                 if (ecrval & 0x02) {
521                         /* FIFO is full. Wait for interrupt. */
522 
523                         /* Clear serviceIntr */
524                         outb (ecrval & ~(1<<2), ECONTROL (port));
525                 false_alarm:
526                         ret = parport_wait_event (port, HZ);
527                         if (ret < 0) break;
528                         ret = 0;
529                         if (!time_before (jiffies, expire)) {
530                                 /* Timed out. */
531                                 printk (KERN_DEBUG "FIFO write timed out\n");
532                                 break;
533                         }
534                         ecrval = inb (ECONTROL (port));
535                         if (!(ecrval & (1<<2))) {
536                                 if (current->need_resched &&
537                                     time_before (jiffies, expire))
538                                         schedule ();
539 
540                                 goto false_alarm;
541                         }
542 
543                         continue;
544                 }
545 
546                 /* Can't fail now. */
547                 expire = jiffies + port->cad->timeout;
548 
549         poll:
550                 if (signal_pending (current))
551                         break;
552 
553                 if (ecrval & 0x01) {
554                         /* FIFO is empty. Blast it full. */
555                         const int n = left < fifo_depth ? left : fifo_depth;
556                         outsb (fifo, bufp, n);
557                         bufp += n;
558                         left -= n;
559 
560                         /* Adjust the poll time. */
561                         if (i < (poll_for - 2)) poll_for--;
562                         continue;
563                 } else if (i++ < poll_for) {
564                         udelay (10);
565                         ecrval = inb (ECONTROL (port));
566                         goto poll;
567                 }
568 
569                 /* Half-full (call me an optimist) */
570                 byte = *bufp++;
571                 outb (byte, fifo);
572                 left--;
573         }
574 
575         return length - left;
576 }
577 
578 static size_t parport_pc_fifo_write_block_dma (struct parport *port,
579                                                const void *buf, size_t length)
580 {
581         int ret = 0;
582         unsigned long dmaflag;
583         size_t left = length;
584         const struct parport_pc_private *priv = port->physport->private_data;
585         dma_addr_t dma_addr, dma_handle;
586         size_t maxlen = 0x10000; /* max 64k per DMA transfer */
587         unsigned long start = (unsigned long) buf;
588         unsigned long end = (unsigned long) buf + length - 1;
589 
590         if (end < MAX_DMA_ADDRESS) {
591                 /* If it would cross a 64k boundary, cap it at the end. */
592                 if ((start ^ end) & ~0xffffUL)
593                         maxlen = 0x10000 - (start & 0xffff);
594 
595                 dma_addr = dma_handle = pci_map_single(priv->dev, (void *)buf, length,
596                                                        PCI_DMA_TODEVICE);
597         } else {
598                 /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */
599                 maxlen   = PAGE_SIZE;          /* sizeof(priv->dma_buf) */
600                 dma_addr = priv->dma_handle;
601                 dma_handle = 0;
602         }
603 
604         port = port->physport;
605 
606         /* We don't want to be interrupted every character. */
607         parport_pc_disable_irq (port);
608         frob_econtrol (port, (1<<4), (1<<4)); /* nErrIntrEn */
609 
610         /* Forward mode. */
611         parport_pc_data_forward (port); /* Must be in PS2 mode */
612 
613         while (left) {
614                 long expire = jiffies + port->physport->cad->timeout;
615 
616                 size_t count = left;
617 
618                 if (count > maxlen)
619                         count = maxlen;
620 
621                 if (!dma_handle)   /* bounce buffer ! */
622                         memcpy(priv->dma_buf, buf, count);
623 
624                 dmaflag = claim_dma_lock();
625                 disable_dma(port->dma);
626                 clear_dma_ff(port->dma);
627                 set_dma_mode(port->dma, DMA_MODE_WRITE);
628                 set_dma_addr(port->dma, dma_addr);
629                 set_dma_count(port->dma, count);
630 
631                 /* Set DMA mode */
632                 frob_econtrol (port, 1<<3, 1<<3);
633 
634                 /* Clear serviceIntr */
635                 frob_econtrol (port, 1<<2, 0);
636 
637                 enable_dma(port->dma);
638                 release_dma_lock(dmaflag);
639 
640                 /* assume DMA will be successful */
641                 left -= count;
642                 buf  += count;
643                 if (dma_handle) dma_addr += count;
644 
645                 /* Wait for interrupt. */
646         false_alarm:
647                 ret = parport_wait_event (port, HZ);
648                 if (ret < 0) break;
649                 ret = 0;
650                 if (!time_before (jiffies, expire)) {
651                         /* Timed out. */
652                         printk (KERN_DEBUG "DMA write timed out\n");
653                         break;
654                 }
655                 /* Is serviceIntr set? */
656                 if (!(inb (ECONTROL (port)) & (1<<2))) {
657                         if (current->need_resched)
658                                 schedule ();
659 
660                         goto false_alarm;
661                 }
662 
663                 dmaflag = claim_dma_lock();
664                 disable_dma(port->dma);
665                 clear_dma_ff(port->dma);
666                 count = get_dma_residue(port->dma);
667                 release_dma_lock(dmaflag);
668 
669                 if (current->need_resched)
670                         /* Can't yield the port. */
671                         schedule ();
672 
673                 /* Anyone else waiting for the port? */
674                 if (port->waithead) {
675                         printk (KERN_DEBUG "Somebody wants the port\n");
676                         break;
677                 }
678 
679                 /* update for possible DMA residue ! */
680                 buf  -= count;
681                 left += count;
682                 if (dma_handle) dma_addr -= count;
683         }
684 
685         /* Maybe got here through break, so adjust for DMA residue! */
686         dmaflag = claim_dma_lock();
687         disable_dma(port->dma);
688         clear_dma_ff(port->dma);
689         left += get_dma_residue(port->dma);
690         release_dma_lock(dmaflag);
691 
692         /* Turn off DMA mode */
693         frob_econtrol (port, 1<<3, 0);
694         
695         if (dma_handle)
696                 pci_unmap_single(priv->dev, dma_handle, length, PCI_DMA_TODEVICE);
697 
698         return length - left;
699 }
700 
701 /* Parallel Port FIFO mode (ECP chipsets) */
702 size_t parport_pc_compat_write_block_pio (struct parport *port,
703                                           const void *buf, size_t length,
704                                           int flags)
705 {
706         size_t written;
707         int r;
708 
709         /* Special case: a timeout of zero means we cannot call schedule(). */
710         if (!port->physport->cad->timeout)
711                 return parport_ieee1284_write_compat (port, buf,
712                                                       length, flags);
713 
714         /* Set up parallel port FIFO mode.*/
715         parport_pc_data_forward (port); /* Must be in PS2 mode */
716         parport_pc_frob_control (port, PARPORT_CONTROL_STROBE, 0);
717         r = change_mode (port, ECR_PPF); /* Parallel port FIFO */
718         if (r)  printk (KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", port->name);
719 
720         port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
721 
722         /* Write the data to the FIFO. */
723         if (port->dma != PARPORT_DMA_NONE)
724                 written = parport_pc_fifo_write_block_dma (port, buf, length);
725         else
726                 written = parport_pc_fifo_write_block_pio (port, buf, length);
727 
728         /* Finish up. */
729         if (change_mode (port, ECR_PS2) == -EBUSY) {
730                 const struct parport_pc_private *priv = 
731                         port->physport->private_data;
732 
733                 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name);
734 
735                 /* Prevent further data transfer. */
736                 frob_econtrol (port, 0xe0, ECR_TST << 5);
737 
738                 /* Adjust for the contents of the FIFO. */
739                 for (written -= priv->fifo_depth; ; written++) {
740                         if (inb (ECONTROL (port)) & 0x2)
741                                 /* Full up. */
742                                 break;
743 
744                         outb (0, FIFO (port));
745                 }
746 
747                 /* Reset the FIFO and return to PS2 mode. */
748                 frob_econtrol (port, 0xe0, ECR_PS2 << 5);
749         }
750 
751         r = parport_wait_peripheral (port,
752                                      PARPORT_STATUS_BUSY,
753                                      PARPORT_STATUS_BUSY);
754         if (r)
755                 printk (KERN_DEBUG
756                         "%s: BUSY timeout (%d) in compat_write_block_pio\n", 
757                         port->name, r);
758 
759         port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
760 
761         return written;
762 }
763 
764 /* ECP */
765 #ifdef CONFIG_PARPORT_1284
766 size_t parport_pc_ecp_write_block_pio (struct parport *port,
767                                        const void *buf, size_t length,
768                                        int flags)
769 {
770         size_t written;
771         int r;
772 
773         /* Special case: a timeout of zero means we cannot call schedule(). */
774         if (!port->physport->cad->timeout)
775                 return parport_ieee1284_ecp_write_data (port, buf,
776                                                         length, flags);
777 
778         /* Switch to forward mode if necessary. */
779         if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
780                 /* Event 47: Set nInit high. */
781                 parport_frob_control (port,
782                                       PARPORT_CONTROL_INIT
783                                       | PARPORT_CONTROL_AUTOFD,
784                                       PARPORT_CONTROL_INIT
785                                       | PARPORT_CONTROL_AUTOFD);
786 
787                 /* Event 49: PError goes high. */
788                 r = parport_wait_peripheral (port,
789                                              PARPORT_STATUS_PAPEROUT,
790                                              PARPORT_STATUS_PAPEROUT);
791                 if (r)
792                         printk (KERN_DEBUG "%s: PError timeout (%d) "
793                                 "in ecp_write_block_pio\n", port->name, r);
794         }
795 
796         /* Set up ECP parallel port mode.*/
797         parport_pc_data_forward (port); /* Must be in PS2 mode */
798         parport_pc_frob_control (port,
799                                  PARPORT_CONTROL_STROBE |
800                                  PARPORT_CONTROL_AUTOFD,
801                                  0);
802         r = change_mode (port, ECR_ECP); /* ECP FIFO */
803         if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name);
804         port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
805 
806         /* Write the data to the FIFO. */
807         if (port->dma != PARPORT_DMA_NONE)
808                 written = parport_pc_fifo_write_block_dma (port, buf, length);
809         else
810                 written = parport_pc_fifo_write_block_pio (port, buf, length);
811 
812         /* Finish up. */
813         if (change_mode (port, ECR_PS2) == -EBUSY) {
814                 const struct parport_pc_private *priv =
815                         port->physport->private_data;
816 
817                 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name);
818 
819                 /* Prevent further data transfer. */
820                 frob_econtrol (port, 0xe0, ECR_TST << 5);
821 
822                 /* Adjust for the contents of the FIFO. */
823                 for (written -= priv->fifo_depth; ; written++) {
824                         if (inb (ECONTROL (port)) & 0x2)
825                                 /* Full up. */
826                                 break;
827 
828                         outb (0, FIFO (port));
829                 }
830 
831                 /* Reset the FIFO and return to PS2 mode. */
832                 frob_econtrol (port, 0xe0, ECR_PS2 << 5);
833 
834                 /* Host transfer recovery. */
835                 parport_pc_data_reverse (port); /* Must be in PS2 mode */
836                 udelay (5);
837                 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
838                 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0);
839                 if (r)
840                         printk (KERN_DEBUG "%s: PE,1 timeout (%d) "
841                                 "in ecp_write_block_pio\n", port->name, r);
842 
843                 parport_frob_control (port,
844                                       PARPORT_CONTROL_INIT,
845                                       PARPORT_CONTROL_INIT);
846                 r = parport_wait_peripheral (port,
847                                              PARPORT_STATUS_PAPEROUT,
848                                              PARPORT_STATUS_PAPEROUT);
849                 if (r)
850                         printk (KERN_DEBUG "%s: PE,2 timeout (%d) "
851                                 "in ecp_write_block_pio\n", port->name, r);
852         }
853 
854         r = parport_wait_peripheral (port,
855                                      PARPORT_STATUS_BUSY, 
856                                      PARPORT_STATUS_BUSY);
857         if(r)
858                 printk (KERN_DEBUG
859                         "%s: BUSY timeout (%d) in ecp_write_block_pio\n",
860                         port->name, r);
861 
862         port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
863 
864         return written;
865 }
866 
867 size_t parport_pc_ecp_read_block_pio (struct parport *port,
868                                       void *buf, size_t length, int flags)
869 {
870         size_t left = length;
871         size_t fifofull;
872         int r;
873         const int fifo = FIFO(port);
874         const struct parport_pc_private *priv = port->physport->private_data;
875         const int fifo_depth = priv->fifo_depth;
876         char *bufp = buf;
877 
878         port = port->physport;
879 
880         /* Special case: a timeout of zero means we cannot call schedule(). */
881         if (!port->cad->timeout)
882                 return parport_ieee1284_ecp_read_data (port, buf,
883                                                        length, flags);
884 
885         fifofull = fifo_depth;
886         if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE)
887                 /* If the peripheral is allowed to send RLE compressed
888                  * data, it is possible for a byte to expand to 128
889                  * bytes in the FIFO. */
890                 fifofull = 128;
891 
892         /* If the caller wants less than a full FIFO's worth of data,
893          * go through software emulation.  Otherwise we may have to through
894          * away data. */
895         if (length < fifofull)
896                 return parport_ieee1284_ecp_read_data (port, buf,
897                                                        length, flags);
898 
899         /* Switch to reverse mode if necessary. */
900         if ((port->ieee1284.phase != IEEE1284_PH_REV_IDLE) &&
901             (port->ieee1284.phase != IEEE1284_PH_REV_DATA)) {
902                 /* Event 38: Set nAutoFd low */
903                 parport_frob_control (port,
904                                       PARPORT_CONTROL_AUTOFD,
905                                       PARPORT_CONTROL_AUTOFD);
906                 parport_pc_data_reverse (port); /* Must be in PS2 mode */
907                 udelay (5);
908 
909                 /* Event 39: Set nInit low to initiate bus reversal */
910                 parport_frob_control (port,
911                                       PARPORT_CONTROL_INIT,
912                                       0);
913 
914                 /* Event 40: PError goes low */
915                 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0);
916                 if (r)
917                         printk (KERN_DEBUG "%s: PE timeout Event 40 (%d) "
918                                 "in ecp_read_block_pio\n", port->name, r);
919         }
920 
921         /* Set up ECP FIFO mode.*/
922         parport_pc_data_reverse (port); /* Must be in PS2 mode */
923         parport_pc_frob_control (port,
924                                  PARPORT_CONTROL_STROBE |
925                                  PARPORT_CONTROL_AUTOFD,
926                                  0);
927         r = change_mode (port, ECR_ECP); /* ECP FIFO */
928         if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name);
929         port->ieee1284.phase = IEEE1284_PH_REV_DATA;
930 
931         /* Do the transfer. */
932         while (left > fifofull) {
933                 int ret;
934                 long int expire = jiffies + port->cad->timeout;
935                 unsigned char ecrval = inb (ECONTROL (port));
936 
937                 if (current->need_resched && time_before (jiffies, expire))
938                         /* Can't yield the port. */
939                         schedule ();
940 
941                 /* At this point, the FIFO may already be full.
942                  * Ideally, we'd be able to tell the port to hold on
943                  * for a second while we empty the FIFO, and we'd be
944                  * able to ensure that no data is lost.  I'm not sure
945                  * that's the case. :-(  It might be that you can play
946                  * games with STB, as in the forward case; someone should
947                  * look at a datasheet. */
948 
949                 if (ecrval & 0x01) {
950                         /* FIFO is empty. Wait for interrupt. */
951 
952                         /* Anyone else waiting for the port? */
953                         if (port->waithead) {
954                                 printk (KERN_DEBUG
955                                         "Somebody wants the port\n");
956                                 break;
957                         }
958 
959                         /* Clear serviceIntr */
960                         outb (ecrval & ~(1<<2), ECONTROL (port));
961                 false_alarm:
962                         ret = parport_wait_event (port, HZ);
963                         if (ret < 0) break;
964                         ret = 0;
965                         if (!time_before (jiffies, expire)) {
966                                 /* Timed out. */
967                                 printk (KERN_DEBUG "PIO read timed out\n");
968                                 break;
969                         }
970                         ecrval = inb (ECONTROL (port));
971                         if (!(ecrval & (1<<2))) {
972                                 if (current->need_resched &&
973                                     time_before (jiffies, expire))
974                                         schedule ();
975 
976                                 goto false_alarm;
977                         }
978 
979                         continue;
980                 }
981 
982                 if (ecrval & 0x02) {
983                         /* FIFO is full. */
984                         insb (fifo, bufp, fifo_depth);
985                         bufp += fifo_depth;
986                         left -= fifo_depth;
987                         continue;
988                 }
989 
990                 *bufp++ = inb (fifo);
991                 left--;
992         }
993 
994         port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
995 
996         /* Go to forward idle mode to shut the peripheral up. */
997         parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
998         r = parport_wait_peripheral (port,
999                                      PARPORT_STATUS_PAPEROUT,
1000                                      PARPORT_STATUS_PAPEROUT);
1001         if (r)
1002                 printk (KERN_DEBUG
1003                         "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n",
1004                         port->name, r);
1005 
1006         port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
1007 
1008         /* Finish up. */
1009         {
1010                 int lost = get_fifo_residue (port);
1011                 if (lost)
1012                         /* Shouldn't happen with compliant peripherals. */
1013                         printk (KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n",
1014                                 port->name, lost);
1015         }
1016 
1017         return length - left;
1018 }
1019 
1020 #endif /* IEEE 1284 support */
1021 
1022 #endif /* Allowed to use FIFO/DMA */
1023 
1024 void parport_pc_inc_use_count(void)
1025 {
1026 #ifdef MODULE
1027         MOD_INC_USE_COUNT;
1028 #endif
1029 }
1030 
1031 void parport_pc_dec_use_count(void)
1032 {
1033 #ifdef MODULE
1034         MOD_DEC_USE_COUNT;
1035 #endif
1036 }
1037 
1038 struct parport_operations parport_pc_ops = 
1039 {
1040         parport_pc_write_data,
1041         parport_pc_read_data,
1042 
1043         parport_pc_write_control,
1044         parport_pc_read_control,
1045         parport_pc_frob_control,
1046 
1047         parport_pc_read_status,
1048 
1049         parport_pc_enable_irq,
1050         parport_pc_disable_irq,
1051 
1052         parport_pc_data_forward,
1053         parport_pc_data_reverse,
1054 
1055         parport_pc_init_state,
1056         parport_pc_save_state,
1057         parport_pc_restore_state,
1058 
1059         parport_pc_inc_use_count,
1060         parport_pc_dec_use_count,
1061 
1062         parport_ieee1284_epp_write_data,
1063         parport_ieee1284_epp_read_data,
1064         parport_ieee1284_epp_write_addr,
1065         parport_ieee1284_epp_read_addr,
1066 
1067         parport_ieee1284_ecp_write_data,
1068         parport_ieee1284_ecp_read_data,
1069         parport_ieee1284_ecp_write_addr,
1070 
1071         parport_ieee1284_write_compat,
1072         parport_ieee1284_read_nibble,
1073         parport_ieee1284_read_byte,
1074 };
1075 
1076 #ifdef CONFIG_PARPORT_PC_SUPERIO
1077 /* Super-IO chipset detection, Winbond, SMSC */
1078 static void __devinit show_parconfig_smsc37c669(int io, int key)
1079 {
1080         int cr1,cr4,cra,cr23,cr26,cr27,i=0;
1081         char *modes[]={ "SPP and Bidirectional (PS/2)", 
1082                         "EPP and SPP",
1083                         "ECP",
1084                         "ECP and EPP"};
1085 
1086         outb(key,io);
1087         outb(key,io);
1088         outb(1,io);
1089         cr1=inb(io+1);
1090         outb(4,io);
1091         cr4=inb(io+1);
1092         outb(0x0a,io);
1093         cra=inb(io+1);
1094         outb(0x23,io);
1095         cr23=inb(io+1);
1096         outb(0x26,io);
1097         cr26=inb(io+1);
1098         outb(0x27,io);
1099         cr27=inb(io+1);
1100         outb(0xaa,io);
1101 
1102         printk ("SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, "
1103                 "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n",
1104                 cr1,cr4,cra,cr23,cr26,cr27);
1105 
1106         /* The documentation calls DMA and IRQ-Lines by letters, so
1107            the board maker can/will wire them
1108            appropriately/randomly...  G=reserved H=IDE-irq, */
1109         printk ("SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, "
1110                 "fifo threshold=%d\n", cr23*4,
1111                 (cr27 &0x0f) ? 'A'-1+(cr27 &0x0f): '-',
1112                 (cr26 &0x0f) ? 'A'-1+(cr26 &0x0f): '-', cra & 0x0f);
1113         printk("SMSC LPT Config: enabled=%s power=%s\n",
1114                (cr23*4 >=0x100) ?"yes":"no", (cr1 & 4) ? "yes" : "no");
1115         printk("SMSC LPT Config: Port mode=%s, EPP version =%s\n",
1116                (cr1 & 0x08 ) ? "Standard mode only (SPP)" : modes[cr4 & 0x03], 
1117                (cr4 & 0x40) ? "1.7" : "1.9");
1118 
1119         /* Heuristics !  BIOS setup for this mainboard device limits
1120            the choices to standard settings, i.e. io-address and IRQ
1121            are related, however DMA can be 1 or 3, assume DMA_A=DMA1,
1122            DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */
1123         if(cr23*4 >=0x100) { /* if active */
1124                 while((superios[i].io!= 0) && (i<NR_SUPERIOS))
1125                         i++;
1126                 if(i==NR_SUPERIOS)
1127                         printk("Super-IO: too many chips!\n");
1128                 else {
1129                         int d;
1130                         switch (cr23*4) {
1131                                 case 0x3bc:
1132                                         superios[i].io = 0x3bc;
1133                                         superios[i].irq = 7;
1134                                         break;
1135                                 case 0x378:
1136                                         superios[i].io = 0x378;
1137                                         superios[i].irq = 7;
1138                                         break;
1139                                 case 0x278:
1140                                         superios[i].io = 0x278;
1141                                         superios[i].irq = 5;
1142                         }
1143                         d=(cr26 &0x0f);
1144                         if((d==1) || (d==3)) 
1145                                 superios[i].dma= d;
1146                         else
1147                                 superios[i].dma= PARPORT_DMA_NONE;
1148                 }
1149         }
1150 }
1151 
1152 
1153 static void __devinit show_parconfig_winbond(int io, int key)
1154 {
1155         int cr30,cr60,cr61,cr70,cr74,crf0,i=0;
1156         char *modes[]={ "Standard (SPP) and Bidirectional(PS/2)", /* 0 */
1157                         "EPP-1.9 and SPP",
1158                         "ECP",
1159                         "ECP and EPP-1.9",
1160                         "Standard (SPP)",
1161                         "EPP-1.7 and SPP",              /* 5 */
1162                         "undefined!",
1163                         "ECP and EPP-1.7"};
1164         char *irqtypes[]={"pulsed low, high-Z", "follows nACK"};
1165                 
1166         /* The registers are called compatible-PnP because the
1167            register layout is modelled after ISA-PnP, the access
1168            method is just another ... */
1169         outb(key,io);
1170         outb(key,io);
1171         outb(0x07,io);   /* Register 7: Select Logical Device */
1172         outb(0x01,io+1); /* LD1 is Parallel Port */
1173         outb(0x30,io);
1174         cr30=inb(io+1);
1175         outb(0x60,io);
1176         cr60=inb(io+1);
1177         outb(0x61,io);
1178         cr61=inb(io+1);
1179         outb(0x70,io);
1180         cr70=inb(io+1);
1181         outb(0x74,io);
1182         cr74=inb(io+1);
1183         outb(0xf0,io);
1184         crf0=inb(io+1);
1185         outb(0xaa,io);
1186 
1187         printk("Winbond LPT Config: cr_30=%02x 60,61=%02x%02x "
1188                "70=%02x 74=%02x, f0=%02x\n", cr30,cr60,cr61,cr70,cr74,crf0);
1189         printk("Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ", 
1190                (cr30 & 0x01) ? "yes":"no", cr60,cr61,cr70&0x0f );
1191         if ((cr74 & 0x07) > 3)
1192                 printk("dma=none\n");
1193         else
1194                 printk("dma=%d\n",cr74 & 0x07);
1195         printk("Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n",
1196                irqtypes[crf0>>7], (crf0>>3)&0x0f);
1197         printk("Winbond LPT Config: Port mode=%s\n", modes[crf0 & 0x07]);
1198 
1199         if(cr30 & 0x01) { /* the settings can be interrogated later ... */
1200                 while((superios[i].io!= 0) && (i<NR_SUPERIOS))
1201                         i++;
1202                 if(i==NR_SUPERIOS) 
1203                         printk("Super-IO: too many chips!\n");
1204                 else {
1205                         superios[i].io = (cr60<<8)|cr61;
1206                         superios[i].irq = cr70&0x0f;
1207                         superios[i].dma = (((cr74 & 0x07) > 3) ?
1208                                            PARPORT_DMA_NONE : (cr74 & 0x07));
1209                 }
1210         }
1211 }
1212 
1213 static void __devinit decode_winbond(int efer, int key, int devid, int devrev, int oldid)
1214 {
1215         char *type=NULL;
1216         int id,progif=2;
1217 
1218         if (devid == devrev)
1219                 /* simple heuristics, we happened to read some
1220                    non-winbond register */
1221                 return;
1222 
1223         printk("Winbond chip at EFER=0x%x key=0x%02x devid=%02x devrev=%02x "
1224                "oldid=%02x\n", efer,key,devid,devrev,oldid);
1225         id=(devid<<8) | devrev;
1226 
1227         /* Values are from public data sheets pdf files, I can just
1228            confirm 83977TF is correct :-) */
1229         if      (id == 0x9771) type="83977F/AF";
1230         else if (id == 0x9773) type="83977TF / SMSC 97w33x/97w34x";
1231         else if (id == 0x9774) type="83977ATF";
1232         else if ((id & ~0x0f) == 0x5270) type="83977CTF / SMSC 97w36x";
1233         else if ((id & ~0x0f) == 0x52f0) type="83977EF / SMSC 97w35x";
1234         else if ((id & ~0x0f) == 0x5210) type="83627";
1235         else if ((id & ~0x0f) == 0x6010) type="83697HF";
1236         else if ((oldid &0x0f ) == 0x0a) { type="83877F"; progif=1;}
1237         else if ((oldid &0x0f ) == 0x0b) { type="83877AF"; progif=1;}
1238         else if ((oldid &0x0f ) == 0x0c) { type="83877TF"; progif=1;}
1239         else if ((oldid &0x0f ) == 0x0d) { type="83877ATF"; progif=1;}
1240         else progif=0;
1241 
1242         if(type==NULL) 
1243                 printk("Winbond unknown chip type\n");
1244         else    
1245                 printk("Winbond chip type %s\n",type);
1246 
1247         if(progif==2)
1248                 show_parconfig_winbond(efer,key);
1249         return;
1250 }
1251 
1252 static void __devinit decode_smsc(int efer, int key, int devid, int devrev)
1253 {
1254         char *type=NULL;
1255         void (*func)(int io, int key);
1256         int id;
1257 
1258         if (devid == devrev)
1259                 /* simple heuristics, we happened to read some
1260                    non-smsc register */
1261                 return;
1262 
1263         func=NULL;
1264         printk("SMSC chip at EFER=0x%x key=0x%02x devid=%02x devrev=%02x\n",
1265                efer,key,devid,devrev);
1266         id=(devid<<8) | devrev;
1267 
1268         if      (id==0x0302) {type="37c669"; func=show_parconfig_smsc37c669;}
1269         else if (id==0x6582) type="37c665IR";
1270         else if (devid==0x65) type="37c665GT";
1271         else if (devid==0x66) type="37c666GT";
1272 
1273         if(type==NULL)
1274                 printk("SMSC unknown chip type\n");
1275         else
1276                 printk("SMSC chip type %s\n",type);
1277 
1278         if(func) (func)(efer,key);
1279         return;
1280 }
1281 
1282 
1283 static void __devinit winbond_check(int io, int key)
1284 {
1285         int devid,devrev,oldid,x_devid,x_devrev,x_oldid;
1286 
1287         /* First probe without key */
1288         outb(0x20,io);
1289         x_devid=inb(io+1);
1290         outb(0x21,io);
1291         x_devrev=inb(io+1);
1292         outb(0x09,io);
1293         x_oldid=inb(io+1);
1294 
1295         outb(key,io);
1296         outb(key,io);     /* Write Magic Sequence to EFER, extended
1297                              funtion enable register */
1298         outb(0x20,io);    /* Write EFIR, extended function index register */
1299         devid=inb(io+1);  /* Read EFDR, extended function data register */
1300         outb(0x21,io);
1301         devrev=inb(io+1);
1302         outb(0x09,io);
1303         oldid=inb(io+1);
1304         outb(0xaa,io);    /* Magic Seal */
1305 
1306         if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1307                 return; /* protection against false positives */
1308 
1309         decode_winbond(io,key,devid,devrev,oldid);
1310 }
1311 
1312 static void __devinit winbond_check2(int io,int key)
1313 {
1314         int devid,devrev,oldid,x_devid,x_devrev,x_oldid;
1315 
1316         /* First probe without the key */
1317         outb(0x20,io+2);
1318         x_devid=inb(io+2);
1319         outb(0x21,io+1);
1320         x_devrev=inb(io+2);
1321         outb(0x09,io+1);
1322         x_oldid=inb(io+2);
1323 
1324         outb(key,io);     /* Write Magic Byte to EFER, extended
1325                              funtion enable register */
1326         outb(0x20,io+2);  /* Write EFIR, extended function index register */
1327         devid=inb(io+2);  /* Read EFDR, extended function data register */
1328         outb(0x21,io+1);
1329         devrev=inb(io+2);
1330         outb(0x09,io+1);
1331         oldid=inb(io+2);
1332         outb(0xaa,io);    /* Magic Seal */
1333 
1334         if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1335                 return; /* protection against false positives */
1336 
1337         decode_winbond(io,key,devid,devrev,oldid);
1338 }
1339 
1340 static void __devinit smsc_check(int io, int key)
1341 {
1342         int id,rev,oldid,oldrev,x_id,x_rev,x_oldid,x_oldrev;
1343 
1344         /* First probe without the key */
1345         outb(0x0d,io);
1346         x_oldid=inb(io+1);
1347         outb(0x0e,io);
1348         x_oldrev=inb(io+1);
1349         outb(0x20,io);
1350         x_id=inb(io+1);
1351         outb(0x21,io);
1352         x_rev=inb(io+1);
1353 
1354         outb(key,io);
1355         outb(key,io);     /* Write Magic Sequence to EFER, extended
1356                              funtion enable register */
1357         outb(0x0d,io);    /* Write EFIR, extended function index register */
1358         oldid=inb(io+1);  /* Read EFDR, extended function data register */
1359         outb(0x0e,io);
1360         oldrev=inb(io+1);
1361         outb(0x20,io);
1362         id=inb(io+1);
1363         outb(0x21,io);
1364         rev=inb(io+1);
1365         outb(0xaa,io);    /* Magic Seal */
1366 
1367         if ((x_id == id) && (x_oldrev == oldrev) &&
1368             (x_oldid == oldid) && (x_rev == rev))
1369                 return; /* protection against false positives */
1370 
1371         decode_smsc(io,key,oldid,oldrev);
1372 }
1373 
1374 
1375 static void __devinit detect_and_report_winbond (void)
1376 { 
1377         printk("Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n");
1378 
1379         winbond_check(0x3f0,0x87);
1380         winbond_check(0x370,0x87);
1381         winbond_check(0x2e ,0x87);
1382         winbond_check(0x4e ,0x87);
1383         winbond_check(0x3f0,0x86);
1384         winbond_check2(0x250,0x88); 
1385         winbond_check2(0x250,0x89);
1386 }
1387 
1388 static void __devinit detect_and_report_smsc (void)
1389 {
1390         printk("SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n");
1391         smsc_check(0x3f0,0x55);
1392         smsc_check(0x370,0x55);
1393         smsc_check(0x3f0,0x44);
1394         smsc_check(0x370,0x44);
1395 }
1396 #endif /* CONFIG_PARPORT_PC_SUPERIO */
1397 
1398 static int __devinit get_superio_dma (struct parport *p)
1399 {
1400         int i=0;
1401         while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
1402                 i++;
1403         if (i!=NR_SUPERIOS)
1404                 return superios[i].dma;
1405         return PARPORT_DMA_NONE;
1406 }
1407 
1408 static int __devinit get_superio_irq (struct parport *p)
1409 {
1410         int i=0;
1411         while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
1412                 i++;
1413         if (i!=NR_SUPERIOS)
1414                 return superios[i].irq;
1415         return PARPORT_IRQ_NONE;
1416 }
1417         
1418 
1419 /* --- Mode detection ------------------------------------- */
1420 
1421 /*
1422  * Checks for port existence, all ports support SPP MODE
1423  * Returns: 
1424  *         0           :  No parallel port at this adress
1425  *  PARPORT_MODE_PCSPP :  SPP port detected 
1426  *                        (if the user specified an ioport himself,
1427  *                         this shall always be the case!)
1428  *
1429  */
1430 static int __devinit parport_SPP_supported(struct parport *pb)
1431 {
1432         unsigned char r, w;
1433 
1434         /*
1435          * first clear an eventually pending EPP timeout 
1436          * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
1437          * that does not even respond to SPP cycles if an EPP
1438          * timeout is pending
1439          */
1440         clear_epp_timeout(pb);
1441 
1442         /* Do a simple read-write test to make sure the port exists. */
1443         w = 0xc;
1444         outb (w, CONTROL (pb));
1445 
1446         /* Is there a control register that we can read from?  Some
1447          * ports don't allow reads, so read_control just returns a
1448          * software copy. Some ports _do_ allow reads, so bypass the
1449          * software copy here.  In addition, some bits aren't
1450          * writable. */
1451         r = inb (CONTROL (pb));
1452         if ((r & 0xf) == w) {
1453                 w = 0xe;
1454                 outb (w, CONTROL (pb));
1455                 r = inb (CONTROL (pb));
1456                 outb (0xc, CONTROL (pb));
1457                 if ((r & 0xf) == w)
1458                         return PARPORT_MODE_PCSPP;
1459         }
1460 
1461         if (user_specified)
1462                 /* That didn't work, but the user thinks there's a
1463                  * port here. */
1464                 printk (KERN_DEBUG "parport 0x%lx (WARNING): CTR: "
1465                         "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1466 
1467         /* Try the data register.  The data lines aren't tri-stated at
1468          * this stage, so we expect back what we wrote. */
1469         w = 0xaa;
1470         parport_pc_write_data (pb, w);
1471         r = parport_pc_read_data (pb);
1472         if (r == w) {
1473                 w = 0x55;
1474                 parport_pc_write_data (pb, w);
1475                 r = parport_pc_read_data (pb);
1476                 if (r == w)
1477                         return PARPORT_MODE_PCSPP;
1478         }
1479 
1480         if (user_specified) {
1481                 /* Didn't work, but the user is convinced this is the
1482                  * place. */
1483                 printk (KERN_DEBUG "parport 0x%lx (WARNING): DATA: "
1484                         "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1485                 printk (KERN_DEBUG "parport 0x%lx: You gave this address, "
1486                         "but there is probably no parallel port there!\n",
1487                         pb->base);
1488         }
1489 
1490         /* It's possible that we can't read the control register or
1491          * the data register.  In that case just believe the user. */
1492         if (user_specified)
1493                 return PARPORT_MODE_PCSPP;
1494 
1495         return 0;
1496 }
1497 
1498 /* Check for ECR
1499  *
1500  * Old style XT ports alias io ports every 0x400, hence accessing ECR
1501  * on these cards actually accesses the CTR.
1502  *
1503  * Modern cards don't do this but reading from ECR will return 0xff
1504  * regardless of what is written here if the card does NOT support
1505  * ECP.
1506  *
1507  * We first check to see if ECR is the same as CTR.  If not, the low
1508  * two bits of ECR aren't writable, so we check by writing ECR and
1509  * reading it back to see if it's what we expect.
1510  */
1511 static int __devinit parport_ECR_present(struct parport *pb)
1512 {
1513         struct parport_pc_private *priv = pb->private_data;
1514         unsigned char r = 0xc;
1515 
1516         outb (r, CONTROL (pb));
1517         if ((inb (ECONTROL (pb)) & 0x3) == (r & 0x3)) {
1518                 outb (r ^ 0x2, CONTROL (pb)); /* Toggle bit 1 */
1519 
1520                 r = inb (CONTROL (pb));
1521                 if ((inb (ECONTROL (pb)) & 0x2) == (r & 0x2))
1522                         goto no_reg; /* Sure that no ECR register exists */
1523         }
1524         
1525         if ((inb (ECONTROL (pb)) & 0x3 ) != 0x1)
1526                 goto no_reg;
1527 
1528         outb (0x34, ECONTROL (pb));
1529         if (inb (ECONTROL (pb)) != 0x35)
1530                 goto no_reg;
1531 
1532         priv->ecr = 1;
1533         outb (0xc, CONTROL (pb));
1534         
1535         /* Go to mode 000 */
1536         frob_econtrol (pb, 0xe0, ECR_SPP << 5);
1537 
1538         return 1;
1539 
1540  no_reg:
1541         outb (0xc, CONTROL (pb));
1542         return 0; 
1543 }
1544 
1545 #ifdef CONFIG_PARPORT_1284
1546 /* Detect PS/2 support.
1547  *
1548  * Bit 5 (0x20) sets the PS/2 data direction; setting this high
1549  * allows us to read data from the data lines.  In theory we would get back
1550  * 0xff but any peripheral attached to the port may drag some or all of the
1551  * lines down to zero.  So if we get back anything that isn't the contents
1552  * of the data register we deem PS/2 support to be present. 
1553  *
1554  * Some SPP ports have "half PS/2" ability - you can't turn off the line
1555  * drivers, but an external peripheral with sufficiently beefy drivers of
1556  * its own can overpower them and assert its own levels onto the bus, from
1557  * where they can then be read back as normal.  Ports with this property
1558  * and the right type of device attached are likely to fail the SPP test,
1559  * (as they will appear to have stuck bits) and so the fact that they might
1560  * be misdetected here is rather academic. 
1561  */
1562 
1563 static int __devinit parport_PS2_supported(struct parport *pb)
1564 {
1565         int ok = 0;
1566   
1567         clear_epp_timeout(pb);
1568 
1569         /* try to tri-state the buffer */
1570         parport_pc_data_reverse (pb);
1571         
1572         parport_pc_write_data(pb, 0x55);
1573         if (parport_pc_read_data(pb) != 0x55) ok++;
1574 
1575         parport_pc_write_data(pb, 0xaa);
1576         if (parport_pc_read_data(pb) != 0xaa) ok++;
1577 
1578         /* cancel input mode */
1579         parport_pc_data_forward (pb);
1580 
1581         if (ok) {
1582                 pb->modes |= PARPORT_MODE_TRISTATE;
1583         } else {
1584                 struct parport_pc_private *priv = pb->private_data;
1585                 priv->ctr_writable &= ~0x20;
1586         }
1587 
1588         return ok;
1589 }
1590 
1591 static int __devinit parport_ECP_supported(struct parport *pb)
1592 {
1593         int i;
1594         int config, configb;
1595         int pword;
1596         struct parport_pc_private *priv = pb->private_data;
1597         int intrline[]={0,7,9,10,11,14,15,5}; /* Translate ECP
1598                                                  intrLine to ISA irq
1599                                                  value */
1600 
1601         /* If there is no ECR, we have no hope of supporting ECP. */
1602         if (!priv->ecr)
1603                 return 0;
1604 
1605         /* Find out FIFO depth */
1606         outb (ECR_SPP << 5, ECONTROL (pb)); /* Reset FIFO */
1607         outb (ECR_TST << 5, ECONTROL (pb)); /* TEST FIFO */
1608         for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02); i++)
1609                 outb (0xaa, FIFO (pb));
1610 
1611         /*
1612          * Using LGS chipset it uses ECR register, but
1613          * it doesn't support ECP or FIFO MODE
1614          */
1615         if (i == 1024) {
1616                 outb (ECR_SPP << 5, ECONTROL (pb));
1617                 return 0;
1618         }
1619 
1620         priv->fifo_depth = i;
1621         printk (KERN_INFO "0x%lx: FIFO is %d bytes\n", pb->base, i);
1622 
1623         /* Find out writeIntrThreshold */
1624         frob_econtrol (pb, 1<<2, 1<<2);
1625         frob_econtrol (pb, 1<<2, 0);
1626         for (i = 1; i <= priv->fifo_depth; i++) {
1627                 inb (FIFO (pb));
1628                 udelay (50);
1629                 if (inb (ECONTROL (pb)) & (1<<2))
1630                         break;
1631         }
1632 
1633         if (i <= priv->fifo_depth)
1634                 printk (KERN_INFO "0x%lx: writeIntrThreshold is %d\n",
1635                         pb->base, i);
1636         else
1637                 /* Number of bytes we know we can write if we get an
1638                    interrupt. */
1639                 i = 0;
1640 
1641         priv->writeIntrThreshold = i;
1642 
1643         /* Find out readIntrThreshold */
1644         frob_econtrol (pb, 0xe0, ECR_PS2 << 5); /* Reset FIFO and enable PS2 */
1645         parport_pc_data_reverse (pb); /* Must be in PS2 mode */
1646         frob_econtrol (pb, 0xe0, ECR_TST << 5); /* Test FIFO */
1647         frob_econtrol (pb, 1<<2, 1<<2);
1648         frob_econtrol (pb, 1<<2, 0);
1649         for (i = 1; i <= priv->fifo_depth; i++) {
1650                 outb (0xaa, FIFO (pb));
1651                 if (inb (ECONTROL (pb)) & (1<<2))
1652                         break;
1653         }
1654 
1655         if (i <= priv->fifo_depth)
1656                 printk (KERN_INFO "0x%lx: readIntrThreshold is %d\n",
1657                         pb->base, i);
1658         else
1659                 /* Number of bytes we can read if we get an interrupt. */
1660                 i = 0;
1661 
1662         priv->readIntrThreshold = i;
1663 
1664         outb (ECR_SPP << 5, ECONTROL (pb)); /* Reset FIFO */
1665         outb (0xf4, ECONTROL (pb)); /* Configuration mode */
1666         config = inb (CONFIGA (pb));
1667         pword = (config >> 4) & 0x7;
1668         switch (pword) {
1669         case 0:
1670                 pword = 2;
1671                 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n",
1672                         pb->base);
1673                 break;
1674         case 2:
1675                 pword = 4;
1676                 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n",
1677                         pb->base);
1678                 break;
1679         default:
1680                 printk (KERN_WARNING "0x%lx: Unknown implementation ID\n",
1681                         pb->base);
1682                 /* Assume 1 */
1683         case 1:
1684                 pword = 1;
1685         }
1686         priv->pword = pword;
1687         printk (KERN_DEBUG "0x%lx: PWord is %d bits\n", pb->base, 8 * pword);
1688 
1689         printk (KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base,
1690                 config & 0x80 ? "Level" : "Pulses");
1691 
1692         configb = inb (CONFIGB (pb));
1693         if (!(configb & 0x40)) {
1694                 printk (KERN_WARNING "0x%lx: possible IRQ conflict!\n",
1695                         pb->base);
1696                 pb->irq = PARPORT_IRQ_NONE;
1697         }
1698         printk (KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n",
1699                 pb->base, config, configb);
1700         printk (KERN_DEBUG "0x%lx: ECP settings irq=", pb->base);
1701         if ((configb >>3) & 0x07)
1702                 printk("%d",intrline[(configb >>3) & 0x07]);
1703         else
1704                 printk("<none or set by other means>");
1705         printk ( " dma=");
1706         if( (configb & 0x03 ) == 0x00)
1707                 printk("<none or set by other means>\n");
1708         else
1709                 printk("%d\n",configb & 0x07);
1710 
1711         /* Go back to mode 000 */
1712         frob_econtrol (pb, 0xe0, ECR_SPP << 5);
1713         pb->modes |= PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
1714 
1715         return 1;
1716 }
1717 
1718 static int __devinit parport_ECPPS2_supported(struct parport *pb)
1719 {
1720         const struct parport_pc_private *priv = pb->private_data;
1721         int result;
1722         unsigned char oecr;
1723 
1724         if (!priv->ecr)
1725                 return 0;
1726 
1727         oecr = inb (ECONTROL (pb));
1728         outb (ECR_PS2 << 5, ECONTROL (pb));
1729         
1730         result = parport_PS2_supported(pb);
1731 
1732         outb (oecr, ECONTROL (pb));
1733         return result;
1734 }
1735 
1736 /* EPP mode detection  */
1737 
1738 static int __devinit parport_EPP_supported(struct parport *pb)
1739 {
1740         const struct parport_pc_private *priv = pb->private_data;
1741 
1742         /*
1743          * Theory:
1744          *      Bit 0 of STR is the EPP timeout bit, this bit is 0
1745          *      when EPP is possible and is set high when an EPP timeout
1746          *      occurs (EPP uses the HALT line to stop the CPU while it does
1747          *      the byte transfer, an EPP timeout occurs if the attached
1748          *      device fails to respond after 10 micro seconds).
1749          *
1750          *      This bit is cleared by either reading it (National Semi)
1751          *      or writing a 1 to the bit (SMC, UMC, WinBond), others ???
1752          *      This bit is always high in non EPP modes.
1753          */
1754 
1755         /* If EPP timeout bit clear then EPP available */
1756         if (!clear_epp_timeout(pb))
1757                 return 0;  /* No way to clear timeout */
1758 
1759         /* Check for Intel bug. */
1760         if (priv->ecr) {
1761                 unsigned char i;
1762                 for (i = 0x00; i < 0x80; i += 0x20) {
1763                         outb (i, ECONTROL (pb));
1764                         if (clear_epp_timeout (pb))
1765                                 /* Phony EPP in ECP. */
1766                                 return 0;
1767                 }
1768         }
1769 
1770         pb->modes |= PARPORT_MODE_EPP;
1771 
1772         /* Set up access functions to use EPP hardware. */
1773         pb->ops->epp_read_data = parport_pc_epp_read_data;
1774         pb->ops->epp_write_data = parport_pc_epp_write_data;
1775         pb->ops->epp_read_addr = parport_pc_epp_read_addr;
1776         pb->ops->epp_write_addr = parport_pc_epp_write_addr;
1777 
1778         return 1;
1779 }
1780 
1781 static int __devinit parport_ECPEPP_supported(struct parport *pb)
1782 {
1783         struct parport_pc_private *priv = pb->private_data;
1784         int result;
1785         unsigned char oecr;
1786 
1787         if (!priv->ecr)
1788                 return 0;
1789 
1790         oecr = inb (ECONTROL (pb));
1791         /* Search for SMC style EPP+ECP mode */
1792         outb (0x80, ECONTROL (pb));
1793         outb (0x04, CONTROL (pb));
1794         result = parport_EPP_supported(pb);
1795 
1796         outb (oecr, ECONTROL (pb));
1797 
1798         if (result) {
1799                 /* Set up access functions to use ECP+EPP hardware. */
1800                 pb->ops->epp_read_data = parport_pc_ecpepp_read_data;
1801                 pb->ops->epp_write_data = parport_pc_ecpepp_write_data;
1802                 pb->ops->epp_read_addr = parport_pc_ecpepp_read_addr;
1803                 pb->ops->epp_write_addr = parport_pc_ecpepp_write_addr;
1804         }
1805 
1806         return result;
1807 }
1808 
1809 #else /* No IEEE 1284 support */
1810 
1811 /* Don't bother probing for modes we know we won't use. */
1812 static int __devinit parport_PS2_supported(struct parport *pb) { return 0; }
1813 static int __devinit parport_ECP_supported(struct parport *pb) { return 0; }
1814 static int __devinit parport_EPP_supported(struct parport *pb) { return 0; }
1815 static int __devinit parport_ECPEPP_supported(struct parport *pb){return 0;}
1816 static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;}
1817 
1818 #endif /* No IEEE 1284 support */
1819 
1820 /* --- IRQ detection -------------------------------------- */
1821 
1822 /* Only if supports ECP mode */
1823 static int __devinit programmable_irq_support(struct parport *pb)
1824 {
1825         int irq, intrLine;
1826         unsigned char oecr = inb (ECONTROL (pb));
1827         static const int lookup[8] = {
1828                 PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5
1829         };
1830 
1831         outb (ECR_CNF << 5, ECONTROL (pb)); /* Configuration MODE */
1832 
1833         intrLine = (inb (CONFIGB (pb)) >> 3) & 0x07;
1834         irq = lookup[intrLine];
1835 
1836         outb (oecr, ECONTROL (pb));
1837         return irq;
1838 }
1839 
1840 static int __devinit irq_probe_ECP(struct parport *pb)
1841 {
1842         int i;
1843         unsigned long irqs;
1844 
1845         sti();
1846         irqs = probe_irq_on();
1847                 
1848         outb (ECR_SPP << 5, ECONTROL (pb)); /* Reset FIFO */
1849         outb ((ECR_TST << 5) | 0x04, ECONTROL (pb));
1850         outb (ECR_TST << 5, ECONTROL (pb));
1851 
1852         /* If Full FIFO sure that writeIntrThreshold is generated */
1853         for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02) ; i++) 
1854                 outb (0xaa, FIFO (pb));
1855                 
1856         pb->irq = probe_irq_off(irqs);
1857         outb (ECR_SPP << 5, ECONTROL (pb));
1858 
1859         if (pb->irq <= 0)
1860                 pb->irq = PARPORT_IRQ_NONE;
1861 
1862         return pb->irq;
1863 }
1864 
1865 /*
1866  * This detection seems that only works in National Semiconductors
1867  * This doesn't work in SMC, LGS, and Winbond 
1868  */
1869 static int __devinit irq_probe_EPP(struct parport *pb)
1870 {
1871 #ifndef ADVANCED_DETECT
1872         return PARPORT_IRQ_NONE;
1873 #else
1874         int irqs;
1875         unsigned char oecr;
1876 
1877         if (pb->modes & PARPORT_MODE_PCECR)
1878                 oecr = inb (ECONTROL (pb));
1879 
1880         sti();
1881         irqs = probe_irq_on();
1882 
1883         if (pb->modes & PARPORT_MODE_PCECR)
1884                 frob_econtrol (pb, 0x10, 0x10);
1885         
1886         clear_epp_timeout(pb);
1887         parport_pc_frob_control (pb, 0x20, 0x20);
1888         parport_pc_frob_control (pb, 0x10, 0x10);
1889         clear_epp_timeout(pb);
1890 
1891         /* Device isn't expecting an EPP read
1892          * and generates an IRQ.
1893          */
1894         parport_pc_read_epp(pb);
1895         udelay(20);
1896 
1897         pb->irq = probe_irq_off (irqs);
1898         if (pb->modes & PARPORT_MODE_PCECR)
1899                 outb (oecr, ECONTROL (pb));
1900         parport_pc_write_control(pb, 0xc);
1901 
1902         if (pb->irq <= 0)
1903                 pb->irq = PARPORT_IRQ_NONE;
1904 
1905         return pb->irq;
1906 #endif /* Advanced detection */
1907 }
1908 
1909 static int __devinit irq_probe_SPP(struct parport *pb)
1910 {
1911         /* Don't even try to do this. */
1912         return PARPORT_IRQ_NONE;
1913 }
1914 
1915 /* We will attempt to share interrupt requests since other devices
1916  * such as sound cards and network cards seem to like using the
1917  * printer IRQs.
1918  *
1919  * When ECP is available we can autoprobe for IRQs.
1920  * NOTE: If we can autoprobe it, we can register the IRQ.
1921  */
1922 static int __devinit parport_irq_probe(struct parport *pb)
1923 {
1924         const struct parport_pc_private *priv = pb->private_data;
1925 
1926         if (priv->ecr) {
1927                 pb->irq = programmable_irq_support(pb);
1928         }
1929 
1930         if (pb->modes & PARPORT_MODE_ECP)
1931                 pb->irq = irq_probe_ECP(pb);
1932 
1933         if (pb->irq == PARPORT_IRQ_NONE && priv->ecr &&
1934             (pb->modes & PARPORT_MODE_EPP))
1935                 pb->irq = irq_probe_EPP(pb);
1936 
1937         clear_epp_timeout(pb);
1938 
1939         if (pb->irq == PARPORT_IRQ_NONE && (pb->modes & PARPORT_MODE_EPP))
1940                 pb->irq = irq_probe_EPP(pb);
1941 
1942         clear_epp_timeout(pb);
1943 
1944         if (pb->irq == PARPORT_IRQ_NONE)
1945                 pb->irq = irq_probe_SPP(pb);
1946 
1947         if (pb->irq == PARPORT_IRQ_NONE)
1948                 pb->irq = get_superio_irq(pb);
1949 
1950         return pb->irq;
1951 }
1952 
1953 /* --- DMA detection -------------------------------------- */
1954 
1955 /* Only if chipset conforms to ECP ISA Interface Standard */
1956 static int __devinit programmable_dma_support (struct parport *p)
1957 {
1958         unsigned char oecr = inb (ECONTROL (p));
1959         int dma;
1960 
1961         frob_econtrol (p, 0xe0, ECR_CNF << 5);
1962         
1963         dma = inb (CONFIGB(p)) & 0x07;
1964         /* 000: Indicates jumpered 8-bit DMA if read-only.
1965            100: Indicates jumpered 16-bit DMA if read-only. */
1966         if ((dma & 0x03) == 0)
1967                 dma = PARPORT_DMA_NONE;
1968 
1969         outb (oecr, ECONTROL (p));
1970         return dma;
1971 }
1972 
1973 static int __devinit parport_dma_probe (struct parport *p)
1974 {
1975         const struct parport_pc_private *priv = p->private_data;
1976         if (priv->ecr)
1977                 p->dma = programmable_dma_support(p); /* ask ECP chipset first */
1978         if (p->dma == PARPORT_DMA_NONE)
1979                 /* ask known Super-IO chips proper, although these
1980                    claim ECP compatible, some don't report their DMA
1981                    conforming to ECP standards */
1982                 p->dma = get_superio_dma(p);
1983 
1984         return p->dma;
1985 }
1986 
1987 /* --- Initialisation code -------------------------------- */
1988 
1989 struct parport *__devinit parport_pc_probe_port (unsigned long int base,
1990                                                  unsigned long int base_hi,
1991                                                  int irq, int dma,
1992                                                  struct pci_dev *dev)
1993 {
1994         struct parport_pc_private *priv;
1995         struct parport_operations *ops;
1996         struct parport tmp;
1997         struct parport *p = &tmp;
1998         int probedirq = PARPORT_IRQ_NONE;
1999         if (check_region(base, 3)) return NULL;
2000         priv = kmalloc (sizeof (struct parport_pc_private), GFP_KERNEL);
2001         if (!priv) {
2002                 printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base);
2003                 return NULL;
2004         }
2005         ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL);
2006         if (!ops) {
2007                 printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n",
2008                         base);
2009                 kfree (priv);
2010                 return NULL;
2011         }
2012         memcpy (ops, &parport_pc_ops, sizeof (struct parport_operations));
2013         priv->ctr = 0xc;
2014         priv->ctr_writable = 0xff;
2015         priv->ecr = 0;
2016         priv->fifo_depth = 0;
2017         priv->dma_buf = 0;
2018         priv->dma_handle = 0;
2019         priv->dev = dev;
2020         p->base = base;
2021         p->base_hi = base_hi;
2022         p->irq = irq;
2023         p->dma = dma;
2024         p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
2025         p->ops = ops;
2026         p->private_data = priv;
2027         p->physport = p;
2028         if (base_hi && !check_region(base_hi,3)) {
2029                 parport_ECR_present(p);
2030                 parport_ECP_supported(p);
2031         }
2032         if (base != 0x3bc) {
2033                 if (!check_region(base+0x3, 5)) {
2034                         if (!parport_EPP_supported(p))
2035                                 parport_ECPEPP_supported(p);
2036                 }
2037         }
2038         if (!parport_SPP_supported (p)) {
2039                 /* No port. */
2040                 kfree (priv);
2041                 return NULL;
2042         }
2043         if (priv->ecr)
2044                 parport_ECPPS2_supported(p);
2045         else
2046                 parport_PS2_supported (p);
2047 
2048         if (!(p = parport_register_port(base, PARPORT_IRQ_NONE,
2049                                         PARPORT_DMA_NONE, ops))) {
2050                 kfree (priv);
2051                 kfree (ops);
2052                 return NULL;
2053         }
2054 
2055         p->base_hi = base_hi;
2056         p->modes = tmp.modes;
2057         p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
2058         p->private_data = priv;
2059 
2060         printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
2061         if (p->base_hi && (p->modes & PARPORT_MODE_ECP))
2062                 printk(" (0x%lx)", p->base_hi);
2063         p->irq = irq;
2064         p->dma = dma;
2065         if (p->irq == PARPORT_IRQ_AUTO) {
2066                 p->irq = PARPORT_IRQ_NONE;
2067                 parport_irq_probe(p);
2068         } else if (p->irq == PARPORT_IRQ_PROBEONLY) {
2069                 p->irq = PARPORT_IRQ_NONE;
2070                 parport_irq_probe(p);
2071                 probedirq = p->irq;
2072                 p->irq = PARPORT_IRQ_NONE;
2073         }
2074         if (p->irq != PARPORT_IRQ_NONE) {
2075                 printk(", irq %d", p->irq);
2076 
2077                 if (p->dma == PARPORT_DMA_AUTO) {
2078                         p->dma = PARPORT_DMA_NONE;
2079                         parport_dma_probe(p);
2080                 }
2081         }
2082         if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
2083                                            is mandatory (see above) */
2084                 p->dma = PARPORT_DMA_NONE;
2085 
2086 #ifdef CONFIG_PARPORT_PC_FIFO
2087         if (p->dma != PARPORT_DMA_NOFIFO &&
2088             priv->fifo_depth > 0 && p->irq != PARPORT_IRQ_NONE) {
2089                 p->ops->compat_write_data = parport_pc_compat_write_block_pio;
2090 #ifdef CONFIG_PARPORT_1284
2091                 p->ops->ecp_write_data = parport_pc_ecp_write_block_pio;
2092 #endif /* IEEE 1284 support */
2093                 if (p->dma != PARPORT_DMA_NONE) {
2094                         printk(", dma %d", p->dma);
2095                         p->modes |= PARPORT_MODE_DMA;
2096                 }
2097                 else printk(", using FIFO");
2098         }
2099         else
2100                 /* We can't use the DMA channel after all. */
2101                 p->dma = PARPORT_DMA_NONE;
2102 #endif /* Allowed to use FIFO/DMA */
2103 
2104         printk(" [");
2105 #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
2106         {
2107                 int f = 0;
2108                 printmode(PCSPP);
2109                 printmode(TRISTATE);
2110                 printmode(COMPAT)
2111                 printmode(EPP);
2112                 printmode(ECP);
2113                 printmode(DMA);
2114         }
2115 #undef printmode
2116 #ifndef CONFIG_PARPORT_1284
2117         printk ("(,...)");
2118 #endif /* CONFIG_PARPORT_1284 */
2119         printk("]\n");
2120         if (probedirq != PARPORT_IRQ_NONE) 
2121                 printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq);
2122         parport_proc_register(p);
2123 
2124         request_region (p->base, 3, p->name);
2125         if (p->size > 3)
2126                 request_region (p->base + 3, p->size - 3, p->name);
2127         if (p->modes & PARPORT_MODE_ECP)
2128                 request_region (p->base_hi, 3, p->name);
2129 
2130         if (p->irq != PARPORT_IRQ_NONE) {
2131                 if (request_irq (p->irq, parport_pc_interrupt,
2132                                  0, p->name, p)) {
2133                         printk (KERN_WARNING "%s: irq %d in use, "
2134                                 "resorting to polled operation\n",
2135                                 p->name, p->irq);
2136                         p->irq = PARPORT_IRQ_NONE;
2137                         p->dma = PARPORT_DMA_NONE;
2138                 }
2139 
2140 #ifdef CONFIG_PARPORT_PC_FIFO
2141                 if (p->dma != PARPORT_DMA_NONE) {
2142                         if (request_dma (p->dma, p->name)) {
2143                                 printk (KERN_WARNING "%s: dma %d in use, "
2144                                         "resorting to PIO operation\n",
2145                                         p->name, p->dma);
2146                                 p->dma = PARPORT_DMA_NONE;
2147                         } else {
2148                                 priv->dma_buf =
2149                                   pci_alloc_consistent(priv->dev,
2150                                                        PAGE_SIZE,
2151                                                        &priv->dma_handle);
2152                                 if (! priv->dma_buf) {
2153                                         printk (KERN_WARNING "%s: "
2154                                                 "cannot get buffer for DMA, "
2155                                                 "resorting to PIO operation\n",
2156                                                 p->name);
2157                                         free_dma(p->dma);
2158                                         p->dma = PARPORT_DMA_NONE;
2159                                 }
2160                         }
2161                 }
2162 #endif /* CONFIG_PARPORT_PC_FIFO */
2163         }
2164 
2165         /* Done probing.  Now put the port into a sensible start-up state. */
2166         if (priv->ecr)
2167                 /*
2168                  * Put the ECP detected port in PS2 mode.
2169                  * Do this also for ports that have ECR but don't do ECP.
2170                  */
2171                 outb (0x34, ECONTROL (p));
2172 
2173         parport_pc_write_data(p, 0);
2174         parport_pc_data_forward (p);
2175 
2176         /* Now that we've told the sharing engine about the port, and
2177            found out its characteristics, let the high-level drivers
2178            know about it. */
2179         parport_announce_port (p);
2180 
2181         return p;
2182 }
2183 
2184 
2185 /* Via support maintained by Jeff Garzik <jgarzik@mandrakesoft.com> */
2186 static int __devinit sio_via_686a_probe (struct pci_dev *pdev)
2187 {
2188         u8 tmp;
2189         int dma, irq;
2190         unsigned port1, port2, have_eppecp;
2191 
2192         /*
2193          * unlock super i/o configuration, set 0x85_1
2194          */
2195         pci_read_config_byte (pdev, 0x85, &tmp);
2196         tmp |= (1 << 1);
2197         pci_write_config_byte (pdev, 0x85, tmp);
2198         
2199         /* 
2200          * Super I/O configuration, index port == 3f0h, data port == 3f1h
2201          */
2202         
2203         /* 0xE2_1-0: Parallel Port Mode / Enable */
2204         outb (0xE2, 0x3F0);
2205         tmp = inb (0x3F1);
2206         
2207         if ((tmp & 0x03) == 0x03) {
2208                 printk (KERN_INFO "parport_pc: Via 686A parallel port disabled in BIOS\n");
2209                 return 0;
2210         }
2211         
2212         /* 0xE6: Parallel Port I/O Base Address, bits 9-2 */
2213         outb (0xE6, 0x3F0);
2214         port1 = inb (0x3F1) << 2;
2215         
2216         switch (port1) {
2217         case 0x3bc: port2 = 0x7bc; break;
2218         case 0x378: port2 = 0x778; break;
2219         case 0x278: port2 = 0x678; break;
2220         default:
2221                 printk (KERN_INFO "parport_pc: Via 686A weird parport base 0x%X, ignoring\n",
2222                         port1);
2223                 return 0;
2224         }
2225 
2226         /* 0xF0_5: EPP+ECP enable */
2227         outb (0xF0, 0x3F0);
2228         have_eppecp = (inb (0x3F1) & (1 << 5));
2229         
2230         /*
2231          * lock super i/o configuration, clear 0x85_1
2232          */
2233         pci_read_config_byte (pdev, 0x85, &tmp);
2234         tmp &= ~(1 << 1);
2235         pci_write_config_byte (pdev, 0x85, tmp);
2236 
2237         /*
2238          * Get DMA and IRQ from PCI->ISA bridge PCI config registers
2239          */
2240 
2241         /* 0x50_3-2: PnP Routing for Parallel Port DRQ */
2242         pci_read_config_byte (pdev, 0x50, &tmp);
2243         dma = ((tmp >> 2) & 0x03);
2244         
2245         /* 0x51_7-4: PnP Routing for Parallel Port IRQ */
2246         pci_read_config_byte (pdev, 0x51, &tmp);
2247         irq = ((tmp >> 4) & 0x0F);
2248 
2249         /* filter bogus IRQs */
2250         switch (irq) {
2251         case 0:
2252         case 2:
2253         case 8:
2254         case 13:
2255                 irq = PARPORT_IRQ_NONE;
2256                 break;
2257 
2258         default: /* do nothing */
2259                 break;
2260         }
2261 
2262         /* if ECP not enabled, DMA is not enabled, assumed bogus 'dma' value */
2263         if (!have_eppecp)
2264                 dma = PARPORT_DMA_NONE;
2265 
2266         /* finally, do the probe with values obtained */
2267         if (parport_pc_probe_port (port1, port2, irq, dma, NULL)) {
2268                 printk (KERN_INFO
2269                         "parport_pc: Via 686A parallel port: io=0x%X", port1);
2270                 if (irq != PARPORT_IRQ_NONE)
2271                         printk (", irq=%d", irq);
2272                 if (dma != PARPORT_DMA_NONE)
2273                         printk (", dma=%d", dma);
2274                 printk ("\n");
2275                 return 1;
2276         }
2277         
2278         printk (KERN_WARNING "parport_pc: Strange, can't probe Via 686A parallel port: io=0x%X, irq=%d, dma=%d\n",
2279                 port1, irq, dma);
2280         return 0;
2281 }
2282 
2283 
2284 enum parport_pc_sio_types {
2285         sio_via_686a = 0,       /* Via VT82C686A motherboard Super I/O */
2286         last_sio
2287 };
2288 
2289 /* each element directly indexed from enum list, above */
2290 static struct parport_pc_superio {
2291         int (*probe) (struct pci_dev *pdev);
2292 } parport_pc_superio_info[] __devinitdata = {
2293         { sio_via_686a_probe, },
2294 };
2295 
2296 
2297 enum parport_pc_pci_cards {
2298         siig_1s1p_10x_550 = last_sio,
2299         siig_1s1p_10x_650,
2300         siig_1s1p_10x_850,
2301         siig_1p_10x,
2302         siig_2p_10x,
2303         siig_2s1p_10x_550,
2304         siig_2s1p_10x_650,
2305         siig_2s1p_10x_850,
2306         siig_1p_20x,
2307         siig_2p_20x,
2308         siig_2p1s_20x_550,
2309         siig_2p1s_20x_650,
2310         siig_2p1s_20x_850,
2311         siig_1s1p_20x_550,
2312         siig_1s1p_20x_650,
2313         siig_1s1p_20x_850,
2314         siig_2s1p_20x_550,
2315         siig_2s1p_20x_650,
2316         siig_2s1p_20x_850,
2317         lava_parallel,
2318         lava_parallel_dual_a,
2319         lava_parallel_dual_b,
2320         boca_ioppar,
2321         plx_9050,
2322         afavlab_tk9902,
2323         timedia_4078a,
2324         timedia_4079h,
2325         timedia_4085h,
2326         timedia_4088a,
2327         timedia_4089a,
2328         timedia_4095a,
2329         timedia_4096a,
2330         timedia_4078u,
2331         timedia_4079a,
2332         timedia_4085u,
2333         timedia_4079r,
2334         timedia_4079s,
2335         timedia_4079d,
2336         timedia_4079e,
2337         timedia_4079f,
2338         timedia_9079a,
2339         timedia_9079b,
2340         timedia_9079c,
2341         timedia_4006a,
2342         timedia_4014,
2343         timedia_4008a,
2344         timedia_4018,
2345         timedia_9018a,
2346         syba_2p_epp,
2347         syba_1p_ecp,
2348 };
2349 
2350 
2351 /* each element directly indexed from enum list, above 
2352  * (but offset by last_sio) */
2353 static struct parport_pc_pci {
2354         int numports;
2355         struct { /* BAR (base address registers) numbers in the config
2356                     space header */
2357                 int lo;
2358                 int hi; /* -1 if not there, >6 for offset-method (max
2359                            BAR is 6) */
2360         } addr[4];
2361 } cards[] __devinitdata = {
2362         /* siig_1s1p_10x_550 */         { 1, { { 3, 4 }, } },
2363         /* siig_1s1p_10x_650 */         { 1, { { 3, 4 }, } },
2364         /* siig_1s1p_10x_850 */         { 1, { { 3, 4 }, } },
2365         /* siig_1p_10x */               { 1, { { 2, 3 }, } },
2366         /* siig_2p_10x */               { 2, { { 2, 3 }, { 4, 5 }, } },
2367         /* siig_2s1p_10x_550 */         { 1, { { 4, 5 }, } },
2368         /* siig_2s1p_10x_650 */         { 1, { { 4, 5 }, } },
2369         /* siig_2s1p_10x_850 */         { 1, { { 4, 5 }, } },
2370         /* siig_1p_20x */               { 1, { { 0, 1 }, } },
2371         /* siig_2p_20x */               { 2, { { 0, 1 }, { 2, 3 }, } },
2372         /* siig_2p1s_20x_550 */         { 2, { { 1, 2 }, { 3, 4 }, } },
2373         /* siig_2p1s_20x_650 */         { 2, { { 1, 2 }, { 3, 4 }, } },
2374         /* siig_2p1s_20x_850 */         { 2, { { 1, 2 }, { 3, 4 }, } },
2375         /* siig_1s1p_20x_550 */         { 1, { { 1, 2 }, } },
2376         /* siig_1s1p_20x_650 */         { 1, { { 1, 2 }, } },
2377         /* siig_1s1p_20x_850 */         { 1, { { 1, 2 }, } },
2378         /* siig_2s1p_20x_550 */         { 1, { { 2, 3 }, } },
2379         /* siig_2s1p_20x_650 */         { 1, { { 2, 3 }, } },
2380         /* siig_2s1p_20x_850 */         { 1, { { 2, 3 }, } },
2381         /* lava_parallel */             { 1, { { 0, -1 }, } },
2382         /* lava_parallel_dual_a */      { 1, { { 0, -1 }, } },
2383         /* lava_parallel_dual_b */      { 1, { { 0, -1 }, } },
2384         /* boca_ioppar */               { 1, { { 0, -1 }, } },
2385         /* plx_9050 */                  { 2, { { 4, -1 }, { 5, -1 }, } },
2386         /* afavlab_tk9902 */            { 1, { { 0, 1 }, } },
2387         /* timedia_4078a */             { 1, { { 2, -1 }, } },
2388         /* timedia_4079h */             { 1, { { 2, 3 }, } },
2389         /* timedia_4085h */             { 2, { { 2, -1 }, { 4, -1 }, } },
2390         /* timedia_4088a */             { 2, { { 2, 3 }, { 4, 5 }, } },
2391         /* timedia_4089a */             { 2, { { 2, 3 }, { 4, 5 }, } },
2392         /* timedia_4095a */             { 2, { { 2, 3 }, { 4, 5 }, } },
2393         /* timedia_4096a */             { 2, { { 2, 3 }, { 4, 5 }, } },
2394         /* timedia_4078u */             { 1, { { 2, -1 }, } },
2395         /* timedia_4079a */             { 1, { { 2, 3 }, } },
2396         /* timedia_4085u */             { 2, { { 2, -1 }, { 4, -1 }, } },
2397         /* timedia_4079r */             { 1, { { 2, 3 }, } },
2398         /* timedia_4079s */             { 1, { { 2, 3 }, } },
2399         /* timedia_4079d */             { 1, { { 2, 3 }, } },
2400         /* timedia_4079e */             { 1, { { 2, 3 }, } },
2401         /* timedia_4079f */             { 1, { { 2, 3 }, } },
2402         /* timedia_9079a */             { 1, { { 2, 3 }, } },
2403         /* timedia_9079b */             { 1, { { 2, 3 }, } },
2404         /* timedia_9079c */             { 1, { { 2, 3 }, } },
2405         /* timedia_4006a */             { 1, { { 0, -1 }, } },
2406         /* timedia_4014  */             { 2, { { 0, -1 }, { 2, -1 }, } },
2407         /* timedia_4008a */             { 1, { { 0, 1 }, } },
2408         /* timedia_4018  */             { 2, { { 0, 1 }, { 2, 3 }, } },
2409         /* timedia_9018a */             { 2, { { 0, 1 }, { 2, 3 }, } },
2410                                         /* SYBA uses fixed offsets in
2411                                            a 1K io window */
2412         /* syba_2p_epp AP138B */        { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
2413         /* syba_1p_ecp W83787 */        { 1, { { 0, 0x078 }, } },
2414 };
2415 
2416 static struct pci_device_id parport_pc_pci_tbl[] __devinitdata = {
2417         /* Super-IO onboard chips */
2418         { 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a },
2419 
2420         /* PCI cards */
2421         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550,
2422           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x_550 },
2423         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650,
2424           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x_650 },
2425         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850,
2426           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x_850 },
2427         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_10x,
2428           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_10x },
2429         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_10x,
2430           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_10x },
2431         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550,
2432           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x_550 },
2433         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650,
2434           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x_650 },
2435         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850,
2436           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x_850 },
2437         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_20x,
2438           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_20x },
2439         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_20x,
2440           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_20x },
2441         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550,
2442           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x_550 },
2443         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650,
2444           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x_650 },
2445         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850,
2446           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x_850 },
2447         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550,
2448           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x_550 },
2449         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650,
2450           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x_650 },
2451         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850,
2452           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x_850 },
2453         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550,
2454           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x_550 },
2455         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650,
2456           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x_650 },
2457         { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850,
2458           PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x_850 },
2459         { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PARALLEL,
2460           PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel },
2461         { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_A,
2462           PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_a },
2463         { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_B,
2464           PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_b },
2465         { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR,
2466           PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar },
2467         { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
2468           PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0,0, plx_9050 },
2469         { PCI_VENDOR_ID_AFAVLAB, PCI_DEVICE_ID_AFAVLAB_TK9902,
2470           PCI_ANY_ID, PCI_ANY_ID, 0, 0, afavlab_tk9902 },
2471         /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
2472         { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a },
2473         { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h },
2474         { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h },
2475         { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a },
2476         { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a },
2477         { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a },
2478         { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a },
2479         { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u },
2480         { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a },
2481         { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u },
2482         { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r },
2483         { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s },
2484         { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d },
2485         { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e },
2486         { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f },
2487         { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a },
2488         { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b },
2489         { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c },
2490         { 0x1409, 0x7268, 0x1409, 0x0101, 0, 0, timedia_4006a },
2491         { 0x1409, 0x7268, 0x1409, 0x0102, 0, 0, timedia_4014 },
2492         { 0x1409, 0x7268, 0x1409, 0x0103, 0, 0, timedia_4008a },
2493         { 0x1409, 0x7268, 0x1409, 0x0104, 0, 0, timedia_4018 },
2494         { 0x1409, 0x7268, 0x1409, 0x9018, 0, 0, timedia_9018a },
2495         { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_2P_EPP,
2496           PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_2p_epp },
2497         { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_1P_ECP,
2498           PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp },
2499         { 0, } /* terminate list */
2500 };
2501 MODULE_DEVICE_TABLE(pci,parport_pc_pci_tbl);
2502 
2503 static int __devinit parport_pc_pci_probe (struct pci_dev *dev,
2504                                            const struct pci_device_id *id)
2505 {
2506         int err, count, n, i = id->driver_data;
2507         if (i < last_sio)
2508                 /* This is an onboard Super-IO and has already been probed */
2509                 return 0;
2510 
2511         /* This is a PCI card */
2512         i -= last_sio;
2513         count = 0;
2514         if ((err = pci_enable_device (dev)) != 0)
2515                 return err;
2516 
2517         for (n = 0; n < cards[i].numports; n++) {
2518                 int lo = cards[i].addr[n].lo;
2519                 int hi = cards[i].addr[n].hi;
2520                 unsigned long io_lo, io_hi;
2521                 io_lo = pci_resource_start (dev, lo);
2522                 io_hi = 0;
2523                 if ((hi >= 0) && (hi <= 6))
2524                         io_hi = pci_resource_start (dev, hi);
2525                 else if (hi > 6)
2526                         io_lo += hi; /* Reinterpret the meaning of
2527                                         "hi" as an offset (see SYBA
2528                                         def.) */
2529                 /* TODO: test if sharing interrupts works */
2530                 printk (KERN_DEBUG "PCI parallel port detected: %04x:%04x, "
2531                         "I/O at %#lx(%#lx)\n",
2532                         parport_pc_pci_tbl[i + last_sio].vendor,
2533                         parport_pc_pci_tbl[i + last_sio].device, io_lo, io_hi);
2534                 if (parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE,
2535                                            PARPORT_DMA_NONE, dev))
2536                         count++;
2537         }
2538 
2539         return count == 0 ? -ENODEV : 0;
2540 }
2541 
2542 static struct pci_driver parport_pc_pci_driver = {
2543         name:           "parport_pc",
2544         id_table:       parport_pc_pci_tbl,
2545         probe:          parport_pc_pci_probe,
2546 };
2547 
2548 static int __init parport_pc_init_superio (void)
2549 {
2550 #ifdef CONFIG_PCI
2551         const struct pci_device_id *id;
2552         struct pci_dev *pdev;
2553 
2554         pci_for_each_dev(pdev) {
2555                 id = pci_match_device (parport_pc_pci_tbl, pdev);
2556                 if (id == NULL || id->driver_data >= last_sio)
2557                         continue;
2558 
2559                 return parport_pc_superio_info[id->driver_data].probe (pdev);
2560         }
2561 #endif /* CONFIG_PCI */
2562 
2563         return 0; /* zero devices found */
2564 }
2565 
2566 /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
2567 static int __init __attribute__((unused))
2568 parport_pc_find_isa_ports (int autoirq, int autodma)
2569 {
2570         int count = 0;
2571 
2572         if (parport_pc_probe_port(0x3bc, 0x7bc, autoirq, autodma, NULL))
2573                 count++;
2574         if (parport_pc_probe_port(0x378, 0x778, autoirq, autodma, NULL))
2575                 count++;
2576         if (parport_pc_probe_port(0x278, 0x678, autoirq, autodma, NULL))
2577                 count++;
2578 
2579         return count;
2580 }
2581 
2582 /* This function is called by parport_pc_init if the user didn't
2583  * specify any ports to probe.  Its job is to find some ports.  Order
2584  * is important here -- we want ISA ports to be registered first,
2585  * followed by PCI cards (for least surprise), but before that we want
2586  * to do chipset-specific tests for some onboard ports that we know
2587  * about.
2588  *
2589  * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
2590  * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
2591  */
2592 static int __init parport_pc_find_ports (int autoirq, int autodma)
2593 {
2594         int count = 0, r;
2595 
2596 #ifdef CONFIG_PARPORT_PC_SUPERIO
2597         detect_and_report_winbond ();
2598         detect_and_report_smsc ();
2599 #endif
2600 
2601         /* Onboard SuperIO chipsets that show themselves on the PCI bus. */
2602         count += parport_pc_init_superio ();
2603 
2604         /* ISA ports and whatever (see asm/parport.h). */
2605         count += parport_pc_find_nonpci_ports (autoirq, autodma);
2606 
2607         r = pci_register_driver (&parport_pc_pci_driver);
2608         if (r > 0)
2609                 count += r;
2610 
2611         return count;
2612 }
2613 
2614 int __init parport_pc_init (int *io, int *io_hi, int *irq, int *dma)
2615 {
2616         int count = 0, i = 0;
2617 
2618         if (io && *io) {
2619                 /* Only probe the ports we were given. */
2620                 user_specified = 1;
2621                 do {
2622                         if (!*io_hi) *io_hi = 0x400 + *io;
2623                         if (parport_pc_probe_port(*(io++), *(io_hi++),
2624                                                   *(irq++), *(dma++), NULL))
2625                                 count++;
2626                 } while (*io && (++i < PARPORT_PC_MAX_PORTS));
2627         } else {
2628                 count += parport_pc_find_ports (irq[0], dma[0]);
2629         }
2630 
2631         return count;
2632 }
2633 
2634 /* Exported symbols. */
2635 #ifdef CONFIG_PARPORT_PC_PCMCIA
2636 
2637 /* parport_cs needs this in order to dyncamically get us to find ports. */
2638 EXPORT_SYMBOL (parport_pc_probe_port);
2639 
2640 #else
2641 
2642 EXPORT_NO_SYMBOLS;
2643 
2644 #endif
2645 
2646 #ifdef MODULE
2647 static int io[PARPORT_PC_MAX_PORTS+1] = { [0 ... PARPORT_PC_MAX_PORTS] = 0 };
2648 static int io_hi[PARPORT_PC_MAX_PORTS+1] = { [0 ... PARPORT_PC_MAX_PORTS] = 0 };
2649 static int dmaval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_AUTO };
2650 static int irqval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY };
2651 static const char *irq[PARPORT_PC_MAX_PORTS] = { NULL, };
2652 static const char *dma[PARPORT_PC_MAX_PORTS] = { NULL, };
2653 
2654 MODULE_AUTHOR("Phil Blundell, Tim Waugh, others");
2655 MODULE_DESCRIPTION("PC-style parallel port driver");
2656 MODULE_PARM_DESC(io, "Base I/O address (SPP regs)");
2657 MODULE_PARM(io, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS) "i");
2658 MODULE_PARM_DESC(io_hi, "Base I/O address (ECR)");
2659 MODULE_PARM(io_hi, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS) "i");
2660 MODULE_PARM_DESC(irq, "IRQ line");
2661 MODULE_PARM(irq, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS) "s");
2662 MODULE_PARM_DESC(dma, "DMA channel");
2663 MODULE_PARM(dma, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS) "s");
2664 
2665 int init_module(void)
2666 {       
2667         /* Work out how many ports we have, then get parport_share to parse
2668            the irq values. */
2669         unsigned int i;
2670         for (i = 0; i < PARPORT_PC_MAX_PORTS && io[i]; i++);
2671         if (i) {
2672                 if (parport_parse_irqs(i, irq, irqval)) return 1;
2673                 if (parport_parse_dmas(i, dma, dmaval)) return 1;
2674         }
2675         else {
2676                 /* The user can make us use any IRQs or DMAs we find. */
2677                 int val;
2678 
2679                 if (irq[0] && !parport_parse_irqs (1, irq, &val))
2680                         switch (val) {
2681                         case PARPORT_IRQ_NONE:
2682                         case PARPORT_IRQ_AUTO:
2683                                 irqval[0] = val;
2684                         }
2685 
2686                 if (dma[0] && !parport_parse_dmas (1, dma, &val))
2687                         switch (val) {
2688                         case PARPORT_DMA_NONE:
2689                         case PARPORT_DMA_AUTO:
2690                                 dmaval[0] = val;
2691                         }
2692         }
2693 
2694         return !parport_pc_init (io, io_hi, irqval, dmaval);
2695 }
2696 
2697 void cleanup_module(void)
2698 {
2699         /* We ought to keep track of which ports are actually ours. */
2700         struct parport *p = parport_enumerate(), *tmp;
2701 
2702         if (!user_specified)
2703                 pci_unregister_driver (&parport_pc_pci_driver);
2704 
2705         while (p) {
2706                 tmp = p->next;
2707                 if (p->modes & PARPORT_MODE_PCSPP) { 
2708                         struct parport_pc_private *priv = p->private_data;
2709                         struct parport_operations *ops = p->ops;
2710                         if (p->dma != PARPORT_DMA_NONE)
2711                                 free_dma(p->dma);
2712                         if (p->irq != PARPORT_IRQ_NONE)
2713                                 free_irq(p->irq, p);
2714                         release_region(p->base, 3);
2715                         if (p->size > 3)
2716                                 release_region(p->base + 3, p->size - 3);
2717                         if (p->modes & PARPORT_MODE_ECP)
2718                                 release_region(p->base_hi, 3);
2719                         parport_proc_unregister(p);
2720                         if (priv->dma_buf)
2721                                 pci_free_consistent(priv->dev, PAGE_SIZE,
2722                                                     priv->dma_buf,
2723                                                     priv->dma_handle);
2724                         kfree (p->private_data);
2725                         parport_unregister_port(p);
2726                         kfree (ops); /* hope no-one cached it */
2727                 }
2728                 p = tmp;
2729         }
2730 }
2731 #endif
2732 

~ [ 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.