summaryrefslogtreecommitdiff
path: root/common/charge_state_v2.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r--common/charge_state_v2.c554
1 files changed, 286 insertions, 268 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index f3dc811eef..728606ef8a 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1,4 +1,4 @@
-/* Copyright 2014 The Chromium OS Authors. All rights reserved.
+/* Copyright 2014 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -7,6 +7,7 @@
#include "battery.h"
#include "battery_smart.h"
+#include "builtin/assert.h"
#include "charge_manager.h"
#include "charger_profile_override.h"
#include "charge_state.h"
@@ -35,8 +36,8 @@
/* Console output macros */
#define CPUTS(outstr) cputs(CC_CHARGER, outstr)
-#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ##args)
/* Extra debugging prints when allocating power between lid and base. */
#undef CHARGE_ALLOCATE_EXTRA_DEBUG
@@ -87,8 +88,8 @@ static int prev_ac, prev_charge, prev_full, prev_disp_charge;
static enum battery_present prev_bp;
static int is_full; /* battery not accepting current */
static enum ec_charge_control_mode chg_ctl_mode;
-static int manual_voltage; /* Manual voltage override (-1 = no override) */
-static int manual_current; /* Manual current override (-1 = no override) */
+static int manual_voltage; /* Manual voltage override (-1 = no override) */
+static int manual_current; /* Manual current override (-1 = no override) */
static unsigned int user_current_limit = -1U;
test_export_static timestamp_t shutdown_target_time;
static bool is_charging_progress_displayed;
@@ -155,18 +156,10 @@ static int battery_was_removed;
static int problems_exist;
static int debugging;
-
-static const char * const prob_text[] = {
- "static update",
- "set voltage",
- "set current",
- "set mode",
- "set input current",
- "post init",
- "chg params",
- "batt params",
- "custom profile",
- "cfg secondary chg"
+static const char *const prob_text[] = {
+ "static update", "set voltage", "set current", "set mode",
+ "set input current", "post init", "chg params", "batt params",
+ "custom profile", "cfg secondary chg"
};
BUILD_ASSERT(ARRAY_SIZE(prob_text) == NUM_PROBLEM_TYPES);
@@ -184,7 +177,7 @@ void charge_problem(enum problem_type p, int v)
t_now = get_time();
t_diff.val = t_now.val - last_prob_time[p].val;
CPRINTS("charge problem: %s, 0x%x -> 0x%x after %.6" PRId64 "s",
- prob_text[p], last_prob_val[p], v, t_diff.val);
+ prob_text[p], last_prob_val[p], v, t_diff.val);
last_prob_val[p] = v;
last_prob_time[p] = t_now;
}
@@ -304,11 +297,12 @@ static const struct dual_battery_policy db_policy = {
};
/* Add at most "value" to power_var, subtracting from total_power budget. */
-#define CHG_ALLOCATE(power_var, total_power, value) do { \
- int val_capped = MIN(value, total_power); \
- (power_var) += val_capped; \
- (total_power) -= val_capped; \
-} while (0)
+#define CHG_ALLOCATE(power_var, total_power, value) \
+ do { \
+ int val_capped = MIN(value, total_power); \
+ (power_var) += val_capped; \
+ (total_power) -= val_capped; \
+ } while (0)
/* Update base battery information */
static void update_base_battery_info(void)
@@ -346,9 +340,9 @@ static void update_base_battery_info(void)
/* Newly connected battery, or change in capacity. */
if (old_flags & EC_BATT_FLAG_INVALID_DATA ||
- ((old_flags & EC_BATT_FLAG_BATT_PRESENT) !=
- (bd->flags & EC_BATT_FLAG_BATT_PRESENT)) ||
- old_full_capacity != bd->full_capacity)
+ ((old_flags & EC_BATT_FLAG_BATT_PRESENT) !=
+ (bd->flags & EC_BATT_FLAG_BATT_PRESENT)) ||
+ old_full_capacity != bd->full_capacity)
host_set_single_event(EC_HOST_EVENT_BATTERY);
if (flags_changed)
@@ -359,8 +353,8 @@ static void update_base_battery_info(void)
BATT_FLAG_BAD_REMAINING_CAPACITY))
charge_base = -1;
else if (bd->full_capacity > 0)
- charge_base = 100 * bd->remaining_capacity
- / bd->full_capacity;
+ charge_base = 100 * bd->remaining_capacity /
+ bd->full_capacity;
else
charge_base = 0;
}
@@ -380,8 +374,8 @@ static int set_base_current(int current_base, int allow_charge_base)
const int otg_voltage = db_policy.otg_voltage;
int ret;
- ret = ec_ec_client_base_charge_control(current_base,
- otg_voltage, allow_charge_base);
+ ret = ec_ec_client_base_charge_control(current_base, otg_voltage,
+ allow_charge_base);
if (ret) {
/* Ignore errors until the base is responsive. */
if (base_responsive)
@@ -418,9 +412,9 @@ static void set_base_lid_current(int current_base, int allow_charge_base,
if (prev_current_base != current_base ||
prev_allow_charge_base != allow_charge_base ||
prev_current_lid != current_lid) {
- CPRINTS("Base/Lid: %d%s/%d%s mA",
- current_base, allow_charge_base ? "+" : "",
- current_lid, allow_charge_lid ? "+" : "");
+ CPRINTS("Base/Lid: %d%s/%d%s mA", current_base,
+ allow_charge_base ? "+" : "", current_lid,
+ allow_charge_lid ? "+" : "");
}
/*
@@ -452,12 +446,12 @@ static void set_base_lid_current(int current_base, int allow_charge_base,
return;
if (allow_charge_lid)
ret = charge_request(curr.requested_voltage,
- curr.requested_current);
+ curr.requested_current);
else
ret = charge_request(0, 0);
} else {
- ret = charge_set_output_current_limit(CHARGER_SOLO,
- -current_lid, otg_voltage);
+ ret = charge_set_output_current_limit(
+ CHARGER_SOLO, -current_lid, otg_voltage);
}
if (ret)
@@ -536,7 +530,6 @@ static void charge_allocate_input_current_limit(void)
const struct ec_response_battery_dynamic_info *const base_bd =
&battery_dynamic[BATT_IDX_BASE];
-
if (!base_connected) {
set_base_lid_current(0, 0, curr.desired_input_current, 1);
prev_base_battery_power = -1;
@@ -553,7 +546,8 @@ static void charge_allocate_input_current_limit(void)
* but the value is currently wrong, especially during transitions.
*/
if (total_power <= 0) {
- int base_critical = charge_base >= 0 &&
+ int base_critical =
+ charge_base >= 0 &&
charge_base < db_policy.max_charge_base_batt_to_batt;
/* Discharging */
@@ -567,14 +561,14 @@ static void charge_allocate_input_current_limit(void)
if (manual_noac_current_base > 0) {
base_current = -manual_noac_current_base;
- lid_current =
- add_margin(manual_noac_current_base,
- db_policy.margin_otg_current);
+ lid_current = add_margin(
+ manual_noac_current_base,
+ db_policy.margin_otg_current);
} else {
lid_current = manual_noac_current_base;
- base_current =
- add_margin(-manual_noac_current_base,
- db_policy.margin_otg_current);
+ base_current = add_margin(
+ -manual_noac_current_base,
+ db_policy.margin_otg_current);
}
set_base_lid_current(base_current, 0, lid_current, 0);
@@ -605,18 +599,20 @@ static void charge_allocate_input_current_limit(void)
* touchpad events.
*/
if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) &&
- !base_critical) {
+ !base_critical) {
set_base_lid_current(0, 0, 0, 0);
return;
}
if (charge_base > db_policy.min_charge_base_otg) {
int lid_current = db_policy.max_base_to_lid_current;
- int base_current = add_margin(lid_current,
- db_policy.margin_otg_current);
+ int base_current = add_margin(
+ lid_current, db_policy.margin_otg_current);
/* Draw current from base to lid */
- set_base_lid_current(-base_current, 0, lid_current,
- charge_lid < db_policy.max_charge_lid_batt_to_batt);
+ set_base_lid_current(
+ -base_current, 0, lid_current,
+ charge_lid <
+ db_policy.max_charge_lid_batt_to_batt);
} else {
/*
* Base battery is too low, apply power to it, and allow
@@ -635,8 +631,8 @@ static void charge_allocate_input_current_limit(void)
int base_current =
(db_policy.min_base_system_power * 1000) /
db_policy.otg_voltage;
- int lid_current = add_margin(base_current,
- db_policy.margin_otg_current);
+ int lid_current = add_margin(
+ base_current, db_policy.margin_otg_current);
set_base_lid_current(base_current, base_critical,
-lid_current, 0);
@@ -664,8 +660,8 @@ static void charge_allocate_input_current_limit(void)
lid_system_power = charger_get_system_power() / 1000;
/* Smooth system power, as it is very spiky */
- lid_system_power = smooth_value(prev_lid_system_power,
- lid_system_power, db_policy.lid_system_power_smooth);
+ lid_system_power = smooth_value(prev_lid_system_power, lid_system_power,
+ db_policy.lid_system_power_smooth);
prev_lid_system_power = lid_system_power;
/*
@@ -677,15 +673,15 @@ static void charge_allocate_input_current_limit(void)
*/
/* Estimate lid battery power. */
if (!(curr.batt.flags &
- (BATT_FLAG_BAD_VOLTAGE | BATT_FLAG_BAD_CURRENT)))
- lid_battery_power = curr.batt.current *
- curr.batt.voltage / 1000;
+ (BATT_FLAG_BAD_VOLTAGE | BATT_FLAG_BAD_CURRENT)))
+ lid_battery_power =
+ curr.batt.current * curr.batt.voltage / 1000;
if (lid_battery_power < prev_lid_battery_power)
- lid_battery_power = smooth_value(prev_lid_battery_power,
- lid_battery_power, db_policy.battery_power_smooth);
+ lid_battery_power =
+ smooth_value(prev_lid_battery_power, lid_battery_power,
+ db_policy.battery_power_smooth);
if (!(curr.batt.flags &
- (BATT_FLAG_BAD_DESIRED_VOLTAGE |
- BATT_FLAG_BAD_DESIRED_CURRENT)))
+ (BATT_FLAG_BAD_DESIRED_VOLTAGE | BATT_FLAG_BAD_DESIRED_CURRENT)))
lid_battery_power_max = curr.batt.desired_current *
curr.batt.desired_voltage / 1000;
@@ -699,19 +695,20 @@ static void charge_allocate_input_current_limit(void)
base_bd->desired_voltage / 1000;
}
if (base_battery_power < prev_base_battery_power)
- base_battery_power = smooth_value(prev_base_battery_power,
- base_battery_power, db_policy.battery_power_smooth);
+ base_battery_power = smooth_value(
+ prev_base_battery_power, base_battery_power,
+ db_policy.battery_power_smooth);
base_battery_power = MIN(base_battery_power, base_battery_power_max);
if (debugging) {
CPRINTF("%s:\n", __func__);
CPRINTF("total power: %d\n", total_power);
- CPRINTF("base battery power: %d (%d)\n",
- base_battery_power, base_battery_power_max);
+ CPRINTF("base battery power: %d (%d)\n", base_battery_power,
+ base_battery_power_max);
CPRINTF("lid system power: %d\n", lid_system_power);
CPRINTF("lid battery power: %d\n", lid_battery_power);
- CPRINTF("percent base/lid: %d%% %d%%\n",
- charge_base, charge_lid);
+ CPRINTF("percent base/lid: %d%% %d%%\n", charge_base,
+ charge_lid);
}
prev_lid_battery_power = lid_battery_power;
@@ -720,30 +717,31 @@ static void charge_allocate_input_current_limit(void)
if (total_power > 0) { /* Charging */
/* Allocate system power */
CHG_ALLOCATE(power_base, total_power,
- db_policy.min_base_system_power);
+ db_policy.min_base_system_power);
CHG_ALLOCATE(power_lid, total_power, lid_system_power);
/* Allocate lid, then base battery power */
- lid_battery_power = add_margin(lid_battery_power,
- db_policy.margin_lid_battery_power);
+ lid_battery_power = add_margin(
+ lid_battery_power, db_policy.margin_lid_battery_power);
CHG_ALLOCATE(power_lid, total_power, lid_battery_power);
- base_battery_power = add_margin(base_battery_power,
- db_policy.margin_base_battery_power);
+ base_battery_power =
+ add_margin(base_battery_power,
+ db_policy.margin_base_battery_power);
CHG_ALLOCATE(power_base, total_power, base_battery_power);
/* Give everything else to the lid. */
CHG_ALLOCATE(power_lid, total_power, total_power);
if (debugging)
- CPRINTF("power: base %d mW / lid %d mW\n",
- power_base, power_lid);
+ CPRINTF("power: base %d mW / lid %d mW\n", power_base,
+ power_lid);
current_base = 1000 * power_base / curr.input_voltage;
current_lid = 1000 * power_lid / curr.input_voltage;
if (current_base > db_policy.max_lid_to_base_current) {
- current_lid += (current_base
- - db_policy.max_lid_to_base_current);
+ current_lid += (current_base -
+ db_policy.max_lid_to_base_current);
current_base = db_policy.max_lid_to_base_current;
}
@@ -760,12 +758,13 @@ static void charge_allocate_input_current_limit(void)
}
#endif /* CONFIG_EC_EC_COMM_BATTERY_CLIENT */
-static const char * const state_list[] = {
- "idle", "discharge", "charge", "precharge"
-};
+static const char *const state_list[] = { "idle", "discharge", "charge",
+ "precharge" };
BUILD_ASSERT(ARRAY_SIZE(state_list) == NUM_STATES_V2);
-static const char * const batt_pres[] = {
- "NO", "YES", "NOT_SURE",
+static const char *const batt_pres[] = {
+ "NO",
+ "YES",
+ "NOT_SURE",
};
const char *mode_text[] = EC_CHARGE_MODE_TEXT;
@@ -774,9 +773,9 @@ BUILD_ASSERT(ARRAY_SIZE(mode_text) == CHARGE_CONTROL_COUNT);
static void dump_charge_state(void)
{
#define DUMP(FLD, FMT) ccprintf(#FLD " = " FMT "\n", curr.FLD)
-#define DUMP_CHG(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.chg. FLD)
-#define DUMP_BATT(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.batt. FLD)
-#define DUMP_OCPC(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.ocpc. FLD)
+#define DUMP_CHG(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.chg.FLD)
+#define DUMP_BATT(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.batt.FLD)
+#define DUMP_OCPC(FLD, FMT) ccprintf("\t" #FLD " = " FMT "\n", curr.ocpc.FLD)
enum ec_charge_control_mode cmode = get_chg_ctrl_mode();
@@ -846,8 +845,8 @@ static void dump_charge_state(void)
ccprintf("battery_was_removed = %d\n", battery_was_removed);
ccprintf("debug output = %s\n", debugging ? "on" : "off");
ccprintf("Battery sustainer = %s (%d%% ~ %d%%)\n",
- battery_sustainer_enabled() ? "on" : "off",
- sustain_soc.lower, sustain_soc.upper);
+ battery_sustainer_enabled() ? "on" : "off", sustain_soc.lower,
+ sustain_soc.upper);
#undef DUMP
}
@@ -901,14 +900,13 @@ static void show_charging_progress(void)
dsoc = charge_get_display_charge();
if (rv)
CPRINTS("Battery %d%% (Display %d.%d %%) / ??h:?? %s%s",
- curr.batt.state_of_charge,
- dsoc / 10, dsoc % 10,
+ curr.batt.state_of_charge, dsoc / 10, dsoc % 10,
to_full ? "to full" : "to empty",
is_full ? ", not accepting current" : "");
else
CPRINTS("Battery %d%% (Display %d.%d %%) / %dh:%d %s%s",
- curr.batt.state_of_charge,
- dsoc / 10, dsoc % 10, minutes / 60, minutes % 60,
+ curr.batt.state_of_charge, dsoc / 10, dsoc % 10,
+ minutes / 60, minutes % 60,
to_full ? "to full" : "to empty",
is_full ? ", not accepting current" : "");
@@ -948,6 +946,11 @@ test_mockable int calc_is_full(void)
return ret;
}
+__overridable int board_should_charger_bypass(void)
+{
+ return false;
+}
+
/*
* Ask the charger for some voltage and current. If either value is 0,
* charging is disabled; otherwise it's enabled. Negative values are ignored.
@@ -956,6 +959,7 @@ static int charge_request(int voltage, int current)
{
int r1 = EC_SUCCESS, r2 = EC_SUCCESS, r3 = EC_SUCCESS, r4 = EC_SUCCESS;
static int prev_volt, prev_curr;
+ bool should_bypass;
if (!voltage || !current) {
#ifdef CONFIG_CHARGER_NARROW_VDC
@@ -983,6 +987,17 @@ static int charge_request(int voltage, int current)
}
/*
+ * Enable bypass mode if applicable. Transition from Bypass to Bypass +
+ * CHRG or backward is done after this call (by set_current & set_mode)
+ * thus not done here. Similarly, when bypass is disabled, transitioning
+ * from nvdc + chrg will be done separately.
+ */
+ should_bypass = board_should_charger_bypass();
+ if ((should_bypass && !(curr.chg.status & CHARGER_BYPASS_MODE)) ||
+ (!should_bypass && (curr.chg.status & CHARGER_BYPASS_MODE)))
+ charger_enable_bypass_mode(0, should_bypass);
+
+ /*
* Set current before voltage so that if we are just starting
* to charge, we allow some time (i2c delay) for charging circuit to
* start at a voltage just above battery voltage before jumping
@@ -1019,9 +1034,9 @@ static int charge_request(int voltage, int current)
*/
if (curr.ocpc.active_chg_chip == CHARGER_SECONDARY) {
if ((current >= 0) || (voltage >= 0))
- r3 = ocpc_config_secondary_charger(&curr.desired_input_current,
- &curr.ocpc,
- voltage, current);
+ r3 = ocpc_config_secondary_charger(
+ &curr.desired_input_current, &curr.ocpc,
+ voltage, current);
if (r3 != EC_SUCCESS)
charge_problem(PR_CFG_SEC_CHG, r3);
}
@@ -1140,9 +1155,8 @@ static inline int battery_too_low(void)
curr.batt.voltage <= batt_info->voltage_min));
}
-__attribute__((weak))
-enum critical_shutdown board_critical_shutdown_check(
- struct charge_state_data *curr)
+__attribute__((weak)) enum critical_shutdown
+board_critical_shutdown_check(struct charge_state_data *curr)
{
#ifdef CONFIG_BATTERY_CRITICAL_SHUTDOWN_CUT_OFF
return CRITICAL_SHUTDOWN_CUTOFF;
@@ -1173,21 +1187,21 @@ static int is_battery_critical(void)
}
if (battery_too_low() && !curr.batt_is_charging) {
- CPRINTS("Low battery: %d%%, %dmV",
- curr.batt.state_of_charge, curr.batt.voltage);
+ CPRINTS("Low battery: %d%%, %dmV", curr.batt.state_of_charge,
+ curr.batt.voltage);
return 1;
}
return 0;
}
- /*
- * If the battery is at extremely low charge (and discharging) or extremely
- * high temperature, the EC will notify the AP and start a timer. If the
- * critical condition is not corrected before the timeout expires, the EC
- * will shut down the AP (if the AP is not already off) and then optionally
- * hibernate or cut off battery.
- */
+/*
+ * If the battery is at extremely low charge (and discharging) or extremely
+ * high temperature, the EC will notify the AP and start a timer. If the
+ * critical condition is not corrected before the timeout expires, the EC
+ * will shut down the AP (if the AP is not already off) and then optionally
+ * hibernate or cut off battery.
+ */
static int shutdown_on_critical_battery(void)
{
if (!is_battery_critical()) {
@@ -1199,8 +1213,8 @@ static int shutdown_on_critical_battery(void)
if (!shutdown_target_time.val) {
/* Start count down timer */
CPRINTS("Start shutdown due to critical battery");
- shutdown_target_time.val = get_time().val
- + CRITICAL_BATTERY_SHUTDOWN_TIMEOUT_US;
+ shutdown_target_time.val =
+ get_time().val + CRITICAL_BATTERY_SHUTDOWN_TIMEOUT_US;
#ifdef CONFIG_HOSTCMD_EVENTS
if (!chipset_in_state(CHIPSET_STATE_ANY_OFF))
host_set_single_event(EC_HOST_EVENT_BATTERY_SHUTDOWN);
@@ -1245,14 +1259,36 @@ static int shutdown_on_critical_battery(void)
}
} else {
/* Timeout waiting for AP to shut down, so kill it */
- CPRINTS(
- "charge force shutdown due to critical battery");
+ CPRINTS("charge force shutdown due to critical battery");
chipset_force_shutdown(CHIPSET_SHUTDOWN_BATTERY_CRIT);
}
return 1;
}
+int battery_is_below_threshold(enum batt_threshold_type type, bool transitioned)
+{
+ int threshold;
+
+ /* We can't tell what the current charge is. Assume it's okay. */
+ if (curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE)
+ return 0;
+
+ switch (type) {
+ case BATT_THRESHOLD_TYPE_LOW:
+ threshold = BATTERY_LEVEL_LOW;
+ break;
+ case BATT_THRESHOLD_TYPE_SHUTDOWN:
+ threshold = CONFIG_BATT_HOST_SHUTDOWN_PERCENTAGE;
+ break;
+ default:
+ return 0;
+ }
+
+ return curr.batt.state_of_charge <= threshold &&
+ (!transitioned || prev_charge > threshold);
+}
+
/*
* Send host events as the battery charge drops below certain thresholds.
* We handle forced shutdown and other actions elsewhere; this is just for the
@@ -1261,17 +1297,11 @@ static int shutdown_on_critical_battery(void)
*/
static void notify_host_of_low_battery_charge(void)
{
- /* We can't tell what the current charge is. Assume it's okay. */
- if (curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE)
- return;
-
#ifdef CONFIG_HOSTCMD_EVENTS
- if (curr.batt.state_of_charge <= BATTERY_LEVEL_LOW &&
- prev_charge > BATTERY_LEVEL_LOW)
+ if (battery_is_below_threshold(BATT_THRESHOLD_TYPE_LOW, true))
host_set_single_event(EC_HOST_EVENT_BATTERY_LOW);
- if (curr.batt.state_of_charge <= BATTERY_LEVEL_CRITICAL &&
- prev_charge > BATTERY_LEVEL_CRITICAL)
+ if (battery_is_below_threshold(BATT_THRESHOLD_TYPE_SHUTDOWN, true))
host_set_single_event(EC_HOST_EVENT_BATTERY_CRITICAL);
#endif
}
@@ -1295,16 +1325,16 @@ static void notify_host_of_low_battery_voltage(void)
THROTTLE_SRC_BAT_VOLTAGE);
uvp_throttle_start_time = get_time();
} else if (uvp_throttle_start_time.val &&
- (curr.batt.voltage < BAT_LOW_VOLTAGE_THRESH +
- BAT_UVP_HYSTERESIS)) {
+ (curr.batt.voltage <
+ BAT_LOW_VOLTAGE_THRESH + BAT_UVP_HYSTERESIS)) {
/*
* Reset the timer when we are not sure if VBAT can stay
* above BAT_LOW_VOLTAGE_THRESH after we stop throttling.
*/
uvp_throttle_start_time = get_time();
} else if (uvp_throttle_start_time.val &&
- (get_time().val > uvp_throttle_start_time.val +
- BAT_UVP_TIMEOUT_US)) {
+ (get_time().val >
+ uvp_throttle_start_time.val + BAT_UVP_TIMEOUT_US)) {
throttle_ap(THROTTLE_OFF, THROTTLE_SOFT,
THROTTLE_SRC_BAT_VOLTAGE);
uvp_throttle_start_time.val = 0;
@@ -1328,8 +1358,8 @@ static void notify_host_of_over_current(struct batt_params *batt)
throttle_ap(THROTTLE_ON, THROTTLE_SOFT,
THROTTLE_SRC_BAT_DISCHG_CURRENT);
} else if (ocp_throttle_start_time.val &&
- (get_time().val > ocp_throttle_start_time.val +
- BAT_OCP_TIMEOUT_US)) {
+ (get_time().val >
+ ocp_throttle_start_time.val + BAT_OCP_TIMEOUT_US)) {
/*
* Clear the timer and notify AP to stop throttling if
* we haven't seen over current for BAT_OCP_TIMEOUT_US.
@@ -1361,8 +1391,8 @@ static int battery_outside_charging_temperature(void)
if (curr.batt.flags & BATT_FLAG_BAD_TEMPERATURE)
return 0;
- if((curr.batt.desired_voltage == 0) &&
- (curr.batt.desired_current == 0)){
+ if ((curr.batt.desired_voltage == 0) &&
+ (curr.batt.desired_current == 0)) {
max_c = batt_info->start_charging_max_c;
min_c = batt_info->start_charging_min_c;
} else {
@@ -1370,9 +1400,7 @@ static int battery_outside_charging_temperature(void)
min_c = batt_info->charging_min_c;
}
-
- if ((batt_temp_c >= max_c) ||
- (batt_temp_c <= min_c)) {
+ if ((batt_temp_c >= max_c) || (batt_temp_c <= min_c)) {
return 1;
}
return 0;
@@ -1385,8 +1413,8 @@ static void sustain_battery_soc(void)
int rv;
/* If either AC or battery is not present, nothing to do. */
- if (!curr.ac || curr.batt.is_present != BP_YES
- || !battery_sustainer_enabled())
+ if (!curr.ac || curr.batt.is_present != BP_YES ||
+ !battery_sustainer_enabled())
return;
soc = charge_get_display_charge() / 10;
@@ -1402,7 +1430,8 @@ static void sustain_battery_soc(void)
/* Going up */
if (sustain_soc.upper < soc)
mode = sustain_soc.upper == sustain_soc.lower ?
- CHARGE_CONTROL_IDLE : CHARGE_CONTROL_DISCHARGE;
+ CHARGE_CONTROL_IDLE :
+ CHARGE_CONTROL_DISCHARGE;
break;
case CHARGE_CONTROL_IDLE:
/* Discharging naturally */
@@ -1422,8 +1451,8 @@ static void sustain_battery_soc(void)
return;
rv = set_chg_ctrl_mode(mode);
- CPRINTS("%s: %s control mode to %s",
- __func__, rv == EC_SUCCESS ? "Switched" : "Failed to switch",
+ CPRINTS("%s: %s control mode to %s", __func__,
+ rv == EC_SUCCESS ? "Switched" : "Failed to switch",
mode_text[mode]);
}
@@ -1454,6 +1483,7 @@ static void charge_wakeup(void)
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME, charge_wakeup, HOOK_PRIO_DEFAULT);
DECLARE_HOOK(HOOK_AC_CHANGE, charge_wakeup, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_POWER_SUPPLY_CHANGE, charge_wakeup, HOOK_PRIO_DEFAULT);
#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
/* Reset the base on S5->S0 transition. */
@@ -1465,20 +1495,19 @@ static void bat_low_voltage_throttle_reset(void)
{
uvp_throttle_start_time.val = 0;
}
-DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN,
- bat_low_voltage_throttle_reset,
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, bat_low_voltage_throttle_reset,
HOOK_PRIO_DEFAULT);
#endif
static int get_desired_input_current(enum battery_present batt_present,
- const struct charger_info * const info)
+ const struct charger_info *const info)
{
if (batt_present == BP_YES || system_is_locked() || base_connected) {
#ifdef CONFIG_CHARGE_MANAGER
int ilim = charge_manager_get_charger_current();
return ilim == CHARGE_CURRENT_UNINITIALIZED ?
- CHARGE_CURRENT_UNINITIALIZED :
- MAX(CONFIG_CHARGER_INPUT_CURRENT, ilim);
+ CHARGE_CURRENT_UNINITIALIZED :
+ MAX(CONFIG_CHARGER_INPUT_CURRENT, ilim);
#else
return CONFIG_CHARGER_INPUT_CURRENT;
#endif
@@ -1498,9 +1527,9 @@ static void wakeup_battery(int *need_static)
set_charge_state(ST_IDLE);
curr.requested_voltage = 0;
curr.requested_current = 0;
- } else if (curr.state == ST_PRECHARGE
- && (get_time().val > precharge_start_time.val +
- PRECHARGE_TIMEOUT_US)) {
+ } else if (curr.state == ST_PRECHARGE &&
+ (get_time().val >
+ precharge_start_time.val + PRECHARGE_TIMEOUT_US)) {
/* We've tried long enough, give up */
CPRINTS("battery seems to be dead");
battery_seems_dead = 1;
@@ -1531,9 +1560,10 @@ static void deep_charge_battery(int *need_static)
/* Deep charge time out , do nothing */
curr.requested_voltage = 0;
curr.requested_current = 0;
- } else if (curr.state == ST_PRECHARGE
- && (get_time().val > precharge_start_time.val +
- CONFIG_BATTERY_LOW_VOLTAGE_TIMEOUT)) {
+ } else if (curr.state == ST_PRECHARGE &&
+ (get_time().val >
+ precharge_start_time.val +
+ CONFIG_BATTERY_LOW_VOLTAGE_TIMEOUT)) {
/* We've tried long enough, give up */
CPRINTS("Precharge for low voltage timed out");
set_charge_state(ST_IDLE);
@@ -1552,13 +1582,11 @@ static void deep_charge_battery(int *need_static)
}
}
-
static void revive_battery(int *need_static)
{
- if (IS_ENABLED(CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD)
- && curr.requested_voltage == 0
- && curr.requested_current == 0
- && curr.batt.state_of_charge == 0) {
+ if (IS_ENABLED(CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD) &&
+ curr.requested_voltage == 0 && curr.requested_current == 0 &&
+ curr.batt.state_of_charge == 0) {
/*
* Battery is dead, give precharge current
* TODO (crosbug.com/p/29467): remove this workaround
@@ -1566,10 +1594,9 @@ static void revive_battery(int *need_static)
*/
curr.requested_voltage = batt_info->voltage_max;
curr.requested_current = batt_info->precharge_current;
- } else if (IS_ENABLED(CONFIG_BATTERY_REVIVE_DISCONNECT)
- && curr.requested_voltage == 0
- && curr.requested_current == 0
- && battery_seems_disconnected) {
+ } else if (IS_ENABLED(CONFIG_BATTERY_REVIVE_DISCONNECT) &&
+ curr.requested_voltage == 0 && curr.requested_current == 0 &&
+ battery_seems_disconnected) {
/*
* Battery is in disconnect state. Apply a
* current to kick it out of this state.
@@ -1577,8 +1604,8 @@ static void revive_battery(int *need_static)
CPRINTS("found battery in disconnect state");
curr.requested_voltage = batt_info->voltage_max;
curr.requested_current = batt_info->precharge_current;
- } else if (curr.state == ST_PRECHARGE
- || battery_seems_dead || battery_was_removed) {
+ } else if (curr.state == ST_PRECHARGE || battery_seems_dead ||
+ battery_was_removed) {
CPRINTS("battery woke up");
/* Update the battery-specific values */
batt_info = battery_get_info();
@@ -1594,7 +1621,7 @@ void charger_task(void *u)
int sleep_usec;
int battery_critical;
int need_static = 1;
- const struct charger_info * const info = charger_get_info();
+ const struct charger_info *const info = charger_get_info();
int prev_plt_and_desired_mw;
int chgnum = 0;
@@ -1622,8 +1649,8 @@ void charger_task(void *u)
* as needed.
*/
prev_bp = BP_NOT_INIT;
- curr.desired_input_current = get_desired_input_current(
- curr.batt.is_present, info);
+ curr.desired_input_current =
+ get_desired_input_current(curr.batt.is_present, info);
if (IS_ENABLED(CONFIG_USB_PD_PREFER_MV)) {
/* init battery desired power */
@@ -1640,7 +1667,6 @@ void charger_task(void *u)
battery_level_shutdown = board_set_battery_level_shutdown();
while (1) {
-
/* Let's see what's going on... */
curr.ts = get_time();
sleep_usec = 0;
@@ -1657,8 +1683,8 @@ void charger_task(void *u)
curr.ac = 0;
/* System is off: if AC gets connected, reset the base. */
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF) &&
- !prev_ac && curr.ac)
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF) && !prev_ac &&
+ curr.ac)
board_base_reset();
#endif
if (curr.ac != prev_ac) {
@@ -1679,7 +1705,7 @@ void charger_task(void *u)
if (rv != EC_SUCCESS) {
charge_problem(PR_POST_INIT, rv);
} else if (curr.desired_input_current !=
- CHARGE_CURRENT_UNINITIALIZED) {
+ CHARGE_CURRENT_UNINITIALIZED) {
rv = charger_set_input_current_limit(
chgnum,
curr.desired_input_current);
@@ -1727,8 +1753,8 @@ void charger_task(void *u)
get_desired_input_current(prev_bp, info);
if (curr.desired_input_current !=
CHARGE_CURRENT_UNINITIALIZED)
- charger_set_input_current_limit(chgnum,
- curr.desired_input_current);
+ charger_set_input_current_limit(
+ chgnum, curr.desired_input_current);
hook_notify(HOOK_BATTERY_SOC_CHANGE);
}
@@ -1749,7 +1775,7 @@ void charger_task(void *u)
* applying power to a battery we can't talk to.
*/
if (curr.batt.flags & (BATT_FLAG_BAD_DESIRED_VOLTAGE |
- BATT_FLAG_BAD_DESIRED_CURRENT)) {
+ BATT_FLAG_BAD_DESIRED_CURRENT)) {
curr.requested_voltage = 0;
curr.requested_current = 0;
} else {
@@ -1805,9 +1831,9 @@ void charger_task(void *u)
goto wait_for_it;
}
- if (IS_ENABLED(CONFIG_BATTERY_LOW_VOLTAGE_PROTECTION)
- && !(curr.batt.flags & BATT_FLAG_BAD_VOLTAGE)
- && (curr.batt.voltage <= batt_info->voltage_min)) {
+ if (IS_ENABLED(CONFIG_BATTERY_LOW_VOLTAGE_PROTECTION) &&
+ !(curr.batt.flags & BATT_FLAG_BAD_VOLTAGE) &&
+ (curr.batt.voltage <= batt_info->voltage_min)) {
deep_charge_battery(&need_static);
goto wait_for_it;
}
@@ -1819,23 +1845,23 @@ void charger_task(void *u)
* the battery disconnect state is one of the items used
* to decide whether or not to leave safe mode.
*/
- battery_seems_disconnected =
- battery_get_disconnect_state() == BATTERY_DISCONNECTED;
+ battery_seems_disconnected = battery_get_disconnect_state() ==
+ BATTERY_DISCONNECTED;
revive_battery(&need_static);
set_charge_state(ST_CHARGE);
-wait_for_it:
- if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE)
- && get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL) {
+ wait_for_it:
+ if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE) &&
+ get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL) {
sleep_usec = charger_profile_override(&curr);
if (sleep_usec < 0)
charge_problem(PR_CUSTOM, sleep_usec);
}
- if (IS_ENABLED(CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS)
- && battery_outside_charging_temperature()) {
+ if (IS_ENABLED(CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS) &&
+ battery_outside_charging_temperature()) {
curr.requested_current = 0;
curr.requested_voltage = 0;
curr.batt.flags &= ~BATT_FLAG_WANT_CHARGE;
@@ -1845,23 +1871,8 @@ wait_for_it:
#ifdef CONFIG_CHARGE_MANAGER
if (curr.batt.state_of_charge >=
- CONFIG_CHARGE_MANAGER_BAT_PCT_SAFE_MODE_EXIT &&
+ CONFIG_CHARGE_MANAGER_BAT_PCT_SAFE_MODE_EXIT &&
!battery_seems_disconnected) {
- /*
- * Sometimes the fuel gauge will report that it has
- * sufficient state of charge and remaining capacity,
- * but in actuality it doesn't. When the EC sees that
- * information, it trusts it and leaves charge manager
- * safe mode. Doing so will allow CHARGE_PORT_NONE to
- * be selected, thereby cutting off the input FETs.
- * When the battery cannot provide the charge it claims,
- * the system loses power, shuts down, and the battery
- * is not charged even though the charger is plugged in.
- * By waiting 500ms, we can avoid the selection of
- * CHARGE_PORT_NONE around init time and not cut off the
- * input FETs.
- */
- msleep(500);
charge_manager_leave_safe_mode();
}
#endif
@@ -1882,12 +1893,11 @@ wait_for_it:
sustain_battery_soc();
if ((!(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
- curr.batt.state_of_charge != prev_charge) ||
+ curr.batt.state_of_charge != prev_charge) ||
#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
(charge_base != prev_charge_base) ||
#endif
- (is_full != prev_full) ||
- (curr.state != prev_state) ||
+ (is_full != prev_full) || (curr.state != prev_state) ||
(charge_get_display_charge() != prev_disp_charge)) {
show_charging_progress();
prev_charge = curr.batt.state_of_charge;
@@ -1968,9 +1978,8 @@ wait_for_it:
sleep_usec = CHARGE_POLL_PERIOD_SHORT;
else if (sleep_usec <= 0) {
/* default values depend on the state */
- if (!curr.ac &&
- (curr.state == ST_IDLE ||
- curr.state == ST_DISCHARGE)) {
+ if (!curr.ac && (curr.state == ST_IDLE ||
+ curr.state == ST_DISCHARGE)) {
#ifdef CONFIG_CHARGER_OTG
int output_current = curr.output_current;
#else
@@ -1980,9 +1989,10 @@ wait_for_it:
* If AP is off and we do not provide power, we
* can sleep a long time.
*/
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF |
- CHIPSET_STATE_ANY_SUSPEND)
- && output_current == 0)
+ if (chipset_in_state(
+ CHIPSET_STATE_ANY_OFF |
+ CHIPSET_STATE_ANY_SUSPEND) &&
+ output_current == 0)
sleep_usec =
CHARGE_POLL_PERIOD_VERY_LONG;
else
@@ -2062,15 +2072,14 @@ wait_for_it:
}
}
-
/*****************************************************************************/
/* Exported functions */
int charge_want_shutdown(void)
{
return (curr.state == ST_DISCHARGE) &&
- !(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
- (curr.batt.state_of_charge < battery_level_shutdown);
+ !(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
+ (curr.batt.state_of_charge < battery_level_shutdown);
}
int charge_prevent_power_on(int power_button_pressed)
@@ -2103,14 +2112,14 @@ int charge_prevent_power_on(int power_button_pressed)
if (current_batt_params->is_present != BP_YES ||
#ifdef CONFIG_BATTERY_MEASURE_IMBALANCE
(current_batt_params->flags & BATT_FLAG_IMBALANCED_CELL &&
- current_batt_params->state_of_charge <
- CONFIG_CHARGER_MIN_BAT_PCT_IMBALANCED_POWER_ON) ||
+ current_batt_params->state_of_charge <
+ CONFIG_CHARGER_MIN_BAT_PCT_IMBALANCED_POWER_ON) ||
#endif
#ifdef CONFIG_BATTERY_REVIVE_DISCONNECT
battery_get_disconnect_state() != BATTERY_NOT_DISCONNECTED ||
#endif
current_batt_params->state_of_charge <
- CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON)
+ CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON)
prevent_power_on = 1;
#if defined(CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON) && \
@@ -2123,13 +2132,14 @@ int charge_prevent_power_on(int power_button_pressed)
#if defined(CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON_WITH_BATT) && \
defined(CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC)
else if (charge_manager_get_power_limit_uw() >=
- CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON_WITH_BATT * 1000
+ CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON_WITH_BATT *
+ 1000
#ifdef CONFIG_BATTERY_REVIVE_DISCONNECT
- && battery_get_disconnect_state() ==
- BATTERY_NOT_DISCONNECTED
+ && battery_get_disconnect_state() ==
+ BATTERY_NOT_DISCONNECTED
#endif
- && (current_batt_params->state_of_charge >=
- CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC))
+ && (current_batt_params->state_of_charge >=
+ CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON_WITH_AC))
prevent_power_on = 0;
#endif
}
@@ -2140,18 +2150,18 @@ int charge_prevent_power_on(int power_button_pressed)
* except when auto-power-on at EC startup and the battery
* is physically present.
*/
- prevent_power_on &= (system_is_locked() || (automatic_power_on
+ prevent_power_on &=
+ (system_is_locked() || (automatic_power_on
#ifdef CONFIG_BATTERY_HW_PRESENT_CUSTOM
- && battery_hw_present() == BP_YES
+ && battery_hw_present() == BP_YES
#endif
- ));
+ ));
#endif /* CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON */
#ifdef CONFIG_CHARGE_MANAGER
/* Always prevent power on until charge current is initialized */
- if (extpower_is_present() &&
- (charge_manager_get_charger_current() ==
- CHARGE_CURRENT_UNINITIALIZED))
+ if (extpower_is_present() && (charge_manager_get_charger_current() ==
+ CHARGE_CURRENT_UNINITIALIZED))
prevent_power_on = 1;
#ifdef CONFIG_BATTERY_HW_PRESENT_CUSTOM
/*
@@ -2161,19 +2171,19 @@ int charge_prevent_power_on(int power_button_pressed)
if (extpower_is_present() && battery_hw_present() == BP_NO
#ifdef CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON
&& charge_manager_get_power_limit_uw() <
- CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON * 1000
+ CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON * 1000
#endif /* CONFIG_CHARGER_MIN_POWER_MW_FOR_POWER_ON */
- )
+ )
prevent_power_on = 1;
#endif /* CONFIG_BATTERY_HW_PRESENT_CUSTOM */
#endif /* CONFIG_CHARGE_MANAGER */
- /*
- * Prevent power on if there is no battery nor ac power. This
- * happens when the servo is powering the EC to flash it. Only include
- * this logic for boards in initial bring up phase since this won't
- * happen for released boards.
- */
+ /*
+ * Prevent power on if there is no battery nor ac power. This
+ * happens when the servo is powering the EC to flash it. Only
+ * include this logic for boards in initial bring up phase since
+ * this won't happen for released boards.
+ */
#ifdef CONFIG_SYSTEM_UNLOCKED
if (!current_batt_params->is_present && !curr.ac)
prevent_power_on = 1;
@@ -2197,11 +2207,19 @@ static int battery_near_full(void)
enum charge_state charge_get_state(void)
{
+ uint32_t chflags;
+
switch (curr.state) {
case ST_IDLE:
+ chflags = charge_get_flags();
+
if (battery_seems_dead || curr.batt.is_present == BP_NO)
return PWR_STATE_ERROR;
- return PWR_STATE_IDLE;
+
+ if (chflags & CHARGE_FLAG_FORCE_IDLE)
+ return PWR_STATE_FORCED_IDLE;
+ else
+ return PWR_STATE_IDLE;
case ST_DISCHARGE:
#ifdef CONFIG_PWR_STATE_DISCHARGE_FULL
if (battery_near_full())
@@ -2219,8 +2237,13 @@ enum charge_state charge_get_state(void)
else
return PWR_STATE_CHARGE;
case ST_PRECHARGE:
+ chflags = charge_get_flags();
+
/* we're in battery discovery mode */
- return PWR_STATE_IDLE;
+ if (chflags & CHARGE_FLAG_FORCE_IDLE)
+ return PWR_STATE_FORCED_IDLE;
+ else
+ return PWR_STATE_IDLE;
default:
/* Anything else can be considered an error for LED purposes */
return PWR_STATE_ERROR;
@@ -2317,8 +2340,7 @@ int charge_set_input_current_limit(int ma, int mv)
* browning out due to insufficient input current.
*/
if (curr.batt.is_present != BP_YES && !system_is_locked() &&
- !base_connected) {
-
+ !base_connected) {
int prev_input = 0;
charger_get_input_current_limit(chgnum, &prev_input);
@@ -2333,8 +2355,8 @@ int charge_set_input_current_limit(int ma, int mv)
* input system power.
*/
- if (mv > 0 && mv * curr.desired_input_current >
- PD_MAX_POWER_MW * 1000)
+ if (mv > 0 &&
+ mv * curr.desired_input_current > PD_MAX_POWER_MW * 1000)
ma = (PD_MAX_POWER_MW * 1000) / mv;
/*
* If the active charger has already been initialized to at
@@ -2346,11 +2368,11 @@ int charge_set_input_current_limit(int ma, int mv)
if (prev_input >= ma)
return EC_SUCCESS;
#endif
- /*
- * If the current needs lowered due to PD max power
- * considerations, or needs raised for the selected active
- * charger chip, fall through to set.
- */
+ /*
+ * If the current needs lowered due to PD max power
+ * considerations, or needs raised for the selected
+ * active charger chip, fall through to set.
+ */
#endif /* CONFIG_USB_POWER_DELIVERY */
}
@@ -2468,8 +2490,8 @@ charge_command_charge_control(struct host_cmd_handler_args *args)
if (p->cmd == EC_CHARGE_CONTROL_CMD_SET) {
if (p->mode == CHARGE_CONTROL_NORMAL) {
rv = battery_sustainer_set(
- p->sustain_soc.lower,
- p->sustain_soc.upper);
+ p->sustain_soc.lower,
+ p->sustain_soc.upper);
if (rv == EC_RES_UNAVAILABLE)
return EC_RES_UNAVAILABLE;
if (rv)
@@ -2565,7 +2587,6 @@ charge_command_charge_state(struct host_cmd_handler_args *args)
chgnum = in->chgnum;
switch (in->cmd) {
-
case CHARGE_STATE_CMD_GET_STATE:
out->get_state.ac = curr.ac;
out->get_state.chg_voltage = curr.chg.voltage;
@@ -2577,18 +2598,18 @@ charge_command_charge_state(struct host_cmd_handler_args *args)
case CHARGE_STATE_CMD_GET_PARAM:
val = 0;
- if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE)
- && in->get_param.param >= CS_PARAM_CUSTOM_PROFILE_MIN
- && in->get_param.param <= CS_PARAM_CUSTOM_PROFILE_MAX) {
+ if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE) &&
+ in->get_param.param >= CS_PARAM_CUSTOM_PROFILE_MIN &&
+ in->get_param.param <= CS_PARAM_CUSTOM_PROFILE_MAX) {
/* custom profile params */
- rv = charger_profile_override_get_param(
+ rv = charger_profile_override_get_param(
in->get_param.param, &val);
- } else if (IS_ENABLED(CONFIG_CHARGE_STATE_DEBUG)
- && in->get_param.param >= CS_PARAM_DEBUG_MIN
- && in->get_param.param <= CS_PARAM_DEBUG_MAX) {
+ } else if (IS_ENABLED(CONFIG_CHARGE_STATE_DEBUG) &&
+ in->get_param.param >= CS_PARAM_DEBUG_MIN &&
+ in->get_param.param <= CS_PARAM_DEBUG_MAX) {
/* debug params */
- rv = charge_get_charge_state_debug(
- in->get_param.param, &val);
+ rv = charge_get_charge_state_debug(in->get_param.param,
+ &val);
} else {
/* standard params */
switch (in->get_param.param) {
@@ -2615,10 +2636,11 @@ charge_command_charge_state(struct host_cmd_handler_args *args)
*/
if ((curr.batt.is_present != BP_YES ||
curr.batt.state_of_charge <
- CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT)
- && charge_manager_get_power_limit_uw() <
- CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW
- * 1000 && system_is_locked())
+ CONFIG_CHARGER_LIMIT_POWER_THRESH_BAT_PCT) &&
+ charge_manager_get_power_limit_uw() <
+ CONFIG_CHARGER_LIMIT_POWER_THRESH_CHG_MW *
+ 1000 &&
+ system_is_locked())
val = 1;
else
#endif
@@ -2639,11 +2661,11 @@ charge_command_charge_state(struct host_cmd_handler_args *args)
return EC_RES_ACCESS_DENIED;
val = in->set_param.value;
- if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE)
- && in->set_param.param >= CS_PARAM_CUSTOM_PROFILE_MIN
- && in->set_param.param <= CS_PARAM_CUSTOM_PROFILE_MAX) {
+ if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE) &&
+ in->set_param.param >= CS_PARAM_CUSTOM_PROFILE_MIN &&
+ in->set_param.param <= CS_PARAM_CUSTOM_PROFILE_MAX) {
/* custom profile params */
- rv = charger_profile_override_set_param(
+ rv = charger_profile_override_set_param(
in->set_param.param, val);
} else {
switch (in->set_param.param) {
@@ -2669,7 +2691,6 @@ charge_command_charge_state(struct host_cmd_handler_args *args)
break;
default:
rv = EC_RES_INVALID_PARAM;
-
}
}
break;
@@ -2690,7 +2711,7 @@ DECLARE_HOST_COMMAND(EC_CMD_CHARGE_STATE, charge_command_charge_state,
#ifdef CONFIG_CMD_PWR_AVG
-static int command_pwr_avg(int argc, char **argv)
+static int command_pwr_avg(int argc, const char **argv)
{
int avg_mv;
int avg_ma;
@@ -2705,18 +2726,16 @@ static int command_pwr_avg(int argc, char **argv)
avg_ma = battery_get_avg_current();
avg_mw = avg_mv * avg_ma / 1000;
- ccprintf("mv = %d\nma = %d\nmw = %d\n",
- avg_mv, avg_ma, avg_mw);
+ ccprintf("mv = %d\nma = %d\nmw = %d\n", avg_mv, avg_ma, avg_mw);
return EC_SUCCESS;
}
-DECLARE_CONSOLE_COMMAND(pwr_avg, command_pwr_avg,
- NULL,
+DECLARE_CONSOLE_COMMAND(pwr_avg, command_pwr_avg, NULL,
"Get 1 min power average");
#endif /* CONFIG_CMD_PWR_AVG */
-static int command_chgstate(int argc, char **argv)
+static int command_chgstate(int argc, const char **argv)
{
int rv;
int val;
@@ -2729,7 +2748,7 @@ static int command_chgstate(int argc, char **argv)
if (!parse_bool(argv[2], &val))
return EC_ERROR_PARAM2;
rv = set_chg_ctrl_mode(val ? CHARGE_CONTROL_IDLE :
- CHARGE_CONTROL_NORMAL);
+ CHARGE_CONTROL_NORMAL);
if (rv)
return rv;
} else if (!strcasecmp(argv[1], "discharge")) {
@@ -2738,7 +2757,7 @@ static int command_chgstate(int argc, char **argv)
if (!parse_bool(argv[2], &val))
return EC_ERROR_PARAM2;
rv = set_chg_ctrl_mode(val ? CHARGE_CONTROL_DISCHARGE :
- CHARGE_CONTROL_NORMAL);
+ CHARGE_CONTROL_NORMAL);
if (rv)
return rv;
} else if (!strcasecmp(argv[1], "debug")) {
@@ -2774,7 +2793,7 @@ DECLARE_CONSOLE_COMMAND(chgstate, command_chgstate,
"Get/set charge state machine status");
#ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT
-static int command_chgdualdebug(int argc, char **argv)
+static int command_chgdualdebug(int argc, const char **argv)
{
int val;
char *e;
@@ -2812,9 +2831,8 @@ static int command_chgdualdebug(int argc, char **argv)
return EC_ERROR_PARAM1;
}
} else {
- ccprintf("Base/Lid: %d%s/%d mA\n",
- prev_current_base, prev_allow_charge_base ? "+" : "",
- prev_current_lid);
+ ccprintf("Base/Lid: %d%s/%d mA\n", prev_current_base,
+ prev_allow_charge_base ? "+" : "", prev_current_lid);
}
return EC_SUCCESS;