Add configs for battery detect via gpio or custom function

BUG=chrome-os-partner:24649
BRANCH=baytrail
TEST=Boot target device w/o battery. There should be no 30 second
delay prior to boot.

Change-Id: If7a60919701d1c241670d0b32e04f3e188a643f1
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/182921
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
ChromeOS Developer
2014-01-14 21:23:50 -08:00
committed by chrome-internal-fetch
parent 7c588a3292
commit c35251d662
10 changed files with 48 additions and 34 deletions

View File

@@ -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 */

View File

@@ -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);
}

View File

@@ -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},

View File

@@ -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 */

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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);

View File

@@ -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.

View File

@@ -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_CHECK_CONNECTED
#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_PRESENT_GPIO
/*
* Compile smart battery support