All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-omap@vger.kernel.org,
	Pavel Machek <pavel@ucw.cz>
Subject: [PATCH 5/7] power: supply: cpcap-battery: Use accumulator for current and power average
Date: Sun,  7 Apr 2019 11:12:52 -0700	[thread overview]
Message-ID: <20190407181254.64537-6-tony@atomide.com> (raw)
In-Reply-To: <20190407181254.64537-1-tony@atomide.com>

We should not use measured current value for average since we have proper
coulomb counter values available. Using measured current value should
be only used when the value is queried at a higher rate than the 250 ms
rate the coulomb counter is configured to run at.

Cc: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/power/supply/cpcap-battery.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -476,11 +476,11 @@ static int cpcap_battery_get_property(struct power_supply *psy,
 		val->intval = ddata->config.info.voltage_min_design;
 		break;
 	case POWER_SUPPLY_PROP_CURRENT_AVG:
-		if (cached) {
+		sample = latest->cc.sample - previous->cc.sample;
+		if (!sample) {
 			val->intval = cpcap_battery_cc_get_avg_current(ddata);
 			break;
 		}
-		sample = latest->cc.sample - previous->cc.sample;
 		accumulator = latest->cc.accumulator - previous->cc.accumulator;
 		val->intval = cpcap_battery_cc_to_ua(ddata, sample,
 						     accumulator,
@@ -497,13 +497,13 @@ static int cpcap_battery_get_property(struct power_supply *psy,
 		val->intval = div64_s64(tmp, 100);
 		break;
 	case POWER_SUPPLY_PROP_POWER_AVG:
-		if (cached) {
+		sample = latest->cc.sample - previous->cc.sample;
+		if (!sample) {
 			tmp = cpcap_battery_cc_get_avg_current(ddata);
 			tmp *= (latest->voltage / 10000);
 			val->intval = div64_s64(tmp, 100);
 			break;
 		}
-		sample = latest->cc.sample - previous->cc.sample;
 		accumulator = latest->cc.accumulator - previous->cc.accumulator;
 		tmp = cpcap_battery_cc_to_ua(ddata, sample, accumulator,
 					     latest->cc.offset);
-- 
2.21.0

  parent reply	other threads:[~2019-04-07 18:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-07 18:12 [PATCH 0/7] Some fixes and improvments for cpcap battery and charger Tony Lindgren
2019-04-07 18:12 ` [PATCH 1/7] power: supply: cpcap-battery: Fix division by zero Tony Lindgren
2019-04-08 12:01   ` Pavel Machek
2019-04-07 18:12 ` [PATCH 2/7] power: supply: cpcap-battery: Fix low battery check Tony Lindgren
2019-05-05 19:14   ` Pavel Machek
2019-04-07 18:12 ` [PATCH 3/7] power: supply: cpcap-battery: Fix signed counter sample register Tony Lindgren
2019-04-08 12:03   ` Pavel Machek
2019-04-07 18:12 ` [PATCH 4/7] power: supply: cpcap-battery: Fix coulomb counter calibration register use Tony Lindgren
2019-04-08 12:03   ` Pavel Machek
2019-04-07 18:12 ` Tony Lindgren [this message]
2019-04-07 18:12 ` [PATCH 6/7] power: supply: cpcap-battery: Fix pointless EPROBE_DEFER warnings Tony Lindgren
2019-04-08 12:04   ` Pavel Machek
2019-04-07 18:12 ` [PATCH 7/7] power: supply: cpcap-charger: " Tony Lindgren
2019-04-15 21:31 ` [PATCH 0/7] Some fixes and improvments for cpcap battery and charger Sebastian Reichel
2019-05-18 18:33 ` Tony Lindgren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190407181254.64537-6-tony@atomide.com \
    --to=tony@atomide.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.