2 kbic.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU General 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
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/init.h>
25 #include <linux/delay.h>
26 #include <linux/kernel.h>
27 #include <linux/types.h>
28 #include <linux/wait.h>
33 #define r12w() (delay_p,inw(pi->port+1)&0xffff)
35 #define j44(a,b) ((((a>>4)&0x0f)|(b&0xf0))^0x88)
36 #define j53(w) (((w>>3)&0x1f)|((w>>4)&0xe0))
39 /* cont = 0 - access the IDE register file
40 cont = 1 - access the IDE command set
43 static int cont_map[2] = { 0x80, 0x40 };
45 static int kbic_read_regr( PIA *pi, int cont, int regr )
53 case 0: w0(regr|0x18|s); w2(4); w2(6); w2(4); w2(1); w0(8);
54 a = r1(); w0(0x28); b = r1(); w2(4);
57 case 1: w0(regr|0x38|s); w2(4); w2(6); w2(4); w2(5); w0(8);
61 case 2: w0(regr|0x08|s); w2(4); w2(6); w2(4); w2(0xa5); w2(0xa1);
67 case 5: w0(0x20|s); w2(4); w2(6); w2(4); w3(regr);
68 a = r4(); b = r4(); w2(4); w2(0); w2(4);
75 static void kbic_write_regr( PIA *pi, int cont, int regr, int val)
85 case 2: w0(regr|0x10|s); w2(4); w2(6); w2(4);
86 w0(val); w2(5); w2(4);
91 case 5: w0(0x20|s); w2(4); w2(6); w2(4); w3(regr);
99 static void k951_connect ( PIA *pi )
101 { pi->saved_r0 = r0();
106 static void k951_disconnect ( PIA *pi )
112 #define CCP(x) w2(0xc4);w0(0xaa);w0(0x55);w0(0);w0(0xff);w0(0x87);\
113 w0(0x78);w0(x);w2(0xc5);w2(0xc4);w0(0xff);
115 static void k971_connect ( PIA *pi )
117 { pi->saved_r0 = r0();
123 static void k971_disconnect ( PIA *pi )
130 /* counts must be congruent to 0 MOD 4, but all known applications
134 static void kbic_read_block( PIA *pi, char * buf, int count )
140 case 0: w0(0x98); w2(4); w2(6); w2(4);
141 for (k=0;k<count/2;k++) {
142 w2(1); w0(8); a = r1();
147 buf[2*k+1] = j44(a,b);
152 case 1: w0(0xb8); w2(4); w2(6); w2(4);
153 for (k=0;k<count/4;k++) {
156 w0(8); buf[4*k] = j53(r12w());
157 w0(0xb8); buf[4*k+1] = j53(r12w());
159 buf[4*k+3] = j53(r12w());
160 w0(8); buf[4*k+2] = j53(r12w());
165 case 2: w0(0x88); w2(4); w2(6); w2(4);
166 for (k=0;k<count/2;k++) {
167 w2(0xa0); w2(0xa1); buf[2*k] = r0();
168 w2(0xa5); buf[2*k+1] = r0();
173 case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
174 for (k=0;k<count;k++) buf[k] = r4();
178 case 4: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
179 for (k=0;k<count/2;k++) ((u16 *)buf)[k] = r4w();
183 case 5: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
184 for (k=0;k<count/4;k++) ((u32 *)buf)[k] = r4l();
192 static void kbic_write_block( PIA *pi, char * buf, int count )
200 case 2: w0(0x90); w2(4); w2(6); w2(4);
201 for(k=0;k<count/2;k++) {
202 w0(buf[2*k+1]); w2(0); w2(4);
203 w0(buf[2*k]); w2(5); w2(4);
207 case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
208 for(k=0;k<count/2;k++) {
215 case 4: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
216 for(k=0;k<count/2;k++) w4w(pi_swab16(buf,k));
220 case 5: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
221 for(k=0;k<count/4;k++) w4l(pi_swab32(buf,k));
229 static void kbic_log_adapter( PIA *pi, char * scratch,
230 int verbose, char * chip )
232 { char *mode_string[6] = {"4-bit","5/3","8-bit",
233 "EPP-8","EPP_16","EPP-32"};
235 printk("%s: kbic %s, KingByte %s at 0x%x, ",
236 pi->device,KBIC_VERSION,chip,pi->port);
237 printk("mode %d (%s), delay %d\n",pi->mode,
238 mode_string[pi->mode],pi->delay);
242 static void k951_log_adapter( PIA *pi, char * scratch, int verbose )
244 { kbic_log_adapter(pi,scratch,verbose,"KBIC-951A");
247 static void k971_log_adapter( PIA *pi, char * scratch, int verbose )
249 { kbic_log_adapter(pi,scratch,verbose,"KBIC-971A");
252 static struct pi_protocol k951 = {
253 .owner = THIS_MODULE,
259 .write_regr = kbic_write_regr,
260 .read_regr = kbic_read_regr,
261 .write_block = kbic_write_block,
262 .read_block = kbic_read_block,
263 .connect = k951_connect,
264 .disconnect = k951_disconnect,
265 .log_adapter = k951_log_adapter,
268 static struct pi_protocol k971 = {
269 .owner = THIS_MODULE,
275 .write_regr = kbic_write_regr,
276 .read_regr = kbic_read_regr,
277 .write_block = kbic_write_block,
278 .read_block = kbic_read_block,
279 .connect = k971_connect,
280 .disconnect = k971_disconnect,
281 .log_adapter = k971_log_adapter,
284 static int __init kbic_init(void)
288 rv = paride_register(&k951);
291 rv = paride_register(&k971);
293 paride_unregister(&k951);
297 static void __exit kbic_exit(void)
299 paride_unregister(&k951);
300 paride_unregister(&k971);
303 MODULE_LICENSE("GPL");
304 module_init(kbic_init)
305 module_exit(kbic_exit)