2 epia.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU General Public License.
5 epia.c is a low-level protocol driver for Shuttle Technologies
6 EPIA parallel to IDE adapter chip. This device is now obsolete
7 and has been replaced with the EPAT chip, which is supported
8 by epat.c, however, some devices based on EPIA are still
15 1.01 GRG 1998.05.06 init_proto, release_proto
16 1.02 GRG 1998.06.17 support older versions of EPIA
20 #define EPIA_VERSION "1.02"
22 #include <linux/module.h>
23 #include <linux/delay.h>
24 #include <linux/kernel.h>
25 #include <linux/types.h>
26 #include <linux/wait.h>
31 /* mode codes: 0 nybble reads on port 1, 8-bit writes
32 1 5/3 reads on ports 1 & 2, 8-bit writes
33 2 8-bit reads and writes
39 #define j44(a,b) (((a>>4)&0x0f)+(b&0xf0))
40 #define j53(a,b) (((a>>3)&0x1f)+((b<<4)&0xe0))
42 /* cont = 0 IDE register file
43 cont = 1 IDE control registers
46 static int cont_map[2] = { 0, 0x80 };
48 static int epia_read_regr( PIA *pi, int cont, int regr )
52 regr += cont_map[cont];
56 case 0: r = regr^0x39;
57 w0(r); w2(1); w2(3); w0(r);
58 a = r1(); w2(1); b = r1(); w2(4);
61 case 1: r = regr^0x31;
62 w0(r); w2(1); w0(r&0x37);
63 w2(3); w2(5); w0(r|0xf0);
64 a = r1(); b = r2(); w2(4);
67 case 2: r = regr^0x29;
68 w0(r); w2(1); w2(0X21); w2(0x23);
74 case 5: w3(regr); w2(0x24); a = r4(); w2(4);
81 static void epia_write_regr( PIA *pi, int cont, int regr, int val)
85 regr += cont_map[cont];
91 case 2: r = regr^0x19;
92 w0(r); w2(1); w0(val); w2(3); w2(4);
97 case 5: r = regr^0x40;
98 w3(r); w4(val); w2(4);
103 #define WR(r,v) epia_write_regr(pi,0,r,v)
104 #define RR(r) (epia_read_regr(pi,0,r))
106 /* The use of register 0x84 is entirely unclear - it seems to control
107 some EPP counters ... currently we know about 3 different block
108 sizes: the standard 512 byte reads and writes, 12 byte writes and
109 2048 byte reads (the last two being used in the CDrom drivers.
112 static void epia_connect ( PIA *pi )
114 { pi->saved_r0 = r0();
117 w2(4); w0(0xa0); w0(0x50); w0(0xc0); w0(0x30); w0(0xa0); w0(0);
120 w0(0xa); w2(1); w2(4); w0(0x82); w2(4); w2(0xc); w2(4);
121 w2(0x24); w2(0x26); w2(4);
126 static void epia_disconnect ( PIA *pi )
128 { /* WR(0x84,0x10); */
135 static void epia_read_block( PIA *pi, char * buf, int count )
141 case 0: w0(0x81); w2(1); w2(3); w0(0xc1);
143 for (k=0;k<count;k++) {
152 case 1: w0(0x91); w2(1); w0(0x10); w2(3);
153 w0(0x51); w2(5); w0(0xd1);
155 for (k=0;k<count;k++) {
164 case 2: w0(0x89); w2(1); w2(0x23); w2(0x21);
166 for (k=0;k<count;k++) {
174 case 3: if (count > 512) WR(0x84,3);
176 for (k=0;k<count;k++) buf[k] = r4();
180 case 4: if (count > 512) WR(0x84,3);
182 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
186 case 5: if (count > 512) WR(0x84,3);
188 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
195 static void epia_write_block( PIA *pi, char * buf, int count )
197 { int ph, k, last, d;
203 case 2: w0(0xa1); w2(1); w2(3); w2(1); w2(5);
204 ph = 0; last = 0x8000;
205 for (k=0;k<count;k++) {
207 if (d != last) { last = d; w0(d); }
214 case 3: if (count < 512) WR(0x84,1);
216 for (k=0;k<count;k++) w4(buf[k]);
217 if (count < 512) WR(0x84,0);
220 case 4: if (count < 512) WR(0x84,1);
222 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
223 if (count < 512) WR(0x84,0);
226 case 5: if (count < 512) WR(0x84,1);
228 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
229 if (count < 512) WR(0x84,0);
236 static int epia_test_proto( PIA *pi, char * scratch, int verbose )
244 for (k=0;k<256;k++) {
247 if (RR(2) != (k^0xaa)) e[j]++;
256 epia_read_block(pi,scratch,512);
257 for (k=0;k<256;k++) {
258 if ((scratch[2*k] & 0xff) != ((k+1) & 0xff)) f++;
259 if ((scratch[2*k+1] & 0xff) != ((-2-k) & 0xff)) f++;
265 printk("%s: epia: port 0x%x, mode %d, test=(%d,%d,%d)\n",
266 pi->device,pi->port,pi->mode,e[0],e[1],f);
269 return (e[0] && e[1]) || f;
274 static void epia_log_adapter( PIA *pi, char * scratch, int verbose )
276 { char *mode_string[6] = {"4-bit","5/3","8-bit",
277 "EPP-8","EPP-16","EPP-32"};
279 printk("%s: epia %s, Shuttle EPIA at 0x%x, ",
280 pi->device,EPIA_VERSION,pi->port);
281 printk("mode %d (%s), delay %d\n",pi->mode,
282 mode_string[pi->mode],pi->delay);
286 static void epia_init_proto( PIA *pi)
291 static void epia_release_proto( PIA *pi)
296 struct pi_protocol epia = {"epia",0,6,3,1,1,
314 int init_module(void)
316 { return pi_register( &epia ) - 1;
319 void cleanup_module(void)
321 { pi_unregister( &epia );
328 MODULE_LICENSE("GPL");