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
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>
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
)
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);
56 case 1: w0(regr
|0x38|s
); w2(4); w2(6); w2(4); w2(5); w0(8);
60 case 2: w0(regr
|0x08|s
); w2(4); w2(6); w2(4); w2(0xa5); w2(0xa1);
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);
74 static void kbic_write_regr( PIA
*pi
, int cont
, int regr
, int val
)
84 case 2: w0(regr
|0x10|s
); w2(4); w2(6); w2(4);
85 w0(val
); w2(5); w2(4);
90 case 5: w0(0x20|s
); w2(4); w2(6); w2(4); w3(regr
);
98 static void k951_connect ( PIA
*pi
)
100 { pi
->saved_r0
= r0();
105 static void k951_disconnect ( PIA
*pi
)
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();
122 static void k971_disconnect ( PIA
*pi
)
129 /* counts must be congruent to 0 MOD 4, but all known applications
133 static void kbic_read_block( PIA
*pi
, char * buf
, int count
)
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();
146 buf
[2*k
+1] = j44(a
,b
);
151 case 1: w0(0xb8); w2(4); w2(6); w2(4);
152 for (k
=0;k
<count
/4;k
++) {
155 w0(8); buf
[4*k
] = j53(r12w());
156 w0(0xb8); buf
[4*k
+1] = j53(r12w());
158 buf
[4*k
+3] = j53(r12w());
159 w0(8); buf
[4*k
+2] = j53(r12w());
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();
172 case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
173 for (k
=0;k
<count
;k
++) buf
[k
] = r4();
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();
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();
191 static void kbic_write_block( PIA
*pi
, char * buf
, int count
)
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);
206 case 3: w0(0xa0); w2(4); w2(6); w2(4); w3(0);
207 for(k
=0;k
<count
/2;k
++) {
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
));
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
));
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
)
256 static void kbic_release_proto( PIA
*pi
)
261 struct pi_protocol k951
= {"k951",0,6,3,1,1,
277 struct pi_protocol k971
= {"k971",0,6,3,1,1,
294 int init_module(void)
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
);