diff --git a/board/poppy/board.c b/board/poppy/board.c index d6f526d3b8..a8f374f2ec 100644 --- a/board/poppy/board.c +++ b/board/poppy/board.c @@ -705,6 +705,36 @@ void board_hibernate(void) ; } +int board_get_version(void) +{ + static int ver = -1; + uint8_t id4; + + if (ver != -1) + return ver; + + ver = 0; + + /* First 3 strappings are binary. */ + if (gpio_get_level(GPIO_BOARD_VERSION1)) + ver |= 0x01; + if (gpio_get_level(GPIO_BOARD_VERSION2)) + ver |= 0x02; + if (gpio_get_level(GPIO_BOARD_VERSION3)) + ver |= 0x04; + + /* + * 4th bit is using tristate strapping, ternary encoding: + * Hi-Z (id4=2) => 0, (id4=0) => 1, (id4=1) => 2 + */ + id4 = gpio_get_ternary(GPIO_BOARD_VERSION4); + ver |= ((id4 + 1) % 3) * 0x08; + + CPRINTS("Board ID = %d", ver); + + return ver; +} + /* Lid Sensor mutex */ static struct mutex g_lid_mutex; diff --git a/board/poppy/board.h b/board/poppy/board.h index 587b35f9c1..69e3d9cb65 100644 --- a/board/poppy/board.h +++ b/board/poppy/board.h @@ -25,6 +25,7 @@ /* EC */ #define CONFIG_ADC #define CONFIG_BOARD_VERSION +#define CONFIG_BOARD_SPECIFIC_VERSION #define CONFIG_BUTTON_COUNT 2 #define CONFIG_BUTTON_RECOVERY #define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL diff --git a/board/poppy/gpio.inc b/board/poppy/gpio.inc index fb8aed6b77..82b89ead32 100644 --- a/board/poppy/gpio.inc +++ b/board/poppy/gpio.inc @@ -115,6 +115,7 @@ GPIO(LED_WHITE_C1, PIN(3, 0), GPIO_OUT_LOW) GPIO(BOARD_VERSION1, PIN(C, 4), GPIO_INPUT) /* Board ID bit0 */ GPIO(BOARD_VERSION2, PIN(C, 2), GPIO_INPUT) /* Board ID bit1 */ GPIO(BOARD_VERSION3, PIN(1, 3), GPIO_INPUT) /* Board ID bit2 */ +GPIO(BOARD_VERSION4, PIN(1, 7), GPIO_INPUT) /* Board ID strap 3 (ternary) */ /* Alternate functions GPIO definitions */ ALTERNATE(PIN_MASK(6, 0x30), 1, MODULE_UART, 0) /* GPIO64-65 */ /* UART from EC to Servo */