diff options
author | Vijay Hiremath <vijay.p.hiremath@intel.com> | 2017-06-05 17:06:26 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-08-08 17:34:10 -0700 |
commit | 8bfde69fdd9b5feb4c47c8c714416c17afe00f78 (patch) | |
tree | 42c37aa23fb38cfe3aab6474c57e166ea1990617 /board/glkrvp | |
parent | 045e3340d928912091d877ef164b6d16cb48c0f2 (diff) | |
download | chrome-ec-8bfde69fdd9b5feb4c47c8c714416c17afe00f78.tar.gz |
GLKRVP: Enable fast charging and battery cut-off
BUG=b:64452259
BRANCH=glkrvp
TEST=Fast charging & battery cut-off works
Change-Id: Ica19ed11891ef5ac8b37140a5fcbb311333d5b5a
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/604732
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'board/glkrvp')
-rw-r--r-- | board/glkrvp/battery.c | 161 | ||||
-rw-r--r-- | board/glkrvp/board.h | 5 |
2 files changed, 162 insertions, 4 deletions
diff --git a/board/glkrvp/battery.c b/board/glkrvp/battery.c index 7d2dba797b..c708d08fff 100644 --- a/board/glkrvp/battery.c +++ b/board/glkrvp/battery.c @@ -6,8 +6,10 @@ */ #include "battery.h" +#include "charger_profile_override.h" #include "console.h" #include "ioexpander_pca9555.h" +#include "util.h" #define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args) @@ -17,8 +19,29 @@ pca9555_read(I2C_PORT_PCA555_BATT_PRESENT_GPIO, \ I2C_ADDR_PCA555_BATT_PRESENT_GPIO, (reg), (data)) -/* SMP-CA-445 Battery */ -static const struct battery_info info = { +/* Shutdown mode parameter to write to manufacturer access register */ +#define SB_SHUTDOWN_DATA 0x0010 + +enum fast_chg_voltage_ranges { + VOLTAGE_RANGE_0, + VOLTAGE_RANGE_1, + VOLTAGE_RANGE_2, +}; + +enum temp_range { + TEMP_RANGE_0, + TEMP_RANGE_1, + TEMP_RANGE_2, + TEMP_RANGE_3, + TEMP_RANGE_4, + TEMP_RANGE_5, +}; + +/* keep track of previous charge profile info */ +static const struct fast_charge_profile *prev_chg_profile_info; + +/* SMP-CA-445 battery & BQ30Z554 fuel gauge */ +static const struct battery_info batt_info_smp_ca445 = { .voltage_max = 8700, /* mV */ .voltage_normal = 7600, @@ -38,7 +61,116 @@ static const struct battery_info info = { const struct battery_info *battery_get_info(void) { - return &info; + return &batt_info_smp_ca445; +} + +static const struct fast_charge_profile fast_charge_smp_ca445_info[] = { + /* < 0C */ + [TEMP_RANGE_0] = { + .temp_c = TEMPC_TENTHS_OF_DEG(-1), + .current_mA = { + [VOLTAGE_RANGE_0] = 0, + [VOLTAGE_RANGE_1] = 0, + [VOLTAGE_RANGE_2] = 0, + }, + }, + + /* 0C >= && <=15C */ + [TEMP_RANGE_1] = { + .temp_c = TEMPC_TENTHS_OF_DEG(15), + .current_mA = { + [VOLTAGE_RANGE_0] = 890, + [VOLTAGE_RANGE_1] = 445, + [VOLTAGE_RANGE_2] = 445, + }, + }, + + /* 15C > && <=20C */ + [TEMP_RANGE_2] = { + .temp_c = TEMPC_TENTHS_OF_DEG(20), + .current_mA = { + [VOLTAGE_RANGE_0] = 1335, + [VOLTAGE_RANGE_1] = 1335, + [VOLTAGE_RANGE_2] = 1335, + }, + }, + + /* 20C > && <=45C */ + [TEMP_RANGE_3] = { + .temp_c = TEMPC_TENTHS_OF_DEG(45), + .current_mA = { + [VOLTAGE_RANGE_0] = 2225, + [VOLTAGE_RANGE_1] = 2225, + [VOLTAGE_RANGE_2] = 2225, + }, + }, + + /* 45C > && <=55C */ + [TEMP_RANGE_4] = { + .temp_c = TEMPC_TENTHS_OF_DEG(55), + .current_mA = { + [VOLTAGE_RANGE_0] = 1335, + [VOLTAGE_RANGE_1] = 1335, + [VOLTAGE_RANGE_2] = 0, + }, + }, + + /* > 55C */ + [TEMP_RANGE_5] = { + .temp_c = TEMPC_TENTHS_OF_DEG(CHARGER_PROF_TEMP_C_LAST_RANGE), + .current_mA = { + [VOLTAGE_RANGE_0] = 0, + [VOLTAGE_RANGE_1] = 0, + [VOLTAGE_RANGE_2] = 0, + }, + }, +}; + +static const struct fast_charge_params fast_chg_params_smp_ca445 = { + .total_temp_ranges = ARRAY_SIZE(fast_charge_smp_ca445_info), + .default_temp_range_profile = TEMP_RANGE_3, + .voltage_mV = { + [VOLTAGE_RANGE_0] = 8000, + [VOLTAGE_RANGE_1] = 8200, + [VOLTAGE_RANGE_2] = CHARGER_PROF_VOLTAGE_MV_LAST_RANGE, + }, + .chg_profile_info = &fast_charge_smp_ca445_info[0], +}; + +/* + * This can override the smart battery's charging profile. To make a change, + * modify one or more of requested_voltage, requested_current, or state. + * Leave everything else unchanged. + * + * Return the next poll period in usec, or zero to use the default (which is + * state dependent). + */ +int charger_profile_override(struct charge_state_data *curr) +{ + return charger_profile_override_common(curr, + &fast_chg_params_smp_ca445, + &prev_chg_profile_info, + batt_info_smp_ca445.voltage_max); +} + +int board_cut_off_battery(void) +{ + int rv; + + /* Ship mode command must be sent twice to take effect */ + rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); + if (rv != EC_SUCCESS) + return rv; + + return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); +} + +static inline int batt_smp_cos4870_is_initialized(void) +{ + int batt_status; + + return battery_status(&batt_status) ? 0 : + batt_status & STATUS_INITIALIZED; } static inline enum battery_present battery_hw_present(void) @@ -57,5 +189,26 @@ static inline enum battery_present battery_hw_present(void) */ enum battery_present battery_is_present(void) { - return battery_hw_present(); + static enum battery_present batt_pres_prev = BP_NOT_SURE; + enum battery_present batt_pres; + + /* Get the physical hardware status */ + batt_pres = battery_hw_present(); + + /* + * Make sure battery status is implemented, I2C transactions are + * success & the battery status is Initialized to find out if it + * is a working battery and it is not in the cut-off mode. + * + * FETs are turned off after Power Shutdown time. + * The device will wake up when a voltage is applied to PACK. + * Battery status will be inactive until it is initialized. + */ + if (batt_pres == BP_YES && batt_pres_prev != batt_pres && + !battery_is_cut_off() && !batt_smp_cos4870_is_initialized()) + batt_pres = BP_NO; + + batt_pres_prev = batt_pres; + + return batt_pres; } diff --git a/board/glkrvp/board.h b/board/glkrvp/board.h index 5741fe4449..876c90ea6c 100644 --- a/board/glkrvp/board.h +++ b/board/glkrvp/board.h @@ -26,6 +26,7 @@ /* EC console commands */ /* Battery */ +#define CONFIG_BATTERY_CUT_OFF #define CONFIG_BATTERY_PRESENT_CUSTOM #define CONFIG_BATTERY_SMART @@ -34,6 +35,10 @@ #define CONFIG_CHARGER_INPUT_CURRENT 2250 #define CONFIG_CHARGER_ISL9238 #define CONFIG_CHARGER_NARROW_VDC +#define CONFIG_CHARGER_PROFILE_OVERRIDE +#define CONFIG_CHARGER_PROFILE_OVERRIDE_COMMON +#undef CONFIG_CHARGER_PROFILE_VOLTAGE_RANGES +#define CONFIG_CHARGER_PROFILE_VOLTAGE_RANGES 3 #define CONFIG_CHARGER_SENSE_RESISTOR 10 #define CONFIG_CHARGER_SENSE_RESISTOR_AC 10 #define CONFIG_CHARGER_V2 |