From f21a0681c78e67ccc11f350dc3a455360fc765fb Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Thu, 10 May 2018 11:55:48 -0700 Subject: Nami: Read CBI early and cache it This patch adds a HOOK_INIT handler which reads CBI. This handler runs as early as I2C controller is ready so that all subsequent code can refer to cached CBI. Signed-off-by: Daisuke Nojiri BUG=none BRANCH=none TEST=Verify CBI is read reliably on Nami at boot. Change-Id: I979947d6bd63ce0cdc1400ba561c543d9ed7b40e Reviewed-on: https://chromium-review.googlesource.com/1054341 Commit-Ready: Daisuke Nojiri Tested-by: Daisuke Nojiri Reviewed-by: Aaron Durbin --- board/nami/board.c | 27 +++++++++++++++++++-------- board/nami/board.h | 1 + 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/board/nami/board.c b/board/nami/board.c index 53e4575de3..af3a4d36f3 100644 --- a/board/nami/board.c +++ b/board/nami/board.c @@ -65,7 +65,9 @@ #define USB_PD_PORT_PS8751 0 #define USB_PD_PORT_ANX7447 1 -static uint32_t oem = PROJECT_NAMI; +static uint16_t board_version; +static uint8_t oem = PROJECT_NAMI; +static uint16_t sku; static void tcpc_alert_event(enum gpio_signal signal) { @@ -663,17 +665,26 @@ static void board_chipset_suspend(void) } DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); -/* Initialize board. */ -static void board_init(void) +static void cbi_init(void) { - uint32_t version; + uint32_t val; + + if (cbi_get_board_version(&val) == EC_SUCCESS && val <= UINT16_MAX) + board_version = val; + CPRINTS("Board Version: 0x%04x", board_version); - if (cbi_get_board_version(&version) == EC_SUCCESS) - CPRINTS("Board Version: 0x%04x", version); + if (cbi_get_oem_id(&val) == EC_SUCCESS && val < PROJECT_COUNT) + oem = val; + CPRINTS("OEM: %d", oem); - if (cbi_get_oem_id(&oem)) - CPRINTS("OEM: 0x%x", oem); + if (cbi_get_sku_id(&val) == EC_SUCCESS && val <= UINT16_MAX) + sku = val; + CPRINTS("SKU: 0x%04x", sku); +} +DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_INIT_I2C + 1); +static void board_init(void) +{ /* * This enables pull-down on F_DIO1 (SPI MISO), and F_DIO0 (SPI MOSI), * whenever the EC is not doing SPI flash transactions. This avoids diff --git a/board/nami/board.h b/board/nami/board.h index 8b9d4b33f1..a292e32372 100644 --- a/board/nami/board.h +++ b/board/nami/board.h @@ -266,6 +266,7 @@ enum oem_id { PROJECT_SONA, PROJECT_PANTHEON, PROJECT_NAMI, + PROJECT_COUNT, }; /* TODO(crosbug.com/p/61098): Verify the numbers below. */ -- cgit v1.2.1