From: Carl Philipp Klemm <philipp@uvos.xyz>
To: Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-omap@vger.kernel.org,
Arthur Demchenkov <spinal.by@gmail.com>,
Tony Lindgren <tony@atomide.com>,
Merlijn Wajer <merlijn@wizzup.org>, Pavel Machek <pavel@ucw.cz>
Subject: [PATCH 3/5] power: supply: cpcap-battery: invalidate empty->counter_uah and charge_full when they are grossly wrong
Date: Sun, 17 Jan 2021 22:46:38 +0100 [thread overview]
Message-ID: <20210117224638.10c9d9aee7c0144fafd70520@uvos.xyz> (raw)
This invalidates empty->counter_uah and charge_full when charge_now indicates
that they are grossly wrong and adds some tolerance to
POWER_SUPPLY_PROP_CHARGE_FULL to allow for inaccuracies in the charge counter
and manufacturing tolerances in the battery.
Signed-off-by: Carl Philipp Klemm <philipp@uvos.xyz>
---
drivers/power/supply/cpcap-battery.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c
index 86ed41d9627f..8ae0c9c7ebcb 100644
--- a/drivers/power/supply/cpcap-battery.c
+++ b/drivers/power/supply/cpcap-battery.c
@@ -667,10 +667,22 @@ static int cpcap_battery_get_property(struct power_supply *psy,
if (!empty->voltage)
return -ENODATA;
val->intval = empty->counter_uah - latest->counter_uah;
- if (val->intval < 0)
+ if (val->intval < 0) {
+ if (ddata->charge_full && abs(val->intval) > ddata->charge_full/5) {
+ empty->voltage = 0;
+ ddata->charge_full = 0;
+ return -ENODATA;
+ }
val->intval = 0;
- else if (ddata->charge_full && ddata->charge_full < val->intval)
+ }
+ else if (ddata->charge_full && ddata->charge_full < val->intval) {
+ if (val->intval > (6*ddata->charge_full)/5) {
+ empty->voltage = 0;
+ ddata->charge_full = 0;
+ return -ENODATA;
+ }
val->intval = ddata->charge_full;
+ }
break;
case POWER_SUPPLY_PROP_CHARGE_FULL:
if (!ddata->charge_full)
@@ -747,7 +759,7 @@ static int cpcap_battery_set_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_CHARGE_FULL:
if (val->intval < 0)
return -EINVAL;
- if (val->intval > ddata->config.info.charge_full_design)
+ if (val->intval > (6*ddata->config.info.charge_full_design)/5)
return -EINVAL;
ddata->charge_full = val->intval;
--
2.29.2
next reply other threads:[~2021-01-17 21:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-17 21:46 Carl Philipp Klemm [this message]
2021-04-05 8:12 ` [PATCH 3/5] power: supply: cpcap-battery: invalidate empty->counter_uah and charge_full when they are grossly wrong Sebastian Reichel
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=20210117224638.10c9d9aee7c0144fafd70520@uvos.xyz \
--to=philipp@uvos.xyz \
--cc=linux-omap@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=merlijn@wizzup.org \
--cc=pavel@ucw.cz \
--cc=spinal.by@gmail.com \
--cc=sre@kernel.org \
--cc=tony@atomide.com \
/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.