21 #define PI_VERSION "1.06"
23 #include <linux/module.h>
25 #include <linux/types.h>
26 #include <linux/kernel.h>
28 #include <linux/string.h>
30 #include <linux/wait.h>
31 #include <linux/sched.h>
32 #include <linux/parport.h>
46 pi->
proto->write_regr(pi, cont, regr, val);
53 return pi->
proto->read_regr(pi, cont, regr);
60 pi->
proto->write_block(pi, buf, count);
67 pi->
proto->read_block(pi, buf, count);
72 static void pi_wake_up(
void *
p)
86 spin_unlock_irqrestore(&pi_spinlock, flags);
101 spin_unlock_irqrestore(&pi_spinlock, flags);
105 spin_unlock_irqrestore(&pi_spinlock, flags);
118 static void pi_claim(
PIA * pi)
128 static void pi_unclaim(
PIA * pi)
138 pi->
proto->connect(pi);
145 pi->
proto->disconnect(pi);
151 static void pi_unregister_parport(
PIA * pi)
161 pi_unregister_parport(pi);
162 if (pi->
proto->release_proto)
163 pi->
proto->release_proto(pi);
164 module_put(pi->
proto->owner);
174 pi->
proto->connect(pi);
176 for (j = 0; j < 2; j++) {
178 for (k = 0; k < 256; k++) {
185 pi->
proto->disconnect(pi);
188 printk(
"%s: %s: port 0x%x, mode %d, test=(%d,%d)\n",
190 pi->
mode, e[0], e[1]);
192 return (e[0] && e[1]);
195 static int pi_test_proto(
PIA * pi,
char *scratch,
int verbose)
200 if (pi->
proto->test_proto)
201 res = pi->
proto->test_proto(pi, scratch, verbose);
203 res = default_test_proto(pi, scratch, verbose);
215 printk(
"paride: %s protocol already registered\n",
220 while ((k < MAX_PROTOS) && (protocols[k]))
222 if (k == MAX_PROTOS) {
223 printk(
"paride: protocol table full\n");
228 printk(
"paride: %s registered as protocol %d\n", pr->
name, k);
238 if (protocols[pr->
index] != pr) {
239 printk(
"paride: %s not registered\n", pr->
name);
247 static int pi_register_parport(
PIA * pi,
int verbose)
257 pi_wake_up,
NULL, 0, (
void *) pi);
272 static int pi_probe_mode(
PIA * pi,
int max,
char *scratch,
int verbose)
276 if (pi->
mode != -1) {
282 if ((range == 8) && (pi->
port % 8))
285 return (!pi_test_proto(pi, scratch, verbose));
292 if ((range == 8) && (pi->
port % 8))
295 if (!pi_test_proto(pi, scratch, verbose))
302 static int pi_probe_unit(
PIA * pi,
int unit,
char *scratch,
int verbose)
311 e = pi->
proto->max_units;
314 if (!pi_register_parport(pi, verbose))
317 if (pi->
proto->test_port) {
319 max = pi->
proto->test_port(pi);
322 max = pi->
proto->max_mode;
324 if (pi->
proto->probe_unit) {
327 if (pi->
proto->probe_unit(pi)) {
329 if (pi_probe_mode(pi, max, scratch, verbose))
331 pi_unregister_parport(pi);
335 pi_unregister_parport(pi);
339 if (!pi_probe_mode(pi, max, scratch, verbose)) {
340 pi_unregister_parport(pi);
349 int devtype,
int verbose,
char *
device)
352 int lpts[7] = { 0x3bc, 0x378, 0x278, 0x268, 0x27c, 0x26c, 0 };
358 request_module(
"paride_protocol");
363 }
else if ((s < 0) || (s >=
MAX_PROTOS) || (port <= 0) ||
364 (!protocols[s]) || (unit < 0) ||
365 (unit >= protocols[s]->max_units)) {
366 printk(
"%s: Invalid parameters\n", device);
370 for (p = s; p <
e; p++) {
375 if (!try_module_get(proto->
owner))
381 module_put(proto->
owner);
400 if (pi_probe_unit(pi, unit, scratch, verbose))
405 while ((pi->
port = lpts[k++]))
407 (pi, unit, scratch, verbose))
412 if (pi->
proto->release_proto)
413 pi->
proto->release_proto(pi);
414 module_put(proto->
owner);
419 printk(
"%s: Autoprobe failed\n", device);
421 printk(
"%s: Adapter not found\n", device);
429 pi->
proto->log_adapter(pi, scratch, verbose);