Thread (10 messages) 10 messages, 3 authors, 2020-02-05
STALE2317d
Revisions (6)
  1. v1 [diff vs current]
  2. v2 [diff vs current]
  3. v3 [diff vs current]
  4. v4 [diff vs current]
  5. v5 [diff vs current]
  6. v6 current

[PATCH v6 1/2] hwmon: (adt7475) Added attenuator bypass support

From: Logan Shaw <hidden>
Date: 2020-01-26 22:10:33
Also in: linux-hwmon, lkml
Subsystem: adt7475 hardware monitor driver, hardware monitoring, the rest · Maintainers: Jean Delvare, Guenter Roeck, Linus Torvalds

Added support for reading DTS properties to set attenuators on
device probe for the ADT7473, ADT7475, ADT7476, and ADT7490.

Signed-off-by: Logan Shaw <redacted>
---
---
 drivers/hwmon/adt7475.c | 55 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 6c64d50c9aae..3f4bdc1eaaec 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -19,6 +19,7 @@
 #include <linux/hwmon-vid.h>
 #include <linux/err.h>
 #include <linux/jiffies.h>
+#include <linux/of.h>
 #include <linux/util_macros.h>
 
 /* Indexes for the sysfs hooks */
@@ -1457,6 +1458,57 @@ static int adt7475_update_limits(struct i2c_client *client)
 	return 0;
 }
 
+static void modify_config(const struct i2c_client *client, char *property,
+			  u8 *config, u8 bit_index)
+{
+	u32 prop_value = 0;
+	int ret = of_property_read_u32(client->dev.of_node, property,
+					&prop_value);
+
+	if (!ret) {
+		if (prop_value)
+			*config |= (1 << bit_index);
+		else
+			*config &= ~(1 << bit_index);
+	}
+}
+
+static int load_attenuators(const struct i2c_client *client, int chip,
+			    u8 *config2, u8 *config4)
+{
+	u8 conf_copy;
+	int ret;
+
+	if (chip == adt7476 || chip == adt7490) {
+		conf_copy = *config4;
+
+		modify_config(client, "bypass-attenuator-in0", &conf_copy, 4);
+		modify_config(client, "bypass-attenuator-in1", &conf_copy, 5);
+		modify_config(client, "bypass-attenuator-in3", &conf_copy, 6);
+		modify_config(client, "bypass-attenuator-in4", &conf_copy, 7);
+
+		ret = i2c_smbus_write_byte_data(client, REG_CONFIG4,
+						conf_copy);
+		if (ret < 0)
+			return ret;
+
+		*config4 = conf_copy;
+	} else if (chip == adt7473 || chip == adt7475) {
+		conf_copy = *config2;
+
+		modify_config(client, "bypass-attenuator-in1", &conf_copy, 5);
+
+		ret = i2c_smbus_write_byte_data(client, REG_CONFIG2,
+						conf_copy);
+		if (ret < 0)
+			return ret;
+
+		*config2 = conf_copy;
+	}
+
+	return 0;
+}
+
 static int adt7475_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -1546,6 +1598,9 @@ static int adt7475_probe(struct i2c_client *client,
 
 	/* Voltage attenuators can be bypassed, globally or individually */
 	config2 = adt7475_read(REG_CONFIG2);
+	if (load_attenuators(client, chip, &config2, &data->config4) < 0)
+		dev_warn(&client->dev, "Error setting bypass attenuators\n");
+
 	if (config2 & CONFIG2_ATTN) {
 		data->bypass_attn = (0x3 << 3) | 0x3;
 	} else {
-- 
2.25.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help