Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3428818img; Mon, 25 Mar 2019 10:05:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqyM2/LrTHcmS+BnYUwbO9rdgLAeUPpqhnFLMUJ7ASNtXfRNx9qhDch8PmuOmk7uBpVzeZD5 X-Received: by 2002:a17:902:4681:: with SMTP id p1mr25458779pld.42.1553533535888; Mon, 25 Mar 2019 10:05:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553533535; cv=none; d=google.com; s=arc-20160816; b=qP9nrJ/34kyQMQegc9n+t/rkpGLf00LevoN1m3See4KeTOGWhvYPChejFS62BZIQK6 7GTW8LxzwSo1LXsNchL2US5+lBVF1fllpvQKmJ5NiOAxzh5cHtnbvTJY9RPg3qjAsQN0 v25d+9rZIIUYEGW6MDFJvvkI8VCV2nzU4peCwwRNAhHPXQA/DnNvp8bcLICDp+ptAA2t b+YSNxqdVvxlpTCLSsRtyaUG53ZpdregKukR7lM26IJjdl5DsulzQZBNga2JzEQOpIdT JsNjWFWkqW0Iw3MasvKpNyKvXq5JTJUQwZPMahhR8/H276huAGr4Gog9YNW3bfqkMo21 G+Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=HLoK6GXlNnGP4K5SxZmU2mM4NxfIC8P7/iZfrmZJlFY=; b=o1yaG7AoLXgSfCsGdHgTMhg4pB3CgSCnRLPApN7PNkVXdBo/Nj/Z6HnXUnIOmYittk FZOnI4BNeqK1rq1cw3q4D2FVXbA2A5XRBugYJdMKzJDFaQTaaBVpmwR//6K6S3Q02uMS jUcU0cn5PjO8+EP3fxQhfVQEtFnYJrABUKULG8IbRLTvaGGo4+J8UVbs/Jl5DuoktBWw H0YSjlwLR0KXnRR9JqpWmgnx/CFNP6Pn0WwKDQ9EdNLZVS7TlM05XmqDpXLlOOBvYzzY oJskQB4VBDGjARV4MNtVGKmbbGGKvbqc2/dfGdSQxxAtRMr3BF9/x1IJaC0hlW0lDkNd cOig== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=Mj6jSPmU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b61si12266108plb.22.2019.03.25.10.05.19; Mon, 25 Mar 2019 10:05:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@chromium.org header.s=google header.b=Mj6jSPmU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729669AbfCYRDA (ORCPT + 99 others); Mon, 25 Mar 2019 13:03:00 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:40203 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729106AbfCYRC7 (ORCPT ); Mon, 25 Mar 2019 13:02:59 -0400 Received: by mail-io1-f66.google.com with SMTP id d201so8253213iof.7 for ; Mon, 25 Mar 2019 10:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HLoK6GXlNnGP4K5SxZmU2mM4NxfIC8P7/iZfrmZJlFY=; b=Mj6jSPmUpB5kL6Ipz3ma6OMrOYO2ZIWcsGpEXosoT+ncrmyiVYrYrai75tO+wxcKgK 2QLWeTb27Y9EoXNk66PHYSubqM+5Ki+RIpUhTDlE9df29+aGK0tkmSJ/bP4r3TaJPYmV S19AzaTmmEeUqsLg/M4yG3SdSaUCL8yRnERVY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HLoK6GXlNnGP4K5SxZmU2mM4NxfIC8P7/iZfrmZJlFY=; b=UEKvofyilBOtJTkxn9+dIFGVhJDaEYORDW2YyjyCX3QIykxwrPqYew36Np1xjpu5zP V7L7cS2sUKPcVMprJMLyQahdeDV70+InAM4YHNT9BN4msPNBimrBtxbbRSIIQSC/zkUx iJUKG+V9s082uy0OU0BAgzIMtSxJ5E1rpKrwOyD07SGskLvEJH4P4UU5cy+LA1ysXPWN zU5AtR/F6xh7zusBQEdBIq42QLlc8KU6ZAOLv/7GDW15MW3FbuJy65xPnsb7Ey37NY8o VvipDuDTrcgEgkopQ9cGW9HvRXW4sCnsNVFLFRKKimsbx/W5Eum8gfTGBPocXhRGwR+0 bOfQ== X-Gm-Message-State: APjAAAXfWdORwwrDiQb7hg5f6QKJ8SUoBVYM5OBR7Lux6cf6v/Y5DAIq CsT+WE0PLbIeS8SvPWrR2LGHanE0ZFjwtA== X-Received: by 2002:a5e:db48:: with SMTP id r8mr17770800iop.220.1553533378987; Mon, 25 Mar 2019 10:02:58 -0700 (PDT) Received: from twawrzynczak.bld.corp.google.com ([2620:15c:183:200:3175:8c2d:44b6:cfea]) by smtp.gmail.com with ESMTPSA id t62sm5872797ita.35.2019.03.25.10.02.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Mar 2019 10:02:58 -0700 (PDT) From: twawrzynczak@chromium.org Cc: Benson Leung , Enric Balletbo i Serra , Guenter Roeck , linux-kernel@vger.kernel.org, Tim Wawrzynczak Subject: [PATCH v2] platform/chrome: mfd/cros_ec_sysfs: Add sysfs entry to retrieve EC uptime. Date: Mon, 25 Mar 2019 11:02:50 -0600 Message-Id: <20190325170250.2547-1-twawrzynczak@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tim Wawrzynczak 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 --- 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