diff options
author | Nick Sanders <nsanders@chromium.org> | 2017-10-13 18:34:48 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2018-01-23 21:29:16 +0000 |
commit | fb95f61fc55708caee94e3882285033a39808b31 (patch) | |
tree | f511bf2a195723eb657d0e3b377aff00c33fc7e4 | |
parent | 4a47178dd9f5b4d1d3469ef68a3f0a95a1c609fc (diff) | |
download | chrome-ec-fb95f61fc55708caee94e3882285033a39808b31.tar.gz |
servo_v4: fix board version GPIO access
Ensure GPIOs are inputs when read: Initialize GPIO direction on startup,
and clean up register accesses using reg names rather than magic numbers.
Add board version reporting with CONFIG_BOARD_SPECIFIC_VERSION.
BUG=None
BRANCH=servo
TEST=version is correctly 3
Signed-off-by: Nick Sanders <nsanders@chromium.org>
Change-Id: Ia04b01932fc36540af64b48b5e0bb6516f1529e2
Reviewed-on: https://chromium-review.googlesource.com/749693
Reviewed-by: Shawn N <shawnn@chromium.org>
(cherry picked from commit 5ed0c143b3cf8094640615971c9d09afa19c117f)
Reviewed-on: https://chromium-review.googlesource.com/736994
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
-rw-r--r-- | board/servo_v4/board.c | 39 | ||||
-rw-r--r-- | board/servo_v4/board.h | 2 |
2 files changed, 26 insertions, 15 deletions
diff --git a/board/servo_v4/board.c b/board/servo_v4/board.c index 4b77a4ba15..10ab28bbbc 100644 --- a/board/servo_v4/board.c +++ b/board/servo_v4/board.c @@ -213,23 +213,31 @@ const int num_rw_sections = ARRAY_SIZE(board_rw_sections); * Initialize board. */ +/* + * Support tca6416 I2C ioexpander. + */ +#define GPIOX_I2C_ADDR 0x40 +#define GPIOX_IN_PORT_A 0x0 +#define GPIOX_IN_PORT_B 0x1 +#define GPIOX_OUT_PORT_A 0x2 +#define GPIOX_OUT_PORT_B 0x3 +#define GPIOX_DIR_PORT_A 0x6 +#define GPIOX_DIR_PORT_B 0x7 + + /* Write a GPIO output on the tca6416 I2C ioexpander. */ static void write_ioexpander(int bank, int gpio, int val) { int tmp; /* Read output port register */ - i2c_read8(1, 0x40, 0x2 + bank, &tmp); + i2c_read8(1, GPIOX_I2C_ADDR, GPIOX_OUT_PORT_A + bank, &tmp); if (val) tmp |= (1 << gpio); else tmp &= ~(1 << gpio); /* Write back modified output port register */ - i2c_write8(1, 0x40, 0x2 + bank, tmp); - - /* Set Configuration port to output/0 */ - i2c_read8(1, 0x40, 0x6 + bank, &tmp); - i2c_write8(1, 0x40, 0x6 + bank, tmp & ~(1 << gpio)); + i2c_write8(1, GPIOX_I2C_ADDR, GPIOX_OUT_PORT_A + bank, tmp); } /* Read a single GPIO input on the tca6416 I2C ioexpander. */ @@ -238,11 +246,8 @@ 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); + i2c_read8(1, GPIOX_I2C_ADDR, GPIOX_IN_PORT_A + bank, &tmp); return (tmp & mask) >> bit; } @@ -271,11 +276,15 @@ static void init_usb3_port(void) static void init_ioexpander(void) { /* Write all GPIO to output 0 */ - i2c_write8(1, 0x40, 0x2, 0x0); - i2c_write8(1, 0x40, 0x3, 0x0); - /* Write all GPIO to output direction */ - i2c_write8(1, 0x40, 0x6, 0x0); - i2c_write8(1, 0x40, 0x7, 0x0); + i2c_write8(1, GPIOX_I2C_ADDR, GPIOX_OUT_PORT_A, 0x0); + i2c_write8(1, GPIOX_I2C_ADDR, GPIOX_OUT_PORT_B, 0x0); + + /* + * Write GPIO direction: strap resistors to input, + * all others to output. + */ + i2c_write8(1, GPIOX_I2C_ADDR, GPIOX_DIR_PORT_A, 0x0); + i2c_write8(1, GPIOX_I2C_ADDR, GPIOX_DIR_PORT_B, 0x18); } /* Define voltage thresholds for SBU USB detection */ diff --git a/board/servo_v4/board.h b/board/servo_v4/board.h index eae492e9a6..8bbf1bed43 100644 --- a/board/servo_v4/board.h +++ b/board/servo_v4/board.h @@ -15,6 +15,8 @@ * id from previous versions. */ #define BOARD_VERSION_BLACK 3 +#define CONFIG_BOARD_VERSION +#define CONFIG_BOARD_SPECIFIC_VERSION /* 48 MHz SYSCLK clock frequency */ #define CPU_CLOCK 48000000 |