watchdog_dev: Use device tree alias for naming watchdogs
PATCH 1/1 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
--- drivers/watchdog/watchdog_dev.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/watchdog/watchdog_dev.c +8 -1
@@ -41,6 +41,7 @@#include <linux/miscdevice.h> /* For handling misc devices */ #include <linux/init.h> /* For __init/__exit/... */ #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ +#include <linux/of.h> #include "watchdog_core.h"
@@ -522,7 +523,13 @@ static struct miscdevice watchdog_miscdev = {int watchdog_dev_register (struct watchdog_device *watchdog) { -int err, devno; +int err, devno, ret; + +if (watchdog->parent) { + ret =of_alias_get_id (watchdog->parent->of_node,"watchdog" ); +if (ret >=0 ) + watchdog->id = ret; + }if (watchdog->id ==0 ) { old_wdd = watchdog;
Signature · 1 line
2.1.0
Guenter Roeck
maintainerQuoted 16 lines · Justin Chen
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 = "/..../....." ... }
Quoted 6 lines
This will translate to...
/dev/watchdog0/dev/watchdog3/dev/watchdog2Signed-off-by Justin Chen <[email protected]>
Interesting idea. Checking through other subsystems, many others do the same, so it makes sense to use that mechanism.
However, the id assignment should be in the calling code, in __watchdog_register_device, to avoid that another id, possibly conflicting, is assigned through the ida mechanism.
This is a bit more complicated than it looks like to ensure correct id assignment. Have a look into the i2c code to see how it is handled. Essentially we must pass the requested number to ida_simple_get().
Thanks,
Guenter
Quoted 32 lines
--- drivers/watchdog/watchdog_dev.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/watchdog/watchdog_dev.c +8
-1@@ -41,6 +41,7 @@#include <linux/miscdevice.h> /* For handling misc devices */ #include <linux/init.h> /* For __init/__exit/... */ #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ +#include <linux/of.h> #include "watchdog_core.h" @@ -522,7 +523,13 @@ static struct miscdevice watchdog_miscdev = {int watchdog_dev_register (struct watchdog_device *watchdog) { -int err, devno; +int err, devno, ret; + +if (watchdog->parent) { + ret =of_alias_get_id (watchdog->parent->of_node,"watchdog" ); +if (ret >=0 ) + watchdog->id = ret; + }if (watchdog->id ==0 ) { old_wdd = watchdog;
Quoted 26 lines · Guenter Roeck
Quoted 17 lines · Justin Chen
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 = "/..../....." ... }Quoted 6 lines
This will translate to...
/dev/watchdog0/dev/watchdog3/dev/watchdog2Signed-off-by Justin Chen <[email protected]>
Quoted 7 lines
Interesting idea. Checking through other subsystems, many others do the same,
so it makes sense to use that mechanism.However, the id assignment should be in the calling code, in
__watchdog_register_device,
to avoid that another id, possibly conflicting, is assigned through the
ida
Quoted 5 lines
mechanism.
This is a bit more complicated than it looks like to ensure correct id assignment.
Have a look into the i2c code to see how it is handled. Essentially we
must
Quoted 5 lines
pass
the requested number toida_simple_get().Thanks,
Guenter
Ok that makes sense. I will put a wrapper function around ida_simple_get() that will request a specific number, if that fails then do a normal request. Something like this...
ret = of_alias_get_id(....)
id = ida_simple_get(&watchdog_ida, ret, ret, GFP_KERNEL);
if (id != ret)
id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KENREL);
thanks,
Justin
Quoted 37 lines
Quoted 36 lines
--- drivers/watchdog/watchdog_dev.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/watchdog/watchdog_dev.c +8
-1@@ -41,6 +41,7 @@#include <linux/miscdevice.h> /* For handling misc devices */ #include <linux/init.h> /* For __init/__exit/... */ #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ +#include <linux/of.h> #include "watchdog_core.h" @@ -522,7 +523,13 @@ static struct miscdevice watchdog_miscdev = {int watchdog_dev_register (struct watchdog_device *watchdog) { -int err, devno; +int err, devno, ret; + +if (watchdog->parent) { + ret =of_alias_get_id (watchdog->parent->of_node,"watchdog" ); +if (ret >=0 ) + watchdog->id = ret; + }if (watchdog->id ==0 ) {old_wdd = watchdog;
Guenter Roeck
maintainerQuoted 47 lines · Justin Chen
Quoted 26 lines · Guenter Roeck
Quoted 17 lines · Justin Chen
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 = "/..../....." ... }Quoted 6 lines
This will translate to...
/dev/watchdog0/dev/watchdog3/dev/watchdog2Signed-off-by Justin Chen <[email protected]>Quoted 7 lines
Interesting idea. Checking through other subsystems, many others do the same,
so it makes sense to use that mechanism.However, the id assignment should be in the calling code, in
__watchdog_register_device,
to avoid that another id, possibly conflicting, is assigned through theida
Quoted 5 lines
mechanism.
This is a bit more complicated than it looks like to ensure correct id assignment.
Have a look into the i2c code to see how it is handled. Essentially wemust
Quoted 5 lines
pass
the requested number toida_simple_get().Thanks,
Guenter
Quoted 8 lines
Ok that makes sense. I will put a wrapper function around
ida_simple_get()that will request a specific number, if that fails then do a normal request. Something like this...ret =
of_alias_get_id(....)id =
ida_simple_get(&watchdog_ida, ret, ret, GFP_KERNEL);
ret, ret + 1
but something like
ret = of_alias_get_id(...); if (ret >= 0) id = ida_simple_get(&watchdog_ida, ret, ret + 1, GFP_KERNEL); else id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL); if (id < 0) return id;
would be better. Passing 'ret' directly would not work, because ida_simple_get() expects an unsigned range as parameters, and of_alias_get_id() can return a negative error code.
Thanks,
Guenter