Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 910FBC433EF for ; Mon, 15 Nov 2021 17:28:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EB6F63292 for ; Mon, 15 Nov 2021 17:28:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236805AbhKORbN (ORCPT ); Mon, 15 Nov 2021 12:31:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:41950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236855AbhKORO7 (ORCPT ); Mon, 15 Nov 2021 12:14:59 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 988FE63253; Mon, 15 Nov 2021 17:11:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1636996301; bh=ae12yPE0FGuOl5/OdtdlkIjDReYRtkavE6qsNLUd/9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RGMXei1DvpGgkF2/mBCR1wwNL0Qzy1JZOIbG+Cyk6+2Ikju50e+ha3AjVflI5mbdZ GhdsvKgSwU/TTlY07lOcJsYXMGcrgcnH/wXKgtj05uXiPfFBmVhmaZbwetAoGel2AZ ITScQmQQB+3VBDdM6DKxQB7JsoJh0Pj2od97lmJo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Krzysztof Kozlowski , Wolfgang Wiedmeyer , Henrik Grimler , Hans de Goede , Sebastian Reichel Subject: [PATCH 5.4 089/355] power: supply: max17042_battery: use VFSOC for capacity when no rsns Date: Mon, 15 Nov 2021 18:00:13 +0100 Message-Id: <20211115165316.681773641@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211115165313.549179499@linuxfoundation.org> References: <20211115165313.549179499@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Henrik Grimler commit 223a3b82834f036a62aa831f67cbf1f1d644c6e2 upstream. On Galaxy S3 (i9300/i9305), which has the max17047 fuel gauge and no current sense resistor (rsns), the RepSOC register does not provide an accurate state of charge value. The reported value is wrong, and does not change over time. VFSOC however, which uses the voltage fuel gauge to determine the state of charge, always shows an accurate value. For devices without current sense, VFSOC is already used for the soc-alert (0x0003 is written to MiscCFG register), so with this change the source of the alert and the PROP_CAPACITY value match. Fixes: 359ab9f5b154 ("power_supply: Add MAX17042 Fuel Gauge Driver") Cc: Reviewed-by: Krzysztof Kozlowski Suggested-by: Wolfgang Wiedmeyer Signed-off-by: Henrik Grimler Reviewed-by: Hans de Goede Signed-off-by: Sebastian Reichel Signed-off-by: Greg Kroah-Hartman --- drivers/power/supply/max17042_battery.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -312,7 +312,10 @@ static int max17042_get_property(struct val->intval = data * 625 / 8; break; case POWER_SUPPLY_PROP_CAPACITY: - ret = regmap_read(map, MAX17042_RepSOC, &data); + if (chip->pdata->enable_current_sense) + ret = regmap_read(map, MAX17042_RepSOC, &data); + else + ret = regmap_read(map, MAX17042_VFSOC, &data); if (ret < 0) return ret;