watchdog: bcm47xx_wdt.c: convert to watchdog core api
[deliverable/linux.git] / drivers / watchdog / bcm47xx_wdt.c
CommitLineData
90074dce 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
27c766aa
JP
13#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
90074dce 15#include <linux/bitops.h>
16#include <linux/errno.h>
90074dce 17#include <linux/init.h>
18#include <linux/kernel.h>
90074dce 19#include <linux/module.h>
20#include <linux/moduleparam.h>
21#include <linux/reboot.h>
22#include <linux/types.h>
90074dce 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
34static int wdt_time = WDT_DEFAULT_TIME;
86a1e189 35static bool nowayout = WATCHDOG_NOWAYOUT;
90074dce 36
37module_param(wdt_time, int, 0);
38MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="
39 __MODULE_STRING(WDT_DEFAULT_TIME) ")");
40
86a1e189 41module_param(nowayout, bool, 0);
90074dce 42MODULE_PARM_DESC(nowayout,
43 "Watchdog cannot be stopped once started (default="
44 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
90074dce 45
90074dce 46static struct timer_list wdt_timer;
47static atomic_t ticks;
48
49static inline void bcm47xx_wdt_hw_start(void)
50{
51 /* this is 2,5s on 100Mhz clock and 2s on 133 Mhz */
08ccf572 52 switch (bcm47xx_bus_type) {
a656ffcb 53#ifdef CONFIG_BCM47XX_SSB
08ccf572
HM
54 case BCM47XX_BUS_TYPE_SSB:
55 ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0xfffffff);
56 break;
c1d1c5d4
HM
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;
a656ffcb 63#endif
08ccf572 64 }
90074dce 65}
66
67static inline int bcm47xx_wdt_hw_stop(void)
68{
08ccf572 69 switch (bcm47xx_bus_type) {
a656ffcb 70#ifdef CONFIG_BCM47XX_SSB
08ccf572
HM
71 case BCM47XX_BUS_TYPE_SSB:
72 return ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
c1d1c5d4
HM
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;
a656ffcb 78#endif
08ccf572
HM
79 }
80 return -EINVAL;
90074dce 81}
82
83static 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 {
27c766aa 89 pr_crit("Watchdog will fire soon!!!\n");
90074dce 90 }
91}
92
5434a04d 93static int bcm47xx_wdt_keepalive(struct watchdog_device *wdd)
90074dce 94{
95 atomic_set(&ticks, wdt_time);
5434a04d
HM
96
97 return 0;
90074dce 98}
99
5434a04d 100static int bcm47xx_wdt_start(struct watchdog_device *wdd)
90074dce 101{
102 bcm47xx_wdt_pet();
103 bcm47xx_timer_tick(0);
5434a04d
HM
104
105 return 0;
90074dce 106}
107
5434a04d 108static int bcm47xx_wdt_stop(struct watchdog_device *wdd)
90074dce 109{
110 del_timer_sync(&wdt_timer);
111 bcm47xx_wdt_hw_stop();
90074dce 112
5434a04d 113 return 0;
90074dce 114}
115
5434a04d
HM
116static int bcm47xx_wdt_set_timeout(struct watchdog_device *wdd,
117 unsigned int new_time)
90074dce 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
42747d71 126static const struct watchdog_info bcm47xx_wdt_info = {
5f3b2756
WVS
127 .identity = DRV_NAME,
128 .options = WDIOF_SETTIMEOUT |
90074dce 129 WDIOF_KEEPALIVEPING |
130 WDIOF_MAGICCLOSE,
131};
132
90074dce 133static int bcm47xx_wdt_notify_sys(struct notifier_block *this,
5434a04d 134 unsigned long code, void *unused)
90074dce 135{
136 if (code == SYS_DOWN || code == SYS_HALT)
137 bcm47xx_wdt_stop();
138 return NOTIFY_DONE;
139}
140
5434a04d 141static struct watchdog_ops bcm47xx_wdt_ops = {
90074dce 142 .owner = THIS_MODULE,
5434a04d
HM
143 .start = bcm47xx_wdt_start,
144 .stop = bcm47xx_wdt_stop,
145 .ping = bcm47xx_wdt_keepalive,
146 .set_timeout = bcm47xx_wdt_set_timeout,
90074dce 147};
148
5434a04d
HM
149static struct watchdog_device bcm47xx_wdt_wdd = {
150 .info = &bcm47xx_wdt_info,
151 .ops = &bcm47xx_wdt_ops,
90074dce 152};
153
154static struct notifier_block bcm47xx_wdt_notifier = {
155 .notifier_call = bcm47xx_wdt_notify_sys,
156};
157
158static 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);
27c766aa 169 pr_info("wdt_time value must be 0 < wdt_time < %d, using %d\n",
90074dce 170 (WDT_MAX_TIME + 1), wdt_time);
171 }
5434a04d 172 watchdog_set_nowayout(&bcm47xx_wdt_wdd, nowayout);
90074dce 173
174 ret = register_reboot_notifier(&bcm47xx_wdt_notifier);
175 if (ret)
176 return ret;
177
5434a04d 178 ret = watchdog_register_device(&bcm47xx_wdt_wdd);
90074dce 179 if (ret) {
180 unregister_reboot_notifier(&bcm47xx_wdt_notifier);
181 return ret;
182 }
183
27c766aa
JP
184 pr_info("BCM47xx Watchdog Timer enabled (%d seconds%s)\n",
185 wdt_time, nowayout ? ", nowayout" : "");
90074dce 186 return 0;
187}
188
189static void __exit bcm47xx_wdt_exit(void)
190{
5434a04d 191 watchdog_unregister_device(&bcm47xx_wdt_wdd);
90074dce 192
193 unregister_reboot_notifier(&bcm47xx_wdt_notifier);
194}
195
196module_init(bcm47xx_wdt_init);
197module_exit(bcm47xx_wdt_exit);
198
199MODULE_AUTHOR("Aleksandar Radovanovic");
200MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx");
201MODULE_LICENSE("GPL");
This page took 0.275167 seconds and 5 git commands to generate.