Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp242001ybt; Tue, 7 Jul 2020 21:54:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSdGc8yP/697l+i4Dp7R7EW9SV3d13Jhj0evd2iNtQOt1Ugt3ebZPtjlhdg9mcL5S5IT+a X-Received: by 2002:a17:906:fcc1:: with SMTP id qx1mr51427321ejb.379.1594184051936; Tue, 07 Jul 2020 21:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594184051; cv=none; d=google.com; s=arc-20160816; b=SrfYeyiNSkKkspkAPxPpCm3H5abpK5ugpD07nWI/C4tv4jBdTQ866Z/HOtNxyhysFl jWoTAGX1iKA4deE792nM5XPSkZXVzZ4NLq736tRWUoXYAnkyXA4UJ1KfDnqLtSSbiXQI zlN4u8dOu5ucbbXSZrIEmzvSmUiJPwMzmTa/3znHrZVQcTOXA35rk2jWn+VtJ/LxfGNz fXoCtZiWnp+zCcpLymuNsyJzTNNodjHktqhxiUIfmBOV7kLXYAdSU3cidtMH+JoySw05 Koe0DeUN4gKyMDg4dRKn+W41sjW5yhhSc7bKSKNOsB+GAB37dkSR3mdiZIzr/ZF7jwMu p6rA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=n8PnW3sFHAwVEzGZ63D4MDBKW+EPhyK1cLjmjloA+4g=; b=0DQ6Bj+rRHkliL8Uve9wToUxcqa+aActePyYdsJr7H/kvnlZ93deCPYlOyu8kXe1er ABF08GxwbSas3fvnqSZO06bFiZXFV2zS+lcwABJAMzbnlK9SCqcqAT6bS0P4who/ucWQ v6EPu29cjdj1JIQ2mlOBrRwIwdVY54ixN4SOO1/cvL9Dgo26D7OwKUHKg0pJx3x+1TKV diOKL6nJaJ+IORMveIcbCbInV1tsBohRPSonXNuqGx5L32Te9+tO6trjM9SPnwhQhpTr CslO4ZgOZ+8SA6hGxFGDOMmxOwRHKWmzIgINUaccYP+hpKMt1fPP42Jxi65th5eNu1U/ bihQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Yc9NoAIT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id mm15si14658796ejb.561.2020.07.07.21.53.49; Tue, 07 Jul 2020 21:54:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Yc9NoAIT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728927AbgGHExQ (ORCPT + 99 others); Wed, 8 Jul 2020 00:53:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726102AbgGHExQ (ORCPT ); Wed, 8 Jul 2020 00:53:16 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E533C061755 for ; Tue, 7 Jul 2020 21:53:16 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id e8so21088124pgc.5 for ; Tue, 07 Jul 2020 21:53:16 -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=n8PnW3sFHAwVEzGZ63D4MDBKW+EPhyK1cLjmjloA+4g=; b=Yc9NoAITE98gAWoI7c21HmGv2cbj4L3Bb0cH5RajuuYQM5zScqrDN8hHcmjxM3CRa2 9dvRZKO02Gg5eF33MXy5UvA2TsXjN9GmEZpPBOUUq2HSanFAeS6JB1RXqw2xrppORwdr 1FASBv9+T3x25rMUtNu5LljdtFOPx+JMl16xw= 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=n8PnW3sFHAwVEzGZ63D4MDBKW+EPhyK1cLjmjloA+4g=; b=I+rhM1VdwSx9M6OWmVZvlwwnlwTu20xYlyDnyiAM0NOc8YHajeEcRywm3M5m+k2Zyv KpGqh6vGy5/gcNPOQkgWZwsYvJPkFmMVP4z/Iy9DveKuqvfvhSIRPKZEgstnz38rcZI9 IOpSAef0S61ugvrCtqU+L/V6KZVGpFHa+ZSPpd9UAwfMYKF9H1ZGLvuIkPUWY0aZkg2C aVaazrfJgoJ6OIRCKI1YSWqazYwO75i+u7w7u+3JvVznMDB9vDWfu2YN6qtKYgMFPdtP QEMZDJ1KYC7UaKQd0bduXE4q5g/ap9wPdmuToQQA830RIwIw9zeY4XiizZjAdnkVIL7m zzTQ== X-Gm-Message-State: AOAM533O77vSDJuWVmBz6JXKIW+lDFX8lhoCKT0la0U18Wlc+Zkuz2CW kMLmiHKHYnDcDcuqVRZ/L6kJ28DFzW8= X-Received: by 2002:aa7:8d95:: with SMTP id i21mr4807045pfr.240.1594183995606; Tue, 07 Jul 2020 21:53:15 -0700 (PDT) Received: from localhost ([2401:fa00:9:14:f693:9fff:fef4:fbcd]) by smtp.gmail.com with ESMTPSA id e5sm4020470pjy.26.2020.07.07.21.53.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Jul 2020 21:53:15 -0700 (PDT) From: Eizan Miyamoto To: LKML Cc: Eizan Miyamoto , Benson Leung , Enric Balletbo i Serra , Guenter Roeck Subject: [PATCH v1] platform/chrome: cros_ec_debugfs: conditionally create uptime node Date: Wed, 8 Jul 2020 14:53:00 +1000 Message-Id: <20200708145215.v1.1.I9d49b374536424fcc98bc6bd935cdab8fac2ae71@changeid> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog 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 Before creating an 'uptime' node in debugfs, this change adds a check to see if a EC_CMD_GET_UPTIME_INFO command can be successfully run. If the uptime node is created, userspace programs may periodically poll it (e.g., timberslide), causing commands to be sent to the EC each time. If the EC doesn't support EC_CMD_GET_UPTIME_INFO, an error will be emitted in the EC console, producing noise. Signed-off-by: Eizan Miyamoto --- drivers/platform/chrome/cros_ec_debugfs.c | 35 +++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_debugfs.c b/drivers/platform/chrome/cros_ec_debugfs.c index ecfada00e6c51..8708fe12f8ca8 100644 --- a/drivers/platform/chrome/cros_ec_debugfs.c +++ b/drivers/platform/chrome/cros_ec_debugfs.c @@ -242,17 +242,14 @@ static ssize_t cros_ec_pdinfo_read(struct file *file, read_buf, p - read_buf); } -static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf, - size_t count, loff_t *ppos) +static int cros_ec_get_uptime(struct cros_ec_device *ec_dev, + uint32_t *uptime) { - struct cros_ec_debugfs *debug_info = file->private_data; - struct cros_ec_device *ec_dev = debug_info->ec->ec_dev; struct { struct cros_ec_command cmd; struct ec_response_uptime_info resp; } __packed msg = {}; struct ec_response_uptime_info *resp; - char read_buf[32]; int ret; resp = (struct ec_response_uptime_info *)&msg.resp; @@ -264,8 +261,24 @@ static ssize_t cros_ec_uptime_read(struct file *file, char __user *user_buf, if (ret < 0) return ret; - ret = scnprintf(read_buf, sizeof(read_buf), "%u\n", - resp->time_since_ec_boot_ms); + *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]; + int ret; + uint32_t uptime; + + 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); } @@ -425,6 +438,7 @@ static int cros_ec_debugfs_probe(struct platform_device *pd) const char *name = ec_platform->ec_name; struct cros_ec_debugfs *debug_info; int ret; + uint32_t uptime; debug_info = devm_kzalloc(ec->dev, sizeof(*debug_info), GFP_KERNEL); if (!debug_info) @@ -444,8 +458,11 @@ 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); + if (cros_ec_get_uptime(debug_info->ec->ec_dev, &uptime) >= 0) + debugfs_create_file("uptime", 0444, debug_info->dir, debug_info, + &cros_ec_uptime_fops); + else + dev_dbg(ec->dev, "EC does not provide uptime"); debugfs_create_x32("last_resume_result", 0444, debug_info->dir, &ec->ec_dev->last_resume_result); -- 2.27.0.383.g050319c2ae-goog