summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Parker <dparker@chromium.org>2013-07-17 01:28:29 -0700
committerChromeBot <chrome-bot@google.com>2013-07-19 18:01:48 -0700
commitc243537dda10b1f48b08d444d3cc22673e8edcf1 (patch)
tree5d99cfdc2fcfaa82a96577f4f3e86a17cab1c943
parent50ebe0565285562d080f7194f9f93f6b961c323f (diff)
downloadchrome-ec-c243537dda10b1f48b08d444d3cc22673e8edcf1.tar.gz
Constrain charging voltage to values chargers can provide.
BUG=chrome-os-partner:20863 BRANCH=falco,peppy,slippy,wolf TEST=Manual. On Peppy, there should no longer be "Charging Voltage" messages every second on the EC console. On other platforms verify that V_Batt reported by the 'charger' command is divisible by 16. Change-Id: Idd775a1d8033ff3405d10919e1e15ddddebc6c23 Signed-off-by: Dave Parker <dparker@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/62699 Reviewed-by: Bill Richardson <wfrichar@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--common/charge_state.c14
-rw-r--r--common/charger_common.c8
-rw-r--r--include/charger.h9
3 files changed, 28 insertions, 3 deletions
diff --git a/common/charge_state.c b/common/charge_state.c
index e0646c80c5..2d342c1764 100644
--- a/common/charge_state.c
+++ b/common/charge_state.c
@@ -404,6 +404,7 @@ static enum power_state state_charge(struct power_state_context *ctx)
struct batt_params *batt = &ctx->curr.batt;
int debounce = 0;
int want_current;
+ int want_voltage;
timestamp_t now;
if (curr->error)
@@ -425,9 +426,16 @@ static enum power_state state_charge(struct power_state_context *ctx)
now = get_time();
- if (batt->desired_voltage != curr->charging_voltage) {
- CPRINTF("[%T Charge voltage %dmV]\n", batt->desired_voltage);
- if (charger_set_voltage(batt->desired_voltage))
+ /*
+ * Adjust desired voltage to one the charger can actually supply
+ * or else we'll keep asking for a voltage the charger can't actually
+ * supply.
+ */
+ want_voltage = charger_closest_voltage(batt->desired_voltage);
+
+ if (want_voltage != curr->charging_voltage) {
+ CPRINTF("[%T Charge voltage %dmV]\n", want_voltage);
+ if (charger_set_voltage(want_voltage))
return PWR_STATE_ERROR;
update_charger_time(ctx, now);
}
diff --git a/common/charger_common.c b/common/charger_common.c
index 0e57c8c02c..bb301c48a5 100644
--- a/common/charger_common.c
+++ b/common/charger_common.c
@@ -17,6 +17,14 @@
#define CPUTS(outstr) cputs(CC_CHARGER, outstr)
#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
+int charger_closest_voltage(int voltage)
+{
+ const struct charger_info *info;
+
+ info = charger_get_info();
+ return voltage - (voltage % info->voltage_step);
+}
+
static int print_info(void)
{
int rv;
diff --git a/include/charger.h b/include/charger.h
index 661433d21a..9b75bb95b2 100644
--- a/include/charger.h
+++ b/include/charger.h
@@ -53,6 +53,15 @@ int charger_set_mode(int mode);
*/
int charger_closest_current(int current);
+/**
+ * Return the closest match the charger can supply to the requested voltage.
+ *
+ * @param voltage Requested voltage in mV.
+ *
+ * @return Voltage the charger will actually supply if <voltage> is requested.
+ */
+int charger_closest_voltage(int voltage);
+
/* Get/set charge current limit in mA */
int charger_get_current(int *current);
int charger_set_current(int current);