FreeBSD/sys/dev/wbwd/wbwd.c
/*
 * (Re)load the watchdog counter depending on timeout.  A timeout of 0 will
 * disable the watchdog.
 */
(Re)load the watchdog counter depending on timeout.  A timeout of 0 will
disable the watchdog.
( Re ) load the watchdog counter depending on timeout . A timeout of 0 will disable the watchdog .
static int
wb_set_watchdog(struct wb_softc *sc, unsigned int timeout)
{
	if (timeout != 0) {
		if (sc->timeout_override > 0)
			timeout = sc->timeout_override;
		if (timeout > 255 * 60)
			return (EINVAL);
	}
	if (sc->debug_verbose)
		wb_print_state(sc, "Before watchdog counter (re)load");
	if ((*sc->ext_cfg_enter_f)(sc, 0) != 0)
		return (ENXIO);
	write_reg(sc, WB_LDN_REG, WB_LDN_REG_LDN8);
	if (timeout == 0) {
		sc->reg_timeout = 0;
		write_reg(sc, sc->time_reg, sc->reg_timeout);
	} else {
		sc->reg_1 = read_reg(sc, sc->ctl_reg);
		if (timeout > 255) {
			sc->reg_1 |= WB_LDN8_CRF5_SCALE;
			sc->reg_timeout = (timeout / 60);
			if (timeout % 60)
				sc->reg_timeout++;
		} else {
			sc->reg_1 &= ~WB_LDN8_CRF5_SCALE;
			sc->reg_timeout = timeout;
		}
		sc->reg_2 = read_reg(sc, sc->csr_reg);
		if (sc->reg_2 & WB_LDN8_CRF7_TS) {
			sc->reg_2 &= ~WB_LDN8_CRF7_TS;
			write_reg(sc, sc->csr_reg, sc->reg_2);
		}
		write_reg(sc, sc->ctl_reg, sc->reg_1);
		write_reg(sc, sc->time_reg, sc->reg_timeout);
	}
	(*sc->ext_cfg_exit_f)(sc, 0);
	if (sc->debug_verbose)
		wb_print_state(sc, "After watchdog counter (re)load");
	return (0);
}
static int wb_set_watchdog ( struct wb_softc * sc , unsigned int timeout ) { if ( timeout != 0 ) { if ( sc -> timeout_override > 0 ) timeout = sc -> timeout_override ; if ( timeout > 255 * 60 ) return ( EINVAL ) ; } if ( sc -> debug_verbose ) wb_print_state ( sc , " " ) ; if ( ( * sc -> ext_cfg_enter_f ) ( sc , 0 ) != 0 ) return ( ENXIO ) ; write_reg ( sc , WB_LDN_REG , WB_LDN_REG_LDN8 ) ; if ( timeout == 0 ) { sc -> reg_timeout = 0 ; write_reg ( sc , sc -> time_reg , sc -> reg_timeout ) ; } else { sc -> reg_1 = read_reg ( sc , sc -> ctl_reg ) ; if ( timeout > 255 ) { sc -> reg_1 |= WB_LDN8_CRF5_SCALE ; sc -> reg_timeout = ( timeout / 60 ) ; if ( timeout % 60 ) sc -> reg_timeout ++ ; } else { sc -> reg_1 &= ~ WB_LDN8_CRF5_SCALE ; sc -> reg_timeout = timeout ; } sc -> reg_2 = read_reg ( sc , sc -> csr_reg ) ; if ( sc -> reg_2 & WB_LDN8_CRF7_TS ) { sc -> reg_2 &= ~ WB_LDN8_CRF7_TS ; write_reg ( sc , sc -> csr_reg , sc -> reg_2 ) ; } write_reg ( sc , sc -> ctl_reg , sc -> reg_1 ) ; write_reg ( sc , sc -> time_reg , sc -> reg_timeout ) ; } ( * sc -> ext_cfg_exit_f ) ( sc , 0 ) ; if ( sc -> debug_verbose ) wb_print_state ( sc , " " ) ; return ( 0 ) ; }
(Re)load the watchdog counter depending on timeout.
( Re ) load the watchdog counter depending on timeout .
/*
		 * In case an override is set, let it override.  It may lead
		 * to strange results as we do not check the input of the sysctl.
		 */ /* Make sure we support the requested timeout. */ /* Watchdog is configured as part of LDN 8 (GPIO Port2, Watchdog) */ /* Disable watchdog. */ /* Read current scaling factor. */ /* Set scaling factor to 60s. */ /* Set scaling factor to 1s. */ /* In case we fired before we need to clear to fire again. */ /* Write back scaling factor. */ /* Set timer and arm/reset the watchdog. */