1 /* Low-level parallel-port routines for 8255-based PC-style hardware.
3 * Authors: Phil Blundell <Philip.Blundell@pobox.com>
4 * Tim Waugh <tim@cyberelk.demon.co.uk>
5 * Jose Renau <renau@acm.org>
6 * David Campbell <campbell@torque.net>
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
28 * In addition, there are some optional registers:
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
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/config.h>
46 #include <linux/module.h>
47 #include <linux/init.h>
48 #include <linux/sched.h>
49 #include <linux/delay.h>
50 #include <linux/errno.h>
51 #include <linux/interrupt.h>
52 #include <linux/ioport.h>
53 #include <linux/kernel.h>
54 #include <linux/slab.h>
55 #include <linux/pci.h>
56 #include <linux/pnp.h>
57 #include <linux/sysctl.h>
61 #include <asm/uaccess.h>
63 #include <linux/parport.h>
64 #include <linux/parport_pc.h>
65 #include <asm/parport.h>
67 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
78 #define ECR_MODE_MASK 0xe0
79 #define ECR_WRITE(p,v) frob_econtrol((p),0xff,(v))
84 #define DPRINTK printk
86 #define DPRINTK(stuff...)
91 static struct superio_struct { /* For Super-IO chips autodetection */
95 } superios[NR_SUPERIOS] __devinitdata = { {0,},};
97 static int user_specified;
98 #if defined(CONFIG_PARPORT_PC_SUPERIO) || \
99 (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
100 static int verbose_probing;
102 static int pci_registered_parport;
103 static int pnp_registered_parport;
105 /* frob_control, but for ECR */
106 static void frob_econtrol (struct parport *pb, unsigned char m,
109 unsigned char ectr = 0;
112 ectr = inb (ECONTROL (pb));
114 DPRINTK (KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n",
115 m, v, ectr, (ectr & ~m) ^ v);
117 outb ((ectr & ~m) ^ v, ECONTROL (pb));
120 static __inline__ void frob_set_mode (struct parport *p, int mode)
122 frob_econtrol (p, ECR_MODE_MASK, mode << 5);
125 #ifdef CONFIG_PARPORT_PC_FIFO
126 /* Safely change the mode bits in the ECR
129 -EBUSY: Could not drain FIFO in some finite amount of time,
132 static int change_mode(struct parport *p, int m)
134 const struct parport_pc_private *priv = p->physport->private_data;
138 DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n",m);
141 printk (KERN_DEBUG "change_mode: but there's no ECR!\n");
145 /* Bits <7:5> contain the mode. */
146 oecr = inb (ECONTROL (p));
147 mode = (oecr >> 5) & 0x7;
148 if (mode == m) return 0;
150 if (mode >= 2 && !(priv->ctr & 0x20)) {
151 /* This mode resets the FIFO, so we may
152 * have to wait for it to drain first. */
153 unsigned long expire = jiffies + p->physport->cad->timeout;
156 case ECR_PPF: /* Parallel Port FIFO mode */
157 case ECR_ECP: /* ECP Parallel Port mode */
158 /* Busy wait for 200us */
159 for (counter = 0; counter < 40; counter++) {
160 if (inb (ECONTROL (p)) & 0x01)
162 if (signal_pending (current)) break;
167 while (!(inb (ECONTROL (p)) & 0x01)) {
168 if (time_after_eq (jiffies, expire))
169 /* The FIFO is stuck. */
171 __set_current_state (TASK_INTERRUPTIBLE);
172 schedule_timeout ((HZ + 99) / 100);
173 if (signal_pending (current))
179 if (mode >= 2 && m >= 2) {
180 /* We have to go through mode 001 */
182 oecr |= ECR_PS2 << 5;
193 #ifdef CONFIG_PARPORT_1284
194 /* Find FIFO lossage; FIFO is reset */
195 static int get_fifo_residue (struct parport *p)
199 const struct parport_pc_private *priv = p->physport->private_data;
201 /* Adjust for the contents of the FIFO. */
202 for (residue = priv->fifo_depth; ; residue--) {
203 if (inb (ECONTROL (p)) & 0x2)
210 printk (KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name,
213 /* Reset the FIFO. */
214 frob_set_mode (p, ECR_PS2);
216 /* Now change to config mode and clean up. FIXME */
217 frob_set_mode (p, ECR_CNF);
218 cnfga = inb (CONFIGA (p));
219 printk (KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga);
221 if (!(cnfga & (1<<2))) {
222 printk (KERN_DEBUG "%s: Accounting for extra byte\n", p->name);
226 /* Don't care about partial PWords until support is added for
227 * PWord != 1 byte. */
229 /* Back to PS2 mode. */
230 frob_set_mode (p, ECR_PS2);
232 DPRINTK (KERN_DEBUG "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n", inb (ECONTROL (p)));
235 #endif /* IEEE 1284 support */
236 #endif /* FIFO support */
239 * Clear TIMEOUT BIT in EPP MODE
241 * This is also used in SPP detection.
243 static int clear_epp_timeout(struct parport *pb)
247 if (!(parport_pc_read_status(pb) & 0x01))
250 /* To clear timeout some chips require double read */
251 parport_pc_read_status(pb);
252 r = parport_pc_read_status(pb);
253 outb (r | 0x01, STATUS (pb)); /* Some reset by writing 1 */
254 outb (r & 0xfe, STATUS (pb)); /* Others by writing 0 */
255 r = parport_pc_read_status(pb);
263 * Most of these aren't static because they may be used by the
264 * parport_xxx_yyy macros. extern __inline__ versions of several
265 * of these are in parport_pc.h.
268 static irqreturn_t parport_pc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
270 parport_generic_irq(irq, (struct parport *) dev_id, regs);
271 /* FIXME! Was it really ours? */
275 void parport_pc_init_state(struct pardevice *dev, struct parport_state *s)
279 dev->port->irq != PARPORT_IRQ_NONE)
283 s->u.pc.ecr = 0x34; /* NetMos chip can cause problems 0x24;
287 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;
292 s->u.pc.ecr = inb (ECONTROL (p));
295 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));
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)
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);
327 insb (EPPDATA (port), buf, 16);
333 /* grab single byte from the warp fifo */
334 *((char *)buf) = inb (EPPDATA (port));
339 status = inb (STATUS (port));
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);
349 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
350 if (!(((long)buf | length) & 0x03)) {
351 insl (EPPDATA (port), buf, (length >> 2));
353 insb (EPPDATA (port), buf, length);
355 if (inb (STATUS (port)) & 0x01) {
356 clear_epp_timeout (port);
361 for (; got < length; got++) {
362 *((char*)buf) = inb (EPPDATA(port));
364 if (inb (STATUS (port)) & 0x01) {
366 clear_epp_timeout (port);
374 static size_t parport_pc_epp_write_data (struct parport *port, const void *buf,
375 size_t length, int flags)
379 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
380 if (!(((long)buf | length) & 0x03)) {
381 outsl (EPPDATA (port), buf, (length >> 2));
383 outsb (EPPDATA (port), buf, length);
385 if (inb (STATUS (port)) & 0x01) {
386 clear_epp_timeout (port);
391 for (; written < length; written++) {
392 outb (*((char*)buf), EPPDATA(port));
394 if (inb (STATUS(port)) & 0x01) {
395 clear_epp_timeout (port);
403 static size_t parport_pc_epp_read_addr (struct parport *port, void *buf,
404 size_t length, int flags)
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);
416 for (; got < length; got++) {
417 *((char*)buf) = inb (EPPADDR (port));
419 if (inb (STATUS (port)) & 0x01) {
420 clear_epp_timeout (port);
428 static size_t parport_pc_epp_write_addr (struct parport *port,
429 const void *buf, size_t length,
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);
442 for (; written < length; written++) {
443 outb (*((char*)buf), EPPADDR (port));
445 if (inb (STATUS (port)) & 0x01) {
446 clear_epp_timeout (port);
454 static size_t parport_pc_ecpepp_read_data (struct parport *port, void *buf,
455 size_t length, int flags)
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);
468 static size_t parport_pc_ecpepp_write_data (struct parport *port,
469 const void *buf, size_t length,
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);
483 static size_t parport_pc_ecpepp_read_addr (struct parport *port, void *buf,
484 size_t length, int flags)
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);
497 static size_t parport_pc_ecpepp_write_addr (struct parport *port,
498 const void *buf, size_t length,
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);
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)
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));
534 parport_pc_data_forward (port); /* Must be in PS2 mode */
538 unsigned char ecrval = inb (ECONTROL (port));
541 if (need_resched() && time_before (jiffies, expire))
542 /* Can't yield the port. */
545 /* Anyone else waiting for the port? */
546 if (port->waithead) {
547 printk (KERN_DEBUG "Somebody wants the port\n");
552 /* FIFO is full. Wait for interrupt. */
554 /* Clear serviceIntr */
555 ECR_WRITE (port, ecrval & ~(1<<2));
557 ret = parport_wait_event (port, HZ);
560 if (!time_before (jiffies, expire)) {
562 printk (KERN_DEBUG "FIFO write timed out\n");
565 ecrval = inb (ECONTROL (port));
566 if (!(ecrval & (1<<2))) {
567 if (need_resched() &&
568 time_before (jiffies, expire))
577 /* Can't fail now. */
578 expire = jiffies + port->cad->timeout;
581 if (signal_pending (current))
585 /* FIFO is empty. Blast it full. */
586 const int n = left < fifo_depth ? left : fifo_depth;
587 outsb (fifo, bufp, n);
591 /* Adjust the poll time. */
592 if (i < (poll_for - 2)) poll_for--;
594 } else if (i++ < poll_for) {
596 ecrval = inb (ECONTROL (port));
600 /* Half-full (call me an optimist) */
606 dump_parport_state ("leave fifo_write_block_pio", port);
607 return length - left;
610 static size_t parport_pc_fifo_write_block_dma (struct parport *port,
611 const void *buf, size_t length)
614 unsigned long dmaflag;
615 size_t left = length;
616 const struct parport_pc_private *priv = port->physport->private_data;
617 dma_addr_t dma_addr, dma_handle;
618 size_t maxlen = 0x10000; /* max 64k per DMA transfer */
619 unsigned long start = (unsigned long) buf;
620 unsigned long end = (unsigned long) buf + length - 1;
622 dump_parport_state ("enter fifo_write_block_dma", port);
623 if (end < MAX_DMA_ADDRESS) {
624 /* If it would cross a 64k boundary, cap it at the end. */
625 if ((start ^ end) & ~0xffffUL)
626 maxlen = 0x10000 - (start & 0xffff);
628 dma_addr = dma_handle = pci_map_single(priv->dev, (void *)buf, length,
631 /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */
632 maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */
633 dma_addr = priv->dma_handle;
637 port = port->physport;
639 /* We don't want to be interrupted every character. */
640 parport_pc_disable_irq (port);
641 /* set nErrIntrEn and serviceIntr */
642 frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2));
645 parport_pc_data_forward (port); /* Must be in PS2 mode */
648 unsigned long expire = jiffies + port->physport->cad->timeout;
655 if (!dma_handle) /* bounce buffer ! */
656 memcpy(priv->dma_buf, buf, count);
658 dmaflag = claim_dma_lock();
659 disable_dma(port->dma);
660 clear_dma_ff(port->dma);
661 set_dma_mode(port->dma, DMA_MODE_WRITE);
662 set_dma_addr(port->dma, dma_addr);
663 set_dma_count(port->dma, count);
666 frob_econtrol (port, 1<<3, 1<<3);
668 /* Clear serviceIntr */
669 frob_econtrol (port, 1<<2, 0);
671 enable_dma(port->dma);
672 release_dma_lock(dmaflag);
674 /* assume DMA will be successful */
677 if (dma_handle) dma_addr += count;
679 /* Wait for interrupt. */
681 ret = parport_wait_event (port, HZ);
684 if (!time_before (jiffies, expire)) {
686 printk (KERN_DEBUG "DMA write timed out\n");
689 /* Is serviceIntr set? */
690 if (!(inb (ECONTROL (port)) & (1<<2))) {
696 dmaflag = claim_dma_lock();
697 disable_dma(port->dma);
698 clear_dma_ff(port->dma);
699 count = get_dma_residue(port->dma);
700 release_dma_lock(dmaflag);
702 cond_resched(); /* Can't yield the port. */
704 /* Anyone else waiting for the port? */
705 if (port->waithead) {
706 printk (KERN_DEBUG "Somebody wants the port\n");
710 /* update for possible DMA residue ! */
713 if (dma_handle) dma_addr -= count;
716 /* Maybe got here through break, so adjust for DMA residue! */
717 dmaflag = claim_dma_lock();
718 disable_dma(port->dma);
719 clear_dma_ff(port->dma);
720 left += get_dma_residue(port->dma);
721 release_dma_lock(dmaflag);
723 /* Turn off DMA mode */
724 frob_econtrol (port, 1<<3, 0);
727 pci_unmap_single(priv->dev, dma_handle, length, PCI_DMA_TODEVICE);
729 dump_parport_state ("leave fifo_write_block_dma", port);
730 return length - left;
733 /* Parallel Port FIFO mode (ECP chipsets) */
734 size_t parport_pc_compat_write_block_pio (struct parport *port,
735 const void *buf, size_t length,
740 unsigned long expire;
741 const struct parport_pc_private *priv = port->physport->private_data;
743 /* Special case: a timeout of zero means we cannot call schedule().
744 * Also if O_NONBLOCK is set then use the default implementation. */
745 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
746 return parport_ieee1284_write_compat (port, buf,
749 /* Set up parallel port FIFO mode.*/
750 parport_pc_data_forward (port); /* Must be in PS2 mode */
751 parport_pc_frob_control (port, PARPORT_CONTROL_STROBE, 0);
752 r = change_mode (port, ECR_PPF); /* Parallel port FIFO */
753 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", port->name);
755 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
757 /* Write the data to the FIFO. */
758 if (port->dma != PARPORT_DMA_NONE)
759 written = parport_pc_fifo_write_block_dma (port, buf, length);
761 written = parport_pc_fifo_write_block_pio (port, buf, length);
764 /* For some hardware we don't want to touch the mode until
765 * the FIFO is empty, so allow 4 seconds for each position
768 expire = jiffies + (priv->fifo_depth * HZ * 4);
770 /* Wait for the FIFO to empty */
771 r = change_mode (port, ECR_PS2);
775 } while (time_before (jiffies, expire));
778 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name);
780 /* Prevent further data transfer. */
781 frob_set_mode (port, ECR_TST);
783 /* Adjust for the contents of the FIFO. */
784 for (written -= priv->fifo_depth; ; written++) {
785 if (inb (ECONTROL (port)) & 0x2) {
789 outb (0, FIFO (port));
792 /* Reset the FIFO and return to PS2 mode. */
793 frob_set_mode (port, ECR_PS2);
796 r = parport_wait_peripheral (port,
798 PARPORT_STATUS_BUSY);
801 "%s: BUSY timeout (%d) in compat_write_block_pio\n",
804 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
810 #ifdef CONFIG_PARPORT_1284
811 size_t parport_pc_ecp_write_block_pio (struct parport *port,
812 const void *buf, size_t length,
817 unsigned long expire;
818 const struct parport_pc_private *priv = port->physport->private_data;
820 /* Special case: a timeout of zero means we cannot call schedule().
821 * Also if O_NONBLOCK is set then use the default implementation. */
822 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
823 return parport_ieee1284_ecp_write_data (port, buf,
826 /* Switch to forward mode if necessary. */
827 if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
828 /* Event 47: Set nInit high. */
829 parport_frob_control (port,
831 | PARPORT_CONTROL_AUTOFD,
833 | PARPORT_CONTROL_AUTOFD);
835 /* Event 49: PError goes high. */
836 r = parport_wait_peripheral (port,
837 PARPORT_STATUS_PAPEROUT,
838 PARPORT_STATUS_PAPEROUT);
840 printk (KERN_DEBUG "%s: PError timeout (%d) "
841 "in ecp_write_block_pio\n", port->name, r);
845 /* Set up ECP parallel port mode.*/
846 parport_pc_data_forward (port); /* Must be in PS2 mode */
847 parport_pc_frob_control (port,
848 PARPORT_CONTROL_STROBE |
849 PARPORT_CONTROL_AUTOFD,
851 r = change_mode (port, ECR_ECP); /* ECP FIFO */
852 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name);
853 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
855 /* Write the data to the FIFO. */
856 if (port->dma != PARPORT_DMA_NONE)
857 written = parport_pc_fifo_write_block_dma (port, buf, length);
859 written = parport_pc_fifo_write_block_pio (port, buf, length);
862 /* For some hardware we don't want to touch the mode until
863 * the FIFO is empty, so allow 4 seconds for each position
866 expire = jiffies + (priv->fifo_depth * (HZ * 4));
868 /* Wait for the FIFO to empty */
869 r = change_mode (port, ECR_PS2);
873 } while (time_before (jiffies, expire));
876 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name);
878 /* Prevent further data transfer. */
879 frob_set_mode (port, ECR_TST);
881 /* Adjust for the contents of the FIFO. */
882 for (written -= priv->fifo_depth; ; written++) {
883 if (inb (ECONTROL (port)) & 0x2) {
887 outb (0, FIFO (port));
890 /* Reset the FIFO and return to PS2 mode. */
891 frob_set_mode (port, ECR_PS2);
893 /* Host transfer recovery. */
894 parport_pc_data_reverse (port); /* Must be in PS2 mode */
896 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
897 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0);
899 printk (KERN_DEBUG "%s: PE,1 timeout (%d) "
900 "in ecp_write_block_pio\n", port->name, r);
902 parport_frob_control (port,
903 PARPORT_CONTROL_INIT,
904 PARPORT_CONTROL_INIT);
905 r = parport_wait_peripheral (port,
906 PARPORT_STATUS_PAPEROUT,
907 PARPORT_STATUS_PAPEROUT);
909 printk (KERN_DEBUG "%s: PE,2 timeout (%d) "
910 "in ecp_write_block_pio\n", port->name, r);
913 r = parport_wait_peripheral (port,
915 PARPORT_STATUS_BUSY);
918 "%s: BUSY timeout (%d) in ecp_write_block_pio\n",
921 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
926 size_t parport_pc_ecp_read_block_pio (struct parport *port,
927 void *buf, size_t length, int flags)
929 size_t left = length;
932 const int fifo = FIFO(port);
933 const struct parport_pc_private *priv = port->physport->private_data;
934 const int fifo_depth = priv->fifo_depth;
937 port = port->physport;
938 DPRINTK (KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n");
939 dump_parport_state ("enter fcn", port);
941 /* Special case: a timeout of zero means we cannot call schedule().
942 * Also if O_NONBLOCK is set then use the default implementation. */
943 if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
944 return parport_ieee1284_ecp_read_data (port, buf,
947 if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) {
948 /* If the peripheral is allowed to send RLE compressed
949 * data, it is possible for a byte to expand to 128
950 * bytes in the FIFO. */
953 fifofull = fifo_depth;
956 /* If the caller wants less than a full FIFO's worth of data,
957 * go through software emulation. Otherwise we may have to throw
959 if (length < fifofull)
960 return parport_ieee1284_ecp_read_data (port, buf,
963 if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) {
964 /* change to reverse-idle phase (must be in forward-idle) */
966 /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */
967 parport_frob_control (port,
968 PARPORT_CONTROL_AUTOFD
969 | PARPORT_CONTROL_STROBE,
970 PARPORT_CONTROL_AUTOFD);
971 parport_pc_data_reverse (port); /* Must be in PS2 mode */
973 /* Event 39: Set nInit low to initiate bus reversal */
974 parport_frob_control (port,
975 PARPORT_CONTROL_INIT,
977 /* Event 40: Wait for nAckReverse (PError) to go low */
978 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0);
980 printk (KERN_DEBUG "%s: PE timeout Event 40 (%d) "
981 "in ecp_read_block_pio\n", port->name, r);
986 /* Set up ECP FIFO mode.*/
987 /* parport_pc_frob_control (port,
988 PARPORT_CONTROL_STROBE |
989 PARPORT_CONTROL_AUTOFD,
990 PARPORT_CONTROL_AUTOFD); */
991 r = change_mode (port, ECR_ECP); /* ECP FIFO */
992 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name);
994 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
996 /* the first byte must be collected manually */
997 dump_parport_state ("pre 43", port);
998 /* Event 43: Wait for nAck to go low */
999 r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0);
1001 /* timed out while reading -- no data */
1002 printk (KERN_DEBUG "PIO read timed out (initial byte)\n");
1006 *bufp++ = inb (DATA (port));
1008 dump_parport_state ("43-44", port);
1009 /* Event 44: nAutoFd (HostAck) goes high to acknowledge */
1010 parport_pc_frob_control (port,
1011 PARPORT_CONTROL_AUTOFD,
1013 dump_parport_state ("pre 45", port);
1014 /* Event 45: Wait for nAck to go high */
1015 /* r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, PARPORT_STATUS_ACK); */
1016 dump_parport_state ("post 45", port);
1019 /* timed out while waiting for peripheral to respond to ack */
1020 printk (KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n");
1022 /* keep hold of the byte we've got already */
1025 /* Event 46: nAutoFd (HostAck) goes low to accept more data */
1026 parport_pc_frob_control (port,
1027 PARPORT_CONTROL_AUTOFD,
1028 PARPORT_CONTROL_AUTOFD);
1031 dump_parport_state ("rev idle", port);
1032 /* Do the transfer. */
1033 while (left > fifofull) {
1035 unsigned long expire = jiffies + port->cad->timeout;
1036 unsigned char ecrval = inb (ECONTROL (port));
1038 if (need_resched() && time_before (jiffies, expire))
1039 /* Can't yield the port. */
1042 /* At this point, the FIFO may already be full. In
1043 * that case ECP is already holding back the
1044 * peripheral (assuming proper design) with a delayed
1045 * handshake. Work fast to avoid a peripheral
1048 if (ecrval & 0x01) {
1049 /* FIFO is empty. Wait for interrupt. */
1050 dump_parport_state ("FIFO empty", port);
1052 /* Anyone else waiting for the port? */
1053 if (port->waithead) {
1054 printk (KERN_DEBUG "Somebody wants the port\n");
1058 /* Clear serviceIntr */
1059 ECR_WRITE (port, ecrval & ~(1<<2));
1061 dump_parport_state ("waiting", port);
1062 ret = parport_wait_event (port, HZ);
1063 DPRINTK (KERN_DEBUG "parport_wait_event returned %d\n", ret);
1067 if (!time_before (jiffies, expire)) {
1069 dump_parport_state ("timeout", port);
1070 printk (KERN_DEBUG "PIO read timed out\n");
1073 ecrval = inb (ECONTROL (port));
1074 if (!(ecrval & (1<<2))) {
1075 if (need_resched() &&
1076 time_before (jiffies, expire)) {
1082 /* Depending on how the FIFO threshold was
1083 * set, how long interrupt service took, and
1084 * how fast the peripheral is, we might be
1085 * lucky and have a just filled FIFO. */
1089 if (ecrval & 0x02) {
1091 dump_parport_state ("FIFO full", port);
1092 insb (fifo, bufp, fifo_depth);
1098 DPRINTK (KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n");
1100 /* FIFO not filled. We will cycle this loop for a while
1101 * and either the peripheral will fill it faster,
1102 * tripping a fast empty with insb, or we empty it. */
1103 *bufp++ = inb (fifo);
1107 /* scoop up anything left in the FIFO */
1108 while (left && !(inb (ECONTROL (port) & 0x01))) {
1109 *bufp++ = inb (fifo);
1113 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
1114 dump_parport_state ("rev idle2", port);
1118 /* Go to forward idle mode to shut the peripheral up (event 47). */
1119 parport_frob_control (port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT);
1121 /* event 49: PError goes high */
1122 r = parport_wait_peripheral (port,
1123 PARPORT_STATUS_PAPEROUT,
1124 PARPORT_STATUS_PAPEROUT);
1127 "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n",
1131 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
1135 int lost = get_fifo_residue (port);
1137 /* Shouldn't happen with compliant peripherals. */
1138 printk (KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n",
1142 dump_parport_state ("fwd idle", port);
1143 return length - left;
1146 #endif /* IEEE 1284 support */
1147 #endif /* Allowed to use FIFO/DMA */
1151 * ******************************************
1152 * INITIALISATION AND MODULE STUFF BELOW HERE
1153 * ******************************************
1156 /* GCC is not inlining extern inline function later overwriten to non-inline,
1157 so we use outlined_ variants here. */
1158 struct parport_operations parport_pc_ops =
1160 .write_data = parport_pc_write_data,
1161 .read_data = parport_pc_read_data,
1163 .write_control = parport_pc_write_control,
1164 .read_control = parport_pc_read_control,
1165 .frob_control = parport_pc_frob_control,
1167 .read_status = parport_pc_read_status,
1169 .enable_irq = parport_pc_enable_irq,
1170 .disable_irq = parport_pc_disable_irq,
1172 .data_forward = parport_pc_data_forward,
1173 .data_reverse = parport_pc_data_reverse,
1175 .init_state = parport_pc_init_state,
1176 .save_state = parport_pc_save_state,
1177 .restore_state = parport_pc_restore_state,
1179 .epp_write_data = parport_ieee1284_epp_write_data,
1180 .epp_read_data = parport_ieee1284_epp_read_data,
1181 .epp_write_addr = parport_ieee1284_epp_write_addr,
1182 .epp_read_addr = parport_ieee1284_epp_read_addr,
1184 .ecp_write_data = parport_ieee1284_ecp_write_data,
1185 .ecp_read_data = parport_ieee1284_ecp_read_data,
1186 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
1188 .compat_write_data = parport_ieee1284_write_compat,
1189 .nibble_read_data = parport_ieee1284_read_nibble,
1190 .byte_read_data = parport_ieee1284_read_byte,
1192 .owner = THIS_MODULE,
1195 #ifdef CONFIG_PARPORT_PC_SUPERIO
1196 /* Super-IO chipset detection, Winbond, SMSC */
1197 static void __devinit show_parconfig_smsc37c669(int io, int key)
1199 int cr1,cr4,cra,cr23,cr26,cr27,i=0;
1200 static const char *modes[]={ "SPP and Bidirectional (PS/2)",
1221 if (verbose_probing) {
1222 printk (KERN_INFO "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, "
1223 "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n",
1224 cr1,cr4,cra,cr23,cr26,cr27);
1226 /* The documentation calls DMA and IRQ-Lines by letters, so
1227 the board maker can/will wire them
1228 appropriately/randomly... G=reserved H=IDE-irq, */
1229 printk (KERN_INFO "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, "
1230 "fifo threshold=%d\n", cr23*4,
1231 (cr27 &0x0f) ? 'A'-1+(cr27 &0x0f): '-',
1232 (cr26 &0x0f) ? 'A'-1+(cr26 &0x0f): '-', cra & 0x0f);
1233 printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n",
1234 (cr23*4 >=0x100) ?"yes":"no", (cr1 & 4) ? "yes" : "no");
1235 printk(KERN_INFO "SMSC LPT Config: Port mode=%s, EPP version =%s\n",
1236 (cr1 & 0x08 ) ? "Standard mode only (SPP)" : modes[cr4 & 0x03],
1237 (cr4 & 0x40) ? "1.7" : "1.9");
1240 /* Heuristics ! BIOS setup for this mainboard device limits
1241 the choices to standard settings, i.e. io-address and IRQ
1242 are related, however DMA can be 1 or 3, assume DMA_A=DMA1,
1243 DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */
1244 if(cr23*4 >=0x100) { /* if active */
1245 while((superios[i].io!= 0) && (i<NR_SUPERIOS))
1248 printk(KERN_INFO "Super-IO: too many chips!\n");
1253 superios[i].io = 0x3bc;
1254 superios[i].irq = 7;
1257 superios[i].io = 0x378;
1258 superios[i].irq = 7;
1261 superios[i].io = 0x278;
1262 superios[i].irq = 5;
1265 if((d==1) || (d==3))
1268 superios[i].dma= PARPORT_DMA_NONE;
1274 static void __devinit show_parconfig_winbond(int io, int key)
1276 int cr30,cr60,cr61,cr70,cr74,crf0,i=0;
1277 static const char *modes[] = {
1278 "Standard (SPP) and Bidirectional(PS/2)", /* 0 */
1283 "EPP-1.7 and SPP", /* 5 */
1285 "ECP and EPP-1.7" };
1286 static char *irqtypes[] = { "pulsed low, high-Z", "follows nACK" };
1288 /* The registers are called compatible-PnP because the
1289 register layout is modelled after ISA-PnP, the access
1290 method is just another ... */
1293 outb(0x07,io); /* Register 7: Select Logical Device */
1294 outb(0x01,io+1); /* LD1 is Parallel Port */
1309 if (verbose_probing) {
1310 printk(KERN_INFO "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x "
1311 "70=%02x 74=%02x, f0=%02x\n", cr30,cr60,cr61,cr70,cr74,crf0);
1312 printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ",
1313 (cr30 & 0x01) ? "yes":"no", cr60,cr61,cr70&0x0f );
1314 if ((cr74 & 0x07) > 3)
1315 printk("dma=none\n");
1317 printk("dma=%d\n",cr74 & 0x07);
1318 printk(KERN_INFO "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n",
1319 irqtypes[crf0>>7], (crf0>>3)&0x0f);
1320 printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n", modes[crf0 & 0x07]);
1323 if(cr30 & 0x01) { /* the settings can be interrogated later ... */
1324 while((superios[i].io!= 0) && (i<NR_SUPERIOS))
1327 printk(KERN_INFO "Super-IO: too many chips!\n");
1329 superios[i].io = (cr60<<8)|cr61;
1330 superios[i].irq = cr70&0x0f;
1331 superios[i].dma = (((cr74 & 0x07) > 3) ?
1332 PARPORT_DMA_NONE : (cr74 & 0x07));
1337 static void __devinit decode_winbond(int efer, int key, int devid, int devrev, int oldid)
1339 const char *type = "unknown";
1342 if (devid == devrev)
1343 /* simple heuristics, we happened to read some
1344 non-winbond register */
1347 id=(devid<<8) | devrev;
1349 /* Values are from public data sheets pdf files, I can just
1350 confirm 83977TF is correct :-) */
1351 if (id == 0x9771) type="83977F/AF";
1352 else if (id == 0x9773) type="83977TF / SMSC 97w33x/97w34x";
1353 else if (id == 0x9774) type="83977ATF";
1354 else if ((id & ~0x0f) == 0x5270) type="83977CTF / SMSC 97w36x";
1355 else if ((id & ~0x0f) == 0x52f0) type="83977EF / SMSC 97w35x";
1356 else if ((id & ~0x0f) == 0x5210) type="83627";
1357 else if ((id & ~0x0f) == 0x6010) type="83697HF";
1358 else if ((oldid &0x0f ) == 0x0a) { type="83877F"; progif=1;}
1359 else if ((oldid &0x0f ) == 0x0b) { type="83877AF"; progif=1;}
1360 else if ((oldid &0x0f ) == 0x0c) { type="83877TF"; progif=1;}
1361 else if ((oldid &0x0f ) == 0x0d) { type="83877ATF"; progif=1;}
1364 if (verbose_probing)
1365 printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x "
1366 "devid=%02x devrev=%02x oldid=%02x type=%s\n",
1367 efer, key, devid, devrev, oldid, type);
1370 show_parconfig_winbond(efer,key);
1373 static void __devinit decode_smsc(int efer, int key, int devid, int devrev)
1375 const char *type = "unknown";
1376 void (*func)(int io, int key);
1379 if (devid == devrev)
1380 /* simple heuristics, we happened to read some
1381 non-smsc register */
1385 id=(devid<<8) | devrev;
1387 if (id==0x0302) {type="37c669"; func=show_parconfig_smsc37c669;}
1388 else if (id==0x6582) type="37c665IR";
1389 else if (devid==0x65) type="37c665GT";
1390 else if (devid==0x66) type="37c666GT";
1392 if (verbose_probing)
1393 printk(KERN_INFO "SMSC chip at EFER=0x%x "
1394 "key=0x%02x devid=%02x devrev=%02x type=%s\n",
1395 efer, key, devid, devrev, type);
1402 static void __devinit winbond_check(int io, int key)
1404 int devid,devrev,oldid,x_devid,x_devrev,x_oldid;
1406 if (!request_region(io, 3, __FUNCTION__))
1409 /* First probe without key */
1418 outb(key,io); /* Write Magic Sequence to EFER, extended
1419 funtion enable register */
1420 outb(0x20,io); /* Write EFIR, extended function index register */
1421 devid=inb(io+1); /* Read EFDR, extended function data register */
1426 outb(0xaa,io); /* Magic Seal */
1428 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1429 goto out; /* protection against false positives */
1431 decode_winbond(io,key,devid,devrev,oldid);
1433 release_region(io, 3);
1436 static void __devinit winbond_check2(int io,int key)
1438 int devid,devrev,oldid,x_devid,x_devrev,x_oldid;
1440 if (!request_region(io, 3, __FUNCTION__))
1443 /* First probe without the key */
1451 outb(key,io); /* Write Magic Byte to EFER, extended
1452 funtion enable register */
1453 outb(0x20,io+2); /* Write EFIR, extended function index register */
1454 devid=inb(io+2); /* Read EFDR, extended function data register */
1459 outb(0xaa,io); /* Magic Seal */
1461 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1462 goto out; /* protection against false positives */
1464 decode_winbond(io,key,devid,devrev,oldid);
1466 release_region(io, 3);
1469 static void __devinit smsc_check(int io, int key)
1471 int id,rev,oldid,oldrev,x_id,x_rev,x_oldid,x_oldrev;
1473 if (!request_region(io, 3, __FUNCTION__))
1476 /* First probe without the key */
1487 outb(key,io); /* Write Magic Sequence to EFER, extended
1488 funtion enable register */
1489 outb(0x0d,io); /* Write EFIR, extended function index register */
1490 oldid=inb(io+1); /* Read EFDR, extended function data register */
1497 outb(0xaa,io); /* Magic Seal */
1499 if ((x_id == id) && (x_oldrev == oldrev) &&
1500 (x_oldid == oldid) && (x_rev == rev))
1501 goto out; /* protection against false positives */
1503 decode_smsc(io,key,oldid,oldrev);
1505 release_region(io, 3);
1509 static void __devinit detect_and_report_winbond (void)
1511 if (verbose_probing)
1512 printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n");
1513 winbond_check(0x3f0,0x87);
1514 winbond_check(0x370,0x87);
1515 winbond_check(0x2e ,0x87);
1516 winbond_check(0x4e ,0x87);
1517 winbond_check(0x3f0,0x86);
1518 winbond_check2(0x250,0x88);
1519 winbond_check2(0x250,0x89);
1522 static void __devinit detect_and_report_smsc (void)
1524 if (verbose_probing)
1525 printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n");
1526 smsc_check(0x3f0,0x55);
1527 smsc_check(0x370,0x55);
1528 smsc_check(0x3f0,0x44);
1529 smsc_check(0x370,0x44);
1531 #endif /* CONFIG_PARPORT_PC_SUPERIO */
1533 static int __devinit get_superio_dma (struct parport *p)
1536 while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
1539 return superios[i].dma;
1540 return PARPORT_DMA_NONE;
1543 static int __devinit get_superio_irq (struct parport *p)
1546 while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
1549 return superios[i].irq;
1550 return PARPORT_IRQ_NONE;
1554 /* --- Mode detection ------------------------------------- */
1557 * Checks for port existence, all ports support SPP MODE
1559 * 0 : No parallel port at this address
1560 * PARPORT_MODE_PCSPP : SPP port detected
1561 * (if the user specified an ioport himself,
1562 * this shall always be the case!)
1565 static int __devinit parport_SPP_supported(struct parport *pb)
1570 * first clear an eventually pending EPP timeout
1571 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
1572 * that does not even respond to SPP cycles if an EPP
1573 * timeout is pending
1575 clear_epp_timeout(pb);
1577 /* Do a simple read-write test to make sure the port exists. */
1579 outb (w, CONTROL (pb));
1581 /* Is there a control register that we can read from? Some
1582 * ports don't allow reads, so read_control just returns a
1583 * software copy. Some ports _do_ allow reads, so bypass the
1584 * software copy here. In addition, some bits aren't
1586 r = inb (CONTROL (pb));
1587 if ((r & 0xf) == w) {
1589 outb (w, CONTROL (pb));
1590 r = inb (CONTROL (pb));
1591 outb (0xc, CONTROL (pb));
1593 return PARPORT_MODE_PCSPP;
1597 /* That didn't work, but the user thinks there's a
1599 printk (KERN_INFO "parport 0x%lx (WARNING): CTR: "
1600 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1602 /* Try the data register. The data lines aren't tri-stated at
1603 * this stage, so we expect back what we wrote. */
1605 parport_pc_write_data (pb, w);
1606 r = parport_pc_read_data (pb);
1609 parport_pc_write_data (pb, w);
1610 r = parport_pc_read_data (pb);
1612 return PARPORT_MODE_PCSPP;
1615 if (user_specified) {
1616 /* Didn't work, but the user is convinced this is the
1618 printk (KERN_INFO "parport 0x%lx (WARNING): DATA: "
1619 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1620 printk (KERN_INFO "parport 0x%lx: You gave this address, "
1621 "but there is probably no parallel port there!\n",
1625 /* It's possible that we can't read the control register or
1626 * the data register. In that case just believe the user. */
1628 return PARPORT_MODE_PCSPP;
1635 * Old style XT ports alias io ports every 0x400, hence accessing ECR
1636 * on these cards actually accesses the CTR.
1638 * Modern cards don't do this but reading from ECR will return 0xff
1639 * regardless of what is written here if the card does NOT support
1642 * We first check to see if ECR is the same as CTR. If not, the low
1643 * two bits of ECR aren't writable, so we check by writing ECR and
1644 * reading it back to see if it's what we expect.
1646 static int __devinit parport_ECR_present(struct parport *pb)
1648 struct parport_pc_private *priv = pb->private_data;
1649 unsigned char r = 0xc;
1651 outb (r, CONTROL (pb));
1652 if ((inb (ECONTROL (pb)) & 0x3) == (r & 0x3)) {
1653 outb (r ^ 0x2, CONTROL (pb)); /* Toggle bit 1 */
1655 r = inb (CONTROL (pb));
1656 if ((inb (ECONTROL (pb)) & 0x2) == (r & 0x2))
1657 goto no_reg; /* Sure that no ECR register exists */
1660 if ((inb (ECONTROL (pb)) & 0x3 ) != 0x1)
1663 ECR_WRITE (pb, 0x34);
1664 if (inb (ECONTROL (pb)) != 0x35)
1668 outb (0xc, CONTROL (pb));
1670 /* Go to mode 000 */
1671 frob_set_mode (pb, ECR_SPP);
1676 outb (0xc, CONTROL (pb));
1680 #ifdef CONFIG_PARPORT_1284
1681 /* Detect PS/2 support.
1683 * Bit 5 (0x20) sets the PS/2 data direction; setting this high
1684 * allows us to read data from the data lines. In theory we would get back
1685 * 0xff but any peripheral attached to the port may drag some or all of the
1686 * lines down to zero. So if we get back anything that isn't the contents
1687 * of the data register we deem PS/2 support to be present.
1689 * Some SPP ports have "half PS/2" ability - you can't turn off the line
1690 * drivers, but an external peripheral with sufficiently beefy drivers of
1691 * its own can overpower them and assert its own levels onto the bus, from
1692 * where they can then be read back as normal. Ports with this property
1693 * and the right type of device attached are likely to fail the SPP test,
1694 * (as they will appear to have stuck bits) and so the fact that they might
1695 * be misdetected here is rather academic.
1698 static int __devinit parport_PS2_supported(struct parport *pb)
1702 clear_epp_timeout(pb);
1704 /* try to tri-state the buffer */
1705 parport_pc_data_reverse (pb);
1707 parport_pc_write_data(pb, 0x55);
1708 if (parport_pc_read_data(pb) != 0x55) ok++;
1710 parport_pc_write_data(pb, 0xaa);
1711 if (parport_pc_read_data(pb) != 0xaa) ok++;
1713 /* cancel input mode */
1714 parport_pc_data_forward (pb);
1717 pb->modes |= PARPORT_MODE_TRISTATE;
1719 struct parport_pc_private *priv = pb->private_data;
1720 priv->ctr_writable &= ~0x20;
1726 #ifdef CONFIG_PARPORT_PC_FIFO
1727 static int __devinit parport_ECP_supported(struct parport *pb)
1730 int config, configb;
1732 struct parport_pc_private *priv = pb->private_data;
1733 /* Translate ECP intrLine to ISA irq value */
1734 static const int intrline[]= { 0, 7, 9, 10, 11, 14, 15, 5 };
1736 /* If there is no ECR, we have no hope of supporting ECP. */
1740 /* Find out FIFO depth */
1741 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */
1742 ECR_WRITE (pb, ECR_TST << 5); /* TEST FIFO */
1743 for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02); i++)
1744 outb (0xaa, FIFO (pb));
1747 * Using LGS chipset it uses ECR register, but
1748 * it doesn't support ECP or FIFO MODE
1751 ECR_WRITE (pb, ECR_SPP << 5);
1755 priv->fifo_depth = i;
1756 if (verbose_probing)
1757 printk (KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i);
1759 /* Find out writeIntrThreshold */
1760 frob_econtrol (pb, 1<<2, 1<<2);
1761 frob_econtrol (pb, 1<<2, 0);
1762 for (i = 1; i <= priv->fifo_depth; i++) {
1765 if (inb (ECONTROL (pb)) & (1<<2))
1769 if (i <= priv->fifo_depth) {
1770 if (verbose_probing)
1771 printk (KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n",
1774 /* Number of bytes we know we can write if we get an
1778 priv->writeIntrThreshold = i;
1780 /* Find out readIntrThreshold */
1781 frob_set_mode (pb, ECR_PS2); /* Reset FIFO and enable PS2 */
1782 parport_pc_data_reverse (pb); /* Must be in PS2 mode */
1783 frob_set_mode (pb, ECR_TST); /* Test FIFO */
1784 frob_econtrol (pb, 1<<2, 1<<2);
1785 frob_econtrol (pb, 1<<2, 0);
1786 for (i = 1; i <= priv->fifo_depth; i++) {
1787 outb (0xaa, FIFO (pb));
1788 if (inb (ECONTROL (pb)) & (1<<2))
1792 if (i <= priv->fifo_depth) {
1793 if (verbose_probing)
1794 printk (KERN_INFO "0x%lx: readIntrThreshold is %d\n",
1797 /* Number of bytes we can read if we get an interrupt. */
1800 priv->readIntrThreshold = i;
1802 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */
1803 ECR_WRITE (pb, 0xf4); /* Configuration mode */
1804 config = inb (CONFIGA (pb));
1805 pword = (config >> 4) & 0x7;
1809 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n",
1814 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n",
1818 printk (KERN_WARNING "0x%lx: Unknown implementation ID\n",
1824 priv->pword = pword;
1826 if (verbose_probing) {
1827 printk (KERN_DEBUG "0x%lx: PWord is %d bits\n", pb->base, 8 * pword);
1829 printk (KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base,
1830 config & 0x80 ? "Level" : "Pulses");
1832 configb = inb (CONFIGB (pb));
1833 printk (KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n",
1834 pb->base, config, configb);
1835 printk (KERN_DEBUG "0x%lx: ECP settings irq=", pb->base);
1836 if ((configb >>3) & 0x07)
1837 printk("%d",intrline[(configb >>3) & 0x07]);
1839 printk("<none or set by other means>");
1841 if( (configb & 0x03 ) == 0x00)
1842 printk("<none or set by other means>\n");
1844 printk("%d\n",configb & 0x07);
1847 /* Go back to mode 000 */
1848 frob_set_mode (pb, ECR_SPP);
1854 static int __devinit parport_ECPPS2_supported(struct parport *pb)
1856 const struct parport_pc_private *priv = pb->private_data;
1863 oecr = inb (ECONTROL (pb));
1864 ECR_WRITE (pb, ECR_PS2 << 5);
1865 result = parport_PS2_supported(pb);
1866 ECR_WRITE (pb, oecr);
1870 /* EPP mode detection */
1872 static int __devinit parport_EPP_supported(struct parport *pb)
1874 const struct parport_pc_private *priv = pb->private_data;
1878 * Bit 0 of STR is the EPP timeout bit, this bit is 0
1879 * when EPP is possible and is set high when an EPP timeout
1880 * occurs (EPP uses the HALT line to stop the CPU while it does
1881 * the byte transfer, an EPP timeout occurs if the attached
1882 * device fails to respond after 10 micro seconds).
1884 * This bit is cleared by either reading it (National Semi)
1885 * or writing a 1 to the bit (SMC, UMC, WinBond), others ???
1886 * This bit is always high in non EPP modes.
1889 /* If EPP timeout bit clear then EPP available */
1890 if (!clear_epp_timeout(pb)) {
1891 return 0; /* No way to clear timeout */
1894 /* Check for Intel bug. */
1897 for (i = 0x00; i < 0x80; i += 0x20) {
1899 if (clear_epp_timeout (pb)) {
1900 /* Phony EPP in ECP. */
1906 pb->modes |= PARPORT_MODE_EPP;
1908 /* Set up access functions to use EPP hardware. */
1909 pb->ops->epp_read_data = parport_pc_epp_read_data;
1910 pb->ops->epp_write_data = parport_pc_epp_write_data;
1911 pb->ops->epp_read_addr = parport_pc_epp_read_addr;
1912 pb->ops->epp_write_addr = parport_pc_epp_write_addr;
1917 static int __devinit parport_ECPEPP_supported(struct parport *pb)
1919 struct parport_pc_private *priv = pb->private_data;
1927 oecr = inb (ECONTROL (pb));
1928 /* Search for SMC style EPP+ECP mode */
1929 ECR_WRITE (pb, 0x80);
1930 outb (0x04, CONTROL (pb));
1931 result = parport_EPP_supported(pb);
1933 ECR_WRITE (pb, oecr);
1936 /* Set up access functions to use ECP+EPP hardware. */
1937 pb->ops->epp_read_data = parport_pc_ecpepp_read_data;
1938 pb->ops->epp_write_data = parport_pc_ecpepp_write_data;
1939 pb->ops->epp_read_addr = parport_pc_ecpepp_read_addr;
1940 pb->ops->epp_write_addr = parport_pc_ecpepp_write_addr;
1946 #else /* No IEEE 1284 support */
1948 /* Don't bother probing for modes we know we won't use. */
1949 static int __devinit parport_PS2_supported(struct parport *pb) { return 0; }
1950 #ifdef CONFIG_PARPORT_PC_FIFO
1951 static int __devinit parport_ECP_supported(struct parport *pb) { return 0; }
1953 static int __devinit parport_EPP_supported(struct parport *pb) { return 0; }
1954 static int __devinit parport_ECPEPP_supported(struct parport *pb){return 0;}
1955 static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;}
1957 #endif /* No IEEE 1284 support */
1959 /* --- IRQ detection -------------------------------------- */
1961 /* Only if supports ECP mode */
1962 static int __devinit programmable_irq_support(struct parport *pb)
1965 unsigned char oecr = inb (ECONTROL (pb));
1966 static const int lookup[8] = {
1967 PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5
1970 ECR_WRITE (pb, ECR_CNF << 5); /* Configuration MODE */
1972 intrLine = (inb (CONFIGB (pb)) >> 3) & 0x07;
1973 irq = lookup[intrLine];
1975 ECR_WRITE (pb, oecr);
1979 static int __devinit irq_probe_ECP(struct parport *pb)
1984 irqs = probe_irq_on();
1986 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */
1987 ECR_WRITE (pb, (ECR_TST << 5) | 0x04);
1988 ECR_WRITE (pb, ECR_TST << 5);
1990 /* If Full FIFO sure that writeIntrThreshold is generated */
1991 for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02) ; i++)
1992 outb (0xaa, FIFO (pb));
1994 pb->irq = probe_irq_off(irqs);
1995 ECR_WRITE (pb, ECR_SPP << 5);
1998 pb->irq = PARPORT_IRQ_NONE;
2004 * This detection seems that only works in National Semiconductors
2005 * This doesn't work in SMC, LGS, and Winbond
2007 static int __devinit irq_probe_EPP(struct parport *pb)
2009 #ifndef ADVANCED_DETECT
2010 return PARPORT_IRQ_NONE;
2015 if (pb->modes & PARPORT_MODE_PCECR)
2016 oecr = inb (ECONTROL (pb));
2018 irqs = probe_irq_on();
2020 if (pb->modes & PARPORT_MODE_PCECR)
2021 frob_econtrol (pb, 0x10, 0x10);
2023 clear_epp_timeout(pb);
2024 parport_pc_frob_control (pb, 0x20, 0x20);
2025 parport_pc_frob_control (pb, 0x10, 0x10);
2026 clear_epp_timeout(pb);
2028 /* Device isn't expecting an EPP read
2029 * and generates an IRQ.
2031 parport_pc_read_epp(pb);
2034 pb->irq = probe_irq_off (irqs);
2035 if (pb->modes & PARPORT_MODE_PCECR)
2036 ECR_WRITE (pb, oecr);
2037 parport_pc_write_control(pb, 0xc);
2040 pb->irq = PARPORT_IRQ_NONE;
2043 #endif /* Advanced detection */
2046 static int __devinit irq_probe_SPP(struct parport *pb)
2048 /* Don't even try to do this. */
2049 return PARPORT_IRQ_NONE;
2052 /* We will attempt to share interrupt requests since other devices
2053 * such as sound cards and network cards seem to like using the
2056 * When ECP is available we can autoprobe for IRQs.
2057 * NOTE: If we can autoprobe it, we can register the IRQ.
2059 static int __devinit parport_irq_probe(struct parport *pb)
2061 struct parport_pc_private *priv = pb->private_data;
2064 pb->irq = programmable_irq_support(pb);
2066 if (pb->irq == PARPORT_IRQ_NONE)
2067 pb->irq = irq_probe_ECP(pb);
2070 if ((pb->irq == PARPORT_IRQ_NONE) && priv->ecr &&
2071 (pb->modes & PARPORT_MODE_EPP))
2072 pb->irq = irq_probe_EPP(pb);
2074 clear_epp_timeout(pb);
2076 if (pb->irq == PARPORT_IRQ_NONE && (pb->modes & PARPORT_MODE_EPP))
2077 pb->irq = irq_probe_EPP(pb);
2079 clear_epp_timeout(pb);
2081 if (pb->irq == PARPORT_IRQ_NONE)
2082 pb->irq = irq_probe_SPP(pb);
2084 if (pb->irq == PARPORT_IRQ_NONE)
2085 pb->irq = get_superio_irq(pb);
2090 /* --- DMA detection -------------------------------------- */
2092 /* Only if chipset conforms to ECP ISA Interface Standard */
2093 static int __devinit programmable_dma_support (struct parport *p)
2095 unsigned char oecr = inb (ECONTROL (p));
2098 frob_set_mode (p, ECR_CNF);
2100 dma = inb (CONFIGB(p)) & 0x07;
2101 /* 000: Indicates jumpered 8-bit DMA if read-only.
2102 100: Indicates jumpered 16-bit DMA if read-only. */
2103 if ((dma & 0x03) == 0)
2104 dma = PARPORT_DMA_NONE;
2106 ECR_WRITE (p, oecr);
2110 static int __devinit parport_dma_probe (struct parport *p)
2112 const struct parport_pc_private *priv = p->private_data;
2114 p->dma = programmable_dma_support(p); /* ask ECP chipset first */
2115 if (p->dma == PARPORT_DMA_NONE) {
2116 /* ask known Super-IO chips proper, although these
2117 claim ECP compatible, some don't report their DMA
2118 conforming to ECP standards */
2119 p->dma = get_superio_dma(p);
2125 /* --- Initialisation code -------------------------------- */
2127 static LIST_HEAD(ports_list);
2128 static spinlock_t ports_lock = SPIN_LOCK_UNLOCKED;
2130 struct parport *parport_pc_probe_port (unsigned long int base,
2131 unsigned long int base_hi,
2133 struct pci_dev *dev)
2135 struct parport_pc_private *priv;
2136 struct parport_operations *ops;
2138 int probedirq = PARPORT_IRQ_NONE;
2139 struct resource *base_res;
2140 struct resource *ECR_res = NULL;
2141 struct resource *EPP_res = NULL;
2143 ops = kmalloc(sizeof (struct parport_operations), GFP_KERNEL);
2147 priv = kmalloc (sizeof (struct parport_pc_private), GFP_KERNEL);
2151 /* a misnomer, actually - it's allocate and reserve parport number */
2152 p = parport_register_port(base, irq, dma, ops);
2156 base_res = request_region(base, 3, p->name);
2160 memcpy(ops, &parport_pc_ops, sizeof (struct parport_operations));
2162 priv->ctr_writable = ~0x10;
2164 priv->fifo_depth = 0;
2165 priv->dma_buf = NULL;
2166 priv->dma_handle = 0;
2168 INIT_LIST_HEAD(&priv->list);
2170 p->base_hi = base_hi;
2171 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
2172 p->private_data = priv;
2175 ECR_res = request_region(base_hi, 3, p->name);
2177 parport_ECR_present(p);
2180 if (base != 0x3bc) {
2181 EPP_res = request_region(base+0x3, 5, p->name);
2183 if (!parport_EPP_supported(p))
2184 parport_ECPEPP_supported(p);
2186 if (!parport_SPP_supported (p))
2190 parport_ECPPS2_supported(p);
2192 parport_PS2_supported(p);
2194 p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
2196 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
2197 if (p->base_hi && priv->ecr)
2198 printk(" (0x%lx)", p->base_hi);
2199 if (p->irq == PARPORT_IRQ_AUTO) {
2200 p->irq = PARPORT_IRQ_NONE;
2201 parport_irq_probe(p);
2202 } else if (p->irq == PARPORT_IRQ_PROBEONLY) {
2203 p->irq = PARPORT_IRQ_NONE;
2204 parport_irq_probe(p);
2206 p->irq = PARPORT_IRQ_NONE;
2208 if (p->irq != PARPORT_IRQ_NONE) {
2209 printk(", irq %d", p->irq);
2210 priv->ctr_writable |= 0x10;
2212 if (p->dma == PARPORT_DMA_AUTO) {
2213 p->dma = PARPORT_DMA_NONE;
2214 parport_dma_probe(p);
2217 if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
2218 is mandatory (see above) */
2219 p->dma = PARPORT_DMA_NONE;
2221 #ifdef CONFIG_PARPORT_PC_FIFO
2222 if (parport_ECP_supported(p) &&
2223 p->dma != PARPORT_DMA_NOFIFO &&
2224 priv->fifo_depth > 0 && p->irq != PARPORT_IRQ_NONE) {
2225 p->modes |= PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
2226 p->ops->compat_write_data = parport_pc_compat_write_block_pio;
2227 #ifdef CONFIG_PARPORT_1284
2228 p->ops->ecp_write_data = parport_pc_ecp_write_block_pio;
2229 /* currently broken, but working on it.. (FB) */
2230 /* p->ops->ecp_read_data = parport_pc_ecp_read_block_pio; */
2231 #endif /* IEEE 1284 support */
2232 if (p->dma != PARPORT_DMA_NONE) {
2233 printk(", dma %d", p->dma);
2234 p->modes |= PARPORT_MODE_DMA;
2236 else printk(", using FIFO");
2239 /* We can't use the DMA channel after all. */
2240 p->dma = PARPORT_DMA_NONE;
2241 #endif /* Allowed to use FIFO/DMA */
2244 #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
2248 printmode(TRISTATE);
2255 #ifndef CONFIG_PARPORT_1284
2257 #endif /* CONFIG_PARPORT_1284 */
2259 if (probedirq != PARPORT_IRQ_NONE)
2260 printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq);
2262 /* If No ECP release the ports grabbed above. */
2263 if (ECR_res && (p->modes & PARPORT_MODE_ECP) == 0) {
2264 release_region(base_hi, 3);
2267 /* Likewise for EEP ports */
2268 if (EPP_res && (p->modes & PARPORT_MODE_EPP) == 0) {
2269 release_region(base+3, 5);
2272 if (p->irq != PARPORT_IRQ_NONE) {
2273 if (request_irq (p->irq, parport_pc_interrupt,
2275 printk (KERN_WARNING "%s: irq %d in use, "
2276 "resorting to polled operation\n",
2278 p->irq = PARPORT_IRQ_NONE;
2279 p->dma = PARPORT_DMA_NONE;
2282 #ifdef CONFIG_PARPORT_PC_FIFO
2283 if (p->dma != PARPORT_DMA_NONE) {
2284 if (request_dma (p->dma, p->name)) {
2285 printk (KERN_WARNING "%s: dma %d in use, "
2286 "resorting to PIO operation\n",
2288 p->dma = PARPORT_DMA_NONE;
2291 pci_alloc_consistent(priv->dev,
2294 if (! priv->dma_buf) {
2295 printk (KERN_WARNING "%s: "
2296 "cannot get buffer for DMA, "
2297 "resorting to PIO operation\n",
2300 p->dma = PARPORT_DMA_NONE;
2304 #endif /* CONFIG_PARPORT_PC_FIFO */
2307 /* Done probing. Now put the port into a sensible start-up state. */
2310 * Put the ECP detected port in PS2 mode.
2311 * Do this also for ports that have ECR but don't do ECP.
2313 ECR_WRITE (p, 0x34);
2315 parport_pc_write_data(p, 0);
2316 parport_pc_data_forward (p);
2318 /* Now that we've told the sharing engine about the port, and
2319 found out its characteristics, let the high-level drivers
2321 spin_lock(&ports_lock);
2322 list_add(&priv->list, &ports_list);
2323 spin_unlock(&ports_lock);
2324 parport_announce_port (p);
2330 release_region(base_hi, 3);
2332 release_region(base+0x3, 5);
2333 release_region(base, 3);
2335 parport_put_port(p);
2344 EXPORT_SYMBOL (parport_pc_probe_port);
2346 void parport_pc_unregister_port (struct parport *p)
2348 struct parport_pc_private *priv = p->private_data;
2349 struct parport_operations *ops = p->ops;
2351 parport_remove_port(p);
2352 spin_lock(&ports_lock);
2353 list_del_init(&priv->list);
2354 spin_unlock(&ports_lock);
2355 if (p->dma != PARPORT_DMA_NONE)
2357 if (p->irq != PARPORT_IRQ_NONE)
2358 free_irq(p->irq, p);
2359 release_region(p->base, 3);
2361 release_region(p->base + 3, p->size - 3);
2362 if (p->modes & PARPORT_MODE_ECP)
2363 release_region(p->base_hi, 3);
2364 #ifdef CONFIG_PARPORT_PC_FIFO
2366 pci_free_consistent(priv->dev, PAGE_SIZE,
2369 #endif /* CONFIG_PARPORT_PC_FIFO */
2370 kfree (p->private_data);
2371 parport_put_port(p);
2372 kfree (ops); /* hope no-one cached it */
2375 EXPORT_SYMBOL (parport_pc_unregister_port);
2379 /* ITE support maintained by Rich Liu <richliu@poorman.org> */
2380 static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq,
2383 short inta_addr[6] = { 0x2A0, 0x2C0, 0x220, 0x240, 0x1E0 };
2384 struct resource *base_res;
2386 u32 ite8872_lpt, ite8872_lpthi;
2387 u8 ite8872_irq, type;
2388 char *fake_name = "parport probe";
2392 DPRINTK (KERN_DEBUG "sio_ite_8872_probe()\n");
2394 // make sure which one chip
2395 for(i = 0; i < 5; i++) {
2396 base_res = request_region(inta_addr[i], 0x8, fake_name);
2399 pci_write_config_dword (pdev, 0x60,
2400 0xe7000000 | inta_addr[i]);
2401 pci_write_config_dword (pdev, 0x78,
2402 0x00000000 | inta_addr[i]);
2403 test = inb (inta_addr[i]);
2404 if (test != 0xff) break;
2405 release_region(inta_addr[i], 0x8);
2409 printk (KERN_INFO "parport_pc: cannot find ITE8872 INTA\n");
2413 type = inb (inta_addr[i] + 0x18);
2418 printk (KERN_INFO "parport_pc: ITE8871 found (1P)\n");
2419 ite8872set = 0x64200000;
2422 printk (KERN_INFO "parport_pc: ITE8875 found (1P)\n");
2423 ite8872set = 0x64200000;
2426 printk (KERN_INFO "parport_pc: ITE8872 found (2S1P)\n");
2427 ite8872set = 0x64e00000;
2430 printk (KERN_INFO "parport_pc: ITE8873 found (1S)\n");
2433 DPRINTK (KERN_DEBUG "parport_pc: ITE8874 found (2S)\n");
2436 printk (KERN_INFO "parport_pc: unknown ITE887x\n");
2437 printk (KERN_INFO "parport_pc: please mail 'lspci -nvv' "
2438 "output to Rich.Liu@ite.com.tw\n");
2442 pci_read_config_byte (pdev, 0x3c, &ite8872_irq);
2443 pci_read_config_dword (pdev, 0x1c, &ite8872_lpt);
2444 ite8872_lpt &= 0x0000ff00;
2445 pci_read_config_dword (pdev, 0x20, &ite8872_lpthi);
2446 ite8872_lpthi &= 0x0000ff00;
2447 pci_write_config_dword (pdev, 0x6c, 0xe3000000 | ite8872_lpt);
2448 pci_write_config_dword (pdev, 0x70, 0xe3000000 | ite8872_lpthi);
2449 pci_write_config_dword (pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt);
2450 // SET SPP&EPP , Parallel Port NO DMA , Enable All Function
2452 pci_write_config_dword (pdev, 0x9c,
2453 ite8872set | (ite8872_irq * 0x11111));
2455 DPRINTK (KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq);
2456 DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n",
2458 DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n",
2461 /* Let the user (or defaults) steer us away from interrupts */
2463 if (autoirq != PARPORT_IRQ_AUTO)
2464 irq = PARPORT_IRQ_NONE;
2467 * Release the resource so that parport_pc_probe_port can get it.
2469 release_resource(base_res);
2470 if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi,
2471 irq, PARPORT_DMA_NONE, NULL)) {
2473 "parport_pc: ITE 8872 parallel port: io=0x%X",
2475 if (irq != PARPORT_IRQ_NONE)
2476 printk (", irq=%d", irq);
2484 /* Via support maintained by Jeff Garzik <jgarzik@pobox.com> */
2485 static int __devinit sio_via_686a_probe (struct pci_dev *pdev, int autoirq,
2490 unsigned port1, port2, have_eppecp;
2493 * unlock super i/o configuration, set 0x85_1
2495 pci_read_config_byte (pdev, 0x85, &tmp);
2497 pci_write_config_byte (pdev, 0x85, tmp);
2500 * Super I/O configuration, index port == 3f0h, data port == 3f1h
2503 /* 0xE2_1-0: Parallel Port Mode / Enable */
2507 if ((tmp & 0x03) == 0x03) {
2508 printk (KERN_INFO "parport_pc: Via 686A parallel port disabled in BIOS\n");
2512 /* 0xE6: Parallel Port I/O Base Address, bits 9-2 */
2514 port1 = inb (0x3F1) << 2;
2517 case 0x3bc: port2 = 0x7bc; break;
2518 case 0x378: port2 = 0x778; break;
2519 case 0x278: port2 = 0x678; break;
2521 printk (KERN_INFO "parport_pc: Weird Via 686A parport base 0x%X, ignoring\n",
2526 /* 0xF0_5: EPP+ECP enable */
2528 have_eppecp = (inb (0x3F1) & (1 << 5));
2531 * lock super i/o configuration, clear 0x85_1
2533 pci_read_config_byte (pdev, 0x85, &tmp);
2535 pci_write_config_byte (pdev, 0x85, tmp);
2538 * Get DMA and IRQ from PCI->ISA bridge PCI config registers
2541 /* 0x50_3-2: PnP Routing for Parallel Port DRQ */
2542 pci_read_config_byte (pdev, 0x50, &tmp);
2543 dma = ((tmp >> 2) & 0x03);
2545 /* 0x51_7-4: PnP Routing for Parallel Port IRQ */
2546 pci_read_config_byte (pdev, 0x51, &tmp);
2547 irq = ((tmp >> 4) & 0x0F);
2549 /* filter bogus IRQs */
2555 irq = PARPORT_IRQ_NONE;
2558 default: /* do nothing */
2562 /* if ECP not enabled, DMA is not enabled, assumed bogus 'dma' value */
2564 dma = PARPORT_DMA_NONE;
2566 /* Let the user (or defaults) steer us away from interrupts and DMA */
2567 if (autoirq != PARPORT_IRQ_AUTO) {
2568 irq = PARPORT_IRQ_NONE;
2569 dma = PARPORT_DMA_NONE;
2571 if (autodma != PARPORT_DMA_AUTO)
2572 dma = PARPORT_DMA_NONE;
2574 /* finally, do the probe with values obtained */
2575 if (parport_pc_probe_port (port1, port2, irq, dma, NULL)) {
2577 "parport_pc: Via 686A parallel port: io=0x%X", port1);
2578 if (irq != PARPORT_IRQ_NONE)
2579 printk (", irq=%d", irq);
2580 if (dma != PARPORT_DMA_NONE)
2581 printk (", dma=%d", dma);
2586 printk (KERN_WARNING "parport_pc: Strange, can't probe Via 686A parallel port: io=0x%X, irq=%d, dma=%d\n",
2592 enum parport_pc_sio_types {
2593 sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */
2598 /* each element directly indexed from enum list, above */
2599 static struct parport_pc_superio {
2600 int (*probe) (struct pci_dev *pdev, int autoirq, int autodma);
2601 } parport_pc_superio_info[] __devinitdata = {
2602 { sio_via_686a_probe, },
2603 { sio_ite_8872_probe, },
2607 enum parport_pc_pci_cards {
2608 siig_1p_10x = last_sio,
2613 lava_parallel_dual_a,
2614 lava_parallel_dual_b,
2661 /* each element directly indexed from enum list, above
2662 * (but offset by last_sio) */
2663 static struct parport_pc_pci {
2665 struct { /* BAR (base address registers) numbers in the config
2668 int hi; /* -1 if not there, >6 for offset-method (max
2672 /* If set, this is called immediately after pci_enable_device.
2673 * If it returns non-zero, no probing will take place and the
2674 * ports will not be used. */
2675 int (*preinit_hook) (struct pci_dev *pdev, int autoirq, int autodma);
2677 /* If set, this is called after probing for ports. If 'failed'
2678 * is non-zero we couldn't use any of the ports. */
2679 void (*postinit_hook) (struct pci_dev *pdev, int failed);
2680 } cards[] __devinitdata = {
2681 /* siig_1p_10x */ { 1, { { 2, 3 }, } },
2682 /* siig_2p_10x */ { 2, { { 2, 3 }, { 4, 5 }, } },
2683 /* siig_1p_20x */ { 1, { { 0, 1 }, } },
2684 /* siig_2p_20x */ { 2, { { 0, 1 }, { 2, 3 }, } },
2685 /* lava_parallel */ { 1, { { 0, -1 }, } },
2686 /* lava_parallel_dual_a */ { 1, { { 0, -1 }, } },
2687 /* lava_parallel_dual_b */ { 1, { { 0, -1 }, } },
2688 /* boca_ioppar */ { 1, { { 0, -1 }, } },
2689 /* plx_9050 */ { 2, { { 4, -1 }, { 5, -1 }, } },
2690 /* timedia_4078a */ { 1, { { 2, -1 }, } },
2691 /* timedia_4079h */ { 1, { { 2, 3 }, } },
2692 /* timedia_4085h */ { 2, { { 2, -1 }, { 4, -1 }, } },
2693 /* timedia_4088a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2694 /* timedia_4089a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2695 /* timedia_4095a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2696 /* timedia_4096a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2697 /* timedia_4078u */ { 1, { { 2, -1 }, } },
2698 /* timedia_4079a */ { 1, { { 2, 3 }, } },
2699 /* timedia_4085u */ { 2, { { 2, -1 }, { 4, -1 }, } },
2700 /* timedia_4079r */ { 1, { { 2, 3 }, } },
2701 /* timedia_4079s */ { 1, { { 2, 3 }, } },
2702 /* timedia_4079d */ { 1, { { 2, 3 }, } },
2703 /* timedia_4079e */ { 1, { { 2, 3 }, } },
2704 /* timedia_4079f */ { 1, { { 2, 3 }, } },
2705 /* timedia_9079a */ { 1, { { 2, 3 }, } },
2706 /* timedia_9079b */ { 1, { { 2, 3 }, } },
2707 /* timedia_9079c */ { 1, { { 2, 3 }, } },
2708 /* timedia_4006a */ { 1, { { 0, -1 }, } },
2709 /* timedia_4014 */ { 2, { { 0, -1 }, { 2, -1 }, } },
2710 /* timedia_4008a */ { 1, { { 0, 1 }, } },
2711 /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2712 /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } },
2713 /* SYBA uses fixed offsets in
2715 /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
2716 /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } },
2717 /* titan_010l */ { 1, { { 3, -1 }, } },
2718 /* titan_1284p2 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2719 /* avlab_1p */ { 1, { { 0, 1}, } },
2720 /* avlab_2p */ { 2, { { 0, 1}, { 2, 3 },} },
2721 /* The Oxford Semi cards are unusual: 954 doesn't support ECP,
2722 * and 840 locks up if you write 1 to bit 2! */
2723 /* oxsemi_954 */ { 1, { { 0, -1 }, } },
2724 /* oxsemi_840 */ { 1, { { 0, -1 }, } },
2725 /* aks_0100 */ { 1, { { 0, -1 }, } },
2726 /* mobility_pp */ { 1, { { 0, 1 }, } },
2727 /* netmos_9705 */ { 1, { { 0, -1 }, } }, /* untested */
2728 /* netmos_9805 */ { 1, { { 0, -1 }, } }, /* untested */
2729 /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */
2730 /* netmos_9855 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */
2731 /* netmos_9735 */ { 1, { { 2, 3 }, } }, /* untested */
2732 /* netmos_9835 */ { 1, { { 2, 3 }, } }, /* untested */
2733 /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */
2734 /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */
2737 static struct pci_device_id parport_pc_pci_tbl[] = {
2738 /* Super-IO onboard chips */
2739 { 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a },
2740 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8872,
2741 PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_ite_8872 },
2744 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_10x,
2745 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_10x },
2746 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_10x,
2747 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_10x },
2748 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_20x,
2749 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_20x },
2750 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_20x,
2751 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_20x },
2752 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PARALLEL,
2753 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel },
2754 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_A,
2755 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_a },
2756 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_B,
2757 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_b },
2758 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR,
2759 PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar },
2760 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
2761 PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0,0, plx_9050 },
2762 /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
2763 { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a },
2764 { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h },
2765 { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h },
2766 { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a },
2767 { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a },
2768 { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a },
2769 { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a },
2770 { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u },
2771 { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a },
2772 { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u },
2773 { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r },
2774 { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s },
2775 { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d },
2776 { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e },
2777 { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f },
2778 { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a },
2779 { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b },
2780 { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c },
2781 { 0x1409, 0x7268, 0x1409, 0x0101, 0, 0, timedia_4006a },
2782 { 0x1409, 0x7268, 0x1409, 0x0102, 0, 0, timedia_4014 },
2783 { 0x1409, 0x7268, 0x1409, 0x0103, 0, 0, timedia_4008a },
2784 { 0x1409, 0x7268, 0x1409, 0x0104, 0, 0, timedia_4018 },
2785 { 0x1409, 0x7268, 0x1409, 0x9018, 0, 0, timedia_9018a },
2786 { 0x14f2, 0x0121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, mobility_pp },
2787 { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_2P_EPP,
2788 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_2p_epp },
2789 { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_1P_ECP,
2790 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp },
2791 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L,
2792 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l },
2793 { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 },
2794 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
2795 { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, /* AFAVLAB_TK9902 */
2796 { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p},
2797 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954PP,
2798 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_954 },
2799 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_12PCI840,
2800 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_840 },
2801 { PCI_VENDOR_ID_AKS, PCI_DEVICE_ID_AKS_ALADDINCARD,
2802 PCI_ANY_ID, PCI_ANY_ID, 0, 0, aks_0100 },
2803 /* NetMos communication controllers */
2804 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9705,
2805 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9705 },
2806 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9805,
2807 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 },
2808 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815,
2809 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 },
2810 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855,
2811 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 },
2812 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735,
2813 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9735 },
2814 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835,
2815 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9835 },
2816 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9755,
2817 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9755 },
2818 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9715,
2819 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9715 },
2820 { 0, } /* terminate list */
2822 MODULE_DEVICE_TABLE(pci,parport_pc_pci_tbl);
2824 static int parport_pc_pci_probe (struct pci_dev *dev,
2825 const struct pci_device_id *id)
2827 int err, count, n, i = id->driver_data;
2830 /* This is an onboard Super-IO and has already been probed */
2833 /* This is a PCI card */
2836 if ((err = pci_enable_device (dev)) != 0)
2839 if (cards[i].preinit_hook &&
2840 cards[i].preinit_hook (dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE))
2843 for (n = 0; n < cards[i].numports; n++) {
2844 int lo = cards[i].addr[n].lo;
2845 int hi = cards[i].addr[n].hi;
2846 unsigned long io_lo, io_hi;
2847 io_lo = pci_resource_start (dev, lo);
2849 if ((hi >= 0) && (hi <= 6))
2850 io_hi = pci_resource_start (dev, hi);
2852 io_lo += hi; /* Reinterpret the meaning of
2853 "hi" as an offset (see SYBA
2855 /* TODO: test if sharing interrupts works */
2856 printk (KERN_DEBUG "PCI parallel port detected: %04x:%04x, "
2857 "I/O at %#lx(%#lx)\n",
2858 parport_pc_pci_tbl[i + last_sio].vendor,
2859 parport_pc_pci_tbl[i + last_sio].device, io_lo, io_hi);
2860 if (parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE,
2861 PARPORT_DMA_NONE, dev))
2865 if (cards[i].postinit_hook)
2866 cards[i].postinit_hook (dev, count == 0);
2868 return count == 0 ? -ENODEV : 0;
2871 static struct pci_driver parport_pc_pci_driver = {
2872 .name = "parport_pc",
2873 .id_table = parport_pc_pci_tbl,
2874 .probe = parport_pc_pci_probe,
2877 static int __init parport_pc_init_superio (int autoirq, int autodma)
2879 const struct pci_device_id *id;
2880 struct pci_dev *pdev = NULL;
2883 while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
2884 id = pci_match_device (parport_pc_pci_tbl, pdev);
2885 if (id == NULL || id->driver_data >= last_sio)
2888 if (parport_pc_superio_info[id->driver_data].probe
2889 (pdev, autoirq, autodma)) {
2894 return ret; /* number of devices found */
2897 static struct pci_driver parport_pc_pci_driver;
2898 static int __init parport_pc_init_superio(int autoirq, int autodma) {return 0;}
2899 #endif /* CONFIG_PCI */
2902 static const struct pnp_device_id parport_pc_pnp_tbl[] = {
2903 /* Standard LPT Printer Port */
2904 {.id = "PNP0400", .driver_data = 0},
2905 /* ECP Printer Port */
2906 {.id = "PNP0401", .driver_data = 0},
2910 MODULE_DEVICE_TABLE(pnp,parport_pc_pnp_tbl);
2912 static int parport_pc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *id)
2914 struct parport *pdata;
2915 unsigned long io_lo, io_hi;
2918 if (pnp_port_valid(dev,0) &&
2919 !(pnp_port_flags(dev,0) & IORESOURCE_DISABLED)) {
2920 io_lo = pnp_port_start(dev,0);
2924 if (pnp_port_valid(dev,1) &&
2925 !(pnp_port_flags(dev,1) & IORESOURCE_DISABLED)) {
2926 io_hi = pnp_port_start(dev,1);
2930 if (pnp_irq_valid(dev,0) &&
2931 !(pnp_irq_flags(dev,0) & IORESOURCE_DISABLED)) {
2932 irq = pnp_irq(dev,0);
2934 irq = PARPORT_IRQ_NONE;
2936 if (pnp_dma_valid(dev,0) &&
2937 !(pnp_dma_flags(dev,0) & IORESOURCE_DISABLED)) {
2938 dma = pnp_dma(dev,0);
2940 dma = PARPORT_DMA_NONE;
2942 printk(KERN_INFO "parport: PnPBIOS parport detected.\n");
2943 if (!(pdata = parport_pc_probe_port (io_lo, io_hi, irq, dma, NULL)))
2946 pnp_set_drvdata(dev,pdata);
2950 static void parport_pc_pnp_remove(struct pnp_dev *dev)
2952 struct parport *pdata = (struct parport *)pnp_get_drvdata(dev);
2956 parport_pc_unregister_port(pdata);
2959 /* we only need the pnp layer to activate the device, at least for now */
2960 static struct pnp_driver parport_pc_pnp_driver = {
2961 .name = "parport_pc",
2962 .id_table = parport_pc_pnp_tbl,
2963 .probe = parport_pc_pnp_probe,
2964 .remove = parport_pc_pnp_remove,
2968 /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
2969 static int __init __attribute__((unused))
2970 parport_pc_find_isa_ports (int autoirq, int autodma)
2974 if (parport_pc_probe_port(0x3bc, 0x7bc, autoirq, autodma, NULL))
2976 if (parport_pc_probe_port(0x378, 0x778, autoirq, autodma, NULL))
2978 if (parport_pc_probe_port(0x278, 0x678, autoirq, autodma, NULL))
2984 /* This function is called by parport_pc_init if the user didn't
2985 * specify any ports to probe. Its job is to find some ports. Order
2986 * is important here -- we want ISA ports to be registered first,
2987 * followed by PCI cards (for least surprise), but before that we want
2988 * to do chipset-specific tests for some onboard ports that we know
2991 * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
2992 * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
2994 static int __init parport_pc_find_ports (int autoirq, int autodma)
2998 #ifdef CONFIG_PARPORT_PC_SUPERIO
2999 detect_and_report_winbond ();
3000 detect_and_report_smsc ();
3003 /* Onboard SuperIO chipsets that show themselves on the PCI bus. */
3004 count += parport_pc_init_superio (autoirq, autodma);
3006 /* PnP ports, skip detection if SuperIO already found them */
3008 r = pnp_register_driver (&parport_pc_pnp_driver);
3010 pnp_registered_parport = 1;
3015 /* ISA ports and whatever (see asm/parport.h). */
3016 count += parport_pc_find_nonpci_ports (autoirq, autodma);
3018 r = pci_register_driver (&parport_pc_pci_driver);
3020 pci_registered_parport = 1;
3028 * Piles of crap below pretend to be a parser for module and kernel
3029 * parameters. Say "thank you" to whoever had come up with that
3030 * syntax and keep in mind that code below is a cleaned up version.
3033 static int __initdata io[PARPORT_PC_MAX_PORTS+1] = { [0 ... PARPORT_PC_MAX_PORTS] = 0 };
3034 static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] =
3035 { [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO };
3036 static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE };
3037 static int __initdata irqval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY };
3039 static int __init parport_parse_param(const char *s, int *val,
3040 int automatic, int none, int nofifo)
3044 if (!strncmp(s, "auto", 4))
3046 else if (!strncmp(s, "none", 4))
3048 else if (nofifo && !strncmp(s, "nofifo", 4))
3052 unsigned long r = simple_strtoul(s, &ep, 0);
3056 printk(KERN_ERR "parport: bad specifier `%s'\n", s);
3063 static int __init parport_parse_irq(const char *irqstr, int *val)
3065 return parport_parse_param(irqstr, val, PARPORT_IRQ_AUTO,
3066 PARPORT_IRQ_NONE, 0);
3069 static int __init parport_parse_dma(const char *dmastr, int *val)
3071 return parport_parse_param(dmastr, val, PARPORT_DMA_AUTO,
3072 PARPORT_DMA_NONE, PARPORT_DMA_NOFIFO);
3076 static const char *irq[PARPORT_PC_MAX_PORTS];
3077 static const char *dma[PARPORT_PC_MAX_PORTS];
3079 MODULE_PARM_DESC(io, "Base I/O address (SPP regs)");
3080 MODULE_PARM(io, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS) "i");
3081 MODULE_PARM_DESC(io_hi, "Base I/O address (ECR)");
3082 MODULE_PARM(io_hi, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS) "i");
3083 MODULE_PARM_DESC(irq, "IRQ line");
3084 MODULE_PARM(irq, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS) "s");
3085 MODULE_PARM_DESC(dma, "DMA channel");
3086 MODULE_PARM(dma, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS) "s");
3087 #if defined(CONFIG_PARPORT_PC_SUPERIO) || \
3088 (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
3089 MODULE_PARM_DESC(verbose_probing, "Log chit-chat during initialisation");
3090 MODULE_PARM(verbose_probing, "i");
3093 static int __init parse_parport_params(void)
3098 for (i = 0; i < PARPORT_PC_MAX_PORTS && io[i]; i++) {
3099 if (parport_parse_irq(irq[i], &val))
3102 if (parport_parse_dma(dma[i], &val))
3107 /* The user can make us use any IRQs or DMAs we find. */
3108 if (irq[0] && !parport_parse_irq(irq[0], &val))
3110 case PARPORT_IRQ_NONE:
3111 case PARPORT_IRQ_AUTO:
3115 printk (KERN_WARNING
3116 "parport_pc: irq specified "
3117 "without base address. Use 'io=' "
3118 "to specify one\n");
3121 if (dma[0] && !parport_parse_dma(dma[0], &val))
3123 case PARPORT_DMA_NONE:
3124 case PARPORT_DMA_AUTO:
3128 printk (KERN_WARNING
3129 "parport_pc: dma specified "
3130 "without base address. Use 'io=' "
3131 "to specify one\n");
3139 static int parport_setup_ptr __initdata = 0;
3142 * Acceptable parameters:
3146 * parport=0xBASE[,IRQ[,DMA]]
3148 * IRQ/DMA may be numeric or 'auto' or 'none'
3150 static int __init parport_setup (char *str)
3156 if (!str || !*str || (*str == '0' && !*(str+1))) {
3157 /* Disable parport if "parport=0" in cmdline */
3158 io[0] = PARPORT_DISABLE;
3162 if (!strncmp (str, "auto", 4)) {
3163 irqval[0] = PARPORT_IRQ_AUTO;
3164 dmaval[0] = PARPORT_DMA_AUTO;
3168 val = simple_strtoul (str, &endptr, 0);
3169 if (endptr == str) {
3170 printk (KERN_WARNING "parport=%s not understood\n", str);
3174 if (parport_setup_ptr == PARPORT_PC_MAX_PORTS) {
3175 printk(KERN_ERR "parport=%s ignored, too many ports\n", str);
3179 io[parport_setup_ptr] = val;
3180 irqval[parport_setup_ptr] = PARPORT_IRQ_NONE;
3181 dmaval[parport_setup_ptr] = PARPORT_DMA_NONE;
3183 sep = strchr(str, ',');
3185 if (parport_parse_irq(sep, &val))
3187 irqval[parport_setup_ptr] = val;
3188 sep = strchr(sep, ',');
3190 if (parport_parse_dma(sep, &val))
3192 dmaval[parport_setup_ptr] = val;
3195 parport_setup_ptr++;
3199 static int __init parse_parport_params(void)
3201 return io[0] == PARPORT_DISABLE;
3204 __setup ("parport=", parport_setup);
3207 /* "Parser" ends here */
3209 static int __init parport_pc_init(void)
3213 if (parse_parport_params())
3218 /* Only probe the ports we were given. */
3220 for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) {
3223 if ((io_hi[i]) == PARPORT_IOHI_AUTO)
3224 io_hi[i] = 0x400 + io[i];
3225 if (parport_pc_probe_port(io[i], io_hi[i],
3226 irqval[i], dmaval[i], NULL))
3230 count += parport_pc_find_ports (irqval[0], dmaval[0]);
3235 static void __exit parport_pc_exit(void)
3237 if (pci_registered_parport)
3238 pci_unregister_driver (&parport_pc_pci_driver);
3239 if (pnp_registered_parport)
3240 pnp_unregister_driver (&parport_pc_pnp_driver);
3242 spin_lock(&ports_lock);
3243 while (!list_empty(&ports_list)) {
3244 struct parport_pc_private *priv;
3245 struct parport *port;
3246 priv = list_entry(ports_list.next,
3247 struct parport_pc_private, list);
3249 spin_unlock(&ports_lock);
3250 parport_pc_unregister_port(port);
3251 spin_lock(&ports_lock);
3253 spin_unlock(&ports_lock);
3256 MODULE_AUTHOR("Phil Blundell, Tim Waugh, others");
3257 MODULE_DESCRIPTION("PC-style parallel port driver");
3258 MODULE_LICENSE("GPL");
3259 module_init(parport_pc_init)
3260 module_exit(parport_pc_exit)