summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--driver/battery/smart.c23
-rw-r--r--include/config.h33
-rw-r--r--zephyr/Kconfig.battery43
-rw-r--r--zephyr/shim/include/config_chip.h6
4 files changed, 99 insertions, 6 deletions
diff --git a/driver/battery/smart.c b/driver/battery/smart.c
index b3d1787338..4d64c29efa 100644
--- a/driver/battery/smart.c
+++ b/driver/battery/smart.c
@@ -590,14 +590,25 @@ int battery_wait_for_stable(void)
BATTERY_NO_RESPONSE_TIMEOUT);
while (get_time().val < wait_timeout) {
/* Starting pinging battery */
- if (battery_status(&status) == EC_SUCCESS) {
- /* Battery is stable */
- CPRINTS("battery responded with status %x", status);
- return EC_SUCCESS;
+ if (battery_status(&status) != EC_SUCCESS) {
+ msleep(25); /* clock stretching could hold 25ms */
+ continue;
+ }
+
+#ifdef CONFIG_BATTERY_STBL_STAT
+ if (((status & CONFIG_BATT_ALARM_MASK1) ==
+ CONFIG_BATT_ALARM_MASK1) ||
+ ((status & CONFIG_BATT_ALARM_MASK2) ==
+ CONFIG_BATT_ALARM_MASK2)) {
+ msleep(25);
+ continue;
}
- msleep(25); /* clock stretching could hold 25ms */
+#endif
+ /* Battery is stable */
+ CPRINTS("battery responded with status %x", status);
+ return EC_SUCCESS;
}
- CPRINTS("battery not responding");
+ CPRINTS("battery not responding with status %x", status);
return EC_ERROR_NOT_POWERED;
}
diff --git a/include/config.h b/include/config.h
index a3a2edb1ed..dfc684f278 100644
--- a/include/config.h
+++ b/include/config.h
@@ -665,6 +665,12 @@
#undef CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV
/*
+ * Check the specific battery status to judge whether the battery is
+ * initialized and stable when the battery wakes up from ship mode.
+ */
+#undef CONFIG_BATTERY_STBL_STAT
+
+/*
* Some batteries don't update full capacity timely or don't update it at all.
* On such systems, compensation is required to guarantee remaining_capacity
* will be equal to full_capacity eventually. This used to be done in ACPI.
@@ -6411,6 +6417,33 @@
#define CONFIG_BATTERY_V1
#endif
+/*
+ * Check the specific battery status to judge whether the battery is
+ * initialized and stable when the battery wakes up from ship mode.
+ * Use two MASKs to provide logical AND and logical OR options for different
+ * status. For example:
+ *
+ * Logical OR -- just check one of TCA/TDA mask:
+ * #define CONFIG_BATT_ALARM_MASK1 \
+ * (STATUS_TERMINATE_CHARGE_ALARM | STATUS_TERMINATE_DISCHARGE_ALARM)
+ * #define CONFIG_BATT_ALARM_MASK2 0xFFFF
+ *
+ * Logical AND -- check both TCA/TDA mask:
+ * #define CONFIG_BATT_ALARM_MASK1 STATUS_TERMINATE_CHARGE_ALARM
+ * #define CONFIG_BATT_ALARM_MASK2 STATUS_TERMINATE_DISCHARGE_ALARM
+ *
+ * The default configuration is logical OR.
+ */
+#ifdef CONFIG_BATTERY_STBL_STAT
+#ifndef CONFIG_BATT_ALARM_MASK1
+#define CONFIG_BATT_ALARM_MASK1 \
+ (STATUS_TERMINATE_CHARGE_ALARM | STATUS_TERMINATE_DISCHARGE_ALARM)
+#endif
+#ifndef CONFIG_BATT_ALARM_MASK2
+#define CONFIG_BATT_ALARM_MASK2 0xFFFF
+#endif
+#endif
+
/*****************************************************************************/
/* Define derived USB PD Discharge common path */
#if defined(CONFIG_USB_PD_DISCHARGE_GPIO) || \
diff --git a/zephyr/Kconfig.battery b/zephyr/Kconfig.battery
index 01d42567ab..2247e30cff 100644
--- a/zephyr/Kconfig.battery
+++ b/zephyr/Kconfig.battery
@@ -178,6 +178,49 @@ config PLATFORM_EC_BATTERY_MAX_IMBALANCE_MV
system tolerant of larger values of
CONFIG_PLATFORM_EC_BATTERY_MAX_IMBALANCE_MV.
+config PLATFORM_EC_BATTERY_STBL_STAT
+ bool "Check whether the battery is initialized and stable"
+ help
+ Enables support for checking the specific battery status to
+ judge whether the battery is initialized and stable when the battery
+ wakes up from ship mode. Use two MASKs to provide logical AND and
+ logical OR options for different status.
+
+ For example:
+ STATUS_TERMINATE_CHARGE_ALARM(TCA):0x4000
+ STATUS_TERMINATE_DISCHARGE_ALARM(TDA):0x0800
+
+ Logical OR -- just check one of TCA/TDA mask:
+ CONFIG_PLATFORM_EC_BATT_ALARM_MASK1=(0x4000 | 0x0800)
+ CONFIG_PLATFORM_EC_BATT_ALARM_MASK2=0xFFFF
+
+ Logical AND -- check both TCA/TDA mask:
+ CONFIG_PLATFORM_EC_BATT_ALARM_MASK1=0x4000
+ CONFIG_PLATFORM_EC_BATT_ALARM_MASK2=0x0800
+
+ The default configuration is logical OR.
+
+if PLATFORM_EC_BATTERY_STBL_STAT
+
+config PLATFORM_EC_BATT_ALARM_MASK1
+ hex "The battery status mask"
+ default 0x4800
+ help
+ Use two MASKs to provide logical AND and logical OR options for different
+ status. Default mask 0x4800 means
+ (STATUS_TERMINATE_CHARGE_ALARM | STATUS_TERMINATE_DISCHARGE_ALARM),
+ any one of these two masks is set, the battery state can be considered
+ stable.
+
+config PLATFORM_EC_BATT_ALARM_MASK2
+ hex "The battery status mask"
+ default 0xFFFF
+ help
+ Use two MASKs to provide logical AND and logical OR options for different
+ status. Default mask 0xFFFF means do not use this mask.
+
+endif # PLATFORM_EC_BATTERY_STBL_STAT
+
config PLATFORM_EC_CHARGER_MIN_BAT_PCT_IMBALANCED_POWER_ON
int "Minimum battery percentage for power on with an imbalanced pack"
depends on PLATFORM_EC_BATTERY_MEASURE_IMBALANCE
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index 132494d5f4..fa8e278996 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -297,7 +297,13 @@
CONFIG_PLATFORM_EC_BATTERY_MAX_IMBALANCE_MV
#define CONFIG_CHARGER_MIN_BAT_PCT_IMBALANCED_POWER_ON \
CONFIG_PLATFORM_EC_CHARGER_MIN_BAT_PCT_IMBALANCED_POWER_ON
+#endif
+#undef CONFIG_BATTERY_STBL_STAT
+#ifdef CONFIG_PLATFORM_EC_BATTERY_STBL_STAT
+#define CONFIG_BATTERY_STBL_STAT
+#define CONFIG_BATT_ALARM_MASK1 CONFIG_PLATFORM_EC_BATT_ALARM_MASK1
+#define CONFIG_BATT_ALARM_MASK2 CONFIG_PLATFORM_EC_BATT_ALARM_MASK2
#endif
#undef CONFIG_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV