summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacky Wang <jacky5_wang@pegatron.corp-partner.google.com>2021-03-09 14:03:51 +0800
committerCommit Bot <commit-bot@chromium.org>2021-03-13 03:06:18 +0000
commitaa2a279ca26a5d84fef5b16214be4e9bc33a8b9c (patch)
tree5bb2923bae6e9a9522af638aba85c1aacf023a20
parenta7e01d5732e13061badefaa6efd73fb176fc1144 (diff)
downloadchrome-ec-aa2a279ca26a5d84fef5b16214be4e9bc33a8b9c.tar.gz
Jelboz: Dynamic charging current control.
1. Limit Charging Current by thrmal sensor 0 temperature(Charger). 2. If temperature over or under 54C and keep 5s, Charging Current will change to next level. 3. Limit Charging Current table : 2200/1800/1700/1600 BUG=b:181085004 BRANCH=firmware-zork-13434.B TEST=make BOARD=shuboz 1. Verified pass by thermal team. Signed-off-by: Jacky Wang <jacky5_wang@pegatron.corp-partner.google.com> Change-Id: Ic2526db54815759e52b56c662a364237ff6d878f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2716585 Reviewed-by: Edward Hill <ecgh@chromium.org> Commit-Queue: Edward Hill <ecgh@chromium.org> (cherry picked from commit ddf23ec1c9810399cd97be585248a4faadaec02c) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2757808
-rw-r--r--board/shuboz/battery.c88
-rw-r--r--board/shuboz/board.h2
2 files changed, 90 insertions, 0 deletions
diff --git a/board/shuboz/battery.c b/board/shuboz/battery.c
index 7372708305..155cadab41 100644
--- a/board/shuboz/battery.c
+++ b/board/shuboz/battery.c
@@ -6,7 +6,12 @@
*/
#include "battery_fuel_gauge.h"
+#include "battery_smart.h"
+#include "charge_state.h"
#include "common.h"
+#include "hooks.h"
+#include "temp_sensor.h"
+#include "thermal.h"
#include "util.h"
/*
@@ -64,3 +69,86 @@ 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_CM1500;
+
+static uint16_t current_table[] = {
+ 2200,
+ 1800,
+ 1700,
+ 1600,
+};
+#define NUM_CURRENT_LEVELS ARRAY_SIZE(current_table)
+
+#define TEMP_THRESHOLD 54
+static int current_level;
+
+/* Called by hook task every hook second (1 sec) */
+static void current_update(void)
+{
+ int t, temp;
+ int rv;
+ static int Uptime;
+ static int Dntime;
+
+ rv = temp_sensor_read(TEMP_SENSOR_CHARGER, &t);
+ if (rv != EC_SUCCESS)
+ return;
+
+ temp = K_TO_C(t);
+
+ if (temp > TEMP_THRESHOLD) {
+ Dntime = 0;
+ if (Uptime < 5)
+ Uptime++;
+ else {
+ Uptime = 0;
+ current_level++;
+ }
+ } else if (current_level != 0 && temp < TEMP_THRESHOLD) {
+ Uptime = 0;
+ if (Dntime < 5)
+ Dntime++;
+ else {
+ Dntime = 0;
+ current_level--;
+ }
+ } else {
+ Uptime = 0;
+ Dntime = 0;
+ }
+
+ if (current_level < 0)
+ current_level = 0;
+ else if (current_level > NUM_CURRENT_LEVELS)
+ current_level = NUM_CURRENT_LEVELS;
+}
+DECLARE_HOOK(HOOK_SECOND, current_update, HOOK_PRIO_DEFAULT);
+
+int charger_profile_override(struct charge_state_data *curr)
+{
+ /*
+ * Precharge must be executed when communication is failed on
+ * dead battery.
+ */
+ if (!(curr->batt.flags & BATT_FLAG_RESPONSIVE))
+ return 0;
+
+ if (current_level != 0) {
+ if (curr->requested_current > current_table[current_level-1])
+ curr->requested_current =
+ current_table[current_level - 1];
+ }
+
+ 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/shuboz/board.h b/board/shuboz/board.h
index 7832458f85..a15d03e454 100644
--- a/board/shuboz/board.h
+++ b/board/shuboz/board.h
@@ -21,6 +21,8 @@
#define CONFIG_USB_PD_PORT_MAX_COUNT 2
#define CONFIG_USB_PORT_ENABLE_DYNAMIC
+#define CONFIG_CHARGER_PROFILE_OVERRIDE
+
/* USB-A config */
#define GPIO_USB1_ILIM_SEL IOEX_USB_A0_CHARGE_EN_L
#define GPIO_USB2_ILIM_SEL IOEX_USB_A1_CHARGE_EN_DB_L