summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@chromium.org>2021-10-28 21:11:01 -0700
committerCommit Bot <commit-bot@chromium.org>2021-11-01 16:59:59 +0000
commitf78ff015a80e4be41fc70f3690d4a27996d3de38 (patch)
tree0fced249c545bf896b3ad46d2ab25d179d3ecb7d
parent753008b1b35247b8276be31b06bb6d7295a2d76c (diff)
downloadchrome-ec-f78ff015a80e4be41fc70f3690d4a27996d3de38.tar.gz
bq25710: Add PSYS sensing configuration
This adds a new config option to enable the PSYS monitoring feature on the BQ25710, BQ25720 chargers. The register definition for configuring PSYS on the BQ25720 is expanded to 2 bits, giving more control to meaure battery and AC separately. We keep it simple and include both when measurement is enabled. BRANCH=none BUG=b:195615830 TEST=with rest of patch series, psys values reported by dump_intel_rapl_consumption look reasonable Change-Id: I0f299c6a24d20ef5bdcda13de74b30ba0c2d5d3c Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3253076 Reviewed-by: Ryan Lin <ryan.lin@intel.com> Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r--driver/charger/bq25710.c43
-rw-r--r--driver/charger/bq25710.h15
-rw-r--r--include/config.h9
-rw-r--r--zephyr/Kconfig.battery11
-rw-r--r--zephyr/shim/include/config_chip.h5
5 files changed, 83 insertions, 0 deletions
diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c
index 13da37ab65..096d15ed1c 100644
--- a/driver/charger/bq25710.c
+++ b/driver/charger/bq25710.c
@@ -5,6 +5,8 @@
* TI bq25710 battery charger driver.
*/
+#include <stdbool.h>
+
#include "battery.h"
#include "battery_smart.h"
#include "bq25710.h"
@@ -20,6 +22,11 @@
#include "timer.h"
#include "util.h"
+#if !defined(CONFIG_CHARGER_BQ25710) && \
+ !defined(CONFIG_CHARGER_BQ25720)
+#error Only the BQ25720 and BQ25710 are supported by bq25710 driver.
+#endif
+
#ifndef CONFIG_CHARGER_NARROW_VDC
#error "BQ25710 is a NVDC charger, please enable CONFIG_CHARGER_NARROW_VDC."
#endif
@@ -164,6 +171,39 @@ static int bq25710_set_low_power_mode(int chgnum, int enable)
return EC_SUCCESS;
}
+static int bq25710_set_psys_sensing(int chgnum, bool enable)
+{
+ int rv;
+ int reg;
+ int mask, on, off;
+
+ rv = raw_read16(chgnum, BQ25710_REG_CHARGE_OPTION_1, &reg);
+ if (rv)
+ return rv;
+
+ if (IS_ENABLED(CONFIG_CHARGER_BQ25720)) {
+ mask = BQ25720_CHARGE_OPTION_1_PSYS_MASK;
+ on = BQ25720_CHARGE_OPTION_1_PSYS_ON;
+ off = BQ25720_CHARGE_OPTION_1_PSYS_OFF;
+ } else if (IS_ENABLED(CONFIG_CHARGER_BQ25710)) {
+ mask = BQ25710_CHARGE_OPTION_1_PSYS_MASK;
+ on = BQ25710_CHARGE_OPTION_1_PSYS_ON;
+ off = BQ25710_CHARGE_OPTION_1_PSYS_OFF;
+ }
+
+ reg &= ~mask;
+ if (enable)
+ reg |= on;
+ else
+ reg |= off;
+
+ rv = raw_write16(chgnum, BQ25710_REG_CHARGE_OPTION_1, reg);
+ if (rv)
+ return rv;
+
+ return EC_SUCCESS;
+}
+
static int bq25710_adc_start(int chgnum, int adc_en_mask)
{
int reg;
@@ -245,6 +285,9 @@ static void bq25710_init(int chgnum)
bq25710_set_low_power_mode(chgnum, 1);
}
+ if (IS_ENABLED(CONFIG_CHARGER_BQ25710_PSYS_SENSING))
+ bq25710_set_psys_sensing(chgnum, true);
+
if (!raw_read16(chgnum, BQ25710_REG_PROCHOT_OPTION_1, &reg)) {
/* Disable VDPM prochot profile at initialization */
reg &= ~BQ25710_PROCHOT_PROFILE_VDPM;
diff --git a/driver/charger/bq25710.h b/driver/charger/bq25710.h
index 68c7619ceb..eafd3883a8 100644
--- a/driver/charger/bq25710.h
+++ b/driver/charger/bq25710.h
@@ -50,6 +50,21 @@
#define BQ25710_CHARGE_OPTION_0_EN_IDPM BIT(1)
#define BQ25710_CHARGE_OPTION_0_CHRG_INHIBIT BIT(0)
+/* ChargeOption1 Register */
+#define BQ25710_CHARGE_OPTION_1_PSYS_SHIFT 12
+#define BQ25720_CHARGE_OPTION_1_PSYS_MASK (0x03 << \
+ BQ25710_CHARGE_OPTION_1_PSYS_SHIFT)
+#define BQ25720_CHARGE_OPTION_1_PSYS_ON (0 << \
+ BQ25710_CHARGE_OPTION_1_PSYS_SHIFT)
+#define BQ25720_CHARGE_OPTION_1_PSYS_OFF (3 << \
+ BQ25710_CHARGE_OPTION_1_PSYS_SHIFT)
+#define BQ25710_CHARGE_OPTION_1_PSYS_MASK \
+ BIT(BQ25710_CHARGE_OPTION_1_PSYS_SHIFT)
+#define BQ25710_CHARGE_OPTION_1_PSYS_ON (1 << \
+ BQ25710_CHARGE_OPTION_1_PSYS_SHIFT)
+#define BQ25710_CHARGE_OPTION_1_PSYS_OFF (0 << \
+ BQ25710_CHARGE_OPTION_1_PSYS_SHIFT)
+
/* ChargeOption2 Register */
#define BQ25710_CHARGE_OPTION_2_EN_EXTILIM BIT(7)
#define BQ25710_CHARGE_OPTION_2_TMAX_SHIFT 8
diff --git a/include/config.h b/include/config.h
index ce5fa5c25e..8ad208c5f3 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1054,6 +1054,15 @@
#undef CONFIG_CHARGER_BQ25710_SENSE_RESISTOR_AC
/*
+ * This config option is used to enable the PSYS sensing circuit on the
+ * BQ25710 and BQ25720 chargers. This is used for system power
+ * monitoring on board designs that support this capability. This
+ * circuit is disabled by default (reset) and needs to be explicitly
+ * enabled for meaningful results.
+ */
+#undef CONFIG_CHARGER_BQ25710_PSYS_SENSING
+
+/*
* Board specific maximum input current limit, in mA.
*/
#undef CONFIG_CHARGER_MAX_INPUT_CURRENT
diff --git a/zephyr/Kconfig.battery b/zephyr/Kconfig.battery
index d7e5e459da..feddbc421b 100644
--- a/zephyr/Kconfig.battery
+++ b/zephyr/Kconfig.battery
@@ -250,6 +250,17 @@ endchoice # "Discharge control method"
endif # PLATFORM_EC_CHARGER_DISCHARGE_ON_AC
+config CONFIG_PLATFORM_EC_CHARGER_BQ25710_PSYS_SENSING
+ bool "Charger monitors PSYS"
+ default n
+ depends on PLATFORM_EC_CHARGER_BQ25710 || PLATFORM_EC_CHARGER_BQ25720
+ help
+ This enables the PSYS sensing circuit on the BQ25710 and
+ BQ25720 chargers. This is used for system power monitoring on
+ board designs that support this capability. This circuit is
+ disabled by default (reset) and needs to be explicitly enabled
+ for meaningful results.
+
config PLATFORM_EC_CHARGER_BQ25710_SENSE_RESISTOR
int "Value of the charge sense-resistor, in mOhms"
default 10
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index 8cb5b3b4af..59593665c1 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -1705,6 +1705,11 @@
CONFIG_PLATFORM_EC_BATTERY_DEVICE_CHEMISTRY
#endif
+#undef CONFIG_CHARGER_BQ25710_PSYS_SENSING
+#ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25710_PSYS_SENSING
+#define CONFIG_CHARGER_BQ25710_PSYS_SENSING
+#endif
+
#undef CONFIG_CHARGER_BQ25710_SENSE_RESISTOR
#ifdef CONFIG_PLATFORM_EC_CHARGER_BQ25710_SENSE_RESISTOR
#define CONFIG_CHARGER_BQ25710_SENSE_RESISTOR \