diff options
author | Vijay Hiremath <vijay.p.hiremath@intel.com> | 2016-11-15 16:38:11 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-11-22 11:52:06 -0800 |
commit | 242d29858465f8cec6b4a45c9a8a9a0193828821 (patch) | |
tree | 38873c4952cad9e7ad251c3a15fb27b71e3b1419 /board/reef/battery.c | |
parent | 50fbfc5040ab2668b3031f0ebf56be8e7f4546fe (diff) | |
download | chrome-ec-242d29858465f8cec6b4a45c9a8a9a0193828821.tar.gz |
electro/reef: Configure the battery parameters for electro & reef
Electro & Reef use the same board files but have different batteries
hence configure the respective battery parameters for these boards.
BUG=chrome-os-partner:59876
BRANCH=none
TEST=Manually tested on Reef. Boot with/without/battery works.
cut-off and boot from cut-off works.
Change-Id: I0e4684987133d6bcd9cabab5c5a1ce5b6c5684d2
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/411353
Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'board/reef/battery.c')
-rw-r--r-- | board/reef/battery.c | 163 |
1 files changed, 138 insertions, 25 deletions
diff --git a/board/reef/battery.c b/board/reef/battery.c index 582c0addad..9d76a8da9b 100644 --- a/board/reef/battery.c +++ b/board/reef/battery.c @@ -13,32 +13,108 @@ #include "ec_commands.h" #include "extpower.h" #include "gpio.h" +#include "hooks.h" #include "i2c.h" #include "util.h" -#define ELECTRO_SHIP_MODE_REG 0x3a -#define ELECTRO_SHIP_MODE_DAT 0xC574 +enum battery_type { + BATTERY_SONY_CORP, + BATTERY_SMP_COS4870, + BATTERY_TYPE_COUNT, +}; + +struct board_batt_params { + char *manuf_name; + int ship_mode_reg; + int ship_mode_data; + struct battery_info batt_info; + int (*batt_init)(void); +}; + +#define DEFAULT_BATTERY_TYPE BATTERY_SONY_CORP static enum battery_present batt_pres_prev = BP_NOT_SURE; -/* Battery info for BQ40Z55 */ -static const struct battery_info info = { - .voltage_max = 8700, /* mV */ - .voltage_normal = 7600, +static enum battery_type board_battery_type = BATTERY_TYPE_COUNT; - /* - * Actual value 6000mV, added 100mV for charger accuracy so - * that unwanted low VSYS_Prochot# assertion can be avoided. - */ - .voltage_min = 6100, - .precharge_current = 256, /* mA */ - .start_charging_min_c = 0, - .start_charging_max_c = 46, - .charging_min_c = 0, - .charging_max_c = 45, - .discharging_min_c = 0, - .discharging_max_c = 60, +static int batt_smp_cos4870_init(void) +{ + int batt_status; + + return battery_status(&batt_status) ? 0 : + batt_status & STATUS_INITIALIZED; +} + +static int batt_sony_corp_init(void) +{ + /* TODO: crosbug.com/p/59904 */ + return 1; +} + +static const struct board_batt_params info[] = { + /* SONY CORP BATTERY battery specific configurations */ + [BATTERY_SONY_CORP] = { + .manuf_name = "SONYCorp", + .ship_mode_reg = 0x3A, + .ship_mode_data = 0xC574, + .batt_init = batt_sony_corp_init, + + /* Battery info for BQ40z555 (TODO: crosbug.com/p/59904) */ + .batt_info = { + .voltage_max = 8700, /* mV */ + .voltage_normal = 7600, + + /* + * Actual value 6000mV, added 100mV for charger accuracy + * so that unwanted low VSYS_Prochot# assertion can be + * avoided. + */ + .voltage_min = 6100, + .precharge_current = 256, /* mA */ + .start_charging_min_c = 0, + .start_charging_max_c = 46, + .charging_min_c = 0, + .charging_max_c = 45, + .discharging_min_c = 0, + .discharging_max_c = 60, + }, + }, + + /* SMP COS4870 BATTERY battery specific configurations */ + [BATTERY_SMP_COS4870] = { + .manuf_name = "SMP-COS4870", + .ship_mode_reg = 0x00, + .ship_mode_data = 0x0010, + .batt_init = batt_smp_cos4870_init, + + /* Battery info for BQ40Z55 */ + .batt_info = { + .voltage_max = 8700, /* mV */ + .voltage_normal = 7600, + + /* + * Actual value 6000mV, added 100mV for charger accuracy + * so that unwanted low VSYS_Prochot# assertion can be + * avoided. + */ + .voltage_min = 6100, + .precharge_current = 256, /* mA */ + .start_charging_min_c = 0, + .start_charging_max_c = 46, + .charging_min_c = 0, + .charging_max_c = 45, + .discharging_min_c = 0, + .discharging_max_c = 60, + }, + }, }; +BUILD_ASSERT(ARRAY_SIZE(info) == BATTERY_TYPE_COUNT); + +static inline const struct board_batt_params *board_get_batt_params(void) +{ + return &info[board_battery_type == BATTERY_TYPE_COUNT ? + DEFAULT_BATTERY_TYPE : board_battery_type]; +} static inline enum battery_present battery_hw_present(void) { @@ -46,21 +122,55 @@ static inline enum battery_present battery_hw_present(void) return gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES; } +/* Get type of the battery connected on the board */ +static int board_get_battery_type(void) +{ + char name[32]; + int i; + + if (!battery_manufacturer_name(name, sizeof(name))) { + for (i = 0; i < BATTERY_TYPE_COUNT; i++) { + if (!strcasecmp(name, info[i].manuf_name)) { + board_battery_type = i; + break; + } + } + } + + return board_battery_type; +} + +/* + * Initialize the battery type for the board. + * + * Very first battery info is called by the charger driver to initialize + * the charger parameters hence initialize the battery type for the board + * as soon as the I2C is initialized. + */ +static void board_init_battery_type(void) +{ + board_get_battery_type(); +} +DECLARE_HOOK(HOOK_INIT, board_init_battery_type, HOOK_PRIO_INIT_I2C + 1); + const struct battery_info *battery_get_info(void) { - return &info; + return &board_get_batt_params()->batt_info; } int board_cut_off_battery(void) { int rv; + const struct board_batt_params *board_battery = board_get_batt_params(); /* Ship mode command must be sent twice to take effect */ - rv = sb_write(ELECTRO_SHIP_MODE_REG, ELECTRO_SHIP_MODE_DAT); + rv = sb_write(board_battery->ship_mode_reg, + board_battery->ship_mode_data); if (rv != EC_SUCCESS) return rv; - return sb_write(ELECTRO_SHIP_MODE_REG, ELECTRO_SHIP_MODE_DAT); + return sb_write(board_battery->ship_mode_reg, + board_battery->ship_mode_data); } enum battery_disconnect_state battery_get_disconnect_state(void) @@ -133,6 +243,7 @@ static int fast_charging_allowed = 1; * state dependent). */ +/* TODO: crosbug.com/p/59904 */ int charger_profile_override(struct charge_state_data *curr) { /* temp in 0.1 deg C */ @@ -296,7 +407,6 @@ DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge, enum battery_present battery_is_present(void) { enum battery_present batt_pres; - int batt_status, rv; /* Get the physical hardware status */ batt_pres = battery_hw_present(); @@ -315,9 +425,12 @@ enum battery_present battery_is_present(void) */ if (batt_pres == BP_YES && batt_pres_prev != batt_pres && !battery_is_cut_off()) { - rv = battery_status(&batt_status); - if ((rv && bd9995x_get_battery_voltage() >= info.voltage_min) || - (!rv && !(batt_status & STATUS_INITIALIZED))) + /* Re-init board battery if battery presence status changes */ + if (board_get_battery_type() == BATTERY_TYPE_COUNT) { + if (bd9995x_get_battery_voltage() >= + board_get_batt_params()->batt_info.voltage_min) + batt_pres = BP_NO; + } else if (!board_get_batt_params()->batt_init()) batt_pres = BP_NO; } |