1 /* ppa.c -- low level driver for the IOMEGA PPA3
2 * parallel port SCSI host adapter.
4 * (The PPA3 is the embedded controller in the ZIP drive.)
6 * (c) 1995,1996 Grant R. Guenther, grant@torque.net,
7 * under the terms of the GNU General Public License.
9 * Current Maintainer: David Campbell (Perth, Western Australia, GMT+0800)
13 #include <linux/config.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/blkdev.h>
18 #include <linux/parport.h>
19 #include <linux/workqueue.h>
20 #include <linux/delay.h>
21 #include <linux/jiffies.h>
24 #include <scsi/scsi.h>
25 #include <scsi/scsi_cmnd.h>
26 #include <scsi/scsi_device.h>
27 #include <scsi/scsi_host.h>
30 static void ppa_reset_pulse(unsigned int base
);
33 struct pardevice
*dev
; /* Parport device entry */
34 int base
; /* Actual port address */
35 int mode
; /* Transfer mode */
36 struct scsi_cmnd
*cur_cmd
; /* Current queued command */
37 struct work_struct ppa_tq
; /* Polling interrupt stuff */
38 unsigned long jstart
; /* Jiffies at start */
39 unsigned long recon_tmo
; /* How many usecs to wait for reconnection (6th bit) */
40 unsigned int failed
:1; /* Failure flag */
41 unsigned wanted
:1; /* Parport sharing busy flag */
42 wait_queue_head_t
*waiting
;
43 struct Scsi_Host
*host
;
44 struct list_head list
;
49 static inline ppa_struct
*ppa_dev(struct Scsi_Host
*host
)
51 return *(ppa_struct
**)&host
->hostdata
;
54 static DEFINE_SPINLOCK(arbitration_lock
);
56 static void got_it(ppa_struct
*dev
)
58 dev
->base
= dev
->dev
->port
->base
;
60 dev
->cur_cmd
->SCp
.phase
= 1;
62 wake_up(dev
->waiting
);
65 static void ppa_wakeup(void *ref
)
67 ppa_struct
*dev
= (ppa_struct
*) ref
;
70 spin_lock_irqsave(&arbitration_lock
, flags
);
72 parport_claim(dev
->dev
);
76 spin_unlock_irqrestore(&arbitration_lock
, flags
);
80 static int ppa_pb_claim(ppa_struct
*dev
)
84 spin_lock_irqsave(&arbitration_lock
, flags
);
85 if (parport_claim(dev
->dev
) == 0) {
90 spin_unlock_irqrestore(&arbitration_lock
, flags
);
94 static void ppa_pb_dismiss(ppa_struct
*dev
)
98 spin_lock_irqsave(&arbitration_lock
, flags
);
101 spin_unlock_irqrestore(&arbitration_lock
, flags
);
103 parport_release(dev
->dev
);
106 static inline void ppa_pb_release(ppa_struct
*dev
)
108 parport_release(dev
->dev
);
112 * Start of Chipset kludges
115 /* This is to give the ppa driver a way to modify the timings (and other
116 * parameters) by writing to the /proc/scsi/ppa/0 file.
117 * Very simple method really... (To simple, no error checking :( )
118 * Reason: Kernel hackers HATE having to unload and reload modules for
120 * Also gives a method to use a script to obtain optimum timings (TODO)
123 static inline int ppa_proc_write(ppa_struct
*dev
, char *buffer
, int length
)
127 if ((length
> 5) && (strncmp(buffer
, "mode=", 5) == 0)) {
128 x
= simple_strtoul(buffer
+ 5, NULL
, 0);
132 if ((length
> 10) && (strncmp(buffer
, "recon_tmo=", 10) == 0)) {
133 x
= simple_strtoul(buffer
+ 10, NULL
, 0);
135 printk("ppa: recon_tmo set to %ld\n", x
);
138 printk("ppa /proc: invalid variable\n");
142 static int ppa_proc_info(struct Scsi_Host
*host
, char *buffer
, char **start
, off_t offset
, int length
, int inout
)
145 ppa_struct
*dev
= ppa_dev(host
);
148 return ppa_proc_write(dev
, buffer
, length
);
150 len
+= sprintf(buffer
+ len
, "Version : %s\n", PPA_VERSION
);
152 sprintf(buffer
+ len
, "Parport : %s\n",
153 dev
->dev
->port
->name
);
155 sprintf(buffer
+ len
, "Mode : %s\n",
156 PPA_MODE_STRING
[dev
->mode
]);
159 sprintf(buffer
+ len
, "recon_tmo : %lu\n", dev
->recon_tmo
);
162 /* Request for beyond end of buffer */
166 *start
= buffer
+ offset
;
173 static int device_check(ppa_struct
*dev
);
176 #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
177 y, __FUNCTION__, __LINE__); ppa_fail_func(x,y);
178 static inline void ppa_fail_func(ppa_struct
*dev
, int error_code
)
180 static inline void ppa_fail(ppa_struct
*dev
, int error_code
)
183 /* If we fail a device then we trash status / message bytes */
185 dev
->cur_cmd
->result
= error_code
<< 16;
191 * Wait for the high bit to be set.
193 * In principle, this could be tied to an interrupt, but the adapter
194 * doesn't appear to be designed to support interrupts. We spin on
195 * the 0x80 ready bit.
197 static unsigned char ppa_wait(ppa_struct
*dev
)
200 unsigned short ppb
= dev
->base
;
204 /* Wait for bit 6 and 7 - PJC */
205 for (r
= r_str(ppb
); ((r
& 0xc0) != 0xc0) && (k
); k
--) {
211 * return some status information.
212 * Semantics: 0xc0 = ZIP wants more data
213 * 0xd0 = ZIP wants to send more data
214 * 0xe0 = ZIP is expecting SCSI command data
215 * 0xf0 = end of transfer, ZIP is sending status
220 /* Counter expired - Time out occurred */
221 ppa_fail(dev
, DID_TIME_OUT
);
222 printk("ppa timeout in ppa_wait\n");
223 return 0; /* command timed out */
227 * Clear EPP Timeout Bit
229 static inline void epp_reset(unsigned short ppb
)
235 w_str(ppb
, i
& 0xfe);
239 * Wait for empty ECP fifo (if we are in ECP fifo mode only)
241 static inline void ecp_sync(ppa_struct
*dev
)
243 int i
, ppb_hi
= dev
->dev
->port
->base_hi
;
248 if ((r_ecr(ppb_hi
) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
249 for (i
= 0; i
< 100; i
++) {
250 if (r_ecr(ppb_hi
) & 0x01)
254 printk("ppa: ECP sync failed as data still present in FIFO.\n");
258 static int ppa_byte_out(unsigned short base
, const char *buffer
, int len
)
262 for (i
= len
; i
; i
--) {
263 w_dtr(base
, *buffer
++);
267 return 1; /* All went well - we hope! */
270 static int ppa_byte_in(unsigned short base
, char *buffer
, int len
)
274 for (i
= len
; i
; i
--) {
275 *buffer
++ = r_dtr(base
);
279 return 1; /* All went well - we hope! */
282 static int ppa_nibble_in(unsigned short base
, char *buffer
, int len
)
288 h
= r_str(base
) & 0xf0;
290 *buffer
++ = h
| ((r_str(base
) & 0xf0) >> 4);
292 return 1; /* All went well - we hope! */
295 static int ppa_out(ppa_struct
*dev
, char *buffer
, int len
)
298 unsigned short ppb
= dev
->base
;
302 if ((r
& 0x50) != 0x40) {
303 ppa_fail(dev
, DID_ERROR
);
309 /* 8 bit output, with a loop */
310 r
= ppa_byte_out(ppb
, buffer
, len
);
318 #ifdef CONFIG_SCSI_IZIP_EPP16
319 if (!(((long) buffer
| len
) & 0x01))
320 outsw(ppb
+ 4, buffer
, len
>> 1);
322 if (!(((long) buffer
| len
) & 0x03))
323 outsl(ppb
+ 4, buffer
, len
>> 2);
326 outsb(ppb
+ 4, buffer
, len
);
328 r
= !(r_str(ppb
) & 0x01);
334 printk("PPA: bug in ppa_out()\n");
340 static int ppa_in(ppa_struct
*dev
, char *buffer
, int len
)
343 unsigned short ppb
= dev
->base
;
347 if ((r
& 0x50) != 0x50) {
348 ppa_fail(dev
, DID_ERROR
);
353 /* 4 bit input, with a loop */
354 r
= ppa_nibble_in(ppb
, buffer
, len
);
359 /* 8 bit input, with a loop */
361 r
= ppa_byte_in(ppb
, buffer
, len
);
371 #ifdef CONFIG_SCSI_IZIP_EPP16
372 if (!(((long) buffer
| len
) & 0x01))
373 insw(ppb
+ 4, buffer
, len
>> 1);
375 if (!(((long) buffer
| len
) & 0x03))
376 insl(ppb
+ 4, buffer
, len
>> 2);
379 insb(ppb
+ 4, buffer
, len
);
381 r
= !(r_str(ppb
) & 0x01);
387 printk("PPA: bug in ppa_ins()\n");
394 /* end of ppa_io.h */
395 static inline void ppa_d_pulse(unsigned short ppb
, unsigned char b
)
405 static void ppa_disconnect(ppa_struct
*dev
)
407 unsigned short ppb
= dev
->base
;
410 ppa_d_pulse(ppb
, 0x3c);
411 ppa_d_pulse(ppb
, 0x20);
412 ppa_d_pulse(ppb
, 0xf);
415 static inline void ppa_c_pulse(unsigned short ppb
, unsigned char b
)
424 static inline void ppa_connect(ppa_struct
*dev
, int flag
)
426 unsigned short ppb
= dev
->base
;
429 ppa_c_pulse(ppb
, 0x3c);
430 ppa_c_pulse(ppb
, 0x20);
431 if ((flag
== CONNECT_EPP_MAYBE
) && IN_EPP_MODE(dev
->mode
))
432 ppa_c_pulse(ppb
, 0xcf);
434 ppa_c_pulse(ppb
, 0x8f);
437 static int ppa_select(ppa_struct
*dev
, int target
)
440 unsigned short ppb
= dev
->base
;
443 * Bit 6 (0x40) is the device selected bit.
444 * First we must wait till the current device goes off line...
450 } while ((r_str(ppb
) & 0x40) && (k
));
454 w_dtr(ppb
, (1 << target
));
457 w_dtr(ppb
, 0x80); /* This is NOT the initator */
465 while (!(r_str(ppb
) & 0x40) && (k
));
473 * This is based on a trace of what the Iomega DOS 'guest' driver does.
474 * I've tried several different kinds of parallel ports with guest and
475 * coded this to react in the same ways that it does.
477 * The return value from this function is just a hint about where the
478 * handshaking failed.
481 static int ppa_init(ppa_struct
*dev
)
484 unsigned short ppb
= dev
->base
;
487 ppa_connect(dev
, CONNECT_NORMAL
);
489 retv
= 2; /* Failed */
492 if ((r_str(ppb
) & 0x08) == 0x08)
496 if ((r_str(ppb
) & 0x08) == 0x00)
500 ppa_reset_pulse(ppb
);
501 udelay(1000); /* Allow devices to settle down */
503 udelay(1000); /* Another delay to allow devices to settle */
508 return device_check(dev
);
511 static inline int ppa_send_command(struct scsi_cmnd
*cmd
)
513 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
516 w_ctr(dev
->base
, 0x0c);
518 for (k
= 0; k
< cmd
->cmd_len
; k
++)
519 if (!ppa_out(dev
, &cmd
->cmnd
[k
], 1))
525 * The bulk flag enables some optimisations in the data transfer loops,
526 * it should be true for any command that transfers data in integral
527 * numbers of sectors.
529 * The driver appears to remain stable if we speed up the parallel port
530 * i/o in this function, but not elsewhere.
532 static int ppa_completion(struct scsi_cmnd
*cmd
)
537 * 1 Finished data transfer
539 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
540 unsigned short ppb
= dev
->base
;
541 unsigned long start_jiffies
= jiffies
;
544 int fast
, bulk
, status
;
547 bulk
= ((v
== READ_6
) ||
548 (v
== READ_10
) || (v
== WRITE_6
) || (v
== WRITE_10
));
551 * We only get here if the drive is ready to comunicate,
552 * hence no need for a full ppa_wait.
554 r
= (r_str(ppb
) & 0xf0);
556 while (r
!= (unsigned char) 0xf0) {
558 * If we have been running for more than a full timer tick
561 if (time_after(jiffies
, start_jiffies
+ 1))
564 if ((cmd
->SCp
.this_residual
<= 0)) {
565 ppa_fail(dev
, DID_ERROR
);
566 return -1; /* ERROR_RETURN */
569 /* On some hardware we have SCSI disconnected (6th bit low)
570 * for about 100usecs. It is too expensive to wait a
571 * tick on every loop so we busy wait for no more than
572 * 500usecs to give the drive a chance first. We do not
573 * change things for "normal" hardware since generally
574 * the 6th bit is always high.
575 * This makes the CPU load higher on some hardware
576 * but otherwise we can not get more than 50K/secs
577 * on this problem hardware.
579 if ((r
& 0xc0) != 0xc0) {
580 /* Wait for reconnection should be no more than
581 * jiffy/2 = 5ms = 5000 loops
583 unsigned long k
= dev
->recon_tmo
;
584 for (; k
&& ((r
= (r_str(ppb
) & 0xf0)) & 0xc0) != 0xc0;
592 /* determine if we should use burst I/O */
593 fast
= (bulk
&& (cmd
->SCp
.this_residual
>= PPA_BURST_SIZE
))
594 ? PPA_BURST_SIZE
: 1;
596 if (r
== (unsigned char) 0xc0)
597 status
= ppa_out(dev
, cmd
->SCp
.ptr
, fast
);
599 status
= ppa_in(dev
, cmd
->SCp
.ptr
, fast
);
601 cmd
->SCp
.ptr
+= fast
;
602 cmd
->SCp
.this_residual
-= fast
;
605 ppa_fail(dev
, DID_BUS_BUSY
);
606 return -1; /* ERROR_RETURN */
608 if (cmd
->SCp
.buffer
&& !cmd
->SCp
.this_residual
) {
609 /* if scatter/gather, advance to the next segment */
610 if (cmd
->SCp
.buffers_residual
--) {
612 cmd
->SCp
.this_residual
=
613 cmd
->SCp
.buffer
->length
;
615 page_address(cmd
->SCp
.buffer
->page
) +
616 cmd
->SCp
.buffer
->offset
;
619 /* Now check to see if the drive is ready to comunicate */
620 r
= (r_str(ppb
) & 0xf0);
621 /* If not, drop back down to the scheduler and wait a timer tick */
625 return 1; /* FINISH_RETURN */
629 * Since the PPA itself doesn't generate interrupts, we use
630 * the scheduler's task queue to generate a stream of call-backs and
631 * complete the request when the drive is ready.
633 static void ppa_interrupt(void *data
)
635 ppa_struct
*dev
= (ppa_struct
*) data
;
636 struct scsi_cmnd
*cmd
= dev
->cur_cmd
;
639 printk("PPA: bug in ppa_interrupt\n");
642 if (ppa_engine(dev
, cmd
)) {
643 dev
->ppa_tq
.data
= (void *) dev
;
644 schedule_delayed_work(&dev
->ppa_tq
, 1);
647 /* Command must of completed hence it is safe to let go... */
649 switch ((cmd
->result
>> 16) & 0xff) {
653 printk("ppa: no device at SCSI ID %i\n", cmd
->device
->target
);
656 printk("ppa: BUS BUSY - EPP timeout detected\n");
659 printk("ppa: unknown timeout\n");
662 printk("ppa: told to abort\n");
665 printk("ppa: parity error (???)\n");
668 printk("ppa: internal driver error\n");
671 printk("ppa: told to reset device\n");
674 printk("ppa: bad interrupt (???)\n");
677 printk("ppa: bad return code (%02x)\n",
678 (cmd
->result
>> 16) & 0xff);
682 if (cmd
->SCp
.phase
> 1)
692 static int ppa_engine(ppa_struct
*dev
, struct scsi_cmnd
*cmd
)
694 unsigned short ppb
= dev
->base
;
695 unsigned char l
= 0, h
= 0;
698 /* First check for any errors that may of occurred
699 * Here we check for internal errors
704 switch (cmd
->SCp
.phase
) {
705 case 0: /* Phase 0 - Waiting for parport */
706 if (time_after(jiffies
, dev
->jstart
+ HZ
)) {
708 * We waited more than a second
709 * for parport to call us
711 ppa_fail(dev
, DID_BUS_BUSY
);
714 return 1; /* wait until ppa_wakeup claims parport */
715 case 1: /* Phase 1 - Connected */
716 { /* Perform a sanity check for cable unplugged */
717 int retv
= 2; /* Failed */
719 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
722 if ((r_str(ppb
) & 0x08) == 0x08)
726 if ((r_str(ppb
) & 0x08) == 0x00)
730 if (time_after(jiffies
, dev
->jstart
+ (1 * HZ
))) {
732 ("ppa: Parallel port cable is unplugged!!\n");
733 ppa_fail(dev
, DID_BUS_BUSY
);
737 return 1; /* Try again in a jiffy */
743 case 2: /* Phase 2 - We are now talking to the scsi bus */
744 if (!ppa_select(dev
, scmd_id(cmd
))) {
745 ppa_fail(dev
, DID_NO_CONNECT
);
750 case 3: /* Phase 3 - Ready to accept a command */
752 if (!(r_str(ppb
) & 0x80))
755 if (!ppa_send_command(cmd
))
759 case 4: /* Phase 4 - Setup scatter/gather buffers */
761 /* if many buffers are available, start filling the first */
763 (struct scatterlist
*) cmd
->request_buffer
;
764 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
766 page_address(cmd
->SCp
.buffer
->page
) +
767 cmd
->SCp
.buffer
->offset
;
769 /* else fill the only available buffer */
770 cmd
->SCp
.buffer
= NULL
;
771 cmd
->SCp
.this_residual
= cmd
->request_bufflen
;
772 cmd
->SCp
.ptr
= cmd
->request_buffer
;
774 cmd
->SCp
.buffers_residual
= cmd
->use_sg
- 1;
777 case 5: /* Phase 5 - Data transfer stage */
779 if (!(r_str(ppb
) & 0x80))
782 retv
= ppa_completion(cmd
);
789 case 6: /* Phase 6 - Read status/message */
790 cmd
->result
= DID_OK
<< 16;
791 /* Check for data overrun */
792 if (ppa_wait(dev
) != (unsigned char) 0xf0) {
793 ppa_fail(dev
, DID_ERROR
);
796 if (ppa_in(dev
, &l
, 1)) { /* read status byte */
797 /* Check for optional message byte */
798 if (ppa_wait(dev
) == (unsigned char) 0xf0)
801 (DID_OK
<< 16) + (h
<< 8) + (l
& STATUS_MASK
);
803 return 0; /* Finished */
807 printk("ppa: Invalid scsi phase\n");
812 static int ppa_queuecommand(struct scsi_cmnd
*cmd
,
813 void (*done
) (struct scsi_cmnd
*))
815 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
818 printk("PPA: bug in ppa_queuecommand\n");
822 dev
->jstart
= jiffies
;
824 cmd
->scsi_done
= done
;
825 cmd
->result
= DID_ERROR
<< 16; /* default return code */
826 cmd
->SCp
.phase
= 0; /* bus free */
828 dev
->ppa_tq
.data
= dev
;
829 schedule_work(&dev
->ppa_tq
);
837 * Apparently the disk->capacity attribute is off by 1 sector
838 * for all disk drives. We add the one here, but it should really
839 * be done in sd.c. Even if it gets fixed there, this will still
842 static int ppa_biosparam(struct scsi_device
*sdev
, struct block_device
*dev
,
843 sector_t capacity
, int ip
[])
847 ip
[2] = ((unsigned long) capacity
+ 1) / (ip
[0] * ip
[1]);
851 ip
[2] = ((unsigned long) capacity
+ 1) / (ip
[0] * ip
[1]);
858 static int ppa_abort(struct scsi_cmnd
*cmd
)
860 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
862 * There is no method for aborting commands since Iomega
863 * have tied the SCSI_MESSAGE line high in the interface
866 switch (cmd
->SCp
.phase
) {
867 case 0: /* Do not have access to parport */
868 case 1: /* Have not connected to interface */
869 dev
->cur_cmd
= NULL
; /* Forget the problem */
872 default: /* SCSI command sent, can not abort */
878 static void ppa_reset_pulse(unsigned int base
)
886 static int ppa_reset(struct scsi_cmnd
*cmd
)
888 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
892 dev
->cur_cmd
= NULL
; /* Forget the problem */
894 ppa_connect(dev
, CONNECT_NORMAL
);
895 ppa_reset_pulse(dev
->base
);
896 mdelay(1); /* device settle delay */
898 mdelay(1); /* device settle delay */
902 static int device_check(ppa_struct
*dev
)
904 /* This routine looks for a device and then attempts to use EPP
905 to send a command. If all goes as planned then EPP is available. */
907 static char cmd
[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
908 int loop
, old_mode
, status
, k
, ppb
= dev
->base
;
911 old_mode
= dev
->mode
;
912 for (loop
= 0; loop
< 8; loop
++) {
913 /* Attempt to use EPP for Test Unit Ready */
914 if ((ppb
& 0x0007) == 0x0000)
915 dev
->mode
= PPA_EPP_32
;
918 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
919 /* Select SCSI device */
920 if (!ppa_select(dev
, loop
)) {
924 printk("ppa: Found device at ID %i, Attempting to use %s\n",
925 loop
, PPA_MODE_STRING
[dev
->mode
]);
927 /* Send SCSI command */
930 for (l
= 0; (l
< 6) && (status
); l
++)
931 status
= ppa_out(dev
, cmd
, 1);
935 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
943 if (dev
->mode
== PPA_EPP_32
) {
944 dev
->mode
= old_mode
;
950 k
= 1000000; /* 1 Second */
955 } while (!(l
& 0x80) && (k
));
961 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
962 ppa_reset_pulse(ppb
);
966 if (dev
->mode
== PPA_EPP_32
) {
967 dev
->mode
= old_mode
;
973 printk("ppa: Communication established with ID %i using %s\n",
974 loop
, PPA_MODE_STRING
[dev
->mode
]);
975 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
976 ppa_reset_pulse(ppb
);
985 static struct scsi_host_template ppa_template
= {
986 .module
= THIS_MODULE
,
988 .proc_info
= ppa_proc_info
,
989 .name
= "Iomega VPI0 (ppa) interface",
990 .queuecommand
= ppa_queuecommand
,
991 .eh_abort_handler
= ppa_abort
,
992 .eh_bus_reset_handler
= ppa_reset
,
993 .eh_host_reset_handler
= ppa_reset
,
994 .bios_param
= ppa_biosparam
,
996 .sg_tablesize
= SG_ALL
,
998 .use_clustering
= ENABLE_CLUSTERING
,
1002 /***************************************************************************
1003 * Parallel port probing routines *
1004 ***************************************************************************/
1006 static LIST_HEAD(ppa_hosts
);
1008 static int __ppa_attach(struct parport
*pb
)
1010 struct Scsi_Host
*host
;
1011 DECLARE_WAIT_QUEUE_HEAD(waiting
);
1015 int modes
, ppb
, ppb_hi
;
1018 dev
= kmalloc(sizeof(ppa_struct
), GFP_KERNEL
);
1021 memset(dev
, 0, sizeof(ppa_struct
));
1023 dev
->mode
= PPA_AUTODETECT
;
1024 dev
->recon_tmo
= PPA_RECON_TMO
;
1025 init_waitqueue_head(&waiting
);
1026 dev
->dev
= parport_register_device(pb
, "ppa", NULL
, ppa_wakeup
,
1032 /* Claim the bus so it remembers what we do to the control
1033 * registers. [ CTR and ECP ]
1036 dev
->waiting
= &waiting
;
1037 prepare_to_wait(&waiting
, &wait
, TASK_UNINTERRUPTIBLE
);
1038 if (ppa_pb_claim(dev
))
1039 schedule_timeout(3 * HZ
);
1041 printk(KERN_ERR
"ppa%d: failed to claim parport because "
1042 "a pardevice is owning the port for too long "
1043 "time!\n", pb
->number
);
1044 ppa_pb_dismiss(dev
);
1045 dev
->waiting
= NULL
;
1046 finish_wait(&waiting
, &wait
);
1049 dev
->waiting
= NULL
;
1050 finish_wait(&waiting
, &wait
);
1051 ppb
= dev
->base
= dev
->dev
->port
->base
;
1052 ppb_hi
= dev
->dev
->port
->base_hi
;
1054 modes
= dev
->dev
->port
->modes
;
1056 /* Mode detection works up the chain of speed
1057 * This avoids a nasty if-then-else-if-... tree
1059 dev
->mode
= PPA_NIBBLE
;
1061 if (modes
& PARPORT_MODE_TRISTATE
)
1062 dev
->mode
= PPA_PS2
;
1064 if (modes
& PARPORT_MODE_ECP
) {
1065 w_ecr(ppb_hi
, 0x20);
1066 dev
->mode
= PPA_PS2
;
1068 if ((modes
& PARPORT_MODE_EPP
) && (modes
& PARPORT_MODE_ECP
))
1069 w_ecr(ppb_hi
, 0x80);
1071 /* Done configuration */
1073 err
= ppa_init(dev
);
1074 ppa_pb_release(dev
);
1079 /* now the glue ... */
1080 if (dev
->mode
== PPA_NIBBLE
|| dev
->mode
== PPA_PS2
)
1085 INIT_WORK(&dev
->ppa_tq
, ppa_interrupt
, dev
);
1088 host
= scsi_host_alloc(&ppa_template
, sizeof(ppa_struct
*));
1091 host
->io_port
= pb
->base
;
1092 host
->n_io_port
= ports
;
1093 host
->dma_channel
= -1;
1094 host
->unique_id
= pb
->number
;
1095 *(ppa_struct
**)&host
->hostdata
= dev
;
1097 list_add_tail(&dev
->list
, &ppa_hosts
);
1098 err
= scsi_add_host(host
, NULL
);
1101 scsi_scan_host(host
);
1104 list_del_init(&dev
->list
);
1105 scsi_host_put(host
);
1107 parport_unregister_device(dev
->dev
);
1113 static void ppa_attach(struct parport
*pb
)
1118 static void ppa_detach(struct parport
*pb
)
1121 list_for_each_entry(dev
, &ppa_hosts
, list
) {
1122 if (dev
->dev
->port
== pb
) {
1123 list_del_init(&dev
->list
);
1124 scsi_remove_host(dev
->host
);
1125 scsi_host_put(dev
->host
);
1126 parport_unregister_device(dev
->dev
);
1133 static struct parport_driver ppa_driver
= {
1135 .attach
= ppa_attach
,
1136 .detach
= ppa_detach
,
1139 static int __init
ppa_driver_init(void)
1141 printk("ppa: Version %s\n", PPA_VERSION
);
1142 return parport_register_driver(&ppa_driver
);
1145 static void __exit
ppa_driver_exit(void)
1147 parport_unregister_driver(&ppa_driver
);
1150 module_init(ppa_driver_init
);
1151 module_exit(ppa_driver_exit
);
1152 MODULE_LICENSE("GPL");