From mboxrd@z Thu Jan 1 00:00:00 1970 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 1EB70C433EF for ; Fri, 1 Apr 2022 15:45:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344033AbiDAPrK (ORCPT ); Fri, 1 Apr 2022 11:47:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350546AbiDAPAI (ORCPT ); Fri, 1 Apr 2022 11:00:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E5C291565; Fri, 1 Apr 2022 07:47:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3C54360A53; Fri, 1 Apr 2022 14:47:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5DBEC36AE3; Fri, 1 Apr 2022 14:47:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648824466; bh=SuBR1hW/0xDCQAQZLmbTr1+EmG9QhsVoHp7VnORdMZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mcrpv6LX9VkOmM8EtxZ8tXkfcxuG1ZOnjBLScAaqe1zVtGidwHN7Pa4nliEFY777B dmM0+pMyZG38CHtJogwK8PXLxf6siRPeJbBntnhdNH1fPxgMEpDdJuE/P8FVXNXVCv l+6+FqQ86tGWOGOz/0QFsvInU2gNiVSDidv9UwK6qmNYkttDx1xfwZw8gvd9bsBVBn MjyTXmuE+1sxHy4MgTpWPaapAiM5Rt+Jm0ez98unLWBVHYshknPbLuoj8SBo333a1r wVWFwaSGWI06OQO6qSOeqzi7ASmFEdxNzkJgKNlBgV3wpsrv1xqR+hKC/brMegz/rc H6iZM6wdXUjbw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Evgeny Boger , Chen-Yu Tsai , Sebastian Reichel , Sasha Levin , sre@kernel.org, linux-pm@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 06/22] power: supply: axp20x_battery: properly report current when discharging Date: Fri, 1 Apr 2022 10:47:13 -0400 Message-Id: <20220401144729.1955554-6-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401144729.1955554-1-sashal@kernel.org> References: <20220401144729.1955554-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Evgeny Boger [ Upstream commit d4f408cdcd26921c1268cb8dcbe8ffb6faf837f3 ] As stated in [1], negative current values are used for discharging batteries. AXP PMICs internally have two different ADC channels for shunt current measurement: one used during charging and one during discharging. The values reported by these ADCs are unsigned. While the driver properly selects ADC channel to get the data from, it doesn't apply negative sign when reporting discharging current. [1] Documentation/ABI/testing/sysfs-class-power Signed-off-by: Evgeny Boger Acked-by: Chen-Yu Tsai Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/axp20x_battery.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index 7494f0f0eadb..a2e2443357fa 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -160,7 +160,6 @@ static int axp20x_battery_get_prop(struct power_supply *psy, union power_supply_propval *val) { struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy); - struct iio_channel *chan; int ret = 0, reg, val1; switch (psp) { @@ -240,12 +239,12 @@ static int axp20x_battery_get_prop(struct power_supply *psy, if (ret) return ret; - if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) - chan = axp20x_batt->batt_chrg_i; - else - chan = axp20x_batt->batt_dischrg_i; - - ret = iio_read_channel_processed(chan, &val->intval); + if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) { + ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval); + } else { + ret = iio_read_channel_processed(axp20x_batt->batt_dischrg_i, &val1); + val->intval = -val1; + } if (ret) return ret; -- 2.34.1