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
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/delay.h>
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/wait.h>
20 #include "pata_parport.h"
22 /* mode codes: 0 nybble reads on port 1, 8-bit writes
23 1 5/3 reads on ports 1 & 2, 8-bit writes
24 2 8-bit reads and writes
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
37 static int cont_map[2] = { 0, 0x80 };
39 static int epia_read_regr(struct pi_adapter *pi, int cont, int regr)
43 regr += cont_map[cont];
47 case 0: r = regr^0x39;
48 w0(r); w2(1); w2(3); w0(r);
49 a = r1(); w2(1); b = r1(); w2(4);
52 case 1: r = regr^0x31;
53 w0(r); w2(1); w0(r&0x37);
54 w2(3); w2(5); w0(r|0xf0);
55 a = r1(); b = r2(); w2(4);
58 case 2: r = regr^0x29;
59 w0(r); w2(1); w2(0X21); w2(0x23);
65 case 5: w3(regr); w2(0x24); a = r4(); w2(4);
72 static void epia_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
76 regr += cont_map[cont];
82 case 2: r = regr^0x19;
83 w0(r); w2(1); w0(val); w2(3); w2(4);
88 case 5: r = regr^0x40;
89 w3(r); w4(val); w2(4);
94 #define WR(r,v) epia_write_regr(pi,0,r,v)
95 #define RR(r) (epia_read_regr(pi,0,r))
97 /* The use of register 0x84 is entirely unclear - it seems to control
98 some EPP counters ... currently we know about 3 different block
99 sizes: the standard 512 byte reads and writes, 12 byte writes and
100 2048 byte reads (the last two being used in the CDrom drivers.
103 static void epia_connect(struct pi_adapter *pi)
105 { pi->saved_r0 = r0();
108 w2(4); w0(0xa0); w0(0x50); w0(0xc0); w0(0x30); w0(0xa0); w0(0);
111 w0(0xa); w2(1); w2(4); w0(0x82); w2(4); w2(0xc); w2(4);
112 w2(0x24); w2(0x26); w2(4);
117 static void epia_disconnect(struct pi_adapter *pi)
119 { /* WR(0x84,0x10); */
126 static void epia_read_block(struct pi_adapter *pi, char *buf, int count)
132 case 0: w0(0x81); w2(1); w2(3); w0(0xc1);
134 for (k=0;k<count;k++) {
143 case 1: w0(0x91); w2(1); w0(0x10); w2(3);
144 w0(0x51); w2(5); w0(0xd1);
146 for (k=0;k<count;k++) {
155 case 2: w0(0x89); w2(1); w2(0x23); w2(0x21);
157 for (k=0;k<count;k++) {
165 case 3: if (count > 512) WR(0x84,3);
167 for (k=0;k<count;k++) buf[k] = r4();
171 case 4: if (count > 512) WR(0x84,3);
173 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
177 case 5: if (count > 512) WR(0x84,3);
179 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
186 static void epia_write_block(struct pi_adapter *pi, char *buf, int count)
188 { int ph, k, last, d;
194 case 2: w0(0xa1); w2(1); w2(3); w2(1); w2(5);
195 ph = 0; last = 0x8000;
196 for (k=0;k<count;k++) {
198 if (d != last) { last = d; w0(d); }
205 case 3: if (count < 512) WR(0x84,1);
207 for (k=0;k<count;k++) w4(buf[k]);
208 if (count < 512) WR(0x84,0);
211 case 4: if (count < 512) WR(0x84,1);
213 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
214 if (count < 512) WR(0x84,0);
217 case 5: if (count < 512) WR(0x84,1);
219 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
220 if (count < 512) WR(0x84,0);
227 static int epia_test_proto(struct pi_adapter *pi)
236 for (k=0;k<256;k++) {
239 if (RR(2) != (k^0xaa)) e[j]++;
248 epia_read_block(pi,scratch,512);
249 for (k=0;k<256;k++) {
250 if ((scratch[2*k] & 0xff) != ((k+1) & 0xff)) f++;
251 if ((scratch[2*k+1] & 0xff) != ((-2-k) & 0xff)) f++;
256 dev_dbg(&pi->dev, "epia: port 0x%x, mode %d, test=(%d,%d,%d)\n",
257 pi->port, pi->mode, e[0], e[1], f);
259 return (e[0] && e[1]) || f;
264 static void epia_log_adapter(struct pi_adapter *pi)
266 { char *mode_string[6] = {"4-bit","5/3","8-bit",
267 "EPP-8","EPP-16","EPP-32"};
269 dev_info(&pi->dev, "Shuttle EPIA at 0x%x, mode %d (%s), delay %d\n",
270 pi->port, pi->mode, mode_string[pi->mode], pi->delay);
273 static struct pi_protocol epia = {
274 .owner = THIS_MODULE,
280 .write_regr = epia_write_regr,
281 .read_regr = epia_read_regr,
282 .write_block = epia_write_block,
283 .read_block = epia_read_block,
284 .connect = epia_connect,
285 .disconnect = epia_disconnect,
286 .test_proto = epia_test_proto,
287 .log_adapter = epia_log_adapter,
290 MODULE_LICENSE("GPL");
291 module_pata_parport_driver(epia);