public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 3/4] wdt: Remove dependencies on CONFIG_DW_WDT_* from Designware WDT
Date: Sun, 2 Feb 2020 12:12:57 -0500	[thread overview]
Message-ID: <36ff56bf-2cfa-2a1e-74c7-9c7111115780@gmail.com> (raw)
In-Reply-To: <9b2bb704-e7ea-74ea-c854-60a44472b8ec@gmail.com>

Currently, the designware watchdog driver depends in several places on the
values of CONFIG_DW_WDT_ defines. This patch moves these uses to just the
functions hw_watchdog_*.
---
 drivers/watchdog/designware_wdt.c | 65 ++++++++++++++++++++-----------
 1 file changed, 42 insertions(+), 23 deletions(-)

diff --git a/drivers/watchdog/designware_wdt.c b/drivers/watchdog/designware_wdt.c
index 3b97db1256..61c4046f50 100644
--- a/drivers/watchdog/designware_wdt.c
+++ b/drivers/watchdog/designware_wdt.c
@@ -17,57 +17,76 @@
 #define DW_WDT_CR_RMOD_VAL	0x00
 #define DW_WDT_CRR_RESTART_VAL	0x76
 
+struct designware_wdt_priv {
+	void __iomem *base;
+	ulong clock_khz;
+};
+
 /*
  * Set the watchdog time interval.
  * Counter is 32 bit.
  */
-static int designware_wdt_settimeout(unsigned int timeout)
+static int designware_wdt_settimeout(struct designware_wdt_priv *priv,
+				     u64 timeout)
 {
 	signed int i;
 
 	/* calculate the timeout range value */
-	i = (log_2_n_round_up(timeout * CONFIG_DW_WDT_CLOCK_KHZ)) - 16;
+	i = log_2_n_round_up(timeout * priv->clock_khz) - 16;
 	if (i > 15)
 		i = 15;
 	if (i < 0)
 		i = 0;
 
-	writel((i | (i << 4)), (CONFIG_DW_WDT_BASE + DW_WDT_TORR));
+	writel(i | (i << 4), priv->base + DW_WDT_TORR);
 	return 0;
 }
 
-static void designware_wdt_enable(void)
+static void designware_wdt_enable(struct designware_wdt_priv *priv)
 {
-	writel(((DW_WDT_CR_RMOD_VAL << DW_WDT_CR_RMOD_OFFSET) |
-	      (0x1 << DW_WDT_CR_EN_OFFSET)),
-	      (CONFIG_DW_WDT_BASE + DW_WDT_CR));
+	writel((DW_WDT_CR_RMOD_VAL << DW_WDT_CR_RMOD_OFFSET) |
+	       (0x1 << DW_WDT_CR_EN_OFFSET), priv->base + DW_WDT_CR);
 }
 
-static unsigned int designware_wdt_is_enabled(void)
+static unsigned int designware_wdt_is_enabled(struct designware_wdt_priv *priv)
 {
 	unsigned long val;
-	val = readl((CONFIG_DW_WDT_BASE + DW_WDT_CR));
-	return val & 0x1;
+	val = readl(priv->base + DW_WDT_CR);
+	return val & 1;
 }
 
-#if defined(CONFIG_HW_WATCHDOG)
+static void designware_wdt_reset(struct designware_wdt_priv *priv)
+{
+	if (designware_wdt_is_enabled(priv))
+		writel(DW_WDT_CRR_RESTART_VAL, priv->base + DW_WDT_CRR);
+}
+
+static void designware_wdt_init(struct designware_wdt_priv *priv, u64 timeout)
+{
+	/* reset to disable the watchdog */
+	designware_wdt_reset(priv);
+	/* set timer in miliseconds */
+	designware_wdt_settimeout(priv, timeout);
+	designware_wdt_enable(priv);
+	designware_wdt_reset(priv);
+}
+
+#ifdef CONFIG_HW_WATCHDOG
+static struct designware_wdt_priv wdt_priv = {
+	.base = CONFIG_DW_WDT_BASE,
+};
+
 void hw_watchdog_reset(void)
 {
-	if (designware_wdt_is_enabled())
-		/* restart the watchdog counter */
-		writel(DW_WDT_CRR_RESTART_VAL,
-		       (CONFIG_DW_WDT_BASE + DW_WDT_CRR));
+	/* XXX: may contain a function call; must be done at runtime */
+	wdt_priv.clock_khz = CONFIG_DW_WDT_CLOCK_KHZ;
+	designware_wdt_reset(&wdt_priv);
 }
 
 void hw_watchdog_init(void)
 {
-	/* reset to disable the watchdog */
-	hw_watchdog_reset();
-	/* set timer in miliseconds */
-	designware_wdt_settimeout(CONFIG_WATCHDOG_TIMEOUT_MSECS);
-	/* enable the watchdog */
-	designware_wdt_enable();
-	/* reset the watchdog */
-	hw_watchdog_reset();
+	/* XXX: see above */
+	wdt_priv.clock_khz = CONFIG_DW_WDT_CLOCK_KHZ;
+	designware_wdt_init(&wdt_priv, CONFIG_WATCHDOG_TIMEOUT_MSECS);
 }
 #endif
-- 
2.25.0

  parent reply	other threads:[~2020-02-02 17:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-02 17:10 [PATCH 1/4] wdt: Add CONFIG_DESIGNWARE_WATCHDOG to Kconfig Sean Anderson
2020-02-02 17:12 ` [PATCH 2/4] arm: Move asm/utils.h to log2.h Sean Anderson
2020-02-02 17:24   ` Sean Anderson
2020-02-03  0:04   ` Simon Glass
2020-02-03  8:12     ` Marek Vasut
2020-02-03 15:11       ` Simon Glass
2020-02-03 15:27         ` Sean Anderson
2020-02-03 15:31           ` Simon Glass
2020-02-02 17:12 ` Sean Anderson [this message]
2020-02-02 17:25   ` [PATCH 3/4] wdt: Remove dependencies on CONFIG_DW_WDT_* from Designware WDT Sean Anderson
2020-02-02 17:13 ` [PATCH 4/4] wdt: Add DM support for " Sean Anderson
2020-02-02 17:25   ` Sean Anderson
2020-02-03  0:04     ` Simon Glass
2020-02-03  1:18       ` Sean Anderson
2020-02-03  4:03         ` Simon Glass
2020-02-02 17:15 ` [PATCH 1/4] wdt: Add CONFIG_DESIGNWARE_WATCHDOG to Kconfig Marek Vasut
2020-02-02 17:23   ` Sean Anderson
2020-02-02 17:40     ` Marek Vasut
2020-02-02 17:48       ` Sean Anderson
2020-02-02 17:52         ` Marek Vasut
2020-02-02 18:02           ` Sean Anderson
2020-02-03  8:13             ` Marek Vasut
2020-02-19 21:37               ` Sean Anderson
2020-02-20 16:39                 ` Marek Vasut
2020-02-02 17:24 ` Sean Anderson

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=36ff56bf-2cfa-2a1e-74c7-9c7111115780@gmail.com \
    --to=seanga2@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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