summaryrefslogtreecommitdiff
path: root/common/charger.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/charger.c')
-rw-r--r--common/charger.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/common/charger.c b/common/charger.c
index 15bdf8f73c..ebac3896c1 100644
--- a/common/charger.c
+++ b/common/charger.c
@@ -18,9 +18,20 @@
int charger_closest_voltage(int voltage)
{
- const struct charger_info *info;
+ const struct charger_info *info = charger_get_info();
+
+ /*
+ * If the requested voltage is non-zero but below our minimum,
+ * return the minimum. See crosbug.com/p/8662.
+ */
+ if (voltage > 0 && voltage < info->voltage_min)
+ return info->voltage_min;
+
+ /* Clip to max */
+ if (voltage > info->voltage_max)
+ return info->voltage_max;
- info = charger_get_info();
+ /* Otherwise round down to nearest voltage step */
return voltage - (voltage % info->voltage_step);
}