Merge with Linux 2.4.0-test6-pre9.
[linux-2.6/linux-mips.git] / drivers / block / paride / kbic.c
blob01a9b36d9ff60dd53e3bd0a943d09b1092859136
1 /*
2 kbic.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU public license.
5 This is a low-level driver for the KBIC-951A and KBIC-971A
6 parallel to IDE adapter chips from KingByte Information Systems.
8 The chips are almost identical, however, the wakeup code
9 required for the 971A interferes with the correct operation of
10 the 951A, so this driver registers itself twice, once for
11 each chip.
15 /* Changes:
17 1.01 GRG 1998.05.06 init_proto, release_proto
21 #define KBIC_VERSION "1.01"
23 #include <linux/module.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 #define r12w() (delay_p,inw(pi->port+1)&0xffff)
34 #define j44(a,b) ((((a>>4)&0x0f)|(b&0xf0))^0x88)
35 #define j53(w) (((w>>3)&0x1f)|((w>>4)&0xe0))
38 /* cont = 0 - access the IDE register file
39 cont = 1 - access the IDE command set
42 static int cont_map[2] = { 0x80, 0x40 };
44 static int kbic_read_regr( PIA *pi, int cont, int regr )
46 { int a, b, s;
48 s = cont_map[cont];
50 switch (pi->mode) {
52 case 0: w0(regr|0x18|s); w2(4); w2(6); w2(4); w2(1); w0(8);
53 a = r1(); w0(0x28); b = r1(); w2(4);
54 return j44(a,b);
56 case 1: w0(regr|0x38|s); w2(4); w2(6); w2(4); w2(5); w0(8);
57 a = r12w(); w2(4);
58 return j53(a);
60 case 2: w0(regr|0x08|s); w2(4); w2(6); w2(4); w2(0xa5); w2(0xa1);
61 a = r0(); w2(4);
62 return a;
64 case 3:
65 case 4:
66 case 5: w0(0x20|s); w2(4); w2(6); w2(4); w3(regr);
67 a = r4(); b = r4(); w2(4); w2(0); w2(4);
68 return a;
71 return -1;
74 static void kbic_write_regr( PIA *pi, int cont, int regr, int val)
76 { int s;
78 s = cont_map[cont];
80 switch (pi->mode) {
82 case 0:
83 case 1:
84 case 2: w0(regr|0x10|s); w2(4); w2(6); w2(4);
85 w0(val); w2(5); w2(4);
86 break;
88 case 3:
89 case 4:
90 case 5: w0(0x20|s); w2(4); w2(6); w2(4); w3(regr);
91 w4(val); w4(val);
92 w2(4); w2(0); w2(4);
93 break;
98 static void k951_connect ( PIA *pi )
100 { pi->saved_r0 = r0();
101 pi->saved_r2 = r2();
102 w2(4);
105 static void k951_disconnect ( PIA *pi )
107 { w0(pi->saved_r0);
108 w2(pi->saved_r2);
111 #define CCP(x) w2(0xc4);w0(0xaa);w0(0x55);w0(0);w0(0xff);w0(0x87);\
112 w0(0x78);w0(x);w2(0xc5);w2(0xc4);w0(0xff);
114 static void k971_connect ( PIA *pi )
116 { pi->saved_r0 = r0();
117 pi->saved_r2 = r2();
118 CCP(0x20);
119 w2(4);
122 static void k971_disconnect ( PIA *pi )
124 { CCP(0x30);
125 w0(pi->saved_r0);
126 w2(pi->saved_r2);
129 /* counts must be congruent to 0 MOD 4, but all known applications
130 have this property.
133 static void kbic_read_block( PIA *pi, char * buf, int count )
135 { int k, a, b;
137 switch (pi->mode) {
139 case 0: w0(0x98); w2(4); w2(6); w2(4);
140 for (k=0;k<count/2;k++) {
141 w2(1); w0(8); a = r1();
142 w0(0x28); b = r1();
143 buf[2*k] = j44(a,b);
144 w2(5); b = r1();
145 w0(8); a = r1();
146 buf[2*k+1] = j44(a,b);
147 w2(4);
149 break;
151 case 1: w0(0xb8); w2(4); w2(6); w2(4);
152 for (k=0;k<count/4;k++) {
153 w0(0xb8);
154 w2(4); w2(5);
155 w0(8); buf[4*k] = j53(r12w());
156 w0(0xb8); buf[4*k+1] = j53(r12w());
157 w2(4); w2(5);
158 buf[4*k+3] = j53(r12w());
159 w0(8); buf[4*k+2] = j53(r12w());
161 w2(4);
162 break;
164 case 2: w0(0x88); w2(4); w2(6); w2(4);
165 for (k=0;k<count/2;k++) {
166 w2(0xa0); w2(0xa1); buf[2*k] = r0();
167 w2(0xa5); buf[2*k+1] = r0();
169 w2(4);
170 break;
172 case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
173 for (k=0;k<count;k++) buf[k] = r4();
174 w2(4); w2(0); w2(4);
175 break;
177 case 4: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
178 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
179 w2(4); w2(0); w2(4);
180 break;
182 case 5: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
183 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
184 w2(4); w2(0); w2(4);
185 break;
191 static void kbic_write_block( PIA *pi, char * buf, int count )
193 { int k;
195 switch (pi->mode) {
197 case 0:
198 case 1:
199 case 2: w0(0x90); w2(4); w2(6); w2(4);
200 for(k=0;k<count/2;k++) {
201 w0(buf[2*k+1]); w2(0); w2(4);
202 w0(buf[2*k]); w2(5); w2(4);
204 break;
206 case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
207 for(k=0;k<count/2;k++) {
208 w4(buf[2*k+1]);
209 w4(buf[2*k]);
211 w2(4); w2(0); w2(4);
212 break;
214 case 4: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
215 for(k=0;k<count/2;k++) w4w(pi_swab16(buf,k));
216 w2(4); w2(0); w2(4);
217 break;
219 case 5: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
220 for(k=0;k<count/4;k++) w4l(pi_swab32(buf,k));
221 w2(4); w2(0); w2(4);
222 break;
228 static void kbic_log_adapter( PIA *pi, char * scratch,
229 int verbose, char * chip )
231 { char *mode_string[6] = {"4-bit","5/3","8-bit",
232 "EPP-8","EPP_16","EPP-32"};
234 printk("%s: kbic %s, KingByte %s at 0x%x, ",
235 pi->device,KBIC_VERSION,chip,pi->port);
236 printk("mode %d (%s), delay %d\n",pi->mode,
237 mode_string[pi->mode],pi->delay);
241 static void k951_log_adapter( PIA *pi, char * scratch, int verbose )
243 { kbic_log_adapter(pi,scratch,verbose,"KBIC-951A");
246 static void k971_log_adapter( PIA *pi, char * scratch, int verbose )
248 { kbic_log_adapter(pi,scratch,verbose,"KBIC-971A");
251 static void kbic_init_proto( PIA *pi)
253 { MOD_INC_USE_COUNT;
256 static void kbic_release_proto( PIA *pi)
258 { MOD_DEC_USE_COUNT;
261 struct pi_protocol k951 = {"k951",0,6,3,1,1,
262 kbic_write_regr,
263 kbic_read_regr,
264 kbic_write_block,
265 kbic_read_block,
266 k951_connect,
267 k951_disconnect,
271 k951_log_adapter,
272 kbic_init_proto,
273 kbic_release_proto
277 struct pi_protocol k971 = {"k971",0,6,3,1,1,
278 kbic_write_regr,
279 kbic_read_regr,
280 kbic_write_block,
281 kbic_read_block,
282 k971_connect,
283 k971_disconnect,
287 k971_log_adapter,
288 kbic_init_proto,
289 kbic_release_proto
292 #ifdef MODULE
294 int init_module(void)
296 { int s5,s7;
298 s5 = pi_register(&k951);
299 s7 = pi_register(&k971);
301 return (s5 || s7) - 1;
304 void cleanup_module(void)
306 { pi_unregister( &k951 );
307 pi_unregister( &k971 );
310 #endif
312 /* end of kbic.c */