spring: keep AP off when battery level is too low

When battery level is too low, we want to keep the AP off even when a
power on event is received. Current threshold is set to 1 mAh.

Note that after this change, a board without a battery will need to wait
for 15 seconds before it can boot up.

BUG=chrome-os-partner:18318
TEST=Press power button and see power on event ignored. Charge battery
to over AP off threshold and check we can power on the system.
BRANCH=spring

Change-Id: If32a1935a69be102778bde7ad8976eea0921f87e
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/45825
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
Vic Yang
2013-03-19 10:56:49 +08:00
committed by ChromeBot
parent 447b05b828
commit db20e7afde
4 changed files with 48 additions and 3 deletions

View File

@@ -59,6 +59,9 @@
/* Battery */
#define CONFIG_BATTERY_BQ20Z453
/* Low battery threshold. In mAh. */
#define BATTERY_AP_OFF_LEVEL 1
/* Charger/accessories detection */
#define CONFIG_TSU6721

View File

@@ -506,6 +506,28 @@ static int next_pwr_event(void)
/*****************************************************************************/
static int wait_for_power_on(void)
{
int value;
while (1) {
value = check_for_power_on_event();
if (!value) {
task_wait_event(-1);
continue;
}
if (charge_keep_power_off()) {
CPRINTF("%T battery low. ignoring power on event.\n");
if (value == 1) /* System already on */
power_off();
continue;
}
CPRINTF("%T power on %d\n", value);
return value;
}
}
void chipset_task(void)
{
int value;
@@ -515,9 +537,7 @@ void chipset_task(void)
while (1) {
/* Wait until we need to power on, then power on */
while (value = check_for_power_on_event(), !value)
task_wait_event(-1);
CPRINTF("%T power on %d\n", value);
wait_for_power_on();
if (!power_on()) {
int continue_power = 0;

View File

@@ -42,6 +42,10 @@
#define T2_USEC (10 * SECOND)
#define T3_USEC (10 * SECOND)
#ifndef BATTERY_AP_OFF_LEVEL
#define BATTERY_AP_OFF_LEVEL 0
#endif
static const char * const state_list[] = {
"idle",
"pre-charging",
@@ -373,6 +377,19 @@ enum charging_state charge_get_state(void)
return current_state;
}
int charge_keep_power_off(void)
{
int charge;
if (BATTERY_AP_OFF_LEVEL == 0)
return 0;
if (battery_remaining_capacity(&charge))
return current_state != ST_CHARGING_ERROR;
return charge <= BATTERY_AP_OFF_LEVEL;
}
void pmu_charger_task(void)
{
int next_state;

View File

@@ -269,5 +269,10 @@ void pmu_task_throttled_wake(void);
*/
enum charging_state charge_get_state(void);
/**
* Return non-zero if battery is so low we want to keep AP off.
*/
int charge_keep_power_off(void);
#endif /* __CROS_EC_TPSCHROME_H */