From 9898c64ca95b0f3d962c3f9ebdecced5222454fd Mon Sep 17 00:00:00 2001 From: jdolecek Date: Tue, 3 Feb 2004 18:48:39 +0000 Subject: [PATCH] g/c some unused/write-only/redundant lpt_softc stuff some style changes in lptwrite() + some printfs adjusted --- sys/dev/ppbus/lpt.c | 64 ++++++++++++------------------------------ sys/dev/ppbus/lptvar.h | 24 +++------------- 2 files changed, 22 insertions(+), 66 deletions(-) diff --git a/sys/dev/ppbus/lpt.c b/sys/dev/ppbus/lpt.c index 8049ff2a0a67..a3dcab27f314 100644 --- a/sys/dev/ppbus/lpt.c +++ b/sys/dev/ppbus/lpt.c @@ -1,4 +1,4 @@ -/* $NetBSD: lpt.c,v 1.9 2004/01/30 11:40:55 jdolecek Exp $ */ +/* $NetBSD: lpt.c,v 1.10 2004/02/03 18:48:39 jdolecek Exp $ */ /* * Copyright (c) 1990 William F. Jolitz, TeleMuse @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lpt.c,v 1.9 2004/01/30 11:40:55 jdolecek Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lpt.c,v 1.10 2004/02/03 18:48:39 jdolecek Exp $"); #include "opt_ppbus_lpt.h" @@ -140,8 +140,6 @@ lpt_attach(struct device * parent, struct device * self, void * aux) char buf[64]; int error; - sc->sc_dev_ok = LPT_NOK; - error = lpt_request_ppbus(sc, 0); if(error) { printf("%s(%s): error (%d) requesting bus(%s). Device not " @@ -182,12 +180,7 @@ lpt_attach(struct device * parent, struct device * self, void * aux) "\3PS2\4EPP\5ECP\6FAST_CENTR", buf, sizeof(buf)); printf(": port mode = %s\n", buf); - /* Set ok flag */ - sc->sc_dev_ok = LPT_OK; - lpt_release_ppbus(sc, 0); - - return; } static int @@ -197,17 +190,6 @@ lpt_detach(struct device * self, int flags) struct ppbus_device_softc * ppbdev = (struct ppbus_device_softc *) lpt; int err; - if(lpt->sc_dev_ok == LPT_NOK) { - printf("%s: device not properly attached,\n", self->dv_xname); - if(flags & DETACH_FORCE) { - printf(", continuing (DETACH_FORCE)!\n"); - } - else { - printf(", terminating!\n"); - return 0; - } - } - if(lpt->sc_state & HAVEBUS) { err = lpt_release_ppbus(lpt, 0); if(err) { @@ -224,9 +206,6 @@ lpt_detach(struct device * self, int flags) lpt->sc_state &= ~HAVEBUS; } - lpt->sc_dev_ok = LPT_NOK; - lpt->sc_irq = 0; - ppbdev->ctx.valid = 0; /* Free memory buffers */ @@ -444,12 +423,6 @@ lptopen(dev_t dev_id, int flags, int fmt, struct proc *p) lpt = (struct lpt_softc *) dev; - if(lpt->sc_dev_ok != LPT_OK) { - LPT_DPRINTF(("%s(): device not attached properly [sc = %p, " - "sc_dev_ok = %x].\n", __func__, dev, lpt->sc_dev_ok)); - return ENODEV; - } - ppbus = dev->dv_parent; ppbus_dev = &(lpt->ppbus_dev); @@ -541,7 +514,6 @@ lptopen(dev_t dev_id, int flags, int fmt, struct proc *p) /* Write out the control register */ ppbus_wctr(ppbus, lpt->sc_control); - lpt->sc_xfercnt = 0; lpt->sc_state |= OPEN; return 0; @@ -566,7 +538,6 @@ lptclose(dev_t dev_id, int flags, int fmt, struct proc *p) } sc->sc_state = 0; - sc->sc_xfercnt = 0; return err; } @@ -619,9 +590,8 @@ lptread(dev_t dev_id, struct uio *uio, int ioflag) int lptwrite(dev_t dev_id, struct uio * uio, int ioflag) { - unsigned n; - int err = 0; - size_t cnt; + int error=0; + size_t n, cnt; struct device * dev = device_lookup(&lpt_cd, LPTUNIT(dev_id)); struct lpt_softc * sc = (struct lpt_softc *) dev; @@ -633,28 +603,30 @@ lptwrite(dev_t dev_id, struct uio * uio, int ioflag) return EINVAL; } + LPT_VPRINTF(("%s(%s): writing %d bytes\n", __func__, + dev->dv_xname, uio->uio_resid)); + /* Write the data */ sc->sc_state &= ~INTERRUPTED; - while(uio->uio_resid) { - n = min(BUFSIZE, uio->uio_resid); - err = uiomove(sc->sc_inbuf, n, uio); - if(err) + while (uio->uio_resid) { + n = MIN(BUFSIZE, uio->uio_resid); + error = uiomove(sc->sc_inbuf, n, uio); + if (error) break; - err = ppbus_write(dev->dv_parent, sc->sc_inbuf, n, ioflag, + error = ppbus_write(dev->dv_parent, sc->sc_inbuf, n, ioflag, &cnt); - sc->sc_xfercnt += cnt; - if(err) { - if(err != EWOULDBLOCK) + if (error) { + if (error != EWOULDBLOCK) sc->sc_state |= INTERRUPTED; break; - } + } } - LPT_VPRINTF(("%s(%s): %d bytes sent.\n", __func__, dev->dv_xname, - sc->sc_xfercnt)); + LPT_VPRINTF(("%s(%s): transfer finished, error %d.\n", __func__, + dev->dv_xname, error)); - return err; + return error; } /* Printer ioctl */ diff --git a/sys/dev/ppbus/lptvar.h b/sys/dev/ppbus/lptvar.h index abc699e6f043..1129458445b1 100644 --- a/sys/dev/ppbus/lptvar.h +++ b/sys/dev/ppbus/lptvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: lptvar.h,v 1.4 2004/01/28 17:35:58 jdolecek Exp $ */ +/* $NetBSD: lptvar.h,v 1.5 2004/02/03 18:48:39 jdolecek Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -59,11 +59,7 @@ struct lpt_softc { struct ppbus_device_softc ppbus_dev; -#define LPT_OK 1 -#define LPT_NOK 0 - u_int8_t sc_dev_ok; - - short sc_state; + int sc_state; /* bits for state */ #define OPEN (unsigned)(1<<0) /* device is open */ #define ASLP (unsigned)(1<<1) /* awaiting draining of printer */ @@ -85,22 +81,10 @@ struct lpt_softc { #define LPT_NOPRIME 0x40 /* don't prime on open */ #define LPT_NOINTR 0x80 /* do not use interrupt */ - char * sc_inbuf; - char * sc_outbuf; + char *sc_inbuf; + char *sc_outbuf; bus_addr_t sc_in_baddr; bus_addr_t sc_out_baddr; - size_t sc_xfercnt; - /* char sc_primed; - char * sc_cp;*/ - u_short sc_irq; /* IRQ status of port */ -#define LP_HAS_IRQ 0x01 /* we have an irq available */ -#define LP_USE_IRQ 0x02 /* we are using our irq */ -#define LP_ENABLE_IRQ 0x04 /* enable IRQ on open */ -#define LP_ENABLE_EXT 0x10 /* we shall use advanced mode when possible */ - u_char sc_backoff; /* time to call lptout() again */ - - struct resource * intr_resource; /* interrupt resource */ - void * intr_cookie; /* interrupt registration cookie */ }; #define MAX_SLEEP (hz*5) /* Timeout while waiting for device ready */