summaryrefslogtreecommitdiff
path: root/common/battery.c
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2018-01-26 12:24:13 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-07 11:55:57 -0800
commitad286a050ea566ebd89cb53f5118c91b04a0980c (patch)
treee971a973353b0b2477429009d7f3804bd8d9ecec /common/battery.c
parentc8e2deb24dbbf4165acac4d3b72376d98ec210a1 (diff)
downloadchrome-ec-ad286a050ea566ebd89cb53f5118c91b04a0980c.tar.gz
charge_state_v2: Store battery information in new structures
On dual battery systems, this allows to keep both batteries information in similar structures. This also means that battery information can only be fetched via host commands EC_CMD_BATTERY_GET_STATIC/DYNAMIC (next CL will make it possible to fetch the information via shared memory/ACPI). BRANCH=none BUG=b:65697620 TEST=Boot lux/wand, dual-battery algorithm works, AP can fetch both battery information via host commands. Change-Id: I3c087e8f378c5cef0006f6bfe58335228a880e5b Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/888381 Reviewed-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Diffstat (limited to 'common/battery.c')
-rw-r--r--common/battery.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/common/battery.c b/common/battery.c
index 65a375c02e..711d7f7913 100644
--- a/common/battery.c
+++ b/common/battery.c
@@ -21,6 +21,15 @@
#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
+#ifdef CONFIG_BATTERY_V2
+/*
+ * Store battery information in these 2 structures. Main (lid) battery is always
+ * at index 0, and secondary (base) battery at index 1.
+ */
+struct ec_response_battery_static_info battery_static[CONFIG_BATTERY_COUNT];
+struct ec_response_battery_dynamic_info battery_dynamic[CONFIG_BATTERY_COUNT];
+#endif
+
#ifdef CONFIG_BATTERY_CUT_OFF
#ifndef CONFIG_BATTERY_CUTOFF_DELAY_US
@@ -433,21 +442,20 @@ DECLARE_HOST_COMMAND(EC_CMD_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.
- */
+#ifdef CONFIG_HOSTCMD_BATTERY_V2
+#ifndef CONFIG_BATTERY_V2
+#error "CONFIG_HOSTCMD_BATTERY_V2 cannot be set without CONFIG_BATTERY_V2."
+#endif
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)
+ if (p->index < 0 || p->index >= CONFIG_BATTERY_COUNT)
return EC_RES_INVALID_PARAM;
args->response_size = sizeof(*r);
- memcpy(r, &base_battery_static, sizeof(*r));
+ memcpy(r, &battery_static[p->index], sizeof(*r));
return EC_RES_SUCCESS;
}
@@ -460,15 +468,15 @@ 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)
+ if (p->index < 0 || p->index >= CONFIG_BATTERY_COUNT)
return EC_RES_INVALID_PARAM;
args->response_size = sizeof(*r);
- memcpy(r, &base_battery_dynamic, sizeof(*r));
+ memcpy(r, &battery_dynamic[p->index], 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 */
+#endif /* CONFIG_HOSTCMD_BATTERY_V2 */