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 36936C433FE for ; Mon, 15 Nov 2021 19:27:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1DB6561526 for ; Mon, 15 Nov 2021 19:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245366AbhKOTUM (ORCPT ); Mon, 15 Nov 2021 14:20:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:57212 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238433AbhKORqk (ORCPT ); Mon, 15 Nov 2021 12:46:40 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0E3F863316; Mon, 15 Nov 2021 17:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1636997373; bh=P3Yzc4zLBmByPQy+SlKsb7qPEDaDInBD0d95VbZ4HC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aXiQdL8z0tL7YJGgAfnR9QUP7xPOJW5DHFFTvJxeUB1WD/LGD1a6C4fDT4s9ttj4I f35+7NAr3cVglu/Gu2EPIYiToFGGc/vJKAfjUzTvzYDA24hrep4wKDIegwqqXPCKN7 QUB0pCkj+KwLMJ17AjHoID9p9jsz4c+n3ZRny5T0= 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.10 125/575] power: supply: max17042_battery: use VFSOC for capacity when no rsns Date: Mon, 15 Nov 2021 17:57:30 +0100 Message-Id: <20211115165348.036898096@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211115165343.579890274@linuxfoundation.org> References: <20211115165343.579890274@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 @@ -316,7 +316,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;