Skip to contentSkip to conversation

power: supply: Add adc-battery-helper lib and Intel Dollar Cove TI CC battery driver

PATCH Superseded Hans de Goede 2 participants 10 messages Jul 21, 2025 – Jul 26, 2025 Power supply

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover power: supply: Add adc-battery-helper lib and Intel Dollar Cove TI CC battery driver

Hi All,

Here is a patch-series which primary goal is to add support for using the coulomb-counter in the Intel Dollar Cove TI PMIC as battery power-supply class device.

This PMIC used on some Intel Bay/Cherry Trail systems has some builtin fuel-gauge functionality which just like the UG3105 fuel-gauge is not a full featured autonomous fuel-gauge.

To prepare for adding support for this, this series factors out the UG3105 capacity estimating code, generalized so that it can be re-used in other drivers.

This series has been tested on an Asus ME176C tablet with UG3105 fuel-gauge and on an Acer A1 840 tablet which uses the Intel Dollar Cove TI coulomb- counter as fuel-gauge.

Changes in v3:
- Drop hardcoded open-circuit-voltage to capacity mapping table, replacing it with using the "ocv-capacity-table-n" device-property and replace DIY code with power_supply_batinfo_ocv2cap()
- Rebase on latest upstream where ug3105_battery was already switched to "ocv-capacity-table-n" device-prop + power_supply_batinfo_ocv2cap()
- Switch fg druver to iio_read_channel_processed_scale() which moves the Vbat ADC calibration handling and scaling to the IIO ADC driver
- Drop (already fixed) "power: supply: adc-battery-helper: Fix reporting capacity > 100%"

Changes in v2:
- Drop the 2 already merged bug-fix patches
- Add missing MODULE_DESCRIPTION() to the new adc-battery-helper module

Regards,

Hans

*** BLURB HERE ***

Hans de Goede (5):
power: supply: Add adc-battery-helper
power: supply: ug3105_battery: Switch to adc-battery-helper
power: supply: ug3105_battery: Put FG in standby on remove and
shutdown
power: supply: adc-battery-helper: Add support for optional
charge_finished GPIO
power: supply: Add new Intel Dollar Cove TI battery driver

 drivers/power/supply/Kconfig               |  16 +
 drivers/power/supply/Makefile              |   2 +
 drivers/power/supply/adc-battery-helper.c  | 327 +++++++++++++++++
 drivers/power/supply/adc-battery-helper.h  |  62 ++++
 drivers/power/supply/intel_dc_ti_battery.c | 394 +++++++++++++++++++++
 drivers/power/supply/ug3105_battery.c      | 346 ++++--------------
 6 files changed, 867 insertions(+), 280 deletions(-)
 create mode 100644 drivers/power/supply/adc-battery-helper.c
 create mode 100644 drivers/power/supply/adc-battery-helper.h
 create mode 100644 drivers/power/supply/intel_dc_ti_battery.c
Signature · 1 line
2.49.0
#1 lore raw

PATCH v3 1/5 power: supply: Add adc-battery-helper

The TI PMIC used on some Intel Bay/Cherry Trail systems has some builtin fuel-gauge functionality which just like the UG3105 fuel-gauge is not a full featured autonomous fuel-gauge.

These fuel-gauges offer accurate current and voltage measurements but their coulomb-counters are intended to work together with an always on micro-controller monitoring the fuel-gauge.

Add an adc-battery-helper offering open-circuit-voltage (ocv) and through that capacity estimation for devices where such limited functionality fuel-gauges are exposed directly to Linux.

This is a copy of the existing UG3105 estimating code, generalized so that it can be re-used in other drivers.

The next commit will replace the UG3105 driver's version of this code with using the adc-battery-helper.

The API has been designed for easy integration into existing power-supply drivers. For example this functionality might also be a useful addition to the generic-adc-battery driver.

The requirement of needing the adc_battery_helper struct to be the first member of a battery driver's data struct is not ideal. This is a compromise which is necessary to allow directly using the helper's get_property(), external_power_changed() and suspend()/resume() functions as power-supply / suspend-resume callbacks.

---
Changes in v3:
- Drop hardcoded open-circuit-voltage to capacity mapping table, this table should be provided as "ocv-capacity-table-n" device-property.
- Replace DIY code with power_supply_batinfo_ocv2cap()

