From nobody Mon May 16 13:51:24 2022 X-Original-To: dev-commits-src-branches@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 EB7961B356FB; Mon, 16 May 2022 13:51:25 +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 4L20z11BXHz3Gpr; Mon, 16 May 2022 13:51:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652709085; 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=nLqPGzzMvhwHlHsUoue0qLyU8GeGwJKmDk5k0dlbFoM=; b=uRR+y6Zh1aNLJyYrvKPXZvy4QdBIoa6sNyzx60JY2odJQ4eN/3a8zqIcSaIoBnJqQWfYdQ aMRhbFaPfYgLwpY4vuTHvBIJCyA8cdAnefQ/0bbDNF38RLW4juTABZ/+Gkb3MaOchaI0q+ u7nrGkRbTFH1eEWVZHZjsIcxrIQM5h+He5/f3NaFOHbb9M2AgMtsiMU9HZORi8+9M79WyM KYbECyVZthsc/tPZNQOTZ9JUjyRymkIyoAcxAAF+efWHMCiGE85L1yOa6H77ZHgJLClMdr Ljk+1saJ6YNUD3QBOLNaSJ8kYItYVnqNzK+JOZOC7JFTjOtpn0su1B05xprz0A== 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 D5FC221269; Mon, 16 May 2022 13:51:24 +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 24GDpOHS079798; Mon, 16 May 2022 13:51:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 24GDpOwS079797; Mon, 16 May 2022 13:51:24 GMT (envelope-from git) Date: Mon, 16 May 2022 13:51:24 GMT Message-Id: <202205161351.24GDpOwS079797@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: e22111893089 - stable/13 - aw_wdog: support Allwinner D1 watchdog List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e22111893089ab8fd4447f99f03ff83d71c6c1b4 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652709085; 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=nLqPGzzMvhwHlHsUoue0qLyU8GeGwJKmDk5k0dlbFoM=; b=NxvdgfgHLwbbdOlOY/O5p3KiVX0um3rCZNfDTYK5DkX9gJ7SDZoX+G6BLW0gYCE1ztbH99 kHiKxllXCR7YSUp4xIObWUJMMbn9zyCpLS/lmuAUvf+0umuyVD4K439NqjrRnvze0yV1M0 +uiEMVUpzxprZkXg0ZEy8AgFXE9ySq0OqY/A6+CPuvBwijpOrdandv9L8BSUmJ2OIF3H3H vgtAAgjk6NFU69ucUODemdxqpEQy5okLdtnfJ/NyzNIrE7GLTSVF9At83uHJQ9eJVw6nty R8DjutSgU8hTxvub9prJRTk+IeJamgWgJQsu3akQffM3SHNrfWP70BHXSwZrFw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652709085; a=rsa-sha256; cv=none; b=TCP7dC0vHGWY+6Gn6suJGNHYa6Dm5H40r5zIUhqG+Ym8Y/s44xoeRJepBAs/0jpPTDGsIb 1MjIVtUsfbS2PbQFmacL7uenGGdmFjMm1HCPK/cpOBzcOe5PCK7VCIlLeDDrAdxXYOX9Jg fUKYZQrGGSVbDjEZQRCqnc9efg1V7ZidgtyqYZHeVFTzCKHIyvC6fRc/UjdMzlTNWkjp3j UjQ4TAAgor4cnXQpDT9PTvW9BPK2Gp68XqPc5hCpl1t3YLSqWdRpssiZOxUkfmQEOLa6lJ w6PNP98PIE7pGM6pRkRZHO71HynEMSgrj9Fvtcn0pbnTatkp/SVnmP8xk8WLCQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=e22111893089ab8fd4447f99f03ff83d71c6c1b4 commit e22111893089ab8fd4447f99f03ff83d71c6c1b4 Author: Julien Cassette AuthorDate: 2022-04-12 22:12:49 +0000 Commit: Mitchell Horne CommitDate: 2022-05-16 13:34:04 +0000 aw_wdog: support Allwinner D1 watchdog This device is present on the Allwinner D1-based SoCs. Without this driver, the watchdog timeout will trigger a reset a few seconds after control is given to the kernel. Reviewed By: manu, mhorne MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D34749 (cherry picked from commit 3a6f0bb25f06056c92d7e53ce63e2d297932c96f) --- sys/arm/allwinner/aw_wdog.c | 39 +++++++++++++++++++++++++++++++------ sys/riscv/allwinner/files.allwinner | 3 +++ sys/riscv/conf/GENERIC | 4 ++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/sys/arm/allwinner/aw_wdog.c b/sys/arm/allwinner/aw_wdog.c index 0fc5895eff9f..4e7af4ef25d6 100644 --- a/sys/arm/allwinner/aw_wdog.c +++ b/sys/arm/allwinner/aw_wdog.c @@ -1,6 +1,7 @@ /*- * Copyright (c) 2013 Oleksandr Tymoshenko * Copyright (c) 2016 Emmanuel Vadot + * Copyright (c) 2022 Julien Cassette * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,7 +45,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include @@ -53,17 +53,26 @@ __FBSDID("$FreeBSD$"); #define A10_WDOG_CTRL 0x00 #define A31_WDOG_CTRL 0x10 +#define D1_WDOG_CTRL 0x10 #define WDOG_CTRL_RESTART (1 << 0) #define A31_WDOG_CTRL_KEY (0xa57 << 1) +#define D1_WDOG_CTRL_KEY (0xa57 << 1) #define A10_WDOG_MODE 0x04 #define A31_WDOG_MODE 0x18 +#define D1_WDOG_MODE 0x18 +#define D1_WDOG_MODE_KEY (0x16AA << 16) #define A10_WDOG_MODE_INTVL_SHIFT 3 #define A31_WDOG_MODE_INTVL_SHIFT 4 +#define D1_WDOG_MODE_INTVL_SHIFT 4 #define A10_WDOG_MODE_RST_EN (1 << 1) #define WDOG_MODE_EN (1 << 0) #define A31_WDOG_CONFIG 0x14 +#define D1_WDOG_CONFIG 0x14 #define A31_WDOG_CONFIG_RST_EN_SYSTEM (1 << 0) #define A31_WDOG_CONFIG_RST_EN_INT (2 << 0) +#define D1_WDOG_CONFIG_KEY (0x16AA << 16) +#define D1_WDOG_CONFIG_RST_EN_SYSTEM (1 << 0) +#define D1_WDOG_CONFIG_RST_EN_INT (2 << 0) struct aw_wdog_interval { uint64_t milliseconds; @@ -95,18 +104,21 @@ struct aw_wdog_softc { uint8_t wdog_ctrl; uint32_t wdog_ctrl_key; uint8_t wdog_mode; + uint32_t wdog_mode_key; uint8_t wdog_mode_intvl_shift; uint8_t wdog_mode_en; uint8_t wdog_config; - uint8_t wdog_config_value; + uint32_t wdog_config_value; }; #define A10_WATCHDOG 1 #define A31_WATCHDOG 2 +#define D1_WATCHDOG 3 static struct ofw_compat_data compat_data[] = { {"allwinner,sun4i-a10-wdt", A10_WATCHDOG}, {"allwinner,sun6i-a31-wdt", A31_WATCHDOG}, + {"allwinner,sun20i-d1-wdt", D1_WATCHDOG}, {NULL, 0} }; @@ -126,6 +138,9 @@ aw_wdog_probe(device_t dev) case A31_WATCHDOG: device_set_desc(dev, "Allwinner A31 Watchdog"); return (BUS_PROBE_DEFAULT); + case D1_WATCHDOG: + device_set_desc(dev, "Allwinner D1 Watchdog"); + return (BUS_PROBE_DEFAULT); } return (ENXIO); } @@ -155,6 +170,7 @@ aw_wdog_attach(device_t dev) case A10_WATCHDOG: sc->wdog_ctrl = A10_WDOG_CTRL; sc->wdog_mode = A10_WDOG_MODE; + sc->wdog_mode_key = 0; sc->wdog_mode_intvl_shift = A10_WDOG_MODE_INTVL_SHIFT; sc->wdog_mode_en = A10_WDOG_MODE_RST_EN | WDOG_MODE_EN; break; @@ -162,11 +178,22 @@ aw_wdog_attach(device_t dev) sc->wdog_ctrl = A31_WDOG_CTRL; sc->wdog_ctrl_key = A31_WDOG_CTRL_KEY; sc->wdog_mode = A31_WDOG_MODE; + sc->wdog_mode_key = 0; sc->wdog_mode_intvl_shift = A31_WDOG_MODE_INTVL_SHIFT; sc->wdog_mode_en = WDOG_MODE_EN; sc->wdog_config = A31_WDOG_CONFIG; sc->wdog_config_value = A31_WDOG_CONFIG_RST_EN_SYSTEM; break; + case D1_WATCHDOG: + sc->wdog_ctrl = D1_WDOG_CTRL; + sc->wdog_ctrl_key = D1_WDOG_CTRL_KEY; + sc->wdog_mode = D1_WDOG_MODE; + sc->wdog_mode_key = D1_WDOG_MODE_KEY; + sc->wdog_mode_intvl_shift = D1_WDOG_MODE_INTVL_SHIFT; + sc->wdog_mode_en = WDOG_MODE_EN; + sc->wdog_config = D1_WDOG_CONFIG; + sc->wdog_config_value = D1_WDOG_CONFIG_KEY | D1_WDOG_CONFIG_RST_EN_SYSTEM; + break; default: bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res); return (ENXIO); @@ -199,7 +226,7 @@ aw_wdog_watchdog_fn(void *private, u_int cmd, int *error) (ms > wd_intervals[i].milliseconds)) i++; if (wd_intervals[i].milliseconds) { - WRITE(sc, sc->wdog_mode, + WRITE(sc, sc->wdog_mode, sc->wdog_mode_key | (wd_intervals[i].value << sc->wdog_mode_intvl_shift) | sc->wdog_mode_en); WRITE(sc, sc->wdog_ctrl, @@ -217,12 +244,12 @@ aw_wdog_watchdog_fn(void *private, u_int cmd, int *error) device_printf(sc->dev, "Can't arm, timeout is more than 16 sec\n"); mtx_unlock(&sc->mtx); - WRITE(sc, sc->wdog_mode, 0); + WRITE(sc, sc->wdog_mode, sc->wdog_mode_key); return; } } else - WRITE(sc, sc->wdog_mode, 0); + WRITE(sc, sc->wdog_mode, sc->wdog_mode_key); mtx_unlock(&sc->mtx); } @@ -243,7 +270,7 @@ aw_wdog_watchdog_reset(void) return; } - WRITE(aw_wdog_sc, aw_wdog_sc->wdog_mode, + WRITE(aw_wdog_sc, aw_wdog_sc->wdog_mode, aw_wdog_sc->wdog_mode_key | (wd_intervals[0].value << aw_wdog_sc->wdog_mode_intvl_shift) | aw_wdog_sc->wdog_mode_en); if (aw_wdog_sc->wdog_config) diff --git a/sys/riscv/allwinner/files.allwinner b/sys/riscv/allwinner/files.allwinner new file mode 100644 index 000000000000..fb8c35a0b355 --- /dev/null +++ b/sys/riscv/allwinner/files.allwinner @@ -0,0 +1,3 @@ +# $FreeBSD$ + +arm/allwinner/aw_wdog.c optional aw_wdog diff --git a/sys/riscv/conf/GENERIC b/sys/riscv/conf/GENERIC index 7849ddb38485..12d48986184a 100644 --- a/sys/riscv/conf/GENERIC +++ b/sys/riscv/conf/GENERIC @@ -197,6 +197,10 @@ makeoptions MODULES_EXTRA+="dtb/sifive" device iicbus # Bus support, required for iicoc below. device iicoc # OpenCores I2C controller support +# Allwinner device drivers +device aw_wdog # Allwinner Watchdog +files "../allwinner/files.allwinner" + # SiFive device drivers device fu740_pci_dw device sifive_gpio