Message ID | 20190705114522.42565-3-tomas.melin@vaisala.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | watchdog: cadence_wdt: Support all available prescaler values | expand |
On Fri, Jul 05, 2019 at 11:46:02AM +0000, Melin Tomas wrote: > Maximum and minimum timeout values depend on the actual input clock > frequency and prescaler selection. > > Signed-off-by: Tomas Melin <tomas.melin@vaisala.com> > --- > drivers/watchdog/cadence_wdt.c | 13 ++++++++----- > 1 file changed, 8 insertions(+), 5 deletions(-) > > diff --git a/drivers/watchdog/cadence_wdt.c b/drivers/watchdog/cadence_wdt.c > index 415bd6dd1edb..87b767c87bb6 100644 > --- a/drivers/watchdog/cadence_wdt.c > +++ b/drivers/watchdog/cadence_wdt.c > @@ -18,9 +18,6 @@ > #include <linux/watchdog.h> > > #define CDNS_WDT_DEFAULT_TIMEOUT 10 > -/* Supports 1 - 516 sec */ > -#define CDNS_WDT_MIN_TIMEOUT 1 > -#define CDNS_WDT_MAX_TIMEOUT 516 > > /* Restart key */ > #define CDNS_WDT_RESTART_KEY 0x00001999 > @@ -28,6 +25,10 @@ > /* Counter register access key */ > #define CDNS_WDT_REGISTER_ACCESS_KEY 0x00920000 > > +/* Counter control register, counter restart values */ > +#define CDNS_WDT_CCR_CRV_MIN 0xFFF > +#define CDNS_WDT_CCR_CRV_MAX 0xFFFFFF > + > /* Counter value divisor */ > #define CDNS_WDT_COUNTER_VALUE_DIVISOR 0x1000 > > @@ -315,8 +316,10 @@ static int cdns_wdt_probe(struct platform_device *pdev) > cdns_wdt_device->info = &cdns_wdt_info; > cdns_wdt_device->ops = &cdns_wdt_ops; > cdns_wdt_device->timeout = CDNS_WDT_DEFAULT_TIMEOUT; > - cdns_wdt_device->min_timeout = CDNS_WDT_MIN_TIMEOUT; > - cdns_wdt_device->max_timeout = CDNS_WDT_MAX_TIMEOUT; > + cdns_wdt_device->min_timeout = > + CDNS_WDT_CCR_CRV_MIN * wdt->prescaler / clock_f; > + cdns_wdt_device->max_timeout = > + CDNS_WDT_CCR_CRV_MAX * wdt->prescaler / clock_f; clock_f can at least in theory be 0. So far that didn't matter as much, but now it would crash the kernel. Please add a respective check into the code. > > res = platform_get_resource(pdev, IORESOURCE_MEM, 0); > wdt->regs = devm_ioremap_resource(&pdev->dev, res);
diff --git a/drivers/watchdog/cadence_wdt.c b/drivers/watchdog/cadence_wdt.c index 415bd6dd1edb..87b767c87bb6 100644 --- a/drivers/watchdog/cadence_wdt.c +++ b/drivers/watchdog/cadence_wdt.c @@ -18,9 +18,6 @@ #include <linux/watchdog.h> #define CDNS_WDT_DEFAULT_TIMEOUT 10 -/* Supports 1 - 516 sec */ -#define CDNS_WDT_MIN_TIMEOUT 1 -#define CDNS_WDT_MAX_TIMEOUT 516 /* Restart key */ #define CDNS_WDT_RESTART_KEY 0x00001999 @@ -28,6 +25,10 @@ /* Counter register access key */ #define CDNS_WDT_REGISTER_ACCESS_KEY 0x00920000 +/* Counter control register, counter restart values */ +#define CDNS_WDT_CCR_CRV_MIN 0xFFF +#define CDNS_WDT_CCR_CRV_MAX 0xFFFFFF + /* Counter value divisor */ #define CDNS_WDT_COUNTER_VALUE_DIVISOR 0x1000 @@ -315,8 +316,10 @@ static int cdns_wdt_probe(struct platform_device *pdev) cdns_wdt_device->info = &cdns_wdt_info; cdns_wdt_device->ops = &cdns_wdt_ops; cdns_wdt_device->timeout = CDNS_WDT_DEFAULT_TIMEOUT; - cdns_wdt_device->min_timeout = CDNS_WDT_MIN_TIMEOUT; - cdns_wdt_device->max_timeout = CDNS_WDT_MAX_TIMEOUT; + cdns_wdt_device->min_timeout = + CDNS_WDT_CCR_CRV_MIN * wdt->prescaler / clock_f; + cdns_wdt_device->max_timeout = + CDNS_WDT_CCR_CRV_MAX * wdt->prescaler / clock_f; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); wdt->regs = devm_ioremap_resource(&pdev->dev, res);
Maximum and minimum timeout values depend on the actual input clock frequency and prescaler selection. Signed-off-by: Tomas Melin <tomas.melin@vaisala.com> --- drivers/watchdog/cadence_wdt.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)