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 Public License.
9 * Current Maintainer: David Campbell (Perth, Western Australia, GMT+0800)
13 #include <linux/config.h>
15 /* The following #define is to avoid a clash with hosts.c */
18 #include <linux/blk.h>
20 #include <linux/parport.h>
23 int ppa_release(struct Scsi_Host
*);
24 static void ppa_reset_pulse(unsigned int base
);
27 struct pardevice
*dev
; /* Parport device entry */
28 int base
; /* Actual port address */
29 int mode
; /* Transfer mode */
30 int host
; /* Host number (for proc) */
31 Scsi_Cmnd
*cur_cmd
; /* Current queued command */
32 struct tq_struct ppa_tq
; /* Polling interupt stuff */
33 unsigned long jstart
; /* Jiffies at start */
34 unsigned int failed
:1; /* Failure flag */
35 unsigned int p_busy
:1; /* Parport sharing busy flag */
41 mode: PPA_AUTODETECT, \
44 ppa_tq: {0, 0, ppa_interrupt, NULL}, \
53 static ppa_struct ppa_hosts
[NO_HOSTS
] =
54 {PPA_EMPTY
, PPA_EMPTY
, PPA_EMPTY
, PPA_EMPTY
};
56 #define PPA_BASE(x) ppa_hosts[(x)].base
58 void ppa_wakeup(void *ref
)
60 ppa_struct
*ppa_dev
= (ppa_struct
*) ref
;
65 if (parport_claim(ppa_dev
->dev
)) {
66 printk("ppa: bug in ppa_wakeup\n");
70 ppa_dev
->base
= ppa_dev
->dev
->port
->base
;
72 ppa_dev
->cur_cmd
->SCp
.phase
++;
76 int ppa_release(struct Scsi_Host
*host
)
78 int host_no
= host
->unique_id
;
80 printk("Releasing ppa%i\n", host_no
);
81 parport_unregister_device(ppa_hosts
[host_no
].dev
);
85 static int ppa_pb_claim(int host_no
)
87 if (parport_claim(ppa_hosts
[host_no
].dev
)) {
88 ppa_hosts
[host_no
].p_busy
= 1;
91 if (ppa_hosts
[host_no
].cur_cmd
)
92 ppa_hosts
[host_no
].cur_cmd
->SCp
.phase
++;
96 #define ppa_pb_release(x) parport_release(ppa_hosts[(x)].dev)
98 /***************************************************************************
99 * Parallel port probing routines *
100 ***************************************************************************/
103 Scsi_Host_Template driver_template
= PPA
;
104 #include "scsi_module.c"
108 * Start of Chipset kludges
111 int ppa_detect(Scsi_Host_Template
* host
)
113 struct Scsi_Host
*hreg
;
115 int i
, nhosts
, try_again
;
116 struct parport
*pb
= parport_enumerate();
118 printk("ppa: Version %s\n", PPA_VERSION
);
123 printk("ppa: parport reports no devices.\n");
127 for (i
= 0; pb
; i
++, pb
= pb
->next
) {
131 parport_register_device(pb
, "ppa", NULL
, ppa_wakeup
,
132 NULL
, 0, (void *) &ppa_hosts
[i
]);
134 if (!ppa_hosts
[i
].dev
)
137 /* Claim the bus so it remembers what we do to the control
138 * registers. [ CTR and ECP ]
140 if (ppa_pb_claim(i
)) {
141 unsigned long now
= jiffies
;
142 while (ppa_hosts
[i
].p_busy
) {
143 schedule(); /* We are safe to schedule here */
144 if (time_after(jiffies
, now
+ 3 * HZ
)) {
145 printk(KERN_ERR
"ppa%d: failed to claim parport because a "
146 "pardevice is owning the port for too longtime!\n",
152 ppb
= PPA_BASE(i
) = ppa_hosts
[i
].dev
->port
->base
;
154 modes
= ppa_hosts
[i
].dev
->port
->modes
;
156 /* Mode detection works up the chain of speed
157 * This avoids a nasty if-then-else-if-... tree
159 ppa_hosts
[i
].mode
= PPA_NIBBLE
;
161 if (modes
& PARPORT_MODE_TRISTATE
)
162 ppa_hosts
[i
].mode
= PPA_PS2
;
164 if (modes
& PARPORT_MODE_ECP
) {
166 ppa_hosts
[i
].mode
= PPA_PS2
;
168 if ((modes
& PARPORT_MODE_EPP
) && (modes
& PARPORT_MODE_ECP
))
171 /* Done configuration */
175 parport_unregister_device(ppa_hosts
[i
].dev
);
178 /* now the glue ... */
179 switch (ppa_hosts
[i
].mode
) {
191 default: /* Never gets here */
195 host
->can_queue
= PPA_CAN_QUEUE
;
196 host
->sg_tablesize
= ppa_sg
;
197 hreg
= scsi_register(host
, 0);
198 hreg
->io_port
= pb
->base
;
199 hreg
->n_io_port
= ports
;
200 hreg
->dma_channel
= -1;
202 ppa_hosts
[i
].host
= hreg
->host_no
;
206 if (try_again
== 1) {
207 printk("WARNING - no ppa compatible devices found.\n");
208 printk(" As of 31/Aug/1998 Iomega started shipping parallel\n");
209 printk(" port ZIP drives with a different interface which is\n");
210 printk(" supported by the imm (ZIP Plus) driver. If the\n");
211 printk(" cable is marked with \"AutoDetect\", this is what has\n");
212 printk(" happened.\n");
218 return 1; /* return number of hosts detected */
221 /* This is to give the ppa driver a way to modify the timings (and other
222 * parameters) by writing to the /proc/scsi/ppa/0 file.
223 * Very simple method really... (To simple, no error checking :( )
224 * Reason: Kernel hackers HATE having to unload and reload modules for
226 * Also gives a method to use a script to obtain optimum timings (TODO)
229 static inline int ppa_proc_write(int hostno
, char *buffer
, int length
)
233 if ((length
> 5) && (strncmp(buffer
, "mode=", 5) == 0)) {
234 x
= simple_strtoul(buffer
+ 5, NULL
, 0);
235 ppa_hosts
[hostno
].mode
= x
;
238 printk("ppa /proc: invalid variable\n");
242 int ppa_proc_info(char *buffer
, char **start
, off_t offset
,
243 int length
, int hostno
, int inout
)
248 for (i
= 0; i
< 4; i
++)
249 if (ppa_hosts
[i
].host
== hostno
)
253 return ppa_proc_write(i
, buffer
, length
);
255 len
+= sprintf(buffer
+ len
, "Version : %s\n", PPA_VERSION
);
256 len
+= sprintf(buffer
+ len
, "Parport : %s\n", ppa_hosts
[i
].dev
->port
->name
);
257 len
+= sprintf(buffer
+ len
, "Mode : %s\n", PPA_MODE_STRING
[ppa_hosts
[i
].mode
]);
259 /* Request for beyond end of buffer */
263 *start
= buffer
+ offset
;
270 static int device_check(int host_no
);
273 #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
274 y, __FUNCTION__, __LINE__); ppa_fail_func(x,y);
275 static inline void ppa_fail_func(int host_no
, int error_code
)
277 static inline void ppa_fail(int host_no
, int error_code
)
280 /* If we fail a device then we trash status / message bytes */
281 if (ppa_hosts
[host_no
].cur_cmd
) {
282 ppa_hosts
[host_no
].cur_cmd
->result
= error_code
<< 16;
283 ppa_hosts
[host_no
].failed
= 1;
288 * Wait for the high bit to be set.
290 * In principle, this could be tied to an interrupt, but the adapter
291 * doesn't appear to be designed to support interrupts. We spin on
292 * the 0x80 ready bit.
294 static unsigned char ppa_wait(int host_no
)
297 unsigned short ppb
= PPA_BASE(host_no
);
306 while (!(r
& 0x80) && (k
));
309 * return some status information.
310 * Semantics: 0xc0 = ZIP wants more data
311 * 0xd0 = ZIP wants to send more data
312 * 0xe0 = ZIP is expecting SCSI command data
313 * 0xf0 = end of transfer, ZIP is sending status
318 /* Counter expired - Time out occurred */
319 ppa_fail(host_no
, DID_TIME_OUT
);
320 printk("ppa timeout in ppa_wait\n");
321 return 0; /* command timed out */
325 * output a string, in whatever mode is available, according to the
328 static inline void epp_reset(unsigned short ppb
)
334 w_str(ppb
, i
& 0xfe);
337 static inline void ecp_sync(unsigned short ppb
)
341 if ((r_ecr(ppb
) & 0xe0) != 0x80)
344 for (i
= 0; i
< 100; i
++) {
345 if (r_ecr(ppb
) & 0x01)
349 printk("ppa: ECP sync failed as data still present in FIFO.\n");
352 static int ppa_byte_out(unsigned short base
, const char *buffer
, int len
)
356 for (i
= len
; i
; i
--) {
357 w_dtr(base
, *buffer
++);
361 return 1; /* All went well - we hope! */
364 static int ppa_byte_in(unsigned short base
, char *buffer
, int len
)
368 for (i
= len
; i
; i
--) {
369 *buffer
++ = r_dtr(base
);
373 return 1; /* All went well - we hope! */
376 static int ppa_nibble_in(unsigned short base
, char *buffer
, int len
)
382 h
= r_str(base
) & 0xf0;
384 *buffer
++ = h
| ((r_str(base
) & 0xf0) >> 4);
386 return 1; /* All went well - we hope! */
389 static int ppa_out(int host_no
, char *buffer
, int len
)
392 unsigned short ppb
= PPA_BASE(host_no
);
394 r
= ppa_wait(host_no
);
396 if ((r
& 0x50) != 0x40) {
397 ppa_fail(host_no
, DID_ERROR
);
400 switch (ppa_hosts
[host_no
].mode
) {
403 /* 8 bit output, with a loop */
404 r
= ppa_byte_out(ppb
, buffer
, len
);
412 #ifdef CONFIG_SCSI_IZIP_EPP16
413 if (!(((long) buffer
| len
) & 0x01))
414 outsw(ppb
+ 4, buffer
, len
>> 1);
416 if (!(((long) buffer
| len
) & 0x03))
417 outsl(ppb
+ 4, buffer
, len
>> 2);
420 outsb(ppb
+ 4, buffer
, len
);
422 r
= !(r_str(ppb
) & 0x01);
428 printk("PPA: bug in ppa_out()\n");
434 static int ppa_in(int host_no
, char *buffer
, int len
)
437 unsigned short ppb
= PPA_BASE(host_no
);
439 r
= ppa_wait(host_no
);
441 if ((r
& 0x50) != 0x50) {
442 ppa_fail(host_no
, DID_ERROR
);
445 switch (ppa_hosts
[host_no
].mode
) {
447 /* 4 bit input, with a loop */
448 r
= ppa_nibble_in(ppb
, buffer
, len
);
453 /* 8 bit input, with a loop */
455 r
= ppa_byte_in(ppb
, buffer
, len
);
465 #ifdef CONFIG_SCSI_IZIP_EPP16
466 if (!(((long) buffer
| len
) & 0x01))
467 insw(ppb
+ 4, buffer
, len
>> 1);
469 if (!(((long) buffer
| len
) & 0x03))
470 insl(ppb
+ 4, buffer
, len
>> 2);
473 insb(ppb
+ 4, buffer
, len
);
475 r
= !(r_str(ppb
) & 0x01);
481 printk("PPA: bug in ppa_ins()\n");
488 /* end of ppa_io.h */
489 static inline void ppa_d_pulse(unsigned short ppb
, unsigned char b
)
499 static void ppa_disconnect(int host_no
)
501 unsigned short ppb
= PPA_BASE(host_no
);
504 ppa_d_pulse(ppb
, 0x3c);
505 ppa_d_pulse(ppb
, 0x20);
506 ppa_d_pulse(ppb
, 0xf);
509 static inline void ppa_c_pulse(unsigned short ppb
, unsigned char b
)
518 static inline void ppa_connect(int host_no
, int flag
)
520 unsigned short ppb
= PPA_BASE(host_no
);
523 ppa_c_pulse(ppb
, 0x3c);
524 ppa_c_pulse(ppb
, 0x20);
525 if ((flag
== CONNECT_EPP_MAYBE
) &&
526 IN_EPP_MODE(ppa_hosts
[host_no
].mode
))
527 ppa_c_pulse(ppb
, 0xcf);
529 ppa_c_pulse(ppb
, 0x8f);
532 static int ppa_select(int host_no
, int target
)
535 unsigned short ppb
= PPA_BASE(host_no
);
538 * Bit 6 (0x40) is the device selected bit.
539 * First we must wait till the current device goes off line...
544 } while ((r_str(ppb
) & 0x40) && (k
));
548 w_dtr(ppb
, (1 << target
));
551 w_dtr(ppb
, 0x80); /* This is NOT the initator */
558 while (!(r_str(ppb
) & 0x40) && (k
));
566 * This is based on a trace of what the Iomega DOS 'guest' driver does.
567 * I've tried several different kinds of parallel ports with guest and
568 * coded this to react in the same ways that it does.
570 * The return value from this function is just a hint about where the
571 * handshaking failed.
574 static int ppa_init(int host_no
)
577 unsigned short ppb
= PPA_BASE(host_no
);
579 #if defined(CONFIG_PARPORT) || defined(CONFIG_PARPORT_MODULE)
580 if (ppa_pb_claim(host_no
))
581 while (ppa_hosts
[host_no
].p_busy
)
582 schedule(); /* We can safe schedule here */
585 ppa_disconnect(host_no
);
586 ppa_connect(host_no
, CONNECT_NORMAL
);
588 retv
= 2; /* Failed */
591 if ((r_str(ppb
) & 0x08) == 0x08)
595 if ((r_str(ppb
) & 0x08) == 0x00)
599 ppa_reset_pulse(ppb
);
600 udelay(1000); /* Allow devices to settle down */
601 ppa_disconnect(host_no
);
602 udelay(1000); /* Another delay to allow devices to settle */
605 retv
= device_check(host_no
);
607 ppa_pb_release(host_no
);
611 static inline int ppa_send_command(Scsi_Cmnd
* cmd
)
613 int host_no
= cmd
->host
->unique_id
;
616 w_ctr(PPA_BASE(host_no
), 0x0c);
618 for (k
= 0; k
< cmd
->cmd_len
; k
++)
619 if (!ppa_out(host_no
, &cmd
->cmnd
[k
], 1))
625 * The bulk flag enables some optimisations in the data transfer loops,
626 * it should be true for any command that transfers data in integral
627 * numbers of sectors.
629 * The driver appears to remain stable if we speed up the parallel port
630 * i/o in this function, but not elsewhere.
632 static int ppa_completion(Scsi_Cmnd
* cmd
)
637 * 1 Finished data transfer
639 int host_no
= cmd
->host
->unique_id
;
640 unsigned short ppb
= PPA_BASE(host_no
);
641 unsigned long start_jiffies
= jiffies
;
644 int fast
, bulk
, status
;
647 bulk
= ((v
== READ_6
) ||
653 * We only get here if the drive is ready to comunicate,
654 * hence no need for a full ppa_wait.
656 r
= (r_str(ppb
) & 0xf0);
658 while (r
!= (unsigned char) 0xf0) {
660 * If we have been running for more than a full timer tick
663 if (time_after(jiffies
, start_jiffies
+ 1))
666 if (((r
& 0xc0) != 0xc0) || (cmd
->SCp
.this_residual
<= 0)) {
667 ppa_fail(host_no
, DID_ERROR
);
668 return -1; /* ERROR_RETURN */
670 /* determine if we should use burst I/O */ fast
= (bulk
&& (cmd
->SCp
.this_residual
>= PPA_BURST_SIZE
))
671 ? PPA_BURST_SIZE
: 1;
673 if (r
== (unsigned char) 0xc0)
674 status
= ppa_out(host_no
, cmd
->SCp
.ptr
, fast
);
676 status
= ppa_in(host_no
, cmd
->SCp
.ptr
, fast
);
678 cmd
->SCp
.ptr
+= fast
;
679 cmd
->SCp
.this_residual
-= fast
;
682 ppa_fail(host_no
, DID_BUS_BUSY
);
683 return -1; /* ERROR_RETURN */
685 if (cmd
->SCp
.buffer
&& !cmd
->SCp
.this_residual
) {
686 /* if scatter/gather, advance to the next segment */
687 if (cmd
->SCp
.buffers_residual
--) {
689 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
690 cmd
->SCp
.ptr
= cmd
->SCp
.buffer
->address
;
693 /* Now check to see if the drive is ready to comunicate */
694 r
= (r_str(ppb
) & 0xf0);
695 /* If not, drop back down to the scheduler and wait a timer tick */
699 return 1; /* FINISH_RETURN */
702 /* deprecated synchronous interface */
703 int ppa_command(Scsi_Cmnd
* cmd
)
705 static int first_pass
= 1;
706 int host_no
= cmd
->host
->unique_id
;
709 printk("ppa: using non-queuing interface\n");
712 if (ppa_hosts
[host_no
].cur_cmd
) {
713 printk("PPA: bug in ppa_command\n");
716 ppa_hosts
[host_no
].failed
= 0;
717 ppa_hosts
[host_no
].jstart
= jiffies
;
718 ppa_hosts
[host_no
].cur_cmd
= cmd
;
719 cmd
->result
= DID_ERROR
<< 16; /* default return code */
722 ppa_pb_claim(host_no
);
724 while (ppa_engine(&ppa_hosts
[host_no
], cmd
))
727 if (cmd
->SCp
.phase
) /* Only disconnect if we have connected */
728 ppa_disconnect(cmd
->host
->unique_id
);
730 ppa_pb_release(host_no
);
731 ppa_hosts
[host_no
].cur_cmd
= 0;
736 * Since the PPA itself doesn't generate interrupts, we use
737 * the scheduler's task queue to generate a stream of call-backs and
738 * complete the request when the drive is ready.
740 static void ppa_interrupt(void *data
)
742 ppa_struct
*tmp
= (ppa_struct
*) data
;
743 Scsi_Cmnd
*cmd
= tmp
->cur_cmd
;
747 printk("PPA: bug in ppa_interrupt\n");
750 if (ppa_engine(tmp
, cmd
)) {
751 tmp
->ppa_tq
.data
= (void *) tmp
;
752 tmp
->ppa_tq
.sync
= 0;
753 queue_task(&tmp
->ppa_tq
, &tq_timer
);
756 /* Command must of completed hence it is safe to let go... */
758 switch ((cmd
->result
>> 16) & 0xff) {
762 printk("ppa: no device at SCSI ID %i\n", cmd
->target
);
765 printk("ppa: BUS BUSY - EPP timeout detected\n");
768 printk("ppa: unknown timeout\n");
771 printk("ppa: told to abort\n");
774 printk("ppa: parity error (???)\n");
777 printk("ppa: internal driver error\n");
780 printk("ppa: told to reset device\n");
783 printk("ppa: bad interrupt (???)\n");
786 printk("ppa: bad return code (%02x)\n", (cmd
->result
>> 16) & 0xff);
790 if (cmd
->SCp
.phase
> 1)
791 ppa_disconnect(cmd
->host
->unique_id
);
792 if (cmd
->SCp
.phase
> 0)
793 ppa_pb_release(cmd
->host
->unique_id
);
797 spin_lock_irqsave(&io_request_lock
, flags
);
799 spin_unlock_irqrestore(&io_request_lock
, flags
);
803 static int ppa_engine(ppa_struct
* tmp
, Scsi_Cmnd
* cmd
)
805 int host_no
= cmd
->host
->unique_id
;
806 unsigned short ppb
= PPA_BASE(host_no
);
807 unsigned char l
= 0, h
= 0;
810 /* First check for any errors that may of occurred
811 * Here we check for internal errors
816 switch (cmd
->SCp
.phase
) {
817 case 0: /* Phase 0 - Waiting for parport */
818 if ((jiffies
- tmp
->jstart
) > HZ
) {
820 * We waited more than a second
821 * for parport to call us
823 ppa_fail(host_no
, DID_BUS_BUSY
);
826 return 1; /* wait until ppa_wakeup claims parport */
827 case 1: /* Phase 1 - Connected */
828 { /* Perform a sanity check for cable unplugged */
829 int retv
= 2; /* Failed */
831 ppa_connect(host_no
, CONNECT_EPP_MAYBE
);
834 if ((r_str(ppb
) & 0x08) == 0x08)
838 if ((r_str(ppb
) & 0x08) == 0x00)
842 if ((jiffies
- tmp
->jstart
) > (1 * HZ
)) {
843 printk("ppa: Parallel port cable is unplugged!!\n");
844 ppa_fail(host_no
, DID_BUS_BUSY
);
847 ppa_disconnect(host_no
);
848 return 1; /* Try again in a jiffy */
854 case 2: /* Phase 2 - We are now talking to the scsi bus */
855 if (!ppa_select(host_no
, cmd
->target
)) {
856 ppa_fail(host_no
, DID_NO_CONNECT
);
861 case 3: /* Phase 3 - Ready to accept a command */
863 if (!(r_str(ppb
) & 0x80))
866 if (!ppa_send_command(cmd
))
870 case 4: /* Phase 4 - Setup scatter/gather buffers */
872 /* if many buffers are available, start filling the first */
873 cmd
->SCp
.buffer
= (struct scatterlist
*) cmd
->request_buffer
;
874 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
875 cmd
->SCp
.ptr
= cmd
->SCp
.buffer
->address
;
877 /* else fill the only available buffer */
878 cmd
->SCp
.buffer
= NULL
;
879 cmd
->SCp
.this_residual
= cmd
->request_bufflen
;
880 cmd
->SCp
.ptr
= cmd
->request_buffer
;
882 cmd
->SCp
.buffers_residual
= cmd
->use_sg
;
885 case 5: /* Phase 5 - Data transfer stage */
887 if (!(r_str(ppb
) & 0x80))
890 retv
= ppa_completion(cmd
);
897 case 6: /* Phase 6 - Read status/message */
898 cmd
->result
= DID_OK
<< 16;
899 /* Check for data overrun */
900 if (ppa_wait(host_no
) != (unsigned char) 0xf0) {
901 ppa_fail(host_no
, DID_ERROR
);
904 if (ppa_in(host_no
, &l
, 1)) { /* read status byte */
905 /* Check for optional message byte */
906 if (ppa_wait(host_no
) == (unsigned char) 0xf0)
907 ppa_in(host_no
, &h
, 1);
908 cmd
->result
= (DID_OK
<< 16) + (h
<< 8) + (l
& STATUS_MASK
);
910 return 0; /* Finished */
914 printk("ppa: Invalid scsi phase\n");
919 int ppa_queuecommand(Scsi_Cmnd
* cmd
, void (*done
) (Scsi_Cmnd
*))
921 int host_no
= cmd
->host
->unique_id
;
923 if (ppa_hosts
[host_no
].cur_cmd
) {
924 printk("PPA: bug in ppa_queuecommand\n");
927 ppa_hosts
[host_no
].failed
= 0;
928 ppa_hosts
[host_no
].jstart
= jiffies
;
929 ppa_hosts
[host_no
].cur_cmd
= cmd
;
930 cmd
->scsi_done
= done
;
931 cmd
->result
= DID_ERROR
<< 16; /* default return code */
932 cmd
->SCp
.phase
= 0; /* bus free */
934 ppa_pb_claim(host_no
);
936 ppa_hosts
[host_no
].ppa_tq
.data
= ppa_hosts
+ host_no
;
937 ppa_hosts
[host_no
].ppa_tq
.sync
= 0;
938 queue_task(&ppa_hosts
[host_no
].ppa_tq
, &tq_immediate
);
939 mark_bh(IMMEDIATE_BH
);
945 * Apparently the the disk->capacity attribute is off by 1 sector
946 * for all disk drives. We add the one here, but it should really
947 * be done in sd.c. Even if it gets fixed there, this will still
950 int ppa_biosparam(Disk
* disk
, kdev_t dev
, int ip
[])
954 ip
[2] = (disk
->capacity
+ 1) / (ip
[0] * ip
[1]);
958 ip
[2] = (disk
->capacity
+ 1) / (ip
[0] * ip
[1]);
965 int ppa_abort(Scsi_Cmnd
* cmd
)
967 int host_no
= cmd
->host
->unique_id
;
969 * There is no method for aborting commands since Iomega
970 * have tied the SCSI_MESSAGE line high in the interface
973 switch (cmd
->SCp
.phase
) {
974 case 0: /* Do not have access to parport */
975 case 1: /* Have not connected to interface */
976 ppa_hosts
[host_no
].cur_cmd
= NULL
; /* Forget the problem */
979 default: /* SCSI command sent, can not abort */
985 static void ppa_reset_pulse(unsigned int base
)
993 int ppa_reset(Scsi_Cmnd
* cmd
)
995 int host_no
= cmd
->host
->unique_id
;
998 ppa_disconnect(host_no
);
999 ppa_hosts
[host_no
].cur_cmd
= NULL
; /* Forget the problem */
1001 ppa_connect(host_no
, CONNECT_NORMAL
);
1002 ppa_reset_pulse(PPA_BASE(host_no
));
1003 udelay(1000); /* device settle delay */
1004 ppa_disconnect(host_no
);
1005 udelay(1000); /* device settle delay */
1009 static int device_check(int host_no
)
1011 /* This routine looks for a device and then attempts to use EPP
1012 to send a command. If all goes as planned then EPP is available. */
1014 static char cmd
[6] =
1015 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1016 int loop
, old_mode
, status
, k
, ppb
= PPA_BASE(host_no
);
1019 old_mode
= ppa_hosts
[host_no
].mode
;
1020 for (loop
= 0; loop
< 8; loop
++) {
1021 /* Attempt to use EPP for Test Unit Ready */
1022 if ((ppb
& 0x0007) == 0x0000)
1023 ppa_hosts
[host_no
].mode
= PPA_EPP_32
;
1026 ppa_connect(host_no
, CONNECT_EPP_MAYBE
);
1027 /* Select SCSI device */
1028 if (!ppa_select(host_no
, loop
)) {
1029 ppa_disconnect(host_no
);
1032 printk("ppa: Found device at ID %i, Attempting to use %s\n", loop
,
1033 PPA_MODE_STRING
[ppa_hosts
[host_no
].mode
]);
1035 /* Send SCSI command */
1038 for (l
= 0; (l
< 6) && (status
); l
++)
1039 status
= ppa_out(host_no
, cmd
, 1);
1042 ppa_disconnect(host_no
);
1043 ppa_connect(host_no
, CONNECT_EPP_MAYBE
);
1049 ppa_disconnect(host_no
);
1051 if (ppa_hosts
[host_no
].mode
== PPA_EPP_32
) {
1052 ppa_hosts
[host_no
].mode
= old_mode
;
1055 printk("ppa: Unable to establish communication, aborting driver load.\n");
1059 k
= 1000000; /* 1 Second */
1064 } while (!(l
& 0x80) && (k
));
1069 ppa_disconnect(host_no
);
1070 ppa_connect(host_no
, CONNECT_EPP_MAYBE
);
1071 ppa_reset_pulse(ppb
);
1073 ppa_disconnect(host_no
);
1075 if (ppa_hosts
[host_no
].mode
== PPA_EPP_32
) {
1076 ppa_hosts
[host_no
].mode
= old_mode
;
1079 printk("ppa: Unable to establish communication, aborting driver load.\n");
1082 ppa_disconnect(host_no
);
1083 printk("ppa: Communication established with ID %i using %s\n", loop
,
1084 PPA_MODE_STRING
[ppa_hosts
[host_no
].mode
]);
1085 ppa_connect(host_no
, CONNECT_EPP_MAYBE
);
1086 ppa_reset_pulse(ppb
);
1088 ppa_disconnect(host_no
);
1092 printk("ppa: No devices found, aborting driver load.\n");