From owner-svn-src-stable@freebsd.org Sun Aug 23 20:16:15 2015 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 08FF19C1AD1; Sun, 23 Aug 2015 20:16:15 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E0A5E1FDC; Sun, 23 Aug 2015 20:16:14 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7NKGEFn093167; Sun, 23 Aug 2015 20:16:14 GMT (envelope-from ian@FreeBSD.org) Received: (from ian@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7NKGEOE093163; Sun, 23 Aug 2015 20:16:14 GMT (envelope-from ian@FreeBSD.org) Message-Id: <201508232016.t7NKGEOE093163@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org using -f From: Ian Lepore Date: Sun, 23 Aug 2015 20:16:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r287079 - in stable/10/sys/arm: conf freescale/imx X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Aug 2015 20:16:15 -0000 Author: ian Date: Sun Aug 23 20:16:13 2015 New Revision: 287079 URL: https://svnweb.freebsd.org/changeset/base/287079 Log: MFC r286942, r286943, r286944: imx watchdog fixes... Add compatible strings for all the hardware this driver works with. Also, move the READ/WRITE bus space access macros from the header into the source file, and rename them to RD2/WR2 to make it clear they're 16-bit accessors. (READ/WRITE just don't seem like good names to be in a public header file.) 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). Enable the watchdog driver on imx6, now that it works. Modified: stable/10/sys/arm/conf/IMX6 stable/10/sys/arm/freescale/imx/imx_wdog.c stable/10/sys/arm/freescale/imx/imx_wdogreg.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/arm/conf/IMX6 ============================================================================== --- stable/10/sys/arm/conf/IMX6 Sun Aug 23 18:34:25 2015 (r287078) +++ stable/10/sys/arm/conf/IMX6 Sun Aug 23 20:16:13 2015 (r287079) @@ -160,5 +160,5 @@ device ffec # Freescale Fast Ethernet device fsliic # Freescale i2c/iic device iic # iic protocol device iicbus # iic bus -#device imxwdt # Watchdog. WARNING: can't be disabled!!! +device imxwdt # Watchdog. WARNING: can't be disabled!!! Modified: stable/10/sys/arm/freescale/imx/imx_wdog.c ============================================================================== --- stable/10/sys/arm/freescale/imx/imx_wdog.c Sun Aug 23 18:34:25 2015 (r287078) +++ stable/10/sys/arm/freescale/imx/imx_wdog.c Sun Aug 23 20:16:13 2015 (r287079) @@ -66,6 +66,20 @@ static struct resource_spec imx_wdog_spe { -1, 0 } }; +static struct ofw_compat_data compat_data[] = { + {"fsl,imx6sx-wdt", 1}, + {"fsl,imx6sl-wdt", 1}, + {"fsl,imx6q-wdt", 1}, + {"fsl,imx53-wdt", 1}, + {"fsl,imx51-wdt", 1}, + {"fsl,imx50-wdt", 1}, + {"fsl,imx35-wdt", 1}, + {"fsl,imx27-wdt", 1}, + {"fsl,imx25-wdt", 1}, + {"fsl,imx21-wdt", 1}, + {NULL, 0} +}; + static void imx_watchdog(void *, u_int, int *); static int imx_wdog_probe(device_t); static int imx_wdog_attach(device_t); @@ -84,46 +98,42 @@ static driver_t imx_wdog_driver = { static devclass_t imx_wdog_devclass; DRIVER_MODULE(imx_wdog, simplebus, imx_wdog_driver, imx_wdog_devclass, 0, 0); +#define RD2(_sc, _r) \ + bus_space_read_2((_sc)->sc_bst, (_sc)->sc_bsh, (_r)) +#define WR2(_sc, _r, _v) \ + bus_space_write_2((_sc)->sc_bst, (_sc)->sc_bsh, (_r), (_v)) static void imx_watchdog(void *arg, u_int cmd, int *error) { 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 */ - WRITE(sc, WDOG_SR_REG, WDOG_SR_STEP1); - WRITE(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 = READ(sc, WDOG_CR_REG); - reg &= ~WDOG_CR_WT_MASK; - reg |= (timeout << (WDOG_CR_WT_SHIFT + 1)) & - WDOG_CR_WT_MASK; - WRITE(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 */ - WRITE(sc, WDOG_SR_REG, WDOG_SR_STEP1); - WRITE(sc, WDOG_SR_REG, WDOG_SR_STEP2); + 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 @@ -133,11 +143,10 @@ imx_wdog_probe(device_t dev) if (!ofw_bus_status_okay(dev)) return (ENXIO); - if (!ofw_bus_is_compatible(dev, "fsl,imx51-wdt") && - !ofw_bus_is_compatible(dev, "fsl,imx53-wdt")) + if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) return (ENXIO); - device_set_desc(dev, "Freescale i.MX5xx Watchdog Timer"); + device_set_desc(dev, "Freescale i.MX Watchdog"); return (0); } Modified: stable/10/sys/arm/freescale/imx/imx_wdogreg.h ============================================================================== --- stable/10/sys/arm/freescale/imx/imx_wdogreg.h Sun Aug 23 18:34:25 2015 (r287078) +++ stable/10/sys/arm/freescale/imx/imx_wdogreg.h Sun Aug 23 20:16:13 2015 (r287079) @@ -59,7 +59,3 @@ #define WDOG_MCR_REG 0x08 /* Miscellaneous Control Register */ #define WDOG_MCR_PDE (1 << 0) -#define READ(_sc, _r) \ - bus_space_read_2((_sc)->sc_bst, (_sc)->sc_bsh, (_r)) -#define WRITE(_sc, _r, _v) \ - bus_space_write_2((_sc)->sc_bst, (_sc)->sc_bsh, (_r), (_v))