| 1 | --- a/drivers/watchdog/bcm47xx_wdt.c |
| 2 | +++ b/drivers/watchdog/bcm47xx_wdt.c |
| 3 | @@ -3,6 +3,7 @@ |
| 4 | * |
| 5 | * Copyright (C) 2008 Aleksandar Radovanovic <biblbroks@sezampro.rs> |
| 6 | * Copyright (C) 2009 Matthieu CASTET <castet.matthieu@free.fr> |
| 7 | + * Copyright (C) 2012 Hauke Mehrtens <hauke@hauke-m.de> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | @@ -12,19 +13,19 @@ |
| 12 | |
| 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 14 | |
| 15 | +#include <linux/bcm47xx_wdt.h> |
| 16 | #include <linux/bitops.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/moduleparam.h> |
| 22 | +#include <linux/platform_device.h> |
| 23 | #include <linux/reboot.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/watchdog.h> |
| 26 | #include <linux/timer.h> |
| 27 | #include <linux/jiffies.h> |
| 28 | -#include <linux/ssb/ssb_embedded.h> |
| 29 | -#include <asm/mach-bcm47xx/bcm47xx.h> |
| 30 | |
| 31 | #define DRV_NAME "bcm47xx_wdt" |
| 32 | |
| 33 | @@ -43,48 +44,19 @@ MODULE_PARM_DESC(nowayout, |
| 34 | "Watchdog cannot be stopped once started (default=" |
| 35 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
| 36 | |
| 37 | -static struct timer_list wdt_timer; |
| 38 | -static atomic_t ticks; |
| 39 | - |
| 40 | -static inline void bcm47xx_wdt_hw_start(void) |
| 41 | +static inline struct bcm47xx_wdt *bcm47xx_wdt_get(struct watchdog_device *wdd) |
| 42 | { |
| 43 | - /* this is 2,5s on 100Mhz clock and 2s on 133 Mhz */ |
| 44 | - switch (bcm47xx_bus_type) { |
| 45 | -#ifdef CONFIG_BCM47XX_SSB |
| 46 | - case BCM47XX_BUS_TYPE_SSB: |
| 47 | - ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0xfffffff); |
| 48 | - break; |
| 49 | -#endif |
| 50 | -#ifdef CONFIG_BCM47XX_BCMA |
| 51 | - case BCM47XX_BUS_TYPE_BCMA: |
| 52 | - bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, |
| 53 | - 0xfffffff); |
| 54 | - break; |
| 55 | -#endif |
| 56 | - } |
| 57 | + return container_of(wdd, struct bcm47xx_wdt, wdd); |
| 58 | } |
| 59 | |
| 60 | -static inline int bcm47xx_wdt_hw_stop(void) |
| 61 | +static void bcm47xx_timer_tick(unsigned long data) |
| 62 | { |
| 63 | - switch (bcm47xx_bus_type) { |
| 64 | -#ifdef CONFIG_BCM47XX_SSB |
| 65 | - case BCM47XX_BUS_TYPE_SSB: |
| 66 | - return ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0); |
| 67 | -#endif |
| 68 | -#ifdef CONFIG_BCM47XX_BCMA |
| 69 | - case BCM47XX_BUS_TYPE_BCMA: |
| 70 | - bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0); |
| 71 | - return 0; |
| 72 | -#endif |
| 73 | - } |
| 74 | - return -EINVAL; |
| 75 | -} |
| 76 | + struct bcm47xx_wdt *wdt = (struct bcm47xx_wdt *)data; |
| 77 | + u32 next_tick = min(wdt->wdd.timeout * 1000, wdt->max_timer_ms); |
| 78 | |
| 79 | -static void bcm47xx_timer_tick(unsigned long unused) |
| 80 | -{ |
| 81 | - if (!atomic_dec_and_test(&ticks)) { |
| 82 | - bcm47xx_wdt_hw_start(); |
| 83 | - mod_timer(&wdt_timer, jiffies + HZ); |
| 84 | + if (!atomic_dec_and_test(&wdt->soft_ticks)) { |
| 85 | + wdt->timer_set_ms(wdt, next_tick); |
| 86 | + mod_timer(&wdt->soft_timer, jiffies + HZ); |
| 87 | } else { |
| 88 | pr_crit("Watchdog will fire soon!!!\n"); |
| 89 | } |
| 90 | @@ -92,23 +64,29 @@ static void bcm47xx_timer_tick(unsigned |
| 91 | |
| 92 | static int bcm47xx_wdt_keepalive(struct watchdog_device *wdd) |
| 93 | { |
| 94 | - atomic_set(&ticks, wdt_time); |
| 95 | + struct bcm47xx_wdt *wdt = bcm47xx_wdt_get(wdd); |
| 96 | + |
| 97 | + atomic_set(&wdt->soft_ticks, wdd->timeout); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static int bcm47xx_wdt_start(struct watchdog_device *wdd) |
| 103 | { |
| 104 | - bcm47xx_wdt_pet(); |
| 105 | - bcm47xx_timer_tick(0); |
| 106 | + struct bcm47xx_wdt *wdt = bcm47xx_wdt_get(wdd); |
| 107 | + |
| 108 | + bcm47xx_wdt_keepalive(wdd); |
| 109 | + bcm47xx_timer_tick((unsigned long)wdt); |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static int bcm47xx_wdt_stop(struct watchdog_device *wdd) |
| 115 | { |
| 116 | - del_timer_sync(&wdt_timer); |
| 117 | - bcm47xx_wdt_hw_stop(); |
| 118 | + struct bcm47xx_wdt *wdt = bcm47xx_wdt_get(wdd); |
| 119 | + |
| 120 | + del_timer_sync(&wdt->soft_timer); |
| 121 | + wdt->timer_set(wdt, 0); |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | @@ -116,10 +94,13 @@ static int bcm47xx_wdt_stop(struct watch |
| 126 | static int bcm47xx_wdt_set_timeout(struct watchdog_device *wdd, |
| 127 | unsigned int new_time) |
| 128 | { |
| 129 | - if ((new_time <= 0) || (new_time > WDT_MAX_TIME)) |
| 130 | + if (new_time < 1 || new_time > WDT_MAX_TIME) { |
| 131 | + pr_warn("timeout value must be 1<=x<=%d, using %d\n", |
| 132 | + WDT_MAX_TIME, new_time); |
| 133 | return -EINVAL; |
| 134 | + } |
| 135 | |
| 136 | - wdt_time = new_time; |
| 137 | + wdd->timeout = new_time; |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | @@ -133,8 +114,11 @@ static const struct watchdog_info bcm47x |
| 142 | static int bcm47xx_wdt_notify_sys(struct notifier_block *this, |
| 143 | unsigned long code, void *unused) |
| 144 | { |
| 145 | + struct bcm47xx_wdt *wdt; |
| 146 | + |
| 147 | + wdt = container_of(this, struct bcm47xx_wdt, notifier); |
| 148 | if (code == SYS_DOWN || code == SYS_HALT) |
| 149 | - bcm47xx_wdt_stop(); |
| 150 | + wdt->wdd.ops->stop(&wdt->wdd); |
| 151 | return NOTIFY_DONE; |
| 152 | } |
| 153 | |
| 154 | @@ -146,56 +130,72 @@ static struct watchdog_ops bcm47xx_wdt_o |
| 155 | .set_timeout = bcm47xx_wdt_set_timeout, |
| 156 | }; |
| 157 | |
| 158 | -static struct watchdog_device bcm47xx_wdt_wdd = { |
| 159 | - .info = &bcm47xx_wdt_info, |
| 160 | - .ops = &bcm47xx_wdt_ops, |
| 161 | -}; |
| 162 | - |
| 163 | -static struct notifier_block bcm47xx_wdt_notifier = { |
| 164 | - .notifier_call = bcm47xx_wdt_notify_sys, |
| 165 | -}; |
| 166 | - |
| 167 | -static int __init bcm47xx_wdt_init(void) |
| 168 | +static int __devinit bcm47xx_wdt_probe(struct platform_device *pdev) |
| 169 | { |
| 170 | int ret; |
| 171 | + struct bcm47xx_wdt *wdt = dev_get_platdata(&pdev->dev); |
| 172 | |
| 173 | - if (bcm47xx_wdt_hw_stop() < 0) |
| 174 | - return -ENODEV; |
| 175 | + if (!wdt) |
| 176 | + return -ENXIO; |
| 177 | |
| 178 | - setup_timer(&wdt_timer, bcm47xx_timer_tick, 0L); |
| 179 | + setup_timer(&wdt->soft_timer, bcm47xx_timer_tick, |
| 180 | + (long unsigned int)wdt); |
| 181 | |
| 182 | - if (bcm47xx_wdt_settimeout(wdt_time)) { |
| 183 | - bcm47xx_wdt_settimeout(WDT_DEFAULT_TIME); |
| 184 | - pr_info("wdt_time value must be 0 < wdt_time < %d, using %d\n", |
| 185 | - (WDT_MAX_TIME + 1), wdt_time); |
| 186 | - } |
| 187 | - watchdog_set_nowayout(&bcm47xx_wdt_wdd, nowayout); |
| 188 | + wdt->wdd.ops = &bcm47xx_wdt_ops; |
| 189 | + wdt->wdd.info = &bcm47xx_wdt_info; |
| 190 | + wdt->wdd.timeout = WDT_DEFAULT_TIME; |
| 191 | + ret = wdt->wdd.ops->set_timeout(&wdt->wdd, timeout); |
| 192 | + if (ret) |
| 193 | + goto err_timer; |
| 194 | + watchdog_set_nowayout(&wdt->wdd, nowayout); |
| 195 | + |
| 196 | + wdt->notifier.notifier_call = &bcm47xx_wdt_notify_sys; |
| 197 | |
| 198 | - ret = register_reboot_notifier(&bcm47xx_wdt_notifier); |
| 199 | + ret = register_reboot_notifier(&wdt->notifier); |
| 200 | if (ret) |
| 201 | - return ret; |
| 202 | + goto err_timer; |
| 203 | |
| 204 | - ret = watchdog_register_device(&bcm47xx_wdt_wdd); |
| 205 | - if (ret) { |
| 206 | - unregister_reboot_notifier(&bcm47xx_wdt_notifier); |
| 207 | - return ret; |
| 208 | - } |
| 209 | + ret = watchdog_register_device(&wdt->wdd); |
| 210 | + if (ret) |
| 211 | + goto err_notifier; |
| 212 | |
| 213 | pr_info("BCM47xx Watchdog Timer enabled (%d seconds%s)\n", |
| 214 | wdt_time, nowayout ? ", nowayout" : ""); |
| 215 | return 0; |
| 216 | + |
| 217 | +err_notifier: |
| 218 | + unregister_reboot_notifier(&wdt->notifier); |
| 219 | +err_timer: |
| 220 | + del_timer_sync(&wdt->soft_timer); |
| 221 | + |
| 222 | + return ret; |
| 223 | } |
| 224 | |
| 225 | -static void __exit bcm47xx_wdt_exit(void) |
| 226 | +static int __devexit bcm47xx_wdt_remove(struct platform_device *pdev) |
| 227 | { |
| 228 | - watchdog_unregister_device(&bcm47xx_wdt_wdd); |
| 229 | + struct bcm47xx_wdt *wdt = dev_get_platdata(&pdev->dev); |
| 230 | + |
| 231 | + if (!wdt) |
| 232 | + return -ENXIO; |
| 233 | + |
| 234 | + watchdog_unregister_device(&wdt->wdd); |
| 235 | + unregister_reboot_notifier(&wdt->notifier); |
| 236 | |
| 237 | - unregister_reboot_notifier(&bcm47xx_wdt_notifier); |
| 238 | + return 0; |
| 239 | } |
| 240 | |
| 241 | -module_init(bcm47xx_wdt_init); |
| 242 | -module_exit(bcm47xx_wdt_exit); |
| 243 | +static struct platform_driver bcm47xx_wdt_driver = { |
| 244 | + .driver = { |
| 245 | + .owner = THIS_MODULE, |
| 246 | + .name = "bcm47xx-wdt", |
| 247 | + }, |
| 248 | + .probe = bcm47xx_wdt_probe, |
| 249 | + .remove = __devexit_p(bcm47xx_wdt_remove), |
| 250 | +}; |
| 251 | + |
| 252 | +module_platform_driver(bcm47xx_wdt_driver); |
| 253 | |
| 254 | MODULE_AUTHOR("Aleksandar Radovanovic"); |
| 255 | +MODULE_AUTHOR("Hauke Mehrtens <hauke@hauke-m.de>"); |
| 256 | MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx"); |
| 257 | MODULE_LICENSE("GPL"); |
| 258 | --- a/include/linux/bcm47xx_wdt.h |
| 259 | +++ b/include/linux/bcm47xx_wdt.h |
| 260 | @@ -1,7 +1,10 @@ |
| 261 | #ifndef LINUX_BCM47XX_WDT_H_ |
| 262 | #define LINUX_BCM47XX_WDT_H_ |
| 263 | |
| 264 | +#include <linux/notifier.h> |
| 265 | +#include <linux/timer.h> |
| 266 | #include <linux/types.h> |
| 267 | +#include <linux/watchdog.h> |
| 268 | |
| 269 | |
| 270 | struct bcm47xx_wdt { |
| 271 | @@ -10,6 +13,12 @@ struct bcm47xx_wdt { |
| 272 | u32 max_timer_ms; |
| 273 | |
| 274 | void *driver_data; |
| 275 | + |
| 276 | + struct watchdog_device wdd; |
| 277 | + struct notifier_block notifier; |
| 278 | + |
| 279 | + struct timer_list soft_timer; |
| 280 | + atomic_t soft_ticks; |
| 281 | }; |
| 282 | |
| 283 | static inline void *bcm47xx_wdt_get_drvdata(struct bcm47xx_wdt *wdt) |
| 284 | |