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 <rongchang@chromium.org>
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 <vpalatin@chromium.org>
Reviewed-by: Mark Hayter <mdhayter@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Ready: Rong Chang <rongchang@chromium.org>
Tested-by: Rong Chang <rongchang@chromium.org>
This commit is contained in:
Rong Chang
2012-06-17 13:43:15 +08:00
committed by Gerrit
parent 0aa39fc1e6
commit 638274bd2c
2 changed files with 46 additions and 1 deletions

View File

@@ -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, &reg);
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();

View File

@@ -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 */