summaryrefslogtreecommitdiff
path: root/baseboard/grunt
diff options
context:
space:
mode:
authorEdward Hill <ecgh@chromium.org>2018-10-26 09:00:39 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-10-28 13:54:11 -0700
commite5e282e43718b7acd706a717dc0fa9a821505dfd (patch)
treedf5101f52e064b96d2bccf5fb0ad1e5f0860168f /baseboard/grunt
parent8095c8c9cc84187ba938473930fefa872a67bc24 (diff)
downloadchrome-ec-e5e282e43718b7acd706a717dc0fa9a821505dfd.tar.gz
delan: Use CBI EEPROM for board version and SKU ID
Use board version and SKU ID from CBI EEPROM on Delan if the SKU ID set via resistors + ADC is not valid. BUG=b:76018320 BRANCH=grunt TEST=Read CBI values from EEPROM Change-Id: Ie37336934bd6687e46ad6ae62bc1b2e12355c83c Signed-off-by: Edward Hill <ecgh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1301933 Reviewed-by: Jonathan Brandmeyer <jbrandmeyer@chromium.org>
Diffstat (limited to 'baseboard/grunt')
-rw-r--r--baseboard/grunt/baseboard.c58
-rw-r--r--baseboard/grunt/baseboard.h4
2 files changed, 55 insertions, 7 deletions
diff --git a/baseboard/grunt/baseboard.c b/baseboard/grunt/baseboard.c
index 8243106a0a..740f2442da 100644
--- a/baseboard/grunt/baseboard.c
+++ b/baseboard/grunt/baseboard.c
@@ -14,6 +14,7 @@
#include "common.h"
#include "compile_time_macros.h"
#include "console.h"
+#include "cros_board_info.h"
#include "driver/accel_kionix.h"
#include "driver/accel_kx022.h"
#include "driver/accelgyro_bmi160.h"
@@ -474,24 +475,69 @@ static int board_read_sku_adc(enum adc_channel chan)
return -1;
}
-uint32_t system_get_sku_id(void)
+static uint32_t board_get_adc_sku_id(void)
{
- static uint32_t sku_id = -1;
int sku_id1, sku_id2;
- if (sku_id != -1)
- return sku_id;
-
sku_id1 = board_read_sku_adc(ADC_SKU_ID1);
sku_id2 = board_read_sku_adc(ADC_SKU_ID2);
if (sku_id1 < 0 || sku_id2 < 0)
return 0;
- sku_id = (sku_id2 << 4) | sku_id1;
+ return (sku_id2 << 4) | sku_id1;
+}
+
+static int board_get_gpio_board_version(void)
+{
+ return
+ (!!gpio_get_level(GPIO_BOARD_VERSION1) << 0) |
+ (!!gpio_get_level(GPIO_BOARD_VERSION2) << 1) |
+ (!!gpio_get_level(GPIO_BOARD_VERSION3) << 2);
+}
+
+static int board_version;
+static uint32_t sku_id;
+
+static void cbi_init(void)
+{
+ board_version = board_get_gpio_board_version();
+ sku_id = board_get_adc_sku_id();
+
+ /*
+ * Use board version and SKU ID from CBI EEPROM if the board supports
+ * it and the SKU ID set via resistors + ADC is not valid.
+ */
+#ifdef CONFIG_CROS_BOARD_INFO
+ if (sku_id == 0 || sku_id == 0xff) {
+ uint32_t val;
+
+ if (cbi_get_board_version(&val) == EC_SUCCESS)
+ board_version = val;
+ if (cbi_get_sku_id(&val) == EC_SUCCESS)
+ sku_id = val;
+ }
+#endif
+
+ ccprints("Board Version: %d (0x%x)", board_version, board_version);
+ ccprints("SKU: %d (0x%x)", sku_id, sku_id);
+}
+/*
+ * Reading the SKU resistors requires the ADC module. If we are using EEPROM
+ * then we also need the I2C module, but that is available before ADC.
+ */
+DECLARE_HOOK(HOOK_INIT, cbi_init, HOOK_PRIO_INIT_ADC + 1);
+
+uint32_t system_get_sku_id(void)
+{
return sku_id;
}
+int board_get_version(void)
+{
+ return board_version;
+}
+
/*
* Returns 1 for boards that are convertible into tablet mode, and zero for
* clamshells.
diff --git a/baseboard/grunt/baseboard.h b/baseboard/grunt/baseboard.h
index 1c0f8ed001..f0df8796ff 100644
--- a/baseboard/grunt/baseboard.h
+++ b/baseboard/grunt/baseboard.h
@@ -29,7 +29,7 @@
#define CONFIG_ADC
#define CONFIG_BACKLIGHT_LID
#define CONFIG_BACKLIGHT_LID_ACTIVE_LOW
-#define CONFIG_BOARD_VERSION_GPIO
+#define CONFIG_BOARD_VERSION_CUSTOM
#define CONFIG_EC_FEATURE_BOARD_OVERRIDE
#define CONFIG_HIBERNATE_PSL
#define CONFIG_HOSTCMD_LPC
@@ -244,6 +244,8 @@ void board_reset_pd_mcu(void);
/* Common definition for the USB PD interrupt handlers. */
void tcpc_alert_event(enum gpio_signal signal);
+int board_get_version(void);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BASEBOARD_H */