diff options
Diffstat (limited to 'include/charge_state.h')
-rw-r--r-- | include/charge_state.h | 76 |
1 files changed, 53 insertions, 23 deletions
diff --git a/include/charge_state.h b/include/charge_state.h index ed777c1a64..221947b9d1 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -1,4 +1,4 @@ -/* Copyright 2014 The Chromium OS Authors. All rights reserved. +/* Copyright 2014 The ChromiumOS Authors * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -7,6 +7,7 @@ #include "common.h" #include "timer.h" +#include "stdbool.h" /* Stuff that's common to all charger implementations can go here. */ @@ -14,14 +15,14 @@ #define PRECHARGE_TIMEOUT CONFIG_BATTERY_PRECHARGE_TIMEOUT /* Power state task polling periods in usec */ -#define CHARGE_POLL_PERIOD_VERY_LONG MINUTE -#define CHARGE_POLL_PERIOD_LONG (MSEC * 500) -#define CHARGE_POLL_PERIOD_CHARGE (MSEC * 250) -#define CHARGE_POLL_PERIOD_SHORT (MSEC * 100) -#define CHARGE_MIN_SLEEP_USEC (MSEC * 50) +#define CHARGE_POLL_PERIOD_VERY_LONG MINUTE +#define CHARGE_POLL_PERIOD_LONG (MSEC * 500) +#define CHARGE_POLL_PERIOD_CHARGE (MSEC * 250) +#define CHARGE_POLL_PERIOD_SHORT (MSEC * 100) +#define CHARGE_MIN_SLEEP_USEC (MSEC * 50) /* If a board hasn't provided a max sleep, use 1 minute as default */ #ifndef CHARGE_MAX_SLEEP_USEC -#define CHARGE_MAX_SLEEP_USEC MINUTE +#define CHARGE_MAX_SLEEP_USEC MINUTE #endif /* Power states */ @@ -36,6 +37,8 @@ enum charge_state { PWR_STATE_IDLE0, /* Idle; AC present */ PWR_STATE_IDLE, + /* Forced Idle */ + PWR_STATE_FORCED_IDLE, /* Discharging */ PWR_STATE_DISCHARGE, /* Discharging and fully charged */ @@ -61,20 +64,13 @@ enum charge_state { /* Debugging constants, in the same order as enum charge_state. This string * table was moved here to sync with enum above. */ -#define CHARGE_STATE_NAME_TABLE { \ - "unchange", \ - "init", \ - "reinit", \ - "idle0", \ - "idle", \ - "discharge", \ - "discharge_full", \ - "charge", \ - "charge_near_full", \ - "error" \ +#define CHARGE_STATE_NAME_TABLE \ + { \ + "unchange", "init", "reinit", "idle0", "idle", "discharge", \ + "discharge_full", "charge", "charge_near_full", \ + "error" \ } - /* End of CHARGE_STATE_NAME_TABLE macro */ - +/* End of CHARGE_STATE_NAME_TABLE macro */ /** * Return current charge state. @@ -99,7 +95,14 @@ uint32_t charge_get_flags(void); /** * Return current battery charge percentage. */ +#if defined(CONFIG_BATTERY) || defined(TEST_BUILD) int charge_get_percent(void); +#else +static inline int charge_get_percent(void) +{ + return 0; +} +#endif /** * Return current battery charge if not using charge manager sub-system. @@ -124,7 +127,7 @@ __override_proto int charge_is_consuming_full_input_current(void); /** * Return non-zero if discharging and battery so low we should shut down. */ -#ifdef CONFIG_CHARGER +#if defined(CONFIG_CHARGER) && defined(CONFIG_BATTERY) int charge_want_shutdown(void); #else static inline int charge_want_shutdown(void) @@ -134,13 +137,41 @@ static inline int charge_want_shutdown(void) #endif /** + * Return true if battery level is below threshold, false otherwise, + * or if SoC can't be determined. + * + * @param transitioned True to check if SoC is previously above threshold + */ +enum batt_threshold_type { + BATT_THRESHOLD_TYPE_LOW = 0, + BATT_THRESHOLD_TYPE_SHUTDOWN +}; +#if defined(CONFIG_CHARGER) && defined(CONFIG_BATTERY) +int battery_is_below_threshold(enum batt_threshold_type type, + bool transitioned); +#else +static inline int battery_is_below_threshold(enum batt_threshold_type type, + bool transitioned) +{ + return 0; +} +#endif + +/** * Return non-zero if the battery level is too low to allow power on, even if * a charger is attached. * * @param power_button_pressed True if the power-up attempt is caused by a * power button press. */ +#ifdef CONFIG_BATTERY int charge_prevent_power_on(int power_button_pressed); +#else +static inline int charge_prevent_power_on(int power_button_pressed) +{ + return 0; +} +#endif /** * Get the last polled battery/charger temperature. @@ -159,8 +190,7 @@ int charge_get_battery_temp(int idx, int *temp_ptr); */ const struct batt_params *charger_current_battery_params(void); - /* Config Charger */ #include "charge_state_v2.h" -#endif /* __CROS_EC_CHARGE_STATE_H */ +#endif /* __CROS_EC_CHARGE_STATE_H */ |