summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--baseboard/kalista/baseboard.c5
-rw-r--r--board/endeavour/board.c5
-rw-r--r--board/fizz/board.c6
-rw-r--r--board/host/board.c6
-rw-r--r--board/host/board.h2
-rw-r--r--board/puff/board.c5
-rw-r--r--board/samus_pd/board.h1
-rw-r--r--common/usb_pd_protocol.c5
-rw-r--r--common/usbc/usb_tc_drp_acc_trysrc_sm.c5
-rw-r--r--include/battery.h11
-rw-r--r--include/config.h31
-rw-r--r--test/build.mk2
-rw-r--r--test/charge_manager.c5
-rw-r--r--test/usb_pd.c5
14 files changed, 45 insertions, 49 deletions
diff --git a/baseboard/kalista/baseboard.c b/baseboard/kalista/baseboard.c
index 4567450a23..660cd5e2d6 100644
--- a/baseboard/kalista/baseboard.c
+++ b/baseboard/kalista/baseboard.c
@@ -405,11 +405,6 @@ static void board_extpower(void)
}
DECLARE_HOOK(HOOK_AC_CHANGE, board_extpower, HOOK_PRIO_DEFAULT);
-enum battery_present battery_is_present(void)
-{
- return BP_NO;
-}
-
int64_t get_time_dsw_pwrok(void)
{
/* DSW_PWROK is turned on before EC was powered. */
diff --git a/board/endeavour/board.c b/board/endeavour/board.c
index 2a58c4bc89..15ec87d92b 100644
--- a/board/endeavour/board.c
+++ b/board/endeavour/board.c
@@ -288,11 +288,6 @@ static void board_extpower(void)
}
DECLARE_HOOK(HOOK_AC_CHANGE, board_extpower, HOOK_PRIO_DEFAULT);
-enum battery_present battery_is_present(void)
-{
- return BP_NO;
-}
-
int64_t get_time_dsw_pwrok(void)
{
/* DSW_PWROK is turned on before EC was powered. */
diff --git a/board/fizz/board.c b/board/fizz/board.c
index 027bfdbb1a..8c149d31c8 100644
--- a/board/fizz/board.c
+++ b/board/fizz/board.c
@@ -566,12 +566,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma,
gpio_set_level(GPIO_TYPE_C_60W, p60w);
}
-enum battery_present battery_is_present(void)
-{
- /* The GPIO is low when the battery is present */
- return BP_NO;
-}
-
int64_t get_time_dsw_pwrok(void)
{
/* DSW_PWROK is turned on before EC was powered. */
diff --git a/board/host/board.c b/board/host/board.c
index 80ac631d19..39bf49a9ed 100644
--- a/board/host/board.c
+++ b/board/host/board.c
@@ -4,6 +4,7 @@
*/
/* Emulator board-specific configuration */
+#include "battery.h"
#include "button.h"
#include "extpower.h"
#include "gpio.h"
@@ -28,6 +29,11 @@
#include "gpio_list.h"
+test_mockable enum battery_present battery_is_present(void)
+{
+ return BP_YES;
+}
+
test_mockable_static int dummy_temp_get_val(int idx, int *temp_ptr)
{
*temp_ptr = 0;
diff --git a/board/host/board.h b/board/host/board.h
index b88831e2d9..6c0da164b3 100644
--- a/board/host/board.h
+++ b/board/host/board.h
@@ -9,6 +9,8 @@
#define __CROS_EC_BOARD_H
/* Optional features */
+/* Default-yes, override to no by including fake_battery module. */
+#define CONFIG_BATTERY_PRESENT_CUSTOM
#define CONFIG_EXTPOWER_GPIO
#undef CONFIG_FMAP
#define CONFIG_POWER_BUTTON
diff --git a/board/puff/board.c b/board/puff/board.c
index 3a846736a5..80ebedf7c2 100644
--- a/board/puff/board.c
+++ b/board/puff/board.c
@@ -510,8 +510,3 @@ void board_overcurrent_event(int port, int is_overcurrented)
return;
usbc_overcurrent = is_overcurrented;
}
-
-enum battery_present battery_is_present(void)
-{
- return BP_NO;
-}
diff --git a/board/samus_pd/board.h b/board/samus_pd/board.h
index 8d13c4be12..c6374a3e36 100644
--- a/board/samus_pd/board.h
+++ b/board/samus_pd/board.h
@@ -18,6 +18,7 @@
/* Optional features */
#define CONFIG_ADC
#undef CONFIG_ADC_WATCHDOG
+#define CONFIG_BATTERY_PRESENT_CUSTOM
#define CONFIG_BOARD_PRE_INIT
#define CONFIG_CHARGE_MANAGER
#define CONFIG_CHARGE_RAMP_SW
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 279dc465d2..874572741f 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -5494,8 +5494,9 @@ static enum ec_status hc_remote_flash(struct host_cmd_handler_args *args)
if (p->size + sizeof(*p) > args->params_size)
return EC_RES_INVALID_PARAM;
-#if defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
- defined(CONFIG_BATTERY_PRESENT_GPIO)
+#if defined(CONFIG_BATTERY) && \
+ (defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
+ defined(CONFIG_BATTERY_PRESENT_GPIO))
/*
* Do not allow PD firmware update if no battery and this port
* is sinking power, because we will lose power.
diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
index 0bad15117f..caf16d3ad3 100644
--- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c
+++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c
@@ -1292,8 +1292,9 @@ static enum ec_status hc_remote_flash(struct host_cmd_handler_args *args)
if (p->size + sizeof(*p) > args->params_size)
return EC_RES_INVALID_PARAM;
-#if defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
-defined(CONFIG_BATTERY_PRESENT_GPIO)
+#if defined(CONFIG_BATTERY) && \
+ (defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \
+ defined(CONFIG_BATTERY_PRESENT_GPIO))
/*
* Do not allow PD firmware update if no battery and this port
* is sinking power, because we will lose power.
diff --git a/include/battery.h b/include/battery.h
index a41cd9da40..85970ea4f2 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -168,12 +168,23 @@ void battery_get_params(struct batt_params *batt);
*/
void battery_override_params(struct batt_params *batt);
+#if defined(CONFIG_BATTERY) || defined(CONFIG_BATTERY_PRESENT_CUSTOM)
/**
* Check for presence of battery.
*
* @return Whether there is a battery attached or not, or if we can't tell.
*/
enum battery_present battery_is_present(void);
+#else
+/*
+ * If battery support is not enabled and the board does not specifically
+ * provide its own implementation, assume a battery is never present.
+ */
+static inline enum battery_present battery_is_present(void)
+{
+ return BP_NO;
+}
+#endif
/**
* Check for physical presence of battery.
diff --git a/include/config.h b/include/config.h
index d1e6813e08..59a221d62a 100644
--- a/include/config.h
+++ b/include/config.h
@@ -400,7 +400,13 @@
/*****************************************************************************/
/* Battery config */
-/* Support a simple battery. */
+/*
+ * Support battery management and interrogation.
+ *
+ * This is implied by CONFIG_BATTERY_<device> (below); if not enabled and
+ * CONFIG_BATTERY_PRESENT_CUSTOM is also disabled, the board is assumed to not
+ * have or support a battery.
+ */
#undef CONFIG_BATTERY
/*
@@ -447,21 +453,20 @@
#undef CONFIG_BATTERY_HW_PRESENT_CUSTOM
/*
- * If defined, the charger will check for battery presence before attempting
- * to communicate with it. This avoids the 30 second delay when booting
- * without a battery present. Do not use with CONFIG_BATTERY_PRESENT_GPIO.
+ * battery_is_present() support.
*
- * Replace the default battery_is_present() function with a board-specific
- * implementation in board.c
+ * Choice of battery driver normally determines the implementation of
+ * battery_is_present(); it is also possible to provide a board-specific
+ * implementation or note its presence from a GPIO level.
+ *
+ * If CONFIG_BATTERY is not enabled, a stub implementation that always returns
+ * "not present" is provided unless CONFIG_BATTERY_PRESENT_CUSTOM is enabled.
+ *
+ * These options are mutually exclusive.
*/
+/* The board provides a custom battery_is_present() implementation. */
#undef CONFIG_BATTERY_PRESENT_CUSTOM
-
-/*
- * If defined, GPIO which is driven low when battery is present.
- * Charger will check for battery presence before attempting to communicate
- * with it. This avoids the 30 second delay when booting without a battery
- * present. Do not use with CONFIG_BATTERY_PRESENT_CUSTOM.
- */
+/* Battery is present if the GPIO named by this define reads logic-low. */
#undef CONFIG_BATTERY_PRESENT_GPIO
/*
diff --git a/test/build.mk b/test/build.mk
index aa6b6b4483..319bfc038c 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -151,7 +151,7 @@ thermal-y=thermal.o
timer_calib-y=timer_calib.o
timer_dos-y=timer_dos.o
uptime-y=uptime.o
-usb_common-y=usb_common_test.o
+usb_common-y=usb_common_test.o fake_battery.o
usb_pd_int-y=usb_pd_int.o
usb_pd-y=usb_pd.o
usb_pd_giveback-y=usb_pd.o
diff --git a/test/charge_manager.c b/test/charge_manager.c
index 7fb8685aef..9ac87aa11d 100644
--- a/test/charge_manager.c
+++ b/test/charge_manager.c
@@ -70,11 +70,6 @@ void pd_set_new_power_request(int port)
new_power_request[port] = 1;
}
-enum battery_present battery_is_present(void)
-{
- return BP_YES;
-}
-
static void clear_new_power_requests(void)
{
int i;
diff --git a/test/usb_pd.c b/test/usb_pd.c
index 6ec9b3ffda..c009bdf7bb 100644
--- a/test/usb_pd.c
+++ b/test/usb_pd.c
@@ -48,11 +48,6 @@ uint16_t pd_get_identity_pid(int port)
return 0;
}
-enum battery_present battery_is_present(void)
-{
- return BP_YES;
-}
-
int battery_status(int *status)
{
*status = 1;