---
 drivers/power/supply/Kconfig              |   3 +
 drivers/power/supply/Makefile             |   1 +
 drivers/power/supply/adc-battery-helper.c | 315 ++++++++++++++++++++++
 drivers/power/supply/adc-battery-helper.h |  59 ++++
 4 files changed, 378 insertions(+)
 create mode 100644 drivers/power/supply/adc-battery-helper.c
 create mode 100644 drivers/power/supply/adc-battery-helper.h
drivers/power/supply/Kconfig +3 -0
index 79ddb006e2da..8cfaded2cc5c 100644
@@ -35,6 +35,9 @@ config APM_POWER
 	  Say Y here to enable support APM status emulation using
 	  battery class devices.
 
+config ADC_BATTERY_HELPER
+	tristate
+
 config GENERIC_ADC_BATTERY
 	tristate "Generic battery support using IIO"
 	depends on IIO
drivers/power/supply/Makefile +1 -0
index f943c9150b32..c85c5c441e0f 100644
@@ -7,6 +7,7 @@ power_supply-$(CONFIG_LEDS_TRIGGERS)	+= power_supply_leds.o
 
 obj-$(CONFIG_POWER_SUPPLY)	+= power_supply.o
 obj-$(CONFIG_POWER_SUPPLY_HWMON) += power_supply_hwmon.o
+obj-$(CONFIG_ADC_BATTERY_HELPER) += adc-battery-helper.o
 obj-$(CONFIG_GENERIC_ADC_BATTERY)	+= generic-adc-battery.o
 
 obj-$(CONFIG_APM_POWER)		+= apm_power.o
drivers/power/supply/adc-battery-helper.c new file +315 -0

315 lines not on this page · raw message

drivers/power/supply/adc-battery-helper.h new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on v3 1/5
#2 lore raw

Re: [PATCH v3 1/5] power: supply: Add adc-battery-helper

Quoted 22 lines · Hans de Goede

The TI PMIC used on some Intel Bay/Cherry Trail systems has some builtin fuel-gauge functionality which just like the UG3105 fuel-gauge is not a full featured autonomous fuel-gauge.

These fuel-gauges offer accurate current and voltage measurements but their coulomb-counters are intended to work together with an always on micro-controller monitoring the fuel-gauge.

Add an adc-battery-helper offering open-circuit-voltage (ocv) and through that capacity estimation for devices where such limited functionality fuel-gauges are exposed directly to Linux.

This is a copy of the existing UG3105 estimating code, generalized so that it can be re-used in other drivers.

The next commit will replace the UG3105 driver's version of this code with using the adc-battery-helper.

The API has been designed for easy integration into existing power-supply drivers. For example this functionality might also be a useful addition to the generic-adc-battery driver.

Quoted 7 lines

The requirement of needing the adc_battery_helper struct to be the first member of a battery driver's data struct is not ideal. This is a compromise which is necessary to allow directly using the helper's get_property(), external_power_changed() and suspend()/resume() functions as power-supply / suspend-resume callbacks.

This is a useful and beautiful helper library, approved. This makes it simple and clear what is going on.

Small nitpicks you can fix or ignore:

Quoted 1 line

+#define ADC_BAT_HELPER_MOV_AVG_WINDOW 8

_SIZE

