diff options
author | li feng <li1.feng@intel.com> | 2015-09-18 11:56:57 -0700 |
---|---|---|
committer | ChromeOS bot <3su6n15k.default@developer.gserviceaccount.com> | 2016-04-29 22:44:30 +0000 |
commit | 7e1309501412d266719b3e981989efc6cec7fd59 (patch) | |
tree | c7f13b57d44c9de669fd5c1d305e0c2efc39cc65 | |
parent | 327a3c8463047583bf32117cab12fbbd39575870 (diff) | |
download | chrome-ec-7e1309501412d266719b3e981989efc6cec7fd59.tar.gz |
bq24773: Set charge inhibit bit only when it's changed.
charger_set_mode() is called in each charger_task loop and sets charge
inhibit bit. This reads and writes register option 0 no matter the
requested value is same as before or not. Limit this activity to only when
the bit is changed.
Also if reading option 0 returns value with LEARN mode enabled, try to read
one more time to make sure it's not bogus value. Otherwise, this could
casue LEARN mode been enabled mistakenly and cause battery discharge with
AC on.
BUG=chrome-os-partner:50578
BRANCH=none
TEST=Observed charger_set_mode() only writes charge inhibit bit when it's
changed. If the value keeps then same, no set mode happens.
Change-Id: Ia7f258d44e7cadd00f42f671d112eae17da3016e
Signed-off-by: li feng <li1.feng@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/301185
Reviewed-by: Shawn N <shawnn@chromium.org>
Tested-by: Divya Jyothi <divya.jyothi@intel.com>
Commit-Queue: Divya Jyothi <divya.jyothi@intel.com>
(cherry picked from commit 51683905731cb352964008e5d6ed7bdcffffa9e1)
Reviewed-on: https://chromium-review.googlesource.com/341334
Commit-Queue: Keith Tzeng <keith.tzeng@quantatw.com>
Tested-by: Keith Tzeng <keith.tzeng@quantatw.com>
-rw-r--r-- | driver/charger/bq24773.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/driver/charger/bq24773.c b/driver/charger/bq24773.c index 747bc9787c..1288b63e46 100644 --- a/driver/charger/bq24773.c +++ b/driver/charger/bq24773.c @@ -36,6 +36,8 @@ #define REG8_TO_CURRENT(REG, RS) ((REG) * DEFAULT_SENSE_RESISTOR / (RS) * R8) #define CURRENT_TO_REG8(CUR, RS) ((CUR) * (RS) / DEFAULT_SENSE_RESISTOR / R8) +static int prev_charge_inhibited = -1; + /* Charger parameters */ static const struct charger_info bq2477x_charger_info = { .name = CHARGER_NAME, @@ -142,6 +144,7 @@ int charger_get_option(int *option) int charger_set_option(int option) { + prev_charge_inhibited = option & CHARGE_FLAG_INHIBIT_CHARGE; return raw_write16(REG_CHARGE_OPTION0, option); } @@ -173,11 +176,26 @@ int charger_get_status(int *status) int charger_set_mode(int mode) { int rv; - int option; + int option, i; - rv = charger_get_option(&option); - if (rv) - return rv; + if ((mode & CHARGE_FLAG_INHIBIT_CHARGE) == + prev_charge_inhibited) + return EC_SUCCESS; + + /* + * Refer to crosbug.com/p/45575. If LEARN is enabled, + * read one more time to make sure it's not + * bogus value. + */ + for (i = 0; i < 2; i++) { + rv = charger_get_option(&option); + if (rv) + return rv; + else { + if (!(option & OPTION0_LEARN_ENABLE)) + break; + } + } if (mode & CHARGE_FLAG_INHIBIT_CHARGE) option |= OPTION0_CHARGE_INHIBIT; |