2 paride.c (c) 1997-8 Grant R. Guenther <grant@torque.net>
3 Under the terms of the GNU public license.
5 This is the base module for the family of device drivers
6 that support parallel port IDE devices.
12 1.01 GRG 1998.05.03 Use spinlocks
13 1.02 GRG 1998.05.05 init_proto, release_proto, ktti
14 1.03 GRG 1998.08.15 eliminate compiler warning
15 1.04 GRG 1998.11.28 added support for FRIQ
19 #define PI_VERSION "1.04"
21 #include <linux/module.h>
22 #include <linux/config.h>
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/ioport.h>
26 #include <linux/string.h>
27 #include <linux/spinlock.h>
28 #include <linux/wait.h>
30 #ifdef CONFIG_PARPORT_MODULE
31 #define CONFIG_PARPORT
35 #include <linux/parport.h>
42 static struct pi_protocol
*protocols
[MAX_PROTOS
];
44 spinlock_t pi_spinlock
= SPIN_LOCK_UNLOCKED
;
46 void pi_write_regr( PIA
*pi
, int cont
, int regr
, int val
)
48 { pi
->proto
->write_regr(pi
,cont
,regr
,val
);
51 int pi_read_regr( PIA
*pi
, int cont
, int regr
)
53 { return pi
->proto
->read_regr(pi
,cont
,regr
);
56 void pi_write_block( PIA
*pi
, char * buf
, int count
)
58 { pi
->proto
->write_block(pi
,buf
,count
);
61 void pi_read_block( PIA
*pi
, char * buf
, int count
)
63 { pi
->proto
->read_block(pi
,buf
,count
);
68 static void pi_wake_up( void *p
)
70 { PIA
*pi
= (PIA
*) p
;
72 void (*cont
)(void) = NULL
;
74 spin_lock_irqsave(&pi_spinlock
,flags
);
76 if (pi
->claim_cont
&& !parport_claim(pi
->pardev
)) {
77 cont
= pi
->claim_cont
;
78 pi
->claim_cont
= NULL
;
82 spin_unlock_irqrestore(&pi_spinlock
,flags
);
91 void pi_do_claimed( PIA
*pi
, void(*cont
)(void))
97 spin_lock_irqsave(&pi_spinlock
,flags
);
99 if (!pi
->pardev
|| !parport_claim(pi
->pardev
)) {
101 spin_unlock_irqrestore(&pi_spinlock
,flags
);
104 pi
->claim_cont
= cont
;
105 spin_unlock_irqrestore(&pi_spinlock
,flags
);
116 static void pi_claim( PIA
*pi
)
118 { if (pi
->claimed
) return;
120 #ifdef CONFIG_PARPORT
122 while (parport_claim((struct pardevice
*)(pi
->pardev
)))
123 sleep_on(&(pi
->parq
));
127 static void pi_unclaim( PIA
*pi
)
130 #ifdef CONFIG_PARPORT
131 if (pi
->pardev
) parport_release((struct pardevice
*)(pi
->pardev
));
135 void pi_connect( PIA
*pi
)
138 pi
->proto
->connect(pi
);
141 void pi_disconnect( PIA
*pi
)
143 { pi
->proto
->disconnect(pi
);
147 static void pi_unregister_parport( PIA
*pi
)
150 #ifdef CONFIG_PARPORT
152 parport_unregister_device((struct pardevice
*)(pi
->pardev
));
158 void pi_release( PIA
*pi
)
160 { pi_unregister_parport(pi
);
161 if ((!pi
->pardev
)&&(pi
->reserved
))
162 release_region(pi
->port
,pi
->reserved
);
163 pi
->proto
->release_proto(pi
);
166 #define WR(r,v) pi_write_regr(pi,0,r,v)
167 #define RR(r) (pi_read_regr(pi,0,r))
169 static int pi_test_proto( PIA
*pi
, char * scratch
, int verbose
)
174 if (pi
->proto
->test_proto
) {
176 j
= pi
->proto
->test_proto(pi
,scratch
,verbose
);
185 for (k
=0;k
<256;k
++) {
188 if (RR(2) != (k
^0xaa)) e
[j
]++;
195 printk("%s: %s: port 0x%x, mode %d, test=(%d,%d)\n",
196 pi
->device
,pi
->proto
->name
,pi
->port
,
199 return (e
[0] && e
[1]); /* not here if both > 0 */
202 int pi_register( PIP
*pr
)
206 for (k
=0;k
<MAX_PROTOS
;k
++)
207 if (protocols
[k
] && !strcmp(pr
->name
,protocols
[k
]->name
)) {
208 printk("paride: %s protocol already registered\n",pr
->name
);
212 while((k
<MAX_PROTOS
) && (protocols
[k
])) k
++;
213 if (k
== MAX_PROTOS
) {
214 printk("paride: protocol table full\n");
220 printk("paride: %s registered as protocol %d\n",pr
->name
,k
);
224 void pi_unregister( PIP
*pr
)
227 if (protocols
[pr
->index
] != pr
) {
228 printk("paride: %s not registered\n",pr
->name
);
231 protocols
[pr
->index
] = 0;
235 static void pi_register_parport( PIA
*pi
, int verbose
)
238 #ifdef CONFIG_PARPORT
242 pp
= parport_enumerate();
244 while((pp
)&&(pp
->base
!= pi
->port
)) pp
= pp
->next
;
248 pi
->pardev
= (void *) parport_register_device(
249 pp
,pi
->device
,NULL
,pi_wake_up
,NULL
,0,(void *)pi
);
251 init_waitqueue_head(&pi
->parq
);
253 if (verbose
) printk("%s: 0x%x is %s\n",pi
->device
,pi
->port
,pp
->name
);
255 pi
->parname
= (char *)pp
->name
;
260 static int pi_probe_mode( PIA
*pi
, int max
, char * scratch
, int verbose
)
264 if (pi
->mode
!= -1) {
265 if (pi
->mode
>= max
) return 0;
267 if (pi
->mode
>= pi
->proto
->epp_first
) range
= 8;
268 if ((range
== 8) && (pi
->port
% 8)) return 0;
269 if ((!pi
->pardev
) && check_region(pi
->port
,range
)) return 0;
270 pi
->reserved
= range
;
271 return (!pi_test_proto(pi
,scratch
,verbose
));
274 for(pi
->mode
=0;pi
->mode
<max
;pi
->mode
++) {
276 if (pi
->mode
>= pi
->proto
->epp_first
) range
= 8;
277 if ((range
== 8) && (pi
->port
% 8)) break;
278 if ((!pi
->pardev
) && check_region(pi
->port
,range
)) break;
279 pi
->reserved
= range
;
280 if (!pi_test_proto(pi
,scratch
,verbose
)) best
= pi
->mode
;
286 static int pi_probe_unit( PIA
*pi
, int unit
, char * scratch
, int verbose
)
294 e
= pi
->proto
->max_units
;
297 pi_register_parport(pi
,verbose
);
299 if ((!pi
->pardev
) && check_region(pi
->port
,3)) return 0;
301 if (pi
->proto
->test_port
) {
303 max
= pi
->proto
->test_port(pi
);
306 else max
= pi
->proto
->max_mode
;
308 if (pi
->proto
->probe_unit
) {
310 for (pi
->unit
=s
;pi
->unit
<e
;pi
->unit
++)
311 if (pi
->proto
->probe_unit(pi
)) {
313 if (pi_probe_mode(pi
,max
,scratch
,verbose
)) return 1;
314 pi_unregister_parport(pi
);
318 pi_unregister_parport(pi
);
322 if (!pi_probe_mode(pi
,max
,scratch
,verbose
)) {
323 pi_unregister_parport(pi
);
330 int pi_init(PIA
*pi
, int autoprobe
, int port
, int mode
,
331 int unit
, int protocol
, int delay
, char * scratch
,
332 int devtype
, int verbose
, char *device
)
335 int lpts
[7] = {0x3bc,0x378,0x278,0x268,0x27c,0x26c,0};
337 s
= protocol
; e
= s
+1;
342 } else if ((s
< 0) || (s
>= MAX_PROTOS
) || (port
<= 0) ||
343 (!protocols
[s
]) || (unit
< 0) ||
344 (unit
>= protocols
[s
]->max_units
)) {
345 printk("%s: Invalid parameters\n",device
);
351 pi
->proto
= protocols
[p
];
353 pi
->proto
->init_proto(pi
);
354 if (delay
== -1) pi
->delay
= pi
->proto
->default_delay
;
355 else pi
->delay
= delay
;
356 pi
->devtype
= devtype
;
361 init_waitqueue_head(&pi
->parq
);
363 pi
->claim_cont
= NULL
;
368 if (pi_probe_unit(pi
,unit
,scratch
,verbose
)) break;
372 while ((pi
->port
= lpts
[k
++]))
373 if (pi_probe_unit(pi
,unit
,scratch
,verbose
)) break;
376 pi
->proto
->release_proto(pi
);
381 if (autoprobe
) printk("%s: Autoprobe failed\n",device
);
382 else printk("%s: Adapter not found\n",device
);
387 request_region(pi
->port
,pi
->reserved
,pi
->device
);
390 printk("%s: Sharing %s at 0x%x\n",pi
->device
,
391 pi
->parname
,pi
->port
);
393 pi
->proto
->log_adapter(pi
,scratch
,verbose
);
400 int init_module(void)
404 for (k
=0;k
<MAX_PROTOS
;k
++) protocols
[k
] = 0;
405 printk("paride: version %s installed\n",PI_VERSION
);
409 void cleanup_module(void)
416 void paride_init( void )
420 #ifdef CONFIG_PARIDE_ATEN
421 { extern struct pi_protocol aten
;
425 #ifdef CONFIG_PARIDE_BPCK
426 { extern struct pi_protocol bpck
;
430 #ifdef CONFIG_PARIDE_COMM
431 { extern struct pi_protocol comm
;
435 #ifdef CONFIG_PARIDE_DSTR
436 { extern struct pi_protocol dstr
;
440 #ifdef CONFIG_PARIDE_EPAT
441 { extern struct pi_protocol epat
;
445 #ifdef CONFIG_PARIDE_EPIA
446 { extern struct pi_protocol epia
;
450 #ifdef CONFIG_PARIDE_FRPW
451 { extern struct pi_protocol frpw
;
455 #ifdef CONFIG_PARIDE_FRIQ
456 { extern struct pi_protocol friq
;
460 #ifdef CONFIG_PARIDE_FIT2
461 { extern struct pi_protocol fit2
;
465 #ifdef CONFIG_PARIDE_FIT3
466 { extern struct pi_protocol fit3
;
470 #ifdef CONFIG_PARIDE_KBIC
471 { extern struct pi_protocol k951
;
472 extern struct pi_protocol k971
;
477 #ifdef CONFIG_PARIDE_KTTI
478 { extern struct pi_protocol ktti
;
482 #ifdef CONFIG_PARIDE_ON20
483 { extern struct pi_protocol on20
;
487 #ifdef CONFIG_PARIDE_ON26
488 { extern struct pi_protocol on26
;
493 #ifdef CONFIG_PARIDE_PD
494 { extern int pd_init(void);
498 #ifdef CONFIG_PARIDE_PCD
499 { extern int pcd_init(void);
503 #ifdef CONFIG_PARIDE_PF
504 { extern int pf_init(void);
508 #ifdef CONFIG_PARIDE_PT
509 { extern int pt_init(void);
513 #ifdef CONFIG_PARIDE_PG
514 { extern int pg_init(void);
522 /* end of paride.c */