From nobody Sat Feb 17 15:12:18 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TcXN25Cxcz5BFSJ; Sat, 17 Feb 2024 15:12:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TcXN22hDcz4XZg; Sat, 17 Feb 2024 15:12:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708182738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RQ1uRPaRxAImZme9+Vwf+N9FoCmC1pDIewIo2VtoycA=; b=eBKT7+XN7by1/hyBV4EVZGbIwK1sG0SxUDOL9e1mxneVl5KQYjE3A6l6jzlaQ9esRq6LIk /RBeZziFi0XJ+KLSQPuab3HtF+e8gBCROyf1m1BucdX0b4j0yJMbYIcgS9+4220BCI2SuQ qBzu94QEDZm67sFi05nXHtLZ21kz4uyqRAYGvB3BU/kCCDc3E5QIa/94My2amgcyE/FdRv hPQbNwwMx3bqkD0vTyv5Ax9LXmXV1p9KruoBeP0/Lpz+3ck5EMVrgwfZPkHNNokMUpHXAn NVP39VGaxBE/YUe+fCmeJMTN36oFpeQ/6r6HMyaX9iC/Bbfd4zeabEdRrHOivw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708182738; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RQ1uRPaRxAImZme9+Vwf+N9FoCmC1pDIewIo2VtoycA=; b=xoGlZwFZ3XxzhD9eIdroAv7qtFVIfjyxg+9hC1TwTbFt7qAyacdnKDCjnYPvgBWwKcvBzW 2TeCE5W+2qEtrPqgzpicYfWoDJmDdwEkl2B/eC+eaC02iYPN6eE7WMhGQi3Lx3Ow8qxsN+ 4stSGxLzLjz95B0w/gPtH7x4fwKrTT+L2NO8h8ervprbGq+KnBkjhGbJ5Y2ZnmUAr9j3xa 7phYxYjGLV85OQ+G0YzIyXTTXxONiqSePNreJkuf8rWiAjOjKKj6k5H0OuJnvoE0I2xUOp mlw8LQ5ZjndfZPfo5Ih97QpvC6g+3Bz8LQHYmWPwLNH+mSvFDYj1P4wKm3x3tQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708182738; a=rsa-sha256; cv=none; b=AVBZjNDLvuf62CK+YqGaA+OucRgif+477JhvLPZz5IWgd/CLiF7AlXXNrnwp5EaZ4ggx8B WaU2YbrMGLzyKy96x/gZsbjo7PtbXTGeWKpI3hbJjEQhxjJuSHcdgfFVjwM1w1AZv54uJs bywJvo6rXUEbDbr4Svd2I0mJauMLB7zP34mlp/n6Kr0izyfqypLUXSH5/dybKRqcEMw63K vB/9BNdfJvhXWqfQCYlkrRPv7gHkMc99mp9SZ7FUzliYgf4XmKsqSqTDIxdrbQ18mT5EkC vQkwM2rxmageXsn9DFb3Wn3+LkLf/m52xQNtEhDX2L9VUyFXDtM4TxsEQdV66A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TcXN21Vc4z1CD3; Sat, 17 Feb 2024 15:12:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41HFCI0R077183; Sat, 17 Feb 2024 15:12:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41HFCI4p077180; Sat, 17 Feb 2024 15:12:18 GMT (envelope-from git) Date: Sat, 17 Feb 2024 15:12:18 GMT Message-Id: <202402171512.41HFCI4p077180@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andriy Gapon Subject: git: 1595c09ee252 - stable/14 - gpiopower: trigger low, high and both edges List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 1595c09ee2527f9d1a50a07e922c003889be1769 Auto-Submitted: auto-generated The branch stable/14 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=1595c09ee2527f9d1a50a07e922c003889be1769 commit 1595c09ee2527f9d1a50a07e922c003889be1769 Author: Andriy Gapon AuthorDate: 2024-01-28 11:29:41 +0000 Commit: Andriy Gapon CommitDate: 2024-02-17 14:15:10 +0000 gpiopower: trigger low, high and both edges Power off or reset may be activated either by low or high signal or by an edge. So, try everything. Also, the driver now supports DTS properties for timings. Finally, the driver does not change the pin configuration during attach. It is assumed that the pin is already in a state that does not trigger the power event (otherwise we wouldn't be running). (cherry picked from commit 320e4beb97618c6964380bfa404a3e96c5de7663) --- sys/dev/gpio/gpiopower.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/sys/dev/gpio/gpiopower.c b/sys/dev/gpio/gpiopower.c index 5c369396813f..2f09f79850d5 100644 --- a/sys/dev/gpio/gpiopower.c +++ b/sys/dev/gpio/gpiopower.c @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -41,6 +42,9 @@ struct gpiopower_softc { gpio_pin_t sc_pin; int sc_rbmask; + int sc_hi_period; + int sc_lo_period; + int sc_timeout; }; static void gpiopower_assert(device_t dev, int howto); @@ -65,6 +69,7 @@ gpiopower_attach(device_t dev) { struct gpiopower_softc *sc; phandle_t node; + uint32_t prop; sc = device_get_softc(dev); @@ -80,9 +85,20 @@ gpiopower_attach(device_t dev) sc->sc_rbmask = RB_HALT | RB_POWEROFF; else sc->sc_rbmask = 0; + + sc->sc_hi_period = 100000; + sc->sc_lo_period = 100000; + sc->sc_timeout = 1000000; + + if ((OF_getprop(node, "active-delay-ms", &prop, sizeof(prop))) > 0) + sc->sc_hi_period = fdt32_to_cpu(prop) * 1000; + if ((OF_getprop(node, "inactive-delay-ms", &prop, sizeof(prop))) > 0) + sc->sc_lo_period = fdt32_to_cpu(prop) * 1000; + if ((OF_getprop(node, "timeout-ms", &prop, sizeof(prop))) > 0) + sc->sc_timeout = fdt32_to_cpu(prop) * 1000; + EVENTHANDLER_REGISTER(shutdown_final, gpiopower_assert, dev, SHUTDOWN_PRI_LAST); - gpio_pin_setflags(sc->sc_pin, GPIO_PIN_OUTPUT); return (0); } @@ -107,10 +123,16 @@ gpiopower_assert(device_t dev, int howto) else return; + gpio_pin_setflags(sc->sc_pin, GPIO_PIN_OUTPUT); + gpio_pin_set_active(sc->sc_pin, true); + DELAY(sc->sc_hi_period); + gpio_pin_set_active(sc->sc_pin, false); + DELAY(sc->sc_lo_period); gpio_pin_set_active(sc->sc_pin, true); + DELAY(sc->sc_timeout); - /* Wait a second for it to trip */ - DELAY(10000000); + device_printf(dev, "%s failed\n", + (howto & RB_POWEROFF) != 0 ? "power off" : "reset"); } static device_method_t gpiopower_methods[] = {