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@xxxxxxxxx> --- drivers/hwmon/tmp421.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c index a1dba1d405ee..a41d7935acb9 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 disabled; s16 temp; }; @@ -125,9 +126,8 @@ static int temp_from_u16(u16 reg) return (temp * 1000 + 128) / 256; } -static struct tmp421_data *tmp421_update_device(struct device *dev) +static void tmp421_update_device(struct tmp421_data *data) { - struct tmp421_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; int i; @@ -149,14 +149,17 @@ static struct tmp421_data *tmp421_update_device(struct device *dev) } mutex_unlock(&data->update_lock); - - return data; } static int tmp421_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { - struct tmp421_data *tmp421 = tmp421_update_device(dev); + struct tmp421_data *tmp421 = dev_get_drvdata(dev); + + if (tmp421->channel[channel].disabled) + return -ENODATA; + + tmp421_update_device(tmp421); switch (attr) { case hwmon_temp_input: @@ -314,6 +317,10 @@ void tmp421_probe_child_from_dt(struct i2c_client *client, if (data->channel[i].label) data->temp_config[i] |= HWMON_T_LABEL; + if (!of_device_is_available(child)) { + data->channel[i].disabled = true; + return; + } } void tmp421_probe_from_dt(struct i2c_client *client, struct tmp421_data *data) -- 2.31.1