blob: 4c520d68397e9b87fb38f7905d204530de8d08e7 [file] [log] [blame]
matthieu castet90074dc2009-06-05 18:57:18 +02001/*
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
Joe Perches27c766a2012-02-15 15:06:19 -080013#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
matthieu castet90074dc2009-06-05 18:57:18 +020015#include <linux/bitops.h>
16#include <linux/errno.h>
matthieu castet90074dc2009-06-05 18:57:18 +020017#include <linux/init.h>
18#include <linux/kernel.h>
matthieu castet90074dc2009-06-05 18:57:18 +020019#include <linux/module.h>
20#include <linux/moduleparam.h>
21#include <linux/reboot.h>
22#include <linux/types.h>
matthieu castet90074dc2009-06-05 18:57:18 +020023#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;
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010035static bool nowayout = WATCHDOG_NOWAYOUT;
matthieu castet90074dc2009-06-05 18:57:18 +020036
37module_param(wdt_time, int, 0);
38MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="
39 __MODULE_STRING(WDT_DEFAULT_TIME) ")");
40
Wim Van Sebroeck86a1e182012-03-05 16:51:11 +010041module_param(nowayout, bool, 0);
matthieu castet90074dc2009-06-05 18:57:18 +020042MODULE_PARM_DESC(nowayout,
43 "Watchdog cannot be stopped once started (default="
44 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
matthieu castet90074dc2009-06-05 18:57:18 +020045
matthieu castet90074dc2009-06-05 18:57:18 +020046static 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 */
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020052 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020053#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020054 case BCM47XX_BUS_TYPE_SSB:
55 ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0xfffffff);
56 break;
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020057#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020058#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
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020064 }
matthieu castet90074dc2009-06-05 18:57:18 +020065}
66
67static inline int bcm47xx_wdt_hw_stop(void)
68{
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020069 switch (bcm47xx_bus_type) {
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020070#ifdef CONFIG_BCM47XX_SSB
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020071 case BCM47XX_BUS_TYPE_SSB:
72 return ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
Hauke Mehrtensa656ffc2011-07-23 01:20:13 +020073#endif
Hauke Mehrtensc1d1c5d2011-07-23 01:20:14 +020074#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
Hauke Mehrtens08ccf5722011-07-23 01:20:12 +020079 }
80 return -EINVAL;
matthieu castet90074dc2009-06-05 18:57:18 +020081}
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 {
Joe Perches27c766a2012-02-15 15:06:19 -080089 pr_crit("Watchdog will fire soon!!!\n");
matthieu castet90074dc2009-06-05 18:57:18 +020090 }
91}
92
Hauke Mehrtens5434a042013-01-12 18:14:07 +010093static int bcm47xx_wdt_keepalive(struct watchdog_device *wdd)
matthieu castet90074dc2009-06-05 18:57:18 +020094{
95 atomic_set(&ticks, wdt_time);
Hauke Mehrtens5434a042013-01-12 18:14:07 +010096
97 return 0;
matthieu castet90074dc2009-06-05 18:57:18 +020098}
99
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100100static int bcm47xx_wdt_start(struct watchdog_device *wdd)
matthieu castet90074dc2009-06-05 18:57:18 +0200101{
102 bcm47xx_wdt_pet();
103 bcm47xx_timer_tick(0);
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100104
105 return 0;
matthieu castet90074dc2009-06-05 18:57:18 +0200106}
107
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100108static int bcm47xx_wdt_stop(struct watchdog_device *wdd)
matthieu castet90074dc2009-06-05 18:57:18 +0200109{
110 del_timer_sync(&wdt_timer);
111 bcm47xx_wdt_hw_stop();
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100112
113 return 0;
matthieu castet90074dc2009-06-05 18:57:18 +0200114}
115
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100116static int bcm47xx_wdt_set_timeout(struct watchdog_device *wdd,
117 unsigned int new_time)
matthieu castet90074dc2009-06-05 18:57:18 +0200118{
119 if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
120 return -EINVAL;
121
122 wdt_time = new_time;
123 return 0;
124}
125
Wim Van Sebroeck42747d72009-12-26 18:55:22 +0000126static const struct watchdog_info bcm47xx_wdt_info = {
Wim Van Sebroeck5f3b2752011-02-23 20:04:38 +0000127 .identity = DRV_NAME,
128 .options = WDIOF_SETTIMEOUT |
matthieu castet90074dc2009-06-05 18:57:18 +0200129 WDIOF_KEEPALIVEPING |
130 WDIOF_MAGICCLOSE,
131};
132
matthieu castet90074dc2009-06-05 18:57:18 +0200133static int bcm47xx_wdt_notify_sys(struct notifier_block *this,
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100134 unsigned long code, void *unused)
matthieu castet90074dc2009-06-05 18:57:18 +0200135{
136 if (code == SYS_DOWN || code == SYS_HALT)
137 bcm47xx_wdt_stop();
138 return NOTIFY_DONE;
139}
140
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100141static struct watchdog_ops bcm47xx_wdt_ops = {
matthieu castet90074dc2009-06-05 18:57:18 +0200142 .owner = THIS_MODULE,
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100143 .start = bcm47xx_wdt_start,
144 .stop = bcm47xx_wdt_stop,
145 .ping = bcm47xx_wdt_keepalive,
146 .set_timeout = bcm47xx_wdt_set_timeout,
matthieu castet90074dc2009-06-05 18:57:18 +0200147};
148
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100149static struct watchdog_device bcm47xx_wdt_wdd = {
150 .info = &bcm47xx_wdt_info,
151 .ops = &bcm47xx_wdt_ops,
matthieu castet90074dc2009-06-05 18:57:18 +0200152};
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);
Joe Perches27c766a2012-02-15 15:06:19 -0800169 pr_info("wdt_time value must be 0 < wdt_time < %d, using %d\n",
matthieu castet90074dc2009-06-05 18:57:18 +0200170 (WDT_MAX_TIME + 1), wdt_time);
171 }
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100172 watchdog_set_nowayout(&bcm47xx_wdt_wdd, nowayout);
matthieu castet90074dc2009-06-05 18:57:18 +0200173
174 ret = register_reboot_notifier(&bcm47xx_wdt_notifier);
175 if (ret)
176 return ret;
177
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100178 ret = watchdog_register_device(&bcm47xx_wdt_wdd);
matthieu castet90074dc2009-06-05 18:57:18 +0200179 if (ret) {
180 unregister_reboot_notifier(&bcm47xx_wdt_notifier);
181 return ret;
182 }
183
Joe Perches27c766a2012-02-15 15:06:19 -0800184 pr_info("BCM47xx Watchdog Timer enabled (%d seconds%s)\n",
185 wdt_time, nowayout ? ", nowayout" : "");
matthieu castet90074dc2009-06-05 18:57:18 +0200186 return 0;
187}
188
189static void __exit bcm47xx_wdt_exit(void)
190{
Hauke Mehrtens5434a042013-01-12 18:14:07 +0100191 watchdog_unregister_device(&bcm47xx_wdt_wdd);
matthieu castet90074dc2009-06-05 18:57:18 +0200192
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");