From 31e68a035b83acf13b73f3b5b63fbb99540faea9 Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Tue, 9 Jan 2018 16:31:44 +0800 Subject: [PATCH] driver/charger/isl923x: Make sure CONFIG_CHARGER_NARROW_VDC is set Without this, the battery will discharge if we disallow battery charging (e.g. calling charge_request with either voltage == 0 or current == 0, either by policy, or when the battery is full). Also update config.h to set the option whenever isl923x is used. BRANCH=none BUG=b:66575472 BUG=b:35585464 TEST=make buildall -j Change-Id: Id5515d5ea82a393a3693a3da44cbdc2778296a95 Signed-off-by: Nicolas Boichat Reviewed-on: https://chromium-review.googlesource.com/856538 Reviewed-by: Aseda Aboagye --- board/chell/board.h | 1 - board/elm/board.h | 1 - board/glados/board.h | 1 - board/nami/board.h | 1 - board/nautilus/board.h | 1 - board/oak/board.h | 1 - board/poppy/board.h | 1 - board/rowan/board.h | 1 - board/wheatley/board.h | 1 - common/charge_state_v2.c | 6 +++++- driver/charger/isl923x.c | 4 ++++ include/config.h | 11 ++++++++++- 12 files changed, 19 insertions(+), 11 deletions(-) diff --git a/board/chell/board.h b/board/chell/board.h index 9f3e93cda9..b2eb1271f2 100644 --- a/board/chell/board.h +++ b/board/chell/board.h @@ -32,7 +32,6 @@ #define CONFIG_CHARGER_ILIM_PIN_DISABLED #define CONFIG_CHARGER_INPUT_CURRENT 512 #define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1 -#define CONFIG_CHARGER_NARROW_VDC #define CONFIG_CHARGER_PROFILE_OVERRIDE #define CONFIG_CHARGER_SENSE_RESISTOR 10 #define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 diff --git a/board/elm/board.h b/board/elm/board.h index 4886d010ac..41af08ee4e 100644 --- a/board/elm/board.h +++ b/board/elm/board.h @@ -38,7 +38,6 @@ #define CONFIG_CHARGE_RAMP_HW #define CONFIG_CHARGER_ISL9237 #define CONFIG_CHARGER_MAX_INPUT_CURRENT 3000 -#define CONFIG_CHARGER_NARROW_VDC #define CONFIG_CHARGER_SENSE_RESISTOR 10 #define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 #define CONFIG_CHARGER_DISCHARGE_ON_AC diff --git a/board/glados/board.h b/board/glados/board.h index 24f1ac1b57..507cbcd001 100644 --- a/board/glados/board.h +++ b/board/glados/board.h @@ -34,7 +34,6 @@ #define CONFIG_CHARGER_ILIM_PIN_DISABLED #define CONFIG_CHARGER_INPUT_CURRENT 512 #define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1 -#define CONFIG_CHARGER_NARROW_VDC #define CONFIG_CHARGER_PROFILE_OVERRIDE #define CONFIG_CHARGER_SENSE_RESISTOR 10 #define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 diff --git a/board/nami/board.h b/board/nami/board.h index 9e077163c9..86bb976c82 100644 --- a/board/nami/board.h +++ b/board/nami/board.h @@ -83,7 +83,6 @@ #define CONFIG_CHARGER_DISCHARGE_ON_AC #define CONFIG_CHARGER_INPUT_CURRENT 512 #define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2 -#define CONFIG_CHARGER_NARROW_VDC #define CONFIG_CHARGER_PROFILE_OVERRIDE #define CONFIG_CHARGER_PSYS #define CONFIG_CHARGER_SENSE_RESISTOR 10 diff --git a/board/nautilus/board.h b/board/nautilus/board.h index 3bd80a1d84..f6cd650b48 100644 --- a/board/nautilus/board.h +++ b/board/nautilus/board.h @@ -83,7 +83,6 @@ #define CONFIG_CHARGER_DISCHARGE_ON_AC #define CONFIG_CHARGER_INPUT_CURRENT 512 #define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2 -#define CONFIG_CHARGER_NARROW_VDC #define CONFIG_CHARGER_PROFILE_OVERRIDE #define CONFIG_CHARGER_PSYS #define CONFIG_CHARGER_SENSE_RESISTOR 10 diff --git a/board/oak/board.h b/board/oak/board.h index 432b1454d1..9828e4e9a0 100644 --- a/board/oak/board.h +++ b/board/oak/board.h @@ -46,7 +46,6 @@ #define CONFIG_CHARGE_RAMP_HW #define CONFIG_CHARGER_ISL9237 #define CONFIG_CHARGER_MAX_INPUT_CURRENT 2250 -#define CONFIG_CHARGER_NARROW_VDC #define CONFIG_CHARGER_SENSE_RESISTOR 10 #define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 #endif /* BOARD_REV */ diff --git a/board/poppy/board.h b/board/poppy/board.h index 41aa1f19d9..3fd10a9b20 100644 --- a/board/poppy/board.h +++ b/board/poppy/board.h @@ -83,7 +83,6 @@ #define CONFIG_CHARGER_DISCHARGE_ON_AC #define CONFIG_CHARGER_INPUT_CURRENT 512 #define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 2 -#define CONFIG_CHARGER_NARROW_VDC #define CONFIG_CHARGER_PSYS #define CONFIG_CHARGER_SENSE_RESISTOR 10 #define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 diff --git a/board/rowan/board.h b/board/rowan/board.h index 1eee437180..07bdf64283 100644 --- a/board/rowan/board.h +++ b/board/rowan/board.h @@ -43,7 +43,6 @@ #define CONFIG_CHARGE_RAMP_HW #define CONFIG_CHARGER_ISL9237 #define CONFIG_CHARGER_MAX_INPUT_CURRENT 3000 -#define CONFIG_CHARGER_NARROW_VDC #define CONFIG_CHARGER_SENSE_RESISTOR 10 #define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 #define CONFIG_CHARGER_DISCHARGE_ON_AC diff --git a/board/wheatley/board.h b/board/wheatley/board.h index 56f8169b7e..c3ccf33a84 100644 --- a/board/wheatley/board.h +++ b/board/wheatley/board.h @@ -27,7 +27,6 @@ #define CONFIG_CHARGER_ILIM_PIN_DISABLED #define CONFIG_CHARGER_INPUT_CURRENT 512 #define CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON 1 -#define CONFIG_CHARGER_NARROW_VDC #define CONFIG_CHARGER_PROFILE_OVERRIDE #define CONFIG_CHARGER_SENSE_RESISTOR 10 #define CONFIG_CHARGER_SENSE_RESISTOR_AC 20 diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 4ecc48fbcd..71d46265a5 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -546,7 +546,11 @@ static int charge_request(int voltage, int current) if (!voltage || !current) { #ifdef CONFIG_CHARGER_NARROW_VDC current = 0; - /* With NVDC charger, keep VSYS voltage higher than battery */ + /* + * With NVDC charger, keep VSYS voltage higher than battery, + * otherwise the BGATE FET body diode would conduct and + * discharge the battery. + */ voltage = charger_closest_voltage( curr.batt.voltage + charger_get_info()->voltage_step); /* If the battery is full, request the max voltage. */ diff --git a/driver/charger/isl923x.c b/driver/charger/isl923x.c index 0117ad74d4..5f6312c7c7 100644 --- a/driver/charger/isl923x.c +++ b/driver/charger/isl923x.c @@ -18,6 +18,10 @@ #include "timer.h" #include "util.h" +#ifndef CONFIG_CHARGER_NARROW_VDC +#error "ISL9237/8 is a NVDC charger, please enable CONFIG_CHARGER_NARROW_VDC." +#endif + #define DEFAULT_R_AC 20 #define DEFAULT_R_SNS 10 #define R_AC CONFIG_CHARGER_SENSE_RESISTOR_AC diff --git a/include/config.h b/include/config.h index 3e8d2d6935..918c6ceb54 100644 --- a/include/config.h +++ b/include/config.h @@ -584,7 +584,7 @@ /* Minimum battery percentage for power on */ #undef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON -/* Narrow VDC power path */ +/* Set this option when using a Narrow VDC (NVDC) charger, such as ISL9237/8. */ #undef CONFIG_CHARGER_NARROW_VDC /* @@ -3216,6 +3216,15 @@ #define CONFIG_USB_PD_VBUS_MEASURE_CHARGER #endif +/*****************************************************************************/ +/* + * Define CONFIG_CHARGER_NARROW_VDC for chargers that use a Narrow VDC power + * architecture. + */ +#if defined(CONFIG_CHARGER_ISL9237) || defined(CONFIG_CHARGER_ISL9238) +#define CONFIG_CHARGER_NARROW_VDC +#endif + /*****************************************************************************/ /* * Define CONFIG_BUTTON_TRIGGERED_RECOVERY if a board has a dedicated recovery