Skip to content

Commit

Permalink
[dni_dps460] Add attributes to retrieve PMBus status command codes (s…
Browse files Browse the repository at this point in the history
…onic-net#197)

Add attributes to retrieve PMBus status command codes
(Port of sonic-net#194 from 201811 branch)

Signed-off-by: Arun Saravanan Balachandran <Arun_Saravanan_Balac@dell.com>
  • Loading branch information
ArunSaravananBalachandran authored Feb 25, 2021
1 parent 2fcd4e3 commit 65fccd7
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 0 deletions.
183 changes: 183 additions & 0 deletions patch/driver-hwmon-pmbus-dni_dps460-add-status-attributes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
From 0a3a6f30eb6ea96a1642a3ad75d2de87a1448fb3 Mon Sep 17 00:00:00 2001
From: Arun Saravanan Balachandran <Arun_Saravanan_Balac@dell.com>
Date: Thu, 11 Feb 2021 09:15:41 +0000
Subject: [PATCH] Add attributes to retrieve PMBus status command codes

Signed-off-by: Arun Saravanan Balachandran <Arun_Saravanan_Balac@dell.com>
---
drivers/hwmon/pmbus/dni_dps460.c | 152 +++++++++++++++++++++++++++++++++++++++
1 file changed, 152 insertions(+)

diff --git a/drivers/hwmon/pmbus/dni_dps460.c b/drivers/hwmon/pmbus/dni_dps460.c
index d314c1f..313165a 100644
--- a/drivers/hwmon/pmbus/dni_dps460.c
+++ b/drivers/hwmon/pmbus/dni_dps460.c
@@ -166,13 +166,165 @@ static ssize_t set_pec(struct device *dev, struct device_attribute *dummy,
return count;
}

+static ssize_t show_capability(struct device *dev, struct device_attribute *devattr,
+ char *buf) {
+
+ struct i2c_client *client = to_i2c_client(dev);
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ int val;
+
+ mutex_lock(&data->update_lock);
+ val = pmbus_read_byte_data(client, 0, PMBUS_CAPABILITY);
+ pmbus_clear_faults(client);
+ mutex_unlock(&data->update_lock);
+ if (val < 0) {
+ return val;
+ }
+ return sprintf(buf, "0x%x\n", val);
+}
+
+static ssize_t show_status_word(struct device *dev, struct device_attribute *devattr,
+ char *buf) {
+
+ struct i2c_client *client = to_i2c_client(dev);
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ int val;
+
+ mutex_lock(&data->update_lock);
+ val = pmbus_read_word_data(client, 0, PMBUS_STATUS_WORD);
+ pmbus_clear_faults(client);
+ mutex_unlock(&data->update_lock);
+ if (val < 0) {
+ return val;
+ }
+ return sprintf(buf, "0x%x\n", val);
+}
+
+static ssize_t show_status_vout(struct device *dev, struct device_attribute *devattr,
+ char *buf) {
+
+ struct i2c_client *client = to_i2c_client(dev);
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ int val;
+
+ mutex_lock(&data->update_lock);
+ val = pmbus_read_byte_data(client, 0, PMBUS_STATUS_VOUT);
+ pmbus_clear_faults(client);
+ mutex_unlock(&data->update_lock);
+ if (val < 0) {
+ return val;
+ }
+ return sprintf(buf, "0x%x\n", val);
+}
+
+static ssize_t show_status_iout(struct device *dev, struct device_attribute *devattr,
+ char *buf) {
+
+ struct i2c_client *client = to_i2c_client(dev);
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ int val;
+
+ mutex_lock(&data->update_lock);
+ val = pmbus_read_byte_data(client, 0, PMBUS_STATUS_IOUT);
+ pmbus_clear_faults(client);
+ mutex_unlock(&data->update_lock);
+ if (val < 0) {
+ return val;
+ }
+ return sprintf(buf, "0x%x\n", val);
+}
+
+static ssize_t show_status_input(struct device *dev, struct device_attribute *devattr,
+ char *buf) {
+
+ struct i2c_client *client = to_i2c_client(dev);
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ int val;
+
+ mutex_lock(&data->update_lock);
+ val = pmbus_read_byte_data(client, 0, PMBUS_STATUS_INPUT);
+ pmbus_clear_faults(client);
+ mutex_unlock(&data->update_lock);
+ if (val < 0) {
+ return val;
+ }
+ return sprintf(buf, "0x%x\n", val);
+}
+
+static ssize_t show_status_temp(struct device *dev, struct device_attribute *devattr,
+ char *buf) {
+
+ struct i2c_client *client = to_i2c_client(dev);
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ int val;
+
+ mutex_lock(&data->update_lock);
+ val = pmbus_read_byte_data(client, 0, PMBUS_STATUS_TEMPERATURE);
+ pmbus_clear_faults(client);
+ mutex_unlock(&data->update_lock);
+ if (val < 0) {
+ return val;
+ }
+ return sprintf(buf, "0x%x\n", val);
+}
+
+static ssize_t show_status_cml(struct device *dev, struct device_attribute *devattr,
+ char *buf) {
+
+ struct i2c_client *client = to_i2c_client(dev);
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ int val;
+
+ mutex_lock(&data->update_lock);
+ val = pmbus_read_byte_data(client, 0, PMBUS_STATUS_CML);
+ pmbus_clear_faults(client);
+ mutex_unlock(&data->update_lock);
+ if (val < 0) {
+ return val;
+ }
+ return sprintf(buf, "0x%x\n", val);
+}
+
+static ssize_t show_status_fans(struct device *dev, struct device_attribute *devattr,
+ char *buf) {
+
+ struct i2c_client *client = to_i2c_client(dev);
+ struct pmbus_data *data = i2c_get_clientdata(client);
+ int val;
+
+ mutex_lock(&data->update_lock);
+ val = pmbus_read_byte_data(client, 0, PMBUS_STATUS_FAN_12);
+ pmbus_clear_faults(client);
+ mutex_unlock(&data->update_lock);
+ if (val < 0) {
+ return val;
+ }
+ return sprintf(buf, "0x%x\n", val);
+}
+
static SENSOR_DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec, 0);
static SENSOR_DEVICE_ATTR(fan1_target, S_IWUSR | S_IRUGO, get_target,
set_target, 0);
+static SENSOR_DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL, 0);
+static SENSOR_DEVICE_ATTR(status_word, S_IRUGO, show_status_word, NULL, 0);
+static SENSOR_DEVICE_ATTR(status_vout, S_IRUGO, show_status_vout, NULL, 0);
+static SENSOR_DEVICE_ATTR(status_iout, S_IRUGO, show_status_iout, NULL, 0);
+static SENSOR_DEVICE_ATTR(status_input, S_IRUGO, show_status_input, NULL, 0);
+static SENSOR_DEVICE_ATTR(status_temp, S_IRUGO, show_status_temp, NULL, 0);
+static SENSOR_DEVICE_ATTR(status_cml, S_IRUGO, show_status_cml, NULL, 0);
+static SENSOR_DEVICE_ATTR(status_fans_12, S_IRUGO, show_status_fans, NULL, 0);

