summaryrefslogtreecommitdiff
path: root/common/charge_state_v2.c
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-12-17 13:22:36 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-03 02:26:21 +0000
commit2b0895179733852a7eb13051ad99a494af5cc3bd (patch)
tree557338d88ec7a20212bc8c4f457d7867073513a5 /common/charge_state_v2.c
parenta3f3e38da09eb196a5773021a54832a553c206e3 (diff)
downloadchrome-ec-2b0895179733852a7eb13051ad99a494af5cc3bd.tar.gz
samus: when battery is full, and not in S0, stop charging
When battery is full and system is not in S0, then stop charging and allow battery to power the system. Once battery is no longer full and requests current, allow charging again. This is to work around power consumption issues in our AC input path. The charge override port is stored upon entering S3 and restored going back to S0 so that the charge override port is not affected by this. This also fixes lightbar so lightbar checks if battery is full instead of checking raw percentage. The lightbar is also changed to use the last tap direction if no charger is plugged in. And the lightbar tap for battery threshold for turning green is lowered to 95%. This also moves some samus_pd board code out of interrupt handlers and in to deferred functions to minimize time in interrupts. BUG=chrome-os-partner:34640, chrome-os-partner:34847 BRANCH=samus TEST=load onto samus. use battfake command from pd console to set battery percentage. when system is in G3, see that batt = 100% stops charging, and when batt < 100% it starts charging again. tested that we receive host command from EC with battery information every time battery changes SOC. Change-Id: Ia8e0721508e34ee3630f5e5b0c2f431a00329caf Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/236411 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r--common/charge_state_v2.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index de7cfea731..051113c0e2 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -39,7 +39,8 @@
*/
static const struct battery_info *batt_info;
static struct charge_state_data curr;
-static int prev_ac, prev_charge;
+static int prev_ac, prev_charge, prev_full;
+static int is_full; /* battery not accepting current */
static int state_machine_force_idle;
static int manual_mode; /* volt/curr are no longer maintained by charger */
static unsigned int user_current_limit = -1U;
@@ -275,14 +276,16 @@ static void show_charging_progress(void)
}
if (rv)
- CPRINTS("Battery %d%% / ??h:?? %s",
+ CPRINTS("Battery %d%% / ??h:?? %s%s",
curr.batt.state_of_charge,
- to_full ? "to full" : "to empty");
+ to_full ? "to full" : "to empty",
+ is_full ? ", not accepting current" : "");
else
- CPRINTS("Battery %d%% / %dh:%d %s",
+ CPRINTS("Battery %d%% / %dh:%d %s%s",
curr.batt.state_of_charge,
minutes / 60, minutes % 60,
- to_full ? "to full" : "to empty");
+ to_full ? "to full" : "to empty",
+ is_full ? ", not accepting current" : "");
if (debugging) {
ccprintf("battery:\n");
@@ -294,6 +297,26 @@ static void show_charging_progress(void)
}
}
+/* Calculate if battery is full based on whether it is accepting charge */
+static int calc_is_full(void)
+{
+ static int ret;
+
+ /* If bad state of charge reading, return last value */
+ if (curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE ||
+ curr.batt.state_of_charge > 100)
+ return ret;
+ /*
+ * Battery is full when SoC is above 90% and battery desired current
+ * is 0. This is necessary because some batteries stop charging when
+ * the SoC still reports <100%, so we need to check desired current
+ * to know if it is actually full.
+ */
+ ret = (curr.batt.state_of_charge >= 90 &&
+ curr.batt.desired_current == 0);
+ return ret;
+}
+
/*
* Ask the charger for some voltage and current. If either value is 0,
* charging is disabled; otherwise it's enabled. Negative values are ignored.
@@ -732,11 +755,17 @@ wait_for_it:
notify_host_of_low_battery();
/* And the EC console */
- if (!(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
- curr.batt.state_of_charge != prev_charge) {
+ is_full = calc_is_full();
+ if ((!(curr.batt.flags & BATT_FLAG_BAD_STATE_OF_CHARGE) &&
+ curr.batt.state_of_charge != prev_charge) ||
+ (is_full != prev_full)) {
show_charging_progress();
prev_charge = curr.batt.state_of_charge;
+#ifdef HAS_TASK_PDCMD
+ host_command_pd_send_status();
+#endif
}
+ prev_full = is_full;
/* Turn charger off if it's not needed */
if (curr.state == ST_IDLE || curr.state == ST_DISCHARGE) {
@@ -882,7 +911,7 @@ int charge_get_percent(void)
* to the battery, that'll be zero, which is probably as good as
* anything.
*/
- return curr.batt.state_of_charge;
+ return is_full ? 100 : curr.batt.state_of_charge;
}
int charge_temp_sensor_get_val(int idx, int *temp_ptr)