summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce <Bruce.Wan@quantatw.com>2016-12-30 14:54:21 +0800
committerchrome-bot <chrome-bot@chromium.org>2017-01-02 20:57:19 -0800
commita80a815ea2f915cf14b6526f352521765c47add2 (patch)
treee27eee3e1a192466adff1d49364d8fbe037a2b61
parentbcffec7fdc50e959cb298d094d8af472777dba75 (diff)
downloadchrome-ec-a80a815ea2f915cf14b6526f352521765c47add2.tar.gz
pyro/snappy: Do not discharge on AC when battery is still waking up
Follow reef setting. discharges on AC till the charger is detected and settled but when booting from the cut-off mode this will kill the power hence do not discharge on AC when battery is still waking up and settled. BUG=none BRANCH=reef TEST=make buildall Change-Id: I09d8f5a363d20bb3d0df80694de52ae3a37a0ed9 Signed-off-by: Bruce.Wan <Bruce.Wan@quantatw.com> Reviewed-on: https://chromium-review.googlesource.com/422621 Commit-Ready: Keith Tzeng <keith.tzeng@quantatw.com> Tested-by: Keith Tzeng <keith.tzeng@quantatw.com> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r--board/pyro/battery.c66
-rw-r--r--board/snappy/battery.c66
2 files changed, 82 insertions, 50 deletions
diff --git a/board/pyro/battery.c b/board/pyro/battery.c
index a0c9244514..9d2294bb9c 100644
--- a/board/pyro/battery.c
+++ b/board/pyro/battery.c
@@ -193,6 +193,46 @@ enum battery_disconnect_state battery_get_disconnect_state(void)
static int fast_charging_allowed = 1;
+static int charger_should_discharge_on_ac(struct charge_state_data *curr)
+{
+ /* can not discharge on AC without battery */
+ if (curr->batt.is_present != BP_YES)
+ return 0;
+
+ /* Do not discharge on AC if the battery is still waking up */
+ if (!(curr->batt.flags & BATT_FLAG_WANT_CHARGE) &&
+ !(curr->batt.status & STATUS_FULLY_CHARGED))
+ return 0;
+
+ /*
+ * In light load (<450mA being withdrawn from VSYS) the DCDC of the
+ * charger operates intermittently i.e. DCDC switches continuously
+ * and then stops to regulate the output voltage and current, and
+ * sometimes to prevent reverse current from flowing to the input.
+ * This causes a slight voltage ripple on VSYS that falls in the
+ * audible noise frequency (single digit kHz range). This small
+ * ripple generates audible noise in the output ceramic capacitors
+ * (caps on VSYS and any input of DCDC under VSYS).
+ *
+ * To overcome this issue enable the battery learning operation
+ * and suspend USB charging and DC/DC converter.
+ */
+ if (!battery_is_cut_off() &&
+ !(curr->batt.flags & BATT_FLAG_WANT_CHARGE) &&
+ (curr->batt.status & STATUS_FULLY_CHARGED))
+ return 1;
+
+ /*
+ * To avoid inrush current from the external charger, enable
+ * discharge on AC till the new charger is detected and charge
+ * detect delay has passed.
+ */
+ if (!chg_ramp_is_detected() && curr->batt.state_of_charge > 2)
+ return 1;
+
+ return 0;
+}
+
/*
* This can override the smart battery's charging profile. To make a change,
* modify one or more of requested_voltage, requested_current, or state.
@@ -223,31 +263,7 @@ int charger_profile_override(struct charge_state_data *curr)
/* Current and previous battery voltage */
int batt_voltage;
static int prev_batt_voltage;
- int disch_on_ac;
-
- /*
- * In light load (<450mA being withdrawn from VSYS) the DCDC of the
- * charger operates intermittently i.e. DCDC switches continuously
- * and then stops to regulate the output voltage and current, and
- * sometimes to prevent reverse current from flowing to the input.
- * This causes a slight voltage ripple on VSYS that falls in the
- * audible noise frequency (single digit kHz range). This small
- * ripple generates audible noise in the output ceramic capacitors
- * (caps on VSYS and any input of DCDC under VSYS).
- *
- * To overcome this issue enable the battery learning operation
- * and suspend USB charging and DC/DC converter.
- *
- * And also to avoid inrush current from the external charger, enable
- * discharge on AC till the new charger is detected and charge detect
- * delay has passed.
- */
- disch_on_ac = (curr->batt.is_present == BP_YES &&
- !battery_is_cut_off() &&
- !(curr->batt.flags & BATT_FLAG_WANT_CHARGE) &&
- curr->batt.status & STATUS_FULLY_CHARGED;
- (!chg_ramp_is_detected() &&
- curr->batt.state_of_charge > 2);
+ int disch_on_ac = charger_should_discharge_on_ac(curr);
charger_discharge_on_ac(disch_on_ac);
diff --git a/board/snappy/battery.c b/board/snappy/battery.c
index 4991c9cfeb..c192edc2b1 100644
--- a/board/snappy/battery.c
+++ b/board/snappy/battery.c
@@ -121,6 +121,46 @@ enum battery_disconnect_state battery_get_disconnect_state(void)
static int fast_charging_allowed = 1;
+static int charger_should_discharge_on_ac(struct charge_state_data *curr)
+{
+ /* can not discharge on AC without battery */
+ if (curr->batt.is_present != BP_YES)
+ return 0;
+
+ /* Do not discharge on AC if the battery is still waking up */
+ if (!(curr->batt.flags & BATT_FLAG_WANT_CHARGE) &&
+ !(curr->batt.status & STATUS_FULLY_CHARGED))
+ return 0;
+
+ /*
+ * In light load (<450mA being withdrawn from VSYS) the DCDC of the
+ * charger operates intermittently i.e. DCDC switches continuously
+ * and then stops to regulate the output voltage and current, and
+ * sometimes to prevent reverse current from flowing to the input.
+ * This causes a slight voltage ripple on VSYS that falls in the
+ * audible noise frequency (single digit kHz range). This small
+ * ripple generates audible noise in the output ceramic capacitors
+ * (caps on VSYS and any input of DCDC under VSYS).
+ *
+ * To overcome this issue enable the battery learning operation
+ * and suspend USB charging and DC/DC converter.
+ */
+ if (!battery_is_cut_off() &&
+ !(curr->batt.flags & BATT_FLAG_WANT_CHARGE) &&
+ (curr->batt.status & STATUS_FULLY_CHARGED))
+ return 1;
+
+ /*
+ * To avoid inrush current from the external charger, enable
+ * discharge on AC till the new charger is detected and charge
+ * detect delay has passed.
+ */
+ if (!chg_ramp_is_detected() && curr->batt.state_of_charge > 2)
+ return 1;
+
+ return 0;
+}
+
/*
* This can override the smart battery's charging profile. To make a change,
* modify one or more of requested_voltage, requested_current, or state.
@@ -151,31 +191,7 @@ int charger_profile_override(struct charge_state_data *curr)
/* Current and previous battery voltage */
int batt_voltage;
static int prev_batt_voltage;
- int disch_on_ac;
-
- /*
- * In light load (<450mA being withdrawn from VSYS) the DCDC of the
- * charger operates intermittently i.e. DCDC switches continuously
- * and then stops to regulate the output voltage and current, and
- * sometimes to prevent reverse current from flowing to the input.
- * This causes a slight voltage ripple on VSYS that falls in the
- * audible noise frequency (single digit kHz range). This small
- * ripple generates audible noise in the output ceramic capacitors
- * (caps on VSYS and any input of DCDC under VSYS).
- *
- * To overcome this issue enable the battery learning operation
- * and suspend USB charging and DC/DC converter.
- *
- * And also to avoid inrush current from the external charger, enable
- * discharge on AC till the new charger is detected and charge detect
- * delay has passed.
- */
- disch_on_ac = (curr->batt.is_present == BP_YES &&
- !battery_is_cut_off() &&
- !(curr->batt.flags & BATT_FLAG_WANT_CHARGE) &&
- curr->batt.status & STATUS_FULLY_CHARGED;
- (!chg_ramp_is_detected() &&
- curr->batt.state_of_charge > 2);
+ int disch_on_ac = charger_should_discharge_on_ac(curr);
charger_discharge_on_ac(disch_on_ac);