summaryrefslogtreecommitdiff
path: root/drivers/hwmon/tmp421.c
diff options
context:
space:
mode:
authorKrzysztof Adamski <krzysztof.adamski@nokia.com>2021-10-14 16:01:28 +0300
committerGuenter Roeck <linux@roeck-us.net>2021-10-16 01:49:32 +0300
commit3fba10dc0341462a907c2eb31e1dc60b83da23fa (patch)
treed81d27b68ebafe5ff20b3394d5bb469e66a6fc46 /drivers/hwmon/tmp421.c
parent45e9bda4ffc48f96e9811e158dcd610a5ec49e13 (diff)
downloadlinux-3fba10dc0341462a907c2eb31e1dc60b83da23fa.tar.xz
hwmon: (tmp421) support specifying n-factor via DT
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 <krzysztof.adamski@nokia.com> Link: https://lore.kernel.org/r/69d0bfcc5ba27c67f21d3eabfb100656a14c75b9.1634206677.git.krzysztof.adamski@nokia.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/tmp421.c')
-rw-r--r--drivers/hwmon/tmp421.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/hwmon/tmp421.c b/drivers/hwmon/tmp421.c
index af08bc985a13..4f3737d14ade 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
@@ -310,6 +311,7 @@ static int 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);
@@ -329,6 +331,22 @@ static int tmp421_probe_child_from_dt(struct i2c_client *client,
data->channel[i].enabled = of_device_is_available(child);
+ err = of_property_read_s32(child, "ti,n-factor", &val);
+ if (!err) {
+ if (i == 0) {
+ dev_err(dev, "n-factor can't be set for internal channel\n");
+ return -EINVAL;
+ }
+
+ if (val > 127 || val < -128) {
+ dev_err(dev, "n-factor for channel %d invalid (%d)\n",
+ i, val);
+ return -EINVAL;
+ }
+ i2c_smbus_write_byte_data(client, TMP421_N_FACTOR_REG_1 + i - 1,
+ val);
+ }
+
return 0;
}