Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp433851pxu; Fri, 4 Dec 2020 06:54:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJyH7+DltsnH0gJgLheaz1H9Ea+BhgAr6B5qDtIvSdGVInYZuelztZm6vm5If58BKKqU01Er X-Received: by 2002:a50:85c6:: with SMTP id q6mr8211252edh.126.1607093685934; Fri, 04 Dec 2020 06:54:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607093685; cv=none; d=google.com; s=arc-20160816; b=WNgFz6goseXri+4iZ6yUjuYQx5H/hTbCFMxv+zbio7Dkfn6R932GEAaqGf+Wt0Ps8d FbRdViO9cZueDJLUEvv9DvvxiuaOvc5BatS2sDvCjyy500azaNh04kwWinoGzMv+gx2t R+87fjGy8lRTZFU8rnA4xSj/kTSuTjfvL/uIUVPXk44kK7u0LZUJ9wPAXU1V5zQ4kYs9 HgJM10sOyofbzmMp1xl5hJdqS33wKzbsKoL5oEGgqGlH2neGGhUVqBZCvQb6oFZKaN1g OCdl7aj3fRSlycWHI/U9onZZEKPqyebXvqn8Fij4HXCvA0+Ax/BtoTjDk3O1n/Xllxrp Wh7Q== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=2dK3ir+LWB8RCghaNvBM70NFqDOUmqfEAJGTzJx4JcM=; b=jpAAx7qzx1lXrDZDwCbhUIt0AZ/RE6XNHWIe6PXxM9Nv4APIvzGGhoRHweX4BTc1US 1QMaWynOgLci6Exvi9OVJobjHV5lvvtgfM0ae3EHVVaVNAezSkYtIhDWlu7dy5v2eSj0 Ev5pn25DGK1LKCxyXVq59cLclyA1USjbJpy2kNzRXjuu0OL5++PegEyemcsD3EzLt2ch 7F4uotWDyTmcJzWun4Vxa30DHNFxK5zfy9Yh7V0X9A+fOemCZk9+6xMpc1jWIKGo3LXU FTpf2zraZViMDkVwJMntXS4cmqkNBDhkC8MpB+ukIX9/cdQkMNf3fB30AmhyWT2rldmF 86ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b="U/+dMsGz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id me13si1420951ejb.582.2020.12.04.06.54.23; Fri, 04 Dec 2020 06:54:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@kemnade.info header.s=20180802 header.b="U/+dMsGz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730332AbgLDOum (ORCPT + 99 others); Fri, 4 Dec 2020 09:50:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728722AbgLDOum (ORCPT ); Fri, 4 Dec 2020 09:50:42 -0500 Received: from mail.andi.de1.cc (mail.andi.de1.cc [IPv6:2a01:238:4321:8900:456f:ecd6:43e:202c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1548DC061A4F; Fri, 4 Dec 2020 06:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kemnade.info; s=20180802; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=2dK3ir+LWB8RCghaNvBM70NFqDOUmqfEAJGTzJx4JcM=; b=U/+dMsGz+KRkBhCjE3vEtvIyAW 2+CuNTlRUDBVogyedVFbcSvgyyc6nsCCy/akGkVFrWCdc95OZxUabkAjoVYa+zS2Qk5CBjTcSZNAT 4GGSLyEp1uGV2BFRfJlr8LRONuq+t+EykCwgUKzF9KvadFKpb8HIbHNg2PPzUX1U7W+A=; Received: from p200300ccff0a0b001a3da2fffebfd33a.dip0.t-ipconnect.de ([2003:cc:ff0a:b00:1a3d:a2ff:febf:d33a] helo=aktux) by mail.andi.de1.cc with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1klCPG-0006nV-FI; Fri, 04 Dec 2020 15:49:58 +0100 Received: from andi by aktux with local (Exim 4.92) (envelope-from ) id 1klCPG-00026m-6o; Fri, 04 Dec 2020 15:49:58 +0100 From: Andreas Kemnade To: pali@kernel.org, dmurphy@ti.com, sre@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andreas Kemnade Subject: [PATCH] power: bq27xxx: fix polarity of current_now Date: Fri, 4 Dec 2020 15:49:50 +0100 Message-Id: <20201204144950.8062-1-andreas@kemnade.info> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -1.0 (-) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org current_now has to be negative during discharging and positive during charging, the behavior seen is the other way round. Tested on GTA04 with Openmoko battery Signed-off-by: Andreas Kemnade --- drivers/power/supply/bq27xxx_battery.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index 315e0909e6a4..3ecc18b01d49 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -1789,7 +1789,7 @@ static int bq27xxx_battery_current(struct bq27xxx_device_info *di, if (di->opts & BQ27XXX_O_ZERO) { flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, true); - if (flags & BQ27000_FLAG_CHGS) { + if (!(flags & BQ27000_FLAG_CHGS)) { dev_dbg(di->dev, "negative current!\n"); curr = -curr; } @@ -1797,7 +1797,7 @@ static int bq27xxx_battery_current(struct bq27xxx_device_info *di, val->intval = curr * BQ27XXX_CURRENT_CONSTANT / BQ27XXX_RS; } else { /* Other gauges return signed value */ - val->intval = (int)((s16)curr) * 1000; + val->intval = -(int)((s16)curr) * 1000; } return 0; -- 2.20.1