^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* ppa.c -- low level driver for the IOMEGA PPA3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * parallel port SCSI host adapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * (The PPA3 is the embedded controller in the ZIP drive.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * (c) 1995,1996 Grant R. Guenther, grant@torque.net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * under the terms of the GNU General Public License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/parport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <scsi/scsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <scsi/scsi_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static void ppa_reset_pulse(unsigned int base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) typedef struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct pardevice *dev; /* Parport device entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) int base; /* Actual port address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) int mode; /* Transfer mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct scsi_cmnd *cur_cmd; /* Current queued command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct delayed_work ppa_tq; /* Polling interrupt stuff */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned long jstart; /* Jiffies at start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned long recon_tmo; /* How many usecs to wait for reconnection (6th bit) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unsigned int failed:1; /* Failure flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) unsigned wanted:1; /* Parport sharing busy flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned int dev_no; /* Device number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) wait_queue_head_t *waiting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) } ppa_struct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include "ppa.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static inline ppa_struct *ppa_dev(struct Scsi_Host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return *(ppa_struct **)&host->hostdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static DEFINE_SPINLOCK(arbitration_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static void got_it(ppa_struct *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) dev->base = dev->dev->port->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (dev->cur_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) dev->cur_cmd->SCp.phase = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) wake_up(dev->waiting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static void ppa_wakeup(void *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ppa_struct *dev = (ppa_struct *) ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) spin_lock_irqsave(&arbitration_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (dev->wanted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) parport_claim(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) got_it(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) dev->wanted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) spin_unlock_irqrestore(&arbitration_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static int ppa_pb_claim(ppa_struct *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) int res = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) spin_lock_irqsave(&arbitration_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (parport_claim(dev->dev) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) got_it(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) dev->wanted = res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) spin_unlock_irqrestore(&arbitration_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static void ppa_pb_dismiss(ppa_struct *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int wanted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) spin_lock_irqsave(&arbitration_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) wanted = dev->wanted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) dev->wanted = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) spin_unlock_irqrestore(&arbitration_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (!wanted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) parport_release(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static inline void ppa_pb_release(ppa_struct *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) parport_release(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * Start of Chipset kludges
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /* This is to give the ppa driver a way to modify the timings (and other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * parameters) by writing to the /proc/scsi/ppa/0 file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Very simple method really... (To simple, no error checking :( )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * Reason: Kernel hackers HATE having to unload and reload modules for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * testing...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * Also gives a method to use a script to obtain optimum timings (TODO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static inline int ppa_write_info(struct Scsi_Host *host, char *buffer, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) ppa_struct *dev = ppa_dev(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) unsigned long x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if ((length > 5) && (strncmp(buffer, "mode=", 5) == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) x = simple_strtoul(buffer + 5, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) dev->mode = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if ((length > 10) && (strncmp(buffer, "recon_tmo=", 10) == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) x = simple_strtoul(buffer + 10, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) dev->recon_tmo = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) printk(KERN_INFO "ppa: recon_tmo set to %ld\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) printk(KERN_WARNING "ppa /proc: invalid variable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int ppa_show_info(struct seq_file *m, struct Scsi_Host *host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) ppa_struct *dev = ppa_dev(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) seq_printf(m, "Version : %s\n", PPA_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) seq_printf(m, "Parport : %s\n", dev->dev->port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) seq_printf(m, "Mode : %s\n", PPA_MODE_STRING[dev->mode]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #if PPA_DEBUG > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) seq_printf(m, "recon_tmo : %lu\n", dev->recon_tmo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static int device_check(ppa_struct *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #if PPA_DEBUG > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) y, __func__, __LINE__); ppa_fail_func(x,y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static inline void ppa_fail_func(ppa_struct *dev, int error_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static inline void ppa_fail(ppa_struct *dev, int error_code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* If we fail a device then we trash status / message bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (dev->cur_cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) dev->cur_cmd->result = error_code << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) dev->failed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * Wait for the high bit to be set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * In principle, this could be tied to an interrupt, but the adapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * doesn't appear to be designed to support interrupts. We spin on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * the 0x80 ready bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static unsigned char ppa_wait(ppa_struct *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) unsigned short ppb = dev->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) unsigned char r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) k = PPA_SPIN_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* Wait for bit 6 and 7 - PJC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) for (r = r_str(ppb); ((r & 0xc0) != 0xc0) && (k); k--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) r = r_str(ppb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * return some status information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * Semantics: 0xc0 = ZIP wants more data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * 0xd0 = ZIP wants to send more data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * 0xe0 = ZIP is expecting SCSI command data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * 0xf0 = end of transfer, ZIP is sending status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return (r & 0xf0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Counter expired - Time out occurred */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ppa_fail(dev, DID_TIME_OUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) printk(KERN_WARNING "ppa timeout in ppa_wait\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return 0; /* command timed out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * Clear EPP Timeout Bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static inline void epp_reset(unsigned short ppb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) i = r_str(ppb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) w_str(ppb, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) w_str(ppb, i & 0xfe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * Wait for empty ECP fifo (if we are in ECP fifo mode only)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static inline void ecp_sync(ppa_struct *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int i, ppb_hi = dev->dev->port->base_hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (ppb_hi == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if ((r_ecr(ppb_hi) & 0xe0) == 0x60) { /* mode 011 == ECP fifo mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) for (i = 0; i < 100; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (r_ecr(ppb_hi) & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) udelay(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) printk(KERN_WARNING "ppa: ECP sync failed as data still present in FIFO.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static int ppa_byte_out(unsigned short base, const char *buffer, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) for (i = len; i; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) w_dtr(base, *buffer++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) w_ctr(base, 0xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) w_ctr(base, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return 1; /* All went well - we hope! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) static int ppa_byte_in(unsigned short base, char *buffer, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) for (i = len; i; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) *buffer++ = r_dtr(base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) w_ctr(base, 0x27);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) w_ctr(base, 0x25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return 1; /* All went well - we hope! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static int ppa_nibble_in(unsigned short base, char *buffer, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) for (; len; len--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) unsigned char h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) w_ctr(base, 0x4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) h = r_str(base) & 0xf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) w_ctr(base, 0x6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) *buffer++ = h | ((r_str(base) & 0xf0) >> 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) return 1; /* All went well - we hope! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static int ppa_out(ppa_struct *dev, char *buffer, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) unsigned short ppb = dev->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) r = ppa_wait(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if ((r & 0x50) != 0x40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) ppa_fail(dev, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) switch (dev->mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) case PPA_NIBBLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) case PPA_PS2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* 8 bit output, with a loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) r = ppa_byte_out(ppb, buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) case PPA_EPP_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) case PPA_EPP_16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) case PPA_EPP_8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) epp_reset(ppb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) w_ctr(ppb, 0x4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #ifdef CONFIG_SCSI_IZIP_EPP16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (!(((long) buffer | len) & 0x01))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) outsw(ppb + 4, buffer, len >> 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (!(((long) buffer | len) & 0x03))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) outsl(ppb + 4, buffer, len >> 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) outsb(ppb + 4, buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) r = !(r_str(ppb) & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) ecp_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) printk(KERN_ERR "PPA: bug in ppa_out()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) static int ppa_in(ppa_struct *dev, char *buffer, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) unsigned short ppb = dev->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) r = ppa_wait(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if ((r & 0x50) != 0x50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) ppa_fail(dev, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) switch (dev->mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) case PPA_NIBBLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* 4 bit input, with a loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) r = ppa_nibble_in(ppb, buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) case PPA_PS2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /* 8 bit input, with a loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) w_ctr(ppb, 0x25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) r = ppa_byte_in(ppb, buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) w_ctr(ppb, 0x4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) case PPA_EPP_32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) case PPA_EPP_16:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) case PPA_EPP_8:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) epp_reset(ppb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) w_ctr(ppb, 0x24);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) #ifdef CONFIG_SCSI_IZIP_EPP16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (!(((long) buffer | len) & 0x01))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) insw(ppb + 4, buffer, len >> 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (!(((long) buffer | len) & 0x03))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) insl(ppb + 4, buffer, len >> 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) insb(ppb + 4, buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) w_ctr(ppb, 0x2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) r = !(r_str(ppb) & 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) w_ctr(ppb, 0x2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) ecp_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) printk(KERN_ERR "PPA: bug in ppa_ins()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /* end of ppa_io.h */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static inline void ppa_d_pulse(unsigned short ppb, unsigned char b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) w_dtr(ppb, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) w_ctr(ppb, 0xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) w_ctr(ppb, 0x4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static void ppa_disconnect(ppa_struct *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) unsigned short ppb = dev->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) ppa_d_pulse(ppb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) ppa_d_pulse(ppb, 0x3c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) ppa_d_pulse(ppb, 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) ppa_d_pulse(ppb, 0xf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static inline void ppa_c_pulse(unsigned short ppb, unsigned char b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) w_dtr(ppb, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) w_ctr(ppb, 0x4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) w_ctr(ppb, 0x6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) w_ctr(ppb, 0x4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static inline void ppa_connect(ppa_struct *dev, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) unsigned short ppb = dev->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) ppa_c_pulse(ppb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) ppa_c_pulse(ppb, 0x3c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) ppa_c_pulse(ppb, 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if ((flag == CONNECT_EPP_MAYBE) && IN_EPP_MODE(dev->mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) ppa_c_pulse(ppb, 0xcf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) ppa_c_pulse(ppb, 0x8f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) static int ppa_select(ppa_struct *dev, int target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) int k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) unsigned short ppb = dev->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * Bit 6 (0x40) is the device selected bit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * First we must wait till the current device goes off line...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) k = PPA_SELECT_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) k--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) } while ((r_str(ppb) & 0x40) && (k));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (!k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) w_dtr(ppb, (1 << target));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) w_ctr(ppb, 0xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) w_dtr(ppb, 0x80); /* This is NOT the initator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) w_ctr(ppb, 0x8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) k = PPA_SELECT_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) k--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) while (!(r_str(ppb) & 0x40) && (k));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (!k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * This is based on a trace of what the Iomega DOS 'guest' driver does.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * I've tried several different kinds of parallel ports with guest and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * coded this to react in the same ways that it does.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * The return value from this function is just a hint about where the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * handshaking failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static int ppa_init(ppa_struct *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) int retv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) unsigned short ppb = dev->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) ppa_connect(dev, CONNECT_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) retv = 2; /* Failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) w_ctr(ppb, 0xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if ((r_str(ppb) & 0x08) == 0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) retv--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if ((r_str(ppb) & 0x08) == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) retv--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (!retv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) ppa_reset_pulse(ppb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) udelay(1000); /* Allow devices to settle down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) udelay(1000); /* Another delay to allow devices to settle */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (retv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return device_check(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static inline int ppa_send_command(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) ppa_struct *dev = ppa_dev(cmd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) int k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) w_ctr(dev->base, 0x0c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) for (k = 0; k < cmd->cmd_len; k++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (!ppa_out(dev, &cmd->cmnd[k], 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * The bulk flag enables some optimisations in the data transfer loops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * it should be true for any command that transfers data in integral
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * numbers of sectors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * The driver appears to remain stable if we speed up the parallel port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) * i/o in this function, but not elsewhere.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static int ppa_completion(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) /* Return codes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) * -1 Error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) * 0 Told to schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) * 1 Finished data transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ppa_struct *dev = ppa_dev(cmd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) unsigned short ppb = dev->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) unsigned long start_jiffies = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) unsigned char r, v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) int fast, bulk, status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) v = cmd->cmnd[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) bulk = ((v == READ_6) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) (v == READ_10) || (v == WRITE_6) || (v == WRITE_10));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * We only get here if the drive is ready to comunicate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * hence no need for a full ppa_wait.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) r = (r_str(ppb) & 0xf0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) while (r != (unsigned char) 0xf0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * If we have been running for more than a full timer tick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) * then take a rest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (time_after(jiffies, start_jiffies + 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if ((cmd->SCp.this_residual <= 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) ppa_fail(dev, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return -1; /* ERROR_RETURN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /* On some hardware we have SCSI disconnected (6th bit low)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * for about 100usecs. It is too expensive to wait a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * tick on every loop so we busy wait for no more than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * 500usecs to give the drive a chance first. We do not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * change things for "normal" hardware since generally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * the 6th bit is always high.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) * This makes the CPU load higher on some hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * but otherwise we can not get more than 50K/secs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) * on this problem hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) if ((r & 0xc0) != 0xc0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) /* Wait for reconnection should be no more than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) * jiffy/2 = 5ms = 5000 loops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) unsigned long k = dev->recon_tmo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) for (; k && ((r = (r_str(ppb) & 0xf0)) & 0xc0) != 0xc0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) k--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (!k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /* determine if we should use burst I/O */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) fast = (bulk && (cmd->SCp.this_residual >= PPA_BURST_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) ? PPA_BURST_SIZE : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (r == (unsigned char) 0xc0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) status = ppa_out(dev, cmd->SCp.ptr, fast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) status = ppa_in(dev, cmd->SCp.ptr, fast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) cmd->SCp.ptr += fast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) cmd->SCp.this_residual -= fast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (!status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) ppa_fail(dev, DID_BUS_BUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return -1; /* ERROR_RETURN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) if (cmd->SCp.buffer && !cmd->SCp.this_residual) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /* if scatter/gather, advance to the next segment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (cmd->SCp.buffers_residual--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) cmd->SCp.buffer = sg_next(cmd->SCp.buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) cmd->SCp.this_residual =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) cmd->SCp.buffer->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /* Now check to see if the drive is ready to comunicate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) r = (r_str(ppb) & 0xf0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) /* If not, drop back down to the scheduler and wait a timer tick */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) if (!(r & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) return 1; /* FINISH_RETURN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * Since the PPA itself doesn't generate interrupts, we use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * the scheduler's task queue to generate a stream of call-backs and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) * complete the request when the drive is ready.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) static void ppa_interrupt(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) ppa_struct *dev = container_of(work, ppa_struct, ppa_tq.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) struct scsi_cmnd *cmd = dev->cur_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (!cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) printk(KERN_ERR "PPA: bug in ppa_interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) if (ppa_engine(dev, cmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) schedule_delayed_work(&dev->ppa_tq, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) /* Command must of completed hence it is safe to let go... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) #if PPA_DEBUG > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) switch ((cmd->result >> 16) & 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) case DID_OK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) case DID_NO_CONNECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) printk(KERN_DEBUG "ppa: no device at SCSI ID %i\n", cmd->device->target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) case DID_BUS_BUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) printk(KERN_DEBUG "ppa: BUS BUSY - EPP timeout detected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) case DID_TIME_OUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) printk(KERN_DEBUG "ppa: unknown timeout\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) case DID_ABORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) printk(KERN_DEBUG "ppa: told to abort\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) case DID_PARITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) printk(KERN_DEBUG "ppa: parity error (???)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) case DID_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) printk(KERN_DEBUG "ppa: internal driver error\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) case DID_RESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) printk(KERN_DEBUG "ppa: told to reset device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) case DID_BAD_INTR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) printk(KERN_WARNING "ppa: bad interrupt (???)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) printk(KERN_WARNING "ppa: bad return code (%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) (cmd->result >> 16) & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if (cmd->SCp.phase > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) ppa_pb_dismiss(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) dev->cur_cmd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) cmd->scsi_done(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) static int ppa_engine(ppa_struct *dev, struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) unsigned short ppb = dev->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) unsigned char l = 0, h = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) int retv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) /* First check for any errors that may of occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * Here we check for internal errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (dev->failed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) switch (cmd->SCp.phase) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) case 0: /* Phase 0 - Waiting for parport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (time_after(jiffies, dev->jstart + HZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) * We waited more than a second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) * for parport to call us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) ppa_fail(dev, DID_BUS_BUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) return 1; /* wait until ppa_wakeup claims parport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) case 1: /* Phase 1 - Connected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) { /* Perform a sanity check for cable unplugged */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) int retv = 2; /* Failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) ppa_connect(dev, CONNECT_EPP_MAYBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) w_ctr(ppb, 0xe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) if ((r_str(ppb) & 0x08) == 0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) retv--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) w_ctr(ppb, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) if ((r_str(ppb) & 0x08) == 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) retv--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (retv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) if (time_after(jiffies, dev->jstart + (1 * HZ))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) printk(KERN_ERR "ppa: Parallel port cable is unplugged.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) ppa_fail(dev, DID_BUS_BUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return 1; /* Try again in a jiffy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) cmd->SCp.phase++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) case 2: /* Phase 2 - We are now talking to the scsi bus */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (!ppa_select(dev, scmd_id(cmd))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) ppa_fail(dev, DID_NO_CONNECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) cmd->SCp.phase++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) case 3: /* Phase 3 - Ready to accept a command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) w_ctr(ppb, 0x0c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) if (!(r_str(ppb) & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (!ppa_send_command(cmd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) cmd->SCp.phase++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) case 4: /* Phase 4 - Setup scatter/gather buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) if (scsi_bufflen(cmd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) cmd->SCp.buffer = scsi_sglist(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) cmd->SCp.this_residual = cmd->SCp.buffer->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) cmd->SCp.buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) cmd->SCp.this_residual = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) cmd->SCp.ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) cmd->SCp.phase++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) case 5: /* Phase 5 - Data transfer stage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) w_ctr(ppb, 0x0c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (!(r_str(ppb) & 0x80))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) retv = ppa_completion(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) if (retv == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (retv == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) cmd->SCp.phase++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) case 6: /* Phase 6 - Read status/message */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) cmd->result = DID_OK << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) /* Check for data overrun */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (ppa_wait(dev) != (unsigned char) 0xf0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) ppa_fail(dev, DID_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (ppa_in(dev, &l, 1)) { /* read status byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) /* Check for optional message byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) if (ppa_wait(dev) == (unsigned char) 0xf0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) ppa_in(dev, &h, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) cmd->result =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) (DID_OK << 16) + (h << 8) + (l & STATUS_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return 0; /* Finished */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) printk(KERN_ERR "ppa: Invalid scsi phase\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) static int ppa_queuecommand_lck(struct scsi_cmnd *cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) void (*done) (struct scsi_cmnd *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) ppa_struct *dev = ppa_dev(cmd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) if (dev->cur_cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) printk(KERN_ERR "PPA: bug in ppa_queuecommand\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) dev->failed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) dev->jstart = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) dev->cur_cmd = cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) cmd->scsi_done = done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) cmd->result = DID_ERROR << 16; /* default return code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) cmd->SCp.phase = 0; /* bus free */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) schedule_delayed_work(&dev->ppa_tq, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) ppa_pb_claim(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) static DEF_SCSI_QCMD(ppa_queuecommand)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) * Apparently the disk->capacity attribute is off by 1 sector
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) * for all disk drives. We add the one here, but it should really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) * be done in sd.c. Even if it gets fixed there, this will still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) * work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) static int ppa_biosparam(struct scsi_device *sdev, struct block_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) sector_t capacity, int ip[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) ip[0] = 0x40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) ip[1] = 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) if (ip[2] > 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) ip[0] = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) ip[1] = 0x3f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) ip[2] = ((unsigned long) capacity + 1) / (ip[0] * ip[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (ip[2] > 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) ip[2] = 1023;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) static int ppa_abort(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) ppa_struct *dev = ppa_dev(cmd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) * There is no method for aborting commands since Iomega
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) * have tied the SCSI_MESSAGE line high in the interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) switch (cmd->SCp.phase) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) case 0: /* Do not have access to parport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) case 1: /* Have not connected to interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) dev->cur_cmd = NULL; /* Forget the problem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) default: /* SCSI command sent, can not abort */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) return FAILED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) static void ppa_reset_pulse(unsigned int base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) w_dtr(base, 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) w_ctr(base, 0x8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) udelay(30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) w_ctr(base, 0xc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) static int ppa_reset(struct scsi_cmnd *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) ppa_struct *dev = ppa_dev(cmd->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) if (cmd->SCp.phase)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) dev->cur_cmd = NULL; /* Forget the problem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) ppa_connect(dev, CONNECT_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) ppa_reset_pulse(dev->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) mdelay(1); /* device settle delay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) mdelay(1); /* device settle delay */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) static int device_check(ppa_struct *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) /* This routine looks for a device and then attempts to use EPP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) to send a command. If all goes as planned then EPP is available. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) static u8 cmd[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) int loop, old_mode, status, k, ppb = dev->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) unsigned char l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) old_mode = dev->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) for (loop = 0; loop < 8; loop++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) /* Attempt to use EPP for Test Unit Ready */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) if ((ppb & 0x0007) == 0x0000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) dev->mode = PPA_EPP_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) second_pass:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) ppa_connect(dev, CONNECT_EPP_MAYBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) /* Select SCSI device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (!ppa_select(dev, loop)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) printk(KERN_INFO "ppa: Found device at ID %i, Attempting to use %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) loop, PPA_MODE_STRING[dev->mode]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) /* Send SCSI command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) status = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) w_ctr(ppb, 0x0c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) for (l = 0; (l < 6) && (status); l++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) status = ppa_out(dev, cmd, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) if (!status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) ppa_connect(dev, CONNECT_EPP_MAYBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) w_dtr(ppb, 0x40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) w_ctr(ppb, 0x08);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) udelay(30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) w_ctr(ppb, 0x0c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) udelay(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) udelay(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (dev->mode == PPA_EPP_32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) dev->mode = old_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) goto second_pass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) w_ctr(ppb, 0x0c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) k = 1000000; /* 1 Second */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) l = r_str(ppb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) k--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) } while (!(l & 0x80) && (k));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) l &= 0xf0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) if (l != 0xf0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) ppa_connect(dev, CONNECT_EPP_MAYBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) ppa_reset_pulse(ppb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) udelay(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) udelay(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (dev->mode == PPA_EPP_32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) dev->mode = old_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) goto second_pass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) printk(KERN_INFO "ppa: Communication established with ID %i using %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) loop, PPA_MODE_STRING[dev->mode]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) ppa_connect(dev, CONNECT_EPP_MAYBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) ppa_reset_pulse(ppb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) udelay(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) ppa_disconnect(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) udelay(1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) static int ppa_adjust_queue(struct scsi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) blk_queue_bounce_limit(device->request_queue, BLK_BOUNCE_HIGH);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) static struct scsi_host_template ppa_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) .module = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) .proc_name = "ppa",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) .show_info = ppa_show_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) .write_info = ppa_write_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) .name = "Iomega VPI0 (ppa) interface",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) .queuecommand = ppa_queuecommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) .eh_abort_handler = ppa_abort,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) .eh_host_reset_handler = ppa_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) .bios_param = ppa_biosparam,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) .this_id = -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) .sg_tablesize = SG_ALL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) .can_queue = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) .slave_alloc = ppa_adjust_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) /***************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) * Parallel port probing routines *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) ***************************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) static LIST_HEAD(ppa_hosts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) * Finds the first available device number that can be alloted to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) * new ppa device and returns the address of the previous node so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) * we can add to the tail and have a list in the ascending order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) static inline ppa_struct *find_parent(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) ppa_struct *dev, *par = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) unsigned int cnt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) if (list_empty(&ppa_hosts))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) list_for_each_entry(dev, &ppa_hosts, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) if (dev->dev_no != cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) return par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) par = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) return par;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) static int __ppa_attach(struct parport *pb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) struct Scsi_Host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) DECLARE_WAIT_QUEUE_HEAD_ONSTACK(waiting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) ppa_struct *dev, *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) int ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) int modes, ppb, ppb_hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) struct pardev_cb ppa_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) dev = kzalloc(sizeof(ppa_struct), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) dev->base = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) dev->mode = PPA_AUTODETECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) dev->recon_tmo = PPA_RECON_TMO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) init_waitqueue_head(&waiting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) temp = find_parent();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) if (temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) dev->dev_no = temp->dev_no + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) memset(&ppa_cb, 0, sizeof(ppa_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) ppa_cb.private = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) ppa_cb.wakeup = ppa_wakeup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) dev->dev = parport_register_dev_model(pb, "ppa", &ppa_cb, dev->dev_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) if (!dev->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) /* Claim the bus so it remembers what we do to the control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) * registers. [ CTR and ECP ]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) dev->waiting = &waiting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) prepare_to_wait(&waiting, &wait, TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) if (ppa_pb_claim(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) schedule_timeout(3 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) if (dev->wanted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) printk(KERN_ERR "ppa%d: failed to claim parport because "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) "a pardevice is owning the port for too long "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) "time!\n", pb->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) ppa_pb_dismiss(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) dev->waiting = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) finish_wait(&waiting, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) dev->waiting = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) finish_wait(&waiting, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) ppb = dev->base = dev->dev->port->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) ppb_hi = dev->dev->port->base_hi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) w_ctr(ppb, 0x0c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) modes = dev->dev->port->modes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) /* Mode detection works up the chain of speed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) * This avoids a nasty if-then-else-if-... tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) dev->mode = PPA_NIBBLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) if (modes & PARPORT_MODE_TRISTATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) dev->mode = PPA_PS2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) if (modes & PARPORT_MODE_ECP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) w_ecr(ppb_hi, 0x20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) dev->mode = PPA_PS2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) if ((modes & PARPORT_MODE_EPP) && (modes & PARPORT_MODE_ECP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) w_ecr(ppb_hi, 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) /* Done configuration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) err = ppa_init(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) ppa_pb_release(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) /* now the glue ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) if (dev->mode == PPA_NIBBLE || dev->mode == PPA_PS2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) ports = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) ports = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) INIT_DELAYED_WORK(&dev->ppa_tq, ppa_interrupt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) host = scsi_host_alloc(&ppa_template, sizeof(ppa_struct *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) host->io_port = pb->base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) host->n_io_port = ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) host->dma_channel = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) host->unique_id = pb->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) *(ppa_struct **)&host->hostdata = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) dev->host = host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) list_add_tail(&dev->list, &ppa_hosts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) err = scsi_add_host(host, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) scsi_scan_host(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) list_del_init(&dev->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) scsi_host_put(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) parport_unregister_device(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) static void ppa_attach(struct parport *pb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) __ppa_attach(pb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static void ppa_detach(struct parport *pb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) ppa_struct *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) list_for_each_entry(dev, &ppa_hosts, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) if (dev->dev->port == pb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) list_del_init(&dev->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) scsi_remove_host(dev->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) scsi_host_put(dev->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) parport_unregister_device(dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) static struct parport_driver ppa_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) .name = "ppa",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) .match_port = ppa_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) .detach = ppa_detach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) .devmodel = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) static int __init ppa_driver_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) printk(KERN_INFO "ppa: Version %s\n", PPA_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) return parport_register_driver(&ppa_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static void __exit ppa_driver_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) parport_unregister_driver(&ppa_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) module_init(ppa_driver_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) module_exit(ppa_driver_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) MODULE_LICENSE("GPL");