Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3450140pxb; Mon, 4 Apr 2022 17:21:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkQjlb66HugqgejbRmcN624HU4yU6+tFXDLIZgSRLtAvmAmPzvEv7c9bzML8fadZLmu3oH X-Received: by 2002:a05:6a00:a15:b0:4fb:4112:870e with SMTP id p21-20020a056a000a1500b004fb4112870emr679380pfh.11.1649118097204; Mon, 04 Apr 2022 17:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649118097; cv=none; d=google.com; s=arc-20160816; b=I8f1TN61MphUQhiAGvjVB+2keL4H43cxQ0LtqNfYUk+FLIdu5MFb+1r+5lUmA2nVmG bER68UUvIpvQSwpooA/VeU52+GRTPk6ux4gqeuQGTeSRcfjeBTMeGv7WlmPKZewHSp7y g2qpGcVbhDVLMsHrbcFqdtZhlpRxxWd5zX2ocgS5yoVm8+O9c+EYCgFQe361mjnIiP9L dQphQN51GVwUkKFTLWhQVyrmZdtHKJHHGCLi6Zo/JiTC+/bFQ/EWvncDPZQsWOvwClmW /nEWRmovft7BjuDVKQYuAl9omNJwuvRBKhB86jK0nJM5p+OGk9HsN/4ET3fikruZ7kO7 5WZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ewzo9wamtXPALcouwu5I5j8vVTTlHS/uzdgGlFVVtqg=; b=t/RAQwq1ycKdYY/NmMQdFpATgwjlSKp5P4v8n7JG9Lvqc5eEo+WWAOiNxz3HyRAU/I KI/Wyu7QWp+LlkUoEDD+e2JnIpe7Ofsx6j7jx3UvxkU/gJ7wZpZOHWfm/zve6p+LPGWG eFDxeoQw/NU261DPCJpTwE+gMyO2FnDhihS04R8Y+XqUOLPhVGTkWHkXbP9oy/aFifWg Xp9kUj7LW16ircqvkrN7B2PDnGOGe5iAoBKutuNj0k/QTafgAzZlRTImarolLn7DfY5A yVSsfsbkGjK5CR5ypQS8jYvg48P6I8GrBGPKGmIwX3Vxj0SiqM06yXTwaURXNkpJK+EL EaBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ce2jmIsw; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id f11-20020a170902ce8b00b00153b2d1653dsi11510440plg.325.2022.04.04.17.21.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 17:21:37 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ce2jmIsw; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 85C2F75600; Mon, 4 Apr 2022 16:47:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347289AbiDAOb5 (ORCPT + 99 others); Fri, 1 Apr 2022 10:31:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347245AbiDAOaq (ORCPT ); Fri, 1 Apr 2022 10:30:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EFB728B10D; Fri, 1 Apr 2022 07:27:42 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2B295B82505; Fri, 1 Apr 2022 14:27:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBA91C340EE; Fri, 1 Apr 2022 14:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648823260; bh=2ViwZkbjY63eUQxxgCosViXi4slLzpHzcABYkWOc+9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ce2jmIswMKKhpaRPvKcsOdaNw0GLpTP0OkbccdPhRdbrXMEB0hhIkmy1j/HRI935h yPKWGeRUJgHqate590pSpxB9ZlfdSqRCLYBMEUl/IZFtICbNxypjesgQGP+INe4tkO HAan+nVxWBA7U/SYpnlxgfmHa4IuACmzD+H2cBkSdVsWZv/zmRrIHR8vuVcTGCpGkS P6KglzsFeyK9HRyM4BuSU1GZ3zGnJNkpTkCohlwbuOQH2K5Wl+k/5+erJJzoNaPy+C j1D6adYHHdl+ulGdQiyx3W59xpGAna9TWfvz1lGjpeWXSAt28lvBzgsAbNZ4A5yw/v hdb6AZKKLZ/YQ== 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 5.17 038/149] power: supply: axp20x_battery: properly report current when discharging Date: Fri, 1 Apr 2022 10:23:45 -0400 Message-Id: <20220401142536.1948161-38-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220401142536.1948161-1-sashal@kernel.org> References: <20220401142536.1948161-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 5d197141f476..9106077c0dbb 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -186,7 +186,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) { @@ -266,12 +265,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