12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
16 #include <linux/parport.h>
22 #include <scsi/scsi.h>
28 static void ppa_reset_pulse(
unsigned int base);
38 unsigned int failed:1;
56 dev->
base = dev->
dev->port->base;
63 static void ppa_wakeup(
void *ref)
74 spin_unlock_irqrestore(&arbitration_lock, flags);
88 spin_unlock_irqrestore(&arbitration_lock, flags);
99 spin_unlock_irqrestore(&arbitration_lock, flags);
104 static inline void ppa_pb_release(
ppa_struct *dev)
125 if ((length > 5) && (
strncmp(buffer,
"mode=", 5) == 0)) {
130 if ((length > 10) && (
strncmp(buffer,
"recon_tmo=", 10) == 0)) {
146 return ppa_proc_write(dev, buffer, length);
150 sprintf(buffer + len,
"Parport : %s\n",
151 dev->
dev->port->name);
153 sprintf(buffer + len,
"Mode : %s\n",
154 PPA_MODE_STRING[dev->
mode]);
174 #define ppa_fail(x,y) printk("ppa: ppa_fail(%i) from %s at line %d\n",\
175 y, __func__, __LINE__); ppa_fail_func(x,y);
178 static inline void ppa_fail(
ppa_struct *dev,
int error_code)
183 dev->
cur_cmd->result = error_code << 16;
195 static unsigned char ppa_wait(
ppa_struct *dev)
198 unsigned short ppb = dev->
base;
203 for (r =
r_str(ppb); ((r & 0xc0) != 0xc0) && (
k); k--) {
227 static inline void epp_reset(
unsigned short ppb)
233 w_str(ppb, i & 0xfe);
241 int i, ppb_hi = dev->
dev->port->base_hi;
246 if ((
r_ecr(ppb_hi) & 0xe0) == 0x60) {
247 for (i = 0; i < 100; i++) {
248 if (
r_ecr(ppb_hi) & 0x01)
256 static int ppa_byte_out(
unsigned short base,
const char *buffer,
int len)
260 for (i = len;
i; i--) {
261 w_dtr(base, *buffer++);
268 static int ppa_byte_in(
unsigned short base,
char *buffer,
int len)
272 for (i = len;
i; i--) {
273 *buffer++ =
r_dtr(base);
280 static int ppa_nibble_in(
unsigned short base,
char *buffer,
int len)
286 h =
r_str(base) & 0xf0;
288 *buffer++ = h | ((
r_str(base) & 0xf0) >> 4);
293 static int ppa_out(
ppa_struct *dev,
char *buffer,
int len)
296 unsigned short ppb = dev->
base;
300 if ((r & 0x50) != 0x40) {
308 r = ppa_byte_out(ppb, buffer, len);
316 #ifdef CONFIG_SCSI_IZIP_EPP16
317 if (!(((
long) buffer | len) & 0x01))
318 outsw(ppb + 4, buffer, len >> 1);
320 if (!(((
long) buffer | len) & 0x03))
321 outsl(ppb + 4, buffer, len >> 2);
324 outsb(ppb + 4, buffer, len);
326 r = !(
r_str(ppb) & 0x01);
338 static int ppa_in(
ppa_struct *dev,
char *buffer,
int len)
341 unsigned short ppb = dev->
base;
345 if ((r & 0x50) != 0x50) {
352 r = ppa_nibble_in(ppb, buffer, len);
359 r = ppa_byte_in(ppb, buffer, len);
369 #ifdef CONFIG_SCSI_IZIP_EPP16
370 if (!(((
long) buffer | len) & 0x01))
371 insw(ppb + 4, buffer, len >> 1);
373 if (!(((
long) buffer | len) & 0x03))
374 insl(ppb + 4, buffer, len >> 2);
377 insb(ppb + 4, buffer, len);
379 r = !(
r_str(ppb) & 0x01);
393 static inline void ppa_d_pulse(
unsigned short ppb,
unsigned char b)
405 unsigned short ppb = dev->
base;
408 ppa_d_pulse(ppb, 0x3c);
409 ppa_d_pulse(ppb, 0x20);
410 ppa_d_pulse(ppb, 0xf);
413 static inline void ppa_c_pulse(
unsigned short ppb,
unsigned char b)
424 unsigned short ppb = dev->
base;
427 ppa_c_pulse(ppb, 0x3c);
428 ppa_c_pulse(ppb, 0x20);
430 ppa_c_pulse(ppb, 0xcf);
432 ppa_c_pulse(ppb, 0x8f);
438 unsigned short ppb = dev->
base;
448 }
while ((
r_str(ppb) & 0x40) && (k));
452 w_dtr(ppb, (1 << target));
463 while (!(
r_str(ppb) & 0x40) && (k));
482 unsigned short ppb = dev->
base;
490 if ((
r_str(ppb) & 0x08) == 0x08)
494 if ((
r_str(ppb) & 0x08) == 0x00)
498 ppa_reset_pulse(ppb);
506 return device_check(dev);
509 static inline int ppa_send_command(
struct scsi_cmnd *
cmd)
516 for (k = 0; k < cmd->
cmd_len; k++)
517 if (!ppa_out(dev, &cmd->
cmnd[k], 1))
530 static int ppa_completion(
struct scsi_cmnd *cmd)
538 unsigned short ppb = dev->
base;
539 unsigned long start_jiffies =
jiffies;
552 r = (
r_str(ppb) & 0xf0);
554 while (r != (
unsigned char) 0xf0) {
562 if ((cmd->
SCp.this_residual <= 0)) {
577 if ((r & 0xc0) != 0xc0) {
582 for (; k && ((r = (
r_str(ppb) & 0xf0)) & 0xc0) != 0xc0;
594 if (r == (
unsigned char) 0xc0)
595 status = ppa_out(dev, cmd->
SCp.ptr, fast);
597 status = ppa_in(dev, cmd->
SCp.ptr, fast);
600 cmd->
SCp.this_residual -=
fast;
606 if (cmd->
SCp.buffer && !cmd->
SCp.this_residual) {
608 if (cmd->
SCp.buffers_residual--) {
610 cmd->
SCp.this_residual =
611 cmd->
SCp.buffer->length;
612 cmd->
SCp.ptr = sg_virt(cmd->
SCp.buffer);
616 r = (
r_str(ppb) & 0xf0);
638 if (ppa_engine(dev, cmd)) {
644 switch ((cmd->
result >> 16) & 0xff) {
673 (cmd->
result >> 16) & 0xff);
677 if (cmd->
SCp.phase > 1)
689 unsigned short ppb = dev->
base;
690 unsigned char l = 0,
h = 0;
699 switch (cmd->
SCp.phase) {
717 if ((
r_str(ppb) & 0x08) == 0x08)
721 if ((
r_str(ppb) & 0x08) == 0x00)
738 if (!ppa_select(dev,
scmd_id(cmd))) {
746 if (!(
r_str(ppb) & 0x80))
749 if (!ppa_send_command(cmd))
754 if (scsi_bufflen(cmd)) {
755 cmd->
SCp.buffer = scsi_sglist(cmd);
756 cmd->
SCp.this_residual = cmd->
SCp.buffer->length;
757 cmd->
SCp.ptr = sg_virt(cmd->
SCp.buffer);
760 cmd->
SCp.this_residual = 0;
763 cmd->
SCp.buffers_residual = scsi_sg_count(cmd) - 1;
768 if (!(
r_str(ppb) & 0x80))
771 retv = ppa_completion(cmd);
781 if (ppa_wait(dev) != (
unsigned char) 0xf0) {
785 if (ppa_in(dev, &l, 1)) {
787 if (ppa_wait(dev) == (
unsigned char) 0xf0)
801 static int ppa_queuecommand_lck(
struct scsi_cmnd *cmd,
837 ip[2] = ((
unsigned long) capacity + 1) / (ip[0] * ip[1]);
841 ip[2] = ((
unsigned long) capacity + 1) / (ip[0] * ip[1]);
848 static int ppa_abort(
struct scsi_cmnd *cmd)
856 switch (cmd->
SCp.phase) {
868 static void ppa_reset_pulse(
unsigned int base)
876 static int ppa_reset(
struct scsi_cmnd *cmd)
885 ppa_reset_pulse(dev->
base);
897 static u8 cmd[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
901 old_mode = dev->
mode;
902 for (loop = 0; loop < 8; loop++) {
904 if ((ppb & 0x0007) == 0x0000)
910 if (!ppa_select(dev, loop)) {
915 loop, PPA_MODE_STRING[dev->
mode]);
920 for (l = 0; (l < 6) && (status); l++)
921 status = ppa_out(dev, cmd, 1);
934 dev->
mode = old_mode;
945 }
while (!(l & 0x80) && (k));
952 ppa_reset_pulse(ppb);
957 dev->
mode = old_mode;
963 printk(
KERN_INFO "ppa: Communication established with ID %i using %s\n",
964 loop, PPA_MODE_STRING[dev->
mode]);
966 ppa_reset_pulse(ppb);
984 .proc_info = ppa_proc_info,
985 .name =
"Iomega VPI0 (ppa) interface",
986 .queuecommand = ppa_queuecommand,
987 .eh_abort_handler = ppa_abort,
988 .eh_bus_reset_handler = ppa_reset,
989 .eh_host_reset_handler = ppa_reset,
990 .bios_param = ppa_biosparam,
996 .slave_alloc = ppa_adjust_queue,
1005 static int __ppa_attach(
struct parport *pb)
1012 int modes, ppb, ppb_hi;
1034 if (ppa_pb_claim(dev))
1038 "a pardevice is owning the port for too long "
1040 ppa_pb_dismiss(dev);
1047 ppb = dev->
base = dev->
dev->port->base;
1048 ppb_hi = dev->
dev->port->base_hi;
1050 modes = dev->
dev->port->modes;
1061 w_ecr(ppb_hi, 0x20);
1065 w_ecr(ppb_hi, 0x80);
1069 err = ppa_init(dev);
1070 ppa_pb_release(dev);
1094 err = scsi_add_host(host,
NULL);
1100 list_del_init(&dev->
list);
1109 static void ppa_attach(
struct parport *pb)
1114 static void ppa_detach(
struct parport *pb)
1118 if (dev->
dev->port == pb) {
1119 list_del_init(&dev->
list);
1131 .attach = ppa_attach,
1132 .detach = ppa_detach,
1135 static int __init ppa_driver_init(
void)
1141 static void __exit ppa_driver_exit(
void)