[PATCH 8/8] hwmon: (lm90) read the channel's offset from device-tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Slawomir Stepien <slawomir.stepien@xxxxxxxxx>

Try to read the channel's offset from device-tree. Having offset in
device-tree node is not mandatory. The offset can only be set for remote
channels.

Signed-off-by: Slawomir Stepien <slawomir.stepien@xxxxxxxxx>
---
 drivers/hwmon/lm90.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index e81cc21e525f..e4e7b4ddbfb6 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -1921,6 +1921,7 @@ static int lm90_probe_channel_from_dt(struct i2c_client *client,
 				      struct lm90_data *data)
 {
 	u32 id;
+	s32 val;
 	int err;
 	struct device *dev = &client->dev;
 
@@ -1944,6 +1945,25 @@ static int lm90_probe_channel_from_dt(struct i2c_client *client,
 	if (data->channel_label[id])
 		data->channel_config[id] |= HWMON_T_LABEL;
 
+	err = of_property_read_s32(child, "offset", &val);
+	if (!err) {
+		if (id == 0) {
+			dev_err(dev, "offset can't be set for internal channel\n");
+			return -EINVAL;
+		}
+
+		if (id == 1)
+			err = lm90_set_temp11(data, REMOTE_OFFSET, val);
+		else
+			err = lm90_set_temp11(data, REMOTE2_OFFSET, val);
+
+		if (err) {
+			dev_err(dev, "can't set offset %d for channel %d (%d)\n",
+				val, id, err);
+			return err;
+		}
+	}
+
 	return 0;
 }
 
@@ -2091,6 +2111,12 @@ static int lm90_probe(struct i2c_client *client)
 				err = lm90_update_confreg(data, data->config | 0x04);
 				if (err)
 					return err;
+
+				/*
+				 * In lm90_parse_dt_channel_info() we might set offset, so we need
+				 * to use correct format indication before that
+				 */
+				data->flags |= LM90_FLAG_ADT7461_EXT;
 			}
 		}
 
-- 
2.36.1




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux