/* * Reset the printer, then wait until it's selected and not busy. */ int lptopen(dev_t dev, int flag, int mode, struct proc *p) { int unit = LPTUNIT(dev); u_int8_t flags = LPTFLAGS(dev); struct lpt_softc *sc; u_int8_t control; int error; int spin; if (unit >= lpt_cd.cd_ndevs) return ENXIO; sc = lpt_cd.cd_devs[unit]; if (!sc) return ENXIO; sc->sc_flags = (sc->sc_flags & LPT_POLLED) | flags; if ((sc->sc_flags & (LPT_POLLED|LPT_NOINTR)) == LPT_POLLED) return ENXIO; #ifdef DIAGNOSTIC if (sc->sc_state) printf("%s: stat=0x%x not zero\n", sc->sc_dev.dv_xname, sc->sc_state); #endif if (sc->sc_state) return EBUSY; sc->sc_state = LPT_INIT; LPRINTF(("%s: open: flags=0x%x\n", sc->sc_dev.dv_xname, flags)); if ((flags & LPT_NOPRIME) == 0) { /* assert INIT for 100 usec to start up printer */ bus_space_write_1(sc->sc_iot, sc->sc_ioh, lpt_control, LPC_SELECT); delay(100); } control = LPC_SELECT | LPC_NINIT; bus_space_write_1(sc->sc_iot, sc->sc_ioh, lpt_control, control); /* wait till ready (printer running diagnostics) */ for (spin = 0; NOT_READY_ERR(); spin += STEP) { if (spin >= TIMEOUT) { sc->sc_state = 0; return EBUSY; } /* wait 1/4 second, give up if we get a signal */ error = tsleep((caddr_t)sc, LPTPRI | PCATCH, "lptopen", STEP); if (sc->sc_state == 0) return (EIO); if (error != EWOULDBLOCK) { sc->sc_state = 0; return error; } } if ((flags & LPT_NOINTR) == 0) control |= LPC_IENABLE; if (flags & LPT_AUTOLF) control |= LPC_AUTOLF; sc->sc_control = control; bus_space_write_1(sc->sc_iot, sc->sc_ioh, lpt_control, control); sc->sc_inbuf = geteblk(LPT_BSIZE); sc->sc_count = 0; sc->sc_state = LPT_OPEN; if ((sc->sc_flags & LPT_NOINTR) == 0) lptwakeup(sc); LPRINTF(("%s: opened\n", sc->sc_dev.dv_xname)); return 0; }
/* * Reset the printer, then wait until it's selected and not busy. */ int lptopen(dev_t dev, int flag, int mode, struct lwp *l) { u_char flags = LPTFLAGS(dev); struct lpt_softc *sc; bus_space_tag_t iot; bus_space_handle_t ioh; u_char control; int error; int spin; sc = device_lookup_private(&lpt_cd, LPTUNIT(dev)); if (!sc || !sc->sc_dev_ok) return ENXIO; #if 0 /* XXX what to do? */ if (sc->sc_irq == IRQUNK && (flags & LPT_NOINTR) == 0) return ENXIO; #endif #ifdef DIAGNOSTIC if (sc->sc_state) aprint_verbose_dev(sc->sc_dev, "stat=0x%x not zero\n", sc->sc_state); #endif if (sc->sc_state) return EBUSY; sc->sc_state = LPT_INIT; sc->sc_flags = flags; LPRINTF(("%s: open: flags=0x%x\n", device_xname(sc->sc_dev), (unsigned)flags)); iot = sc->sc_iot; ioh = sc->sc_ioh; if ((flags & LPT_NOPRIME) == 0) { /* assert INIT for 100 usec to start up printer */ bus_space_write_1(iot, ioh, lpt_control, LPC_SELECT); delay(100); } control = LPC_SELECT | LPC_NINIT; bus_space_write_1(iot, ioh, lpt_control, control); /* wait till ready (printer running diagnostics) */ for (spin = 0; NOT_READY_ERR(); spin += STEP) { if (spin >= TIMEOUT) { sc->sc_state = 0; return EBUSY; } /* wait 1/4 second, give up if we get a signal */ error = tsleep((void *)sc, LPTPRI | PCATCH, "lptopen", STEP); if (error != EWOULDBLOCK) { sc->sc_state = 0; return error; } } if ((flags & LPT_NOINTR) == 0) control |= LPC_IENABLE; if (flags & LPT_AUTOLF) control |= LPC_AUTOLF; sc->sc_control = control; bus_space_write_1(iot, ioh, lpt_control, control); sc->sc_inbuf = malloc(LPT_BSIZE, M_DEVBUF, M_WAITOK); sc->sc_count = 0; sc->sc_state = LPT_OPEN; if ((sc->sc_flags & LPT_NOINTR) == 0) lptwakeup(sc); LPRINTF(("%s: opened\n", device_xname(sc->sc_dev))); return 0; }