2 epia.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU 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>
30 /* mode codes: 0 nybble reads on port 1, 8-bit writes
31 1 5/3 reads on ports 1 & 2, 8-bit writes
32 2 8-bit reads and writes
38 #define j44(a,b) (((a>>4)&0x0f)+(b&0xf0))
39 #define j53(a,b) (((a>>3)&0x1f)+((b<<4)&0xe0))
41 /* cont = 0 IDE register file
42 cont = 1 IDE control registers
45 static int cont_map
[2] = { 0, 0x80 };
47 static int epia_read_regr( PIA
*pi
, int cont
, int regr
)
51 regr
+= cont_map
[cont
];
55 case 0: r
= regr
^0x39;
56 w0(r
); w2(1); w2(3); w0(r
);
57 a
= r1(); w2(1); b
= r1(); w2(4);
60 case 1: r
= regr
^0x31;
61 w0(r
); w2(1); w0(r
&0x37);
62 w2(3); w2(5); w0(r
|0xf0);
63 a
= r1(); b
= r2(); w2(4);
66 case 2: r
= regr
^0x29;
67 w0(r
); w2(1); w2(0X21); w2(0x23);
73 case 5: w3(regr
); w2(0x24); a
= r4(); w2(4);
80 static void epia_write_regr( PIA
*pi
, int cont
, int regr
, int val
)
84 regr
+= cont_map
[cont
];
90 case 2: r
= regr
^0x19;
91 w0(r
); w2(1); w0(val
); w2(3); w2(4);
96 case 5: r
= regr
^0x40;
97 w3(r
); w4(val
); w2(4);
102 #define WR(r,v) epia_write_regr(pi,0,r,v)
103 #define RR(r) (epia_read_regr(pi,0,r))
105 /* The use of register 0x84 is entirely unclear - it seems to control
106 some EPP counters ... currently we know about 3 different block
107 sizes: the standard 512 byte reads and writes, 12 byte writes and
108 2048 byte reads (the last two being used in the CDrom drivers.
111 static void epia_connect ( PIA
*pi
)
113 { pi
->saved_r0
= r0();
116 w2(4); w0(0xa0); w0(0x50); w0(0xc0); w0(0x30); w0(0xa0); w0(0);
119 w0(0xa); w2(1); w2(4); w0(0x82); w2(4); w2(0xc); w2(4);
120 w2(0x24); w2(0x26); w2(4);
125 static void epia_disconnect ( PIA
*pi
)
127 { /* WR(0x84,0x10); */
134 static void epia_read_block( PIA
*pi
, char * buf
, int count
)
140 case 0: w0(0x81); w2(1); w2(3); w0(0xc1);
142 for (k
=0;k
<count
;k
++) {
151 case 1: w0(0x91); w2(1); w0(0x10); w2(3);
152 w0(0x51); w2(5); w0(0xd1);
154 for (k
=0;k
<count
;k
++) {
163 case 2: w0(0x89); w2(1); w2(0x23); w2(0x21);
165 for (k
=0;k
<count
;k
++) {
173 case 3: if (count
> 512) WR(0x84,3);
175 for (k
=0;k
<count
;k
++) buf
[k
] = r4();
179 case 4: if (count
> 512) WR(0x84,3);
181 for (k
=0;k
<count
/2;k
++) ((u16
*)buf
)[k
] = r4w();
185 case 5: if (count
> 512) WR(0x84,3);
187 for (k
=0;k
<count
/4;k
++) ((u32
*)buf
)[k
] = r4l();
194 static void epia_write_block( PIA
*pi
, char * buf
, int count
)
196 { int ph
, k
, last
, d
;
202 case 2: w0(0xa1); w2(1); w2(3); w2(1); w2(5);
203 ph
= 0; last
= 0x8000;
204 for (k
=0;k
<count
;k
++) {
206 if (d
!= last
) { last
= d
; w0(d
); }
213 case 3: if (count
< 512) WR(0x84,1);
215 for (k
=0;k
<count
;k
++) w4(buf
[k
]);
216 if (count
< 512) WR(0x84,0);
219 case 4: if (count
< 512) WR(0x84,1);
221 for (k
=0;k
<count
/2;k
++) w4w(((u16
*)buf
)[k
]);
222 if (count
< 512) WR(0x84,0);
225 case 5: if (count
< 512) WR(0x84,1);
227 for (k
=0;k
<count
/4;k
++) w4l(((u32
*)buf
)[k
]);
228 if (count
< 512) WR(0x84,0);
235 static int epia_test_proto( PIA
*pi
, char * scratch
, int verbose
)
243 for (k
=0;k
<256;k
++) {
246 if (RR(2) != (k
^0xaa)) e
[j
]++;
255 epia_read_block(pi
,scratch
,512);
256 for (k
=0;k
<256;k
++) {
257 if ((scratch
[2*k
] & 0xff) != ((k
+1) & 0xff)) f
++;
258 if ((scratch
[2*k
+1] & 0xff) != ((-2-k
) & 0xff)) f
++;
264 printk("%s: epia: port 0x%x, mode %d, test=(%d,%d,%d)\n",
265 pi
->device
,pi
->port
,pi
->mode
,e
[0],e
[1],f
);
268 return (e
[0] && e
[1]) || f
;
273 static void epia_log_adapter( PIA
*pi
, char * scratch
, int verbose
)
275 { char *mode_string
[6] = {"4-bit","5/3","8-bit",
276 "EPP-8","EPP-16","EPP-32"};
278 printk("%s: epia %s, Shuttle EPIA at 0x%x, ",
279 pi
->device
,EPIA_VERSION
,pi
->port
);
280 printk("mode %d (%s), delay %d\n",pi
->mode
,
281 mode_string
[pi
->mode
],pi
->delay
);
285 static void epia_init_proto( PIA
*pi
)
290 static void epia_release_proto( PIA
*pi
)
295 struct pi_protocol epia
= {"epia",0,6,3,1,1,
313 int init_module(void)
315 { return pi_register( &epia
) - 1;
318 void cleanup_module(void)
320 { pi_unregister( &epia
);