[RFC PATCH linux dev-4.10 7/7] hwmon: max31785: Provide config of fault pin behavior

Andrew Jeffery andrew at aj.id.au
Fri Jun 2 16:22:07 AEST 2017


From: Christopher Bostic <cbostic at linux.vnet.ibm.com>

Provide interface to set behavior when FAULT pin is asserted.
When enabled force fan to 100% PWM duty cycle.

Signed-off-by: Christopher Bostic <cbostic at linux.vnet.ibm.com>
[Andrew Jeffery: Make it apply to reworked driver]
Signed-off-by: Andrew Jeffery <andrew at aj.id.au>
---
 drivers/hwmon/max31785.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/drivers/hwmon/max31785.c b/drivers/hwmon/max31785.c
index fb971277165c..06e1708608d7 100644
--- a/drivers/hwmon/max31785.c
+++ b/drivers/hwmon/max31785.c
@@ -38,6 +38,7 @@
 #define MAX31785_REG_MFR_ID			0x99
 #define MAX31785_REG_MFR_MODEL			0x9a
 #define MAX31785_REG_MFR_REVISION		0x9b
+#define MAX31785_REG_MFR_FAULT_RESP		0xd9
 #define MAX31785_REG_MFR_FAN_CONFIG		0xf1
 #define MAX31785_REG_READ_FAN_PWM		0xf3
 
@@ -51,6 +52,9 @@
 /* Fan Status register bits */
 #define MAX31785_FAN_STATUS_FAULT_MASK		0x80
 
+/* Fault response register bits */
+#define MAX31785_FAULT_RESP_PIN_MONITOR		0x01
+
 /* Fan Command constants */
 #define MAX31785_FAN_COMMAND_PWM_RATIO		40
 
@@ -678,6 +682,69 @@ static const struct hwmon_chip_info max31785_chip_info = {
 	.info = max31785_info,
 };
 
+static ssize_t max31785_fault_resp_store(struct device *dev,
+				struct device_attribute *attr, const char *buf,
+				size_t count)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	int rv;
+
+	rv = max31785_set_page(client, 0);
+	if (rv < 0)
+		return rv;
+
+	rv = i2c_smbus_read_byte_data(client, MAX31785_REG_MFR_FAULT_RESP);
+	if (rv < 0)
+		return rv;
+
+	if (!strncmp(buf, "on", strlen("on"))) {
+		if (!(rv & MAX31785_FAULT_RESP_PIN_MONITOR)) {
+			rv |= MAX31785_FAULT_RESP_PIN_MONITOR;
+			rv = i2c_smbus_write_byte_data(client,
+					MAX31785_REG_MFR_FAULT_RESP, rv);
+			if (rv < 0)
+				return rv;
+		}
+	} else if (!strncmp(buf, "off", strlen("off"))) {
+		if (rv & MAX31785_FAULT_RESP_PIN_MONITOR) {
+			rv &= ~MAX31785_FAULT_RESP_PIN_MONITOR;
+			rv = i2c_smbus_write_byte_data(client,
+					MAX31785_REG_MFR_FAULT_RESP, rv);
+			if (rv < 0)
+				return rv;
+		}
+	} else {
+		dev_warn(dev, "Unknown fault response type: [%s]\n", buf);
+		return -EINVAL;
+	}
+	return count;
+}
+
+static ssize_t max31785_fault_resp_show(struct device *dev,
+			       struct device_attribute *attr, char *buf)
+{
+	struct i2c_client *client = to_i2c_client(dev);
+	int rv;
+
+	rv = max31785_set_page(client, 0);
+	if (rv < 0)
+		return rv;
+
+	rv = i2c_smbus_read_byte_data(client, MAX31785_REG_MFR_FAULT_RESP);
+	if (rv < 0)
+		return rv;
+
+	if (rv & MAX31785_FAULT_RESP_PIN_MONITOR)
+		rv = sprintf(buf, "on\n");
+	else
+		rv = sprintf(buf, "off\n");
+
+	return rv;
+}
+
+static DEVICE_ATTR(fault_resp, 0644, max31785_fault_resp_show,
+		max31785_fault_resp_store);
+
 static SENSOR_DEVICE_ATTR(fan1_input_fast, 0444, max31785_fan_get_fast,
 		NULL, 0);
 static SENSOR_DEVICE_ATTR(fan2_input_fast, 0444, max31785_fan_get_fast,
@@ -751,6 +818,10 @@ static int max31785_probe(struct i2c_client *client,
 	if (data->capabilities & MAX31785_CAP_FAST_ROTOR)
 		extra_groups = max31785_groups;
 
+	rc = device_create_file(dev, &dev_attr_fault_resp);
+	if (rc)
+		return rc;
+
 	hwmon_dev = devm_hwmon_device_register_with_info(dev,
 			client->name, data, &max31785_chip_info, extra_groups);
 
-- 
2.11.0



More information about the openbmc mailing list