162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci/*  Driver for the Iomega MatchMaker parallel port SCSI HBA embedded in
462306a36Sopenharmony_ci * the Iomega ZIP Plus drive
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * (c) 1998     David Campbell
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Please note that I live in Perth, Western Australia. GMT+0800
962306a36Sopenharmony_ci */
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#ifndef _IMM_H
1262306a36Sopenharmony_ci#define _IMM_H
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#define   IMM_VERSION   "2.05 (for Linux 2.4.0)"
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/*
1762306a36Sopenharmony_ci * 10 Apr 1998 (Good Friday) - Received EN144302 by email from Iomega.
1862306a36Sopenharmony_ci * Scarry thing is the level of support from one of their managers.
1962306a36Sopenharmony_ci * The onus is now on us (the developers) to shut up and start coding.
2062306a36Sopenharmony_ci *                                              11Apr98 [ 0.10 ]
2162306a36Sopenharmony_ci *
2262306a36Sopenharmony_ci * --- SNIP ---
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * It manages to find the drive which is a good start. Writing data during
2562306a36Sopenharmony_ci * data phase is known to be broken (due to requirements of two byte writes).
2662306a36Sopenharmony_ci * Removing "Phase" debug messages.
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci * PS: Took four hours of coding after I bought a drive.
2962306a36Sopenharmony_ci *      ANZAC Day (Aus "War Veterans Holiday")  25Apr98 [ 0.14 ]
3062306a36Sopenharmony_ci *
3162306a36Sopenharmony_ci * Ten minutes later after a few fixes.... (LITERALLY!!!)
3262306a36Sopenharmony_ci * Have mounted disk, copied file, dismounted disk, remount disk, diff file
3362306a36Sopenharmony_ci *                    -----  It actually works!!! -----
3462306a36Sopenharmony_ci *                                              25Apr98 [ 0.15 ]
3562306a36Sopenharmony_ci *
3662306a36Sopenharmony_ci * Twenty minutes of mucking around, rearanged the IEEE negotiate mechanism.
3762306a36Sopenharmony_ci * Now have byte mode working (only EPP and ECP to go now... :=)
3862306a36Sopenharmony_ci *                                              26Apr98 [ 0.16 ]
3962306a36Sopenharmony_ci *
4062306a36Sopenharmony_ci * Thirty minutes of further coding results in EPP working on my machine.
4162306a36Sopenharmony_ci *                                              27Apr98 [ 0.17 ]
4262306a36Sopenharmony_ci *
4362306a36Sopenharmony_ci * Due to work commitments and inability to get a "true" ECP mode functioning
4462306a36Sopenharmony_ci * I have decided to code the parport support into imm.
4562306a36Sopenharmony_ci *                                              09Jun98 [ 0.18 ]
4662306a36Sopenharmony_ci *
4762306a36Sopenharmony_ci * Driver is now out of beta testing.
4862306a36Sopenharmony_ci * Support for parport has been added.
4962306a36Sopenharmony_ci * Now distributed with the ppa driver.
5062306a36Sopenharmony_ci *                                              12Jun98 [ 2.00 ]
5162306a36Sopenharmony_ci *
5262306a36Sopenharmony_ci * Err.. It appears that imm-2.00 was broken....
5362306a36Sopenharmony_ci *                                              18Jun98 [ 2.01 ]
5462306a36Sopenharmony_ci *
5562306a36Sopenharmony_ci * Patch applied to sync this against the Linux 2.1.x kernel code
5662306a36Sopenharmony_ci * Included qboot_zip.sh
5762306a36Sopenharmony_ci *                                              21Jun98 [ 2.02 ]
5862306a36Sopenharmony_ci *
5962306a36Sopenharmony_ci * Other clean ups include the follow changes:
6062306a36Sopenharmony_ci *    CONFIG_SCSI_PPA_HAVE_PEDANTIC => CONFIG_SCSI_IZIP_EPP16
6162306a36Sopenharmony_ci *    added CONFIG_SCSI_IZIP_SLOW_CTR option
6262306a36Sopenharmony_ci *                                                      [2.03]
6362306a36Sopenharmony_ci *  Fix kernel panic on scsi timeout.		20Aug00 [2.04]
6462306a36Sopenharmony_ci *
6562306a36Sopenharmony_ci *  Avoid io_request_lock problems.
6662306a36Sopenharmony_ci *  John Cavan <johncavan@home.com>		16Nov00 [2.05]
6762306a36Sopenharmony_ci */
6862306a36Sopenharmony_ci/* ------ END OF USER CONFIGURABLE PARAMETERS ----- */
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#include  <linux/stddef.h>
7162306a36Sopenharmony_ci#include  <linux/module.h>
7262306a36Sopenharmony_ci#include  <linux/kernel.h>
7362306a36Sopenharmony_ci#include  <linux/ioport.h>
7462306a36Sopenharmony_ci#include  <linux/delay.h>
7562306a36Sopenharmony_ci#include  <linux/proc_fs.h>
7662306a36Sopenharmony_ci#include  <linux/stat.h>
7762306a36Sopenharmony_ci#include  <linux/blkdev.h>
7862306a36Sopenharmony_ci#include  <linux/sched.h>
7962306a36Sopenharmony_ci#include  <linux/interrupt.h>
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#include  <asm/io.h>
8262306a36Sopenharmony_ci#include  <scsi/scsi_host.h>
8362306a36Sopenharmony_ci/* batteries not included :-) */
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci/*
8662306a36Sopenharmony_ci * modes in which the driver can operate
8762306a36Sopenharmony_ci */
8862306a36Sopenharmony_ci#define   IMM_AUTODETECT        0	/* Autodetect mode                */
8962306a36Sopenharmony_ci#define   IMM_NIBBLE            1	/* work in standard 4 bit mode    */
9062306a36Sopenharmony_ci#define   IMM_PS2               2	/* PS/2 byte mode         */
9162306a36Sopenharmony_ci#define   IMM_EPP_8             3	/* EPP mode, 8 bit                */
9262306a36Sopenharmony_ci#define   IMM_EPP_16            4	/* EPP mode, 16 bit               */
9362306a36Sopenharmony_ci#define   IMM_EPP_32            5	/* EPP mode, 32 bit               */
9462306a36Sopenharmony_ci#define   IMM_UNKNOWN           6	/* Just in case...                */
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_cistatic char *IMM_MODE_STRING[] =
9762306a36Sopenharmony_ci{
9862306a36Sopenharmony_ci	[IMM_AUTODETECT] = "Autodetect",
9962306a36Sopenharmony_ci	[IMM_NIBBLE]	 = "SPP",
10062306a36Sopenharmony_ci	[IMM_PS2]	 = "PS/2",
10162306a36Sopenharmony_ci	[IMM_EPP_8]	 = "EPP 8 bit",
10262306a36Sopenharmony_ci	[IMM_EPP_16]	 = "EPP 16 bit",
10362306a36Sopenharmony_ci#ifdef CONFIG_SCSI_IZIP_EPP16
10462306a36Sopenharmony_ci	[IMM_EPP_32]	 = "EPP 16 bit",
10562306a36Sopenharmony_ci#else
10662306a36Sopenharmony_ci	[IMM_EPP_32]	 = "EPP 32 bit",
10762306a36Sopenharmony_ci#endif
10862306a36Sopenharmony_ci	[IMM_UNKNOWN]	 = "Unknown",
10962306a36Sopenharmony_ci};
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci/* other options */
11262306a36Sopenharmony_ci#define IMM_BURST_SIZE	512	/* data burst size */
11362306a36Sopenharmony_ci#define IMM_SELECT_TMO  500	/* 500 how long to wait for target ? */
11462306a36Sopenharmony_ci#define IMM_SPIN_TMO    5000	/* 50000 imm_wait loop limiter */
11562306a36Sopenharmony_ci#define IMM_DEBUG	0	/* debugging option */
11662306a36Sopenharmony_ci#define IN_EPP_MODE(x) (x == IMM_EPP_8 || x == IMM_EPP_16 || x == IMM_EPP_32)
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci/* args to imm_connect */
11962306a36Sopenharmony_ci#define CONNECT_EPP_MAYBE 1
12062306a36Sopenharmony_ci#define CONNECT_NORMAL  0
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci#define r_dtr(x)        (unsigned char)inb((x))
12362306a36Sopenharmony_ci#define r_str(x)        (unsigned char)inb((x)+1)
12462306a36Sopenharmony_ci#define r_ctr(x)        (unsigned char)inb((x)+2)
12562306a36Sopenharmony_ci#define r_epp(x)        (unsigned char)inb((x)+4)
12662306a36Sopenharmony_ci#define r_fifo(x)       (unsigned char)inb((x))   /* x must be base_hi */
12762306a36Sopenharmony_ci					/* On PCI is: base+0x400 != base_hi */
12862306a36Sopenharmony_ci#define r_ecr(x)        (unsigned char)inb((x)+2) /* x must be base_hi */
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#define w_dtr(x,y)      outb(y, (x))
13162306a36Sopenharmony_ci#define w_str(x,y)      outb(y, (x)+1)
13262306a36Sopenharmony_ci#define w_epp(x,y)      outb(y, (x)+4)
13362306a36Sopenharmony_ci#define w_fifo(x,y)     outb(y, (x))     /* x must be base_hi */
13462306a36Sopenharmony_ci#define w_ecr(x,y)      outb(y, (x)+0x2) /* x must be base_hi */
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#ifdef CONFIG_SCSI_IZIP_SLOW_CTR
13762306a36Sopenharmony_ci#define w_ctr(x,y)      outb_p(y, (x)+2)
13862306a36Sopenharmony_ci#else
13962306a36Sopenharmony_ci#define w_ctr(x,y)      outb(y, (x)+2)
14062306a36Sopenharmony_ci#endif
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_cistatic inline struct scsi_pointer *imm_scsi_pointer(struct scsi_cmnd *cmd)
14362306a36Sopenharmony_ci{
14462306a36Sopenharmony_ci	return scsi_cmd_priv(cmd);
14562306a36Sopenharmony_ci}
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_cistatic int imm_engine(imm_struct *, struct scsi_cmnd *);
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci#endif				/* _IMM_H */
150