summaryrefslogtreecommitdiff
path: root/common/system.c
diff options
context:
space:
mode:
authorPhilip Chen <philipchen@google.com>2021-07-02 16:47:58 -0700
committerCommit Bot <commit-bot@chromium.org>2021-07-09 21:10:26 +0000
commit2c37de83e78e98820ce2a7473932afdec029d2a6 (patch)
treec4c43bcced79adabb1cf6b785633f122b64e8329 /common/system.c
parent107738848df07a66ae4d7c5af8f73a98ca555224 (diff)
downloadchrome-ec-2c37de83e78e98820ce2a7473932afdec029d2a6.tar.gz
system: Clean up system_get_board_version()
Refactor system_get_board_version() a bit so that we can remove CONFIG_BOARD_VERSION_CUSTOM and CONFIG_BOARD_VERSION from config.h. BRANCH=None BUG=b:186264627 TEST=make buildall -j TEST=zmake testall Cq-Depend: chromium:3015243 Change-Id: Id5ab809493c297b7d330ea13dcd6934ec00042a6 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3004112 Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'common/system.c')
-rw-r--r--common/system.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/common/system.c b/common/system.c
index 1648bbe465..d01253fdaf 100644
--- a/common/system.c
+++ b/common/system.c
@@ -813,31 +813,40 @@ int system_get_image_used(enum ec_image copy)
}
/*
+ * Overwrite it in board directory in case that we want to read board version
+ * in our own way.
+ */
+__overridable int board_get_version(void)
+{
+#ifdef CONFIG_BOARD_VERSION_GPIO
+ return (!!gpio_get_level(GPIO_BOARD_VERSION1) << 0) |
+ (!!gpio_get_level(GPIO_BOARD_VERSION2) << 1) |
+ (!!gpio_get_level(GPIO_BOARD_VERSION3) << 2);
+#else
+ return 0;
+#endif
+}
+
+/*
* Returns positive board version if successfully retrieved. Otherwise the
* value is a negative version of an EC return code. Without this optimization
* multiple boards run out of flash size.
*/
int system_get_board_version(void)
{
-#if defined(CONFIG_BOARD_VERSION_CUSTOM)
+ int board_id;
+
+ if (IS_ENABLED(CONFIG_BOARD_VERSION_CBI)) {
+ int error;
+
+ error = cbi_get_board_version(&board_id);
+ if (error)
+ return -error;
+
+ return board_id;
+ };
+
return board_get_version();
-#elif defined(CONFIG_BOARD_VERSION_GPIO)
- return
- (!!gpio_get_level(GPIO_BOARD_VERSION1) << 0) |
- (!!gpio_get_level(GPIO_BOARD_VERSION2) << 1) |
- (!!gpio_get_level(GPIO_BOARD_VERSION3) << 2);
-#elif defined(CONFIG_BOARD_VERSION_CBI)
- int error;
- int32_t version;
-
- error = cbi_get_board_version(&version);
- if (error)
- return -error;
- else
- return version;
-#else
- return 0;
-#endif
}
__attribute__((weak)) /* Weird chips may need their own implementations */
@@ -1604,7 +1613,7 @@ DECLARE_HOST_COMMAND(EC_CMD_GET_CHIP_INFO,
host_command_get_chip_info,
EC_VER_MASK(0));
-#ifdef CONFIG_BOARD_VERSION
+#if defined(CONFIG_BOARD_VERSION_CBI) || defined(CONFIG_BOARD_VERSION_GPIO)
enum ec_status
host_command_get_board_version(struct host_cmd_handler_args *args)
{