From 592919bd01f8a20c16a6e2907c273b94bc9962c4 Mon Sep 17 00:00:00 2001 From: Shine Yin Date: Fri, 22 Feb 2019 17:34:07 +0800 Subject: flapjack: add ATL battery model parameters Add detailed ATL battery information. BUG=b:128583096 BRANCH=None TEST=None Change-Id: Ie790fb2f78544f91b4fb58c5da79dcfdb4a3efde Signed-off-by: YH Lin Reviewed-on: https://chromium-review.googlesource.com/1482634 Commit-Ready: ChromeOS CL Exonerator Bot Reviewed-by: Daisuke Nojiri --- board/flapjack/battery.c | 176 +++++++++++++++++++++++++++++------------------ board/flapjack/board.h | 10 ++- 2 files changed, 118 insertions(+), 68 deletions(-) diff --git a/board/flapjack/battery.c b/board/flapjack/battery.c index 1e7bec10a7..1e088f32d9 100644 --- a/board/flapjack/battery.c +++ b/board/flapjack/battery.c @@ -1,4 +1,4 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. +/* Copyright 2019 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. * @@ -18,28 +18,34 @@ #include "hooks.h" #include "usb_pd.h" #include "util.h" - -#define TEMP_OUT_OF_RANGE TEMP_ZONE_COUNT +#include "board.h" /* We have only one battery now. */ -#define BATT_ID 0 +#define BATT_ID BATTERY_C18_ATL #define BAT_LEVEL_PD_LIMIT 85 -#define BATTERY_SIMPLO_CHARGE_MIN_TEMP 0 -#define BATTERY_SIMPLO_CHARGE_MAX_TEMP 60 - -enum battery_type { - BATTERY_SIMPLO = 0, - BATTERY_COUNT -}; +#define BATTERY_ATL_CHARGE_MIN_TEMP 0 +#define BATTERY_ATL_CHARGE_MAX_TEMP 60 static const struct battery_info info[] = { - [BATTERY_SIMPLO] = { + [BATTERY_C18_ATL] = { + .voltage_max = 4400, + .voltage_normal = 3850, + .voltage_min = 3000, + .precharge_current = 294, + .start_charging_min_c = 0, + .start_charging_max_c = 45, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = -20, + .discharging_max_c = 60, + }, + [BATTERY_C19_ATL] = { .voltage_max = 4400, - .voltage_normal = 3860, + .voltage_normal = 3850, .voltage_min = 3000, - .precharge_current = 256, + .precharge_current = 327, .start_charging_min_c = 0, .start_charging_max_c = 45, .charging_min_c = 0, @@ -48,26 +54,98 @@ static const struct battery_info info[] = { .discharging_max_c = 60, }, }; +BUILD_ASSERT(ARRAY_SIZE(info) == BATTERY_COUNT); static const struct max17055_batt_profile batt_profile[] = { - [BATTERY_SIMPLO] = { - .is_ez_config = 1, - .design_cap = MAX17055_DESIGNCAP_REG(6910), - .ichg_term = MAX17055_ICHGTERM_REG(235), - .v_empty_detect = MAX17055_VEMPTY_REG(3000, 3600), + [BATTERY_C18_ATL] = { + .is_ez_config = 0, + .design_cap = 0x2e78, /* 5948mAh */ + .ichg_term = 0x02ec, /* 117 mA */ + /* Empty voltage = 3400mV, Recovery voltage = 4000mV */ + .v_empty_detect = 0xaa64, + .learn_cfg = 0x4402, + .dpacc = 0x0c7d, + .rcomp0 = 0x0011, + .tempco = 0x0209, + .qr_table00 = 0x5a00, + .qr_table10 = 0x2980, + .qr_table20 = 0x1100, + .qr_table30 = 0x1000, + }, + [BATTERY_C19_ATL] = { + .is_ez_config = 0, + .design_cap = 0x3407, /* 6659mAh */ + .ichg_term = 0x0340, /* 130mA */ + /* Empty voltage = 3400mV, Recovery voltage = 4000mV */ + .v_empty_detect = 0xaa64, + .learn_cfg = 0x4402, + .dpacc = 0x0c7e, + .rcomp0 = 0x000f, + .tempco = 0x000b, + .qr_table00 = 0x5800, + .qr_table10 = 0x2680, + .qr_table20 = 0x0d00, + .qr_table30 = 0x0b00, }, }; +BUILD_ASSERT(ARRAY_SIZE(batt_profile) == BATTERY_COUNT); static const struct max17055_alert_profile alert_profile[] = { - [BATTERY_SIMPLO] = { + [BATTERY_C18_ATL] = { + .v_alert_mxmn = VALRT_DISABLE, + .t_alert_mxmn = MAX17055_TALRTTH_REG( + BATTERY_ATL_CHARGE_MAX_TEMP, + BATTERY_ATL_CHARGE_MIN_TEMP), + .s_alert_mxmn = SALRT_DISABLE, + .i_alert_mxmn = IALRT_DISABLE, + }, + [BATTERY_C19_ATL] = { .v_alert_mxmn = VALRT_DISABLE, .t_alert_mxmn = MAX17055_TALRTTH_REG( - BATTERY_SIMPLO_CHARGE_MAX_TEMP, - BATTERY_SIMPLO_CHARGE_MIN_TEMP), + BATTERY_ATL_CHARGE_MAX_TEMP, + BATTERY_ATL_CHARGE_MIN_TEMP), .s_alert_mxmn = SALRT_DISABLE, .i_alert_mxmn = IALRT_DISABLE, }, }; +BUILD_ASSERT(ARRAY_SIZE(alert_profile) == BATTERY_COUNT); + +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_3, /* t3 <= bat_temp_c < t4 */ + TEMP_ZONE_COUNT, + TEMP_OUT_OF_RANGE = TEMP_ZONE_COUNT, +} temp_zone; + +static const 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_C18_ATL] = { + /* TEMP_ZONE_0 */ + {BATTERY_ATL_CHARGE_MIN_TEMP * 10, 10, 1170, 4400}, + /* TEMP_ZONE_1 */ + {100, 200, 1755, 4400}, + /* TEMP_ZONE_2 */ + {200, 450, 2925, 4400}, + /* TEMP_ZONE_3 */ + {450, BATTERY_ATL_CHARGE_MAX_TEMP * 10, 2925, 4100}, + }, + [BATTERY_C19_ATL] = { + /* TEMP_ZONE_0 */ + {BATTERY_ATL_CHARGE_MIN_TEMP * 10, 10, 1300, 4400}, + /* TEMP_ZONE_1 */ + {100, 200, 1950, 4400}, + /* TEMP_ZONE_2 */ + {200, 450, 3250, 4400}, + /* TEMP_ZONE_3 */ + {450, BATTERY_ATL_CHARGE_MAX_TEMP * 10, 3250, 4100}, + }, +}; const struct battery_info *battery_get_info(void) { @@ -106,67 +184,31 @@ int charger_profile_override(struct charge_state_data *curr) /* 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_SIMPLO] = { - /* TEMP_ZONE_0 */ - {BATTERY_SIMPLO_CHARGE_MIN_TEMP * 10, 150, 1772, 4376}, - /* TEMP_ZONE_1 */ - {150, 450, 4020, 4376}, - /* TEMP_ZONE_2 */ - {450, BATTERY_SIMPLO_CHARGE_MAX_TEMP * 10, 3350, 4300}, - }, - }; - BUILD_ASSERT(ARRAY_SIZE(temp_zones[0]) == TEMP_ZONE_COUNT); - BUILD_ASSERT(ARRAY_SIZE(temp_zones) == BATTERY_COUNT); + if (curr->state != ST_CHARGE) + return 0; 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++) { + for (temp_zone = 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: + if (temp_zone == TEMP_OUT_OF_RANGE) { + curr->requested_current = curr->requested_voltage = 0; + curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE; + curr->state = ST_IDLE; + } else { 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; } /* diff --git a/board/flapjack/board.h b/board/flapjack/board.h index 27d4fee7e5..8eaf824575 100644 --- a/board/flapjack/board.h +++ b/board/flapjack/board.h @@ -138,7 +138,7 @@ #define CONFIG_BATTERY_MAX17055_ALERT /* Battery parameters for max17055 ModelGauge m5 algorithm. */ -#define BATTERY_MAX17055_RSENSE 5 /* m-ohm */ +#define BATTERY_MAX17055_RSENSE 10 /* m-ohm */ #define BATTERY_DESIRED_CHARGING_CURRENT 2000 /* mA */ #define PD_OPERATING_POWER_MW 15000 @@ -245,6 +245,14 @@ enum sensor_id { VSYNC, }; +/* Batteries */ +enum battery_type { + BATTERY_UNKNOWN = 0, + BATTERY_C18_ATL, + BATTERY_C19_ATL, + BATTERY_COUNT, +}; + #include "gpio_signal.h" #include "registers.h" -- cgit v1.2.1