mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 01:50:53 +00:00
battery: move cut-off commands to common/battery.c
So that host and EC commands will be defined in common/battery.c. The board-specific battery.c can focus on the proprietary method. BUG=chrome-os-partner:28248 BRANCH=tot,nyan TEST=make buildall runtest Tested "cutoff" in EC console on big. Change-Id: I213c0d601d0241c8dea309d6ac60c72452d2d100 Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/196621 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
This commit is contained in:
committed by
chrome-internal-fetch
parent
fcf26a43ab
commit
2e7ea4efdb
@@ -20,7 +20,7 @@
|
||||
#define SB_SHIP_MODE_DATA 0xc574
|
||||
|
||||
static struct battery_info *battery_info;
|
||||
static int battery_cut_off;
|
||||
static int support_cut_off;
|
||||
|
||||
struct battery_device {
|
||||
char manuf[9];
|
||||
@@ -293,7 +293,7 @@ const struct battery_info *battery_get_info(void)
|
||||
(support_batteries[i].design_mv == design_mv)) {
|
||||
CPRINTF("[%T battery Manuf:%s, Device=%s, design=%u]\n",
|
||||
manuf, device, design_mv);
|
||||
battery_cut_off = support_batteries[i].support_cut_off;
|
||||
support_cut_off = support_batteries[i].support_cut_off;
|
||||
battery_info = support_batteries[i].battery_info;
|
||||
return battery_info;
|
||||
}
|
||||
@@ -304,12 +304,10 @@ const struct battery_info *battery_get_info(void)
|
||||
return &info_precharge;
|
||||
}
|
||||
|
||||
int battery_command_cut_off(struct host_cmd_handler_args *args)
|
||||
int board_cut_off_battery(void)
|
||||
{
|
||||
if (battery_cut_off)
|
||||
if (support_cut_off)
|
||||
return sb_write(SB_SHIP_MODE_ADDR, SB_SHIP_MODE_DATA);
|
||||
else
|
||||
return EC_RES_INVALID_COMMAND;
|
||||
}
|
||||
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
|
||||
EC_VER_MASK(0));
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
/* Optional features */
|
||||
#define CONFIG_AP_HANG_DETECT
|
||||
#define CONFIG_BATTERY_SMART
|
||||
#define CONFIG_BATTERY_CUT_OFF
|
||||
#define CONFIG_CHARGER
|
||||
#define CONFIG_CHARGER_V2
|
||||
#define CONFIG_CHARGER_BQ24725
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#define SB_SHUTDOWN_DATA 0x0010
|
||||
|
||||
static struct battery_info *battery_info;
|
||||
static int battery_cut_off;
|
||||
static int support_cut_off;
|
||||
|
||||
struct battery_device {
|
||||
char manuf[9];
|
||||
@@ -218,7 +218,7 @@ const struct battery_info *battery_get_info(void)
|
||||
(support_batteries[i].design_mv == design_mv)) {
|
||||
CPRINTF("[%T battery Manuf:%s, Device=%s, design=%u]\n",
|
||||
manuf, device, design_mv);
|
||||
battery_cut_off = support_batteries[i].support_cut_off;
|
||||
support_cut_off = support_batteries[i].support_cut_off;
|
||||
battery_info = support_batteries[i].battery_info;
|
||||
return battery_info;
|
||||
}
|
||||
@@ -229,25 +229,23 @@ const struct battery_info *battery_get_info(void)
|
||||
return &info_precharge;
|
||||
}
|
||||
|
||||
static int cutoff(void)
|
||||
int board_cut_off_battery(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (!support_cut_off)
|
||||
return EC_RES_INVALID_COMMAND;
|
||||
|
||||
/* Ship mode command must be sent twice to take effect */
|
||||
rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
|
||||
|
||||
if (rv != EC_SUCCESS)
|
||||
return rv;
|
||||
goto out;
|
||||
|
||||
return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
|
||||
}
|
||||
|
||||
int battery_command_cut_off(struct host_cmd_handler_args *args)
|
||||
{
|
||||
if (battery_cut_off)
|
||||
return cutoff() ? EC_RES_ERROR : EC_RES_SUCCESS;
|
||||
rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
|
||||
out:
|
||||
if (rv)
|
||||
return EC_RES_ERROR;
|
||||
else
|
||||
return EC_RES_INVALID_COMMAND;
|
||||
return EC_RES_SUCCESS;
|
||||
}
|
||||
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
|
||||
EC_VER_MASK(0));
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
/* Optional features */
|
||||
#define CONFIG_AP_HANG_DETECT
|
||||
#define CONFIG_BATTERY_SMART
|
||||
#define CONFIG_BATTERY_CUT_OFF
|
||||
#define CONFIG_CHARGER
|
||||
#define CONFIG_CHARGER_V2
|
||||
#define CONFIG_CHARGER_BQ24725
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#define SB_SHIP_MODE_DATA 0xc574
|
||||
|
||||
static struct battery_info *battery_info;
|
||||
static int battery_cut_off;
|
||||
static int support_cut_off;
|
||||
|
||||
struct battery_device {
|
||||
char manuf[9];
|
||||
@@ -255,7 +255,7 @@ const struct battery_info *battery_get_info(void)
|
||||
(support_batteries[i].design_mv == design_mv)) {
|
||||
CPRINTF("[%T battery Manuf:%s, Device=%s, design=%u]\n",
|
||||
manuf, device, design_mv);
|
||||
battery_cut_off = support_batteries[i].support_cut_off;
|
||||
support_cut_off = support_batteries[i].support_cut_off;
|
||||
battery_info = support_batteries[i].battery_info;
|
||||
return battery_info;
|
||||
}
|
||||
@@ -266,12 +266,10 @@ const struct battery_info *battery_get_info(void)
|
||||
return &info_precharge;
|
||||
}
|
||||
|
||||
int battery_command_cut_off(struct host_cmd_handler_args *args)
|
||||
int board_cut_off_battery(void)
|
||||
{
|
||||
if (battery_cut_off)
|
||||
if (support_cut_off)
|
||||
return sb_write(SB_SHIP_MODE_ADDR, SB_SHIP_MODE_DATA);
|
||||
else
|
||||
return EC_RES_INVALID_COMMAND;
|
||||
}
|
||||
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
|
||||
EC_VER_MASK(0));
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
/* Optional features */
|
||||
#define CONFIG_AP_HANG_DETECT
|
||||
#define CONFIG_BATTERY_SMART
|
||||
#define CONFIG_BATTERY_CUT_OFF
|
||||
#define CONFIG_CHARGER
|
||||
#define CONFIG_CHARGER_V2
|
||||
#define CONFIG_CHARGER_BQ24725
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "common.h"
|
||||
#include "console.h"
|
||||
#include "gpio.h"
|
||||
#include "host_command.h"
|
||||
#include "timer.h"
|
||||
#include "util.h"
|
||||
#include "watchdog.h"
|
||||
@@ -248,3 +249,22 @@ DECLARE_CONSOLE_COMMAND(battery, command_battery,
|
||||
"<repeat_count> <sleep_ms>",
|
||||
"Print battery info",
|
||||
NULL);
|
||||
|
||||
|
||||
#ifdef CONFIG_BATTERY_CUT_OFF
|
||||
int battery_command_cut_off(struct host_cmd_handler_args *args)
|
||||
{
|
||||
return board_cut_off_battery();
|
||||
}
|
||||
DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off,
|
||||
EC_VER_MASK(0));
|
||||
|
||||
static int command_cutoff(int argc, char **argv)
|
||||
{
|
||||
return board_cut_off_battery();
|
||||
}
|
||||
DECLARE_CONSOLE_COMMAND(cutoff, command_cutoff,
|
||||
"",
|
||||
"Cut off the battery output",
|
||||
NULL);
|
||||
#endif /* CONFIG_BATTERY_CUT_OFF */
|
||||
|
||||
@@ -268,4 +268,11 @@ int battery_device_chemistry(char *dest, int size);
|
||||
*/
|
||||
int battery_manufacturer_date(int *year, int *month, int *day);
|
||||
|
||||
/**
|
||||
* Call board-specific cut-off function.
|
||||
*
|
||||
* @return EC_RES_INVALID_COMMAND if the battery doesn't support.
|
||||
*/
|
||||
int board_cut_off_battery(void);
|
||||
|
||||
#endif /* __CROS_EC_BATTERY_H */
|
||||
|
||||
@@ -128,6 +128,14 @@
|
||||
*/
|
||||
#undef CONFIG_BATTERY_VENDOR_PARAMS
|
||||
|
||||
/*
|
||||
* Support battery cut-off as host command and console command.
|
||||
*
|
||||
* Once defined, you have to implement a board_cut_off_battery() function
|
||||
* in board/???/battery.c file.
|
||||
*/
|
||||
#undef CONFIG_BATTERY_CUT_OFF
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user