All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] watchdog_dev: Use device tree alias for naming watchdogs
@ 2015-09-02 18:00 Justin Chen
  2015-09-02 20:19 ` Guenter Roeck
  2015-10-27 15:47 ` Wim Van Sebroeck
  0 siblings, 2 replies; 7+ messages in thread
From: Justin Chen @ 2015-09-02 18:00 UTC (permalink / raw)
  To: linux-kernel
  Cc: wim, linux-watchdog, linux, bcm-kernel-feedback-list, 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 = "/..../....."
    ...
}

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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] watchdog_dev: Use device tree alias for naming watchdogs
  2015-09-02 18:00 [PATCH] watchdog_dev: Use device tree alias for naming watchdogs Justin Chen
@ 2015-09-02 20:19 ` Guenter Roeck
  2015-10-27 15:47 ` Wim Van Sebroeck
  1 sibling, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2015-09-02 20:19 UTC (permalink / raw)
  To: Justin Chen; +Cc: linux-kernel, wim, linux-watchdog, bcm-kernel-feedback-list

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
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] watchdog_dev: Use device tree alias for naming watchdogs
  2015-09-02 18:00 [PATCH] watchdog_dev: Use device tree alias for naming watchdogs Justin Chen
  2015-09-02 20:19 ` Guenter Roeck
@ 2015-10-27 15:47 ` Wim Van Sebroeck
  1 sibling, 0 replies; 7+ messages in thread
From: Wim Van Sebroeck @ 2015-10-27 15:47 UTC (permalink / raw)
  To: Justin Chen; +Cc: linux-kernel, linux-watchdog, linux, bcm-kernel-feedback-list

Hi Justin,

> 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
> 

Added to linux-watchdog-next.

Kind regards,
Wim.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] watchdog_dev: Use device tree alias for naming watchdogs
  2015-09-01 17:20   ` Justin Chen
@ 2015-09-01 17:53     ` Guenter Roeck
  0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2015-09-01 17:53 UTC (permalink / raw)
  To: Justin Chen; +Cc: linux-kernel, wim, linux-watchdog, bcm-kernel-feedback-list

On Tue, Sep 01, 2015 at 10:20:36AM -0700, Justin Chen wrote:
> On Sat, Aug 29, 2015 at 2:53 AM, Guenter Roeck <linux@roeck-us.net> wrote:
> > On 08/28/2015 02:58 PM, 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
> >>
> >> Signed-off-by: Justin Chen <justinpopo6@gmail.com>
> >
> >
> > 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
> 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] watchdog_dev: Use device tree alias for naming watchdogs
  2015-08-29  9:53 ` Guenter Roeck
@ 2015-09-01 17:20   ` Justin Chen
  2015-09-01 17:53     ` Guenter Roeck
  0 siblings, 1 reply; 7+ messages in thread
From: Justin Chen @ 2015-09-01 17:20 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-kernel, wim, linux-watchdog, bcm-kernel-feedback-list

[-- Attachment #1: Type: text/plain, Size: 2762 bytes --]

On Sat, Aug 29, 2015 at 2:53 AM, Guenter Roeck <linux@roeck-us.net> wrote:
> On 08/28/2015 02:58 PM, 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
>>
>> Signed-off-by: Justin Chen <justinpopo6@gmail.com>
>
>
> 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

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


>
>
>> ---
>>   drivers/watchdog/watchdog_dev.c | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/watchdog/watchdog_dev.c
>> b/drivers/watchdog/watchdog_dev.c
>> index 6aaefba..52b1f0b 100644
>> --- a/drivers/watchdog/watchdog_dev.c
>> +++ b/drivers/watchdog/watchdog_dev.c
>> @@ -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;
>>
>

[-- Attachment #2: Type: text/html, Size: 3776 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] watchdog_dev: Use device tree alias for naming watchdogs
  2015-08-28 21:58 Justin Chen
@ 2015-08-29  9:53 ` Guenter Roeck
  2015-09-01 17:20   ` Justin Chen
  0 siblings, 1 reply; 7+ messages in thread
From: Guenter Roeck @ 2015-08-29  9:53 UTC (permalink / raw)
  To: Justin Chen, linux-kernel; +Cc: wim, linux-watchdog, bcm-kernel-feedback-list

On 08/28/2015 02:58 PM, 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
>
> Signed-off-by: Justin Chen <justinpopo6@gmail.com>

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

> ---
>   drivers/watchdog/watchdog_dev.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
> index 6aaefba..52b1f0b 100644
> --- a/drivers/watchdog/watchdog_dev.c
> +++ b/drivers/watchdog/watchdog_dev.c
> @@ -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;
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] watchdog_dev: Use device tree alias for naming watchdogs
@ 2015-08-28 21:58 Justin Chen
  2015-08-29  9:53 ` Guenter Roeck
  0 siblings, 1 reply; 7+ messages in thread
From: Justin Chen @ 2015-08-28 21:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: wim, linux-watchdog, bcm-kernel-feedback-list, 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 = "/..../....."
	...
}

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

Signed-off-by: Justin Chen <justinpopo6@gmail.com>
---
 drivers/watchdog/watchdog_dev.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index 6aaefba..52b1f0b 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -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;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-10-27 15:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-02 18:00 [PATCH] watchdog_dev: Use device tree alias for naming watchdogs Justin Chen
2015-09-02 20:19 ` Guenter Roeck
2015-10-27 15:47 ` Wim Van Sebroeck
  -- strict thread matches above, loose matches on Subject: below --
2015-08-28 21:58 Justin Chen
2015-08-29  9:53 ` Guenter Roeck
2015-09-01 17:20   ` Justin Chen
2015-09-01 17:53     ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.