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/init.h>
24 #include <linux/delay.h>
25 #include <linux/kernel.h>
26 #include <linux/types.h>
27 #include <linux/wait.h>
32 /* mode codes: 0 nybble reads on port 1, 8-bit writes
33 1 5/3 reads on ports 1 & 2, 8-bit writes
34 2 8-bit reads and writes
40 #define j44(a,b) (((a>>4)&0x0f)+(b&0xf0))
41 #define j53(a,b) (((a>>3)&0x1f)+((b<<4)&0xe0))
43 /* cont = 0 IDE register file
44 cont = 1 IDE control registers
47 static int cont_map
[2] = { 0, 0x80 };
49 static int epia_read_regr( PIA
*pi
, int cont
, int regr
)
53 regr
+= cont_map
[cont
];
57 case 0: r
= regr
^0x39;
58 w0(r
); w2(1); w2(3); w0(r
);
59 a
= r1(); w2(1); b
= r1(); w2(4);
62 case 1: r
= regr
^0x31;
63 w0(r
); w2(1); w0(r
&0x37);
64 w2(3); w2(5); w0(r
|0xf0);
65 a
= r1(); b
= r2(); w2(4);
68 case 2: r
= regr
^0x29;
69 w0(r
); w2(1); w2(0X21); w2(0x23);
75 case 5: w3(regr
); w2(0x24); a
= r4(); w2(4);
82 static void epia_write_regr( PIA
*pi
, int cont
, int regr
, int val
)
86 regr
+= cont_map
[cont
];
92 case 2: r
= regr
^0x19;
93 w0(r
); w2(1); w0(val
); w2(3); w2(4);
98 case 5: r
= regr
^0x40;
99 w3(r
); w4(val
); w2(4);
104 #define WR(r,v) epia_write_regr(pi,0,r,v)
105 #define RR(r) (epia_read_regr(pi,0,r))
107 /* The use of register 0x84 is entirely unclear - it seems to control
108 some EPP counters ... currently we know about 3 different block
109 sizes: the standard 512 byte reads and writes, 12 byte writes and
110 2048 byte reads (the last two being used in the CDrom drivers.
113 static void epia_connect ( PIA
*pi
)
115 { pi
->saved_r0
= r0();
118 w2(4); w0(0xa0); w0(0x50); w0(0xc0); w0(0x30); w0(0xa0); w0(0);
121 w0(0xa); w2(1); w2(4); w0(0x82); w2(4); w2(0xc); w2(4);
122 w2(0x24); w2(0x26); w2(4);
127 static void epia_disconnect ( PIA
*pi
)
129 { /* WR(0x84,0x10); */
136 static void epia_read_block( PIA
*pi
, char * buf
, int count
)
142 case 0: w0(0x81); w2(1); w2(3); w0(0xc1);
144 for (k
=0;k
<count
;k
++) {
153 case 1: w0(0x91); w2(1); w0(0x10); w2(3);
154 w0(0x51); w2(5); w0(0xd1);
156 for (k
=0;k
<count
;k
++) {
165 case 2: w0(0x89); w2(1); w2(0x23); w2(0x21);
167 for (k
=0;k
<count
;k
++) {
175 case 3: if (count
> 512) WR(0x84,3);
177 for (k
=0;k
<count
;k
++) buf
[k
] = r4();
181 case 4: if (count
> 512) WR(0x84,3);
183 for (k
=0;k
<count
/2;k
++) ((u16
*)buf
)[k
] = r4w();
187 case 5: if (count
> 512) WR(0x84,3);
189 for (k
=0;k
<count
/4;k
++) ((u32
*)buf
)[k
] = r4l();
196 static void epia_write_block( PIA
*pi
, char * buf
, int count
)
198 { int ph
, k
, last
, d
;
204 case 2: w0(0xa1); w2(1); w2(3); w2(1); w2(5);
205 ph
= 0; last
= 0x8000;
206 for (k
=0;k
<count
;k
++) {
208 if (d
!= last
) { last
= d
; w0(d
); }
215 case 3: if (count
< 512) WR(0x84,1);
217 for (k
=0;k
<count
;k
++) w4(buf
[k
]);
218 if (count
< 512) WR(0x84,0);
221 case 4: if (count
< 512) WR(0x84,1);
223 for (k
=0;k
<count
/2;k
++) w4w(((u16
*)buf
)[k
]);
224 if (count
< 512) WR(0x84,0);
227 case 5: if (count
< 512) WR(0x84,1);
229 for (k
=0;k
<count
/4;k
++) w4l(((u32
*)buf
)[k
]);
230 if (count
< 512) WR(0x84,0);
237 static int epia_test_proto( PIA
*pi
, char * scratch
, int verbose
)
245 for (k
=0;k
<256;k
++) {
248 if (RR(2) != (k
^0xaa)) e
[j
]++;
257 epia_read_block(pi
,scratch
,512);
258 for (k
=0;k
<256;k
++) {
259 if ((scratch
[2*k
] & 0xff) != ((k
+1) & 0xff)) f
++;
260 if ((scratch
[2*k
+1] & 0xff) != ((-2-k
) & 0xff)) f
++;
266 printk("%s: epia: port 0x%x, mode %d, test=(%d,%d,%d)\n",
267 pi
->device
,pi
->port
,pi
->mode
,e
[0],e
[1],f
);
270 return (e
[0] && e
[1]) || f
;
275 static void epia_log_adapter( PIA
*pi
, char * scratch
, int verbose
)
277 { char *mode_string
[6] = {"4-bit","5/3","8-bit",
278 "EPP-8","EPP-16","EPP-32"};
280 printk("%s: epia %s, Shuttle EPIA at 0x%x, ",
281 pi
->device
,EPIA_VERSION
,pi
->port
);
282 printk("mode %d (%s), delay %d\n",pi
->mode
,
283 mode_string
[pi
->mode
],pi
->delay
);
287 static struct pi_protocol epia
= {
288 .owner
= THIS_MODULE
,
294 .write_regr
= epia_write_regr
,
295 .read_regr
= epia_read_regr
,
296 .write_block
= epia_write_block
,
297 .read_block
= epia_read_block
,
298 .connect
= epia_connect
,
299 .disconnect
= epia_disconnect
,
300 .test_proto
= epia_test_proto
,
301 .log_adapter
= epia_log_adapter
,
304 static int __init
epia_init(void)
306 return paride_register(&epia
);
309 static void __exit
epia_exit(void)
311 paride_unregister(&epia
);
314 MODULE_LICENSE("GPL");
315 module_init(epia_init
)
316 module_exit(epia_exit
)