From: Ahmad Fatoum <a.fat...@barebox.org>

This simplifies handling of the existing warm reboot support and allow
for simple addition of more flags in future.

Signed-off-by: Ahmad Fatoum <a.fat...@barebox.org>
---
 arch/arm/dts/imx7.dtsi   |  2 +-
 commands/reset.c         |  4 ++--
 common/restart.c         |  6 ++++--
 drivers/watchdog/imxwd.c | 35 +++++++++++------------------------
 include/restart.h        |  2 +-
 5 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/arch/arm/dts/imx7.dtsi b/arch/arm/dts/imx7.dtsi
index 1c67bdc54620..d0f6b253ed86 100644
--- a/arch/arm/dts/imx7.dtsi
+++ b/arch/arm/dts/imx7.dtsi
@@ -28,7 +28,7 @@ ca7_reset: cortex-a7-reboot {
                /* This is not fit for use as general purpose reset */
                restart-priority = <5>;
                /*
-                * Can't use imxwd-warm due to errata e10574:
+                * Can't use imxwd without fsl,ext-reset-output due to errata 
e10574:
                 * Watchdog: A watchdog timeout or software trigger will
                 * not reset the SOC
                 */
diff --git a/commands/reset.c b/commands/reset.c
index e97b5668bacb..ccd8291f5353 100644
--- a/commands/reset.c
+++ b/commands/reset.c
@@ -26,7 +26,7 @@ static int cmd_reset(int argc, char *argv[])
                        restart_handlers_print();
                        return 0;
                case 'w':
-                       flags |= RESTART_FLAG_WARM_BOOTROM;
+                       flags |= RESTART_WARM;
                        break;
                case 'r':
                        name = optarg;
@@ -47,7 +47,7 @@ static int cmd_reset(int argc, char *argv[])
 
        if (rst) {
                console_flush();
-               rst->restart(rst, 0);
+               rst->restart(rst, flags);
        }
 
        hang();
diff --git a/common/restart.c b/common/restart.c
index dce7e974f64a..d0ceeab7acd0 100644
--- a/common/restart.c
+++ b/common/restart.c
@@ -32,7 +32,7 @@ int restart_handler_register(struct restart_handler *rst)
                                     &rst->priority);
                if (of_property_read_bool(rst->of_node,
                                          "barebox,restart-warm-bootrom"))
-                       rst->flags |= RESTART_FLAG_WARM_BOOTROM;
+                       rst->flags |= RESTART_WARM;
        }
 
        list_add_tail(&rst->list, &restart_handler_list);
@@ -127,8 +127,10 @@ void restart_handlers_print(void)
        list_for_each_entry(tmp, &restart_handler_list, list) {
                printf("%-20s %-20s %6d ",
                       tmp->name, tmp->dev ? dev_name(tmp->dev) : "", 
tmp->priority);
-               if (tmp->flags & RESTART_FLAG_WARM_BOOTROM)
+               if (tmp->flags & RESTART_WARM)
                        putchar('W');
                putchar('\n');
        }
+
+       printf("\nW: Warm restart capable\n");
 }
diff --git a/drivers/watchdog/imxwd.c b/drivers/watchdog/imxwd.c
index 10d94645fae6..35c688fc2701 100644
--- a/drivers/watchdog/imxwd.c
+++ b/drivers/watchdog/imxwd.c
@@ -30,7 +30,6 @@ struct imx_wd {
        struct device *dev;
        const struct imx_wd_ops *ops;
        struct restart_handler restart;
-       struct restart_handler restart_warm;
        bool ext_reset;
        bool bigendian;
        bool suspend_in_lpm;
@@ -176,6 +175,9 @@ static void __noreturn imxwd_force_soc_reset(struct 
restart_handler *rst,
 {
        struct imx_wd *priv = container_of(rst, struct imx_wd, restart);
 
+       if (flags & RESTART_WARM)
+               priv->ext_reset = false;
+
        priv->ops->soc_reset(priv);
 
        mdelay(1000);
@@ -183,15 +185,6 @@ static void __noreturn imxwd_force_soc_reset(struct 
restart_handler *rst,
        hang();
 }
 
-static void __noreturn imxwd_force_soc_reset_internal(struct restart_handler 
*rst,
-                                                     unsigned long flags)
-{
-       struct imx_wd *priv = container_of(rst, struct imx_wd, restart_warm);
-
-       priv->ext_reset = false;
-       imxwd_force_soc_reset(&priv->restart, flags);
-}
-
 static void imx_watchdog_detect_reset_source(struct imx_wd *priv)
 {
        u16 val = imxwd_read(priv, IMX21_WDOG_WSTR);
@@ -232,13 +225,7 @@ static int imx21_wd_init_no_warm_reset(struct imx_wd *priv)
 
 static int imx21_wd_init(struct imx_wd *priv)
 {
-       priv->restart_warm.name = "imxwd-warm";
-       priv->restart_warm.restart = imxwd_force_soc_reset_internal;
-       priv->restart_warm.priority = RESTART_DEFAULT_PRIORITY - 10;
-       priv->restart_warm.flags = RESTART_FLAG_WARM_BOOTROM;
-
-       restart_handler_register(&priv->restart_warm);
-
+       priv->restart.flags = RESTART_WARM;
        return imx21_wd_init_no_warm_reset(priv);
 }
 
@@ -295,6 +282,13 @@ static int imx_wd_probe(struct device *dev)
                }
        }
 
+       dev->priv = priv;
+
+       priv->restart.name = "imxwd";
+       priv->restart.restart = imxwd_force_soc_reset;
+       priv->restart.priority = RESTART_DEFAULT_PRIORITY;
+       priv->restart.dev = &priv->wd.dev;
+
        if (priv->ops->init) {
                ret = priv->ops->init(priv);
                if (ret) {
@@ -304,13 +298,6 @@ static int imx_wd_probe(struct device *dev)
                }
        }
 
-       dev->priv = priv;
-
-       priv->restart.name = "imxwd";
-       priv->restart.restart = imxwd_force_soc_reset;
-       priv->restart.priority = RESTART_DEFAULT_PRIORITY;
-       priv->restart.dev = &priv->wd.dev;
-
        restart_handler_register(&priv->restart);
 
        return 0;
diff --git a/include/restart.h b/include/restart.h
index 9707a2f40f14..5414fc1fcb69 100644
--- a/include/restart.h
+++ b/include/restart.h
@@ -9,6 +9,7 @@
 struct device_node;
 
 void restart_handlers_print(void);
+#define RESTART_WARM                   BIT(0)
 void __noreturn restart_machine(unsigned long restart_flags);
 struct restart_handler *restart_handler_get_by_name(const char *name, int 
flags);
 
@@ -17,7 +18,6 @@ struct device_node;
 struct restart_handler {
        void (*restart)(struct restart_handler *, unsigned long);
        int priority;
-#define RESTART_FLAG_WARM_BOOTROM      BIT(0)
        int flags;
        struct device_node *of_node;
        const char *name;
-- 
2.39.5


Reply via email to