[PATCH v2] platform/chrome: mfd/cros_ec_sysfs: Add sysfs entry to retrieve EC uptime.
From: twawrzynczak
Date: Mon Mar 25 2019 - 13:03:02 EST
From: Tim Wawrzynczak <twawrzynczak@xxxxxxxxxxxx>
The new sysfs entry 'uptime' is being made available to userspace so that
a userspace daemon can synchronize EC logs with host time.
Signed-off-by: Tim Wawrzynczak <twawrzynczak@xxxxxxxxxxxx>
---
Enric, the use case for this is ChromeOS's userspace daemon, timberslide,
which collects the EC logs for sending bug reports, etc. This is part of
a series of patches which is prefixing host timestamps before each EC
log line. The daemon matches up the EC log lines' seconds-since-boot
with the time gotten from the new 'uptime' node and calculates the
host time that the log line was printed at.
---
drivers/platform/chrome/cros_ec_sysfs.c | 34 +++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c
index fe0b7614ae1b..b3915d3287c5 100644
--- a/drivers/platform/chrome/cros_ec_sysfs.c
+++ b/drivers/platform/chrome/cros_ec_sysfs.c
@@ -107,6 +107,38 @@ static ssize_t reboot_store(struct device *dev,
return count;
}
+static ssize_t uptime_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct ec_response_uptime_info *resp;
+ struct cros_ec_command *msg;
+ int ret;
+ struct cros_ec_dev *ec = to_cros_ec_dev(dev);
+ u32 time_since_ec_boot_ms;
+
+ msg = kmalloc(sizeof(*msg) + sizeof(*resp), GFP_KERNEL);
+ if (!msg)
+ return -ENOMEM;
+
+ /* Get EC uptime information */
+ msg->version = 0;
+ msg->command = EC_CMD_GET_UPTIME_INFO + ec->cmd_offset;
+ msg->insize = sizeof(*resp);
+ msg->outsize = 0;
+ ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
+ if (ret < 0) {
+ time_since_ec_boot_ms = 0;
+ } else {
+ resp = (struct ec_response_uptime_info *)msg->data;
+ time_since_ec_boot_ms = resp->time_since_ec_boot_ms;
+ }
+
+ ret = scnprintf(buf, PAGE_SIZE, "%u\n", time_since_ec_boot_ms);
+
+ kfree(msg);
+ return ret;
+}
+
static ssize_t version_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -314,12 +346,14 @@ static DEVICE_ATTR_RW(reboot);
static DEVICE_ATTR_RO(version);
static DEVICE_ATTR_RO(flashinfo);
static DEVICE_ATTR_RW(kb_wake_angle);
+static DEVICE_ATTR_RO(uptime);
static struct attribute *__ec_attrs[] = {
&dev_attr_kb_wake_angle.attr,
&dev_attr_reboot.attr,
&dev_attr_version.attr,
&dev_attr_flashinfo.attr,
+ &dev_attr_uptime.attr,
NULL,
};
--
2.20.1