mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-11 18:35:28 +00:00
Add ectool discharge command to Falco and Peppy.
Expands and renames ectool 'chargeforceidle' command to 'chargecontrol'. Board-specific calls are needed to enable and disable the discharge while on AC power state. BUG=chrome-os-partner:20506 BRANCH=falco,peppy TEST=Run ectool chargecontrol command with each option (normal, idle, discharge) on Falco and Peppy. Verifiy battery is discharging in discharge mode via EC console 'battery' command. Change-Id: I7ac2b18b4f143bf6abc1e0bb878ad21a99f52100 Signed-off-by: Dave Parker <dparker@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/60689 Reviewed-by: Vic Yang <victoryang@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
|
||||
#include "adc.h"
|
||||
#include "backlight.h"
|
||||
#include "board.h"
|
||||
#include "charger_bq24738.h"
|
||||
#include "chip_temp_sensor.h"
|
||||
#include "chipset_haswell.h"
|
||||
#include "chipset_x86_common.h"
|
||||
@@ -222,3 +224,11 @@ int board_g781_has_power(void)
|
||||
{
|
||||
return gpio_get_level(GPIO_PP3300_DX_EN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Discharge battery when on AC power for factory test.
|
||||
*/
|
||||
int board_discharge_on_ac(int enable)
|
||||
{
|
||||
return charger_discharge_on_ac(enable);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#ifdef HAS_TASK_CHIPSET
|
||||
#define CONFIG_CHIPSET_HASWELL
|
||||
#endif
|
||||
#define CONFIG_CMD_DISCHARGE_ON_AC
|
||||
#define CONFIG_CUSTOM_KEYSCAN
|
||||
#define CONFIG_EXTPOWER_GPIO
|
||||
#ifdef HAS_TASK_KEYPROTO
|
||||
@@ -219,6 +220,9 @@ int board_g781_has_power(void);
|
||||
#define WIRELESS_GPIO_WWAN GPIO_PP3300_LTE_EN
|
||||
#define WIRELESS_GPIO_WLAN_POWER GPIO_PP3300_WLAN_EN
|
||||
|
||||
/* Discharge battery when on AC power for factory test. */
|
||||
int board_discharge_on_ac(int enable);
|
||||
|
||||
#endif /* !__ASSEMBLER__ */
|
||||
|
||||
#endif /* __BOARD_H */
|
||||
|
||||
@@ -216,3 +216,15 @@ int board_g781_has_power(void)
|
||||
{
|
||||
return gpio_get_level(GPIO_PP3300_DX_EN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Discharge battery when on AC power for factory test.
|
||||
*/
|
||||
int board_discharge_on_ac(int enable)
|
||||
{
|
||||
if (enable)
|
||||
gpio_set_level(GPIO_CHARGE_L, 1);
|
||||
else
|
||||
gpio_set_level(GPIO_CHARGE_L, 0);
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#ifdef HAS_TASK_CHIPSET
|
||||
#define CONFIG_CHIPSET_HASWELL
|
||||
#endif
|
||||
#define CONFIG_CMD_DISCHARGE_ON_AC
|
||||
#define CONFIG_CUSTOM_KEYSCAN
|
||||
#define CONFIG_EXTPOWER_GPIO
|
||||
#ifdef HAS_TASK_KEYPROTO
|
||||
@@ -221,6 +222,9 @@ int board_g781_has_power(void);
|
||||
#define WIRELESS_GPIO_WWAN GPIO_PP3300_LTE_EN
|
||||
#define WIRELESS_GPIO_WLAN_POWER GPIO_PP3300_WLAN_EN
|
||||
|
||||
/* Discharge battery when on AC power for factory test. */
|
||||
int board_discharge_on_ac(int enable);
|
||||
|
||||
#endif /* !__ASSEMBLER__ */
|
||||
|
||||
#endif /* __BOARD_H */
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "battery.h"
|
||||
#include "battery_pack.h"
|
||||
#include "board.h"
|
||||
#include "charge_state.h"
|
||||
#include "charger.h"
|
||||
#include "chipset.h"
|
||||
@@ -575,22 +576,18 @@ int charge_want_shutdown(void)
|
||||
charge_get_percent() < BATTERY_LEVEL_SHUTDOWN;
|
||||
}
|
||||
|
||||
static int enter_force_idle_mode(void)
|
||||
static int charge_force_idle(int enable)
|
||||
{
|
||||
/*
|
||||
* Force-idle state is only meaningful if external power is present.
|
||||
* If it's not present we can't charge anyway...
|
||||
*/
|
||||
if (!(charge_get_flags() & CHARGE_FLAG_EXTERNAL_POWER))
|
||||
return EC_ERROR_UNKNOWN;
|
||||
state_machine_force_idle = 1;
|
||||
charger_post_init();
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
static int exit_force_idle_mode(void)
|
||||
{
|
||||
state_machine_force_idle = 0;
|
||||
if (enable) {
|
||||
/*
|
||||
* Force-idle state is only meaningful if external power is
|
||||
* present. If it's not present we can't charge anyway...
|
||||
*/
|
||||
if (!(charge_get_flags() & CHARGE_FLAG_EXTERNAL_POWER))
|
||||
return EC_ERROR_UNKNOWN;
|
||||
charger_post_init();
|
||||
}
|
||||
state_machine_force_idle = enable;
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -820,25 +817,33 @@ DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, charge_shutdown, HOOK_PRIO_LAST);
|
||||
/*****************************************************************************/
|
||||
/* Host commands */
|
||||
|
||||
static int charge_command_force_idle(struct host_cmd_handler_args *args)
|
||||
static int charge_command_charge_control(struct host_cmd_handler_args *args)
|
||||
{
|
||||
const struct ec_params_force_idle *p = args->params;
|
||||
const struct ec_params_charge_control *p = args->params;
|
||||
int rv;
|
||||
|
||||
if (system_is_locked())
|
||||
return EC_RES_ACCESS_DENIED;
|
||||
|
||||
if (p->enabled)
|
||||
rv = enter_force_idle_mode();
|
||||
else
|
||||
rv = exit_force_idle_mode();
|
||||
|
||||
rv = charge_force_idle(p->mode != CHARGE_CONTROL_NORMAL);
|
||||
if (rv != EC_SUCCESS)
|
||||
return EC_RES_ERROR;
|
||||
return rv;
|
||||
|
||||
#ifdef CONFIG_CMD_DISCHARGE_ON_AC
|
||||
rv = board_discharge_on_ac(p->mode == CHARGE_CONTROL_DISCHARGE);
|
||||
if (rv != EC_SUCCESS)
|
||||
return rv;
|
||||
#endif /* CONFIG_CMD_DISCHARGE_ON_AC */
|
||||
|
||||
return EC_RES_SUCCESS;
|
||||
}
|
||||
DECLARE_HOST_COMMAND(EC_CMD_CHARGE_FORCE_IDLE, charge_command_force_idle,
|
||||
EC_VER_MASK(0));
|
||||
/*
|
||||
* TODO(crbug.com/239197) : Adding both versions to the version mask is a
|
||||
* temporary workaround for a problem in the cros_ec driver. Drop
|
||||
* EC_VER_MASK(0) once cros_ec driver can send the correct version.
|
||||
*/
|
||||
DECLARE_HOST_COMMAND(EC_CMD_CHARGE_CONTROL, charge_command_charge_control,
|
||||
EC_VER_MASK(0) | EC_VER_MASK(1));
|
||||
|
||||
static int charge_command_dump(struct host_cmd_handler_args *args)
|
||||
{
|
||||
|
||||
@@ -189,3 +189,20 @@ int charger_post_init(void)
|
||||
rv = charger_set_input_current(CONFIG_CHARGER_INPUT_CURRENT);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int charger_discharge_on_ac(int enable)
|
||||
{
|
||||
int rv;
|
||||
int option;
|
||||
|
||||
rv = charger_get_option(&option);
|
||||
if (rv)
|
||||
return rv;
|
||||
|
||||
if (enable)
|
||||
rv = charger_set_option(option | OPTION_LEARN_ENABLE);
|
||||
else
|
||||
rv = charger_set_option(option & ~OPTION_LEARN_ENABLE);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -54,5 +54,7 @@
|
||||
#define ACPRES_DEGLITCH_150MS (0 << 15)
|
||||
#define ACPRES_DEGLITCH_1300MS_DEFAULT (1 << 15)
|
||||
|
||||
#endif /* __CROS_EC_CHARGER_BQ24738_H */
|
||||
/* Discharge battery when on AC power. */
|
||||
int charger_discharge_on_ac(int enable);
|
||||
|
||||
#endif /* __CROS_EC_CHARGER_BQ24738_H */
|
||||
|
||||
@@ -1396,11 +1396,20 @@ struct ec_params_i2c_write {
|
||||
/*****************************************************************************/
|
||||
/* Charge state commands. Only available when flash write protect unlocked. */
|
||||
|
||||
/* Force charge state machine to stop in idle mode */
|
||||
#define EC_CMD_CHARGE_FORCE_IDLE 0x96
|
||||
/* Force charge state machine to stop charging the battery or force it to
|
||||
* discharge the battery.
|
||||
*/
|
||||
#define EC_CMD_CHARGE_CONTROL 0x96
|
||||
#define EC_VER_CHARGE_CONTROL 1
|
||||
|
||||
struct ec_params_force_idle {
|
||||
uint8_t enabled;
|
||||
enum ec_charge_control_mode {
|
||||
CHARGE_CONTROL_NORMAL = 0,
|
||||
CHARGE_CONTROL_IDLE,
|
||||
CHARGE_CONTROL_DISCHARGE,
|
||||
};
|
||||
|
||||
struct ec_params_charge_control {
|
||||
uint32_t mode; /* enum charge_control_mode */
|
||||
} __packed;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -40,8 +40,8 @@ const char help_str[] =
|
||||
" Set the maximum battery charging current\n"
|
||||
" chargedump\n"
|
||||
" Dump the context of charge state machine\n"
|
||||
" chargeforceidle\n"
|
||||
" Force charge state machine to stop in idle mode\n"
|
||||
" chargecontrol\n"
|
||||
" Force the battery to stop charging or discharge\n"
|
||||
" chipinfo\n"
|
||||
" Prints chip info\n"
|
||||
" cmdversions <cmd>\n"
|
||||
@@ -2375,33 +2375,47 @@ int cmd_charge_current_limit(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
int cmd_charge_force_idle(int argc, char *argv[])
|
||||
int cmd_charge_control(int argc, char *argv[])
|
||||
{
|
||||
struct ec_params_force_idle p;
|
||||
struct ec_params_charge_control p;
|
||||
int rv;
|
||||
char *e;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <0|1>\n", argv[0]);
|
||||
fprintf(stderr, "Usage: %s <normal | idle | discharge>\n",
|
||||
argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
p.enabled = strtol(argv[1], &e, 0);
|
||||
if (e && *e) {
|
||||
if (!strcasecmp(argv[1], "normal")) {
|
||||
p.mode = CHARGE_CONTROL_NORMAL;
|
||||
} else if (!strcasecmp(argv[1], "idle")) {
|
||||
p.mode = CHARGE_CONTROL_IDLE;
|
||||
} else if (!strcasecmp(argv[1], "discharge")) {
|
||||
p.mode = CHARGE_CONTROL_DISCHARGE;
|
||||
} else {
|
||||
fprintf(stderr, "Bad value.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = ec_command(EC_CMD_CHARGE_FORCE_IDLE, 0, &p, sizeof(p), NULL, 0);
|
||||
rv = ec_command(EC_CMD_CHARGE_CONTROL, 1, &p, sizeof(p), NULL, 0);
|
||||
if (rv < 0) {
|
||||
fprintf(stderr, "Is AC connected?\n");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (p.enabled)
|
||||
printf("Charge state machine force idle.\n");
|
||||
else
|
||||
switch (p.mode) {
|
||||
case CHARGE_CONTROL_NORMAL:
|
||||
printf("Charge state machine normal mode.\n");
|
||||
break;
|
||||
case CHARGE_CONTROL_IDLE:
|
||||
printf("Charge state machine force idle.\n");
|
||||
break;
|
||||
case CHARGE_CONTROL_DISCHARGE:
|
||||
printf("Charge state machine force discharge.\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -3097,7 +3111,7 @@ const struct command commands[] = {
|
||||
{"batterycutoff", cmd_battery_cut_off},
|
||||
{"chargecurrentlimit", cmd_charge_current_limit},
|
||||
{"chargedump", cmd_charge_dump},
|
||||
{"chargeforceidle", cmd_charge_force_idle},
|
||||
{"chargecontrol", cmd_charge_control},
|
||||
{"chipinfo", cmd_chipinfo},
|
||||
{"cmdversions", cmd_cmdversions},
|
||||
{"console", cmd_console},
|
||||
|
||||
Reference in New Issue
Block a user