summaryrefslogtreecommitdiff
path: root/common/virtual_battery.c
diff options
context:
space:
mode:
authorDouglas Anderson <dianders@chromium.org>2020-07-15 08:51:55 -0700
committerCommit Bot <commit-bot@chromium.org>2020-07-21 00:39:48 +0000
commit771b693157b92049820f5161a0bf74d19de14e0b (patch)
tree597effd82effa2cb80e52de4169ea9e7f0b6c512 /common/virtual_battery.c
parent0b48d88cc8cf085ece95dc9ebf66b8a07eb72696 (diff)
downloadchrome-ec-771b693157b92049820f5161a0bf74d19de14e0b.tar.gz
virtual_battery: Return manufacture date
Newer kernels seem to request the date and if we don't have something here we get constant spam on the EC console saying "Unhandled VB reg 1b". Let's return the manufacture date in the Smart Battery Spec format, or 0 on error. BUG=b:160784792 TEST=No more spam. BRANCH=none Change-Id: I38e75d467d722b7f14ec74ec38ec68cebe6c8ed9 Signed-off-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Wai-Hong Tam <waihong@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2300459
Diffstat (limited to 'common/virtual_battery.c')
-rw-r--r--common/virtual_battery.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/common/virtual_battery.c b/common/virtual_battery.c
index e9d1c2811d..ef33a4c67a 100644
--- a/common/virtual_battery.c
+++ b/common/virtual_battery.c
@@ -177,6 +177,7 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head,
int write_len)
{
int val;
+ int year, month, day;
/*
* We cache battery operational mode locally for both read and write
* commands. If MODE_CAPACITY bit is set, battery capacity will be
@@ -300,6 +301,20 @@ int virtual_battery_operation(const uint8_t *batt_cmd_head,
return EC_ERROR_INVAL;
memcpy(dest, &val, bounded_read_len);
break;
+ case SB_MANUFACTURE_DATE:
+ /* This may cause an i2c transaction */
+ if (!battery_manufacture_date(&year, &month, &day)) {
+ /* Encode in Smart Battery Spec format */
+ val = ((year - 1980) << 9) + (month << 5) + day;
+ } else {
+ /*
+ * Return 0 on error. The kernel is unhappy with
+ * returning an error code.
+ */
+ val = 0;
+ }
+ memcpy(dest, &val, bounded_read_len);
+ break;
case SB_MANUFACTURER_ACCESS:
/* No manuf. access reg access allowed over VB interface */
return EC_ERROR_INVAL;