summaryrefslogtreecommitdiff
path: root/common/battery.c
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2018-01-12 19:16:15 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-01-14 18:38:29 -0800
commit4c56c17a1a81ca55a2f5572208bd21e811a639ed (patch)
treecf5b43adefb58d4818813f4e0bd41ca637159f80 /common/battery.c
parent66bc9c1082771e4da720f93e64aadfae23c1f22e (diff)
downloadchrome-ec-4c56c17a1a81ca55a2f5572208bd21e811a639ed.tar.gz
battery: Add support for reading base battery through host command
This adds support for EC_CMD_BATTERY_GET_STATIC and EC_CMD_BATTERY_GET_DYNAMIC host commands, that can currently only fetch the base battery information using index = 1. In the future, all battery information can be passed to AP using these host commands (i.e. lid could provide its own battery information on index = 0). BRANCH=none BUG=b:65697620 TEST=ectool battery shows lid battery information (no change) TEST=ectool battery 1 shows base battery information Change-Id: Ib819e4917b3acc337348764f6cc2aa7380bed700 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/863863 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common/battery.c')
-rw-r--r--common/battery.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/common/battery.c b/common/battery.c
index 9f1da6c4fb..65a375c02e 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -9,6 +9,7 @@
#include "charge_state.h"
#include "common.h"
#include "console.h"
+#include "ec_ec_comm_master.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
@@ -431,3 +432,43 @@ DECLARE_HOST_COMMAND(EC_CMD_BATTERY_VENDOR_PARAM,
host_command_battery_vendor_param,
EC_VER_MASK(0));
#endif /* CONFIG_BATTERY_VENDOR_PARAM */
+
+#ifdef CONFIG_EC_EC_COMM_BATTERY_MASTER
+/*
+ * TODO(b:65697620): Add support for returning main battery information through
+ * these commands, as well.
+ */
+static int host_command_battery_get_static(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_battery_static_info *p = args->params;
+ struct ec_response_battery_static_info *r = args->response;
+
+ if (p->index != 1)
+ return EC_RES_INVALID_PARAM;
+
+ args->response_size = sizeof(*r);
+ memcpy(r, &base_battery_static, sizeof(*r));
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_BATTERY_GET_STATIC,
+ host_command_battery_get_static,
+ EC_VER_MASK(0));
+
+static int host_command_battery_get_dynamic(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_battery_dynamic_info *p = args->params;
+ struct ec_response_battery_dynamic_info *r = args->response;
+
+ if (p->index != 1)
+ return EC_RES_INVALID_PARAM;
+
+ args->response_size = sizeof(*r);
+ memcpy(r, &base_battery_dynamic, sizeof(*r));
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_BATTERY_GET_DYNAMIC,
+ host_command_battery_get_dynamic,
+ EC_VER_MASK(0));
+#endif /* CONFIG_EC_EC_COMM_BATTERY */