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
16 /* This driver should work with any hardware that is broadly compatible
17 * with that in the IBM PC. This applies to the majority of integrated
18 * I/O chipsets that are commonly available. The expected register
25 * In addition, there are some optional registers:
29 * base+0x400 ECP config A
30 * base+0x401 ECP config B
31 * base+0x402 ECP control
33 * All registers are 8 bits wide and read/write. If your hardware differs
34 * only in register addresses (eg because your registers are on 32-bit
35 * word boundaries) then you can alter the constants in parport_pc.h to
38 * Note that the ECP registers may not start at offset 0x400 for PCI cards,
39 * but rather will start at port->base_hi.
42 #include <linux/config.h>
43 #include <linux/module.h>
44 #include <linux/init.h>
45 #include <linux/sched.h>
46 #include <linux/delay.h>
47 #include <linux/errno.h>
48 #include <linux/interrupt.h>
49 #include <linux/ioport.h>
50 #include <linux/kernel.h>
51 #include <linux/malloc.h>
52 #include <linux/pci.h>
53 #include <linux/sysctl.h>
57 #include <asm/uaccess.h>
59 #include <linux/parport.h>
60 #include <linux/parport_pc.h>
61 #include <asm/parport.h>
63 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
78 #define DPRINTK printk
80 #define DPRINTK(stuff...)
85 static struct superio_struct
{ /* For Super-IO chips autodetection */
89 } superios
[NR_SUPERIOS
] __devinitdata
= { {0,},};
91 static int user_specified __devinitdata
= 0;
93 /* frob_control, but for ECR */
94 static void frob_econtrol (struct parport
*pb
, unsigned char m
,
97 unsigned char ectr
= inb (ECONTROL (pb
));
98 DPRINTK (KERN_DEBUG
"frob_econtrol(%02x,%02x): %02x -> %02x\n",
99 m
, v
, ectr
, (ectr
& ~m
) ^ v
);
101 outb ((ectr
& ~m
) ^ v
, ECONTROL (pb
));
104 #ifdef CONFIG_PARPORT_PC_FIFO
105 /* Safely change the mode bits in the ECR
108 -EBUSY: Could not drain FIFO in some finite amount of time,
111 static int change_mode(struct parport
*p
, int m
)
113 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
114 int ecr
= ECONTROL(p
);
118 DPRINTK("parport change_mode ECP-ISA to mode 0x%02x\n",m
);
121 printk (KERN_DEBUG
"change_mode: but there's no ECR!\n");
125 /* Bits <7:5> contain the mode. */
127 mode
= (oecr
>> 5) & 0x7;
128 if (mode
== m
) return 0;
130 if (mode
>= 2 && !(priv
->ctr
& 0x20)) {
131 /* This mode resets the FIFO, so we may
132 * have to wait for it to drain first. */
133 long expire
= jiffies
+ p
->physport
->cad
->timeout
;
136 case ECR_PPF
: /* Parallel Port FIFO mode */
137 case ECR_ECP
: /* ECP Parallel Port mode */
138 /* Busy wait for 200us */
139 for (counter
= 0; counter
< 40; counter
++) {
140 if (inb (ECONTROL (p
)) & 0x01)
142 if (signal_pending (current
)) break;
147 while (!(inb (ECONTROL (p
)) & 0x01)) {
148 if (time_after_eq (jiffies
, expire
))
149 /* The FIFO is stuck. */
151 __set_current_state (TASK_INTERRUPTIBLE
);
152 schedule_timeout ((HZ
+ 99) / 100);
153 if (signal_pending (current
))
159 if (mode
>= 2 && m
>= 2) {
160 /* We have to go through mode 001 */
162 oecr
|= ECR_PS2
<< 5;
173 #ifdef CONFIG_PARPORT_1284
174 /* Find FIFO lossage; FIFO is reset */
175 static int get_fifo_residue (struct parport
*p
)
179 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
181 /* Adjust for the contents of the FIFO. */
182 for (residue
= priv
->fifo_depth
; ; residue
--) {
183 if (inb (ECONTROL (p
)) & 0x2)
190 printk (KERN_DEBUG
"%s: %d PWords were left in FIFO\n", p
->name
,
193 /* Reset the FIFO. */
194 frob_econtrol (p
, 0xe0, ECR_PS2
<< 5);
196 /* Now change to config mode and clean up. FIXME */
197 frob_econtrol (p
, 0xe0, ECR_CNF
<< 5);
198 cnfga
= inb (CONFIGA (p
));
199 printk (KERN_DEBUG
"%s: cnfgA contains 0x%02x\n", p
->name
, cnfga
);
201 if (!(cnfga
& (1<<2))) {
202 printk (KERN_DEBUG
"%s: Accounting for extra byte\n", p
->name
);
206 /* Don't care about partial PWords until support is added for
207 * PWord != 1 byte. */
209 /* Back to PS2 mode. */
210 frob_econtrol (p
, 0xe0, ECR_PS2
<< 5);
214 #endif /* IEEE 1284 support */
215 #endif /* FIFO support */
218 * Clear TIMEOUT BIT in EPP MODE
220 * This is also used in SPP detection.
222 static int clear_epp_timeout(struct parport
*pb
)
226 if (!(parport_pc_read_status(pb
) & 0x01))
229 /* To clear timeout some chips require double read */
230 parport_pc_read_status(pb
);
231 r
= parport_pc_read_status(pb
);
232 outb (r
| 0x01, STATUS (pb
)); /* Some reset by writing 1 */
233 outb (r
& 0xfe, STATUS (pb
)); /* Others by writing 0 */
234 r
= parport_pc_read_status(pb
);
242 * Most of these aren't static because they may be used by the
243 * parport_xxx_yyy macros. extern __inline__ versions of several
244 * of these are in parport_pc.h.
247 static void parport_pc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
249 parport_generic_irq(irq
, (struct parport
*) dev_id
, regs
);
252 void parport_pc_write_data(struct parport
*p
, unsigned char d
)
257 unsigned char parport_pc_read_data(struct parport
*p
)
259 return inb (DATA (p
));
262 void parport_pc_write_control(struct parport
*p
, unsigned char d
)
264 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
265 PARPORT_CONTROL_AUTOFD
|
266 PARPORT_CONTROL_INIT
|
267 PARPORT_CONTROL_SELECT
);
269 /* Take this out when drivers have adapted to the newer interface. */
271 printk (KERN_DEBUG
"%s (%s): use data_reverse for this!\n",
272 p
->name
, p
->cad
->name
);
273 parport_pc_data_reverse (p
);
276 __parport_pc_frob_control (p
, wm
, d
& wm
);
279 unsigned char parport_pc_read_control(struct parport
*p
)
281 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
282 PARPORT_CONTROL_AUTOFD
|
283 PARPORT_CONTROL_INIT
|
284 PARPORT_CONTROL_SELECT
);
285 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
286 return priv
->ctr
& wm
; /* Use soft copy */
289 unsigned char parport_pc_frob_control (struct parport
*p
, unsigned char mask
,
292 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
293 PARPORT_CONTROL_AUTOFD
|
294 PARPORT_CONTROL_INIT
|
295 PARPORT_CONTROL_SELECT
);
297 /* Take this out when drivers have adapted to the newer interface. */
299 printk (KERN_DEBUG
"%s (%s): use data_%s for this!\n",
300 p
->name
, p
->cad
->name
,
301 (val
& 0x20) ? "reverse" : "forward");
303 parport_pc_data_reverse (p
);
305 parport_pc_data_forward (p
);
308 /* Restrict mask and val to control lines. */
312 return __parport_pc_frob_control (p
, mask
, val
);
315 unsigned char parport_pc_read_status(struct parport
*p
)
317 return inb (STATUS (p
));
320 void parport_pc_disable_irq(struct parport
*p
)
322 __parport_pc_frob_control (p
, 0x10, 0);
325 void parport_pc_enable_irq(struct parport
*p
)
327 __parport_pc_frob_control (p
, 0x10, 0x10);
330 void parport_pc_data_forward (struct parport
*p
)
332 __parport_pc_frob_control (p
, 0x20, 0);
335 void parport_pc_data_reverse (struct parport
*p
)
337 __parport_pc_frob_control (p
, 0x20, 0x20);
340 void parport_pc_init_state(struct pardevice
*dev
, struct parport_state
*s
)
342 s
->u
.pc
.ctr
= 0xc | (dev
->irq_func
? 0x10 : 0x0);
346 void parport_pc_save_state(struct parport
*p
, struct parport_state
*s
)
348 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
349 s
->u
.pc
.ctr
= inb (CONTROL (p
));
351 s
->u
.pc
.ecr
= inb (ECONTROL (p
));
354 void parport_pc_restore_state(struct parport
*p
, struct parport_state
*s
)
356 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
357 outb (s
->u
.pc
.ctr
, CONTROL (p
));
359 outb (s
->u
.pc
.ecr
, ECONTROL (p
));
362 #ifdef CONFIG_PARPORT_1284
363 static size_t parport_pc_epp_read_data (struct parport
*port
, void *buf
,
364 size_t length
, int flags
)
367 for (; got
< length
; got
++) {
368 *((char*)buf
)++ = inb (EPPDATA(port
));
369 if (inb (STATUS(port
)) & 0x01) {
370 clear_epp_timeout (port
);
378 static size_t parport_pc_epp_write_data (struct parport
*port
, const void *buf
,
379 size_t length
, int flags
)
382 for (; written
< length
; written
++) {
383 outb (*((char*)buf
)++, EPPDATA(port
));
384 if (inb (STATUS(port
)) & 0x01) {
385 clear_epp_timeout (port
);
393 static size_t parport_pc_epp_read_addr (struct parport
*port
, void *buf
,
394 size_t length
, int flags
)
397 for (; got
< length
; got
++) {
398 *((char*)buf
)++ = inb (EPPADDR (port
));
399 if (inb (STATUS (port
)) & 0x01) {
400 clear_epp_timeout (port
);
408 static size_t parport_pc_epp_write_addr (struct parport
*port
,
409 const void *buf
, size_t length
,
413 for (; written
< length
; written
++) {
414 outb (*((char*)buf
)++, EPPADDR (port
));
415 if (inb (STATUS (port
)) & 0x01) {
416 clear_epp_timeout (port
);
424 static size_t parport_pc_ecpepp_read_data (struct parport
*port
, void *buf
,
425 size_t length
, int flags
)
429 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
430 parport_pc_data_reverse (port
);
431 parport_pc_write_control (port
, 0x4);
432 got
= parport_pc_epp_read_data (port
, buf
, length
, flags
);
433 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
438 static size_t parport_pc_ecpepp_write_data (struct parport
*port
,
439 const void *buf
, size_t length
,
444 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
445 parport_pc_write_control (port
, 0x4);
446 parport_pc_data_forward (port
);
447 written
= parport_pc_epp_write_data (port
, buf
, length
, flags
);
448 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
453 static size_t parport_pc_ecpepp_read_addr (struct parport
*port
, void *buf
,
454 size_t length
, int flags
)
458 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
459 parport_pc_data_reverse (port
);
460 parport_pc_write_control (port
, 0x4);
461 got
= parport_pc_epp_read_addr (port
, buf
, length
, flags
);
462 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
467 static size_t parport_pc_ecpepp_write_addr (struct parport
*port
,
468 const void *buf
, size_t length
,
473 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
474 parport_pc_write_control (port
, 0x4);
475 parport_pc_data_forward (port
);
476 written
= parport_pc_epp_write_addr (port
, buf
, length
, flags
);
477 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
481 #endif /* IEEE 1284 support */
483 #ifdef CONFIG_PARPORT_PC_FIFO
484 static size_t parport_pc_fifo_write_block_pio (struct parport
*port
,
485 const void *buf
, size_t length
)
488 const unsigned char *bufp
= buf
;
489 size_t left
= length
;
490 long expire
= jiffies
+ port
->physport
->cad
->timeout
;
491 const int fifo
= FIFO (port
);
492 int poll_for
= 8; /* 80 usecs */
493 const struct parport_pc_private
*priv
= port
->physport
->private_data
;
494 const int fifo_depth
= priv
->fifo_depth
;
496 port
= port
->physport
;
498 /* We don't want to be interrupted every character. */
499 parport_pc_disable_irq (port
);
500 frob_econtrol (port
, (1<<4), (1<<4)); /* nErrIntrEn */
503 parport_pc_data_forward (port
); /* Must be in PS2 mode */
507 unsigned char ecrval
= inb (ECONTROL (port
));
510 if (current
->need_resched
&& time_before (jiffies
, expire
))
511 /* Can't yield the port. */
514 /* Anyone else waiting for the port? */
515 if (port
->waithead
) {
516 printk (KERN_DEBUG
"Somebody wants the port\n");
521 /* FIFO is full. Wait for interrupt. */
523 /* Clear serviceIntr */
524 outb (ecrval
& ~(1<<2), ECONTROL (port
));
526 ret
= parport_wait_event (port
, HZ
);
529 if (!time_before (jiffies
, expire
)) {
531 printk (KERN_DEBUG
"FIFO write timed out\n");
534 ecrval
= inb (ECONTROL (port
));
535 if (!(ecrval
& (1<<2))) {
536 if (current
->need_resched
&&
537 time_before (jiffies
, expire
))
546 /* Can't fail now. */
547 expire
= jiffies
+ port
->cad
->timeout
;
550 if (signal_pending (current
))
554 /* FIFO is empty. Blast it full. */
555 const int n
= left
< fifo_depth
? left
: fifo_depth
;
556 outsb (fifo
, bufp
, n
);
560 /* Adjust the poll time. */
561 if (i
< (poll_for
- 2)) poll_for
--;
563 } else if (i
++ < poll_for
) {
565 ecrval
= inb (ECONTROL (port
));
569 /* Half-full (call me an optimist) */
575 return length
- left
;
578 static size_t parport_pc_fifo_write_block_dma (struct parport
*port
,
579 const void *buf
, size_t length
)
582 unsigned long dmaflag
;
583 size_t left
= length
;
584 const struct parport_pc_private
*priv
= port
->physport
->private_data
;
585 dma_addr_t dma_addr
, dma_handle
;
586 size_t maxlen
= 0x10000; /* max 64k per DMA transfer */
587 unsigned long start
= (unsigned long) buf
;
588 unsigned long end
= (unsigned long) buf
+ length
- 1;
590 if (end
< MAX_DMA_ADDRESS
) {
591 /* If it would cross a 64k boundary, cap it at the end. */
592 if ((start
^ end
) & ~0xffffUL
)
593 maxlen
= 0x10000 - (start
& 0xffff);
595 dma_addr
= dma_handle
= pci_map_single(priv
->dev
, (void *)buf
, length
,
598 /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */
599 maxlen
= PAGE_SIZE
; /* sizeof(priv->dma_buf) */
600 dma_addr
= priv
->dma_handle
;
604 port
= port
->physport
;
606 /* We don't want to be interrupted every character. */
607 parport_pc_disable_irq (port
);
608 frob_econtrol (port
, (1<<4), (1<<4)); /* nErrIntrEn */
611 parport_pc_data_forward (port
); /* Must be in PS2 mode */
614 long expire
= jiffies
+ port
->physport
->cad
->timeout
;
621 if (!dma_handle
) /* bounce buffer ! */
622 memcpy(priv
->dma_buf
, buf
, count
);
624 dmaflag
= claim_dma_lock();
625 disable_dma(port
->dma
);
626 clear_dma_ff(port
->dma
);
627 set_dma_mode(port
->dma
, DMA_MODE_WRITE
);
628 set_dma_addr(port
->dma
, dma_addr
);
629 set_dma_count(port
->dma
, count
);
632 frob_econtrol (port
, 1<<3, 1<<3);
634 /* Clear serviceIntr */
635 frob_econtrol (port
, 1<<2, 0);
637 enable_dma(port
->dma
);
638 release_dma_lock(dmaflag
);
640 /* assume DMA will be successful */
643 if (dma_handle
) dma_addr
+= count
;
645 /* Wait for interrupt. */
647 ret
= parport_wait_event (port
, HZ
);
650 if (!time_before (jiffies
, expire
)) {
652 printk (KERN_DEBUG
"DMA write timed out\n");
655 /* Is serviceIntr set? */
656 if (!(inb (ECONTROL (port
)) & (1<<2))) {
657 if (current
->need_resched
)
663 dmaflag
= claim_dma_lock();
664 disable_dma(port
->dma
);
665 clear_dma_ff(port
->dma
);
666 count
= get_dma_residue(port
->dma
);
667 release_dma_lock(dmaflag
);
669 if (current
->need_resched
)
670 /* Can't yield the port. */
673 /* Anyone else waiting for the port? */
674 if (port
->waithead
) {
675 printk (KERN_DEBUG
"Somebody wants the port\n");
679 /* update for possible DMA residue ! */
682 if (dma_handle
) dma_addr
-= count
;
685 /* Maybe got here through break, so adjust for DMA residue! */
686 dmaflag
= claim_dma_lock();
687 disable_dma(port
->dma
);
688 clear_dma_ff(port
->dma
);
689 left
+= get_dma_residue(port
->dma
);
690 release_dma_lock(dmaflag
);
692 /* Turn off DMA mode */
693 frob_econtrol (port
, 1<<3, 0);
696 pci_unmap_single(priv
->dev
, dma_handle
, length
, PCI_DMA_TODEVICE
);
698 return length
- left
;
701 /* Parallel Port FIFO mode (ECP chipsets) */
702 size_t parport_pc_compat_write_block_pio (struct parport
*port
,
703 const void *buf
, size_t length
,
709 /* Special case: a timeout of zero means we cannot call schedule(). */
710 if (!port
->physport
->cad
->timeout
)
711 return parport_ieee1284_write_compat (port
, buf
,
714 /* Set up parallel port FIFO mode.*/
715 parport_pc_data_forward (port
); /* Must be in PS2 mode */
716 parport_pc_frob_control (port
, PARPORT_CONTROL_STROBE
, 0);
717 r
= change_mode (port
, ECR_PPF
); /* Parallel port FIFO */
718 if (r
) printk (KERN_DEBUG
"%s: Warning change_mode ECR_PPF failed\n", port
->name
);
720 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_DATA
;
722 /* Write the data to the FIFO. */
723 if (port
->dma
!= PARPORT_DMA_NONE
)
724 written
= parport_pc_fifo_write_block_dma (port
, buf
, length
);
726 written
= parport_pc_fifo_write_block_pio (port
, buf
, length
);
729 if (change_mode (port
, ECR_PS2
) == -EBUSY
) {
730 const struct parport_pc_private
*priv
=
731 port
->physport
->private_data
;
733 printk (KERN_DEBUG
"%s: FIFO is stuck\n", port
->name
);
735 /* Prevent further data transfer. */
736 frob_econtrol (port
, 0xe0, ECR_TST
<< 5);
738 /* Adjust for the contents of the FIFO. */
739 for (written
-= priv
->fifo_depth
; ; written
++) {
740 if (inb (ECONTROL (port
)) & 0x2)
744 outb (0, FIFO (port
));
747 /* Reset the FIFO and return to PS2 mode. */
748 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
751 r
= parport_wait_peripheral (port
,
753 PARPORT_STATUS_BUSY
);
756 "%s: BUSY timeout (%d) in compat_write_block_pio\n",
759 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_IDLE
;
765 #ifdef CONFIG_PARPORT_1284
766 size_t parport_pc_ecp_write_block_pio (struct parport
*port
,
767 const void *buf
, size_t length
,
773 /* Special case: a timeout of zero means we cannot call schedule(). */
774 if (!port
->physport
->cad
->timeout
)
775 return parport_ieee1284_ecp_write_data (port
, buf
,
778 /* Switch to forward mode if necessary. */
779 if (port
->physport
->ieee1284
.phase
!= IEEE1284_PH_FWD_IDLE
) {
780 /* Event 47: Set nInit high. */
781 parport_frob_control (port
,
783 | PARPORT_CONTROL_AUTOFD
,
785 | PARPORT_CONTROL_AUTOFD
);
787 /* Event 49: PError goes high. */
788 r
= parport_wait_peripheral (port
,
789 PARPORT_STATUS_PAPEROUT
,
790 PARPORT_STATUS_PAPEROUT
);
792 printk (KERN_DEBUG
"%s: PError timeout (%d) "
793 "in ecp_write_block_pio\n", port
->name
, r
);
796 /* Set up ECP parallel port mode.*/
797 parport_pc_data_forward (port
); /* Must be in PS2 mode */
798 parport_pc_frob_control (port
,
799 PARPORT_CONTROL_STROBE
|
800 PARPORT_CONTROL_AUTOFD
,
802 r
= change_mode (port
, ECR_ECP
); /* ECP FIFO */
803 if (r
) printk (KERN_DEBUG
"%s: Warning change_mode ECR_ECP failed\n", port
->name
);
804 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_DATA
;
806 /* Write the data to the FIFO. */
807 if (port
->dma
!= PARPORT_DMA_NONE
)
808 written
= parport_pc_fifo_write_block_dma (port
, buf
, length
);
810 written
= parport_pc_fifo_write_block_pio (port
, buf
, length
);
813 if (change_mode (port
, ECR_PS2
) == -EBUSY
) {
814 const struct parport_pc_private
*priv
=
815 port
->physport
->private_data
;
817 printk (KERN_DEBUG
"%s: FIFO is stuck\n", port
->name
);
819 /* Prevent further data transfer. */
820 frob_econtrol (port
, 0xe0, ECR_TST
<< 5);
822 /* Adjust for the contents of the FIFO. */
823 for (written
-= priv
->fifo_depth
; ; written
++) {
824 if (inb (ECONTROL (port
)) & 0x2)
828 outb (0, FIFO (port
));
831 /* Reset the FIFO and return to PS2 mode. */
832 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
834 /* Host transfer recovery. */
835 parport_pc_data_reverse (port
); /* Must be in PS2 mode */
837 parport_frob_control (port
, PARPORT_CONTROL_INIT
, 0);
838 r
= parport_wait_peripheral (port
, PARPORT_STATUS_PAPEROUT
, 0);
840 printk (KERN_DEBUG
"%s: PE,1 timeout (%d) "
841 "in ecp_write_block_pio\n", port
->name
, r
);
843 parport_frob_control (port
,
844 PARPORT_CONTROL_INIT
,
845 PARPORT_CONTROL_INIT
);
846 r
= parport_wait_peripheral (port
,
847 PARPORT_STATUS_PAPEROUT
,
848 PARPORT_STATUS_PAPEROUT
);
850 printk (KERN_DEBUG
"%s: PE,2 timeout (%d) "
851 "in ecp_write_block_pio\n", port
->name
, r
);
854 r
= parport_wait_peripheral (port
,
856 PARPORT_STATUS_BUSY
);
859 "%s: BUSY timeout (%d) in ecp_write_block_pio\n",
862 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_IDLE
;
867 size_t parport_pc_ecp_read_block_pio (struct parport
*port
,
868 void *buf
, size_t length
, int flags
)
870 size_t left
= length
;
873 const int fifo
= FIFO(port
);
874 const struct parport_pc_private
*priv
= port
->physport
->private_data
;
875 const int fifo_depth
= priv
->fifo_depth
;
878 port
= port
->physport
;
880 /* Special case: a timeout of zero means we cannot call schedule(). */
881 if (!port
->cad
->timeout
)
882 return parport_ieee1284_ecp_read_data (port
, buf
,
885 fifofull
= fifo_depth
;
886 if (port
->ieee1284
.mode
== IEEE1284_MODE_ECPRLE
)
887 /* If the peripheral is allowed to send RLE compressed
888 * data, it is possible for a byte to expand to 128
889 * bytes in the FIFO. */
892 /* If the caller wants less than a full FIFO's worth of data,
893 * go through software emulation. Otherwise we may have to through
895 if (length
< fifofull
)
896 return parport_ieee1284_ecp_read_data (port
, buf
,
899 /* Switch to reverse mode if necessary. */
900 if ((port
->ieee1284
.phase
!= IEEE1284_PH_REV_IDLE
) &&
901 (port
->ieee1284
.phase
!= IEEE1284_PH_REV_DATA
)) {
902 /* Event 38: Set nAutoFd low */
903 parport_frob_control (port
,
904 PARPORT_CONTROL_AUTOFD
,
905 PARPORT_CONTROL_AUTOFD
);
906 parport_pc_data_reverse (port
); /* Must be in PS2 mode */
909 /* Event 39: Set nInit low to initiate bus reversal */
910 parport_frob_control (port
,
911 PARPORT_CONTROL_INIT
,
914 /* Event 40: PError goes low */
915 r
= parport_wait_peripheral (port
, PARPORT_STATUS_PAPEROUT
, 0);
917 printk (KERN_DEBUG
"%s: PE timeout Event 40 (%d) "
918 "in ecp_read_block_pio\n", port
->name
, r
);
921 /* Set up ECP FIFO mode.*/
922 parport_pc_data_reverse (port
); /* Must be in PS2 mode */
923 parport_pc_frob_control (port
,
924 PARPORT_CONTROL_STROBE
|
925 PARPORT_CONTROL_AUTOFD
,
927 r
= change_mode (port
, ECR_ECP
); /* ECP FIFO */
928 if (r
) printk (KERN_DEBUG
"%s: Warning change_mode ECR_ECP failed\n", port
->name
);
929 port
->ieee1284
.phase
= IEEE1284_PH_REV_DATA
;
931 /* Do the transfer. */
932 while (left
> fifofull
) {
934 long int expire
= jiffies
+ port
->cad
->timeout
;
935 unsigned char ecrval
= inb (ECONTROL (port
));
937 if (current
->need_resched
&& time_before (jiffies
, expire
))
938 /* Can't yield the port. */
941 /* At this point, the FIFO may already be full.
942 * Ideally, we'd be able to tell the port to hold on
943 * for a second while we empty the FIFO, and we'd be
944 * able to ensure that no data is lost. I'm not sure
945 * that's the case. :-( It might be that you can play
946 * games with STB, as in the forward case; someone should
947 * look at a datasheet. */
950 /* FIFO is empty. Wait for interrupt. */
952 /* Anyone else waiting for the port? */
953 if (port
->waithead
) {
955 "Somebody wants the port\n");
959 /* Clear serviceIntr */
960 outb (ecrval
& ~(1<<2), ECONTROL (port
));
962 ret
= parport_wait_event (port
, HZ
);
965 if (!time_before (jiffies
, expire
)) {
967 printk (KERN_DEBUG
"PIO read timed out\n");
970 ecrval
= inb (ECONTROL (port
));
971 if (!(ecrval
& (1<<2))) {
972 if (current
->need_resched
&&
973 time_before (jiffies
, expire
))
984 insb (fifo
, bufp
, fifo_depth
);
990 *bufp
++ = inb (fifo
);
994 port
->ieee1284
.phase
= IEEE1284_PH_REV_IDLE
;
996 /* Go to forward idle mode to shut the peripheral up. */
997 parport_frob_control (port
, PARPORT_CONTROL_INIT
, 0);
998 r
= parport_wait_peripheral (port
,
999 PARPORT_STATUS_PAPEROUT
,
1000 PARPORT_STATUS_PAPEROUT
);
1003 "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n",
1006 port
->ieee1284
.phase
= IEEE1284_PH_FWD_IDLE
;
1010 int lost
= get_fifo_residue (port
);
1012 /* Shouldn't happen with compliant peripherals. */
1013 printk (KERN_DEBUG
"%s: DATA LOSS (%d bytes)!\n",
1017 return length
- left
;
1020 #endif /* IEEE 1284 support */
1022 #endif /* Allowed to use FIFO/DMA */
1024 void parport_pc_inc_use_count(void)
1031 void parport_pc_dec_use_count(void)
1038 struct parport_operations parport_pc_ops
=
1040 parport_pc_write_data
,
1041 parport_pc_read_data
,
1043 parport_pc_write_control
,
1044 parport_pc_read_control
,
1045 parport_pc_frob_control
,
1047 parport_pc_read_status
,
1049 parport_pc_enable_irq
,
1050 parport_pc_disable_irq
,
1052 parport_pc_data_forward
,
1053 parport_pc_data_reverse
,
1055 parport_pc_init_state
,
1056 parport_pc_save_state
,
1057 parport_pc_restore_state
,
1059 parport_pc_inc_use_count
,
1060 parport_pc_dec_use_count
,
1062 parport_ieee1284_epp_write_data
,
1063 parport_ieee1284_epp_read_data
,
1064 parport_ieee1284_epp_write_addr
,
1065 parport_ieee1284_epp_read_addr
,
1067 parport_ieee1284_ecp_write_data
,
1068 parport_ieee1284_ecp_read_data
,
1069 parport_ieee1284_ecp_write_addr
,
1071 parport_ieee1284_write_compat
,
1072 parport_ieee1284_read_nibble
,
1073 parport_ieee1284_read_byte
,
1076 #ifdef CONFIG_PARPORT_PC_SUPERIO
1077 /* Super-IO chipset detection, Winbond, SMSC */
1078 static void __devinit
show_parconfig_smsc37c669(int io
, int key
)
1080 int cr1
,cr4
,cra
,cr23
,cr26
,cr27
,i
=0;
1081 char *modes
[]={ "SPP and Bidirectional (PS/2)",
1102 printk ("SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, "
1103 "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n",
1104 cr1
,cr4
,cra
,cr23
,cr26
,cr27
);
1106 /* The documentation calls DMA and IRQ-Lines by letters, so
1107 the board maker can/will wire them
1108 appropriately/randomly... G=reserved H=IDE-irq, */
1109 printk ("SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, "
1110 "fifo threshold=%d\n", cr23
*4,
1111 (cr27
&0x0f) ? 'A'-1+(cr27
&0x0f): '-',
1112 (cr26
&0x0f) ? 'A'-1+(cr26
&0x0f): '-', cra
& 0x0f);
1113 printk("SMSC LPT Config: enabled=%s power=%s\n",
1114 (cr23
*4 >=0x100) ?"yes":"no", (cr1
& 4) ? "yes" : "no");
1115 printk("SMSC LPT Config: Port mode=%s, EPP version =%s\n",
1116 (cr1
& 0x08 ) ? "Standard mode only (SPP)" : modes
[cr4
& 0x03],
1117 (cr4
& 0x40) ? "1.7" : "1.9");
1119 /* Heuristics ! BIOS setup for this mainboard device limits
1120 the choices to standard settings, i.e. io-address and IRQ
1121 are related, however DMA can be 1 or 3, assume DMA_A=DMA1,
1122 DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */
1123 if(cr23
*4 >=0x100) { /* if active */
1124 while((superios
[i
].io
!= 0) && (i
<NR_SUPERIOS
))
1127 printk("Super-IO: too many chips!\n");
1132 superios
[i
].io
= 0x3bc;
1133 superios
[i
].irq
= 7;
1136 superios
[i
].io
= 0x378;
1137 superios
[i
].irq
= 7;
1140 superios
[i
].io
= 0x278;
1141 superios
[i
].irq
= 5;
1144 if((d
==1) || (d
==3))
1147 superios
[i
].dma
= PARPORT_DMA_NONE
;
1153 static void __devinit
show_parconfig_winbond(int io
, int key
)
1155 int cr30
,cr60
,cr61
,cr70
,cr74
,crf0
,i
=0;
1156 char *modes
[]={ "Standard (SPP) and Bidirectional(PS/2)", /* 0 */
1161 "EPP-1.7 and SPP", /* 5 */
1164 char *irqtypes
[]={"pulsed low, high-Z", "follows nACK"};
1166 /* The registers are called compatible-PnP because the
1167 register layout is modelled after ISA-PnP, the access
1168 method is just another ... */
1171 outb(0x07,io
); /* Register 7: Select Logical Device */
1172 outb(0x01,io
+1); /* LD1 is Parallel Port */
1187 printk("Winbond LPT Config: cr_30=%02x 60,61=%02x%02x "
1188 "70=%02x 74=%02x, f0=%02x\n", cr30
,cr60
,cr61
,cr70
,cr74
,crf0
);
1189 printk("Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ",
1190 (cr30
& 0x01) ? "yes":"no", cr60
,cr61
,cr70
&0x0f );
1191 if ((cr74
& 0x07) > 3)
1192 printk("dma=none\n");
1194 printk("dma=%d\n",cr74
& 0x07);
1195 printk("Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n",
1196 irqtypes
[crf0
>>7], (crf0
>>3)&0x0f);
1197 printk("Winbond LPT Config: Port mode=%s\n", modes
[crf0
& 0x07]);
1199 if(cr30
& 0x01) { /* the settings can be interrogated later ... */
1200 while((superios
[i
].io
!= 0) && (i
<NR_SUPERIOS
))
1203 printk("Super-IO: too many chips!\n");
1205 superios
[i
].io
= (cr60
<<8)|cr61
;
1206 superios
[i
].irq
= cr70
&0x0f;
1207 superios
[i
].dma
= (((cr74
& 0x07) > 3) ?
1208 PARPORT_DMA_NONE
: (cr74
& 0x07));
1213 static void __devinit
decode_winbond(int efer
, int key
, int devid
, int devrev
, int oldid
)
1218 if (devid
== devrev
)
1219 /* simple heuristics, we happened to read some
1220 non-winbond register */
1223 printk("Winbond chip at EFER=0x%x key=0x%02x devid=%02x devrev=%02x "
1224 "oldid=%02x\n", efer
,key
,devid
,devrev
,oldid
);
1225 id
=(devid
<<8) | devrev
;
1227 /* Values are from public data sheets pdf files, I can just
1228 confirm 83977TF is correct :-) */
1229 if (id
== 0x9771) type
="83977F/AF";
1230 else if (id
== 0x9773) type
="83977TF / SMSC 97w33x/97w34x";
1231 else if (id
== 0x9774) type
="83977ATF";
1232 else if ((id
& ~0x0f) == 0x5270) type
="83977CTF / SMSC 97w36x";
1233 else if ((id
& ~0x0f) == 0x52f0) type
="83977EF / SMSC 97w35x";
1234 else if ((id
& ~0x0f) == 0x5210) type
="83627";
1235 else if ((id
& ~0x0f) == 0x6010) type
="83697HF";
1236 else if ((oldid
&0x0f ) == 0x0a) { type
="83877F"; progif
=1;}
1237 else if ((oldid
&0x0f ) == 0x0b) { type
="83877AF"; progif
=1;}
1238 else if ((oldid
&0x0f ) == 0x0c) { type
="83877TF"; progif
=1;}
1239 else if ((oldid
&0x0f ) == 0x0d) { type
="83877ATF"; progif
=1;}
1243 printk("Winbond unknown chip type\n");
1245 printk("Winbond chip type %s\n",type
);
1248 show_parconfig_winbond(efer
,key
);
1252 static void __devinit
decode_smsc(int efer
, int key
, int devid
, int devrev
)
1255 void (*func
)(int io
, int key
);
1258 if (devid
== devrev
)
1259 /* simple heuristics, we happened to read some
1260 non-smsc register */
1264 printk("SMSC chip at EFER=0x%x key=0x%02x devid=%02x devrev=%02x\n",
1265 efer
,key
,devid
,devrev
);
1266 id
=(devid
<<8) | devrev
;
1268 if (id
==0x0302) {type
="37c669"; func
=show_parconfig_smsc37c669
;}
1269 else if (id
==0x6582) type
="37c665IR";
1270 else if (devid
==0x65) type
="37c665GT";
1271 else if (devid
==0x66) type
="37c666GT";
1274 printk("SMSC unknown chip type\n");
1276 printk("SMSC chip type %s\n",type
);
1278 if(func
) (func
)(efer
,key
);
1283 static void __devinit
winbond_check(int io
, int key
)
1285 int devid
,devrev
,oldid
,x_devid
,x_devrev
,x_oldid
;
1287 /* First probe without key */
1296 outb(key
,io
); /* Write Magic Sequence to EFER, extended
1297 funtion enable register */
1298 outb(0x20,io
); /* Write EFIR, extended function index register */
1299 devid
=inb(io
+1); /* Read EFDR, extended function data register */
1304 outb(0xaa,io
); /* Magic Seal */
1306 if ((x_devid
== devid
) && (x_devrev
== devrev
) && (x_oldid
== oldid
))
1307 return; /* protection against false positives */
1309 decode_winbond(io
,key
,devid
,devrev
,oldid
);
1312 static void __devinit
winbond_check2(int io
,int key
)
1314 int devid
,devrev
,oldid
,x_devid
,x_devrev
,x_oldid
;
1316 /* First probe without the key */
1324 outb(key
,io
); /* Write Magic Byte to EFER, extended
1325 funtion enable register */
1326 outb(0x20,io
+2); /* Write EFIR, extended function index register */
1327 devid
=inb(io
+2); /* Read EFDR, extended function data register */
1332 outb(0xaa,io
); /* Magic Seal */
1334 if ((x_devid
== devid
) && (x_devrev
== devrev
) && (x_oldid
== oldid
))
1335 return; /* protection against false positives */
1337 decode_winbond(io
,key
,devid
,devrev
,oldid
);
1340 static void __devinit
smsc_check(int io
, int key
)
1342 int id
,rev
,oldid
,oldrev
,x_id
,x_rev
,x_oldid
,x_oldrev
;
1344 /* First probe without the key */
1355 outb(key
,io
); /* Write Magic Sequence to EFER, extended
1356 funtion enable register */
1357 outb(0x0d,io
); /* Write EFIR, extended function index register */
1358 oldid
=inb(io
+1); /* Read EFDR, extended function data register */
1365 outb(0xaa,io
); /* Magic Seal */
1367 if ((x_id
== id
) && (x_oldrev
== oldrev
) &&
1368 (x_oldid
== oldid
) && (x_rev
== rev
))
1369 return; /* protection against false positives */
1371 decode_smsc(io
,key
,oldid
,oldrev
);
1375 static void __devinit
detect_and_report_winbond (void)
1377 printk("Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n");
1379 winbond_check(0x3f0,0x87);
1380 winbond_check(0x370,0x87);
1381 winbond_check(0x2e ,0x87);
1382 winbond_check(0x4e ,0x87);
1383 winbond_check(0x3f0,0x86);
1384 winbond_check2(0x250,0x88);
1385 winbond_check2(0x250,0x89);
1388 static void __devinit
detect_and_report_smsc (void)
1390 printk("SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n");
1391 smsc_check(0x3f0,0x55);
1392 smsc_check(0x370,0x55);
1393 smsc_check(0x3f0,0x44);
1394 smsc_check(0x370,0x44);
1396 #endif /* CONFIG_PARPORT_PC_SUPERIO */
1398 static int __devinit
get_superio_dma (struct parport
*p
)
1401 while( (superios
[i
].io
!= p
->base
) && (i
<NR_SUPERIOS
))
1404 return superios
[i
].dma
;
1405 return PARPORT_DMA_NONE
;
1408 static int __devinit
get_superio_irq (struct parport
*p
)
1411 while( (superios
[i
].io
!= p
->base
) && (i
<NR_SUPERIOS
))
1414 return superios
[i
].irq
;
1415 return PARPORT_IRQ_NONE
;
1419 /* --- Mode detection ------------------------------------- */
1422 * Checks for port existence, all ports support SPP MODE
1424 * 0 : No parallel port at this adress
1425 * PARPORT_MODE_PCSPP : SPP port detected
1426 * (if the user specified an ioport himself,
1427 * this shall always be the case!)
1430 static int __devinit
parport_SPP_supported(struct parport
*pb
)
1435 * first clear an eventually pending EPP timeout
1436 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
1437 * that does not even respond to SPP cycles if an EPP
1438 * timeout is pending
1440 clear_epp_timeout(pb
);
1442 /* Do a simple read-write test to make sure the port exists. */
1444 outb (w
, CONTROL (pb
));
1446 /* Is there a control register that we can read from? Some
1447 * ports don't allow reads, so read_control just returns a
1448 * software copy. Some ports _do_ allow reads, so bypass the
1449 * software copy here. In addition, some bits aren't
1451 r
= inb (CONTROL (pb
));
1452 if ((r
& 0xf) == w
) {
1454 outb (w
, CONTROL (pb
));
1455 r
= inb (CONTROL (pb
));
1456 outb (0xc, CONTROL (pb
));
1458 return PARPORT_MODE_PCSPP
;
1462 /* That didn't work, but the user thinks there's a
1464 printk (KERN_DEBUG
"parport 0x%lx (WARNING): CTR: "
1465 "wrote 0x%02x, read 0x%02x\n", pb
->base
, w
, r
);
1467 /* Try the data register. The data lines aren't tri-stated at
1468 * this stage, so we expect back what we wrote. */
1470 parport_pc_write_data (pb
, w
);
1471 r
= parport_pc_read_data (pb
);
1474 parport_pc_write_data (pb
, w
);
1475 r
= parport_pc_read_data (pb
);
1477 return PARPORT_MODE_PCSPP
;
1480 if (user_specified
) {
1481 /* Didn't work, but the user is convinced this is the
1483 printk (KERN_DEBUG
"parport 0x%lx (WARNING): DATA: "
1484 "wrote 0x%02x, read 0x%02x\n", pb
->base
, w
, r
);
1485 printk (KERN_DEBUG
"parport 0x%lx: You gave this address, "
1486 "but there is probably no parallel port there!\n",
1490 /* It's possible that we can't read the control register or
1491 * the data register. In that case just believe the user. */
1493 return PARPORT_MODE_PCSPP
;
1500 * Old style XT ports alias io ports every 0x400, hence accessing ECR
1501 * on these cards actually accesses the CTR.
1503 * Modern cards don't do this but reading from ECR will return 0xff
1504 * regardless of what is written here if the card does NOT support
1507 * We first check to see if ECR is the same as CTR. If not, the low
1508 * two bits of ECR aren't writable, so we check by writing ECR and
1509 * reading it back to see if it's what we expect.
1511 static int __devinit
parport_ECR_present(struct parport
*pb
)
1513 struct parport_pc_private
*priv
= pb
->private_data
;
1514 unsigned char r
= 0xc;
1516 outb (r
, CONTROL (pb
));
1517 if ((inb (ECONTROL (pb
)) & 0x3) == (r
& 0x3)) {
1518 outb (r
^ 0x2, CONTROL (pb
)); /* Toggle bit 1 */
1520 r
= inb (CONTROL (pb
));
1521 if ((inb (ECONTROL (pb
)) & 0x2) == (r
& 0x2))
1522 goto no_reg
; /* Sure that no ECR register exists */
1525 if ((inb (ECONTROL (pb
)) & 0x3 ) != 0x1)
1528 outb (0x34, ECONTROL (pb
));
1529 if (inb (ECONTROL (pb
)) != 0x35)
1533 outb (0xc, CONTROL (pb
));
1535 /* Go to mode 000 */
1536 frob_econtrol (pb
, 0xe0, ECR_SPP
<< 5);
1541 outb (0xc, CONTROL (pb
));
1545 #ifdef CONFIG_PARPORT_1284
1546 /* Detect PS/2 support.
1548 * Bit 5 (0x20) sets the PS/2 data direction; setting this high
1549 * allows us to read data from the data lines. In theory we would get back
1550 * 0xff but any peripheral attached to the port may drag some or all of the
1551 * lines down to zero. So if we get back anything that isn't the contents
1552 * of the data register we deem PS/2 support to be present.
1554 * Some SPP ports have "half PS/2" ability - you can't turn off the line
1555 * drivers, but an external peripheral with sufficiently beefy drivers of
1556 * its own can overpower them and assert its own levels onto the bus, from
1557 * where they can then be read back as normal. Ports with this property
1558 * and the right type of device attached are likely to fail the SPP test,
1559 * (as they will appear to have stuck bits) and so the fact that they might
1560 * be misdetected here is rather academic.
1563 static int __devinit
parport_PS2_supported(struct parport
*pb
)
1567 clear_epp_timeout(pb
);
1569 /* try to tri-state the buffer */
1570 parport_pc_data_reverse (pb
);
1572 parport_pc_write_data(pb
, 0x55);
1573 if (parport_pc_read_data(pb
) != 0x55) ok
++;
1575 parport_pc_write_data(pb
, 0xaa);
1576 if (parport_pc_read_data(pb
) != 0xaa) ok
++;
1578 /* cancel input mode */
1579 parport_pc_data_forward (pb
);
1582 pb
->modes
|= PARPORT_MODE_TRISTATE
;
1584 struct parport_pc_private
*priv
= pb
->private_data
;
1585 priv
->ctr_writable
&= ~0x20;
1591 static int __devinit
parport_ECP_supported(struct parport
*pb
)
1594 int config
, configb
;
1596 struct parport_pc_private
*priv
= pb
->private_data
;
1597 int intrline
[]={0,7,9,10,11,14,15,5}; /* Translate ECP
1601 /* If there is no ECR, we have no hope of supporting ECP. */
1605 /* Find out FIFO depth */
1606 outb (ECR_SPP
<< 5, ECONTROL (pb
)); /* Reset FIFO */
1607 outb (ECR_TST
<< 5, ECONTROL (pb
)); /* TEST FIFO */
1608 for (i
=0; i
< 1024 && !(inb (ECONTROL (pb
)) & 0x02); i
++)
1609 outb (0xaa, FIFO (pb
));
1612 * Using LGS chipset it uses ECR register, but
1613 * it doesn't support ECP or FIFO MODE
1616 outb (ECR_SPP
<< 5, ECONTROL (pb
));
1620 priv
->fifo_depth
= i
;
1621 printk (KERN_INFO
"0x%lx: FIFO is %d bytes\n", pb
->base
, i
);
1623 /* Find out writeIntrThreshold */
1624 frob_econtrol (pb
, 1<<2, 1<<2);
1625 frob_econtrol (pb
, 1<<2, 0);
1626 for (i
= 1; i
<= priv
->fifo_depth
; i
++) {
1629 if (inb (ECONTROL (pb
)) & (1<<2))
1633 if (i
<= priv
->fifo_depth
)
1634 printk (KERN_INFO
"0x%lx: writeIntrThreshold is %d\n",
1637 /* Number of bytes we know we can write if we get an
1641 priv
->writeIntrThreshold
= i
;
1643 /* Find out readIntrThreshold */
1644 frob_econtrol (pb
, 0xe0, ECR_PS2
<< 5); /* Reset FIFO and enable PS2 */
1645 parport_pc_data_reverse (pb
); /* Must be in PS2 mode */
1646 frob_econtrol (pb
, 0xe0, ECR_TST
<< 5); /* Test FIFO */
1647 frob_econtrol (pb
, 1<<2, 1<<2);
1648 frob_econtrol (pb
, 1<<2, 0);
1649 for (i
= 1; i
<= priv
->fifo_depth
; i
++) {
1650 outb (0xaa, FIFO (pb
));
1651 if (inb (ECONTROL (pb
)) & (1<<2))
1655 if (i
<= priv
->fifo_depth
)
1656 printk (KERN_INFO
"0x%lx: readIntrThreshold is %d\n",
1659 /* Number of bytes we can read if we get an interrupt. */
1662 priv
->readIntrThreshold
= i
;
1664 outb (ECR_SPP
<< 5, ECONTROL (pb
)); /* Reset FIFO */
1665 outb (0xf4, ECONTROL (pb
)); /* Configuration mode */
1666 config
= inb (CONFIGA (pb
));
1667 pword
= (config
>> 4) & 0x7;
1671 printk (KERN_WARNING
"0x%lx: Unsupported pword size!\n",
1676 printk (KERN_WARNING
"0x%lx: Unsupported pword size!\n",
1680 printk (KERN_WARNING
"0x%lx: Unknown implementation ID\n",
1686 priv
->pword
= pword
;
1687 printk (KERN_DEBUG
"0x%lx: PWord is %d bits\n", pb
->base
, 8 * pword
);
1689 printk (KERN_DEBUG
"0x%lx: Interrupts are ISA-%s\n", pb
->base
,
1690 config
& 0x80 ? "Level" : "Pulses");
1692 configb
= inb (CONFIGB (pb
));
1693 if (!(configb
& 0x40)) {
1694 printk (KERN_WARNING
"0x%lx: possible IRQ conflict!\n",
1696 pb
->irq
= PARPORT_IRQ_NONE
;
1698 printk (KERN_DEBUG
"0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n",
1699 pb
->base
, config
, configb
);
1700 printk (KERN_DEBUG
"0x%lx: ECP settings irq=", pb
->base
);
1701 if ((configb
>>3) & 0x07)
1702 printk("%d",intrline
[(configb
>>3) & 0x07]);
1704 printk("<none or set by other means>");
1706 if( (configb
& 0x03 ) == 0x00)
1707 printk("<none or set by other means>\n");
1709 printk("%d\n",configb
& 0x07);
1711 /* Go back to mode 000 */
1712 frob_econtrol (pb
, 0xe0, ECR_SPP
<< 5);
1713 pb
->modes
|= PARPORT_MODE_ECP
| PARPORT_MODE_COMPAT
;
1718 static int __devinit
parport_ECPPS2_supported(struct parport
*pb
)
1720 const struct parport_pc_private
*priv
= pb
->private_data
;
1727 oecr
= inb (ECONTROL (pb
));
1728 outb (ECR_PS2
<< 5, ECONTROL (pb
));
1730 result
= parport_PS2_supported(pb
);
1732 outb (oecr
, ECONTROL (pb
));
1736 /* EPP mode detection */
1738 static int __devinit
parport_EPP_supported(struct parport
*pb
)
1740 const struct parport_pc_private
*priv
= pb
->private_data
;
1744 * Bit 0 of STR is the EPP timeout bit, this bit is 0
1745 * when EPP is possible and is set high when an EPP timeout
1746 * occurs (EPP uses the HALT line to stop the CPU while it does
1747 * the byte transfer, an EPP timeout occurs if the attached
1748 * device fails to respond after 10 micro seconds).
1750 * This bit is cleared by either reading it (National Semi)
1751 * or writing a 1 to the bit (SMC, UMC, WinBond), others ???
1752 * This bit is always high in non EPP modes.
1755 /* If EPP timeout bit clear then EPP available */
1756 if (!clear_epp_timeout(pb
))
1757 return 0; /* No way to clear timeout */
1759 /* Check for Intel bug. */
1762 for (i
= 0x00; i
< 0x80; i
+= 0x20) {
1763 outb (i
, ECONTROL (pb
));
1764 if (clear_epp_timeout (pb
))
1765 /* Phony EPP in ECP. */
1770 pb
->modes
|= PARPORT_MODE_EPP
;
1772 /* Set up access functions to use EPP hardware. */
1773 pb
->ops
->epp_read_data
= parport_pc_epp_read_data
;
1774 pb
->ops
->epp_write_data
= parport_pc_epp_write_data
;
1775 pb
->ops
->epp_read_addr
= parport_pc_epp_read_addr
;
1776 pb
->ops
->epp_write_addr
= parport_pc_epp_write_addr
;
1781 static int __devinit
parport_ECPEPP_supported(struct parport
*pb
)
1783 struct parport_pc_private
*priv
= pb
->private_data
;
1790 oecr
= inb (ECONTROL (pb
));
1791 /* Search for SMC style EPP+ECP mode */
1792 outb (0x80, ECONTROL (pb
));
1793 outb (0x04, CONTROL (pb
));
1794 result
= parport_EPP_supported(pb
);
1796 outb (oecr
, ECONTROL (pb
));
1799 /* Set up access functions to use ECP+EPP hardware. */
1800 pb
->ops
->epp_read_data
= parport_pc_ecpepp_read_data
;
1801 pb
->ops
->epp_write_data
= parport_pc_ecpepp_write_data
;
1802 pb
->ops
->epp_read_addr
= parport_pc_ecpepp_read_addr
;
1803 pb
->ops
->epp_write_addr
= parport_pc_ecpepp_write_addr
;
1809 #else /* No IEEE 1284 support */
1811 /* Don't bother probing for modes we know we won't use. */
1812 static int __devinit
parport_PS2_supported(struct parport
*pb
) { return 0; }
1813 static int __devinit
parport_ECP_supported(struct parport
*pb
) { return 0; }
1814 static int __devinit
parport_EPP_supported(struct parport
*pb
) { return 0; }
1815 static int __devinit
parport_ECPEPP_supported(struct parport
*pb
){return 0;}
1816 static int __devinit
parport_ECPPS2_supported(struct parport
*pb
){return 0;}
1818 #endif /* No IEEE 1284 support */
1820 /* --- IRQ detection -------------------------------------- */
1822 /* Only if supports ECP mode */
1823 static int __devinit
programmable_irq_support(struct parport
*pb
)
1826 unsigned char oecr
= inb (ECONTROL (pb
));
1827 static const int lookup
[8] = {
1828 PARPORT_IRQ_NONE
, 7, 9, 10, 11, 14, 15, 5
1831 outb (ECR_CNF
<< 5, ECONTROL (pb
)); /* Configuration MODE */
1833 intrLine
= (inb (CONFIGB (pb
)) >> 3) & 0x07;
1834 irq
= lookup
[intrLine
];
1836 outb (oecr
, ECONTROL (pb
));
1840 static int __devinit
irq_probe_ECP(struct parport
*pb
)
1846 irqs
= probe_irq_on();
1848 outb (ECR_SPP
<< 5, ECONTROL (pb
)); /* Reset FIFO */
1849 outb ((ECR_TST
<< 5) | 0x04, ECONTROL (pb
));
1850 outb (ECR_TST
<< 5, ECONTROL (pb
));
1852 /* If Full FIFO sure that writeIntrThreshold is generated */
1853 for (i
=0; i
< 1024 && !(inb (ECONTROL (pb
)) & 0x02) ; i
++)
1854 outb (0xaa, FIFO (pb
));
1856 pb
->irq
= probe_irq_off(irqs
);
1857 outb (ECR_SPP
<< 5, ECONTROL (pb
));
1860 pb
->irq
= PARPORT_IRQ_NONE
;
1866 * This detection seems that only works in National Semiconductors
1867 * This doesn't work in SMC, LGS, and Winbond
1869 static int __devinit
irq_probe_EPP(struct parport
*pb
)
1871 #ifndef ADVANCED_DETECT
1872 return PARPORT_IRQ_NONE
;
1877 if (pb
->modes
& PARPORT_MODE_PCECR
)
1878 oecr
= inb (ECONTROL (pb
));
1881 irqs
= probe_irq_on();
1883 if (pb
->modes
& PARPORT_MODE_PCECR
)
1884 frob_econtrol (pb
, 0x10, 0x10);
1886 clear_epp_timeout(pb
);
1887 parport_pc_frob_control (pb
, 0x20, 0x20);
1888 parport_pc_frob_control (pb
, 0x10, 0x10);
1889 clear_epp_timeout(pb
);
1891 /* Device isn't expecting an EPP read
1892 * and generates an IRQ.
1894 parport_pc_read_epp(pb
);
1897 pb
->irq
= probe_irq_off (irqs
);
1898 if (pb
->modes
& PARPORT_MODE_PCECR
)
1899 outb (oecr
, ECONTROL (pb
));
1900 parport_pc_write_control(pb
, 0xc);
1903 pb
->irq
= PARPORT_IRQ_NONE
;
1906 #endif /* Advanced detection */
1909 static int __devinit
irq_probe_SPP(struct parport
*pb
)
1911 /* Don't even try to do this. */
1912 return PARPORT_IRQ_NONE
;
1915 /* We will attempt to share interrupt requests since other devices
1916 * such as sound cards and network cards seem to like using the
1919 * When ECP is available we can autoprobe for IRQs.
1920 * NOTE: If we can autoprobe it, we can register the IRQ.
1922 static int __devinit
parport_irq_probe(struct parport
*pb
)
1924 const struct parport_pc_private
*priv
= pb
->private_data
;
1927 pb
->irq
= programmable_irq_support(pb
);
1930 if (pb
->modes
& PARPORT_MODE_ECP
)
1931 pb
->irq
= irq_probe_ECP(pb
);
1933 if (pb
->irq
== PARPORT_IRQ_NONE
&& priv
->ecr
&&
1934 (pb
->modes
& PARPORT_MODE_EPP
))
1935 pb
->irq
= irq_probe_EPP(pb
);
1937 clear_epp_timeout(pb
);
1939 if (pb
->irq
== PARPORT_IRQ_NONE
&& (pb
->modes
& PARPORT_MODE_EPP
))
1940 pb
->irq
= irq_probe_EPP(pb
);
1942 clear_epp_timeout(pb
);
1944 if (pb
->irq
== PARPORT_IRQ_NONE
)
1945 pb
->irq
= irq_probe_SPP(pb
);
1947 if (pb
->irq
== PARPORT_IRQ_NONE
)
1948 pb
->irq
= get_superio_irq(pb
);
1953 /* --- DMA detection -------------------------------------- */
1955 /* Only if chipset conforms to ECP ISA Interface Standard */
1956 static int __devinit
programmable_dma_support (struct parport
*p
)
1958 unsigned char oecr
= inb (ECONTROL (p
));
1961 frob_econtrol (p
, 0xe0, ECR_CNF
<< 5);
1963 dma
= inb (CONFIGB(p
)) & 0x07;
1964 /* 000: Indicates jumpered 8-bit DMA if read-only.
1965 100: Indicates jumpered 16-bit DMA if read-only. */
1966 if ((dma
& 0x03) == 0)
1967 dma
= PARPORT_DMA_NONE
;
1969 outb (oecr
, ECONTROL (p
));
1973 static int __devinit
parport_dma_probe (struct parport
*p
)
1975 const struct parport_pc_private
*priv
= p
->private_data
;
1977 p
->dma
= programmable_dma_support(p
); /* ask ECP chipset first */
1978 if (p
->dma
== PARPORT_DMA_NONE
)
1979 /* ask known Super-IO chips proper, although these
1980 claim ECP compatible, some don't report their DMA
1981 conforming to ECP standards */
1982 p
->dma
= get_superio_dma(p
);
1987 /* --- Initialisation code -------------------------------- */
1989 struct parport
*__devinit
parport_pc_probe_port (unsigned long int base
,
1990 unsigned long int base_hi
,
1992 struct pci_dev
*dev
)
1994 struct parport_pc_private
*priv
;
1995 struct parport_operations
*ops
;
1997 struct parport
*p
= &tmp
;
1998 int probedirq
= PARPORT_IRQ_NONE
;
1999 if (check_region(base
, 3)) return NULL
;
2000 priv
= kmalloc (sizeof (struct parport_pc_private
), GFP_KERNEL
);
2002 printk (KERN_DEBUG
"parport (0x%lx): no memory!\n", base
);
2005 ops
= kmalloc (sizeof (struct parport_operations
), GFP_KERNEL
);
2007 printk (KERN_DEBUG
"parport (0x%lx): no memory for ops!\n",
2012 memcpy (ops
, &parport_pc_ops
, sizeof (struct parport_operations
));
2014 priv
->ctr_writable
= 0xff;
2016 priv
->fifo_depth
= 0;
2018 priv
->dma_handle
= 0;
2021 p
->base_hi
= base_hi
;
2024 p
->modes
= PARPORT_MODE_PCSPP
| PARPORT_MODE_SAFEININT
;
2026 p
->private_data
= priv
;
2028 if (base_hi
&& !check_region(base_hi
,3)) {
2029 parport_ECR_present(p
);
2030 parport_ECP_supported(p
);
2032 if (base
!= 0x3bc) {
2033 if (!check_region(base
+0x3, 5)) {
2034 if (!parport_EPP_supported(p
))
2035 parport_ECPEPP_supported(p
);
2038 if (!parport_SPP_supported (p
)) {
2044 parport_ECPPS2_supported(p
);
2046 parport_PS2_supported (p
);
2048 if (!(p
= parport_register_port(base
, PARPORT_IRQ_NONE
,
2049 PARPORT_DMA_NONE
, ops
))) {
2055 p
->base_hi
= base_hi
;
2056 p
->modes
= tmp
.modes
;
2057 p
->size
= (p
->modes
& PARPORT_MODE_EPP
)?8:3;
2058 p
->private_data
= priv
;
2060 printk(KERN_INFO
"%s: PC-style at 0x%lx", p
->name
, p
->base
);
2061 if (p
->base_hi
&& (p
->modes
& PARPORT_MODE_ECP
))
2062 printk(" (0x%lx)", p
->base_hi
);
2065 if (p
->irq
== PARPORT_IRQ_AUTO
) {
2066 p
->irq
= PARPORT_IRQ_NONE
;
2067 parport_irq_probe(p
);
2068 } else if (p
->irq
== PARPORT_IRQ_PROBEONLY
) {
2069 p
->irq
= PARPORT_IRQ_NONE
;
2070 parport_irq_probe(p
);
2072 p
->irq
= PARPORT_IRQ_NONE
;
2074 if (p
->irq
!= PARPORT_IRQ_NONE
) {
2075 printk(", irq %d", p
->irq
);
2077 if (p
->dma
== PARPORT_DMA_AUTO
) {
2078 p
->dma
= PARPORT_DMA_NONE
;
2079 parport_dma_probe(p
);
2082 if (p
->dma
== PARPORT_DMA_AUTO
) /* To use DMA, giving the irq
2083 is mandatory (see above) */
2084 p
->dma
= PARPORT_DMA_NONE
;
2086 #ifdef CONFIG_PARPORT_PC_FIFO
2087 if (p
->dma
!= PARPORT_DMA_NOFIFO
&&
2088 priv
->fifo_depth
> 0 && p
->irq
!= PARPORT_IRQ_NONE
) {
2089 p
->ops
->compat_write_data
= parport_pc_compat_write_block_pio
;
2090 #ifdef CONFIG_PARPORT_1284
2091 p
->ops
->ecp_write_data
= parport_pc_ecp_write_block_pio
;
2092 #endif /* IEEE 1284 support */
2093 if (p
->dma
!= PARPORT_DMA_NONE
) {
2094 printk(", dma %d", p
->dma
);
2095 p
->modes
|= PARPORT_MODE_DMA
;
2097 else printk(", using FIFO");
2100 /* We can't use the DMA channel after all. */
2101 p
->dma
= PARPORT_DMA_NONE
;
2102 #endif /* Allowed to use FIFO/DMA */
2105 #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
2109 printmode(TRISTATE
);
2117 if (probedirq
!= PARPORT_IRQ_NONE
)
2118 printk(KERN_INFO
"%s: irq %d detected\n", p
->name
, probedirq
);
2119 parport_proc_register(p
);
2121 request_region (p
->base
, 3, p
->name
);
2123 request_region (p
->base
+ 3, p
->size
- 3, p
->name
);
2124 if (p
->modes
& PARPORT_MODE_ECP
)
2125 request_region (p
->base_hi
, 3, p
->name
);
2127 if (p
->irq
!= PARPORT_IRQ_NONE
) {
2128 if (request_irq (p
->irq
, parport_pc_interrupt
,
2130 printk (KERN_WARNING
"%s: irq %d in use, "
2131 "resorting to polled operation\n",
2133 p
->irq
= PARPORT_IRQ_NONE
;
2134 p
->dma
= PARPORT_DMA_NONE
;
2137 #ifdef CONFIG_PARPORT_PC_FIFO
2138 if (p
->dma
!= PARPORT_DMA_NONE
) {
2139 if (request_dma (p
->dma
, p
->name
)) {
2140 printk (KERN_WARNING
"%s: dma %d in use, "
2141 "resorting to PIO operation\n",
2143 p
->dma
= PARPORT_DMA_NONE
;
2146 pci_alloc_consistent(priv
->dev
,
2149 if (! priv
->dma_buf
) {
2150 printk (KERN_WARNING
"%s: "
2151 "cannot get buffer for DMA, "
2152 "resorting to PIO operation\n",
2155 p
->dma
= PARPORT_DMA_NONE
;
2159 #endif /* CONFIG_PARPORT_PC_FIFO */
2162 /* Done probing. Now put the port into a sensible start-up state. */
2165 * Put the ECP detected port in PS2 mode.
2166 * Do this also for ports that have ECR but don't do ECP.
2168 outb (0x34, ECONTROL (p
));
2170 parport_pc_write_data(p
, 0);
2171 parport_pc_data_forward (p
);
2173 /* Now that we've told the sharing engine about the port, and
2174 found out its characteristics, let the high-level drivers
2176 parport_announce_port (p
);
2182 /* Via support maintained by Jeff Garzik <jgarzik@mandrakesoft.com> */
2183 static int __devinit
sio_via_686a_probe (struct pci_dev
*pdev
)
2186 unsigned port1
, port2
, have_eppecp
;
2189 * unlock super i/o configuration, set 0x85_1
2191 pci_read_config_byte (pdev
, 0x85, &tmp
);
2193 pci_write_config_byte (pdev
, 0x85, tmp
);
2196 * Super I/O configuration, index port == 3f0h, data port == 3f1h
2199 /* 0xE2_1-0: Parallel Port Mode / Enable */
2203 if ((tmp
& 0x03) == 0x03) {
2204 printk (KERN_INFO
"parport_pc: Via 686A parallel port disabled in BIOS\n");
2208 /* 0xE6: Parallel Port I/O Base Address, bits 9-2 */
2210 port1
= inb (0x3F1) << 2;
2213 case 0x3bc: port2
= 0x7bc; break;
2214 case 0x378: port2
= 0x778; break;
2215 case 0x278: port2
= 0x678; break;
2217 printk (KERN_INFO
"parport_pc: Via 686A weird parport base 0x%X, ignoring\n",
2222 /* 0xF0_5: EPP+ECP enable */
2224 have_eppecp
= (inb (0x3F1) & (1 << 5));
2227 * lock super i/o configuration, clear 0x85_1
2229 pci_read_config_byte (pdev
, 0x85, &tmp
);
2231 pci_write_config_byte (pdev
, 0x85, tmp
);
2234 * Get DMA and IRQ from PCI->ISA bridge PCI config registers
2237 /* 0x50_3-2: PnP Routing for Parallel Port DRQ */
2238 pci_read_config_byte (pdev
, 0x50, &dma
);
2239 dma
= ((dma
>> 2) & 0x03);
2241 /* 0x51_7-4: PnP Routing for Parallel Port IRQ */
2242 pci_read_config_byte (pdev
, 0x51, &irq
);
2243 irq
= ((irq
>> 4) & 0x0F);
2245 /* filter bogus IRQs */
2246 /* 255 means NONE, and is bogus as well */
2253 irq
= PARPORT_IRQ_NONE
;
2256 default: /* do nothing */
2260 /* if ECP not enabled, DMA is not enabled, assumed bogus 'dma' value */
2261 /* 255 means NONE. Looks like some BIOS don't set the DMA correctly
2262 * even on ECP mode */
2263 if (!have_eppecp
|| dma
== 255)
2264 dma
= PARPORT_DMA_NONE
;
2266 /* finally, do the probe with values obtained */
2267 if (parport_pc_probe_port (port1
, port2
, irq
, dma
, NULL
)) {
2268 printk (KERN_INFO
"parport_pc: Via 686A parallel port: io=0x%X, irq=%d, dma=%d\n",
2273 printk (KERN_WARNING
"parport_pc: Strange, can't probe Via 686A parallel port: io=0x%X, irq=%d, dma=%d\n",
2279 enum parport_pc_sio_types
{
2280 sio_via_686a
= 0, /* Via VT82C686A motherboard Super I/O */
2284 /* each element directly indexed from enum list, above */
2285 static struct parport_pc_superio
{
2286 int (*probe
) (struct pci_dev
*pdev
);
2287 } parport_pc_superio_info
[] __devinitdata
= {
2288 { sio_via_686a_probe
, },
2292 enum parport_pc_pci_cards
{
2293 siig_1s1p_10x_550
= last_sio
,
2313 lava_parallel_dual_a
,
2314 lava_parallel_dual_b
,
2346 /* each element directly indexed from enum list, above
2347 * (but offset by last_sio) */
2348 static struct parport_pc_pci
{
2350 struct { /* BAR (base address registers) numbers in the config
2353 int hi
; /* -1 if not there, >6 for offset-method (max
2356 } cards
[] __devinitdata
= {
2357 /* siig_1s1p_10x_550 */ { 1, { { 3, 4 }, } },
2358 /* siig_1s1p_10x_650 */ { 1, { { 3, 4 }, } },
2359 /* siig_1s1p_10x_850 */ { 1, { { 3, 4 }, } },
2360 /* siig_1p_10x */ { 1, { { 2, 3 }, } },
2361 /* siig_2p_10x */ { 2, { { 2, 3 }, { 4, 5 }, } },
2362 /* siig_2s1p_10x_550 */ { 1, { { 4, 5 }, } },
2363 /* siig_2s1p_10x_650 */ { 1, { { 4, 5 }, } },
2364 /* siig_2s1p_10x_850 */ { 1, { { 4, 5 }, } },
2365 /* siig_1p_20x */ { 1, { { 0, 1 }, } },
2366 /* siig_2p_20x */ { 2, { { 0, 1 }, { 2, 3 }, } },
2367 /* siig_2p1s_20x_550 */ { 2, { { 1, 2 }, { 3, 4 }, } },
2368 /* siig_2p1s_20x_650 */ { 2, { { 1, 2 }, { 3, 4 }, } },
2369 /* siig_2p1s_20x_850 */ { 2, { { 1, 2 }, { 3, 4 }, } },
2370 /* siig_1s1p_20x_550 */ { 1, { { 1, 2 }, } },
2371 /* siig_1s1p_20x_650 */ { 1, { { 1, 2 }, } },
2372 /* siig_1s1p_20x_850 */ { 1, { { 1, 2 }, } },
2373 /* siig_2s1p_20x_550 */ { 1, { { 2, 3 }, } },
2374 /* siig_2s1p_20x_650 */ { 1, { { 2, 3 }, } },
2375 /* siig_2s1p_20x_850 */ { 1, { { 2, 3 }, } },
2376 /* lava_parallel */ { 1, { { 0, -1 }, } },
2377 /* lava_parallel_dual_a */ { 1, { { 0, -1 }, } },
2378 /* lava_parallel_dual_b */ { 1, { { 0, -1 }, } },
2379 /* boca_ioppar */ { 1, { { 0, -1 }, } },
2380 /* plx_9050 */ { 2, { { 4, -1 }, { 5, -1 }, } },
2381 /* afavlab_tk9902 */ { 1, { { 0, 1 }, } },
2382 /* timedia_4078a */ { 1, { { 2, -1 }, } },
2383 /* timedia_4079h */ { 1, { { 2, 3 }, } },
2384 /* timedia_4085h */ { 2, { { 2, -1 }, { 4, -1 }, } },
2385 /* timedia_4088a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2386 /* timedia_4089a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2387 /* timedia_4095a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2388 /* timedia_4096a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2389 /* timedia_4078u */ { 1, { { 2, -1 }, } },
2390 /* timedia_4079a */ { 1, { { 2, 3 }, } },
2391 /* timedia_4085u */ { 2, { { 2, -1 }, { 4, -1 }, } },
2392 /* timedia_4079r */ { 1, { { 2, 3 }, } },
2393 /* timedia_4079s */ { 1, { { 2, 3 }, } },
2394 /* timedia_4079d */ { 1, { { 2, 3 }, } },
2395 /* timedia_4079e */ { 1, { { 2, 3 }, } },
2396 /* timedia_4079f */ { 1, { { 2, 3 }, } },
2397 /* timedia_9079a */ { 1, { { 2, 3 }, } },
2398 /* timedia_9079b */ { 1, { { 2, 3 }, } },
2399 /* timedia_9079c */ { 1, { { 2, 3 }, } },
2400 /* timedia_4006a */ { 1, { { 0, -1 }, } },
2401 /* timedia_4014 */ { 2, { { 0, -1 }, { 2, -1 }, } },
2402 /* timedia_4008a */ { 1, { { 0, 1 }, } },
2403 /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2404 /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } },
2405 /* SYBA uses fixed offsets in
2407 /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
2408 /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } },
2411 static struct pci_device_id parport_pc_pci_tbl
[] __devinitdata
= {
2412 /* Super-IO onboard chips */
2413 { 0x1106, 0x0686, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, sio_via_686a
},
2416 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_550
,
2417 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_10x_550
},
2418 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_650
,
2419 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_10x_650
},
2420 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_850
,
2421 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_10x_850
},
2422 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1P_10x
,
2423 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1p_10x
},
2424 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P_10x
,
2425 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p_10x
},
2426 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_550
,
2427 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_10x_550
},
2428 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_650
,
2429 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_10x_650
},
2430 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_850
,
2431 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_10x_850
},
2432 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1P_20x
,
2433 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1p_20x
},
2434 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P_20x
,
2435 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p_20x
},
2436 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_550
,
2437 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p1s_20x_550
},
2438 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_650
,
2439 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p1s_20x_650
},
2440 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_850
,
2441 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2p1s_20x_850
},
2442 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_550
,
2443 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x_550
},
2444 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_650
,
2445 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_20x_650
},
2446 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_850
,
2447 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_1s1p_20x_850
},
2448 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_550
,
2449 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x_550
},
2450 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_650
,
2451 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x_650
},
2452 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_850
,
2453 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, siig_2s1p_20x_850
},
2454 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_PARALLEL
,
2455 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, lava_parallel
},
2456 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_DUAL_PAR_A
,
2457 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, lava_parallel_dual_a
},
2458 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_DUAL_PAR_B
,
2459 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, lava_parallel_dual_b
},
2460 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR
,
2461 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, boca_ioppar
},
2462 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_9050
,
2463 PCI_SUBVENDOR_ID_EXSYS
, PCI_SUBDEVICE_ID_EXSYS_4014
, 0,0, plx_9050
},
2464 { PCI_VENDOR_ID_AFAVLAB
, PCI_DEVICE_ID_AFAVLAB_TK9902
,
2465 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, afavlab_tk9902
},
2466 /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
2467 { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a
},
2468 { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h
},
2469 { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h
},
2470 { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a
},
2471 { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a
},
2472 { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a
},
2473 { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a
},
2474 { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u
},
2475 { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a
},
2476 { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u
},
2477 { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r
},
2478 { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s
},
2479 { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d
},
2480 { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e
},
2481 { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f
},
2482 { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a
},
2483 { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b
},
2484 { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c
},
2485 { 0x1409, 0x7268, 0x1409, 0x0101, 0, 0, timedia_4006a
},
2486 { 0x1409, 0x7268, 0x1409, 0x0102, 0, 0, timedia_4014
},
2487 { 0x1409, 0x7268, 0x1409, 0x0103, 0, 0, timedia_4008a
},
2488 { 0x1409, 0x7268, 0x1409, 0x0104, 0, 0, timedia_4018
},
2489 { 0x1409, 0x7268, 0x1409, 0x9018, 0, 0, timedia_9018a
},
2490 { PCI_VENDOR_ID_SYBA
, PCI_DEVICE_ID_SYBA_2P_EPP
,
2491 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, syba_2p_epp
},
2492 { PCI_VENDOR_ID_SYBA
, PCI_DEVICE_ID_SYBA_1P_ECP
,
2493 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, syba_1p_ecp
},
2494 { 0, } /* terminate list */
2496 MODULE_DEVICE_TABLE(pci
,parport_pc_pci_tbl
);
2498 static int __devinit
parport_pc_pci_probe (struct pci_dev
*dev
,
2499 const struct pci_device_id
*id
)
2501 int err
, count
, n
, i
= id
->driver_data
;
2503 /* This is an onboard Super-IO and has already been probed */
2506 /* This is a PCI card */
2509 if ((err
= pci_enable_device (dev
)) != 0)
2512 for (n
= 0; n
< cards
[i
].numports
; n
++) {
2513 int lo
= cards
[i
].addr
[n
].lo
;
2514 int hi
= cards
[i
].addr
[n
].hi
;
2515 unsigned long io_lo
, io_hi
;
2516 io_lo
= pci_resource_start (dev
, lo
);
2518 if ((hi
>= 0) && (hi
<= 6))
2519 io_hi
= pci_resource_start (dev
, hi
);
2521 io_lo
+= hi
; /* Reinterpret the meaning of
2522 "hi" as an offset (see SYBA
2524 /* TODO: test if sharing interrupts works */
2525 printk (KERN_DEBUG
"PCI parallel port detected: %04x:%04x, "
2526 "I/O at %#lx(%#lx)\n",
2527 parport_pc_pci_tbl
[i
+ last_sio
].vendor
,
2528 parport_pc_pci_tbl
[i
+ last_sio
].device
, io_lo
, io_hi
);
2529 if (parport_pc_probe_port (io_lo
, io_hi
, PARPORT_IRQ_NONE
,
2530 PARPORT_DMA_NONE
, dev
))
2534 return count
== 0 ? -ENODEV
: 0;
2537 static struct pci_driver parport_pc_pci_driver
= {
2539 id_table
: parport_pc_pci_tbl
,
2540 probe
: parport_pc_pci_probe
,
2543 static int __init
parport_pc_init_superio (void)
2546 const struct pci_device_id
*id
;
2547 struct pci_dev
*pdev
;
2549 pci_for_each_dev(pdev
) {
2550 id
= pci_match_device (parport_pc_pci_tbl
, pdev
);
2551 if (id
== NULL
|| id
->driver_data
>= last_sio
)
2554 return parport_pc_superio_info
[id
->driver_data
].probe (pdev
);
2556 #endif /* CONFIG_PCI */
2558 return 0; /* zero devices found */
2561 /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
2562 static int __init
__attribute__((unused
))
2563 parport_pc_find_isa_ports (int autoirq
, int autodma
)
2567 if (parport_pc_probe_port(0x3bc, 0x7bc, autoirq
, autodma
, NULL
))
2569 if (parport_pc_probe_port(0x378, 0x778, autoirq
, autodma
, NULL
))
2571 if (parport_pc_probe_port(0x278, 0x678, autoirq
, autodma
, NULL
))
2577 /* This function is called by parport_pc_init if the user didn't
2578 * specify any ports to probe. Its job is to find some ports. Order
2579 * is important here -- we want ISA ports to be registered first,
2580 * followed by PCI cards (for least surprise), but before that we want
2581 * to do chipset-specific tests for some onboard ports that we know
2584 * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
2585 * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
2587 static int __init
parport_pc_find_ports (int autoirq
, int autodma
)
2591 #ifdef CONFIG_PARPORT_PC_SUPERIO
2592 detect_and_report_winbond ();
2593 detect_and_report_smsc ();
2596 /* Onboard SuperIO chipsets that show themselves on the PCI bus. */
2597 count
+= parport_pc_init_superio ();
2599 /* ISA ports and whatever (see asm/parport.h). */
2600 count
+= parport_pc_find_nonpci_ports (autoirq
, autodma
);
2602 r
= pci_register_driver (&parport_pc_pci_driver
);
2609 int __init
parport_pc_init (int *io
, int *io_hi
, int *irq
, int *dma
)
2611 int count
= 0, i
= 0;
2614 /* Only probe the ports we were given. */
2617 if (!*io_hi
) *io_hi
= 0x400 + *io
;
2618 if (parport_pc_probe_port(*(io
++), *(io_hi
++),
2619 *(irq
++), *(dma
++), NULL
))
2621 } while (*io
&& (++i
< PARPORT_PC_MAX_PORTS
));
2623 count
+= parport_pc_find_ports (irq
[0], dma
[0]);
2629 /* Exported symbols. */
2630 #ifdef CONFIG_PARPORT_PC_PCMCIA
2632 /* parport_cs needs this in order to dyncamically get us to find ports. */
2633 EXPORT_SYMBOL (parport_pc_probe_port
);
2642 static int io
[PARPORT_PC_MAX_PORTS
+1] = { [0 ... PARPORT_PC_MAX_PORTS
] = 0 };
2643 static int io_hi
[PARPORT_PC_MAX_PORTS
+1] = { [0 ... PARPORT_PC_MAX_PORTS
] = 0 };
2644 static int dmaval
[PARPORT_PC_MAX_PORTS
] = { [0 ... PARPORT_PC_MAX_PORTS
-1] = PARPORT_DMA_AUTO
};
2645 static int irqval
[PARPORT_PC_MAX_PORTS
] = { [0 ... PARPORT_PC_MAX_PORTS
-1] = PARPORT_IRQ_PROBEONLY
};
2646 static const char *irq
[PARPORT_PC_MAX_PORTS
] = { NULL
, };
2647 static const char *dma
[PARPORT_PC_MAX_PORTS
] = { NULL
, };
2649 MODULE_AUTHOR("Phil Blundell, Tim Waugh, others");
2650 MODULE_DESCRIPTION("PC-style parallel port driver");
2651 MODULE_PARM_DESC(io
, "Base I/O address (SPP regs)");
2652 MODULE_PARM(io
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "i");
2653 MODULE_PARM_DESC(io_hi
, "Base I/O address (ECR)");
2654 MODULE_PARM(io_hi
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "i");
2655 MODULE_PARM_DESC(irq
, "IRQ line");
2656 MODULE_PARM(irq
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "s");
2657 MODULE_PARM_DESC(dma
, "DMA channel");
2658 MODULE_PARM(dma
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "s");
2660 int init_module(void)
2662 /* Work out how many ports we have, then get parport_share to parse
2665 for (i
= 0; i
< PARPORT_PC_MAX_PORTS
&& io
[i
]; i
++);
2667 if (parport_parse_irqs(i
, irq
, irqval
)) return 1;
2668 if (parport_parse_dmas(i
, dma
, dmaval
)) return 1;
2671 /* The user can make us use any IRQs or DMAs we find. */
2674 if (irq
[0] && !parport_parse_irqs (1, irq
, &val
))
2676 case PARPORT_IRQ_NONE
:
2677 case PARPORT_IRQ_AUTO
:
2681 if (dma
[0] && !parport_parse_dmas (1, dma
, &val
))
2683 case PARPORT_DMA_NONE
:
2684 case PARPORT_DMA_AUTO
:
2689 return !parport_pc_init (io
, io_hi
, irqval
, dmaval
);
2692 void cleanup_module(void)
2694 /* We ought to keep track of which ports are actually ours. */
2695 struct parport
*p
= parport_enumerate(), *tmp
;
2697 if (!user_specified
)
2698 pci_unregister_driver (&parport_pc_pci_driver
);
2702 if (p
->modes
& PARPORT_MODE_PCSPP
) {
2703 struct parport_pc_private
*priv
= p
->private_data
;
2704 struct parport_operations
*ops
= p
->ops
;
2705 if (p
->dma
!= PARPORT_DMA_NONE
)
2707 if (p
->irq
!= PARPORT_IRQ_NONE
)
2708 free_irq(p
->irq
, p
);
2709 release_region(p
->base
, 3);
2711 release_region(p
->base
+ 3, p
->size
- 3);
2712 if (p
->modes
& PARPORT_MODE_ECP
)
2713 release_region(p
->base_hi
, 3);
2714 parport_proc_unregister(p
);
2716 pci_free_consistent(priv
->dev
, PAGE_SIZE
,
2719 kfree (p
->private_data
);
2720 parport_unregister_port(p
);
2721 kfree (ops
); /* hope no-one cached it */