Skip to contentSkip to conversation

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

PATCH Applied Hans de Goede 2 participants 9 messages Aug 31, 2025 – Sep 10, 2025 Power supply

lore
Share & tools
lore
#0 lore raw

v4 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 v4:
- s/MOV_AVG_WINDOW/MOV_AVG_WINDOW_SIZE/
- s/CELCIUS/CELSIUS/
- s/procent/percent/
- Add Linus' Reviewed-by to all patches

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 driver 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

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.51.0
#1 lore raw

PATCH v4 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 v4:
- s/MOV_AVG_WINDOW/MOV_AVG_WINDOW_SIZE/
- s/CELCIUS/CELSIUS/
- Add Linus' Reviewed-by

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.51.0
#2 lore raw

PATCH v4 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.51.0
#3 lore raw

PATCH v4 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.51.0
#4 lore raw

PATCH v4 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 f8f6d2f8ec89..229b49fef8ad 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 90c7edcb9ab1..4e42181c8983 100644
@@ -11,6 +11,7 @@
 #define ADC_BAT_HELPER_MOV_AVG_WINDOW_SIZE		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.51.0
#5 lore raw

PATCH v4 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 fuel-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.51.0
#6 lore raw

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

Hi,

drivers/power/supply/intel_dc_ti_battery.c line 357

Quoted 12 lines · Hans de Goede

[...]

drivers/power/supply/intel_dc_ti_battery.c new file +10 -0
+	/*
+	 * Note cannot use devm_iio_channel_get because ACPI systems lack
+	 * the device<->channel maps which iio_channel_get will uses when passed
+	 * a non NULL device pointer.
+	 */
+	chip->vbat_channel = devm_iio_channel_get(dev, "VBAT");
+	if (IS_ERR(chip->vbat_channel)) {
+		dev_dbg(dev, "devm_iio_channel_get() ret %ld\n", PTR_ERR(chip->vbat_channel));
+		return dev_err_probe(dev, -EPROBE_DEFER, "Waiting for VBAT IIO channel\n");
+	}
[...]

The comment confuses me. What is it supposed to tell me? Is it a leftover from early development stages? Anyways, I merged the whole series as it looks good to me. But I think this comment should be fixed in a follow-up patch :)

Greetings,

-- Sebastian

#7 lore raw

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

Hi Sebastian,

Quoted 18 lines · Sebastian Reichel

Hi,

drivers/power/supply/intel_dc_ti_battery.c line 357

Quoted 12 lines · Hans de Goede

[...]

drivers/power/supply/intel_dc_ti_battery.c new file +10 -0
+	/*
+	 * Note cannot use devm_iio_channel_get because ACPI systems lack
+	 * the device<->channel maps which iio_channel_get will uses when passed
+	 * a non NULL device pointer.
+	 */
+	chip->vbat_channel = devm_iio_channel_get(dev, "VBAT");
+	if (IS_ERR(chip->vbat_channel)) {
+		dev_dbg(dev, "devm_iio_channel_get() ret %ld\n", PTR_ERR(chip->vbat_channel));
+		return dev_err_probe(dev, -EPROBE_DEFER, "Waiting for VBAT IIO channel\n");
+	}
[...]

The comment confuses me. What is it supposed to tell me? Is it a leftover from early development stages?

Yes this is a copy and paste from a comment in drivers/power/supply/axp288_fuel_gauge.c where the comment at least is accurate in that over there the non devm iio_channel_get() is used.

Clearly it is possible to use the devm variant though as shown in this new driver. I'll submit a patch dropping the bogus comment right away.

And I'll also make a note to see if we can move axp288_fuel_gauge.c over to using the devm_ variant too.

Quoted 2 lines

Anyways, I merged the whole
series as it looks good to me.

Thank you.

Quoted 2 lines

But I think this comment should be
fixed in a follow-up patch :)

Follow-up patch is on its way.

Regards,

Hans

#8 lore raw
In reply to Hans de Goede
Quoted 9 lines · Hans de Goede

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.

[...]

Applied, thanks!

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

      commit: 6a93f54333979c2948e9c1e71ea0b377b486a3f5
[2/5] power: supply: ug3105_battery: Switch to adc-battery-helper
      commit: dcf1e7b73797399f8706226c7ff6ad8f18634db4
[3/5] power: supply: ug3105_battery: Put FG in standby on remove and shutdown
      commit: eede3f72a9658a3c82725ed36723d3189a91b3e5
[4/5] power: supply: adc-battery-helper: Add support for optional charge_finished GPIO
      commit: 926b144366c589a0c0c471d02a71590ed24284e0
[5/5] power: supply: Add new Intel Dollar Cove TI battery driver
      commit: 8c5795fe55278fa6a656bf4a0398fb22d5079298

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>