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
18 #define PI_VERSION "1.03"
20 #include <linux/module.h>
21 #include <linux/config.h>
22 #include <linux/types.h>
23 #include <linux/kernel.h>
24 #include <linux/ioport.h>
25 #include <linux/string.h>
26 #include <asm/spinlock.h>
28 #ifdef CONFIG_PARPORT_MODULE
29 #define CONFIG_PARPORT
33 #include <linux/parport.h>
40 static struct pi_protocol
*protocols
[MAX_PROTOS
];
42 spinlock_t pi_spinlock
= SPIN_LOCK_UNLOCKED
;
44 void pi_write_regr( PIA
*pi
, int cont
, int regr
, int val
)
46 { pi
->proto
->write_regr(pi
,cont
,regr
,val
);
49 int pi_read_regr( PIA
*pi
, int cont
, int regr
)
51 { return pi
->proto
->read_regr(pi
,cont
,regr
);
54 void pi_write_block( PIA
*pi
, char * buf
, int count
)
56 { pi
->proto
->write_block(pi
,buf
,count
);
59 void pi_read_block( PIA
*pi
, char * buf
, int count
)
61 { pi
->proto
->read_block(pi
,buf
,count
);
66 static void pi_wake_up( void *p
)
68 { PIA
*pi
= (PIA
*) p
;
70 void (*cont
)(void) = NULL
;
72 spin_lock_irqsave(&pi_spinlock
,flags
);
74 if (pi
->claim_cont
&& !parport_claim(pi
->pardev
)) {
75 cont
= pi
->claim_cont
;
76 pi
->claim_cont
= NULL
;
80 spin_unlock_irqrestore(&pi_spinlock
,flags
);
89 void pi_do_claimed( PIA
*pi
, void(*cont
)(void))
95 spin_lock_irqsave(&pi_spinlock
,flags
);
97 if (!pi
->pardev
|| !parport_claim(pi
->pardev
)) {
99 spin_unlock_irqrestore(&pi_spinlock
,flags
);
102 pi
->claim_cont
= cont
;
103 spin_unlock_irqrestore(&pi_spinlock
,flags
);
114 static void pi_claim( PIA
*pi
)
116 { if (pi
->claimed
) return;
118 #ifdef CONFIG_PARPORT
120 while (parport_claim((struct pardevice
*)(pi
->pardev
)))
121 sleep_on(&(pi
->parq
));
125 static void pi_unclaim( PIA
*pi
)
128 #ifdef CONFIG_PARPORT
129 if (pi
->pardev
) parport_release((struct pardevice
*)(pi
->pardev
));
133 void pi_connect( PIA
*pi
)
136 pi
->proto
->connect(pi
);
139 void pi_disconnect( PIA
*pi
)
141 { pi
->proto
->disconnect(pi
);
145 static void pi_unregister_parport( PIA
*pi
)
148 #ifdef CONFIG_PARPORT
150 parport_unregister_device((struct pardevice
*)(pi
->pardev
));
156 void pi_release( PIA
*pi
)
158 { pi_unregister_parport(pi
);
159 if ((!pi
->pardev
)&&(pi
->reserved
))
160 release_region(pi
->port
,pi
->reserved
);
161 pi
->proto
->release_proto(pi
);
164 #define WR(r,v) pi_write_regr(pi,0,r,v)
165 #define RR(r) (pi_read_regr(pi,0,r))
167 static int pi_test_proto( PIA
*pi
, char * scratch
, int verbose
)
172 if (pi
->proto
->test_proto
) {
174 j
= pi
->proto
->test_proto(pi
,scratch
,verbose
);
183 for (k
=0;k
<256;k
++) {
186 if (RR(2) != (k
^0xaa)) e
[j
]++;
193 printk("%s: %s: port 0x%x, mode %d, test=(%d,%d)\n",
194 pi
->device
,pi
->proto
->name
,pi
->port
,
197 return (e
[0] && e
[1]); /* not here if both > 0 */
200 int pi_register( PIP
*pr
)
204 for (k
=0;k
<MAX_PROTOS
;k
++)
205 if (protocols
[k
] && !strcmp(pr
->name
,protocols
[k
]->name
)) {
206 printk("paride: %s protocol already registered\n",pr
->name
);
210 while((k
<MAX_PROTOS
) && (protocols
[k
])) k
++;
211 if (k
== MAX_PROTOS
) {
212 printk("paride: protocol table full\n");
218 printk("paride: %s registered as protocol %d\n",pr
->name
,k
);
222 void pi_unregister( PIP
*pr
)
225 if (protocols
[pr
->index
] != pr
) {
226 printk("paride: %s not registered\n",pr
->name
);
229 protocols
[pr
->index
] = 0;
233 static void pi_register_parport( PIA
*pi
, int verbose
)
236 #ifdef CONFIG_PARPORT
240 pp
= parport_enumerate();
242 while((pp
)&&(pp
->base
!= pi
->port
)) pp
= pp
->next
;
246 pi
->pardev
= (void *) parport_register_device(
247 pp
,pi
->device
,NULL
,pi_wake_up
,NULL
,0,(void *)pi
);
251 if (verbose
) printk("%s: 0x%x is %s\n",pi
->device
,pi
->port
,pp
->name
);
253 pi
->parname
= (char *)pp
->name
;
258 static int pi_probe_mode( PIA
*pi
, int max
, char * scratch
, int verbose
)
262 if (pi
->mode
!= -1) {
263 if (pi
->mode
>= max
) return 0;
265 if (pi
->mode
>= pi
->proto
->epp_first
) range
= 8;
266 if ((range
== 8) && (pi
->port
% 8)) return 0;
267 if ((!pi
->pardev
) && check_region(pi
->port
,range
)) return 0;
268 pi
->reserved
= range
;
269 return (!pi_test_proto(pi
,scratch
,verbose
));
272 for(pi
->mode
=0;pi
->mode
<max
;pi
->mode
++) {
274 if (pi
->mode
>= pi
->proto
->epp_first
) range
= 8;
275 if ((range
== 8) && (pi
->port
% 8)) break;
276 if ((!pi
->pardev
) && check_region(pi
->port
,range
)) break;
277 pi
->reserved
= range
;
278 if (!pi_test_proto(pi
,scratch
,verbose
)) best
= pi
->mode
;
284 static int pi_probe_unit( PIA
*pi
, int unit
, char * scratch
, int verbose
)
292 e
= pi
->proto
->max_units
;
295 pi_register_parport(pi
,verbose
);
297 if ((!pi
->pardev
) && check_region(pi
->port
,3)) return 0;
299 if (pi
->proto
->test_port
) {
301 max
= pi
->proto
->test_port(pi
);
304 else max
= pi
->proto
->max_mode
;
306 if (pi
->proto
->probe_unit
) {
308 for (pi
->unit
=s
;pi
->unit
<e
;pi
->unit
++)
309 if (pi
->proto
->probe_unit(pi
)) {
311 if (pi_probe_mode(pi
,max
,scratch
,verbose
)) return 1;
312 pi_unregister_parport(pi
);
316 pi_unregister_parport(pi
);
320 if (!pi_probe_mode(pi
,max
,scratch
,verbose
)) {
321 pi_unregister_parport(pi
);
328 int pi_init(PIA
*pi
, int autoprobe
, int port
, int mode
,
329 int unit
, int protocol
, int delay
, char * scratch
,
330 int devtype
, int verbose
, char *device
)
333 int lpts
[7] = {0x3bc,0x378,0x278,0x268,0x27c,0x26c,0};
335 s
= protocol
; e
= s
+1;
340 } else if ((s
< 0) || (s
>= MAX_PROTOS
) || (port
<= 0) ||
341 (!protocols
[s
]) || (unit
< 0) ||
342 (unit
>= protocols
[s
]->max_units
)) {
343 printk("%s: Invalid parameters\n",device
);
349 pi
->proto
= protocols
[p
];
351 pi
->proto
->init_proto(pi
);
352 if (delay
== -1) pi
->delay
= pi
->proto
->default_delay
;
353 else pi
->delay
= delay
;
354 pi
->devtype
= devtype
;
361 pi
->claim_cont
= NULL
;
366 if (pi_probe_unit(pi
,unit
,scratch
,verbose
)) break;
370 while ((pi
->port
= lpts
[k
++]))
371 if (pi_probe_unit(pi
,unit
,scratch
,verbose
)) break;
374 pi
->proto
->release_proto(pi
);
379 if (autoprobe
) printk("%s: Autoprobe failed\n",device
);
380 else printk("%s: Adapter not found\n",device
);
385 request_region(pi
->port
,pi
->reserved
,pi
->device
);
388 printk("%s: Sharing %s at 0x%x\n",pi
->device
,
389 pi
->parname
,pi
->port
);
391 pi
->proto
->log_adapter(pi
,scratch
,verbose
);
398 int init_module(void)
402 for (k
=0;k
<MAX_PROTOS
;k
++) protocols
[k
] = 0;
403 printk("paride: version %s installed\n",PI_VERSION
);
407 void cleanup_module(void)
414 void paride_init( void )
418 #ifdef CONFIG_PARIDE_ATEN
419 { extern struct pi_protocol aten
;
423 #ifdef CONFIG_PARIDE_BPCK
424 { extern struct pi_protocol bpck
;
428 #ifdef CONFIG_PARIDE_COMM
429 { extern struct pi_protocol comm
;
433 #ifdef CONFIG_PARIDE_DSTR
434 { extern struct pi_protocol dstr
;
438 #ifdef CONFIG_PARIDE_EPAT
439 { extern struct pi_protocol epat
;
443 #ifdef CONFIG_PARIDE_EPIA
444 { extern struct pi_protocol epia
;
448 #ifdef CONFIG_PARIDE_FRPW
449 { extern struct pi_protocol frpw
;
453 #ifdef CONFIG_PARIDE_FIT2
454 { extern struct pi_protocol fit2
;
458 #ifdef CONFIG_PARIDE_FIT3
459 { extern struct pi_protocol fit3
;
463 #ifdef CONFIG_PARIDE_KBIC
464 { extern struct pi_protocol k951
;
465 extern struct pi_protocol k971
;
470 #ifdef CONFIG_PARIDE_KTTI
471 { extern struct pi_protocol ktti
;
475 #ifdef CONFIG_PARIDE_ON20
476 { extern struct pi_protocol on20
;
480 #ifdef CONFIG_PARIDE_ON26
481 { extern struct pi_protocol on26
;
486 #ifdef CONFIG_PARIDE_PD
487 { extern int pd_init(void);
491 #ifdef CONFIG_PARIDE_PCD
492 { extern int pcd_init(void);
496 #ifdef CONFIG_PARIDE_PF
497 { extern int pf_init(void);
501 #ifdef CONFIG_PARIDE_PT
502 { extern int pt_init(void);
506 #ifdef CONFIG_PARIDE_PG
507 { extern int pg_init(void);
515 /* end of paride.c */