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) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * Generic parallel printer driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (C) 1992 by Jim Weigand and Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (C) 1992,1993 by Michael K. Johnson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * - Thanks much to Gunter Windau for pointing out to me where the error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *   checking ought to be.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  * Copyright (C) 1993 by Nigel Gamble (added interrupt code)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * Copyright (C) 1994 by Alan Cox (Modularised it)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * LPCAREFUL, LPABORT, LPGETSTATUS added by Chris Metcalf, metcalf@lcs.mit.edu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * Statistics and support for slow printers by Rob Janssen, rob@knoware.nl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * "lp=" command line parameters added by Grant Guenther, grant@torque.net
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * lp_read (Status readback) support added by Carsten Gross,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *                                             carsten@sol.wohnheim.uni-ulm.de
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  * Support for parport by Philip Blundell <philb@gnu.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  * Parport sharing hacking by Andrea Arcangeli
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * Fixed kernel_(to/from)_user memory copy to check for errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  * 				by Riccardo Facchetti <fizban@tin.it>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * 22-JAN-1998  Added support for devfs  Richard Gooch <rgooch@atnf.csiro.au>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  * Redesigned interrupt handling for handle printers with buggy handshake
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *				by Andrea Arcangeli, 11 May 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  * Full efficient handling of printer with buggy irq handshake (now I have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * understood the meaning of the strange handshake). This is done sending new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  * characters if the interrupt is just happened, even if the printer say to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * be still BUSY. This is needed at least with Epson Stylus Color. To enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  * the new TRUST_IRQ mode read the `LP OPTIMIZATION' section below...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * Fixed the irq on the rising edge of the strobe case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * Obsoleted the CAREFUL flag since a printer that doesn' t work with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  * CAREFUL will block a bit after in lp_check_status().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  *				Andrea Arcangeli, 15 Oct 1998
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  * Obsoleted and removed all the lowlevel stuff implemented in the last
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  * month to use the IEEE1284 functions (that handle the _new_ compatibilty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  * mode fine).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) /* This driver should, in theory, work with any parallel port that has an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38)  * appropriate low-level driver; all I/O is done through the parport
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39)  * abstraction layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41)  * If this driver is built into the kernel, you can configure it using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42)  * kernel command-line.  For example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44)  *	lp=parport1,none,parport2	(bind lp0 to parport1, disable lp1 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45)  *					 bind lp2 to parport2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47)  *	lp=auto				(assign lp devices to all ports that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48)  *				         have printers attached, as determined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49)  *					 by the IEEE-1284 autoprobe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)  *	lp=reset			(reset the printer during
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)  *					 initialisation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54)  *	lp=off				(disable the printer driver entirely)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56)  * If the driver is loaded as a module, similar functionality is available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57)  * using module parameters.  The equivalent of the above commands would be:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)  *	# insmod lp.o parport=1,none,2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61)  *	# insmod lp.o parport=auto
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)  *	# insmod lp.o reset=1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) /* COMPATIBILITY WITH OLD KERNELS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  * Under Linux 2.0 and previous versions, lp devices were bound to ports at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  * particular I/O addresses, as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  *	lp0		0x3bc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72)  *	lp1		0x378
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73)  *	lp2		0x278
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  * The new driver, by default, binds lp devices to parport devices as it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  * finds them.  This means that if you only have one port, it will be bound
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  * to lp0 regardless of its I/O address.  If you need the old behaviour, you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78)  * can force it using the parameters described above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79)  */
^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)  * The new interrupt handling code take care of the buggy handshake
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)  * of some HP and Epson printer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  * ___
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  * ACK    _______________    ___________
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86)  *                       |__|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87)  * ____
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88)  * BUSY   _________              _______
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89)  *                 |____________|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * I discovered this using the printer scanner that you can find at:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  *	ftp://e-mind.com/pub/linux/pscan/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  *					11 May 98, Andrea Arcangeli
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  * My printer scanner run on an Epson Stylus Color show that such printer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  * generates the irq on the _rising_ edge of the STROBE. Now lp handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  * this case fine too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101)  *					15 Oct 1998, Andrea Arcangeli
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  * The so called `buggy' handshake is really the well documented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  * compatibility mode IEEE1284 handshake. They changed the well known
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  * Centronics handshake acking in the middle of busy expecting to not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106)  * break drivers or legacy application, while they broken linux lp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107)  * until I fixed it reverse engineering the protocol by hand some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  * month ago...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  *                                     14 Dec 1998, Andrea Arcangeli
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  * Copyright (C) 2000 by Tim Waugh (added LPSETTIMEOUT ioctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) #include <linux/console.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #include <linux/parport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) #undef LP_STATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) #include <linux/lp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) /* if you have more than 8 printers, remember to increase LP_NO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) #define LP_NO 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) static DEFINE_MUTEX(lp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static struct lp_struct lp_table[LP_NO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) static int port_num[LP_NO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static unsigned int lp_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) static struct class *lp_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) #ifdef CONFIG_LP_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) static struct parport *console_registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) #endif /* CONFIG_LP_CONSOLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) #undef LP_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) /* Bits used to manage claiming the parport device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) #define LP_PREEMPT_REQUEST 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) #define LP_PARPORT_CLAIMED 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) /* --- low-level port access ----------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) #define r_dtr(x)	(parport_read_data(lp_table[(x)].dev->port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) #define r_str(x)	(parport_read_status(lp_table[(x)].dev->port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) #define w_ctr(x,y)	do { parport_write_control(lp_table[(x)].dev->port, (y)); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) #define w_dtr(x,y)	do { parport_write_data(lp_table[(x)].dev->port, (y)); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) /* Claim the parport or block trying unless we've already claimed it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) static void lp_claim_parport_or_block(struct lp_struct *this_lp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	if (!test_and_set_bit(LP_PARPORT_CLAIMED, &this_lp->bits)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		parport_claim_or_block(this_lp->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) /* Claim the parport or block trying unless we've already claimed it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) static void lp_release_parport(struct lp_struct *this_lp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	if (test_and_clear_bit(LP_PARPORT_CLAIMED, &this_lp->bits)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		parport_release(this_lp->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) }
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) static int lp_preempt(void *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	struct lp_struct *this_lp = (struct lp_struct *)handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	set_bit(LP_PREEMPT_REQUEST, &this_lp->bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194)  * Try to negotiate to a new mode; if unsuccessful negotiate to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195)  * compatibility mode.  Return the mode we ended up in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) static int lp_negotiate(struct parport *port, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	if (parport_negotiate(port, mode) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		mode = IEEE1284_MODE_COMPAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		parport_negotiate(port, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	return mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) static int lp_reset(int minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	lp_claim_parport_or_block(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	w_ctr(minor, LP_PSELECP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	udelay(LP_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	w_ctr(minor, LP_PSELECP | LP_PINITP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	retval = r_str(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	lp_release_parport(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	return retval;
^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) static void lp_error(int minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	int polling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	if (LP_F(minor) & LP_ABORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	polling = lp_table[minor].dev->port->irq == PARPORT_IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	if (polling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		lp_release_parport(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	prepare_to_wait(&lp_table[minor].waitq, &wait, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	schedule_timeout(LP_TIMEOUT_POLLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	finish_wait(&lp_table[minor].waitq, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	if (polling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		lp_claim_parport_or_block(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		parport_yield_blocking(lp_table[minor].dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) static int lp_check_status(int minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	unsigned int last = lp_table[minor].last_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	unsigned char status = r_str(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	if ((status & LP_PERRORP) && !(LP_F(minor) & LP_CAREFUL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		/* No error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		last = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	else if ((status & LP_POUTPA)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		if (last != LP_POUTPA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 			last = LP_POUTPA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 			printk(KERN_INFO "lp%d out of paper\n", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		error = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 	} else if (!(status & LP_PSELECD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 		if (last != LP_PSELECD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 			last = LP_PSELECD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 			printk(KERN_INFO "lp%d off-line\n", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 		error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	} else if (!(status & LP_PERRORP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 		if (last != LP_PERRORP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 			last = LP_PERRORP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 			printk(KERN_INFO "lp%d on fire\n", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 		last = 0; /* Come here if LP_CAREFUL is set and no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 			     errors are reported. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	lp_table[minor].last_error = last;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	if (last != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		lp_error(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) static int lp_wait_ready(int minor, int nonblock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	/* If we're not in compatibility mode, we're ready now! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	if (lp_table[minor].current_mode != IEEE1284_MODE_COMPAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		return 0;
^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) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		error = lp_check_status(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		if (error && (nonblock || (LP_F(minor) & LP_ABORT)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		if (signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 			error = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	} while (error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) static ssize_t lp_write(struct file *file, const char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 			size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	unsigned int minor = iminor(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	struct parport *port = lp_table[minor].dev->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	char *kbuf = lp_table[minor].lp_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	ssize_t retv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	ssize_t written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	size_t copy_size = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	int nonblock = ((file->f_flags & O_NONBLOCK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 			(LP_F(minor) & LP_ABORT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) #ifdef LP_STATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	if (time_after(jiffies, lp_table[minor].lastcall + LP_TIME(minor)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		lp_table[minor].runchars = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	lp_table[minor].lastcall = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	/* Need to copy the data from user-space. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	if (copy_size > LP_BUFFER_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		copy_size = LP_BUFFER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	if (copy_from_user(kbuf, buf, copy_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		retv = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	/* Claim Parport or sleep until it becomes available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	lp_claim_parport_or_block(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	/* Go to the proper mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	lp_table[minor].current_mode = lp_negotiate(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 						    lp_table[minor].best_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	parport_set_timeout(lp_table[minor].dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 			    (nonblock ? PARPORT_INACTIVITY_O_NONBLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 			     : lp_table[minor].timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	if ((retv = lp_wait_ready(minor, nonblock)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		/* Write the data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 		written = parport_write(port, kbuf, copy_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		if (written > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 			copy_size -= written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 			count -= written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			buf  += written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 			retv += written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		if (signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 			if (retv == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 				retv = -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		if (copy_size > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 			/* incomplete write -> check error ! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 			int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			parport_negotiate(lp_table[minor].dev->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 					  IEEE1284_MODE_COMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 			lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 			error = lp_wait_ready(minor, nonblock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 			if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 				if (retv == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 					retv = error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 			} else if (nonblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 				if (retv == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 					retv = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 			parport_yield_blocking(lp_table[minor].dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			lp_table[minor].current_mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 			  = lp_negotiate(port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 					 lp_table[minor].best_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		} else if (need_resched())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 			schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		if (count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 			copy_size = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 			if (copy_size > LP_BUFFER_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 				copy_size = LP_BUFFER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 			if (copy_from_user(kbuf, buf, copy_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 				if (retv == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 					retv = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	} while (count > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	if (test_and_clear_bit(LP_PREEMPT_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 			       &lp_table[minor].bits)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		printk(KERN_INFO "lp%d releasing parport\n", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		parport_negotiate(lp_table[minor].dev->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 				  IEEE1284_MODE_COMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		lp_release_parport(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	mutex_unlock(&lp_table[minor].port_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	return retv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) #ifdef CONFIG_PARPORT_1284
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) /* Status readback conforming to ieee1284 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) static ssize_t lp_read(struct file *file, char __user *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		       size_t count, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	DEFINE_WAIT(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	unsigned int minor=iminor(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	struct parport *port = lp_table[minor].dev->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	ssize_t retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	char *kbuf = lp_table[minor].lp_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	int nonblock = ((file->f_flags & O_NONBLOCK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 			(LP_F(minor) & LP_ABORT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	if (count > LP_BUFFER_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		count = LP_BUFFER_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	lp_claim_parport_or_block(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	parport_set_timeout(lp_table[minor].dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 			    (nonblock ? PARPORT_INACTIVITY_O_NONBLOCK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 			     : lp_table[minor].timeout));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	parport_negotiate(lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	if (parport_negotiate(lp_table[minor].dev->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 			      IEEE1284_MODE_NIBBLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	while (retval == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		retval = parport_read(port, kbuf, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		if (retval > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		if (nonblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 			retval = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		/* Wait for data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		if (lp_table[minor].dev->port->irq == PARPORT_IRQ_NONE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 			parport_negotiate(lp_table[minor].dev->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 					  IEEE1284_MODE_COMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 			lp_error(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 			if (parport_negotiate(lp_table[minor].dev->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 					      IEEE1284_MODE_NIBBLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 				retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 			prepare_to_wait(&lp_table[minor].waitq, &wait, TASK_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 			schedule_timeout(LP_TIMEOUT_POLLED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 			finish_wait(&lp_table[minor].waitq, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		if (signal_pending(current)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			retval = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	parport_negotiate(lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	lp_release_parport(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	if (retval > 0 && copy_to_user(buf, kbuf, retval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		retval = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	mutex_unlock(&lp_table[minor].port_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	return retval;
^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) #endif /* IEEE 1284 support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) static int lp_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	unsigned int minor = iminor(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	mutex_lock(&lp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	if (minor >= LP_NO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	if ((LP_F(minor) & LP_EXIST) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	if (test_and_set_bit(LP_BUSY_BIT_POS, &LP_F(minor))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	/* If ABORTOPEN is set and the printer is offline or out of paper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	   we may still want to open it to perform ioctl()s.  Therefore we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	   have commandeered O_NONBLOCK, even though it is being used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	   a non-standard manner.  This is strictly a Linux hack, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	   should most likely only ever be used by the tunelp application. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	if ((LP_F(minor) & LP_ABORTOPEN) && !(file->f_flags & O_NONBLOCK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		lp_claim_parport_or_block(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		status = r_str(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 		lp_release_parport(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		if (status & LP_POUTPA) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 			printk(KERN_INFO "lp%d out of paper\n", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 			LP_F(minor) &= ~LP_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			ret = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		} else if (!(status & LP_PSELECD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 			printk(KERN_INFO "lp%d off-line\n", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			LP_F(minor) &= ~LP_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		} else if (!(status & LP_PERRORP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 			printk(KERN_ERR "lp%d printer error\n", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 			LP_F(minor) &= ~LP_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	lp_table[minor].lp_buffer = kmalloc(LP_BUFFER_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	if (!lp_table[minor].lp_buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		LP_F(minor) &= ~LP_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	/* Determine if the peripheral supports ECP mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	lp_claim_parport_or_block(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	if ( (lp_table[minor].dev->port->modes & PARPORT_MODE_ECP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	     !parport_negotiate(lp_table[minor].dev->port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 				 IEEE1284_MODE_ECP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		printk(KERN_INFO "lp%d: ECP mode\n", minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		lp_table[minor].best_mode = IEEE1284_MODE_ECP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		lp_table[minor].best_mode = IEEE1284_MODE_COMPAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 	/* Leave peripheral in compatibility mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	parport_negotiate(lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	lp_release_parport(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	mutex_unlock(&lp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) static int lp_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	unsigned int minor = iminor(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	lp_claim_parport_or_block(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	parport_negotiate(lp_table[minor].dev->port, IEEE1284_MODE_COMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	lp_table[minor].current_mode = IEEE1284_MODE_COMPAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	lp_release_parport(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	kfree(lp_table[minor].lp_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	lp_table[minor].lp_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	LP_F(minor) &= ~LP_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) static int lp_do_ioctl(unsigned int minor, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	unsigned long arg, void __user *argp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) #ifdef LP_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	printk(KERN_DEBUG "lp%d ioctl, cmd: 0x%x, arg: 0x%lx\n", minor, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	if (minor >= LP_NO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	if ((LP_F(minor) & LP_EXIST) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	switch ( cmd ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		case LPTIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 			if (arg > UINT_MAX / HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 				return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 			LP_TIME(minor) = arg * HZ/100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		case LPCHAR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 			LP_CHAR(minor) = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		case LPABORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 			if (arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 				LP_F(minor) |= LP_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 				LP_F(minor) &= ~LP_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 		case LPABORTOPEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 			if (arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 				LP_F(minor) |= LP_ABORTOPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 				LP_F(minor) &= ~LP_ABORTOPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		case LPCAREFUL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 			if (arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 				LP_F(minor) |= LP_CAREFUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 				LP_F(minor) &= ~LP_CAREFUL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		case LPWAIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 			LP_WAIT(minor) = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 		case LPSETIRQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 		case LPGETIRQ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			if (copy_to_user(argp, &LP_IRQ(minor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 					sizeof(int)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		case LPGETSTATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 			if (mutex_lock_interruptible(&lp_table[minor].port_mutex))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 				return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 			lp_claim_parport_or_block(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 			status = r_str(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 			lp_release_parport(&lp_table[minor]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 			mutex_unlock(&lp_table[minor].port_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 			if (copy_to_user(argp, &status, sizeof(int)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		case LPRESET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 			lp_reset(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) #ifdef LP_STATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		case LPGETSTATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 			if (copy_to_user(argp, &LP_STAT(minor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 					sizeof(struct lp_stats)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 			if (capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 				memset(&LP_STAT(minor), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 						sizeof(struct lp_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		case LPGETFLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 			status = LP_F(minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 			if (copy_to_user(argp, &status, sizeof(int)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 				return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 			retval = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) static int lp_set_timeout(unsigned int minor, s64 tv_sec, long tv_usec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	long to_jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	/* Convert to jiffies, place in lp_table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	if (tv_sec < 0 || tv_usec < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	 * we used to not check, so let's not make this fatal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 	 * but deal with user space passing a 32-bit tv_nsec in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	 * a 64-bit field, capping the timeout to 1 second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	 * worth of microseconds, and capping the total at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	 * MAX_JIFFY_OFFSET.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	if (tv_usec > 999999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		tv_usec = 999999;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	if (tv_sec >= MAX_SEC_IN_JIFFIES - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		to_jiffies = MAX_JIFFY_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		to_jiffies = DIV_ROUND_UP(tv_usec, 1000000/HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		to_jiffies += tv_sec * (long) HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	if (to_jiffies <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	lp_table[minor].timeout = to_jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) static int lp_set_timeout32(unsigned int minor, void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	s32 karg[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	if (copy_from_user(karg, arg, sizeof(karg)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	return lp_set_timeout(minor, karg[0], karg[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) static int lp_set_timeout64(unsigned int minor, void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	s64 karg[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	if (copy_from_user(karg, arg, sizeof(karg)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	/* sparc64 suseconds_t is 32-bit only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	if (IS_ENABLED(CONFIG_SPARC64) && !in_compat_syscall())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		karg[1] >>= 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	return lp_set_timeout(minor, karg[0], karg[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) static long lp_ioctl(struct file *file, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 			unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	unsigned int minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	minor = iminor(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	mutex_lock(&lp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	case LPSETTIMEOUT_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		if (BITS_PER_LONG == 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 			ret = lp_set_timeout32(minor, (void __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		fallthrough;	/* for 64-bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	case LPSETTIMEOUT_NEW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		ret = lp_set_timeout64(minor, (void __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		ret = lp_do_ioctl(minor, cmd, arg, (void __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	mutex_unlock(&lp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) static long lp_compat_ioctl(struct file *file, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 			unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	unsigned int minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	minor = iminor(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	mutex_lock(&lp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	case LPSETTIMEOUT_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		if (!COMPAT_USE_64BIT_TIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 			ret = lp_set_timeout32(minor, (void __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		fallthrough;	/* for x32 mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	case LPSETTIMEOUT_NEW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		ret = lp_set_timeout64(minor, (void __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) #ifdef LP_STATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	case LPGETSTATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 		/* FIXME: add an implementation if you set LP_STATS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		ret = lp_do_ioctl(minor, cmd, arg, compat_ptr(arg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	mutex_unlock(&lp_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) static const struct file_operations lp_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	.write		= lp_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	.unlocked_ioctl	= lp_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	.compat_ioctl	= lp_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	.open		= lp_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	.release	= lp_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) #ifdef CONFIG_PARPORT_1284
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	.read		= lp_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	.llseek		= noop_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) /* --- support for console on the line printer ----------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) #ifdef CONFIG_LP_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) #define CONSOLE_LP 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) /* If the printer is out of paper, we can either lose the messages or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807)  * stall until the printer is happy again.  Define CONSOLE_LP_STRICT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808)  * non-zero to get the latter behaviour. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) #define CONSOLE_LP_STRICT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) /* The console must be locked when we get here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) static void lp_console_write(struct console *co, const char *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 			     unsigned count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	struct pardevice *dev = lp_table[CONSOLE_LP].dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	struct parport *port = dev->port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	ssize_t written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	if (parport_claim(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		/* Nothing we can do. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	parport_set_timeout(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	/* Go to compatibility mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	parport_negotiate(port, IEEE1284_MODE_COMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		/* Write the data, converting LF->CRLF as we go. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		ssize_t canwrite = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		char *lf = memchr(s, '\n', count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		if (lf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			canwrite = lf - s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		if (canwrite > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 			written = parport_write(port, s, canwrite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			if (written <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 			s += written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 			count -= written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 			canwrite -= written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		if (lf && canwrite <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 			const char *crlf = "\r\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			int i = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 			/* Dodge the original '\n', and put '\r\n' instead. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 			s++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 			count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 			do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 				written = parport_write(port, crlf, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 				if (written > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 					i -= written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 					crlf += written;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 			} while (i > 0 && (CONSOLE_LP_STRICT || written > 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	} while (count > 0 && (CONSOLE_LP_STRICT || written > 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	parport_release(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) static struct console lpcons = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	.name		= "lp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	.write		= lp_console_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	.flags		= CON_PRINTBUFFER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) #endif /* console on line printer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) /* --- initialisation code ------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) static int parport_nr[LP_NO] = { [0 ... LP_NO-1] = LP_PARPORT_UNSPEC };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) static char *parport[LP_NO];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) static bool reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) module_param_array(parport, charp, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) module_param(reset, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) #ifndef MODULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) static int __init lp_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	static int parport_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	if (get_option(&str, &x)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		if (x == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 			/* disable driver on "lp=" or "lp=0" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 			parport_nr[0] = LP_PARPORT_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 			printk(KERN_WARNING "warning: 'lp=0x%x' is deprecated, ignored\n", x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	} else if (!strncmp(str, "parport", 7)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		int n = simple_strtoul(str+7, NULL, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		if (parport_ptr < LP_NO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 			parport_nr[parport_ptr++] = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 			printk(KERN_INFO "lp: too many ports, %s ignored.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 			       str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	} else if (!strcmp(str, "auto")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		parport_nr[0] = LP_PARPORT_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	} else if (!strcmp(str, "none")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		if (parport_ptr < LP_NO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 			parport_nr[parport_ptr++] = LP_PARPORT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 			printk(KERN_INFO "lp: too many ports, %s ignored.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 			       str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	} else if (!strcmp(str, "reset")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		reset = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) static int lp_register(int nr, struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	struct pardev_cb ppdev_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	memset(&ppdev_cb, 0, sizeof(ppdev_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	ppdev_cb.preempt = lp_preempt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	ppdev_cb.private = &lp_table[nr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	lp_table[nr].dev = parport_register_dev_model(port, "lp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 						      &ppdev_cb, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	if (lp_table[nr].dev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	lp_table[nr].flags |= LP_EXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	if (reset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		lp_reset(nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	device_create(lp_class, port->dev, MKDEV(LP_MAJOR, nr), NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		      "lp%d", nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	       (port->irq == PARPORT_IRQ_NONE)?"polling":"interrupt-driven");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) #ifdef CONFIG_LP_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	if (!nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		if (port->modes & PARPORT_MODE_SAFEININT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 			register_console(&lpcons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 			console_registered = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			printk(KERN_INFO "lp%d: console ready\n", CONSOLE_LP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 			printk(KERN_ERR "lp%d: cannot run console on %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 			       CONSOLE_LP, port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	port_num[nr] = port->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) static void lp_attach(struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	switch (parport_nr[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	case LP_PARPORT_UNSPEC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	case LP_PARPORT_AUTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 		if (parport_nr[0] == LP_PARPORT_AUTO &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		    port->probe_info[0].class != PARPORT_CLASS_PRINTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 		if (lp_count == LP_NO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 			printk(KERN_INFO "lp: ignoring parallel port (max. %d)\n",LP_NO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		for (i = 0; i < LP_NO; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 			if (port_num[i] == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		if (!lp_register(i, port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			lp_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		for (i = 0; i < LP_NO; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			if (port->number == parport_nr[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 				if (!lp_register(i, port))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 					lp_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) static void lp_detach(struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	/* Write this some day. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) #ifdef CONFIG_LP_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	if (console_registered == port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		unregister_console(&lpcons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		console_registered = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) #endif /* CONFIG_LP_CONSOLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	for (n = 0; n < LP_NO; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		if (port_num[n] == port->number) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 			port_num[n] = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 			lp_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 			device_destroy(lp_class, MKDEV(LP_MAJOR, n));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 			parport_unregister_device(lp_table[n].dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) static struct parport_driver lp_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	.name = "lp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	.match_port = lp_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	.detach = lp_detach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	.devmodel = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) static int __init lp_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	int i, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	if (parport_nr[0] == LP_PARPORT_OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	for (i = 0; i < LP_NO; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		lp_table[i].dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		lp_table[i].flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 		lp_table[i].chars = LP_INIT_CHAR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 		lp_table[i].time = LP_INIT_TIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		lp_table[i].wait = LP_INIT_WAIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		lp_table[i].lp_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) #ifdef LP_STATS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		lp_table[i].lastcall = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		lp_table[i].runchars = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		memset(&lp_table[i].stats, 0, sizeof(struct lp_stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		lp_table[i].last_error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		init_waitqueue_head(&lp_table[i].waitq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		init_waitqueue_head(&lp_table[i].dataq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		mutex_init(&lp_table[i].port_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		lp_table[i].timeout = 10 * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		port_num[i] = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	if (register_chrdev(LP_MAJOR, "lp", &lp_fops)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 		printk(KERN_ERR "lp: unable to get major %d\n", LP_MAJOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	lp_class = class_create(THIS_MODULE, "printer");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	if (IS_ERR(lp_class)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 		err = PTR_ERR(lp_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		goto out_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	if (parport_register_driver(&lp_driver)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		printk(KERN_ERR "lp: unable to register with parport\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 		err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		goto out_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	if (!lp_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		printk(KERN_INFO "lp: driver loaded but no devices found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) #ifndef CONFIG_PARPORT_1284
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 		if (parport_nr[0] == LP_PARPORT_AUTO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 			printk(KERN_INFO "lp: (is IEEE 1284 support enabled?)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) out_class:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	class_destroy(lp_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) out_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	unregister_chrdev(LP_MAJOR, "lp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) static int __init lp_init_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	if (parport[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		/* The user gave some parameters.  Let's see what they were.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		if (!strncmp(parport[0], "auto", 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 			parport_nr[0] = LP_PARPORT_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 			int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 			for (n = 0; n < LP_NO && parport[n]; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 				if (!strncmp(parport[n], "none", 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 					parport_nr[n] = LP_PARPORT_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 				else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 					char *ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 					unsigned long r = simple_strtoul(parport[n], &ep, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 					if (ep != parport[n])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 						parport_nr[n] = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 					else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 						printk(KERN_ERR "lp: bad port specifier `%s'\n", parport[n]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 						return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	return lp_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) static void lp_cleanup_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	parport_unregister_driver(&lp_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) #ifdef CONFIG_LP_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	unregister_console(&lpcons);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	unregister_chrdev(LP_MAJOR, "lp");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	class_destroy(lp_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) __setup("lp=", lp_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) module_init(lp_init_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) module_exit(lp_cleanup_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) MODULE_ALIAS_CHARDEV_MAJOR(LP_MAJOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) MODULE_LICENSE("GPL");