2 frpw.c (c) 1996-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU General Public License
5 frpw.c is a low-level protocol driver for the Freecom "Power"
6 parallel port IDE adapter.
8 Some applications of this adapter may require a "printer" reset
9 prior to loading the driver. This can be done by loading and
10 unloading the "lp" driver, or it can be done by this driver
11 if you define FRPW_HARD_RESET. The latter is not recommended
12 as it may upset devices on other ports.
18 1.01 GRG 1998.05.06 init_proto, release_proto
20 added EPP-16 and EPP-32
21 1.02 GRG 1998.09.23 added hard reset to initialisation process
22 1.03 GRG 1998.12.14 made hard reset conditional
26 #define FRPW_VERSION "1.03"
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/delay.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
33 #include <linux/wait.h>
38 #define cec4 w2(0xc);w2(0xe);w2(0xe);w2(0xc);w2(4);w2(4);w2(4);
39 #define j44(l,h) (((l>>4)&0x0f)|(h&0xf0))
41 /* cont = 0 - access the IDE register file
42 cont = 1 - access the IDE command set
45 static int cont_map
[2] = { 0x08, 0x10 };
47 static int frpw_read_regr( PIA
*pi
, int cont
, int regr
)
51 r
= regr
+ cont_map
[cont
];
63 static void frpw_write_regr( PIA
*pi
, int cont
, int regr
, int val
)
67 r
= regr
+ cont_map
[cont
];
71 w2(5);w2(7);w2(5);w2(4);
74 static void frpw_read_block_int( PIA
*pi
, char * buf
, int count
, int regr
)
80 case 0: w2(4); w0(regr
); cec4
;
81 for (k
=0;k
<count
;k
++) {
90 w2(4); w0(regr
+ 0xc0); cec4
;
92 for (k
=0;k
<count
;k
++) {
97 w2(0xac); w2(0xa4); w2(4);
100 case 2: w2(4); w0(regr
+ 0x80); cec4
;
101 for (k
=0;k
<count
;k
++) buf
[k
] = r4();
106 case 3: w2(4); w0(regr
+ 0x80); cec4
;
107 for (k
=0;k
<count
-2;k
++) buf
[k
] = r4();
114 case 4: w2(4); w0(regr
+ 0x80); cec4
;
115 for (k
=0;k
<(count
/2)-1;k
++) ((u16
*)buf
)[k
] = r4w();
122 case 5: w2(4); w0(regr
+ 0x80); cec4
;
123 for (k
=0;k
<(count
/4)-1;k
++) ((u32
*)buf
)[k
] = r4l();
135 static void frpw_read_block( PIA
*pi
, char * buf
, int count
)
137 { frpw_read_block_int(pi
,buf
,count
,0x08);
140 static void frpw_write_block( PIA
*pi
, char * buf
, int count
)
148 case 2: w2(4); w0(8); cec4
; w2(5);
149 for (k
=0;k
<count
;k
++) {
156 case 3: w2(4); w0(0xc8); cec4
; w2(5);
157 for (k
=0;k
<count
;k
++) w4(buf
[k
]);
161 case 4: w2(4); w0(0xc8); cec4
; w2(5);
162 for (k
=0;k
<count
/2;k
++) w4w(((u16
*)buf
)[k
]);
166 case 5: w2(4); w0(0xc8); cec4
; w2(5);
167 for (k
=0;k
<count
/4;k
++) w4l(((u32
*)buf
)[k
]);
173 static void frpw_connect ( PIA
*pi
)
175 { pi
->saved_r0
= r0();
180 static void frpw_disconnect ( PIA
*pi
)
182 { w2(4); w0(0x20); cec4
;
187 /* Stub logic to see if PNP string is available - used to distinguish
188 between the Xilinx and ASIC implementations of the Freecom adapter.
191 static int frpw_test_pnp ( PIA
*pi
)
193 /* returns chip_type: 0 = Xilinx, 1 = ASIC */
195 { int olddelay
, a
, b
;
197 #ifdef FRPW_HARD_RESET
198 w0(0); w2(8); udelay(50); w2(0xc); /* parallel bus reset */
202 olddelay
= pi
->delay
;
208 w2(4); w0(4); w2(6); w2(7);
209 a
= r1() & 0xff; w2(4); b
= r1() & 0xff;
210 w2(0xc); w2(0xe); w2(4);
212 pi
->delay
= olddelay
;
216 return ((~a
&0x40) && (b
&0x40));
219 /* We use the pi->private to remember the result of the PNP test.
220 To make this work, private = port*2 + chip. Yes, I know it's
224 static int frpw_test_proto( PIA
*pi
, char * scratch
, int verbose
)
229 if ((pi
->private>>1) != pi
->port
)
230 pi
->private = frpw_test_pnp(pi
) + 2*pi
->port
;
232 if (((pi
->private%2) == 0) && (pi
->mode
> 2)) {
234 printk("%s: frpw: Xilinx does not support mode %d\n",
235 pi
->device
, pi
->mode
);
239 if (((pi
->private%2) == 1) && (pi
->mode
== 2)) {
241 printk("%s: frpw: ASIC does not support mode 2\n",
248 frpw_write_regr(pi
,0,6,0xa0+j
*0x10);
249 for (k
=0;k
<256;k
++) {
250 frpw_write_regr(pi
,0,2,k
^0xaa);
251 frpw_write_regr(pi
,0,3,k
^0x55);
252 if (frpw_read_regr(pi
,0,2) != (k
^0xaa)) e
[j
]++;
258 frpw_read_block_int(pi
,scratch
,512,0x10);
260 for (k
=0;k
<128;k
++) if (scratch
[k
] != k
) r
++;
264 printk("%s: frpw: port 0x%x, chip %ld, mode %d, test=(%d,%d,%d)\n",
265 pi
->device
,pi
->port
,(pi
->private%2),pi
->mode
,e
[0],e
[1],r
);
268 return (r
|| (e
[0] && e
[1]));
272 static void frpw_log_adapter( PIA
*pi
, char * scratch
, int verbose
)
274 { char *mode_string
[6] = {"4-bit","8-bit","EPP",
275 "EPP-8","EPP-16","EPP-32"};
277 printk("%s: frpw %s, Freecom (%s) adapter at 0x%x, ", pi
->device
,
278 FRPW_VERSION
,((pi
->private%2) == 0)?"Xilinx":"ASIC",pi
->port
);
279 printk("mode %d (%s), delay %d\n",pi
->mode
,
280 mode_string
[pi
->mode
],pi
->delay
);
284 static struct pi_protocol frpw
= {
285 .owner
= THIS_MODULE
,
291 .write_regr
= frpw_write_regr
,
292 .read_regr
= frpw_read_regr
,
293 .write_block
= frpw_write_block
,
294 .read_block
= frpw_read_block
,
295 .connect
= frpw_connect
,
296 .disconnect
= frpw_disconnect
,
297 .test_proto
= frpw_test_proto
,
298 .log_adapter
= frpw_log_adapter
,
301 static int __init
frpw_init(void)
303 return paride_register(&frpw
);
306 static void __exit
frpw_exit(void)
308 paride_unregister(&frpw
);
311 MODULE_LICENSE("GPL");
312 module_init(frpw_init
)
313 module_exit(frpw_exit
)