All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@siemens.com>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Le Jin <le.jin@siemens.com>,
	Bao Cheng Su <baocheng.su@siemens.com>,
	Nian Gao <nian.gao@siemens.com>,
	Chao Zeng <chao.zeng@siemens.com>,
	Lokesh Vutla <lokeshvutla@ti.com>
Subject: [PATCH v8 4/5] watchdog: rti_wdt: Add support for loading firmware
Date: Sat, 18 Sep 2021 08:17:55 +0200	[thread overview]
Message-ID: <7fba5e2370098ecd7a990ef9f400577e68962a7a.1631945876.git.jan.kiszka@siemens.com> (raw)
In-Reply-To: <cover.1631945876.git.jan.kiszka@siemens.com>

From: Jan Kiszka <jan.kiszka@siemens.com>

To avoid the need of extra boot scripting on AM65x for loading a
watchdog firmware, add the required rproc init and loading logic for the
first R5F core to the watchdog start handler. In case the R5F cluster is
in lock-step mode, also initialize the second core. The firmware itself
is embedded into U-Boot binary to ease access to it and ensure it is
properly hashed in case of secure boot.

One possible firmware source is https://github.com/siemens/k3-rti-wdt.

The board is responsible for providing the firmware as additional
loadable via the U-Boot fit image. The driver will pick up its location
from /fit-images/k3-rti-wdt-firmware then.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 drivers/watchdog/Kconfig   | 20 +++++++++
 drivers/watchdog/rti_wdt.c | 88 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 108 insertions(+)

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index f0ff2612a6..1a1fddfe9f 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -209,6 +209,26 @@ config WDT_K3_RTI
 	  Say Y here if you want to include support for the K3 watchdog
 	  timer (RTI module) available in the K3 generation of processors.
 
+if WDT_K3_RTI
+
+config WDT_K3_RTI_LOAD_FW
+	bool "Load watchdog firmware"
+	depends on REMOTEPROC
+	help
+	  Automatically load the specified firmware image into the MCU R5F
+	  core 0. On the AM65x, this firmware is supposed to handle the expiry
+	  of the watchdog timer, typically by resetting the system.
+
+config WDT_K3_RTI_FW_FILE
+	string "Watchdog firmware image file"
+	default "k3-rti-wdt.fw"
+	depends on WDT_K3_RTI_LOAD_FW
+	help
+	  Firmware image to be embedded into U-Boot and loaded on watchdog
+	  start.
+
+endif
+
 config WDT_SANDBOX
 	bool "Enable Watchdog Timer support for Sandbox"
 	depends on SANDBOX && WDT
diff --git a/drivers/watchdog/rti_wdt.c b/drivers/watchdog/rti_wdt.c
index 8335b20ae8..253286d349 100644
--- a/drivers/watchdog/rti_wdt.c
+++ b/drivers/watchdog/rti_wdt.c
@@ -11,9 +11,11 @@
 #include <common.h>
 #include <clk.h>
 #include <dm.h>
+#include <dm/device_compat.h>
 #include <power-domain.h>
 #include <wdt.h>
 #include <asm/io.h>
+#include <remoteproc.h>
 
 /* Timer register set definition */
 #define RTIDWDCTRL		0x90
@@ -42,6 +44,88 @@ struct rti_wdt_priv {
 	unsigned int clk_khz;
 };
 
