summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2020-12-02 15:21:43 +0800
committerCommit Bot <commit-bot@chromium.org>2020-12-03 06:04:31 +0000
commit65feeb47e355aec8b7c971964811a8aac8e02124 (patch)
tree9a2c7c5f86f5f5f4014d9db747517ab57a2138c3 /board
parent43422dfde262954c0a85c03aac1c709227b68da8 (diff)
downloadchrome-ec-65feeb47e355aec8b7c971964811a8aac8e02124.tar.gz
asurada: cache board id on init
The line board_get_version() inside board_hibernate_late() fails if it is the first board_get_version() call, because ADC (or some function related to it) is not usable at that time. To fix this, cache board id to ensure board_hibernate_late() never need to access ADC. Also replace #include <...> to #include "..." for consistency. BUG=b:163963220 TEST=hibernate successful in G3 BRANCH=none Signed-off-by: Ting Shen <phoenixshen@google.com> Change-Id: I0c277cccd081906d6f87793e8e4f1980a4e55c3a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2567458 Tested-by: Ting Shen <phoenixshen@chromium.org> Auto-Submit: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Eric Yilun Lin <yllin@chromium.org> Commit-Queue: Eric Yilun Lin <yllin@chromium.org>
Diffstat (limited to 'board')
-rw-r--r--board/asurada/board_id.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/board/asurada/board_id.c b/board/asurada/board_id.c
index f57863e03b..a2306c2211 100644
--- a/board/asurada/board_id.c
+++ b/board/asurada/board_id.c
@@ -3,12 +3,13 @@
* found in the LICENSE file.
*/
-#include <adc.h>
-#include <common.h>
-#include <console.h>
-#include <gpio.h>
-#include <timer.h>
-#include <util.h>
+#include "adc.h"
+#include "common.h"
+#include "console.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "timer.h"
+#include "util.h"
/**
* Conversion based on following table:
@@ -85,13 +86,11 @@ static int adc_value_to_numeric_id(enum adc_channel ch)
return -EC_ERROR_UNKNOWN;
}
-int board_get_version(void)
-{
- static int version = -1;
-
- if (version >= 0)
- return version;
+static int version = -1;
+/* b/163963220: Cache ADC value before board_hibernate_late() reads it */
+static void board_version_init(void)
+{
version = adc_value_to_numeric_id(ADC_BOARD_ID_0);
if (version < 0) {
ccprints("WARNING: failed to read ADC_BOARD_ID_0");
@@ -99,6 +98,10 @@ int board_get_version(void)
version = 0;
}
+}
+DECLARE_HOOK(HOOK_INIT, board_version_init, HOOK_PRIO_INIT_ADC + 1);
+int board_get_version(void)
+{
return version;
}