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
16 1.05 TMW 2000.06.06 use parport_find_number instead of
20 #define PI_VERSION "1.05"
22 #include <linux/module.h>
23 #include <linux/config.h>
24 #include <linux/kmod.h>
25 #include <linux/types.h>
26 #include <linux/kernel.h>
27 #include <linux/ioport.h>
28 #include <linux/string.h>
29 #include <linux/spinlock.h>
30 #include <linux/wait.h>
32 #ifdef CONFIG_PARPORT_MODULE
33 #define CONFIG_PARPORT
37 #include <linux/parport.h>
44 static struct pi_protocol
*protocols
[MAX_PROTOS
];
46 spinlock_t pi_spinlock
= SPIN_LOCK_UNLOCKED
;
48 void pi_write_regr( PIA
*pi
, int cont
, int regr
, int val
)
50 { pi
->proto
->write_regr(pi
,cont
,regr
,val
);
53 int pi_read_regr( PIA
*pi
, int cont
, int regr
)
55 { return pi
->proto
->read_regr(pi
,cont
,regr
);
58 void pi_write_block( PIA
*pi
, char * buf
, int count
)
60 { pi
->proto
->write_block(pi
,buf
,count
);
63 void pi_read_block( PIA
*pi
, char * buf
, int count
)
65 { pi
->proto
->read_block(pi
,buf
,count
);
70 static void pi_wake_up( void *p
)
72 { PIA
*pi
= (PIA
*) p
;
74 void (*cont
)(void) = NULL
;
76 spin_lock_irqsave(&pi_spinlock
,flags
);
78 if (pi
->claim_cont
&& !parport_claim(pi
->pardev
)) {
79 cont
= pi
->claim_cont
;
80 pi
->claim_cont
= NULL
;
84 spin_unlock_irqrestore(&pi_spinlock
,flags
);
93 void pi_do_claimed( PIA
*pi
, void(*cont
)(void))
99 spin_lock_irqsave(&pi_spinlock
,flags
);
101 if (!pi
->pardev
|| !parport_claim(pi
->pardev
)) {
103 spin_unlock_irqrestore(&pi_spinlock
,flags
);
106 pi
->claim_cont
= cont
;
107 spin_unlock_irqrestore(&pi_spinlock
,flags
);
118 static void pi_claim( PIA
*pi
)
120 { if (pi
->claimed
) return;
122 #ifdef CONFIG_PARPORT
124 wait_event (pi
->parq
,
125 !parport_claim ((struct pardevice
*)pi
->pardev
));
129 static void pi_unclaim( PIA
*pi
)
132 #ifdef CONFIG_PARPORT
133 if (pi
->pardev
) parport_release((struct pardevice
*)(pi
->pardev
));
137 void pi_connect( PIA
*pi
)
140 pi
->proto
->connect(pi
);
143 void pi_disconnect( PIA
*pi
)
145 { pi
->proto
->disconnect(pi
);
149 static void pi_unregister_parport( PIA
*pi
)
152 #ifdef CONFIG_PARPORT
154 parport_unregister_device((struct pardevice
*)(pi
->pardev
));
160 void pi_release( PIA
*pi
)
162 { pi_unregister_parport(pi
);
163 if ((!pi
->pardev
)&&(pi
->reserved
))
164 release_region(pi
->port
,pi
->reserved
);
165 pi
->proto
->release_proto(pi
);
168 #define WR(r,v) pi_write_regr(pi,0,r,v)
169 #define RR(r) (pi_read_regr(pi,0,r))
171 static int pi_test_proto( PIA
*pi
, char * scratch
, int verbose
)
176 if (pi
->proto
->test_proto
) {
178 j
= pi
->proto
->test_proto(pi
,scratch
,verbose
);
187 for (k
=0;k
<256;k
++) {
190 if (RR(2) != (k
^0xaa)) e
[j
]++;
197 printk("%s: %s: port 0x%x, mode %d, test=(%d,%d)\n",
198 pi
->device
,pi
->proto
->name
,pi
->port
,
201 return (e
[0] && e
[1]); /* not here if both > 0 */
204 int pi_register( PIP
*pr
)
208 for (k
=0;k
<MAX_PROTOS
;k
++)
209 if (protocols
[k
] && !strcmp(pr
->name
,protocols
[k
]->name
)) {
210 printk("paride: %s protocol already registered\n",pr
->name
);
214 while((k
<MAX_PROTOS
) && (protocols
[k
])) k
++;
215 if (k
== MAX_PROTOS
) {
216 printk("paride: protocol table full\n");
222 printk("paride: %s registered as protocol %d\n",pr
->name
,k
);
226 void pi_unregister( PIP
*pr
)
229 if (protocols
[pr
->index
] != pr
) {
230 printk("paride: %s not registered\n",pr
->name
);
233 protocols
[pr
->index
] = 0;
237 static void pi_register_parport( PIA
*pi
, int verbose
)
240 #ifdef CONFIG_PARPORT
242 struct parport
*port
;
244 port
= parport_find_base (pi
->port
);
247 pi
->pardev
= parport_register_device(port
,
251 parport_put_port (port
);
252 if (!pi
->pardev
) return;
255 init_waitqueue_head(&pi
->parq
);
257 if (verbose
) printk("%s: 0x%x is %s\n",pi
->device
,pi
->port
,
260 pi
->parname
= (char *)port
->name
;
265 static int pi_probe_mode( PIA
*pi
, int max
, char * scratch
, int verbose
)
269 if (pi
->mode
!= -1) {
270 if (pi
->mode
>= max
) return 0;
272 if (pi
->mode
>= pi
->proto
->epp_first
) range
= 8;
273 if ((range
== 8) && (pi
->port
% 8)) return 0;
274 if ((!pi
->pardev
) && check_region(pi
->port
,range
)) return 0;
275 pi
->reserved
= range
;
276 return (!pi_test_proto(pi
,scratch
,verbose
));
279 for(pi
->mode
=0;pi
->mode
<max
;pi
->mode
++) {
281 if (pi
->mode
>= pi
->proto
->epp_first
) range
= 8;
282 if ((range
== 8) && (pi
->port
% 8)) break;
283 if ((!pi
->pardev
) && check_region(pi
->port
,range
)) break;
284 pi
->reserved
= range
;
285 if (!pi_test_proto(pi
,scratch
,verbose
)) best
= pi
->mode
;
291 static int pi_probe_unit( PIA
*pi
, int unit
, char * scratch
, int verbose
)
299 e
= pi
->proto
->max_units
;
302 pi_register_parport(pi
,verbose
);
304 if ((!pi
->pardev
) && check_region(pi
->port
,3)) return 0;
306 if (pi
->proto
->test_port
) {
308 max
= pi
->proto
->test_port(pi
);
311 else max
= pi
->proto
->max_mode
;
313 if (pi
->proto
->probe_unit
) {
315 for (pi
->unit
=s
;pi
->unit
<e
;pi
->unit
++)
316 if (pi
->proto
->probe_unit(pi
)) {
318 if (pi_probe_mode(pi
,max
,scratch
,verbose
)) return 1;
319 pi_unregister_parport(pi
);
323 pi_unregister_parport(pi
);
327 if (!pi_probe_mode(pi
,max
,scratch
,verbose
)) {
328 pi_unregister_parport(pi
);
335 int pi_init(PIA
*pi
, int autoprobe
, int port
, int mode
,
336 int unit
, int protocol
, int delay
, char * scratch
,
337 int devtype
, int verbose
, char *device
)
340 int lpts
[7] = {0x3bc,0x378,0x278,0x268,0x27c,0x26c,0};
342 s
= protocol
; e
= s
+1;
345 request_module ("paride_protocol");
350 } else if ((s
< 0) || (s
>= MAX_PROTOS
) || (port
<= 0) ||
351 (!protocols
[s
]) || (unit
< 0) ||
352 (unit
>= protocols
[s
]->max_units
)) {
353 printk("%s: Invalid parameters\n",device
);
359 pi
->proto
= protocols
[p
];
361 pi
->proto
->init_proto(pi
);
362 if (delay
== -1) pi
->delay
= pi
->proto
->default_delay
;
363 else pi
->delay
= delay
;
364 pi
->devtype
= devtype
;
369 init_waitqueue_head(&pi
->parq
);
371 pi
->claim_cont
= NULL
;
376 if (pi_probe_unit(pi
,unit
,scratch
,verbose
)) break;
380 while ((pi
->port
= lpts
[k
++]))
381 if (pi_probe_unit(pi
,unit
,scratch
,verbose
)) break;
384 pi
->proto
->release_proto(pi
);
389 if (autoprobe
) printk("%s: Autoprobe failed\n",device
);
390 else printk("%s: Adapter not found\n",device
);
395 request_region(pi
->port
,pi
->reserved
,pi
->device
);
398 printk("%s: Sharing %s at 0x%x\n",pi
->device
,
399 pi
->parname
,pi
->port
);
401 pi
->proto
->log_adapter(pi
,scratch
,verbose
);
408 int init_module(void)
412 for (k
=0;k
<MAX_PROTOS
;k
++) protocols
[k
] = 0;
414 printk("paride: version %s installed\n",PI_VERSION
);
418 void cleanup_module(void)
425 void paride_init( void )
429 #ifdef CONFIG_PARIDE_ATEN
430 { extern struct pi_protocol aten
;
434 #ifdef CONFIG_PARIDE_BPCK
435 { extern struct pi_protocol bpck
;
439 #ifdef CONFIG_PARIDE_COMM
440 { extern struct pi_protocol comm
;
444 #ifdef CONFIG_PARIDE_DSTR
445 { extern struct pi_protocol dstr
;
449 #ifdef CONFIG_PARIDE_EPAT
450 { extern struct pi_protocol epat
;
454 #ifdef CONFIG_PARIDE_EPIA
455 { extern struct pi_protocol epia
;
459 #ifdef CONFIG_PARIDE_FRPW
460 { extern struct pi_protocol frpw
;
464 #ifdef CONFIG_PARIDE_FRIQ
465 { extern struct pi_protocol friq
;
469 #ifdef CONFIG_PARIDE_FIT2
470 { extern struct pi_protocol fit2
;
474 #ifdef CONFIG_PARIDE_FIT3
475 { extern struct pi_protocol fit3
;
479 #ifdef CONFIG_PARIDE_KBIC
480 { extern struct pi_protocol k951
;
481 extern struct pi_protocol k971
;
486 #ifdef CONFIG_PARIDE_KTTI
487 { extern struct pi_protocol ktti
;
491 #ifdef CONFIG_PARIDE_ON20
492 { extern struct pi_protocol on20
;
496 #ifdef CONFIG_PARIDE_ON26
497 { extern struct pi_protocol on26
;
502 #ifdef CONFIG_PARIDE_PD
503 { extern int pd_init(void);
507 #ifdef CONFIG_PARIDE_PCD
508 { extern int pcd_init(void);
512 #ifdef CONFIG_PARIDE_PF
513 { extern int pf_init(void);
517 #ifdef CONFIG_PARIDE_PT
518 { extern int pt_init(void);
522 #ifdef CONFIG_PARIDE_PG
523 { extern int pg_init(void);
531 /* end of paride.c */