cleanup: Use CONFIG_BATTERY_CUT_OFF for supported boards

Common battery cut-off host command / console command infrastructure
already exists behind CONFIG_BATTERY_CUT_OFF, so add the config rather
duplicating the code at the board level.

BUG=chromium:488157
TEST=Manual on Squawks. Verify that both "cutoff" on the ec console and
"ectool batterycutoff" succeed to cut-off the battery.
BRANCH=None

Change-Id: I159026d54924e058ea0262db04d8770c663ee613
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/271513
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Shawn Nematbakhsh
2015-05-15 12:00:42 -07:00
committed by ChromeOS Commit Bot
parent b4cbe7d377
commit 0a71b4418d
14 changed files with 28 additions and 125 deletions

View File

@@ -7,10 +7,6 @@
#include "battery.h"
#include "battery_smart.h"
#include "console.h"
#include "gpio.h"
#include "host_command.h"
#include "util.h"
/* Shutdown mode parameter to write to manufacturer access register */
#define SB_SHUTDOWN_DATA 0x0010
@@ -33,7 +29,7 @@ const struct battery_info *battery_get_info(void)
return &info;
}
static int cutoff(void)
int board_cut_off_battery(void)
{
int rv;
@@ -45,19 +41,3 @@ static int cutoff(void)
return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
}
static int battery_command_cut_off(struct host_cmd_handler_args *args)
{
return cutoff() ? EC_RES_ERROR : EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
EC_VER_MASK(0));
static int command_battcutoff(int argc, char **argv)
{
return cutoff();
}
DECLARE_CONSOLE_COMMAND(battcutoff, command_battcutoff,
NULL,
"Enable battery cutoff (ship mode)",
NULL);

View File

@@ -31,6 +31,7 @@
#define CONFIG_WAKE_PIN GPIO_POWER_BUTTON_L
#define CONFIG_CHARGER
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_SMART
#define CONFIG_CHARGER_V2
#define CONFIG_CHARGER_BQ24770

View File

@@ -7,7 +7,6 @@
#include "battery.h"
#include "battery_smart.h"
#include "host_command.h"
#define SB_SHIP_MODE_DATA 0x0010
@@ -33,16 +32,15 @@ const struct battery_info *battery_get_info(void)
return &info;
}
int battery_command_cut_off(struct host_cmd_handler_args *args)
int board_cut_off_battery(void)
{
int rv;
/* Ship mode command must be sent twice. */
rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHIP_MODE_DATA);
if (rv != EC_SUCCESS)
return rv;
rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHIP_MODE_DATA);
return rv;
return sb_write(SB_MANUFACTURER_ACCESS, SB_SHIP_MODE_DATA);
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
EC_VER_MASK(0));

View File

@@ -10,6 +10,7 @@
/* Optional features */
#define CONFIG_BACKLIGHT_REQ_GPIO GPIO_PCH_BKLTEN
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_VERSION
#define CONFIG_CHARGER
@@ -39,6 +40,9 @@
#define CONFIG_VBOOT_HASH
#define CONFIG_WIRELESS
#undef DEFERRABLE_MAX_COUNT
#define DEFERRABLE_MAX_COUNT 9
#ifndef __ASSEMBLER__
/* I2C ports */

View File

@@ -33,7 +33,7 @@ const struct battery_info *battery_get_info(void)
return &info;
}
static int cutoff(void)
int board_cut_off_battery(void)
{
int rv;
@@ -45,19 +45,3 @@ static int cutoff(void)
return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
}
static int battery_command_cut_off(struct host_cmd_handler_args *args)
{
return cutoff() ? EC_RES_ERROR : EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
EC_VER_MASK(0));
static int command_battcutoff(int argc, char **argv)
{
return cutoff();
}
DECLARE_CONSOLE_COMMAND(battcutoff, command_battcutoff,
NULL,
"Enable battery cutoff (ship mode)",
NULL);

View File

@@ -40,6 +40,7 @@
#define CONFIG_ALS
#define CONFIG_ALS_ISL29035
#define CONFIG_CHARGER
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_SMART
#define CONFIG_CHARGER_V2
#define CONFIG_CHARGER_BQ24770

View File

