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>
73 /* frob_control, but for ECR */
74 static void frob_econtrol (struct parport
*pb
, unsigned char m
,
77 unsigned char ectr
= inb (ECONTROL (pb
));
79 printk (KERN_DEBUG
"frob_econtrol(%02x,%02x): %02x -> %02x\n",
80 m
, v
, ectr
, (ectr
& ~m
) ^ v
);
82 outb ((ectr
& ~m
) ^ v
, ECONTROL (pb
));
85 #ifdef CONFIG_PARPORT_PC_FIFO
86 /* Safely change the mode bits in the ECR */
87 static int change_mode(struct parport
*p
, int m
)
89 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
90 int ecr
= ECONTROL(p
);
95 printk (KERN_DEBUG
"change_mode: but there's no ECR!\n");
99 /* Bits <7:5> contain the mode. */
101 mode
= (oecr
>> 5) & 0x7;
102 if (mode
== m
) return 0;
104 if (mode
>= 2 && !(priv
->ctr
& 0x20)) {
105 /* This mode resets the FIFO, so we may
106 * have to wait for it to drain first. */
107 long expire
= jiffies
+ p
->physport
->cad
->timeout
;
110 case ECR_PPF
: /* Parallel Port FIFO mode */
111 case ECR_ECP
: /* ECP Parallel Port mode */
112 /* Busy wait for 200us */
113 for (counter
= 0; counter
< 40; counter
++) {
114 if (inb (ECONTROL (p
)) & 0x01)
116 if (signal_pending (current
)) break;
121 while (!(inb (ECONTROL (p
)) & 0x01)) {
122 if (time_after_eq (jiffies
, expire
))
123 /* The FIFO is stuck. */
125 current
->state
= TASK_INTERRUPTIBLE
;
126 schedule_timeout ((HZ
+ 99) / 100);
127 if (signal_pending (current
))
133 if (mode
>= 2 && m
>= 2) {
134 /* We have to go through mode 001 */
136 oecr
|= ECR_PS2
<< 5;
147 #ifdef CONFIG_PARPORT_1284
148 /* Find FIFO lossage; FIFO is reset */
149 static int get_fifo_residue (struct parport
*p
)
153 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
155 /* Prevent further data transfer. */
156 parport_frob_control (p
,
157 PARPORT_CONTROL_STROBE
,
158 PARPORT_CONTROL_STROBE
);
160 /* Adjust for the contents of the FIFO. */
161 for (residue
= priv
->fifo_depth
; ; residue
--) {
162 if (inb (ECONTROL (p
)) & 0x2)
169 printk (KERN_DEBUG
"%s: %d PWords were left in FIFO\n", p
->name
,
172 /* Reset the FIFO. */
173 frob_econtrol (p
, 0xe0, ECR_PS2
<< 5);
174 parport_frob_control (p
, PARPORT_CONTROL_STROBE
, 0);
176 /* Now change to config mode and clean up. FIXME */
177 frob_econtrol (p
, 0xe0, ECR_CNF
<< 5);
178 cnfga
= inb (CONFIGA (p
));
179 printk (KERN_DEBUG
"%s: cnfgA contains 0x%02x\n", p
->name
, cnfga
);
181 if (!(cnfga
& (1<<2))) {
182 printk (KERN_DEBUG
"%s: Accounting for extra byte\n", p
->name
);
186 /* Don't care about partial PWords until support is added for
187 * PWord != 1 byte. */
189 /* Back to PS2 mode. */
190 frob_econtrol (p
, 0xe0, ECR_PS2
<< 5);
194 #endif /* IEEE 1284 support */
195 #endif /* FIFO support */
198 * Clear TIMEOUT BIT in EPP MODE
200 * This is also used in SPP detection.
202 static int clear_epp_timeout(struct parport
*pb
)
206 if (!(parport_pc_read_status(pb
) & 0x01))
209 /* To clear timeout some chips require double read */
210 parport_pc_read_status(pb
);
211 r
= parport_pc_read_status(pb
);
212 outb (r
| 0x01, STATUS (pb
)); /* Some reset by writing 1 */
213 outb (r
& 0xfe, STATUS (pb
)); /* Others by writing 0 */
214 r
= parport_pc_read_status(pb
);
222 * Most of these aren't static because they may be used by the
223 * parport_xxx_yyy macros. extern __inline__ versions of several
224 * of these are in parport_pc.h.
227 static void parport_pc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
229 parport_generic_irq(irq
, (struct parport
*) dev_id
, regs
);
232 void parport_pc_write_data(struct parport
*p
, unsigned char d
)
237 unsigned char parport_pc_read_data(struct parport
*p
)
239 return inb (DATA (p
));
242 void parport_pc_write_control(struct parport
*p
, unsigned char d
)
244 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
245 PARPORT_CONTROL_AUTOFD
|
246 PARPORT_CONTROL_INIT
|
247 PARPORT_CONTROL_SELECT
);
249 /* Take this out when drivers have adapted to the newer interface. */
251 printk (KERN_DEBUG
"%s (%s): use data_reverse for this!\n",
252 p
->name
, p
->cad
->name
);
253 parport_pc_data_reverse (p
);
256 __parport_pc_frob_control (p
, wm
, d
& wm
);
259 unsigned char parport_pc_read_control(struct parport
*p
)
261 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
262 PARPORT_CONTROL_AUTOFD
|
263 PARPORT_CONTROL_INIT
|
264 PARPORT_CONTROL_SELECT
);
265 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
266 return priv
->ctr
& wm
; /* Use soft copy */
269 unsigned char parport_pc_frob_control (struct parport
*p
, unsigned char mask
,
272 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
273 PARPORT_CONTROL_AUTOFD
|
274 PARPORT_CONTROL_INIT
|
275 PARPORT_CONTROL_SELECT
);
277 /* Take this out when drivers have adapted to the newer interface. */
279 printk (KERN_DEBUG
"%s (%s): use data_%s for this!\n",
280 p
->name
, p
->cad
->name
,
281 (val
& 0x20) ? "reverse" : "forward");
283 parport_pc_data_reverse (p
);
285 parport_pc_data_forward (p
);
288 /* Restrict mask and val to control lines. */
292 return __parport_pc_frob_control (p
, mask
, val
);
295 unsigned char parport_pc_read_status(struct parport
*p
)
297 return inb (STATUS (p
));
300 void parport_pc_disable_irq(struct parport
*p
)
302 __parport_pc_frob_control (p
, 0x10, 0);
305 void parport_pc_enable_irq(struct parport
*p
)
307 __parport_pc_frob_control (p
, 0x10, 0x10);
310 void parport_pc_data_forward (struct parport
*p
)
312 __parport_pc_frob_control (p
, 0x20, 0);
315 void parport_pc_data_reverse (struct parport
*p
)
317 __parport_pc_frob_control (p
, 0x20, 0x20);
320 void parport_pc_init_state(struct pardevice
*dev
, struct parport_state
*s
)
322 s
->u
.pc
.ctr
= 0xc | (dev
->irq_func
? 0x10 : 0x0);
326 void parport_pc_save_state(struct parport
*p
, struct parport_state
*s
)
328 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
329 s
->u
.pc
.ctr
= inb (CONTROL (p
));
331 s
->u
.pc
.ecr
= inb (ECONTROL (p
));
334 void parport_pc_restore_state(struct parport
*p
, struct parport_state
*s
)
336 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
337 outb (s
->u
.pc
.ctr
, CONTROL (p
));
339 outb (s
->u
.pc
.ecr
, ECONTROL (p
));
342 #ifdef CONFIG_PARPORT_1284
343 static size_t parport_pc_epp_read_data (struct parport
*port
, void *buf
,
344 size_t length
, int flags
)
347 for (; got
< length
; got
++) {
348 *((char*)buf
)++ = inb (EPPDATA(port
));
349 if (inb (STATUS(port
)) & 0x01) {
350 clear_epp_timeout (port
);
358 static size_t parport_pc_epp_write_data (struct parport
*port
, const void *buf
,
359 size_t length
, int flags
)
362 for (; written
< length
; written
++) {
363 outb (*((char*)buf
)++, EPPDATA(port
));
364 if (inb (STATUS(port
)) & 0x01) {
365 clear_epp_timeout (port
);
373 static size_t parport_pc_epp_read_addr (struct parport
*port
, void *buf
,
374 size_t length
, int flags
)
377 for (; got
< length
; got
++) {
378 *((char*)buf
)++ = inb (EPPADDR (port
));
379 if (inb (STATUS (port
)) & 0x01) {
380 clear_epp_timeout (port
);
388 static size_t parport_pc_epp_write_addr (struct parport
*port
,
389 const void *buf
, size_t length
,
393 for (; written
< length
; written
++) {
394 outb (*((char*)buf
)++, EPPADDR (port
));
395 if (inb (STATUS (port
)) & 0x01) {
396 clear_epp_timeout (port
);
404 static size_t parport_pc_ecpepp_read_data (struct parport
*port
, void *buf
,
405 size_t length
, int flags
)
409 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
410 got
= parport_pc_epp_read_data (port
, buf
, length
, flags
);
411 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
416 static size_t parport_pc_ecpepp_write_data (struct parport
*port
,
417 const void *buf
, size_t length
,
422 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
423 written
= parport_pc_epp_write_data (port
, buf
, length
, flags
);
424 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
429 static size_t parport_pc_ecpepp_read_addr (struct parport
*port
, void *buf
,
430 size_t length
, int flags
)
434 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
435 got
= parport_pc_epp_read_addr (port
, buf
, length
, flags
);
436 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
441 static size_t parport_pc_ecpepp_write_addr (struct parport
*port
,
442 const void *buf
, size_t length
,
447 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
448 written
= parport_pc_epp_write_addr (port
, buf
, length
, flags
);
449 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
453 #endif /* IEEE 1284 support */
455 #ifdef CONFIG_PARPORT_PC_FIFO
456 static size_t parport_pc_fifo_write_block_pio (struct parport
*port
,
457 const void *buf
, size_t length
)
460 const unsigned char *bufp
= buf
;
461 size_t left
= length
;
462 long expire
= jiffies
+ port
->physport
->cad
->timeout
;
463 const int fifo
= FIFO (port
);
464 int poll_for
= 8; /* 80 usecs */
465 const struct parport_pc_private
*priv
= port
->physport
->private_data
;
466 const int fifo_depth
= priv
->fifo_depth
;
468 port
= port
->physport
;
470 /* We don't want to be interrupted every character. */
471 parport_pc_disable_irq (port
);
472 frob_econtrol (port
, (1<<4), (1<<4)); /* nErrIntrEn */
475 parport_pc_data_forward (port
); /* Must be in PS2 mode */
479 unsigned char ecrval
= inb (ECONTROL (port
));
482 if (current
->need_resched
&& time_before (jiffies
, expire
))
483 /* Can't yield the port. */
486 /* Anyone else waiting for the port? */
487 if (port
->waithead
) {
488 printk (KERN_DEBUG
"Somebody wants the port\n");
493 /* FIFO is full. Wait for interrupt. */
495 /* Clear serviceIntr */
496 outb (ecrval
& ~(1<<2), ECONTROL (port
));
498 ret
= parport_wait_event (port
, HZ
);
501 if (!time_before (jiffies
, expire
)) {
503 printk (KERN_DEBUG
"Timed out\n");
506 ecrval
= inb (ECONTROL (port
));
507 if (!(ecrval
& (1<<2))) {
508 if (current
->need_resched
&&
509 time_before (jiffies
, expire
))
518 /* Can't fail now. */
519 expire
= jiffies
+ port
->cad
->timeout
;
522 if (signal_pending (current
))
526 /* FIFO is empty. Blast it full. */
527 const int n
= left
< fifo_depth
? left
: fifo_depth
;
528 outsb (fifo
, bufp
, n
);
532 /* Adjust the poll time. */
533 if (i
< (poll_for
- 2)) poll_for
--;
535 } else if (i
++ < poll_for
) {
537 ecrval
= inb (ECONTROL (port
));
541 /* Half-full (call me an optimist) */
547 return length
- left
;
550 static size_t parport_pc_fifo_write_block_dma (struct parport
*port
,
551 const void *buf
, size_t length
)
554 unsigned long dmaflag
;
555 size_t left
= length
;
556 const struct parport_pc_private
*priv
= port
->physport
->private_data
;
558 port
= port
->physport
;
560 /* We don't want to be interrupted every character. */
561 parport_pc_disable_irq (port
);
562 frob_econtrol (port
, (1<<4), (1<<4)); /* nErrIntrEn */
565 parport_pc_data_forward (port
); /* Must be in PS2 mode */
568 long expire
= jiffies
+ port
->physport
->cad
->timeout
;
572 if (count
> PAGE_SIZE
)
575 memcpy(priv
->dma_buf
, buf
, count
);
577 dmaflag
= claim_dma_lock();
578 disable_dma(port
->dma
);
579 clear_dma_ff(port
->dma
);
580 set_dma_mode(port
->dma
, DMA_MODE_WRITE
);
581 set_dma_addr(port
->dma
, virt_to_bus((volatile char *) priv
->dma_buf
));
582 set_dma_count(port
->dma
, count
);
585 frob_econtrol (port
, 1<<3, 1<<3);
587 /* Clear serviceIntr */
588 frob_econtrol (port
, 1<<2, 0);
590 enable_dma(port
->dma
);
591 release_dma_lock(dmaflag
);
593 /* assume DMA will be successful */
597 /* Wait for interrupt. */
599 ret
= parport_wait_event (port
, HZ
);
602 if (!time_before (jiffies
, expire
)) {
604 printk (KERN_DEBUG
"Timed out\n");
607 /* Is serviceIntr set? */
608 if (!(inb (ECONTROL (port
)) & (1<<2))) {
609 if (current
->need_resched
)
615 dmaflag
= claim_dma_lock();
616 disable_dma(port
->dma
);
617 clear_dma_ff(port
->dma
);
618 count
= get_dma_residue(port
->dma
);
619 release_dma_lock(dmaflag
);
621 if (current
->need_resched
)
622 /* Can't yield the port. */
625 /* Anyone else waiting for the port? */
626 if (port
->waithead
) {
627 printk (KERN_DEBUG
"Somebody wants the port\n");
631 /* update for possible DMA residue ! */
636 /* Maybe got here through break, so adjust for DMA residue! */
637 dmaflag
= claim_dma_lock();
638 disable_dma(port
->dma
);
639 clear_dma_ff(port
->dma
);
640 left
+= get_dma_residue(port
->dma
);
641 release_dma_lock(dmaflag
);
643 /* Turn off DMA mode */
644 frob_econtrol (port
, 1<<3, 0);
646 return length
- left
;
649 /* Parallel Port FIFO mode (ECP chipsets) */
650 size_t parport_pc_compat_write_block_pio (struct parport
*port
,
651 const void *buf
, size_t length
,
656 /* Special case: a timeout of zero means we cannot call schedule(). */
657 if (!port
->physport
->cad
->timeout
)
658 return parport_ieee1284_write_compat (port
, buf
,
661 /* Set up parallel port FIFO mode.*/
662 parport_pc_data_forward (port
); /* Must be in PS2 mode */
663 change_mode (port
, ECR_PPF
); /* Parallel port FIFO */
664 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_DATA
;
666 /* Write the data to the FIFO. */
667 if (port
->dma
!= PARPORT_DMA_NONE
)
668 written
= parport_pc_fifo_write_block_dma (port
, buf
, length
);
670 written
= parport_pc_fifo_write_block_pio (port
, buf
, length
);
673 if (change_mode (port
, ECR_PS2
) == -EBUSY
) {
674 const struct parport_pc_private
*priv
=
675 port
->physport
->private_data
;
677 printk (KERN_DEBUG
"%s: FIFO is stuck\n", port
->name
);
679 /* Prevent further data transfer. */
680 parport_frob_control (port
,
681 PARPORT_CONTROL_STROBE
,
682 PARPORT_CONTROL_STROBE
);
684 /* Adjust for the contents of the FIFO. */
685 for (written
-= priv
->fifo_depth
; ; written
++) {
686 if (inb (ECONTROL (port
)) & 0x2)
690 outb (0, FIFO (port
));
693 /* Reset the FIFO and return to PS2 mode. */
694 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
696 /* De-assert strobe. */
697 parport_frob_control (port
, PARPORT_CONTROL_STROBE
, 0);
700 parport_wait_peripheral (port
,
702 PARPORT_STATUS_BUSY
);
703 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_IDLE
;
709 #ifdef CONFIG_PARPORT_1284
710 size_t parport_pc_ecp_write_block_pio (struct parport
*port
,
711 const void *buf
, size_t length
,
716 /* Special case: a timeout of zero means we cannot call schedule(). */
717 if (!port
->physport
->cad
->timeout
)
718 return parport_ieee1284_ecp_write_data (port
, buf
,
721 /* Switch to forward mode if necessary. */
722 if (port
->physport
->ieee1284
.phase
!= IEEE1284_PH_FWD_IDLE
) {
723 /* Event 47: Set nInit high. */
724 parport_frob_control (port
, PARPORT_CONTROL_INIT
, 0);
726 /* Event 40: PError goes high. */
727 parport_wait_peripheral (port
,
728 PARPORT_STATUS_PAPEROUT
,
729 PARPORT_STATUS_PAPEROUT
);
732 /* Set up ECP parallel port mode.*/
733 parport_pc_data_forward (port
); /* Must be in PS2 mode */
734 change_mode (port
, ECR_ECP
); /* ECP FIFO */
735 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_DATA
;
737 /* Write the data to the FIFO. */
738 if (port
->dma
!= PARPORT_DMA_NONE
)
739 written
= parport_pc_fifo_write_block_dma (port
, buf
, length
);
741 written
= parport_pc_fifo_write_block_pio (port
, buf
, length
);
744 if (change_mode (port
, ECR_PS2
) == -EBUSY
) {
745 const struct parport_pc_private
*priv
=
746 port
->physport
->private_data
;
748 printk (KERN_DEBUG
"%s: FIFO is stuck\n", port
->name
);
750 /* Prevent further data transfer. */
751 parport_frob_control (port
,
752 PARPORT_CONTROL_STROBE
,
753 PARPORT_CONTROL_STROBE
);
755 /* Adjust for the contents of the FIFO. */
756 for (written
-= priv
->fifo_depth
; ; written
++) {
757 if (inb (ECONTROL (port
)) & 0x2)
761 outb (0, FIFO (port
));
764 /* Reset the FIFO and return to PS2 mode. */
765 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
767 /* De-assert strobe. */
768 parport_frob_control (port
, PARPORT_CONTROL_STROBE
, 0);
770 /* Host transfer recovery. */
771 parport_pc_data_reverse (port
); /* Must be in PS2 mode */
773 parport_frob_control (port
, PARPORT_CONTROL_INIT
, 0);
774 parport_wait_peripheral (port
, PARPORT_STATUS_PAPEROUT
, 0);
775 parport_frob_control (port
,
776 PARPORT_CONTROL_INIT
,
777 PARPORT_CONTROL_INIT
);
778 parport_wait_peripheral (port
,
779 PARPORT_STATUS_PAPEROUT
,
780 PARPORT_STATUS_PAPEROUT
);
783 parport_wait_peripheral (port
,
785 PARPORT_STATUS_BUSY
);
786 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_IDLE
;
791 size_t parport_pc_ecp_read_block_pio (struct parport
*port
,
792 void *buf
, size_t length
, int flags
)
794 size_t left
= length
;
796 const int fifo
= FIFO(port
);
797 const struct parport_pc_private
*priv
= port
->physport
->private_data
;
798 const int fifo_depth
= priv
->fifo_depth
;
801 port
= port
->physport
;
803 /* Special case: a timeout of zero means we cannot call schedule(). */
804 if (!port
->cad
->timeout
)
805 return parport_ieee1284_ecp_read_data (port
, buf
,
808 fifofull
= fifo_depth
;
809 if (port
->ieee1284
.mode
== IEEE1284_MODE_ECPRLE
)
810 /* If the peripheral is allowed to send RLE compressed
811 * data, it is possible for a byte to expand to 128
812 * bytes in the FIFO. */
815 /* If the caller wants less than a full FIFO's worth of data,
816 * go through software emulation. Otherwise we may have to through
818 if (length
< fifofull
)
819 return parport_ieee1284_ecp_read_data (port
, buf
,
822 /* Switch to reverse mode if necessary. */
823 if (port
->ieee1284
.phase
!= IEEE1284_PH_REV_IDLE
) {
824 /* Event 38: Set nAutoFd low */
825 parport_frob_control (port
,
826 PARPORT_CONTROL_AUTOFD
,
827 PARPORT_CONTROL_AUTOFD
);
828 parport_pc_data_reverse (port
); /* Must be in PS2 mode */
831 /* Event 39: Set nInit low to initiate bus reversal */
832 parport_frob_control (port
,
833 PARPORT_CONTROL_INIT
,
836 /* Event 40: PError goes low */
837 parport_wait_peripheral (port
, PARPORT_STATUS_PAPEROUT
, 0);
840 /* Set up ECP parallel port mode.*/
841 parport_pc_data_reverse (port
); /* Must be in PS2 mode */
842 change_mode (port
, ECR_ECP
); /* ECP FIFO */
843 port
->ieee1284
.phase
= IEEE1284_PH_REV_DATA
;
845 /* Do the transfer. */
846 while (left
> fifofull
) {
848 long int expire
= jiffies
+ port
->cad
->timeout
;
849 unsigned char ecrval
= inb (ECONTROL (port
));
851 if (current
->need_resched
&& time_before (jiffies
, expire
))
852 /* Can't yield the port. */
855 /* At this point, the FIFO may already be full.
856 * Ideally, we'd be able to tell the port to hold on
857 * for a second while we empty the FIFO, and we'd be
858 * able to ensure that no data is lost. I'm not sure
859 * that's the case. :-( It might be that you can play
860 * games with STB, as in the forward case; someone should
861 * look at a datasheet. */
864 /* FIFO is empty. Wait for interrupt. */
866 /* Anyone else waiting for the port? */
867 if (port
->waithead
) {
869 "Somebody wants the port\n");
873 /* Clear serviceIntr */
874 outb (ecrval
& ~(1<<2), ECONTROL (port
));
876 ret
= parport_wait_event (port
, HZ
);
879 if (!time_before (jiffies
, expire
)) {
881 printk (KERN_DEBUG
"Timed out\n");
884 ecrval
= inb (ECONTROL (port
));
885 if (!(ecrval
& (1<<2))) {
886 if (current
->need_resched
&&
887 time_before (jiffies
, expire
))
898 insb (fifo
, bufp
, fifo_depth
);
904 *bufp
++ = inb (fifo
);
909 if (change_mode (port
, ECR_PS2
) == -EBUSY
) {
910 int lost
= get_fifo_residue (port
);
911 printk (KERN_DEBUG
"%s: DATA LOSS (%d bytes)!\n", port
->name
,
915 port
->ieee1284
.phase
= IEEE1284_PH_REV_IDLE
;
917 return length
- left
;
920 #endif /* IEEE 1284 support */
922 #endif /* Allowed to use FIFO/DMA */
924 void parport_pc_inc_use_count(void)
931 void parport_pc_dec_use_count(void)
938 struct parport_operations parport_pc_ops
=
940 parport_pc_write_data
,
941 parport_pc_read_data
,
943 parport_pc_write_control
,
944 parport_pc_read_control
,
945 parport_pc_frob_control
,
947 parport_pc_read_status
,
949 parport_pc_enable_irq
,
950 parport_pc_disable_irq
,
952 parport_pc_data_forward
,
953 parport_pc_data_reverse
,
955 parport_pc_init_state
,
956 parport_pc_save_state
,
957 parport_pc_restore_state
,
959 parport_pc_inc_use_count
,
960 parport_pc_dec_use_count
,
962 parport_ieee1284_epp_write_data
,
963 parport_ieee1284_epp_read_data
,
964 parport_ieee1284_epp_write_addr
,
965 parport_ieee1284_epp_read_addr
,
967 parport_ieee1284_ecp_write_data
,
968 parport_ieee1284_ecp_read_data
,
969 parport_ieee1284_ecp_write_addr
,
971 parport_ieee1284_write_compat
,
972 parport_ieee1284_read_nibble
,
973 parport_ieee1284_read_byte
,
976 /* --- Mode detection ------------------------------------- */
979 * Checks for port existence, all ports support SPP MODE
981 static int __maybe_init
parport_SPP_supported(struct parport
*pb
)
986 * first clear an eventually pending EPP timeout
987 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
988 * that does not even respond to SPP cycles if an EPP
991 clear_epp_timeout(pb
);
993 /* Do a simple read-write test to make sure the port exists. */
995 outb (w
, CONTROL (pb
));
997 /* Is there a control register that we can read from? Some
998 * ports don't allow reads, so read_control just returns a
999 * software copy. Some ports _do_ allow reads, so bypass the
1000 * software copy here. In addition, some bits aren't
1002 r
= inb (CONTROL (pb
));
1003 if ((r
& 0xf) == w
) {
1005 outb (w
, CONTROL (pb
));
1006 r
= inb (CONTROL (pb
));
1007 outb (0xc, CONTROL (pb
));
1009 return PARPORT_MODE_PCSPP
;
1013 /* That didn't work, but the user thinks there's a
1015 printk (KERN_DEBUG
"0x%lx: CTR: wrote 0x%02x, read 0x%02x\n",
1018 /* Try the data register. The data lines aren't tri-stated at
1019 * this stage, so we expect back what we wrote. */
1021 parport_pc_write_data (pb
, w
);
1022 r
= parport_pc_read_data (pb
);
1025 parport_pc_write_data (pb
, w
);
1026 r
= parport_pc_read_data (pb
);
1028 return PARPORT_MODE_PCSPP
;
1032 /* Didn't work, but the user is convinced this is the
1034 printk (KERN_DEBUG
"0x%lx: DATA: wrote 0x%02x, read 0x%02x\n",
1037 /* It's possible that we can't read the control register or
1038 * the data register. In that case just believe the user. */
1040 return PARPORT_MODE_PCSPP
;
1047 * Old style XT ports alias io ports every 0x400, hence accessing ECR
1048 * on these cards actually accesses the CTR.
1050 * Modern cards don't do this but reading from ECR will return 0xff
1051 * regardless of what is written here if the card does NOT support
1054 * We first check to see if ECR is the same as CTR. If not, the low
1055 * two bits of ECR aren't writable, so we check by writing ECR and
1056 * reading it back to see if it's what we expect.
1058 static int __maybe_init
parport_ECR_present(struct parport
*pb
)
1060 struct parport_pc_private
*priv
= pb
->private_data
;
1061 unsigned char r
= 0xc;
1063 outb (r
, CONTROL (pb
));
1064 if ((inb (ECONTROL (pb
)) & 0x3) == (r
& 0x3)) {
1065 outb (r
^ 0x2, CONTROL (pb
)); /* Toggle bit 1 */
1067 r
= inb (CONTROL (pb
));
1068 if ((inb (ECONTROL (pb
)) & 0x2) == (r
& 0x2))
1069 goto no_reg
; /* Sure that no ECR register exists */
1072 if ((inb (ECONTROL (pb
)) & 0x3 ) != 0x1)
1075 outb (0x34, ECONTROL (pb
));
1076 if (inb (ECONTROL (pb
)) != 0x35)
1080 outb (0xc, CONTROL (pb
));
1082 /* Go to mode 000 */
1083 frob_econtrol (pb
, 0xe0, ECR_SPP
<< 5);
1088 outb (0xc, CONTROL (pb
));
1092 #ifdef CONFIG_PARPORT_1284
1093 /* Detect PS/2 support.
1095 * Bit 5 (0x20) sets the PS/2 data direction; setting this high
1096 * allows us to read data from the data lines. In theory we would get back
1097 * 0xff but any peripheral attached to the port may drag some or all of the
1098 * lines down to zero. So if we get back anything that isn't the contents
1099 * of the data register we deem PS/2 support to be present.
1101 * Some SPP ports have "half PS/2" ability - you can't turn off the line
1102 * drivers, but an external peripheral with sufficiently beefy drivers of
1103 * its own can overpower them and assert its own levels onto the bus, from
1104 * where they can then be read back as normal. Ports with this property
1105 * and the right type of device attached are likely to fail the SPP test,
1106 * (as they will appear to have stuck bits) and so the fact that they might
1107 * be misdetected here is rather academic.
1110 static int __maybe_init
parport_PS2_supported(struct parport
*pb
)
1114 clear_epp_timeout(pb
);
1116 /* try to tri-state the buffer */
1117 parport_pc_data_reverse (pb
);
1119 parport_pc_write_data(pb
, 0x55);
1120 if (parport_pc_read_data(pb
) != 0x55) ok
++;
1122 parport_pc_write_data(pb
, 0xaa);
1123 if (parport_pc_read_data(pb
) != 0xaa) ok
++;
1125 /* cancel input mode */
1126 parport_pc_data_forward (pb
);
1129 pb
->modes
|= PARPORT_MODE_TRISTATE
;
1131 struct parport_pc_private
*priv
= pb
->private_data
;
1132 priv
->ctr_writable
&= ~0x20;
1138 static int __maybe_init
parport_ECP_supported(struct parport
*pb
)
1143 struct parport_pc_private
*priv
= pb
->private_data
;
1145 /* If there is no ECR, we have no hope of supporting ECP. */
1149 /* Find out FIFO depth */
1150 outb (ECR_SPP
<< 5, ECONTROL (pb
)); /* Reset FIFO */
1151 outb (ECR_TST
<< 5, ECONTROL (pb
)); /* TEST FIFO */
1152 for (i
=0; i
< 1024 && !(inb (ECONTROL (pb
)) & 0x02); i
++)
1153 outb (0xaa, FIFO (pb
));
1156 * Using LGS chipset it uses ECR register, but
1157 * it doesn't support ECP or FIFO MODE
1160 outb (ECR_SPP
<< 5, ECONTROL (pb
));
1164 priv
->fifo_depth
= i
;
1165 printk (KERN_INFO
"0x%lx: FIFO is %d bytes\n", pb
->base
, i
);
1167 /* Find out writeIntrThreshold */
1168 frob_econtrol (pb
, 1<<2, 1<<2);
1169 frob_econtrol (pb
, 1<<2, 0);
1170 for (i
= 1; i
<= priv
->fifo_depth
; i
++) {
1173 if (inb (ECONTROL (pb
)) & (1<<2))
1177 if (i
<= priv
->fifo_depth
)
1178 printk (KERN_INFO
"0x%lx: writeIntrThreshold is %d\n",
1181 /* Number of bytes we know we can write if we get an
1185 priv
->writeIntrThreshold
= i
;
1187 /* Find out readIntrThreshold */
1188 frob_econtrol (pb
, 0xe0, ECR_PS2
<< 5); /* Reset FIFO and enable PS2 */
1189 parport_pc_data_reverse (pb
); /* Must be in PS2 mode */
1190 frob_econtrol (pb
, 0xe0, ECR_TST
<< 5); /* Test FIFO */
1191 frob_econtrol (pb
, 1<<2, 1<<2);
1192 frob_econtrol (pb
, 1<<2, 0);
1193 for (i
= 1; i
<= priv
->fifo_depth
; i
++) {
1194 outb (0xaa, FIFO (pb
));
1195 if (inb (ECONTROL (pb
)) & (1<<2))
1199 if (i
<= priv
->fifo_depth
)
1200 printk (KERN_INFO
"0x%lx: readIntrThreshold is %d\n",
1203 /* Number of bytes we can read if we get an interrupt. */
1206 priv
->readIntrThreshold
= i
;
1208 outb (ECR_SPP
<< 5, ECONTROL (pb
)); /* Reset FIFO */
1209 outb (0xf4, ECONTROL (pb
)); /* Configuration mode */
1210 config
= inb (FIFO (pb
));
1211 pword
= (config
>> 4) & 0x7;
1215 printk (KERN_WARNING
"0x%lx: Unsupported pword size!\n",
1220 printk (KERN_WARNING
"0x%lx: Unsupported pword size!\n",
1224 printk (KERN_WARNING
"0x%lx: Unknown implementation ID\n",
1230 priv
->pword
= pword
;
1231 printk (KERN_DEBUG
"0x%lx: PWord is %d bits\n", pb
->base
, 8 * pword
);
1233 config
= inb (CONFIGB (pb
));
1234 printk (KERN_DEBUG
"0x%lx: Interrupts are ISA-%s\n", pb
->base
,
1235 config
& 0x80 ? "Level" : "Pulses");
1237 if (!(config
& 0x40)) {
1238 printk (KERN_WARNING
"0x%lx: IRQ conflict!\n", pb
->base
);
1239 pb
->irq
= PARPORT_IRQ_NONE
;
1242 /* Go back to mode 000 */
1243 frob_econtrol (pb
, 0xe0, ECR_SPP
<< 5);
1244 pb
->modes
|= PARPORT_MODE_ECP
;
1249 static int __maybe_init
parport_ECPPS2_supported(struct parport
*pb
)
1251 const struct parport_pc_private
*priv
= pb
->private_data
;
1258 oecr
= inb (ECONTROL (pb
));
1259 outb (ECR_PS2
<< 5, ECONTROL (pb
));
1261 result
= parport_PS2_supported(pb
);
1263 outb (oecr
, ECONTROL (pb
));
1267 /* EPP mode detection */
1269 static int __maybe_init
parport_EPP_supported(struct parport
*pb
)
1271 const struct parport_pc_private
*priv
= pb
->private_data
;
1275 * Bit 0 of STR is the EPP timeout bit, this bit is 0
1276 * when EPP is possible and is set high when an EPP timeout
1277 * occurs (EPP uses the HALT line to stop the CPU while it does
1278 * the byte transfer, an EPP timeout occurs if the attached
1279 * device fails to respond after 10 micro seconds).
1281 * This bit is cleared by either reading it (National Semi)
1282 * or writing a 1 to the bit (SMC, UMC, WinBond), others ???
1283 * This bit is always high in non EPP modes.
1286 /* If EPP timeout bit clear then EPP available */
1287 if (!clear_epp_timeout(pb
))
1288 return 0; /* No way to clear timeout */
1290 /* Check for Intel bug. */
1293 for (i
= 0x00; i
< 0x80; i
+= 0x20) {
1294 outb (i
, ECONTROL (pb
));
1295 if (clear_epp_timeout (pb
))
1296 /* Phony EPP in ECP. */
1301 pb
->modes
|= PARPORT_MODE_EPP
;
1303 /* Set up access functions to use EPP hardware. */
1304 pb
->ops
->epp_read_data
= parport_pc_epp_read_data
;
1305 pb
->ops
->epp_write_data
= parport_pc_epp_write_data
;
1306 pb
->ops
->epp_read_addr
= parport_pc_epp_read_addr
;
1307 pb
->ops
->epp_write_addr
= parport_pc_epp_write_addr
;
1312 static int __maybe_init
parport_ECPEPP_supported(struct parport
*pb
)
1314 struct parport_pc_private
*priv
= pb
->private_data
;
1321 oecr
= inb (ECONTROL (pb
));
1322 /* Search for SMC style EPP+ECP mode */
1323 outb (0x80, ECONTROL (pb
));
1325 result
= parport_EPP_supported(pb
);
1327 outb (oecr
, ECONTROL (pb
));
1330 /* Set up access functions to use ECP+EPP hardware. */
1331 pb
->ops
->epp_read_data
= parport_pc_ecpepp_read_data
;
1332 pb
->ops
->epp_write_data
= parport_pc_ecpepp_write_data
;
1333 pb
->ops
->epp_read_addr
= parport_pc_ecpepp_read_addr
;
1334 pb
->ops
->epp_write_addr
= parport_pc_ecpepp_write_addr
;
1340 #else /* No IEEE 1284 support */
1342 /* Don't bother probing for modes we know we won't use. */
1343 static int __maybe_init
parport_PS2_supported(struct parport
*pb
) { return 0; }
1344 static int __maybe_init
parport_ECP_supported(struct parport
*pb
) { return 0; }
1345 static int __maybe_init
parport_EPP_supported(struct parport
*pb
) { return 0; }
1346 static int __maybe_init
parport_ECPEPP_supported(struct parport
*pb
){return 0;}
1347 static int __maybe_init
parport_ECPPS2_supported(struct parport
*pb
){return 0;}
1349 #endif /* No IEEE 1284 support */
1351 /* --- IRQ detection -------------------------------------- */
1353 /* Only if supports ECP mode */
1354 static int __maybe_init
programmable_irq_support(struct parport
*pb
)
1357 unsigned char oecr
= inb (ECONTROL (pb
));
1358 static const int lookup
[8] = {
1359 PARPORT_IRQ_NONE
, 7, 9, 10, 11, 14, 15, 5
1362 outb (ECR_CNF
<< 5, ECONTROL (pb
)); /* Configuration MODE */
1364 intrLine
= (inb (CONFIGB (pb
)) >> 3) & 0x07;
1365 irq
= lookup
[intrLine
];
1367 outb (oecr
, ECONTROL (pb
));
1371 static int __maybe_init
irq_probe_ECP(struct parport
*pb
)
1377 irqs
= probe_irq_on();
1379 outb (ECR_SPP
<< 5, ECONTROL (pb
)); /* Reset FIFO */
1380 outb ((ECR_TST
<< 5) | 0x04, ECONTROL (pb
));
1381 outb (ECR_TST
<< 5, ECONTROL (pb
));
1383 /* If Full FIFO sure that writeIntrThreshold is generated */
1384 for (i
=0; i
< 1024 && !(inb (ECONTROL (pb
)) & 0x02) ; i
++)
1385 outb (0xaa, FIFO (pb
));
1387 pb
->irq
= probe_irq_off(irqs
);
1388 outb (ECR_SPP
<< 5, ECONTROL (pb
));
1391 pb
->irq
= PARPORT_IRQ_NONE
;
1397 * This detection seems that only works in National Semiconductors
1398 * This doesn't work in SMC, LGS, and Winbond
1400 static int __maybe_init
irq_probe_EPP(struct parport
*pb
)
1402 #ifndef ADVANCED_DETECT
1403 return PARPORT_IRQ_NONE
;
1408 if (pb
->modes
& PARPORT_MODE_PCECR
)
1409 oecr
= inb (ECONTROL (pb
));
1412 irqs
= probe_irq_on();
1414 if (pb
->modes
& PARPORT_MODE_PCECR
)
1415 frob_econtrol (pb
, 0x10, 0x10);
1417 clear_epp_timeout(pb
);
1418 parport_pc_frob_control (pb
, 0x20, 0x20);
1419 parport_pc_frob_control (pb
, 0x10, 0x10);
1420 clear_epp_timeout(pb
);
1422 /* Device isn't expecting an EPP read
1423 * and generates an IRQ.
1425 parport_pc_read_epp(pb
);
1428 pb
->irq
= probe_irq_off (irqs
);
1429 if (pb
->modes
& PARPORT_MODE_PCECR
)
1430 outb (oecr
, ECONTROL (pb
));
1431 parport_pc_write_control(pb
, 0xc);
1434 pb
->irq
= PARPORT_IRQ_NONE
;
1437 #endif /* Advanced detection */
1440 static int __maybe_init
irq_probe_SPP(struct parport
*pb
)
1442 /* Don't even try to do this. */
1443 return PARPORT_IRQ_NONE
;
1446 /* We will attempt to share interrupt requests since other devices
1447 * such as sound cards and network cards seem to like using the
1450 * When ECP is available we can autoprobe for IRQs.
1451 * NOTE: If we can autoprobe it, we can register the IRQ.
1453 static int __maybe_init
parport_irq_probe(struct parport
*pb
)
1455 const struct parport_pc_private
*priv
= pb
->private_data
;
1458 pb
->irq
= programmable_irq_support(pb
);
1459 if (pb
->irq
!= PARPORT_IRQ_NONE
)
1463 if (pb
->modes
& PARPORT_MODE_ECP
)
1464 pb
->irq
= irq_probe_ECP(pb
);
1466 if (pb
->irq
== PARPORT_IRQ_NONE
&& priv
->ecr
&&
1467 (pb
->modes
& PARPORT_MODE_EPP
))
1468 pb
->irq
= irq_probe_EPP(pb
);
1470 clear_epp_timeout(pb
);
1472 if (pb
->irq
== PARPORT_IRQ_NONE
&& (pb
->modes
& PARPORT_MODE_EPP
))
1473 pb
->irq
= irq_probe_EPP(pb
);
1475 clear_epp_timeout(pb
);
1477 if (pb
->irq
== PARPORT_IRQ_NONE
)
1478 pb
->irq
= irq_probe_SPP(pb
);
1484 /* --- DMA detection -------------------------------------- */
1486 /* Only if supports ECP mode */
1487 static int __maybe_init
programmable_dma_support (struct parport
*p
)
1489 unsigned char oecr
= inb (ECONTROL (p
));
1492 frob_econtrol (p
, 0xe0, ECR_CNF
<< 5);
1494 dma
= inb (CONFIGB(p
)) & 0x03;
1496 dma
= PARPORT_DMA_NONE
;
1498 outb (oecr
, ECONTROL (p
));
1502 static int __maybe_init
parport_dma_probe (struct parport
*p
)
1504 const struct parport_pc_private
*priv
= p
->private_data
;
1506 p
->dma
= programmable_dma_support(p
);
1511 /* --- Initialisation code -------------------------------- */
1513 struct parport
*__maybe_init
parport_pc_probe_port (unsigned long int base
,
1514 unsigned long int base_hi
,
1517 struct parport_pc_private
*priv
;
1518 struct parport_operations
*ops
;
1520 struct parport
*p
= &tmp
;
1521 int probedirq
= PARPORT_IRQ_NONE
;
1522 if (check_region(base
, 3)) return NULL
;
1523 priv
= kmalloc (sizeof (struct parport_pc_private
), GFP_KERNEL
);
1525 printk (KERN_DEBUG
"parport (0x%lx): no memory!\n", base
);
1528 ops
= kmalloc (sizeof (struct parport_operations
), GFP_KERNEL
);
1530 printk (KERN_DEBUG
"parport (0x%lx): no memory for ops!\n",
1535 memcpy (ops
, &parport_pc_ops
, sizeof (struct parport_operations
));
1537 priv
->ctr_writable
= 0xff;
1539 priv
->fifo_depth
= 0;
1542 p
->base_hi
= base_hi
;
1545 p
->modes
= PARPORT_MODE_PCSPP
| PARPORT_MODE_SAFEININT
;
1547 p
->private_data
= priv
;
1549 if (base_hi
&& !check_region(base_hi
,3)) {
1550 parport_ECR_present(p
);
1551 parport_ECP_supported(p
);
1553 if (base
!= 0x3bc) {
1554 if (!check_region(base
+0x3, 5)) {
1555 if (!parport_EPP_supported(p
))
1556 parport_ECPEPP_supported(p
);
1559 if (!parport_SPP_supported (p
)) {
1565 parport_ECPPS2_supported(p
);
1567 parport_PS2_supported (p
);
1569 if (!(p
= parport_register_port(base
, PARPORT_IRQ_NONE
,
1570 PARPORT_DMA_NONE
, ops
))) {
1576 p
->base_hi
= base_hi
;
1577 p
->modes
= tmp
.modes
;
1578 p
->size
= (p
->modes
& PARPORT_MODE_EPP
)?8:3;
1579 p
->private_data
= priv
;
1581 printk(KERN_INFO
"%s: PC-style at 0x%lx", p
->name
, p
->base
);
1582 if (p
->base_hi
&& (p
->modes
& PARPORT_MODE_ECP
))
1583 printk(" (0x%lx)", p
->base_hi
);
1586 if (p
->irq
== PARPORT_IRQ_AUTO
) {
1587 p
->irq
= PARPORT_IRQ_NONE
;
1588 parport_irq_probe(p
);
1589 } else if (p
->irq
== PARPORT_IRQ_PROBEONLY
) {
1590 p
->irq
= PARPORT_IRQ_NONE
;
1591 parport_irq_probe(p
);
1593 p
->irq
= PARPORT_IRQ_NONE
;
1595 if (p
->irq
!= PARPORT_IRQ_NONE
) {
1596 printk(", irq %d", p
->irq
);
1598 if (p
->dma
== PARPORT_DMA_AUTO
) {
1599 p
->dma
= PARPORT_DMA_NONE
;
1600 parport_dma_probe(p
);
1603 if (p
->dma
== PARPORT_DMA_AUTO
)
1604 p
->dma
= PARPORT_DMA_NONE
;
1606 #ifdef CONFIG_PARPORT_PC_FIFO
1607 if (p
->dma
!= PARPORT_DMA_NOFIFO
&&
1608 priv
->fifo_depth
> 0 && p
->irq
!= PARPORT_IRQ_NONE
) {
1609 p
->ops
->compat_write_data
= parport_pc_compat_write_block_pio
;
1610 #ifdef CONFIG_PARPORT_1284
1611 p
->ops
->ecp_write_data
= parport_pc_ecp_write_block_pio
;
1612 #endif /* IEEE 1284 support */
1613 if (p
->dma
!= PARPORT_DMA_NONE
) {
1614 printk(", dma %d", p
->dma
);
1615 p
->modes
|= PARPORT_MODE_DMA
;
1617 else printk(", using FIFO");
1620 /* We can't use the DMA channel after all. */
1621 p
->dma
= PARPORT_DMA_NONE
;
1622 #endif /* Allowed to use FIFO/DMA */
1625 #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
1629 printmode(TRISTATE
);
1637 if (probedirq
!= PARPORT_IRQ_NONE
)
1638 printk("%s: irq %d detected\n", p
->name
, probedirq
);
1639 parport_proc_register(p
);
1641 request_region (p
->base
, 3, p
->name
);
1643 request_region (p
->base
+ 3, p
->size
- 3, p
->name
);
1644 if (p
->modes
& PARPORT_MODE_ECP
)
1645 request_region (p
->base_hi
, 3, p
->name
);
1647 if (p
->irq
!= PARPORT_IRQ_NONE
) {
1648 if (request_irq (p
->irq
, parport_pc_interrupt
,
1650 printk (KERN_WARNING
"%s: irq %d in use, "
1651 "resorting to polled operation\n",
1653 p
->irq
= PARPORT_IRQ_NONE
;
1654 p
->dma
= PARPORT_DMA_NONE
;
1657 if (p
->dma
!= PARPORT_DMA_NONE
) {
1658 if (request_dma (p
->dma
, p
->name
)) {
1659 printk (KERN_WARNING
"%s: dma %d in use, "
1660 "resorting to PIO operation\n",
1662 p
->dma
= PARPORT_DMA_NONE
;
1665 (char *)__get_dma_pages(GFP_KERNEL
, 0);
1666 if (! priv
->dma_buf
) {
1667 printk (KERN_WARNING
"%s: "
1668 "cannot get buffer for DMA, "
1669 "resorting to PIO operation\n",
1672 p
->dma
= PARPORT_DMA_NONE
;
1678 /* Done probing. Now put the port into a sensible start-up state.
1679 * SELECT | INIT also puts IEEE1284-compliant devices into
1680 * compatibility mode. */
1683 * Put the ECP detected port in PS2 mode.
1684 * Do this also for ports that have ECR but don't do ECP.
1686 outb (0x34, ECONTROL (p
));
1688 parport_pc_write_data(p
, 0);
1689 parport_pc_data_forward (p
);
1690 parport_pc_write_control(p
, PARPORT_CONTROL_SELECT
);
1692 parport_pc_write_control(p
,
1693 PARPORT_CONTROL_SELECT
1694 | PARPORT_CONTROL_INIT
);
1697 /* Now that we've told the sharing engine about the port, and
1698 found out its characteristics, let the high-level drivers
1700 parport_announce_port (p
);
1705 /* Look for PCI parallel port cards. */
1706 static int __init
parport_pc_init_pci (int irq
, int dma
)
1709 unsigned int vendor
;
1710 unsigned int device
;
1711 unsigned int numports
;
1714 unsigned long hi
; /* -ve if not there */
1717 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_550
, 1,
1719 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_650
, 1,
1721 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_850
, 1,
1723 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1P_10x
, 1,
1725 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P_10x
, 2,
1726 { { 2, 3 }, { 4, 5 }, } },
1727 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_550
, 1,
1729 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_650
, 1,
1731 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_850
, 1,
1733 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1P_20x
, 1,
1735 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P_20x
, 2,
1736 { { 0, 1 }, { 2, 3 }, } },
1737 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_550
, 2,
1738 { { 1, 2 }, { 3, 4 }, } },
1739 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_650
, 2,
1740 { { 1, 2 }, { 3, 4 }, } },
1741 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_850
, 2,
1742 { { 1, 2 }, { 3, 4 }, } },
1743 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_550
, 1,
1745 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_650
, 1,
1747 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_850
, 1,
1749 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_550
, 1,
1751 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_650
, 1,
1753 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_850
, 1,
1755 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_PARALLEL
, 1,
1757 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_DUAL_PAR_A
, 1,
1759 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_DUAL_PAR_B
, 1,
1761 { PCI_VENDOR_ID_EXSYS
, PCI_DEVICE_ID_EXSYS_4014
, 2,
1762 { { 2, -1 }, { 3, -1 }, } },
1766 struct pci_dev
*pcidev
;
1770 if (!pci_present ())
1773 for (i
= 0; cards
[i
].vendor
; i
++) {
1775 while ((pcidev
= pci_find_device (cards
[i
].vendor
,
1779 for (n
= 0; n
< cards
[i
].numports
; n
++) {
1780 unsigned long lo
= cards
[i
].addr
[n
].lo
;
1781 unsigned long hi
= cards
[i
].addr
[n
].hi
;
1782 unsigned long io_lo
, io_hi
;
1783 io_lo
= pcidev
->resource
[lo
].start
;
1784 io_hi
= ((hi
< 0) ? 0 :
1785 pcidev
->resource
[hi
].start
);
1786 if (irq
== PARPORT_IRQ_AUTO
) {
1787 if (parport_pc_probe_port (io_lo
,
1792 } else if (parport_pc_probe_port (io_lo
, io_hi
,
1799 /* Look for parallel controllers that we don't know about. */
1800 for (pcidev
= pci_devices
; pcidev
; pcidev
= pcidev
->next
) {
1801 const int class_noprogif
= pcidev
->class & ~0xff;
1802 if (class_noprogif
!= (PCI_CLASS_COMMUNICATION_PARALLEL
<< 8))
1805 for (i
= 0; cards
[i
].vendor
; i
++)
1806 if ((cards
[i
].vendor
== pcidev
->vendor
) &&
1807 (cards
[i
].device
== pcidev
->device
))
1809 if (cards
[i
].vendor
)
1810 /* We know about this one. */
1814 "Unknown PCI parallel I/O card (%04x/%04x)\n"
1815 "Please send 'lspci' output to "
1816 "tim@cyberelk.demon.co.uk\n",
1817 pcidev
->vendor
, pcidev
->device
);
1823 /* Exported symbols. */
1824 #ifdef CONFIG_PARPORT_PC_PCMCIA
1826 /* parport_cs needs this in order to dyncamically get us to find ports. */
1827 EXPORT_SYMBOL (parport_pc_probe_port
);
1836 static int io
[PARPORT_PC_MAX_PORTS
+1] = { [0 ... PARPORT_PC_MAX_PORTS
] = 0 };
1837 static int io_hi
[PARPORT_PC_MAX_PORTS
+1] = { [0 ... PARPORT_PC_MAX_PORTS
] = 0 };
1838 static int dmaval
[PARPORT_PC_MAX_PORTS
] = { [0 ... PARPORT_PC_MAX_PORTS
-1] = PARPORT_DMA_AUTO
};
1839 static int irqval
[PARPORT_PC_MAX_PORTS
] = { [0 ... PARPORT_PC_MAX_PORTS
-1] = PARPORT_IRQ_PROBEONLY
};
1840 static const char *irq
[PARPORT_PC_MAX_PORTS
] = { NULL
, };
1841 static const char *dma
[PARPORT_PC_MAX_PORTS
] = { NULL
, };
1842 MODULE_PARM(io
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "i");
1843 MODULE_PARM(io_hi
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "i");
1844 MODULE_PARM(irq
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "s");
1845 MODULE_PARM(dma
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "s");
1847 int init_module(void)
1849 /* Work out how many ports we have, then get parport_share to parse
1852 for (i
= 0; i
< PARPORT_PC_MAX_PORTS
&& io
[i
]; i
++);
1854 if (parport_parse_irqs(i
, irq
, irqval
)) return 1;
1855 if (parport_parse_dmas(i
, dma
, dmaval
)) return 1;
1858 /* The user can make us use any IRQs or DMAs we find. */
1861 if (irq
[0] && !parport_parse_irqs (1, irq
, &val
))
1863 case PARPORT_IRQ_NONE
:
1864 case PARPORT_IRQ_AUTO
:
1868 if (dma
[0] && !parport_parse_dmas (1, dma
, &val
))
1870 case PARPORT_DMA_NONE
:
1871 case PARPORT_DMA_AUTO
:
1876 return (parport_pc_init(io
, io_hi
, irqval
, dmaval
)?0:1);
1879 void cleanup_module(void)
1881 struct parport
*p
= parport_enumerate(), *tmp
;
1884 if (p
->modes
& PARPORT_MODE_PCSPP
) {
1885 struct parport_pc_private
*priv
= p
->private_data
;
1886 struct parport_operations
*ops
= p
->ops
;
1887 if (p
->dma
!= PARPORT_DMA_NONE
)
1889 if (p
->irq
!= PARPORT_IRQ_NONE
)
1890 free_irq(p
->irq
, p
);
1891 release_region(p
->base
, 3);
1893 release_region(p
->base
+ 3, p
->size
- 3);
1894 if (p
->modes
& PARPORT_MODE_ECP
)
1895 release_region(p
->base_hi
, 3);
1896 parport_proc_unregister(p
);
1898 free_page((unsigned long) priv
->dma_buf
);
1899 kfree (p
->private_data
);
1900 parport_unregister_port(p
);
1901 kfree (ops
); /* hope no-one cached it */