From 915137770896e9ded6068c5969479849f02ca95c Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Thu, 27 Mar 2014 13:37:21 -0700 Subject: Add charger_get_params() function to query charger state. This returns all the parameters of the charger that must be monitored frequently. While some of the fields are charger-specific, all of the parameters are present in all supported chargers. Nothing uses this yet. BUG=chrome-os-partner:20881 BRANCH=ToT TEST=make buildall -j All targets build; all tests pass. Change-Id: Id3e00532469b193aeab3acf93e94afe3ffb8c6b6 Signed-off-by: Bill Richardson Reviewed-on: https://chromium-review.googlesource.com/191985 Reviewed-by: Randall Spangler --- board/host/charger.c | 2 +- common/charger.c | 20 ++++++++++++++++++++ include/charger.h | 34 +++++++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/board/host/charger.c b/board/host/charger.c index 8a5a2e3c53..0e72fe8fb4 100644 --- a/board/host/charger.c +++ b/board/host/charger.c @@ -36,7 +36,7 @@ const struct charger_info *charger_get_info(void) } -int charger_get_status(int *status) +int charger_get_status(int *status) { *status = CHARGER_LEVEL_2; if (mock_option & CHARGE_FLAG_INHIBIT_CHARGE) diff --git a/common/charger.c b/common/charger.c index d7c92fe2a4..9d153c4159 100644 --- a/common/charger.c +++ b/common/charger.c @@ -96,6 +96,26 @@ int charger_closest_current(int current) return current - (current % info->current_step); } +void charger_get_params(struct charger_params *chg) +{ + memset(chg, 0, sizeof(*chg)); + + if (charger_get_current(&chg->current)) + chg->flags |= CHG_FLAG_BAD_CURRENT; + + if (charger_get_voltage(&chg->voltage)) + chg->flags |= CHG_FLAG_BAD_VOLTAGE; + + if (charger_get_input_current(&chg->input_current)) + chg->flags |= CHG_FLAG_BAD_INPUT_CURRENT; + + if (charger_get_status(&chg->status)) + chg->flags |= CHG_FLAG_BAD_STATUS; + + if (charger_get_option(&chg->option)) + chg->flags |= CHG_FLAG_BAD_OPTION; +} + static void print_item_name(const char *name) { ccprintf(" %-8s", name); diff --git a/include/charger.h b/include/charger.h index 23a4cebb42..bb84990856 100644 --- a/include/charger.h +++ b/include/charger.h @@ -27,21 +27,41 @@ struct charger_info { uint16_t input_current_step; }; +/* + * Parameters common to all chargers. Current is in mA, voltage in mV. + * The status and option values are charger-specific. + */ +struct charger_params { + int current; + int voltage; + int input_current; + int status; + int option; + int flags; +}; + +/* Get the current charger_params. Failures are reported in .flags */ +void charger_get_params(struct charger_params *chg); + +/* Bits to indicate which fields of struct charger_params could not be read */ +#define CHG_FLAG_BAD_CURRENT 0x00000001 +#define CHG_FLAG_BAD_VOLTAGE 0x00000002 +#define CHG_FLAG_BAD_INPUT_CURRENT 0x00000004 +#define CHG_FLAG_BAD_STATUS 0x00000008 +#define CHG_FLAG_BAD_OPTION 0x00000010 +/* All of the above CHG_FLAG_BAD_* bits */ +#define CHG_FLAG_BAD_ANY 0x0000001f + /* Power state machine post init */ int charger_post_init(void); /* Get charger information. */ const struct charger_info *charger_get_info(void); -/* Get smart battery charger status. Supported flags: - * CHARGER_CHARGE_INHIBITED - * CHARGER_LEVEL_2 - */ +/* Get smart battery charger status. Supported flags may vary. */ int charger_get_status(int *status); -/* Set smart battery charger mode. Supported mode(s): - * CHARGER_FLAG_INHIBIT_CHARGE - */ +/* Set smart battery charger mode. Supported modes may vary. */ int charger_set_mode(int mode); /** -- cgit v1.2.1