From: Melin Tomas <tomas.melin@vaisala.com>
To: "wim@linux-watchdog.org" <wim@linux-watchdog.org>,
"linux@roeck-us.net" <linux@roeck-us.net>
Cc: "linux-watchdog@vger.kernel.org" <linux-watchdog@vger.kernel.org>,
Melin Tomas <tomas.melin@vaisala.com>
Subject: [PATCH v2 4/4] watchdog: cadence_wdt: Support all available prescaler values
Date: Fri, 5 Jul 2019 11:46:04 +0000 [thread overview]
Message-ID: <20190705114522.42565-5-tomas.melin@vaisala.com> (raw)
In-Reply-To: <20190705114522.42565-1-tomas.melin@vaisala.com>
Cadence watchdog HW supports prescaler values of
8, 64, 512 and 4096.
Add support to select prescaler values of 8 and 64 for lower
input clock frequencies.
Prescaler value is selected to keep timeout resolution of 1 second.
For clock frequencies below 32kHz, 1 second resolution does
no longer hold, thereby returning an error.
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
---
drivers/watchdog/cadence_wdt.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/watchdog/cadence_wdt.c b/drivers/watchdog/cadence_wdt.c
index 4657800d9d8e..39109b5721c1 100644
--- a/drivers/watchdog/cadence_wdt.c
+++ b/drivers/watchdog/cadence_wdt.c
@@ -33,16 +33,17 @@
#define CDNS_WDT_COUNTER_VALUE_DIVISOR 0x1000
/* Clock prescaler value and selection */
+#define CDNS_WDT_PRESCALE_8 8
#define CDNS_WDT_PRESCALE_64 64
#define CDNS_WDT_PRESCALE_512 512
#define CDNS_WDT_PRESCALE_4096 4096
+#define CDNS_WDT_PRESCALE_SELECT_8 0
#define CDNS_WDT_PRESCALE_SELECT_64 1
#define CDNS_WDT_PRESCALE_SELECT_512 2
#define CDNS_WDT_PRESCALE_SELECT_4096 3
-/* Input clock frequency */
-#define CDNS_WDT_CLK_10MHZ 10000000
-#define CDNS_WDT_CLK_75MHZ 75000000
+/* Base input clock frequency */
+#define CDNS_WDT_CLK_32KHZ 32768
/* Counter maximum value */
#define CDNS_WDT_COUNTER_MAX 0xFFF
@@ -304,7 +305,16 @@ static int cdns_wdt_probe(struct platform_device *pdev)
}
clock_f = clk_get_rate(wdt->clk);
- if (clock_f <= CDNS_WDT_CLK_75MHZ) {
+ if (clock_f < CDNS_WDT_CLK_32KHZ) {
+ dev_err(&pdev->dev, "cannot find suitable clock prescaler\n");
+ return -ERANGE;
+ } else if (clock_f <= CDNS_WDT_CLK_32KHZ * CDNS_WDT_PRESCALE_8) {
+ wdt->prescaler = CDNS_WDT_PRESCALE_8;
+ wdt->ctrl_clksel = CDNS_WDT_PRESCALE_SELECT_8;
+ } else if (clock_f <= CDNS_WDT_CLK_32KHZ * CDNS_WDT_PRESCALE_64) {
+ wdt->prescaler = CDNS_WDT_PRESCALE_64;
+ wdt->ctrl_clksel = CDNS_WDT_PRESCALE_SELECT_64;
+ } else if (clock_f <= CDNS_WDT_CLK_32KHZ * CDNS_WDT_PRESCALE_512) {
wdt->prescaler = CDNS_WDT_PRESCALE_512;
wdt->ctrl_clksel = CDNS_WDT_PRESCALE_SELECT_512;
} else {
--
2.17.2
next prev parent reply other threads:[~2019-07-05 11:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-05 11:46 [PATCH v2 0/4] watchdog: cadence_wdt: Support all available prescaler values Melin Tomas
2019-07-05 11:46 ` [PATCH v2 1/4] watchdog: cadence_wdt: Move clock detection eariler in probe Melin Tomas
2019-07-08 18:03 ` Guenter Roeck
2019-07-05 11:46 ` [PATCH v2 2/4] watchdog: cadence_wdt: Calculate actual timeout limits Melin Tomas
2019-07-08 18:06 ` Guenter Roeck
2019-07-05 11:46 ` [PATCH v2 3/4] watchdog: cadence_wdt: Group struct member init statements Melin Tomas
2019-07-08 18:09 ` Guenter Roeck
2019-07-05 11:46 ` Melin Tomas [this message]
2019-07-08 18:14 ` [PATCH v2 4/4] watchdog: cadence_wdt: Support all available prescaler values Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190705114522.42565-5-tomas.melin@vaisala.com \
--to=tomas.melin@vaisala.com \
--cc=linux-watchdog@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=wim@linux-watchdog.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).