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)  * IEEE 1284.3 Parallel port daisy chain and multiplexor code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 1999, 2000  Tim Waugh <tim@cyberelk.demon.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * modify it under the terms of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * as published by the Free Software Foundation; either version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * 2 of the License, or (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * ??-12-1998: Initial implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * 31-01-1999: Make port-cloning transparent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * 13-02-1999: Move DeviceID technique from parport_probe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * 13-03-1999: Get DeviceID from non-IEEE 1284.3 devices too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * 22-02-2000: Count devices that are actually detected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Any part of this program may be used in documents licensed under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * the GNU Free Documentation License, Version 1.1 or any later version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/parport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <asm/current.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static struct daisydev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct daisydev *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	struct parport *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	int daisy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int devnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) } *topology = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static DEFINE_SPINLOCK(topology_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static int numdevs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static bool daisy_init_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /* Forward-declaration of lower-level functions. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int mux_present(struct parport *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static int num_mux_ports(struct parport *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static int select_port(struct parport *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static int assign_addrs(struct parport *port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) /* Add a device to the discovered topology. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static void add_dev(int devnum, struct parport *port, int daisy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct daisydev *newdev, **p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	newdev = kmalloc(sizeof(struct daisydev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (newdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		newdev->port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		newdev->daisy = daisy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		newdev->devnum = devnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		spin_lock(&topology_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		for (p = &topology; *p && (*p)->devnum<devnum; p = &(*p)->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		newdev->next = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		*p = newdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		spin_unlock(&topology_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /* Clone a parport (actually, make an alias). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static struct parport *clone_parport(struct parport *real, int muxport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct parport *extra = parport_register_port(real->base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 						       real->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 						       real->dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 						       real->ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (extra) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		extra->portnum = real->portnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		extra->physport = real;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		extra->muxport = muxport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		real->slaves[muxport-1] = extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static int daisy_drv_probe(struct pardevice *par_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct device_driver *drv = par_dev->dev.driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (strcmp(drv->name, "daisy_drv"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (strcmp(par_dev->name, daisy_dev_name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static struct parport_driver daisy_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	.name = "daisy_drv",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	.probe = daisy_drv_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	.devmodel = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Discover the IEEE1284.3 topology on a port -- muxes and daisy chains.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * Return value is number of devices actually detected. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int parport_daisy_init(struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	int detected = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	char *deviceid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	static const char *th[] = { /*0*/"th", "st", "nd", "rd", "th" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	int num_ports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	int last_try = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (!daisy_init_done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		 * flag should be marked true first as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		 * parport_register_driver() might try to load the low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		 * level driver which will lead to announcing new ports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		 * and which will again come back here at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		 * parport_daisy_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		daisy_init_done = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		i = parport_register_driver(&daisy_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		if (i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			pr_err("daisy registration failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			daisy_init_done = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	/* Because this is called before any other devices exist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	 * we don't have to claim exclusive access.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	/* If mux present on normal port, need to create new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * parports for each extra port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (port->muxport < 0 && mux_present(port) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	    /* don't be fooled: a mux must have 2 or 4 ports. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	    ((num_ports = num_mux_ports(port)) == 2 || num_ports == 4)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		/* Leave original as port zero. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		port->muxport = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		pr_info("%s: 1st (default) port of %d-way multiplexor\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			port->name, num_ports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		for (i = 1; i < num_ports; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			/* Clone the port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			struct parport *extra = clone_parport(port, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			if (!extra) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				if (signal_pending(current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			pr_info("%s: %d%s port of %d-way multiplexor on %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				extra->name, i + 1, th[i + 1], num_ports,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			/* Analyse that port too.  We won't recurse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			   forever because of the 'port->muxport < 0'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			   test above. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			parport_daisy_init(extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (port->muxport >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		select_port(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	parport_daisy_deselect_all(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	detected += assign_addrs(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	/* Count the potential legacy device at the end. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	add_dev(numdevs++, port, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* Find out the legacy device's IEEE 1284 device ID. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	deviceid = kmalloc(1024, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (deviceid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		if (parport_device_id(numdevs - 1, deviceid, 1024) > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			detected++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		kfree(deviceid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!detected && !last_try) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		/* No devices were detected.  Perhaps they are in some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)                    funny state; let's try to reset them and see if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)                    they wake up. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		parport_daisy_fini(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		parport_write_control(port, PARPORT_CONTROL_SELECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		udelay(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		parport_write_control(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 				       PARPORT_CONTROL_SELECT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 				       PARPORT_CONTROL_INIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		udelay(50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		last_try = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	return detected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Forget about devices on a physical port. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) void parport_daisy_fini(struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct daisydev **p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	spin_lock(&topology_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	p = &topology;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	while (*p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		struct daisydev *dev = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		if (dev->port != port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			p = &dev->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		*p = dev->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		kfree(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	/* Gaps in the numbering could be handled better.  How should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)            someone enumerate through all IEEE1284.3 devices in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)            topology?. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (!topology) numdevs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	spin_unlock(&topology_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  *	parport_open - find a device by canonical device number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  *	@devnum: canonical device number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  *	@name: name to associate with the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  *	This function is similar to parport_register_device(), except
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  *	that it locates a device by its number rather than by the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  *	it is attached to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  *	All parameters except for @devnum are the same as for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  *	parport_register_device().  The return value is the same as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  *	for parport_register_device().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct pardevice *parport_open(int devnum, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct daisydev *p = topology;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct pardev_cb par_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	struct parport *port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	struct pardevice *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	int daisy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	memset(&par_cb, 0, sizeof(par_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	spin_lock(&topology_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	while (p && p->devnum != devnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		p = p->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (!p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		spin_unlock(&topology_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	daisy = p->daisy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	port = parport_get_port(p->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	spin_unlock(&topology_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	dev = parport_register_dev_model(port, name, &par_cb, devnum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	parport_put_port(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	dev->daisy = daisy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	/* Check that there really is a device to select. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (daisy >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		int selected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		parport_claim_or_block(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		selected = port->daisy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		parport_release(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		if (selected != daisy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			/* No corresponding device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			parport_unregister_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)  *	parport_close - close a device opened with parport_open()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)  *	@dev: device to close
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  *	This is to parport_open() as parport_unregister_device() is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  *	parport_register_device().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) void parport_close(struct pardevice *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	parport_unregister_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* Send a daisy-chain-style CPP command packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static int cpp_daisy(struct parport *port, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	unsigned char s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	parport_data_forward(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	parport_write_data(port, 0xaa); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	parport_write_data(port, 0x55); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	parport_write_data(port, 0x00); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	parport_write_data(port, 0xff); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	s = parport_read_status(port) & (PARPORT_STATUS_BUSY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 					  | PARPORT_STATUS_PAPEROUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 					  | PARPORT_STATUS_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 					  | PARPORT_STATUS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (s != (PARPORT_STATUS_BUSY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		  | PARPORT_STATUS_PAPEROUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		  | PARPORT_STATUS_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		  | PARPORT_STATUS_ERROR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		pr_debug("%s: cpp_daisy: aa5500ff(%02x)\n", port->name, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	parport_write_data(port, 0x87); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	s = parport_read_status(port) & (PARPORT_STATUS_BUSY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 					  | PARPORT_STATUS_PAPEROUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 					  | PARPORT_STATUS_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 					  | PARPORT_STATUS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if (s != (PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		pr_debug("%s: cpp_daisy: aa5500ff87(%02x)\n", port->name, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	parport_write_data(port, 0x78); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	parport_write_data(port, cmd); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	parport_frob_control(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			      PARPORT_CONTROL_STROBE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			      PARPORT_CONTROL_STROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	s = parport_read_status(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	parport_frob_control(port, PARPORT_CONTROL_STROBE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	parport_write_data(port, 0xff); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	return s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* Send a mux-style CPP command packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) static int cpp_mux(struct parport *port, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	unsigned char s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	parport_data_forward(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	parport_write_data(port, 0xaa); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	parport_write_data(port, 0x55); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	parport_write_data(port, 0xf0); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	parport_write_data(port, 0x0f); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	parport_write_data(port, 0x52); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	parport_write_data(port, 0xad); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	parport_write_data(port, cmd); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	s = parport_read_status(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	if (!(s & PARPORT_STATUS_ACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		pr_debug("%s: cpp_mux: aa55f00f52ad%02x(%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 			 port->name, cmd, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	rc = (((s & PARPORT_STATUS_SELECT   ? 1 : 0) << 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	      ((s & PARPORT_STATUS_PAPEROUT ? 1 : 0) << 1) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	      ((s & PARPORT_STATUS_BUSY     ? 0 : 1) << 2) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	      ((s & PARPORT_STATUS_ERROR    ? 0 : 1) << 3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) void parport_daisy_deselect_all(struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	cpp_daisy(port, 0x30);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) int parport_daisy_select(struct parport *port, int daisy, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	switch (mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		// For these modes we should switch to EPP mode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		case IEEE1284_MODE_EPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		case IEEE1284_MODE_EPPSL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		case IEEE1284_MODE_EPPSWE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			return !(cpp_daisy(port, 0x20 + daisy) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 				 PARPORT_STATUS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		// For these modes we should switch to ECP mode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		case IEEE1284_MODE_ECP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		case IEEE1284_MODE_ECPRLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		case IEEE1284_MODE_ECPSWE: 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			return !(cpp_daisy(port, 0xd0 + daisy) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 				 PARPORT_STATUS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		// Nothing was told for BECP in Daisy chain specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		// May be it's wise to use ECP?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		case IEEE1284_MODE_BECP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		// Others use compat mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		case IEEE1284_MODE_NIBBLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		case IEEE1284_MODE_BYTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		case IEEE1284_MODE_COMPAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			return !(cpp_daisy(port, 0xe0 + daisy) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 				 PARPORT_STATUS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static int mux_present(struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	return cpp_mux(port, 0x51) == 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static int num_mux_ports(struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	return cpp_mux(port, 0x58);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static int select_port(struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	int muxport = port->muxport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	return cpp_mux(port, 0x60 + muxport) == muxport;
^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) static int assign_addrs(struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	unsigned char s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	unsigned char daisy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	int thisdev = numdevs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	int detected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	char *deviceid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	parport_data_forward(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	parport_write_data(port, 0xaa); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	parport_write_data(port, 0x55); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	parport_write_data(port, 0x00); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	parport_write_data(port, 0xff); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	s = parport_read_status(port) & (PARPORT_STATUS_BUSY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 					  | PARPORT_STATUS_PAPEROUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 					  | PARPORT_STATUS_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 					  | PARPORT_STATUS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	if (s != (PARPORT_STATUS_BUSY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		  | PARPORT_STATUS_PAPEROUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		  | PARPORT_STATUS_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		  | PARPORT_STATUS_ERROR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		pr_debug("%s: assign_addrs: aa5500ff(%02x)\n", port->name, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	parport_write_data(port, 0x87); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	s = parport_read_status(port) & (PARPORT_STATUS_BUSY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 					  | PARPORT_STATUS_PAPEROUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 					  | PARPORT_STATUS_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 					  | PARPORT_STATUS_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	if (s != (PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		pr_debug("%s: assign_addrs: aa5500ff87(%02x)\n", port->name, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	parport_write_data(port, 0x78); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	s = parport_read_status(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	for (daisy = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	     (s & (PARPORT_STATUS_PAPEROUT|PARPORT_STATUS_SELECT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		     == (PARPORT_STATUS_PAPEROUT|PARPORT_STATUS_SELECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		     && daisy < 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	     ++daisy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		parport_write_data(port, daisy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		parport_frob_control(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 				      PARPORT_CONTROL_STROBE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 				      PARPORT_CONTROL_STROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		parport_frob_control(port, PARPORT_CONTROL_STROBE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		add_dev(numdevs++, port, daisy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		/* See if this device thought it was the last in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		 * chain. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		if (!(s & PARPORT_STATUS_BUSY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		/* We are seeing pass through status now. We see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		   last_dev from next device or if last_dev does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		   work status lines from some non-daisy chain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		   device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		s = parport_read_status(port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	parport_write_data(port, 0xff); udelay(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	detected = numdevs - thisdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	pr_debug("%s: Found %d daisy-chained devices\n", port->name, detected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	/* Ask the new devices to introduce themselves. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	deviceid = kmalloc(1024, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	if (!deviceid) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	for (daisy = 0; thisdev < numdevs; thisdev++, daisy++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		parport_device_id(thisdev, deviceid, 1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	kfree(deviceid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	return detected;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }