From nobody Sat Nov 6 18:00:56 2021 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 1476E1833163; Sat, 6 Nov 2021 18:00:57 +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 4HmlY507Hhz4ZTR; Sat, 6 Nov 2021 18:00:57 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 D84A97828; Sat, 6 Nov 2021 18:00:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1A6I0u9A044311; Sat, 6 Nov 2021 18:00:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A6I0uQh044310; Sat, 6 Nov 2021 18:00:56 GMT (envelope-from git) Date: Sat, 6 Nov 2021 18:00:56 GMT Message-Id: <202111061800.1A6I0uQh044310@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: cc0b35259aed - main - rk805: add system poweroff support 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: cc0b35259aed73747721718415fa1854108a276a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=cc0b35259aed73747721718415fa1854108a276a commit cc0b35259aed73747721718415fa1854108a276a Author: Andriy Gapon AuthorDate: 2021-11-06 17:58:43 +0000 Commit: Andriy Gapon CommitDate: 2021-11-06 17:58:43 +0000 rk805: add system poweroff support On my Rock64 neither EFI nor PSCI shutdown actually power off the board. RK805 does the job. Reviewed by: manu, peterj Differential Revision: https://reviews.freebsd.org/D30786 --- sys/arm64/rockchip/rk805.c | 36 ++++++++++++++++++++++++++++++++++++ sys/arm64/rockchip/rk805reg.h | 4 ++++ 2 files changed, 40 insertions(+) diff --git a/sys/arm64/rockchip/rk805.c b/sys/arm64/rockchip/rk805.c index a2ee53b35a07..d3bda29ae362 100644 --- a/sys/arm64/rockchip/rk805.c +++ b/sys/arm64/rockchip/rk805.c @@ -31,8 +31,10 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include +#include #include #include #include @@ -844,6 +846,29 @@ rk805_settime(device_t dev, struct timespec *ts) return (error); } +static void +rk805_poweroff(void *arg, int howto) +{ + device_t dev = arg; + int error; + uint8_t val; + + if ((howto & RB_POWEROFF) == 0) + return; + + device_printf(dev, "Powering off...\n"); + error = rk805_read(dev, RK805_DEV_CTRL, &val, 1); + if (error == 0) { + val |= RK805_DEV_CTRL_OFF; + error = rk805_write(dev, RK805_DEV_CTRL, &val, 1); + + /* Wait a bit for the command to take effect. */ + if (error == 0) + DELAY(100); + } + device_printf(dev, "Power off failed\n"); +} + static int rk805_attach(device_t dev) { @@ -907,6 +932,17 @@ rk805_attach(device_t dev) } } + if (OF_hasprop(ofw_bus_get_node(dev), + "rockchip,system-power-controller")) { + /* + * The priority is chosen to override PSCI and EFI shutdown + * methods as those two just hang without powering off on Rock64 + * at least. + */ + EVENTHANDLER_REGISTER(shutdown_final, rk805_poweroff, dev, + SHUTDOWN_PRI_LAST - 2); + } + return (0); } diff --git a/sys/arm64/rockchip/rk805reg.h b/sys/arm64/rockchip/rk805reg.h index b1f4481a5b68..61c6f49abd2c 100644 --- a/sys/arm64/rockchip/rk805reg.h +++ b/sys/arm64/rockchip/rk805reg.h @@ -93,6 +93,10 @@ #define RK808_LDO8_ON_VSEL 0x49 #define RK808_LDO8_SLEEP_VSEL 0x4A +#define RK805_DEV_CTRL 0x4B +#define RK805_DEV_CTRL_OFF (1 << 0) +#define RK805_DEV_CTRL_SLP (1 << 1) + enum rk805_regulator { RK805_DCDC1 = 0, RK805_DCDC2,