From: Eddie James <eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-hwmon-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org,
jdelvare-IBi9RG/b67k@public.gmane.org,
corbet-T1hC0tSOHrs@public.gmane.org,
mark.rutland-5wv7dgnIgG8@public.gmane.org,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org,
eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org,
"Edward A. James"
<eajames-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH v3 10/12] hwmon (occ): Add non-hwmon attributes
Date: Mon, 20 Nov 2017 17:53:39 -0600 [thread overview]
Message-ID: <1511222021-562-11-git-send-email-eajames@linux.vnet.ibm.com> (raw)
In-Reply-To: <1511222021-562-1-git-send-email-eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
From: "Edward A. James" <eajames-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Create device attributes for additional OCC properties that do not
belong as hwmon sensors. These provide additional information as to the
state of the processor and system.
Signed-off-by: Edward A. James <eajames-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
drivers/hwmon/occ/common.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++
drivers/hwmon/occ/common.h | 1 +
drivers/hwmon/occ/p8_i2c.c | 10 +++++
drivers/hwmon/occ/p9_sbe.c | 2 +
4 files changed, 106 insertions(+)
diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c
index 337f286b..53e3592 100644
--- a/drivers/hwmon/occ/common.c
+++ b/drivers/hwmon/occ/common.c
@@ -24,6 +24,14 @@
#define OCC_FRU_TYPE_VRM 0x3
+/* OCC status bits */
+#define OCC_STAT_MASTER 0x80
+#define OCC_STAT_ACTIVE 0x01
+#define OCC_EXT_STAT_DVFS_OT 0x80
+#define OCC_EXT_STAT_DVFS_POWER 0x40
+#define OCC_EXT_STAT_MEM_THROTTLE 0x20
+#define OCC_EXT_STAT_QUICK_DROP 0x10
+
/* OCC sensor type and version definitions */
struct temp_sensor_1 {
@@ -1108,6 +1116,81 @@ static int occ_setup_sensor_attrs(struct occ *occ)
return 0;
}
+static ssize_t occ_show_status(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int rc;
+ int val = 0;
+ struct occ *occ = dev_get_drvdata(dev);
+ struct occ_poll_response_header *header;
+ struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
+
+ rc = occ_update_response(occ);
+ if (rc)
+ return rc;
+
+ header = (struct occ_poll_response_header *)occ->resp.data;
+
+ switch (sattr->index) {
+ case 0:
+ val = (header->status & OCC_STAT_MASTER) ? 1 : 0;
+ break;
+ case 1:
+ val = (header->status & OCC_STAT_ACTIVE) ? 1 : 0;
+ break;
+ case 2:
+ val = (header->ext_status & OCC_EXT_STAT_DVFS_OT) ? 1 : 0;
+ break;
+ case 3:
+ val = (header->ext_status & OCC_EXT_STAT_DVFS_POWER) ? 1 : 0;
+ break;
+ case 4:
+ val = (header->ext_status & OCC_EXT_STAT_MEM_THROTTLE) ? 1 : 0;
+ break;
+ case 5:
+ val = (header->ext_status & OCC_EXT_STAT_QUICK_DROP) ? 1 : 0;
+ break;
+ case 6:
+ val = header->occ_state;
+ break;
+ case 7:
+ if (header->status & OCC_STAT_MASTER)
+ val = hweight8(header->occs_present);
+ else
+ val = 1;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return snprintf(buf, PAGE_SIZE - 1, "%d\n", val);
+}
+
+static SENSOR_DEVICE_ATTR(occ_master, 0444, occ_show_status, NULL, 0);
+static SENSOR_DEVICE_ATTR(occ_active, 0444, occ_show_status, NULL, 1);
+static SENSOR_DEVICE_ATTR(occ_dvfs_ot, 0444, occ_show_status, NULL, 2);
+static SENSOR_DEVICE_ATTR(occ_dvfs_power, 0444, occ_show_status, NULL, 3);
+static SENSOR_DEVICE_ATTR(occ_mem_throttle, 0444, occ_show_status, NULL, 4);
+static SENSOR_DEVICE_ATTR(occ_quick_drop, 0444, occ_show_status, NULL, 5);
+static SENSOR_DEVICE_ATTR(occ_status, 0444, occ_show_status, NULL, 6);
+static SENSOR_DEVICE_ATTR(occs_present, 0444, occ_show_status, NULL, 7);
+
+static struct attribute *occ_attributes[] = {
+ &sensor_dev_attr_occ_master.dev_attr.attr,
+ &sensor_dev_attr_occ_active.dev_attr.attr,
+ &sensor_dev_attr_occ_dvfs_ot.dev_attr.attr,
+ &sensor_dev_attr_occ_dvfs_power.dev_attr.attr,
+ &sensor_dev_attr_occ_mem_throttle.dev_attr.attr,
+ &sensor_dev_attr_occ_quick_drop.dev_attr.attr,
+ &sensor_dev_attr_occ_status.dev_attr.attr,
+ &sensor_dev_attr_occs_present.dev_attr.attr,
+ NULL
+};
+
+static const struct attribute_group occ_attr_group = {
+ .attrs = occ_attributes,
+};
+
/* only need to do this once at startup, as OCC won't change sensors on us */
static void occ_parse_poll_response(struct occ *occ)
{
@@ -1188,5 +1271,15 @@ int occ_setup(struct occ *occ, const char *name)
return rc;
}
+ rc = sysfs_create_group(&occ->bus_dev->kobj, &occ_attr_group);
+ if (rc)
+ dev_warn(occ->bus_dev, "failed to create status attrs: %d\n",
+ rc);
+
return 0;
}
+
+void occ_shutdown(struct occ *occ)
+{
+ sysfs_remove_group(&occ->bus_dev->kobj, &occ_attr_group);
+}
diff --git a/drivers/hwmon/occ/common.h b/drivers/hwmon/occ/common.h
index 049c3b4..dc9e06d 100644
--- a/drivers/hwmon/occ/common.h
+++ b/drivers/hwmon/occ/common.h
@@ -110,5 +110,6 @@ struct occ {
};
int occ_setup(struct occ *occ, const char *name);
+void occ_shutdown(struct occ *occ);
#endif /* OCC_COMMON_H */
diff --git a/drivers/hwmon/occ/p8_i2c.c b/drivers/hwmon/occ/p8_i2c.c
index 8032c0b..d719632 100644
--- a/drivers/hwmon/occ/p8_i2c.c
+++ b/drivers/hwmon/occ/p8_i2c.c
@@ -230,6 +230,15 @@ static int p8_i2c_occ_probe(struct i2c_client *client,
return occ_setup(occ, "p8_occ");
}
+static int p8_i2c_occ_remove(struct i2c_client *client)
+{
+ struct occ *occ = dev_get_drvdata(&client->dev);
+
+ occ_shutdown(occ);
+
+ return 0;
+}
+
static const struct of_device_id p8_i2c_occ_of_match[] = {
{ .compatible = "ibm,p8-occ-hwmon" },
{}
@@ -243,6 +252,7 @@ static int p8_i2c_occ_probe(struct i2c_client *client,
.of_match_table = p8_i2c_occ_of_match,
},
.probe = p8_i2c_occ_probe,
+ .remove = p8_i2c_occ_remove,
};
module_i2c_driver(p8_i2c_occ_driver);
diff --git a/drivers/hwmon/occ/p9_sbe.c b/drivers/hwmon/occ/p9_sbe.c
index be3a469..7dbe4d5 100644
--- a/drivers/hwmon/occ/p9_sbe.c
+++ b/drivers/hwmon/occ/p9_sbe.c
@@ -135,6 +135,8 @@ static int p9_sbe_occ_remove(struct platform_device *pdev)
p9_sbe_occ->sbe = NULL;
p9_sbe_occ_close_client(p9_sbe_occ);
+ occ_shutdown(occ);
+
return 0;
}
--
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-11-20 23:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-20 23:53 [PATCH v3 00/12] hwmon: Add On-Chip Controller hwmon driver Eddie James
2017-11-20 23:53 ` [PATCH v3 01/12] Documentation: hwmon: Add OCC documentation Eddie James
2017-11-20 23:53 ` [PATCH v3 02/12] Documentation: ABI: Add occ-hwmon driver sysfs documentation Eddie James
2017-11-22 15:15 ` [v3, " Guenter Roeck
2017-11-20 23:53 ` [PATCH v3 03/12] dt-bindings: i2c: Add P8 OCC hwmon device documentation Eddie James
2017-11-21 18:34 ` Rob Herring
2017-11-20 23:53 ` [PATCH v3 04/12] dt-bindings: fsi: Add P9 " Eddie James
[not found] ` <1511222021-562-5-git-send-email-eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-11-21 18:36 ` Rob Herring
2017-11-20 23:53 ` [PATCH v3 05/12] hwmon: Add On-Chip Controller (OCC) hwmon driver Eddie James
2017-11-20 23:53 ` [PATCH v3 07/12] hwmon (occ): Parse OCC poll response Eddie James
2017-11-20 23:53 ` [PATCH v3 08/12] hwmon (occ): Add sensor types and versions Eddie James
2017-11-20 23:53 ` [PATCH v3 09/12] hwmon (occ): Add sensor attributes and register hwmon device Eddie James
2017-11-22 15:22 ` [v3, " Guenter Roeck
[not found] ` <1511222021-562-1-git-send-email-eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-11-20 23:53 ` [PATCH v3 06/12] hwmon (occ): Add command transport method for P8 and P9 Eddie James
2017-11-20 23:53 ` Eddie James [this message]
[not found] ` <1511222021-562-11-git-send-email-eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-11-22 15:23 ` [v3,10/12] hwmon (occ): Add non-hwmon attributes Guenter Roeck
2017-11-20 23:53 ` [PATCH v3 11/12] hwmon (occ): Add error handling Eddie James
2017-11-20 23:53 ` [PATCH v3 12/12] hwmon (occ): Add sysfs notification for errors and throttling Eddie James
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=1511222021-562-11-git-send-email-eajames@linux.vnet.ibm.com \
--to=eajames-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=corbet-T1hC0tSOHrs@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=eajames-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
--cc=jdelvare-IBi9RG/b67k@public.gmane.org \
--cc=joel-U3u1mxZcP9KHXe+LvDLADg@public.gmane.org \
--cc=linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org \
--cc=linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-hwmon-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).