2 epat.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU General Public License.
5 This is the low level protocol driver for the EPAT parallel
6 to IDE adapter from Shuttle Technologies. This adapter is
7 used in many popular parallel port disk products such as the
8 SyQuest EZ drives, the Avatar Shark and the Imation SuperDisk.
14 1.01 GRG 1998.05.06 init_proto, release_proto
15 1.02 Joshua b. Jore CPP(renamed), epat_connect, epat_disconnect
19 #define EPAT_VERSION "1.02"
21 #include <linux/module.h>
22 #include <linux/delay.h>
23 #include <linux/kernel.h>
24 #include <linux/types.h>
25 #include <linux/wait.h>
30 #define j44(a,b) (((a>>4)&0x0f)+(b&0xf0))
31 #define j53(a,b) (((a>>3)&0x1f)+((b<<4)&0xe0))
33 /* cont = 0 IDE register file
34 cont = 1 IDE control registers
35 cont = 2 internal EPAT registers
38 static int cont_map[3] = { 0x18, 0x10, 0 };
40 static void epat_write_regr( PIA *pi, int cont, int regr, int val)
44 r = regr + cont_map[cont];
50 case 2: w0(0x60+r); w2(1); w0(val); w2(4);
55 case 5: w3(0x40+r); w4(val);
61 static int epat_read_regr( PIA *pi, int cont, int regr )
65 r = regr + cont_map[cont];
69 case 0: w0(r); w2(1); w2(3);
70 a = r1(); w2(4); b = r1();
73 case 1: w0(0x40+r); w2(1); w2(4);
74 a = r1(); b = r2(); w0(0xff);
77 case 2: w0(0x20+r); w2(1); w2(0x25);
83 case 5: w3(r); w2(0x24); a = r4(); w2(4);
87 return -1; /* never gets here */
90 static void epat_read_block( PIA *pi, char * buf, int count )
96 case 0: w0(7); w2(1); w2(3); w0(0xff);
98 for(k=0;k<count;k++) {
99 if (k == count-1) w0(0xfd);
102 else { w2(4+ph); b = r1(); }
109 case 1: w0(0x47); w2(1); w2(5); w0(0xff);
111 for(k=0;k<count;k++) {
112 if (k == count-1) w0(0xfd);
121 case 2: w0(0x27); w2(1); w2(0x25); w0(0);
123 for(k=0;k<count-1;k++) {
128 w2(0x26); w2(0x27); buf[count-1] = r0();
132 case 3: w3(0x80); w2(0x24);
133 for(k=0;k<count-1;k++) buf[k] = r4();
134 w2(4); w3(0xa0); w2(0x24); buf[count-1] = r4();
138 case 4: w3(0x80); w2(0x24);
139 for(k=0;k<(count/2)-1;k++) ((u16 *)buf)[k] = r4w();
141 w2(4); w3(0xa0); w2(0x24); buf[count-1] = r4();
145 case 5: w3(0x80); w2(0x24);
146 for(k=0;k<(count/4)-1;k++) ((u32 *)buf)[k] = r4l();
147 for(k=count-4;k<count-1;k++) buf[k] = r4();
148 w2(4); w3(0xa0); w2(0x24); buf[count-1] = r4();
155 static void epat_write_block( PIA *pi, char * buf, int count )
163 case 2: w0(0x67); w2(1); w2(5);
165 for(k=0;k<count;k++) {
174 for(k=0;k<count;k++) w4(buf[k]);
179 for(k=0;k<(count/2);k++) w4w(((u16 *)buf)[k]);
184 for(k=0;k<(count/4);k++) w4l(((u32 *)buf)[k]);
191 /* these macros access the EPAT registers in native addressing */
193 #define WR(r,v) epat_write_regr(pi,2,r,v)
194 #define RR(r) (epat_read_regr(pi,2,r))
196 /* and these access the IDE task file */
198 #define WRi(r,v) epat_write_regr(pi,0,r,v)
199 #define RRi(r) (epat_read_regr(pi,0,r))
201 /* FIXME: the CPP stuff should be fixed to handle multiple EPATs on a chain */
203 #define CPP(x) w2(4);w0(0x22);w0(0xaa);w0(0x55);w0(0);w0(0xff);\
204 w0(0x87);w0(0x78);w0(x);w2(4);w2(5);w2(4);w0(0xff);
206 static void epat_connect ( PIA *pi )
208 { pi->saved_r0 = r0();
211 #ifdef CONFIG_PARIDE_EPATC8
212 /* Initialize the chip */
213 CPP(0);CPP(0x40);CPP(0xe0);
215 WR(0x8,0x12);WR(0xc,0x14);WR(0x12,0x10);
216 WR(0xe,0xf);WR(0xf,4);
217 /* WR(0xe,0xa);WR(0xf,4); */
218 WR(0xe,0xd);WR(0xf,0);
221 /* Connect to the chip */
223 w0(0);w2(1);w2(4); /* Idle into SPP */
225 w0(0);w2(1);w2(4);w2(0xc);
227 w0(0x40);w2(6);w2(7);w2(4);w2(0xc);w2(4);
233 w0(0); w2(1); w2(4); w2(0xc);
234 w0(0x40); w2(6); w2(7); w2(4); w2(0xc); w2(4);
236 WR(8,0x10); WR(0xc,0x14); WR(0xa,0x38); WR(0x12,0x10);
240 static void epat_disconnect (PIA *pi)
246 static int epat_test_proto( PIA *pi, char * scratch, int verbose )
258 for (k=0;k<256;k++) {
261 if (RRi(2) != (k^0xaa)) e[j]++;
268 WR(0x13,1); WR(0x13,0); WR(0xa,0x11);
269 epat_read_block(pi,scratch,512);
271 for (k=0;k<256;k++) {
272 if ((scratch[2*k] & 0xff) != k) f++;
273 if ((scratch[2*k+1] & 0xff) != (0xff-k)) f++;
278 printk("%s: epat: port 0x%x, mode %d, ccr %x, test=(%d,%d,%d)\n",
279 pi->device,pi->port,pi->mode,cc,e[0],e[1],f);
282 return (e[0] && e[1]) || f;
285 static void epat_log_adapter( PIA *pi, char * scratch, int verbose )
288 char *mode_string[6] =
289 {"4-bit","5/3","8-bit","EPP-8","EPP-16","EPP-32"};
292 WR(0xa,0x38); /* read the version code */
296 printk("%s: epat %s, Shuttle EPAT chip %x at 0x%x, ",
297 pi->device,EPAT_VERSION,ver,pi->port);
298 printk("mode %d (%s), delay %d\n",pi->mode,
299 mode_string[pi->mode],pi->delay);
303 static void epat_init_proto( PIA *pi)
308 static void epat_release_proto( PIA *pi)
313 struct pi_protocol epat = {"epat",0,6,3,1,1,
331 int init_module(void)
333 { return pi_register( &epat) - 1;
336 void cleanup_module(void)
338 { pi_unregister( &epat);
344 MODULE_LICENSE("GPL");