@@ -33,7 +33,7 @@ const struct battery_info *battery_get_info(void)
return &info;
}
static int cutoff(void)
int board_cut_off_battery(void)
{
int rv;
@@ -45,19 +45,3 @@ static int cutoff(void)
return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
}
static int battery_command_cut_off(struct host_cmd_handler_args *args)
{
return cutoff() ? EC_RES_ERROR : EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
EC_VER_MASK(0));
static int command_battcutoff(int argc, char **argv)
{
return cutoff();
}
DECLARE_CONSOLE_COMMAND(battcutoff, command_battcutoff,
NULL,
"Enable battery cutoff (ship mode)",
NULL);

View File

@@ -11,6 +11,7 @@
/* Optional features */
#define CONFIG_AP_HANG_DETECT
#define CONFIG_BACKLIGHT_LID
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_VERSION
#define CONFIG_CHARGER

View File

@@ -7,12 +7,9 @@
#include "battery.h"
#include "battery_smart.h"
#include "host_command.h"
#include "i2c.h"
#include "util.h"
#define PARAM_CUT_OFF_LOW 0x10
#define PARAM_CUT_OFF_HIGH 0x00
/* Shutdown mode parameter to write to manufacturer access register */
#define SB_SHUTDOWN_DATA 0x0010
/* Battery temperature ranges in degrees C */
static const struct battery_info info = {
@@ -29,25 +26,15 @@ const struct battery_info *battery_get_info(void)
return &info;
}
int battery_command_cut_off(struct host_cmd_handler_args *args)
int board_cut_off_battery(void)
{
int rv;
uint8_t buf[3];
buf[0] = SB_MANUFACTURER_ACCESS & 0xff;
buf[1] = PARAM_CUT_OFF_LOW;
buf[2] = PARAM_CUT_OFF_HIGH;
/* Ship mode command must be sent twice to take effect */
rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
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 != EC_SUCCESS)
return rv;
if (rv)
return EC_RES_ERROR;
return EC_RES_SUCCESS;
return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
EC_VER_MASK(0));

View File

@@ -17,6 +17,7 @@
/* Optional features */
#define CONFIG_ADC
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_PRE_INIT
#define CONFIG_CHARGER_TPS65090

View File

@@ -7,10 +7,6 @@
#include "battery.h"
#include "battery_smart.h"
#include "console.h"
#include "gpio.h"
#include "host_command.h"
#include "util.h"
/* Shutdown mode parameter to write to manufacturer access register */
#define SB_SHUTDOWN_DATA 0x0010
@@ -38,7 +34,7 @@ const struct battery_info *battery_get_info(void)
return &info;
}
static int cutoff(void)
int board_cut_off_battery(void)
{
int rv;
@@ -50,19 +46,3 @@ static int cutoff(void)
return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
}
static int battery_command_cut_off(struct host_cmd_handler_args *args)
{
return cutoff() ? EC_RES_ERROR : EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
EC_VER_MASK(0));
static int command_battcutoff(int argc, char **argv)
{
return cutoff();
}
DECLARE_CONSOLE_COMMAND(battcutoff, command_battcutoff,
NULL,
"Enable battery cutoff (ship mode)",
NULL);

View File

@@ -11,6 +11,7 @@
/* Optional features */
#define CONFIG_AP_HANG_DETECT
#define CONFIG_BACKLIGHT_LID
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_SMART
#define CONFIG_BOARD_VERSION
#define CONFIG_CHARGER

View File

@@ -7,10 +7,6 @@
#include "battery.h"
#include "battery_smart.h"
#include "console.h"
#include "gpio.h"
#include "host_command.h"
#include "util.h"
/* Shutdown mode parameter to write to manufacturer access register */
#define SB_SHUTDOWN_DATA 0x0010
@@ -33,7 +29,7 @@ const struct battery_info *battery_get_info(void)
return &info;
}
static int cutoff(void)
int board_cut_off_battery(void)
{
int rv;
@@ -45,19 +41,3 @@ static int cutoff(void)
return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
}
static int battery_command_cut_off(struct host_cmd_handler_args *args)
{
return cutoff() ? EC_RES_ERROR : EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
EC_VER_MASK(0));
static int command_battcutoff(int argc, char **argv)
{
return cutoff();
}
DECLARE_CONSOLE_COMMAND(battcutoff, command_battcutoff,
NULL,
"Enable battery cutoff (ship mode)",
NULL);

View File

@@ -40,8 +40,9 @@
#define CONFIG_ALS
#define CONFIG_ALS_ISL29035
#define CONFIG_CHARGER
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_SMART
#define CONFIG_CHARGER
#define CONFIG_CHARGER_V2
#define CONFIG_CHARGER_BQ24770
#define CONFIG_CHARGER_ILIM_PIN_DISABLED