diff options
author | Rong Chang <rongchang@chromium.org> | 2012-06-20 19:21:41 +0800 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-06-20 07:12:18 -0700 |
commit | 024c44cd96bf97e81d4d3af45a0f0cb0ef1425a0 (patch) | |
tree | ad833b91e09318385790f8b2145794c9fbb74e4f | |
parent | bffc0fd3a2c098911a0af206d2e3c1441a6b37be (diff) | |
download | chrome-ec-024c44cd96bf97e81d4d3af45a0f0cb0ef1425a0.tar.gz |
Enable snow I2C host auto detection
This change is picked from daisy change:
I70f66581d0e921c83bc2051b2a521b332e18aa50
It should be reverted after rework all dev boards to new I2C config.
Issue filed against this hack: http://crosbug.com/p/10622
Signed-off-by: Rong Chang <rongchang@chromium.org>
BUG=chrome-os-partner:10622
TEST=manual
Console commands:
'i2c r 0x90 4' - single byte pmu read
'battery' - double bytes battery read
Change-Id: I3185d872dc5ef6673fcd7efddf8394fe73f11813
Reviewed-on: https://gerrit.chromium.org/gerrit/25743
Commit-Ready: Rong Chang <rongchang@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
Reviewed-by: Vic Yang <victoryang@chromium.org>
-rw-r--r-- | board/snow/board.c | 36 | ||||
-rw-r--r-- | board/snow/board.h | 6 |
2 files changed, 41 insertions, 1 deletions
diff --git a/board/snow/board.c b/board/snow/board.c index 0d10bbc6d3..eb02ce5878 100644 --- a/board/snow/board.c +++ b/board/snow/board.c @@ -8,6 +8,7 @@ #include "common.h" #include "dma.h" #include "gpio.h" +#include "i2c.h" #include "registers.h" #include "spi.h" #include "util.h" @@ -68,6 +69,41 @@ const struct gpio_info gpio_list[GPIO_COUNT] = { {"KB_OUT12", GPIO_C, (1<<7), GPIO_KB_OUTPUT, NULL}, }; +#ifdef CONFIG_I2C_HOST_AUTO +static int i2c_host_port = -1; + +/* Detect if tps65090 pmu is present on a i2c bus. + * This hack makes one single ec binary to work on boards with different + * stuffing options. + * + * TODO: Revert i2c host port detection after all dev boards been reworked or + * deprecated. Issue: http://crosbug.com/p/10622 + */ +static int tps65090_is_present(int bus) +{ + const int tps65090_addr = 0x90; + const int charger_ctrl_offset0 = 4; + int rv, reg; + + rv = i2c_read8(bus, tps65090_addr, charger_ctrl_offset0, ®); + + if (rv == EC_SUCCESS) + return 1; + return 0; +} + +int board_i2c_host_port(void) +{ + /* Default I2C host configuration is I2C1(0). + * If PMU doesn't ack on I2C2(1), set the host port to 0. + */ + if (i2c_host_port == -1) + i2c_host_port = tps65090_is_present(1) ? 1 : 0; + + return i2c_host_port; +} +#endif /* CONFIG_I2C_HOST_AUTO */ + void configure_board(void) { uint32_t val; diff --git a/board/snow/board.h b/board/snow/board.h index 0db8aebfec..a9c793a17c 100644 --- a/board/snow/board.h +++ b/board/snow/board.h @@ -35,7 +35,8 @@ /* Charging */ #define CONFIG_SMART_BATTERY #define CONFIG_PMU_TPS65090 -#define I2C_PORT_HOST 1 +#define CONFIG_I2C_HOST_AUTO +#define I2C_PORT_HOST board_i2c_host_port() #define I2C_PORT_BATTERY I2C_PORT_HOST #define I2C_PORT_CHARGER I2C_PORT_HOST @@ -91,4 +92,7 @@ void matrix_interrupt(enum gpio_signal signal); /* Signal to AP that data is waiting */ void board_interrupt_host(int active); +/* Auto detect EC i2c host port */ +int board_i2c_host_port(void); + #endif /* __BOARD_H */ |