Quoted 5 lines
drivers/power/supply/adc-battery-helper.h new file +5 -0
+struct adc_battery_helper {
+       struct power_supply *psy;
+       struct delayed_work work;
+       struct mutex lock;
+       adc_battery_helper_get_func get_voltage_and_current_now;

drivers/power/supply/adc-battery-helper.h line 36

Quoted 10 lines
drivers/power/supply/adc-battery-helper.h new file +10 -0
+       int ocv_uv[ADC_BAT_HELPER_MOV_AVG_WINDOW];              /* micro-volt */
+       int intern_res_mohm[ADC_BAT_HELPER_MOV_AVG_WINDOW];     /* milli-ohm */
+       int poll_count;
+       int ocv_avg_index;
+       int ocv_avg_uv;                                         /* micro-volt */
+       int intern_res_poll_count;
+       int intern_res_avg_index;
+       int intern_res_avg_mohm;                                /* milli-ohm */
+       int volt_uv;                                            /* micro-volt */
+       int curr_ua;                                            /* micro-ampere */

The units are pretty evident from the name I think but if you like it this way that is fine.

Quoted 1 line

+ int capacity; /* procent */

percent

Yours,
Linus Walleij

#3 lore raw

PATCH v3 2/5 power: supply: ug3105_battery: Switch to adc-battery-helper

In reply to Hans de Goede

Switch ug3105_battery to using the new adc-battery-helper, since the helper's algorithms are a copy of the replaced ug3105_battery code this should not cause any functional differences.

---
Changes in v3:
- Rebase on latest upstream ug3105_battery.c

---
 drivers/power/supply/Kconfig          |   1 +
 drivers/power/supply/ug3105_battery.c | 344 +++++---------------------
 2 files changed, 65 insertions(+), 280 deletions(-)
drivers/power/supply/Kconfig +1 -0
index 8cfaded2cc5c..e33a5360d33a 100644
@@ -1046,6 +1046,7 @@ config CHARGER_SURFACE
 config BATTERY_UG3105
 	tristate "uPI uG3105 battery monitor driver"
 	depends on I2C
+	select ADC_BATTERY_HELPER
 	help
 	  Battery monitor driver for the uPI uG3105 battery monitor.
 
drivers/power/supply/ug3105_battery.c +64 -280

438 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on v3 2/5
#4 lore raw

Re: [PATCH v3 2/5] power: supply: ug3105_battery: Switch to adc-battery-helper

Quoted 5 lines · Hans de Goede

Switch ug3105_battery to using the new adc-battery-helper, since the helper's algorithms are a copy of the replaced ug3105_battery code this should not cause any functional differences.

Yours,
Linus Walleij

#5 lore raw

PATCH v3 3/5 power: supply: ug3105_battery: Put FG in standby on remove and shutdown

In reply to Hans de Goede

Put the fuel-gauge in standby mode when the driver is unbound and on system shutdown.

This avoids unnecessary battery drain when the system is off.

---
 drivers/power/supply/ug3105_battery.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/power/supply/ug3105_battery.c +2 -0
index 70dd58e121e3..c4d4ac859fa4 100644
@@ -206,6 +206,8 @@ static struct i2c_driver ug3105_i2c_driver = {
 		.pm = &ug3105_pm_ops,
 	},
 	.probe = ug3105_probe,
+	.remove = ug3105_stop,
+	.shutdown = ug3105_stop,
 	.id_table = ug3105_id,
 };
 module_i2c_driver(ug3105_i2c_driver);
Signature · 1 line
2.49.0
Reviewed-by on v3 3/5
#6 lore raw

Re: [PATCH v3 3/5] power: supply: ug3105_battery: Put FG in standby on remove and shutdown

Quoted 6 lines · Hans de Goede

Put the fuel-gauge in standby mode when the driver is unbound and on system shutdown.

This avoids unnecessary battery drain when the system is off.

Yours,
Linus Walleij

#7 lore raw

PATCH v3 4/5 power: supply: adc-battery-helper: Add support for optional charge_finished GPIO

In reply to Hans de Goede

Charger ICs often have a status pin which indicates when the charger has finished charging the battery. Sometimes the status of this pin can be read over a GPIO.

Add support for optionally reading a charge-finished GPIO and when available use this to determine when to return POWER_SUPPLY_STATUS_FULL.

---
 drivers/power/supply/adc-battery-helper.c | 18 +++++++++++++++---
 drivers/power/supply/adc-battery-helper.h |  5 ++++-
 drivers/power/supply/ug3105_battery.c     |  2 +-
 3 files changed, 20 insertions(+), 5 deletions(-)
drivers/power/supply/adc-battery-helper.c +15 -3
index 919634db5472..c3e42a740496 100644
@@ -51,6 +51,7 @@
 
 #include <linux/cleanup.h>
 #include <linux/devm-helpers.h>
+#include <linux/gpio/consumer.h>
 #include <linux/mutex.h>
 #include <linux/power_supply.h>
 #include <linux/workqueue.h>
@@ -82,8 +83,17 @@ static int adc_battery_helper_get_status(struct adc_battery_helper *help)
 	if (help->curr_ua < -CURR_HYST_UA)
 		return POWER_SUPPLY_STATUS_DISCHARGING;
 
