diff options
author | Furquan Shaikh <furquan@google.com> | 2018-03-09 17:03:46 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-03-21 20:48:36 -0700 |
commit | e513b7339ad66c30fa9cee626e478d06a714e42c (patch) | |
tree | 43cb2db9c6e7b52ae7230cc56f7c4b29d345a36b /board/nautilus/board.c | |
parent | 9aee2a19e81949eca86eb0b113c99d1782eaa2d2 (diff) | |
download | chrome-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>
Diffstat (limited to 'board/nautilus/board.c')
-rw-r--r-- | board/nautilus/board.c | 35 |
1 files changed, 35 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(); +} |