@@ -4,14 +4,17 @@
*
* Copyright (C) 2024 Renesas Electronics Corporation.
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/kernel.h>
+#include <linux/mfd/syscon.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
#include <linux/reset.h>
#include <linux/units.h>
#include <linux/watchdog.h>
@@ -40,6 +43,9 @@
#define WDT_DEFAULT_TIMEOUT 60U
+#define CPG_ERROR_RST2(x) BIT(x)
+#define CPG_ERROR_RST2_WEN(x) BIT((x) + 16)
+
static bool nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, bool, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
@@ -139,6 +145,11 @@ static const struct watchdog_info rzv2h_wdt_ident = {
.identity = "Renesas RZ/V2H WDT Watchdog",
};
+static const struct watchdog_info rzv2h_wdt_ident_card_reset = {
+ .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_CARDRESET,
+ .identity = "Renesas RZ/V2H WDT Watchdog",
+};
+
static int rzv2h_wdt_restart(struct watchdog_device *wdev,
unsigned long action, void *data)
{
@@ -206,9 +217,40 @@ static const struct watchdog_ops rzv2h_wdt_ops = {
static int rzv2h_wdt_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
struct rzv2h_wdt_priv *priv;
+ unsigned int bootstatus = 0;
+ bool cardreset = false;
+ struct regmap *syscon;
int ret;
+ /* Do not error out to maintain old DT compatibility */
+ syscon = syscon_regmap_lookup_by_phandle(np, "renesas,r9a09g057-syscon-wdt-errorrst");
+ if (!IS_ERR(syscon)) {
+ struct of_phandle_args args;
+ u32 reg;
+
+ ret = of_parse_phandle_with_fixed_args(np, "renesas,r9a09g057-syscon-wdt-errorrst",
+ 2, 0, &args);
+ if (ret)
+ return ret;
+
+ ret = regmap_read(syscon, args.args[0], ®);
+ if (ret)
+ return -EINVAL;
+
+ if (reg & CPG_ERROR_RST2(args.args[1])) {
+ ret = regmap_write(syscon, args.args[0],
+ CPG_ERROR_RST2(args.args[1]) |
+ CPG_ERROR_RST2_WEN(args.args[1]));
+ if (ret)
+ return -EINVAL;
+ }
+ cardreset = true;
+ bootstatus = reg & CPG_ERROR_RST2(args.args[1]) ? WDIOF_CARDRESET : 0;
+ regmap_read(syscon, args.args[0], ®);
+ }
+
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
@@ -240,9 +282,13 @@ static int rzv2h_wdt_probe(struct platform_device *pdev)
priv->wdev.min_timeout = 1;
priv->wdev.timeout = WDT_DEFAULT_TIMEOUT;
- priv->wdev.info = &rzv2h_wdt_ident;
+ if (!cardreset)
+ priv->wdev.info = &rzv2h_wdt_ident;
+ else
+ priv->wdev.info = &rzv2h_wdt_ident_card_reset;
priv->wdev.ops = &rzv2h_wdt_ops;
priv->wdev.parent = dev;
+ priv->wdev.bootstatus = bootstatus;
watchdog_set_drvdata(&priv->wdev, priv);
watchdog_set_nowayout(&priv->wdev, nowayout);
watchdog_stop_on_unregister(&priv->wdev);