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>
This commit is contained in:
Vic Yang
2013-06-05 18:43:55 +08:00
committed by ChromeBot
parent 3e0e15d185
commit ea32f132f7

View File

@@ -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,