diff options
Diffstat (limited to 'common/system.c')
-rw-r--r-- | common/system.c | 47 |
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) { |