Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)         paride.c  (c) 1997-8  Grant R. Guenther <grant@torque.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)                               Under the terms of the GNU General Public License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 	This is the base module for the family of device drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)         that support parallel port IDE devices.  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) /* Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 	1.01	GRG 1998.05.03	Use spinlocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	1.02	GRG 1998.05.05  init_proto, release_proto, ktti
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	1.03	GRG 1998.08.15  eliminate compiler warning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	1.04    GRG 1998.11.28  added support for FRIQ 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	1.05    TMW 2000.06.06  use parport_find_number instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 				parport_enumerate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	1.06    TMW 2001.03.26  more sane parport-or-not resource management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define PI_VERSION      "1.06"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/kmod.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/sched.h>	/* TASK_* */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/parport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include "paride.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define MAX_PROTOS	32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static struct pi_protocol *protocols[MAX_PROTOS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static DEFINE_SPINLOCK(pi_spinlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) void pi_write_regr(PIA * pi, int cont, int regr, int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	pi->proto->write_regr(pi, cont, regr, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) EXPORT_SYMBOL(pi_write_regr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) int pi_read_regr(PIA * pi, int cont, int regr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return pi->proto->read_regr(pi, cont, regr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) EXPORT_SYMBOL(pi_read_regr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) void pi_write_block(PIA * pi, char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	pi->proto->write_block(pi, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) EXPORT_SYMBOL(pi_write_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) void pi_read_block(PIA * pi, char *buf, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	pi->proto->read_block(pi, buf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) EXPORT_SYMBOL(pi_read_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static void pi_wake_up(void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	PIA *pi = (PIA *) p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	void (*cont) (void) = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	spin_lock_irqsave(&pi_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (pi->claim_cont && !parport_claim(pi->pardev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		cont = pi->claim_cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		pi->claim_cont = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		pi->claimed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	spin_unlock_irqrestore(&pi_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	wake_up(&(pi->parq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (cont)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		cont();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) int pi_schedule_claimed(PIA * pi, void (*cont) (void))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	spin_lock_irqsave(&pi_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (pi->pardev && parport_claim(pi->pardev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		pi->claim_cont = cont;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		spin_unlock_irqrestore(&pi_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	pi->claimed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	spin_unlock_irqrestore(&pi_spinlock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) EXPORT_SYMBOL(pi_schedule_claimed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) void pi_do_claimed(PIA * pi, void (*cont) (void))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (pi_schedule_claimed(pi, cont))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		cont();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) EXPORT_SYMBOL(pi_do_claimed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static void pi_claim(PIA * pi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (pi->claimed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	pi->claimed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (pi->pardev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		wait_event(pi->parq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			   !parport_claim((struct pardevice *) pi->pardev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static void pi_unclaim(PIA * pi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	pi->claimed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	if (pi->pardev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		parport_release((struct pardevice *) (pi->pardev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) void pi_connect(PIA * pi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	pi_claim(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	pi->proto->connect(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) EXPORT_SYMBOL(pi_connect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) void pi_disconnect(PIA * pi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	pi->proto->disconnect(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	pi_unclaim(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) EXPORT_SYMBOL(pi_disconnect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static void pi_unregister_parport(PIA * pi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (pi->pardev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		parport_unregister_device((struct pardevice *) (pi->pardev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		pi->pardev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) void pi_release(PIA * pi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	pi_unregister_parport(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	if (pi->proto->release_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		pi->proto->release_proto(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	module_put(pi->proto->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) EXPORT_SYMBOL(pi_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static int default_test_proto(PIA * pi, char *scratch, int verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int e[2] = { 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	pi->proto->connect(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	for (j = 0; j < 2; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		pi_write_regr(pi, 0, 6, 0xa0 + j * 0x10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		for (k = 0; k < 256; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			pi_write_regr(pi, 0, 2, k ^ 0xaa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 			pi_write_regr(pi, 0, 3, k ^ 0x55);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 			if (pi_read_regr(pi, 0, 2) != (k ^ 0xaa))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				e[j]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	pi->proto->disconnect(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		printk("%s: %s: port 0x%x, mode  %d, test=(%d,%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		       pi->device, pi->proto->name, pi->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		       pi->mode, e[0], e[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return (e[0] && e[1]);	/* not here if both > 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static int pi_test_proto(PIA * pi, char *scratch, int verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	pi_claim(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (pi->proto->test_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		res = pi->proto->test_proto(pi, scratch, verbose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		res = default_test_proto(pi, scratch, verbose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	pi_unclaim(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) int paride_register(PIP * pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	int k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	for (k = 0; k < MAX_PROTOS; k++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		if (protocols[k] && !strcmp(pr->name, protocols[k]->name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			printk("paride: %s protocol already registered\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			       pr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	k = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	while ((k < MAX_PROTOS) && (protocols[k]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		k++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (k == MAX_PROTOS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		printk("paride: protocol table full\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	protocols[k] = pr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	pr->index = k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	printk("paride: %s registered as protocol %d\n", pr->name, k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) EXPORT_SYMBOL(paride_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) void paride_unregister(PIP * pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	if (!pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (protocols[pr->index] != pr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		printk("paride: %s not registered\n", pr->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	protocols[pr->index] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) EXPORT_SYMBOL(paride_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static int pi_register_parport(PIA *pi, int verbose, int unit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	struct parport *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct pardev_cb par_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	port = parport_find_base(pi->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (!port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	memset(&par_cb, 0, sizeof(par_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	par_cb.wakeup = pi_wake_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	par_cb.private = (void *)pi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	pi->pardev = parport_register_dev_model(port, pi->device, &par_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 						unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	parport_put_port(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (!pi->pardev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	init_waitqueue_head(&pi->parq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		printk("%s: 0x%x is %s\n", pi->device, pi->port, port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	pi->parname = (char *) port->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static int pi_probe_mode(PIA * pi, int max, char *scratch, int verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	int best, range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	if (pi->mode != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		if (pi->mode >= max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		range = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		if (pi->mode >= pi->proto->epp_first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			range = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		if ((range == 8) && (pi->port % 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		pi->reserved = range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		return (!pi_test_proto(pi, scratch, verbose));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	best = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	for (pi->mode = 0; pi->mode < max; pi->mode++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		range = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		if (pi->mode >= pi->proto->epp_first)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			range = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		if ((range == 8) && (pi->port % 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		pi->reserved = range;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		if (!pi_test_proto(pi, scratch, verbose))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 			best = pi->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	pi->mode = best;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	return (best > -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static int pi_probe_unit(PIA * pi, int unit, char *scratch, int verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	int max, s, e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	s = unit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	e = s + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (s == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		s = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		e = pi->proto->max_units;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	if (!pi_register_parport(pi, verbose, s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (pi->proto->test_port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		pi_claim(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		max = pi->proto->test_port(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		pi_unclaim(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		max = pi->proto->max_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (pi->proto->probe_unit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		pi_claim(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		for (pi->unit = s; pi->unit < e; pi->unit++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 			if (pi->proto->probe_unit(pi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 				pi_unclaim(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				if (pi_probe_mode(pi, max, scratch, verbose))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 					return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 				pi_unregister_parport(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		pi_unclaim(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		pi_unregister_parport(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	if (!pi_probe_mode(pi, max, scratch, verbose)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		pi_unregister_parport(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int pi_init(PIA * pi, int autoprobe, int port, int mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	int unit, int protocol, int delay, char *scratch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	int devtype, int verbose, char *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	int p, k, s, e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	int lpts[7] = { 0x3bc, 0x378, 0x278, 0x268, 0x27c, 0x26c, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	s = protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	e = s + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (!protocols[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		request_module("paride_protocol");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (autoprobe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		s = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		e = MAX_PROTOS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	} else if ((s < 0) || (s >= MAX_PROTOS) || (port <= 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		   (!protocols[s]) || (unit < 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		   (unit >= protocols[s]->max_units)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		printk("%s: Invalid parameters\n", device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	for (p = s; p < e; p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		struct pi_protocol *proto = protocols[p];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		if (!proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		/* still racy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		if (!try_module_get(proto->owner))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		pi->proto = proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		pi->private = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		if (proto->init_proto && proto->init_proto(pi) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			pi->proto = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			module_put(proto->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		if (delay == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			pi->delay = pi->proto->default_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			pi->delay = delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		pi->devtype = devtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		pi->device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		pi->parname = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		pi->pardev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		init_waitqueue_head(&pi->parq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		pi->claimed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		pi->claim_cont = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		pi->mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		if (port != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			pi->port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			if (pi_probe_unit(pi, unit, scratch, verbose))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			pi->port = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			k = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			while ((pi->port = lpts[k++]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 				if (pi_probe_unit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 				    (pi, unit, scratch, verbose))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			if (pi->port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		if (pi->proto->release_proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 			pi->proto->release_proto(pi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		module_put(proto->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	if (!pi->port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		if (autoprobe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 			printk("%s: Autoprobe failed\n", device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			printk("%s: Adapter not found\n", device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	if (pi->parname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		printk("%s: Sharing %s at 0x%x\n", pi->device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		       pi->parname, pi->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	pi->proto->log_adapter(pi, scratch, verbose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) EXPORT_SYMBOL(pi_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static int pi_probe(struct pardevice *par_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	struct device_driver *drv = par_dev->dev.driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	int len = strlen(drv->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (strncmp(par_dev->name, drv->name, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) void *pi_register_driver(char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	struct parport_driver *parp_drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	parp_drv = kzalloc(sizeof(*parp_drv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (!parp_drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	parp_drv->name = name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	parp_drv->probe = pi_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	parp_drv->devmodel = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	ret = parport_register_driver(parp_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		kfree(parp_drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	return (void *)parp_drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) EXPORT_SYMBOL(pi_register_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) void pi_unregister_driver(void *_drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	struct parport_driver *drv = _drv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	parport_unregister_driver(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	kfree(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) EXPORT_SYMBOL(pi_unregister_driver);