-	if (help->supplied && help->ocv_avg_uv > full_uv)
-		return POWER_SUPPLY_STATUS_FULL;
+	if (help->supplied) {
+		bool full;
+
+		if (help->charge_finished)
+			full = gpiod_get_value_cansleep(help->charge_finished);
+		else
+			full = help->ocv_avg_uv > full_uv;
+
+		if (full)
+			return POWER_SUPPLY_STATUS_FULL;
+	}
 
 	return POWER_SUPPLY_STATUS_NOT_CHARGING;
 }
@@ -255,13 +265,15 @@ static void adc_battery_helper_start_work(struct adc_battery_helper *help)
 }
 
 int adc_battery_helper_init(struct adc_battery_helper *help, struct power_supply *psy,
-			    adc_battery_helper_get_func get_voltage_and_current_now)
+			    adc_battery_helper_get_func get_voltage_and_current_now,
+			    struct gpio_desc *charge_finished_gpio)
 {
 	struct device *dev = psy->dev.parent;
 	int ret;
 
 	help->psy = psy;
 	help->get_voltage_and_current_now = get_voltage_and_current_now;
+	help->charge_finished = charge_finished_gpio;
 
 	ret = devm_mutex_init(dev, &help->lock);
 	if (ret)
drivers/power/supply/adc-battery-helper.h +4 -1
index 6daba08c1a21..1876c4239729 100644
@@ -11,6 +11,7 @@
 #define ADC_BAT_HELPER_MOV_AVG_WINDOW				8
 
 struct power_supply;
+struct gpio_desc;
 
 /*
  * The adc battery helper code needs voltage- and current-now to be sampled as
@@ -21,6 +22,7 @@ typedef int (*adc_battery_helper_get_func)(struct power_supply *psy, int *volt,
 
 struct adc_battery_helper {
 	struct power_supply *psy;
+	struct gpio_desc *charge_finished;
 	struct delayed_work work;
 	struct mutex lock;
 	adc_battery_helper_get_func get_voltage_and_current_now;
@@ -44,7 +46,8 @@ extern const enum power_supply_property adc_battery_helper_properties[];
 #define ADC_HELPER_NUM_PROPERTIES 7
 
 int adc_battery_helper_init(struct adc_battery_helper *help, struct power_supply *psy,
-			    adc_battery_helper_get_func get_voltage_and_current_now);
+			    adc_battery_helper_get_func get_voltage_and_current_now,
+			    struct gpio_desc *charge_finished_gpio);
 /*
  * The below functions can be directly used as power-supply / suspend-resume
  * callbacks. They cast the power_supply_get_drvdata() / dev_get_drvdata() data
drivers/power/supply/ug3105_battery.c +1 -1
index c4d4ac859fa4..210e0f9aa5e0 100644
@@ -161,7 +161,7 @@ static int ug3105_probe(struct i2c_client *client)
 	}
 
 	ret = adc_battery_helper_init(&chip->helper, chip->psy,
-				      ug3105_get_voltage_and_current_now);
+				      ug3105_get_voltage_and_current_now, NULL);
 	if (ret)
 		goto stop;
 
Signature · 1 line
2.49.0
#8 lore raw

PATCH v3 5/5 power: supply: Add new Intel Dollar Cove TI battery driver

In reply to Hans de Goede

Intel has 2 completely different "Dollar Cove" PMICs for its Bay Trail / Cherry Trail SoCs. One is made by X-Powers and is called the AXP288.

The AXP288's builtin charger and fuel-gauge functions are already supported by the axp288_charger / axp288_fuel_gauge drivers.

The other "Dollar Cove" PMIC is made by TI and does not have any clear TI denomination, its MFD driver calls it the "Intel Dollar Cove TI PMIC".

The Intel Dollar Cove TI PMIC comes with a coulomb-counters with limited functionality which is intended to work together with an always on micro-controller monitoring it for fuel-gauge functionality.

Most devices with the Dollar Cove TI PMIC have full-featured fuel-gauge functionality exposed through ACPI with the information coming from either the embedded-controller or a separate full-featured full-gauge IC.

But some designs lack this, add a battery-monitoring driver using the PMIC's coulomb-counter combined with the adc-battery-helper for capacity estimation for these designs.

Register definitions were taken from kernel/drivers/platform/x86/dc_ti_cc.c from the Acer A1-840 Android kernel source-code archive named:
"App. Guide_Acer_20151221_A_A.zip"
which is distributed by Acer from the Acer A1-840 support page:
https://www.acer.com/us-en/support/product-support/A1-840/downloads

---
Changes in v3:
- Switch to iio_read_channel_processed_scale() which moves the Vbat ADC calibration handling and scaling to the ADC driver

---
 drivers/power/supply/Kconfig               |  12 +
 drivers/power/supply/Makefile              |   1 +
 drivers/power/supply/intel_dc_ti_battery.c | 394 +++++++++++++++++++++
 3 files changed, 407 insertions(+)
 create mode 100644 drivers/power/supply/intel_dc_ti_battery.c
drivers/power/supply/Kconfig +12 -0
index e33a5360d33a..72f3b2b4d346 100644
@@ -247,6 +247,18 @@ config BATTERY_INGENIC
 	  This driver can also be built as a module. If so, the module will be
 	  called ingenic-battery.
 
+config BATTERY_INTEL_DC_TI
+	tristate "Intel Bay / Cherry Trail Dollar Cove TI battery driver"
+	depends on INTEL_SOC_PMIC_CHTDC_TI && INTEL_DC_TI_ADC && IIO && ACPI
+	select ADC_BATTERY_HELPER
+	help
+	  Choose this option if you want to monitor battery status on Intel
+	  Bay Trail / Cherry Trail tablets using the Dollar Cove TI PMIC's
+	  coulomb-counter as fuel-gauge.
+
+	  To compile this driver as a module, choose M here: the module will be
+	  called intel_dc_ti_battery.
+
 config BATTERY_IPAQ_MICRO
 	tristate "iPAQ Atmel Micro ASIC battery driver"
 	depends on MFD_IPAQ_MICRO
drivers/power/supply/Makefile +1 -0
index c85c5c441e0f..51e37e8bdeb3 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_BATTERY_OLPC)	+= olpc_battery.o
 obj-$(CONFIG_BATTERY_SAMSUNG_SDI)	+= samsung-sdi-battery.o
 obj-$(CONFIG_BATTERY_COLLIE)	+= collie_battery.o
 obj-$(CONFIG_BATTERY_INGENIC)	+= ingenic-battery.o
+obj-$(CONFIG_BATTERY_INTEL_DC_TI) += intel_dc_ti_battery.o
 obj-$(CONFIG_BATTERY_IPAQ_MICRO) += ipaq_micro_battery.o
 obj-$(CONFIG_BATTERY_WM97XX)	+= wm97xx_battery.o
 obj-$(CONFIG_BATTERY_SBS)	+= sbs-battery.o
drivers/power/supply/intel_dc_ti_battery.c new file +394 -0

394 lines not on this page · raw message

Signature · 1 line
2.49.0
Reviewed-by on v3 5/5
#9 lore raw

Re: [PATCH v3 5/5] power: supply: Add new Intel Dollar Cove TI battery driver

Quoted 21 lines · Hans de Goede

Intel has 2 completely different "Dollar Cove" PMICs for its Bay Trail / Cherry Trail SoCs. One is made by X-Powers and is called the AXP288.

The AXP288's builtin charger and fuel-gauge functions are already supported by the axp288_charger / axp288_fuel_gauge drivers.

The other "Dollar Cove" PMIC is made by TI and does not have any clear TI denomination, its MFD driver calls it the "Intel Dollar Cove TI PMIC".

The Intel Dollar Cove TI PMIC comes with a coulomb-counters with limited functionality which is intended to work together with an always on micro-controller monitoring it for fuel-gauge functionality.

Most devices with the Dollar Cove TI PMIC have full-featured fuel-gauge functionality exposed through ACPI with the information coming from either the embedded-controller or a separate full-featured full-gauge IC.

But some designs lack this, add a battery-monitoring driver using the PMIC's coulomb-counter combined with the adc-battery-helper for capacity estimation for these designs.

Quoted 7 lines

Register definitions were taken from kernel/drivers/platform/x86/dc_ti_cc.c from the Acer A1-840 Android kernel source-code archive named:
"App. Guide_Acer_20151221_A_A.zip"
which is distributed by Acer from the Acer A1-840 support page:
https://www.acer.com/us-en/support/product-support/A1-840/downloads

Nice, looking good!

Yours,
Linus Walleij