From: Juergen Borleis <jbe@pengutronix.de>
To: linux-kernel@vger.kernel.org
Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
David Woodhouse <dwmw2@infradead.org>,
kernel@pengutronix.de
Subject: [PATCH 7/7] bq27xxx: enable hot-plug support
Date: Tue, 10 Jun 2014 11:44:53 +0200 [thread overview]
Message-ID: <1402393493-3559-8-git-send-email-jbe@pengutronix.de> (raw)
In-Reply-To: <1402393493-3559-1-git-send-email-jbe@pengutronix.de>
These kind of devices can be part of the attached battery or part of the board
with an externally attached battery. In both cases we must consider a battery
change can be handled and at least the battery connection state gets
reported correctly.
Signed-off-by: Juergen Borleis <jbe@pengutronix.de>
---
drivers/power/bq27x00_battery.c | 58 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 54 insertions(+), 4 deletions(-)
diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
index 0a02d86..5a6c00d 100644
--- a/drivers/power/bq27x00_battery.c
+++ b/drivers/power/bq27x00_battery.c
@@ -188,6 +188,14 @@ static void bq27245_init_cache(struct bq27x00_reg_cache *cache)
cache->power_avg = cache->health = -ENODATA;
}
+static void bq27xxx_is_gone(struct bq27x00_device_info *di)
+{
+ di->dev_accessible = false;
+ bq27245_init_cache(&di->cache);
+ di->last_update = jiffies;
+ power_supply_changed(&di->bat);
+}
+
static void bq27xxx_is_awake(struct bq27x00_device_info *di)
{
di->dev_accessible = true;
@@ -220,8 +228,10 @@ static int bq27x00_battery_read_rsoc(struct bq27x00_device_info *di)
else
rsoc = bq27x00_read(di, BQ27000_REG_RSOC, true);
- if (rsoc < 0)
+ if (rsoc < 0) {
dev_dbg(di->dev, "error reading relative State-of-Charge\n");
+ bq27xxx_is_gone(di);
+ }
return rsoc;
}
@@ -238,6 +248,7 @@ static int bq27x00_battery_read_charge(struct bq27x00_device_info *di, u8 reg)
if (charge < 0) {
dev_dbg(di->dev, "error reading charge register %02x: %d\n",
reg, charge);
+ bq27xxx_is_gone(di);
return charge;
}
@@ -260,6 +271,10 @@ static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di)
bool is_higher = bq27xxx_is_chip_version_higher(di);
flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500);
+ if (flags < 0) {
+ bq27xxx_is_gone(di);
+ return flags;
+ }
if (flags >= 0 && !is_higher && (flags & BQ27000_FLAG_CI))
return -ENODATA;
@@ -272,7 +287,12 @@ static inline int bq27x00_battery_read_nac(struct bq27x00_device_info *di)
*/
static inline int bq27x00_battery_read_lmd(struct bq27x00_device_info *di)
{
- return bq27x00_battery_read_charge(di, BQ27x00_REG_LMD);
+ int reg;
+
+ reg = bq27x00_battery_read_charge(di, BQ27x00_REG_LMD);
+ if (reg < 0)
+ bq27xxx_is_gone(di);
+ return reg;
}
/*
@@ -298,6 +318,7 @@ static int bq27x00_battery_read_ilmd(struct bq27x00_device_info *di)
if (ilmd < 0) {
dev_dbg(di->dev, "error reading initial last measured discharge\n");
+ bq27xxx_is_gone(di);
return ilmd;
}
@@ -320,6 +341,7 @@ static int bq27x00_battery_read_energy(struct bq27x00_device_info *di)
ae = bq27x00_read(di, BQ27x00_REG_AE, false);
if (ae < 0) {
dev_dbg(di->dev, "error reading available energy\n");
+ bq27xxx_is_gone(di);
return ae;
}
@@ -342,6 +364,7 @@ static int bq27x00_battery_read_temperature(struct bq27x00_device_info *di)
temp = bq27x00_read(di, BQ27x00_REG_TEMP, false);
if (temp < 0) {
dev_err(di->dev, "error reading temperature\n");
+ bq27xxx_is_gone(di);
return temp;
}
@@ -360,8 +383,10 @@ static int bq27x00_battery_read_cyct(struct bq27x00_device_info *di)
int cyct;
cyct = bq27x00_read(di, BQ27x00_REG_CYCT, false);
- if (cyct < 0)
+ if (cyct < 0) {
dev_err(di->dev, "error reading cycle count total\n");
+ bq27xxx_is_gone(di);
+ }
return cyct;
}
@@ -378,6 +403,7 @@ static int bq27x00_battery_read_time(struct bq27x00_device_info *di, u8 reg)
if (tval < 0) {
dev_dbg(di->dev, "error reading time register %02x: %d\n",
reg, tval);
+ bq27xxx_is_gone(di);
return tval;
}
@@ -399,6 +425,7 @@ static int bq27x00_battery_read_pwr_avg(struct bq27x00_device_info *di, u8 reg)
if (tval < 0) {
dev_dbg(di->dev, "error reading power avg register %02x: %d\n",
reg, tval);
+ bq27xxx_is_gone(di);
return tval;
}
@@ -419,6 +446,7 @@ static int bq27x00_battery_read_health(struct bq27x00_device_info *di)
tval = bq27x00_read(di, BQ27x00_REG_FLAGS, false);
if (tval < 0) {
dev_dbg(di->dev, "error reading flag register:%d\n", tval);
+ bq27xxx_is_gone(di);
return tval;
}
@@ -446,8 +474,29 @@ static void bq27x00_update(struct bq27x00_device_info *di)
struct bq27x00_reg_cache cache = {0, };
bool is_bq27500 = di->chip == BQ27500;
bool is_bq27425 = di->chip == BQ27425;
+ int reg;
+
+ reg = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500);
+ if (di->dev_accessible == false) {
+ /* check, if the device is present now */
+ if (reg < 0) {
+ dev_dbg(di->dev, "BQ27xxx still not present\n");
+ goto out; /* no, still not present */
+ }
+
+ /* it seems present now */
+ bq27xxx_is_awake(di);
+ dev_dbg(di->dev, "BQ27xxx detected\n");
+ }
+
+ if (reg < 0) {
+ /* it seems gone now */
+ dev_dbg(di->dev, "BQ27xxx is gone\n");
+ bq27xxx_is_gone(di);
+ return;
+ }
- cache.flags = bq27x00_read(di, BQ27x00_REG_FLAGS, !is_bq27500);
+ cache.flags = reg;
if (cache.flags >= 0) {
if (!is_bq27500 && !is_bq27425
&& (cache.flags & BQ27000_FLAG_CI)) {
@@ -492,6 +541,7 @@ static void bq27x00_update(struct bq27x00_device_info *di)
power_supply_changed(&di->bat);
}
+out:
di->last_update = jiffies;
}
--
2.0.0.rc2
next prev parent reply other threads:[~2014-06-10 9:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-10 9:44 Power/battery/BQ27xxx: some fixes and " Juergen Borleis
2014-06-10 9:44 ` [PATCH 1/7] bq27425: fix register offset for SOC on bq27425 Juergen Borleis
2014-06-10 9:44 ` [PATCH 2/7] bq27425: add support to read the control registers Juergen Borleis
2014-06-10 9:44 ` [PATCH 3/7] bq27425: add support for different firmware chip types Juergen Borleis
2014-06-10 9:44 ` [PATCH 4/7] bq27425: the DesignCapacity register is at a different offset Juergen Borleis
2014-06-10 9:44 ` [PATCH 5/7] bq27xxx: suppress error messages Juergen Borleis
2014-06-10 9:44 ` [PATCH 6/7] bq27xxx: init the cache first Juergen Borleis
2014-06-10 9:44 ` Juergen Borleis [this message]
2014-07-08 8:28 ` Power/battery/BQ27xxx: some fixes and hot-plug support Steffen Trumtrar
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=1402393493-3559-8-git-send-email-jbe@pengutronix.de \
--to=jbe@pengutronix.de \
--cc=dbaryshkov@gmail.com \
--cc=dwmw2@infradead.org \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®