From ebb25bc556e399678189895b0371065e8c9507c0 Mon Sep 17 00:00:00 2001 From: YongBeum Ha Date: Thu, 20 Dec 2018 08:54:49 +0900 Subject: casta : Add battery information Casta uses same battery as nautilus. BUG=b:122868858 BRANCH=octopus TEST=make -j buildall; flash EC & check battery information Change-Id: I55894821744d242958c2dcf31da355b315d9ac8f Signed-off-by: YongBeum Ha Signed-off-by: Karthikeyan Ramasubramanian Reviewed-on: https://chromium-review.googlesource.com/c/1385764 Reviewed-by: Philip Chen Reviewed-on: https://chromium-review.googlesource.com/1430740 Reviewed-by: Jett Rink --- board/casta/board.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'board/casta/board.c') diff --git a/board/casta/board.c b/board/casta/board.c index 124601fa75..bcea197537 100644 --- a/board/casta/board.c +++ b/board/casta/board.c @@ -88,6 +88,49 @@ const struct temp_sensor_t temp_sensors[] = { }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); +/* + * 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); +} + +static int is_battery_port(int port) +{ + return (port == I2C_PORT_BATTERY); +} + +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) +{ + /* + * The bus free time needs to be maintained from last transaction + * on I2C bus to any device on it to the next transaction to battery. + */ + if (!is_battery_port(port)) + return; + + battery_last_i2c_time = get_time(); +} + void board_overcurrent_event(int port, int is_overcurrented) { /* Sanity check the port. */ -- cgit v1.2.1