summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorDuncan Laurie <dlaurie@chromium.org>2016-12-12 09:59:59 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-12-13 11:50:53 -0800
commitaff701c5743b0200a0f24cc606ab8a87d41e9bd8 (patch)
tree7bfb4d0fde33be6b31d1b00d702abe97b3d9da7d /board
parentfffc34706d2ce60678d0e3ef203d4639e18f7d39 (diff)
downloadchrome-ec-aff701c5743b0200a0f24cc606ab8a87d41e9bd8.tar.gz
eve: Use ternary encoding for board version
The Eve board version will use Hi-Z to get 3 values out of each bit in the version. In order to support this read each strap and determine the ternary encoding. BUG=chrome-os-partner:58666 BRANCH=none TEST=ensure P0 reports 0 and P1 reports 1, test with an unused GPIO to ensure that a tristate pin will also be read properly. Change-Id: Ib1f569e2b06bed0995eb70f24c90533cbccb0fb8 Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/418978 Reviewed-by: Scott Collyer <scollyer@chromium.org>
Diffstat (limited to 'board')
-rw-r--r--board/eve/board.c44
-rw-r--r--board/eve/board.h2
2 files changed, 46 insertions, 0 deletions
diff --git a/board/eve/board.c b/board/eve/board.c
index 95196dee43..5598c9aaad 100644
--- a/board/eve/board.c
+++ b/board/eve/board.c
@@ -590,6 +590,50 @@ void board_hibernate(void)
bd9995x_set_power_save_mode(BD9995X_PWR_SAVE_MAX);
}
+static int gpio_get_ternary(enum gpio_signal gpio)
+{
+ int pd, pu;
+ int flags = gpio_get_default_flags(gpio);
+
+ /* Read GPIO with internal pull-down */
+ gpio_set_flags(gpio, GPIO_INPUT | GPIO_PULL_DOWN);
+ pd = gpio_get_level(gpio);
+ usleep(100);
+
+ /* Read GPIO with internal pull-up */
+ gpio_set_flags(gpio, GPIO_INPUT | GPIO_PULL_UP);
+ pu = gpio_get_level(gpio);
+ usleep(100);
+
+ /* Reset GPIO flags */
+ gpio_set_flags(gpio, flags);
+
+ /* Check PU and PD readings to determine tristate */
+ return pu && !pd ? 2 : pd;
+}
+
+int board_get_version(void)
+{
+ static int ver;
+
+ if (!ver) {
+ /*
+ * Read the board EC ID on the tristate strappings
+ * using ternary encoding: 0 = 0, 1 = 1, Hi-Z = 2
+ */
+ uint8_t id0, id1, id2;
+
+ id0 = gpio_get_ternary(GPIO_BOARD_VERSION1);
+ id1 = gpio_get_ternary(GPIO_BOARD_VERSION2);
+ id2 = gpio_get_ternary(GPIO_BOARD_VERSION3);
+
+ ver = (id2 * 9) + (id1 * 3) + id0;
+ CPRINTS("Board ID = %d", ver);
+ }
+
+ return ver;
+}
+
/* Base Sensor mutex */
static struct mutex g_base_mutex;
diff --git a/board/eve/board.h b/board/eve/board.h
index e6318cc7bf..2e6235064d 100644
--- a/board/eve/board.h
+++ b/board/eve/board.h
@@ -18,6 +18,7 @@
#define CONFIG_ADC
#define CONFIG_BOARD_HAS_BEFORE_RSMRST
#define CONFIG_BOARD_VERSION
+#define CONFIG_BOARD_SPECIFIC_VERSION
#define CONFIG_BUTTON_COUNT 2
#define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL
#define CONFIG_DPTF
@@ -241,6 +242,7 @@ enum adc_channel {
#define PD_MAX_VOLTAGE_MV 20000
/* Board specific handlers */
+int board_get_version(void);
void board_reset_pd_mcu(void);
void board_set_tcpc_power_mode(int port, int mode);
void board_print_tcpc_fw_version(int port);