Skip to content

Commit af084fd

Browse files
neuschaeferWim Van Sebroeck
authored andcommitted
watchdog: npcm: Enable clock if provided
On the Nuvoton WPCM450 SoC, with its upcoming clock driver, peripheral clocks are individually gated and ungated. Therefore, the watchdog driver must be able to ungate the watchdog clock. Signed-off-by: Jonathan Neuschäfer <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent 6adbfba commit af084fd

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/watchdog/npcm_wdt.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Copyright (c) 2018 IBM Corp.
44

55
#include <linux/bitops.h>
6+
#include <linux/clk.h>
67
#include <linux/delay.h>
78
#include <linux/interrupt.h>
89
#include <linux/kernel.h>
@@ -43,6 +44,7 @@
4344
struct npcm_wdt {
4445
struct watchdog_device wdd;
4546
void __iomem *reg;
47+
struct clk *clk;
4648
};
4749

4850
static inline struct npcm_wdt *to_npcm_wdt(struct watchdog_device *wdd)
@@ -66,6 +68,9 @@ static int npcm_wdt_start(struct watchdog_device *wdd)
6668
struct npcm_wdt *wdt = to_npcm_wdt(wdd);
6769
u32 val;
6870

71+
if (wdt->clk)
72+
clk_prepare_enable(wdt->clk);
73+
6974
if (wdd->timeout < 2)
7075
val = 0x800;
7176
else if (wdd->timeout < 3)
@@ -100,6 +105,9 @@ static int npcm_wdt_stop(struct watchdog_device *wdd)
100105

101106
writel(0, wdt->reg);
102107

108+
if (wdt->clk)
109+
clk_disable_unprepare(wdt->clk);
110+
103111
return 0;
104112
}
105113

@@ -147,6 +155,10 @@ static int npcm_wdt_restart(struct watchdog_device *wdd,
147155
{
148156
struct npcm_wdt *wdt = to_npcm_wdt(wdd);
149157

158+
/* For reset, we start the WDT clock and leave it running. */
159+
if (wdt->clk)
160+
clk_prepare_enable(wdt->clk);
161+
150162
writel(NPCM_WTR | NPCM_WTRE | NPCM_WTE, wdt->reg);
151163
udelay(1000);
152164

@@ -191,6 +203,10 @@ static int npcm_wdt_probe(struct platform_device *pdev)
191203
if (IS_ERR(wdt->reg))
192204
return PTR_ERR(wdt->reg);
193205

206+
wdt->clk = devm_clk_get_optional(&pdev->dev, NULL);
207+
if (IS_ERR(wdt->clk))
208+
return PTR_ERR(wdt->clk);
209+
194210
irq = platform_get_irq(pdev, 0);
195211
if (irq < 0)
196212
return irq;

0 commit comments

Comments
 (0)