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 unsigned int dev_no
; /* Device number */
41 wait_queue_head_t
*waiting
;
42 struct Scsi_Host
*host
;
43 struct list_head list
;
48 static inline ppa_struct
*ppa_dev(struct Scsi_Host
*host
)
50 return *(ppa_struct
**)&host
->hostdata
;
53 static DEFINE_SPINLOCK(arbitration_lock
);
55 static void got_it(ppa_struct
*dev
)
57 dev
->base
= dev
->dev
->port
->base
;
59 dev
->cur_cmd
->SCp
.phase
= 1;
61 wake_up(dev
->waiting
);
64 static void ppa_wakeup(void *ref
)
66 ppa_struct
*dev
= (ppa_struct
*) ref
;
69 spin_lock_irqsave(&arbitration_lock
, flags
);
71 parport_claim(dev
->dev
);
75 spin_unlock_irqrestore(&arbitration_lock
, flags
);
79 static int ppa_pb_claim(ppa_struct
*dev
)
83 spin_lock_irqsave(&arbitration_lock
, flags
);
84 if (parport_claim(dev
->dev
) == 0) {
89 spin_unlock_irqrestore(&arbitration_lock
, flags
);
93 static void ppa_pb_dismiss(ppa_struct
*dev
)
97 spin_lock_irqsave(&arbitration_lock
, flags
);
100 spin_unlock_irqrestore(&arbitration_lock
, flags
);
102 parport_release(dev
->dev
);
105 static inline void ppa_pb_release(ppa_struct
*dev
)
107 parport_release(dev
->dev
);
111 * Start of Chipset kludges
114 /* This is to give the ppa driver a way to modify the timings (and other
115 * parameters) by writing to the /proc/scsi/ppa/0 file.
116 * Very simple method really... (To simple, no error checking :( )
117 * Reason: Kernel hackers HATE having to unload and reload modules for
119 * Also gives a method to use a script to obtain optimum timings (TODO)
122 static inline int ppa_write_info(struct Scsi_Host
*host
, char *buffer
, int length
)
124 ppa_struct
*dev
= ppa_dev(host
);
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(KERN_INFO
"ppa: recon_tmo set to %ld\n", x
);
138 printk(KERN_WARNING
"ppa /proc: invalid variable\n");
142 static int ppa_show_info(struct seq_file
*m
, struct Scsi_Host
*host
)
144 ppa_struct
*dev
= ppa_dev(host
);
146 seq_printf(m
, "Version : %s\n", PPA_VERSION
);
147 seq_printf(m
, "Parport : %s\n", dev
->dev
->port
->name
);
148 seq_printf(m
, "Mode : %s\n", PPA_MODE_STRING
[dev
->mode
]);
150 seq_printf(m
, "recon_tmo : %lu\n", dev
->recon_tmo
);
155 static int device_check(ppa_struct
*dev
);
158 #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
159 y, __func__, __LINE__); ppa_fail_func(x,y);
160 static inline void ppa_fail_func(ppa_struct
*dev
, int error_code
)
162 static inline void ppa_fail(ppa_struct
*dev
, int error_code
)
165 /* If we fail a device then we trash status / message bytes */
167 dev
->cur_cmd
->result
= error_code
<< 16;
173 * Wait for the high bit to be set.
175 * In principle, this could be tied to an interrupt, but the adapter
176 * doesn't appear to be designed to support interrupts. We spin on
177 * the 0x80 ready bit.
179 static unsigned char ppa_wait(ppa_struct
*dev
)
182 unsigned short ppb
= dev
->base
;
186 /* Wait for bit 6 and 7 - PJC */
187 for (r
= r_str(ppb
); ((r
& 0xc0) != 0xc0) && (k
); k
--) {
193 * return some status information.
194 * Semantics: 0xc0 = ZIP wants more data
195 * 0xd0 = ZIP wants to send more data
196 * 0xe0 = ZIP is expecting SCSI command data
197 * 0xf0 = end of transfer, ZIP is sending status
202 /* Counter expired - Time out occurred */
203 ppa_fail(dev
, DID_TIME_OUT
);
204 printk(KERN_WARNING
"ppa timeout in ppa_wait\n");
205 return 0; /* command timed out */
209 * Clear EPP Timeout Bit
211 static inline void epp_reset(unsigned short ppb
)
217 w_str(ppb
, i
& 0xfe);
221 * Wait for empty ECP fifo (if we are in ECP fifo mode only)
223 static inline void ecp_sync(ppa_struct
*dev
)
225 int i
, ppb_hi
= dev
->dev
->port
->base_hi
;
230 if ((r_ecr(ppb_hi
) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
231 for (i
= 0; i
< 100; i
++) {
232 if (r_ecr(ppb_hi
) & 0x01)
236 printk(KERN_WARNING
"ppa: ECP sync failed as data still present in FIFO.\n");
240 static int ppa_byte_out(unsigned short base
, const char *buffer
, int len
)
244 for (i
= len
; i
; i
--) {
245 w_dtr(base
, *buffer
++);
249 return 1; /* All went well - we hope! */
252 static int ppa_byte_in(unsigned short base
, char *buffer
, int len
)
256 for (i
= len
; i
; i
--) {
257 *buffer
++ = r_dtr(base
);
261 return 1; /* All went well - we hope! */
264 static int ppa_nibble_in(unsigned short base
, char *buffer
, int len
)
270 h
= r_str(base
) & 0xf0;
272 *buffer
++ = h
| ((r_str(base
) & 0xf0) >> 4);
274 return 1; /* All went well - we hope! */
277 static int ppa_out(ppa_struct
*dev
, char *buffer
, int len
)
280 unsigned short ppb
= dev
->base
;
284 if ((r
& 0x50) != 0x40) {
285 ppa_fail(dev
, DID_ERROR
);
291 /* 8 bit output, with a loop */
292 r
= ppa_byte_out(ppb
, buffer
, len
);
300 #ifdef CONFIG_SCSI_IZIP_EPP16
301 if (!(((long) buffer
| len
) & 0x01))
302 outsw(ppb
+ 4, buffer
, len
>> 1);
304 if (!(((long) buffer
| len
) & 0x03))
305 outsl(ppb
+ 4, buffer
, len
>> 2);
308 outsb(ppb
+ 4, buffer
, len
);
310 r
= !(r_str(ppb
) & 0x01);
316 printk(KERN_ERR
"PPA: bug in ppa_out()\n");
322 static int ppa_in(ppa_struct
*dev
, char *buffer
, int len
)
325 unsigned short ppb
= dev
->base
;
329 if ((r
& 0x50) != 0x50) {
330 ppa_fail(dev
, DID_ERROR
);
335 /* 4 bit input, with a loop */
336 r
= ppa_nibble_in(ppb
, buffer
, len
);
341 /* 8 bit input, with a loop */
343 r
= ppa_byte_in(ppb
, buffer
, len
);
353 #ifdef CONFIG_SCSI_IZIP_EPP16
354 if (!(((long) buffer
| len
) & 0x01))
355 insw(ppb
+ 4, buffer
, len
>> 1);
357 if (!(((long) buffer
| len
) & 0x03))
358 insl(ppb
+ 4, buffer
, len
>> 2);
361 insb(ppb
+ 4, buffer
, len
);
363 r
= !(r_str(ppb
) & 0x01);
369 printk(KERN_ERR
"PPA: bug in ppa_ins()\n");
376 /* end of ppa_io.h */
377 static inline void ppa_d_pulse(unsigned short ppb
, unsigned char b
)
387 static void ppa_disconnect(ppa_struct
*dev
)
389 unsigned short ppb
= dev
->base
;
392 ppa_d_pulse(ppb
, 0x3c);
393 ppa_d_pulse(ppb
, 0x20);
394 ppa_d_pulse(ppb
, 0xf);
397 static inline void ppa_c_pulse(unsigned short ppb
, unsigned char b
)
406 static inline void ppa_connect(ppa_struct
*dev
, int flag
)
408 unsigned short ppb
= dev
->base
;
411 ppa_c_pulse(ppb
, 0x3c);
412 ppa_c_pulse(ppb
, 0x20);
413 if ((flag
== CONNECT_EPP_MAYBE
) && IN_EPP_MODE(dev
->mode
))
414 ppa_c_pulse(ppb
, 0xcf);
416 ppa_c_pulse(ppb
, 0x8f);
419 static int ppa_select(ppa_struct
*dev
, int target
)
422 unsigned short ppb
= dev
->base
;
425 * Bit 6 (0x40) is the device selected bit.
426 * First we must wait till the current device goes off line...
432 } while ((r_str(ppb
) & 0x40) && (k
));
436 w_dtr(ppb
, (1 << target
));
439 w_dtr(ppb
, 0x80); /* This is NOT the initator */
447 while (!(r_str(ppb
) & 0x40) && (k
));
455 * This is based on a trace of what the Iomega DOS 'guest' driver does.
456 * I've tried several different kinds of parallel ports with guest and
457 * coded this to react in the same ways that it does.
459 * The return value from this function is just a hint about where the
460 * handshaking failed.
463 static int ppa_init(ppa_struct
*dev
)
466 unsigned short ppb
= dev
->base
;
469 ppa_connect(dev
, CONNECT_NORMAL
);
471 retv
= 2; /* Failed */
474 if ((r_str(ppb
) & 0x08) == 0x08)
478 if ((r_str(ppb
) & 0x08) == 0x00)
482 ppa_reset_pulse(ppb
);
483 udelay(1000); /* Allow devices to settle down */
485 udelay(1000); /* Another delay to allow devices to settle */
490 return device_check(dev
);
493 static inline int ppa_send_command(struct scsi_cmnd
*cmd
)
495 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
498 w_ctr(dev
->base
, 0x0c);
500 for (k
= 0; k
< cmd
->cmd_len
; k
++)
501 if (!ppa_out(dev
, &cmd
->cmnd
[k
], 1))
507 * The bulk flag enables some optimisations in the data transfer loops,
508 * it should be true for any command that transfers data in integral
509 * numbers of sectors.
511 * The driver appears to remain stable if we speed up the parallel port
512 * i/o in this function, but not elsewhere.
514 static int ppa_completion(struct scsi_cmnd
*cmd
)
519 * 1 Finished data transfer
521 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
522 unsigned short ppb
= dev
->base
;
523 unsigned long start_jiffies
= jiffies
;
526 int fast
, bulk
, status
;
529 bulk
= ((v
== READ_6
) ||
530 (v
== READ_10
) || (v
== WRITE_6
) || (v
== WRITE_10
));
533 * We only get here if the drive is ready to comunicate,
534 * hence no need for a full ppa_wait.
536 r
= (r_str(ppb
) & 0xf0);
538 while (r
!= (unsigned char) 0xf0) {
540 * If we have been running for more than a full timer tick
543 if (time_after(jiffies
, start_jiffies
+ 1))
546 if ((cmd
->SCp
.this_residual
<= 0)) {
547 ppa_fail(dev
, DID_ERROR
);
548 return -1; /* ERROR_RETURN */
551 /* On some hardware we have SCSI disconnected (6th bit low)
552 * for about 100usecs. It is too expensive to wait a
553 * tick on every loop so we busy wait for no more than
554 * 500usecs to give the drive a chance first. We do not
555 * change things for "normal" hardware since generally
556 * the 6th bit is always high.
557 * This makes the CPU load higher on some hardware
558 * but otherwise we can not get more than 50K/secs
559 * on this problem hardware.
561 if ((r
& 0xc0) != 0xc0) {
562 /* Wait for reconnection should be no more than
563 * jiffy/2 = 5ms = 5000 loops
565 unsigned long k
= dev
->recon_tmo
;
566 for (; k
&& ((r
= (r_str(ppb
) & 0xf0)) & 0xc0) != 0xc0;
574 /* determine if we should use burst I/O */
575 fast
= (bulk
&& (cmd
->SCp
.this_residual
>= PPA_BURST_SIZE
))
576 ? PPA_BURST_SIZE
: 1;
578 if (r
== (unsigned char) 0xc0)
579 status
= ppa_out(dev
, cmd
->SCp
.ptr
, fast
);
581 status
= ppa_in(dev
, cmd
->SCp
.ptr
, fast
);
583 cmd
->SCp
.ptr
+= fast
;
584 cmd
->SCp
.this_residual
-= fast
;
587 ppa_fail(dev
, DID_BUS_BUSY
);
588 return -1; /* ERROR_RETURN */
590 if (cmd
->SCp
.buffer
&& !cmd
->SCp
.this_residual
) {
591 /* if scatter/gather, advance to the next segment */
592 if (cmd
->SCp
.buffers_residual
--) {
593 cmd
->SCp
.buffer
= sg_next(cmd
->SCp
.buffer
);
594 cmd
->SCp
.this_residual
=
595 cmd
->SCp
.buffer
->length
;
596 cmd
->SCp
.ptr
= sg_virt(cmd
->SCp
.buffer
);
599 /* Now check to see if the drive is ready to comunicate */
600 r
= (r_str(ppb
) & 0xf0);
601 /* If not, drop back down to the scheduler and wait a timer tick */
605 return 1; /* FINISH_RETURN */
609 * Since the PPA itself doesn't generate interrupts, we use
610 * the scheduler's task queue to generate a stream of call-backs and
611 * complete the request when the drive is ready.
613 static void ppa_interrupt(struct work_struct
*work
)
615 ppa_struct
*dev
= container_of(work
, ppa_struct
, ppa_tq
.work
);
616 struct scsi_cmnd
*cmd
= dev
->cur_cmd
;
619 printk(KERN_ERR
"PPA: bug in ppa_interrupt\n");
622 if (ppa_engine(dev
, cmd
)) {
623 schedule_delayed_work(&dev
->ppa_tq
, 1);
626 /* Command must of completed hence it is safe to let go... */
628 switch ((cmd
->result
>> 16) & 0xff) {
632 printk(KERN_DEBUG
"ppa: no device at SCSI ID %i\n", cmd
->device
->target
);
635 printk(KERN_DEBUG
"ppa: BUS BUSY - EPP timeout detected\n");
638 printk(KERN_DEBUG
"ppa: unknown timeout\n");
641 printk(KERN_DEBUG
"ppa: told to abort\n");
644 printk(KERN_DEBUG
"ppa: parity error (???)\n");
647 printk(KERN_DEBUG
"ppa: internal driver error\n");
650 printk(KERN_DEBUG
"ppa: told to reset device\n");
653 printk(KERN_WARNING
"ppa: bad interrupt (???)\n");
656 printk(KERN_WARNING
"ppa: bad return code (%02x)\n",
657 (cmd
->result
>> 16) & 0xff);
661 if (cmd
->SCp
.phase
> 1)
671 static int ppa_engine(ppa_struct
*dev
, struct scsi_cmnd
*cmd
)
673 unsigned short ppb
= dev
->base
;
674 unsigned char l
= 0, h
= 0;
677 /* First check for any errors that may of occurred
678 * Here we check for internal errors
683 switch (cmd
->SCp
.phase
) {
684 case 0: /* Phase 0 - Waiting for parport */
685 if (time_after(jiffies
, dev
->jstart
+ HZ
)) {
687 * We waited more than a second
688 * for parport to call us
690 ppa_fail(dev
, DID_BUS_BUSY
);
693 return 1; /* wait until ppa_wakeup claims parport */
694 case 1: /* Phase 1 - Connected */
695 { /* Perform a sanity check for cable unplugged */
696 int retv
= 2; /* Failed */
698 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
701 if ((r_str(ppb
) & 0x08) == 0x08)
705 if ((r_str(ppb
) & 0x08) == 0x00)
709 if (time_after(jiffies
, dev
->jstart
+ (1 * HZ
))) {
710 printk(KERN_ERR
"ppa: Parallel port cable is unplugged.\n");
711 ppa_fail(dev
, DID_BUS_BUSY
);
715 return 1; /* Try again in a jiffy */
722 case 2: /* Phase 2 - We are now talking to the scsi bus */
723 if (!ppa_select(dev
, scmd_id(cmd
))) {
724 ppa_fail(dev
, DID_NO_CONNECT
);
730 case 3: /* Phase 3 - Ready to accept a command */
732 if (!(r_str(ppb
) & 0x80))
735 if (!ppa_send_command(cmd
))
740 case 4: /* Phase 4 - Setup scatter/gather buffers */
741 if (scsi_bufflen(cmd
)) {
742 cmd
->SCp
.buffer
= scsi_sglist(cmd
);
743 cmd
->SCp
.this_residual
= cmd
->SCp
.buffer
->length
;
744 cmd
->SCp
.ptr
= sg_virt(cmd
->SCp
.buffer
);
746 cmd
->SCp
.buffer
= NULL
;
747 cmd
->SCp
.this_residual
= 0;
750 cmd
->SCp
.buffers_residual
= scsi_sg_count(cmd
) - 1;
754 case 5: /* Phase 5 - Data transfer stage */
756 if (!(r_str(ppb
) & 0x80))
759 retv
= ppa_completion(cmd
);
767 case 6: /* Phase 6 - Read status/message */
768 cmd
->result
= DID_OK
<< 16;
769 /* Check for data overrun */
770 if (ppa_wait(dev
) != (unsigned char) 0xf0) {
771 ppa_fail(dev
, DID_ERROR
);
774 if (ppa_in(dev
, &l
, 1)) { /* read status byte */
775 /* Check for optional message byte */
776 if (ppa_wait(dev
) == (unsigned char) 0xf0)
779 (DID_OK
<< 16) + (h
<< 8) + (l
& STATUS_MASK
);
781 return 0; /* Finished */
785 printk(KERN_ERR
"ppa: Invalid scsi phase\n");
790 static int ppa_queuecommand_lck(struct scsi_cmnd
*cmd
,
791 void (*done
) (struct scsi_cmnd
*))
793 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
796 printk(KERN_ERR
"PPA: bug in ppa_queuecommand\n");
800 dev
->jstart
= jiffies
;
802 cmd
->scsi_done
= done
;
803 cmd
->result
= DID_ERROR
<< 16; /* default return code */
804 cmd
->SCp
.phase
= 0; /* bus free */
806 schedule_delayed_work(&dev
->ppa_tq
, 0);
813 static DEF_SCSI_QCMD(ppa_queuecommand
)
816 * Apparently the disk->capacity attribute is off by 1 sector
817 * for all disk drives. We add the one here, but it should really
818 * be done in sd.c. Even if it gets fixed there, this will still
821 static int ppa_biosparam(struct scsi_device
*sdev
, struct block_device
*dev
,
822 sector_t capacity
, int ip
[])
826 ip
[2] = ((unsigned long) capacity
+ 1) / (ip
[0] * ip
[1]);
830 ip
[2] = ((unsigned long) capacity
+ 1) / (ip
[0] * ip
[1]);
837 static int ppa_abort(struct scsi_cmnd
*cmd
)
839 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
841 * There is no method for aborting commands since Iomega
842 * have tied the SCSI_MESSAGE line high in the interface
845 switch (cmd
->SCp
.phase
) {
846 case 0: /* Do not have access to parport */
847 case 1: /* Have not connected to interface */
848 dev
->cur_cmd
= NULL
; /* Forget the problem */
851 default: /* SCSI command sent, can not abort */
857 static void ppa_reset_pulse(unsigned int base
)
865 static int ppa_reset(struct scsi_cmnd
*cmd
)
867 ppa_struct
*dev
= ppa_dev(cmd
->device
->host
);
871 dev
->cur_cmd
= NULL
; /* Forget the problem */
873 ppa_connect(dev
, CONNECT_NORMAL
);
874 ppa_reset_pulse(dev
->base
);
875 mdelay(1); /* device settle delay */
877 mdelay(1); /* device settle delay */
881 static int device_check(ppa_struct
*dev
)
883 /* This routine looks for a device and then attempts to use EPP
884 to send a command. If all goes as planned then EPP is available. */
886 static u8 cmd
[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
887 int loop
, old_mode
, status
, k
, ppb
= dev
->base
;
890 old_mode
= dev
->mode
;
891 for (loop
= 0; loop
< 8; loop
++) {
892 /* Attempt to use EPP for Test Unit Ready */
893 if ((ppb
& 0x0007) == 0x0000)
894 dev
->mode
= PPA_EPP_32
;
897 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
898 /* Select SCSI device */
899 if (!ppa_select(dev
, loop
)) {
903 printk(KERN_INFO
"ppa: Found device at ID %i, Attempting to use %s\n",
904 loop
, PPA_MODE_STRING
[dev
->mode
]);
906 /* Send SCSI command */
909 for (l
= 0; (l
< 6) && (status
); l
++)
910 status
= ppa_out(dev
, cmd
, 1);
914 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
922 if (dev
->mode
== PPA_EPP_32
) {
923 dev
->mode
= old_mode
;
929 k
= 1000000; /* 1 Second */
934 } while (!(l
& 0x80) && (k
));
940 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
941 ppa_reset_pulse(ppb
);
945 if (dev
->mode
== PPA_EPP_32
) {
946 dev
->mode
= old_mode
;
952 printk(KERN_INFO
"ppa: Communication established with ID %i using %s\n",
953 loop
, PPA_MODE_STRING
[dev
->mode
]);
954 ppa_connect(dev
, CONNECT_EPP_MAYBE
);
955 ppa_reset_pulse(ppb
);
964 static int ppa_adjust_queue(struct scsi_device
*device
)
966 blk_queue_bounce_limit(device
->request_queue
, BLK_BOUNCE_HIGH
);
970 static struct scsi_host_template ppa_template
= {
971 .module
= THIS_MODULE
,
973 .show_info
= ppa_show_info
,
974 .write_info
= ppa_write_info
,
975 .name
= "Iomega VPI0 (ppa) interface",
976 .queuecommand
= ppa_queuecommand
,
977 .eh_abort_handler
= ppa_abort
,
978 .eh_host_reset_handler
= ppa_reset
,
979 .bios_param
= ppa_biosparam
,
981 .sg_tablesize
= SG_ALL
,
983 .slave_alloc
= ppa_adjust_queue
,
986 /***************************************************************************
987 * Parallel port probing routines *
988 ***************************************************************************/
990 static LIST_HEAD(ppa_hosts
);
993 * Finds the first available device number that can be alloted to the
994 * new ppa device and returns the address of the previous node so that
995 * we can add to the tail and have a list in the ascending order.
998 static inline ppa_struct
*find_parent(void)
1000 ppa_struct
*dev
, *par
= NULL
;
1001 unsigned int cnt
= 0;
1003 if (list_empty(&ppa_hosts
))
1006 list_for_each_entry(dev
, &ppa_hosts
, list
) {
1007 if (dev
->dev_no
!= cnt
)
1016 static int __ppa_attach(struct parport
*pb
)
1018 struct Scsi_Host
*host
;
1019 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waiting
);
1021 ppa_struct
*dev
, *temp
;
1023 int modes
, ppb
, ppb_hi
;
1025 struct pardev_cb ppa_cb
;
1027 dev
= kzalloc(sizeof(ppa_struct
), GFP_KERNEL
);
1031 dev
->mode
= PPA_AUTODETECT
;
1032 dev
->recon_tmo
= PPA_RECON_TMO
;
1033 init_waitqueue_head(&waiting
);
1034 temp
= find_parent();
1036 dev
->dev_no
= temp
->dev_no
+ 1;
1038 memset(&ppa_cb
, 0, sizeof(ppa_cb
));
1039 ppa_cb
.private = dev
;
1040 ppa_cb
.wakeup
= ppa_wakeup
;
1042 dev
->dev
= parport_register_dev_model(pb
, "ppa", &ppa_cb
, dev
->dev_no
);
1047 /* Claim the bus so it remembers what we do to the control
1048 * registers. [ CTR and ECP ]
1051 dev
->waiting
= &waiting
;
1052 prepare_to_wait(&waiting
, &wait
, TASK_UNINTERRUPTIBLE
);
1053 if (ppa_pb_claim(dev
))
1054 schedule_timeout(3 * HZ
);
1056 printk(KERN_ERR
"ppa%d: failed to claim parport because "
1057 "a pardevice is owning the port for too long "
1058 "time!\n", pb
->number
);
1059 ppa_pb_dismiss(dev
);
1060 dev
->waiting
= NULL
;
1061 finish_wait(&waiting
, &wait
);
1064 dev
->waiting
= NULL
;
1065 finish_wait(&waiting
, &wait
);
1066 ppb
= dev
->base
= dev
->dev
->port
->base
;
1067 ppb_hi
= dev
->dev
->port
->base_hi
;
1069 modes
= dev
->dev
->port
->modes
;
1071 /* Mode detection works up the chain of speed
1072 * This avoids a nasty if-then-else-if-... tree
1074 dev
->mode
= PPA_NIBBLE
;
1076 if (modes
& PARPORT_MODE_TRISTATE
)
1077 dev
->mode
= PPA_PS2
;
1079 if (modes
& PARPORT_MODE_ECP
) {
1080 w_ecr(ppb_hi
, 0x20);
1081 dev
->mode
= PPA_PS2
;
1083 if ((modes
& PARPORT_MODE_EPP
) && (modes
& PARPORT_MODE_ECP
))
1084 w_ecr(ppb_hi
, 0x80);
1086 /* Done configuration */
1088 err
= ppa_init(dev
);
1089 ppa_pb_release(dev
);
1094 /* now the glue ... */
1095 if (dev
->mode
== PPA_NIBBLE
|| dev
->mode
== PPA_PS2
)
1100 INIT_DELAYED_WORK(&dev
->ppa_tq
, ppa_interrupt
);
1103 host
= scsi_host_alloc(&ppa_template
, sizeof(ppa_struct
*));
1106 host
->io_port
= pb
->base
;
1107 host
->n_io_port
= ports
;
1108 host
->dma_channel
= -1;
1109 host
->unique_id
= pb
->number
;
1110 *(ppa_struct
**)&host
->hostdata
= dev
;
1112 list_add_tail(&dev
->list
, &ppa_hosts
);
1113 err
= scsi_add_host(host
, NULL
);
1116 scsi_scan_host(host
);
1119 list_del_init(&dev
->list
);
1120 scsi_host_put(host
);
1122 parport_unregister_device(dev
->dev
);
1128 static void ppa_attach(struct parport
*pb
)
1133 static void ppa_detach(struct parport
*pb
)
1136 list_for_each_entry(dev
, &ppa_hosts
, list
) {
1137 if (dev
->dev
->port
== pb
) {
1138 list_del_init(&dev
->list
);
1139 scsi_remove_host(dev
->host
);
1140 scsi_host_put(dev
->host
);
1141 parport_unregister_device(dev
->dev
);
1148 static struct parport_driver ppa_driver
= {
1150 .match_port
= ppa_attach
,
1151 .detach
= ppa_detach
,
1155 static int __init
ppa_driver_init(void)
1157 printk(KERN_INFO
"ppa: Version %s\n", PPA_VERSION
);
1158 return parport_register_driver(&ppa_driver
);
1161 static void __exit
ppa_driver_exit(void)
1163 parport_unregister_driver(&ppa_driver
);
1166 module_init(ppa_driver_init
);
1167 module_exit(ppa_driver_exit
);
1168 MODULE_LICENSE("GPL");