summaryrefslogtreecommitdiff
path: root/baseboard
diff options
context:
space:
mode:
authorLeo Zhou <zhoubo@huaqin.corp-partner.google.com>2019-08-10 15:27:50 +0800
committerCommit Bot <commit-bot@chromium.org>2019-08-26 09:54:27 +0000
commitb3470c02db3b03781cc4d7b0a4c7894a342cba1a (patch)
tree9784f366c1b029aa9541c689d181ec383ba9d587 /baseboard
parent8064c30fe43d1336cbd3ce302792e27c68ae5125 (diff)
downloadchrome-ec-b3470c02db3b03781cc4d7b0a4c7894a342cba1a.tar.gz
Krane: Override the charger_profile_override based on battery SPEC
Based on the battery specification modify the battery_info and restructure the charger_profile_override BUG=b:139012888 BRANCH=master TEST=Do a charge Test under extreme temperature Change-Id: I2f85abe98d4e7f73f77c6ff0091fb0cb144e2769 Signed-off-by: Leo zhou <zhoubo@huaqin.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1746349 Tested-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'baseboard')
-rw-r--r--baseboard/kukui/battery_mm8013.c74
1 files changed, 71 insertions, 3 deletions
diff --git a/baseboard/kukui/battery_mm8013.c b/baseboard/kukui/battery_mm8013.c
index ad65116ebf..8fed84fe53 100644
--- a/baseboard/kukui/battery_mm8013.c
+++ b/baseboard/kukui/battery_mm8013.c
@@ -17,6 +17,11 @@
#define BATT_ID 0
+#define BATTERY_SCUD_CHARGE_MIN_TEMP 0
+#define BATTERY_SCUD_CHARGE_MAX_TEMP 50
+
+#define BAT_LEVEL_PD_LIMIT 85
+
#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
enum battery_type {
@@ -28,14 +33,14 @@ static const struct battery_info info[] = {
[BATTERY_SCUD] = {
.voltage_max = 4400,
.voltage_normal = 3850,
- .voltage_min = 3400,
+ .voltage_min = 3000,
.precharge_current = 256,
.start_charging_min_c = 0,
.start_charging_max_c = 45,
.charging_min_c = 0,
.charging_max_c = 50,
.discharging_min_c = -20,
- .discharging_max_c = 60,
+ .discharging_max_c = 59,
},
};
@@ -53,7 +58,70 @@ enum battery_disconnect_state battery_get_disconnect_state(void)
int charger_profile_override(struct charge_state_data *curr)
{
- /* TODO(b:138269954): Add battery configs for krane. */
+ /* battery temp in 0.1 deg C */
+ int bat_temp_c = curr->batt.temperature - 2731;
+ /*
+ * Keep track of battery temperature range:
+ *
+ * ZONE_0 ZONE_1 ZONE_2
+ * -----+--------+--------+------------+----- Temperature (C)
+ * t0 t1 t2 t3
+ */
+ enum {
+ TEMP_ZONE_0, /* t0 < bat_temp_c <= t1 */
+ TEMP_ZONE_1, /* t1 < bat_temp_c <= t2 */
+ TEMP_ZONE_2, /* t2 < bat_temp_c <= t3 */
+ TEMP_ZONE_COUNT
+ } temp_zone;
+
+ static struct {
+ int temp_min; /* 0.1 deg C */
+ int temp_max; /* 0.1 deg C */
+ int desired_current; /* mA */
+ int desired_voltage; /* mV */
+ } temp_zones[BATTERY_COUNT][TEMP_ZONE_COUNT] = {
+ [BATTERY_SCUD] = {
+ /* TEMP_ZONE_0 */
+ {BATTERY_SCUD_CHARGE_MIN_TEMP * 10, 150, 1400, 4400},
+ /* TEMP_ZONE_1 */
+ {150, 450, 3500, 4400},
+ /* TEMP_ZONE_2 */
+ {450, BATTERY_SCUD_CHARGE_MAX_TEMP * 10, 3500, 4200},
+ },
+ };
+ BUILD_ASSERT(ARRAY_SIZE(temp_zones[0]) == TEMP_ZONE_COUNT);
+ BUILD_ASSERT(ARRAY_SIZE(temp_zones) == BATTERY_COUNT);
+
+ if ((curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE) ||
+ (bat_temp_c < temp_zones[BATT_ID][0].temp_min) ||
+ (bat_temp_c >= temp_zones[BATT_ID][TEMP_ZONE_COUNT - 1].temp_max))
+ temp_zone = TEMP_OUT_OF_RANGE;
+ else {
+ for (temp_zone = 0; temp_zone < TEMP_ZONE_COUNT; temp_zone++) {
+ if (bat_temp_c <
+ temp_zones[BATT_ID][temp_zone].temp_max)
+ break;
+ }
+ }
+
+ if (curr->state != ST_CHARGE)
+ return 0;
+
+ switch (temp_zone) {
+ case TEMP_ZONE_0:
+ case TEMP_ZONE_1:
+ case TEMP_ZONE_2:
+ curr->requested_current =
+ temp_zones[BATT_ID][temp_zone].desired_current;
+ curr->requested_voltage =
+ temp_zones[BATT_ID][temp_zone].desired_voltage;
+ break;
+ case TEMP_OUT_OF_RANGE:
+ curr->requested_current = curr->requested_voltage = 0;
+ curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE;
+ curr->state = ST_IDLE;
+ break;
+ }
#ifdef VARIANT_KUKUI_CHARGER_MT6370
mt6370_charger_profile_override(curr);