Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

watchdog: watchdog_dev: Use device tree alias for naming watchdogs

Currently there is no way to easily differentiate multiple
watchdog devices. The watchdogs are named by the order they
are probed.
1st probed watchdog: /dev/watchdog0
2nd probed watchdog: /dev/watchdog1
...

This change uses the alias of the watchdog device node for
the name of the watchdog.
aliases {
watchdog0 = "/...../...."
watchdog3 = "/..../....."
watchdog2 = "/..../....."
...
}

This will translate to...
/dev/watchdog0
/dev/watchdog3
/dev/watchdog2

v2
Assign alias number to id in watchdog_core instead of watchdog_dev.
If failed to get id, fallback to original ida_simple_get call.

Signed-off-by: Justin Chen <justinpopo6@gmail.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

authored by

Justin Chen and committed by
Wim Van Sebroeck
9dd4e173 7a3629fe

+13 -2
+13 -2
drivers/watchdog/watchdog_core.c
··· 139 139 140 140 static int __watchdog_register_device(struct watchdog_device *wdd) 141 141 { 142 - int ret, id, devno; 142 + int ret, id = -1, devno; 143 143 144 144 if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL) 145 145 return -EINVAL; ··· 157 157 */ 158 158 159 159 mutex_init(&wdd->lock); 160 - id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL); 160 + 161 + /* Use alias for watchdog id if possible */ 162 + if (wdd->parent) { 163 + ret = of_alias_get_id(wdd->parent->of_node, "watchdog"); 164 + if (ret >= 0) 165 + id = ida_simple_get(&watchdog_ida, ret, 166 + ret + 1, GFP_KERNEL); 167 + } 168 + 169 + if (id < 0) 170 + id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL); 171 + 161 172 if (id < 0) 162 173 return id; 163 174 wdd->id = id;