summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleksij Rempel <o.rempel@pengutronix.de>2018-03-13 09:33:25 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-03-23 07:35:24 +0100
commit65a644388e845bde01215bf378d4df2a6a260a6a (patch)
tree3ccbaa7637c5991eff52f91b61fa967842282a52
parent1ef7cd07a304cbc485329d68ad64a0b83936ce6e (diff)
downloadbarebox-65a644388e845bde01215bf378d4df2a6a260a6a.tar.gz
barebox-65a644388e845bde01215bf378d4df2a6a260a6a.tar.xz
watchdog: register watchdog virtual device with short name wdog
the watchdog hwdev is usually named with devicetree schema which is not practical for CLI. On device registration "wdog" will be extended with some index number extracted from devicetree (if awailable) or automatically assigned first available number. End result will be "wdog0" .. etc. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/watchdog/wd_core.c24
-rw-r--r--include/watchdog.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index 56436e6f8d..de1f4c7327 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -31,8 +31,31 @@ static const char *watchdog_name(struct watchdog *wd)
return "unknown";
}
+static int watchdog_register_dev(struct watchdog *wd, const char *name, int id)
+{
+ wd->dev.parent = wd->hwdev;
+ wd->dev.id = id;
+ strncpy(wd->dev.name, name, MAX_DRIVER_NAME);
+
+ return register_device(&wd->dev);
+}
+
int watchdog_register(struct watchdog *wd)
{
+ struct param_d *p;
+ const char *alias;
+ int ret = 0;
+
+ alias = of_alias_get(wd->hwdev->device_node);
+ if (alias)
+ ret = watchdog_register_dev(wd, alias, DEVICE_ID_SINGLE);
+
+ if (!alias || ret)
+ ret = watchdog_register_dev(wd, "wdog", DEVICE_ID_DYNAMIC);
+
+ if (ret)
+ return ret;
+
if (!wd->priority)
wd->priority = WATCHDOG_DEFAULT_PRIORITY;
@@ -47,6 +70,7 @@ EXPORT_SYMBOL(watchdog_register);
int watchdog_deregister(struct watchdog *wd)
{
+ unregister_device(&wd->dev);
list_del(&wd->list);
return 0;
diff --git a/include/watchdog.h b/include/watchdog.h
index 848981cc0d..75964178b1 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -17,6 +17,7 @@ struct watchdog {
int (*set_timeout)(struct watchdog *, unsigned);
const char *name;
struct device_d *hwdev;
+ struct device_d dev;
unsigned int priority;
struct list_head list;
};