From: Richard Tresidder <rtresidd@electromag.com.au>
To: sre@kernel.org, enric.balletbo@collabora.com,
ncrews@chromium.org, andrew.smirnov@gmail.com,
groeck@chromium.org, rtresidd@electromag.com.au,
david@lechnology.com, tglx@linutronix.de,
kstewart@linuxfoundation.org, gregkh@linuxfoundation.org,
rfontana@redhat.com, allison@lohutok.net, baolin.wang@linaro.org,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RESEND v2 1/1] power/supply/sbs-battery: Fix confusing battery status when idle or empty
Date: Thu, 25 Jul 2019 16:55:29 +0800 [thread overview]
Message-ID: <1564044929-26104-1-git-send-email-rtresidd@electromag.com.au> (raw)
When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect status indication of FULL for the battery simply
because it wasn't discharging at that point in time.
The battery will now be flagged as IDLE.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.
Signed-off-by: Richard Tresidder <rtresidd@electromag.com.au>
---
Notes:
power/supply/sbs-battery: Fix confusing battery status when idle or empty
When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect
status indication of FULL for the battery simply because it wasn't
discharging at that point in time.
The battery will now be flagged as IDLE.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.
v2: missed a later merge that should have been included in original patch
drivers/power/supply/power_supply_sysfs.c | 3 ++-
drivers/power/supply/sbs-battery.c | 32 +++++++++++++++----------------
include/linux/power_supply.h | 2 ++
3 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c
index ce6671c..68ec49d 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -51,7 +51,8 @@
};
static const char * const power_supply_status_text[] = {
- "Unknown", "Charging", "Discharging", "Not charging", "Full"
+ "Unknown", "Charging", "Discharging", "Not charging", "Full",
+ "Empty", "Idle"
};
static const char * const power_supply_charge_type_text[] = {
diff --git a/drivers/power/supply/sbs-battery.c b/drivers/power/supply/sbs-battery.c
index ea8ba3e..664c317 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -294,16 +294,12 @@ static int sbs_status_correct(struct i2c_client *client, int *intval)
ret = (s16)ret;
- /* Not drawing current means full (cannot be not charging) */
- if (ret == 0)
- *intval = POWER_SUPPLY_STATUS_FULL;
-
- if (*intval == POWER_SUPPLY_STATUS_FULL) {
- /* Drawing or providing current when full */
- if (ret > 0)
- *intval = POWER_SUPPLY_STATUS_CHARGING;
- else if (ret < 0)
- *intval = POWER_SUPPLY_STATUS_DISCHARGING;
+ if ((*intval == POWER_SUPPLY_STATUS_DISCHARGING && (ret == 0)) {
+ /* Charging indicator not set in battery */
+ *intval = POWER_SUPPLY_STATUS_IDLE;
+ } else if ((*intval == POWER_SUPPLY_STATUS_FULL) && (ret < 0)) {
+ /* Full Flag set but we are discharging */
+ *intval = POWER_SUPPLY_STATUS_DISCHARGING;
}
return 0;
@@ -424,10 +420,12 @@ static int sbs_get_battery_property(struct i2c_client *client,
if (ret & BATTERY_FULL_CHARGED)
val->intval = POWER_SUPPLY_STATUS_FULL;
- else if (ret & BATTERY_DISCHARGING)
- val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
- else
+ else if (ret & BATTERY_FULL_DISCHARGED)
+ val->intval = POWER_SUPPLY_STATUS_EMPTY;
+ else if (!(ret & BATTERY_DISCHARGING))
val->intval = POWER_SUPPLY_STATUS_CHARGING;
+ else
+ val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
sbs_status_correct(client, &val->intval);
@@ -781,10 +779,12 @@ static void sbs_delayed_work(struct work_struct *work)
if (ret & BATTERY_FULL_CHARGED)
ret = POWER_SUPPLY_STATUS_FULL;
- else if (ret & BATTERY_DISCHARGING)
- ret = POWER_SUPPLY_STATUS_DISCHARGING;
- else
+ else if (ret & BATTERY_FULL_DISCHARGED)
+ ret = POWER_SUPPLY_STATUS_EMPTY;
+ else if (!(ret & BATTERY_DISCHARGING))
ret = POWER_SUPPLY_STATUS_CHARGING;
+ else
+ ret = POWER_SUPPLY_STATUS_DISCHARGING;
sbs_status_correct(chip->client, &ret);
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 28413f7..c9f3347 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -37,6 +37,8 @@ enum {
POWER_SUPPLY_STATUS_DISCHARGING,
POWER_SUPPLY_STATUS_NOT_CHARGING,
POWER_SUPPLY_STATUS_FULL,
+ POWER_SUPPLY_STATUS_EMPTY,
+ POWER_SUPPLY_STATUS_IDLE,
};
/* What algorithm is the charger using? */
--
1.8.3.1
next reply other threads:[~2019-07-25 8:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-25 8:55 Richard Tresidder [this message]
2019-07-26 17:47 ` [RESEND v2 1/1] power/supply/sbs-battery: Fix confusing battery status when idle or empty Nick Crews
2019-07-29 4:25 ` Richard Tresidder
2019-07-26 20:31 ` kbuild test robot
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=1564044929-26104-1-git-send-email-rtresidd@electromag.com.au \
--to=rtresidd@electromag.com.au \
--cc=allison@lohutok.net \
--cc=andrew.smirnov@gmail.com \
--cc=baolin.wang@linaro.org \
--cc=david@lechnology.com \
--cc=enric.balletbo@collabora.com \
--cc=gregkh@linuxfoundation.org \
--cc=groeck@chromium.org \
--cc=kstewart@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=ncrews@chromium.org \
--cc=rfontana@redhat.com \
--cc=sre@kernel.org \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).