3
3
// Copyright (c) 2018 IBM Corp.
4
4
5
5
#include <linux/bitops.h>
6
+ #include <linux/clk.h>
6
7
#include <linux/delay.h>
7
8
#include <linux/interrupt.h>
8
9
#include <linux/kernel.h>
43
44
struct npcm_wdt {
44
45
struct watchdog_device wdd ;
45
46
void __iomem * reg ;
47
+ struct clk * clk ;
46
48
};
47
49
48
50
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)
66
68
struct npcm_wdt * wdt = to_npcm_wdt (wdd );
67
69
u32 val ;
68
70
71
+ if (wdt -> clk )
72
+ clk_prepare_enable (wdt -> clk );
73
+
69
74
if (wdd -> timeout < 2 )
70
75
val = 0x800 ;
71
76
else if (wdd -> timeout < 3 )
@@ -100,6 +105,9 @@ static int npcm_wdt_stop(struct watchdog_device *wdd)
100
105
101
106
writel (0 , wdt -> reg );
102
107
108
+ if (wdt -> clk )
109
+ clk_disable_unprepare (wdt -> clk );
110
+
103
111
return 0 ;
104
112
}
105
113
@@ -147,6 +155,10 @@ static int npcm_wdt_restart(struct watchdog_device *wdd,
147
155
{
148
156
struct npcm_wdt * wdt = to_npcm_wdt (wdd );
149
157
158
+ /* For reset, we start the WDT clock and leave it running. */
159
+ if (wdt -> clk )
160
+ clk_prepare_enable (wdt -> clk );
161
+
150
162
writel (NPCM_WTR | NPCM_WTRE | NPCM_WTE , wdt -> reg );
151
163
udelay (1000 );
152
164
@@ -191,6 +203,10 @@ static int npcm_wdt_probe(struct platform_device *pdev)
191
203
if (IS_ERR (wdt -> reg ))
192
204
return PTR_ERR (wdt -> reg );
193
205
206
+ wdt -> clk = devm_clk_get_optional (& pdev -> dev , NULL );
207
+ if (IS_ERR (wdt -> clk ))
208
+ return PTR_ERR (wdt -> clk );
209
+
194
210
irq = platform_get_irq (pdev , 0 );
195
211
if (irq < 0 )
196
212
return irq ;
0 commit comments