All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: (lm87) Add channel data from the dts file.
@ 2016-09-05  5:36 Mahoda Ratnayaka
  2016-09-06 17:20 ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Mahoda Ratnayaka @ 2016-09-05  5:36 UTC (permalink / raw)
  To: Jean Delvare, Guenter Roeck, linux-hwmon; +Cc: Mahoda Ratnayaka, Chris Packham

Currently there is no method for setting the channel
value from the DTS file. When, the driver uses a dts
file to initialize the driver platform_data is not set.
As a the result channel variable may not be set correctly.

Without the channel variable set correctly, some of the
sensors will not be initialized correctly. For example
temp3 sensor sysfs entries.

This adds the required functionality to set the channel
variable from the DTS file. This is done via reading the
reading a property named "channel" from the lm87 driver.

Signed-off-by: Mahoda Ratnayaka <mahoda.ratnayaka@alliedtelesis.co.nz>
---
 drivers/hwmon/lm87.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index a5e2958..ac0018b 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -858,14 +858,25 @@ static void lm87_remove_files(struct i2c_client *client)
 static void lm87_init_client(struct i2c_client *client)
 {
 	struct lm87_data *data = i2c_get_clientdata(client);
+	struct device_node *np = NULL;
+	const char *channel = NULL;
+	u8 val;
 
-	if (dev_get_platdata(&client->dev)) {
+	np = client->dev.of_node;
+
+	/* Use value read from the dts file to setup channel value. */
+	if (np && of_property_read_u8(np, "channels", &val) == 0) {
+		data->channel = val;
+		lm87_write_value(client,
+				 LM87_REG_CHANNEL_MODE, data->channel);
+	} else if (dev_get_platdata(&client->dev)) {
 		data->channel = *(u8 *)dev_get_platdata(&client->dev);
 		lm87_write_value(client,
 				 LM87_REG_CHANNEL_MODE, data->channel);
 	} else {
 		data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
 	}
+
 	data->config = lm87_read_value(client, LM87_REG_CONFIG) & 0x6F;
 
 	if (!(data->config & 0x01)) {
-- 
2.9.3


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

* Re: [PATCH] hwmon: (lm87) Add channel data from the dts file.
  2016-09-05  5:36 [PATCH] hwmon: (lm87) Add channel data from the dts file Mahoda Ratnayaka
@ 2016-09-06 17:20 ` Guenter Roeck
  2016-09-07  0:17     ` Mahoda Ratnayaka
  0 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2016-09-06 17:20 UTC (permalink / raw)
  To: Mahoda Ratnayaka; +Cc: Jean Delvare, linux-hwmon, Chris Packham

On Mon, Sep 05, 2016 at 05:36:14PM +1200, Mahoda Ratnayaka wrote:
> Currently there is no method for setting the channel
> value from the DTS file. When, the driver uses a dts
> file to initialize the driver platform_data is not set.
> As a the result channel variable may not be set correctly.
> 
> Without the channel variable set correctly, some of the
> sensors will not be initialized correctly. For example
> temp3 sensor sysfs entries.
> 
> This adds the required functionality to set the channel
> variable from the DTS file. This is done via reading the
> reading a property named "channel" from the lm87 driver.
> 
Devicetree properties need to be documented and approved by devicetree
maintainers.

> Signed-off-by: Mahoda Ratnayaka <mahoda.ratnayaka@alliedtelesis.co.nz>
> ---
>  drivers/hwmon/lm87.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
> index a5e2958..ac0018b 100644
> --- a/drivers/hwmon/lm87.c
> +++ b/drivers/hwmon/lm87.c
> @@ -858,14 +858,25 @@ static void lm87_remove_files(struct i2c_client *client)
>  static void lm87_init_client(struct i2c_client *client)
>  {
>  	struct lm87_data *data = i2c_get_clientdata(client);
> +	struct device_node *np = NULL;
> +	const char *channel = NULL;
> +	u8 val;
>  
> -	if (dev_get_platdata(&client->dev)) {
> +	np = client->dev.of_node;
> +
> +	/* Use value read from the dts file to setup channel value. */

Isn't that obvious from the code ?

> +	if (np && of_property_read_u8(np, "channels", &val) == 0) {

When using a function, you need to include the file declaring it,
in this case linux/of.h. of_property_read_u8( )already checks for
np == NULL, so there is no need to check it here. Instead of "== 0",
please use "!".

> +		data->channel = val;
> +		lm87_write_value(client,
> +				 LM87_REG_CHANNEL_MODE, data->channel);
> +	} else if (dev_get_platdata(&client->dev)) {
>  		data->channel = *(u8 *)dev_get_platdata(&client->dev);
>  		lm87_write_value(client,
>  				 LM87_REG_CHANNEL_MODE, data->channel);
>  	} else {
>  		data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
>  	}
> +

Please no unnecessary whitespace changes.

>  	data->config = lm87_read_value(client, LM87_REG_CONFIG) & 0x6F;
>  
>  	if (!(data->config & 0x01)) {
> -- 
> 2.9.3
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] hwmon: (lm87) Add channel data from the dts file.
@ 2016-09-07  0:17     ` Mahoda Ratnayaka
  0 siblings, 0 replies; 5+ messages in thread
From: Mahoda Ratnayaka @ 2016-09-07  0:17 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Jean Delvare, linux-hwmon, Chris Packham, devicetree

Thanks Guenter for the comments, I'll first update the lm87 Documentation to include the
device tree information and then I'll update the documentation with my proposed update along 
with the updated patch for reading the property in the driver.

Thanks,
Mahoda
________________________________________
From: linux-hwmon-owner@vger.kernel.org <linux-hwmon-owner@vger.kernel.org> on behalf of Guenter Roeck <linux@roeck-us.net>
Sent: Wednesday, 7 September 2016 5:20 a.m.
To: Mahoda Ratnayaka
Cc: Jean Delvare; linux-hwmon@vger.kernel.org; Chris Packham
Subject: Re: [PATCH] hwmon: (lm87) Add channel data from the dts file.

On Mon, Sep 05, 2016 at 05:36:14PM +1200, Mahoda Ratnayaka wrote:
> Currently there is no method for setting the channel
> value from the DTS file. When, the driver uses a dts
> file to initialize the driver platform_data is not set.
> As a the result channel variable may not be set correctly.
>
> Without the channel variable set correctly, some of the
> sensors will not be initialized correctly. For example
> temp3 sensor sysfs entries.
>
> This adds the required functionality to set the channel
> variable from the DTS file. This is done via reading the
> reading a property named "channel" from the lm87 driver.
>
Devicetree properties need to be documented and approved by devicetree
maintainers.

> Signed-off-by: Mahoda Ratnayaka <mahoda.ratnayaka@alliedtelesis.co.nz>
> ---
>  drivers/hwmon/lm87.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
> index a5e2958..ac0018b 100644
> --- a/drivers/hwmon/lm87.c
> +++ b/drivers/hwmon/lm87.c
> @@ -858,14 +858,25 @@ static void lm87_remove_files(struct i2c_client *client)
>  static void lm87_init_client(struct i2c_client *client)
>  {
>       struct lm87_data *data = i2c_get_clientdata(client);
> +     struct device_node *np = NULL;
> +     const char *channel = NULL;
> +     u8 val;
>
> -     if (dev_get_platdata(&client->dev)) {
> +     np = client->dev.of_node;
> +
> +     /* Use value read from the dts file to setup channel value. */

Isn't that obvious from the code ?

> +     if (np && of_property_read_u8(np, "channels", &val) == 0) {

When using a function, you need to include the file declaring it,
in this case linux/of.h. of_property_read_u8( )already checks for
np == NULL, so there is no need to check it here. Instead of "== 0",
please use "!".

> +             data->channel = val;
> +             lm87_write_value(client,
> +                              LM87_REG_CHANNEL_MODE, data->channel);
> +     } else if (dev_get_platdata(&client->dev)) {
>               data->channel = *(u8 *)dev_get_platdata(&client->dev);
>               lm87_write_value(client,
>                                LM87_REG_CHANNEL_MODE, data->channel);
>       } else {
>               data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
>       }
> +

Please no unnecessary whitespace changes.

>       data->config = lm87_read_value(client, LM87_REG_CONFIG) & 0x6F;
>
>       if (!(data->config & 0x01)) {
> --
> 2.9.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] hwmon: (lm87) Add channel data from the dts file.
@ 2016-09-07  0:17     ` Mahoda Ratnayaka
  0 siblings, 0 replies; 5+ messages in thread
From: Mahoda Ratnayaka @ 2016-09-07  0:17 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Jean Delvare, linux-hwmon-u79uwXL29TY76Z2rM5mHXA, Chris Packham,
	devicetree-u79uwXL29TY76Z2rM5mHXA

Thanks Guenter for the comments, I'll first update the lm87 Documentation to include the
device tree information and then I'll update the documentation with my proposed update along 
with the updated patch for reading the property in the driver.

Thanks,
Mahoda
________________________________________
From: linux-hwmon-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org <linux-hwmon-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org> on behalf of Guenter Roeck <linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org>
Sent: Wednesday, 7 September 2016 5:20 a.m.
To: Mahoda Ratnayaka
Cc: Jean Delvare; linux-hwmon-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; Chris Packham
Subject: Re: [PATCH] hwmon: (lm87) Add channel data from the dts file.

On Mon, Sep 05, 2016 at 05:36:14PM +1200, Mahoda Ratnayaka wrote:
> Currently there is no method for setting the channel
> value from the DTS file. When, the driver uses a dts
> file to initialize the driver platform_data is not set.
> As a the result channel variable may not be set correctly.
>
> Without the channel variable set correctly, some of the
> sensors will not be initialized correctly. For example
> temp3 sensor sysfs entries.
>
> This adds the required functionality to set the channel
> variable from the DTS file. This is done via reading the
> reading a property named "channel" from the lm87 driver.
>
Devicetree properties need to be documented and approved by devicetree
maintainers.

> Signed-off-by: Mahoda Ratnayaka <mahoda.ratnayaka-6g8wRflRTwXFdCa3tKVlE6U/zSkkHjvu@public.gmane.org>
> ---
>  drivers/hwmon/lm87.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
> index a5e2958..ac0018b 100644
> --- a/drivers/hwmon/lm87.c
> +++ b/drivers/hwmon/lm87.c
> @@ -858,14 +858,25 @@ static void lm87_remove_files(struct i2c_client *client)
>  static void lm87_init_client(struct i2c_client *client)
>  {
>       struct lm87_data *data = i2c_get_clientdata(client);
> +     struct device_node *np = NULL;
> +     const char *channel = NULL;
> +     u8 val;
>
> -     if (dev_get_platdata(&client->dev)) {
> +     np = client->dev.of_node;
> +
> +     /* Use value read from the dts file to setup channel value. */

Isn't that obvious from the code ?

> +     if (np && of_property_read_u8(np, "channels", &val) == 0) {

When using a function, you need to include the file declaring it,
in this case linux/of.h. of_property_read_u8( )already checks for
np == NULL, so there is no need to check it here. Instead of "== 0",
please use "!".

> +             data->channel = val;
> +             lm87_write_value(client,
> +                              LM87_REG_CHANNEL_MODE, data->channel);
> +     } else if (dev_get_platdata(&client->dev)) {
>               data->channel = *(u8 *)dev_get_platdata(&client->dev);
>               lm87_write_value(client,
>                                LM87_REG_CHANNEL_MODE, data->channel);
>       } else {
>               data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
>       }
> +

Please no unnecessary whitespace changes.

>       data->config = lm87_read_value(client, LM87_REG_CONFIG) & 0x6F;
>
>       if (!(data->config & 0x01)) {
> --
> 2.9.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] hwmon: (lm87) Add channel data from the dts file.
  2016-09-07  0:17     ` Mahoda Ratnayaka
  (?)
@ 2016-09-07  1:35     ` Guenter Roeck
  -1 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2016-09-07  1:35 UTC (permalink / raw)
  To: Mahoda Ratnayaka; +Cc: Jean Delvare, linux-hwmon, Chris Packham, devicetree

On 09/06/2016 05:17 PM, Mahoda Ratnayaka wrote:
> Thanks Guenter for the comments, I'll first update the lm87 Documentation to include the
> device tree information and then I'll update the documentation with my proposed update along
> with the updated patch for reading the property in the driver.
>

Devicetree documentation needs to be a new file in Documentation/devicetree/bindings/hwmon/.

Thanks,
Guenter

> Thanks,
> Mahoda
> ________________________________________
> From: linux-hwmon-owner@vger.kernel.org <linux-hwmon-owner@vger.kernel.org> on behalf of Guenter Roeck <linux@roeck-us.net>
> Sent: Wednesday, 7 September 2016 5:20 a.m.
> To: Mahoda Ratnayaka
> Cc: Jean Delvare; linux-hwmon@vger.kernel.org; Chris Packham
> Subject: Re: [PATCH] hwmon: (lm87) Add channel data from the dts file.
>
> On Mon, Sep 05, 2016 at 05:36:14PM +1200, Mahoda Ratnayaka wrote:
>> Currently there is no method for setting the channel
>> value from the DTS file. When, the driver uses a dts
>> file to initialize the driver platform_data is not set.
>> As a the result channel variable may not be set correctly.
>>
>> Without the channel variable set correctly, some of the
>> sensors will not be initialized correctly. For example
>> temp3 sensor sysfs entries.
>>
>> This adds the required functionality to set the channel
>> variable from the DTS file. This is done via reading the
>> reading a property named "channel" from the lm87 driver.
>>
> Devicetree properties need to be documented and approved by devicetree
> maintainers.
>
>> Signed-off-by: Mahoda Ratnayaka <mahoda.ratnayaka@alliedtelesis.co.nz>
>> ---
>>  drivers/hwmon/lm87.c | 13 ++++++++++++-
>>  1 file changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
>> index a5e2958..ac0018b 100644
>> --- a/drivers/hwmon/lm87.c
>> +++ b/drivers/hwmon/lm87.c
>> @@ -858,14 +858,25 @@ static void lm87_remove_files(struct i2c_client *client)
>>  static void lm87_init_client(struct i2c_client *client)
>>  {
>>       struct lm87_data *data = i2c_get_clientdata(client);
>> +     struct device_node *np = NULL;
>> +     const char *channel = NULL;
>> +     u8 val;
>>
>> -     if (dev_get_platdata(&client->dev)) {
>> +     np = client->dev.of_node;
>> +
>> +     /* Use value read from the dts file to setup channel value. */
>
> Isn't that obvious from the code ?
>
>> +     if (np && of_property_read_u8(np, "channels", &val) == 0) {
>
> When using a function, you need to include the file declaring it,
> in this case linux/of.h. of_property_read_u8( )already checks for
> np == NULL, so there is no need to check it here. Instead of "== 0",
> please use "!".
>
>> +             data->channel = val;
>> +             lm87_write_value(client,
>> +                              LM87_REG_CHANNEL_MODE, data->channel);
>> +     } else if (dev_get_platdata(&client->dev)) {
>>               data->channel = *(u8 *)dev_get_platdata(&client->dev);
>>               lm87_write_value(client,
>>                                LM87_REG_CHANNEL_MODE, data->channel);
>>       } else {
>>               data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
>>       }
>> +
>
> Please no unnecessary whitespace changes.
>
>>       data->config = lm87_read_value(client, LM87_REG_CONFIG) & 0x6F;
>>
>>       if (!(data->config & 0x01)) {
>> --
>> 2.9.3
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


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

end of thread, other threads:[~2016-09-07  1:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-05  5:36 [PATCH] hwmon: (lm87) Add channel data from the dts file Mahoda Ratnayaka
2016-09-06 17:20 ` Guenter Roeck
2016-09-07  0:17   ` Mahoda Ratnayaka
2016-09-07  0:17     ` Mahoda Ratnayaka
2016-09-07  1:35     ` 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.