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.)
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 unsigned int mode = PPA_AUTODETECT;
49 module_param(mode, uint, 0644);
50 MODULE_PARM_DESC(mode, "Transfer mode (0 = Autodetect, 1 = SPP 4-bit, "
51 "2 = SPP 8-bit, 3 = EPP 8-bit, 4 = EPP 16-bit, 5 = EPP 32-bit");
53 static struct scsi_pointer *ppa_scsi_pointer(struct scsi_cmnd *cmd)
55 return scsi_cmd_priv(cmd);
58 static inline ppa_struct *ppa_dev(struct Scsi_Host *host)
60 return *(ppa_struct **)&host->hostdata;
63 static DEFINE_SPINLOCK(arbitration_lock);
65 static void got_it(ppa_struct *dev)
67 dev->base = dev->dev->port->base;
69 ppa_scsi_pointer(dev->cur_cmd)->phase = 1;
71 wake_up(dev->waiting);
74 static void ppa_wakeup(void *ref)
76 ppa_struct *dev = (ppa_struct *) ref;
79 spin_lock_irqsave(&arbitration_lock, flags);
81 parport_claim(dev->dev);
85 spin_unlock_irqrestore(&arbitration_lock, flags);
89 static int ppa_pb_claim(ppa_struct *dev)
93 spin_lock_irqsave(&arbitration_lock, flags);
94 if (parport_claim(dev->dev) == 0) {
99 spin_unlock_irqrestore(&arbitration_lock, flags);
103 static void ppa_pb_dismiss(ppa_struct *dev)
107 spin_lock_irqsave(&arbitration_lock, flags);
108 wanted = dev->wanted;
110 spin_unlock_irqrestore(&arbitration_lock, flags);
112 parport_release(dev->dev);
115 static inline void ppa_pb_release(ppa_struct *dev)
117 parport_release(dev->dev);
121 * Start of Chipset kludges
124 /* This is to give the ppa driver a way to modify the timings (and other
125 * parameters) by writing to the /proc/scsi/ppa/0 file.
126 * Very simple method really... (To simple, no error checking :( )
127 * Reason: Kernel hackers HATE having to unload and reload modules for
129 * Also gives a method to use a script to obtain optimum timings (TODO)
132 static inline int ppa_write_info(struct Scsi_Host *host, char *buffer, int length)
134 ppa_struct *dev = ppa_dev(host);
137 if ((length > 5) && (strncmp(buffer, "mode=", 5) == 0)) {
138 x = simple_strtoul(buffer + 5, NULL, 0);
142 if ((length > 10) && (strncmp(buffer, "recon_tmo=", 10) == 0)) {
143 x = simple_strtoul(buffer + 10, NULL, 0);
145 printk(KERN_INFO "ppa: recon_tmo set to %ld\n", x);
148 printk(KERN_WARNING "ppa /proc: invalid variable\n");
152 static int ppa_show_info(struct seq_file *m, struct Scsi_Host *host)
154 ppa_struct *dev = ppa_dev(host);
156 seq_printf(m, "Version : %s\n", PPA_VERSION);
157 seq_printf(m, "Parport : %s\n", dev->dev->port->name);
158 seq_printf(m, "Mode : %s\n", PPA_MODE_STRING[dev->mode]);
160 seq_printf(m, "recon_tmo : %lu\n", dev->recon_tmo);
165 static int device_check(ppa_struct *dev, bool autodetect);
168 #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
169 y, __func__, __LINE__); ppa_fail_func(x,y);
170 static inline void ppa_fail_func(ppa_struct *dev, int error_code)
172 static inline void ppa_fail(ppa_struct *dev, int error_code)
175 /* If we fail a device then we trash status / message bytes */
177 dev->cur_cmd->result = error_code << 16;
183 * Wait for the high bit to be set.
185 * In principle, this could be tied to an interrupt, but the adapter
186 * doesn't appear to be designed to support interrupts. We spin on
187 * the 0x80 ready bit.
189 static unsigned char ppa_wait(ppa_struct *dev)
192 unsigned short ppb = dev->base;
196 /* Wait for bit 6 and 7 - PJC */
197 for (r = r_str(ppb); ((r & 0xc0) != 0xc0) && (k); k--) {
203 * return some status information.
204 * Semantics: 0xc0 = ZIP wants more data
205 * 0xd0 = ZIP wants to send more data
206 * 0xe0 = ZIP is expecting SCSI command data
207 * 0xf0 = end of transfer, ZIP is sending status
212 /* Counter expired - Time out occurred */
213 ppa_fail(dev, DID_TIME_OUT);
214 printk(KERN_WARNING "ppa timeout in ppa_wait\n");
215 return 0; /* command timed out */
219 * Clear EPP Timeout Bit
221 static inline void epp_reset(unsigned short ppb)
227 w_str(ppb, i & 0xfe);
231 * Wait for empty ECP fifo (if we are in ECP fifo mode only)
233 static inline void ecp_sync(ppa_struct *dev)
235 int i, ppb_hi = dev->dev->port->base_hi;
240 if ((r_ecr(ppb_hi) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
241 for (i = 0; i < 100; i++) {
242 if (r_ecr(ppb_hi) & 0x01)
246 printk(KERN_WARNING "ppa: ECP sync failed as data still present in FIFO.\n");
250 static int ppa_byte_out(unsigned short base, const char *buffer, int len)
254 for (i = len; i; i--) {
255 w_dtr(base, *buffer++);
259 return 1; /* All went well - we hope! */
262 static int ppa_byte_in(unsigned short base, char *buffer, int len)
266 for (i = len; i; i--) {
267 *buffer++ = r_dtr(base);
271 return 1; /* All went well - we hope! */
274 static int ppa_nibble_in(unsigned short base, char *buffer, int len)
280 h = r_str(base) & 0xf0;
282 *buffer++ = h | ((r_str(base) & 0xf0) >> 4);
284 return 1; /* All went well - we hope! */
287 static int ppa_out(ppa_struct *dev, char *buffer, int len)
290 unsigned short ppb = dev->base;
294 if ((r & 0x50) != 0x40) {
295 ppa_fail(dev, DID_ERROR);
301 /* 8 bit output, with a loop */
302 r = ppa_byte_out(ppb, buffer, len);
310 if (dev->mode == PPA_EPP_32 && !(((long) buffer | len) & 0x03))
311 outsl(ppb + 4, buffer, len >> 2);
312 else if (dev->mode == PPA_EPP_16 && !(((long) buffer | len) & 0x01))
313 outsw(ppb + 4, buffer, len >> 1);
315 outsb(ppb + 4, buffer, len);
317 r = !(r_str(ppb) & 0x01);
323 printk(KERN_ERR "PPA: bug in ppa_out()\n");
329 static int ppa_in(ppa_struct *dev, char *buffer, int len)
332 unsigned short ppb = dev->base;
336 if ((r & 0x50) != 0x50) {
337 ppa_fail(dev, DID_ERROR);
342 /* 4 bit input, with a loop */
343 r = ppa_nibble_in(ppb, buffer, len);
348 /* 8 bit input, with a loop */
350 r = ppa_byte_in(ppb, buffer, len);
360 if (dev->mode == PPA_EPP_32 && !(((long) buffer | len) & 0x03))
361 insl(ppb + 4, buffer, len >> 2);
362 else if (dev->mode == PPA_EPP_16 && !(((long) buffer | len) & 0x01))
363 insw(ppb + 4, buffer, len >> 1);
365 insb(ppb + 4, buffer, len);
367 r = !(r_str(ppb) & 0x01);
373 printk(KERN_ERR "PPA: bug in ppa_ins()\n");
380 /* end of ppa_io.h */
381 static inline void ppa_d_pulse(unsigned short ppb, unsigned char b)
391 static void ppa_disconnect(ppa_struct *dev)
393 unsigned short ppb = dev->base;
396 ppa_d_pulse(ppb, 0x3c);
397 ppa_d_pulse(ppb, 0x20);
398 ppa_d_pulse(ppb, 0xf);
401 static inline void ppa_c_pulse(unsigned short ppb, unsigned char b)
410 static inline void ppa_connect(ppa_struct *dev, int flag)
412 unsigned short ppb = dev->base;
415 ppa_c_pulse(ppb, 0x3c);
416 ppa_c_pulse(ppb, 0x20);
417 if ((flag == CONNECT_EPP_MAYBE) && IN_EPP_MODE(dev->mode))
418 ppa_c_pulse(ppb, 0xcf);
420 ppa_c_pulse(ppb, 0x8f);
423 static int ppa_select(ppa_struct *dev, int target)
426 unsigned short ppb = dev->base;
429 * Bit 6 (0x40) is the device selected bit.
430 * First we must wait till the current device goes off line...
436 } while ((r_str(ppb) & 0x40) && (k));
440 w_dtr(ppb, (1 << target));
443 w_dtr(ppb, 0x80); /* This is NOT the initator */
451 while (!(r_str(ppb) & 0x40) && (k));
459 * This is based on a trace of what the Iomega DOS 'guest' driver does.
460 * I've tried several different kinds of parallel ports with guest and
461 * coded this to react in the same ways that it does.
463 * The return value from this function is just a hint about where the
464 * handshaking failed.
467 static int ppa_init(ppa_struct *dev)
470 unsigned short ppb = dev->base;
471 bool autodetect = dev->mode == PPA_AUTODETECT;
474 int modes = dev->dev->port->modes;
475 int ppb_hi = dev->dev->port->base_hi;
477 /* Mode detection works up the chain of speed
478 * This avoids a nasty if-then-else-if-... tree
480 dev->mode = PPA_NIBBLE;
482 if (modes & PARPORT_MODE_TRISTATE)
485 if (modes & PARPORT_MODE_ECP) {
489 if ((modes & PARPORT_MODE_EPP) && (modes & PARPORT_MODE_ECP))
494 ppa_connect(dev, CONNECT_NORMAL);
496 retv = 2; /* Failed */
499 if ((r_str(ppb) & 0x08) == 0x08)
503 if ((r_str(ppb) & 0x08) == 0x00)
507 ppa_reset_pulse(ppb);
508 udelay(1000); /* Allow devices to settle down */
510 udelay(1000); /* Another delay to allow devices to settle */
515 return device_check(dev, autodetect);
518 static inline int ppa_send_command(struct scsi_cmnd *cmd)
520 ppa_struct *dev = ppa_dev(cmd->device->host);
523 w_ctr(dev->base, 0x0c);
525 for (k = 0; k < cmd->cmd_len; k++)
526 if (!ppa_out(dev, &cmd->cmnd[k], 1))
532 * The bulk flag enables some optimisations in the data transfer loops,
533 * it should be true for any command that transfers data in integral
534 * numbers of sectors.
536 * The driver appears to remain stable if we speed up the parallel port
537 * i/o in this function, but not elsewhere.
539 static int ppa_completion(struct scsi_cmnd *const cmd)
544 * 1 Finished data transfer
546 struct scsi_pointer *scsi_pointer = ppa_scsi_pointer(cmd);
547 ppa_struct *dev = ppa_dev(cmd->device->host);
548 unsigned short ppb = dev->base;
549 unsigned long start_jiffies = jiffies;
552 int fast, bulk, status;
555 bulk = ((v == READ_6) ||
556 (v == READ_10) || (v == WRITE_6) || (v == WRITE_10));
559 * We only get here if the drive is ready to comunicate,
560 * hence no need for a full ppa_wait.
562 r = (r_str(ppb) & 0xf0);
564 while (r != (unsigned char) 0xf0) {
566 * If we have been running for more than a full timer tick
569 if (time_after(jiffies, start_jiffies + 1))
572 if (scsi_pointer->this_residual <= 0) {
573 ppa_fail(dev, DID_ERROR);
574 return -1; /* ERROR_RETURN */
577 /* On some hardware we have SCSI disconnected (6th bit low)
578 * for about 100usecs. It is too expensive to wait a
579 * tick on every loop so we busy wait for no more than
580 * 500usecs to give the drive a chance first. We do not
581 * change things for "normal" hardware since generally
582 * the 6th bit is always high.
583 * This makes the CPU load higher on some hardware
584 * but otherwise we can not get more than 50K/secs
585 * on this problem hardware.
587 if ((r & 0xc0) != 0xc0) {
588 /* Wait for reconnection should be no more than
589 * jiffy/2 = 5ms = 5000 loops
591 unsigned long k = dev->recon_tmo;
592 for (; k && ((r = (r_str(ppb) & 0xf0)) & 0xc0) != 0xc0;
600 /* determine if we should use burst I/O */
601 fast = bulk && scsi_pointer->this_residual >= PPA_BURST_SIZE ?
604 if (r == (unsigned char) 0xc0)
605 status = ppa_out(dev, scsi_pointer->ptr, fast);
607 status = ppa_in(dev, scsi_pointer->ptr, fast);
609 scsi_pointer->ptr += fast;
610 scsi_pointer->this_residual -= fast;
613 ppa_fail(dev, DID_BUS_BUSY);
614 return -1; /* ERROR_RETURN */
616 if (scsi_pointer->buffer && !scsi_pointer->this_residual) {
617 /* if scatter/gather, advance to the next segment */
618 if (scsi_pointer->buffers_residual--) {
619 scsi_pointer->buffer =
620 sg_next(scsi_pointer->buffer);
621 scsi_pointer->this_residual =
622 scsi_pointer->buffer->length;
624 sg_virt(scsi_pointer->buffer);
627 /* Now check to see if the drive is ready to comunicate */
628 r = (r_str(ppb) & 0xf0);
629 /* If not, drop back down to the scheduler and wait a timer tick */
633 return 1; /* FINISH_RETURN */
637 * Since the PPA itself doesn't generate interrupts, we use
638 * the scheduler's task queue to generate a stream of call-backs and
639 * complete the request when the drive is ready.
641 static void ppa_interrupt(struct work_struct *work)
643 ppa_struct *dev = container_of(work, ppa_struct, ppa_tq.work);
644 struct scsi_cmnd *cmd = dev->cur_cmd;
647 printk(KERN_ERR "PPA: bug in ppa_interrupt\n");
650 if (ppa_engine(dev, cmd)) {
651 schedule_delayed_work(&dev->ppa_tq, 1);
654 /* Command must of completed hence it is safe to let go... */
656 switch ((cmd->result >> 16) & 0xff) {
660 printk(KERN_DEBUG "ppa: no device at SCSI ID %i\n", scmd_id(cmd));
663 printk(KERN_DEBUG "ppa: BUS BUSY - EPP timeout detected\n");
666 printk(KERN_DEBUG "ppa: unknown timeout\n");
669 printk(KERN_DEBUG "ppa: told to abort\n");
672 printk(KERN_DEBUG "ppa: parity error (???)\n");
675 printk(KERN_DEBUG "ppa: internal driver error\n");
678 printk(KERN_DEBUG "ppa: told to reset device\n");
681 printk(KERN_WARNING "ppa: bad interrupt (???)\n");
684 printk(KERN_WARNING "ppa: bad return code (%02x)\n",
685 (cmd->result >> 16) & 0xff);
689 if (ppa_scsi_pointer(cmd)->phase > 1)
699 static int ppa_engine(ppa_struct *dev, struct scsi_cmnd *cmd)
701 struct scsi_pointer *scsi_pointer = ppa_scsi_pointer(cmd);
702 unsigned short ppb = dev->base;
703 unsigned char l = 0, h = 0;
706 /* First check for any errors that may of occurred
707 * Here we check for internal errors
712 switch (scsi_pointer->phase) {
713 case 0: /* Phase 0 - Waiting for parport */
714 if (time_after(jiffies, dev->jstart + HZ)) {
716 * We waited more than a second
717 * for parport to call us
719 ppa_fail(dev, DID_BUS_BUSY);
722 return 1; /* wait until ppa_wakeup claims parport */
723 case 1: /* Phase 1 - Connected */
724 { /* Perform a sanity check for cable unplugged */
725 int retv = 2; /* Failed */
727 ppa_connect(dev, CONNECT_EPP_MAYBE);
730 if ((r_str(ppb) & 0x08) == 0x08)
734 if ((r_str(ppb) & 0x08) == 0x00)
738 if (time_after(jiffies, dev->jstart + (1 * HZ))) {
739 printk(KERN_ERR "ppa: Parallel port cable is unplugged.\n");
740 ppa_fail(dev, DID_BUS_BUSY);
744 return 1; /* Try again in a jiffy */
747 scsi_pointer->phase++;
751 case 2: /* Phase 2 - We are now talking to the scsi bus */
752 if (!ppa_select(dev, scmd_id(cmd))) {
753 ppa_fail(dev, DID_NO_CONNECT);
756 scsi_pointer->phase++;
759 case 3: /* Phase 3 - Ready to accept a command */
761 if (!(r_str(ppb) & 0x80))
764 if (!ppa_send_command(cmd))
766 scsi_pointer->phase++;
769 case 4: /* Phase 4 - Setup scatter/gather buffers */
770 if (scsi_bufflen(cmd)) {
771 scsi_pointer->buffer = scsi_sglist(cmd);
772 scsi_pointer->this_residual =
773 scsi_pointer->buffer->length;
774 scsi_pointer->ptr = sg_virt(scsi_pointer->buffer);
776 scsi_pointer->buffer = NULL;
777 scsi_pointer->this_residual = 0;
778 scsi_pointer->ptr = NULL;
780 scsi_pointer->buffers_residual = scsi_sg_count(cmd) - 1;
781 scsi_pointer->phase++;
784 case 5: /* Phase 5 - Data transfer stage */
786 if (!(r_str(ppb) & 0x80))
789 retv = ppa_completion(cmd);
794 scsi_pointer->phase++;
797 case 6: /* Phase 6 - Read status/message */
798 cmd->result = DID_OK << 16;
799 /* Check for data overrun */
800 if (ppa_wait(dev) != (unsigned char) 0xf0) {
801 ppa_fail(dev, DID_ERROR);
804 if (ppa_in(dev, &l, 1)) { /* read status byte */
805 /* Check for optional message byte */
806 if (ppa_wait(dev) == (unsigned char) 0xf0)
809 (DID_OK << 16) + (h << 8) + (l & STATUS_MASK);
811 return 0; /* Finished */
814 printk(KERN_ERR "ppa: Invalid scsi phase\n");
819 static int ppa_queuecommand_lck(struct scsi_cmnd *cmd)
821 ppa_struct *dev = ppa_dev(cmd->device->host);
824 printk(KERN_ERR "PPA: bug in ppa_queuecommand\n");
828 dev->jstart = jiffies;
830 cmd->result = DID_ERROR << 16; /* default return code */
831 ppa_scsi_pointer(cmd)->phase = 0; /* bus free */
833 schedule_delayed_work(&dev->ppa_tq, 0);
840 static DEF_SCSI_QCMD(ppa_queuecommand)
843 * Apparently the disk->capacity attribute is off by 1 sector
844 * for all disk drives. We add the one here, but it should really
845 * be done in sd.c. Even if it gets fixed there, this will still
848 static int ppa_biosparam(struct scsi_device *sdev, struct block_device *dev,
849 sector_t capacity, int ip[])
853 ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
857 ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
864 static int ppa_abort(struct scsi_cmnd *cmd)
866 ppa_struct *dev = ppa_dev(cmd->device->host);
868 * There is no method for aborting commands since Iomega
869 * have tied the SCSI_MESSAGE line high in the interface
872 switch (ppa_scsi_pointer(cmd)->phase) {
873 case 0: /* Do not have access to parport */
874 case 1: /* Have not connected to interface */
875 dev->cur_cmd = NULL; /* Forget the problem */
877 default: /* SCSI command sent, can not abort */
882 static void ppa_reset_pulse(unsigned int base)
890 static int ppa_reset(struct scsi_cmnd *cmd)
892 ppa_struct *dev = ppa_dev(cmd->device->host);
894 if (ppa_scsi_pointer(cmd)->phase)
896 dev->cur_cmd = NULL; /* Forget the problem */
898 ppa_connect(dev, CONNECT_NORMAL);
899 ppa_reset_pulse(dev->base);
900 mdelay(1); /* device settle delay */
902 mdelay(1); /* device settle delay */
906 static int device_check(ppa_struct *dev, bool autodetect)
908 /* This routine looks for a device and then attempts to use EPP
909 to send a command. If all goes as planned then EPP is available. */
911 static u8 cmd[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
912 int loop, old_mode, status, k, ppb = dev->base;
915 old_mode = dev->mode;
916 for (loop = 0; loop < 8; loop++) {
917 /* Attempt to use EPP for Test Unit Ready */
918 if (autodetect && (ppb & 0x0007) == 0x0000)
919 dev->mode = PPA_EPP_8;
922 ppa_connect(dev, CONNECT_EPP_MAYBE);
923 /* Select SCSI device */
924 if (!ppa_select(dev, loop)) {
928 printk(KERN_INFO "ppa: Found device at ID %i, Attempting to use %s\n",
929 loop, PPA_MODE_STRING[dev->mode]);
931 /* Send SCSI command */
934 for (l = 0; (l < 6) && (status); l++)
935 status = ppa_out(dev, cmd, 1);
939 ppa_connect(dev, CONNECT_EPP_MAYBE);
947 if (dev->mode != old_mode) {
948 dev->mode = old_mode;
954 k = 1000000; /* 1 Second */
959 } while (!(l & 0x80) && (k));
965 ppa_connect(dev, CONNECT_EPP_MAYBE);
966 ppa_reset_pulse(ppb);
970 if (dev->mode != old_mode) {
971 dev->mode = old_mode;
977 printk(KERN_INFO "ppa: Communication established with ID %i using %s\n",
978 loop, PPA_MODE_STRING[dev->mode]);
979 ppa_connect(dev, CONNECT_EPP_MAYBE);
980 ppa_reset_pulse(ppb);
989 static int ppa_adjust_queue(struct scsi_device *device)
991 blk_queue_bounce_limit(device->request_queue, BLK_BOUNCE_HIGH);
995 static const struct scsi_host_template ppa_template = {
996 .module = THIS_MODULE,
998 .show_info = ppa_show_info,
999 .write_info = ppa_write_info,
1000 .name = "Iomega VPI0 (ppa) interface",
1001 .queuecommand = ppa_queuecommand,
1002 .eh_abort_handler = ppa_abort,
1003 .eh_host_reset_handler = ppa_reset,
1004 .bios_param = ppa_biosparam,
1006 .sg_tablesize = SG_ALL,
1008 .slave_alloc = ppa_adjust_queue,
1009 .cmd_size = sizeof(struct scsi_pointer),
1012 /***************************************************************************
1013 * Parallel port probing routines *
1014 ***************************************************************************/
1016 static LIST_HEAD(ppa_hosts);
1019 * Finds the first available device number that can be alloted to the
1020 * new ppa device and returns the address of the previous node so that
1021 * we can add to the tail and have a list in the ascending order.
1024 static inline ppa_struct *find_parent(void)
1026 ppa_struct *dev, *par = NULL;
1027 unsigned int cnt = 0;
1029 if (list_empty(&ppa_hosts))
1032 list_for_each_entry(dev, &ppa_hosts, list) {
1033 if (dev->dev_no != cnt)
1042 static int __ppa_attach(struct parport *pb)
1044 struct Scsi_Host *host;
1045 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waiting);
1047 ppa_struct *dev, *temp;
1050 struct pardev_cb ppa_cb;
1052 dev = kzalloc(sizeof(ppa_struct), GFP_KERNEL);
1056 dev->mode = mode < PPA_UNKNOWN ? mode : PPA_AUTODETECT;
1057 dev->recon_tmo = PPA_RECON_TMO;
1058 init_waitqueue_head(&waiting);
1059 temp = find_parent();
1061 dev->dev_no = temp->dev_no + 1;
1063 memset(&ppa_cb, 0, sizeof(ppa_cb));
1064 ppa_cb.private = dev;
1065 ppa_cb.wakeup = ppa_wakeup;
1067 dev->dev = parport_register_dev_model(pb, "ppa", &ppa_cb, dev->dev_no);
1072 /* Claim the bus so it remembers what we do to the control
1073 * registers. [ CTR and ECP ]
1076 dev->waiting = &waiting;
1077 prepare_to_wait(&waiting, &wait, TASK_UNINTERRUPTIBLE);
1078 if (ppa_pb_claim(dev))
1079 schedule_timeout(3 * HZ);
1081 printk(KERN_ERR "ppa%d: failed to claim parport because "
1082 "a pardevice is owning the port for too long "
1083 "time!\n", pb->number);
1084 ppa_pb_dismiss(dev);
1085 dev->waiting = NULL;
1086 finish_wait(&waiting, &wait);
1089 dev->waiting = NULL;
1090 finish_wait(&waiting, &wait);
1091 dev->base = dev->dev->port->base;
1092 w_ctr(dev->base, 0x0c);
1094 /* Done configuration */
1096 err = ppa_init(dev);
1097 ppa_pb_release(dev);
1102 /* now the glue ... */
1103 if (dev->mode == PPA_NIBBLE || dev->mode == PPA_PS2)
1108 INIT_DELAYED_WORK(&dev->ppa_tq, ppa_interrupt);
1111 host = scsi_host_alloc(&ppa_template, sizeof(ppa_struct *));
1114 host->io_port = pb->base;
1115 host->n_io_port = ports;
1116 host->dma_channel = -1;
1117 host->unique_id = pb->number;
1118 *(ppa_struct **)&host->hostdata = dev;
1120 list_add_tail(&dev->list, &ppa_hosts);
1121 err = scsi_add_host(host, NULL);
1124 scsi_scan_host(host);
1127 list_del_init(&dev->list);
1128 scsi_host_put(host);
1130 parport_unregister_device(dev->dev);
1136 static void ppa_attach(struct parport *pb)
1141 static void ppa_detach(struct parport *pb)
1144 list_for_each_entry(dev, &ppa_hosts, list) {
1145 if (dev->dev->port == pb) {
1146 list_del_init(&dev->list);
1147 scsi_remove_host(dev->host);
1148 scsi_host_put(dev->host);
1149 parport_unregister_device(dev->dev);
1156 static struct parport_driver ppa_driver = {
1158 .match_port = ppa_attach,
1159 .detach = ppa_detach,
1162 module_parport_driver(ppa_driver);
1164 MODULE_LICENSE("GPL");