From: Stanley Chu <[email protected]>

Calculate a timeout value that is close to the requested value.

Signed-off-by: Stanley Chu <[email protected]>
---
 drivers/watchdog/npcm_wdt.c | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/drivers/watchdog/npcm_wdt.c b/drivers/watchdog/npcm_wdt.c
index 57b61215a2a..7becc646fda 100644
--- a/drivers/watchdog/npcm_wdt.c
+++ b/drivers/watchdog/npcm_wdt.c
@@ -27,26 +27,11 @@ struct npcm_wdt_priv {
 static int npcm_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
 {
        struct npcm_wdt_priv *priv = dev_get_priv(dev);
-       u32 time_out, val;
-
-       time_out = (u32)(timeout_ms) / 1000;
-       if (time_out < 2)
-               val = 0x800;
-       else if (time_out < 3)
-               val = 0x420;
-       else if (time_out < 6)
-               val = 0x810;
-       else if (time_out < 11)
-               val = 0x430;
-       else if (time_out < 22)
-               val = 0x820;
-       else if (time_out < 44)
-               val = 0xc00;
-       else if (time_out < 87)
-               val = 0x830;
-       else if (time_out < 173)
-               val = 0xc10;
-       else if (time_out < 688)
+       u32 val;
+
+       if (timeout_ms < 343552)
+               val = ((timeout_ms / 1342) << 16) + 0x800;
+       else if (timeout_ms < 688000)
                val = 0xc20;
        else
                val = 0xc30;
-- 
2.34.1

Reply via email to