diff options
-rw-r--r-- | board/vilboz/battery.c | 81 | ||||
-rw-r--r-- | board/vilboz/board.h | 2 |
2 files changed, 83 insertions, 0 deletions
diff --git a/board/vilboz/battery.c b/board/vilboz/battery.c index dccc02805b..05beee34bc 100644 --- a/board/vilboz/battery.c +++ b/board/vilboz/battery.c @@ -6,7 +6,11 @@ */ #include "battery_fuel_gauge.h" +#include "battery_smart.h" +#include "charge_state.h" #include "common.h" +#include "temp_sensor.h" +#include "thermal.h" #include "util.h" /* @@ -375,3 +379,80 @@ const struct board_batt_params board_battery_info[] = { BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT); const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_SMP; + +struct chg_curr_step { + int on; + int off; + int curr_ma; +}; + +static const struct chg_curr_step chg_curr_table[] = { + {.on = 0, .off = 35, .curr_ma = 2800}, + {.on = 36, .off = 35, .curr_ma = 1500}, + {.on = 39, .off = 38, .curr_ma = 1000}, +}; + +/* All charge current tables must have the same number of levels */ +#define NUM_CHG_CURRENT_LEVELS ARRAY_SIZE(chg_curr_table) + +int charger_profile_override(struct charge_state_data *curr) +{ + int rv; + int chg_temp_c; + int current; + int thermal_sensor0; + static int current_level; + static int prev_tmp; + + /* + * Precharge must be executed when communication is failed on + * dead battery. + */ + if (!(curr->batt.flags & BATT_FLAG_RESPONSIVE)) + return 0; + + current = curr->requested_current; + + rv = temp_sensor_read(TEMP_SENSOR_CHARGER, &thermal_sensor0); + chg_temp_c = K_TO_C(thermal_sensor0); + + if (rv != EC_SUCCESS) + return 0; + + if (chipset_in_state(CHIPSET_STATE_ON)) { + if (chg_temp_c < prev_tmp) { + if (chg_temp_c <= chg_curr_table[current_level].off) + current_level = current_level - 1; + } else if (chg_temp_c > prev_tmp) { + if (chg_temp_c >= chg_curr_table[current_level + 1].on) + current_level = current_level + 1; + } + } + + /* + * Prevent level always minus 0 or over table steps. + */ + if (current_level < 0) + current_level = 0; + else if (current_level >= NUM_CHG_CURRENT_LEVELS) + current_level = NUM_CHG_CURRENT_LEVELS - 1; + + prev_tmp = chg_temp_c; + current = chg_curr_table[current_level].curr_ma; + + curr->requested_current = MIN(curr->requested_current, current); + + return 0; +} + +enum ec_status charger_profile_override_get_param(uint32_t param, + uint32_t *value) +{ + return EC_RES_INVALID_PARAM; +} + +enum ec_status charger_profile_override_set_param(uint32_t param, + uint32_t value) +{ + return EC_RES_INVALID_PARAM; +} diff --git a/board/vilboz/board.h b/board/vilboz/board.h index 3babb9bbc7..33ecda9b30 100644 --- a/board/vilboz/board.h +++ b/board/vilboz/board.h @@ -19,6 +19,8 @@ #define GPIO_USB1_ILIM_SEL GPIO_USB_A0_CHARGE_EN_L #define GPIO_USB2_ILIM_SEL GPIO_USB_A1_CHARGE_EN_DB_L +#define CONFIG_CHARGER_PROFILE_OVERRIDE + /* Power LEDs */ #define CONFIG_LED_POWER_LED |