Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1217784 > unrolled thread

[PATCH] watchdog_dev: Use device tree alias for naming watchdogs

Started byJustin Chen <justinpopo6@gmail.com>
First post2015-09-02 20:10 +0200
Last post2015-09-02 22:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] watchdog_dev: Use device tree alias for naming watchdogs Justin Chen <justinpopo6@gmail.com> - 2015-09-02 20:10 +0200
    Re: [PATCH] watchdog_dev: Use device tree alias for naming watchdogs Guenter Roeck <linux@roeck-us.net> - 2015-09-02 22:20 +0200

#1217784 — [PATCH] watchdog_dev: Use device tree alias for naming watchdogs

FromJustin Chen <justinpopo6@gmail.com>
Date2015-09-02 20:10 +0200
Subject[PATCH] watchdog_dev: Use device tree alias for naming watchdogs
Message-ID<q4kDU-4f5-5@gated-at.bofh.it>
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>
---
 drivers/watchdog/watchdog_core.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
index 1a80594..873f139 100644
--- a/drivers/watchdog/watchdog_core.c
+++ b/drivers/watchdog/watchdog_core.c
@@ -139,7 +139,7 @@ EXPORT_SYMBOL_GPL(watchdog_init_timeout);
 
 static int __watchdog_register_device(struct watchdog_device *wdd)
 {
-	int ret, id, devno;
+	int ret, id = -1, devno;
 
 	if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
 		return -EINVAL;
@@ -157,7 +157,18 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
 	 */
 
 	mutex_init(&wdd->lock);
-	id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL);
+
+	/* Use alias for watchdog id if possible */
+	if (wdd->parent) {
+		ret = of_alias_get_id(wdd->parent->of_node, "watchdog");
+		if (ret >= 0)
+			id = ida_simple_get(&watchdog_ida, ret,
+					    ret + 1, GFP_KERNEL);
+	}
+
+	if (id < 0)
+		id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL);
+
 	if (id < 0)
 		return id;
 	wdd->id = id;
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1217839

FromGuenter Roeck <linux@roeck-us.net>
Date2015-09-02 22:20 +0200
Message-ID<q4mFH-773-17@gated-at.bofh.it>
In reply to#1217784
Hi Justin,

On Wed, Sep 02, 2015 at 11:00:17AM -0700, Justin Chen wrote:
> 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>

Minor nitpick: the changelog should be after the '---'.

Other than that, I really like it. Well done.

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

Thanks,
Guenter

> ---
>  drivers/watchdog/watchdog_core.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
> index 1a80594..873f139 100644
> --- a/drivers/watchdog/watchdog_core.c
> +++ b/drivers/watchdog/watchdog_core.c
> @@ -139,7 +139,7 @@ EXPORT_SYMBOL_GPL(watchdog_init_timeout);
>  
>  static int __watchdog_register_device(struct watchdog_device *wdd)
>  {
> -	int ret, id, devno;
> +	int ret, id = -1, devno;
>  
>  	if (wdd == NULL || wdd->info == NULL || wdd->ops == NULL)
>  		return -EINVAL;
> @@ -157,7 +157,18 @@ static int __watchdog_register_device(struct watchdog_device *wdd)
>  	 */
>  
>  	mutex_init(&wdd->lock);
> -	id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL);
> +
> +	/* Use alias for watchdog id if possible */
> +	if (wdd->parent) {
> +		ret = of_alias_get_id(wdd->parent->of_node, "watchdog");
> +		if (ret >= 0)
> +			id = ida_simple_get(&watchdog_ida, ret,
> +					    ret + 1, GFP_KERNEL);
> +	}
> +
> +	if (id < 0)
> +		id = ida_simple_get(&watchdog_ida, 0, MAX_DOGS, GFP_KERNEL);
> +
>  	if (id < 0)
>  		return id;
>  	wdd->id = id;
> -- 
> 2.1.0
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web