Merge tag 'u-boot-imx-20200825' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx
[platform/kernel/u-boot.git] / drivers / watchdog / ast_wdt.c
index 3539844..9b83d2a 100644 (file)
@@ -1,15 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2017 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
 #include <dm.h>
 #include <errno.h>
+#include <log.h>
 #include <wdt.h>
 #include <asm/io.h>
 #include <asm/arch/wdt.h>
+#include <linux/err.h>
 
 #define WDT_AST2500    2500
 #define WDT_AST2400    2400
@@ -24,6 +25,12 @@ static int ast_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
        ulong driver_data = dev_get_driver_data(dev);
        u32 reset_mode = ast_reset_mode_from_flags(flags);
 
+       /* 32 bits at 1MHz is 4294967ms */
+       timeout = min_t(u64, timeout, 4294967);
+
+       /* WDT counts in ticks of 1MHz clock. 1ms / 1e3 * 1e6 */
+       timeout *= 1000;
+
        clrsetbits_le32(&priv->regs->ctrl,
                        WDT_CTRL_RESET_MASK << WDT_CTRL_RESET_MODE_SHIFT,
                        reset_mode << WDT_CTRL_RESET_MODE_SHIFT);
@@ -51,6 +58,7 @@ static int ast_wdt_stop(struct udevice *dev)
 
        clrbits_le32(&priv->regs->ctrl, WDT_CTRL_EN);
 
+       writel(WDT_RESET_DEFAULT, &priv->regs->reset_mask);
        return 0;
 }
 
@@ -82,9 +90,9 @@ static int ast_wdt_ofdata_to_platdata(struct udevice *dev)
 {
        struct ast_wdt_priv *priv = dev_get_priv(dev);
 
-       priv->regs = devfdt_get_addr_ptr(dev);
-       if (IS_ERR(priv->regs))
-               return PTR_ERR(priv->regs);
+       priv->regs = dev_read_addr_ptr(dev);
+       if (!priv->regs)
+               return -EINVAL;
 
        return 0;
 }
@@ -119,5 +127,4 @@ U_BOOT_DRIVER(ast_wdt) = {
        .priv_auto_alloc_size = sizeof(struct ast_wdt_priv),
        .ofdata_to_platdata = ast_wdt_ofdata_to_platdata,
        .ops = &ast_wdt_ops,
-       .flags = DM_FLAG_PRE_RELOC,
 };