Lines Matching +full:watchdog +full:- +full:enable
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
30 * Support for Winbond watchdog.
38 * the watchdog functions and possibly others poking the registers at the same
50 #include <sys/watchdog.h>
66 #define WB_LDN_REG_LDN8 0x08 /* GPIO 2, Watchdog */
69 * LDN8 (GPIO 2, Watchdog) specific registers and options.
75 /* CRF5: Watchdog scale, P20. Mapped to reg_1. */
81 /* CRF6: Watchdog Timeout (0 == off). Mapped to reg_timeout. */
84 /* CRF7: Watchdog mouse, keyb, force, .. Mapped to reg_2. */
88 #define WB_LDN8_CRF7_FORCE 0x20 /* 1: force timeout (self-clear) */
90 #define WB_LDN8_CRF7_IRQS 0x0f /* irq source for watchdog, 2 == SMI */
107 * Special feature to let the watchdog fire at a different
108 * timeout as set by watchdog(4) but still use that API to
109 * re-load it periodically.
187 .descr = "Winbond 83627DHG-P",
192 .descr = "Winbond 83667HG-B",
237 * Return the watchdog related registers as we last read them. This will
238 * usually not give the current timeout or state on whether the watchdog
252 sbuf_printf(&sb, "LDN8 (GPIO2, Watchdog): "); in sysctl_wb_debug()
253 sbuf_printf(&sb, "CR%02X 0x%02x ", sc->ctl_reg, sc->reg_1); in sysctl_wb_debug()
254 sbuf_printf(&sb, "CR%02X 0x%02x ", sc->time_reg, sc->reg_timeout); in sysctl_wb_debug()
255 sbuf_printf(&sb, "CR%02X 0x%02x", sc->csr_reg, sc->reg_2); in sysctl_wb_debug()
264 * the registers the same time as the watchdog, this sysctl handler should
274 sc->reg_1 = superio_read(sc->dev, sc->ctl_reg); in sysctl_wb_debug_current()
275 sc->reg_timeout = superio_read(sc->dev, sc->time_reg); in sysctl_wb_debug_current()
276 sc->reg_2 = superio_read(sc->dev, sc->csr_reg); in sysctl_wb_debug_current()
282 * Sysctl handlers to force a watchdog timeout or to test the NMI functionality
287 * lot of boards have jumpers to change the action on watchdog timeout or
288 * disable the watchdog completely.
289 * XXX-BZ notyet: currently no general infrastructure exists to do this.
300 val = sc->test_nmi; in sysctl_wb_force_test_nmi()
305 if (error || !req->newptr) in sysctl_wb_force_test_nmi()
313 sc->test_nmi = 0; in sysctl_wb_force_test_nmi()
322 sc->test_nmi = 1; in sysctl_wb_force_test_nmi()
325 /* Force watchdog to fire. */ in sysctl_wb_force_test_nmi()
326 sc->reg_2 = superio_read(sc->dev, sc->csr_reg); in sysctl_wb_force_test_nmi()
327 sc->reg_2 |= WB_LDN8_CRF7_FORCE; in sysctl_wb_force_test_nmi()
328 superio_write(sc->dev, sc->csr_reg, sc->reg_2); in sysctl_wb_force_test_nmi()
334 * Print current watchdog state.
343 device_printf(sc->dev, "%s%sWatchdog %sabled. %s" in wb_print_state()
347 (sc->reg_timeout > 0x00) ? "en" : "dis", in wb_print_state()
348 (sc->reg_2 & WB_LDN8_CRF7_TS) ? "Watchdog fired. " : "", in wb_print_state()
349 (sc->reg_1 & WB_LDN8_CRF5_SCALE) ? 60 : 1, in wb_print_state()
350 sc->reg_timeout, in wb_print_state()
351 (sc->reg_timeout > 0x00) ? "<" : "", in wb_print_state()
352 sc->reg_timeout * ((sc->reg_1 & WB_LDN8_CRF5_SCALE) ? 60 : 1), in wb_print_state()
353 (sc->reg_timeout > 0x00) ? " left" : "", in wb_print_state()
354 sc->ctl_reg, sc->reg_1, sc->csr_reg, sc->reg_2); in wb_print_state()
358 * (Re)load the watchdog counter depending on timeout. A timeout of 0 will
359 * disable the watchdog.
370 if (sc->timeout_override > 0) in wb_set_watchdog()
371 timeout = sc->timeout_override; in wb_set_watchdog()
378 if (sc->debug_verbose) in wb_set_watchdog()
379 wb_print_state(sc, "Before watchdog counter (re)load"); in wb_set_watchdog()
382 /* Disable watchdog. */ in wb_set_watchdog()
383 sc->reg_timeout = 0; in wb_set_watchdog()
384 superio_write(sc->dev, sc->time_reg, sc->reg_timeout); in wb_set_watchdog()
388 sc->reg_1 = superio_read(sc->dev, sc->ctl_reg); in wb_set_watchdog()
392 sc->reg_1 |= WB_LDN8_CRF5_SCALE; in wb_set_watchdog()
393 sc->reg_timeout = (timeout / 60); in wb_set_watchdog()
395 sc->reg_timeout++; in wb_set_watchdog()
398 sc->reg_1 &= ~WB_LDN8_CRF5_SCALE; in wb_set_watchdog()
399 sc->reg_timeout = timeout; in wb_set_watchdog()
403 sc->reg_2 = superio_read(sc->dev, sc->csr_reg); in wb_set_watchdog()
404 if (sc->reg_2 & WB_LDN8_CRF7_TS) { in wb_set_watchdog()
405 sc->reg_2 &= ~WB_LDN8_CRF7_TS; in wb_set_watchdog()
406 superio_write(sc->dev, sc->csr_reg, sc->reg_2); in wb_set_watchdog()
410 superio_write(sc->dev, sc->ctl_reg, sc->reg_1); in wb_set_watchdog()
412 /* Set timer and arm/reset the watchdog. */ in wb_set_watchdog()
413 superio_write(sc->dev, sc->time_reg, sc->reg_timeout); in wb_set_watchdog()
416 if (sc->debug_verbose) in wb_set_watchdog()
417 wb_print_state(sc, "After watchdog counter (re)load"); in wb_set_watchdog()
422 * watchdog(9) EVENTHANDLER function implementation to (re)load the counter
423 * with the given timeout or disable the watchdog.
433 KASSERT(sc != NULL, ("%s: watchdog handler function called without " in wb_watchdog_fn()
438 /* Reset (and arm) watchdog. */ in wb_watchdog_fn()
452 /* Disable watchdog. */ in wb_watchdog_fn()
455 /* Failed to disable watchdog. */ in wb_watchdog_fn()
479 sc->chip = wb_devs[j].chip; in wb_probe()
481 "%s (0x%02x/0x%02x) Watchdog Timer", in wb_probe()
504 sc->dev = dev; in wb_attach()
509 switch (sc->chip) { in wb_attach()
512 sc->ctl_reg = 0xf3; in wb_attach()
513 sc->time_reg = 0xf4; in wb_attach()
514 sc->csr_reg = 0xf7; in wb_attach()
517 sc->ctl_reg = 0xf0; in wb_attach()
518 sc->time_reg = 0xf1; in wb_attach()
519 sc->csr_reg = 0xf2; in wb_attach()
522 sc->ctl_reg = 0xf5; in wb_attach()
523 sc->time_reg = 0xf6; in wb_attach()
524 sc->csr_reg = 0xf7; in wb_attach()
528 switch (sc->chip) { in wb_attach()
551 t = superio_read(dev, 0x2D) & ~0x01; /* PIN77 -> WDT0# */ in wb_attach()
553 t = superio_read(dev, sc->ctl_reg); in wb_attach()
554 t |= 0x02; /* enable the WDTO# output low pulse in wb_attach()
556 superio_write(dev, sc->ctl_reg, t); in wb_attach()
561 t = superio_read(dev, 0x2C) & ~0x80; /* PIN47 -> WDT0# */ in wb_attach()
582 t = superio_read(dev, sc->ctl_reg); in wb_attach()
583 t |= 0x02; /* enable the WDTO# output low pulse in wb_attach()
585 superio_write(dev, sc->ctl_reg, t); in wb_attach()
591 /* Read the current watchdog configuration. */ in wb_attach()
592 sc->reg_1 = superio_read(dev, sc->ctl_reg); in wb_attach()
593 sc->reg_timeout = superio_read(dev, sc->time_reg); in wb_attach()
594 sc->reg_2 = superio_read(dev, sc->csr_reg); in wb_attach()
596 /* Print current state if bootverbose or watchdog already enabled. */ in wb_attach()
597 if (bootverbose || (sc->reg_timeout > 0x00)) in wb_attach()
598 wb_print_state(sc, "Before watchdog attach"); in wb_attach()
600 sc->reg_1 &= ~WB_LDN8_CRF5_KEYB_P20; in wb_attach()
601 sc->reg_1 |= WB_LDN8_CRF5_KBRST; in wb_attach()
602 superio_write(dev, sc->ctl_reg, sc->reg_1); in wb_attach()
605 * Clear a previous watchdog timeout event (if still set). in wb_attach()
609 sc->reg_2 &= ~(WB_LDN8_CRF7_MOUSE|WB_LDN8_CRF7_TS); in wb_attach()
610 superio_write(dev, sc->csr_reg, sc->reg_2); in wb_attach()
615 sc->timeout_override = timeout; in wb_attach()
620 "timeout_override", CTLFLAG_RW, &sc->timeout_override, 0, in wb_attach()
621 "Timeout in seconds overriding default watchdog timeout"); in wb_attach()
623 "debug_verbose", CTLFLAG_RW, &sc->debug_verbose, 0, in wb_attach()
635 sysctl_wb_force_test_nmi, "I", "Enable to force watchdog to fire."); in wb_attach()
637 /* Register watchdog. */ in wb_attach()
638 sc->ev_tag = EVENTHANDLER_REGISTER(watchdog_list, wb_watchdog_fn, sc, in wb_attach()
642 wb_print_state(sc, "After watchdog attach"); in wb_attach()
654 /* Unregister and stop the watchdog if running. */ in wb_detach()
655 if (sc->ev_tag) in wb_detach()
656 EVENTHANDLER_DEREGISTER(watchdog_list, sc->ev_tag); in wb_detach()