17 #define BPCK_VERSION "1.02"
19 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/types.h>
24 #include <linux/wait.h>
32 #define PC pi->private
33 #define r2() (PC=(in_p(2) & 0xff))
34 #define w2(byte) {out_p(2,byte); PC = byte;}
35 #define t2(pat) {PC ^= pat; out_p(2,PC);}
36 #define e2() {PC &= 0xfe; out_p(2,PC);}
37 #define o2() {PC |= 1; out_p(2,PC);}
39 #define j44(l,h) (((l>>3)&0x7)|((l>>4)&0x8)|((h<<1)&0x70)|(h&0x80))
46 static int cont_map[3] = { 0x40, 0x48, 0 };
48 static int bpck_read_regr(
PIA *pi,
int cont,
int regr )
52 r = regr + cont_map[
cont];
56 case 0:
w0(r & 0xf);
w0(r);
t2(2);
t2(4);
62 case 1:
w0(r & 0xf);
w0(r);
t2(2);
70 case 4:
w0(r);
w2(9);
w2(0);
w2(0x20);
79 static void bpck_write_regr(
PIA *pi,
int cont,
int regr,
int val )
83 r = regr + cont_map[
cont];
96 case 4:
w0(r);
w2(9);
w2(0);
105 #define WR(r,v) bpck_write_regr(pi,2,r,v)
106 #define RR(r) (bpck_read_regr(pi,2,r))
108 static void bpck_write_block(
PIA *pi,
char *
buf,
int count )
116 for (i=0;i<
count;i++) {
w0(buf[i]);
t2(4); }
122 for (i=0;i<
count;i++) {
w0(buf[i]);
t2(4); }
128 for (i=0;i<
count;i++)
w4(buf[i]);
135 for (i=0;i<count/2;i++)
w4w(((
u16 *)buf)[i]);
142 for (i=0;i<count/4;i++)
w4l(((
u32 *)buf)[i]);
149 static void bpck_read_block(
PIA *pi,
char *
buf,
int count )
157 for (i=0;i<
count;i++) {
166 w0(0x40);
t2(2);
t2(0x20);
167 for(i=0;i<
count;i++) {
t2(4); buf[
i] =
r0(); }
174 for (i=0;i<
count;i++) buf[i] =
r4();
181 for (i=0;i<count/2;i++) ((
u16 *)buf)[
i] =
r4w();
188 for (i=0;i<count/4;i++) ((
u32 *)buf)[
i] =
r4l();
196 static int bpck_probe_unit (
PIA *pi )
198 {
int o1, o0,
f7,
id;
206 w0(255-
id);
w2(4);
w0(
id);
208 t2(2); t =
r1()&0xf8;
209 f7 = ((
id % 8) == 7);
210 if ((f7) || (t != o1)) {
t2(2); s =
r1()&0xf8; }
211 if ((t == o1) && ((!f7) || (s == o1))) {
219 static void bpck_connect (
PIA *pi )
228 case 0:
t2(8);
WR(4,0);
231 case 1:
t2(8);
WR(4,0x10);
236 case 4:
w2(0);
WR(4,8);
253 static void bpck_disconnect (
PIA *pi )
256 if (pi->
mode >= 2) {
w2(9);
w2(0); }
else t2(2);
260 static void bpck_force_spp (
PIA *pi )
280 {
int i,
e,
l,
h, om;
287 case 0: bpck_connect(pi);
298 case 1: bpck_connect(pi);
300 w0(0x13);
t2(2);
t2(0x20);
308 case 4: om = pi->
mode;
320 case 2:
for (i=0;i<
TEST_LEN;i++) buf[i] =
r4();
322 case 3:
for (i=0;i<TEST_LEN/2;i++) ((
u16 *)buf)[
i] =
r4w();
324 case 4:
for (i=0;i<TEST_LEN/4;i++) ((
u32 *)buf)[
i] =
r4l();
337 printk(
"%s: bpck: 0x%x unit %d mode %d: ",
344 for (i=0;i<
TEST_LEN;i++)
if (buf[i] != (i+1)) e++;
348 static void bpck_read_eeprom (
PIA *pi,
char * buf )
366 f = (((i + 0x180) & p) != 0) * 2;
379 v = 2*v + (f == 0x84);
400 static int bpck_test_port (
PIA *pi )
404 w2(0x2c); i =
r0();
w0(255-i); r =
r0();
w0(i);
407 if (r == (255-i)) m = 0;
410 if (r != (255-i)) m = -1;
412 if (m == 0) {
w2(6);
w2(0
xc); r =
r0();
w0(0xaa);
w0(r);
w0(0xaa); }
413 if (m == 2) {
w2(0x26);
w2(0
xc); }
415 if (m == -1)
return 0;
421 {
char *mode_string[5] = {
"4-bit",
"8-bit",
"EPP-8",
428 bpck_read_eeprom(pi,scratch);
433 if ((scratch[i] <
' ') || (scratch[i] >
'~'))
435 printk(
"%s: bpck EEPROM: %64.64s\n",pi->
device,scratch);
440 printk(
"%s: bpck %s, backpack %8.8s unit %d",
442 printk(
" at 0x%x, mode %d (%s), delay %d\n",pi->
port,
453 .write_regr = bpck_write_regr,
454 .read_regr = bpck_read_regr,
455 .write_block = bpck_write_block,
456 .read_block = bpck_read_block,
457 .connect = bpck_connect,
458 .disconnect = bpck_disconnect,
459 .test_port = bpck_test_port,
460 .probe_unit = bpck_probe_unit,
461 .test_proto = bpck_test_proto,
462 .log_adapter = bpck_log_adapter,
465 static int __init bpck_init(
void)
470 static void __exit bpck_exit(
void)