From nobody Sun Jan 28 11:31:19 2024 X-Original-To: dev-commits-src-main@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 4TN8QH5CXhz58PjB; Sun, 28 Jan 2024 11:31:19 +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 4TN8QH4kqrz4jRt; Sun, 28 Jan 2024 11:31:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706441479; 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=jQqWhyA4nx24S0Pv4+Au2aeYPz8m4lJWge+2ftRfVr0=; b=T69k/809kc1GKfjp5Q0/pHPX2aELj6FOW2DrlNZeSD0EAWkOEu1I3o8VqxJcJ1ELTadAXy D0nCoo2FsxJ/WHW/IkeZSVWy1nvG5ty9wtrUWCKIhb48B201WhxIX74sSyffz0+X06BX0t GE+XeNnrxnkDrFHTQ1DHdNLHdQ79/7Bqxxjawi/6FsIPhs+sw8NyB4eqtp72ugTNWe4RVy uPOncw7weuqz9hw+Elty7VqF9NHVHD9V02YpuvTB7dmp129Vwp9JsKts2bQnQb+//nTdy5 LFzzguTvZxELN6e+z5f9ZJwKUiCtcoKlKjwG3DJnch+jBQTTjok8qaOZowzISw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706441479; 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=jQqWhyA4nx24S0Pv4+Au2aeYPz8m4lJWge+2ftRfVr0=; b=BEKpPS56f319m//nnm1Y7uUfhkUMi9bK09hm3nIlx2fJofLMUkzrheDLhRqpf25BnNsdxR iuJD3Upv94wP3FzWqwsATqAdxTTIZKR0UX18pIZfSUhuo80Bk5MRgRYqcqOhWOxBGriBUO 6QY3uL2J4Xu7Ou8+tDcmHJWJDXPxgugppMUBhqtl7xY6Muv1BmbuTqlFEVUKVUgw8iOxoJ M4/trIYAvp2p4o8xaKaI70NVCGRkOK4ES6INvKYtv5/+22QjY9TrcFRz4GvZV2OQWYZJlD tnEJpxRuMuwYOR+Rvu3KWnb//9jswNZL56fRWN5hjTerBzHCSwGJ8TM991jH8w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706441479; a=rsa-sha256; cv=none; b=ot4zLJFkIymfrchsbxjBZoxxDKWR8i525shI8t7XSrY4InUPiYWapIPZmCk2Ohx9ttEP+T 2Yx6+RVZyBw4VS107AYbZB5btti1nz0741C8a1lkR0Ykz5dQa/qu5z74nGZ/Ls3TGb2IIf ibkGCSQx2gvZHRVKcollywYTDN3VAAOAg0kaMJmNxCDHnB/PksxtqvAAP+VMF2D+XXaU48 aqu05TC1cB7ckLtEjHuXliIF3VWKI+rMbVl9BuyWfBpn5jUSYKvTcCfAuycn0k9X9EIRic aiaGzLusUuL84RabmJvcJS7xTtMWPFbCdzEms2mhFat245vLyrP37o7/DewGrA== 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 4TN8QH3VwGz15w8; Sun, 28 Jan 2024 11:31:19 +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 40SBVJjj066679; Sun, 28 Jan 2024 11:31:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40SBVJCs066676; Sun, 28 Jan 2024 11:31:19 GMT (envelope-from git) Date: Sun, 28 Jan 2024 11:31:19 GMT Message-Id: <202401281131.40SBVJCs066676@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andriy Gapon Subject: git: 320e4beb9761 - main - gpiopower: trigger low, high and both edges List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 320e4beb97618c6964380bfa404a3e96c5de7663 Auto-Submitted: auto-generated The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=320e4beb97618c6964380bfa404a3e96c5de7663 commit 320e4beb97618c6964380bfa404a3e96c5de7663 Author: Andriy Gapon AuthorDate: 2024-01-28 11:29:41 +0000 Commit: Andriy Gapon CommitDate: 2024-01-28 11:29:41 +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). --- 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[] = {