[PATCH linux 3/4] hwmon: (isl68137) add accessors for changing VOUT_MAX

Xo Wang xow at google.com
Tue Jul 11 10:43:00 AEST 2017


From: Robert Lippert <rlippert at google.com>

To workaround a controller errata, VOUT_MAX must be changed dynamically
on some early Zaius boards.  PMBus core framework does not have
any support for making this value settable so add some device-specific
sysfs files to expose the value.

Signed-off-by: Robert Lippert <rlippert at google.com>
---
 drivers/hwmon/pmbus/isl68137.c | 44 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/drivers/hwmon/pmbus/isl68137.c b/drivers/hwmon/pmbus/isl68137.c
index cc95a3d339af..2341f376bc2b 100644
--- a/drivers/hwmon/pmbus/isl68137.c
+++ b/drivers/hwmon/pmbus/isl68137.c
@@ -134,6 +134,38 @@ static SENSOR_DEVICE_ATTR_2(avs1_enabled, 0644,
 			    isl68137_avs_enable_show, isl68137_avs_enable_store,
 			    0, 1);
 
+static ssize_t isl68137_word_show(struct device *dev,
+				  struct device_attribute *devattr, char *buf)
+{
+	struct i2c_client *client = kobj_to_i2c_client(&dev->kobj);
+	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+	int val = pmbus_read_word_data(client, attr->index, attr->nr);
+	return snprintf(buf, PAGE_SIZE, "%d\n", val);
+}
+
+static ssize_t isl68137_word_store(struct device *dev,
+				   struct device_attribute *devattr,
+				   const char *buf, size_t count)
+{
+	struct i2c_client *client = kobj_to_i2c_client(&dev->kobj);
+	struct sensor_device_attribute_2 *attr = to_sensor_dev_attr_2(devattr);
+	char *end;
+	int rc;
+	long new = simple_strtol(buf, &end, 0);
+	if (end == buf || new > INT_MAX || new < INT_MIN)
+		return -EINVAL;
+
+	rc = pmbus_write_word_data(client, attr->index, attr->nr, new);
+	return rc < 0 ? rc : count;
+}
+
+static SENSOR_DEVICE_ATTR_2(vout0_max, 0644,
+			    isl68137_word_show, isl68137_word_store,
+			    PMBUS_VOUT_MAX, 0);
+static SENSOR_DEVICE_ATTR_2(vout1_max, 0644,
+			    isl68137_word_show, isl68137_word_store,
+			    PMBUS_VOUT_MAX, 1);
+
 static int isl68137_remove(struct i2c_client *client);
 
 static int isl68137_probe(struct i2c_client *client,
@@ -153,6 +185,14 @@ static int isl68137_probe(struct i2c_client *client,
 				&sensor_dev_attr_avs1_enabled.dev_attr);
 	if (rc)
 		goto out_fail;
+	rc = device_create_file(&client->dev,
+				&sensor_dev_attr_vout0_max.dev_attr);
+	if (rc)
+		goto out_fail;
+	rc = device_create_file(&client->dev,
+				&sensor_dev_attr_vout1_max.dev_attr);
+	if (rc)
+		goto out_fail;
 
 	return rc;
 
@@ -163,6 +203,10 @@ static int isl68137_probe(struct i2c_client *client,
 
 static int isl68137_remove(struct i2c_client *client)
 {
+	device_remove_file(&client->dev,
+			   &sensor_dev_attr_vout1_max.dev_attr);
+	device_remove_file(&client->dev,
+			   &sensor_dev_attr_vout0_max.dev_attr);
 	device_remove_file(&client->dev,
 			   &sensor_dev_attr_avs1_enabled.dev_attr);
 	device_remove_file(&client->dev,
-- 
2.13.2.725.g09c95d1e9-goog



More information about the openbmc mailing list