From 838b062c785ddf12185b7d9d45a444818fca57db Mon Sep 17 00:00:00 2001 From: Michael5 Chen1 Date: Wed, 20 Apr 2022 11:06:43 +0800 Subject: virtual_battery: Support Battery MFG function and manufacture info Add Battery MFG function and manufacture info (0x70) BUG=b:228360450 BRANCH=kukui TEST=make buildall zmake build -a Signed-off-by: Michael5 Chen1 Change-Id: I81c73c468de170dac1ef141514cabbc30bf97536 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3595402 Reviewed-by: Eric Yilun Lin Reviewed-by: Daisuke Nojiri (cherry picked from commit 7d03da76a7360483a00c499532cac0c3375067c3) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3644561 Tested-by: Jacky Wang Commit-Queue: Jacky Wang Reviewed-by: Jacky Wang --- common/virtual_battery.c | 16 ++++++++++++++++ include/battery_smart.h | 5 +++++ include/config.h | 6 ++++++ zephyr/Kconfig.battery | 10 ++++++++++ zephyr/shim/include/config_chip.h | 6 ++++++ 5 files changed, 43 insertions(+) diff --git a/common/virtual_battery.c b/common/virtual_battery.c index fa821ccf7f..0f07482e09 100644 --- a/common/virtual_battery.c +++ b/common/virtual_battery.c @@ -354,6 +354,12 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head, return EC_ERROR_INVAL; memcpy(dest, &str, read_len); break; + + case SB_MANUFACTURE_INFO: + if (sb_read_string(*batt_cmd_head, str, sizeof(str))) + return EC_ERROR_INVAL; + memcpy(dest, &str, MIN(read_len, sizeof(str))); + break; #endif case SB_MANUFACTURER_ACCESS: #ifdef CONFIG_BATTERY_SMART @@ -370,6 +376,16 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head, val = 0x0011; memcpy(dest, &val, bounded_read_len); break; +#ifdef CONFIG_SMART_BATTERY_OPTIONAL_MFG_FUNC + case SB_OPTIONAL_MFG_FUNC1: + case SB_OPTIONAL_MFG_FUNC2: + case SB_OPTIONAL_MFG_FUNC3: + case SB_OPTIONAL_MFG_FUNC4: + if (sb_read(*batt_cmd_head, &val)) + return EC_ERROR_INVAL; + memcpy(dest, &val, bounded_read_len); + break; +#endif default: CPRINTS("Unhandled VB reg %x", *batt_cmd_head); return EC_ERROR_INVAL; diff --git a/include/battery_smart.h b/include/battery_smart.h index 635ac8558a..243f4515e3 100644 --- a/include/battery_smart.h +++ b/include/battery_smart.h @@ -56,9 +56,14 @@ #define SB_DEVICE_NAME 0x21 #define SB_DEVICE_CHEMISTRY 0x22 #define SB_MANUFACTURER_DATA 0x23 +#define SB_OPTIONAL_MFG_FUNC1 0x3C +#define SB_OPTIONAL_MFG_FUNC2 0x3D +#define SB_OPTIONAL_MFG_FUNC3 0x3E +#define SB_OPTIONAL_MFG_FUNC4 0x3F /* Extension of smart battery spec, may not be supported on all platforms */ #define SB_PACK_STATUS 0x43 #define SB_ALT_MANUFACTURER_ACCESS 0x44 +#define SB_MANUFACTURE_INFO 0x70 /* Battery mode */ #define MODE_INTERNAL_CHARGE_CONTROLLER BIT(0) diff --git a/include/config.h b/include/config.h index 45916cbc9a..0b11149a4e 100644 --- a/include/config.h +++ b/include/config.h @@ -2390,6 +2390,12 @@ #undef CONFIG_I2C_PASSTHRU_RESTRICTED #undef CONFIG_I2C_VIRTUAL_BATTERY +/* + * Define this configuration to support smart battery MFG function + * for virtual battery. + */ +#undef CONFIG_SMART_BATTERY_OPTIONAL_MFG_FUNC + /* * Define this option if an i2c bus may be unpowered at a certain point during * runtime. An example could be, a sensor bus which is not needed in lower diff --git a/zephyr/Kconfig.battery b/zephyr/Kconfig.battery index 52553a0079..249d56020e 100644 --- a/zephyr/Kconfig.battery +++ b/zephyr/Kconfig.battery @@ -401,4 +401,14 @@ config PLATFORM_EC_BATT_FULL_CHIPSET_OFF_INPUT_LIMIT_MV This condition is checked on chipset shutdown and startup, AC change and battery SOC change. +if PLATFORM_EC_I2C_VIRTUAL_BATTERY + +config PLATFORM_EC_SMART_BATTERY_OPTIONAL_MFG_FUNC + bool "Support smart battery optional MFG function" + help + Enable this option when need support smart battery optional commands. + Only make sense when PLATFORM_EC_I2C_VIRTUAL_BATTERY. + +endif # PLATFORM_EC_I2C_VIRTUAL_BATTERY + endif # PLATFORM_EC_BATTERY diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index 0a960ccca9..4fd649630d 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -150,6 +150,12 @@ #define CONFIG_BATTERY_SMART #endif +#undef CONFIG_SMART_BATTERY_OPTIONAL_MFG_FUNC + +#ifdef CONFIG_PLATFORM_EC_SMART_BATTERY_OPTIONAL_MFG_FUNC +#define CONFIG_SMART_BATTERY_OPTIONAL_MFG_FUNC +#endif + #undef CONFIG_BATTERY_PRESENT_CUSTOM #ifdef CONFIG_PLATFORM_EC_BATTERY_PRESENT_CUSTOM #define CONFIG_BATTERY_PRESENT_CUSTOM -- cgit v1.2.1