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 * Better EPP probing - Carlos Henrique Bauer <chbauer@acm.org>
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
39 #include <linux/config.h>
40 #include <linux/module.h>
41 #include <linux/init.h>
42 #include <linux/sched.h>
43 #include <linux/delay.h>
44 #include <linux/errno.h>
45 #include <linux/interrupt.h>
46 #include <linux/ioport.h>
47 #include <linux/kernel.h>
48 #include <linux/malloc.h>
49 #include <linux/pci.h>
50 #include <linux/sysctl.h>
54 #include <asm/uaccess.h>
56 #include <linux/parport.h>
57 #include <linux/parport_pc.h>
59 /* Maximum number of ports to support. It is useless to set this greater
60 than PARPORT_MAX (in <linux/parport.h>). */
61 #define PARPORT_PC_MAX_PORTS 8
73 static int user_specified __initdata
= 0;
75 /* frob_control, but for ECR */
76 static void frob_econtrol (struct parport
*pb
, unsigned char m
,
79 outb ((inb (ECONTROL (pb
)) & ~m
) ^ v
, ECONTROL (pb
));
82 #ifdef CONFIG_PARPORT_1284
83 /* Safely change the mode bits in the ECR */
84 static int change_mode(struct parport
*p
, int m
)
86 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
87 int ecr
= ECONTROL(p
);
92 printk (KERN_DEBUG
"change_mode: but there's no ECR!\n");
96 /* Bits <7:5> contain the mode. */
98 mode
= (oecr
>> 5) & 0x7;
99 if (mode
== m
) return 0;
101 /* We have to go through mode 000 */
102 change_mode (p
, ECR_SPP
);
104 if (m
< 2 && !(parport_read_control (p
) & 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
))
140 /* Find FIFO lossage; FIFO is reset */
141 static int get_fifo_residue (struct parport
*p
)
145 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
147 /* Prevent further data transfer. */
148 parport_frob_control (p
,
149 PARPORT_CONTROL_STROBE
,
150 PARPORT_CONTROL_STROBE
);
152 /* Adjust for the contents of the FIFO. */
153 for (residue
= priv
->fifo_depth
; ; residue
--) {
154 if (inb (ECONTROL (p
)) & 0x2)
161 printk (KERN_DEBUG
"%s: %d PWords were left in FIFO\n", p
->name
,
164 /* Reset the FIFO. */
165 frob_econtrol (p
, 0xe0, 0x20);
166 parport_frob_control (p
, PARPORT_CONTROL_STROBE
, 0);
168 /* Now change to config mode and clean up. FIXME */
169 frob_econtrol (p
, 0xe0, 0xe0);
170 cnfga
= inb (CONFIGA (p
));
171 printk (KERN_DEBUG
"%s: cnfgA contains 0x%02x\n", p
->name
, cnfga
);
173 if (!(cnfga
& (1<<2))) {
174 printk (KERN_DEBUG
"%s: Accounting for extra byte\n", p
->name
);
178 /* Don't care about partial PWords until support is added for
179 * PWord != 1 byte. */
181 /* Back to PS2 mode. */
182 frob_econtrol (p
, 0xe0, 0x20);
187 #endif /* IEEE 1284 support */
190 * Clear TIMEOUT BIT in EPP MODE
192 * This is also used in SPP detection.
194 static int clear_epp_timeout(struct parport
*pb
)
198 if (!(parport_pc_read_status(pb
) & 0x01))
201 /* To clear timeout some chips require double read */
202 parport_pc_read_status(pb
);
203 r
= parport_pc_read_status(pb
);
204 outb (r
| 0x01, STATUS (pb
)); /* Some reset by writing 1 */
205 outb (r
& 0xfe, STATUS (pb
)); /* Others by writing 0 */
206 r
= parport_pc_read_status(pb
);
214 * These aren't static because they may be used by the parport_xxx_yyy
215 * macros. extern __inline__ versions of several of these are in
219 static void parport_pc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
221 parport_generic_irq(irq
, (struct parport
*) dev_id
, regs
);
224 void parport_pc_write_data(struct parport
*p
, unsigned char d
)
229 unsigned char parport_pc_read_data(struct parport
*p
)
231 return inb (DATA (p
));
234 unsigned char __frob_control (struct parport
*p
, unsigned char mask
,
237 struct parport_pc_private
*priv
= p
->physport
->private_data
;
238 unsigned char ctr
= priv
->ctr
;
239 ctr
= (ctr
& ~mask
) ^ val
;
240 ctr
&= priv
->ctr_writable
; /* only write writable bits. */
241 outb (ctr
, CONTROL (p
));
242 return priv
->ctr
= ctr
; /* update soft copy */
245 void parport_pc_write_control(struct parport
*p
, unsigned char d
)
247 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
248 PARPORT_CONTROL_AUTOFD
|
249 PARPORT_CONTROL_INIT
|
250 PARPORT_CONTROL_SELECT
);
252 /* Take this out when drivers have adapted to the newer interface. */
254 printk (KERN_DEBUG
"%s (%s): use data_reverse for this!\n",
255 p
->name
, p
->cad
->name
);
256 parport_pc_data_reverse (p
);
259 __frob_control (p
, wm
, d
& wm
);
262 unsigned char parport_pc_read_control(struct parport
*p
)
264 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
265 return priv
->ctr
; /* Use soft copy */
268 unsigned char parport_pc_frob_control (struct parport
*p
, unsigned char mask
,
271 const unsigned char wm
= (PARPORT_CONTROL_STROBE
|
272 PARPORT_CONTROL_AUTOFD
|
273 PARPORT_CONTROL_INIT
|
274 PARPORT_CONTROL_SELECT
);
276 /* Take this out when drivers have adapted to the newer interface. */
278 printk (KERN_DEBUG
"%s (%s): use data_reverse for this!\n",
279 p
->name
, p
->cad
->name
);
280 parport_pc_data_reverse (p
);
283 /* Restrict mask and val to control lines. */
287 return __frob_control (p
, mask
, val
);
290 unsigned char parport_pc_read_status(struct parport
*p
)
292 return inb (STATUS (p
));
295 void parport_pc_disable_irq(struct parport
*p
)
297 __frob_control (p
, 0x10, 0);
300 void parport_pc_enable_irq(struct parport
*p
)
302 __frob_control (p
, 0x10, 0x10);
305 void parport_pc_data_forward (struct parport
*p
)
307 __frob_control (p
, 0x20, 0);
310 void parport_pc_data_reverse (struct parport
*p
)
312 __frob_control (p
, 0x20, 0x20);
315 void parport_pc_init_state(struct pardevice
*dev
, struct parport_state
*s
)
317 struct parport_pc_private
*priv
= dev
->port
->physport
->private_data
;
318 priv
->ctr
= s
->u
.pc
.ctr
= 0xc | (dev
->irq_func
? 0x10 : 0x0);
322 void parport_pc_save_state(struct parport
*p
, struct parport_state
*s
)
324 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
325 s
->u
.pc
.ctr
= inb (CONTROL (p
));
327 s
->u
.pc
.ecr
= inb (ECONTROL (p
));
330 void parport_pc_restore_state(struct parport
*p
, struct parport_state
*s
)
332 const struct parport_pc_private
*priv
= p
->physport
->private_data
;
333 outb (s
->u
.pc
.ctr
, CONTROL (p
));
335 outb (s
->u
.pc
.ecr
, ECONTROL (p
));
338 #ifdef CONFIG_PARPORT_1284
339 static size_t parport_pc_epp_read_data (struct parport
*port
, void *buf
,
340 size_t length
, int flags
)
343 for (; got
< length
; got
++) {
344 *((char*)buf
)++ = inb (EPPDATA(port
));
345 if (inb (STATUS(port
)) & 0x01) {
346 clear_epp_timeout (port
);
354 static size_t parport_pc_epp_write_data (struct parport
*port
, const void *buf
,
355 size_t length
, int flags
)
358 for (; written
< length
; written
++) {
359 outb (*((char*)buf
)++, EPPDATA(port
));
360 if (inb (STATUS(port
)) & 0x01) {
361 clear_epp_timeout (port
);
369 static size_t parport_pc_epp_read_addr (struct parport
*port
, void *buf
,
370 size_t length
, int flags
)
373 for (; got
< length
; got
++) {
374 *((char*)buf
)++ = inb (EPPADDR (port
));
375 if (inb (STATUS (port
)) & 0x01) {
376 clear_epp_timeout (port
);
384 static size_t parport_pc_epp_write_addr (struct parport
*port
,
385 const void *buf
, size_t length
,
389 for (; written
< length
; written
++) {
390 outb (*((char*)buf
)++, EPPADDR (port
));
391 if (inb (STATUS (port
)) & 0x01) {
392 clear_epp_timeout (port
);
400 static size_t parport_pc_ecpepp_read_data (struct parport
*port
, void *buf
,
401 size_t length
, int flags
)
405 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
406 got
= parport_pc_epp_read_data (port
, buf
, length
, flags
);
407 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
412 static size_t parport_pc_ecpepp_write_data (struct parport
*port
,
413 const void *buf
, size_t length
,
418 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
419 written
= parport_pc_epp_write_data (port
, buf
, length
, flags
);
420 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
425 static size_t parport_pc_ecpepp_read_addr (struct parport
*port
, void *buf
,
426 size_t length
, int flags
)
430 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
431 got
= parport_pc_epp_read_addr (port
, buf
, length
, flags
);
432 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
437 static size_t parport_pc_ecpepp_write_addr (struct parport
*port
,
438 const void *buf
, size_t length
,
443 frob_econtrol (port
, 0xe0, ECR_EPP
<< 5);
444 written
= parport_pc_epp_write_addr (port
, buf
, length
, flags
);
445 frob_econtrol (port
, 0xe0, ECR_PS2
<< 5);
449 #endif /* IEEE 1284 support */
451 #ifdef CONFIG_PARPORT_PC_FIFO
452 static size_t parport_pc_fifo_write_block_pio (struct parport
*port
,
453 const void *buf
, size_t length
)
456 const unsigned char *bufp
= buf
;
457 size_t left
= length
;
458 long expire
= jiffies
+ port
->physport
->cad
->timeout
;
459 const int fifo
= FIFO (port
);
460 int poll_for
= 8; /* 80 usecs */
461 const struct parport_pc_private
*priv
= port
->physport
->private_data
;
462 const int fifo_depth
= priv
->fifo_depth
;
464 port
= port
->physport
;
466 /* We don't want to be interrupted every character. */
467 parport_pc_disable_irq (port
);
468 frob_econtrol (port
, (1<<4), (1<<4)); /* nErrIntrEn */
471 parport_pc_data_forward (port
);
475 unsigned char ecrval
= inb (ECONTROL (port
));
478 if (current
->need_resched
&& time_before (jiffies
, expire
))
479 /* Can't yield the port. */
482 /* Anyone else waiting for the port? */
483 if (port
->waithead
) {
484 printk (KERN_DEBUG
"Somebody wants the port\n");
489 /* FIFO is full. Wait for interrupt. */
491 /* Clear serviceIntr */
492 outb (ecrval
& ~(1<<2), ECONTROL (port
));
494 ret
= parport_wait_event (port
, HZ
);
497 if (!time_before (jiffies
, expire
)) {
499 printk (KERN_DEBUG
"Timed out\n");
502 ecrval
= inb (ECONTROL (port
));
503 if (!(ecrval
& (1<<2))) {
504 if (current
->need_resched
&&
505 time_before (jiffies
, expire
))
514 /* Can't fail now. */
515 expire
= jiffies
+ port
->cad
->timeout
;
518 if (signal_pending (current
))
522 /* FIFO is empty. Blast it full. */
523 const int n
= left
< fifo_depth
? left
: fifo_depth
;
524 outsb (fifo
, bufp
, n
);
528 /* Adjust the poll time. */
529 if (i
< (poll_for
- 2)) poll_for
--;
531 } else if (i
++ < poll_for
) {
533 ecrval
= inb (ECONTROL (port
));
537 /* Half-full (call me an optimist) */
543 return length
- left
;
546 static size_t parport_pc_fifo_write_block_dma (struct parport
*port
,
547 const void *buf
, size_t length
)
550 unsigned long dmaflag
;
551 size_t left
= length
;
552 const struct parport_pc_private
*priv
= port
->physport
->private_data
;
554 port
= port
->physport
;
556 /* We don't want to be interrupted every character. */
557 parport_pc_disable_irq (port
);
558 frob_econtrol (port
, (1<<4), (1<<4)); /* nErrIntrEn */
561 parport_pc_data_forward (port
);
564 long expire
= jiffies
+ port
->physport
->cad
->timeout
;
568 if (count
> PAGE_SIZE
)
571 memcpy(priv
->dma_buf
, buf
, count
);
573 dmaflag
= claim_dma_lock();
574 disable_dma(port
->dma
);
575 clear_dma_ff(port
->dma
);
576 set_dma_mode(port
->dma
, DMA_MODE_WRITE
);
577 set_dma_addr(port
->dma
, virt_to_bus((volatile char *) priv
->dma_buf
));
578 set_dma_count(port
->dma
, count
);
581 frob_econtrol (port
, 1<<3, 1<<3);
583 /* Clear serviceIntr */
584 frob_econtrol (port
, 1<<2, 0);
586 enable_dma(port
->dma
);
587 release_dma_lock(dmaflag
);
589 /* assume DMA will be successful */
593 /* Wait for interrupt. */
595 ret
= parport_wait_event (port
, HZ
);
598 if (!time_before (jiffies
, expire
)) {
600 printk (KERN_DEBUG
"Timed out\n");
603 /* Is serviceIntr set? */
604 if (!(inb (ECONTROL (port
)) & (1<<2))) {
605 if (current
->need_resched
)
611 dmaflag
= claim_dma_lock();
612 disable_dma(port
->dma
);
613 clear_dma_ff(port
->dma
);
614 count
= get_dma_residue(port
->dma
);
615 release_dma_lock(dmaflag
);
617 if (current
->need_resched
)
618 /* Can't yield the port. */
621 /* Anyone else waiting for the port? */
622 if (port
->waithead
) {
623 printk (KERN_DEBUG
"Somebody wants the port\n");
627 /* update for possible DMA residue ! */
632 /* Maybe got here through break, so adjust for DMA residue! */
633 dmaflag
= claim_dma_lock();
634 disable_dma(port
->dma
);
635 clear_dma_ff(port
->dma
);
636 left
+= get_dma_residue(port
->dma
);
637 release_dma_lock(dmaflag
);
639 /* Turn off DMA mode */
640 frob_econtrol (port
, 1<<3, 0);
642 return length
- left
;
645 /* Parallel Port FIFO mode (ECP chipsets) */
646 size_t parport_pc_compat_write_block_pio (struct parport
*port
,
647 const void *buf
, size_t length
,
652 /* Special case: a timeout of zero means we cannot call schedule(). */
653 if (!port
->physport
->cad
->timeout
)
654 return parport_ieee1284_write_compat (port
, buf
,
657 /* Set up parallel port FIFO mode.*/
658 change_mode (port
, ECR_PPF
); /* Parallel port FIFO */
659 parport_pc_data_forward (port
);
660 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_DATA
;
662 /* Write the data to the FIFO. */
663 if (port
->dma
!= PARPORT_DMA_NONE
)
664 written
= parport_pc_fifo_write_block_dma (port
, buf
, length
);
666 written
= parport_pc_fifo_write_block_pio (port
, buf
, length
);
669 if (change_mode (port
, ECR_PS2
) == -EBUSY
) {
670 const struct parport_pc_private
*priv
=
671 port
->physport
->private_data
;
673 printk (KERN_DEBUG
"%s: FIFO is stuck\n", port
->name
);
675 /* Prevent further data transfer. */
676 parport_frob_control (port
,
677 PARPORT_CONTROL_STROBE
,
678 PARPORT_CONTROL_STROBE
);
680 /* Adjust for the contents of the FIFO. */
681 for (written
-= priv
->fifo_depth
; ; written
++) {
682 if (inb (ECONTROL (port
)) & 0x2)
686 outb (0, FIFO (port
));
689 /* Reset the FIFO. */
690 frob_econtrol (port
, 0xe0, 0);
692 /* De-assert strobe. */
693 parport_frob_control (port
, PARPORT_CONTROL_STROBE
, 0);
696 parport_wait_peripheral (port
,
698 PARPORT_STATUS_BUSY
);
699 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_IDLE
;
705 #ifdef CONFIG_PARPORT_1284
706 size_t parport_pc_ecp_write_block_pio (struct parport
*port
,
707 const void *buf
, size_t length
,
712 /* Special case: a timeout of zero means we cannot call schedule(). */
713 if (!port
->physport
->cad
->timeout
)
714 return parport_ieee1284_ecp_write_data (port
, buf
,
717 /* Switch to forward mode if necessary. */
718 if (port
->physport
->ieee1284
.phase
!= IEEE1284_PH_FWD_IDLE
) {
719 /* Event 47: Set nInit high. */
720 parport_frob_control (port
, PARPORT_CONTROL_INIT
, 0);
722 /* Event 40: PError goes high. */
723 parport_wait_peripheral (port
,
724 PARPORT_STATUS_PAPEROUT
,
725 PARPORT_STATUS_PAPEROUT
);
728 /* Set up ECP parallel port mode.*/
729 change_mode (port
, ECR_ECP
); /* ECP FIFO */
730 parport_pc_data_forward (port
);
731 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_DATA
;
733 /* Write the data to the FIFO. */
734 if (port
->dma
!= PARPORT_DMA_NONE
)
735 written
= parport_pc_fifo_write_block_dma (port
, buf
, length
);
737 written
= parport_pc_fifo_write_block_pio (port
, buf
, length
);
740 if (change_mode (port
, ECR_PS2
) == -EBUSY
) {
741 const struct parport_pc_private
*priv
=
742 port
->physport
->private_data
;
744 printk (KERN_DEBUG
"%s: FIFO is stuck\n", port
->name
);
746 /* Prevent further data transfer. */
747 parport_frob_control (port
,
748 PARPORT_CONTROL_STROBE
,
749 PARPORT_CONTROL_STROBE
);
751 /* Adjust for the contents of the FIFO. */
752 for (written
-= priv
->fifo_depth
; ; written
++) {
753 if (inb (ECONTROL (port
)) & 0x2)
757 outb (0, FIFO (port
));
760 /* Reset the FIFO. */
761 frob_econtrol (port
, 0xe0, 0);
762 parport_frob_control (port
, PARPORT_CONTROL_STROBE
, 0);
764 /* Host transfer recovery. */
765 parport_frob_control (port
,
766 PARPORT_CONTROL_INIT
,
767 PARPORT_CONTROL_INIT
);
768 parport_pc_data_reverse (port
);
769 parport_wait_peripheral (port
, PARPORT_STATUS_PAPEROUT
, 0);
770 parport_frob_control (port
, PARPORT_CONTROL_INIT
, 0);
771 parport_wait_peripheral (port
,
772 PARPORT_STATUS_PAPEROUT
,
773 PARPORT_STATUS_PAPEROUT
);
776 parport_wait_peripheral (port
,
778 PARPORT_STATUS_BUSY
);
779 port
->physport
->ieee1284
.phase
= IEEE1284_PH_FWD_IDLE
;
784 size_t parport_pc_ecp_read_block_pio (struct parport
*port
,
785 void *buf
, size_t length
, int flags
)
787 size_t left
= length
;
789 const int fifo
= FIFO(port
);
790 const struct parport_pc_private
*priv
= port
->physport
->private_data
;
791 const int fifo_depth
= priv
->fifo_depth
;
794 port
= port
->physport
;
796 /* Special case: a timeout of zero means we cannot call schedule(). */
797 if (!port
->cad
->timeout
)
798 return parport_ieee1284_ecp_read_data (port
, buf
,
801 fifofull
= fifo_depth
;
802 if (port
->ieee1284
.mode
== IEEE1284_MODE_ECPRLE
)
803 /* If the peripheral is allowed to send RLE compressed
804 * data, it is possible for a byte to expand to 128
805 * bytes in the FIFO. */
808 /* If the caller wants less than a full FIFO's worth of data,
809 * go through software emulation. Otherwise we may have to through
811 if (length
< fifofull
)
812 return parport_ieee1284_ecp_read_data (port
, buf
,
815 /* Switch to reverse mode if necessary. */
816 if (port
->ieee1284
.phase
!= IEEE1284_PH_REV_IDLE
) {
817 /* Event 38: Set nAutoFd low */
818 parport_frob_control (port
,
819 PARPORT_CONTROL_AUTOFD
,
820 PARPORT_CONTROL_AUTOFD
);
821 parport_pc_data_reverse (port
);
824 /* Event 39: Set nInit low to initiate bus reversal */
825 parport_frob_control (port
,
826 PARPORT_CONTROL_INIT
,
827 PARPORT_CONTROL_INIT
);
829 /* Event 40: PError goes low */
830 parport_wait_peripheral (port
, PARPORT_STATUS_PAPEROUT
, 0);
833 /* Set up ECP parallel port mode.*/
834 change_mode (port
, ECR_ECP
); /* ECP FIFO */
835 parport_pc_data_reverse (port
);
836 port
->ieee1284
.phase
= IEEE1284_PH_REV_DATA
;
838 /* Do the transfer. */
839 while (left
> fifofull
) {
841 long int expire
= jiffies
+ port
->cad
->timeout
;
842 unsigned char ecrval
= inb (ECONTROL (port
));
844 if (current
->need_resched
&& time_before (jiffies
, expire
))
845 /* Can't yield the port. */
848 /* At this point, the FIFO may already be full.
849 * Ideally, we'd be able to tell the port to hold on
850 * for a second while we empty the FIFO, and we'd be
851 * able to ensure that no data is lost. I'm not sure
852 * that's the case. :-( It might be that you can play
853 * games with STB, as in the forward case; someone should
854 * look at a datasheet. */
857 /* FIFO is empty. Wait for interrupt. */
859 /* Anyone else waiting for the port? */
860 if (port
->waithead
) {
862 "Somebody wants the port\n");
866 /* Clear serviceIntr */
867 outb (ecrval
& ~(1<<2), ECONTROL (port
));
869 ret
= parport_wait_event (port
, HZ
);
872 if (!time_before (jiffies
, expire
)) {
874 printk (KERN_DEBUG
"Timed out\n");
877 ecrval
= inb (ECONTROL (port
));
878 if (!(ecrval
& (1<<2))) {
879 if (current
->need_resched
&&
880 time_before (jiffies
, expire
))
891 insb (fifo
, bufp
, fifo_depth
);
897 *bufp
++ = inb (fifo
);
902 if (change_mode (port
, ECR_PS2
) == -EBUSY
) {
903 int lost
= get_fifo_residue (port
);
904 printk (KERN_DEBUG
"%s: DATA LOSS (%d bytes)!\n", port
->name
,
908 port
->ieee1284
.phase
= IEEE1284_PH_REV_IDLE
;
910 return length
- left
;
913 #endif /* IEEE 1284 support */
915 #endif /* Allowed to use FIFO/DMA */
917 void parport_pc_inc_use_count(void)
924 void parport_pc_dec_use_count(void)
931 static void parport_pc_fill_inode(struct inode
*inode
, int fill
)
933 /* Is this still needed? -tim */
942 struct parport_operations parport_pc_ops
=
944 parport_pc_write_data
,
945 parport_pc_read_data
,
947 parport_pc_write_control
,
948 parport_pc_read_control
,
949 parport_pc_frob_control
,
951 parport_pc_read_status
,
953 parport_pc_enable_irq
,
954 parport_pc_disable_irq
,
956 parport_pc_data_forward
,
957 parport_pc_data_reverse
,
959 parport_pc_interrupt
,
960 parport_pc_init_state
,
961 parport_pc_save_state
,
962 parport_pc_restore_state
,
964 parport_pc_inc_use_count
,
965 parport_pc_dec_use_count
,
966 parport_pc_fill_inode
,
968 parport_ieee1284_epp_write_data
,
969 parport_ieee1284_epp_read_data
,
970 parport_ieee1284_epp_write_addr
,
971 parport_ieee1284_epp_read_addr
,
973 parport_ieee1284_ecp_write_data
,
974 parport_ieee1284_ecp_read_data
,
975 parport_ieee1284_ecp_write_addr
,
977 parport_ieee1284_write_compat
,
978 parport_ieee1284_read_nibble
,
979 parport_ieee1284_read_byte
,
982 /* --- Mode detection ------------------------------------- */
985 * Checks for port existence, all ports support SPP MODE
987 static int __init
parport_SPP_supported(struct parport
*pb
)
992 * first clear an eventually pending EPP timeout
993 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
994 * that does not even respond to SPP cycles if an EPP
997 clear_epp_timeout(pb
);
999 /* Do a simple read-write test to make sure the port exists. */
1001 outb (w
, CONTROL (pb
));
1003 /* Is there a control register that we can read from? Some
1004 * ports don't allow reads, so read_control just returns a
1005 * software copy. Some ports _do_ allow reads, so bypass the
1006 * software copy here. In addition, some bits aren't
1008 r
= inb (CONTROL (pb
));
1009 if ((r
& 0xf) == w
) {
1011 outb (w
, CONTROL (pb
));
1012 r
= inb (CONTROL (pb
));
1013 outb (0xc, CONTROL (pb
));
1015 return PARPORT_MODE_PCSPP
;
1019 /* That didn't work, but the user thinks there's a
1021 printk (KERN_DEBUG
"0x%lx: CTR: wrote 0x%02x, read 0x%02x\n",
1024 /* Try the data register. The data lines aren't tri-stated at
1025 * this stage, so we expect back what we wrote. */
1027 parport_pc_write_data (pb
, w
);
1028 r
= parport_pc_read_data (pb
);
1031 parport_pc_write_data (pb
, w
);
1032 r
= parport_pc_read_data (pb
);
1034 return PARPORT_MODE_PCSPP
;
1038 /* Didn't work, but the user is convinced this is the
1040 printk (KERN_DEBUG
"0x%lx: DATA: wrote 0x%02x, read 0x%02x\n",
1043 /* It's possible that we can't read the control register or
1044 * the data register. In that case just believe the user. */
1046 return PARPORT_MODE_PCSPP
;
1053 * Old style XT ports alias io ports every 0x400, hence accessing ECR
1054 * on these cards actually accesses the CTR.
1056 * Modern cards don't do this but reading from ECR will return 0xff
1057 * regardless of what is written here if the card does NOT support
1060 * We first check to see if ECR is the same as CTR. If not, the low
1061 * two bits of ECR aren't writable, so we check by writing ECR and
1062 * reading it back to see if it's what we expect.
1064 static int __init
parport_ECR_present(struct parport
*pb
)
1066 struct parport_pc_private
*priv
= pb
->private_data
;
1067 unsigned char r
= 0xc;
1070 outb (r
, CONTROL (pb
));
1071 if ((inb (ECONTROL (pb
)) & 0x3) == (r
& 0x3)) {
1072 outb (r
^ 0x2, CONTROL (pb
)); /* Toggle bit 1 */
1074 r
= inb (CONTROL (pb
));
1075 if ((inb (ECONTROL (pb
)) & 0x2) == (r
& 0x2))
1076 goto no_reg
; /* Sure that no ECR register exists */
1079 if ((inb (ECONTROL (pb
)) & 0x3 ) != 0x1)
1082 outb (0x34, ECONTROL (pb
));
1083 if (inb (ECONTROL (pb
)) != 0x35)
1087 outb (0xc, CONTROL (pb
));
1089 /* Go to mode 000 */
1090 frob_econtrol (pb
, 0xe0, ECR_SPP
<< 5);
1095 outb (0xc, CONTROL (pb
));
1099 #ifdef CONFIG_PARPORT_1284
1100 /* Detect PS/2 support.
1102 * Bit 5 (0x20) sets the PS/2 data direction; setting this high
1103 * allows us to read data from the data lines. In theory we would get back
1104 * 0xff but any peripheral attached to the port may drag some or all of the
1105 * lines down to zero. So if we get back anything that isn't the contents
1106 * of the data register we deem PS/2 support to be present.
1108 * Some SPP ports have "half PS/2" ability - you can't turn off the line
1109 * drivers, but an external peripheral with sufficiently beefy drivers of
1110 * its own can overpower them and assert its own levels onto the bus, from
1111 * where they can then be read back as normal. Ports with this property
1112 * and the right type of device attached are likely to fail the SPP test,
1113 * (as they will appear to have stuck bits) and so the fact that they might
1114 * be misdetected here is rather academic.
1117 static int __init
parport_PS2_supported(struct parport
*pb
)
1121 clear_epp_timeout(pb
);
1123 /* try to tri-state the buffer */
1124 parport_pc_data_reverse (pb
);
1126 parport_pc_write_data(pb
, 0x55);
1127 if (parport_pc_read_data(pb
) != 0x55) ok
++;
1129 parport_pc_write_data(pb
, 0xaa);
1130 if (parport_pc_read_data(pb
) != 0xaa) ok
++;
1132 /* cancel input mode */
1133 parport_pc_data_forward (pb
);
1136 pb
->modes
|= PARPORT_MODE_TRISTATE
;
1138 struct parport_pc_private
*priv
= pb
->private_data
;
1139 priv
->ctr_writable
&= ~0x20;
1145 static int __init
parport_ECP_supported(struct parport
*pb
)
1150 struct parport_pc_private
*priv
= pb
->private_data
;
1152 /* If there is no ECR, we have no hope of supporting ECP. */
1156 /* Find out FIFO depth */
1157 outb (ECR_SPP
<< 5, ECONTROL (pb
)); /* Reset FIFO */
1158 outb (ECR_TST
<< 5, ECONTROL (pb
)); /* TEST FIFO */
1159 for (i
=0; i
< 1024 && !(inb (ECONTROL (pb
)) & 0x02); i
++)
1160 outb (0xaa, FIFO (pb
));
1163 * Using LGS chipset it uses ECR register, but
1164 * it doesn't support ECP or FIFO MODE
1167 outb (ECR_SPP
<< 5, ECONTROL (pb
));
1171 priv
->fifo_depth
= i
;
1172 printk (KERN_INFO
"0x%lx: FIFO is %d bytes\n", pb
->base
, i
);
1174 /* Find out writeIntrThreshold */
1175 frob_econtrol (pb
, 1<<2, 1<<2);
1176 frob_econtrol (pb
, 1<<2, 0);
1177 for (i
= 1; i
<= priv
->fifo_depth
; i
++) {
1180 if (inb (ECONTROL (pb
)) & (1<<2))
1184 if (i
<= priv
->fifo_depth
)
1185 printk (KERN_INFO
"0x%lx: writeIntrThreshold is %d\n",
1188 /* Number of bytes we know we can write if we get an
1192 priv
->writeIntrThreshold
= i
;
1194 /* Find out readIntrThreshold */
1195 frob_econtrol (pb
, 0xe0, ECR_PS2
<< 5); /* Reset FIFO */
1196 parport_pc_data_reverse (pb
);
1197 frob_econtrol (pb
, 0xe0, ECR_TST
<< 5); /* Test FIFO */
1198 frob_econtrol (pb
, 1<<2, 1<<2);
1199 frob_econtrol (pb
, 1<<2, 0);
1200 for (i
= 1; i
<= priv
->fifo_depth
; i
++) {
1201 outb (0xaa, FIFO (pb
));
1202 if (inb (ECONTROL (pb
)) & (1<<2))
1206 if (i
<= priv
->fifo_depth
)
1207 printk (KERN_INFO
"0x%lx: readIntrThreshold is %d\n",
1210 /* Number of bytes we can read if we get an interrupt. */
1213 priv
->readIntrThreshold
= i
;
1215 outb (ECR_SPP
<< 5, ECONTROL (pb
)); /* Reset FIFO */
1216 outb (0xf4, ECONTROL (pb
)); /* Configuration mode */
1217 config
= inb (FIFO (pb
));
1218 pword
= (config
>> 4) & 0x7;
1222 printk (KERN_WARNING
"0x%lx: Unsupported pword size!\n",
1227 printk (KERN_WARNING
"0x%lx: Unsupported pword size!\n",
1231 printk (KERN_WARNING
"0x%lx: Unknown implementation ID\n",
1237 priv
->pword
= pword
;
1238 printk (KERN_DEBUG
"0x%lx: PWord is %d bits\n", pb
->base
, 8 * pword
);
1240 config
= inb (CONFIGB (pb
));
1241 printk (KERN_DEBUG
"0x%lx: Interrupts are ISA-%s\n", pb
->base
,
1242 config
& 0x80 ? "Level" : "Pulses");
1244 if (!(config
& 0x40)) {
1245 printk (KERN_WARNING
"0x%lx: IRQ conflict!\n", pb
->base
);
1246 pb
->irq
= PARPORT_IRQ_NONE
;
1249 /* Go back to mode 000 */
1250 frob_econtrol (pb
, 0xe0, ECR_SPP
<< 5);
1251 pb
->modes
|= PARPORT_MODE_ECP
;
1256 static int __init
parport_ECPPS2_supported(struct parport
*pb
)
1258 const struct parport_pc_private
*priv
= pb
->private_data
;
1265 oecr
= inb (ECONTROL (pb
));
1266 outb (ECR_PS2
<< 5, ECONTROL (pb
));
1268 result
= parport_PS2_supported(pb
);
1270 outb (oecr
, ECONTROL (pb
));
1274 /* EPP mode detection */
1276 static int __init
parport_EPP_supported(struct parport
*pb
)
1278 /* If EPP timeout bit clear then EPP available */
1279 if (!clear_epp_timeout(pb
))
1280 return 0; /* No way to clear timeout */
1284 * Bit 0 of STR is the EPP timeout bit, this bit is 0
1285 * when EPP is possible and is set high when an EPP timeout
1286 * occurs (EPP uses the HALT line to stop the CPU while it does
1287 * the byte transfer, an EPP timeout occurs if the attached
1288 * device fails to respond after 10 micro seconds).
1290 * This bit is cleared by either reading it (National Semi)
1291 * or writing a 1 to the bit (SMC, UMC, WinBond), others ???
1292 * This bit is always high in non EPP modes.
1295 parport_pc_data_reverse (pb
);
1296 parport_pc_enable_irq (pb
);
1297 clear_epp_timeout(pb
);
1300 udelay(30); /* Wait for possible EPP timeout */
1302 if (parport_pc_read_status(pb
) & 0x01)
1307 * Write two values to the EPP address register and
1308 * read them back. When the transfer times out, the state of
1309 * the EPP register is undefined in some cases (EPP 1.9?) but
1310 * in others (EPP 1.7, ECPEPP?) it is possible to read back
1313 clear_epp_timeout(pb
);
1314 udelay(30); /* Wait for possible EPP timeout */
1316 /* Enable outputs. */
1317 parport_pc_data_forward (pb
);
1318 outb (0x55, EPPADDR (pb
));
1320 clear_epp_timeout(pb
);
1321 udelay(30); /* Wait for possible EPP timeout */
1323 /* We must enable the outputs to be able to read the address
1325 parport_pc_data_forward (pb
);
1327 if (inb (EPPADDR (pb
)) == 0x55) {
1328 clear_epp_timeout(pb
);
1329 udelay(30); /* Wait for possible EPP timeout */
1330 outb (0xaa, EPPADDR (pb
));
1332 if (inb (EPPADDR (pb
)) == 0xaa)
1339 clear_epp_timeout(pb
);
1340 pb
->modes
|= PARPORT_MODE_EPP
;
1342 /* Set up access functions to use EPP hardware. */
1343 parport_pc_ops
.epp_read_data
= parport_pc_epp_read_data
;
1344 parport_pc_ops
.epp_write_data
= parport_pc_epp_write_data
;
1345 parport_pc_ops
.epp_read_addr
= parport_pc_epp_read_addr
;
1346 parport_pc_ops
.epp_write_addr
= parport_pc_epp_write_addr
;
1351 static int __init
parport_ECPEPP_supported(struct parport
*pb
)
1353 struct parport_pc_private
*priv
= pb
->private_data
;
1360 oecr
= inb (ECONTROL (pb
));
1361 /* Search for SMC style EPP+ECP mode */
1362 outb (0x80, ECONTROL (pb
));
1364 result
= parport_EPP_supported(pb
);
1366 outb (oecr
, ECONTROL (pb
));
1369 /* Set up access functions to use ECP+EPP hardware. */
1370 parport_pc_ops
.epp_read_data
= parport_pc_ecpepp_read_data
;
1371 parport_pc_ops
.epp_write_data
= parport_pc_ecpepp_write_data
;
1372 parport_pc_ops
.epp_read_addr
= parport_pc_ecpepp_read_addr
;
1373 parport_pc_ops
.epp_write_addr
= parport_pc_ecpepp_write_addr
;
1379 #else /* No IEEE 1284 support */
1381 /* Don't bother probing for modes we know we won't use. */
1382 static int __init
parport_PS2_supported(struct parport
*pb
) { return 0; }
1383 static int __init
parport_ECP_supported(struct parport
*pb
) { return 0; }
1384 static int __init
parport_EPP_supported(struct parport
*pb
) { return 0; }
1385 static int __init
parport_ECPEPP_supported(struct parport
*pb
) { return 0; }
1386 static int __init
parport_ECPPS2_supported(struct parport
*pb
) { return 0; }
1388 #endif /* No IEEE 1284 support */
1390 /* --- IRQ detection -------------------------------------- */
1392 /* Only if supports ECP mode */
1393 static int __init
programmable_irq_support(struct parport
*pb
)
1396 unsigned char oecr
= inb (ECONTROL (pb
));
1397 static const int lookup
[8] = {
1398 PARPORT_IRQ_NONE
, 7, 9, 10, 11, 14, 15, 5
1401 outb (ECR_CNF
<< 5, ECONTROL (pb
)); /* Configuration MODE */
1403 intrLine
= (inb (CONFIGB (pb
)) >> 3) & 0x07;
1404 irq
= lookup
[intrLine
];
1406 outb (oecr
, ECONTROL (pb
));
1410 static int __init
irq_probe_ECP(struct parport
*pb
)
1415 irqs
= probe_irq_on();
1417 outb (ECR_SPP
<< 5, ECONTROL (pb
)); /* Reset FIFO */
1418 outb ((ECR_TST
<< 5) | 0x04, ECONTROL (pb
));
1419 outb (ECR_TST
<< 5, ECONTROL (pb
));
1421 /* If Full FIFO sure that writeIntrThreshold is generated */
1422 for (i
=0; i
< 1024 && !(inb (ECONTROL (pb
)) & 0x02) ; i
++)
1423 outb (0xaa, FIFO (pb
));
1425 pb
->irq
= probe_irq_off(irqs
);
1426 outb (ECR_SPP
<< 5, ECONTROL (pb
));
1429 pb
->irq
= PARPORT_IRQ_NONE
;
1435 * This detection seems that only works in National Semiconductors
1436 * This doesn't work in SMC, LGS, and Winbond
1438 static int __init
irq_probe_EPP(struct parport
*pb
)
1440 #ifndef ADVANCED_DETECT
1441 return PARPORT_IRQ_NONE
;
1446 if (pb
->modes
& PARPORT_MODE_PCECR
)
1447 oecr
= inb (ECONTROL (pb
));
1450 irqs
= probe_irq_on();
1452 if (pb
->modes
& PARPORT_MODE_PCECR
)
1453 frob_econtrol (pb
, 0x10, 0x10);
1455 clear_epp_timeout(pb
);
1456 parport_pc_frob_control (pb
, 0x20, 0x20);
1457 parport_pc_frob_control (pb
, 0x10, 0x10);
1458 clear_epp_timeout(pb
);
1460 /* Device isn't expecting an EPP read
1461 * and generates an IRQ.
1463 parport_pc_read_epp(pb
);
1466 pb
->irq
= probe_irq_off (irqs
);
1467 if (pb
->modes
& PARPORT_MODE_PCECR
)
1468 outb (oecr
, ECONTROL (pb
));
1469 parport_pc_write_control(pb
, 0xc);
1472 pb
->irq
= PARPORT_IRQ_NONE
;
1475 #endif /* Advanced detection */
1478 static int __init
irq_probe_SPP(struct parport
*pb
)
1480 /* Don't even try to do this. */
1481 return PARPORT_IRQ_NONE
;
1484 /* We will attempt to share interrupt requests since other devices
1485 * such as sound cards and network cards seem to like using the
1488 * When ECP is available we can autoprobe for IRQs.
1489 * NOTE: If we can autoprobe it, we can register the IRQ.
1491 static int __init
parport_irq_probe(struct parport
*pb
)
1493 const struct parport_pc_private
*priv
= pb
->private_data
;
1496 pb
->irq
= programmable_irq_support(pb
);
1497 if (pb
->irq
!= PARPORT_IRQ_NONE
)
1501 if (pb
->modes
& PARPORT_MODE_ECP
)
1502 pb
->irq
= irq_probe_ECP(pb
);
1504 if (pb
->irq
== PARPORT_IRQ_NONE
&& priv
->ecr
&&
1505 (pb
->modes
& PARPORT_MODE_EPP
))
1506 pb
->irq
= irq_probe_EPP(pb
);
1508 clear_epp_timeout(pb
);
1510 if (pb
->irq
== PARPORT_IRQ_NONE
&& (pb
->modes
& PARPORT_MODE_EPP
))
1511 pb
->irq
= irq_probe_EPP(pb
);
1513 clear_epp_timeout(pb
);
1515 if (pb
->irq
== PARPORT_IRQ_NONE
)
1516 pb
->irq
= irq_probe_SPP(pb
);
1522 /* --- DMA detection -------------------------------------- */
1524 /* Only if supports ECP mode */
1525 static int __init
programmable_dma_support (struct parport
*p
)
1527 unsigned char oecr
= inb (ECONTROL (p
));
1530 frob_econtrol (p
, 0xe0, ECR_CNF
<< 5);
1532 dma
= inb (CONFIGB(p
)) & 0x03;
1534 dma
= PARPORT_DMA_NONE
;
1536 outb (oecr
, ECONTROL (p
));
1540 static int __init
parport_dma_probe (struct parport
*p
)
1542 const struct parport_pc_private
*priv
= p
->private_data
;
1544 p
->dma
= programmable_dma_support(p
);
1549 /* --- Initialisation code -------------------------------- */
1551 static int __init
probe_one_port(unsigned long int base
,
1552 unsigned long int base_hi
,
1555 struct parport_pc_private
*priv
;
1557 struct parport
*p
= &tmp
;
1558 int probedirq
= PARPORT_IRQ_NONE
;
1559 if (check_region(base
, 3)) return 0;
1560 priv
= kmalloc (sizeof (struct parport_pc_private
), GFP_KERNEL
);
1562 printk (KERN_DEBUG
"parport (0x%lx): no memory!\n", base
);
1566 priv
->ctr_writable
= 0xff;
1568 priv
->fifo_depth
= 0;
1571 p
->base_hi
= base_hi
;
1574 p
->modes
= PARPORT_MODE_PCSPP
;
1575 p
->ops
= &parport_pc_ops
;
1576 p
->private_data
= priv
;
1578 if (base_hi
&& !check_region(base_hi
,3)) {
1579 parport_ECR_present(p
);
1580 parport_ECP_supported(p
);
1581 parport_ECPPS2_supported(p
);
1583 if (base
!= 0x3bc) {
1584 if (!check_region(base
+0x3, 5)) {
1585 parport_ECPEPP_supported(p
);
1586 parport_EPP_supported(p
);
1589 if (!parport_SPP_supported (p
)) {
1595 parport_PS2_supported (p
);
1597 if (!(p
= parport_register_port(base
, PARPORT_IRQ_NONE
,
1598 PARPORT_DMA_NONE
, &parport_pc_ops
))) {
1603 p
->base_hi
= base_hi
;
1604 p
->modes
= tmp
.modes
;
1605 p
->size
= (p
->modes
& PARPORT_MODE_EPP
)?8:3;
1606 p
->private_data
= priv
;
1608 printk(KERN_INFO
"%s: PC-style at 0x%lx", p
->name
, p
->base
);
1609 if (p
->base_hi
&& (p
->modes
& PARPORT_MODE_ECP
))
1610 printk(" (0x%lx)", p
->base_hi
);
1613 if (p
->irq
== PARPORT_IRQ_AUTO
) {
1614 p
->irq
= PARPORT_IRQ_NONE
;
1615 parport_irq_probe(p
);
1616 } else if (p
->irq
== PARPORT_IRQ_PROBEONLY
) {
1617 p
->irq
= PARPORT_IRQ_NONE
;
1618 parport_irq_probe(p
);
1620 p
->irq
= PARPORT_IRQ_NONE
;
1622 if (p
->irq
!= PARPORT_IRQ_NONE
) {
1623 printk(", irq %d", p
->irq
);
1625 if (p
->dma
== PARPORT_DMA_AUTO
) {
1626 p
->dma
= PARPORT_DMA_NONE
;
1627 parport_dma_probe(p
);
1630 if (p
->dma
== PARPORT_DMA_AUTO
)
1631 p
->dma
= PARPORT_DMA_NONE
;
1632 if (p
->dma
!= PARPORT_DMA_NONE
)
1633 printk(", dma %d", p
->dma
);
1635 #ifdef CONFIG_PARPORT_PC_FIFO
1636 if (priv
->fifo_depth
> 0 && p
->irq
!= PARPORT_IRQ_NONE
) {
1637 parport_pc_ops
.compat_write_data
=
1638 parport_pc_compat_write_block_pio
;
1639 #ifdef CONFIG_PARPORT_1284
1640 parport_pc_ops
.ecp_write_data
=
1641 parport_pc_ecp_write_block_pio
;
1642 #endif /* IEEE 1284 support */
1643 if (p
->dma
!= PARPORT_DMA_NONE
)
1644 p
->modes
|= PARPORT_MODE_DMA
;
1645 printk(", using FIFO");
1647 #endif /* Allowed to use FIFO/DMA */
1650 #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
1654 printmode(TRISTATE
);
1662 if (probedirq
!= PARPORT_IRQ_NONE
)
1663 printk("%s: irq %d detected\n", p
->name
, probedirq
);
1664 parport_proc_register(p
);
1666 request_region (p
->base
, p
->size
, p
->name
);
1667 if (p
->modes
& PARPORT_MODE_ECP
)
1668 request_region (p
->base_hi
, 3, p
->name
);
1670 if (p
->irq
!= PARPORT_IRQ_NONE
) {
1671 if (request_irq (p
->irq
, parport_pc_interrupt
,
1673 printk (KERN_WARNING
"%s: irq %d in use, "
1674 "resorting to polled operation\n",
1676 p
->irq
= PARPORT_IRQ_NONE
;
1677 p
->dma
= PARPORT_DMA_NONE
;
1680 if (p
->dma
!= PARPORT_DMA_NONE
) {
1681 if (request_dma (p
->dma
, p
->name
)) {
1682 printk (KERN_WARNING
"%s: dma %d in use, "
1683 "resorting to PIO operation\n",
1685 p
->dma
= PARPORT_DMA_NONE
;
1687 priv
->dma_buf
= (char *) __get_dma_pages(GFP_KERNEL
, 1);
1688 if (! priv
->dma_buf
) {
1689 printk (KERN_WARNING
"%s: "
1690 "cannot get buffer for DMA, "
1691 "resorting to PIO operation\n",
1694 p
->dma
= PARPORT_DMA_NONE
;
1700 /* Done probing. Now put the port into a sensible start-up state.
1701 * SELECT | INIT also puts IEEE1284-compliant devices into
1702 * compatibility mode. */
1703 if (p
->modes
& PARPORT_MODE_ECP
)
1705 * Put the ECP detected port in PS2 mode.
1707 outb (0x24, ECONTROL (p
));
1709 parport_pc_write_data(p
, 0);
1710 parport_pc_write_control(p
, PARPORT_CONTROL_SELECT
);
1712 parport_pc_write_control(p
,
1713 PARPORT_CONTROL_SELECT
1714 | PARPORT_CONTROL_INIT
);
1717 /* Now that we've told the sharing engine about the port, and
1718 found out its characteristics, let the high-level drivers
1720 parport_announce_port (p
);
1725 /* Look for PCI parallel port cards. */
1726 static int __init
parport_pc_init_pci (int irq
, int dma
)
1728 /* These need to go in pci.h: */
1729 #ifndef PCI_VENDOR_ID_SIIG
1730 #define PCI_VENDOR_ID_SIIG 0x131f
1731 #define PCI_DEVICE_ID_SIIG_1S1P_10x_550 0x1010
1732 #define PCI_DEVICE_ID_SIIG_1S1P_10x_650 0x1011
1733 #define PCI_DEVICE_ID_SIIG_1S1P_10x_850 0x1012
1734 #define PCI_DEVICE_ID_SIIG_1P_10x 0x1020
1735 #define PCI_DEVICE_ID_SIIG_2P_10x 0x1021
1736 #define PCI_DEVICE_ID_SIIG_2S1P_10x_550 0x1034
1737 #define PCI_DEVICE_ID_SIIG_2S1P_10x_650 0x1035
1738 #define PCI_DEVICE_ID_SIIG_2S1P_10x_850 0x1036
1739 #define PCI_DEVICE_ID_SIIG_1P_20x 0x2020
1740 #define PCI_DEVICE_ID_SIIG_2P_20x 0x2021
1741 #define PCI_DEVICE_ID_SIIG_2P1S_20x_550 0x2040
1742 #define PCI_DEVICE_ID_SIIG_2P1S_20x_650 0x2041
1743 #define PCI_DEVICE_ID_SIIG_2P1S_20x_850 0x2042
1744 #define PCI_DEVICE_ID_SIIG_1S1P_20x_550 0x2010
1745 #define PCI_DEVICE_ID_SIIG_1S1P_20x_650 0x2011
1746 #define PCI_DEVICE_ID_SIIG_1S1P_20x_850 0x2012
1747 #define PCI_DEVICE_ID_SIIG_2S1P_20x_550 0x2060
1748 #define PCI_DEVICE_ID_SIIG_2S1P_20x_650 0x2061
1749 #define PCI_DEVICE_ID_SIIG_2S1P_20x_850 0x2062
1750 #define PCI_VENDOR_ID_LAVA 0x1407
1751 #define PCI_DEVICE_ID_LAVA_PARALLEL 0x8000
1752 #define PCI_DEVICE_ID_LAVA_DUAL_PAR_A 0x8001 /* The Lava Dual Parallel is */
1753 #define PCI_DEVICE_ID_LAVA_DUAL_PAR_B 0x8002 /* two PCI devices on a card */
1757 unsigned int vendor
;
1758 unsigned int device
;
1759 unsigned int numports
;
1762 unsigned int hi
; /* -ve if not there */
1765 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_550
, 1,
1767 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_650
, 1,
1769 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_850
, 1,
1771 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1P_10x
, 1,
1773 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P_10x
, 2,
1774 { { 2, 3 }, { 4, 5 }, } },
1775 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_550
, 1,
1777 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_650
, 1,
1779 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_850
, 1,
1781 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1P_20x
, 1,
1783 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P_20x
, 2,
1784 { { 0, 1 }, { 2, 3 }, } },
1785 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_550
, 2,
1786 { { 1, 2 }, { 3, 4 }, } },
1787 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_650
, 2,
1788 { { 1, 2 }, { 3, 4 }, } },
1789 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_850
, 2,
1790 { { 1, 2 }, { 3, 4 }, } },
1791 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_550
, 1,
1793 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_650
, 1,
1795 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_850
, 1,
1797 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_550
, 1,
1799 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_650
, 1,
1801 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_850
, 1,
1803 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_PARALLEL
, 1,
1805 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_DUAL_PAR_A
, 1,
1807 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_DUAL_PAR_B
, 1,
1815 if (!pci_present ())
1818 for (i
= 0; cards
[i
].vendor
; i
++) {
1819 struct pci_dev
*pcidev
= NULL
;
1820 while ((pcidev
= pci_find_device (cards
[i
].vendor
,
1824 for (n
= 0; n
< cards
[i
].numports
; n
++) {
1825 int lo
= cards
[i
].addr
[n
].lo
;
1826 int hi
= cards
[i
].addr
[n
].hi
;
1827 int io_lo
= pcidev
->base_address
[lo
];
1828 int io_hi
= ((hi
< 0) ? 0 :
1829 pcidev
->base_address
[hi
]);
1830 io_lo
&= PCI_BASE_ADDRESS_IO_MASK
;
1831 io_hi
&= PCI_BASE_ADDRESS_IO_MASK
;
1832 count
+= probe_one_port (io_lo
, io_hi
,
1841 int __init
parport_pc_init(int *io
, int *io_hi
, int *irq
, int *dma
)
1843 int count
= 0, i
= 0;
1845 /* Only probe the ports we were given. */
1848 if (!*io_hi
) *io_hi
= 0x400 + *io
;
1849 count
+= probe_one_port(*(io
++), *(io_hi
++),
1850 *(irq
++), *(dma
++));
1851 } while (*io
&& (++i
< PARPORT_PC_MAX_PORTS
));
1853 /* Probe all the likely ports. */
1854 count
+= probe_one_port(0x3bc, 0x7bc, irq
[0], dma
[0]);
1855 count
+= probe_one_port(0x378, 0x778, irq
[0], dma
[0]);
1856 count
+= probe_one_port(0x278, 0x678, irq
[0], dma
[0]);
1857 count
+= parport_pc_init_pci (irq
[0], dma
[0]);
1864 static int io
[PARPORT_PC_MAX_PORTS
+1] = { [0 ... PARPORT_PC_MAX_PORTS
] = 0 };
1865 static int io_hi
[PARPORT_PC_MAX_PORTS
+1] = { [0 ... PARPORT_PC_MAX_PORTS
] = 0 };
1866 static int dmaval
[PARPORT_PC_MAX_PORTS
] = { [0 ... PARPORT_PC_MAX_PORTS
-1] = PARPORT_DMA_AUTO
};
1867 static int irqval
[PARPORT_PC_MAX_PORTS
] = { [0 ... PARPORT_PC_MAX_PORTS
-1] = PARPORT_IRQ_PROBEONLY
};
1868 static const char *irq
[PARPORT_PC_MAX_PORTS
] = { NULL
, };
1869 static const char *dma
[PARPORT_PC_MAX_PORTS
] = { NULL
, };
1870 MODULE_PARM(io
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "i");
1871 MODULE_PARM(io_hi
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "i");
1872 MODULE_PARM(irq
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "s");
1873 MODULE_PARM(dma
, "1-" __MODULE_STRING(PARPORT_PC_MAX_PORTS
) "s");
1875 int init_module(void)
1877 /* Work out how many ports we have, then get parport_share to parse
1880 for (i
= 0; i
< PARPORT_PC_MAX_PORTS
&& io
[i
]; i
++);
1882 if (parport_parse_irqs(i
, irq
, irqval
)) return 1;
1883 if (parport_parse_dmas(i
, dma
, dmaval
)) return 1;
1886 /* The user can make us use any IRQs or DMAs we find. */
1889 if (irq
[0] && !parport_parse_irqs (1, irq
, &val
))
1891 case PARPORT_IRQ_NONE
:
1892 case PARPORT_IRQ_AUTO
:
1896 if (dma
[0] && !parport_parse_dmas (1, dma
, &val
))
1898 case PARPORT_DMA_NONE
:
1899 case PARPORT_DMA_AUTO
:
1904 return (parport_pc_init(io
, io_hi
, irqval
, dmaval
)?0:1);
1907 void cleanup_module(void)
1909 struct parport
*p
= parport_enumerate(), *tmp
;
1912 if (p
->modes
& PARPORT_MODE_PCSPP
) {
1913 struct parport_pc_private
*priv
= p
->private_data
;
1914 if (p
->dma
!= PARPORT_DMA_NONE
)
1916 if (p
->irq
!= PARPORT_IRQ_NONE
)
1917 free_irq(p
->irq
, p
);
1918 release_region(p
->base
, p
->size
);
1919 if (p
->modes
& PARPORT_MODE_ECP
)
1920 release_region(p
->base_hi
, 3);
1921 parport_proc_unregister(p
);
1923 free_page((unsigned long) priv
->dma_buf
);
1924 kfree (p
->private_data
);
1925 parport_unregister_port(p
);