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

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

 



Added support for reading DTS properties to set attenuators on
device probe. Only bypasses attenuators on the ADT7476 and ADT7490
(other chips do not support this).

Signed-off-by: Logan Shaw <logan.shaw@xxxxxxxxxxxxxxxxxxx>
---
---
 drivers/hwmon/adt7475.c | 73 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 6c64d50c9aae..1e6ca1bc28ce 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,68 @@ static int adt7475_update_limits(struct i2c_client *client)
 	return 0;
 }
 
+/**
+ * Reads individual voltage input bypass attenuator properties from the DTS,
+ * and if the property is present the corresponding bit is set in the
+ * register. Only the ADT7476 and ADT7490 support bypassing individual
+ * attenuators.
+ *
+ * Properties must be in the form of "bypass-attenuator-inx", where x is an
+ * integer from the set {0, 1, 3, 4} (can not bypass in2 attenuator).
+ *
+ * Returns a negative error code if there was an error writing to the register.
+ */
+static int load_individual_bypass_attenuators(const struct i2c_client *client,
+					      u8 *config4)
+{
+	u8 config4_copy = *config4;
+
+	if (of_get_property(client->dev.of_node, "bypass-attenuator-in0", NULL))
+		config4_copy |= (1 << 4);
+
+	if (of_get_property(client->dev.of_node, "bypass-attenuator-in1", NULL))
+		config4_copy |= (1 << 5);
+
+	if (of_get_property(client->dev.of_node, "bypass-attenuator-in3", NULL))
+		config4_copy |= (1 << 6);
+
+	if (of_get_property(client->dev.of_node, "bypass-attenuator-in4", NULL))
+		config4_copy |= (1 << 7);
+
+	if (i2c_smbus_write_byte_data(client, REG_CONFIG4, config4_copy) < 0)
+		return -EREMOTEIO;
+
+	*config4 = config4_copy;
+
+	return 0;
+}
+
+/**
+ * Sets the bypass all attenuators bit, if the "bypass-attenuator-all"
+ * property exists in the DTS.
+ *
+ * Returns a negative error code if there was an error writing to the
+ * register.
+ */
+static int load_all_bypass_attenuator(const struct i2c_client *client,
+				      u8 *config2)
+{
+	u8 config2_copy = *config2;
+
+	if (!of_get_property(client->dev.of_node,
+			     "bypass-attenuator-all", NULL))
+		return 0;
+
+	config2_copy |= (1 << 5);
+
+	if (i2c_smbus_write_byte_data(client, REG_CONFIG2, config2_copy) < 0)
+		return -EREMOTEIO;
+
+	*config2 = config2_copy;
+
+	return 0;
+}
+
 static int adt7475_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -1545,7 +1608,17 @@ static int adt7475_probe(struct i2c_client *client,
 	}
 
 	/* Voltage attenuators can be bypassed, globally or individually */
+	if (chip == adt7476 || chip == adt7490)
+		if (load_individual_bypass_attenuators(client,
+							&(data->config4)) < 0)
+			dev_warn(&client->dev,
+				 "Error setting bypass attenuator bits\n");
+
 	config2 = adt7475_read(REG_CONFIG2);
+	if (chip == adt7476 || chip == adt7490)
+		if (load_all_bypass_attenuator(client, &config2) < 0)
+			dev_warn(&client->dev, "Error setting bypass all attenuator\n");
+
 	if (config2 & CONFIG2_ATTN) {
 		data->bypass_attn = (0x3 << 3) | 0x3;
 	} else {
-- 
2.23.0




[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux