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> 29 #ifdef CONFIG_PARPORT_MODULE 30 #define CONFIG_PARPORT 34 #include <linux/parport.h> 41 static struct pi_protocol
*protocols
[MAX_PROTOS
]; 43 spinlock_t pi_spinlock
= SPIN_LOCK_UNLOCKED
; 45 voidpi_write_regr( PIA
*pi
,int cont
,int regr
,int val
) 47 { pi
->proto
->write_regr(pi
,cont
,regr
,val
); 50 intpi_read_regr( PIA
*pi
,int cont
,int regr
) 52 {return pi
->proto
->read_regr(pi
,cont
,regr
); 55 voidpi_write_block( PIA
*pi
,char* buf
,int count
) 57 { pi
->proto
->write_block(pi
,buf
,count
); 60 voidpi_read_block( PIA
*pi
,char* buf
,int count
) 62 { pi
->proto
->read_block(pi
,buf
,count
); 67 static voidpi_wake_up(void*p
) 69 { PIA
*pi
= (PIA
*) p
; 71 void(*cont
)(void) = NULL
; 73 spin_lock_irqsave(&pi_spinlock
,flags
); 75 if(pi
->claim_cont
&& !parport_claim(pi
->pardev
)) { 76 cont
= pi
->claim_cont
; 77 pi
->claim_cont
= NULL
; 81 spin_unlock_irqrestore(&pi_spinlock
,flags
); 90 voidpi_do_claimed( PIA
*pi
,void(*cont
)(void)) 96 spin_lock_irqsave(&pi_spinlock
,flags
); 98 if(!pi
->pardev
|| !parport_claim(pi
->pardev
)) { 100 spin_unlock_irqrestore(&pi_spinlock
,flags
); 103 pi
->claim_cont
= cont
; 104 spin_unlock_irqrestore(&pi_spinlock
,flags
); 115 static voidpi_claim( PIA
*pi
) 117 {if(pi
->claimed
)return; 119 #ifdef CONFIG_PARPORT 121 while(parport_claim((struct pardevice
*)(pi
->pardev
))) 122 sleep_on(&(pi
->parq
)); 126 static voidpi_unclaim( PIA
*pi
) 129 #ifdef CONFIG_PARPORT 130 if(pi
->pardev
)parport_release((struct pardevice
*)(pi
->pardev
)); 134 voidpi_connect( PIA
*pi
) 137 pi
->proto
->connect(pi
); 140 voidpi_disconnect( PIA
*pi
) 142 { pi
->proto
->disconnect(pi
); 146 static voidpi_unregister_parport( PIA
*pi
) 149 #ifdef CONFIG_PARPORT 151 parport_unregister_device((struct pardevice
*)(pi
->pardev
)); 157 voidpi_release( PIA
*pi
) 159 {pi_unregister_parport(pi
); 160 if((!pi
->pardev
)&&(pi
->reserved
)) 161 release_region(pi
->port
,pi
->reserved
); 162 pi
->proto
->release_proto(pi
); 165 #define WR(r,v) pi_write_regr(pi,0,r,v) 166 #define RR(r) (pi_read_regr(pi,0,r)) 168 static intpi_test_proto( PIA
*pi
,char* scratch
,int verbose
) 173 if(pi
->proto
->test_proto
) { 175 j
= pi
->proto
->test_proto(pi
,scratch
,verbose
); 187 if(RR(2) != (k
^0xaa)) e
[j
]++; 194 printk("%s: %s: port 0x%x, mode %d, test=(%d,%d)\n", 195 pi
->device
,pi
->proto
->name
,pi
->port
, 198 return(e
[0] && e
[1]);/* not here if both > 0 */ 201 intpi_register( PIP
*pr
) 205 for(k
=0;k
<MAX_PROTOS
;k
++) 206 if(protocols
[k
] && !strcmp(pr
->name
,protocols
[k
]->name
)) { 207 printk("paride: %s protocol already registered\n",pr
->name
); 211 while((k
<MAX_PROTOS
) && (protocols
[k
])) k
++; 212 if(k
== MAX_PROTOS
) { 213 printk("paride: protocol table full\n"); 219 printk("paride: %s registered as protocol %d\n",pr
->name
,k
); 223 voidpi_unregister( PIP
*pr
) 226 if(protocols
[pr
->index
] != pr
) { 227 printk("paride: %s not registered\n",pr
->name
); 230 protocols
[pr
->index
] =0; 234 static voidpi_register_parport( PIA
*pi
,int verbose
) 237 #ifdef CONFIG_PARPORT 241 pp
=parport_enumerate(); 243 while((pp
)&&(pp
->base
!= pi
->port
)) pp
= pp
->next
; 247 pi
->pardev
= (void*)parport_register_device( 248 pp
,pi
->device
,NULL
,pi_wake_up
,NULL
,0,(void*)pi
); 250 init_waitqueue_head(&pi
->parq
); 252 if(verbose
)printk("%s: 0x%x is %s\n",pi
->device
,pi
->port
,pp
->name
); 254 pi
->parname
= (char*)pp
->name
; 259 static intpi_probe_mode( PIA
*pi
,int max
,char* scratch
,int verbose
) 264 if(pi
->mode
>= max
)return0; 266 if(pi
->mode
>= pi
->proto
->epp_first
) range
=8; 267 if((range
==8) && (pi
->port
%8))return0; 268 if((!pi
->pardev
) &&check_region(pi
->port
,range
))return0; 269 pi
->reserved
= range
; 270 return(!pi_test_proto(pi
,scratch
,verbose
)); 273 for(pi
->mode
=0;pi
->mode
<max
;pi
->mode
++) { 275 if(pi
->mode
>= pi
->proto
->epp_first
) range
=8; 276 if((range
==8) && (pi
->port
%8))break; 277 if((!pi
->pardev
) &&check_region(pi
->port
,range
))break; 278 pi
->reserved
= range
; 279 if(!pi_test_proto(pi
,scratch
,verbose
)) best
= pi
->mode
; 285 static intpi_probe_unit( PIA
*pi
,int unit
,char* scratch
,int verbose
) 293 e
= pi
->proto
->max_units
; 296 pi_register_parport(pi
,verbose
); 298 if((!pi
->pardev
) &&check_region(pi
->port
,3))return0; 300 if(pi
->proto
->test_port
) { 302 max
= pi
->proto
->test_port(pi
); 305 else max
= pi
->proto
->max_mode
; 307 if(pi
->proto
->probe_unit
) { 309 for(pi
->unit
=s
;pi
->unit
<e
;pi
->unit
++) 310 if(pi
->proto
->probe_unit(pi
)) { 312 if(pi_probe_mode(pi
,max
,scratch
,verbose
))return1; 313 pi_unregister_parport(pi
); 317 pi_unregister_parport(pi
); 321 if(!pi_probe_mode(pi
,max
,scratch
,verbose
)) { 322 pi_unregister_parport(pi
); 329 intpi_init(PIA
*pi
,int autoprobe
,int port
,int mode
, 330 int unit
,int protocol
,int delay
,char* scratch
, 331 int devtype
,int verbose
,char*device
) 334 int lpts
[7] = {0x3bc,0x378,0x278,0x268,0x27c,0x26c,0}; 336 s
= protocol
; e
= s
+1; 341 }else if((s
<0) || (s
>= MAX_PROTOS
) || (port
<=0) || 342 (!protocols
[s
]) || (unit
<0) || 343 (unit
>= protocols
[s
]->max_units
)) { 344 printk("%s: Invalid parameters\n",device
); 350 pi
->proto
= protocols
[p
]; 352 pi
->proto
->init_proto(pi
); 353 if(delay
== -1) pi
->delay
= pi
->proto
->default_delay
; 354 else pi
->delay
= delay
; 355 pi
->devtype
= devtype
; 360 init_waitqueue_head(&pi
->parq
); 362 pi
->claim_cont
= NULL
; 367 if(pi_probe_unit(pi
,unit
,scratch
,verbose
))break; 371 while((pi
->port
= lpts
[k
++])) 372 if(pi_probe_unit(pi
,unit
,scratch
,verbose
))break; 375 pi
->proto
->release_proto(pi
); 380 if(autoprobe
)printk("%s: Autoprobe failed\n",device
); 381 elseprintk("%s: Adapter not found\n",device
); 386 request_region(pi
->port
,pi
->reserved
,pi
->device
); 389 printk("%s: Sharing %s at 0x%x\n",pi
->device
, 390 pi
->parname
,pi
->port
); 392 pi
->proto
->log_adapter(pi
,scratch
,verbose
); 403 for(k
=0;k
<MAX_PROTOS
;k
++) protocols
[k
] =0; 404 printk("paride: version %s installed\n",PI_VERSION
); 408 voidcleanup_module(void) 415 voidparide_init(void) 419 #ifdef CONFIG_PARIDE_ATEN 420 {externstruct pi_protocol aten
; 424 #ifdef CONFIG_PARIDE_BPCK 425 {externstruct pi_protocol bpck
; 429 #ifdef CONFIG_PARIDE_COMM 430 {externstruct pi_protocol comm
; 434 #ifdef CONFIG_PARIDE_DSTR 435 {externstruct pi_protocol dstr
; 439 #ifdef CONFIG_PARIDE_EPAT 440 {externstruct pi_protocol epat
; 444 #ifdef CONFIG_PARIDE_EPIA 445 {externstruct pi_protocol epia
; 449 #ifdef CONFIG_PARIDE_FRPW 450 {externstruct pi_protocol frpw
; 454 #ifdef CONFIG_PARIDE_FRIQ 455 {externstruct pi_protocol friq
; 459 #ifdef CONFIG_PARIDE_FIT2 460 {externstruct pi_protocol fit2
; 464 #ifdef CONFIG_PARIDE_FIT3 465 {externstruct pi_protocol fit3
; 469 #ifdef CONFIG_PARIDE_KBIC 470 {externstruct pi_protocol k951
; 471 externstruct pi_protocol k971
; 476 #ifdef CONFIG_PARIDE_KTTI 477 {externstruct pi_protocol ktti
; 481 #ifdef CONFIG_PARIDE_ON20 482 {externstruct pi_protocol on20
; 486 #ifdef CONFIG_PARIDE_ON26 487 {externstruct pi_protocol on26
; 492 #ifdef CONFIG_PARIDE_PD 493 {externintpd_init(void); 497 #ifdef CONFIG_PARIDE_PCD 498 {externintpcd_init(void); 502 #ifdef CONFIG_PARIDE_PF 503 {externintpf_init(void); 507 #ifdef CONFIG_PARIDE_PT 508 {externintpt_init(void); 512 #ifdef CONFIG_PARIDE_PG 513 {externintpg_init(void); 521 /* end of paride.c */