aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/watchdog/watchdog_core.c
diff options
context:
space:
mode:
authorAlan Cox <alan@linux.intel.com>2012-05-10 15:48:59 -0400
committerWim Van Sebroeck <wim@iguana.be>2012-05-30 01:54:25 -0400
commit45f5fed30a6460ec58f159ff297a2974153a97de (patch)
treed173b2d22ed1187fb7ed2cb85015ddf5c545da05 /drivers/watchdog/watchdog_core.c
parentfb5f6658163412dce22724e906e324ab7fd62c18 (diff)
watchdog: Add multiple device support
We keep the old /dev/watchdog interface file for the first watchdog via miscdev. This is basically a cut and paste of the relevant interface code from the rtc driver layer tweaked for watchdog. Revised to fix problems noted by Hans de Goede Signed-off-by: Alan Cox <alan@linux.intel.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/watchdog/watchdog_core.c')
-rw-r--r--drivers/watchdog/watchdog_core.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index 8598308278d..5f987936900 100644
--- a/drivers/watchdog/watchdog_core.c
+++ b/drivers/watchdog/watchdog_core.c
@@ -34,9 +34,12 @@
34#include <linux/kernel.h> /* For printk/panic/... */ 34#include <linux/kernel.h> /* For printk/panic/... */
35#include <linux/watchdog.h> /* For watchdog specific items */ 35#include <linux/watchdog.h> /* For watchdog specific items */
36#include <linux/init.h> /* For __init/__exit/... */ 36#include <linux/init.h> /* For __init/__exit/... */
37#include <linux/idr.h> /* For ida_* macros */
37 38
38#include "watchdog_core.h" /* For watchdog_dev_register/... */ 39#include "watchdog_core.h" /* For watchdog_dev_register/... */
39 40
41static DEFINE_IDA(watchdog_ida);
42
40/** 43/**
41 * watchdog_register_device() - register a watchdog device 44 * watchdog_register_device() - register a watchdog device
42 * @wdd: watchdog device 45 * @wdd: watchdog device
@@ -49,7 +52,7 @@
49 */ 52 */
50int watchdog_register_device(struct watchdog_device *wdd) 53int watchdog_register_device(struct watchdog_device *wdd)
51{ 54{
52 int ret; 55 int ret, id;
53 56
54 if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL) 57 if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
55 return -EINVAL; 58 return -EINVAL;
@@ -74,11 +77,28 @@ int watchdog_register_device(struct watchdog_device *wdd)
74 * corrupted in a later stage then we expect a kernel panic! 77 * corrupted in a later stage then we expect a kernel panic!
75 */ 78 */
76 79
77 /* We only support 1 watchdog device via the /dev/watchdog interface */ 80 id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL);
81 if (id < 0)
82 return id;
83 wdd->id = id;
84
78 ret = watchdog_dev_register(wdd); 85 ret = watchdog_dev_register(wdd);
79 if (ret) { 86 if (ret) {
80 pr_err("error registering /dev/watchdog (err=%d)\n", ret); 87 ida_simple_remove(&watchdog_ida, id);
81 return ret; 88 if (!(id == 0 && ret == -EBUSY))
89 return ret;
90
91 /* Retry in case a legacy watchdog module exists */
92 id = ida_simple_get(&watchdog_ida, 1, MAX_DOGS, GFP_KERNEL);
93 if (id < 0)
94 return id;
95 wdd->id = id;
96
97 ret = watchdog_dev_register(wdd);
98 if (ret) {
99 ida_simple_remove(&watchdog_ida, id);
100 return ret;
101 }
82 } 102 }
83 103
84 return 0; 104 return 0;
@@ -102,9 +122,24 @@ void watchdog_unregister_device(struct watchdog_device *wdd)
102 ret = watchdog_dev_unregister(wdd); 122 ret = watchdog_dev_unregister(wdd);
103 if (ret) 123 if (ret)
104 pr_err("error unregistering /dev/watchdog (err=%d)\n", ret); 124 pr_err("error unregistering /dev/watchdog (err=%d)\n", ret);
125 ida_simple_remove(&watchdog_ida, wdd->id);
105} 126}
106EXPORT_SYMBOL_GPL(watchdog_unregister_device); 127EXPORT_SYMBOL_GPL(watchdog_unregister_device);
107 128
129static int __init watchdog_init(void)
130{
131 return watchdog_dev_init();
132}
133
134static void __exit watchdog_exit(void)
135{
136 watchdog_dev_exit();
137 ida_destroy(&watchdog_ida);
138}
139
140subsys_initcall(watchdog_init);
141module_exit(watchdog_exit);
142
108MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>"); 143MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
109MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>"); 144MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
110MODULE_DESCRIPTION("WatchDog Timer Driver Core"); 145MODULE_DESCRIPTION("WatchDog Timer Driver Core");