From nobody Sat Feb 17 19:22:32 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 4Tcdwn24fxz53y3C; Sat, 17 Feb 2024 19:22:33 +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 4Tcdwn0XcLz4FXh; Sat, 17 Feb 2024 19:22:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708197753; 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=aNhM/9Gu1A/YoC8YFoFTSTn+RDyPEqnQPoAm/AYWCFk=; b=tudPX4RlXG8e08ityIkP7iKQgxqqAMkz7NmpRRgstGycQPLreUDTrNVF8O47v6CJ+th+le D3aou95EeBwd8UrDGt8322Qp7efo3/4gG4MeUEFYUIlPqfI83iH831mik1KEyT8a/x8R1G HJLVjlNXam9Emx28nzgt5yShpeO7foskrwGGskaDGkpJraBCZ1W+YUQcVhRJT1Lqy0KwNQ m97bvRCiastdbzdvlhOh/2ZUq6UcWEu3BYfGoAFoc3Licy34YxHbAu7l22NOYuF955bv9t s8NeGtlo1ffVUkpM0Li5MGWguoEcv9PVGyL4cf3vFd8QoQSwSE+G3Gi38tZe+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708197753; 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=aNhM/9Gu1A/YoC8YFoFTSTn+RDyPEqnQPoAm/AYWCFk=; b=i6TitXquej7kwW8Ga233B3Q3W/snJyiggFa72vfcnXc66ioDstlYl4Gu+jbglZ6ZIVnuHJ ua5dvFz2UGLs3+owSUAdaHUpW0nkInZZ/bTJLUSPDlmkjD7opeX4OAZlxTLO+gOvz7OJQJ eJaiQ5QbCgZup5Nvox+u57UZGGpowFbBBBo3miWGI+k1FyLjd+sB5IEpUKhNd3K+G5A55f 14uoqFbhd9aTer97qWW5ieKX3GSL+YhtIWpN5WKy5W8DBifcaX3QGD1czVpb1n8UrGRE4V 2HHIHFSuQNNZEEqkt5SRVTQ5VcNsVDy2Jid1+axRB4a4PaJo8gHmCZLYRV3+tA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708197753; a=rsa-sha256; cv=none; b=mIMzBXOcRIO3kqz5NKU3VEosh65qJw7DcxkbwLLGfVUVNGdEZ/JPQlQLbVg4lZkC7+7IX2 wSx8B9E9HWo9eFbwT4oJX3OhxtUnG7hFc8NUDl7XLlw+UKi1gXMnNHIMHt6tHDMTOZciRd PgRjAyjnn/VJVK9p4LAHpOJRNeXZur9pLlNeBuK8RRuSFl/yUxp2XkU7TGj1mk4B2ITmeK sE9As+Xy+dsqMBNyRMQcVPK/fKMQ739HbdKQMHlK+pzoAhjuuO4RE7a2FuVTg+uKSjdVQ5 1IQgo06DdvUdVVnbR41cUy+No+H57x5ZbXOLTFzXfCib5eJcamFHyUDR30gQiQ== 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 4Tcdwm6lgwzKvW; Sat, 17 Feb 2024 19:22:32 +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 41HJMWOx000404; Sat, 17 Feb 2024 19:22:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41HJMWPv000401; Sat, 17 Feb 2024 19:22:32 GMT (envelope-from git) Date: Sat, 17 Feb 2024 19:22:32 GMT Message-Id: <202402171922.41HJMWPv000401@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: 929db0457513 - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: 929db0457513b577c4e256f6633dc72f76151c91 Auto-Submitted: auto-generated The branch stable/13 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=929db0457513b577c4e256f6633dc72f76151c91 commit 929db0457513b577c4e256f6633dc72f76151c91 Author: Andriy Gapon AuthorDate: 2024-01-28 11:29:41 +0000 Commit: Andriy Gapon CommitDate: 2024-02-17 19:22:08 +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 a3dd8b02622f..a60214e2a51e 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); @@ -81,9 +86,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); } @@ -108,10 +124,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 devclass_t gpiopower_devclass;