summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/amenia/battery.c10
-rw-r--r--board/reef/battery.c10
-rw-r--r--driver/charger/bd99955.c26
3 files changed, 28 insertions, 18 deletions
diff --git a/board/amenia/battery.c b/board/amenia/battery.c
index 9363bbde93..2f308473f5 100644
--- a/board/amenia/battery.c
+++ b/board/amenia/battery.c
@@ -34,15 +34,7 @@ static const struct battery_info info = {
const struct battery_info *battery_get_info(void)
{
- static struct battery_info batt_info;
-
- if (battery_is_present() == BP_YES)
- return &info;
-
- /* Use voltage_max for voltage min if battery is not present */
- batt_info = info;
- batt_info.voltage_min = batt_info.voltage_max;
- return &batt_info;
+ return &info;
}
int board_cut_off_battery(void)
diff --git a/board/reef/battery.c b/board/reef/battery.c
index 5f29aa0628..2b86f7f012 100644
--- a/board/reef/battery.c
+++ b/board/reef/battery.c
@@ -34,15 +34,7 @@ static const struct battery_info info = {
const struct battery_info *battery_get_info(void)
{
- static struct battery_info batt_info;
-
- if (battery_is_present() == BP_YES)
- return &info;
-
- /* Use voltage_max for voltage min if battery is not present */
- batt_info = info;
- batt_info.voltage_min = batt_info.voltage_max;
- return &batt_info;
+ return &info;
}
int board_cut_off_battery(void)
diff --git a/driver/charger/bd99955.c b/driver/charger/bd99955.c
index 21fe69f293..251fcb987c 100644
--- a/driver/charger/bd99955.c
+++ b/driver/charger/bd99955.c
@@ -593,6 +593,24 @@ int charger_get_voltage(int *voltage)
int charger_set_voltage(int voltage)
{
+ int rv;
+ int reg;
+ const struct battery_info *bi = battery_get_info();
+
+ /*
+ * Regulate the system voltage to battery max if the battery
+ * is not present or the battery is discharging on AC.
+ */
+ rv = ch_raw_read16(BD99955_CMD_CHGOP_SET2, &reg,
+ BD99955_EXTENDED_COMMAND);
+ if (rv)
+ return rv;
+
+ if (reg & BD99955_CMD_CHGOP_SET2_BATT_LEARN ||
+ battery_is_present() != BP_YES ||
+ battery_is_cut_off())
+ voltage = bi->voltage_max;
+
/* Charge voltage step 16 mV */
voltage &= ~0x0F;
@@ -646,6 +664,14 @@ static void bd99995_init(void)
ch_raw_write16(BD99955_CMD_CHGOP_SET2, reg,
BD99955_EXTENDED_COMMAND);
+ /* VSYS Valid Threshold High & Low Settings */
+ ch_raw_write16(BD99955_CMD_VSYSVAL_THH_SET,
+ bi->voltage_max & 0x7fe0,
+ BD99955_EXTENDED_COMMAND);
+ ch_raw_write16(BD99955_CMD_VSYSVAL_THL_SET,
+ bi->voltage_min & 0x7fe0,
+ BD99955_EXTENDED_COMMAND);
+
/* Set battery OVP to 500 + maximum battery voltage */
ch_raw_write16(BD99955_CMD_VBATOVP_SET,
(bi->voltage_max + 500) & 0x7ff0,