Skip to contentSkip to conversation

power: supply: add standalone S2MU106 fuel gauge (Samsung Galaxy XCover5)

PATCH In review Adil Hüsrev Tepe 2 participants 7 messages Nov 17 – Nov 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover power: supply: add standalone S2MU106 fuel gauge (Samsung Galaxy XCover5)

This supersedes "[PATCH v1 0/3] power: supply: s2mu005-battery: add S2MU106" (https://lore.kernel.org/all/[email protected]/),
which I am withdrawing rather than sending a v2 of.

That series extended s2mu005-battery.c/its binding with a samsung,s2mu106-fuel-gauge compatible falling back to samsung,s2mu005-fuel-gauge. Sashiko AI's review pointed out that the fallback is unsound: a board using it binds through the plain samsung,s2mu005-fuel-gauge compatible with no guard at all, which still exercises s2mu005_fg_get_voltage_avg()/get_current_avg() against MONOUT registers the S2MU106 doesn't have, and the resulting garbage current_avg can flip the reported POWER_SUPPLY_STATUS. Patch 3/3 of that series added a has_monout flag to keep the S2MU106 match entry out of that path, but the binding still allowed the unguarded fallback, which is the actual hole.

Rather than patch around that, this series gives the S2MU106 fuel gauge its own compatible and its own standalone driver. It only shares the S2MU005's STATUS/RVBAT/RCURCC/RSOC register layout and scaling, not its device-tree node shape or its MONOUT path, so there is nothing to usefully fall back to. samsung,s2mu005-fuel-gauge and s2mu005-battery.c are untouched by this series.

Both patches were drafted with an AI coding assistant (Claude Code, Anthropic); I reviewed every line, built both (arm64, 0 warnings), ran checkpatch --strict and dt_binding_check (clean), and tested the driver live on a Samsung Galaxy XCover5 (Exynos850; re-confirmed 2026-11-17, kernel 7.4.0-rc1-00023-gdcb8b91fb779+ #30): it probes, and /sys/class/power_supply/s2mu106-battery/ reports plausible voltage, capacity and charging-status values that track the device's actual state, confirmed across a flash/reboot cycle.

Adil Hüsrev Tepe (2):
dt-bindings: power: supply: add samsung,s2mu106-fuelgauge
power: supply: s2mu106-fuelgauge: add standalone driver

 .../power/supply/samsung,s2mu106-fuelgauge.yaml | 47 ++++++++
 drivers/power/supply/Kconfig                    |  8 ++
 drivers/power/supply/Makefile                   |  1 +
 drivers/power/supply/s2mu106-fuelgauge.c        | 240 +++++++++++++++++++++++
 4 files changed, 296 insertions(+)
#1 lore raw

PATCH 1/2 dt-bindings: power: supply: add samsung,s2mu106-fuelgauge

Add a binding for the Samsung S2MU106 PMIC's fuel gauge, as a standalone I2C device (own address, 0x3b) rather than a fallback compatible on samsung,s2mu005-fuel-gauge.

A previous version of this series
(https://lore.kernel.org/all/[email protected]/)
extended the S2MU005 fuel-gauge binding and driver instead, with samsung,s2mu106-fuel-gauge falling back to samsung,s2mu005-fuel-gauge. Sashiko AI's review of that series pointed out that the fallback let a board bind through the plain samsung,s2mu005-fuel-gauge compatible with no guard at all, which runs s2mu005_fg_get_voltage_avg()/ get_current_avg() against MONOUT registers the S2MU106 doesn't have, and can misreport charging status from the resulting garbage reads.

Rather than add a flag to close that specific hole, this binding avoids the fallback-compatible construction entirely: the S2MU106 fuel gauge only shares the S2MU005's STATUS/RVBAT/RCURCC/RSOC register layout and scaling, not its device-tree node shape, so it gets its own compatible and its own driver
("power: supply: s2mu106-fuelgauge: add standalone driver"). samsung,s2mu005-fuel-gauge is left untouched.

---
 .../supply/samsung,s2mu106-fuelgauge.yaml     | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/samsung,s2mu106-fuelgauge.yaml
Documentation/devicetree/bindings/power/supply/samsung,s2mu106-fuelgauge.yaml new file +51 -0
new file mode 100644
index 000000000..3dd91412e
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/supply/samsung,s2mu106-fuelgauge.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Samsung S2MU106 Fuel Gauge
+
+maintainers:
+  - Adil Hüsrev Tepe <[email protected]>
+
+description:
+  Fuel-gauge sub-function of the Samsung S2MU106 PMIC, on its own I2C address
+  (separate from the 0x3d charger/MUIC/FLED block). As on the Galaxy XCover5.
+
+allOf:
+  - $ref: power-supply.yaml#
+
+properties:
+  compatible:
+    const: samsung,s2mu106-fuelgauge
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  monitored-battery: true
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        fuel-gauge@3b {
+            compatible = "samsung,s2mu106-fuelgauge";
+            reg = <0x3b>;
+            interrupt-parent = <&gpa1>;
+            interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
+            monitored-battery = <&battery>;
+        };
+    };
+...
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH 1/2] dt-bindings: power: supply: add samsung,s2mu106-fuelgauge

Quoted 10 lines · Adil Hüsrev Tepe

Add a binding for the Samsung S2MU106 PMIC's fuel gauge, as a standalone I2C device (own address, 0x3b) rather than a fallback compatible on samsung,s2mu005-fuel-gauge.

A previous version of this series
(https://lore.kernel.org/all/[email protected]/)
extended the S2MU005 fuel-gauge binding and driver instead, with samsung,s2mu106-fuel-gauge falling back to samsung,s2mu005-fuel-gauge. Sashiko AI's review of that series pointed out that the fallback let a board bind through the plain samsung,s2mu005-fuel-gauge compatible

Why is this relevant to commit msg? Whatever was decided in previous review, stays in previous review. If you had bugs, would you be describing each bug?

Quoted 3 lines

with no guard at all, which runs s2mu005_fg_get_voltage_avg()/ get_current_avg() against MONOUT registers the S2MU106 doesn't have, and can misreport charging status from the resulting garbage reads.

Explain simply differences between devices.

Quoted 8 lines

Rather than add a flag to close that specific hole, this binding avoids the fallback-compatible construction entirely: the S2MU106 fuel gauge only shares the S2MU005's STATUS/RVBAT/RCURCC/RSOC register layout and scaling, not its device-tree node shape, so it gets its own compatible and its own driver
("power: supply: s2mu106-fuelgauge: add standalone driver"). samsung,s2mu005-fuel-gauge is left untouched.

This is completely redundant paragraph. Are you pasting here LLM stuff? LLM has no place in commit msg. Usage of LLM means you do not understand what you did.

Quoted 32 lines
---
 .../supply/samsung,s2mu106-fuelgauge.yaml     | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/samsung,s2mu106-fuelgauge.yaml
Documentation/devicetree/bindings/power/supply/samsung,s2mu106-fuelgauge.yaml new file +19 -0
new file mode 100644
index 000000000..3dd91412e
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/supply/samsung,s2mu106-fuelgauge.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Samsung S2MU106 Fuel Gauge
+
+maintainers:
+  - Adil Hüsrev Tepe <[email protected]>
+
+description:
+  Fuel-gauge sub-function of the Samsung S2MU106 PMIC, on its own I2C address
+  (separate from the 0x3d charger/MUIC/FLED block). As on the Galaxy XCover5.
+
+allOf:
+  - $ref: power-supply.yaml#
+
+properties:

Documentation/devicetree/bindings/power/supply/samsung,s2mu106-fuelgauge.yaml line 29

Quoted 10 lines
Documentation/devicetree/bindings/power/supply/samsung,s2mu106-fuelgauge.yaml new file +10 -0
+  compatible:
+    const: samsung,s2mu106-fuelgauge
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  monitored-battery: true

Exactly the same as s2mu005. I do not understand why do you need a new binding file and no one suggested that.

Best regards,
Krzysztof

#3 lore raw

Re: [PATCH 1/2] dt-bindings: power: supply: add samsung,s2mu106-fuelgauge

Quoted 2 lines · Krzysztof Kozlowski

Exactly the same as s2mu005. I do not understand why do you need a new binding file and no one suggested that.

There is no good reason for it. I'll drop this binding and add samsung,s2mu106-fuel-gauge to the enum in samsung,s2mu005-fuel-gauge.yaml instead, without a fallback.

I'll also cut the commit message down to what differs between the two chips.

Adil

#4 lore raw

PATCH 2/2 power: supply: s2mu106-fuelgauge: add standalone driver

In reply to Adil Hüsrev Tepe

Add a standalone driver for the fuel gauge in the Samsung S2MU106 PMIC, as fitted on the Samsung Galaxy XCover5 (own I2C address, 0x3b). It shares the S2MU005 fuel gauge's STATUS/RVBAT/RCURCC/RSOC register layout and scaling, which this driver reads directly with the stock fixed-point formulas; it has no MONOUT average-monitoring registers, so unlike s2mu005-battery.c it never reads VOLTAGE_AVG/CURRENT_AVG or uses current_avg to decide POWER_SUPPLY_STATUS.

This replaces a previous version of this series
(https://lore.kernel.org/all/[email protected]/)
that instead extended s2mu005-battery.c with a samsung,s2mu106-fuel-gauge fallback compatible; see "dt-bindings: power: supply: add samsung,s2mu106-fuelgauge" in this series for why that shape was dropped.

The driver was drafted with an AI coding assistant (Claude Code, Anthropic) from this register map; I reviewed every line, built it (arm64, 0 warnings), ran checkpatch --strict (clean), and tested it on a Samsung Galaxy XCover5 (re-confirmed 2026-11-17, kernel 7.4.0-rc1-00023-gdcb8b91fb779+ #30): it probes, and /sys/class/power_supply/s2mu106-battery/ reports plausible voltage, capacity and charging-status values that track the device's actual state (confirmed live, including across a flash/reboot cycle).

---
 drivers/power/supply/Kconfig             |  13 ++
 drivers/power/supply/Makefile            |   1 +
 drivers/power/supply/s2mu106-fuelgauge.c | 240 +++++++++++++++++++++++
 3 files changed, 254 insertions(+)
 create mode 100644 drivers/power/supply/s2mu106-fuelgauge.c
drivers/power/supply/Kconfig +13 -0
index 1eeb176b2..cc8fed03b 100644
@@ -240,6 +240,19 @@ config BATTERY_S2MU005
 
 	  This driver, if built as a module, will be called s2mu005-fuel-gauge.
 
+config BATTERY_S2MU106
+	tristate "Samsung S2MU106 PMIC fuel gauge driver"
+	depends on I2C
+	select REGMAP_I2C
+	help
+	  Say Y here to build a driver for the fuel gauge block of the
+	  Samsung S2MU106 PMIC, as fitted on the Samsung Galaxy XCover5.
+	  It is a standalone I2C device at address 0x3b, reporting
+	  voltage, current, capacity and charging status.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called s2mu106-fuelgauge.
+
 config CHARGER_S2MU106
 	tristate "Samsung S2MU106 charger driver (read-only)"
 	depends on I2C
drivers/power/supply/Makefile +1 -0
index cd16c6e48..531a0b024 100644
@@ -135,4 +135,5 @@ obj-$(CONFIG_CHARGER_QCOM_SMB2)	+= qcom_smbx.o
 obj-$(CONFIG_FUEL_GAUGE_MM8013)	+= mm8013.o
 obj-$(CONFIG_MACSMC_POWER)	+= macsmc-power.o
 obj-$(CONFIG_CHARGER_MAX77759)	+= max77759_charger.o
+obj-$(CONFIG_BATTERY_S2MU106)	+= s2mu106-fuelgauge.o
 obj-$(CONFIG_CHARGER_S2MU106)	+= s2mu106-charger.o
drivers/power/supply/s2mu106-fuelgauge.c new file +240 -0

240 lines not on this page · raw message

Signature · 1 line
2.53.0
#5 lore raw

Re: [PATCH 2/2] power: supply: s2mu106-fuelgauge: add standalone driver

Quoted 8 lines · Adil Hüsrev Tepe

Add a standalone driver for the fuel gauge in the Samsung S2MU106 PMIC, as fitted on the Samsung Galaxy XCover5 (own I2C address, 0x3b). It shares the S2MU005 fuel gauge's STATUS/RVBAT/RCURCC/RSOC register layout and scaling, which this driver reads directly with the stock fixed-point formulas; it has no MONOUT average-monitoring registers, so unlike s2mu005-battery.c it never reads VOLTAGE_AVG/CURRENT_AVG or uses current_avg to decide POWER_SUPPLY_STATUS.

Quoted 6 lines

This replaces a previous version of this series
(https://lore.kernel.org/all/[email protected]/)
that instead extended s2mu005-battery.c with a samsung,s2mu106-fuel-gauge fallback compatible; see "dt-bindings: power: supply: add samsung,s2mu106-fuelgauge" in this series for why that shape was dropped.

No relevant

Quoted 3 lines

The driver was drafted with an AI coding assistant (Claude Code, Anthropic) from this register map; I reviewed every line, built it

Not relevant!

Quoted 6 lines

(arm64, 0 warnings), ran checkpatch --strict (clean), and tested it on a Samsung Galaxy XCover5 (re-confirmed 2026-11-17, kernel 7.4.0-rc1-00023-gdcb8b91fb779+ #30): it probes, and /sys/class/power_supply/s2mu106-battery/ reports plausible voltage, capacity and charging-status values that track the device's actual state (confirmed live, including across a flash/reboot cycle).

Even less relevant, drop. AI usage goes to changelog.

Quoted 15 lines
drivers/power/supply/s2mu106-fuelgauge.c new file +15 -0
+static int s2mu106_fg_probe(struct i2c_client *client)
+{
+	struct s2mu106_fg *fg;
+	struct power_supply_config cfg = {};
+
+	fg = devm_kzalloc(&client->dev, sizeof(*fg), GFP_KERNEL);
+	if (!fg)
+		return -ENOMEM;
+
+	fg->dev = &client->dev;
+	mutex_init(&fg->lock);
+
+	fg->regmap = devm_regmap_init_i2c(client, &s2mu106_fg_regmap_config);
+	if (IS_ERR(fg->regmap))
+		return PTR_ERR(fg->regmap);

drivers/power/supply/s2mu106-fuelgauge.c line 212

Quoted 10 lines
drivers/power/supply/s2mu106-fuelgauge.c new file +10 -0
+
+	i2c_set_clientdata(client, fg);
+
+	cfg.drv_data = fg;
+	fg->psy = devm_power_supply_register(&client->dev, &s2mu106_fg_desc, &cfg);
+	if (IS_ERR(fg->psy))
+		return PTR_ERR(fg->psy);
+
+	dev_info(&client->dev, "S2MU106 fuel gauge registered (addr 0x%02x)\n",
+		 client->addr);

Drop, drivers should be silent on success.

Review

Quoted 1 line
(quoted diff) +1 -0
+	return 0;

Why do you need a new driver instead of integrating it into existing s2mu005?

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH 2/2] power: supply: s2mu106-fuelgauge: add standalone driver

Quoted 1 line · Krzysztof Kozlowski

Even less relevant, drop. AI usage goes to changelog.

Will do.

Quoted 1 line

Drop, drivers should be silent on success.

Ack.

Quoted 2 lines

Why do you need a new driver instead of integrating it into existing s2mu005?

I don't. Kaustabh said the same on the earlier series, so the next version goes back to s2mu005-battery.c, with S2MU106 as its own match entry that skips the average-monitoring registers it doesn't have. This standalone series can be dropped.

Adil