From: Eddie James <eajames@linux.vnet.ibm.com>
To: openbmc@lists.ozlabs.org
Cc: "Edward A. James" <eajames@us.ibm.com>
Subject: [RFC linux dev-4.10 3/3] drivers/hwmon/pmbus: Add sensor status to pmbus attributes
Date: Mon, 7 Aug 2017 18:04:45 -0500 [thread overview]
Message-ID: <1502147085-437-4-git-send-email-eajames@linux.vnet.ibm.com> (raw)
In-Reply-To: <1502147085-437-1-git-send-email-eajames@linux.vnet.ibm.com>
From: "Edward A. James" <eajames@us.ibm.com>
Extend the pmbus core to provide status registers for attributes.
Signed-off-by: Edward A. James <eajames@us.ibm.com>
---
drivers/hwmon/pmbus/pmbus_core.c | 51 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index fc88cae..d319f94 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -87,6 +87,14 @@ struct pmbus_label {
#define to_pmbus_label(_attr) \
container_of(_attr, struct pmbus_label, attribute)
+struct pmbus_status {
+ char name[PMBUS_NAME_SIZE]; /* sysfs status name */
+ struct device_attribute attribute;
+ int reg;
+};
+#define to_pmbus_status(_attr) \
+ container_of(_attr, struct pmbus_status, attribute)
+
struct pmbus_data {
struct device *dev;
struct device *hwmon_dev;
@@ -993,6 +1001,16 @@ static ssize_t pmbus_show_label(struct device *dev,
return snprintf(buf, PAGE_SIZE, "%s\n", label->label);
}
+static ssize_t pmbus_show_status(struct device *dev,
+ struct device_attribute *da, char *buf)
+{
+ struct pmbus_status *status = to_pmbus_status(da);
+ struct pmbus_data *data = pmbus_update_device(dev);
+
+ return snprintf(buf, PAGE_SIZE, "%02x\n",
+ pmbus_get_status(data, status->reg) & 0xFF);
+}
+
static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
{
if (data->num_attributes >= data->max_attributes - 1) {
@@ -1131,6 +1149,25 @@ static int pmbus_add_label(struct pmbus_data *data,
return pmbus_add_attribute(data, &a->attr);
}
+static int pmbus_add_status(struct pmbus_data *data, const char *name, int seq,
+ int reg)
+{
+ struct pmbus_status *status;
+ struct device_attribute *a;
+
+ status = devm_kzalloc(data->dev, sizeof(*status), GFP_KERNEL);
+ if (!status)
+ return -ENOMEM;
+
+ a = &status->attribute;
+
+ snprintf(status->name, sizeof(status->name), "%s%d_status", name, seq);
+ status->reg = reg;
+
+ pmbus_dev_attr_init(a, status->name, S_IRUGO, pmbus_show_status, NULL);
+ return pmbus_add_attribute(data, &a->attr);
+}
+
/*
* Search for attributes. Allocate sensors, booleans, and labels as needed.
*/
@@ -1253,6 +1290,16 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,
return ret;
}
}
+ if (attr->sbase > 0 && attr->sbase < PB_STATUS_VMON_BASE) {
+ /* Add "status" attribute for physical status registers to dump
+ * the contents. This is pretty useful for hardware diagnostic
+ * purposes, as an alarm or fault bit doesn't necessarily
+ * provide all the info available.
+ */
+ ret = pmbus_add_status(data, name, index, attr->sbase + page);
+ if (ret)
+ return ret;
+ }
return 0;
}
@@ -1885,6 +1932,10 @@ static int pmbus_add_fan_attributes(struct i2c_client *client,
PB_FAN_FAN1_FAULT >> (f & 1));
if (ret)
return ret;
+ ret = pmbus_add_status(data, "fan", index,
+ base);
+ if (ret)
+ return ret;
}
index++;
}
--
1.8.3.1
prev parent reply other threads:[~2017-08-07 23:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-07 23:04 [RFC linux dev-4.10 0/3] drivers/hwmon/pmbus: core extensions Eddie James
2017-08-07 23:04 ` [RFC linux dev-4.10 1/3] drivers/hwmon/pmbus: Use STATUS_WORD by default and do correct access Eddie James
2017-08-07 23:04 ` [RFC linux dev-4.10 2/3] drivers/hmwon/pmbus: store STATUS_WORD in status registers Eddie James
2017-08-07 23:04 ` Eddie James [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1502147085-437-4-git-send-email-eajames@linux.vnet.ibm.com \
--to=eajames@linux.vnet.ibm.com \
--cc=eajames@us.ibm.com \
--cc=openbmc@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.