summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bresticker <abrestic@chromium.org>2014-06-09 16:01:19 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-07-08 02:13:20 +0000
commitb1dec633cb59fa79d4d9c4d2104eba84f280d7b2 (patch)
tree5e4e35865129cfd6d8ddff1f49dac748c62736c4
parent9ba7bd4284eb8aac2347f3a71fc830c59ccbe387 (diff)
downloadchrome-ec-b1dec633cb59fa79d4d9c4d2104eba84f280d7b2.tar.gz
charger v2: set charger mode when requesting current/voltage
(cherry-pick back to ToT) Clear the CHARGE_INHIBIT bit when requesting non-zero current/voltage and set it when charging should be disabled. On Blaze with the BQ24725 charger, setting this bit saves 10-15mW when we're not on AC. This also fixes an issue where battery charging would not get enabled when the charger is connected while the machine is in S3/S5. This is because the kernel driver would inhibit charging when the charger was removed and then the EC would not enable it when the charger was re-connected while the host was off, such as in S3/S5. BRANCH=nyan BUG=chrome-os-partner:29386 TEST=Boot Blaze, disconnect charger, suspend, connect charger and observe that the battery now starts charging. Signed-off-by: Andrew Bresticker <abrestic@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/203163 Reviewed-by: Randall Spangler <rspangler@chromium.org> (cherry picked from commit bd4469ae4ffbbd6f2cd5549bdb8809838e55d6f7) Change-Id: Ibcb635b01a2292f214f71ab400ec34cd12e7536f Original-Change-Id: I2efaf02296dc08c0de85950a70ad2592f4428241 Reviewed-on: https://chromium-review.googlesource.com/206909 Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Yung-chieh Lo <yjlou@chromium.org> Tested-by: Yung-chieh Lo <yjlou@chromium.org>
-rw-r--r--common/charge_state_v2.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index ba88aabc2d..5b9d32ba89 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -6,6 +6,7 @@
*/
#include "battery.h"
+#include "battery_smart.h"
#include "charge_state.h"
#include "charger.h"
#include "chipset.h"
@@ -50,6 +51,7 @@ enum problem_type {
PR_STATIC_UPDATE,
PR_SET_VOLTAGE,
PR_SET_CURRENT,
+ PR_SET_MODE,
PR_POST_INIT,
PR_CHG_FLAGS,
PR_BATT_FLAGS,
@@ -61,6 +63,7 @@ static const char * const prob_text[] = {
"static update",
"set voltage",
"set current",
+ "set mode",
"post init",
"chg params",
"batt params",
@@ -293,10 +296,9 @@ static void show_charging_progress(void)
*/
static int charge_request(int voltage, int current)
{
- int r1 = EC_SUCCESS, r2 = EC_SUCCESS;
+ int r1 = EC_SUCCESS, r2 = EC_SUCCESS, r3 = EC_SUCCESS;
static int prev_volt, prev_curr;
- /* TODO(crosbug.com/p/27640): should we call charger_set_mode() too? */
if (!voltage || !current)
voltage = current = 0;
@@ -314,6 +316,17 @@ static int charge_request(int voltage, int current)
problem(PR_SET_CURRENT, r2);
/*
+ * Set the charge inhibit bit when possible as it appears to save
+ * power in some cases (e.g. Nyan with BQ24735).
+ */
+ if (voltage > 0 || current > 0)
+ r3 = charger_set_mode(0);
+ else
+ r3 = charger_set_mode(CHARGE_FLAG_INHIBIT_CHARGE);
+ if (r3 != EC_SUCCESS)
+ problem(PR_SET_MODE, r3);
+
+ /*
* Only update if the request worked, so we'll keep trying on failures.
*/
if (!r1 && !r2) {