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.
9 * Current Maintainer: David Campbell (Perth, Western Australia, GMT+0800)
13 #include <linux/config.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/blkdev.h>
18 #include <linux/parport.h>
19 #include <linux/workqueue.h>
20 #include <linux/delay.h>
23 #include <scsi/scsi.h>
24 #include <scsi/scsi_cmnd.h>
25 #include <scsi/scsi_device.h>
26 #include <scsi/scsi_host.h>
29 static void ppa_reset_pulse(unsigned int base);
32 struct pardevice *dev; /* Parport device entry */
33 int base; /* Actual port address */
34 int mode; /* Transfer mode */
35 struct scsi_cmnd *cur_cmd; /* Current queued command */
36 struct work_struct ppa_tq; /* Polling interrupt stuff */
37 unsigned long jstart; /* Jiffies at start */
38 unsigned long recon_tmo; /* How many usecs to wait for reconnection (6th bit) */
39 unsigned int failed:1; /* Failure flag */
40 unsigned wanted:1; /* Parport sharing busy flag */
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_proc_write(ppa_struct *dev, char *buffer, int length)
126 if ((length > 5) && (strncmp(buffer, "mode=", 5) == 0)) {
127 x = simple_strtoul(buffer + 5, NULL, 0);
131 if ((length > 10) && (strncmp(buffer, "recon_tmo=", 10) == 0)) {
132 x = simple_strtoul(buffer + 10, NULL, 0);
134 printk("ppa: recon_tmo set to %ld\n", x);
137 printk("ppa /proc: invalid variable\n");
141 static int ppa_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int inout)
144 ppa_struct *dev = ppa_dev(host);
147 return ppa_proc_write(dev, buffer, length);
149 len += sprintf(buffer + len, "Version : %s\n", PPA_VERSION);
151 sprintf(buffer + len, "Parport : %s\n",
152 dev->dev->port->name);
154 sprintf(buffer + len, "Mode : %s\n",
155 PPA_MODE_STRING[dev->mode]);
158 sprintf(buffer + len, "recon_tmo : %lu\n", dev->recon_tmo);
161 /* Request for beyond end of buffer */
165 *start = buffer + offset;
172 static int device_check(ppa_struct *dev);
175 #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
176 y, __FUNCTION__, __LINE__); ppa_fail_func(x,y);
177 static inline void ppa_fail_func(ppa_struct *dev, int error_code)
179 static inline void ppa_fail(ppa_struct *dev, int error_code)
182 /* If we fail a device then we trash status / message bytes */
184 dev->cur_cmd->result = error_code << 16;
190 * Wait for the high bit to be set.
192 * In principle, this could be tied to an interrupt, but the adapter
193 * doesn't appear to be designed to support interrupts. We spin on
194 * the 0x80 ready bit.
196 static unsigned char ppa_wait(ppa_struct *dev)
199 unsigned short ppb = dev->base;
203 /* Wait for bit 6 and 7 - PJC */
204 for (r = r_str(ppb); ((r & 0xc0) != 0xc0) && (k); k--) {
210 * return some status information.
211 * Semantics: 0xc0 = ZIP wants more data
212 * 0xd0 = ZIP wants to send more data
213 * 0xe0 = ZIP is expecting SCSI command data
214 * 0xf0 = end of transfer, ZIP is sending status
219 /* Counter expired - Time out occurred */
220 ppa_fail(dev, DID_TIME_OUT);
221 printk("ppa timeout in ppa_wait\n");
222 return 0; /* command timed out */
226 * Clear EPP Timeout Bit
228 static inline void epp_reset(unsigned short ppb)
234 w_str(ppb, i & 0xfe);
238 * Wait for empty ECP fifo (if we are in ECP fifo mode only)
240 static inline void ecp_sync(ppa_struct *dev)
242 int i, ppb_hi = dev->dev->port->base_hi;
247 if ((r_ecr(ppb_hi) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
248 for (i = 0; i < 100; i++) {
249 if (r_ecr(ppb_hi) & 0x01)
253 printk("ppa: ECP sync failed as data still present in FIFO.\n");
257 static int ppa_byte_out(unsigned short base, const char *buffer, int len)
261 for (i = len; i; i--) {
262 w_dtr(base, *buffer++);
266 return 1; /* All went well - we hope! */
269 static int ppa_byte_in(unsigned short base, char *buffer, int len)
273 for (i = len; i; i--) {
274 *buffer++ = r_dtr(base);
278 return 1; /* All went well - we hope! */
281 static int ppa_nibble_in(unsigned short base, char *buffer, int len)
287 h = r_str(base) & 0xf0;
289 *buffer++ = h | ((r_str(base) & 0xf0) >> 4);
291 return 1; /* All went well - we hope! */
294 static int ppa_out(ppa_struct *dev, char *buffer, int len)
297 unsigned short ppb = dev->base;
301 if ((r & 0x50) != 0x40) {
302 ppa_fail(dev, DID_ERROR);
308 /* 8 bit output, with a loop */
309 r = ppa_byte_out(ppb, buffer, len);
317 #ifdef CONFIG_SCSI_IZIP_EPP16
318 if (!(((long) buffer | len) & 0x01))
319 outsw(ppb + 4, buffer, len >> 1);
321 if (!(((long) buffer | len) & 0x03))
322 outsl(ppb + 4, buffer, len >> 2);
325 outsb(ppb + 4, buffer, len);
327 r = !(r_str(ppb) & 0x01);
333 printk("PPA: bug in ppa_out()\n");
339 static int ppa_in(ppa_struct *dev, char *buffer, int len)
342 unsigned short ppb = dev->base;
346 if ((r & 0x50) != 0x50) {
347 ppa_fail(dev, DID_ERROR);
352 /* 4 bit input, with a loop */
353 r = ppa_nibble_in(ppb, buffer, len);
358 /* 8 bit input, with a loop */
360 r = ppa_byte_in(ppb, buffer, len);
370 #ifdef CONFIG_SCSI_IZIP_EPP16
371 if (!(((long) buffer | len) & 0x01))
372 insw(ppb + 4, buffer, len >> 1);
374 if (!(((long) buffer | len) & 0x03))
375 insl(ppb + 4, buffer, len >> 2);
378 insb(ppb + 4, buffer, len);
380 r = !(r_str(ppb) & 0x01);
386 printk("PPA: bug in ppa_ins()\n");
393 /* end of ppa_io.h */
394 static inline void ppa_d_pulse(unsigned short ppb, unsigned char b)
404 static void ppa_disconnect(ppa_struct *dev)
406 unsigned short ppb = dev->base;
409 ppa_d_pulse(ppb, 0x3c);
410 ppa_d_pulse(ppb, 0x20);
411 ppa_d_pulse(ppb, 0xf);
414 static inline void ppa_c_pulse(unsigned short ppb, unsigned char b)
423 static inline void ppa_connect(ppa_struct *dev, int flag)
425 unsigned short ppb = dev->base;
428 ppa_c_pulse(ppb, 0x3c);
429 ppa_c_pulse(ppb, 0x20);
430 if ((flag == CONNECT_EPP_MAYBE) && IN_EPP_MODE(dev->mode))
431 ppa_c_pulse(ppb, 0xcf);
433 ppa_c_pulse(ppb, 0x8f);
436 static int ppa_select(ppa_struct *dev, int target)
439 unsigned short ppb = dev->base;
442 * Bit 6 (0x40) is the device selected bit.
443 * First we must wait till the current device goes off line...
449 } while ((r_str(ppb) & 0x40) && (k));
453 w_dtr(ppb, (1 << target));
456 w_dtr(ppb, 0x80); /* This is NOT the initator */
464 while (!(r_str(ppb) & 0x40) && (k));
472 * This is based on a trace of what the Iomega DOS 'guest' driver does.
473 * I've tried several different kinds of parallel ports with guest and
474 * coded this to react in the same ways that it does.
476 * The return value from this function is just a hint about where the
477 * handshaking failed.
480 static int ppa_init(ppa_struct *dev)
483 unsigned short ppb = dev->base;
486 ppa_connect(dev, CONNECT_NORMAL);
488 retv = 2; /* Failed */
491 if ((r_str(ppb) & 0x08) == 0x08)
495 if ((r_str(ppb) & 0x08) == 0x00)
499 ppa_reset_pulse(ppb);
500 udelay(1000); /* Allow devices to settle down */
502 udelay(1000); /* Another delay to allow devices to settle */
507 return device_check(dev);
510 static inline int ppa_send_command(struct scsi_cmnd *cmd)
512 ppa_struct *dev = ppa_dev(cmd->device->host);
515 w_ctr(dev->base, 0x0c);
517 for (k = 0; k < cmd->cmd_len; k++)
518 if (!ppa_out(dev, &cmd->cmnd[k], 1))
524 * The bulk flag enables some optimisations in the data transfer loops,
525 * it should be true for any command that transfers data in integral
526 * numbers of sectors.
528 * The driver appears to remain stable if we speed up the parallel port
529 * i/o in this function, but not elsewhere.
531 static int ppa_completion(struct scsi_cmnd *cmd)
536 * 1 Finished data transfer
538 ppa_struct *dev = ppa_dev(cmd->device->host);
539 unsigned short ppb = dev->base;
540 unsigned long start_jiffies = jiffies;
543 int fast, bulk, status;
546 bulk = ((v == READ_6) ||
547 (v == READ_10) || (v == WRITE_6) || (v == WRITE_10));
550 * We only get here if the drive is ready to comunicate,
551 * hence no need for a full ppa_wait.
553 r = (r_str(ppb) & 0xf0);
555 while (r != (unsigned char) 0xf0) {
557 * If we have been running for more than a full timer tick
560 if (time_after(jiffies, start_jiffies + 1))
563 if ((cmd->SCp.this_residual <= 0)) {
564 ppa_fail(dev, DID_ERROR);
565 return -1; /* ERROR_RETURN */
568 /* On some hardware we have SCSI disconnected (6th bit low)
569 * for about 100usecs. It is too expensive to wait a
570 * tick on every loop so we busy wait for no more than
571 * 500usecs to give the drive a chance first. We do not
572 * change things for "normal" hardware since generally
573 * the 6th bit is always high.
574 * This makes the CPU load higher on some hardware
575 * but otherwise we can not get more than 50K/secs
576 * on this problem hardware.
578 if ((r & 0xc0) != 0xc0) {
579 /* Wait for reconnection should be no more than
580 * jiffy/2 = 5ms = 5000 loops
582 unsigned long k = dev->recon_tmo;
583 for (; k && ((r = (r_str(ppb) & 0xf0)) & 0xc0) != 0xc0;
591 /* determine if we should use burst I/O */
592 fast = (bulk && (cmd->SCp.this_residual >= PPA_BURST_SIZE))
593 ? PPA_BURST_SIZE : 1;
595 if (r == (unsigned char) 0xc0)
596 status = ppa_out(dev, cmd->SCp.ptr, fast);
598 status = ppa_in(dev, cmd->SCp.ptr, fast);
600 cmd->SCp.ptr += fast;
601 cmd->SCp.this_residual -= fast;
604 ppa_fail(dev, DID_BUS_BUSY);
605 return -1; /* ERROR_RETURN */
607 if (cmd->SCp.buffer && !cmd->SCp.this_residual) {
608 /* if scatter/gather, advance to the next segment */
609 if (cmd->SCp.buffers_residual--) {
611 cmd->SCp.this_residual =
612 cmd->SCp.buffer->length;
614 page_address(cmd->SCp.buffer->page) +
615 cmd->SCp.buffer->offset;
618 /* Now check to see if the drive is ready to comunicate */
619 r = (r_str(ppb) & 0xf0);
620 /* If not, drop back down to the scheduler and wait a timer tick */
624 return 1; /* FINISH_RETURN */
628 * Since the PPA itself doesn't generate interrupts, we use
629 * the scheduler's task queue to generate a stream of call-backs and
630 * complete the request when the drive is ready.
632 static void ppa_interrupt(void *data)
634 ppa_struct *dev = (ppa_struct *) data;
635 struct scsi_cmnd *cmd = dev->cur_cmd;
638 printk("PPA: bug in ppa_interrupt\n");
641 if (ppa_engine(dev, cmd)) {
642 dev->ppa_tq.data = (void *) dev;
643 schedule_delayed_work(&dev->ppa_tq, 1);
646 /* Command must of completed hence it is safe to let go... */
648 switch ((cmd->result >> 16) & 0xff) {
652 printk("ppa: no device at SCSI ID %i\n", cmd->device->target);
655 printk("ppa: BUS BUSY - EPP timeout detected\n");
658 printk("ppa: unknown timeout\n");
661 printk("ppa: told to abort\n");
664 printk("ppa: parity error (???)\n");
667 printk("ppa: internal driver error\n");
670 printk("ppa: told to reset device\n");
673 printk("ppa: bad interrupt (???)\n");
676 printk("ppa: bad return code (%02x)\n",
677 (cmd->result >> 16) & 0xff);
681 if (cmd->SCp.phase > 1)
691 static int ppa_engine(ppa_struct *dev, struct scsi_cmnd *cmd)
693 unsigned short ppb = dev->base;
694 unsigned char l = 0, h = 0;
697 /* First check for any errors that may of occurred
698 * Here we check for internal errors
703 switch (cmd->SCp.phase) {
704 case 0: /* Phase 0 - Waiting for parport */
705 if (time_after(jiffies, dev->jstart + HZ)) {
707 * We waited more than a second
708 * for parport to call us
710 ppa_fail(dev, DID_BUS_BUSY);
713 return 1; /* wait until ppa_wakeup claims parport */
714 case 1: /* Phase 1 - Connected */
715 { /* Perform a sanity check for cable unplugged */
716 int retv = 2; /* Failed */
718 ppa_connect(dev, CONNECT_EPP_MAYBE);
721 if ((r_str(ppb) & 0x08) == 0x08)
725 if ((r_str(ppb) & 0x08) == 0x00)
729 if ((jiffies - dev->jstart) > (1 * HZ)) {
731 ("ppa: Parallel port cable is unplugged!!\n");
732 ppa_fail(dev, DID_BUS_BUSY);
736 return 1; /* Try again in a jiffy */
742 case 2: /* Phase 2 - We are now talking to the scsi bus */
743 if (!ppa_select(dev, cmd->device->id)) {
744 ppa_fail(dev, DID_NO_CONNECT);
749 case 3: /* Phase 3 - Ready to accept a command */
751 if (!(r_str(ppb) & 0x80))
754 if (!ppa_send_command(cmd))
758 case 4: /* Phase 4 - Setup scatter/gather buffers */
760 /* if many buffers are available, start filling the first */
762 (struct scatterlist *) cmd->request_buffer;
763 cmd->SCp.this_residual = cmd->SCp.buffer->length;
765 page_address(cmd->SCp.buffer->page) +
766 cmd->SCp.buffer->offset;
768 /* else fill the only available buffer */
769 cmd->SCp.buffer = NULL;
770 cmd->SCp.this_residual = cmd->request_bufflen;
771 cmd->SCp.ptr = cmd->request_buffer;
773 cmd->SCp.buffers_residual = cmd->use_sg - 1;
776 case 5: /* Phase 5 - Data transfer stage */
778 if (!(r_str(ppb) & 0x80))
781 retv = ppa_completion(cmd);
788 case 6: /* Phase 6 - Read status/message */
789 cmd->result = DID_OK << 16;
790 /* Check for data overrun */
791 if (ppa_wait(dev) != (unsigned char) 0xf0) {
792 ppa_fail(dev, DID_ERROR);
795 if (ppa_in(dev, &l, 1)) { /* read status byte */
796 /* Check for optional message byte */
797 if (ppa_wait(dev) == (unsigned char) 0xf0)
800 (DID_OK << 16) + (h << 8) + (l & STATUS_MASK);
802 return 0; /* Finished */
806 printk("ppa: Invalid scsi phase\n");
811 static int ppa_queuecommand(struct scsi_cmnd *cmd,
812 void (*done) (struct scsi_cmnd *))
814 ppa_struct *dev = ppa_dev(cmd->device->host);
817 printk("PPA: bug in ppa_queuecommand\n");
821 dev->jstart = jiffies;
823 cmd->scsi_done = done;
824 cmd->result = DID_ERROR << 16; /* default return code */
825 cmd->SCp.phase = 0; /* bus free */
827 dev->ppa_tq.data = dev;
828 schedule_work(&dev->ppa_tq);
836 * Apparently the disk->capacity attribute is off by 1 sector
837 * for all disk drives. We add the one here, but it should really
838 * be done in sd.c. Even if it gets fixed there, this will still
841 static int ppa_biosparam(struct scsi_device *sdev, struct block_device *dev,
842 sector_t capacity, int ip[])
846 ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
850 ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
857 static int ppa_abort(struct scsi_cmnd *cmd)
859 ppa_struct *dev = ppa_dev(cmd->device->host);
861 * There is no method for aborting commands since Iomega
862 * have tied the SCSI_MESSAGE line high in the interface
865 switch (cmd->SCp.phase) {
866 case 0: /* Do not have access to parport */
867 case 1: /* Have not connected to interface */
868 dev->cur_cmd = NULL; /* Forget the problem */
871 default: /* SCSI command sent, can not abort */
877 static void ppa_reset_pulse(unsigned int base)
885 static int ppa_reset(struct scsi_cmnd *cmd)
887 ppa_struct *dev = ppa_dev(cmd->device->host);
891 dev->cur_cmd = NULL; /* Forget the problem */
893 ppa_connect(dev, CONNECT_NORMAL);
894 ppa_reset_pulse(dev->base);
895 mdelay(1); /* device settle delay */
897 mdelay(1); /* device settle delay */
901 static int device_check(ppa_struct *dev)
903 /* This routine looks for a device and then attempts to use EPP
904 to send a command. If all goes as planned then EPP is available. */
906 static char cmd[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
907 int loop, old_mode, status, k, ppb = dev->base;
910 old_mode = dev->mode;
911 for (loop = 0; loop < 8; loop++) {
912 /* Attempt to use EPP for Test Unit Ready */
913 if ((ppb & 0x0007) == 0x0000)
914 dev->mode = PPA_EPP_32;
917 ppa_connect(dev, CONNECT_EPP_MAYBE);
918 /* Select SCSI device */
919 if (!ppa_select(dev, loop)) {
923 printk("ppa: Found device at ID %i, Attempting to use %s\n",
924 loop, PPA_MODE_STRING[dev->mode]);
926 /* Send SCSI command */
929 for (l = 0; (l < 6) && (status); l++)
930 status = ppa_out(dev, cmd, 1);
934 ppa_connect(dev, CONNECT_EPP_MAYBE);
942 if (dev->mode == PPA_EPP_32) {
943 dev->mode = old_mode;
949 k = 1000000; /* 1 Second */
954 } while (!(l & 0x80) && (k));
960 ppa_connect(dev, CONNECT_EPP_MAYBE);
961 ppa_reset_pulse(ppb);
965 if (dev->mode == PPA_EPP_32) {
966 dev->mode = old_mode;
972 printk("ppa: Communication established with ID %i using %s\n",
973 loop, PPA_MODE_STRING[dev->mode]);
974 ppa_connect(dev, CONNECT_EPP_MAYBE);
975 ppa_reset_pulse(ppb);
984 static struct scsi_host_template ppa_template = {
985 .module = THIS_MODULE,
987 .proc_info = ppa_proc_info,
988 .name = "Iomega VPI0 (ppa) interface",
989 .queuecommand = ppa_queuecommand,
990 .eh_abort_handler = ppa_abort,
991 .eh_bus_reset_handler = ppa_reset,
992 .eh_host_reset_handler = ppa_reset,
993 .bios_param = ppa_biosparam,
995 .sg_tablesize = SG_ALL,
997 .use_clustering = ENABLE_CLUSTERING,
1001 /***************************************************************************
1002 * Parallel port probing routines *
1003 ***************************************************************************/
1005 static LIST_HEAD(ppa_hosts);
1007 static int __ppa_attach(struct parport *pb)
1009 struct Scsi_Host *host;
1010 DECLARE_WAIT_QUEUE_HEAD(waiting);
1014 int modes, ppb, ppb_hi;
1017 dev = kmalloc(sizeof(ppa_struct), GFP_KERNEL);
1020 memset(dev, 0, sizeof(ppa_struct));
1022 dev->mode = PPA_AUTODETECT;
1023 dev->recon_tmo = PPA_RECON_TMO;
1024 init_waitqueue_head(&waiting);
1025 dev->dev = parport_register_device(pb, "ppa", NULL, ppa_wakeup,
1031 /* Claim the bus so it remembers what we do to the control
1032 * registers. [ CTR and ECP ]
1035 dev->waiting = &waiting;
1036 prepare_to_wait(&waiting, &wait, TASK_UNINTERRUPTIBLE);
1037 if (ppa_pb_claim(dev))
1038 schedule_timeout(3 * HZ);
1040 printk(KERN_ERR "ppa%d: failed to claim parport because "
1041 "a pardevice is owning the port for too long "
1042 "time!\n", pb->number);
1043 ppa_pb_dismiss(dev);
1044 dev->waiting = NULL;
1045 finish_wait(&waiting, &wait);
1048 dev->waiting = NULL;
1049 finish_wait(&waiting, &wait);
1050 ppb = dev->base = dev->dev->port->base;
1051 ppb_hi = dev->dev->port->base_hi;
1053 modes = dev->dev->port->modes;
1055 /* Mode detection works up the chain of speed
1056 * This avoids a nasty if-then-else-if-... tree
1058 dev->mode = PPA_NIBBLE;
1060 if (modes & PARPORT_MODE_TRISTATE)
1061 dev->mode = PPA_PS2;
1063 if (modes & PARPORT_MODE_ECP) {
1064 w_ecr(ppb_hi, 0x20);
1065 dev->mode = PPA_PS2;
1067 if ((modes & PARPORT_MODE_EPP) && (modes & PARPORT_MODE_ECP))
1068 w_ecr(ppb_hi, 0x80);
1070 /* Done configuration */
1072 err = ppa_init(dev);
1073 ppa_pb_release(dev);
1078 /* now the glue ... */
1079 if (dev->mode == PPA_NIBBLE || dev->mode == PPA_PS2)
1084 INIT_WORK(&dev->ppa_tq, ppa_interrupt, dev);
1087 host = scsi_host_alloc(&ppa_template, sizeof(ppa_struct *));
1090 host->io_port = pb->base;
1091 host->n_io_port = ports;
1092 host->dma_channel = -1;
1093 host->unique_id = pb->number;
1094 *(ppa_struct **)&host->hostdata = dev;
1096 list_add_tail(&dev->list, &ppa_hosts);
1097 err = scsi_add_host(host, NULL);
1100 scsi_scan_host(host);
1103 list_del_init(&dev->list);
1104 scsi_host_put(host);
1106 parport_unregister_device(dev->dev);
1112 static void ppa_attach(struct parport *pb)
1117 static void ppa_detach(struct parport *pb)
1120 list_for_each_entry(dev, &ppa_hosts, list) {
1121 if (dev->dev->port == pb) {
1122 list_del_init(&dev->list);
1123 scsi_remove_host(dev->host);
1124 scsi_host_put(dev->host);
1125 parport_unregister_device(dev->dev);
1132 static struct parport_driver ppa_driver = {
1134 .attach = ppa_attach,
1135 .detach = ppa_detach,
1138 static int __init ppa_driver_init(void)
1140 printk("ppa: Version %s\n", PPA_VERSION);
1141 return parport_register_driver(&ppa_driver);
1144 static void __exit ppa_driver_exit(void)
1146 parport_unregister_driver(&ppa_driver);
1149 module_init(ppa_driver_init);
1150 module_exit(ppa_driver_exit);
1151 MODULE_LICENSE("GPL");