Home | History | Annotate | Line # | Download | only in ic
lpt.c revision 1.45.2.3
      1  1.45.2.3  thorpej /*	$NetBSD: lpt.c,v 1.45.2.3 1997/10/15 05:36:13 thorpej Exp $	*/
      2  1.45.2.2  thorpej 
      3  1.45.2.2  thorpej /*
      4  1.45.2.2  thorpej  * Copyright (c) 1993, 1994 Charles Hannum.
      5  1.45.2.2  thorpej  * Copyright (c) 1990 William F. Jolitz, TeleMuse
      6  1.45.2.2  thorpej  * All rights reserved.
      7  1.45.2.2  thorpej  *
      8  1.45.2.2  thorpej  * Redistribution and use in source and binary forms, with or without
      9  1.45.2.2  thorpej  * modification, are permitted provided that the following conditions
     10  1.45.2.2  thorpej  * are met:
     11  1.45.2.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     12  1.45.2.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     13  1.45.2.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.45.2.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     15  1.45.2.2  thorpej  *    documentation and/or other materials provided with the distribution.
     16  1.45.2.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     17  1.45.2.2  thorpej  *    must display the following acknowledgement:
     18  1.45.2.2  thorpej  *	This software is a component of "386BSD" developed by
     19  1.45.2.2  thorpej  *	William F. Jolitz, TeleMuse.
     20  1.45.2.2  thorpej  * 4. Neither the name of the developer nor the name "386BSD"
     21  1.45.2.2  thorpej  *    may be used to endorse or promote products derived from this software
     22  1.45.2.2  thorpej  *    without specific prior written permission.
     23  1.45.2.2  thorpej  *
     24  1.45.2.2  thorpej  * THIS SOFTWARE IS A COMPONENT OF 386BSD DEVELOPED BY WILLIAM F. JOLITZ
     25  1.45.2.2  thorpej  * AND IS INTENDED FOR RESEARCH AND EDUCATIONAL PURPOSES ONLY. THIS
     26  1.45.2.2  thorpej  * SOFTWARE SHOULD NOT BE CONSIDERED TO BE A COMMERCIAL PRODUCT.
     27  1.45.2.2  thorpej  * THE DEVELOPER URGES THAT USERS WHO REQUIRE A COMMERCIAL PRODUCT
     28  1.45.2.2  thorpej  * NOT MAKE USE OF THIS WORK.
     29  1.45.2.2  thorpej  *
     30  1.45.2.2  thorpej  * FOR USERS WHO WISH TO UNDERSTAND THE 386BSD SYSTEM DEVELOPED
     31  1.45.2.2  thorpej  * BY WILLIAM F. JOLITZ, WE RECOMMEND THE USER STUDY WRITTEN
     32  1.45.2.2  thorpej  * REFERENCES SUCH AS THE  "PORTING UNIX TO THE 386" SERIES
     33  1.45.2.2  thorpej  * (BEGINNING JANUARY 1991 "DR. DOBBS JOURNAL", USA AND BEGINNING
     34  1.45.2.2  thorpej  * JUNE 1991 "UNIX MAGAZIN", GERMANY) BY WILLIAM F. JOLITZ AND
     35  1.45.2.2  thorpej  * LYNNE GREER JOLITZ, AS WELL AS OTHER BOOKS ON UNIX AND THE
     36  1.45.2.2  thorpej  * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
     37  1.45.2.2  thorpej  * OF 386BSD ENTITLED "386BSD FROM THE INSIDE OUT" WILL BE AVAILABLE LATE 1992.
     38  1.45.2.2  thorpej  *
     39  1.45.2.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND
     40  1.45.2.2  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     41  1.45.2.2  thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     42  1.45.2.2  thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE DEVELOPER BE LIABLE
     43  1.45.2.2  thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     44  1.45.2.2  thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     45  1.45.2.2  thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     46  1.45.2.2  thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     47  1.45.2.2  thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     48  1.45.2.2  thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     49  1.45.2.2  thorpej  * SUCH DAMAGE.
     50  1.45.2.2  thorpej  */
     51  1.45.2.2  thorpej 
     52  1.45.2.2  thorpej /*
     53  1.45.2.2  thorpej  * Device Driver for AT style parallel printer port
     54  1.45.2.2  thorpej  */
     55  1.45.2.2  thorpej 
     56  1.45.2.2  thorpej #include <sys/param.h>
     57  1.45.2.2  thorpej #include <sys/systm.h>
     58  1.45.2.2  thorpej #include <sys/proc.h>
     59  1.45.2.2  thorpej #include <sys/user.h>
     60  1.45.2.2  thorpej #include <sys/buf.h>
     61  1.45.2.2  thorpej #include <sys/kernel.h>
     62  1.45.2.2  thorpej #include <sys/ioctl.h>
     63  1.45.2.2  thorpej #include <sys/uio.h>
     64  1.45.2.2  thorpej #include <sys/device.h>
     65  1.45.2.2  thorpej #include <sys/conf.h>
     66  1.45.2.2  thorpej #include <sys/syslog.h>
     67  1.45.2.2  thorpej 
     68  1.45.2.2  thorpej #include <machine/bus.h>
     69  1.45.2.2  thorpej #include <machine/intr.h>
     70  1.45.2.2  thorpej 
     71  1.45.2.2  thorpej #include <dev/ic/lptreg.h>
     72  1.45.2.2  thorpej #include <dev/ic/lptvar.h>
     73  1.45.2.2  thorpej 
     74  1.45.2.2  thorpej #define	TIMEOUT		hz*16	/* wait up to 16 seconds for a ready */
     75  1.45.2.2  thorpej #define	STEP		hz/4
     76  1.45.2.2  thorpej 
     77  1.45.2.2  thorpej #define	LPTPRI		(PZERO+8)
     78  1.45.2.2  thorpej #define	LPT_BSIZE	1024
     79  1.45.2.2  thorpej 
     80  1.45.2.2  thorpej #define LPTDEBUG
     81  1.45.2.2  thorpej 
     82  1.45.2.2  thorpej #ifndef LPTDEBUG
     83  1.45.2.2  thorpej #define LPRINTF(a)
     84  1.45.2.2  thorpej #else
     85  1.45.2.2  thorpej #define LPRINTF(a)	if (lptdebug) printf a
     86  1.45.2.2  thorpej int lptdebug = 0;
     87  1.45.2.2  thorpej #endif
     88  1.45.2.2  thorpej 
     89  1.45.2.2  thorpej /* XXX does not belong here */
     90  1.45.2.2  thorpej cdev_decl(lpt);
     91  1.45.2.2  thorpej 
     92  1.45.2.2  thorpej struct cfdriver lpt_cd = {
     93  1.45.2.2  thorpej 	NULL, "lpt", DV_TTY
     94  1.45.2.2  thorpej };
     95  1.45.2.2  thorpej 
     96  1.45.2.2  thorpej #define	LPTUNIT(s)	(minor(s) & 0x1f)
     97  1.45.2.2  thorpej #define	LPTFLAGS(s)	(minor(s) & 0xe0)
     98  1.45.2.2  thorpej 
     99  1.45.2.2  thorpej void
    100  1.45.2.2  thorpej lpt_attach_subr(sc)
    101  1.45.2.2  thorpej 	struct lpt_softc *sc;
    102  1.45.2.2  thorpej {
    103  1.45.2.2  thorpej 	bus_space_tag_t iot;
    104  1.45.2.2  thorpej 	bus_space_handle_t ioh;
    105  1.45.2.2  thorpej 
    106  1.45.2.2  thorpej 	sc->sc_state = 0;
    107  1.45.2.2  thorpej 
    108  1.45.2.2  thorpej 	iot = sc->sc_iot;
    109  1.45.2.2  thorpej 	ioh = sc->sc_ioh;
    110  1.45.2.2  thorpej 
    111  1.45.2.2  thorpej 	bus_space_write_1(iot, ioh, lpt_control, LPC_NINIT);
    112  1.45.2.2  thorpej }
    113  1.45.2.2  thorpej 
    114  1.45.2.2  thorpej /*
    115  1.45.2.2  thorpej  * Reset the printer, then wait until it's selected and not busy.
    116  1.45.2.2  thorpej  */
    117  1.45.2.2  thorpej int
    118  1.45.2.2  thorpej lptopen(dev, flag, mode, p)
    119  1.45.2.2  thorpej 	dev_t dev;
    120  1.45.2.2  thorpej 	int flag;
    121  1.45.2.2  thorpej 	int mode;
    122  1.45.2.2  thorpej 	struct proc *p;
    123  1.45.2.2  thorpej {
    124  1.45.2.2  thorpej 	int unit = LPTUNIT(dev);
    125  1.45.2.2  thorpej 	u_char flags = LPTFLAGS(dev);
    126  1.45.2.2  thorpej 	struct lpt_softc *sc;
    127  1.45.2.2  thorpej 	bus_space_tag_t iot;
    128  1.45.2.2  thorpej 	bus_space_handle_t ioh;
    129  1.45.2.2  thorpej 	u_char control;
    130  1.45.2.2  thorpej 	int error;
    131  1.45.2.2  thorpej 	int spin;
    132  1.45.2.2  thorpej 
    133  1.45.2.2  thorpej 	if (unit >= lpt_cd.cd_ndevs)
    134  1.45.2.2  thorpej 		return ENXIO;
    135  1.45.2.2  thorpej 	sc = lpt_cd.cd_devs[unit];
    136  1.45.2.2  thorpej 	if (!sc)
    137  1.45.2.2  thorpej 		return ENXIO;
    138  1.45.2.2  thorpej 
    139  1.45.2.2  thorpej #if 0	/* XXX what to do? */
    140  1.45.2.2  thorpej 	if (sc->sc_irq == IRQUNK && (flags & LPT_NOINTR) == 0)
    141  1.45.2.2  thorpej 		return ENXIO;
    142  1.45.2.2  thorpej #endif
    143  1.45.2.2  thorpej 
    144  1.45.2.2  thorpej #ifdef DIAGNOSTIC
    145  1.45.2.2  thorpej 	if (sc->sc_state)
    146  1.45.2.2  thorpej 		printf("%s: stat=0x%x not zero\n", sc->sc_dev.dv_xname,
    147  1.45.2.2  thorpej 		    sc->sc_state);
    148  1.45.2.2  thorpej #endif
    149  1.45.2.2  thorpej 
    150  1.45.2.2  thorpej 	if (sc->sc_state)
    151  1.45.2.2  thorpej 		return EBUSY;
    152  1.45.2.2  thorpej 
    153  1.45.2.2  thorpej 	sc->sc_state = LPT_INIT;
    154  1.45.2.2  thorpej 	sc->sc_flags = flags;
    155  1.45.2.2  thorpej 	LPRINTF(("%s: open: flags=0x%x\n", sc->sc_dev.dv_xname,
    156  1.45.2.2  thorpej 	    (unsigned)flags));
    157  1.45.2.2  thorpej 	iot = sc->sc_iot;
    158  1.45.2.2  thorpej 	ioh = sc->sc_ioh;
    159  1.45.2.2  thorpej 
    160  1.45.2.2  thorpej 	if ((flags & LPT_NOPRIME) == 0) {
    161  1.45.2.2  thorpej 		/* assert INIT for 100 usec to start up printer */
    162  1.45.2.2  thorpej 		bus_space_write_1(iot, ioh, lpt_control, LPC_SELECT);
    163  1.45.2.2  thorpej 		delay(100);
    164  1.45.2.2  thorpej 	}
    165  1.45.2.2  thorpej 
    166  1.45.2.2  thorpej 	control = LPC_SELECT | LPC_NINIT;
    167  1.45.2.2  thorpej 	bus_space_write_1(iot, ioh, lpt_control, control);
    168  1.45.2.2  thorpej 
    169  1.45.2.2  thorpej 	/* wait till ready (printer running diagnostics) */
    170  1.45.2.2  thorpej 	for (spin = 0; NOT_READY_ERR(); spin += STEP) {
    171  1.45.2.2  thorpej 		if (spin >= TIMEOUT) {
    172  1.45.2.2  thorpej 			sc->sc_state = 0;
    173  1.45.2.2  thorpej 			return EBUSY;
    174  1.45.2.2  thorpej 		}
    175  1.45.2.2  thorpej 
    176  1.45.2.2  thorpej 		/* wait 1/4 second, give up if we get a signal */
    177  1.45.2.2  thorpej 		error = tsleep((caddr_t)sc, LPTPRI | PCATCH, "lptopen", STEP);
    178  1.45.2.2  thorpej 		if (error != EWOULDBLOCK) {
    179  1.45.2.2  thorpej 			sc->sc_state = 0;
    180  1.45.2.2  thorpej 			return error;
    181  1.45.2.2  thorpej 		}
    182  1.45.2.2  thorpej 	}
    183  1.45.2.2  thorpej 
    184  1.45.2.2  thorpej 	if ((flags & LPT_NOINTR) == 0)
    185  1.45.2.2  thorpej 		control |= LPC_IENABLE;
    186  1.45.2.2  thorpej 	if (flags & LPT_AUTOLF)
    187  1.45.2.2  thorpej 		control |= LPC_AUTOLF;
    188  1.45.2.2  thorpej 	sc->sc_control = control;
    189  1.45.2.2  thorpej 	bus_space_write_1(iot, ioh, lpt_control, control);
    190  1.45.2.2  thorpej 
    191  1.45.2.2  thorpej 	sc->sc_inbuf = geteblk(LPT_BSIZE);
    192  1.45.2.2  thorpej 	sc->sc_count = 0;
    193  1.45.2.2  thorpej 	sc->sc_state = LPT_OPEN;
    194  1.45.2.2  thorpej 
    195  1.45.2.2  thorpej 	if ((sc->sc_flags & LPT_NOINTR) == 0)
    196  1.45.2.2  thorpej 		lptwakeup(sc);
    197  1.45.2.2  thorpej 
    198  1.45.2.2  thorpej 	LPRINTF(("%s: opened\n", sc->sc_dev.dv_xname));
    199  1.45.2.2  thorpej 	return 0;
    200  1.45.2.2  thorpej }
    201  1.45.2.2  thorpej 
    202  1.45.2.2  thorpej int
    203  1.45.2.3  thorpej lptnotready(status, sc)
    204  1.45.2.2  thorpej 	u_char status;
    205  1.45.2.2  thorpej 	struct lpt_softc *sc;
    206  1.45.2.2  thorpej {
    207  1.45.2.2  thorpej 	u_char new;
    208  1.45.2.2  thorpej 
    209  1.45.2.2  thorpej 	status = (status ^ LPS_INVERT) & LPS_MASK;
    210  1.45.2.2  thorpej 	new = status & ~sc->sc_laststatus;
    211  1.45.2.2  thorpej 	sc->sc_laststatus = status;
    212  1.45.2.2  thorpej 
    213  1.45.2.2  thorpej 	if (new & LPS_SELECT)
    214  1.45.2.2  thorpej 		log(LOG_NOTICE, "%s: offline\n", sc->sc_dev.dv_xname);
    215  1.45.2.2  thorpej 	else if (new & LPS_NOPAPER)
    216  1.45.2.2  thorpej 		log(LOG_NOTICE, "%s: out of paper\n", sc->sc_dev.dv_xname);
    217  1.45.2.2  thorpej 	else if (new & LPS_NERR)
    218  1.45.2.2  thorpej 		log(LOG_NOTICE, "%s: output error\n", sc->sc_dev.dv_xname);
    219  1.45.2.2  thorpej 
    220  1.45.2.2  thorpej 	return status;
    221  1.45.2.2  thorpej }
    222  1.45.2.2  thorpej 
    223  1.45.2.2  thorpej void
    224  1.45.2.2  thorpej lptwakeup(arg)
    225  1.45.2.2  thorpej 	void *arg;
    226  1.45.2.2  thorpej {
    227  1.45.2.2  thorpej 	struct lpt_softc *sc = arg;
    228  1.45.2.2  thorpej 	int s;
    229  1.45.2.2  thorpej 
    230  1.45.2.2  thorpej 	s = spltty();
    231  1.45.2.2  thorpej 	lptintr(sc);
    232  1.45.2.2  thorpej 	splx(s);
    233  1.45.2.2  thorpej 
    234  1.45.2.2  thorpej 	timeout(lptwakeup, sc, STEP);
    235  1.45.2.2  thorpej }
    236  1.45.2.2  thorpej 
    237  1.45.2.2  thorpej /*
    238  1.45.2.2  thorpej  * Close the device, and free the local line buffer.
    239  1.45.2.2  thorpej  */
    240  1.45.2.2  thorpej int
    241  1.45.2.2  thorpej lptclose(dev, flag, mode, p)
    242  1.45.2.2  thorpej 	dev_t dev;
    243  1.45.2.2  thorpej 	int flag;
    244  1.45.2.2  thorpej 	int mode;
    245  1.45.2.2  thorpej 	struct proc *p;
    246  1.45.2.2  thorpej {
    247  1.45.2.2  thorpej 	int unit = LPTUNIT(dev);
    248  1.45.2.2  thorpej 	struct lpt_softc *sc = lpt_cd.cd_devs[unit];
    249  1.45.2.2  thorpej 	bus_space_tag_t iot = sc->sc_iot;
    250  1.45.2.2  thorpej 	bus_space_handle_t ioh = sc->sc_ioh;
    251  1.45.2.2  thorpej 
    252  1.45.2.2  thorpej 	if (sc->sc_count)
    253  1.45.2.3  thorpej 		(void) lptpushbytes(sc);
    254  1.45.2.2  thorpej 
    255  1.45.2.2  thorpej 	if ((sc->sc_flags & LPT_NOINTR) == 0)
    256  1.45.2.2  thorpej 		untimeout(lptwakeup, sc);
    257  1.45.2.2  thorpej 
    258  1.45.2.2  thorpej 	bus_space_write_1(iot, ioh, lpt_control, LPC_NINIT);
    259  1.45.2.2  thorpej 	sc->sc_state = 0;
    260  1.45.2.2  thorpej 	bus_space_write_1(iot, ioh, lpt_control, LPC_NINIT);
    261  1.45.2.2  thorpej 	brelse(sc->sc_inbuf);
    262  1.45.2.2  thorpej 
    263  1.45.2.2  thorpej 	LPRINTF(("%s: closed\n", sc->sc_dev.dv_xname));
    264  1.45.2.2  thorpej 	return 0;
    265  1.45.2.2  thorpej }
    266  1.45.2.2  thorpej 
    267  1.45.2.2  thorpej int
    268  1.45.2.3  thorpej lptpushbytes(sc)
    269  1.45.2.2  thorpej 	struct lpt_softc *sc;
    270  1.45.2.2  thorpej {
    271  1.45.2.2  thorpej 	bus_space_tag_t iot = sc->sc_iot;
    272  1.45.2.2  thorpej 	bus_space_handle_t ioh = sc->sc_ioh;
    273  1.45.2.2  thorpej 	int error;
    274  1.45.2.2  thorpej 
    275  1.45.2.2  thorpej 	if (sc->sc_flags & LPT_NOINTR) {
    276  1.45.2.2  thorpej 		int spin, tic;
    277  1.45.2.2  thorpej 		u_char control = sc->sc_control;
    278  1.45.2.2  thorpej 
    279  1.45.2.2  thorpej 		while (sc->sc_count > 0) {
    280  1.45.2.2  thorpej 			spin = 0;
    281  1.45.2.2  thorpej 			while (NOT_READY()) {
    282  1.45.2.2  thorpej 				if (++spin < sc->sc_spinmax)
    283  1.45.2.2  thorpej 					continue;
    284  1.45.2.2  thorpej 				tic = 0;
    285  1.45.2.2  thorpej 				/* adapt busy-wait algorithm */
    286  1.45.2.2  thorpej 				sc->sc_spinmax++;
    287  1.45.2.2  thorpej 				while (NOT_READY_ERR()) {
    288  1.45.2.2  thorpej 					/* exponential backoff */
    289  1.45.2.2  thorpej 					tic = tic + tic + 1;
    290  1.45.2.2  thorpej 					if (tic > TIMEOUT)
    291  1.45.2.2  thorpej 						tic = TIMEOUT;
    292  1.45.2.2  thorpej 					error = tsleep((caddr_t)sc,
    293  1.45.2.2  thorpej 					    LPTPRI | PCATCH, "lptpsh", tic);
    294  1.45.2.2  thorpej 					if (error != EWOULDBLOCK)
    295  1.45.2.2  thorpej 						return error;
    296  1.45.2.2  thorpej 				}
    297  1.45.2.2  thorpej 				break;
    298  1.45.2.2  thorpej 			}
    299  1.45.2.2  thorpej 
    300  1.45.2.2  thorpej 			bus_space_write_1(iot, ioh, lpt_data, *sc->sc_cp++);
    301  1.45.2.2  thorpej 			bus_space_write_1(iot, ioh, lpt_control,
    302  1.45.2.2  thorpej 			    control | LPC_STROBE);
    303  1.45.2.2  thorpej 			sc->sc_count--;
    304  1.45.2.2  thorpej 			bus_space_write_1(iot, ioh, lpt_control, control);
    305  1.45.2.2  thorpej 
    306  1.45.2.2  thorpej 			/* adapt busy-wait algorithm */
    307  1.45.2.2  thorpej 			if (spin*2 + 16 < sc->sc_spinmax)
    308  1.45.2.2  thorpej 				sc->sc_spinmax--;
    309  1.45.2.2  thorpej 		}
    310  1.45.2.2  thorpej 	} else {
    311  1.45.2.2  thorpej 		int s;
    312  1.45.2.2  thorpej 
    313  1.45.2.2  thorpej 		while (sc->sc_count > 0) {
    314  1.45.2.2  thorpej 			/* if the printer is ready for a char, give it one */
    315  1.45.2.2  thorpej 			if ((sc->sc_state & LPT_OBUSY) == 0) {
    316  1.45.2.2  thorpej 				LPRINTF(("%s: write %u\n", sc->sc_dev.dv_xname,
    317  1.45.2.2  thorpej 				    sc->sc_count));
    318  1.45.2.2  thorpej 				s = spltty();
    319  1.45.2.2  thorpej 				(void) lptintr(sc);
    320  1.45.2.2  thorpej 				splx(s);
    321  1.45.2.2  thorpej 			}
    322  1.45.2.2  thorpej 			error = tsleep((caddr_t)sc, LPTPRI | PCATCH,
    323  1.45.2.2  thorpej 			    "lptwrite2", 0);
    324  1.45.2.2  thorpej 			if (error)
    325  1.45.2.2  thorpej 				return error;
    326  1.45.2.2  thorpej 		}
    327  1.45.2.2  thorpej 	}
    328  1.45.2.2  thorpej 	return 0;
    329  1.45.2.2  thorpej }
    330  1.45.2.2  thorpej 
    331  1.45.2.2  thorpej /*
    332  1.45.2.2  thorpej  * Copy a line from user space to a local buffer, then call putc to get the
    333  1.45.2.2  thorpej  * chars moved to the output queue.
    334  1.45.2.2  thorpej  */
    335  1.45.2.2  thorpej int
    336  1.45.2.2  thorpej lptwrite(dev, uio, flags)
    337  1.45.2.2  thorpej 	dev_t dev;
    338  1.45.2.2  thorpej 	struct uio *uio;
    339  1.45.2.2  thorpej 	int flags;
    340  1.45.2.2  thorpej {
    341  1.45.2.2  thorpej 	struct lpt_softc *sc = lpt_cd.cd_devs[LPTUNIT(dev)];
    342  1.45.2.2  thorpej 	size_t n;
    343  1.45.2.2  thorpej 	int error = 0;
    344  1.45.2.2  thorpej 
    345  1.45.2.2  thorpej 	while ((n = min(LPT_BSIZE, uio->uio_resid)) != 0) {
    346  1.45.2.2  thorpej 		uiomove(sc->sc_cp = sc->sc_inbuf->b_data, n, uio);
    347  1.45.2.2  thorpej 		sc->sc_count = n;
    348  1.45.2.3  thorpej 		error = lptpushbytes(sc);
    349  1.45.2.2  thorpej 		if (error) {
    350  1.45.2.2  thorpej 			/*
    351  1.45.2.2  thorpej 			 * Return accurate residual if interrupted or timed
    352  1.45.2.2  thorpej 			 * out.
    353  1.45.2.2  thorpej 			 */
    354  1.45.2.2  thorpej 			uio->uio_resid += sc->sc_count;
    355  1.45.2.2  thorpej 			sc->sc_count = 0;
    356  1.45.2.2  thorpej 			return error;
    357  1.45.2.2  thorpej 		}
    358  1.45.2.2  thorpej 	}
    359  1.45.2.2  thorpej 	return 0;
    360  1.45.2.2  thorpej }
    361  1.45.2.2  thorpej 
    362  1.45.2.2  thorpej /*
    363  1.45.2.2  thorpej  * Handle printer interrupts which occur when the printer is ready to accept
    364  1.45.2.2  thorpej  * another char.
    365  1.45.2.2  thorpej  */
    366  1.45.2.2  thorpej int
    367  1.45.2.2  thorpej lptintr(arg)
    368  1.45.2.2  thorpej 	void *arg;
    369  1.45.2.2  thorpej {
    370  1.45.2.2  thorpej 	struct lpt_softc *sc = arg;
    371  1.45.2.2  thorpej 	bus_space_tag_t iot = sc->sc_iot;
    372  1.45.2.2  thorpej 	bus_space_handle_t ioh = sc->sc_ioh;
    373  1.45.2.2  thorpej 
    374  1.45.2.2  thorpej #if 0
    375  1.45.2.2  thorpej 	if ((sc->sc_state & LPT_OPEN) == 0)
    376  1.45.2.2  thorpej 		return 0;
    377  1.45.2.2  thorpej #endif
    378  1.45.2.2  thorpej 
    379  1.45.2.2  thorpej 	/* is printer online and ready for output */
    380  1.45.2.2  thorpej 	if (NOT_READY() && NOT_READY_ERR())
    381  1.45.2.2  thorpej 		return 0;
    382  1.45.2.2  thorpej 
    383  1.45.2.2  thorpej 	if (sc->sc_count) {
    384  1.45.2.2  thorpej 		u_char control = sc->sc_control;
    385  1.45.2.2  thorpej 		/* send char */
    386  1.45.2.2  thorpej 		bus_space_write_1(iot, ioh, lpt_data, *sc->sc_cp++);
    387  1.45.2.2  thorpej 		bus_space_write_1(iot, ioh, lpt_control, control | LPC_STROBE);
    388  1.45.2.2  thorpej 		sc->sc_count--;
    389  1.45.2.2  thorpej 		bus_space_write_1(iot, ioh, lpt_control, control);
    390  1.45.2.2  thorpej 		sc->sc_state |= LPT_OBUSY;
    391  1.45.2.2  thorpej 	} else
    392  1.45.2.2  thorpej 		sc->sc_state &= ~LPT_OBUSY;
    393  1.45.2.2  thorpej 
    394  1.45.2.2  thorpej 	if (sc->sc_count == 0) {
    395  1.45.2.2  thorpej 		/* none, wake up the top half to get more */
    396  1.45.2.2  thorpej 		wakeup((caddr_t)sc);
    397  1.45.2.2  thorpej 	}
    398  1.45.2.2  thorpej 
    399  1.45.2.2  thorpej 	return 1;
    400  1.45.2.2  thorpej }
    401  1.45.2.2  thorpej 
    402  1.45.2.2  thorpej int
    403  1.45.2.2  thorpej lptioctl(dev, cmd, data, flag, p)
    404  1.45.2.2  thorpej 	dev_t dev;
    405  1.45.2.2  thorpej 	u_long cmd;
    406  1.45.2.2  thorpej 	caddr_t data;
    407  1.45.2.2  thorpej 	int flag;
    408  1.45.2.2  thorpej 	struct proc *p;
    409  1.45.2.2  thorpej {
    410  1.45.2.2  thorpej 	int error = 0;
    411  1.45.2.2  thorpej 
    412  1.45.2.2  thorpej 	switch (cmd) {
    413  1.45.2.2  thorpej 	default:
    414  1.45.2.2  thorpej 		error = ENODEV;
    415  1.45.2.2  thorpej 	}
    416  1.45.2.2  thorpej 
    417  1.45.2.2  thorpej 	return error;
    418  1.45.2.2  thorpej }
    419