From 55032aa1236dc4f85485147f5927cfaf513def98 Mon Sep 17 00:00:00 2001 From: Vijay Hiremath Date: Mon, 4 Apr 2016 16:21:18 -0700 Subject: [PATCH] Driver: BD99955: Set minimum charge current & charge voltage values If the charge current or charge voltage registers are set to zero then the charger cuts the power to board. BD99955 does not support 0mA charge current & 0mV charge voltage values hence set the charge current & charge voltage to charger's minimum values. BUG=chrome-os-partner:52050 BRANCH=none TEST=Manually tested on Amenia. Board can boot without the battery. Battery does not discharge when the charger current or charger voltage is sent to 0 from the charger manager. Change-Id: I8049525594d107d7ad1ff2f17e8df757ee86458c Signed-off-by: Vijay Hiremath Reviewed-on: https://chromium-review.googlesource.com/337404 Commit-Ready: Vijay P Hiremath Tested-by: Vijay P Hiremath Reviewed-by: Shawn N --- driver/charger/bd99955.c | 20 +++++++------------- driver/charger/bd99955.h | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/driver/charger/bd99955.c b/driver/charger/bd99955.c index 61dc4eaf31..e2d968c7f6 100644 --- a/driver/charger/bd99955.c +++ b/driver/charger/bd99955.c @@ -322,6 +322,9 @@ int charger_set_current(int current) /* Charge current step 64 mA */ current &= ~0x3F; + if (current < bd99955_charger_info.current_min) + current = bd99955_charger_info.current_min; + return ch_raw_write16(BD99955_CMD_CHG_CURRENT, current, BD99955_BAT_CHG_COMMAND); } @@ -334,21 +337,12 @@ int charger_get_voltage(int *voltage) int charger_set_voltage(int voltage) { - /* - * The BD99955 will drop voltage to as low as requested. As the - * charger state machine will pass in 0 voltage, protect the system - * voltage by capping to the minimum. The reason is that the BD99955 - * only can regulate the system voltage which will kill the board's - * power if below 0. - */ - if (voltage == 0) { - const struct battery_info *bi = battery_get_info(); - - voltage = bi->voltage_min; - } - /* Charge voltage step 16 mV */ voltage &= ~0x0F; + + if (voltage < bd99955_charger_info.voltage_min) + voltage = bd99955_charger_info.voltage_min; + return ch_raw_write16(BD99955_CMD_CHG_VOLTAGE, voltage, BD99955_BAT_CHG_COMMAND); } diff --git a/driver/charger/bd99955.h b/driver/charger/bd99955.h index aab249842c..cd9bfdfff5 100644 --- a/driver/charger/bd99955.h +++ b/driver/charger/bd99955.h @@ -31,7 +31,7 @@ enum bd99955_charge_port { #define CHARGE_V_MIN 3072 #define CHARGE_V_STEP 16 #define CHARGE_I_MAX 16320 -#define CHARGE_I_MIN 0 +#define CHARGE_I_MIN 64 #define CHARGE_I_OFF 0 #define CHARGE_I_STEP 64 #define INPUT_I_MAX 16352