diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2017-01-25 10:39:09 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-01-25 22:12:30 -0800 |
commit | 7a4eac1bed523e0f37597efcf1b887d996a037f0 (patch) | |
tree | 4ec10d33497182116aa9f60fdccab559591451e5 | |
parent | 325c93fa94dc8ffbd15386d66c45dc0aaca262bb (diff) | |
download | chrome-ec-7a4eac1bed523e0f37597efcf1b887d996a037f0.tar.gz |
Reef: Reduce max battery charge voltage for 0.5% margin
(From CL 431233)
Limit battery charge voltage to prevent battery over-charge, due to
regulation inaccuracy. Since RO FW may charge > 8656 mV, ensure the
battery is not full before charging.
BUG=chrome-os-partner:61906
BRANCH=none
TEST=Manual on Electro, sysjump with battery @ 99%, verify battery
discharges, then re-charges to 100%, before discharging once again.
Change-Id: I28212c83057a442fd75e39f8ad51927a7a1f2817
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/432857
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r-- | board/reef/battery.c | 9 | ||||
-rw-r--r-- | driver/charger/bd9995x.c | 11 | ||||
-rw-r--r-- | include/common.h | 6 |
3 files changed, 18 insertions, 8 deletions
diff --git a/board/reef/battery.c b/board/reef/battery.c index 602834257a..a76bd92d1d 100644 --- a/board/reef/battery.c +++ b/board/reef/battery.c @@ -11,6 +11,7 @@ #include "charge_ramp.h" #include "charge_state.h" #include "charger_profile_override.h" +#include "common.h" #include "console.h" #include "ec_commands.h" #include "extpower.h" @@ -118,7 +119,7 @@ static const struct fast_charge_params fast_chg_params_smp_cos4870 = { }; const struct battery_info batt_info_smp_cos4870 = { - .voltage_max = 8700, /* mV */ + .voltage_max = TARGET_WITH_MARGIN(8700, 5), .voltage_normal = 7600, /* * Actual value 6000mV, added 100mV for charger accuracy so that @@ -162,7 +163,7 @@ static const struct fast_charge_params fast_chg_params_sonycorp = { }; const struct battery_info batt_info_sonycorp = { - .voltage_max = 8700, /* mV */ + .voltage_max = TARGET_WITH_MARGIN(8700, 5), .voltage_normal = 7600, /* @@ -216,7 +217,7 @@ static const struct fast_charge_params fast_chg_params_panasonic = { }; const struct battery_info batt_info_panasoic = { - .voltage_max = 8800, /* mV */ + .voltage_max = TARGET_WITH_MARGIN(8800, 5), .voltage_normal = 7700, /* @@ -324,7 +325,7 @@ static const struct fast_charge_params fast_chg_params_cpt_c22n1626 = { }; const struct battery_info batt_info_c22n1626 = { - .voltage_max = 8800, /* mV */ + .voltage_max = TARGET_WITH_MARGIN(8800, 5), .voltage_normal = 7700, /* diff --git a/driver/charger/bd9995x.c b/driver/charger/bd9995x.c index 607d0b81f6..c668aa5260 100644 --- a/driver/charger/bd9995x.c +++ b/driver/charger/bd9995x.c @@ -607,6 +607,7 @@ int charger_get_voltage(int *voltage) int charger_set_voltage(int voltage) { + const int battery_voltage_max = battery_get_info()->voltage_max; int rv; int reg; @@ -620,14 +621,16 @@ int charger_set_voltage(int voltage) return rv; if (voltage == 0 || - reg & BD9995X_CMD_CHGOP_SET2_BATT_LEARN || - battery_is_present() != BP_YES || - battery_is_cut_off()) - voltage = battery_get_info()->voltage_max; + reg & BD9995X_CMD_CHGOP_SET2_BATT_LEARN || + battery_is_present() != BP_YES || + battery_is_cut_off() || + voltage > battery_voltage_max) + voltage = battery_voltage_max; /* Charge voltage step 16 mV */ voltage &= ~0x0F; + /* Assumes charger's voltage_min < battery's voltagte_max */ if (voltage < bd9995x_charger_info.voltage_min) voltage = bd9995x_charger_info.voltage_min; diff --git a/include/common.h b/include/common.h index 0bdea8965d..f35d543ce8 100644 --- a/include/common.h +++ b/include/common.h @@ -84,6 +84,12 @@ #define CELSIUS_TO_DECI_KELVIN(temp_c) ((temp_c) * 10 + 2731) #define DECI_KELVIN_TO_CELSIUS(temp_dk) ((temp_dk - 2731) / 10) +/* Calculate a value with error margin considered. For example, + * TARGET_WITH_MARGIN(X, 5) returns X' where X' * 100.5% is almost equal to + * but does not exceed X. */ +#define TARGET_WITH_MARGIN(target, tenths_percent) \ + (((target) * 1000) / (1000 + (tenths_percent))) + /* Include top-level configuration file */ #include "config.h" |