Lines Matching +full:spin +full:- +full:up
1 /*-
2 * SPDX-License-Identifier: BSD-4-Clause
35 * ON-LINE 386BSD USER MANUAL BEFORE USE. A BOOK DISCUSSING THE INTERNALS
100 #define LPINITRDY 4 /* wait up to 4 seconds for a ready */
165 /* Printer Ready condition - from lpa.c */
202 if (sc->sc_state & HAVEBUS) in lpt_request_ppbus()
207 sc->sc_state |= HAVEBUS; in lpt_request_ppbus()
219 if (sc->sc_state & HAVEBUS) { in lpt_release_ppbus()
222 sc->sc_state &= ~HAVEBUS; in lpt_release_ppbus()
241 } while (temp != data && --timeout); in lpt_port_test()
248 * test pattern - 1999/02/08 des@freebsd.org
250 * New lpt port probe Geoff Rehmet - Rhodes University - 14/2/94
282 * Before probing the control port, we write a 0 to the data port -
288 * This probe routine has been tested on Epson Lx-800, HP LJ3P,
289 * Epson FX-1170 and C.Itoh 8510RM
339 dev = device_find_child(parent, LPT_NAME, -1); in lpt_identify()
367 sc->sc_primed = 0; /* not primed yet */ in lpt_attach()
368 ppb_init_callout(ppbus, &sc->sc_timer, 0); in lpt_attach()
382 sc->sc_intr_resource = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, in lpt_attach()
384 if (sc->sc_intr_resource) { in lpt_attach()
385 error = bus_setup_intr(dev, sc->sc_intr_resource, in lpt_attach()
387 &sc->sc_intr_cookie); in lpt_attach()
390 sc->sc_intr_resource); in lpt_attach()
395 sc->sc_irq = LP_HAS_IRQ | LP_USE_IRQ | LP_ENABLE_IRQ; in lpt_attach()
396 device_printf(dev, "Interrupt-driven port\n"); in lpt_attach()
398 sc->sc_irq = 0; in lpt_attach()
401 lprintf(("irq %x\n", sc->sc_irq)); in lpt_attach()
403 sc->sc_inbuf = malloc(BUFSIZE, M_DEVBUF, M_WAITOK); in lpt_attach()
404 sc->sc_statbuf = malloc(BUFSTATSIZE, M_DEVBUF, M_WAITOK); in lpt_attach()
405 sc->sc_dev = dev; in lpt_attach()
406 sc->sc_cdev = make_dev(&lpt_cdevsw, unit, in lpt_attach()
408 sc->sc_cdev->si_drv1 = sc; in lpt_attach()
409 sc->sc_cdev->si_drv2 = 0; in lpt_attach()
410 sc->sc_cdev_bypass = make_dev(&lpt_cdevsw, unit, in lpt_attach()
412 sc->sc_cdev_bypass->si_drv1 = sc; in lpt_attach()
413 sc->sc_cdev_bypass->si_drv2 = (void *)LP_BYPASS; in lpt_attach()
423 destroy_dev(sc->sc_cdev); in lpt_detach()
424 destroy_dev(sc->sc_cdev_bypass); in lpt_detach()
428 callout_drain(&sc->sc_timer); in lpt_detach()
429 if (sc->sc_intr_resource != NULL) { in lpt_detach()
430 bus_teardown_intr(dev, sc->sc_intr_resource, in lpt_detach()
431 sc->sc_intr_cookie); in lpt_detach()
432 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_intr_resource); in lpt_detach()
434 free(sc->sc_inbuf, M_DEVBUF); in lpt_detach()
435 free(sc->sc_statbuf, M_DEVBUF); in lpt_detach()
444 device_t dev = sc->sc_dev; in lptout()
450 if (sc->sc_state & OPEN) { in lptout()
451 sc->sc_backoff++; in lptout()
452 if (sc->sc_backoff > hz/LPTOUTMAX) in lptout()
453 sc->sc_backoff = hz/LPTOUTMAX; in lptout()
454 callout_reset(&sc->sc_timer, sc->sc_backoff, lptout, sc); in lptout()
456 sc->sc_state &= ~TOUT; in lptout()
458 if (sc->sc_state & EERROR) in lptout()
459 sc->sc_state &= ~EERROR; in lptout()
464 if (sc->sc_xfercnt) { in lptout()
467 sc->sc_state &= ~OBUSY; in lptout()
473 * lptopen -- reset the printer, then wait until it's selected and not busy.
475 * printer -- this is just used for passing ioctls.
482 struct lpt_data *sc = dev->si_drv1; in lptopen()
489 lptdev = sc->sc_dev; in lptopen()
493 if (sc->sc_state) { in lptopen()
495 sc->sc_state)); in lptopen()
499 sc->sc_state |= LPTINIT; in lptopen()
501 sc->sc_flags = (uintptr_t)dev->si_drv2; in lptopen()
504 if (sc->sc_flags & LP_BYPASS) { in lptopen()
505 sc->sc_state = OPEN; in lptopen()
513 sc->sc_state = 0; in lptopen()
519 sc->sc_flags)); in lptopen()
523 if (sc->sc_irq & LP_ENABLE_IRQ) in lptopen()
524 sc->sc_irq |= LP_USE_IRQ; in lptopen()
526 sc->sc_irq &= ~LP_USE_IRQ; in lptopen()
529 if ((sc->sc_flags & LP_NO_PRIME) == 0) { in lptopen()
530 if ((sc->sc_flags & LP_PRIMEOPEN) || sc->sc_primed == 0) { in lptopen()
532 sc->sc_primed++; in lptopen()
547 sc->sc_state = 0; in lptopen()
552 /* wait 1/4 second, give up if we get a signal */ in lptopen()
556 sc->sc_state = 0; in lptopen()
564 sc->sc_control = LPC_SEL|LPC_NINIT; in lptopen()
565 if (sc->sc_flags & LP_AUTOLF) in lptopen()
566 sc->sc_control |= LPC_AUTOL; in lptopen()
568 /* enable interrupt if interrupt-driven */ in lptopen()
569 if (sc->sc_irq & LP_USE_IRQ) in lptopen()
570 sc->sc_control |= LPC_ENA; in lptopen()
572 ppb_wctr(ppbus, sc->sc_control); in lptopen()
574 sc->sc_state &= ~LPTINIT; in lptopen()
575 sc->sc_state |= OPEN; in lptopen()
576 sc->sc_xfercnt = 0; in lptopen()
579 lprintf(("irq %x\n", sc->sc_irq)); in lptopen()
580 if (sc->sc_irq & LP_USE_IRQ) { in lptopen()
581 sc->sc_state |= TOUT; in lptopen()
582 sc->sc_backoff = hz / LPTOUTINITIAL; in lptopen()
583 callout_reset(&sc->sc_timer, sc->sc_backoff, lptout, sc); in lptopen()
595 * lptclose -- close the device, free the local line buffer.
603 struct lpt_data *sc = dev->si_drv1; in lptclose()
604 device_t lptdev = sc->sc_dev; in lptclose()
609 if (sc->sc_flags & LP_BYPASS) in lptclose()
618 if ((!(sc->sc_state & INTERRUPTED)) && (sc->sc_irq & LP_USE_IRQ)) in lptclose()
619 while ((ppb_rstr(ppbus) & RDY_MASK) != LP_READY || sc->sc_xfercnt) in lptclose()
620 /* wait 1 second, give up if we get a signal */ in lptclose()
625 sc->sc_state &= ~OPEN; in lptclose()
626 callout_stop(&sc->sc_timer); in lptclose()
635 sc->sc_state = 0; in lptclose()
636 sc->sc_xfercnt = 0; in lptclose()
653 device_t dev = sc->sc_dev; in lpt_pushbytes()
655 int spin, err, tic; in lpt_pushbytes() local
661 while (sc->sc_xfercnt > 0) { in lpt_pushbytes()
663 ch = *(sc->sc_cp); in lpt_pushbytes()
664 sc->sc_cp++; in lpt_pushbytes()
665 sc->sc_xfercnt--; in lpt_pushbytes()
672 for (spin = 0; NOT_READY(ppbus) && spin < MAX_SPIN; ++spin) in lpt_pushbytes()
674 if (spin >= MAX_SPIN) { in lpt_pushbytes()
698 ppb_wctr(ppbus, sc->sc_control|LPC_STB); in lpt_pushbytes()
699 ppb_wctr(ppbus, sc->sc_control); in lpt_pushbytes()
705 * lptread --retrieve printer status in IEEE1284 NIBBLE mode
711 struct lpt_data *sc = dev->si_drv1; in lptread()
712 device_t lptdev = sc->sc_dev; in lptread()
716 if (sc->sc_flags & LP_BYPASS) { in lptread()
729 while (uio->uio_resid) { in lptread()
731 sc->sc_statbuf, min(BUFSTATSIZE, in lptread()
732 uio->uio_resid), &len))) { in lptread()
740 error = uiomove(sc->sc_statbuf, len, uio); in lptread()
753 * lptwrite --copy a line from user space to a local buffer, then call
764 struct lpt_data *sc = dev->si_drv1; in lptwrite()
765 device_t lptdev = sc->sc_dev; in lptwrite()
768 if (sc->sc_flags & LP_BYPASS) { in lptwrite()
780 sc->sc_state &= ~INTERRUPTED; in lptwrite()
781 while ((n = min(BUFSIZE, uio->uio_resid)) != 0) { in lptwrite()
782 sc->sc_cp = sc->sc_inbuf; in lptwrite()
784 err = uiomove(sc->sc_cp, n, uio); in lptwrite()
788 sc->sc_xfercnt = n; in lptwrite()
790 if (sc->sc_irq & LP_ENABLE_EXT) { in lptwrite()
792 err = ppb_write(ppbus, sc->sc_cp, in lptwrite()
793 sc->sc_xfercnt, 0); in lptwrite()
798 sc->sc_xfercnt = 0; in lptwrite()
801 sc->sc_state |= INTERRUPTED; in lptwrite()
808 device_get_nameunit(sc->sc_dev)); in lptwrite()
814 } else while ((sc->sc_xfercnt > 0)&&(sc->sc_irq & LP_USE_IRQ)) { in lptwrite()
818 if ((sc->sc_state & OBUSY) == 0){ in lptwrite()
819 lprintf(("\nC %d. ", sc->sc_xfercnt)); in lptwrite()
823 if (sc->sc_state & OBUSY) in lptwrite()
826 sc->sc_state |= INTERRUPTED; in lptwrite()
833 if (!(sc->sc_irq & LP_USE_IRQ) && (sc->sc_xfercnt)) { in lptwrite()
853 * lptintr -- handle printer interrupts which occur when the printer is
862 device_t lptdev = sc->sc_dev; in lptintr()
870 * Avoid falling back to lptout() too quickly. First spin-loop in lptintr()
877 sc->sc_state = (sc->sc_state | OBUSY) & ~EERROR; in lptintr()
878 sc->sc_backoff = hz / LPTOUTINITIAL; in lptintr()
880 if (sc->sc_xfercnt) { in lptintr()
882 /*lprintf(("%x ", *sc->sc_cp)); */ in lptintr()
883 ppb_wdtr(ppbus, *sc->sc_cp++) ; in lptintr()
884 ppb_wctr(ppbus, sc->sc_control|LPC_STB); in lptintr()
886 ppb_wctr(ppbus, sc->sc_control); in lptintr()
889 if (--(sc->sc_xfercnt) > 0) in lptintr()
897 sc->sc_state &= ~OBUSY; in lptintr()
899 if (!(sc->sc_state & INTERRUPTED)) in lptintr()
905 (sc->sc_state & OPEN)) in lptintr()
906 sc->sc_state |= EERROR; in lptintr()
916 struct lpt_data *sc = dev->si_drv1; in lptioctl()
922 ppbus = device_get_parent(sc->sc_dev); in lptioctl()
924 if (sc->sc_irq & LP_HAS_IRQ) { in lptioctl()
934 old_sc_irq = sc->sc_irq; in lptioctl()
937 sc->sc_irq &= (~LP_ENABLE_IRQ); in lptioctl()
940 sc->sc_irq &= (~LP_ENABLE_EXT); in lptioctl()
941 sc->sc_irq |= LP_ENABLE_IRQ; in lptioctl()
947 sc->sc_irq &= (~LP_ENABLE_IRQ); in lptioctl()
948 sc->sc_irq |= LP_ENABLE_EXT; in lptioctl()
951 sc->sc_irq &= (~LP_ENABLE_EXT); in lptioctl()
957 if (old_sc_irq != sc->sc_irq ) in lptioctl()
959 device_get_nameunit(sc->sc_dev), in lptioctl()
960 (sc->sc_irq & LP_ENABLE_IRQ)? in lptioctl()
961 "interrupt-driven":"polled", in lptioctl()
962 (sc->sc_irq & LP_ENABLE_EXT)? in lptioctl()