From patchwork Thu Feb 15 20:41:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 10223517 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 3DFB7602CB for ; Thu, 15 Feb 2018 20:42:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 284AE2953C for ; Thu, 15 Feb 2018 20:42:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21EA72955A; Thu, 15 Feb 2018 20:42:39 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A87B2953C for ; Thu, 15 Feb 2018 20:42:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755852AbeBOUl7 (ORCPT ); Thu, 15 Feb 2018 15:41:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:32844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752381AbeBOUl6 (ORCPT ); Thu, 15 Feb 2018 15:41:58 -0500 Received: from mail.kernel.org (unknown [185.189.112.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0BDCD21721; Thu, 15 Feb 2018 20:41:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0BDCD21721 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=sre@kernel.org Date: Thu, 15 Feb 2018 21:41:53 +0100 From: Sebastian Reichel To: Merlijn Wajer Cc: linux-omap@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: Charging status for N900/RX-51 with bq27200 Message-ID: <20180215204153.ztdal3qhtmgi7sjo@earth.universe> References: <581dcb51-f469-61c9-e023-62ac535bc41a@wizzup.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <581dcb51-f469-61c9-e023-62ac535bc41a@wizzup.org> User-Agent: NeoMutt/20171215 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Merlijn, On Thu, Feb 15, 2018 at 12:53:32PM +0100, Merlijn Wajer wrote: > On my N900, with kernel 4.15-rc6 (I realise it's not the very latest), > the (charging) status of the battery is confusing or plain wrong: > > When no charger is connected, this is reported: > > # cat > /sys/devices/platform/68000000.ocp/48072000.i2c/i2c-2/2-0055/power_supply/bq27200-0/status > Not charging > > When a charged is connected, this is reported: > > # cat > /sys/devices/platform/68000000.ocp/48072000.i2c/i2c-2/2-0055/power_supply/bq27200-0/status > Charging > > The odd part here is "Not charging" -- on all my other devices, a device > that is discharging is reported as "Discharging", not as "Not charging". "Not charging" is reported, when the battery is neither charged, nor dis-charged. It's supposed to be used when a charger is connected without charging the battery. > [...] > > The N900 reporting "Not charging" when it is in fact discharging > confuses userspace, such as UPower. It's a bug. > I am not particularly versed in the N900/RX-51 drivers, but from a > quick glance this line looks suspicious [1]. > > Cheers, > Merlijn > > [1] > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/power/supply/bq27xxx_battery.c#n1673 Basically the bq27xxx driver assumes, that charger is connected. I guess the problem is, that the N900 devicetree does not specify, that the bq27xxx is supplied by the charger, so power_supply_am_i_supplied returns -ENODEV. This can be fixed by adding the following to the N900 DT: &bq27200 { power-supplies = <&bq24150a>; }; But there is also a bug in the bq27xxx driver, that should cope with no charger being specified. The following patch should fix the issue. I currently don't have my N900 with me. Could you give it a try? -- Sebastian -------------------------------------------------- From 47642af85cc9ffc829b5f478e71b1751a98e2659 Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Thu, 15 Feb 2018 21:28:40 +0100 Subject: [PATCH] power: supply: bq27xxx: support missing supplier device power_supply_am_i_supplied() can return negative error codes. In this case we should assume, that no charger is connected and the battery should be marked as DISCHARGING instead of NOT_CHARGING. Reported-by: Merlijn Wajer Signed-off-by: Sebastian Reichel --- drivers/power/supply/bq27xxx_battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index d99981542a46..7ce60519b1bc 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -1670,7 +1670,7 @@ static int bq27xxx_battery_status(struct bq27xxx_device_info *di, status = POWER_SUPPLY_STATUS_FULL; else if (di->cache.flags & BQ27000_FLAG_CHGS) status = POWER_SUPPLY_STATUS_CHARGING; - else if (power_supply_am_i_supplied(di->bat)) + else if (power_supply_am_i_supplied(di->bat) > 0) status = POWER_SUPPLY_STATUS_NOT_CHARGING; else status = POWER_SUPPLY_STATUS_DISCHARGING;