Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2066970imb; Sun, 3 Mar 2019 16:55:19 -0800 (PST) X-Google-Smtp-Source: APXvYqycyYZq+MA8NLurkf+QDC2pDc1CNb9TlAOMaamh4I2dyThzyPU11sh8qw7iuUM2/X9Y+dET X-Received: by 2002:a17:902:282b:: with SMTP id e40mr17655425plb.111.1551660918929; Sun, 03 Mar 2019 16:55:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551660918; cv=none; d=google.com; s=arc-20160816; b=ztbwIyEOQccEkIlO+dOjjtL6m00vauFal4dQtY7NuKdnuznM8KHUmuwyJok9Bbju8z MUTP2j7J19MEccuawMQHf/mLq3k0w9AMjBsid3eC8H/Sed3qeLIxZeVHMriOHeAkDN4V tovIX/GwRiHzmOXS7b4CEhPg5g1gwm/L4+MI00szsyDHMtGL1GBjgw4I0rj8xSxkf3ip pf7TqzV09Z3g9lA78FwR8QKuzxnehlbuIujaYI/36RVHWdNUVhTcZ4ye0cj39h2M5SVT /HZbfEZG6X3Gj37EiI6/l7faIM1W4yDaJoBWXv++XVwWLbt5jmXB8uecFOj0Hcee9nn6 p/DQ== 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=PLPQ4soph4vxPlH+wbj1lca5XYhfxI+OtP5XJZcYUfc=; b=o5PV4/19XkMnXIk4QHeqfEnrtaYQSQm6zt0Jc0qvBKKMZOK4HoZcF1Ng1or3vBCUl8 bYyz3iECA+7wrmcvZHFxNmmFYaUY3Dt6e1GAd5OLJQVZ/OlbNWLDKO+n80nHjg8ETTD5 80L352T1qlzmRysaVoyX9XPQvhwt2GanPEBcihRRS7C+Rd8LrGVzqrzdpl8tick/ykNr oY1pWSxbg7GyFzc4ta3BL0STX+pRVYvp+xKJ/IqCWJNF0fX17v8k1rblJX5FUX0YVOIh yxpK/Oq1sgigEbgxwWKNsg65FxT5mcNTWlyiACcEfELwkyK7/qoe+IMkHcRpMIMMd4u7 eFgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=h4zzeMZJ; 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 x18si4113791pll.104.2019.03.03.16.55.04; Sun, 03 Mar 2019 16:55:18 -0800 (PST) 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=h4zzeMZJ; 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 S1726096AbfCDAyY (ORCPT + 99 others); Sun, 3 Mar 2019 19:54:24 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:33275 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725962AbfCDAyX (ORCPT ); Sun, 3 Mar 2019 19:54:23 -0500 Received: by mail-pf1-f194.google.com with SMTP id i19so1716575pfd.0 for ; Sun, 03 Mar 2019 16:54:23 -0800 (PST) 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=PLPQ4soph4vxPlH+wbj1lca5XYhfxI+OtP5XJZcYUfc=; b=h4zzeMZJ5t3OL7t9OsPIjJe29QHtx1xPUJBKoeKSDSCplvLUzgt5ycvJzN4k1vQkei c1pZpNLsSIb8LjkN30PQQeQe3CbvQLscstMcQZgb0bdLvA1yMrIBU46rr/fFIjQhpjI6 lindm/Lw+L4RxoFqJHv03uFWCzBor6tBU7Jzg= 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=PLPQ4soph4vxPlH+wbj1lca5XYhfxI+OtP5XJZcYUfc=; b=Q+SLaefCy/FXPqHxWJNVRoMGMSS0HtIuFwFQPzGii/VJCSxLDVG+gT1kCuZlv6lbRp YCybQjmcM0IT91ted0lGPa2aB+eDXod9bIlvKLih8/bM7ZnG0DxtG2jn5QMZ7LlQoFuQ KIef9pDbx5knoqbf1wqA8E3jIDW/LxK1W66x2Cye+b2O3G/MwQYQ/iA7tMOC9t/PbIVg KH88X5tu2YNhdbeX9d/ww67icblnWIXOCpkV0WHZhAS+cDqb3hO7M5VluwH36SDkQ45W /YMK7uffuUeo5qg8l8EXfEs+lNZh4GA6c/+bZAjzNNKOs91+aDjkYECnNhoqKiRoGcpd 1NBQ== X-Gm-Message-State: APjAAAXQ8ElwQDwoUwM2YM+dXiTKJrMoKDSP6rvxSQafD9QeGWvbc5J9 GFEaXw4g4TiZoNtFTNAdSLrxgxLoCJw= X-Received: by 2002:a62:3990:: with SMTP id u16mr17437485pfj.80.1551660862833; Sun, 03 Mar 2019 16:54:22 -0800 (PST) Received: from ravisadineni0.mtv.corp.google.com ([2620:15c:202:1:98d2:1663:78dd:3593]) by smtp.gmail.com with ESMTPSA id k10sm7412446pgp.91.2019.03.03.16.54.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 03 Mar 2019 16:54:22 -0800 (PST) From: RaviChandra Sadineni To: ravisadineni@chromium.org Cc: Benson Leung , Enric Balletbo i Serra , Guenter Roeck , linux-kernel@vger.kernel.org, tbroch@google.com, dnojiri@google.com Subject: [PATCH V2] cros_ec: Expose sysfile to force battery cut-off on shutdown. Date: Sun, 3 Mar 2019 16:54:14 -0800 Message-Id: <20190304005414.218310-1-ravisadineni@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 On chromebooks, power_manager daemon normally shutsdown(S5) the device when the battery charge falls below 4% threshold. Chromeos EC then normally spends an hour in S5 before hibernating. If the battery charge falls below critical threshold in the mean time, EC does a battery cutoff instead of hibernating. On some chromebooks, S5 is optimal enough resulting in EC hibernating without battery cut-off. This results in battery deep-discharging. This is a bad user experience as battery has to trickle charge before booting when the A.C is plugged in the next time. This patch exposes a sysfs file for an userland daemon to suggest EC if it has to do a battery cut-off instead of hibernating when the system enters S5 next time. Signed-off-by: RaviChandra Sadineni --- V2: Use kstrtobool() instead of kstrtou8() and add documentation. .../ABI/testing/sysfs-class-chromeos | 8 ++++ drivers/platform/chrome/cros_ec_sysfs.c | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-chromeos diff --git a/Documentation/ABI/testing/sysfs-class-chromeos b/Documentation/ABI/testing/sysfs-class-chromeos new file mode 100644 index 000000000000..44d3cee6e7ae --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-chromeos @@ -0,0 +1,8 @@ +What: /sys/class/chromeos/cros_ec/cutoff_at_shutdown +Date: February 2019 +Contact: Ravi Chandra Sadineni +Description: + On writing '[Yy1]' to cutoff_at_shutdown property, + kernel sends a host command to EC requesting battery + cutoff on next shutdown. If AC is plugged in before + next shutdown, EC resets this flag. diff --git a/drivers/platform/chrome/cros_ec_sysfs.c b/drivers/platform/chrome/cros_ec_sysfs.c index f34a50121064..f5168ce8bfc7 100644 --- a/drivers/platform/chrome/cros_ec_sysfs.c +++ b/drivers/platform/chrome/cros_ec_sysfs.c @@ -322,14 +322,51 @@ static ssize_t kb_wake_angle_store(struct device *dev, return count; } +/* Battery cut-off control */ +static ssize_t cutoff_at_shutdown_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct ec_params_battery_cutoff *param; + struct cros_ec_command *msg; + int ret; + struct cros_ec_dev *ec = container_of( + dev, struct cros_ec_dev, class_dev); + bool cutoff_battery; + + if (kstrtobool(buf, &cutoff_battery)) + return -EINVAL; + + if (!cutoff_battery) + return count; + + msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + param = (struct ec_params_battery_cutoff *)msg->data; + msg->command = EC_CMD_BATTERY_CUT_OFF + ec->cmd_offset; + msg->version = 1; + param->flags = EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN; + msg->outsize = sizeof(*param); + msg->insize = 0; + ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg); + kfree(msg); + if (ret < 0) + return ret; + return count; +} + /* Module initialization */ 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_WO(cutoff_at_shutdown); static struct attribute *__ec_attrs[] = { + &dev_attr_cutoff_battery_at_shutdown.attr, &dev_attr_kb_wake_angle.attr, &dev_attr_reboot.attr, &dev_attr_version.attr, -- 2.20.1