diff options
author | Vic Yang <victoryang@chromium.org> | 2013-06-05 18:43:55 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-06-05 11:25:10 -0700 |
commit | ea32f132f7007086801b694b607606b5813a8253 (patch) | |
tree | accfb6adca223f0a4a24a62feddbeff5d5be9aa6 /common | |
parent | 3e0e15d185f6a324451992a7c2bfc5000c4f15c8 (diff) | |
download | chrome-ec-ea32f132f7007086801b694b607606b5813a8253.tar.gz |
spring: Guard battery cut-off command with lock
The two I2C commands for battery cut-off must be sent out back to back.
Thus we need to guard them with I2C port lock to prevent being
preempted.
BUG=chrome-os-partner:19901
TEST=Check battery cutoff still works.
BRANCH=spring
Change-Id: Iac51037432b108d4cac29d5c73cafa9ce2310b12
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/57598
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/battery_spring.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/common/battery_spring.c b/common/battery_spring.c index 28baf58c33..4604671b8e 100644 --- a/common/battery_spring.c +++ b/common/battery_spring.c @@ -6,15 +6,31 @@ */ #include "host_command.h" +#include "i2c.h" #include "smart_battery.h" +#include "util.h" -#define PARAM_CUT_OFF 0x0010 +#define PARAM_CUT_OFF_LOW 0x10 +#define PARAM_CUT_OFF_HIGH 0x00 int battery_command_cut_off(struct host_cmd_handler_args *args) { - sb_write(SB_MANUFACTURER_ACCESS, PARAM_CUT_OFF); - sb_write(SB_MANUFACTURER_ACCESS, PARAM_CUT_OFF); + int rv; + uint8_t buf[3]; + buf[0] = SB_MANUFACTURER_ACCESS & 0xff; + buf[1] = PARAM_CUT_OFF_LOW; + buf[2] = PARAM_CUT_OFF_HIGH; + + i2c_lock(I2C_PORT_BATTERY, 1); + rv = i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0, + I2C_XFER_SINGLE); + rv = i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0, + I2C_XFER_SINGLE); + i2c_lock(I2C_PORT_BATTERY, 0); + + if (rv) + return EC_RES_ERROR; return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off, |