+#ifdef CONFIG_WDT_K3_RTI_LOAD_FW
+#define RTI_WDT_FIT_PATH	"/fit-images/k3-rti-wdt-firmware"
+
+static int rti_wdt_load_fw(struct udevice *dev)
+{
+	struct udevice *rproc_dev;
+	int primary_core, ret;
+	u32 cluster_mode;
+	ofnode node;
+	u64 rti_wdt_fw;
+	u32 rti_wdt_fw_size;
+
+	node = ofnode_path(RTI_WDT_FIT_PATH);
+	if (!ofnode_valid(node))
+		goto fit_error;
+
+	ret = ofnode_read_u64(node, "load", &rti_wdt_fw);
+	if (ret)
+		goto fit_error;
+	ret = ofnode_read_u32(node, "size", &rti_wdt_fw_size);
+	if (ret)
+		goto fit_error;
+
+	node = ofnode_by_compatible(ofnode_null(), "ti,am654-r5fss");
+	if (!ofnode_valid(node))
+		goto dt_error;
+
+	ret = ofnode_read_u32(node, "ti,cluster-mode", &cluster_mode);
+	if (ret)
+		cluster_mode = 1;
+
+	node = ofnode_by_compatible(node, "ti,am654-r5f");
+	if (!ofnode_valid(node))
+		goto dt_error;
+
+	ret = uclass_get_device_by_ofnode(UCLASS_REMOTEPROC, node, &rproc_dev);
+	if (ret)
+		return ret;
+
+	primary_core = dev_seq(rproc_dev);
+
+	ret = rproc_dev_init(primary_core);
+	if (ret)
+		goto fw_error;
+
+	if (cluster_mode == 1) {
+		ret = rproc_dev_init(primary_core + 1);
+		if (ret)
+			goto fw_error;
+	}
+
+	ret = rproc_load(primary_core, (ulong)rti_wdt_fw,
+			 rti_wdt_fw_size);
+	if (ret)
+		goto fw_error;
+
+	ret = rproc_start(primary_core);
+	if (ret)
+		goto fw_error;
+
+	return 0;
+
+fit_error:
+	dev_err(dev, "No loadable firmware found under %s\n", RTI_WDT_FIT_PATH);
+	return -ENOENT;
+
+dt_error:
+	dev_err(dev, "No compatible firmware target processor found\n");
+	return -ENODEV;
+
+fw_error:
+	dev_err(dev, "Failed to load watchdog firmware into remote processor %d\n",
+		primary_core);
+	return ret;
+}
+#else
+static inline int rti_wdt_load_fw(struct udevice *dev)
+{
+	return 0;
+}
+#endif
+
 static int rti_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
 {
 	struct rti_wdt_priv *priv = dev_get_priv(dev);
@@ -51,6 +135,10 @@ static int rti_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
 	if (readl(priv->regs + RTIDWDCTRL) == WDENABLE_KEY)
 		return -EBUSY;
 
+	ret = rti_wdt_load_fw(dev);
+	if (ret < 0)
+		return ret;
+
 	timer_margin = timeout_ms * priv->clk_khz / 1000;
 	timer_margin >>= WDT_PRELOAD_SHIFT;
 	if (timer_margin > WDT_PRELOAD_MAX)
-- 
2.31.1


  parent reply	other threads:[~2021-09-18  6:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-18  6:17 [PATCH v8 0/5] Add SIMATIC IOT2050 board support Jan Kiszka
2021-09-18  6:17 ` [PATCH v8 1/5] arm: dts: Add IOT2050 device tree files Jan Kiszka
2021-10-03 23:34   ` Tom Rini
2021-09-18  6:17 ` [PATCH v8 2/5] board: siemens: Add support for SIMATIC IOT2050 devices Jan Kiszka
2021-10-03 23:34   ` Tom Rini
2021-10-04 15:54     ` Jan Kiszka
2021-10-04 16:02       ` Tom Rini
2021-10-04 16:35         ` Jan Kiszka
2021-09-18  6:17 ` [PATCH v8 3/5] arm64: dts: ti: k3-am65-mcu: Add RTI watchdog entry Jan Kiszka
2021-10-03 18:40   ` Tom Rini
2021-10-04  7:44     ` Jan Kiszka
2021-09-18  6:17 ` Jan Kiszka [this message]
2021-10-03 23:34   ` [PATCH v8 4/5] watchdog: rti_wdt: Add support for loading firmware Tom Rini
2021-09-18  6:17 ` [PATCH v8 5/5] iot2050: Enable watchdog support, but do not auto-start it Jan Kiszka
2021-10-03 23:34   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7fba5e2370098ecd7a990ef9f400577e68962a7a.1631945876.git.jan.kiszka@siemens.com \
    --to=jan.kiszka@siemens.com \
    --cc=baocheng.su@siemens.com \
    --cc=chao.zeng@siemens.com \
    --cc=le.jin@siemens.com \
    --cc=lokeshvutla@ti.com \
    --cc=nian.gao@siemens.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.