diff options
author | YongBeum Ha <ybha@samsung.com> | 2018-12-20 08:54:49 +0900 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-01-24 00:51:38 -0800 |
commit | ebb25bc556e399678189895b0371065e8c9507c0 (patch) | |
tree | 6f179932ebd77a447577fb94e4c79fd3d8c8ad54 /board/casta/board.c | |
parent | 544ba7da11eeeae342861b5ecfc72a50152a4711 (diff) | |
download | chrome-ec-ebb25bc556e399678189895b0371065e8c9507c0.tar.gz |
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 <ybha@samsung.com>
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/1385764
Reviewed-by: Philip Chen <philipchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1430740
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'board/casta/board.c')
-rw-r--r-- | board/casta/board.c | 43 |
1 files changed, 43 insertions, 0 deletions
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. */ |