2 * Watchdog driver for Broadcom BCM47XX
4 * Copyright (C) 2008 Aleksandar Radovanovic <biblbroks@sezampro.rs>
5 * Copyright (C) 2009 Matthieu CASTET <castet.matthieu@free.fr>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/bitops.h>
16 #include <linux/errno.h>
17 #include <linux/init.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/moduleparam.h>
21 #include <linux/reboot.h>
22 #include <linux/types.h>
23 #include <linux/watchdog.h>
24 #include <linux/timer.h>
25 #include <linux/jiffies.h>
26 #include <linux/ssb/ssb_embedded.h>
27 #include <asm/mach-bcm47xx/bcm47xx.h>
29 #define DRV_NAME "bcm47xx_wdt"
31 #define WDT_DEFAULT_TIME 30 /* seconds */
32 #define WDT_MAX_TIME 255 /* seconds */
34 static int wdt_time
= WDT_DEFAULT_TIME
;
35 static bool nowayout
= WATCHDOG_NOWAYOUT
;
37 module_param(wdt_time
, int, 0);
38 MODULE_PARM_DESC(wdt_time
, "Watchdog time in seconds. (default="
39 __MODULE_STRING(WDT_DEFAULT_TIME
) ")");
41 module_param(nowayout
, bool, 0);
42 MODULE_PARM_DESC(nowayout
,
43 "Watchdog cannot be stopped once started (default="
44 __MODULE_STRING(WATCHDOG_NOWAYOUT
) ")");
46 static struct timer_list wdt_timer
;
47 static atomic_t ticks
;
49 static inline void bcm47xx_wdt_hw_start(void)
51 /* this is 2,5s on 100Mhz clock and 2s on 133 Mhz */
52 switch (bcm47xx_bus_type
) {
53 #ifdef CONFIG_BCM47XX_SSB
54 case BCM47XX_BUS_TYPE_SSB
:
55 ssb_watchdog_timer_set(&bcm47xx_bus
.ssb
, 0xfffffff);
58 #ifdef CONFIG_BCM47XX_BCMA
59 case BCM47XX_BUS_TYPE_BCMA
:
60 bcma_chipco_watchdog_timer_set(&bcm47xx_bus
.bcma
.bus
.drv_cc
,
67 static inline int bcm47xx_wdt_hw_stop(void)
69 switch (bcm47xx_bus_type
) {
70 #ifdef CONFIG_BCM47XX_SSB
71 case BCM47XX_BUS_TYPE_SSB
:
72 return ssb_watchdog_timer_set(&bcm47xx_bus
.ssb
, 0);
74 #ifdef CONFIG_BCM47XX_BCMA
75 case BCM47XX_BUS_TYPE_BCMA
:
76 bcma_chipco_watchdog_timer_set(&bcm47xx_bus
.bcma
.bus
.drv_cc
, 0);
83 static void bcm47xx_timer_tick(unsigned long unused
)
85 if (!atomic_dec_and_test(&ticks
)) {
86 bcm47xx_wdt_hw_start();
87 mod_timer(&wdt_timer
, jiffies
+ HZ
);
89 pr_crit("Watchdog will fire soon!!!\n");
93 static int bcm47xx_wdt_keepalive(struct watchdog_device
*wdd
)
95 atomic_set(&ticks
, wdt_time
);
100 static int bcm47xx_wdt_start(struct watchdog_device
*wdd
)
103 bcm47xx_timer_tick(0);
108 static int bcm47xx_wdt_stop(struct watchdog_device
*wdd
)
110 del_timer_sync(&wdt_timer
);
111 bcm47xx_wdt_hw_stop();
116 static int bcm47xx_wdt_set_timeout(struct watchdog_device
*wdd
,
117 unsigned int new_time
)
119 if ((new_time
<= 0) || (new_time
> WDT_MAX_TIME
))
126 static const struct watchdog_info bcm47xx_wdt_info
= {
127 .identity
= DRV_NAME
,
128 .options
= WDIOF_SETTIMEOUT
|
129 WDIOF_KEEPALIVEPING
|
133 static int bcm47xx_wdt_notify_sys(struct notifier_block
*this,
134 unsigned long code
, void *unused
)
136 if (code
== SYS_DOWN
|| code
== SYS_HALT
)
141 static struct watchdog_ops bcm47xx_wdt_ops
= {
142 .owner
= THIS_MODULE
,
143 .start
= bcm47xx_wdt_start
,
144 .stop
= bcm47xx_wdt_stop
,
145 .ping
= bcm47xx_wdt_keepalive
,
146 .set_timeout
= bcm47xx_wdt_set_timeout
,
149 static struct watchdog_device bcm47xx_wdt_wdd
= {
150 .info
= &bcm47xx_wdt_info
,
151 .ops
= &bcm47xx_wdt_ops
,
154 static struct notifier_block bcm47xx_wdt_notifier
= {
155 .notifier_call
= bcm47xx_wdt_notify_sys
,
158 static int __init
bcm47xx_wdt_init(void)
162 if (bcm47xx_wdt_hw_stop() < 0)
165 setup_timer(&wdt_timer
, bcm47xx_timer_tick
, 0L);
167 if (bcm47xx_wdt_settimeout(wdt_time
)) {
168 bcm47xx_wdt_settimeout(WDT_DEFAULT_TIME
);
169 pr_info("wdt_time value must be 0 < wdt_time < %d, using %d\n",
170 (WDT_MAX_TIME
+ 1), wdt_time
);
172 watchdog_set_nowayout(&bcm47xx_wdt_wdd
, nowayout
);
174 ret
= register_reboot_notifier(&bcm47xx_wdt_notifier
);
178 ret
= watchdog_register_device(&bcm47xx_wdt_wdd
);
180 unregister_reboot_notifier(&bcm47xx_wdt_notifier
);
184 pr_info("BCM47xx Watchdog Timer enabled (%d seconds%s)\n",
185 wdt_time
, nowayout
? ", nowayout" : "");
189 static void __exit
bcm47xx_wdt_exit(void)
191 watchdog_unregister_device(&bcm47xx_wdt_wdd
);
193 unregister_reboot_notifier(&bcm47xx_wdt_notifier
);
196 module_init(bcm47xx_wdt_init
);
197 module_exit(bcm47xx_wdt_exit
);
199 MODULE_AUTHOR("Aleksandar Radovanovic");
200 MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx");
201 MODULE_LICENSE("GPL");