diff options
| author | Hauke Mehrtens <hauke@hauke-m.de> | 2013-01-12 12:14:07 -0500 |
|---|---|---|
| committer | Wim Van Sebroeck <wim@iguana.be> | 2013-03-01 06:47:13 -0500 |
| commit | 5434a04db905bb0af281cdb758d1357fbecd0fe8 (patch) | |
| tree | b87b6045e6d308a495e70be16564e879061f3bb9 | |
| parent | 52e5cc4efa576223174ad4c08a335802a36cb18c (diff) | |
watchdog: bcm47xx_wdt.c: convert to watchdog core api
Convert the bcm47xx_wdt.c driver to the new watchdog core api.
The nowayout parameter is now added unconditionally to the module.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
| -rw-r--r-- | drivers/watchdog/Kconfig | 1 | ||||
| -rw-r--r-- | drivers/watchdog/bcm47xx_wdt.c | 152 |
2 files changed, 23 insertions, 130 deletions
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index beded63689d1..f3aae8ccb6f0 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig | |||
| @@ -997,6 +997,7 @@ config ATH79_WDT | |||
| 997 | config BCM47XX_WDT | 997 | config BCM47XX_WDT |
| 998 | tristate "Broadcom BCM47xx Watchdog Timer" | 998 | tristate "Broadcom BCM47xx Watchdog Timer" |
| 999 | depends on BCM47XX | 999 | depends on BCM47XX |
| 1000 | select WATCHDOG_CORE | ||
| 1000 | help | 1001 | help |
| 1001 | Hardware driver for the Broadcom BCM47xx Watchdog Timer. | 1002 | Hardware driver for the Broadcom BCM47xx Watchdog Timer. |
| 1002 | 1003 | ||
diff --git a/drivers/watchdog/bcm47xx_wdt.c b/drivers/watchdog/bcm47xx_wdt.c index bc0e91e78e86..4c520d68397e 100644 --- a/drivers/watchdog/bcm47xx_wdt.c +++ b/drivers/watchdog/bcm47xx_wdt.c | |||
| @@ -14,15 +14,12 @@ | |||
| 14 | 14 | ||
| 15 | #include <linux/bitops.h> | 15 | #include <linux/bitops.h> |
| 16 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
| 17 | #include <linux/fs.h> | ||
| 18 | #include <linux/init.h> | 17 | #include <linux/init.h> |
| 19 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
| 20 | #include <linux/miscdevice.h> | ||
| 21 | #include <linux/module.h> | 19 | #include <linux/module.h> |
| 22 | #include <linux/moduleparam.h> | 20 | #include <linux/moduleparam.h> |
| 23 | #include <linux/reboot.h> | 21 | #include <linux/reboot.h> |
| 24 | #include <linux/types.h> | 22 | #include <linux/types.h> |
| 25 | #include <linux/uaccess.h> | ||
| 26 | #include <linux/watchdog.h> | 23 | #include <linux/watchdog.h> |
| 27 | #include <linux/timer.h> | 24 | #include <linux/timer.h> |
| 28 | #include <linux/jiffies.h> | 25 | #include <linux/jiffies.h> |
| @@ -41,15 +38,11 @@ module_param(wdt_time, int, 0); | |||
| 41 | MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default=" | 38 | MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default=" |
| 42 | __MODULE_STRING(WDT_DEFAULT_TIME) ")"); | 39 | __MODULE_STRING(WDT_DEFAULT_TIME) ")"); |
| 43 | 40 | ||
| 44 | #ifdef CONFIG_WATCHDOG_NOWAYOUT | ||
| 45 | module_param(nowayout, bool, 0); | 41 | module_param(nowayout, bool, 0); |
| 46 | MODULE_PARM_DESC(nowayout, | 42 | MODULE_PARM_DESC(nowayout, |
| 47 | "Watchdog cannot be stopped once started (default=" | 43 | "Watchdog cannot be stopped once started (default=" |
| 48 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | 44 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
| 49 | #endif | ||
| 50 | 45 | ||
| 51 | static unsigned long bcm47xx_wdt_busy; | ||
| 52 | static char expect_release; | ||
| 53 | static struct timer_list wdt_timer; | 46 | static struct timer_list wdt_timer; |
| 54 | static atomic_t ticks; | 47 | static atomic_t ticks; |
| 55 | 48 | ||
| @@ -97,29 +90,31 @@ static void bcm47xx_timer_tick(unsigned long unused) | |||
| 97 | } | 90 | } |
| 98 | } | 91 | } |
| 99 | 92 | ||
| 100 | static inline void bcm47xx_wdt_pet(void) | 93 | static int bcm47xx_wdt_keepalive(struct watchdog_device *wdd) |
| 101 | { | 94 | { |
| 102 | atomic_set(&ticks, wdt_time); | 95 | atomic_set(&ticks, wdt_time); |
| 96 | |||
| 97 | return 0; | ||
| 103 | } | 98 | } |
| 104 | 99 | ||
| 105 | static void bcm47xx_wdt_start(void) | 100 | static int bcm47xx_wdt_start(struct watchdog_device *wdd) |
| 106 | { | 101 | { |
| 107 | bcm47xx_wdt_pet(); | 102 | bcm47xx_wdt_pet(); |
| 108 | bcm47xx_timer_tick(0); | 103 | bcm47xx_timer_tick(0); |
| 104 | |||
| 105 | return 0; | ||
| 109 | } | 106 | } |
| 110 | 107 | ||
| 111 | static void bcm47xx_wdt_pause(void) | 108 | static int bcm47xx_wdt_stop(struct watchdog_device *wdd) |
| 112 | { | 109 | { |
| 113 | del_timer_sync(&wdt_timer); | 110 | del_timer_sync(&wdt_timer); |
| 114 | bcm47xx_wdt_hw_stop(); | 111 | bcm47xx_wdt_hw_stop(); |
| 115 | } | ||
| 116 | 112 | ||
| 117 | static void bcm47xx_wdt_stop(void) | 113 | return 0; |
| 118 | { | ||
| 119 | bcm47xx_wdt_pause(); | ||
| 120 | } | 114 | } |
| 121 | 115 | ||
| 122 | static int bcm47xx_wdt_settimeout(int new_time) | 116 | static int bcm47xx_wdt_set_timeout(struct watchdog_device *wdd, |
| 117 | unsigned int new_time) | ||
| 123 | { | 118 | { |
| 124 | if ((new_time <= 0) || (new_time > WDT_MAX_TIME)) | 119 | if ((new_time <= 0) || (new_time > WDT_MAX_TIME)) |
| 125 | return -EINVAL; | 120 | return -EINVAL; |
| @@ -128,51 +123,6 @@ static int bcm47xx_wdt_settimeout(int new_time) | |||
| 128 | return 0; | 123 | return 0; |
| 129 | } | 124 | } |
| 130 | 125 | ||
| 131 | static int bcm47xx_wdt_open(struct inode *inode, struct file *file) | ||
| 132 | { | ||
| 133 | if (test_and_set_bit(0, &bcm47xx_wdt_busy)) | ||
| 134 | return -EBUSY; | ||
| 135 | |||
| 136 | bcm47xx_wdt_start(); | ||
| 137 | return nonseekable_open(inode, file); | ||
| 138 | } | ||
| 139 | |||
| 140 | static int bcm47xx_wdt_release(struct inode *inode, struct file *file) | ||
| 141 | { | ||
| 142 | if (expect_release == 42) { | ||
| 143 | bcm47xx_wdt_stop(); | ||
| 144 | } else { | ||
| 145 | pr_crit("Unexpected close, not stopping watchdog!\n"); | ||
| 146 | bcm47xx_wdt_start(); | ||
| 147 | } | ||
| 148 | |||
| 149 | clear_bit(0, &bcm47xx_wdt_busy); | ||
| 150 | expect_release = 0; | ||
| 151 | return 0; | ||
| 152 | } | ||
| 153 | |||
| 154 | static ssize_t bcm47xx_wdt_write(struct file *file, const char __user *data, | ||
| 155 | size_t len, loff_t *ppos) | ||
| 156 | { | ||
| 157 | if (len) { | ||
| 158 | if (!nowayout) { | ||
| 159 | size_t i; | ||
| 160 | |||
| 161 | expect_release = 0; | ||
| 162 | |||
| 163 | for (i = 0; i != len; i++) { | ||
| 164 | char c; | ||
| 165 | if (get_user(c, data + i)) | ||
| 166 | return -EFAULT; | ||
| 167 | if (c == 'V') | ||
| 168 | expect_release = 42; | ||
| 169 | } | ||
| 170 | } | ||
| 171 | bcm47xx_wdt_pet(); | ||
| 172 | } | ||
| 173 | return len; | ||
| 174 | } | ||
| 175 | |||
| 176 | static const struct watchdog_info bcm47xx_wdt_info = { | 126 | static const struct watchdog_info bcm47xx_wdt_info = { |
| 177 | .identity = DRV_NAME, | 127 | .identity = DRV_NAME, |
| 178 | .options = WDIOF_SETTIMEOUT | | 128 | .options = WDIOF_SETTIMEOUT | |
| @@ -180,80 +130,25 @@ static const struct watchdog_info bcm47xx_wdt_info = { | |||
| 180 | WDIOF_MAGICCLOSE, | 130 | WDIOF_MAGICCLOSE, |
| 181 | }; | 131 | }; |
| 182 | 132 | ||
| 183 | static long bcm47xx_wdt_ioctl(struct file *file, | ||
| 184 | unsigned int cmd, unsigned long arg) | ||
| 185 | { | ||
| 186 | void __user *argp = (void __user *)arg; | ||
| 187 | int __user *p = argp; | ||
| 188 | int new_value, retval = -EINVAL; | ||
| 189 | |||
| 190 | switch (cmd) { | ||
| 191 | case WDIOC_GETSUPPORT: | ||
| 192 | return copy_to_user(argp, &bcm47xx_wdt_info, | ||
| 193 | sizeof(bcm47xx_wdt_info)) ? -EFAULT : 0; | ||
| 194 | |||
| 195 | case WDIOC_GETSTATUS: | ||
| 196 | case WDIOC_GETBOOTSTATUS: | ||
| 197 | return put_user(0, p); | ||
| 198 | |||
| 199 | case WDIOC_SETOPTIONS: | ||
| 200 | if (get_user(new_value, p)) | ||
| 201 | return -EFAULT; | ||
| 202 | |||
| 203 | if (new_value & WDIOS_DISABLECARD) { | ||
| 204 | bcm47xx_wdt_stop(); | ||
| 205 | retval = 0; | ||
| 206 | } | ||
| 207 | |||
| 208 | if (new_value & WDIOS_ENABLECARD) { | ||
| 209 | bcm47xx_wdt_start(); | ||
| 210 | retval = 0; | ||
| 211 | } | ||
