From ea32f132f7007086801b694b607606b5813a8253 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Wed, 5 Jun 2013 18:43:55 +0800 Subject: [PATCH] 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 Reviewed-on: https://gerrit.chromium.org/gerrit/57598 Reviewed-by: Vincent Palatin Reviewed-by: Randall Spangler --- common/battery_spring.c | 22 +++++++++++++++++++--- 1 file 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,