Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp24387ybi; Thu, 13 Jun 2019 10:58:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpklCQ2ztivAz7xJwy/LF/pufcIxTwCHoNoXmkjcm4VfD7qUtxIm4OgHG0URW9Qn7aPafu X-Received: by 2002:a63:dc56:: with SMTP id f22mr16215857pgj.305.1560448701640; Thu, 13 Jun 2019 10:58:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560448701; cv=none; d=google.com; s=arc-20160816; b=D00tIn7Hlkq7di4BUs00VwdUotKJFJsebL0gchfnr+/HCADV69IQ6ASLN3NpHbRV8w dvFKFZFIsq0hf3DutdvvyfZ7A4h4QnUPPD++wNO5TvNtEjPQ2cFOisUdvp6RxPGn3XXf h3st7pvuYz7O9OQLJkECVqn6behUZBMfy/6/n8uXhQigA02QYQEras+FCd+/t71jGD6v ZkLMnNQPujScX1RBGMytEmW3da1xC5MsqMnHE/DyHRw0z6QdZiEW79AFQ+d3+G8iTsFr eLPII7pxPnPxpsfuk3kvRcu//NR2ZgcOKsmTqtGDqxMwpkCBnJBfNB7BfxdmVyp9i04G oKBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S+C5KnlUcg5YPzZfX26R37voPkYptIXnREwPhl8gT4c=; b=GbDtQv1GtvMshkwFZn5ie251woRTg1i0PfYidxqdBtj5CaCfSvfmD7poaGHuaENHuK uUw5yOdwRBfVtdNg4GZrCh32A71fseHYJNXlU8MTqyO3ycZI2LXOzLupDZ2IXKVtXemP XtSf9R5T1kLNPHQjMXQo15kABewJcYSnCy68rR0H64ycN0YOW04kgjDtbdJ9+yhN1LC7 9WvwstfTAILpzoBSEljKN35uxskPQv2C1Drn91Ysr/1jfCdBgCmQ7GQthzbQ+kD9aGvw LgMcSW9VuIOgL/3QtTJZQU0RJ+ryDtChTF+ii33K2n33UA6T/qPN6yV9IxcE7FIKxKOK 2Pfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AqI8F2BB; 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=pass (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 n63si305055pjb.36.2019.06.13.10.58.06; Thu, 13 Jun 2019 10:58:21 -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=pass header.i=@chromium.org header.s=google header.b=AqI8F2BB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727459AbfFMR56 (ORCPT + 99 others); Thu, 13 Jun 2019 13:57:58 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:35655 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbfFMR56 (ORCPT ); Thu, 13 Jun 2019 13:57:58 -0400 Received: by mail-io1-f67.google.com with SMTP id m24so18952072ioo.2 for ; Thu, 13 Jun 2019 10:57:57 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=S+C5KnlUcg5YPzZfX26R37voPkYptIXnREwPhl8gT4c=; b=AqI8F2BBGVu1AQ1QdKMRqGCvQpB4/wiYaeyLAwgWmgVRrgplVxSsHhYOmgrTvl8VK0 jgocQhcA+U0TrCIdBQapKE5yLVXWO57i7ONmO7p9CsS/3OUDpJyQ6J47nj1rEv/GerpP 4h2xArBSYHO+qkiyjyhs19XMw55shFqfIvw60= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=S+C5KnlUcg5YPzZfX26R37voPkYptIXnREwPhl8gT4c=; b=VDvs/+QYDQUSMG/OPuvFEFNyBstzZN8ctMu+Z/W/TXrTWaQ9MKpepYm4PrflI01OiS LxjB07q+tQriixFgfHGC/57006tGscmAl51EJ6bh/b/MViQfsxCxEeiHkg/1wzwkUCaG atsN6B1Y3yQ18VF1XgDHBX3UX16UZQnH7sTupvLQ3n9yCS4ShV7caEe+QM5fR8z4rpTX GvmviiiL4rGDROhkwo1dOQFrLaEEUJhNe7XYSfOdmS/Opcw3Lf93Fjqv3S6hFSl3ll/D WOcgR2scIy1zF10LFHWGuA8/A9zRzLOvuCQ1rhffdVetf3MMZXgH/MEtxeqeekDY3DIJ jPRA== X-Gm-Message-State: APjAAAVNY2vZoe8yn8jIFOKwRJy2/iKf9ENB7O9aAF6RcDTuET3D14E+ F2OthWRK23/VZCd/0bHdcCOyXEToWNxwOg== X-Received: by 2002:a05:6638:5:: with SMTP id z5mr18806075jao.58.1560448677432; Thu, 13 Jun 2019 10:57:57 -0700 (PDT) Received: from twawrzynczak.bld.corp.google.com ([2620:15c:183:200:b018:adbe:f5f7:d86b]) by smtp.gmail.com with ESMTPSA id k8sm491091iob.78.2019.06.13.10.57.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Jun 2019 10:57:56 -0700 (PDT) From: twawrzynczak@chromium.org To: Enric Balletbo i Serra Cc: Benson Leung , Olof Johansson , Tim Wawrzynczak , linux-kernel@vger.kernel.org Subject: [PATCH v6] platform/chrome: mfd/cros_ec_debugfs: Add debugfs entry to retrieve EC uptime. Date: Thu, 13 Jun 2019 11:57:36 -0600 Message-Id: <20190613175736.260117-1-twawrzynczak@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tim Wawrzynczak The new debugfs 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 --- Sorry about that Enric, I was confused that you meant Lee's tree. Also I got myself confused with all the patchsets :) Changelist from v5: 1) Rebase on lee's for-mfd-next Changelist from v4: 1) Add EC_CMD_GET_UPTIME_INFO 2) Rebase on top of 5.3 3) Get rid of cros_ec_create_uptime Changelist from v3: 1) Don't check return values of debugfs_* functions. 2) Only expose 'uptime' file if EC supports it. --- Documentation/ABI/testing/debugfs-cros-ec | 10 ++++ drivers/platform/chrome/cros_ec_debugfs.c | 56 +++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Documentation/ABI/testing/debugfs-cros-ec diff --git a/Documentation/ABI/testing/debugfs-cros-ec b/Documentation/ABI/testing/debugfs-cros-ec new file mode 100644 index 000000000000..ca6f4838ee0d --- /dev/null +++ b/Documentation/ABI/testing/debugfs-cros-ec @@ -0,0 +1,10 @@ +What: /sys/kernel/debug//uptime +Date: June 2019 +KernelVersion: 5.3 +Description: + Read-only. + Reads the EC's current uptime information + (using EC_CMD_GET_UPTIME_INFO) and prints + time_since_ec_boot_ms into the file. + This is used for synchronizing AP host time + with the cros_ec log. diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c index 4c2a27f6a6d0..dbba007c576d 100644 --- a/drivers/platform/chrome/cros_ec_debugfs.c +++ b/drivers/platform/chrome/cros_ec_debugfs.c @@ -241,6 +241,52 @@ static ssize_t cros_ec_pdinfo_read(struct file *file, read_buf, p - read_buf); } +static int cros_ec_get_uptime(struct cros_ec_device *ec_dev, u32 *uptime) +{ + struct { + struct cros_ec_command msg; + struct ec_response_uptime_info resp; + } __packed ec_buf; + struct ec_response_uptime_info *resp; + struct cros_ec_command *msg; + int ret; + + msg = &ec_buf.msg; + resp = (struct ec_response_uptime_info *)msg->data; + + msg->command = EC_CMD_GET_UPTIME_INFO; + msg->version = 0; + msg->insize = sizeof(*resp); + msg->outsize = 0; + + ret = cros_ec_cmd_xfer_status(ec_dev, msg); + if (ret < 0) + return ret; + + *uptime = resp->time_since_ec_boot_ms; + return 0; +} + +static ssize_t cros_ec_uptime_read(struct file *file, + char __user *user_buf, + size_t count, + loff_t *ppos) +{ + struct cros_ec_debugfs *debug_info = file->private_data; + struct cros_ec_device *ec_dev = debug_info->ec->ec_dev; + char read_buf[32]; + u32 uptime; + int ret; + + ret = cros_ec_get_uptime(ec_dev, &uptime); + if (ret < 0) + return ret; + + ret = scnprintf(read_buf, sizeof(read_buf), "%u\n", uptime); + + return simple_read_from_buffer(user_buf, count, ppos, read_buf, ret); +} + const struct file_operations cros_ec_console_log_fops = { .owner = THIS_MODULE, .open = cros_ec_console_log_open, @@ -257,6 +303,13 @@ const struct file_operations cros_ec_pdinfo_fops = { .llseek = default_llseek, }; +const struct file_operations cros_ec_uptime_fops = { + .owner = THIS_MODULE, + .open = simple_open, + .read = cros_ec_uptime_read, + .llseek = default_llseek, +}; + static int ec_read_version_supported(struct cros_ec_dev *ec) { struct ec_params_get_cmd_versions_v1 *params; @@ -408,6 +461,9 @@ static int cros_ec_debugfs_probe(struct platform_device *pd) debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info, &cros_ec_pdinfo_fops); + debugfs_create_file("uptime", 0444, debug_info->dir, debug_info, + &cros_ec_uptime_fops); + ec->debug_info = debug_info; dev_set_drvdata(&pd->dev, ec); -- 2.22.0.rc2.383.gf4fbbf30c2-goog