static struct attribute *dni_dps460_attrs[] = {
&sensor_dev_attr_fan1_target.dev_attr.attr,
&sensor_dev_attr_pec.dev_attr.attr,
+ &sensor_dev_attr_capability.dev_attr.attr,
+ &sensor_dev_attr_status_word.dev_attr.attr,
+ &sensor_dev_attr_status_vout.dev_attr.attr,
+ &sensor_dev_attr_status_iout.dev_attr.attr,
+ &sensor_dev_attr_status_input.dev_attr.attr,
+ &sensor_dev_attr_status_temp.dev_attr.attr,
+ &sensor_dev_attr_status_cml.dev_attr.attr,
+ &sensor_dev_attr_status_fans_12.dev_attr.attr,
NULL
};
static struct attribute_group dni_dps460_attr_grp = {
--
2.7.4

1 change: 1 addition & 0 deletions patch/series
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ driver-hwmon-max6620-update.patch
driver-hwmon-max6658-fix-write-convrate.patch
driver-hwmon-pmbus-dni_dps460.patch
driver-hwmon-pmbus-dni_dps460-update-pmbus-core.patch
driver-hwmon-pmbus-dni_dps460-add-status-attributes.patch
driver-hwmon-pmbus-dps1900.patch
driver-support-tun-config-carrier-enable.patch
driver-support-optoe.patch
Expand Down

0 comments on commit 65fccd7

Please sign in to comment.