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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0982DC3525A for ; Wed, 24 Nov 2021 12:16:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243985AbhKXMTD (ORCPT ); Wed, 24 Nov 2021 07:19:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:47096 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243573AbhKXMOL (ORCPT ); Wed, 24 Nov 2021 07:14:11 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 965EE610E8; Wed, 24 Nov 2021 12:09:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1637755757; bh=i5IZgTlu9zgY0KdIW5G3K0QRC0Zp16AV/rIwZMwoqs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cmp/dq+NlCgPXq0QdQOiPvo7jv4DLp2M2MhA+8DmTKmSI5/iC/JFB2tHb6iNsO2t7 Z/595FwY+wEH8Z90Nq3f7PCjfau8d0V9kiQDEZOTBY/+Z8jXpxd++40Yoev2+Uuksu cpZbDTOUeoXf1wF5c0JtrXY7UU3j2CxMIUANbZgA= 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 4.9 045/207] power: supply: max17042_battery: use VFSOC for capacity when no rsns Date: Wed, 24 Nov 2021 12:55:16 +0100 Message-Id: <20211124115705.393330577@linuxfoundation.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20211124115703.941380739@linuxfoundation.org> References: <20211124115703.941380739@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 @@ -246,7 +246,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;