diff options
author | Sheng-Liang Song <ssl@chromium.org> | 2014-07-25 14:25:51 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-09-03 22:49:57 +0000 |
commit | 51a279cf3aa62ebd0c3a5148ae5a3e227a3a22e0 (patch) | |
tree | 8049357793b29a305af762bf3046f913507b5db4 /driver | |
parent | 51e48026c206688c3387c4b4f1d1c0ed42a959e1 (diff) | |
download | chrome-ec-51a279cf3aa62ebd0c3a5148ae5a3e227a3a22e0.tar.gz |
EC: smart battery using smbus API
Ref: Common Smart Battery System Inferface Specification v8.0.
Ref: http://smbus.org/specs/smbus20.pdf
- Enable smbus read/write APIs with compile options
BUG=chrome-os-partner:30930
BRANCH=ToT,glimmer
TEST=Verified with LGC & Simplo firmware update.
Change-Id: I3f4bb23147f22365adb378c2e39c40d5ba100889
Signed-off-by: Sheng-Liang Song <ssl@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/209906
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/battery/smart.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/driver/battery/smart.c b/driver/battery/smart.c index 0df0fefbe8..0c63e0fec1 100644 --- a/driver/battery/smart.c +++ b/driver/battery/smart.c @@ -10,6 +10,7 @@ #include "console.h" #include "host_command.h" #include "i2c.h" +#include "smbus.h" #include "timer.h" #include "util.h" @@ -39,7 +40,17 @@ test_mockable int sb_read(int cmd, int *param) if (battery_is_cut_off()) return EC_RES_ACCESS_DENIED; #endif +#ifdef CONFIG_SMBUS + { + int rv; + uint16_t d16 = 0; + rv = smbus_read_word(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, &d16); + *param = d16; + return rv; + } +#else return i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); +#endif } test_mockable int sb_write(int cmd, int param) @@ -51,7 +62,11 @@ test_mockable int sb_write(int cmd, int param) if (battery_is_cut_off()) return EC_RES_ACCESS_DENIED; #endif +#ifdef CONFIG_SMBUS + return smbus_write_word(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); +#else return i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); +#endif } int sb_read_string(int port, int slave_addr, int offset, uint8_t *data, @@ -64,7 +79,11 @@ int sb_read_string(int port, int slave_addr, int offset, uint8_t *data, if (battery_is_cut_off()) return EC_RES_ACCESS_DENIED; #endif +#ifdef CONFIG_SMBUS + return smbus_read_string(port, slave_addr, offset, data, len); +#else return i2c_read_string(port, slave_addr, offset, data, len); +#endif } int battery_get_mode(int *mode) @@ -372,7 +391,7 @@ static int host_command_sb_read_word(struct host_cmd_handler_args *args) if (p->reg > 0x1c) return EC_RES_INVALID_PARAM; - rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, p->reg, &val); + rv = sb_read(p->reg, &val); if (rv) return EC_RES_ERROR; @@ -392,7 +411,7 @@ static int host_command_sb_write_word(struct host_cmd_handler_args *args) if (p->reg > 0x1c) return EC_RES_INVALID_PARAM; - rv = i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, p->reg, p->value); + rv = sb_write(p->reg, p->value); if (rv) return EC_RES_ERROR; |