summaryrefslogtreecommitdiff
path: root/board/cappy2
diff options
context:
space:
mode:
authorwangganxiang <wangganxiang@huaqin.corp-partner.google.com>2021-08-12 14:34:36 +0800
committerCommit Bot <commit-bot@chromium.org>2021-09-01 04:46:48 +0000
commitcbe28c81d4f1d7eb4c9221dc225306e2df6c394b (patch)
treefc10fd9f4351dac120d78cba636d6cc1d66de64a /board/cappy2
parent33b3eed3c149fc12d306a90e322a023cea6fdc30 (diff)
downloadchrome-ec-cbe28c81d4f1d7eb4c9221dc225306e2df6c394b.tar.gz
cappy2: Add battery swelling function
According to the spec, add the battery swelling function. BUG=b:196308789 BRANCH=keeby TEST=make BOARD=cappy2 pass After testing, consistent with the battery spec. Signed-off-by: wangganxiang <wangganxiang@huaqin.corp-partner.google.com> Change-Id: Ie8232d720a04974ccbb71c26b95fb0c0097b4a53 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3090226 Reviewed-by: Mike Lee <mike5@huaqin.corp-partner.google.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'board/cappy2')
-rw-r--r--board/cappy2/battery.c92
1 files changed, 90 insertions, 2 deletions
diff --git a/board/cappy2/battery.c b/board/cappy2/battery.c
index d249d64d43..aa81d0b353 100644
--- a/board/cappy2/battery.c
+++ b/board/cappy2/battery.c
@@ -4,9 +4,15 @@
*
* Battery pack vendor provided charging profile
*/
+#include "battery.h"
#include "battery_fuel_gauge.h"
+#include "battery_smart.h"
#include "charge_state.h"
#include "common.h"
+#include "util.h"
+
+#define CHARGING_VOLTAGE_MV_SAFE 8400
+#define CHARGING_CURRENT_MA_SAFE 1500
/*
* Battery info for lalala battery types. Note that the fields
@@ -70,8 +76,90 @@ const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_SDI;
int charger_profile_override(struct charge_state_data *curr)
{
- if (curr->requested_voltage == 8700)
- curr->requested_voltage = 8800;
+ int current;
+ int voltage;
+ /* battery temp in 0.1 deg C */
+ int bat_temp_c;
+ const struct battery_info *batt_info;
+
+ /*
+ * Keep track of battery temperature range:
+ *
+ * ZONE_0 ZONE_1 ZONE_2 ZONE_3
+ * ---+------+--------+--------+------+--- Temperature (C)
+ * 0 5 12 45 50
+ */
+ enum {
+ TEMP_ZONE_0, /* 0 <= bat_temp_c <= 5 */
+ TEMP_ZONE_1, /* 5 < bat_temp_c <= 12 */
+ TEMP_ZONE_2, /* 12 < bat_temp_c <= 45 */
+ TEMP_ZONE_3, /* 45 < bat_temp_c <= 50 */
+ TEMP_ZONE_COUNT,
+ TEMP_OUT_OF_RANGE = TEMP_ZONE_COUNT
+ } temp_zone;
+
+ /*
+ * Precharge must be executed when communication is failed on
+ * dead battery.
+ */
+ if (!(curr->batt.flags & BATT_FLAG_RESPONSIVE))
+ return 0;
+
+ current = curr->requested_current;
+ voltage = curr->requested_voltage;
+ bat_temp_c = curr->batt.temperature - 2731;
+ batt_info = battery_get_info();
+
+ /*
+ * If the temperature reading is bad, assume the temperature
+ * is out of allowable range.
+ */
+ if ((curr->batt.flags & BATT_FLAG_BAD_TEMPERATURE) ||
+ (bat_temp_c < 0) || (bat_temp_c > 500))
+ temp_zone = TEMP_OUT_OF_RANGE;
+ else if (bat_temp_c <= 50)
+ temp_zone = TEMP_ZONE_0;
+ else if (bat_temp_c <= 120)
+ temp_zone = TEMP_ZONE_1;
+ else if (bat_temp_c <= 450)
+ temp_zone = TEMP_ZONE_2;
+ else
+ temp_zone = TEMP_ZONE_3;
+
+ switch (temp_zone) {
+ case TEMP_ZONE_0:
+ voltage = CHARGING_VOLTAGE_MV_SAFE;
+ current = CHARGING_CURRENT_MA_SAFE;
+ break;
+
+ case TEMP_ZONE_1:
+ voltage += 100;
+ current = CHARGING_CURRENT_MA_SAFE;
+ break;
+
+ case TEMP_ZONE_2:
+ voltage += 100;
+ break;
+
+ case TEMP_ZONE_3:
+ voltage = CHARGING_VOLTAGE_MV_SAFE;
+ break;
+
+ case TEMP_OUT_OF_RANGE:
+ /* Don't charge if outside of allowable temperature range */
+ current = 0;
+ voltage = 0;
+ curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE;
+ if (curr->state != ST_DISCHARGE)
+ curr->state = ST_IDLE;
+ break;
+ }
+
+ if (voltage > batt_info->voltage_max)
+ voltage = batt_info->voltage_max;
+
+ curr->requested_voltage = voltage;
+ curr->requested_current = MIN(curr->requested_current, current);
return 0;
}