Skip to content

Commit

Permalink
watchdog: orion_wdt: take timeout value in ms
Browse files Browse the repository at this point in the history
The generic wdt_start API expects to be called with the timeout in
milliseconds. Update the orion_wdt driver to accept a timeout in
milliseconds and use the clock rate specified in the dts to convert the
timeout to an appropriate value for the timer reload register.

Signed-off-by: Chris Packham <[email protected]>
Reviewed-by: Stefan Roese <[email protected]>
Signed-off-by: Stefan Roese <[email protected]>
  • Loading branch information
cpackham authored and stroese committed Apr 12, 2019
1 parent 8562e41 commit 8e427ba
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion board/CZ.NIC/turris_omnia/turris_omnia.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ int board_init(void)
puts("Cannot find Armada 385 watchdog!\n");
} else {
puts("Enabling Armada 385 watchdog.\n");
wdt_start(watchdog_dev, (u32) 25000000 * 120, 0);
wdt_start(watchdog_dev, 120000, 0);
}
# endif

Expand Down
1 change: 1 addition & 0 deletions drivers/watchdog/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ config WDT_BCM6345
config WDT_ORION
bool "Orion watchdog timer support"
depends on WDT
select CLK
help
Select this to enable Orion watchdog timer, which can be found on some
Marvell Armada chips.
Expand Down
23 changes: 19 additions & 4 deletions drivers/watchdog/orion_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#include <common.h>
#include <dm.h>
#include <clk.h>
#include <wdt.h>
#include <linux/kernel.h>
#include <asm/io.h>
#include <asm/arch/cpu.h>
#include <asm/arch/soc.h>
Expand All @@ -27,6 +29,8 @@ struct orion_wdt_priv {
void __iomem *rstout;
void __iomem *rstout_mask;
u32 timeout;
unsigned long clk_rate;
struct clk clk;
};

#define RSTOUT_ENABLE_BIT BIT(8)
Expand All @@ -44,25 +48,27 @@ static int orion_wdt_reset(struct udevice *dev)
struct orion_wdt_priv *priv = dev_get_priv(dev);

/* Reload watchdog duration */
writel(priv->timeout, priv->reg + priv->wdt_counter_offset);
writel(priv->clk_rate * priv->timeout,
priv->reg + priv->wdt_counter_offset);

return 0;
}

static int orion_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
static int orion_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
{
struct orion_wdt_priv *priv = dev_get_priv(dev);
u32 reg;

priv->timeout = (u32) timeout;
priv->timeout = DIV_ROUND_UP(timeout_ms, 1000);

/* Enable the fixed watchdog clock input */
reg = readl(priv->reg + TIMER_CTRL);
reg |= WDT_AXP_FIXED_ENABLE_BIT;
writel(reg, priv->reg + TIMER_CTRL);

/* Set watchdog duration */
writel(priv->timeout, priv->reg + priv->wdt_counter_offset);
writel(priv->clk_rate * priv->timeout,
priv->reg + priv->wdt_counter_offset);

/* Clear the watchdog expiration bit */
reg = readl(priv->reg + TIMER_A370_STATUS);
Expand Down Expand Up @@ -147,9 +153,18 @@ static int orion_wdt_ofdata_to_platdata(struct udevice *dev)

static int orion_wdt_probe(struct udevice *dev)
{
struct orion_wdt_priv *priv = dev_get_priv(dev);
int ret;

debug("%s: Probing wdt%u\n", __func__, dev->seq);
orion_wdt_stop(dev);

ret = clk_get_by_name(dev, "fixed", &priv->clk);
if (!ret)
priv->clk_rate = clk_get_rate(&priv->clk);
else
priv->clk_rate = 25000000;

return 0;
}

Expand Down

0 comments on commit 8e427ba

Please sign in to comment.