Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp110356pxu; Tue, 24 Nov 2020 20:50:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNT2UojRtwcYliyxfNtNeQNU77WGf35EegUST8UGRKM08r/qoB4RirjxF0rZBFRtRqNnZx X-Received: by 2002:a17:906:d931:: with SMTP id rn17mr1563851ejb.308.1606279822623; Tue, 24 Nov 2020 20:50:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606279822; cv=none; d=google.com; s=arc-20160816; b=EQIyOp+rrtins2W813g42LRLXlA5mV3hfUgw2HuqTpdHDejaAu7oRr2O/ZPoVSfGVF q1GUVuuC1e1jrVO1xJuPP+qGrmua+Llj6GC6i1hGHgPliO07OJSUDVOYs806rIRT7Sxf pVfa76bjptvoWIiXuykfY4Ipi7yYhYnlBzFG2U5mNXA82RSD4sh6dVfRQcGQcVajFqAN pe6/CJTl52AVJapqYTomeGhbqMFuxKbtS67B4SCgX3PU9gFSc55NO4yo7vsjWjuYBtqd xChQ9kxGp4m5bYwkXPVlbOub4VEbTFVq1o/1bW54xy4ORTGUX+PYS79G9O3B8RhHNyWJ d5xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Ni0k1oj5iFL2Zs68EHJqhwnAvfNV7uW8wMpWWs8VNZQ=; b=yWdu+wrTkQ5Vp18496XWwItbvyOKPc7oKMQl50byaoiNNdDqKPYQQ3a+ZytV+6PZeW X5/KgiTLm6weq8iHdOHIMh0ZjCT/w90fv6EwXO2kPgZTwGnFKctXI9T1lTq2SD/4HjtR TKYKVKNHG0EdtlXLmAMKT2EXEnrYFhQnON1EKqg/k34qfcrBiHxno4B3i2JULmxv0d0M 4+mBkJzJK/fOJZiSlDVS2zO7Jc+zyJR3K1wOwWWmNPq8ED1CP9E5s4JX4583TyzVjLio swVq3aWD9POmVzFHW7ks+NajYSo0//bvkeZXbF49JyvgzPDfwEq3B8ysB8a/4OopGNrn DflQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=puri.sm Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v7si519402ede.343.2020.11.24.20.50.00; Tue, 24 Nov 2020 20:50:22 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=puri.sm Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727209AbgKYEqV (ORCPT + 99 others); Tue, 24 Nov 2020 23:46:21 -0500 Received: from comms.puri.sm ([159.203.221.185]:48066 "EHLO comms.puri.sm" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbgKYEqV (ORCPT ); Tue, 24 Nov 2020 23:46:21 -0500 Received: from localhost (localhost [127.0.0.1]) by comms.puri.sm (Postfix) with ESMTP id 37F43E0399; Tue, 24 Nov 2020 20:46:21 -0800 (PST) Received: from comms.puri.sm ([127.0.0.1]) by localhost (comms.puri.sm [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t2ineu87QF7d; Tue, 24 Nov 2020 20:46:20 -0800 (PST) From: Sebastian Krzyszkowiak To: Sebastian Reichel Cc: Geordan Neukum , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@puri.sm Subject: [PATCH 2/4] power: max17042_battery: Improve accuracy of current_now and current_avg readings Date: Wed, 25 Nov 2020 05:46:17 +0100 Message-ID: <4526762.6nKOPmpm47@pliszka> In-Reply-To: <2264396.HPVdm0XNkV@pliszka> References: <2264396.HPVdm0XNkV@pliszka> Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dividing 1562500 by r_sns value usually doesn't result in an integer. Signed-off-by: Sebastian Krzyszkowiak --- drivers/power/supply/max17042_battery.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index 2e9672fe4df1..86adccb0f32d 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -395,8 +395,8 @@ static int max17042_get_property(struct power_supply *psy, if (ret < 0) return ret; - val->intval = sign_extend32(data, 15); - val->intval *= 1562500 / chip->pdata->r_sns; + data64 = sign_extend64(data, 15) * 1562500ll; + val->intval = div_s64(data64, chip->pdata->r_sns); } else { return -EINVAL; } @@ -407,8 +407,8 @@ static int max17042_get_property(struct power_supply *psy, if (ret < 0) return ret; - val->intval = sign_extend32(data, 15); - val->intval *= 1562500 / chip->pdata->r_sns; + data64 = sign_extend64(data, 15) * 1562500ll; + val->intval = div_s64(data64, chip->pdata->r_sns); } else { return -EINVAL; } -- 2.29.2