summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2012-06-22 20:41:02 +0000
committerVincent Palatin <vpalatin@chromium.org>2012-06-22 14:36:18 -0700
commit20e46cfbd5770eff6f78cb4a76b16f0927d2feb1 (patch)
tree2ea0f17fe695435f0314c69ee29e1d8acd7af71f
parentd35f8165fe58c5bb68ab53a47edd8f98bdec0317 (diff)
downloadchrome-ec-20e46cfbd5770eff6f78cb4a76b16f0927d2feb1.tar.gz
stm32: don't try to use the AP I2C connection when the CPU is running
If the EC shares the I2C-2 bus with the battery and the charger, we don't want to be a master on that bus when the AP is ON and can send us I2C messages. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> (cherry picked from commit 2a7de5168d93339ff80d81b08dd7b0246bf3ac17) BUG=none TEST=on Lucas DVT, check we can read battery info when AP is OFF and we cannot when AP is ON. Change-Id: I766c66e54709a18c81ebd4d9f75e8e4f97d3184b Reviewed-on: https://gerrit.chromium.org/gerrit/25964 Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Katie Roberts-Hoffman <katierh@chromium.org>
-rw-r--r--board/daisy/board.h1
-rw-r--r--board/snow/board.h1
-rw-r--r--chip/stm32/i2c.c14
3 files changed, 15 insertions, 1 deletions
diff --git a/board/daisy/board.h b/board/daisy/board.h
index fe0a708620..3c88816f69 100644
--- a/board/daisy/board.h
+++ b/board/daisy/board.h
@@ -39,6 +39,7 @@
#define I2C_PORT_HOST board_i2c_host_port()
#define I2C_PORT_BATTERY I2C_PORT_HOST
#define I2C_PORT_CHARGER I2C_PORT_HOST
+#define I2C_PORT_SLAVE 1
/* GPIO signal list */
enum gpio_signal {
diff --git a/board/snow/board.h b/board/snow/board.h
index 8c20201ccf..adf9fd426b 100644
--- a/board/snow/board.h
+++ b/board/snow/board.h
@@ -42,6 +42,7 @@
#define I2C_PORT_HOST board_i2c_host_port()
#define I2C_PORT_BATTERY I2C_PORT_HOST
#define I2C_PORT_CHARGER I2C_PORT_HOST
+#define I2C_PORT_SLAVE 1
/* GPIO signal list */
enum gpio_signal {
diff --git a/chip/stm32/i2c.c b/chip/stm32/i2c.c
index c3fe00af2b..1a4546800a 100644
--- a/chip/stm32/i2c.c
+++ b/chip/stm32/i2c.c
@@ -4,6 +4,7 @@
*/
#include "board.h"
+#include "chipset.h"
#include "common.h"
#include "console.h"
#include "ec_commands.h"
@@ -379,6 +380,10 @@ static void handle_i2c_error(int port, int rv)
timestamp_t t1, t2;
uint32_t r;
+ /* we have not used the bus, just exit */
+ if (rv == EC_ERROR_BUSY)
+ return;
+
if (rv)
dump_i2c_reg(port);
@@ -407,6 +412,10 @@ static int i2c_master_transmit(int port, int slave_addr, uint8_t *data,
{
int rv, i;
+ /* if the AP is ON, don't play with the connection */
+ if ((port == I2C_PORT_SLAVE) && chipset_in_state(CHIPSET_STATE_ON))
+ return EC_ERROR_BUSY;
+
disable_ack(port);
rv = master_start(port, slave_addr);
if (rv)
@@ -447,6 +456,10 @@ static int i2c_master_receive(int port, int slave_addr, uint8_t *data,
*/
int rv, i;
+ /* if the AP is ON, don't play with the connection */
+ if ((port == I2C_PORT_SLAVE) && chipset_in_state(CHIPSET_STATE_ON))
+ return EC_ERROR_BUSY;
+
if (data == NULL || size < 1)
return EC_ERROR_INVAL;
@@ -701,4 +714,3 @@ DECLARE_CONSOLE_COMMAND(i2c, command_i2c,
NULL);
#endif /* I2C_PORT_HOST */
-