From patchwork Tue Oct 25 10:24:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pavel Machek X-Patchwork-Id: 9394271 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 88CCD60231 for ; Tue, 25 Oct 2016 10:26:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 797D529273 for ; Tue, 25 Oct 2016 10:26:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E17629316; Tue, 25 Oct 2016 10:26:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0FE2B29273 for ; Tue, 25 Oct 2016 10:26:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1byyup-0002tE-2R; Tue, 25 Oct 2016 10:25:07 +0000 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1byyui-0002fS-Bj for linux-arm-kernel@lists.infradead.org; Tue, 25 Oct 2016 10:25:02 +0000 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id 53F68823B9; Tue, 25 Oct 2016 12:24:36 +0200 (CEST) Date: Tue, 25 Oct 2016 12:24:35 +0200 From: Pavel Machek To: Pali =?iso-8859-1?Q?Roh=E1r?= Subject: Re: [RFC] shutdown machine when li-ion battery goes below 3V Message-ID: <20161025102435.GA6916@amd> References: <20161024212250.GA31336@amd> <20161024212932.uhjz752z2cy5hohl@atomide.com> <20161024214152.GA32310@amd> <201610242348.47484@pali> MIME-Version: 1.0 In-Reply-To: <201610242348.47484@pali> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161025_032500_681377_E9C3DF37 X-CRM114-Status: GOOD ( 20.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ivo.g.dimitrov.75@gmail.com, khilman@kernel.org, Tony Lindgren , aaro.koskinen@iki.fi, sre@kernel.org, kernel list , abcloriens@gmail.com, linux-omap@vger.kernel.org, patrikbachan@gmail.com, linux-arm-kernel , serge@hallyn.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon 2016-10-24 23:48:47, Pali Rohár wrote: > On Monday 24 October 2016 23:41:52 Pavel Machek wrote: > > On Mon 2016-10-24 14:29:33, Tony Lindgren wrote: > > > Also, the shutdown voltage can depend on external devices > > > connected. It could be for example 3.3V depending on eMMC on some > > > devices while devices with no eMMC could have it at 3.0V. > > > > Actually, I'd like to shutdown at 3.3V or more (like 3.5V), because > > going below that is pretty mean to the battery. But if I set > > threshold too high, GSM activity will push it below that for a very > > short while, and I'll shutdown too soon. > > > > Ideas welcome... > > bq27x00 has EDVF flag which means that battery is empty. Maemo with > bq27x00 driver is configured to issue system shutdown when EDVF is set. > > Maybe kernel should issue emergency shutdown e.g. after minute or two > after EDVF flag is set? Thanks for pointer. EDVF seems to be exposed as health. ... but only if battery is calibrated, AFAICT. if (has_ci_flag && (cache.flags & BQ27000_FLAG_CI)) { dev_info_once(di->dev, "battery is not calibrated! ignoring capacity values\n"); ... cache.health = -ENODATA; Plus, it prioritizes battery cold over battery dead. IMO we don't need to shutdown on battery cold (we just may not charge the battery), but we need to shutdown on battery dead. So something like this? Pavel Signed-off-by: Pavel Machek diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index 8eb2f8f..5ddf6d7 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -680,10 +680,10 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di) /* Unlikely but important to return first */ if (unlikely(bq27xxx_battery_overtemp(di, flags))) return POWER_SUPPLY_HEALTH_OVERHEAT; - if (unlikely(bq27xxx_battery_undertemp(di, flags))) - return POWER_SUPPLY_HEALTH_COLD; if (unlikely(bq27xxx_battery_dead(di, flags))) return POWER_SUPPLY_HEALTH_DEAD; + if (unlikely(bq27xxx_battery_undertemp(di, flags))) + return POWER_SUPPLY_HEALTH_COLD; return POWER_SUPPLY_HEALTH_GOOD; }