summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRong Chang <rongchang@chromium.org>2012-06-17 13:43:15 +0800
committerGerrit <chrome-bot@google.com>2012-06-19 01:26:29 -0700
commit638274bd2c6a6be9dcdc010327f290afe443912a (patch)
tree960bd0e45de1926f92be9ccb846c64e7acc5ceca
parent0aa39fc1e63cd52ecb006d7f33f2c8f29d87da12 (diff)
downloadchrome-ec-638274bd2c6a6be9dcdc010327f290afe443912a.tar.gz
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>
-rw-r--r--board/daisy/board.c41
-rw-r--r--board/daisy/board.h6
2 files changed, 46 insertions, 1 deletions
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, &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();
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 */