diff options
-rw-r--r-- | board/servo_v4/board.c | 41 | ||||
-rw-r--r-- | board/servo_v4/board.h | 15 |
2 files changed, 56 insertions, 0 deletions
diff --git a/board/servo_v4/board.c b/board/servo_v4/board.c index ce2a647bb8..5559b09f68 100644 --- a/board/servo_v4/board.c +++ b/board/servo_v4/board.c @@ -24,6 +24,7 @@ #include "usart_rx_dma.h" #include "usb_gpio.h" #include "usb_i2c.h" +#include "usb_pd.h" #include "usb_spi.h" #include "usb-stream.h" #include "util.h" @@ -261,6 +262,21 @@ static void write_ioexpander(int bank, int gpio, int val) i2c_write8(1, 0x40, 0x6 + bank, tmp & ~(1 << gpio)); } +/* Read a single GPIO input on the tca6416 I2C ioexpander. */ +static int read_ioexpander_bit(int bank, int bit) +{ + int tmp; + int mask = 1 << bit; + + /* Configure GPIO for this bit as an input */ + i2c_read8(1, 0x40, 0x6 + bank, &tmp); + i2c_write8(1, 0x40, 0x6 + bank, tmp | mask); + /* Read input port register */ + i2c_read8(1, 0x40, bank, &tmp); + + return (tmp & mask) >> bit; +} + /* Enable uservo USB. */ static void init_uservo_port(void) { @@ -335,6 +351,23 @@ void ccd_set_mode(enum ccd_mode new_mode) } } +int board_get_version(void) +{ + static int ver = -1; + + if (ver < 0) { + uint8_t id0, id1; + + id0 = read_ioexpander_bit(1, 3); + id1 = read_ioexpander_bit(1, 4); + + ver = (id1 * 2) + id0; + CPRINTS("Board ID = %d", ver); + } + + return ver; +} + static void board_init(void) { /* USB to serial queues */ @@ -364,5 +397,13 @@ static void board_init(void) * console will survie a DUT EC reset. */ gpio_set_level(GPIO_SBU_MUX_EN, 1); + + /* + * Set the USB PD max voltage to value appropriate for the board + * version. The red/blue versions of servo_v4 have an ESD between VBUS + * and CC1/CC2 that has a breakdown voltage of 11V. + */ + pd_set_max_voltage(board_get_version() >= BOARD_VERSION_BLACK ? + PD_MAX_VOLTAGE_MV : 9000); } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); diff --git a/board/servo_v4/board.h b/board/servo_v4/board.h index 629e19b38e..b909c72c50 100644 --- a/board/servo_v4/board.h +++ b/board/servo_v4/board.h @@ -8,6 +8,14 @@ #ifndef __CROS_EC_BOARD_H #define __CROS_EC_BOARD_H +/* + * Board Versions: + * Versions are designated by the PCB color and consist of red, blue, and + * black. Only the black version has pullup resistors to distinguish its board + * id from previous versions. + */ +#define BOARD_VERSION_BLACK 3 + /* 48 MHz SYSCLK clock frequency */ #define CPU_CLOCK 48000000 @@ -194,5 +202,12 @@ int pd_tcpc_cc_ra(int port, int cc_volt, int cc_sel); */ int pd_set_rp_rd(int port, int cc_pull, int rp_value); +/** + * Get board HW ID version + * + * @return HW ID version + */ +int board_get_version(void); + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ |