power: supply: s2mu005-battery: add S2MU106 (Samsung Galaxy XCover5)
Subsystems (2)
cover power: supply: s2mu005-battery: add S2MU106 (Samsung Galaxy XCover5)
This series adds support for the Samsung S2MU106 PMIC fuel gauge to the existing s2mu005-battery driver, for the Samsung Galaxy XCover5 (Exynos850).
The S2MU106 fuel gauge shares the S2MU005's direct voltage, current and state-of-charge registers and their scaling. This was verified on an
XCover5: with the s2mu005 driver bound to the S2MU106 gauge, voltage, state of charge and the sign of the charge current all read correctly. It does not, however, share the MONOUT average-monitoring path, so the S2MU106 variant exposes only the instantaneous values. The XCover5 also does not wire the gauge's alert line, which patch 2 accommodates.
1 dt-bindings: add samsung,s2mu106-fuel-gauge 2 make the alert interrupt optional 3 add S2MU106 support
Based on v7.4-rc1.
Tool usage
----------
Prepared during XCover5 mainline bring-up with an AI coding assistant (Claude Code, Anthropic): it compared the S2MU005/S2MU106 fuel-gauge register maps, drafted these changes and changelogs, and ran a live A/B comparison on the device under my direction. I reviewed every line, tested on hardware, and take responsibility for the series. Review comments are welcome and I will answer them myself.
Adil Hüsrev Tepe (3):
dt-bindings: power: supply: samsung,s2mu005-fuel-gauge: add S2MU106
power: supply: s2mu005-battery: make the alert interrupt optional
power: supply: s2mu005-battery: add S2MU106 support
.../supply/samsung,s2mu005-fuel-gauge.yaml | 7 +- drivers/power/supply/s2mu005-battery.c | 71 +++++++++++++++---- 2 files changed, 63 insertions(+), 15 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/3 dt-bindings: power: supply: samsung,s2mu005-fuel-gauge: add S2MU106
The fuel gauge in the Samsung S2MU106 PMIC shares the S2MU005 fuel gauge's register layout and scaling for the direct voltage, current and state-of-charge registers. Add a "samsung,s2mu106-fuel-gauge" compatible with the existing "samsung,s2mu005-fuel-gauge" as a fallback.
This was verified on a Samsung Galaxy XCover5 (Exynos850): the s2mu005 fuel-gauge driver, bound to the S2MU106 fuel gauge, reports voltage, state of charge and the sign of the charge current correctly.
--- .../bindings/power/supply/samsung,s2mu005-fuel-gauge.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/power/supply/samsung,s2mu005-fuel-gauge.yaml +5 -2
@@ -14,8 +14,11 @@ allOf: properties: compatible: - enum: - - samsung,s2mu005-fuel-gauge + oneOf: + - const: samsung,s2mu005-fuel-gauge + - items: + - const: samsung,s2mu106-fuel-gauge + - const: samsung,s2mu005-fuel-gauge reg: maxItems: 1
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v1 1/3] dt-bindings: power: supply: samsung,s2mu005-fuel-gauge: add S2MU106
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] dt-bindings: power: supply: s2mu005: invalid fallback compatible for S2MU106 --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] dt-bindings: power: supply: s2mu005: invalid fallback compatible for S2MU106
--
commit c83b096797bb5a947ce97c34b89a173145f99454
Author: Adil Hüsrev Tepe <[email protected]>
dt-bindings: power: supply: samsung,s2mu005-fuel-gauge: add S2MU106
This commit adds the samsung,s2mu106-fuel-gauge compatible string to the Samsung S2MU005 fuel-gauge binding with samsung,s2mu005-fuel-gauge as a required fallback.
Quoted 8 lines
Documentation/devicetree/bindings/power/supply/samsung,s2mu005-fuel-gauge.yaml +0
-0@@ -14,8 +14,11 @@ allOf: properties: compatible:
Documentation/devicetree/bindings/power/supply/samsung,s2mu005-fuel-gauge.yaml allOf: · line 24
Quoted 10 lines
Documentation/devicetree/bindings/power/supply/samsung,s2mu005-fuel-gauge.yaml +5
-2- enum: - - samsung,s2mu005-fuel-gauge + oneOf: + - const: samsung,s2mu005-fuel-gauge + - items: + - const: samsung,s2mu106-fuel-gauge + - const: samsung,s2mu005-fuel-gauge reg: maxItems: 1
[Severity: Medium]
Should samsung,s2mu106-fuel-gauge be listed in the compatible enum without a samsung,s2mu005-fuel-gauge fallback?
When a devicetree node uses this fallback and binds via the samsung,s2mu005-fuel-gauge driver entry, s2mu005_fg_get_voltage_avg() and s2mu005_fg_get_current_avg() write S2MU005-specific selector values to S2MU005_FG_REG_MONOUTSEL and read bogus values from S2MU005_FG_REG_MONOUT. Because s2mu005_fg_get_status() checks both current_now < 0 and current_avg < 0 before reporting POWER_SUPPLY_STATUS_DISCHARGING, those bogus MONOUT reads also cause POWER_SUPPLY_PROP_STATUS to misreport the charging state.
Later commit "power: supply: s2mu005-battery: add S2MU106 support" adds a distinct match entry for samsung,s2mu106-fuel-gauge with has_monout = false to avoid touching MONOUT, while this schema forbids a standalone samsung,s2mu106-fuel-gauge compatible string.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/3 power: supply: s2mu005-battery: make the alert interrupt optional
In reply to Adil Hüsrev TepeThe driver unconditionally requests the fuel-gauge alert interrupt and fails to probe if the board does not wire it. Not all boards route the alert line (for example the Samsung Galaxy XCover5), so only request the interrupt when one is present; the gauge is otherwise polled on demand.
--- drivers/power/supply/s2mu005-battery.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/power/supply/s2mu005-battery.c +7 -5
@@ -273,11 +273,13 @@ static int s2mu005_fg_i2c_probe(struct i2c_client *client)return dev_err_probe (dev,PTR_ERR (priv->psy),"failed to register power supply subsystem\n" ); - ret =devm_request_threaded_irq (priv->dev, client->irq,NULL , - s2mu005_handle_irq,IRQF_ONESHOT , - psy_desc->name, priv); -if (ret) -return dev_err_probe (dev, ret,"failed to request IRQ\n" ); +if (client->irq >0 ) { + ret =devm_request_threaded_irq (priv->dev, client->irq,NULL , + s2mu005_handle_irq,IRQF_ONESHOT , + psy_desc->name, priv); +if (ret) +return dev_err_probe (dev, ret,"failed to request IRQ\n" ); + }return 0 ; }
Signature · 1 line
2.53.0
PATCH 3/3 power: supply: s2mu005-battery: add S2MU106 support
In reply to Adil Hüsrev TepeThe Samsung S2MU106 PMIC fuel gauge uses the same STATUS/RVBAT/RCURCC/ RSOC registers and scaling as the S2MU005, so the same read paths apply. It does not, however, share the MONOUT average-monitoring path: reading the averaged voltage and current through it returns bogus values on the S2MU106. Introduce a per-variant descriptor so the S2MU106 exposes only the instantaneous voltage, current, capacity and status, and derive the status from the instantaneous current alone when the average is absent.
Tested on a Samsung Galaxy XCover5 (Exynos850): voltage, state of charge and the sign of the charge current track the stock readings; the gauge has no alert line wired, which the preceding patch already accommodates.
--- drivers/power/supply/s2mu005-battery.c | 61 ++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 9 deletions(-)
drivers/power/supply/s2mu005-battery.c +52 -9
@@ -38,6 +38,7 @@ struct s2mu005_fg {struct regmap *regmap;struct power_supply *psy;struct mutex monout_mutex; +bool has_monout; };static const struct regmap_config s2mu005_fg_regmap_config = {
@@ -168,16 +169,18 @@ static int s2mu005_fg_get_capacity(struct s2mu005_fg *priv, int *value)static int s2mu005_fg_get_status (struct s2mu005_fg *priv,int *value) { -int current_now, current_avg, capacity; +int current_now, current_avg =-1 , capacity;int ret; ret =s2mu005_fg_get_current_now (priv, ¤t_now);if (ret <0 )return ret; - ret =s2mu005_fg_get_current_avg (priv, ¤t_avg); -if (ret <0 ) -return ret; +if (priv->has_monout) { + ret =s2mu005_fg_get_current_avg (priv, ¤t_avg); +if (ret <0 ) +return ret; + }/* * Verify both current values reported to reduce inaccuracies due to
@@ -240,12 +243,47 @@ static const struct power_supply_desc s2mu005_fg_desc = { .get_property = s2mu005_fg_get_property, }; +/* +* The S2MU106 fuel gauge shares the direct STATUS/RVBAT/RCURCC/RSOC +* registers and their scaling, but not the MONOUT average-monitoring path, +* so the averaged voltage and current are not exposed on it. +*/ +static const enum power_supply_property s2mu106_fg_properties[] = { +POWER_SUPPLY_PROP_VOLTAGE_NOW , +POWER_SUPPLY_PROP_CURRENT_NOW , +POWER_SUPPLY_PROP_CAPACITY , +POWER_SUPPLY_PROP_STATUS , +}; + +static const struct power_supply_desc s2mu106_fg_desc = { + .name ="s2mu106-fuel-gauge" , + .type =POWER_SUPPLY_TYPE_BATTERY , + .properties = s2mu106_fg_properties, + .num_properties =ARRAY_SIZE (s2mu106_fg_properties), + .get_property = s2mu005_fg_get_property, +}; + +struct s2mu005_fg_variant { +const struct power_supply_desc *desc; +bool has_monout; +}; + +static const struct s2mu005_fg_variant s2mu005_fg_variant = { + .desc = &s2mu005_fg_desc, + .has_monout = true, +}; + +static const struct s2mu005_fg_variant s2mu106_fg_variant = { + .desc = &s2mu106_fg_desc, + .has_monout = false, +}; +static int s2mu005_fg_i2c_probe (struct i2c_client *client) {struct device *dev = &client->dev;struct s2mu005_fg *priv;struct power_supply_config psy_cfg = {}; -const struct power_supply_desc *psy_desc; +const struct s2mu005_fg_variant *variant;int ret; priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL );
@@ -264,11 +302,12 @@ static int s2mu005_fg_i2c_probe(struct i2c_client *client)if (ret)return dev_err_probe (dev, ret,"failed to initialize MONOUT mutex\n" ); - psy_desc =device_get_match_data (dev); + variant =device_get_match_data (dev); + priv->has_monout = variant->has_monout; psy_cfg.drv_data = priv; psy_cfg.fwnode =dev_fwnode (dev); - priv->psy =devm_power_supply_register (priv->dev, psy_desc, &psy_cfg); + priv->psy =devm_power_supply_register (priv->dev, variant->desc, &psy_cfg);if (IS_ERR (priv->psy))return dev_err_probe (dev,PTR_ERR (priv->psy),"failed to register power supply subsystem\n" );
@@ -276,7 +315,7 @@ static int s2mu005_fg_i2c_probe(struct i2c_client *client)if (client->irq >0 ) { ret =devm_request_threaded_irq (priv->dev, client->irq,NULL , s2mu005_handle_irq,IRQF_ONESHOT , - psy_desc->name, priv); + variant->desc->name, priv);if (ret)return dev_err_probe (dev, ret,"failed to request IRQ\n" ); }
@@ -287,7 +326,11 @@ static int s2mu005_fg_i2c_probe(struct i2c_client *client)static const struct of_device_id s2mu005_fg_of_match_table[] = { { .compatible ="samsung,s2mu005-fuel-gauge" , - .data = &s2mu005_fg_desc, + .data = &s2mu005_fg_variant, + }, + { + .compatible ="samsung,s2mu106-fuel-gauge" , + .data = &s2mu106_fg_variant, }, { } };
Signature · 1 line
2.53.0
I'd like to withdraw this series rather than send a v2.
A review bot (Sashiko AI) flagged that patch 1's fallback compatible (samsung,s2mu106-fuel-gauge falling back to samsung,s2mu005-fuel-gauge) is unsound: a board using that fallback binds to the S2MU005 driver as-is, which still reads the MONOUT average-monitoring registers for VOLTAGE_AVG/CURRENT_AVG and uses current_avg to help decide POWER_SUPPLY_STATUS. The S2MU106 doesn't have that path, so those reads return garbage, and garbage current_avg can flip the reported charging status. Patch 3's has_monout flag avoids calling into that path from the S2MU106 variant I added, but the binding still allows a device to bind through the plain samsung,s2mu005-fuel-gauge compatible with no has_monout gate at all, which is the actual hole.
On reflection, extending s2mu005-battery.c was the wrong shape for this chip regardless of that specific bug. The S2MU106 fuel gauge is a separate, standalone I2C device on the Galaxy XCover5 (own address, 0x3b), not a drop-in register-compatible S2MU005 variant sharing a device tree node -- it only happens to reuse the same STATUS/RVBAT/ RCURCC/RSOC register layout and scaling. A dedicated driver avoids the fallback-compatible construction entirely, since there's nothing to fall back to.
I'll send that as a new series instead: a samsung,s2mu106-fuelgauge binding and a standalone drivers/power/supply/s2mu106-fuelgauge.c, with no changes to s2mu005-battery.c or its binding. Sorry for the noise -- I should have settled on this shape before sending v1.
Adil
Quoted 23 lines · Adil Hüsrev Tepe
I'd like to withdraw this series rather than send a v2.
A review bot (Sashiko AI) flagged that patch 1's fallback compatible (samsung,s2mu106-fuel-gauge falling back to samsung,s2mu005-fuel-gauge) is unsound: a board using that fallback binds to the S2MU005 driver as-is, which still reads the MONOUT average-monitoring registers for VOLTAGE_AVG/CURRENT_AVG and uses
current_avgto help decidePOWER_SUPPLY_STATUS. The S2MU106 doesn't have that path, so those reads return garbage, and garbagecurrent_avgcan flip the reported charging status. Patch 3'shas_monoutflag avoids calling into that path from the S2MU106 variant I added, but the binding still allows a device to bind through the plain samsung,s2mu005-fuel-gauge compatible with nohas_monoutgate at all, which is the actual hole.On reflection, extending
s2mu005-battery.cwas the wrong shape for this chip regardless of that specific bug. The S2MU106 fuel gauge is a separate, standalone I2C device on the Galaxy XCover5 (own address,0x3b), not a drop-in register-compatible S2MU005 variant sharing a device tree node -- it only happens to reuse the same STATUS/RVBAT/ RCURCC/RSOC register layout and scaling. A dedicated driver avoids the fallback-compatible construction entirely, since there's nothing to fall back to.
Quoted 4 lines
I'll send that as a new series instead: a samsung,s2mu106-fuelgauge binding and a standalone
drivers/power/supply/s2mu106-fuelgauge.c, with no changes tos2mu005-battery.cor its binding. Sorry for the noise -- I should have settled on this shape before sending v1.
Actually, this one was just fine. I didn't look at the patches meticulously but it seems like it does belong here. The correct approach would be to adjust the driver correctly so that it accepts both.
The compatible patch is, in fact incorrect. The driver clearly uses two separate compatibles for the two devices, so there should not be any fallback.
Quoted 1 line
Adil
Quoted 7 lines · Kaustabh Chakraborty
Actually, this one was just fine. I didn't look at the patches meticulously but it seems like it does belong here. The correct approach would be to adjust the driver correctly so that it accepts both.
The compatible patch is, in fact incorrect. The driver clearly uses two separate compatibles for the two devices, so there should not be any fallback.
Hi Kaustabh,
Thanks for taking a look. To be precise about what I was reacting to: the unsoundness wasn't that the same driver matches two compatibles -- patch 3 did add a distinct match entry for each, with has_monout set correctly per chip. It's that patch 1's binding declared the S2MU106 compatible as a fallback to the S2MU005 one:
compatible = "samsung,s2mu106-fuel-gauge", "samsung,s2mu005-fuel-gauge";
That pattern exists so a kernel with no S2MU106-specific knowledge still binds correctly via the old compatible alone. It doesn't hold here: a DT node that lists only the old compatible (no S2MU106 string at all) still matches s2mu005-battery.c's existing entry and takes the has_monout=true path, reading MONOUT registers the S2MU106 doesn't have.
You're right that the actual fix is narrower than what I did: drop the fallback from the binding (require samsung,s2mu106-fuel-gauge on its own), keep extending s2mu005-battery.c as patches 2-3 did. I went further and withdrew the whole series for a standalone driver, partly because I'd also talked myself into a chip sharing three register offsets and their scaling with another, on its own I2C address, not really belonging in that other chip's device tree node/driver file. That's a shape preference more than a bug fix, and I should have said so as a separate point rather than folding it into the same withdrawal.
The standalone series (dt-bindings: power: supply: add samsung,s2mu106-fuelgauge + power: supply: s2mu106-fuelgauge: add standalone driver) is already out and hasn't had review yet. If you still think reusing s2mu005-battery.c (minus the fallback) is the better shape, I'd rather hear that case on that thread than have it settled by default -- I don't have a strong attachment either way beyond not wanting the MONOUT bug back.
(Resent for the lists: my two earlier copies of this reply went out as HTML and vger rejected both, so only you received them. Sorry for the duplicate.)
Adil