summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2018-03-09 17:03:46 -0800
committerchrome-bot <chrome-bot@chromium.org>2018-03-21 20:48:36 -0700
commite513b7339ad66c30fa9cee626e478d06a714e42c (patch)
tree43cb2db9c6e7b52ae7230cc56f7c4b29d345a36b
parent9aee2a19e81949eca86eb0b113c99d1782eaa2d2 (diff)
downloadchrome-ec-e513b7339ad66c30fa9cee626e478d06a714e42c.tar.gz
nautilus: Use I2C callbacks to ensure minimum bus free time for battery
Battery on nautilus requires a minimum bus free time of 5ms between I2C transactions. Use I2C_XFER_CALLBACK mechanism to ensure that this time is guaranteed before starting a new i2c transaction. BUG=b:73147310 BRANCH=None TEST=make -j BOARD=nautilus. Verified on nautilus that no issue is observed while charging the battery. Change-Id: Ieba168835190b5d1334e413dc4f74e0248bf5a15 Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://chromium-review.googlesource.com/957966 Commit-Ready: Furquan Shaikh <furquan@chromium.org> Tested-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r--board/nautilus/board.c35
-rw-r--r--board/nautilus/board.h1
2 files changed, 36 insertions, 0 deletions
diff --git a/board/nautilus/board.c b/board/nautilus/board.c
index 215f0213a8..ff9ad80944 100644
--- a/board/nautilus/board.c
+++ b/board/nautilus/board.c
@@ -9,6 +9,7 @@
#include "adc_chip.h"
#include "bd99992gw.h"
#include "board_config.h"
+#include "battery_smart.h"
#include "button.h"
#include "charge_manager.h"
#include "charge_state.h"
@@ -733,3 +734,37 @@ int board_has_working_reset_flags(void)
/* All other board versions should have working reset flags */
return 1;
}
+
+/*
+ * I2C callbacks to ensure bus free time for battery I2C transactions is at
+ * least 5ms.
+ */
+#define BATTERY_FREE_MIN_DELTA_US (5 * MSEC)
+static timestamp_t battery_last_i2c_time;
+
+static int is_battery_i2c(int port, int slave_addr)
+{
+ return (port == I2C_PORT_BATTERY) && (slave_addr == BATTERY_ADDR);
+}
+
+void i2c_start_xfer_notify(int port, int slave_addr)
+{
+ unsigned int time_delta_us;
+
+ if (!is_battery_i2c(port, slave_addr))
+ return;
+
+ time_delta_us = time_since32(battery_last_i2c_time);
+ if (time_delta_us >= BATTERY_FREE_MIN_DELTA_US)
+ return;
+
+ usleep(BATTERY_FREE_MIN_DELTA_US - time_delta_us);
+}
+
+void i2c_end_xfer_notify(int port, int slave_addr)
+{
+ if (!is_battery_i2c(port, slave_addr))
+ return;
+
+ battery_last_i2c_time = get_time();
+}
diff --git a/board/nautilus/board.h b/board/nautilus/board.h
index 242bbc0524..b6362799a2 100644
--- a/board/nautilus/board.h
+++ b/board/nautilus/board.h
@@ -25,6 +25,7 @@
#define CONFIG_FPU
#define CONFIG_I2C
#define CONFIG_I2C_MASTER
+#define CONFIG_I2C_XFER_BOARD_CALLBACK
#define CONFIG_KEYBOARD_COL2_INVERTED
#define CONFIG_KEYBOARD_PROTOCOL_8042
#define CONFIG_LED_COMMON