diff mbox series

[v5,3/9] hwmon: (tmp421) support disabling channels from DT

Message ID a85d623f0792b862870933a875bdf802f4c017f1.1634206677.git.krzysztof.adamski@nokia.com (mailing list archive)
State Accepted
Headers show
Series Add per channel properies support in tmp421 | expand

Commit Message

Krzysztof Adamski Oct. 14, 2021, 1:01 p.m. UTC
The previous patch introduced per channel subnodes in DT that let us
specify some channel specific properties. This built a ground for easily
disabling individual channels of the sensor that may not be connected to
any external diode and thus are not returning any meaningful data.

This patch adds support for parsing the "status" property of channels DT
subnodes and makes sure the -ENODATA is returned when disabled channels
value is read.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
  drivers/hwmon/tmp421.c | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Guenter Roeck Oct. 15, 2021, 10:47 p.m. UTC | #1
On Thu, Oct 14, 2021 at 03:01:09PM +0200, Krzysztof Adamski wrote:
> The previous patch introduced per channel subnodes in DT that let us
> specify some channel specific properties. This built a ground for easily
> disabling individual channels of the sensor that may not be connected to
> any external diode and thus are not returning any meaningful data.
> 
> This patch adds support for parsing the "status" property of channels DT
> subnodes and makes sure the -ENODATA is returned when disabled channels
> value is read.
> 
> Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>

Same problem as with patch 2/9. Any idea what happened ?

Anyway, applied after fixing it up.

Guenter

> ---
>  drivers/hwmon/tmp421.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
> index 89346ca6c9a9..af08bc985a13 100644
> --- a/drivers/hwmon/tmp421.c
> +++ b/drivers/hwmon/tmp421.c
> @@ -89,6 +89,7 @@ MODULE_DEVICE_TABLE(of, tmp421_of_match);
>  
>  struct tmp421_channel {
>  	const char *label;
> +	bool enabled;
>  	s16 temp;
>  };
>  
> @@ -170,6 +171,9 @@ static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
>  	if (ret)
>  		return ret;
>  
> +	if (!tmp421->channel[channel].enabled)
> +		return -ENODATA;
> +
>  	switch (attr) {
>  	case hwmon_temp_input:
>  		*val = temp_from_raw(tmp421->channel[channel].temp,
> @@ -323,6 +327,8 @@ static int tmp421_probe_child_from_dt(struct i2c_client *client,
>  	if (data->channel[i].label)
>  		data->temp_config[i] |= HWMON_T_LABEL;
>  
> +	data->channel[i].enabled = of_device_is_available(child);
> +
>  	return 0;
>  }
>  
> @@ -371,8 +377,10 @@ static int tmp421_probe(struct i2c_client *client)
>  	if (err)
>  		return err;
>  
> -	for (i = 0; i < data->channels; i++)
> +	for (i = 0; i < data->channels; i++) {
>  		data->temp_config[i] = HWMON_T_INPUT | HWMON_T_FAULT;
> +		data->channel[i].enabled = true;
> +	}
>  
>  	err = tmp421_probe_from_dt(client, data);
>  	if (err)
Krzysztof Adamski Oct. 17, 2021, midnight UTC | #2
Dnia Fri, Oct 15, 2021 at 03:47:41PM -0700, Guenter Roeck napisaƂ(a):
>On Thu, Oct 14, 2021 at 03:01:09PM +0200, Krzysztof Adamski wrote:
>> The previous patch introduced per channel subnodes in DT that let us
>> specify some channel specific properties. This built a ground for easily
>> disabling individual channels of the sensor that may not be connected to
>> any external diode and thus are not returning any meaningful data.
>>
>> This patch adds support for parsing the "status" property of channels DT
>> subnodes and makes sure the -ENODATA is returned when disabled channels
>> value is read.
>>
>> Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
>
>Same problem as with patch 2/9. Any idea what happened ?
>
>Anyway, applied after fixing it up.

Thank you and sorry for the trouble. It isn't trivial to send patches
via our enterprise mail platform and this time I had to contrive more
than usually. I did use mutt, as I usually do, but had to run it from
different machine. Even though I did use the same config, the mutt
version was different and EDITOR might have been configured differently,
so maybe that created a problem? Or it was the Exchange server which
mangled my patches? I don't know now but I will watch out for that,
thank you for the heads up on that.

Best regards,
Krzysztof Adamski
diff mbox series

Patch

diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index 89346ca6c9a9..af08bc985a13 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -89,6 +89,7 @@  MODULE_DEVICE_TABLE(of, tmp421_of_match);
  
  struct tmp421_channel {
  	const char *label;
+	bool enabled;
  	s16 temp;
  };
  
@@ -170,6 +171,9 @@  static int tmp421_read(struct device *dev, enum hwmon_sensor_types type,
  	if (ret)
  		return ret;
  
+	if (!tmp421->channel[channel].enabled)
+		return -ENODATA;
+
  	switch (attr) {
  	case hwmon_temp_input:
  		*val = temp_from_raw(tmp421->channel[channel].temp,
@@ -323,6 +327,8 @@  static int tmp421_probe_child_from_dt(struct i2c_client *client,
  	if (data->channel[i].label)
  		data->temp_config[i] |= HWMON_T_LABEL;
  
+	data->channel[i].enabled = of_device_is_available(child);
+
  	return 0;
  }
  
@@ -371,8 +377,10 @@  static int tmp421_probe(struct i2c_client *client)
  	if (err)
  		return err;
  
-	for (i = 0; i < data->channels; i++)
+	for (i = 0; i < data->channels; i++) {
  		data->temp_config[i] = HWMON_T_INPUT | HWMON_T_FAULT;
+		data->channel[i].enabled = true;
+	}
  
  	err = tmp421_probe_from_dt(client, data);
  	if (err)