Message ID | 20200805191414.146609-1-seanga2@gmail.com |
---|---|
State | Superseded |
Delegated to: | Andes |
Headers | show |
Series | [1/7] wdt: dw: Switch to using fls for log2 | expand |
On 8/5/20 9:14 PM, Sean Anderson wrote: > log_2_n_round_up is only found in arm. fls performs the same job and is > generic. > > Signed-off-by: Sean Anderson <seanga2@gmail.com> > --- > > drivers/watchdog/designware_wdt.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c > index 12f09a7a39..5684acefd2 100644 > --- a/drivers/watchdog/designware_wdt.c > +++ b/drivers/watchdog/designware_wdt.c > @@ -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; The two functions create different results: generic_fls(15) = 4, log_2_n_round_up(15) = 4 generic_fls(16) = 5, log_2_n_round_up(16) = 4 generic_fls(17) = 5, log_2_n_round_up(17) = 5 Please, describe the effect of your change in the commit message. Best regards Heinrich > i = clamp(i, 0, 15); > > writel(i | (i << 4), base + DW_WDT_TORR); >
On 8/5/20 5:06 PM, Heinrich Schuchardt wrote: > On 8/5/20 9:14 PM, Sean Anderson wrote: >> log_2_n_round_up is only found in arm. fls performs the same job and is >> generic. >> >> Signed-off-by: Sean Anderson <seanga2@gmail.com> >> --- >> >> drivers/watchdog/designware_wdt.c | 3 +-- >> 1 file changed, 1 insertion(+), 2 deletions(-) >> >> diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c >> index 12f09a7a39..5684acefd2 100644 >> --- a/drivers/watchdog/designware_wdt.c >> +++ b/drivers/watchdog/designware_wdt.c >> @@ -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; > > The two functions create different results: > > generic_fls(15) = 4, log_2_n_round_up(15) = 4 > generic_fls(16) = 5, log_2_n_round_up(16) = 4 > generic_fls(17) = 5, log_2_n_round_up(17) = 5 > > Please, describe the effect of your change in the commit message. Hm, then perhaps this should be i = fls(timeout * clk_khz - 1) - 16; --Sean
diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c index 12f09a7a39..5684acefd2 100644 --- a/drivers/watchdog/designware_wdt.c +++ b/drivers/watchdog/designware_wdt.c @@ -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);
log_2_n_round_up is only found in arm. fls performs the same job and is generic. Signed-off-by: Sean Anderson <seanga2@gmail.com> --- drivers/watchdog/designware_wdt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)