Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2070856imb; Sun, 3 Mar 2019 17:03:37 -0800 (PST) X-Google-Smtp-Source: APXvYqxhqBHOjmAsV2DWVmLRszirtQXMBdf1ORJ6f1SoaDTpRoP6B17JYlkXQImnqghBvStIWw6n X-Received: by 2002:a62:788a:: with SMTP id t132mr17550422pfc.101.1551661417271; Sun, 03 Mar 2019 17:03:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551661417; cv=none; d=google.com; s=arc-20160816; b=QARRsbUZoSIoHpOVYps/VgaR3aGgUjy5NBLXQ3DGX/QRf2pTmPAzAeF0uFHE/Bvmjm VxSLFzZyCyrfeB5/YgEmZMBRMzRbgaWFkis3KX8FpTK3Vr8h3XtEmczD7qYHbI5xvznG LrQyy25L0MKKDqlJjFge0rlS/uHNjz4ub4pGiqGlcZfNSyZxE3bfja1D3hwoYGL82/Gw MG8rNKu9xtE857/QORVLebSx1kzviMKeXNZvT5Jtm7eFvVwQLDACUN/BJfyOF42jTPww JtEMscD6lNqH8dvVyG9TnYnBOAEs+npOufNY0gi+3lrfVPtlYBt/pUXXdXONGQWYGs21 repw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=nZ8L3AK9nFah5RoucXb6574z84G9P6bkJYPZQpK8AT8=; b=GYb0CUkgUSSaRWadWxUleSupQkf0pwalp0XTni43OxZ1GJjnyKNbDLEySOJP5+OWKB Fud3AlRndLK16K9T+CawSFYCRvujx+2XdSYLVS3nBX/RmBnBAEUNzPiEX01L8t5p21Rk LwNVF3C7I4AGI/LbR2jYxLa78f4KxrBoQOD8FPHtjQrxkavajo/Gdpg8tM9kVqy8B3qY scQ/FG5Syyux41azIiPuHMVpJ+YS/9OOAuDodLwK7by5kGc6CdjZINd+qdi2g3b0AWCM /E6x70rdVmodQda6TKp0XijpARSXhGR6eDjM2uH2ru1xGgeRUFrUm9fjwLSBqYY2lcII lYmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=HBHs1ZR1; 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 b125si4152617pfb.242.2019.03.03.17.03.21; Sun, 03 Mar 2019 17:03:37 -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=HBHs1ZR1; 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 S1726090AbfCDBCz (ORCPT + 99 others); Sun, 3 Mar 2019 20:02:55 -0500 Received: from mail-qk1-f196.google.com ([209.85.222.196]:43593 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725962AbfCDBCz (ORCPT ); Sun, 3 Mar 2019 20:02:55 -0500 Received: by mail-qk1-f196.google.com with SMTP id f196so1951130qke.10 for ; Sun, 03 Mar 2019 17:02:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nZ8L3AK9nFah5RoucXb6574z84G9P6bkJYPZQpK8AT8=; b=HBHs1ZR1YNljbbrzpAgI/qvoSerqyAXQ8MHxX7H/APi3g4RWDGSt2pMGaaPMtApOkF HrfiNqiaDUOp08rpbo8Wb5k3qFzq8x+/5Z5oOaMUi+kPnkRvKWL+DEeUY3ILKIU0Gjlq jH44jctnJ85yfPrX/UkYZ8BEobUHjU1C10wBE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nZ8L3AK9nFah5RoucXb6574z84G9P6bkJYPZQpK8AT8=; b=JCf26KqzlLhUvA2RypEs+HRNZ8YnIiigFlHfbm5kcgTKy1XDc1sUkrbjUPgbAtJTHg yUh5iuLjAjbw9Sy/czOBjNorCVncMa5tYaONbLkHoDgRqq3Clsipi10vacKtm6hM1hyb TeN7CQYp5IUHJbPBLvOTT0vkgaxTIq9sLhGe4s5Tutm8RiSA6aAzPrKAawLJpEphENS7 xE5kQLbhKLBC/9W/8526xyRD39Mn4TWjjLO9M8SCdis76QwcUf0ESf6ufkzy6lH4t5Mj GmGV3ljsQLXhOezjm3twp3Kw8kx6LsI8UtD/Fbrnh9dXHiFsNGLooLhwFmFwG+AEP3Im qiWw== X-Gm-Message-State: APjAAAU7QwSnoWyX+ko46Or9sl9/o9laIwjhIwH69KNAEHbPqH7HvQWo Iv+Yex/AQyhPvDJK5nQEOFx/KBx8CEWypKuCYByV8A== X-Received: by 2002:a37:4f44:: with SMTP id d65mr11441082qkb.287.1551661373752; Sun, 03 Mar 2019 17:02:53 -0800 (PST) MIME-Version: 1.0 References: <20190301192156.253010-1-ravisadineni@chromium.org> In-Reply-To: From: Ravi Chandra Sadineni Date: Sun, 3 Mar 2019 17:02:42 -0800 Message-ID: Subject: Re: [PATCH] cros_ec: Expose sysfile to force battery cut-off on shutdown. To: Guenter Roeck Cc: Benson Leung , Enric Balletbo i Serra , Guenter Roeck , linux-kernel , Todd Broch , Daisuke Nojiri Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Guenter, On Fri, Mar 1, 2019 at 1:00 PM Guenter Roeck wrote: > > On Fri, Mar 1, 2019 at 11:22 AM RaviChandra Sadineni wrote: >> >> 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 >> --- >> 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 f34a50121064..151c7c143941 100644 >> --- a/drivers/platform/chrome/cros_ec_sysfs.c >> +++ b/drivers/platform/chrome/cros_ec_sysfs.c >> @@ -322,14 +322,48 @@ static ssize_t kb_wake_angle_store(struct device *dev, >> return count; >> } >> >> +/* Battery cut-off control */ >> +static ssize_t cutoff_battery_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); >> + uint8_t cutoff_battery; >> + >> + if (kstrtou8(buf, 10, &cutoff_battery) || (cutoff_battery != 1)) > > > Excessive ( ). Also, why not kstrtobool() ? Done. > >> >> + return -EINVAL; >> + >> >> + 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; > > > For some reason I fail to see where cutoff_battery is used to determine what to send to the EC. Am I missing something ? Currently there is no way to reset the flag. i.e EC does not expose a console command to reset the flag once set. So I intend to accept only true bool flag. Is there a better way to do this ? > >> >> + 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_battery_at_shutdown); >> > > I personally dislike excessively long sysfs attribute names. I would prefer to see a shorter name and have it documented in Documentation/ABI/testing/sysfs-class-chromeos. > > Is WO really desirable and warranted here ? Currently EC does not expose a host command to read the status. Maintaining the state in the kernel might not work as the state can go out of sync. For example, when AC is plugged in, EC resets the flag and the kernel will not be aware of it. > >> >> 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 >> Thanks, Ravi