From abdb022a2be9cac6a108b69253ccba1dd7e09ba3 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Fri, 26 Jan 2018 14:51:10 +0800 Subject: battery: Allow 2 batteries to be fetched via ACPI We share the same shared memory fields for both batteries. When the host wants to switch battery to read out: - The host sets EC_ACPI_MEM_BATTERY_INDEX to the required index - EC then swaps the data is the shared memory fields, then update EC_MEMMAP_BATT_INDEX - Host waits for EC_MEMMAP_BATT_INDEX to have the required value, then fetches the data BRANCH=none BUG=b:65697620 TEST=Boot lux, both /sys/class/power_supply/BAT0 and BAT1 are present, data is valid. TEST=Unplug base, BAT1 goes away, replug, BAT1 comes back. Change-Id: Icce12f9eef2f6f8cde9bae0a968a65e1703d0369 Signed-off-by: Nicolas Boichat Reviewed-on: https://chromium-review.googlesource.com/888382 Reviewed-by: Gwendal Grignou --- include/battery.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'include/battery.h') diff --git a/include/battery.h b/include/battery.h index b783432ded..a97745b794 100644 --- a/include/battery.h +++ b/include/battery.h @@ -13,8 +13,9 @@ /* Battery index, only used with CONFIG_BATTERY_V2. */ enum battery_index { - BATT_IDX_MAIN, - BATT_IDX_BASE, + BATT_IDX_INVALID = -1, + BATT_IDX_MAIN = 0, + BATT_IDX_BASE = 1, }; #ifdef CONFIG_BATTERY_V2 @@ -377,6 +378,19 @@ void print_battery_debug(void); */ enum battery_disconnect_state battery_get_disconnect_state(void); +#ifdef CONFIG_BATTERY_V2 +/** + * Refresh battery information in host memory mapped region, if index is + * currently presented. + */ +void battery_memmap_refresh(enum battery_index index); + +/** + * Set which index to present in host memory mapped region. + */ +void battery_memmap_set_index(enum battery_index index); +#endif /* CONFIG_BATTERY_V2 */ + #ifdef CONFIG_CMD_I2C_STRESS_TEST_BATTERY extern struct i2c_stress_test_dev battery_i2c_stress_test_dev; #endif -- cgit v1.2.1