mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-30 02:20:48 +00:00
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>
38 lines
961 B
C
38 lines
961 B
C
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*
|
|
* Smart battery driver for Spring.
|
|
*/
|
|
|
|
#include "host_command.h"
|
|
#include "i2c.h"
|
|
#include "smart_battery.h"
|
|
#include "util.h"
|
|
|
|
#define PARAM_CUT_OFF_LOW 0x10
|
|
#define PARAM_CUT_OFF_HIGH 0x00
|
|
|
|
int battery_command_cut_off(struct host_cmd_handler_args *args)
|
|
{
|
|
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,
|
|
EC_VER_MASK(0));
|