diff options
-rw-r--r-- | board/nyan/battery.c | 11 | ||||
-rw-r--r-- | board/peppy/battery.c | 8 | ||||
-rw-r--r-- | board/peppy/board.c | 2 | ||||
-rw-r--r-- | board/peppy/board.h | 4 | ||||
-rw-r--r-- | board/samus/board.c | 6 | ||||
-rw-r--r-- | board/samus/board.h | 2 | ||||
-rw-r--r-- | common/battery.c | 16 | ||||
-rw-r--r-- | common/charge_state.c | 7 | ||||
-rw-r--r-- | include/battery.h | 8 | ||||
-rw-r--r-- | include/config.h | 18 |
10 files changed, 48 insertions, 34 deletions
diff --git a/board/nyan/battery.c b/board/nyan/battery.c index 7c0058c1d6..6bd445fdf4 100644 --- a/board/nyan/battery.c +++ b/board/nyan/battery.c @@ -240,14 +240,3 @@ int battery_command_cut_off(struct host_cmd_handler_args *args) } DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off, EC_VER_MASK(0)); - - -#ifdef CONFIG_BATTERY_CHECK_CONNECTED -/** - * Physical detection of battery connection. - */ -int battery_is_connected(void) -{ - return (gpio_get_level(GPIO_BAT_DETECT_L) == 0); -} -#endif /* CONFIG_BATTERY_CHECK_CONNECTED */ diff --git a/board/peppy/battery.c b/board/peppy/battery.c index 3d5856ef30..8a9411d7c9 100644 --- a/board/peppy/battery.c +++ b/board/peppy/battery.c @@ -42,11 +42,3 @@ int battery_command_cut_off(struct host_cmd_handler_args *args) } DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off, EC_VER_MASK(0)); - -/** - * Physical detection of battery connection. - */ -int battery_is_connected(void) -{ - return (gpio_get_level(GPIO_BAT_DETECT_L) == 0); -} diff --git a/board/peppy/board.c b/board/peppy/board.c index 72e98278bd..aee817bbb1 100644 --- a/board/peppy/board.c +++ b/board/peppy/board.c @@ -78,7 +78,7 @@ const struct gpio_info gpio_list[] = { {"BOARD_VERSION2", LM4_GPIO_Q, (1<<6), GPIO_INPUT, NULL}, {"BOARD_VERSION3", LM4_GPIO_Q, (1<<7), GPIO_INPUT, NULL}, {"CPU_PGOOD", LM4_GPIO_C, (1<<4), GPIO_INPUT, NULL}, - {"BAT_DETECT_L", LM4_GPIO_B, (1<<4), GPIO_INPUT, NULL}, + {"BAT_PRESENT_L", LM4_GPIO_B, (1<<4), GPIO_INPUT, NULL}, /* Outputs; all unasserted by default except for reset signals */ {"CPU_PROCHOT", LM4_GPIO_B, (1<<1), GPIO_OUT_LOW, NULL}, diff --git a/board/peppy/board.h b/board/peppy/board.h index b635ff256b..e5b60c3d17 100644 --- a/board/peppy/board.h +++ b/board/peppy/board.h @@ -11,7 +11,7 @@ /* Optional features */ #define CONFIG_BACKLIGHT_LID #define CONFIG_BACKLIGHT_REQ_GPIO GPIO_PCH_BKLTEN -#define CONFIG_BATTERY_CHECK_CONNECTED +#define CONFIG_BATTERY_PRESENT_GPIO GPIO_BAT_PRESENT_L #define CONFIG_BATTERY_SMART #define CONFIG_BOARD_VERSION #define CONFIG_CHARGER @@ -86,7 +86,7 @@ enum gpio_signal { GPIO_BOARD_VERSION2, /* Board version stuffing resistor 2 */ GPIO_BOARD_VERSION3, /* Board version stuffing resistor 3 */ GPIO_CPU_PGOOD, /* Power good to the CPU */ - GPIO_BAT_DETECT_L, /* Battery detect. Repurposed BAT_TEMP */ + GPIO_BAT_PRESENT_L, /* Battery present. Repurposed BAT_TEMP */ /* Outputs */ GPIO_CPU_PROCHOT, /* Force CPU to think it's overheated */ diff --git a/board/samus/board.c b/board/samus/board.c index 3ae8e9d590..de32c21c7f 100644 --- a/board/samus/board.c +++ b/board/samus/board.c @@ -309,10 +309,12 @@ struct keyboard_scan_config keyscan_config = { }, }; +#ifdef CONFIG_BATTERY_PRESENT_CUSTOM /** - * Physical detection of battery connection. + * Physical check of battery presence. */ -int battery_is_connected(void) +int battery_is_present(void) { return adc_read_channel(ADC_CH_BAT_TEMP) < (9 * ADC_READ_MAX / 10); } +#endif diff --git a/board/samus/board.h b/board/samus/board.h index a0abf8757a..dc90f3b0cd 100644 --- a/board/samus/board.h +++ b/board/samus/board.h @@ -28,8 +28,8 @@ #define CONFIG_POWER_BUTTON_X86 #define CONFIG_BACKLIGHT_REQ_GPIO GPIO_PCH_BL_EN -#define CONFIG_BATTERY_CHECK_CONNECTED #define CONFIG_BATTERY_LINK +#define CONFIG_BATTERY_PRESENT_CUSTOM #define CONFIG_BATTERY_SMART #define CONFIG_CHARGER #define CONFIG_CHARGER_BQ24715 diff --git a/common/battery.c b/common/battery.c index 8794027562..7f318646a3 100644 --- a/common/battery.c +++ b/common/battery.c @@ -6,11 +6,27 @@ */ #include "battery.h" +#include "common.h" #include "console.h" +#include "gpio.h" #include "timer.h" #include "util.h" #include "watchdog.h" +#ifdef CONFIG_BATTERY_PRESENT_GPIO +#ifdef CONFIG_BATTERY_PRESENT_CUSTOM +#error "Don't define both CONFIG_BATTERY_PRESENT_CUSTOM and" \ + "CONFIG_BATTERY_PRESENT_GPIO" +#endif +/** + * Physical detection of battery. + */ +int battery_is_present(void) +{ + return (gpio_get_level(CONFIG_BATTERY_PRESENT_GPIO) == 0); +} +#endif + static const char *get_error_text(int rv) { if (rv == EC_ERROR_UNIMPLEMENTED) diff --git a/common/charge_state.c b/common/charge_state.c index 4539a88626..16bb69b428 100644 --- a/common/charge_state.c +++ b/common/charge_state.c @@ -248,12 +248,13 @@ static int state_common(struct charge_state_context *ctx) state_machine_force_idle = 0; } -#ifdef CONFIG_BATTERY_CHECK_CONNECTED - if (!battery_is_connected()) { +#if defined(CONFIG_BATTERY_PRESENT_CUSTOM) || \ + defined(CONFIG_BATTERY_PRESENT_GPIO) + if (!battery_is_present()) { curr->error |= F_BATTERY_NOT_CONNECTED; return curr->error; } -#endif /* CONFIG_BATTERY_CHECK_CONNECTED */ +#endif /* Read params and see if battery is responsive */ battery_get_params(batt); diff --git a/include/battery.h b/include/battery.h index b10f8904c4..7072b522ef 100644 --- a/include/battery.h +++ b/include/battery.h @@ -98,11 +98,13 @@ void battery_get_params(struct batt_params *batt); void battery_vendor_params(struct batt_params *batt); /** - * Attempt communication with the battery. + * Check for presence of battery. * - * @return non-zero if the battery responds. + * @return non-zero if the battery is present. Note that the + * battery may not be responding on the i2c interface if it + * is deeply discharged. */ -int battery_is_connected(void); +int battery_is_present(void); /** * Get battery mode. diff --git a/include/config.h b/include/config.h index c84186620f..4ae871112f 100644 --- a/include/config.h +++ b/include/config.h @@ -86,10 +86,22 @@ #undef CONFIG_BATTERY_MOCK /* - * Battery can check if it's connected. If defined, charger will check for - * battery presence before attempting to communicate with it. + * 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. + * + * Replace the default battery_is_present() function with a board-specific + * implementation in board.c + */ +#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. */ -#undef CONFIG_BATTERY_CHECK_CONNECTED +#undef CONFIG_BATTERY_PRESENT_GPIO /* * Compile smart battery support |