From 638274bd2c6a6be9dcdc010327f290afe443912a Mon Sep 17 00:00:00 2001 From: Rong Chang Date: Sun, 17 Jun 2012 13:43:15 +0800 Subject: [PATCH] Enable daisy I2C host auto detection This change is a temperary hack. And it should be reverted after finalize daisy board design. The host port on daisy can be configured as I2C1 or I2C2. PMU is connected directly to the host port, hence the host port can be detected. This change unifies ec firmware image for different I2C configurations. Signed-off-by: Rong Chang BUG=chrome-os-partner:10612 TEST=manual Build daisy ec firmware. Flash it to daisy boards with different I2C port config. Check uart console commands: 'i2c r 0x90 4' - single byte pmu read 'battery' - double bytes battery read Change-Id: I70f66581d0e921c83bc2051b2a521b332e18aa50 Reviewed-on: https://gerrit.chromium.org/gerrit/25502 Reviewed-by: Vincent Palatin Reviewed-by: Mark Hayter Reviewed-by: Simon Glass Commit-Ready: Rong Chang Tested-by: Rong Chang --- board/daisy/board.c | 41 +++++++++++++++++++++++++++++++++++++++++ board/daisy/board.h | 6 +++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/board/daisy/board.c b/board/daisy/board.c index 1d5a57e66c..fa15b04ebe 100644 --- a/board/daisy/board.c +++ b/board/daisy/board.c @@ -7,6 +7,7 @@ #include "board.h" #include "common.h" #include "dma.h" +#include "i2c.h" #include "gpio.h" #include "registers.h" #include "spi.h" @@ -82,6 +83,46 @@ const struct gpio_info gpio_list[GPIO_COUNT] = { {"KB_OUT12", GPIO_C, (1<<7), GPIO_KB_OUTPUT, NULL}, }; +/* Auto detect I2C host port + * Daisy board has two I2C ports, I2C1(0) and I2C2(1), that can be configured + * as host. PMU chip is connected directly to the EC, and hence can be used + * for port detection + */ +#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) { dma_init(); diff --git a/board/daisy/board.h b/board/daisy/board.h index e85e0b2dc3..542a2fa967 100644 --- a/board/daisy/board.h +++ b/board/daisy/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 @@ -94,4 +95,7 @@ void board_keyboard_suppress_noise(void); /* 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 */