Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / drivers / block / paride / epia.c
blobfb0e782d055e455dd1863d6be83ef90423eb0a4a
1 /*
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
9 available.
13 /* Changes:
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>
28 #include <asm/io.h>
30 #include "paride.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
35 3 8-bit EPP mode
36 4 16-bit EPP
37 5 32-bit EPP
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 )
51 { int a, b, r;
53 regr += cont_map[cont];
55 switch (pi->mode) {
57 case 0: r = regr^0x39;
58 w0(r); w2(1); w2(3); w0(r);
59 a = r1(); w2(1); b = r1(); w2(4);
60 return j44(a,b);
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);
66 return j53(a,b);
68 case 2: r = regr^0x29;
69 w0(r); w2(1); w2(0X21); w2(0x23);
70 a = r0(); w2(4);
71 return a;
73 case 3:
74 case 4:
75 case 5: w3(regr); w2(0x24); a = r4(); w2(4);
76 return a;
79 return -1;
82 static void epia_write_regr( PIA *pi, int cont, int regr, int val)
84 { int r;
86 regr += cont_map[cont];
88 switch (pi->mode) {
90 case 0:
91 case 1:
92 case 2: r = regr^0x19;
93 w0(r); w2(1); w0(val); w2(3); w2(4);
94 break;
96 case 3:
97 case 4:
98 case 5: r = regr^0x40;
99 w3(r); w4(val); w2(4);
100 break;
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();
116 pi->saved_r2 = r2();
118 w2(4); w0(0xa0); w0(0x50); w0(0xc0); w0(0x30); w0(0xa0); w0(0);
119 w2(1); w2(4);
120 if (pi->mode >= 3) {
121 w0(0xa); w2(1); w2(4); w0(0x82); w2(4); w2(0xc); w2(4);
122 w2(0x24); w2(0x26); w2(4);
124 WR(0x86,8);
127 static void epia_disconnect ( PIA *pi )
129 { /* WR(0x84,0x10); */
130 w0(pi->saved_r0);
131 w2(1); w2(4);
132 w0(pi->saved_r0);
133 w2(pi->saved_r2);
136 static void epia_read_block( PIA *pi, char * buf, int count )
138 { int k, ph, a, b;
140 switch (pi->mode) {
142 case 0: w0(0x81); w2(1); w2(3); w0(0xc1);
143 ph = 1;
144 for (k=0;k<count;k++) {
145 w2(2+ph); a = r1();
146 w2(4+ph); b = r1();
147 buf[k] = j44(a,b);
148 ph = 1 - ph;
150 w0(0); w2(4);
151 break;
153 case 1: w0(0x91); w2(1); w0(0x10); w2(3);
154 w0(0x51); w2(5); w0(0xd1);
155 ph = 1;
156 for (k=0;k<count;k++) {
157 w2(4+ph);
158 a = r1(); b = r2();
159 buf[k] = j53(a,b);
160 ph = 1 - ph;
162 w0(0); w2(4);
163 break;
165 case 2: w0(0x89); w2(1); w2(0x23); w2(0x21);
166 ph = 1;
167 for (k=0;k<count;k++) {
168 w2(0x24+ph);
169 buf[k] = r0();
170 ph = 1 - ph;
172 w2(6); w2(4);
173 break;
175 case 3: if (count > 512) WR(0x84,3);
176 w3(0); w2(0x24);
177 for (k=0;k<count;k++) buf[k] = r4();
178 w2(4); WR(0x84,0);
179 break;
181 case 4: if (count > 512) WR(0x84,3);
182 w3(0); w2(0x24);
183 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
184 w2(4); WR(0x84,0);
185 break;
187 case 5: if (count > 512) WR(0x84,3);
188 w3(0); w2(0x24);
189 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
190 w2(4); WR(0x84,0);
191 break;
196 static void epia_write_block( PIA *pi, char * buf, int count )
198 { int ph, k, last, d;
200 switch (pi->mode) {
202 case 0:
203 case 1:
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++) {
207 d = buf[k];
208 if (d != last) { last = d; w0(d); }
209 w2(4+ph);
210 ph = 1 - ph;
212 w2(7); w2(4);
213 break;
215 case 3: if (count < 512) WR(0x84,1);
216 w3(0x40);
217 for (k=0;k<count;k++) w4(buf[k]);
218 if (count < 512) WR(0x84,0);
219 break;
221 case 4: if (count < 512) WR(0x84,1);
222 w3(0x40);
223 for (k=0;k<count/2;k++) w4w(((u16 *)buf)[k]);
224 if (count < 512) WR(0x84,0);
225 break;
227 case 5: if (count < 512) WR(0x84,1);
228 w3(0x40);
229 for (k=0;k<count/4;k++) w4l(((u32 *)buf)[k]);
230 if (count < 512) WR(0x84,0);
231 break;
237 static int epia_test_proto( PIA *pi, char * scratch, int verbose )
239 { int j, k, f;
240 int e[2] = {0,0};
242 epia_connect(pi);
243 for (j=0;j<2;j++) {
244 WR(6,0xa0+j*0x10);
245 for (k=0;k<256;k++) {
246 WR(2,k^0xaa);
247 WR(3,k^0x55);
248 if (RR(2) != (k^0xaa)) e[j]++;
250 WR(2,1); WR(3,1);
252 epia_disconnect(pi);
254 f = 0;
255 epia_connect(pi);
256 WR(0x84,8);
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++;
262 WR(0x84,0);
263 epia_disconnect(pi);
265 if (verbose) {
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,
289 .name = "epia",
290 .max_mode = 6,
291 .epp_first = 3,
292 .default_delay = 1,
293 .max_units = 1,
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)