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 struct scsi_pointer *ppa_scsi_pointer(struct scsi_cmnd *cmd)
50 return scsi_cmd_priv(cmd);
53 static inline ppa_struct *ppa_dev(struct Scsi_Host *host)
55 return *(ppa_struct **)&host->hostdata;
58 static DEFINE_SPINLOCK(arbitration_lock);
60 static void got_it(ppa_struct *dev)
62 dev->base = dev->dev->port->base;
64 ppa_scsi_pointer(dev->cur_cmd)->phase = 1;
66 wake_up(dev->waiting);
69 static void ppa_wakeup(void *ref)
71 ppa_struct *dev = (ppa_struct *) ref;
74 spin_lock_irqsave(&arbitration_lock, flags);
76 parport_claim(dev->dev);
80 spin_unlock_irqrestore(&arbitration_lock, flags);
84 static int ppa_pb_claim(ppa_struct *dev)
88 spin_lock_irqsave(&arbitration_lock, flags);
89 if (parport_claim(dev->dev) == 0) {
94 spin_unlock_irqrestore(&arbitration_lock, flags);
98 static void ppa_pb_dismiss(ppa_struct *dev)
102 spin_lock_irqsave(&arbitration_lock, flags);
103 wanted = dev->wanted;
105 spin_unlock_irqrestore(&arbitration_lock, flags);
107 parport_release(dev->dev);
110 static inline void ppa_pb_release(ppa_struct *dev)
112 parport_release(dev->dev);
116 * Start of Chipset kludges
119 /* This is to give the ppa driver a way to modify the timings (and other
120 * parameters) by writing to the /proc/scsi/ppa/0 file.
121 * Very simple method really... (To 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)
127 static inline int ppa_write_info(struct Scsi_Host *host, char *buffer, int length)
129 ppa_struct *dev = ppa_dev(host);
132 if ((length > 5) && (strncmp(buffer, "mode=", 5) == 0)) {
133 x = simple_strtoul(buffer + 5, NULL, 0);
137 if ((length > 10) && (strncmp(buffer, "recon_tmo=", 10) == 0)) {
138 x = simple_strtoul(buffer + 10, NULL, 0);
140 printk(KERN_INFO "ppa: recon_tmo set to %ld\n", x);
143 printk(KERN_WARNING "ppa /proc: invalid variable\n");
147 static int ppa_show_info(struct seq_file *m, struct Scsi_Host *host)
149 ppa_struct *dev = ppa_dev(host);
151 seq_printf(m, "Version : %s\n", PPA_VERSION);
152 seq_printf(m, "Parport : %s\n", dev->dev->port->name);
153 seq_printf(m, "Mode : %s\n", PPA_MODE_STRING[dev->mode]);
155 seq_printf(m, "recon_tmo : %lu\n", dev->recon_tmo);
160 static int device_check(ppa_struct *dev);
163 #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
164 y, __func__, __LINE__); ppa_fail_func(x,y);
165 static inline void ppa_fail_func(ppa_struct *dev, int error_code)
167 static inline void ppa_fail(ppa_struct *dev, int error_code)
170 /* If we fail a device then we trash status / message bytes */
172 dev->cur_cmd->result = error_code << 16;
178 * Wait for the high bit to be set.
180 * In principle, this could be tied to an interrupt, but the adapter
181 * doesn't appear to be designed to support interrupts. We spin on
182 * the 0x80 ready bit.
184 static unsigned char ppa_wait(ppa_struct *dev)
187 unsigned short ppb = dev->base;
191 /* Wait for bit 6 and 7 - PJC */
192 for (r = r_str(ppb); ((r & 0xc0) != 0xc0) && (k); k--) {
198 * return some status information.
199 * Semantics: 0xc0 = ZIP wants more data
200 * 0xd0 = ZIP wants to send more data
201 * 0xe0 = ZIP is expecting SCSI command data
202 * 0xf0 = end of transfer, ZIP is sending status
207 /* Counter expired - Time out occurred */
208 ppa_fail(dev, DID_TIME_OUT);
209 printk(KERN_WARNING "ppa timeout in ppa_wait\n");
210 return 0; /* command timed out */
214 * Clear EPP Timeout Bit
216 static inline void epp_reset(unsigned short ppb)
222 w_str(ppb, i & 0xfe);
226 * Wait for empty ECP fifo (if we are in ECP fifo mode only)
228 static inline void ecp_sync(ppa_struct *dev)
230 int i, ppb_hi = dev->dev->port->base_hi;
235 if ((r_ecr(ppb_hi) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
236 for (i = 0; i < 100; i++) {
237 if (r_ecr(ppb_hi) & 0x01)
241 printk(KERN_WARNING "ppa: ECP sync failed as data still present in FIFO.\n");
245 static int ppa_byte_out(unsigned short base, const char *buffer, int len)
249 for (i = len; i; i--) {
250 w_dtr(base, *buffer++);
254 return 1; /* All went well - we hope! */
257 static int ppa_byte_in(unsigned short base, char *buffer, int len)
261 for (i = len; i; i--) {
262 *buffer++ = r_dtr(base);
266 return 1; /* All went well - we hope! */
269 static int ppa_nibble_in(unsigned short base, char *buffer, int len)
275 h = r_str(base) & 0xf0;
277 *buffer++ = h | ((r_str(base) & 0xf0) >> 4);
279 return 1; /* All went well - we hope! */
282 static int ppa_out(ppa_struct *dev, char *buffer, int len)
285 unsigned short ppb = dev->base;
289 if ((r & 0x50) != 0x40) {
290 ppa_fail(dev, DID_ERROR);
296 /* 8 bit output, with a loop */
297 r = ppa_byte_out(ppb, buffer, len);
305 #ifdef CONFIG_SCSI_IZIP_EPP16
306 if (!(((long) buffer | len) & 0x01))
307 outsw(ppb + 4, buffer, len >> 1);
309 if (!(((long) buffer | len) & 0x03))
310 outsl(ppb + 4, buffer, len >> 2);
313 outsb(ppb + 4, buffer, len);
315 r = !(r_str(ppb) & 0x01);
321 printk(KERN_ERR "PPA: bug in ppa_out()\n");
327 static int ppa_in(ppa_struct *dev, char *buffer, int len)
330 unsigned short ppb = dev->base;
334 if ((r & 0x50) != 0x50) {
335 ppa_fail(dev, DID_ERROR);
340 /* 4 bit input, with a loop */
341 r = ppa_nibble_in(ppb, buffer, len);
346 /* 8 bit input, with a loop */
348 r = ppa_byte_in(ppb, buffer, len);
358 #ifdef CONFIG_SCSI_IZIP_EPP16
359 if (!(((long) buffer | len) & 0x01))
360 insw(ppb + 4, buffer, len >> 1);
362 if (!(((long) buffer | len) & 0x03))
363 insl(ppb + 4, buffer, len >> 2);
366 insb(ppb + 4, buffer, len);
368 r = !(r_str(ppb) & 0x01);
374 printk(KERN_ERR "PPA: bug in ppa_ins()\n");
381 /* end of ppa_io.h */
382 static inline void ppa_d_pulse(unsigned short ppb, unsigned char b)
392 static void ppa_disconnect(ppa_struct *dev)
394 unsigned short ppb = dev->base;
397 ppa_d_pulse(ppb, 0x3c);
398 ppa_d_pulse(ppb, 0x20);
399 ppa_d_pulse(ppb, 0xf);
402 static inline void ppa_c_pulse(unsigned short ppb, unsigned char b)
411 static inline void ppa_connect(ppa_struct *dev, int flag)
413 unsigned short ppb = dev->base;
416 ppa_c_pulse(ppb, 0x3c);
417 ppa_c_pulse(ppb, 0x20);
418 if ((flag == CONNECT_EPP_MAYBE) && IN_EPP_MODE(dev->mode))
419 ppa_c_pulse(ppb, 0xcf);
421 ppa_c_pulse(ppb, 0x8f);
424 static int ppa_select(ppa_struct *dev, int target)
427 unsigned short ppb = dev->base;
430 * Bit 6 (0x40) is the device selected bit.
431 * First we must wait till the current device goes off line...
437 } while ((r_str(ppb) & 0x40) && (k));
441 w_dtr(ppb, (1 << target));
444 w_dtr(ppb, 0x80); /* This is NOT the initator */
452 while (!(r_str(ppb) & 0x40) && (k));
460 * This is based on a trace of what the Iomega DOS 'guest' driver does.
461 * I've tried several different kinds of parallel ports with guest and
462 * coded this to react in the same ways that it does.
464 * The return value from this function is just a hint about where the
465 * handshaking failed.
468 static int ppa_init(ppa_struct *dev)
471 unsigned short ppb = dev->base;
474 ppa_connect(dev, CONNECT_NORMAL);
476 retv = 2; /* Failed */
479 if ((r_str(ppb) & 0x08) == 0x08)
483 if ((r_str(ppb) & 0x08) == 0x00)
487 ppa_reset_pulse(ppb);
488 udelay(1000); /* Allow devices to settle down */
490 udelay(1000); /* Another delay to allow devices to settle */
495 return device_check(dev);
498 static inline int ppa_send_command(struct scsi_cmnd *cmd)
500 ppa_struct *dev = ppa_dev(cmd->device->host);
503 w_ctr(dev->base, 0x0c);
505 for (k = 0; k < cmd->cmd_len; k++)
506 if (!ppa_out(dev, &cmd->cmnd[k], 1))
512 * The bulk flag enables some optimisations in the data transfer loops,
513 * it should be true for any command that transfers data in integral
514 * numbers of sectors.
516 * The driver appears to remain stable if we speed up the parallel port
517 * i/o in this function, but not elsewhere.
519 static int ppa_completion(struct scsi_cmnd *const cmd)
524 * 1 Finished data transfer
526 struct scsi_pointer *scsi_pointer = ppa_scsi_pointer(cmd);
527 ppa_struct *dev = ppa_dev(cmd->device->host);
528 unsigned short ppb = dev->base;
529 unsigned long start_jiffies = jiffies;
532 int fast, bulk, status;
535 bulk = ((v == READ_6) ||
536 (v == READ_10) || (v == WRITE_6) || (v == WRITE_10));
539 * We only get here if the drive is ready to comunicate,
540 * hence no need for a full ppa_wait.
542 r = (r_str(ppb) & 0xf0);
544 while (r != (unsigned char) 0xf0) {
546 * If we have been running for more than a full timer tick
549 if (time_after(jiffies, start_jiffies + 1))
552 if (scsi_pointer->this_residual <= 0) {
553 ppa_fail(dev, DID_ERROR);
554 return -1; /* ERROR_RETURN */
557 /* On some hardware we have SCSI disconnected (6th bit low)
558 * for about 100usecs. It is too expensive to wait a
559 * tick on every loop so we busy wait for no more than
560 * 500usecs to give the drive a chance first. We do not
561 * change things for "normal" hardware since generally
562 * the 6th bit is always high.
563 * This makes the CPU load higher on some hardware
564 * but otherwise we can not get more than 50K/secs
565 * on this problem hardware.
567 if ((r & 0xc0) != 0xc0) {
568 /* Wait for reconnection should be no more than
569 * jiffy/2 = 5ms = 5000 loops
571 unsigned long k = dev->recon_tmo;
572 for (; k && ((r = (r_str(ppb) & 0xf0)) & 0xc0) != 0xc0;
580 /* determine if we should use burst I/O */
581 fast = bulk && scsi_pointer->this_residual >= PPA_BURST_SIZE ?
584 if (r == (unsigned char) 0xc0)
585 status = ppa_out(dev, scsi_pointer->ptr, fast);
587 status = ppa_in(dev, scsi_pointer->ptr, fast);
589 scsi_pointer->ptr += fast;
590 scsi_pointer->this_residual -= fast;
593 ppa_fail(dev, DID_BUS_BUSY);
594 return -1; /* ERROR_RETURN */
596 if (scsi_pointer->buffer && !scsi_pointer->this_residual) {
597 /* if scatter/gather, advance to the next segment */
598 if (scsi_pointer->buffers_residual--) {
599 scsi_pointer->buffer =
600 sg_next(scsi_pointer->buffer);
601 scsi_pointer->this_residual =
602 scsi_pointer->buffer->length;
604 sg_virt(scsi_pointer->buffer);
607 /* Now check to see if the drive is ready to comunicate */
608 r = (r_str(ppb) & 0xf0);
609 /* If not, drop back down to the scheduler and wait a timer tick */
613 return 1; /* FINISH_RETURN */
617 * Since the PPA itself doesn't generate interrupts, we use
618 * the scheduler's task queue to generate a stream of call-backs and
619 * complete the request when the drive is ready.
621 static void ppa_interrupt(struct work_struct *work)
623 ppa_struct *dev = container_of(work, ppa_struct, ppa_tq.work);
624 struct scsi_cmnd *cmd = dev->cur_cmd;
627 printk(KERN_ERR "PPA: bug in ppa_interrupt\n");
630 if (ppa_engine(dev, cmd)) {
631 schedule_delayed_work(&dev->ppa_tq, 1);
634 /* Command must of completed hence it is safe to let go... */
636 switch ((cmd->result >> 16) & 0xff) {
640 printk(KERN_DEBUG "ppa: no device at SCSI ID %i\n", cmd->device->target);
643 printk(KERN_DEBUG "ppa: BUS BUSY - EPP timeout detected\n");
646 printk(KERN_DEBUG "ppa: unknown timeout\n");
649 printk(KERN_DEBUG "ppa: told to abort\n");
652 printk(KERN_DEBUG "ppa: parity error (???)\n");
655 printk(KERN_DEBUG "ppa: internal driver error\n");
658 printk(KERN_DEBUG "ppa: told to reset device\n");
661 printk(KERN_WARNING "ppa: bad interrupt (???)\n");
664 printk(KERN_WARNING "ppa: bad return code (%02x)\n",
665 (cmd->result >> 16) & 0xff);
669 if (ppa_scsi_pointer(cmd)->phase > 1)
679 static int ppa_engine(ppa_struct *dev, struct scsi_cmnd *cmd)
681 struct scsi_pointer *scsi_pointer = ppa_scsi_pointer(cmd);
682 unsigned short ppb = dev->base;
683 unsigned char l = 0, h = 0;
686 /* First check for any errors that may of occurred
687 * Here we check for internal errors
692 switch (scsi_pointer->phase) {
693 case 0: /* Phase 0 - Waiting for parport */
694 if (time_after(jiffies, dev->jstart + HZ)) {
696 * We waited more than a second
697 * for parport to call us
699 ppa_fail(dev, DID_BUS_BUSY);
702 return 1; /* wait until ppa_wakeup claims parport */
703 case 1: /* Phase 1 - Connected */
704 { /* Perform a sanity check for cable unplugged */
705 int retv = 2; /* Failed */
707 ppa_connect(dev, CONNECT_EPP_MAYBE);
710 if ((r_str(ppb) & 0x08) == 0x08)
714 if ((r_str(ppb) & 0x08) == 0x00)
718 if (time_after(jiffies, dev->jstart + (1 * HZ))) {
719 printk(KERN_ERR "ppa: Parallel port cable is unplugged.\n");
720 ppa_fail(dev, DID_BUS_BUSY);
724 return 1; /* Try again in a jiffy */
727 scsi_pointer->phase++;
731 case 2: /* Phase 2 - We are now talking to the scsi bus */
732 if (!ppa_select(dev, scmd_id(cmd))) {
733 ppa_fail(dev, DID_NO_CONNECT);
736 scsi_pointer->phase++;
739 case 3: /* Phase 3 - Ready to accept a command */
741 if (!(r_str(ppb) & 0x80))
744 if (!ppa_send_command(cmd))
746 scsi_pointer->phase++;
749 case 4: /* Phase 4 - Setup scatter/gather buffers */
750 if (scsi_bufflen(cmd)) {
751 scsi_pointer->buffer = scsi_sglist(cmd);
752 scsi_pointer->this_residual =
753 scsi_pointer->buffer->length;
754 scsi_pointer->ptr = sg_virt(scsi_pointer->buffer);
756 scsi_pointer->buffer = NULL;
757 scsi_pointer->this_residual = 0;
758 scsi_pointer->ptr = NULL;
760 scsi_pointer->buffers_residual = scsi_sg_count(cmd) - 1;
761 scsi_pointer->phase++;
764 case 5: /* Phase 5 - Data transfer stage */
766 if (!(r_str(ppb) & 0x80))
769 retv = ppa_completion(cmd);
774 scsi_pointer->phase++;
777 case 6: /* Phase 6 - Read status/message */
778 cmd->result = DID_OK << 16;
779 /* Check for data overrun */
780 if (ppa_wait(dev) != (unsigned char) 0xf0) {
781 ppa_fail(dev, DID_ERROR);
784 if (ppa_in(dev, &l, 1)) { /* read status byte */
785 /* Check for optional message byte */
786 if (ppa_wait(dev) == (unsigned char) 0xf0)
789 (DID_OK << 16) + (h << 8) + (l & STATUS_MASK);
791 return 0; /* Finished */
794 printk(KERN_ERR "ppa: Invalid scsi phase\n");
799 static int ppa_queuecommand_lck(struct scsi_cmnd *cmd)
801 ppa_struct *dev = ppa_dev(cmd->device->host);
804 printk(KERN_ERR "PPA: bug in ppa_queuecommand\n");
808 dev->jstart = jiffies;
810 cmd->result = DID_ERROR << 16; /* default return code */
811 ppa_scsi_pointer(cmd)->phase = 0; /* bus free */
813 schedule_delayed_work(&dev->ppa_tq, 0);
820 static DEF_SCSI_QCMD(ppa_queuecommand)
823 * Apparently the disk->capacity attribute is off by 1 sector
824 * for all disk drives. We add the one here, but it should really
825 * be done in sd.c. Even if it gets fixed there, this will still
828 static int ppa_biosparam(struct scsi_device *sdev, struct block_device *dev,
829 sector_t capacity, int ip[])
833 ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
837 ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
844 static int ppa_abort(struct scsi_cmnd *cmd)
846 ppa_struct *dev = ppa_dev(cmd->device->host);
848 * There is no method for aborting commands since Iomega
849 * have tied the SCSI_MESSAGE line high in the interface
852 switch (ppa_scsi_pointer(cmd)->phase) {
853 case 0: /* Do not have access to parport */
854 case 1: /* Have not connected to interface */
855 dev->cur_cmd = NULL; /* Forget the problem */
857 default: /* SCSI command sent, can not abort */
862 static void ppa_reset_pulse(unsigned int base)
870 static int ppa_reset(struct scsi_cmnd *cmd)
872 ppa_struct *dev = ppa_dev(cmd->device->host);
874 if (ppa_scsi_pointer(cmd)->phase)
876 dev->cur_cmd = NULL; /* Forget the problem */
878 ppa_connect(dev, CONNECT_NORMAL);
879 ppa_reset_pulse(dev->base);
880 mdelay(1); /* device settle delay */
882 mdelay(1); /* device settle delay */
886 static int device_check(ppa_struct *dev)
888 /* This routine looks for a device and then attempts to use EPP
889 to send a command. If all goes as planned then EPP is available. */
891 static u8 cmd[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
892 int loop, old_mode, status, k, ppb = dev->base;
895 old_mode = dev->mode;
896 for (loop = 0; loop < 8; loop++) {
897 /* Attempt to use EPP for Test Unit Ready */
898 if ((ppb & 0x0007) == 0x0000)
899 dev->mode = PPA_EPP_32;
902 ppa_connect(dev, CONNECT_EPP_MAYBE);
903 /* Select SCSI device */
904 if (!ppa_select(dev, loop)) {
908 printk(KERN_INFO "ppa: Found device at ID %i, Attempting to use %s\n",
909 loop, PPA_MODE_STRING[dev->mode]);
911 /* Send SCSI command */
914 for (l = 0; (l < 6) && (status); l++)
915 status = ppa_out(dev, cmd, 1);
919 ppa_connect(dev, CONNECT_EPP_MAYBE);
927 if (dev->mode == PPA_EPP_32) {
928 dev->mode = old_mode;
934 k = 1000000; /* 1 Second */
939 } while (!(l & 0x80) && (k));
945 ppa_connect(dev, CONNECT_EPP_MAYBE);
946 ppa_reset_pulse(ppb);
950 if (dev->mode == PPA_EPP_32) {
951 dev->mode = old_mode;
957 printk(KERN_INFO "ppa: Communication established with ID %i using %s\n",
958 loop, PPA_MODE_STRING[dev->mode]);
959 ppa_connect(dev, CONNECT_EPP_MAYBE);
960 ppa_reset_pulse(ppb);
969 static int ppa_adjust_queue(struct scsi_device *device)
971 blk_queue_bounce_limit(device->request_queue, BLK_BOUNCE_HIGH);
975 static struct scsi_host_template ppa_template = {
976 .module = THIS_MODULE,
978 .show_info = ppa_show_info,
979 .write_info = ppa_write_info,
980 .name = "Iomega VPI0 (ppa) interface",
981 .queuecommand = ppa_queuecommand,
982 .eh_abort_handler = ppa_abort,
983 .eh_host_reset_handler = ppa_reset,
984 .bios_param = ppa_biosparam,
986 .sg_tablesize = SG_ALL,
988 .slave_alloc = ppa_adjust_queue,
989 .cmd_size = sizeof(struct scsi_pointer),
992 /***************************************************************************
993 * Parallel port probing routines *
994 ***************************************************************************/
996 static LIST_HEAD(ppa_hosts);
999 * Finds the first available device number that can be alloted to the
1000 * new ppa device and returns the address of the previous node so that
1001 * we can add to the tail and have a list in the ascending order.
1004 static inline ppa_struct *find_parent(void)
1006 ppa_struct *dev, *par = NULL;
1007 unsigned int cnt = 0;
1009 if (list_empty(&ppa_hosts))
1012 list_for_each_entry(dev, &ppa_hosts, list) {
1013 if (dev->dev_no != cnt)
1022 static int __ppa_attach(struct parport *pb)
1024 struct Scsi_Host *host;
1025 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waiting);
1027 ppa_struct *dev, *temp;
1029 int modes, ppb, ppb_hi;
1031 struct pardev_cb ppa_cb;
1033 dev = kzalloc(sizeof(ppa_struct), GFP_KERNEL);
1037 dev->mode = PPA_AUTODETECT;
1038 dev->recon_tmo = PPA_RECON_TMO;
1039 init_waitqueue_head(&waiting);
1040 temp = find_parent();
1042 dev->dev_no = temp->dev_no + 1;
1044 memset(&ppa_cb, 0, sizeof(ppa_cb));
1045 ppa_cb.private = dev;
1046 ppa_cb.wakeup = ppa_wakeup;
1048 dev->dev = parport_register_dev_model(pb, "ppa", &ppa_cb, dev->dev_no);
1053 /* Claim the bus so it remembers what we do to the control
1054 * registers. [ CTR and ECP ]
1057 dev->waiting = &waiting;
1058 prepare_to_wait(&waiting, &wait, TASK_UNINTERRUPTIBLE);
1059 if (ppa_pb_claim(dev))
1060 schedule_timeout(3 * HZ);
1062 printk(KERN_ERR "ppa%d: failed to claim parport because "
1063 "a pardevice is owning the port for too long "
1064 "time!\n", pb->number);
1065 ppa_pb_dismiss(dev);
1066 dev->waiting = NULL;
1067 finish_wait(&waiting, &wait);
1070 dev->waiting = NULL;
1071 finish_wait(&waiting, &wait);
1072 ppb = dev->base = dev->dev->port->base;
1073 ppb_hi = dev->dev->port->base_hi;
1075 modes = dev->dev->port->modes;
1077 /* Mode detection works up the chain of speed
1078 * This avoids a nasty if-then-else-if-... tree
1080 dev->mode = PPA_NIBBLE;
1082 if (modes & PARPORT_MODE_TRISTATE)
1083 dev->mode = PPA_PS2;
1085 if (modes & PARPORT_MODE_ECP) {
1086 w_ecr(ppb_hi, 0x20);
1087 dev->mode = PPA_PS2;
1089 if ((modes & PARPORT_MODE_EPP) && (modes & PARPORT_MODE_ECP))
1090 w_ecr(ppb_hi, 0x80);
1092 /* Done configuration */
1094 err = ppa_init(dev);
1095 ppa_pb_release(dev);
1100 /* now the glue ... */
1101 if (dev->mode == PPA_NIBBLE || dev->mode == PPA_PS2)
1106 INIT_DELAYED_WORK(&dev->ppa_tq, ppa_interrupt);
1109 host = scsi_host_alloc(&ppa_template, sizeof(ppa_struct *));
1112 host->io_port = pb->base;
1113 host->n_io_port = ports;
1114 host->dma_channel = -1;
1115 host->unique_id = pb->number;
1116 *(ppa_struct **)&host->hostdata = dev;
1118 list_add_tail(&dev->list, &ppa_hosts);
1119 err = scsi_add_host(host, NULL);
1122 scsi_scan_host(host);
1125 list_del_init(&dev->list);
1126 scsi_host_put(host);
1128 parport_unregister_device(dev->dev);
1134 static void ppa_attach(struct parport *pb)
1139 static void ppa_detach(struct parport *pb)
1142 list_for_each_entry(dev, &ppa_hosts, list) {
1143 if (dev->dev->port == pb) {
1144 list_del_init(&dev->list);
1145 scsi_remove_host(dev->host);
1146 scsi_host_put(dev->host);
1147 parport_unregister_device(dev->dev);
1154 static struct parport_driver ppa_driver = {
1156 .match_port = ppa_attach,
1157 .detach = ppa_detach,
1160 module_parport_driver(ppa_driver);
1162 MODULE_LICENSE("GPL");