1 /* imm.c -- low level driver for the IOMEGA MatchMaker
2 * parallel port SCSI host adapter.
4 * (The IMM is the embedded controller in the ZIP Plus drive.)
6 * Current Maintainer: David Campbell (Perth, Western Australia)
9 * My unoffical company acronym list is 21 pages long:
10 * FLA: Four letter acronym with built in facility for
11 * future expansion to five letters.
14 #include <linux/config.h>
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/blkdev.h>
19 #include <linux/parport.h>
20 #include <linux/workqueue.h>
23 #include <scsi/scsi.h>
24 #include <scsi/scsi_cmnd.h>
25 #include <scsi/scsi_device.h>
26 #include <scsi/scsi_host.h>
28 /* The following #define is to avoid a clash with hosts.c */
29 #define IMM_PROBE_SPP 0x0001
30 #define IMM_PROBE_PS2 0x0002
31 #define IMM_PROBE_ECR 0x0010
32 #define IMM_PROBE_EPP17 0x0100
33 #define IMM_PROBE_EPP19 0x0200
37 struct pardevice *dev; /* Parport device entry */
38 int base; /* Actual port address */
39 int base_hi; /* Hi Base address for ECP-ISA chipset */
40 int mode; /* Transfer mode */
41 struct scsi_cmnd *cur_cmd; /* Current queued command */
42 struct work_struct imm_tq; /* Polling interrupt stuff */
43 unsigned long jstart; /* Jiffies at start */
44 unsigned failed:1; /* Failure flag */
45 unsigned dp:1; /* Data phase present */
46 unsigned rd:1; /* Read data in data phase */
47 unsigned wanted:1; /* Parport sharing busy flag */
48 wait_queue_head_t *waiting;
49 struct Scsi_Host *host;
50 struct list_head list;
53 static void imm_reset_pulse(unsigned int base);
54 static int device_check(imm_struct *dev);
58 static inline imm_struct *imm_dev(struct Scsi_Host *host)
60 return *(imm_struct **)&host->hostdata;
63 static DEFINE_SPINLOCK(arbitration_lock);
65 static void got_it(imm_struct *dev)
67 dev->base = dev->dev->port->base;
69 dev->cur_cmd->SCp.phase = 1;
71 wake_up(dev->waiting);
74 static void imm_wakeup(void *ref)
76 imm_struct *dev = (imm_struct *) ref;
79 spin_lock_irqsave(&arbitration_lock, flags);
81 parport_claim(dev->dev);
85 spin_unlock_irqrestore(&arbitration_lock, flags);
88 static int imm_pb_claim(imm_struct *dev)
92 spin_lock_irqsave(&arbitration_lock, flags);
93 if (parport_claim(dev->dev) == 0) {
98 spin_unlock_irqrestore(&arbitration_lock, flags);
102 static void imm_pb_dismiss(imm_struct *dev)
106 spin_lock_irqsave(&arbitration_lock, flags);
107 wanted = dev->wanted;
109 spin_unlock_irqrestore(&arbitration_lock, flags);
111 parport_release(dev->dev);
114 static inline void imm_pb_release(imm_struct *dev)
116 parport_release(dev->dev);
119 /* This is to give the imm driver a way to modify the timings (and other
120 * parameters) by writing to the /proc/scsi/imm/0 file.
121 * Very simple method really... (Too simple, no error checking :( )
122 * Reason: Kernel hackers HATE having to unload and reload modules for
124 * Also gives a method to use a script to obtain optimum timings (TODO)
126 static inline int imm_proc_write(imm_struct *dev, char *buffer, int length)
130 if ((length > 5) && (strncmp(buffer, "mode=", 5) == 0)) {
131 x = simple_strtoul(buffer + 5, NULL, 0);
135 printk("imm /proc: invalid variable\n");
139 static int imm_proc_info(struct Scsi_Host *host, char *buffer, char **start,
140 off_t offset, int length, int inout)
142 imm_struct *dev = imm_dev(host);
146 return imm_proc_write(dev, buffer, length);
148 len += sprintf(buffer + len, "Version : %s\n", IMM_VERSION);
150 sprintf(buffer + len, "Parport : %s\n",
151 dev->dev->port->name);
153 sprintf(buffer + len, "Mode : %s\n",
154 IMM_MODE_STRING[dev->mode]);
156 /* Request for beyond end of buffer */
160 *start = buffer + offset;
168 #define imm_fail(x,y) printk("imm: imm_fail(%i) from %s at line %d\n",\
169 y, __FUNCTION__, __LINE__); imm_fail_func(x,y);
171 imm_fail_func(imm_struct *dev, int error_code)
174 imm_fail(imm_struct *dev, int error_code)
177 /* If we fail a device then we trash status / message bytes */
179 dev->cur_cmd->result = error_code << 16;
185 * Wait for the high bit to be set.
187 * In principle, this could be tied to an interrupt, but the adapter
188 * doesn't appear to be designed to support interrupts. We spin on
189 * the 0x80 ready bit.
191 static unsigned char imm_wait(imm_struct *dev)
194 unsigned short ppb = dev->base;
205 while (!(r & 0x80) && (k));
208 * STR register (LPT base+1) to SCSI mapping:
211 * ===================================
219 * ==================================
221 * 0xc0 0x88 ZIP wants more data
222 * 0xd0 0x98 ZIP wants to send more data
223 * 0xe0 0xa8 ZIP is expecting SCSI command data
224 * 0xf0 0xb8 end of transfer, ZIP is sending status
230 /* Counter expired - Time out occurred */
231 imm_fail(dev, DID_TIME_OUT);
232 printk("imm timeout in imm_wait\n");
233 return 0; /* command timed out */
236 static int imm_negotiate(imm_struct * tmp)
239 * The following is supposedly the IEEE 1284-1994 negotiate
240 * sequence. I have yet to obtain a copy of the above standard
241 * so this is a bit of a guess...
243 * A fair chunk of this is based on the Linux parport implementation
246 * Return 0 if data available
247 * 1 if no data available
250 unsigned short base = tmp->base;
251 unsigned char a, mode;
270 a = (r_str(base) & 0x20) ? 0 : 1;
278 ("IMM: IEEE1284 negotiate indicates no data available.\n");
279 imm_fail(tmp, DID_ERROR);
285 * Clear EPP timeout bit.
287 static inline void epp_reset(unsigned short ppb)
293 w_str(ppb, i & 0xfe);
297 * Wait for empty ECP fifo (if we are in ECP fifo mode only)
299 static inline void ecp_sync(imm_struct *dev)
301 int i, ppb_hi = dev->base_hi;
306 if ((r_ecr(ppb_hi) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
307 for (i = 0; i < 100; i++) {
308 if (r_ecr(ppb_hi) & 0x01)
312 printk("imm: ECP sync failed as data still present in FIFO.\n");
316 static int imm_byte_out(unsigned short base, const char *buffer, int len)
320 w_ctr(base, 0x4); /* apparently a sane mode */
321 for (i = len >> 1; i; i--) {
322 w_dtr(base, *buffer++);
323 w_ctr(base, 0x5); /* Drop STROBE low */
324 w_dtr(base, *buffer++);
325 w_ctr(base, 0x0); /* STROBE high + INIT low */
327 w_ctr(base, 0x4); /* apparently a sane mode */
328 return 1; /* All went well - we hope! */
331 static int imm_nibble_in(unsigned short base, char *buffer, int len)
337 * The following is based on documented timing signals
340 for (i = len; i; i--) {
342 l = (r_str(base) & 0xf0) >> 4;
344 *buffer++ = (r_str(base) & 0xf0) | l;
347 return 1; /* All went well - we hope! */
350 static int imm_byte_in(unsigned short base, char *buffer, int len)
355 * The following is based on documented timing signals
358 for (i = len; i; i--) {
360 *buffer++ = r_dtr(base);
363 return 1; /* All went well - we hope! */
366 static int imm_out(imm_struct *dev, char *buffer, int len)
368 unsigned short ppb = dev->base;
369 int r = imm_wait(dev);
373 * a) the SCSI bus is BUSY (device still listening)
374 * b) the device is listening
376 if ((r & 0x18) != 0x08) {
377 imm_fail(dev, DID_ERROR);
378 printk("IMM: returned SCSI status %2x\n", r);
387 #ifdef CONFIG_SCSI_IZIP_EPP16
388 if (!(((long) buffer | len) & 0x01))
389 outsw(ppb + 4, buffer, len >> 1);
391 if (!(((long) buffer | len) & 0x03))
392 outsl(ppb + 4, buffer, len >> 2);
395 outsb(ppb + 4, buffer, len);
397 r = !(r_str(ppb) & 0x01);
404 /* 8 bit output, with a loop */
405 r = imm_byte_out(ppb, buffer, len);
409 printk("IMM: bug in imm_out()\n");
415 static int imm_in(imm_struct *dev, char *buffer, int len)
417 unsigned short ppb = dev->base;
418 int r = imm_wait(dev);
422 * a) the SCSI bus is BUSY (device still listening)
423 * b) the device is sending data
425 if ((r & 0x18) != 0x18) {
426 imm_fail(dev, DID_ERROR);
431 /* 4 bit input, with a loop */
432 r = imm_nibble_in(ppb, buffer, len);
437 /* 8 bit input, with a loop */
438 r = imm_byte_in(ppb, buffer, len);
447 #ifdef CONFIG_SCSI_IZIP_EPP16
448 if (!(((long) buffer | len) & 0x01))
449 insw(ppb + 4, buffer, len >> 1);
451 if (!(((long) buffer | len) & 0x03))
452 insl(ppb + 4, buffer, len >> 2);
455 insb(ppb + 4, buffer, len);
457 r = !(r_str(ppb) & 0x01);
463 printk("IMM: bug in imm_ins()\n");
470 static int imm_cpp(unsigned short ppb, unsigned char b)
473 * Comments on udelay values refer to the
474 * Command Packet Protocol (CPP) timing diagram.
477 unsigned char s1, s2, s3;
479 udelay(2); /* 1 usec - infinite */
481 udelay(10); /* 7 usec - infinite */
483 udelay(10); /* 7 usec - infinite */
485 udelay(10); /* 7 usec - infinite */
487 udelay(10); /* 7 usec - infinite */
488 s1 = r_str(ppb) & 0xb8;
490 udelay(10); /* 7 usec - infinite */
491 s2 = r_str(ppb) & 0xb8;
493 udelay(10); /* 7 usec - infinite */
494 s3 = r_str(ppb) & 0x38;
497 * 0000 00aa Assign address aa to current device
498 * 0010 00aa Select device aa in EPP Winbond mode
499 * 0010 10aa Select device aa in EPP mode
500 * 0011 xxxx Deselect all devices
501 * 0110 00aa Test device aa
502 * 1101 00aa Select device aa in ECP mode
503 * 1110 00aa Select device aa in Compatible mode
506 udelay(2); /* 1 usec - infinite */
508 udelay(10); /* 7 usec - infinite */
510 udelay(2); /* 1 usec - infinite */
512 udelay(10); /* 7 usec - infinite */
514 udelay(10); /* 7 usec - infinite */
517 * The following table is electrical pin values.
518 * (BSY is inverted at the CTR register)
520 * BSY ACK POut SEL Fault
525 * L => Last device in chain
528 * Observered values for S1,S2,S3 are:
529 * Disconnect => f8/58/78
530 * Connect => f8/58/70
532 if ((s1 == 0xb8) && (s2 == 0x18) && (s3 == 0x30))
533 return 1; /* Connected */
534 if ((s1 == 0xb8) && (s2 == 0x18) && (s3 == 0x38))
535 return 0; /* Disconnected */
537 return -1; /* No device present */
540 static inline int imm_connect(imm_struct *dev, int flag)
542 unsigned short ppb = dev->base;
544 imm_cpp(ppb, 0xe0); /* Select device 0 in compatible mode */
545 imm_cpp(ppb, 0x30); /* Disconnect all devices */
547 if ((dev->mode == IMM_EPP_8) ||
548 (dev->mode == IMM_EPP_16) ||
549 (dev->mode == IMM_EPP_32))
550 return imm_cpp(ppb, 0x28); /* Select device 0 in EPP mode */
551 return imm_cpp(ppb, 0xe0); /* Select device 0 in compatible mode */
554 static void imm_disconnect(imm_struct *dev)
556 imm_cpp(dev->base, 0x30); /* Disconnect all devices */
559 static int imm_select(imm_struct *dev, int target)
562 unsigned short ppb = dev->base;
565 * Firstly we want to make sure there is nothing
566 * holding onto the SCSI bus.
573 } while ((r_str(ppb) & 0x08) && (k));
579 * Now assert the SCSI ID (HOST and TARGET) on the data bus
582 w_dtr(ppb, 0x80 | (1 << target));
586 * Deassert SELIN first followed by STROBE
592 * ACK should drop low while SELIN is deasserted.
593 * FAULT should drop low when the SCSI device latches the bus.
599 while (!(r_str(ppb) & 0x08) && (k));
602 * Place the interface back into a sane state (status mode)
608 static int imm_init(imm_struct *dev)
610 if (imm_connect(dev, 0) != 1)
612 imm_reset_pulse(dev->base);
613 udelay(1000); /* Delay to allow devices to settle */
615 udelay(1000); /* Another delay to allow devices to settle */
616 return device_check(dev);
619 static inline int imm_send_command(struct scsi_cmnd *cmd)
621 imm_struct *dev = imm_dev(cmd->device->host);
624 /* NOTE: IMM uses byte pairs */
625 for (k = 0; k < cmd->cmd_len; k += 2)
626 if (!imm_out(dev, &cmd->cmnd[k], 2))
632 * The bulk flag enables some optimisations in the data transfer loops,
633 * it should be true for any command that transfers data in integral
634 * numbers of sectors.
636 * The driver appears to remain stable if we speed up the parallel port
637 * i/o in this function, but not elsewhere.
639 static int imm_completion(struct scsi_cmnd *cmd)
644 * 1 Finished data transfer
646 imm_struct *dev = imm_dev(cmd->device->host);
647 unsigned short ppb = dev->base;
648 unsigned long start_jiffies = jiffies;
651 int fast, bulk, status;
654 bulk = ((v == READ_6) ||
655 (v == READ_10) || (v == WRITE_6) || (v == WRITE_10));
658 * We only get here if the drive is ready to comunicate,
659 * hence no need for a full imm_wait.
662 r = (r_str(ppb) & 0xb8);
665 * while (device is not ready to send status byte)
668 while (r != (unsigned char) 0xb8) {
670 * If we have been running for more than a full timer tick
673 if (time_after(jiffies, start_jiffies + 1))
678 * a) Drive status is screwy (!ready && !present)
679 * b) Drive is requesting/sending more data than expected
681 if (((r & 0x88) != 0x88) || (cmd->SCp.this_residual <= 0)) {
682 imm_fail(dev, DID_ERROR);
683 return -1; /* ERROR_RETURN */
685 /* determine if we should use burst I/O */
688 && (cmd->SCp.this_residual >=
689 IMM_BURST_SIZE)) ? IMM_BURST_SIZE : 2;
690 status = imm_out(dev, cmd->SCp.ptr, fast);
693 && (cmd->SCp.this_residual >=
694 IMM_BURST_SIZE)) ? IMM_BURST_SIZE : 1;
695 status = imm_in(dev, cmd->SCp.ptr, fast);
698 cmd->SCp.ptr += fast;
699 cmd->SCp.this_residual -= fast;
702 imm_fail(dev, DID_BUS_BUSY);
703 return -1; /* ERROR_RETURN */
705 if (cmd->SCp.buffer && !cmd->SCp.this_residual) {
706 /* if scatter/gather, advance to the next segment */
707 if (cmd->SCp.buffers_residual--) {
709 cmd->SCp.this_residual =
710 cmd->SCp.buffer->length;
712 page_address(cmd->SCp.buffer->page) +
713 cmd->SCp.buffer->offset;
716 * Make sure that we transfer even number of bytes
717 * otherwise it makes imm_byte_out() messy.
719 if (cmd->SCp.this_residual & 0x01)
720 cmd->SCp.this_residual++;
723 /* Now check to see if the drive is ready to comunicate */
725 r = (r_str(ppb) & 0xb8);
727 /* If not, drop back down to the scheduler and wait a timer tick */
731 return 1; /* FINISH_RETURN */
735 * Since the IMM itself doesn't generate interrupts, we use
736 * the scheduler's task queue to generate a stream of call-backs and
737 * complete the request when the drive is ready.
739 static void imm_interrupt(void *data)
741 imm_struct *dev = (imm_struct *) data;
742 struct scsi_cmnd *cmd = dev->cur_cmd;
743 struct Scsi_Host *host = cmd->device->host;
747 printk("IMM: bug in imm_interrupt\n");
750 if (imm_engine(dev, cmd)) {
751 INIT_WORK(&dev->imm_tq, imm_interrupt, (void *) dev);
752 schedule_delayed_work(&dev->imm_tq, 1);
755 /* Command must of completed hence it is safe to let go... */
757 switch ((cmd->result >> 16) & 0xff) {
761 printk("imm: no device at SCSI ID %i\n", cmd->device->id);
764 printk("imm: BUS BUSY - EPP timeout detected\n");
767 printk("imm: unknown timeout\n");
770 printk("imm: told to abort\n");
773 printk("imm: parity error (???)\n");
776 printk("imm: internal driver error\n");
779 printk("imm: told to reset device\n");
782 printk("imm: bad interrupt (???)\n");
785 printk("imm: bad return code (%02x)\n",
786 (cmd->result >> 16) & 0xff);
790 if (cmd->SCp.phase > 1)
795 spin_lock_irqsave(host->host_lock, flags);
798 spin_unlock_irqrestore(host->host_lock, flags);
802 static int imm_engine(imm_struct *dev, struct scsi_cmnd *cmd)
804 unsigned short ppb = dev->base;
805 unsigned char l = 0, h = 0;
808 /* First check for any errors that may have occurred
809 * Here we check for internal errors
814 switch (cmd->SCp.phase) {
815 case 0: /* Phase 0 - Waiting for parport */
816 if (time_after(jiffies, dev->jstart + HZ)) {
818 * We waited more than a second
819 * for parport to call us
821 imm_fail(dev, DID_BUS_BUSY);
824 return 1; /* wait until imm_wakeup claims parport */
825 /* Phase 1 - Connected */
827 imm_connect(dev, CONNECT_EPP_MAYBE);
830 /* Phase 2 - We are now talking to the scsi bus */
832 if (!imm_select(dev, cmd->device->id)) {
833 imm_fail(dev, DID_NO_CONNECT);
838 /* Phase 3 - Ready to accept a command */
841 if (!(r_str(ppb) & 0x80))
844 if (!imm_send_command(cmd))
848 /* Phase 4 - Setup scatter/gather buffers */
851 /* if many buffers are available, start filling the first */
853 (struct scatterlist *) cmd->request_buffer;
854 cmd->SCp.this_residual = cmd->SCp.buffer->length;
856 page_address(cmd->SCp.buffer->page) +
857 cmd->SCp.buffer->offset;
859 /* else fill the only available buffer */
860 cmd->SCp.buffer = NULL;
861 cmd->SCp.this_residual = cmd->request_bufflen;
862 cmd->SCp.ptr = cmd->request_buffer;
864 cmd->SCp.buffers_residual = cmd->use_sg - 1;
866 if (cmd->SCp.this_residual & 0x01)
867 cmd->SCp.this_residual++;
868 /* Phase 5 - Pre-Data transfer stage */
870 /* Spin lock for BUSY */
872 if (!(r_str(ppb) & 0x80))
875 /* Require negotiation for read requests */
876 x = (r_str(ppb) & 0xb8);
877 dev->rd = (x & 0x10) ? 1 : 0;
878 dev->dp = (x & 0x20) ? 0 : 1;
880 if ((dev->dp) && (dev->rd))
881 if (imm_negotiate(dev))
885 /* Phase 6 - Data transfer stage */
887 /* Spin lock for BUSY */
889 if (!(r_str(ppb) & 0x80))
893 retv = imm_completion(cmd);
901 /* Phase 7 - Post data transfer stage */
903 if ((dev->dp) && (dev->rd)) {
904 if ((dev->mode == IMM_NIBBLE) || (dev->mode == IMM_PS2)) {
913 /* Phase 8 - Read status/message */
915 /* Check for data overrun */
916 if (imm_wait(dev) != (unsigned char) 0xb8) {
917 imm_fail(dev, DID_ERROR);
920 if (imm_negotiate(dev))
922 if (imm_in(dev, &l, 1)) { /* read status byte */
923 /* Check for optional message byte */
924 if (imm_wait(dev) == (unsigned char) 0xb8)
926 cmd->result = (DID_OK << 16) + (l & STATUS_MASK);
928 if ((dev->mode == IMM_NIBBLE) || (dev->mode == IMM_PS2)) {
934 return 0; /* Finished */
938 printk("imm: Invalid scsi phase\n");
943 static int imm_queuecommand(struct scsi_cmnd *cmd,
944 void (*done)(struct scsi_cmnd *))
946 imm_struct *dev = imm_dev(cmd->device->host);
949 printk("IMM: bug in imm_queuecommand\n");
953 dev->jstart = jiffies;
955 cmd->scsi_done = done;
956 cmd->result = DID_ERROR << 16; /* default return code */
957 cmd->SCp.phase = 0; /* bus free */
959 INIT_WORK(&dev->imm_tq, imm_interrupt, dev);
960 schedule_work(&dev->imm_tq);
968 * Apparently the disk->capacity attribute is off by 1 sector
969 * for all disk drives. We add the one here, but it should really
970 * be done in sd.c. Even if it gets fixed there, this will still
973 static int imm_biosparam(struct scsi_device *sdev, struct block_device *dev,
974 sector_t capacity, int ip[])
978 ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
982 ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
987 static int imm_abort(struct scsi_cmnd *cmd)
989 imm_struct *dev = imm_dev(cmd->device->host);
991 * There is no method for aborting commands since Iomega
992 * have tied the SCSI_MESSAGE line high in the interface
995 switch (cmd->SCp.phase) {
996 case 0: /* Do not have access to parport */
997 case 1: /* Have not connected to interface */
998 dev->cur_cmd = NULL; /* Forget the problem */
1001 default: /* SCSI command sent, can not abort */
1007 static void imm_reset_pulse(unsigned int base)
1019 static int imm_reset(struct scsi_cmnd *cmd)
1021 imm_struct *dev = imm_dev(cmd->device->host);
1024 imm_disconnect(dev);
1025 dev->cur_cmd = NULL; /* Forget the problem */
1027 imm_connect(dev, CONNECT_NORMAL);
1028 imm_reset_pulse(dev->base);
1029 udelay(1000); /* device settle delay */
1030 imm_disconnect(dev);
1031 udelay(1000); /* device settle delay */
1035 static int device_check(imm_struct *dev)
1037 /* This routine looks for a device and then attempts to use EPP
1038 to send a command. If all goes as planned then EPP is available. */
1040 static char cmd[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
1041 int loop, old_mode, status, k, ppb = dev->base;
1044 old_mode = dev->mode;
1045 for (loop = 0; loop < 8; loop++) {
1046 /* Attempt to use EPP for Test Unit Ready */
1047 if ((ppb & 0x0007) == 0x0000)
1048 dev->mode = IMM_EPP_32;
1051 imm_connect(dev, CONNECT_EPP_MAYBE);
1052 /* Select SCSI device */
1053 if (!imm_select(dev, loop)) {
1054 imm_disconnect(dev);
1057 printk("imm: Found device at ID %i, Attempting to use %s\n",
1058 loop, IMM_MODE_STRING[dev->mode]);
1060 /* Send SCSI command */
1063 for (l = 0; (l < 3) && (status); l++)
1064 status = imm_out(dev, &cmd[l << 1], 2);
1067 imm_disconnect(dev);
1068 imm_connect(dev, CONNECT_EPP_MAYBE);
1069 imm_reset_pulse(dev->base);
1071 imm_disconnect(dev);
1073 if (dev->mode == IMM_EPP_32) {
1074 dev->mode = old_mode;
1077 printk("imm: Unable to establish communication\n");
1082 k = 1000000; /* 1 Second */
1087 } while (!(l & 0x80) && (k));
1092 imm_disconnect(dev);
1093 imm_connect(dev, CONNECT_EPP_MAYBE);
1094 imm_reset_pulse(dev->base);
1096 imm_disconnect(dev);
1098 if (dev->mode == IMM_EPP_32) {
1099 dev->mode = old_mode;
1103 ("imm: Unable to establish communication\n");
1106 imm_disconnect(dev);
1108 ("imm: Communication established at 0x%x with ID %i using %s\n",
1109 ppb, loop, IMM_MODE_STRING[dev->mode]);
1110 imm_connect(dev, CONNECT_EPP_MAYBE);
1111 imm_reset_pulse(dev->base);
1113 imm_disconnect(dev);
1117 printk("imm: No devices found\n");
1121 static int imm_adjust_queue(struct scsi_device *device)
1123 blk_queue_bounce_limit(device->request_queue, BLK_BOUNCE_HIGH);
1127 static struct scsi_host_template imm_template = {
1128 .module = THIS_MODULE,
1130 .proc_info = imm_proc_info,
1131 .name = "Iomega VPI2 (imm) interface",
1132 .queuecommand = imm_queuecommand,
1133 .eh_abort_handler = imm_abort,
1134 .eh_bus_reset_handler = imm_reset,
1135 .eh_host_reset_handler = imm_reset,
1136 .bios_param = imm_biosparam,
1138 .sg_tablesize = SG_ALL,
1140 .use_clustering = ENABLE_CLUSTERING,
1142 .slave_alloc = imm_adjust_queue,
1143 .unchecked_isa_dma = 1, /* imm cannot deal with highmem, so
1144 * this is an easy trick to ensure
1145 * all io pages for this host reside
1149 /***************************************************************************
1150 * Parallel port probing routines *
1151 ***************************************************************************/
1153 static LIST_HEAD(imm_hosts);
1155 static int __imm_attach(struct parport *pb)
1157 struct Scsi_Host *host;
1159 DECLARE_WAIT_QUEUE_HEAD(waiting);
1165 init_waitqueue_head(&waiting);
1167 dev = kmalloc(sizeof(imm_struct), GFP_KERNEL);
1171 memset(dev, 0, sizeof(imm_struct));
1174 dev->mode = IMM_AUTODETECT;
1175 INIT_LIST_HEAD(&dev->list);
1177 dev->dev = parport_register_device(pb, "imm", NULL, imm_wakeup,
1184 /* Claim the bus so it remembers what we do to the control
1185 * registers. [ CTR and ECP ]
1188 dev->waiting = &waiting;
1189 prepare_to_wait(&waiting, &wait, TASK_UNINTERRUPTIBLE);
1190 if (imm_pb_claim(dev))
1191 schedule_timeout(3 * HZ);
1193 printk(KERN_ERR "imm%d: failed to claim parport because "
1194 "a pardevice is owning the port for too long "
1195 "time!\n", pb->number);
1196 imm_pb_dismiss(dev);
1197 dev->waiting = NULL;
1198 finish_wait(&waiting, &wait);
1201 dev->waiting = NULL;
1202 finish_wait(&waiting, &wait);
1203 ppb = dev->base = dev->dev->port->base;
1204 dev->base_hi = dev->dev->port->base_hi;
1206 modes = dev->dev->port->modes;
1208 /* Mode detection works up the chain of speed
1209 * This avoids a nasty if-then-else-if-... tree
1211 dev->mode = IMM_NIBBLE;
1213 if (modes & PARPORT_MODE_TRISTATE)
1214 dev->mode = IMM_PS2;
1216 /* Done configuration */
1218 err = imm_init(dev);
1220 imm_pb_release(dev);
1225 /* now the glue ... */
1226 if (dev->mode == IMM_NIBBLE || dev->mode == IMM_PS2)
1231 INIT_WORK(&dev->imm_tq, imm_interrupt, dev);
1234 host = scsi_host_alloc(&imm_template, sizeof(imm_struct *));
1237 host->io_port = pb->base;
1238 host->n_io_port = ports;
1239 host->dma_channel = -1;
1240 host->unique_id = pb->number;
1241 *(imm_struct **)&host->hostdata = dev;
1243 list_add_tail(&dev->list, &imm_hosts);
1244 err = scsi_add_host(host, NULL);
1247 scsi_scan_host(host);
1251 list_del_init(&dev->list);
1252 scsi_host_put(host);
1254 parport_unregister_device(dev->dev);
1260 static void imm_attach(struct parport *pb)
1265 static void imm_detach(struct parport *pb)
1268 list_for_each_entry(dev, &imm_hosts, list) {
1269 if (dev->dev->port == pb) {
1270 list_del_init(&dev->list);
1271 scsi_remove_host(dev->host);
1272 scsi_host_put(dev->host);
1273 parport_unregister_device(dev->dev);
1280 static struct parport_driver imm_driver = {
1282 .attach = imm_attach,
1283 .detach = imm_detach,
1286 static int __init imm_driver_init(void)
1288 printk("imm: Version %s\n", IMM_VERSION);
1289 return parport_register_driver(&imm_driver);
1292 static void __exit imm_driver_exit(void)
1294 parport_unregister_driver(&imm_driver);
1297 module_init(imm_driver_init);
1298 module_exit(imm_driver_exit);
1300 MODULE_LICENSE("GPL");