4c520d68397e9b87fb38f7905d204530de8d08e7
[deliverable/linux.git] / drivers / watchdog / bcm47xx_wdt.c
1 /*
2 * Watchdog driver for Broadcom BCM47XX
3 *
4 * Copyright (C) 2008 Aleksandar Radovanovic <biblbroks@sezampro.rs>
5 * Copyright (C) 2009 Matthieu CASTET <castet.matthieu@free.fr>
6 *
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.
11 */
12
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
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>
28
29 #define DRV_NAME "bcm47xx_wdt"
30
31 #define WDT_DEFAULT_TIME 30 /* seconds */
32 #define WDT_MAX_TIME 255 /* seconds */
33
34 static int wdt_time = WDT_DEFAULT_TIME;
35 static bool nowayout = WATCHDOG_NOWAYOUT;
36
37 module_param(wdt_time, int, 0);
38 MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="
39 __MODULE_STRING(WDT_DEFAULT_TIME) ")");
40
41 module_param(nowayout, bool, 0);
42 MODULE_PARM_DESC(nowayout,
43 "Watchdog cannot be stopped once started (default="
44 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
45
46 static struct timer_list wdt_timer;
47 static atomic_t ticks;
48
49 static inline void bcm47xx_wdt_hw_start(void)
50 {
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);
56 break;
57 #endif
58 #ifdef CONFIG_BCM47XX_BCMA
59 case BCM47XX_BUS_TYPE_BCMA:
60 bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc,
61 0xfffffff);
62 break;
63 #endif
64 }
65 }
66
67 static inline int bcm47xx_wdt_hw_stop(void)
68 {
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);
73 #endif
74 #ifdef CONFIG_BCM47XX_BCMA
75 case BCM47XX_BUS_TYPE_BCMA:
76 bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
77 return 0;
78 #endif
79 }
80 return -EINVAL;
81 }
82
83 static void bcm47xx_timer_tick(unsigned long unused)
84 {
85 if (!atomic_dec_and_test(&ticks)) {
86 bcm47xx_wdt_hw_start();
87 mod_timer(&wdt_timer, jiffies + HZ);
88 } else {
89 pr_crit("Watchdog will fire soon!!!\n");
90 }
91 }
92
93 static int bcm47xx_wdt_keepalive(struct watchdog_device *wdd)
94 {
95 atomic_set(&ticks, wdt_time);
96
97 return 0;
98 }
99
100 static int bcm47xx_wdt_start(struct watchdog_device *wdd)
101 {
102 bcm47xx_wdt_pet();
103 bcm47xx_timer_tick(0);
104
105 return 0;
106 }
107
108 static int bcm47xx_wdt_stop(struct watchdog_device *wdd)
109 {
110 del_timer_sync(&wdt_timer);
111 bcm47xx_wdt_hw_stop();
112
113 return 0;
114 }
115
116 static int bcm47xx_wdt_set_timeout(struct watchdog_device *wdd,
117 unsigned int new_time)
118 {
119 if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
120 return -EINVAL;
121
122 wdt_time = new_time;
123 return 0;
124 }
125
126 static const struct watchdog_info bcm47xx_wdt_info = {
127 .identity = DRV_NAME,
128 .options = WDIOF_SETTIMEOUT |
129 WDIOF_KEEPALIVEPING |
130 WDIOF_MAGICCLOSE,
131 };
132
133 static int bcm47xx_wdt_notify_sys(struct notifier_block *this,
134 unsigned long code, void *unused)
135 {
136 if (code == SYS_DOWN || code == SYS_HALT)
137 bcm47xx_wdt_stop();
138 return NOTIFY_DONE;
139 }
140
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,
147 };
148
149 static struct watchdog_device bcm47xx_wdt_wdd = {
150 .info = &bcm47xx_wdt_info,
151 .ops = &bcm47xx_wdt_ops,
152 };
153
154 static struct notifier_block bcm47xx_wdt_notifier = {
155 .notifier_call = bcm47xx_wdt_notify_sys,
156 };
157
158 static int __init bcm47xx_wdt_init(void)
159 {
160 int ret;
161
162 if (bcm47xx_wdt_hw_stop() < 0)
163 return -ENODEV;
164
165 setup_timer(&wdt_timer, bcm47xx_timer_tick, 0L);
166
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);
171 }
172 watchdog_set_nowayout(&bcm47xx_wdt_wdd, nowayout);
173
174 ret = register_reboot_notifier(&bcm47xx_wdt_notifier);
175 if (ret)
176 return ret;
177
178 ret = watchdog_register_device(&bcm47xx_wdt_wdd);
179 if (ret) {
180 unregister_reboot_notifier(&bcm47xx_wdt_notifier);
181 return ret;
182 }
183
184 pr_info("BCM47xx Watchdog Timer enabled (%d seconds%s)\n",
185 wdt_time, nowayout ? ", nowayout" : "");
186 return 0;
187 }
188
189 static void __exit bcm47xx_wdt_exit(void)
190 {
191 watchdog_unregister_device(&bcm47xx_wdt_wdd);
192
193 unregister_reboot_notifier(&bcm47xx_wdt_notifier);
194 }
195
196 module_init(bcm47xx_wdt_init);
197 module_exit(bcm47xx_wdt_exit);
198
199 MODULE_AUTHOR("Aleksandar Radovanovic");
200 MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx");
201 MODULE_LICENSE("GPL");
This page took 0.094469 seconds and 4 git commands to generate.