2 bpck.c (c) 1996-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU General Public License.
5 bpck.c is a low-level protocol driver for the MicroSolutions
6 "backpack" parallel port IDE adapter.
12 1.01 GRG 1998.05.05 init_proto, release_proto, pi->delay
13 1.02 GRG 1998.08.15 default pi->delay returned to 4
17 #define BPCK_VERSION "1.02"
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/delay.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))
41 /* cont = 0 - access the IDE register file
42 cont = 1 - access the IDE command set
43 cont = 2 - use internal bpck register addressing
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);
97 w0(val
); w2(1); w2(3); w2(0);
103 /* These macros access the bpck registers in native addressing */
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
)
115 w0(0x40); t2(2); t2(1);
116 for (i
=0;i
<count
;i
++) { w0(buf
[i
]); t2(4); }
121 w0(0x40); t2(2); t2(1);
122 for (i
=0;i
<count
;i
++) { w0(buf
[i
]); t2(4); }
127 w0(0x40); w2(9); w2(0); w2(1);
128 for (i
=0;i
<count
;i
++) w4(buf
[i
]);
134 w0(0x40); w2(9); w2(0); w2(1);
135 for (i
=0;i
<count
/2;i
++) w4w(((u16
*)buf
)[i
]);
141 w0(0x40); w2(9); w2(0); w2(1);
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(); }
173 w0(0x40); w2(9); w2(0); w2(0x20);
174 for (i
=0;i
<count
;i
++) buf
[i
] = r4();
180 w0(0x40); w2(9); w2(0); w2(0x20);
181 for (i
=0;i
<count
/2;i
++) ((u16
*)buf
)[i
] = r4w();
187 w0(0x40); w2(9); w2(0); w2(0x20);
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
;
203 w2(4); w2(0xe); r2(); t2(2);
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
))) {
215 t2(8); w0(0); t2(2); w2(0x4c); w0(o0
);
219 static void bpck_connect ( PIA
*pi
)
221 { pi
->saved_r0
= r0();
222 w0(0xff-pi
->unit
); w2(4); w0(pi
->unit
);
228 case 0: t2(8); WR(4,0);
231 case 1: t2(8); WR(4,0x10);
236 case 4: w2(0); WR(4,8);
243 if (pi
->devtype
== PI_PCD
) {
244 WR(0x46,0x10); /* fiddle with ESS logic ??? */
253 static void bpck_disconnect ( PIA
*pi
)
256 if (pi
->mode
>= 2) { w2(9); w2(0); } else t2(2);
257 w2(0x4c); w0(pi
->saved_r0
);
260 static void bpck_force_spp ( PIA
*pi
)
262 /* This fakes the EPP protocol to turn off EPP ... */
264 { pi
->saved_r0
= r0();
265 w0(0xff-pi
->unit
); w2(4); w0(pi
->unit
);
271 w0(0); w2(1); w2(3); w2(0);
273 w2(0x4c); w0(pi
->saved_r0
);
278 static int bpck_test_proto( PIA
*pi
, char * scratch
, int verbose
)
280 { int i
, e
, l
, h
, om
;
287 case 0: bpck_connect(pi
);
290 for(i
=0;i
<TEST_LEN
;i
++) {
298 case 1: bpck_connect(pi
);
300 w0(0x13); t2(2); t2(0x20);
301 for(i
=0;i
<TEST_LEN
;i
++) { t2(4); buf
[i
] = r0(); }
308 case 4: om
= pi
->mode
;
317 w0(0x13); w2(9); w2(1); w0(0); w2(3); w2(0); w2(0xe0);
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: ",
338 pi
->device
,pi
->port
,pi
->unit
,pi
->mode
);
339 for (i
=0;i
<TEST_LEN
;i
++) printk("%3d",buf
[i
]);
344 for (i
=0;i
<TEST_LEN
;i
++) if (buf
[i
] != (i
+1)) e
++;
348 static void bpck_read_eeprom ( PIA
*pi
, char * buf
)
350 { int i
,j
,k
,n
,p
,v
,f
, om
, od
;
354 om
= pi
->mode
; od
= pi
->delay
;
355 pi
->mode
= 0; pi
->delay
= 6;
366 f
= (((i
+ 0x180) & p
) != 0) * 2;
379 v
= 2*v
+ (f
== 0x84);
397 pi
->mode
= om
; pi
->delay
= od
;
400 static int bpck_test_port ( PIA
*pi
) /* check for 8-bit port */
404 w2(0x2c); i
= r0(); w0(255-i
); r
= r0(); w0(i
);
407 if (r
== (255-i
)) m
= 0;
409 w2(0xc); i
= r0(); w0(255-i
); r
= r0(); w0(i
);
410 if (r
!= (255-i
)) m
= -1;
412 if (m
== 0) { w2(6); w2(0xc); r
= r0(); w0(0xaa); w0(r
); w0(0xaa); }
413 if (m
== 2) { w2(0x26); w2(0xc); }
415 if (m
== -1) return 0;
419 static void bpck_log_adapter( PIA
*pi
, char * scratch
, int verbose
)
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
);
436 printk("%s: %64.64s\n",pi
->device
,&scratch
[64]);
440 printk("%s: bpck %s, backpack %8.8s unit %d",
441 pi
->device
,BPCK_VERSION
,&scratch
[110],pi
->unit
);
442 printk(" at 0x%x, mode %d (%s), delay %d\n",pi
->port
,
443 pi
->mode
,mode_string
[pi
->mode
],pi
->delay
);
446 static struct pi_protocol bpck
= {
447 .owner
= THIS_MODULE
,
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)
467 return paride_register(&bpck
)-1;
470 static void __exit
bpck_exit(void)
472 paride_unregister(&bpck
);
475 MODULE_LICENSE("GPL");
476 module_init(bpck_init
)
477 module_exit(bpck_exit
)