summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael5 Chen1 <michael5_chen1@pegatron.corp-partner.google.com>2022-04-13 13:25:54 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-04-18 03:56:29 +0000
commitc67a30cf4f30c48d08b684c449cb1092db09cebf (patch)
treebfb58ee92c226b3a6c379d695849b760d408b88a
parent984275e6f274f3c59b92ba73c2e5ed8a62cfe81d (diff)
downloadchrome-ec-c67a30cf4f30c48d08b684c449cb1092db09cebf.tar.gz
virtual_battery: Return manufacturer data
Add battery command manufacturer data BUG=b:228360450 BRANCH=kukui TEST=make buildall Run command "ectool i2cxfer 2 0x0b 0x05 0x23" on damu Signed-off-by: Michael5 Chen1 <michael5_chen1@pegatron.corp-partner.google.com> Change-Id: Iab93801e28b0d6f32cb257c19573e6dfbdc3c3bb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3583910 Reviewed-by: Ting Shen <phoenixshen@chromium.org> (cherry picked from commit 4efe01202e6c8e5681c953732ebf3ada539c8804) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3590092 Reviewed-by: Eric Yilun Lin <yllin@google.com> Commit-Queue: Eric Yilun Lin <yllin@google.com>
-rw-r--r--common/virtual_battery.c13
-rw-r--r--driver/battery/smart.c5
-rw-r--r--include/battery.h9
3 files changed, 27 insertions, 0 deletions
diff --git a/common/virtual_battery.c b/common/virtual_battery.c
index 1caef535f6..19241d3ee0 100644
--- a/common/virtual_battery.c
+++ b/common/virtual_battery.c
@@ -178,6 +178,9 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head,
{
int val;
int year, month, day;
+#ifdef CONFIG_BATTERY_SMART
+ char str[32];
+#endif
/*
* We cache battery operational mode locally for both read and write
* commands. If MODE_CAPACITY bit is set, battery capacity will be
@@ -342,6 +345,16 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head,
}
memcpy(dest, &val, bounded_read_len);
break;
+#ifdef CONFIG_BATTERY_SMART
+ case SB_MANUFACTURER_DATA:
+ if (read_len > ARRAY_SIZE(str))
+ return EC_ERROR_INVAL;
+ /* This may cause an i2c transaction */
+ if (battery_manufacturer_data(str, ARRAY_SIZE(str)))
+ return EC_ERROR_INVAL;
+ memcpy(dest, &str, read_len);
+ break;
+#endif
case SB_MANUFACTURER_ACCESS:
/* No manuf. access reg access allowed over VB interface */
return EC_ERROR_INVAL;
diff --git a/driver/battery/smart.c b/driver/battery/smart.c
index 69048adbc6..29abe65f32 100644
--- a/driver/battery/smart.c
+++ b/driver/battery/smart.c
@@ -317,6 +317,11 @@ test_mockable int battery_device_chemistry(char *dest, int size)
return sb_read_string(SB_DEVICE_CHEMISTRY, dest, size);
}
+int battery_manufacturer_data(char *data, int size)
+{
+ return sb_read_string(SB_MANUFACTURER_DATA, data, size);
+}
+
int battery_get_avg_current(void)
{
int current;
diff --git a/include/battery.h b/include/battery.h
index 8f90a107b4..35b3d502ce 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -359,6 +359,15 @@ int battery_device_chemistry(char *dest, int size);
int battery_manufacturer_date(int *year, int *month, int *day);
/**
+ * Read battery manufacturer data.
+ *
+ * @param dest Destination buffer.
+ * @param size Length of destination buffer.
+ * @return non-zero if error.
+ */
+int battery_manufacturer_data(char *data, int size);
+
+/**
* Report the absolute difference between the highest and lowest cell voltage in
* the battery pack, in millivolts. On error or unimplemented, returns '0'.
*/