1 /* linux/drivers/char/watchdog/s3c2410_wdt.c
3 * Copyright (c) 2004 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * S3C2410 Watchdog Timer Support
8 * Based on, softdog.c by Alan Cox,
9 * (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/types.h>
29 #include <linux/timer.h>
30 #include <linux/watchdog.h>
31 #include <linux/platform_device.h>
32 #include <linux/interrupt.h>
33 #include <linux/clk.h>
34 #include <linux/uaccess.h>
36 #include <linux/cpufreq.h>
37 #include <linux/slab.h>
38 #include <linux/err.h>
40 #include <linux/mfd/syscon.h>
41 #include <linux/regmap.h>
42 #include <linux/delay.h>
44 #define S3C2410_WTCON 0x00
45 #define S3C2410_WTDAT 0x04
46 #define S3C2410_WTCNT 0x08
47 #define S3C2410_WTCLRINT 0x0c
49 #define S3C2410_WTCNT_MAXCNT 0xffff
51 #define S3C2410_WTCON_RSTEN (1 << 0)
52 #define S3C2410_WTCON_INTEN (1 << 2)
53 #define S3C2410_WTCON_ENABLE (1 << 5)
55 #define S3C2410_WTCON_DIV16 (0 << 3)
56 #define S3C2410_WTCON_DIV32 (1 << 3)
57 #define S3C2410_WTCON_DIV64 (2 << 3)
58 #define S3C2410_WTCON_DIV128 (3 << 3)
60 #define S3C2410_WTCON_MAXDIV 0x80
62 #define S3C2410_WTCON_PRESCALE(x) ((x) << 8)
63 #define S3C2410_WTCON_PRESCALE_MASK (0xff << 8)
64 #define S3C2410_WTCON_PRESCALE_MAX 0xff
66 #define S3C2410_WATCHDOG_ATBOOT (0)
67 #define S3C2410_WATCHDOG_DEFAULT_TIME (15)
69 #define EXYNOS5_RST_STAT_REG_OFFSET 0x0404
70 #define EXYNOS5_WDT_DISABLE_REG_OFFSET 0x0408
71 #define EXYNOS5_WDT_MASK_RESET_REG_OFFSET 0x040c
72 #define QUIRK_HAS_PMU_CONFIG (1 << 0)
73 #define QUIRK_HAS_RST_STAT (1 << 1)
74 #define QUIRK_HAS_WTCLRINT_REG (1 << 2)
76 /* These quirks require that we have a PMU register map */
77 #define QUIRKS_HAVE_PMUREG (QUIRK_HAS_PMU_CONFIG | \
80 static bool nowayout
= WATCHDOG_NOWAYOUT
;
81 static int tmr_margin
;
82 static int tmr_atboot
= S3C2410_WATCHDOG_ATBOOT
;
83 static int soft_noboot
;
85 module_param(tmr_margin
, int, 0);
86 module_param(tmr_atboot
, int, 0);
87 module_param(nowayout
, bool, 0);
88 module_param(soft_noboot
, int, 0);
90 MODULE_PARM_DESC(tmr_margin
, "Watchdog tmr_margin in seconds. (default="
91 __MODULE_STRING(S3C2410_WATCHDOG_DEFAULT_TIME
) ")");
92 MODULE_PARM_DESC(tmr_atboot
,
93 "Watchdog is started at boot time if set to 1, default="
94 __MODULE_STRING(S3C2410_WATCHDOG_ATBOOT
));
95 MODULE_PARM_DESC(nowayout
, "Watchdog cannot be stopped once started (default="
96 __MODULE_STRING(WATCHDOG_NOWAYOUT
) ")");
97 MODULE_PARM_DESC(soft_noboot
, "Watchdog action, set to 1 to ignore reboots, "
98 "0 to reboot (default 0)");
101 * struct s3c2410_wdt_variant - Per-variant config data
103 * @disable_reg: Offset in pmureg for the register that disables the watchdog
104 * timer reset functionality.
105 * @mask_reset_reg: Offset in pmureg for the register that masks the watchdog
106 * timer reset functionality.
107 * @mask_bit: Bit number for the watchdog timer in the disable register and the
108 * mask reset register.
109 * @rst_stat_reg: Offset in pmureg for the register that has the reset status.
110 * @rst_stat_bit: Bit number in the rst_stat register indicating a watchdog
112 * @quirks: A bitfield of quirks.
115 struct s3c2410_wdt_variant
{
127 void __iomem
*reg_base
;
130 unsigned long wtcon_save
;
131 unsigned long wtdat_save
;
132 struct watchdog_device wdt_device
;
133 struct notifier_block freq_transition
;
134 struct s3c2410_wdt_variant
*drv_data
;
135 struct regmap
*pmureg
;
138 static const struct s3c2410_wdt_variant drv_data_s3c2410
= {
143 static const struct s3c2410_wdt_variant drv_data_s3c6410
= {
144 .quirks
= QUIRK_HAS_WTCLRINT_REG
,
147 static const struct s3c2410_wdt_variant drv_data_exynos5250
= {
148 .disable_reg
= EXYNOS5_WDT_DISABLE_REG_OFFSET
,
149 .mask_reset_reg
= EXYNOS5_WDT_MASK_RESET_REG_OFFSET
,
151 .rst_stat_reg
= EXYNOS5_RST_STAT_REG_OFFSET
,
153 .quirks
= QUIRK_HAS_PMU_CONFIG
| QUIRK_HAS_RST_STAT \
154 | QUIRK_HAS_WTCLRINT_REG
,
157 static const struct s3c2410_wdt_variant drv_data_exynos5420
= {
158 .disable_reg
= EXYNOS5_WDT_DISABLE_REG_OFFSET
,
159 .mask_reset_reg
= EXYNOS5_WDT_MASK_RESET_REG_OFFSET
,
161 .rst_stat_reg
= EXYNOS5_RST_STAT_REG_OFFSET
,
163 .quirks
= QUIRK_HAS_PMU_CONFIG
| QUIRK_HAS_RST_STAT \
164 | QUIRK_HAS_WTCLRINT_REG
,
167 static const struct s3c2410_wdt_variant drv_data_exynos7
= {
168 .disable_reg
= EXYNOS5_WDT_DISABLE_REG_OFFSET
,
169 .mask_reset_reg
= EXYNOS5_WDT_MASK_RESET_REG_OFFSET
,
171 .rst_stat_reg
= EXYNOS5_RST_STAT_REG_OFFSET
,
172 .rst_stat_bit
= 23, /* A57 WDTRESET */
173 .quirks
= QUIRK_HAS_PMU_CONFIG
| QUIRK_HAS_RST_STAT \
174 | QUIRK_HAS_WTCLRINT_REG
,
177 static const struct of_device_id s3c2410_wdt_match
[] = {
178 { .compatible
= "samsung,s3c2410-wdt",
179 .data
= &drv_data_s3c2410
},
180 { .compatible
= "samsung,s3c6410-wdt",
181 .data
= &drv_data_s3c6410
},
182 { .compatible
= "samsung,exynos5250-wdt",
183 .data
= &drv_data_exynos5250
},
184 { .compatible
= "samsung,exynos5420-wdt",
185 .data
= &drv_data_exynos5420
},
186 { .compatible
= "samsung,exynos7-wdt",
187 .data
= &drv_data_exynos7
},
190 MODULE_DEVICE_TABLE(of
, s3c2410_wdt_match
);
193 static const struct platform_device_id s3c2410_wdt_ids
[] = {
195 .name
= "s3c2410-wdt",
196 .driver_data
= (unsigned long)&drv_data_s3c2410
,
200 MODULE_DEVICE_TABLE(platform
, s3c2410_wdt_ids
);
204 static inline unsigned int s3c2410wdt_max_timeout(struct clk
*clock
)
206 unsigned long freq
= clk_get_rate(clock
);
208 return S3C2410_WTCNT_MAXCNT
/ (freq
/ (S3C2410_WTCON_PRESCALE_MAX
+ 1)
209 / S3C2410_WTCON_MAXDIV
);
212 static inline struct s3c2410_wdt
*freq_to_wdt(struct notifier_block
*nb
)
214 return container_of(nb
, struct s3c2410_wdt
, freq_transition
);
217 static int s3c2410wdt_mask_and_disable_reset(struct s3c2410_wdt
*wdt
, bool mask
)
220 u32 mask_val
= 1 << wdt
->drv_data
->mask_bit
;
223 /* No need to do anything if no PMU CONFIG needed */
224 if (!(wdt
->drv_data
->quirks
& QUIRK_HAS_PMU_CONFIG
))
230 ret
= regmap_update_bits(wdt
->pmureg
,
231 wdt
->drv_data
->disable_reg
,
236 ret
= regmap_update_bits(wdt
->pmureg
,
237 wdt
->drv_data
->mask_reset_reg
,
241 dev_err(wdt
->dev
, "failed to update reg(%d)\n", ret
);
246 static int s3c2410wdt_keepalive(struct watchdog_device
*wdd
)
248 struct s3c2410_wdt
*wdt
= watchdog_get_drvdata(wdd
);
250 spin_lock(&wdt
->lock
);
251 writel(wdt
->count
, wdt
->reg_base
+ S3C2410_WTCNT
);
252 spin_unlock(&wdt
->lock
);
257 static void __s3c2410wdt_stop(struct s3c2410_wdt
*wdt
)
261 wtcon
= readl(wdt
->reg_base
+ S3C2410_WTCON
);
262 wtcon
&= ~(S3C2410_WTCON_ENABLE
| S3C2410_WTCON_RSTEN
);
263 writel(wtcon
, wdt
->reg_base
+ S3C2410_WTCON
);
266 static int s3c2410wdt_stop(struct watchdog_device
*wdd
)
268 struct s3c2410_wdt
*wdt
= watchdog_get_drvdata(wdd
);
270 spin_lock(&wdt
->lock
);
271 __s3c2410wdt_stop(wdt
);
272 spin_unlock(&wdt
->lock
);
277 static int s3c2410wdt_start(struct watchdog_device
*wdd
)
280 struct s3c2410_wdt
*wdt
= watchdog_get_drvdata(wdd
);
282 spin_lock(&wdt
->lock
);
284 __s3c2410wdt_stop(wdt
);
286 wtcon
= readl(wdt
->reg_base
+ S3C2410_WTCON
);
287 wtcon
|= S3C2410_WTCON_ENABLE
| S3C2410_WTCON_DIV128
;
290 wtcon
|= S3C2410_WTCON_INTEN
;
291 wtcon
&= ~S3C2410_WTCON_RSTEN
;
293 wtcon
&= ~S3C2410_WTCON_INTEN
;
294 wtcon
|= S3C2410_WTCON_RSTEN
;
297 dev_dbg(wdt
->dev
, "Starting watchdog: count=0x%08x, wtcon=%08lx\n",
300 writel(wdt
->count
, wdt
->reg_base
+ S3C2410_WTDAT
);
301 writel(wdt
->count
, wdt
->reg_base
+ S3C2410_WTCNT
);
302 writel(wtcon
, wdt
->reg_base
+ S3C2410_WTCON
);
303 spin_unlock(&wdt
->lock
);
308 static inline int s3c2410wdt_is_running(struct s3c2410_wdt
*wdt
)
310 return readl(wdt
->reg_base
+ S3C2410_WTCON
) & S3C2410_WTCON_ENABLE
;
313 static int s3c2410wdt_set_heartbeat(struct watchdog_device
*wdd
, unsigned timeout
)
315 struct s3c2410_wdt
*wdt
= watchdog_get_drvdata(wdd
);
316 unsigned long freq
= clk_get_rate(wdt
->clock
);
318 unsigned int divisor
= 1;
324 freq
= DIV_ROUND_UP(freq
, 128);
325 count
= timeout
* freq
;
327 dev_dbg(wdt
->dev
, "Heartbeat: count=%d, timeout=%d, freq=%lu\n",
328 count
, timeout
, freq
);
330 /* if the count is bigger than the watchdog register,
331 then work out what we need to do (and if) we can
332 actually make this value
335 if (count
>= 0x10000) {
336 divisor
= DIV_ROUND_UP(count
, 0xffff);
338 if (divisor
> 0x100) {
339 dev_err(wdt
->dev
, "timeout %d too big\n", timeout
);
344 dev_dbg(wdt
->dev
, "Heartbeat: timeout=%d, divisor=%d, count=%d (%08x)\n",
345 timeout
, divisor
, count
, DIV_ROUND_UP(count
, divisor
));
347 count
= DIV_ROUND_UP(count
, divisor
);
350 /* update the pre-scaler */
351 wtcon
= readl(wdt
->reg_base
+ S3C2410_WTCON
);
352 wtcon
&= ~S3C2410_WTCON_PRESCALE_MASK
;
353 wtcon
|= S3C2410_WTCON_PRESCALE(divisor
-1);
355 writel(count
, wdt
->reg_base
+ S3C2410_WTDAT
);
356 writel(wtcon
, wdt
->reg_base
+ S3C2410_WTCON
);
358 wdd
->timeout
= (count
* divisor
) / freq
;
363 static int s3c2410wdt_restart(struct watchdog_device
*wdd
, unsigned long action
,
366 struct s3c2410_wdt
*wdt
= watchdog_get_drvdata(wdd
);
367 void __iomem
*wdt_base
= wdt
->reg_base
;
369 /* disable watchdog, to be safe */
370 writel(0, wdt_base
+ S3C2410_WTCON
);
372 /* put initial values into count and data */
373 writel(0x80, wdt_base
+ S3C2410_WTCNT
);
374 writel(0x80, wdt_base
+ S3C2410_WTDAT
);
376 /* set the watchdog to go and reset... */
377 writel(S3C2410_WTCON_ENABLE
| S3C2410_WTCON_DIV16
|
378 S3C2410_WTCON_RSTEN
| S3C2410_WTCON_PRESCALE(0x20),
379 wdt_base
+ S3C2410_WTCON
);
381 /* wait for reset to assert... */
387 #define OPTIONS (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE)
389 static const struct watchdog_info s3c2410_wdt_ident
= {
391 .firmware_version
= 0,
392 .identity
= "S3C2410 Watchdog",
395 static const struct watchdog_ops s3c2410wdt_ops
= {
396 .owner
= THIS_MODULE
,
397 .start
= s3c2410wdt_start
,
398 .stop
= s3c2410wdt_stop
,
399 .ping
= s3c2410wdt_keepalive
,
400 .set_timeout
= s3c2410wdt_set_heartbeat
,
401 .restart
= s3c2410wdt_restart
,
404 static struct watchdog_device s3c2410_wdd
= {
405 .info
= &s3c2410_wdt_ident
,
406 .ops
= &s3c2410wdt_ops
,
407 .timeout
= S3C2410_WATCHDOG_DEFAULT_TIME
,
410 /* interrupt handler code */
412 static irqreturn_t
s3c2410wdt_irq(int irqno
, void *param
)
414 struct s3c2410_wdt
*wdt
= platform_get_drvdata(param
);
416 dev_info(wdt
->dev
, "watchdog timer expired (irq)\n");
418 s3c2410wdt_keepalive(&wdt
->wdt_device
);
420 if (wdt
->drv_data
->quirks
& QUIRK_HAS_WTCLRINT_REG
)
421 writel(0x1, wdt
->reg_base
+ S3C2410_WTCLRINT
);
426 #ifdef CONFIG_ARM_S3C24XX_CPUFREQ
428 static int s3c2410wdt_cpufreq_transition(struct notifier_block
*nb
,
429 unsigned long val
, void *data
)
432 struct s3c2410_wdt
*wdt
= freq_to_wdt(nb
);
434 if (!s3c2410wdt_is_running(wdt
))
437 if (val
== CPUFREQ_PRECHANGE
) {
438 /* To ensure that over the change we don't cause the
439 * watchdog to trigger, we perform an keep-alive if
440 * the watchdog is running.
443 s3c2410wdt_keepalive(&wdt
->wdt_device
);
444 } else if (val
== CPUFREQ_POSTCHANGE
) {
445 s3c2410wdt_stop(&wdt
->wdt_device
);
447 ret
= s3c2410wdt_set_heartbeat(&wdt
->wdt_device
,
448 wdt
->wdt_device
.timeout
);
451 s3c2410wdt_start(&wdt
->wdt_device
);
460 dev_err(wdt
->dev
, "cannot set new value for timeout %d\n",
461 wdt
->wdt_device
.timeout
);
465 static inline int s3c2410wdt_cpufreq_register(struct s3c2410_wdt
*wdt
)
467 wdt
->freq_transition
.notifier_call
= s3c2410wdt_cpufreq_transition
;
469 return cpufreq_register_notifier(&wdt
->freq_transition
,
470 CPUFREQ_TRANSITION_NOTIFIER
);
473 static inline void s3c2410wdt_cpufreq_deregister(struct s3c2410_wdt
*wdt
)
475 wdt
->freq_transition
.notifier_call
= s3c2410wdt_cpufreq_transition
;
477 cpufreq_unregister_notifier(&wdt
->freq_transition
,
478 CPUFREQ_TRANSITION_NOTIFIER
);
483 static inline int s3c2410wdt_cpufreq_register(struct s3c2410_wdt
*wdt
)
488 static inline void s3c2410wdt_cpufreq_deregister(struct s3c2410_wdt
*wdt
)
493 static inline unsigned int s3c2410wdt_get_bootstatus(struct s3c2410_wdt
*wdt
)
495 unsigned int rst_stat
;
498 if (!(wdt
->drv_data
->quirks
& QUIRK_HAS_RST_STAT
))
501 ret
= regmap_read(wdt
->pmureg
, wdt
->drv_data
->rst_stat_reg
, &rst_stat
);
503 dev_warn(wdt
->dev
, "Couldn't get RST_STAT register\n");
504 else if (rst_stat
& BIT(wdt
->drv_data
->rst_stat_bit
))
505 return WDIOF_CARDRESET
;
510 static inline struct s3c2410_wdt_variant
*
511 s3c2410_get_wdt_drv_data(struct platform_device
*pdev
)
513 if (pdev
->dev
.of_node
) {
514 const struct of_device_id
*match
;
515 match
= of_match_node(s3c2410_wdt_match
, pdev
->dev
.of_node
);
516 return (struct s3c2410_wdt_variant
*)match
->data
;
518 return (struct s3c2410_wdt_variant
*)
519 platform_get_device_id(pdev
)->driver_data
;
523 static int s3c2410wdt_probe(struct platform_device
*pdev
)
526 struct s3c2410_wdt
*wdt
;
527 struct resource
*wdt_mem
;
528 struct resource
*wdt_irq
;
535 wdt
= devm_kzalloc(dev
, sizeof(*wdt
), GFP_KERNEL
);
539 wdt
->dev
= &pdev
->dev
;
540 spin_lock_init(&wdt
->lock
);
541 wdt
->wdt_device
= s3c2410_wdd
;
543 wdt
->drv_data
= s3c2410_get_wdt_drv_data(pdev
);
544 if (wdt
->drv_data
->quirks
& QUIRKS_HAVE_PMUREG
) {
545 wdt
->pmureg
= syscon_regmap_lookup_by_phandle(dev
->of_node
,
546 "samsung,syscon-phandle");
547 if (IS_ERR(wdt
->pmureg
)) {
548 dev_err(dev
, "syscon regmap lookup failed.\n");
549 return PTR_ERR(wdt
->pmureg
);
553 wdt_irq
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
554 if (wdt_irq
== NULL
) {
555 dev_err(dev
, "no irq resource specified\n");
560 /* get the memory region for the watchdog timer */
561 wdt_mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
562 wdt
->reg_base
= devm_ioremap_resource(dev
, wdt_mem
);
563 if (IS_ERR(wdt
->reg_base
)) {
564 ret
= PTR_ERR(wdt
->reg_base
);
568 wdt
->clock
= devm_clk_get(dev
, "watchdog");
569 if (IS_ERR(wdt
->clock
)) {
570 dev_err(dev
, "failed to find watchdog clock source\n");
571 ret
= PTR_ERR(wdt
->clock
);
575 ret
= clk_prepare_enable(wdt
->clock
);
577 dev_err(dev
, "failed to enable clock\n");
581 wdt
->wdt_device
.min_timeout
= 1;
582 wdt
->wdt_device
.max_timeout
= s3c2410wdt_max_timeout(wdt
->clock
);
584 ret
= s3c2410wdt_cpufreq_register(wdt
);
586 dev_err(dev
, "failed to register cpufreq\n");
590 watchdog_set_drvdata(&wdt
->wdt_device
, wdt
);
592 /* see if we can actually set the requested timer margin, and if
593 * not, try the default value */
595 watchdog_init_timeout(&wdt
->wdt_device
, tmr_margin
, &pdev
->dev
);
596 ret
= s3c2410wdt_set_heartbeat(&wdt
->wdt_device
,
597 wdt
->wdt_device
.timeout
);
599 started
= s3c2410wdt_set_heartbeat(&wdt
->wdt_device
,
600 S3C2410_WATCHDOG_DEFAULT_TIME
);
604 "tmr_margin value out of range, default %d used\n",
605 S3C2410_WATCHDOG_DEFAULT_TIME
);
607 dev_info(dev
, "default timer value is out of range, "
611 ret
= devm_request_irq(dev
, wdt_irq
->start
, s3c2410wdt_irq
, 0,
614 dev_err(dev
, "failed to install irq (%d)\n", ret
);
618 watchdog_set_nowayout(&wdt
->wdt_device
, nowayout
);
619 watchdog_set_restart_priority(&wdt
->wdt_device
, 128);
621 wdt
->wdt_device
.bootstatus
= s3c2410wdt_get_bootstatus(wdt
);
622 wdt
->wdt_device
.parent
= &pdev
->dev
;
624 ret
= watchdog_register_device(&wdt
->wdt_device
);
626 dev_err(dev
, "cannot register watchdog (%d)\n", ret
);
630 ret
= s3c2410wdt_mask_and_disable_reset(wdt
, false);
634 if (tmr_atboot
&& started
== 0) {
635 dev_info(dev
, "starting watchdog timer\n");
636 s3c2410wdt_start(&wdt
->wdt_device
);
637 } else if (!tmr_atboot
) {
638 /* if we're not enabling the watchdog, then ensure it is
639 * disabled if it has been left running from the bootloader
642 s3c2410wdt_stop(&wdt
->wdt_device
);
645 platform_set_drvdata(pdev
, wdt
);
647 /* print out a statement of readiness */
649 wtcon
= readl(wdt
->reg_base
+ S3C2410_WTCON
);
651 dev_info(dev
, "watchdog %sactive, reset %sabled, irq %sabled\n",
652 (wtcon
& S3C2410_WTCON_ENABLE
) ? "" : "in",
653 (wtcon
& S3C2410_WTCON_RSTEN
) ? "en" : "dis",
654 (wtcon
& S3C2410_WTCON_INTEN
) ? "en" : "dis");
659 watchdog_unregister_device(&wdt
->wdt_device
);
662 s3c2410wdt_cpufreq_deregister(wdt
);
665 clk_disable_unprepare(wdt
->clock
);
671 static int s3c2410wdt_remove(struct platform_device
*dev
)
674 struct s3c2410_wdt
*wdt
= platform_get_drvdata(dev
);
676 ret
= s3c2410wdt_mask_and_disable_reset(wdt
, true);
680 watchdog_unregister_device(&wdt
->wdt_device
);
682 s3c2410wdt_cpufreq_deregister(wdt
);
684 clk_disable_unprepare(wdt
->clock
);
689 static void s3c2410wdt_shutdown(struct platform_device
*dev
)
691 struct s3c2410_wdt
*wdt
= platform_get_drvdata(dev
);
693 s3c2410wdt_mask_and_disable_reset(wdt
, true);
695 s3c2410wdt_stop(&wdt
->wdt_device
);
698 #ifdef CONFIG_PM_SLEEP
700 static int s3c2410wdt_suspend(struct device
*dev
)
703 struct s3c2410_wdt
*wdt
= dev_get_drvdata(dev
);
705 /* Save watchdog state, and turn it off. */
706 wdt
->wtcon_save
= readl(wdt
->reg_base
+ S3C2410_WTCON
);
707 wdt
->wtdat_save
= readl(wdt
->reg_base
+ S3C2410_WTDAT
);
709 ret
= s3c2410wdt_mask_and_disable_reset(wdt
, true);
713 /* Note that WTCNT doesn't need to be saved. */
714 s3c2410wdt_stop(&wdt
->wdt_device
);
719 static int s3c2410wdt_resume(struct device
*dev
)
722 struct s3c2410_wdt
*wdt
= dev_get_drvdata(dev
);
724 /* Restore watchdog state. */
725 writel(wdt
->wtdat_save
, wdt
->reg_base
+ S3C2410_WTDAT
);
726 writel(wdt
->wtdat_save
, wdt
->reg_base
+ S3C2410_WTCNT
);/* Reset count */
727 writel(wdt
->wtcon_save
, wdt
->reg_base
+ S3C2410_WTCON
);
729 ret
= s3c2410wdt_mask_and_disable_reset(wdt
, false);
733 dev_info(dev
, "watchdog %sabled\n",
734 (wdt
->wtcon_save
& S3C2410_WTCON_ENABLE
) ? "en" : "dis");
740 static SIMPLE_DEV_PM_OPS(s3c2410wdt_pm_ops
, s3c2410wdt_suspend
,
743 static struct platform_driver s3c2410wdt_driver
= {
744 .probe
= s3c2410wdt_probe
,
745 .remove
= s3c2410wdt_remove
,
746 .shutdown
= s3c2410wdt_shutdown
,
747 .id_table
= s3c2410_wdt_ids
,
749 .name
= "s3c2410-wdt",
750 .pm
= &s3c2410wdt_pm_ops
,
751 .of_match_table
= of_match_ptr(s3c2410_wdt_match
),
755 module_platform_driver(s3c2410wdt_driver
);
757 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, "
758 "Dimitry Andric <dimitry.andric@tomtom.com>");
759 MODULE_DESCRIPTION("S3C2410 Watchdog Device Driver");
760 MODULE_LICENSE("GPL");