wdt: dw: Switch to using fls for log2
Subsystems (2)
PATCH 1/7 wdt: dw: Switch to using fls for log2
log_2_n_round_up is only found in arm. fls performs the same job and is generic.
---
drivers/watchdog/designware_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/watchdog/designware_wdt.c +1 -2
@@ -9,7 +9,6 @@#include <reset.h> #include <wdt.h> #include <asm/io.h> -#include <asm/utils.h> #include <linux/bitops.h> #define DW_WDT_CR 0x00
@@ -35,7 +34,7 @@ static int designware_wdt_settimeout(void __iomem *base, unsigned int clk_khz,signed int i;/* calculate the timeout range value */ - i =log_2_n_round_up (timeout * clk_khz) -16 ; + i =fls (timeout * clk_khz) -16 ; i =clamp (i,0 ,15 );writel (i | (i <<4 ), base +DW_WDT_TORR );
Signature · 1 line
2.27.0
PATCH 2/7 wdt: dw: Switch to if(CONFIG()) instead of using #if
This is preferred over #if because the compiler can check syntax even if the feature is disabled. This cannot be used for CONFIG_CLK because CONFIG_DW_WDT_CLOCK_KHZ is not defined on all platforms.
---
drivers/watchdog/designware_wdt.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/watchdog/designware_wdt.c +9 -9
@@ -136,17 +136,17 @@ static int designware_wdt_probe(struct udevice *dev) priv->clk_khz =CONFIG_DW_WDT_CLOCK_KHZ ;#endif -#if CONFIG_IS_ENABLED (DM_RESET ) -struct reset_ctl_bulk resets; +if (CONFIG_IS_ENABLED (DM_RESET )) { +struct reset_ctl_bulk resets; - ret =reset_get_bulk (dev, &resets); -if (ret) -return ret; + ret =reset_get_bulk (dev, &resets); +if (ret) +return ret; - ret =reset_deassert_bulk (&resets); -if (ret) -return ret; -#endif + ret =reset_deassert_bulk (&resets); +if (ret) +return ret; + }/* reset to disable the watchdog */ return designware_wdt_stop (dev);
Signature · 1 line
2.27.0
PATCH 2/7 wdt: dw: Switch to if(CONFIG()) instead of using #if
Quoted 5 lines · Sean Anderson
This is preferred over #if because the compiler can check syntax even if the feature is disabled. This cannot be used for
CONFIG_CLKbecauseCONFIG_DW_WDT_CLOCK_KHZis not defined on all platforms.Signed-off-by Sean Anderson <[email protected]>
PATCH 3/7 wdt: dw: Fix clock rate being off by 1000
In reply to Sean AndersonThe clock subsystem returns clock rates in Hz. We need to divide by 1000 so the rate is in kHz.
---
drivers/watchdog/designware_wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/designware_wdt.c +1 -1
@@ -129,7 +129,7 @@ static int designware_wdt_probe(struct udevice *dev)if (ret)return ret; - priv->clk_khz =clk_get_rate (&clk); + priv->clk_khz =clk_get_rate (&clk) /1000 ;if (!priv->clk_khz)return -EINVAL ;#else
Signature · 1 line
2.27.0
PATCH 3/7 wdt: dw: Fix clock rate being off by 1000
Quoted 10 lines · Sean Anderson
The clock subsystem returns clock rates in Hz. We need to divide by 1000 so the rate is in kHz.
Fixes cf89ef8d10f240554541c20b2e1bdcdd58d1d7e6Signed-off-by Sean Anderson <[email protected]>---
drivers/watchdog/designware_wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 4/7 wdt: dw: Enable the clock before using it
In reply to Sean AndersonThe watchdog won't work if the clock isn't enabled.
---
drivers/watchdog/designware_wdt.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/watchdog/designware_wdt.c +4 -0
@@ -129,6 +129,10 @@ static int designware_wdt_probe(struct udevice *dev)if (ret)return ret; + ret =clk_enable (&clk); +if (ret) +return ret; + priv->clk_khz =clk_get_rate (&clk) /1000 ;if (!priv->clk_khz)return -EINVAL ;
Signature · 1 line
2.27.0
PATCH 4/7 wdt: dw: Enable the clock before using it
Quoted 10 lines · Sean Anderson
The watchdog won't work if the clock isn't enabled.
Fixes cf89ef8d10f240554541c20b2e1bdcdd58d1d7e6Signed-off-by Sean Anderson <[email protected]>---
drivers/watchdog/designware_wdt.c | 4 ++++ 1 file changed, 4 insertions(+)
PATCH 5/7 wdt: dw: Free the clock on error
In reply to Sean AndersonThe clock subsystem requires that clk_free be called on clocks obtained via clk_get_*.
---
drivers/watchdog/designware_wdt.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/watchdog/designware_wdt.c +12 -5
@@ -131,11 +131,13 @@ static int designware_wdt_probe(struct udevice *dev) ret =clk_enable (&clk);if (ret) -return ret; + goto err; priv->clk_khz =clk_get_rate (&clk) /1000 ; -if (!priv->clk_khz) -return -EINVAL ; +if (!priv->clk_khz) { + ret = -EINVAL ; + goto err; + }#else priv->clk_khz =CONFIG_DW_WDT_CLOCK_KHZ ;#endif
@@ -145,15 +147,20 @@ static int designware_wdt_probe(struct udevice *dev) ret =reset_get_bulk (dev, &resets);if (ret) -return ret; + goto err; ret =reset_deassert_bulk (&resets);if (ret) -return ret; + goto err; }/* reset to disable the watchdog */ return designware_wdt_stop (dev); + +err: +if (CONFIG_IS_ENABLED (CLK )) +clk_free (&clk); +return ret; }static const struct wdt_ops designware_wdt_ops = {
Signature · 1 line
2.27.0
PATCH 5/7 wdt: dw: Free the clock on error
Quoted 10 lines · Sean Anderson
The clock subsystem requires that
clk_freebe called on clocks obtained via clk_get_*.Signed-off-by Sean Anderson <[email protected]>---
drivers/watchdog/designware_wdt.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
PATCH 6/7 riscv: Add watchdog bindings for the k210
In reply to Sean AndersonThis adds the necessary bindings. Most of them are already there.
---
arch/riscv/dts/k210-maix-bit.dts | 4 ++++ 1 file changed, 4 insertions(+)
arch/riscv/dts/k210-maix-bit.dts +4 -0
@@ -45,3 +45,7 @@ &i2s0 { #sound-dai-cells = <1>; }; + +&wdt0 { + status = "okay"; +};
Signature · 1 line
2.27.0
PATCH 7/7 riscv: Enable watchdog for the k210
In reply to Sean AndersonThis enables the necessary config options.
---
board/sipeed/maix/Kconfig | 2 ++ 1 file changed, 2 insertions(+)
board/sipeed/maix/Kconfig +2 -0
@@ -44,4 +44,6 @@ config BOARD_SPECIFIC_OPTIONS imply RESET_SYSCON imply SYSRESET imply SYSRESET_SYSCON + imply WDT + imply DESIGNWARE_WATCHDOG endif
Signature · 1 line
2.27.0
PATCH 1/7 wdt: dw: Switch to using fls for log2
In reply to Sean AndersonQuoted 22 lines · Sean Anderson
log_2_n_round_upis only found in arm. fls performs the same job and is generic.Signed-off-by Sean Anderson <[email protected]>---
drivers/watchdog/designware_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/watchdog/designware_wdt.c +0
-1@@ -9,7 +9,6 @@#include <reset.h> #include <wdt.h> #include <asm/io.h> -#include <asm/utils.h> #include <linux/bitops.h> #define DW_WDT_CR 0x00
drivers/watchdog/designware_wdt.c static int designware_wdt_settimeout(void __iomem *base, unsigned int clk_khz, · line 37
Quoted 5 lines
drivers/watchdog/designware_wdt.c +1
-1@@ -35,7 +34,7 @@ static int designware_wdt_settimeout(void __iomem *base, unsigned int clk_khz,signed int i;/* calculate the timeout range value */ - i =log_2_n_round_up (timeout * clk_khz) -16 ; + i =fls (timeout * clk_khz) -16 ;
The two functions create different results:
generic_fls(15) = 4, log_2_n_round_up(15) = 4generic_fls(16) = 5, log_2_n_round_up(16) = 4generic_fls(17) = 5, log_2_n_round_up(17) = 5
Please, describe the effect of your change in the commit message.
Best regards
Heinrich
Quoted 4 lines
drivers/watchdog/designware_wdt.c +0
-0i =clamp (i,0 ,15 );writel (i | (i <<4 ), base +DW_WDT_TORR );
PATCH 1/7 wdt: dw: Switch to using fls for log2
Quoted 31 lines · Heinrich Schuchardt
Quoted 22 lines · Sean Anderson
log_2_n_round_upis only found in arm. fls performs the same job and is generic.Signed-off-by Sean Anderson <[email protected]>---
drivers/watchdog/designware_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/watchdog/designware_wdt.c +0
-1@@ -9,7 +9,6 @@#include <reset.h> #include <wdt.h> #include <asm/io.h> -#include <asm/utils.h> #include <linux/bitops.h> #define DW_WDT_CR 0x00drivers/watchdog/designware_wdt.c static int designware_wdt_settimeout(void __iomem *base, unsigned int clk_khz, · line 37
Quoted 5 lines
drivers/watchdog/designware_wdt.c +1
-1@@ -35,7 +34,7 @@ static int designware_wdt_settimeout(void __iomem *base, unsigned int clk_khz,signed int i;/* calculate the timeout range value */ - i =log_2_n_round_up (timeout * clk_khz) -16 ; + i =fls (timeout * clk_khz) -16 ;The two functions create different results:
Quoted 5 lines
generic_fls(15)= 4,log_2_n_round_up(15)= 4generic_fls(16)= 5,log_2_n_round_up(16)= 4generic_fls(17)= 5,log_2_n_round_up(17)= 5Please, describe the effect of your change in the commit message.
Hm, then perhaps this should be
i = fls(timeout * clk_khz - 1) - 16;
--Sean