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.
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/blkdev.h>
16 #include <linux/parport.h>
17 #include <linux/workqueue.h>
18 #include <linux/delay.h>
19 #include <linux/jiffies.h>
22 #include <scsi/scsi.h>
23 #include <scsi/scsi_cmnd.h>
24 #include <scsi/scsi_device.h>
25 #include <scsi/scsi_host.h>
28 static void ppa_reset_pulse(unsigned int base
);
31 struct pardevice
*dev
; /* Parport device entry */
32 int base
; /* Actual port address */
33 int mode
; /* Transfer mode */
34 struct scsi_cmnd
*cur_cmd
; /* Current queued command */
35 struct delayed_work ppa_tq
; /* Polling interrupt stuff */
36 unsigned long jstart
; /* Jiffies at start */
37 unsigned long recon_tmo
; /* How many usecs to wait for reconnection (6th bit) */
38 unsigned int failed
:1; /* Failure flag */
39 unsigned wanted
:1; /* Parport sharing busy flag */
40 wait_queue_head_t
*waiting
;
41 struct Scsi_Host
*host
;
42 struct list_head list
;
47 static inline ppa_struct
*ppa_dev(struct Scsi_Host
*host
)
49 return *(ppa_struct
**)&host
->hostdata
;
52 static DEFINE_SPINLOCK(arbitration_lock
);
54 static void got_it(ppa_struct
*dev
)
56 dev
->base
= dev
->dev
->port
->base
;
58 dev
->cur_cmd
->SCp
.phase
= 1;
60 wake_up(dev
->waiting
);
63 static void ppa_wakeup(void *ref
)
65 ppa_struct
*dev
= (ppa_struct
*) ref
;
68 spin_lock_irqsave(&arbitration_lock
, flags
);
70 parport_claim(dev
->dev
);
74 spin_unlock_irqrestore(&arbitration_lock
, flags
);
78 static int ppa_pb_claim(ppa_struct
*dev
)
82 spin_lock_irqsave(&arbitration_lock
, flags
);
83 if (parport_claim(dev
->dev
) == 0) {
88 spin_unlock_irqrestore(&arbitration_lock
, flags
);
92 static void ppa_pb_dismiss(ppa_struct
*dev
)
96 spin_lock_irqsave(&arbitration_lock
, flags
);
99 spin_unlock_irqrestore(&arbitration_lock
, flags
);
101 parport_release(dev
->dev
);
104 static inline void ppa_pb_release(ppa_struct
*dev
)
106 parport_release(dev
->dev
);
110 * Start of Chipset kludges
113 /* This is to give the ppa driver a way to modify the timings (and other
114 * parameters) by writing to the /proc/scsi/ppa/0 file.
115 * Very simple method really... (To simple, no error checking :( )
116 * Reason: Kernel hackers HATE having to unload and reload modules for
118 * Also gives a method to use a script to obtain optimum timings (TODO)
121 static inline int ppa_proc_write(ppa_struct
*dev
, char *buffer
, int length
)
125 if ((length
> 5) && (strncmp(buffer
, "mode=", 5) == 0)) {
126 x
= simple_strtoul(buffer
+ 5, NULL
, 0);
130 if ((length
> 10) && (strncmp(buffer
, "recon_tmo=", 10) == 0)) {
131 x
= simple_strtoul(buffer
+ 10, NULL
, 0);
133 printk(KERN_INFO
"ppa: recon_tmo set to %ld\n", x
);
136 printk(KERN_WARNING
"ppa /proc: invalid variable\n");
140 static int ppa_proc_info(struct Scsi_Host
*host
, char *buffer
, char **start
, off_t offset
, int length
, int inout
)
143 ppa_struct
*dev
= ppa_dev(host
);
146 return ppa_proc_write(dev
, buffer
, length
);
148 len
+= sprintf(buffer
+ len
, "Version : %s\n", PPA_VERSION
);
150 sprintf(buffer
+ len
, "Parport : %s\n",
151 dev
->dev
->port
->name
);
153 sprintf(buffer
+ len
, "Mode : %s\n",
154 PPA_MODE_STRING
[dev
->mode
]);
157 sprintf(buffer
+ len
, "recon_tmo : %lu\n", dev
->recon_tmo
);
160 /* Request for beyond end of buffer */
164 *start
= buffer
+ offset
;
171 static int device_check(ppa_struct
*dev
);
174 #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
175 y, __func__, __LINE__); ppa_fail_func(x,y);
176 static inline void ppa_fail_func(ppa_struct
*dev
, int error_code
)
178 static inline void ppa_fail(ppa_struct
*dev
, int error_code
)
181 /* If we fail a device then we trash status / message bytes */
183 dev
->cur_cmd
->result
= error_code
<< 16;
189 * Wait for the high bit to be set.
191 * In principle, this could be tied to an interrupt, but the adapter
192 * doesn't appear to be designed to support interrupts. We spin on
193 * the 0x80 ready bit.
195 static unsigned char ppa_wait(ppa_struct
*dev
)
198 unsigned short ppb
= dev
->base
;
202 /* Wait for bit 6 and 7 - PJC */
203 for (r
= r_str(ppb
); ((r
& 0xc0) != 0xc0) && (k
); k
--) {
209 * return some status information.
210 * Semantics: 0xc0 = ZIP wants more data
211 * 0xd0 = ZIP wants to send more data
212 * 0xe0 = ZIP is expecting SCSI command data
213 * 0xf0 = end of transfer, ZIP is sending status
218 /* Counter expired - Time out occurred */
219 ppa_fail(dev
, DID_TIME_OUT
);
220 printk(KERN_WARNING
"ppa timeout in ppa_wait\n");
221 return 0; /* command timed out */
225 * Clear EPP Timeout Bit
227 static inline void epp_reset(unsigned short ppb
)
233 w_str(ppb
, i
& 0xfe);
237 * Wait for empty ECP fifo (if we are in ECP fifo mode only)
239 static inline void ecp_sync(ppa_struct
*dev
)
241 int i
, ppb_hi
= dev
->dev
->port
->base_hi
;
246 if ((r_ecr(ppb_hi
) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
247 for (i
= 0; i
< 100; i
++) {
248 if (r_ecr(ppb_hi
) & 0x01)
252 printk(KERN_WARNING
"ppa: ECP sync failed as data still present in FIFO.\n");
256 static int ppa_byte_out(unsigned short base
, const char *buffer
, int len
)
260 for (i
= len
; i
; i
--) {
261 w_dtr(base
, *buffer
++);
265 return 1; /* All went well - we hope! */
268 static int ppa_byte_in(unsigned short base
, char *buffer
, int len
)
272 for (i
= len
; i
; i
--) {
273 *buffer
++ = r_dtr(base
);
277 return 1; /* All went well - we hope! */
280 static int ppa_nibble_in(unsigned short base
, char *buffer
, int len
)
286 h
= r_str(base
) & 0xf0;
288 *buffer
++ = h
| ((r_str(base
) & 0xf0) >> 4);
290 return 1; /* All went well - we hope! */
293 static int ppa_out(ppa_struct
*dev
, char *buffer
, int len
)
296 unsigned short ppb
= dev
->base
;
300 if ((r
& 0x50) != 0x40) {
301 ppa_fail(dev
, DID_ERROR
);
307 /* 8 bit output, with a loop */
308 r
= ppa_byte_out(ppb
, buffer
, len
);
316 #ifdef CONFIG_SCSI_IZIP_EPP16
317 if (!(((long) buffer
| len
) & 0x01))
318 outsw(ppb
+ 4, buffer
, len
>> 1);
320 if (!(((long) buffer
| len
) & 0x03))
321 outsl(ppb
+ 4, buffer
, len
>> 2);
324 outsb(ppb
+ 4, buffer
, len
);
326 r
= !(r_str(ppb
) & 0x01);
332 printk(KERN_ERR
"PPA: bug in ppa_out()\n");
338 static int ppa_in(ppa_struct
*dev
, char *buffer
, int len
)
341 unsigned short ppb
= dev
->base
;
345 if ((r
& 0x50) != 0x50) {
346 ppa_fail(dev
, DID_ERROR
);
351 /* 4 bit input, with a loop */
352 r
= ppa_nibble_in(ppb
, buffer
, len
);
357 /* 8 bit input, with a loop */
359 r
= ppa_byte_in(ppb
, buffer
, len
);
369 #ifdef CONFIG_SCSI_IZIP_EPP16
370 if (!(((long) buffer
| len
) & 0x01))
371 insw(ppb
+ 4, buffer
, len
>> 1);
373 if (!(((long) buffer
| len
) & 0x03))
374 insl(ppb
+ 4, buffer
, len
>> 2);
377 insb(ppb
+ 4, buffer
, len
);
379 r
= !(r_str(ppb
) & 0x01);
385 printk(KERN_ERR
"PPA: bug in ppa_ins()\n");
392 /* end of ppa_io.h */
393 static inline void ppa_d_pulse(unsigned short ppb
, unsigned char b
)
403 static void ppa_disconnect(ppa_struct
*dev
)
405 unsigned short ppb
= dev
->base
;
408 ppa_d_pulse(ppb
, 0x3c);
409 ppa_d_pulse(ppb
, 0x20);
410 ppa_d_pulse(ppb
, 0xf);
413 static inline void ppa_c_pulse(unsigned short ppb
, unsigned char b
)
422 static inline void ppa_connect(ppa_struct
*dev
, int flag
)
424 unsigned short ppb
= dev
->base
;
427 ppa_c_pulse(ppb
, 0x3c);
428 ppa_c_pulse(ppb
, 0x20);
429 if ((flag
== CONNECT_EPP_MAYBE
) && IN_EPP_MODE(dev
->mode
))
430 ppa_c_pulse(ppb
, 0xcf);
432 ppa_c_pulse(ppb
, 0x8f);
435 static int ppa_select(ppa_struct
*dev
, int target
)
438 unsigned short ppb
= dev
->base
;
441 * Bit 6 (0x40) is the device selected bit.
442 * First we must wait till the current device goes off line...
448 } while ((r_str(ppb
) & 0x40) && (k
));
452 w_dtr(ppb
, (1 << target
));
455 w_dtr(ppb
, 0x80); /* This is NOT the initator */
463 while (!(r_str(ppb
) & 0x40) && (k
));
471 * This is based on a trace of what the Iomega DOS 'guest' driver does.
472 * I've tried several different kinds of parallel ports with guest and
473 * coded this to react in the same ways that it does.
475 * The return value from this function is just a hint about where the
476 * handshaking failed.
479 static int ppa_init(ppa_struct
*dev
)
482 unsigned short ppb
= dev
->base
;
485 ppa_connect(dev
, CONNECT_NORMAL
);
487 retv
= 2; /* Failed */
490 if ((r_str(ppb
) & 0x08) == 0x08)
494 if ((r_str(ppb
) & 0x08) == 0x00)
498 ppa_reset_pulse(ppb
);
499 udelay(1000); /* Allow devices to settle down */
501 udelay(1000); /* Another delay to allow devices to settle */
506 return device_check(dev
);
509 static inline int ppa_send_command(struct scsi_cmnd
*cmd
)
511 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
514 w_ctr(dev
->base
, 0x0c);
516 for (k
= 0; k
< cmd
->cmd_len
; k
++)
517 if (!ppa_out(dev
, &cmd
->cmnd
[k
], 1))
523 * The bulk flag enables some optimisations in the data transfer loops,
524 * it should be true for any command that transfers data in integral
525 * numbers of sectors.
527 * The driver appears to remain stable if we speed up the parallel port
528 * i/o in this function, but not elsewhere.
530 static int ppa_completion(struct scsi_cmnd
*cmd
)
535 * 1 Finished data transfer
537 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
538 unsigned short ppb
= dev
->base
;
539 unsigned long start_jiffies
= jiffies
;
542 int fast
, bulk
, status
;
545 bulk
= ((v
== READ_6
) ||
546 (v
== READ_10
) || (v
== WRITE_6
) || (v
== WRITE_10
));
549 * We only get here if the drive is ready to comunicate,
550 * hence no need for a full ppa_wait.
552 r
= (r_str(ppb
) & 0xf0);
554 while (r
!= (unsigned char) 0xf0) {
556 * If we have been running for more than a full timer tick
559 if (time_after(jiffies
, start_jiffies
+ 1))
562 if ((cmd
->SCp
.this_residual
<= 0)) {
563 ppa_fail(dev
, DID_ERROR
);
564 return -1; /* ERROR_RETURN */
567 /* On some hardware we have SCSI disconnected (6th bit low)
568 * for about 100usecs. It is too expensive to wait a
569 * tick on every loop so we busy wait for no more than
570 * 500usecs to give the drive a chance first. We do not
571 * change things for "normal" hardware since generally
572 * the 6th bit is always high.
573 * This makes the CPU load higher on some hardware
574 * but otherwise we can not get more than 50K/secs
575 * on this problem hardware.
577 if ((r
& 0xc0) != 0xc0) {
578 /* Wait for reconnection should be no more than
579 * jiffy/2 = 5ms = 5000 loops
581 unsigned long k
= dev
->recon_tmo
;
582 for (; k
&& ((r
= (r_str(ppb
) & 0xf0)) & 0xc0) != 0xc0;
590 /* determine if we should use burst I/O */
591 fast
= (bulk
&& (cmd
->SCp
.this_residual
>= PPA_BURST_SIZE
))
592 ? PPA_BURST_SIZE
: 1;
594 if (r
== (unsigned char) 0xc0)
595 status
= ppa_out(dev
, cmd
->SCp
.ptr
, fast
);
597 status
= ppa_in(dev
, cmd
->SCp
.ptr
, fast
);
599 cmd
->SCp
.ptr
+= fast
;
600 cmd
->SCp
.this_residual
-= fast
;
603 ppa_fail(dev
, DID_BUS_BUSY
);
604 return -1; /* ERROR_RETURN */
606 if (cmd
->SCp
.buffer
&& !cmd
->SCp
.this_residual
) {
607 /* if scatter/gather, advance to the next segment */
608 if (cmd
->SCp
.buffers_residual
--) {
610 cmd
->SCp
.this_residual
=
611 cmd
->SCp
.buffer
->length
;
612 cmd
->SCp
.ptr
= sg_virt(cmd
->SCp
.buffer
);
615 /* Now check to see if the drive is ready to comunicate */
616 r
= (r_str(ppb
) & 0xf0);
617 /* If not, drop back down to the scheduler and wait a timer tick */
621 return 1; /* FINISH_RETURN */
625 * Since the PPA itself doesn't generate interrupts, we use
626 * the scheduler's task queue to generate a stream of call-backs and
627 * complete the request when the drive is ready.
629 static void ppa_interrupt(struct work_struct
*work
)
631 ppa_struct
*dev
= container_of(work
, ppa_struct
, ppa_tq
.work
);
632 struct scsi_cmnd
*cmd
= dev
->cur_cmd
;
635 printk(KERN_ERR
"PPA: bug in ppa_interrupt\n");
638 if (ppa_engine(dev
, cmd
)) {
639 schedule_delayed_work(&dev
->ppa_tq
, 1);
642 /* Command must of completed hence it is safe to let go... */
644 switch ((cmd
->result
>> 16) & 0xff) {
648 printk(KERN_DEBUG
"ppa: no device at SCSI ID %i\n", cmd
->device
->target
);
651 printk(KERN_DEBUG
"ppa: BUS BUSY - EPP timeout detected\n");
654 printk(KERN_DEBUG
"ppa: unknown timeout\n");
657 printk(KERN_DEBUG
"ppa: told to abort\n");
660 printk(KERN_DEBUG
"ppa: parity error (???)\n");
663 printk(KERN_DEBUG
"ppa: internal driver error\n");
666 printk(KERN_DEBUG
"ppa: told to reset device\n");
669 printk(KERN_WARNING
"ppa: bad interrupt (???)\n");
672 printk(KERN_WARNING
"ppa: bad return code (%02x)\n",
673 (cmd
->result
>> 16) & 0xff);
677 if (cmd
->SCp
.phase
> 1)
687 static int ppa_engine(ppa_struct
*dev
, struct scsi_cmnd
*cmd
)
689 unsigned short ppb
= dev
->base
;
690 unsigned char l
= 0, h
= 0;
693 /* First check for any errors that may of occurred
694 * Here we check for internal errors
699 switch (cmd
->SCp
.phase
) {
700 case 0: /* Phase 0 - Waiting for parport */
701 if (time_after(jiffies
, dev
->jstart
+ HZ
)) {
703 * We waited more than a second
704 * for parport to call us
706 ppa_fail(dev
, DID_BUS_BUSY
);
709 return 1; /* wait until ppa_wakeup claims parport */
710 case 1: /* Phase 1 - Connected */
711 { /* Perform a sanity check for cable unplugged */
712 int retv
= 2; /* Failed */
714 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
717 if ((r_str(ppb
) & 0x08) == 0x08)
721 if ((r_str(ppb
) & 0x08) == 0x00)
725 if (time_after(jiffies
, dev
->jstart
+ (1 * HZ
))) {
726 printk(KERN_ERR
"ppa: Parallel port cable is unplugged.\n");
727 ppa_fail(dev
, DID_BUS_BUSY
);
731 return 1; /* Try again in a jiffy */
737 case 2: /* Phase 2 - We are now talking to the scsi bus */
738 if (!ppa_select(dev
, scmd_id(cmd
))) {
739 ppa_fail(dev
, DID_NO_CONNECT
);
744 case 3: /* Phase 3 - Ready to accept a command */
746 if (!(r_str(ppb
) & 0x80))
749 if (!ppa_send_command(cmd
))
753 case 4: /* Phase 4 - Setup scatter/gather buffers */
754 if (scsi_bufflen(cmd
)) {
755 cmd
->SCp
.buffer
= scsi_sglist(cmd
);
756 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
757 cmd
->SCp
.ptr
= sg_virt(cmd
->SCp
.buffer
);
759 cmd
->SCp
.buffer
= NULL
;
760 cmd
->SCp
.this_residual
= 0;
763 cmd
->SCp
.buffers_residual
= scsi_sg_count(cmd
) - 1;
766 case 5: /* Phase 5 - Data transfer stage */
768 if (!(r_str(ppb
) & 0x80))
771 retv
= ppa_completion(cmd
);
778 case 6: /* Phase 6 - Read status/message */
779 cmd
->result
= DID_OK
<< 16;
780 /* Check for data overrun */
781 if (ppa_wait(dev
) != (unsigned char) 0xf0) {
782 ppa_fail(dev
, DID_ERROR
);
785 if (ppa_in(dev
, &l
, 1)) { /* read status byte */
786 /* Check for optional message byte */
787 if (ppa_wait(dev
) == (unsigned char) 0xf0)
790 (DID_OK
<< 16) + (h
<< 8) + (l
& STATUS_MASK
);
792 return 0; /* Finished */
796 printk(KERN_ERR
"ppa: Invalid scsi phase\n");
801 static int ppa_queuecommand(struct scsi_cmnd
*cmd
,
802 void (*done
) (struct scsi_cmnd
*))
804 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
807 printk(KERN_ERR
"PPA: bug in ppa_queuecommand\n");
811 dev
->jstart
= jiffies
;
813 cmd
->scsi_done
= done
;
814 cmd
->result
= DID_ERROR
<< 16; /* default return code */
815 cmd
->SCp
.phase
= 0; /* bus free */
817 schedule_delayed_work(&dev
->ppa_tq
, 0);
825 * Apparently the disk->capacity attribute is off by 1 sector
826 * for all disk drives. We add the one here, but it should really
827 * be done in sd.c. Even if it gets fixed there, this will still
830 static int ppa_biosparam(struct scsi_device
*sdev
, struct block_device
*dev
,
831 sector_t capacity
, int ip
[])
835 ip
[2] = ((unsigned long) capacity
+ 1) / (ip
[0] * ip
[1]);
839 ip
[2] = ((unsigned long) capacity
+ 1) / (ip
[0] * ip
[1]);
846 static int ppa_abort(struct scsi_cmnd
*cmd
)
848 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
850 * There is no method for aborting commands since Iomega
851 * have tied the SCSI_MESSAGE line high in the interface
854 switch (cmd
->SCp
.phase
) {
855 case 0: /* Do not have access to parport */
856 case 1: /* Have not connected to interface */
857 dev
->cur_cmd
= NULL
; /* Forget the problem */
860 default: /* SCSI command sent, can not abort */
866 static void ppa_reset_pulse(unsigned int base
)
874 static int ppa_reset(struct scsi_cmnd
*cmd
)
876 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
880 dev
->cur_cmd
= NULL
; /* Forget the problem */
882 ppa_connect(dev
, CONNECT_NORMAL
);
883 ppa_reset_pulse(dev
->base
);
884 mdelay(1); /* device settle delay */
886 mdelay(1); /* device settle delay */
890 static int device_check(ppa_struct
*dev
)
892 /* This routine looks for a device and then attempts to use EPP
893 to send a command. If all goes as planned then EPP is available. */
895 static u8 cmd
[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
896 int loop
, old_mode
, status
, k
, ppb
= dev
->base
;
899 old_mode
= dev
->mode
;
900 for (loop
= 0; loop
< 8; loop
++) {
901 /* Attempt to use EPP for Test Unit Ready */
902 if ((ppb
& 0x0007) == 0x0000)
903 dev
->mode
= PPA_EPP_32
;
906 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
907 /* Select SCSI device */
908 if (!ppa_select(dev
, loop
)) {
912 printk(KERN_INFO
"ppa: Found device at ID %i, Attempting to use %s\n",
913 loop
, PPA_MODE_STRING
[dev
->mode
]);
915 /* Send SCSI command */
918 for (l
= 0; (l
< 6) && (status
); l
++)
919 status
= ppa_out(dev
, cmd
, 1);
923 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
931 if (dev
->mode
== PPA_EPP_32
) {
932 dev
->mode
= old_mode
;
938 k
= 1000000; /* 1 Second */
943 } while (!(l
& 0x80) && (k
));
949 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
950 ppa_reset_pulse(ppb
);
954 if (dev
->mode
== PPA_EPP_32
) {
955 dev
->mode
= old_mode
;
961 printk(KERN_INFO
"ppa: Communication established with ID %i using %s\n",
962 loop
, PPA_MODE_STRING
[dev
->mode
]);
963 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
964 ppa_reset_pulse(ppb
);
973 static int ppa_adjust_queue(struct scsi_device
*device
)
975 blk_queue_bounce_limit(device
->request_queue
, BLK_BOUNCE_HIGH
);
979 static struct scsi_host_template ppa_template
= {
980 .module
= THIS_MODULE
,
982 .proc_info
= ppa_proc_info
,
983 .name
= "Iomega VPI0 (ppa) interface",
984 .queuecommand
= ppa_queuecommand
,
985 .eh_abort_handler
= ppa_abort
,
986 .eh_bus_reset_handler
= ppa_reset
,
987 .eh_host_reset_handler
= ppa_reset
,
988 .bios_param
= ppa_biosparam
,
990 .sg_tablesize
= SG_ALL
,
992 .use_clustering
= ENABLE_CLUSTERING
,
994 .slave_alloc
= ppa_adjust_queue
,
997 /***************************************************************************
998 * Parallel port probing routines *
999 ***************************************************************************/
1001 static LIST_HEAD(ppa_hosts
);
1003 static int __ppa_attach(struct parport
*pb
)
1005 struct Scsi_Host
*host
;
1006 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waiting
);
1010 int modes
, ppb
, ppb_hi
;
1013 dev
= kzalloc(sizeof(ppa_struct
), GFP_KERNEL
);
1017 dev
->mode
= PPA_AUTODETECT
;
1018 dev
->recon_tmo
= PPA_RECON_TMO
;
1019 init_waitqueue_head(&waiting
);
1020 dev
->dev
= parport_register_device(pb
, "ppa", NULL
, ppa_wakeup
,
1026 /* Claim the bus so it remembers what we do to the control
1027 * registers. [ CTR and ECP ]
1030 dev
->waiting
= &waiting
;
1031 prepare_to_wait(&waiting
, &wait
, TASK_UNINTERRUPTIBLE
);
1032 if (ppa_pb_claim(dev
))
1033 schedule_timeout(3 * HZ
);
1035 printk(KERN_ERR
"ppa%d: failed to claim parport because "
1036 "a pardevice is owning the port for too long "
1037 "time!\n", pb
->number
);
1038 ppa_pb_dismiss(dev
);
1039 dev
->waiting
= NULL
;
1040 finish_wait(&waiting
, &wait
);
1043 dev
->waiting
= NULL
;
1044 finish_wait(&waiting
, &wait
);
1045 ppb
= dev
->base
= dev
->dev
->port
->base
;
1046 ppb_hi
= dev
->dev
->port
->base_hi
;
1048 modes
= dev
->dev
->port
->modes
;
1050 /* Mode detection works up the chain of speed
1051 * This avoids a nasty if-then-else-if-... tree
1053 dev
->mode
= PPA_NIBBLE
;
1055 if (modes
& PARPORT_MODE_TRISTATE
)
1056 dev
->mode
= PPA_PS2
;
1058 if (modes
& PARPORT_MODE_ECP
) {
1059 w_ecr(ppb_hi
, 0x20);
1060 dev
->mode
= PPA_PS2
;
1062 if ((modes
& PARPORT_MODE_EPP
) && (modes
& PARPORT_MODE_ECP
))
1063 w_ecr(ppb_hi
, 0x80);
1065 /* Done configuration */
1067 err
= ppa_init(dev
);
1068 ppa_pb_release(dev
);
1073 /* now the glue ... */
1074 if (dev
->mode
== PPA_NIBBLE
|| dev
->mode
== PPA_PS2
)
1079 INIT_DELAYED_WORK(&dev
->ppa_tq
, ppa_interrupt
);
1082 host
= scsi_host_alloc(&ppa_template
, sizeof(ppa_struct
*));
1085 host
->io_port
= pb
->base
;
1086 host
->n_io_port
= ports
;
1087 host
->dma_channel
= -1;
1088 host
->unique_id
= pb
->number
;
1089 *(ppa_struct
**)&host
->hostdata
= dev
;
1091 list_add_tail(&dev
->list
, &ppa_hosts
);
1092 err
= scsi_add_host(host
, NULL
);
1095 scsi_scan_host(host
);
1098 list_del_init(&dev
->list
);
1099 scsi_host_put(host
);
1101 parport_unregister_device(dev
->dev
);
1107 static void ppa_attach(struct parport
*pb
)
1112 static void ppa_detach(struct parport
*pb
)
1115 list_for_each_entry(dev
, &ppa_hosts
, list
) {
1116 if (dev
->dev
->port
== pb
) {
1117 list_del_init(&dev
->list
);
1118 scsi_remove_host(dev
->host
);
1119 scsi_host_put(dev
->host
);
1120 parport_unregister_device(dev
->dev
);
1127 static struct parport_driver ppa_driver
= {
1129 .attach
= ppa_attach
,
1130 .detach
= ppa_detach
,
1133 static int __init
ppa_driver_init(void)
1135 printk(KERN_INFO
"ppa: Version %s\n", PPA_VERSION
);
1136 return parport_register_driver(&ppa_driver
);
1139 static void __exit
ppa_driver_exit(void)
1141 parport_unregister_driver(&ppa_driver
);
1144 module_init(ppa_driver_init
);
1145 module_exit(ppa_driver_exit
);
1146 MODULE_LICENSE("GPL");