svn commit: r286943 - head/sys/arm/freescale/imx

Ian Lepore ian at FreeBSD.org
Wed Aug 19 20:50:32 UTC 2015


Author: ian
Date: Wed Aug 19 20:50:31 2015
New Revision: 286943
URL: https://svnweb.freebsd.org/changeset/base/286943

Log:
  Make the imx watchdog actually work, by setting WDOG_CR_WDE (enable bit).
  Also, follow the rules from watchdog(9) about what values to return in
  various situations (especially, don't touch *error when asked to set a
  non-zero timeout that isn't achievable on the hardware).

Modified:
  head/sys/arm/freescale/imx/imx_wdog.c

Modified: head/sys/arm/freescale/imx/imx_wdog.c
==============================================================================
--- head/sys/arm/freescale/imx/imx_wdog.c	Wed Aug 19 20:31:35 2015	(r286942)
+++ head/sys/arm/freescale/imx/imx_wdog.c	Wed Aug 19 20:50:31 2015	(r286943)
@@ -107,40 +107,32 @@ imx_watchdog(void *arg, u_int cmd, int *
 {
 	struct imx_wdog_softc *sc;
 	uint16_t reg;
-	int timeout;
+	u_int timeout;
 
 	sc = arg;
 	mtx_lock(&sc->sc_mtx);
-
-	/* Refresh counter, since we feels good */
-	WR2(sc, WDOG_SR_REG, WDOG_SR_STEP1);
-	WR2(sc, WDOG_SR_REG, WDOG_SR_STEP2);
-
-	/* We don't require precession, so "-10" (/1024) is ok */
-	timeout = (1 << ((cmd & WD_INTERVAL) - 10)) / 1000000;
-	if (timeout > 1 && timeout < 128) {
-		if (timeout != sc->sc_timeout) {
-			device_printf(sc->sc_dev,
-			    "WARNING: watchdog can't be disabled!!!");
-			sc->sc_timeout = timeout;
-			reg = RD2(sc, WDOG_CR_REG);
-			reg &= ~WDOG_CR_WT_MASK;
-			reg |= (timeout << (WDOG_CR_WT_SHIFT + 1)) &
-			    WDOG_CR_WT_MASK;
-			WR2(sc, WDOG_CR_REG, reg);
+	if (cmd == 0) {
+		if (bootverbose)
+			device_printf(sc->sc_dev, "Can not be disabled.\n");
+		*error = EOPNOTSUPP;
+	} else {
+		timeout = (u_int)((1ULL << (cmd & WD_INTERVAL)) / 1000000000U);
+		if (timeout > 1 && timeout < 128) {
+			if (timeout != sc->sc_timeout) {
+				sc->sc_timeout = timeout;
+				reg = RD2(sc, WDOG_CR_REG);
+				reg &= ~WDOG_CR_WT_MASK;
+				reg |= (timeout << (WDOG_CR_WT_SHIFT + 1)) &
+				    WDOG_CR_WT_MASK;
+				WR2(sc, WDOG_CR_REG, reg | WDOG_CR_WDE);
+			}
 			/* Refresh counter */
 			WR2(sc, WDOG_SR_REG, WDOG_SR_STEP1);
 			WR2(sc, WDOG_SR_REG, WDOG_SR_STEP2);
 			*error = 0;
-		} else {
-			*error = EOPNOTSUPP;
 		}
-	} else {
-		device_printf(sc->sc_dev, "Can not be disabled.\n");
-		*error = EOPNOTSUPP;
 	}
 	mtx_unlock(&sc->sc_mtx);
-
 }
 
 static int


More information about the svn-src-head mailing list