Thread (43 messages) 43 messages, 5 authors, 2021-10-08
STALE1714d
Revisions (5)
  1. v1 current
  2. v2 [diff vs current]
  3. v3 [diff vs current]
  4. v4 [diff vs current]
  5. v5 [diff vs current]

[PATCH 6/8] hwmon: (tmp421) support specifying n-factor via DT

From: Krzysztof Adamski <hidden>
Date: 2021-09-07 13:45:45
Also in: linux-hwmon
Subsystem: hardware monitoring, the rest · Maintainers: Guenter Roeck, Linus Torvalds

Previous patches added a way to specify some channel specific parameters
in DT and n-factor is definitely one of them. This calibration mechanism
is board specific as its value depends on the diodes/transistors being
connected to the sensor and thus the DT seems like a right fit for that
information. It is very similar to the value of shunt resistor that some
drivers allows specifying in DT.

This patch adds a possibility to set n-factor for each channel via
"n-factor" DT property in each channel subnode.

Signed-off-by: Krzysztof Adamski <redacted>
---
 drivers/hwmon/tmp421.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index a41d7935acb9..90c6b094785e 100644
--- a/drivers/hwmon/tmp421.c
+++ b/drivers/hwmon/tmp421.c
@@ -34,6 +34,7 @@ enum chips { tmp421, tmp422, tmp423, tmp441, tmp442 };
 #define TMP421_STATUS_REG			0x08
 #define TMP421_CONFIG_REG_1			0x09
 #define TMP421_CONVERSION_RATE_REG		0x0B
+#define TMP421_N_FACTOR_REG_1			0x21
 #define TMP421_MANUFACTURER_ID_REG		0xFE
 #define TMP421_DEVICE_ID_REG			0xFF
 
@@ -302,6 +303,7 @@ void tmp421_probe_child_from_dt(struct i2c_client *client,
 {
 	struct device *dev = &client->dev;
 	u32 i;
+	s32 val;
 	int err;
 
 	err = of_property_read_u32(child, "reg", &i);
@@ -321,6 +323,21 @@ void tmp421_probe_child_from_dt(struct i2c_client *client,
 		data->channel[i].disabled = true;
 		return;
 	}
+
+	if (i == 0)
+		return; /* input 0 is internal channel */
+
+	err = of_property_read_s32(child, "n-factor", &val);
+	if (!err) {
+		if (val > 127 || val < -128)
+			dev_err(dev, "n-factor for channel %d invalid (%d)\n",
+				i, val);
+		else
+			i2c_smbus_write_byte_data(client,
+						  TMP421_N_FACTOR_REG_1 + i - 1,
+						  val);
+	}
+
 }
 
 void tmp421_probe_from_dt(struct i2c_client *client, struct tmp421_data *data)
-- 
2.31.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help