added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / drivers / parport / parport_pc.c
blobb31320c8c878f2acd6651b833920450338d38d9d
1 /* Low-level parallel-port routines for 8255-based PC-style hardware.
2 *
3 * Authors: Phil Blundell <philb@gnu.org>
4 * Tim Waugh <tim@cyberelk.demon.co.uk>
5 * Jose Renau <renau@acm.org>
6 * David Campbell
7 * Andrea Arcangeli
9 * based on work by Grant Guenther <grant@torque.net> and Phil Blundell.
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 * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G.
15 * Various hacks, Fred Barnes, 04/2001
16 * Updated probing logic - Adam Belay <ambx1@neo.rr.com>
19 /* This driver should work with any hardware that is broadly compatible
20 * with that in the IBM PC. This applies to the majority of integrated
21 * I/O chipsets that are commonly available. The expected register
22 * layout is:
24 * base+0 data
25 * base+1 status
26 * base+2 control
28 * In addition, there are some optional registers:
30 * base+3 EPP address
31 * base+4 EPP data
32 * base+0x400 ECP config A
33 * base+0x401 ECP config B
34 * base+0x402 ECP control
36 * All registers are 8 bits wide and read/write. If your hardware differs
37 * only in register addresses (eg because your registers are on 32-bit
38 * word boundaries) then you can alter the constants in parport_pc.h to
39 * accommodate this.
41 * Note that the ECP registers may not start at offset 0x400 for PCI cards,
42 * but rather will start at port->base_hi.
45 #include <linux/module.h>
46 #include <linux/init.h>
47 #include <linux/sched.h>
48 #include <linux/delay.h>
49 #include <linux/errno.h>
50 #include <linux/interrupt.h>
51 #include <linux/ioport.h>
52 #include <linux/kernel.h>
53 #include <linux/slab.h>
54 #include <linux/dma-mapping.h>
55 #include <linux/pci.h>
56 #include <linux/pnp.h>
57 #include <linux/platform_device.h>
58 #include <linux/sysctl.h>
60 #include <asm/io.h>
61 #include <asm/dma.h>
62 #include <asm/uaccess.h>
64 #include <linux/parport.h>
65 #include <linux/parport_pc.h>
66 #include <linux/via.h>
67 #include <asm/parport.h>
69 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
71 #ifdef CONFIG_ISA_DMA_API
72 #define HAS_DMA
73 #endif
75 /* ECR modes */
76 #define ECR_SPP 00
77 #define ECR_PS2 01
78 #define ECR_PPF 02
79 #define ECR_ECP 03
80 #define ECR_EPP 04
81 #define ECR_VND 05
82 #define ECR_TST 06
83 #define ECR_CNF 07
84 #define ECR_MODE_MASK 0xe0
85 #define ECR_WRITE(p,v) frob_econtrol((p),0xff,(v))
87 #undef DEBUG
89 #ifdef DEBUG
90 #define DPRINTK printk
91 #else
92 #define DPRINTK(stuff...)
93 #endif
96 #define NR_SUPERIOS 3
97 static struct superio_struct { /* For Super-IO chips autodetection */
98 int io;
99 int irq;
100 int dma;
101 } superios[NR_SUPERIOS] = { {0,},};
103 static int user_specified;
104 #if defined(CONFIG_PARPORT_PC_SUPERIO) || \
105 (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
106 static int verbose_probing;
107 #endif
108 static int pci_registered_parport;
109 static int pnp_registered_parport;
111 /* frob_control, but for ECR */
112 static void frob_econtrol (struct parport *pb, unsigned char m,
113 unsigned char v)
115 unsigned char ectr = 0;
117 if (m != 0xff)
118 ectr = inb (ECONTROL (pb));
120 DPRINTK (KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n",
121 m, v, ectr, (ectr & ~m) ^ v);
123 outb ((ectr & ~m) ^ v, ECONTROL (pb));
126 static __inline__ void frob_set_mode (struct parport *p, int mode)
128 frob_econtrol (p, ECR_MODE_MASK, mode << 5);
131 #ifdef CONFIG_PARPORT_PC_FIFO
132 /* Safely change the mode bits in the ECR
133 Returns:
134 0 : Success
135 -EBUSY: Could not drain FIFO in some finite amount of time,
136 mode not changed!
138 static int change_mode(struct parport *p, int m)
140 const struct parport_pc_private *priv = p->physport->private_data;
141 unsigned char oecr;
142 int mode;
144 DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n",m);
146 if (!priv->ecr) {
147 printk (KERN_DEBUG "change_mode: but there's no ECR!\n");
148 return 0;
151 /* Bits <7:5> contain the mode. */
152 oecr = inb (ECONTROL (p));
153 mode = (oecr >> 5) & 0x7;
154 if (mode == m) return 0;
156 if (mode >= 2 && !(priv->ctr & 0x20)) {
157 /* This mode resets the FIFO, so we may
158 * have to wait for it to drain first. */
159 unsigned long expire = jiffies + p->physport->cad->timeout;
160 int counter;
161 switch (mode) {
162 case ECR_PPF: /* Parallel Port FIFO mode */
163 case ECR_ECP: /* ECP Parallel Port mode */
164 /* Busy wait for 200us */
165 for (counter = 0; counter < 40; counter++) {
166 if (inb (ECONTROL (p)) & 0x01)
167 break;
168 if (signal_pending (current)) break;
169 udelay (5);
172 /* Poll slowly. */
173 while (!(inb (ECONTROL (p)) & 0x01)) {
174 if (time_after_eq (jiffies, expire))
175 /* The FIFO is stuck. */
176 return -EBUSY;
177 schedule_timeout_interruptible(msecs_to_jiffies(10));
178 if (signal_pending (current))
179 break;
184 if (mode >= 2 && m >= 2) {
185 /* We have to go through mode 001 */
186 oecr &= ~(7 << 5);
187 oecr |= ECR_PS2 << 5;
188 ECR_WRITE (p, oecr);
191 /* Set the mode. */
192 oecr &= ~(7 << 5);
193 oecr |= m << 5;
194 ECR_WRITE (p, oecr);
195 return 0;
198 #ifdef CONFIG_PARPORT_1284
199 /* Find FIFO lossage; FIFO is reset */
200 #if 0
201 static int get_fifo_residue (struct parport *p)
203 int residue;
204 int cnfga;
205 const struct parport_pc_private *priv = p->physport->private_data;
207 /* Adjust for the contents of the FIFO. */
208 for (residue = priv->fifo_depth; ; residue--) {
209 if (inb (ECONTROL (p)) & 0x2)
210 /* Full up. */
211 break;
213 outb (0, FIFO (p));
216 printk (KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name,
217 residue);
219 /* Reset the FIFO. */
220 frob_set_mode (p, ECR_PS2);
222 /* Now change to config mode and clean up. FIXME */
223 frob_set_mode (p, ECR_CNF);
224 cnfga = inb (CONFIGA (p));
225 printk (KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga);
227 if (!(cnfga & (1<<2))) {
228 printk (KERN_DEBUG "%s: Accounting for extra byte\n", p->name);
229 residue++;
232 /* Don't care about partial PWords until support is added for
233 * PWord != 1 byte. */
235 /* Back to PS2 mode. */
236 frob_set_mode (p, ECR_PS2);
238 DPRINTK (KERN_DEBUG "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n", inb (ECONTROL (p)));
239 return residue;
241 #endif /* 0 */
242 #endif /* IEEE 1284 support */
243 #endif /* FIFO support */
246 * Clear TIMEOUT BIT in EPP MODE
248 * This is also used in SPP detection.
250 static int clear_epp_timeout(struct parport *pb)
252 unsigned char r;
254 if (!(parport_pc_read_status(pb) & 0x01))
255 return 1;
257 /* To clear timeout some chips require double read */
258 parport_pc_read_status(pb);
259 r = parport_pc_read_status(pb);
260 outb (r | 0x01, STATUS (pb)); /* Some reset by writing 1 */
261 outb (r & 0xfe, STATUS (pb)); /* Others by writing 0 */
262 r = parport_pc_read_status(pb);
264 return !(r & 0x01);
268 * Access functions.
270 * Most of these aren't static because they may be used by the
271 * parport_xxx_yyy macros. extern __inline__ versions of several
272 * of these are in parport_pc.h.
275 static void parport_pc_init_state(struct pardevice *dev, struct parport_state *s)
277 s->u.pc.ctr = 0xc;
278 if (dev->irq_func &&
279 dev->port->irq != PARPORT_IRQ_NONE)
280 /* Set ackIntEn */
281 s->u.pc.ctr |= 0x10;
283 s->u.pc.ecr = 0x34; /* NetMos chip can cause problems 0x24;
284 * D.Gruszka VScom */
287 static void parport_pc_save_state(struct parport *p, struct parport_state *s)
289 const struct parport_pc_private *priv = p->physport->private_data;
290 s->u.pc.ctr = priv->ctr;
291 if (priv->ecr)
292 s->u.pc.ecr = inb (ECONTROL (p));
295 static void parport_pc_restore_state(struct parport *p, struct parport_state *s)
297 struct parport_pc_private *priv = p->physport->private_data;
298 register unsigned char c = s->u.pc.ctr & priv->ctr_writable;
299 outb (c, CONTROL (p));
300 priv->ctr = c;
301 if (priv->ecr)
302 ECR_WRITE (p, s->u.pc.ecr);
305 #ifdef CONFIG_PARPORT_1284
306 static size_t parport_pc_epp_read_data (struct parport *port, void *buf,
307 size_t length, int flags)
309 size_t got = 0;
311 if (flags & PARPORT_W91284PIC) {
312 unsigned char status;
313 size_t left = length;
315 /* use knowledge about data lines..:
316 * nFault is 0 if there is at least 1 byte in the Warp's FIFO
317 * pError is 1 if there are 16 bytes in the Warp's FIFO
319 status = inb (STATUS (port));
321 while (!(status & 0x08) && (got < length)) {
322 if ((left >= 16) && (status & 0x20) && !(status & 0x08)) {
323 /* can grab 16 bytes from warp fifo */
324 if (!((long)buf & 0x03)) {
325 insl (EPPDATA (port), buf, 4);
326 } else {
327 insb (EPPDATA (port), buf, 16);
329 buf += 16;
330 got += 16;
331 left -= 16;
332 } else {
333 /* grab single byte from the warp fifo */
334 *((char *)buf) = inb (EPPDATA (port));
335 buf++;
336 got++;
337 left--;
339 status = inb (STATUS (port));
340 if (status & 0x01) {
341 /* EPP timeout should never occur... */
342 printk (KERN_DEBUG "%s: EPP timeout occurred while talking to "
343 "w91284pic (should not have done)\n", port->name);
344 clear_epp_timeout (port);
347 return got;
349 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
350 if (!(((long)buf | length) & 0x03)) {
351 insl (EPPDATA (port), buf, (length >> 2));
352 } else {
353 insb (EPPDATA (port), buf, length);
355 if (inb (STATUS (port)) & 0x01) {
356 clear_epp_timeout (port);
357 return -EIO;
359 return length;
361 for (; got < length; got++) {
362 *((char*)buf) = inb (EPPDATA(port));
363 buf++;
364 if (inb (STATUS (port)) & 0x01) {
365 /* EPP timeout */
366 clear_epp_timeout (port);
367 break;
371 return got;
374 static size_t parport_pc_epp_write_data (struct parport *port, const void *buf,
375 size_t length, int flags)
377 size_t written = 0;
379 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
380 if (!(((long)buf | length) & 0x03)) {
381 outsl (EPPDATA (port), buf, (length >> 2));
382 } else {
383 outsb (EPPDATA (port), buf, length);
385 if (inb (STATUS (port)) & 0x01) {
386 clear_epp_timeout (port);
387 return -EIO;
389 return length;
391 for (; written < length; written++) {
392 outb (*((char*)buf), EPPDATA(port));
393 buf++;
394 if (inb (STATUS(port)) & 0x01) {
395 clear_epp_timeout (port);
396 break;
400 return written;
403 static size_t parport_pc_epp_read_addr (struct parport *port, void *buf,
404 size_t length, int flags)
406 size_t got = 0;
408 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
409 insb (EPPADDR (port), buf, length);
410 if (inb (STATUS (port)) & 0x01) {
411 clear_epp_timeout (port);
412 return -EIO;
414 return length;
416 for (; got < length; got++) {
417 *((char*)buf) = inb (EPPADDR (port));
418 buf++;
419 if (inb (STATUS (port)) & 0x01) {
420 clear_epp_timeout (port);
421 break;
425 return got;
428 static size_t parport_pc_epp_write_addr (struct parport *port,
429 const void *buf, size_t length,
430 int flags)
432 size_t written = 0;
434 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
435 outsb (EPPADDR (port), buf, length);
436 if (inb (STATUS (port)) & 0x01) {
437 clear_epp_timeout (port);
438 return -EIO;
440 return length;
442 for (; written < length; written++) {
443 outb (*((char*)buf), EPPADDR (port));
444 buf++;
445 if (inb (STATUS (port)) & 0x01) {
446 clear_epp_timeout (port);
447 break;
451 return written;
454 static size_t parport_pc_ecpepp_read_data (struct parport *port, void *buf,
455 size_t length, int flags)
457 size_t got;
459 frob_set_mode (port, ECR_EPP);
460 parport_pc_data_reverse (port);
461 parport_pc_write_control (port, 0x4);
462 got = parport_pc_epp_read_data (port, buf, length, flags);
463 frob_set_mode (port, ECR_PS2);
465 return got;
468 static size_t parport_pc_ecpepp_write_data (struct parport *port,
469 const void *buf, size_t length,
470 int flags)
472 size_t written;
474 frob_set_mode (port, ECR_EPP);
475 parport_pc_write_control (port, 0x4);
476 parport_pc_data_forward (port);
477 written = parport_pc_epp_write_data (port, buf, length, flags);
478 frob_set_mode (port, ECR_PS2);
480 return written;
483 static size_t parport_pc_ecpepp_read_addr (struct parport *port, void *buf,
484 size_t length, int flags)
486 size_t got;
488 frob_set_mode (port, ECR_EPP);
489 parport_pc_data_reverse (port);
490 parport_pc_write_control (port, 0x4);
491 got = parport_pc_epp_read_addr (port, buf, length, flags);
492 frob_set_mode (port, ECR_PS2);
494 return got;
497 static size_t parport_pc_ecpepp_write_addr (struct parport *port,
498 const void *buf, size_t length,
499 int flags)
501 size_t written;
503 frob_set_mode (port, ECR_EPP);
504 parport_pc_write_control (port, 0x4);
505 parport_pc_data_forward (port);
506 written = parport_pc_epp_write_addr (port, buf, length, flags);
507 frob_set_mode (port, ECR_PS2);
509 return written;
511 #endif /* IEEE 1284 support */
513 #ifdef CONFIG_PARPORT_PC_FIFO
514 static size_t parport_pc_fifo_write_block_pio (struct parport *port,
515 const void *buf, size_t length)
517 int ret = 0;
518 const unsigned char *bufp = buf;
519 size_t left = length;
520 unsigned long expire = jiffies + port->physport->cad->timeout;
521 const int fifo = FIFO (port);
522 int poll_for = 8; /* 80 usecs */
523 const struct parport_pc_private *priv = port->physport->private_data;
524 const int fifo_depth = priv->fifo_depth;
526 port = port->physport;
528 /* We don't want to be interrupted every character. */
529 parport_pc_disable_irq (port);
530 /* set nErrIntrEn and serviceIntr */
531 frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2));
533 /* Forward mode. */
534 parport_pc_data_forward (port); /* Must be in PS2 mode */
536 while (left) {
537 unsigned char byte;
538 unsigned char ecrval = inb (ECONTROL (port));
539 int i = 0;
541 if (need_resched() && time_before (jiffies, expire))
542 /* Can't yield the port. */
543 schedule ();
545 /* Anyone else waiting for the port? */
546 if (port->waithead) {
547 printk (KERN_DEBUG "Somebody wants the port\n");
548 break;
551 if (ecrval & 0x02) {
552 /* FIFO is full. Wait for interrupt. */
554 /* Clear serviceIntr */
555 ECR_WRITE (port, ecrval & ~(1<<2));
556 false_alarm:
557 ret = parport_wait_event (port, HZ);
558 if (ret < 0) break;
559 ret = 0;
560 if (!time_before (jiffies, expire)) {
561 /* Timed out. */
562 printk (KERN_DEBUG "FIFO write timed out\n");
563 break;
565 ecrval = inb (ECONTROL (port));
566 if (!(ecrval & (1<<2))) {
567 if (need_resched() &&
568 time_before (jiffies, expire))
569 schedule ();
571 goto false_alarm;
574 continue;
577 /* Can't fail now. */
578 expire = jiffies + port->cad->timeout;
580 poll:
581 if (signal_pending (current))
582 break;
584 if (ecrval & 0x01) {
585 /* FIFO is empty. Blast it full. */
586 const int n = left < fifo_depth ? left : fifo_depth;
587 outsb (fifo, bufp, n);
588 bufp += n;
589 left -= n;
591 /* Adjust the poll time. */
592 if (i < (poll_for - 2)) poll_for--;
593 continue;
594 } else if (i++ < poll_for) {
595 udelay (10);
596 ecrval = inb (ECONTROL (port));
597 goto poll;
600 /* Half-full (call me an optimist) */
601 byte = *bufp++;
602 outb (byte, fifo);
603 left--;
606 dump_parport_state ("leave fifo_write_block_pio", port);
607 return length - left;
610 #ifdef HAS_DMA
611 static size_t parport_pc_fifo_write_block_dma (struct parport *port,
612 const void *buf, size_t length)
614 int ret = 0;
615 unsigned long dmaflag;
616 size_t left = length;
617 const struct parport_pc_private *priv = port->physport->private_data;
618 struct device *dev = port->physport->dev;
619 dma_addr_t dma_addr, dma_handle;
620 size_t maxlen = 0x10000; /* max 64k per DMA transfer */
621 unsigned long start = (unsigned long) buf;
622 unsigned long end = (unsigned long) buf + length - 1;
624 dump_parport_state ("enter fifo_write_block_dma", port);
625 if (end < MAX_DMA_ADDRESS) {
626 /* If it would cross a 64k boundary, cap it at the end. */
627 if ((start ^ end) & ~0xffffUL)
628 maxlen = 0x10000 - (start & 0xffff);
630 dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length,
631 DMA_TO_DEVICE);
632 } else {
633 /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */
634 maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */
635 dma_addr = priv->dma_handle;
636 dma_handle = 0;
639 port = port->physport;
641 /* We don't want to be interrupted every character. */
642 parport_pc_disable_irq (port);
643 /* set nErrIntrEn and serviceIntr */
644 frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2));
646 /* Forward mode. */
647 parport_pc_data_forward (port); /* Must be in PS2 mode */
649 while (left) {
650 unsigned long expire = jiffies + port->physport->cad->timeout;
652 size_t count = left;
654 if (count > maxlen)
655 count = maxlen;
657 if (!dma_handle) /* bounce buffer ! */
658 memcpy(priv->dma_buf, buf, count);
660 dmaflag = claim_dma_lock();
661 disable_dma(port->dma);
662 clear_dma_ff(port->dma);
663 set_dma_mode(port->dma, DMA_MODE_WRITE);
664 set_dma_addr(port->dma, dma_addr);
665 set_dma_count(port->dma, count);
667 /* Set DMA mode */
668 frob_econtrol (port, 1<<3, 1<<3);
670 /* Clear serviceIntr */
671 frob_econtrol (port, 1<<2, 0);
673 enable_dma(port->dma);
674 release_dma_lock(dmaflag);
676 /* assume DMA will be successful */
677 left -= count;
678 buf += count;
679 if (dma_handle) dma_addr += count;
681 /* Wait for interrupt. */
682 false_alarm:
683 ret = parport_wait_event (port, HZ);
684 if (ret < 0) break;
685 ret = 0;
686 if (!time_before (jiffies, expire)) {
687 /* Timed out. */
688 printk (KERN_DEBUG "DMA write timed out\n");
689 break;
691 /* Is serviceIntr set? */
692 if (!(inb (ECONTROL (port)) & (1<<2))) {
693 cond_resched();
695 goto false_alarm;
698 dmaflag = claim_dma_lock();
699 disable_dma(port->dma);
700 clear_dma_ff(port->dma);
701 count = get_dma_residue(port->dma);
702 release_dma_lock(dmaflag);
704 cond_resched(); /* Can't yield the port. */
706 /* Anyone else waiting for the port? */
707 if (port->waithead) {
708 printk (KERN_DEBUG "Somebody wants the port\n");
709 break;
712 /* update for possible DMA residue ! */
713 buf -= count;
714 left += count;
715 if (dma_handle) dma_addr -= count;
718 /* Maybe got here through break, so adjust for DMA residue! */
719 dmaflag = claim_dma_lock();
720 disable_dma(port->dma);
721 clear_dma_ff(port->dma);
722 left += get_dma_residue(port->dma);
723 release_dma_lock(dmaflag);
725 /* Turn off DMA mode */
726 frob_econtrol (port, 1<<3, 0);
728 if (dma_handle)
729 dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE);
731 dump_parport_state ("leave fifo_write_block_dma", port);
732 return length - left;
734 #endif
736 static inline size_t parport_pc_fifo_write_block(struct parport *port,
737 const void *buf, size_t length)
739 #ifdef HAS_DMA
740 if (port->dma != PARPORT_DMA_NONE)
741 return parport_pc_fifo_write_block_dma (port, buf, length);
742 #endif
743 return parport_pc_fifo_write_block_pio (port, buf, length);
746 /* Parallel Port FIFO mode (ECP chipsets) */
747 static size_t parport_pc_compat_write_block_pio (struct parport *port,
748 const void *buf, size_t length,
749 int flags)
751 size_t written;
752 int r;
753 unsigned long expire;
754 const struct parport_pc_private *priv = port->physport->private_data;
756 /* Special case: a timeout of zero means we cannot call schedule().
757 * Also if O_NONBLOCK is set then use the default implementation. */
758 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
759 return parport_ieee1284_write_compat (port, buf,
760 length, flags);
762 /* Set up parallel port FIFO mode.*/
763 parport_pc_data_forward (port); /* Must be in PS2 mode */
764 parport_pc_frob_control (port, PARPORT_CONTROL_STROBE, 0);
765 r = change_mode (port, ECR_PPF); /* Parallel port FIFO */
766 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", port->name);
768 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
770 /* Write the data to the FIFO. */
771 written = parport_pc_fifo_write_block(port, buf, length);
773 /* Finish up. */
774 /* For some hardware we don't want to touch the mode until
775 * the FIFO is empty, so allow 4 seconds for each position
776 * in the fifo.
778 expire = jiffies + (priv->fifo_depth * HZ * 4);
779 do {
780 /* Wait for the FIFO to empty */
781 r = change_mode (port, ECR_PS2);
782 if (r != -EBUSY) {
783 break;
785 } while (time_before (jiffies, expire));
786 if (r == -EBUSY) {
788 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name);
790 /* Prevent further data transfer. */
791 frob_set_mode (port, ECR_TST);
793 /* Adjust for the contents of the FIFO. */
794 for (written -= priv->fifo_depth; ; written++) {
795 if (inb (ECONTROL (port)) & 0x2) {
796 /* Full up. */
797 break;
799 outb (0, FIFO (port));
802 /* Reset the FIFO and return to PS2 mode. */
803 frob_set_mode (port, ECR_PS2);
806 r = parport_wait_peripheral (port,
807 PARPORT_STATUS_BUSY,
808 PARPORT_STATUS_BUSY);
809 if (r)
810 printk (KERN_DEBUG
811 "%s: BUSY timeout (%d) in compat_write_block_pio\n",
812 port->name, r);
814 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
816 return written;
819 /* ECP */
820 #ifdef CONFIG_PARPORT_1284
821 static size_t parport_pc_ecp_write_block_pio (struct parport *port,
822 const void *buf, size_t length,
823 int flags)
825 size_t written;
826 int r;
827 unsigned long expire;
828 const struct parport_pc_private *priv = port->physport->private_data;
830 /* Special case: a timeout of zero means we cannot call schedule().
831 * Also if O_NONBLOCK is set then use the default implementation. */
832 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
833 return parport_ieee1284_ecp_write_data (port, buf,
834 length, flags);
836 /* Switch to forward mode if necessary. */
837 if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
838 /* Event 47: Set nInit high. */
839 parport_frob_control (port,
840 PARPORT_CONTROL_INIT
841 | PARPORT_CONTROL_AUTOFD,
842 PARPORT_CONTROL_INIT
843 | PARPORT_CONTROL_AUTOFD);
845 /* Event 49: PError goes high. */
846 r = parport_wait_peripheral (port,
847 PARPORT_STATUS_PAPEROUT,
848 PARPORT_STATUS_PAPEROUT);
849 if (r) {
850 printk (KERN_DEBUG "%s: PError timeout (%d) "
851 "in ecp_write_block_pio\n", port->name, r);
855 /* Set up ECP parallel port mode.*/
856 parport_pc_data_forward (port); /* Must be in PS2 mode */
857 parport_pc_frob_control (port,
858 PARPORT_CONTROL_STROBE |
859 PARPORT_CONTROL_AUTOFD,
861 r = change_mode (port, ECR_ECP); /* ECP FIFO */
862 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name);
863 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
865 /* Write the data to the FIFO. */
866 written = parport_pc_fifo_write_block(port, buf, length);
868 /* Finish up. */
869 /* For some hardware we don't want to touch the mode until
870 * the FIFO is empty, so allow 4 seconds for each position
871 * in the fifo.
873 expire = jiffies + (priv->fifo_depth * (HZ * 4));
874 do {
875 /* Wait for the FIFO to empty */
876 r = change_mode (port, ECR_PS2);
877 if (r != -EBUSY) {
878 break;
880 } while (time_before (jiffies, expire));
881 if (r == -EBUSY) {
883 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name);
885 /* Prevent further data transfer. */
886 frob_set_mode (port, ECR_TST);
888 /* Adjust for the contents of the FIFO. */
889 for (written -= priv->fifo_depth; ; written++) {
890 if (inb (ECONTROL (port)) & 0x2) {
891 /* Full up. */
892 break;
894 outb (0, FIFO (port));
897 /* Reset the FIFO and return to PS2 mode. */
898 frob_set_mode (port, ECR_PS2);
900 /* Host transfer recovery. */
901 parport_pc_data_reverse (port); /* Must be in PS2 mode */
902 udelay (5);
903 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
904 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0);
905 if (r)
906 printk (KERN_DEBUG "%s: PE,1 timeout (%d) "
907 "in ecp_write_block_pio\n", port->name, r);
909 parport_frob_control (port,
910 PARPORT_CONTROL_INIT,
911 PARPORT_CONTROL_INIT);
912 r = parport_wait_peripheral (port,
913 PARPORT_STATUS_PAPEROUT,
914 PARPORT_STATUS_PAPEROUT);
915 if (r)
916 printk (KERN_DEBUG "%s: PE,2 timeout (%d) "
917 "in ecp_write_block_pio\n", port->name, r);
920 r = parport_wait_peripheral (port,
921 PARPORT_STATUS_BUSY,
922 PARPORT_STATUS_BUSY);
923 if(r)
924 printk (KERN_DEBUG
925 "%s: BUSY timeout (%d) in ecp_write_block_pio\n",
926 port->name, r);
928 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
930 return written;
933 #if 0
934 static size_t parport_pc_ecp_read_block_pio (struct parport *port,
935 void *buf, size_t length,
936 int flags)
938 size_t left = length;
939 size_t fifofull;
940 int r;
941 const int fifo = FIFO(port);
942 const struct parport_pc_private *priv = port->physport->private_data;
943 const int fifo_depth = priv->fifo_depth;
944 char *bufp = buf;
946 port = port->physport;
947 DPRINTK (KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n");
948 dump_parport_state ("enter fcn", port);
950 /* Special case: a timeout of zero means we cannot call schedule().
951 * Also if O_NONBLOCK is set then use the default implementation. */
952 if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
953 return parport_ieee1284_ecp_read_data (port, buf,
954 length, flags);
956 if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) {
957 /* If the peripheral is allowed to send RLE compressed
958 * data, it is possible for a byte to expand to 128
959 * bytes in the FIFO. */
960 fifofull = 128;
961 } else {
962 fifofull = fifo_depth;
965 /* If the caller wants less than a full FIFO's worth of data,
966 * go through software emulation. Otherwise we may have to throw
967 * away data. */
968 if (length < fifofull)
969 return parport_ieee1284_ecp_read_data (port, buf,
970 length, flags);
972 if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) {
973 /* change to reverse-idle phase (must be in forward-idle) */
975 /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */
976 parport_frob_control (port,
977 PARPORT_CONTROL_AUTOFD
978 | PARPORT_CONTROL_STROBE,
979 PARPORT_CONTROL_AUTOFD);
980 parport_pc_data_reverse (port); /* Must be in PS2 mode */
981 udelay (5);
982 /* Event 39: Set nInit low to initiate bus reversal */
983 parport_frob_control (port,
984 PARPORT_CONTROL_INIT,
986 /* Event 40: Wait for nAckReverse (PError) to go low */
987 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0);
988 if (r) {
989 printk (KERN_DEBUG "%s: PE timeout Event 40 (%d) "
990 "in ecp_read_block_pio\n", port->name, r);
991 return 0;
995 /* Set up ECP FIFO mode.*/
996 /* parport_pc_frob_control (port,
997 PARPORT_CONTROL_STROBE |
998 PARPORT_CONTROL_AUTOFD,
999 PARPORT_CONTROL_AUTOFD); */
1000 r = change_mode (port, ECR_ECP); /* ECP FIFO */
1001 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name);
1003 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
1005 /* the first byte must be collected manually */
1006 dump_parport_state ("pre 43", port);
1007 /* Event 43: Wait for nAck to go low */
1008 r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0);
1009 if (r) {
1010 /* timed out while reading -- no data */
1011 printk (KERN_DEBUG "PIO read timed out (initial byte)\n");
1012 goto out_no_data;
1014 /* read byte */
1015 *bufp++ = inb (DATA (port));
1016 left--;
1017 dump_parport_state ("43-44", port);
1018 /* Event 44: nAutoFd (HostAck) goes high to acknowledge */
1019 parport_pc_frob_control (port,
1020 PARPORT_CONTROL_AUTOFD,
1022 dump_parport_state ("pre 45", port);
1023 /* Event 45: Wait for nAck to go high */
1024 /* r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, PARPORT_STATUS_ACK); */
1025 dump_parport_state ("post 45", port);
1026 r = 0;
1027 if (r) {
1028 /* timed out while waiting for peripheral to respond to ack */
1029 printk (KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n");
1031 /* keep hold of the byte we've got already */
1032 goto out_no_data;
1034 /* Event 46: nAutoFd (HostAck) goes low to accept more data */
1035 parport_pc_frob_control (port,
1036 PARPORT_CONTROL_AUTOFD,
1037 PARPORT_CONTROL_AUTOFD);
1040 dump_parport_state ("rev idle", port);
1041 /* Do the transfer. */
1042 while (left > fifofull) {
1043 int ret;
1044 unsigned long expire = jiffies + port->cad->timeout;
1045 unsigned char ecrval = inb (ECONTROL (port));
1047 if (need_resched() && time_before (jiffies, expire))
1048 /* Can't yield the port. */
1049 schedule ();
1051 /* At this point, the FIFO may already be full. In
1052 * that case ECP is already holding back the
1053 * peripheral (assuming proper design) with a delayed
1054 * handshake. Work fast to avoid a peripheral
1055 * timeout. */
1057 if (ecrval & 0x01) {
1058 /* FIFO is empty. Wait for interrupt. */
1059 dump_parport_state ("FIFO empty", port);
1061 /* Anyone else waiting for the port? */
1062 if (port->waithead) {
1063 printk (KERN_DEBUG "Somebody wants the port\n");
1064 break;
1067 /* Clear serviceIntr */
1068 ECR_WRITE (port, ecrval & ~(1<<2));
1069 false_alarm:
1070 dump_parport_state ("waiting", port);
1071 ret = parport_wait_event (port, HZ);
1072 DPRINTK (KERN_DEBUG "parport_wait_event returned %d\n", ret);
1073 if (ret < 0)
1074 break;
1075 ret = 0;
1076 if (!time_before (jiffies, expire)) {
1077 /* Timed out. */
1078 dump_parport_state ("timeout", port);
1079 printk (KERN_DEBUG "PIO read timed out\n");
1080 break;
1082 ecrval = inb (ECONTROL (port));
1083 if (!(ecrval & (1<<2))) {
1084 if (need_resched() &&
1085 time_before (jiffies, expire)) {
1086 schedule ();
1088 goto false_alarm;
1091 /* Depending on how the FIFO threshold was
1092 * set, how long interrupt service took, and
1093 * how fast the peripheral is, we might be
1094 * lucky and have a just filled FIFO. */
1095 continue;
1098 if (ecrval & 0x02) {
1099 /* FIFO is full. */
1100 dump_parport_state ("FIFO full", port);
1101 insb (fifo, bufp, fifo_depth);
1102 bufp += fifo_depth;
1103 left -= fifo_depth;
1104 continue;
1107 DPRINTK (KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n");
1109 /* FIFO not filled. We will cycle this loop for a while
1110 * and either the peripheral will fill it faster,
1111 * tripping a fast empty with insb, or we empty it. */
1112 *bufp++ = inb (fifo);
1113 left--;
1116 /* scoop up anything left in the FIFO */
1117 while (left && !(inb (ECONTROL (port) & 0x01))) {
1118 *bufp++ = inb (fifo);
1119 left--;
1122 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
1123 dump_parport_state ("rev idle2", port);
1125 out_no_data:
1127 /* Go to forward idle mode to shut the peripheral up (event 47). */
1128 parport_frob_control (port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT);
1130 /* event 49: PError goes high */
1131 r = parport_wait_peripheral (port,
1132 PARPORT_STATUS_PAPEROUT,
1133 PARPORT_STATUS_PAPEROUT);
1134 if (r) {
1135 printk (KERN_DEBUG
1136 "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n",
1137 port->name, r);
1140 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
1142 /* Finish up. */
1144 int lost = get_fifo_residue (port);
1145 if (lost)
1146 /* Shouldn't happen with compliant peripherals. */
1147 printk (KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n",
1148 port->name, lost);
1151 dump_parport_state ("fwd idle", port);
1152 return length - left;
1154 #endif /* 0 */
1155 #endif /* IEEE 1284 support */
1156 #endif /* Allowed to use FIFO/DMA */
1160 * ******************************************
1161 * INITIALISATION AND MODULE STUFF BELOW HERE
1162 * ******************************************
1165 /* GCC is not inlining extern inline function later overwriten to non-inline,
1166 so we use outlined_ variants here. */
1167 static const struct parport_operations parport_pc_ops =
1169 .write_data = parport_pc_write_data,
1170 .read_data = parport_pc_read_data,
1172 .write_control = parport_pc_write_control,
1173 .read_control = parport_pc_read_control,
1174 .frob_control = parport_pc_frob_control,
1176 .read_status = parport_pc_read_status,
1178 .enable_irq = parport_pc_enable_irq,
1179 .disable_irq = parport_pc_disable_irq,
1181 .data_forward = parport_pc_data_forward,
1182 .data_reverse = parport_pc_data_reverse,
1184 .init_state = parport_pc_init_state,
1185 .save_state = parport_pc_save_state,
1186 .restore_state = parport_pc_restore_state,
1188 .epp_write_data = parport_ieee1284_epp_write_data,
1189 .epp_read_data = parport_ieee1284_epp_read_data,
1190 .epp_write_addr = parport_ieee1284_epp_write_addr,
1191 .epp_read_addr = parport_ieee1284_epp_read_addr,
1193 .ecp_write_data = parport_ieee1284_ecp_write_data,
1194 .ecp_read_data = parport_ieee1284_ecp_read_data,
1195 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
1197 .compat_write_data = parport_ieee1284_write_compat,
1198 .nibble_read_data = parport_ieee1284_read_nibble,
1199 .byte_read_data = parport_ieee1284_read_byte,
1201 .owner = THIS_MODULE,
1204 #ifdef CONFIG_PARPORT_PC_SUPERIO
1205 /* Super-IO chipset detection, Winbond, SMSC */
1206 static void __devinit show_parconfig_smsc37c669(int io, int key)
1208 int cr1,cr4,cra,cr23,cr26,cr27,i=0;
1209 static const char *const modes[]={
1210 "SPP and Bidirectional (PS/2)",
1211 "EPP and SPP",
1212 "ECP",
1213 "ECP and EPP" };
1215 outb(key,io);
1216 outb(key,io);
1217 outb(1,io);
1218 cr1=inb(io+1);
1219 outb(4,io);
1220 cr4=inb(io+1);
1221 outb(0x0a,io);
1222 cra=inb(io+1);
1223 outb(0x23,io);
1224 cr23=inb(io+1);
1225 outb(0x26,io);
1226 cr26=inb(io+1);
1227 outb(0x27,io);
1228 cr27=inb(io+1);
1229 outb(0xaa,io);
1231 if (verbose_probing) {
1232 printk (KERN_INFO "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, "
1233 "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n",
1234 cr1,cr4,cra,cr23,cr26,cr27);
1236 /* The documentation calls DMA and IRQ-Lines by letters, so
1237 the board maker can/will wire them
1238 appropriately/randomly... G=reserved H=IDE-irq, */
1239 printk (KERN_INFO "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, "
1240 "fifo threshold=%d\n", cr23*4,
1241 (cr27 &0x0f) ? 'A'-1+(cr27 &0x0f): '-',
1242 (cr26 &0x0f) ? 'A'-1+(cr26 &0x0f): '-', cra & 0x0f);
1243 printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n",
1244 (cr23*4 >=0x100) ?"yes":"no", (cr1 & 4) ? "yes" : "no");
1245 printk(KERN_INFO "SMSC LPT Config: Port mode=%s, EPP version =%s\n",
1246 (cr1 & 0x08 ) ? "Standard mode only (SPP)" : modes[cr4 & 0x03],
1247 (cr4 & 0x40) ? "1.7" : "1.9");
1250 /* Heuristics ! BIOS setup for this mainboard device limits
1251 the choices to standard settings, i.e. io-address and IRQ
1252 are related, however DMA can be 1 or 3, assume DMA_A=DMA1,
1253 DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */
1254 if(cr23*4 >=0x100) { /* if active */
1255 while((superios[i].io!= 0) && (i<NR_SUPERIOS))
1256 i++;
1257 if(i==NR_SUPERIOS)
1258 printk(KERN_INFO "Super-IO: too many chips!\n");
1259 else {
1260 int d;
1261 switch (cr23*4) {
1262 case 0x3bc:
1263 superios[i].io = 0x3bc;
1264 superios[i].irq = 7;
1265 break;
1266 case 0x378:
1267 superios[i].io = 0x378;
1268 superios[i].irq = 7;
1269 break;
1270 case 0x278:
1271 superios[i].io = 0x278;
1272 superios[i].irq = 5;
1274 d=(cr26 &0x0f);
1275 if((d==1) || (d==3))
1276 superios[i].dma= d;
1277 else
1278 superios[i].dma= PARPORT_DMA_NONE;
1284 static void __devinit show_parconfig_winbond(int io, int key)
1286 int cr30,cr60,cr61,cr70,cr74,crf0,i=0;
1287 static const char *const modes[] = {
1288 "Standard (SPP) and Bidirectional(PS/2)", /* 0 */
1289 "EPP-1.9 and SPP",
1290 "ECP",
1291 "ECP and EPP-1.9",
1292 "Standard (SPP)",
1293 "EPP-1.7 and SPP", /* 5 */
1294 "undefined!",
1295 "ECP and EPP-1.7" };
1296 static char *const irqtypes[] = {
1297 "pulsed low, high-Z",
1298 "follows nACK" };
1300 /* The registers are called compatible-PnP because the
1301 register layout is modelled after ISA-PnP, the access
1302 method is just another ... */
1303 outb(key,io);
1304 outb(key,io);
1305 outb(0x07,io); /* Register 7: Select Logical Device */
1306 outb(0x01,io+1); /* LD1 is Parallel Port */
1307 outb(0x30,io);
1308 cr30=inb(io+1);
1309 outb(0x60,io);
1310 cr60=inb(io+1);
1311 outb(0x61,io);
1312 cr61=inb(io+1);
1313 outb(0x70,io);
1314 cr70=inb(io+1);
1315 outb(0x74,io);
1316 cr74=inb(io+1);
1317 outb(0xf0,io);
1318 crf0=inb(io+1);
1319 outb(0xaa,io);
1321 if (verbose_probing) {
1322 printk(KERN_INFO "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x "
1323 "70=%02x 74=%02x, f0=%02x\n", cr30,cr60,cr61,cr70,cr74,crf0);
1324 printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ",
1325 (cr30 & 0x01) ? "yes":"no", cr60,cr61,cr70&0x0f );
1326 if ((cr74 & 0x07) > 3)
1327 printk("dma=none\n");
1328 else
1329 printk("dma=%d\n",cr74 & 0x07);
1330 printk(KERN_INFO "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n",
1331 irqtypes[crf0>>7], (crf0>>3)&0x0f);
1332 printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n", modes[crf0 & 0x07]);
1335 if(cr30 & 0x01) { /* the settings can be interrogated later ... */
1336 while((superios[i].io!= 0) && (i<NR_SUPERIOS))
1337 i++;
1338 if(i==NR_SUPERIOS)
1339 printk(KERN_INFO "Super-IO: too many chips!\n");
1340 else {
1341 superios[i].io = (cr60<<8)|cr61;
1342 superios[i].irq = cr70&0x0f;
1343 superios[i].dma = (((cr74 & 0x07) > 3) ?
1344 PARPORT_DMA_NONE : (cr74 & 0x07));
1349 static void __devinit decode_winbond(int efer, int key, int devid, int devrev, int oldid)
1351 const char *type = "unknown";
1352 int id,progif=2;
1354 if (devid == devrev)
1355 /* simple heuristics, we happened to read some
1356 non-winbond register */
1357 return;
1359 id=(devid<<8) | devrev;
1361 /* Values are from public data sheets pdf files, I can just
1362 confirm 83977TF is correct :-) */
1363 if (id == 0x9771) type="83977F/AF";
1364 else if (id == 0x9773) type="83977TF / SMSC 97w33x/97w34x";
1365 else if (id == 0x9774) type="83977ATF";
1366 else if ((id & ~0x0f) == 0x5270) type="83977CTF / SMSC 97w36x";
1367 else if ((id & ~0x0f) == 0x52f0) type="83977EF / SMSC 97w35x";
1368 else if ((id & ~0x0f) == 0x5210) type="83627";
1369 else if ((id & ~0x0f) == 0x6010) type="83697HF";
1370 else if ((oldid &0x0f ) == 0x0a) { type="83877F"; progif=1;}
1371 else if ((oldid &0x0f ) == 0x0b) { type="83877AF"; progif=1;}
1372 else if ((oldid &0x0f ) == 0x0c) { type="83877TF"; progif=1;}
1373 else if ((oldid &0x0f ) == 0x0d) { type="83877ATF"; progif=1;}
1374 else progif=0;
1376 if (verbose_probing)
1377 printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x "
1378 "devid=%02x devrev=%02x oldid=%02x type=%s\n",
1379 efer, key, devid, devrev, oldid, type);
1381 if (progif == 2)
1382 show_parconfig_winbond(efer,key);
1385 static void __devinit decode_smsc(int efer, int key, int devid, int devrev)
1387 const char *type = "unknown";
1388 void (*func)(int io, int key);
1389 int id;
1391 if (devid == devrev)
1392 /* simple heuristics, we happened to read some
1393 non-smsc register */
1394 return;
1396 func=NULL;
1397 id=(devid<<8) | devrev;
1399 if (id==0x0302) {type="37c669"; func=show_parconfig_smsc37c669;}
1400 else if (id==0x6582) type="37c665IR";
1401 else if (devid==0x65) type="37c665GT";
1402 else if (devid==0x66) type="37c666GT";
1404 if (verbose_probing)
1405 printk(KERN_INFO "SMSC chip at EFER=0x%x "
1406 "key=0x%02x devid=%02x devrev=%02x type=%s\n",
1407 efer, key, devid, devrev, type);
1409 if (func)
1410 func(efer,key);
1414 static void __devinit winbond_check(int io, int key)
1416 int origval, devid, devrev, oldid, x_devid, x_devrev, x_oldid;
1418 if (!request_region(io, 3, __func__))
1419 return;
1421 origval = inb(io); /* Save original value */
1423 /* First probe without key */
1424 outb(0x20,io);
1425 x_devid=inb(io+1);
1426 outb(0x21,io);
1427 x_devrev=inb(io+1);
1428 outb(0x09,io);
1429 x_oldid=inb(io+1);
1431 outb(key,io);
1432 outb(key,io); /* Write Magic Sequence to EFER, extended
1433 funtion enable register */
1434 outb(0x20,io); /* Write EFIR, extended function index register */
1435 devid=inb(io+1); /* Read EFDR, extended function data register */
1436 outb(0x21,io);
1437 devrev=inb(io+1);
1438 outb(0x09,io);
1439 oldid=inb(io+1);
1440 outb(0xaa,io); /* Magic Seal */
1442 outb(origval, io); /* in case we poked some entirely different hardware */
1444 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1445 goto out; /* protection against false positives */
1447 decode_winbond(io,key,devid,devrev,oldid);
1448 out:
1449 release_region(io, 3);
1452 static void __devinit winbond_check2(int io,int key)
1454 int origval[3], devid, devrev, oldid, x_devid, x_devrev, x_oldid;
1456 if (!request_region(io, 3, __func__))
1457 return;
1459 origval[0] = inb(io); /* Save original values */
1460 origval[1] = inb(io + 1);
1461 origval[2] = inb(io + 2);
1463 /* First probe without the key */
1464 outb(0x20,io+2);
1465 x_devid=inb(io+2);
1466 outb(0x21,io+1);
1467 x_devrev=inb(io+2);
1468 outb(0x09,io+1);
1469 x_oldid=inb(io+2);
1471 outb(key,io); /* Write Magic Byte to EFER, extended
1472 funtion enable register */
1473 outb(0x20,io+2); /* Write EFIR, extended function index register */
1474 devid=inb(io+2); /* Read EFDR, extended function data register */
1475 outb(0x21,io+1);
1476 devrev=inb(io+2);
1477 outb(0x09,io+1);
1478 oldid=inb(io+2);
1479 outb(0xaa,io); /* Magic Seal */
1481 outb(origval[0], io); /* in case we poked some entirely different hardware */
1482 outb(origval[1], io + 1);
1483 outb(origval[2], io + 2);
1485 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1486 goto out; /* protection against false positives */
1488 decode_winbond(io,key,devid,devrev,oldid);
1489 out:
1490 release_region(io, 3);
1493 static void __devinit smsc_check(int io, int key)
1495 int origval, id, rev, oldid, oldrev, x_id, x_rev, x_oldid, x_oldrev;
1497 if (!request_region(io, 3, __func__))
1498 return;
1500 origval = inb(io); /* Save original value */
1502 /* First probe without the key */
1503 outb(0x0d,io);
1504 x_oldid=inb(io+1);
1505 outb(0x0e,io);
1506 x_oldrev=inb(io+1);
1507 outb(0x20,io);
1508 x_id=inb(io+1);
1509 outb(0x21,io);
1510 x_rev=inb(io+1);
1512 outb(key,io);
1513 outb(key,io); /* Write Magic Sequence to EFER, extended
1514 funtion enable register */
1515 outb(0x0d,io); /* Write EFIR, extended function index register */
1516 oldid=inb(io+1); /* Read EFDR, extended function data register */
1517 outb(0x0e,io);
1518 oldrev=inb(io+1);
1519 outb(0x20,io);
1520 id=inb(io+1);
1521 outb(0x21,io);
1522 rev=inb(io+1);
1523 outb(0xaa,io); /* Magic Seal */
1525 outb(origval, io); /* in case we poked some entirely different hardware */
1527 if ((x_id == id) && (x_oldrev == oldrev) &&
1528 (x_oldid == oldid) && (x_rev == rev))
1529 goto out; /* protection against false positives */
1531 decode_smsc(io,key,oldid,oldrev);
1532 out:
1533 release_region(io, 3);
1537 static void __devinit detect_and_report_winbond (void)
1539 if (verbose_probing)
1540 printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n");
1541 winbond_check(0x3f0,0x87);
1542 winbond_check(0x370,0x87);
1543 winbond_check(0x2e ,0x87);
1544 winbond_check(0x4e ,0x87);
1545 winbond_check(0x3f0,0x86);
1546 winbond_check2(0x250,0x88);
1547 winbond_check2(0x250,0x89);
1550 static void __devinit detect_and_report_smsc (void)
1552 if (verbose_probing)
1553 printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n");
1554 smsc_check(0x3f0,0x55);
1555 smsc_check(0x370,0x55);
1556 smsc_check(0x3f0,0x44);
1557 smsc_check(0x370,0x44);
1560 static void __devinit detect_and_report_it87(void)
1562 u16 dev;
1563 u8 origval, r;
1564 if (verbose_probing)
1565 printk(KERN_DEBUG "IT8705 Super-IO detection, now testing port 2E ...\n");
1566 if (!request_region(0x2e, 2, __func__))
1567 return;
1568 origval = inb(0x2e); /* Save original value */
1569 outb(0x87, 0x2e);
1570 outb(0x01, 0x2e);
1571 outb(0x55, 0x2e);
1572 outb(0x55, 0x2e);
1573 outb(0x20, 0x2e);
1574 dev = inb(0x2f) << 8;
1575 outb(0x21, 0x2e);
1576 dev |= inb(0x2f);
1577 if (dev == 0x8712 || dev == 0x8705 || dev == 0x8715 ||
1578 dev == 0x8716 || dev == 0x8718 || dev == 0x8726) {
1579 printk(KERN_INFO "IT%04X SuperIO detected.\n", dev);
1580 outb(0x07, 0x2E); /* Parallel Port */
1581 outb(0x03, 0x2F);
1582 outb(0xF0, 0x2E); /* BOOT 0x80 off */
1583 r = inb(0x2f);
1584 outb(0xF0, 0x2E);
1585 outb(r | 8, 0x2F);
1586 outb(0x02, 0x2E); /* Lock */
1587 outb(0x02, 0x2F);
1588 } else {
1589 outb(origval, 0x2e); /* Oops, sorry to disturb */
1591 release_region(0x2e, 2);
1593 #endif /* CONFIG_PARPORT_PC_SUPERIO */
1595 static int get_superio_dma (struct parport *p)
1597 int i=0;
1598 while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
1599 i++;
1600 if (i!=NR_SUPERIOS)
1601 return superios[i].dma;
1602 return PARPORT_DMA_NONE;
1605 static int get_superio_irq (struct parport *p)
1607 int i=0;
1608 while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
1609 i++;
1610 if (i!=NR_SUPERIOS)
1611 return superios[i].irq;
1612 return PARPORT_IRQ_NONE;
1616 /* --- Mode detection ------------------------------------- */
1619 * Checks for port existence, all ports support SPP MODE
1620 * Returns:
1621 * 0 : No parallel port at this address
1622 * PARPORT_MODE_PCSPP : SPP port detected
1623 * (if the user specified an ioport himself,
1624 * this shall always be the case!)
1627 static int parport_SPP_supported(struct parport *pb)
1629 unsigned char r, w;
1632 * first clear an eventually pending EPP timeout
1633 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
1634 * that does not even respond to SPP cycles if an EPP
1635 * timeout is pending
1637 clear_epp_timeout(pb);
1639 /* Do a simple read-write test to make sure the port exists. */
1640 w = 0xc;
1641 outb (w, CONTROL (pb));
1643 /* Is there a control register that we can read from? Some
1644 * ports don't allow reads, so read_control just returns a
1645 * software copy. Some ports _do_ allow reads, so bypass the
1646 * software copy here. In addition, some bits aren't
1647 * writable. */
1648 r = inb (CONTROL (pb));
1649 if ((r & 0xf) == w) {
1650 w = 0xe;
1651 outb (w, CONTROL (pb));
1652 r = inb (CONTROL (pb));
1653 outb (0xc, CONTROL (pb));
1654 if ((r & 0xf) == w)
1655 return PARPORT_MODE_PCSPP;
1658 if (user_specified)
1659 /* That didn't work, but the user thinks there's a
1660 * port here. */
1661 printk (KERN_INFO "parport 0x%lx (WARNING): CTR: "
1662 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1664 /* Try the data register. The data lines aren't tri-stated at
1665 * this stage, so we expect back what we wrote. */
1666 w = 0xaa;
1667 parport_pc_write_data (pb, w);
1668 r = parport_pc_read_data (pb);
1669 if (r == w) {
1670 w = 0x55;
1671 parport_pc_write_data (pb, w);
1672 r = parport_pc_read_data (pb);
1673 if (r == w)
1674 return PARPORT_MODE_PCSPP;
1677 if (user_specified) {
1678 /* Didn't work, but the user is convinced this is the
1679 * place. */
1680 printk (KERN_INFO "parport 0x%lx (WARNING): DATA: "
1681 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1682 printk (KERN_INFO "parport 0x%lx: You gave this address, "
1683 "but there is probably no parallel port there!\n",
1684 pb->base);
1687 /* It's possible that we can't read the control register or
1688 * the data register. In that case just believe the user. */
1689 if (user_specified)
1690 return PARPORT_MODE_PCSPP;
1692 return 0;
1695 /* Check for ECR
1697 * Old style XT ports alias io ports every 0x400, hence accessing ECR
1698 * on these cards actually accesses the CTR.
1700 * Modern cards don't do this but reading from ECR will return 0xff
1701 * regardless of what is written here if the card does NOT support
1702 * ECP.
1704 * We first check to see if ECR is the same as CTR. If not, the low
1705 * two bits of ECR aren't writable, so we check by writing ECR and
1706 * reading it back to see if it's what we expect.
1708 static int parport_ECR_present(struct parport *pb)
1710 struct parport_pc_private *priv = pb->private_data;
1711 unsigned char r = 0xc;
1713 outb (r, CONTROL (pb));
1714 if ((inb (ECONTROL (pb)) & 0x3) == (r & 0x3)) {
1715 outb (r ^ 0x2, CONTROL (pb)); /* Toggle bit 1 */
1717 r = inb (CONTROL (pb));
1718 if ((inb (ECONTROL (pb)) & 0x2) == (r & 0x2))
1719 goto no_reg; /* Sure that no ECR register exists */
1722 if ((inb (ECONTROL (pb)) & 0x3 ) != 0x1)
1723 goto no_reg;
1725 ECR_WRITE (pb, 0x34);
1726 if (inb (ECONTROL (pb)) != 0x35)
1727 goto no_reg;
1729 priv->ecr = 1;
1730 outb (0xc, CONTROL (pb));
1732 /* Go to mode 000 */
1733 frob_set_mode (pb, ECR_SPP);
1735 return 1;
1737 no_reg:
1738 outb (0xc, CONTROL (pb));
1739 return 0;
1742 #ifdef CONFIG_PARPORT_1284
1743 /* Detect PS/2 support.
1745 * Bit 5 (0x20) sets the PS/2 data direction; setting this high
1746 * allows us to read data from the data lines. In theory we would get back
1747 * 0xff but any peripheral attached to the port may drag some or all of the
1748 * lines down to zero. So if we get back anything that isn't the contents
1749 * of the data register we deem PS/2 support to be present.
1751 * Some SPP ports have "half PS/2" ability - you can't turn off the line
1752 * drivers, but an external peripheral with sufficiently beefy drivers of
1753 * its own can overpower them and assert its own levels onto the bus, from
1754 * where they can then be read back as normal. Ports with this property
1755 * and the right type of device attached are likely to fail the SPP test,
1756 * (as they will appear to have stuck bits) and so the fact that they might
1757 * be misdetected here is rather academic.
1760 static int parport_PS2_supported(struct parport *pb)
1762 int ok = 0;
1764 clear_epp_timeout(pb);
1766 /* try to tri-state the buffer */
1767 parport_pc_data_reverse (pb);
1769 parport_pc_write_data(pb, 0x55);
1770 if (parport_pc_read_data(pb) != 0x55) ok++;
1772 parport_pc_write_data(pb, 0xaa);
1773 if (parport_pc_read_data(pb) != 0xaa) ok++;
1775 /* cancel input mode */
1776 parport_pc_data_forward (pb);
1778 if (ok) {
1779 pb->modes |= PARPORT_MODE_TRISTATE;
1780 } else {
1781 struct parport_pc_private *priv = pb->private_data;
1782 priv->ctr_writable &= ~0x20;
1785 return ok;
1788 #ifdef CONFIG_PARPORT_PC_FIFO
1789 static int parport_ECP_supported(struct parport *pb)
1791 int i;
1792 int config, configb;
1793 int pword;
1794 struct parport_pc_private *priv = pb->private_data;
1795 /* Translate ECP intrLine to ISA irq value */
1796 static const int intrline[]= { 0, 7, 9, 10, 11, 14, 15, 5 };
1798 /* If there is no ECR, we have no hope of supporting ECP. */
1799 if (!priv->ecr)
1800 return 0;
1802 /* Find out FIFO depth */
1803 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */
1804 ECR_WRITE (pb, ECR_TST << 5); /* TEST FIFO */
1805 for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02); i++)
1806 outb (0xaa, FIFO (pb));
1809 * Using LGS chipset it uses ECR register, but
1810 * it doesn't support ECP or FIFO MODE
1812 if (i == 1024) {
1813 ECR_WRITE (pb, ECR_SPP << 5);
1814 return 0;
1817 priv->fifo_depth = i;
1818 if (verbose_probing)
1819 printk (KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i);
1821 /* Find out writeIntrThreshold */
1822 frob_econtrol (pb, 1<<2, 1<<2);
1823 frob_econtrol (pb, 1<<2, 0);
1824 for (i = 1; i <= priv->fifo_depth; i++) {
1825 inb (FIFO (pb));
1826 udelay (50);
1827 if (inb (ECONTROL (pb)) & (1<<2))
1828 break;
1831 if (i <= priv->fifo_depth) {
1832 if (verbose_probing)
1833 printk (KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n",
1834 pb->base, i);
1835 } else
1836 /* Number of bytes we know we can write if we get an
1837 interrupt. */
1838 i = 0;
1840 priv->writeIntrThreshold = i;
1842 /* Find out readIntrThreshold */
1843 frob_set_mode (pb, ECR_PS2); /* Reset FIFO and enable PS2 */
1844 parport_pc_data_reverse (pb); /* Must be in PS2 mode */
1845 frob_set_mode (pb, ECR_TST); /* Test FIFO */
1846 frob_econtrol (pb, 1<<2, 1<<2);
1847 frob_econtrol (pb, 1<<2, 0);
1848 for (i = 1; i <= priv->fifo_depth; i++) {
1849 outb (0xaa, FIFO (pb));
1850 if (inb (ECONTROL (pb)) & (1<<2))
1851 break;
1854 if (i <= priv->fifo_depth) {
1855 if (verbose_probing)
1856 printk (KERN_INFO "0x%lx: readIntrThreshold is %d\n",
1857 pb->base, i);
1858 } else
1859 /* Number of bytes we can read if we get an interrupt. */
1860 i = 0;
1862 priv->readIntrThreshold = i;
1864 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */
1865 ECR_WRITE (pb, 0xf4); /* Configuration mode */
1866 config = inb (CONFIGA (pb));
1867 pword = (config >> 4) & 0x7;
1868 switch (pword) {
1869 case 0:
1870 pword = 2;
1871 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n",
1872 pb->base);
1873 break;
1874 case 2:
1875 pword = 4;
1876 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n",
1877 pb->base);
1878 break;
1879 default:
1880 printk (KERN_WARNING "0x%lx: Unknown implementation ID\n",
1881 pb->base);
1882 /* Assume 1 */
1883 case 1:
1884 pword = 1;
1886 priv->pword = pword;
1888 if (verbose_probing) {
1889 printk (KERN_DEBUG "0x%lx: PWord is %d bits\n", pb->base, 8 * pword);
1891 printk (KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base,
1892 config & 0x80 ? "Level" : "Pulses");
1894 configb = inb (CONFIGB (pb));
1895 printk (KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n",
1896 pb->base, config, configb);
1897 printk (KERN_DEBUG "0x%lx: ECP settings irq=", pb->base);
1898 if ((configb >>3) & 0x07)
1899 printk("%d",intrline[(configb >>3) & 0x07]);
1900 else
1901 printk("<none or set by other means>");
1902 printk (" dma=");
1903 if( (configb & 0x03 ) == 0x00)
1904 printk("<none or set by other means>\n");
1905 else
1906 printk("%d\n",configb & 0x07);
1909 /* Go back to mode 000 */
1910 frob_set_mode (pb, ECR_SPP);
1912 return 1;
1914 #endif
1916 static int parport_ECPPS2_supported(struct parport *pb)
1918 const struct parport_pc_private *priv = pb->private_data;
1919 int result;
1920 unsigned char oecr;
1922 if (!priv->ecr)
1923 return 0;
1925 oecr = inb (ECONTROL (pb));
1926 ECR_WRITE (pb, ECR_PS2 << 5);
1927 result = parport_PS2_supported(pb);
1928 ECR_WRITE (pb, oecr);
1929 return result;
1932 /* EPP mode detection */
1934 static int parport_EPP_supported(struct parport *pb)
1936 const struct parport_pc_private *priv = pb->private_data;
1939 * Theory:
1940 * Bit 0 of STR is the EPP timeout bit, this bit is 0
1941 * when EPP is possible and is set high when an EPP timeout
1942 * occurs (EPP uses the HALT line to stop the CPU while it does
1943 * the byte transfer, an EPP timeout occurs if the attached
1944 * device fails to respond after 10 micro seconds).
1946 * This bit is cleared by either reading it (National Semi)
1947 * or writing a 1 to the bit (SMC, UMC, WinBond), others ???
1948 * This bit is always high in non EPP modes.
1951 /* If EPP timeout bit clear then EPP available */
1952 if (!clear_epp_timeout(pb)) {
1953 return 0; /* No way to clear timeout */
1956 /* Check for Intel bug. */
1957 if (priv->ecr) {
1958 unsigned char i;
1959 for (i = 0x00; i < 0x80; i += 0x20) {
1960 ECR_WRITE (pb, i);
1961 if (clear_epp_timeout (pb)) {
1962 /* Phony EPP in ECP. */
1963 return 0;
1968 pb->modes |= PARPORT_MODE_EPP;
1970 /* Set up access functions to use EPP hardware. */
1971 pb->ops->epp_read_data = parport_pc_epp_read_data;
1972 pb->ops->epp_write_data = parport_pc_epp_write_data;
1973 pb->ops->epp_read_addr = parport_pc_epp_read_addr;
1974 pb->ops->epp_write_addr = parport_pc_epp_write_addr;
1976 return 1;
1979 static int parport_ECPEPP_supported(struct parport *pb)
1981 struct parport_pc_private *priv = pb->private_data;
1982 int result;
1983 unsigned char oecr;
1985 if (!priv->ecr) {
1986 return 0;
1989 oecr = inb (ECONTROL (pb));
1990 /* Search for SMC style EPP+ECP mode */
1991 ECR_WRITE (pb, 0x80);
1992 outb (0x04, CONTROL (pb));
1993 result = parport_EPP_supported(pb);
1995 ECR_WRITE (pb, oecr);
1997 if (result) {
1998 /* Set up access functions to use ECP+EPP hardware. */
1999 pb->ops->epp_read_data = parport_pc_ecpepp_read_data;
2000 pb->ops->epp_write_data = parport_pc_ecpepp_write_data;
2001 pb->ops->epp_read_addr = parport_pc_ecpepp_read_addr;
2002 pb->ops->epp_write_addr = parport_pc_ecpepp_write_addr;
2005 return result;
2008 #else /* No IEEE 1284 support */
2010 /* Don't bother probing for modes we know we won't use. */
2011 static int __devinit parport_PS2_supported(struct parport *pb) { return 0; }
2012 #ifdef CONFIG_PARPORT_PC_FIFO
2013 static int parport_ECP_supported(struct parport *pb) { return 0; }
2014 #endif
2015 static int __devinit parport_EPP_supported(struct parport *pb) { return 0; }
2016 static int __devinit parport_ECPEPP_supported(struct parport *pb){return 0;}
2017 static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;}
2019 #endif /* No IEEE 1284 support */
2021 /* --- IRQ detection -------------------------------------- */
2023 /* Only if supports ECP mode */
2024 static int programmable_irq_support(struct parport *pb)
2026 int irq, intrLine;
2027 unsigned char oecr = inb (ECONTROL (pb));
2028 static const int lookup[8] = {
2029 PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5
2032 ECR_WRITE (pb, ECR_CNF << 5); /* Configuration MODE */
2034 intrLine = (inb (CONFIGB (pb)) >> 3) & 0x07;
2035 irq = lookup[intrLine];
2037 ECR_WRITE (pb, oecr);
2038 return irq;
2041 static int irq_probe_ECP(struct parport *pb)
2043 int i;
2044 unsigned long irqs;
2046 irqs = probe_irq_on();
2048 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */
2049 ECR_WRITE (pb, (ECR_TST << 5) | 0x04);
2050 ECR_WRITE (pb, ECR_TST << 5);
2052 /* If Full FIFO sure that writeIntrThreshold is generated */
2053 for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02) ; i++)
2054 outb (0xaa, FIFO (pb));
2056 pb->irq = probe_irq_off(irqs);
2057 ECR_WRITE (pb, ECR_SPP << 5);
2059 if (pb->irq <= 0)
2060 pb->irq = PARPORT_IRQ_NONE;
2062 return pb->irq;
2066 * This detection seems that only works in National Semiconductors
2067 * This doesn't work in SMC, LGS, and Winbond
2069 static int irq_probe_EPP(struct parport *pb)
2071 #ifndef ADVANCED_DETECT
2072 return PARPORT_IRQ_NONE;
2073 #else
2074 int irqs;
2075 unsigned char oecr;
2077 if (pb->modes & PARPORT_MODE_PCECR)
2078 oecr = inb (ECONTROL (pb));
2080 irqs = probe_irq_on();
2082 if (pb->modes & PARPORT_MODE_PCECR)
2083 frob_econtrol (pb, 0x10, 0x10);
2085 clear_epp_timeout(pb);
2086 parport_pc_frob_control (pb, 0x20, 0x20);
2087 parport_pc_frob_control (pb, 0x10, 0x10);
2088 clear_epp_timeout(pb);
2090 /* Device isn't expecting an EPP read
2091 * and generates an IRQ.
2093 parport_pc_read_epp(pb);
2094 udelay(20);
2096 pb->irq = probe_irq_off (irqs);
2097 if (pb->modes & PARPORT_MODE_PCECR)
2098 ECR_WRITE (pb, oecr);
2099 parport_pc_write_control(pb, 0xc);
2101 if (pb->irq <= 0)
2102 pb->irq = PARPORT_IRQ_NONE;
2104 return pb->irq;
2105 #endif /* Advanced detection */
2108 static int irq_probe_SPP(struct parport *pb)
2110 /* Don't even try to do this. */
2111 return PARPORT_IRQ_NONE;
2114 /* We will attempt to share interrupt requests since other devices
2115 * such as sound cards and network cards seem to like using the
2116 * printer IRQs.
2118 * When ECP is available we can autoprobe for IRQs.
2119 * NOTE: If we can autoprobe it, we can register the IRQ.
2121 static int parport_irq_probe(struct parport *pb)
2123 struct parport_pc_private *priv = pb->private_data;
2125 if (priv->ecr) {
2126 pb->irq = programmable_irq_support(pb);
2128 if (pb->irq == PARPORT_IRQ_NONE)
2129 pb->irq = irq_probe_ECP(pb);
2132 if ((pb->irq == PARPORT_IRQ_NONE) && priv->ecr &&
2133 (pb->modes & PARPORT_MODE_EPP))
2134 pb->irq = irq_probe_EPP(pb);
2136 clear_epp_timeout(pb);
2138 if (pb->irq == PARPORT_IRQ_NONE && (pb->modes & PARPORT_MODE_EPP))
2139 pb->irq = irq_probe_EPP(pb);
2141 clear_epp_timeout(pb);
2143 if (pb->irq == PARPORT_IRQ_NONE)
2144 pb->irq = irq_probe_SPP(pb);
2146 if (pb->irq == PARPORT_IRQ_NONE)
2147 pb->irq = get_superio_irq(pb);
2149 return pb->irq;
2152 /* --- DMA detection -------------------------------------- */
2154 /* Only if chipset conforms to ECP ISA Interface Standard */
2155 static int programmable_dma_support (struct parport *p)
2157 unsigned char oecr = inb (ECONTROL (p));
2158 int dma;
2160 frob_set_mode (p, ECR_CNF);
2162 dma = inb (CONFIGB(p)) & 0x07;
2163 /* 000: Indicates jumpered 8-bit DMA if read-only.
2164 100: Indicates jumpered 16-bit DMA if read-only. */
2165 if ((dma & 0x03) == 0)
2166 dma = PARPORT_DMA_NONE;
2168 ECR_WRITE (p, oecr);
2169 return dma;
2172 static int parport_dma_probe (struct parport *p)
2174 const struct parport_pc_private *priv = p->private_data;
2175 if (priv->ecr)
2176 p->dma = programmable_dma_support(p); /* ask ECP chipset first */
2177 if (p->dma == PARPORT_DMA_NONE) {
2178 /* ask known Super-IO chips proper, although these
2179 claim ECP compatible, some don't report their DMA
2180 conforming to ECP standards */
2181 p->dma = get_superio_dma(p);
2184 return p->dma;
2187 /* --- Initialisation code -------------------------------- */
2189 static LIST_HEAD(ports_list);
2190 static DEFINE_SPINLOCK(ports_lock);
2192 struct parport *parport_pc_probe_port (unsigned long int base,
2193 unsigned long int base_hi,
2194 int irq, int dma,
2195 struct device *dev)
2197 struct parport_pc_private *priv;
2198 struct parport_operations *ops;
2199 struct parport *p;
2200 int probedirq = PARPORT_IRQ_NONE;
2201 struct resource *base_res;
2202 struct resource *ECR_res = NULL;
2203 struct resource *EPP_res = NULL;
2204 struct platform_device *pdev = NULL;
2206 if (!dev) {
2207 /* We need a physical device to attach to, but none was
2208 * provided. Create our own. */
2209 pdev = platform_device_register_simple("parport_pc",
2210 base, NULL, 0);
2211 if (IS_ERR(pdev))
2212 return NULL;
2213 dev = &pdev->dev;
2215 dev->coherent_dma_mask = DMA_BIT_MASK(24);
2216 dev->dma_mask = &dev->coherent_dma_mask;
2219 ops = kmalloc(sizeof (struct parport_operations), GFP_KERNEL);
2220 if (!ops)
2221 goto out1;
2223 priv = kmalloc (sizeof (struct parport_pc_private), GFP_KERNEL);
2224 if (!priv)
2225 goto out2;
2227 /* a misnomer, actually - it's allocate and reserve parport number */
2228 p = parport_register_port(base, irq, dma, ops);
2229 if (!p)
2230 goto out3;
2232 base_res = request_region(base, 3, p->name);
2233 if (!base_res)
2234 goto out4;
2236 memcpy(ops, &parport_pc_ops, sizeof (struct parport_operations));
2237 priv->ctr = 0xc;
2238 priv->ctr_writable = ~0x10;
2239 priv->ecr = 0;
2240 priv->fifo_depth = 0;
2241 priv->dma_buf = NULL;
2242 priv->dma_handle = 0;
2243 INIT_LIST_HEAD(&priv->list);
2244 priv->port = p;
2246 p->dev = dev;
2247 p->base_hi = base_hi;
2248 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
2249 p->private_data = priv;
2251 if (base_hi) {
2252 ECR_res = request_region(base_hi, 3, p->name);
2253 if (ECR_res)
2254 parport_ECR_present(p);
2257 if (base != 0x3bc) {
2258 EPP_res = request_region(base+0x3, 5, p->name);
2259 if (EPP_res)
2260 if (!parport_EPP_supported(p))
2261 parport_ECPEPP_supported(p);
2263 if (!parport_SPP_supported (p))
2264 /* No port. */
2265 goto out5;
2266 if (priv->ecr)
2267 parport_ECPPS2_supported(p);
2268 else
2269 parport_PS2_supported(p);
2271 p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
2273 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
2274 if (p->base_hi && priv->ecr)
2275 printk(" (0x%lx)", p->base_hi);
2276 if (p->irq == PARPORT_IRQ_AUTO) {
2277 p->irq = PARPORT_IRQ_NONE;
2278 parport_irq_probe(p);
2279 } else if (p->irq == PARPORT_IRQ_PROBEONLY) {
2280 p->irq = PARPORT_IRQ_NONE;
2281 parport_irq_probe(p);
2282 probedirq = p->irq;
2283 p->irq = PARPORT_IRQ_NONE;
2285 if (p->irq != PARPORT_IRQ_NONE) {
2286 printk(", irq %d", p->irq);
2287 priv->ctr_writable |= 0x10;
2289 if (p->dma == PARPORT_DMA_AUTO) {
2290 p->dma = PARPORT_DMA_NONE;
2291 parport_dma_probe(p);
2294 if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
2295 is mandatory (see above) */
2296 p->dma = PARPORT_DMA_NONE;
2298 #ifdef CONFIG_PARPORT_PC_FIFO
2299 if (parport_ECP_supported(p) &&
2300 p->dma != PARPORT_DMA_NOFIFO &&
2301 priv->fifo_depth > 0 && p->irq != PARPORT_IRQ_NONE) {
2302 p->modes |= PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
2303 p->ops->compat_write_data = parport_pc_compat_write_block_pio;
2304 #ifdef CONFIG_PARPORT_1284
2305 p->ops->ecp_write_data = parport_pc_ecp_write_block_pio;
2306 /* currently broken, but working on it.. (FB) */
2307 /* p->ops->ecp_read_data = parport_pc_ecp_read_block_pio; */
2308 #endif /* IEEE 1284 support */
2309 if (p->dma != PARPORT_DMA_NONE) {
2310 printk(", dma %d", p->dma);
2311 p->modes |= PARPORT_MODE_DMA;
2313 else printk(", using FIFO");
2315 else
2316 /* We can't use the DMA channel after all. */
2317 p->dma = PARPORT_DMA_NONE;
2318 #endif /* Allowed to use FIFO/DMA */
2320 printk(" [");
2321 #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
2323 int f = 0;
2324 printmode(PCSPP);
2325 printmode(TRISTATE);
2326 printmode(COMPAT)
2327 printmode(EPP);
2328 printmode(ECP);
2329 printmode(DMA);
2331 #undef printmode
2332 #ifndef CONFIG_PARPORT_1284
2333 printk ("(,...)");
2334 #endif /* CONFIG_PARPORT_1284 */
2335 printk("]\n");
2336 if (probedirq != PARPORT_IRQ_NONE)
2337 printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq);
2339 /* If No ECP release the ports grabbed above. */
2340 if (ECR_res && (p->modes & PARPORT_MODE_ECP) == 0) {
2341 release_region(base_hi, 3);
2342 ECR_res = NULL;
2344 /* Likewise for EEP ports */
2345 if (EPP_res && (p->modes & PARPORT_MODE_EPP) == 0) {
2346 release_region(base+3, 5);
2347 EPP_res = NULL;
2349 if (p->irq != PARPORT_IRQ_NONE) {
2350 if (request_irq (p->irq, parport_irq_handler,
2351 0, p->name, p)) {
2352 printk (KERN_WARNING "%s: irq %d in use, "
2353 "resorting to polled operation\n",
2354 p->name, p->irq);
2355 p->irq = PARPORT_IRQ_NONE;
2356 p->dma = PARPORT_DMA_NONE;
2359 #ifdef CONFIG_PARPORT_PC_FIFO
2360 #ifdef HAS_DMA
2361 if (p->dma != PARPORT_DMA_NONE) {
2362 if (request_dma (p->dma, p->name)) {
2363 printk (KERN_WARNING "%s: dma %d in use, "
2364 "resorting to PIO operation\n",
2365 p->name, p->dma);
2366 p->dma = PARPORT_DMA_NONE;
2367 } else {
2368 priv->dma_buf =
2369 dma_alloc_coherent(dev,
2370 PAGE_SIZE,
2371 &priv->dma_handle,
2372 GFP_KERNEL);
2373 if (! priv->dma_buf) {
2374 printk (KERN_WARNING "%s: "
2375 "cannot get buffer for DMA, "
2376 "resorting to PIO operation\n",
2377 p->name);
2378 free_dma(p->dma);
2379 p->dma = PARPORT_DMA_NONE;
2383 #endif
2384 #endif
2387 /* Done probing. Now put the port into a sensible start-up state. */
2388 if (priv->ecr)
2390 * Put the ECP detected port in PS2 mode.
2391 * Do this also for ports that have ECR but don't do ECP.
2393 ECR_WRITE (p, 0x34);
2395 parport_pc_write_data(p, 0);
2396 parport_pc_data_forward (p);
2398 /* Now that we've told the sharing engine about the port, and
2399 found out its characteristics, let the high-level drivers
2400 know about it. */
2401 spin_lock(&ports_lock);
2402 list_add(&priv->list, &ports_list);
2403 spin_unlock(&ports_lock);
2404 parport_announce_port (p);
2406 return p;
2408 out5:
2409 if (ECR_res)
2410 release_region(base_hi, 3);
2411 if (EPP_res)
2412 release_region(base+0x3, 5);
2413 release_region(base, 3);
2414 out4:
2415 parport_put_port(p);
2416 out3:
2417 kfree (priv);
2418 out2:
2419 kfree (ops);
2420 out1:
2421 if (pdev)
2422 platform_device_unregister(pdev);
2423 return NULL;
2426 EXPORT_SYMBOL (parport_pc_probe_port);
2428 void parport_pc_unregister_port (struct parport *p)
2430 struct parport_pc_private *priv = p->private_data;
2431 struct parport_operations *ops = p->ops;
2433 parport_remove_port(p);
2434 spin_lock(&ports_lock);
2435 list_del_init(&priv->list);
2436 spin_unlock(&ports_lock);
2437 #if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
2438 if (p->dma != PARPORT_DMA_NONE)
2439 free_dma(p->dma);
2440 #endif
2441 if (p->irq != PARPORT_IRQ_NONE)
2442 free_irq(p->irq, p);
2443 release_region(p->base, 3);
2444 if (p->size > 3)
2445 release_region(p->base + 3, p->size - 3);
2446 if (p->modes & PARPORT_MODE_ECP)
2447 release_region(p->base_hi, 3);
2448 #if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
2449 if (priv->dma_buf)
2450 dma_free_coherent(p->physport->dev, PAGE_SIZE,
2451 priv->dma_buf,
2452 priv->dma_handle);
2453 #endif
2454 kfree (p->private_data);
2455 parport_put_port(p);
2456 kfree (ops); /* hope no-one cached it */
2459 EXPORT_SYMBOL (parport_pc_unregister_port);
2461 #ifdef CONFIG_PCI
2463 /* ITE support maintained by Rich Liu <richliu@poorman.org> */
2464 static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq,
2465 int autodma,
2466 const struct parport_pc_via_data *via)
2468 short inta_addr[6] = { 0x2A0, 0x2C0, 0x220, 0x240, 0x1E0 };
2469 struct resource *base_res;
2470 u32 ite8872set;
2471 u32 ite8872_lpt, ite8872_lpthi;
2472 u8 ite8872_irq, type;
2473 int irq;
2474 int i;
2476 DPRINTK (KERN_DEBUG "sio_ite_8872_probe()\n");
2478 // make sure which one chip
2479 for(i = 0; i < 5; i++) {
2480 base_res = request_region(inta_addr[i], 32, "it887x");
2481 if (base_res) {
2482 int test;
2483 pci_write_config_dword (pdev, 0x60,
2484 0xe5000000 | inta_addr[i]);
2485 pci_write_config_dword (pdev, 0x78,
2486 0x00000000 | inta_addr[i]);
2487 test = inb (inta_addr[i]);
2488 if (test != 0xff) break;
2489 release_region(inta_addr[i], 0x8);
2492 if(i >= 5) {
2493 printk (KERN_INFO "parport_pc: cannot find ITE8872 INTA\n");
2494 return 0;
2497 type = inb (inta_addr[i] + 0x18);
2498 type &= 0x0f;
2500 switch (type) {
2501 case 0x2:
2502 printk (KERN_INFO "parport_pc: ITE8871 found (1P)\n");
2503 ite8872set = 0x64200000;
2504 break;
2505 case 0xa:
2506 printk (KERN_INFO "parport_pc: ITE8875 found (1P)\n");
2507 ite8872set = 0x64200000;
2508 break;
2509 case 0xe:
2510 printk (KERN_INFO "parport_pc: ITE8872 found (2S1P)\n");
2511 ite8872set = 0x64e00000;
2512 break;
2513 case 0x6:
2514 printk (KERN_INFO "parport_pc: ITE8873 found (1S)\n");
2515 return 0;
2516 case 0x8:
2517 DPRINTK (KERN_DEBUG "parport_pc: ITE8874 found (2S)\n");
2518 return 0;
2519 default:
2520 printk (KERN_INFO "parport_pc: unknown ITE887x\n");
2521 printk (KERN_INFO "parport_pc: please mail 'lspci -nvv' "
2522 "output to Rich.Liu@ite.com.tw\n");
2523 return 0;
2526 pci_read_config_byte (pdev, 0x3c, &ite8872_irq);
2527 pci_read_config_dword (pdev, 0x1c, &ite8872_lpt);
2528 ite8872_lpt &= 0x0000ff00;
2529 pci_read_config_dword (pdev, 0x20, &ite8872_lpthi);
2530 ite8872_lpthi &= 0x0000ff00;
2531 pci_write_config_dword (pdev, 0x6c, 0xe3000000 | ite8872_lpt);
2532 pci_write_config_dword (pdev, 0x70, 0xe3000000 | ite8872_lpthi);
2533 pci_write_config_dword (pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt);
2534 // SET SPP&EPP , Parallel Port NO DMA , Enable All Function
2535 // SET Parallel IRQ
2536 pci_write_config_dword (pdev, 0x9c,
2537 ite8872set | (ite8872_irq * 0x11111));
2539 DPRINTK (KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq);
2540 DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n",
2541 ite8872_lpt);
2542 DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n",
2543 ite8872_lpthi);
2545 /* Let the user (or defaults) steer us away from interrupts */
2546 irq = ite8872_irq;
2547 if (autoirq != PARPORT_IRQ_AUTO)
2548 irq = PARPORT_IRQ_NONE;
2551 * Release the resource so that parport_pc_probe_port can get it.
2553 release_resource(base_res);
2554 if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi,
2555 irq, PARPORT_DMA_NONE, &pdev->dev)) {
2556 printk (KERN_INFO
2557 "parport_pc: ITE 8872 parallel port: io=0x%X",
2558 ite8872_lpt);
2559 if (irq != PARPORT_IRQ_NONE)
2560 printk (", irq=%d", irq);
2561 printk ("\n");
2562 return 1;
2565 return 0;
2568 /* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru>
2569 based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */
2570 static int __devinitdata parport_init_mode = 0;
2572 /* Data for two known VIA chips */
2573 static struct parport_pc_via_data via_686a_data __devinitdata = {
2574 0x51,
2575 0x50,
2576 0x85,
2577 0x02,
2578 0xE2,
2579 0xF0,
2580 0xE6
2582 static struct parport_pc_via_data via_8231_data __devinitdata = {
2583 0x45,
2584 0x44,
2585 0x50,
2586 0x04,
2587 0xF2,
2588 0xFA,
2589 0xF6
2592 static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
2593 int autodma,
2594 const struct parport_pc_via_data *via)
2596 u8 tmp, tmp2, siofunc;
2597 u8 ppcontrol = 0;
2598 int dma, irq;
2599 unsigned port1, port2;
2600 unsigned have_epp = 0;
2602 printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n");
2604 switch(parport_init_mode)
2606 case 1:
2607 printk(KERN_DEBUG "parport_pc: setting SPP mode\n");
2608 siofunc = VIA_FUNCTION_PARPORT_SPP;
2609 break;
2610 case 2:
2611 printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n");
2612 siofunc = VIA_FUNCTION_PARPORT_SPP;
2613 ppcontrol = VIA_PARPORT_BIDIR;
2614 break;
2615 case 3:
2616 printk(KERN_DEBUG "parport_pc: setting EPP mode\n");
2617 siofunc = VIA_FUNCTION_PARPORT_EPP;
2618 ppcontrol = VIA_PARPORT_BIDIR;
2619 have_epp = 1;
2620 break;
2621 case 4:
2622 printk(KERN_DEBUG "parport_pc: setting ECP mode\n");
2623 siofunc = VIA_FUNCTION_PARPORT_ECP;
2624 ppcontrol = VIA_PARPORT_BIDIR;
2625 break;
2626 case 5:
2627 printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n");
2628 siofunc = VIA_FUNCTION_PARPORT_ECP;
2629 ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP;
2630 have_epp = 1;
2631 break;
2632 default:
2633 printk(KERN_DEBUG "parport_pc: probing current configuration\n");
2634 siofunc = VIA_FUNCTION_PROBE;
2635 break;
2638 * unlock super i/o configuration
2640 pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
2641 tmp |= via->via_pci_superio_config_data;
2642 pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
2644 /* Bits 1-0: Parallel Port Mode / Enable */
2645 outb(via->viacfg_function, VIA_CONFIG_INDEX);
2646 tmp = inb (VIA_CONFIG_DATA);
2647 /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */
2648 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
2649 tmp2 = inb (VIA_CONFIG_DATA);
2650 if (siofunc == VIA_FUNCTION_PROBE)
2652 siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE;
2653 ppcontrol = tmp2;
2655 else
2657 tmp &= ~VIA_FUNCTION_PARPORT_DISABLE;
2658 tmp |= siofunc;
2659 outb(via->viacfg_function, VIA_CONFIG_INDEX);
2660 outb(tmp, VIA_CONFIG_DATA);
2661 tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP);
2662 tmp2 |= ppcontrol;
2663 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
2664 outb(tmp2, VIA_CONFIG_DATA);
2667 /* Parallel Port I/O Base Address, bits 9-2 */
2668 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
2669 port1 = inb(VIA_CONFIG_DATA) << 2;
2671 printk (KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n",port1);
2672 if ((port1 == 0x3BC) && have_epp)
2674 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
2675 outb((0x378 >> 2), VIA_CONFIG_DATA);
2676 printk(KERN_DEBUG "parport_pc: Parallel port base changed to 0x378\n");
2677 port1 = 0x378;
2681 * lock super i/o configuration
2683 pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
2684 tmp &= ~via->via_pci_superio_config_data;
2685 pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
2687 if (siofunc == VIA_FUNCTION_PARPORT_DISABLE) {
2688 printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n");
2689 return 0;
2692 /* Bits 7-4: PnP Routing for Parallel Port IRQ */
2693 pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp);
2694 irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4);
2696 if (siofunc == VIA_FUNCTION_PARPORT_ECP)
2698 /* Bits 3-2: PnP Routing for Parallel Port DMA */
2699 pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp);
2700 dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2);
2702 else
2703 /* if ECP not enabled, DMA is not enabled, assumed bogus 'dma' value */
2704 dma = PARPORT_DMA_NONE;
2706 /* Let the user (or defaults) steer us away from interrupts and DMA */
2707 if (autoirq == PARPORT_IRQ_NONE) {
2708 irq = PARPORT_IRQ_NONE;
2709 dma = PARPORT_DMA_NONE;
2711 if (autodma == PARPORT_DMA_NONE)
2712 dma = PARPORT_DMA_NONE;
2714 switch (port1) {
2715 case 0x3bc: port2 = 0x7bc; break;
2716 case 0x378: port2 = 0x778; break;
2717 case 0x278: port2 = 0x678; break;
2718 default:
2719 printk(KERN_INFO "parport_pc: Weird VIA parport base 0x%X, ignoring\n",
2720 port1);
2721 return 0;
2724 /* filter bogus IRQs */
2725 switch (irq) {
2726 case 0:
2727 case 2:
2728 case 8:
2729 case 13:
2730 irq = PARPORT_IRQ_NONE;
2731 break;
2733 default: /* do nothing */
2734 break;
2737 /* finally, do the probe with values obtained */
2738 if (parport_pc_probe_port (port1, port2, irq, dma, &pdev->dev)) {
2739 printk (KERN_INFO
2740 "parport_pc: VIA parallel port: io=0x%X", port1);
2741 if (irq != PARPORT_IRQ_NONE)
2742 printk (", irq=%d", irq);
2743 if (dma != PARPORT_DMA_NONE)
2744 printk (", dma=%d", dma);
2745 printk ("\n");
2746 return 1;
2749 printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n",
2750 port1, irq, dma);
2751 return 0;
2755 enum parport_pc_sio_types {
2756 sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */
2757 sio_via_8231, /* Via VT8231 south bridge integrated Super IO */
2758 sio_ite_8872,
2759 last_sio
2762 /* each element directly indexed from enum list, above */
2763 static struct parport_pc_superio {
2764 int (*probe) (struct pci_dev *pdev, int autoirq, int autodma,
2765 const struct parport_pc_via_data *via);
2766 const struct parport_pc_via_data *via;
2767 } parport_pc_superio_info[] __devinitdata = {
2768 { sio_via_probe, &via_686a_data, },
2769 { sio_via_probe, &via_8231_data, },
2770 { sio_ite_8872_probe, NULL, },
2773 enum parport_pc_pci_cards {
2774 siig_1p_10x = last_sio,
2775 siig_2p_10x,
2776 siig_1p_20x,
2777 siig_2p_20x,
2778 lava_parallel,
2779 lava_parallel_dual_a,
2780 lava_parallel_dual_b,
2781 boca_ioppar,
2782 plx_9050,
2783 timedia_4078a,
2784 timedia_4079h,
2785 timedia_4085h,
2786 timedia_4088a,
2787 timedia_4089a,
2788 timedia_4095a,
2789 timedia_4096a,
2790 timedia_4078u,
2791 timedia_4079a,
2792 timedia_4085u,
2793 timedia_4079r,
2794 timedia_4079s,
2795 timedia_4079d,
2796 timedia_4079e,
2797 timedia_4079f,
2798 timedia_9079a,
2799 timedia_9079b,
2800 timedia_9079c,
2801 timedia_4006a,
2802 timedia_4014,
2803 timedia_4008a,
2804 timedia_4018,
2805 timedia_9018a,
2806 syba_2p_epp,
2807 syba_1p_ecp,
2808 titan_010l,
2809 titan_1284p1,
2810 titan_1284p2,
2811 avlab_1p,
2812 avlab_2p,
2813 oxsemi_952,
2814 oxsemi_954,
2815 oxsemi_840,
2816 oxsemi_pcie_pport,
2817 aks_0100,
2818 mobility_pp,
2819 netmos_9705,
2820 netmos_9715,
2821 netmos_9755,
2822 netmos_9805,
2823 netmos_9815,
2824 quatech_sppxp100,
2828 /* each element directly indexed from enum list, above
2829 * (but offset by last_sio) */
2830 static struct parport_pc_pci {
2831 int numports;
2832 struct { /* BAR (base address registers) numbers in the config
2833 space header */
2834 int lo;
2835 int hi; /* -1 if not there, >6 for offset-method (max
2836 BAR is 6) */
2837 } addr[4];
2839 /* If set, this is called immediately after pci_enable_device.
2840 * If it returns non-zero, no probing will take place and the
2841 * ports will not be used. */
2842 int (*preinit_hook) (struct pci_dev *pdev, int autoirq, int autodma);
2844 /* If set, this is called after probing for ports. If 'failed'
2845 * is non-zero we couldn't use any of the ports. */
2846 void (*postinit_hook) (struct pci_dev *pdev, int failed);
2847 } cards[] = {
2848 /* siig_1p_10x */ { 1, { { 2, 3 }, } },
2849 /* siig_2p_10x */ { 2, { { 2, 3 }, { 4, 5 }, } },
2850 /* siig_1p_20x */ { 1, { { 0, 1 }, } },
2851 /* siig_2p_20x */ { 2, { { 0, 1 }, { 2, 3 }, } },
2852 /* lava_parallel */ { 1, { { 0, -1 }, } },
2853 /* lava_parallel_dual_a */ { 1, { { 0, -1 }, } },
2854 /* lava_parallel_dual_b */ { 1, { { 0, -1 }, } },
2855 /* boca_ioppar */ { 1, { { 0, -1 }, } },
2856 /* plx_9050 */ { 2, { { 4, -1 }, { 5, -1 }, } },
2857 /* timedia_4078a */ { 1, { { 2, -1 }, } },
2858 /* timedia_4079h */ { 1, { { 2, 3 }, } },
2859 /* timedia_4085h */ { 2, { { 2, -1 }, { 4, -1 }, } },
2860 /* timedia_4088a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2861 /* timedia_4089a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2862 /* timedia_4095a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2863 /* timedia_4096a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2864 /* timedia_4078u */ { 1, { { 2, -1 }, } },
2865 /* timedia_4079a */ { 1, { { 2, 3 }, } },
2866 /* timedia_4085u */ { 2, { { 2, -1 }, { 4, -1 }, } },
2867 /* timedia_4079r */ { 1, { { 2, 3 }, } },
2868 /* timedia_4079s */ { 1, { { 2, 3 }, } },
2869 /* timedia_4079d */ { 1, { { 2, 3 }, } },
2870 /* timedia_4079e */ { 1, { { 2, 3 }, } },
2871 /* timedia_4079f */ { 1, { { 2, 3 }, } },
2872 /* timedia_9079a */ { 1, { { 2, 3 }, } },
2873 /* timedia_9079b */ { 1, { { 2, 3 }, } },
2874 /* timedia_9079c */ { 1, { { 2, 3 }, } },
2875 /* timedia_4006a */ { 1, { { 0, -1 }, } },
2876 /* timedia_4014 */ { 2, { { 0, -1 }, { 2, -1 }, } },
2877 /* timedia_4008a */ { 1, { { 0, 1 }, } },
2878 /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2879 /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } },
2880 /* SYBA uses fixed offsets in
2881 a 1K io window */
2882 /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
2883 /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } },
2884 /* titan_010l */ { 1, { { 3, -1 }, } },
2885 /* titan_1284p1 */ { 1, { { 0, 1 }, } },
2886 /* titan_1284p2 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2887 /* avlab_1p */ { 1, { { 0, 1}, } },
2888 /* avlab_2p */ { 2, { { 0, 1}, { 2, 3 },} },
2889 /* The Oxford Semi cards are unusual: 954 doesn't support ECP,
2890 * and 840 locks up if you write 1 to bit 2! */
2891 /* oxsemi_952 */ { 1, { { 0, 1 }, } },
2892 /* oxsemi_954 */ { 1, { { 0, -1 }, } },
2893 /* oxsemi_840 */ { 1, { { 0, 1 }, } },
2894 /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, } },
2895 /* aks_0100 */ { 1, { { 0, -1 }, } },
2896 /* mobility_pp */ { 1, { { 0, 1 }, } },
2897 /* netmos_9705 */ { 1, { { 0, -1 }, } }, /* untested */
2898 /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */
2899 /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */
2900 /* netmos_9805 */ { 1, { { 0, -1 }, } }, /* untested */
2901 /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */
2902 /* quatech_sppxp100 */ { 1, { { 0, 1 }, } },
2905 static const struct pci_device_id parport_pc_pci_tbl[] = {
2906 /* Super-IO onboard chips */
2907 { 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a },
2908 { 0x1106, 0x8231, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_8231 },
2909 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8872,
2910 PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_ite_8872 },
2912 /* PCI cards */
2913 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_10x,
2914 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_10x },
2915 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_10x,
2916 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_10x },
2917 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_20x,
2918 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_20x },
2919 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_20x,
2920 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_20x },
2921 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PARALLEL,
2922 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel },
2923 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_A,
2924 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_a },
2925 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_B,
2926 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_b },
2927 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR,
2928 PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar },
2929 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
2930 PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0,0, plx_9050 },
2931 /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
2932 { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a },
2933 { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h },
2934 { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h },
2935 { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a },
2936 { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a },
2937 { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a },
2938 { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a },
2939 { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u },
2940 { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a },
2941 { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u },
2942 { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r },
2943 { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s },
2944 { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d },
2945 { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e },
2946 { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f },
2947 { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a },
2948 { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b },
2949 { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c },
2950 { 0x1409, 0x7268, 0x1409, 0x0101, 0, 0, timedia_4006a },
2951 { 0x1409, 0x7268, 0x1409, 0x0102, 0, 0, timedia_4014 },
2952 { 0x1409, 0x7268, 0x1409, 0x0103, 0, 0, timedia_4008a },
2953 { 0x1409, 0x7268, 0x1409, 0x0104, 0, 0, timedia_4018 },
2954 { 0x1409, 0x7268, 0x1409, 0x9018, 0, 0, timedia_9018a },
2955 { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_2P_EPP,
2956 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_2p_epp },
2957 { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_1P_ECP,
2958 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp },
2959 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L,
2960 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l },
2961 { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 },
2962 { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 },
2963 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
2964 { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, /* AFAVLAB_TK9902 */
2965 { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p},
2966 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP,
2967 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 },
2968 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954PP,
2969 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_954 },
2970 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_12PCI840,
2971 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_840 },
2972 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe840,
2973 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2974 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe840_G,
2975 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2976 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_0,
2977 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2978 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_0_G,
2979 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2980 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1,
2981 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2982 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_G,
2983 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2984 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_U,
2985 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2986 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_GU,
2987 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2988 { PCI_VENDOR_ID_AKS, PCI_DEVICE_ID_AKS_ALADDINCARD,
2989 PCI_ANY_ID, PCI_ANY_ID, 0, 0, aks_0100 },
2990 { 0x14f2, 0x0121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, mobility_pp },
2991 /* NetMos communication controllers */
2992 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9705,
2993 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9705 },
2994 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9715,
2995 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9715 },
2996 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9755,
2997 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9755 },
2998 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9805,
2999 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 },
3000 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815,
3001 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 },
3002 /* Quatech SPPXP-100 Parallel port PCI ExpressCard */
3003 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_SPPXP_100,
3004 PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 },
3005 { 0, } /* terminate list */
3007 MODULE_DEVICE_TABLE(pci,parport_pc_pci_tbl);
3009 struct pci_parport_data {
3010 int num;
3011 struct parport *ports[2];
3014 static int parport_pc_pci_probe (struct pci_dev *dev,
3015 const struct pci_device_id *id)
3017 int err, count, n, i = id->driver_data;
3018 struct pci_parport_data *data;
3020 if (i < last_sio)
3021 /* This is an onboard Super-IO and has already been probed */
3022 return 0;
3024 /* This is a PCI card */
3025 i -= last_sio;
3026 count = 0;
3027 if ((err = pci_enable_device (dev)) != 0)
3028 return err;
3030 data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL);
3031 if (!data)
3032 return -ENOMEM;
3034 if (cards[i].preinit_hook &&
3035 cards[i].preinit_hook (dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) {
3036 kfree(data);
3037 return -ENODEV;
3040 for (n = 0; n < cards[i].numports; n++) {
3041 int lo = cards[i].addr[n].lo;
3042 int hi = cards[i].addr[n].hi;
3043 unsigned long io_lo, io_hi;
3044 io_lo = pci_resource_start (dev, lo);
3045 io_hi = 0;
3046 if ((hi >= 0) && (hi <= 6))
3047 io_hi = pci_resource_start (dev, hi);
3048 else if (hi > 6)
3049 io_lo += hi; /* Reinterpret the meaning of
3050 "hi" as an offset (see SYBA
3051 def.) */
3052 /* TODO: test if sharing interrupts works */
3053 printk (KERN_DEBUG "PCI parallel port detected: %04x:%04x, "
3054 "I/O at %#lx(%#lx)\n",
3055 parport_pc_pci_tbl[i + last_sio].vendor,
3056 parport_pc_pci_tbl[i + last_sio].device, io_lo, io_hi);
3057 data->ports[count] =
3058 parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE,
3059 PARPORT_DMA_NONE, &dev->dev);
3060 if (data->ports[count])
3061 count++;
3064 data->num = count;
3066 if (cards[i].postinit_hook)
3067 cards[i].postinit_hook (dev, count == 0);
3069 if (count) {
3070 pci_set_drvdata(dev, data);
3071 return 0;
3074 kfree(data);
3076 return -ENODEV;
3079 static void __devexit parport_pc_pci_remove(struct pci_dev *dev)
3081 struct pci_parport_data *data = pci_get_drvdata(dev);
3082 int i;
3084 pci_set_drvdata(dev, NULL);
3086 if (data) {
3087 for (i = data->num - 1; i >= 0; i--)
3088 parport_pc_unregister_port(data->ports[i]);
3090 kfree(data);
3094 static struct pci_driver parport_pc_pci_driver = {
3095 .name = "parport_pc",
3096 .id_table = parport_pc_pci_tbl,
3097 .probe = parport_pc_pci_probe,
3098 .remove = __devexit_p(parport_pc_pci_remove),
3101 static int __init parport_pc_init_superio (int autoirq, int autodma)
3103 const struct pci_device_id *id;
3104 struct pci_dev *pdev = NULL;
3105 int ret = 0;
3107 for_each_pci_dev(pdev) {
3108 id = pci_match_id(parport_pc_pci_tbl, pdev);
3109 if (id == NULL || id->driver_data >= last_sio)
3110 continue;
3112 if (parport_pc_superio_info[id->driver_data].probe
3113 (pdev, autoirq, autodma,parport_pc_superio_info[id->driver_data].via)) {
3114 ret++;
3118 return ret; /* number of devices found */
3120 #else
3121 static struct pci_driver parport_pc_pci_driver;
3122 static int __init parport_pc_init_superio(int autoirq, int autodma) {return 0;}
3123 #endif /* CONFIG_PCI */
3125 #ifdef CONFIG_PNP
3127 static const struct pnp_device_id parport_pc_pnp_tbl[] = {
3128 /* Standard LPT Printer Port */
3129 {.id = "PNP0400", .driver_data = 0},
3130 /* ECP Printer Port */
3131 {.id = "PNP0401", .driver_data = 0},
3135 MODULE_DEVICE_TABLE(pnp,parport_pc_pnp_tbl);
3137 static int parport_pc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *id)
3139 struct parport *pdata;
3140 unsigned long io_lo, io_hi;
3141 int dma, irq;
3143 if (pnp_port_valid(dev,0) &&
3144 !(pnp_port_flags(dev,0) & IORESOURCE_DISABLED)) {
3145 io_lo = pnp_port_start(dev,0);
3146 } else
3147 return -EINVAL;
3149 if (pnp_port_valid(dev,1) &&
3150 !(pnp_port_flags(dev,1) & IORESOURCE_DISABLED)) {
3151 io_hi = pnp_port_start(dev,1);
3152 } else
3153 io_hi = 0;
3155 if (pnp_irq_valid(dev,0) &&
3156 !(pnp_irq_flags(dev,0) & IORESOURCE_DISABLED)) {
3157 irq = pnp_irq(dev,0);
3158 } else
3159 irq = PARPORT_IRQ_NONE;
3161 if (pnp_dma_valid(dev,0) &&
3162 !(pnp_dma_flags(dev,0) & IORESOURCE_DISABLED)) {
3163 dma = pnp_dma(dev,0);
3164 } else
3165 dma = PARPORT_DMA_NONE;
3167 dev_info(&dev->dev, "reported by %s\n", dev->protocol->name);
3168 if (!(pdata = parport_pc_probe_port (io_lo, io_hi, irq, dma, &dev->dev)))
3169 return -ENODEV;
3171 pnp_set_drvdata(dev,pdata);
3172 return 0;
3175 static void parport_pc_pnp_remove(struct pnp_dev *dev)
3177 struct parport *pdata = (struct parport *)pnp_get_drvdata(dev);
3178 if (!pdata)
3179 return;
3181 parport_pc_unregister_port(pdata);
3184 /* we only need the pnp layer to activate the device, at least for now */
3185 static struct pnp_driver parport_pc_pnp_driver = {
3186 .name = "parport_pc",
3187 .id_table = parport_pc_pnp_tbl,
3188 .probe = parport_pc_pnp_probe,
3189 .remove = parport_pc_pnp_remove,
3192 #else
3193 static struct pnp_driver parport_pc_pnp_driver;
3194 #endif /* CONFIG_PNP */
3196 static int __devinit parport_pc_platform_probe(struct platform_device *pdev)
3198 /* Always succeed, the actual probing is done in
3199 * parport_pc_probe_port(). */
3200 return 0;
3203 static struct platform_driver parport_pc_platform_driver = {
3204 .driver = {
3205 .owner = THIS_MODULE,
3206 .name = "parport_pc",
3208 .probe = parport_pc_platform_probe,
3211 /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
3212 static int __devinit __attribute__((unused))
3213 parport_pc_find_isa_ports (int autoirq, int autodma)
3215 int count = 0;
3217 if (parport_pc_probe_port(0x3bc, 0x7bc, autoirq, autodma, NULL))
3218 count++;
3219 if (parport_pc_probe_port(0x378, 0x778, autoirq, autodma, NULL))
3220 count++;
3221 if (parport_pc_probe_port(0x278, 0x678, autoirq, autodma, NULL))
3222 count++;
3224 return count;
3227 /* This function is called by parport_pc_init if the user didn't
3228 * specify any ports to probe. Its job is to find some ports. Order
3229 * is important here -- we want ISA ports to be registered first,
3230 * followed by PCI cards (for least surprise), but before that we want
3231 * to do chipset-specific tests for some onboard ports that we know
3232 * about.
3234 * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
3235 * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
3237 static void __init parport_pc_find_ports (int autoirq, int autodma)
3239 int count = 0, err;
3241 #ifdef CONFIG_PARPORT_PC_SUPERIO
3242 detect_and_report_it87();
3243 detect_and_report_winbond();
3244 detect_and_report_smsc();
3245 #endif
3247 /* Onboard SuperIO chipsets that show themselves on the PCI bus. */
3248 count += parport_pc_init_superio(autoirq, autodma);
3250 /* PnP ports, skip detection if SuperIO already found them */
3251 if (!count) {
3252 err = pnp_register_driver(&parport_pc_pnp_driver);
3253 if (!err)
3254 pnp_registered_parport = 1;
3257 /* ISA ports and whatever (see asm/parport.h). */
3258 parport_pc_find_nonpci_ports(autoirq, autodma);
3260 err = pci_register_driver(&parport_pc_pci_driver);
3261 if (!err)
3262 pci_registered_parport = 1;
3266 * Piles of crap below pretend to be a parser for module and kernel
3267 * parameters. Say "thank you" to whoever had come up with that
3268 * syntax and keep in mind that code below is a cleaned up version.
3271 static int __initdata io[PARPORT_PC_MAX_PORTS+1] = { [0 ... PARPORT_PC_MAX_PORTS] = 0 };
3272 static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] =
3273 { [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO };
3274 static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE };
3275 static int __initdata irqval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY };
3277 static int __init parport_parse_param(const char *s, int *val,
3278 int automatic, int none, int nofifo)
3280 if (!s)
3281 return 0;
3282 if (!strncmp(s, "auto", 4))
3283 *val = automatic;
3284 else if (!strncmp(s, "none", 4))
3285 *val = none;
3286 else if (nofifo && !strncmp(s, "nofifo", 4))
3287 *val = nofifo;
3288 else {
3289 char *ep;
3290 unsigned long r = simple_strtoul(s, &ep, 0);
3291 if (ep != s)
3292 *val = r;
3293 else {
3294 printk(KERN_ERR "parport: bad specifier `%s'\n", s);
3295 return -1;
3298 return 0;
3301 static int __init parport_parse_irq(const char *irqstr, int *val)
3303 return parport_parse_param(irqstr, val, PARPORT_IRQ_AUTO,
3304 PARPORT_IRQ_NONE, 0);
3307 static int __init parport_parse_dma(const char *dmastr, int *val)
3309 return parport_parse_param(dmastr, val, PARPORT_DMA_AUTO,
3310 PARPORT_DMA_NONE, PARPORT_DMA_NOFIFO);
3313 #ifdef CONFIG_PCI
3314 static int __init parport_init_mode_setup(char *str)
3316 printk(KERN_DEBUG "parport_pc.c: Specified parameter parport_init_mode=%s\n", str);
3318 if (!strcmp (str, "spp"))
3319 parport_init_mode=1;
3320 if (!strcmp (str, "ps2"))
3321 parport_init_mode=2;
3322 if (!strcmp (str, "epp"))
3323 parport_init_mode=3;
3324 if (!strcmp (str, "ecp"))
3325 parport_init_mode=4;
3326 if (!strcmp (str, "ecpepp"))
3327 parport_init_mode=5;
3328 return 1;
3330 #endif
3332 #ifdef MODULE
3333 static const char *irq[PARPORT_PC_MAX_PORTS];
3334 static const char *dma[PARPORT_PC_MAX_PORTS];
3336 MODULE_PARM_DESC(io, "Base I/O address (SPP regs)");
3337 module_param_array(io, int, NULL, 0);
3338 MODULE_PARM_DESC(io_hi, "Base I/O address (ECR)");
3339 module_param_array(io_hi, int, NULL, 0);
3340 MODULE_PARM_DESC(irq, "IRQ line");
3341 module_param_array(irq, charp, NULL, 0);
3342 MODULE_PARM_DESC(dma, "DMA channel");
3343 module_param_array(dma, charp, NULL, 0);
3344 #if defined(CONFIG_PARPORT_PC_SUPERIO) || \
3345 (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
3346 MODULE_PARM_DESC(verbose_probing, "Log chit-chat during initialisation");
3347 module_param(verbose_probing, int, 0644);
3348 #endif
3349 #ifdef CONFIG_PCI
3350 static char *init_mode;
3351 MODULE_PARM_DESC(init_mode, "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)");
3352 module_param(init_mode, charp, 0);
3353 #endif
3355 static int __init parse_parport_params(void)
3357 unsigned int i;
3358 int val;
3360 #ifdef CONFIG_PCI
3361 if (init_mode)
3362 parport_init_mode_setup(init_mode);
3363 #endif
3365 for (i = 0; i < PARPORT_PC_MAX_PORTS && io[i]; i++) {
3366 if (parport_parse_irq(irq[i], &val))
3367 return 1;
3368 irqval[i] = val;
3369 if (parport_parse_dma(dma[i], &val))
3370 return 1;
3371 dmaval[i] = val;
3373 if (!io[0]) {
3374 /* The user can make us use any IRQs or DMAs we find. */
3375 if (irq[0] && !parport_parse_irq(irq[0], &val))
3376 switch (val) {
3377 case PARPORT_IRQ_NONE:
3378 case PARPORT_IRQ_AUTO:
3379 irqval[0] = val;
3380 break;
3381 default:
3382 printk (KERN_WARNING
3383 "parport_pc: irq specified "
3384 "without base address. Use 'io=' "
3385 "to specify one\n");
3388 if (dma[0] && !parport_parse_dma(dma[0], &val))
3389 switch (val) {
3390 case PARPORT_DMA_NONE:
3391 case PARPORT_DMA_AUTO:
3392 dmaval[0] = val;
3393 break;
3394 default:
3395 printk (KERN_WARNING
3396 "parport_pc: dma specified "
3397 "without base address. Use 'io=' "
3398 "to specify one\n");
3401 return 0;
3404 #else
3406 static int parport_setup_ptr __initdata = 0;
3409 * Acceptable parameters:
3411 * parport=0
3412 * parport=auto
3413 * parport=0xBASE[,IRQ[,DMA]]
3415 * IRQ/DMA may be numeric or 'auto' or 'none'
3417 static int __init parport_setup (char *str)
3419 char *endptr;
3420 char *sep;
3421 int val;
3423 if (!str || !*str || (*str == '0' && !*(str+1))) {
3424 /* Disable parport if "parport=0" in cmdline */
3425 io[0] = PARPORT_DISABLE;
3426 return 1;
3429 if (!strncmp (str, "auto", 4)) {
3430 irqval[0] = PARPORT_IRQ_AUTO;
3431 dmaval[0] = PARPORT_DMA_AUTO;
3432 return 1;
3435 val = simple_strtoul (str, &endptr, 0);
3436 if (endptr == str) {
3437 printk (KERN_WARNING "parport=%s not understood\n", str);
3438 return 1;
3441 if (parport_setup_ptr == PARPORT_PC_MAX_PORTS) {
3442 printk(KERN_ERR "parport=%s ignored, too many ports\n", str);
3443 return 1;
3446 io[parport_setup_ptr] = val;
3447 irqval[parport_setup_ptr] = PARPORT_IRQ_NONE;
3448 dmaval[parport_setup_ptr] = PARPORT_DMA_NONE;
3450 sep = strchr(str, ',');
3451 if (sep++) {
3452 if (parport_parse_irq(sep, &val))
3453 return 1;
3454 irqval[parport_setup_ptr] = val;
3455 sep = strchr(sep, ',');
3456 if (sep++) {
3457 if (parport_parse_dma(sep, &val))
3458 return 1;
3459 dmaval[parport_setup_ptr] = val;
3462 parport_setup_ptr++;
3463 return 1;
3466 static int __init parse_parport_params(void)
3468 return io[0] == PARPORT_DISABLE;
3471 __setup ("parport=", parport_setup);
3474 * Acceptable parameters:
3476 * parport_init_mode=[spp|ps2|epp|ecp|ecpepp]
3478 #ifdef CONFIG_PCI
3479 __setup("parport_init_mode=",parport_init_mode_setup);
3480 #endif
3481 #endif
3483 /* "Parser" ends here */
3485 static int __init parport_pc_init(void)
3487 int err;
3489 if (parse_parport_params())
3490 return -EINVAL;
3492 err = platform_driver_register(&parport_pc_platform_driver);
3493 if (err)
3494 return err;
3496 if (io[0]) {
3497 int i;
3498 /* Only probe the ports we were given. */
3499 user_specified = 1;
3500 for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) {
3501 if (!io[i])
3502 break;
3503 if ((io_hi[i]) == PARPORT_IOHI_AUTO)
3504 io_hi[i] = 0x400 + io[i];
3505 parport_pc_probe_port(io[i], io_hi[i],
3506 irqval[i], dmaval[i], NULL);
3508 } else
3509 parport_pc_find_ports (irqval[0], dmaval[0]);
3511 return 0;
3514 static void __exit parport_pc_exit(void)
3516 if (pci_registered_parport)
3517 pci_unregister_driver (&parport_pc_pci_driver);
3518 if (pnp_registered_parport)
3519 pnp_unregister_driver (&parport_pc_pnp_driver);
3520 platform_driver_unregister(&parport_pc_platform_driver);
3522 while (!list_empty(&ports_list)) {
3523 struct parport_pc_private *priv;
3524 struct parport *port;
3525 priv = list_entry(ports_list.next,
3526 struct parport_pc_private, list);
3527 port = priv->port;
3528 if (port->dev && port->dev->bus == &platform_bus_type)
3529 platform_device_unregister(
3530 to_platform_device(port->dev));
3531 parport_pc_unregister_port(port);
3535 MODULE_AUTHOR("Phil Blundell, Tim Waugh, others");
3536 MODULE_DESCRIPTION("PC-style parallel port driver");
3537 MODULE_LICENSE("GPL");
3538 module_init(parport_pc_init)
3539 module_exit(parport_pc_exit)