mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/3] power: supply: s2mu005-battery: add S2MU106
@ 2026-11-27 22:32 Adil Hüsrev Tepe
  2026-11-27 22:32 ` [PATCH v2 1/3] dt-bindings: power: supply: samsung,s2mu005-fuel-gauge: " Adil Hüsrev Tepe
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-27 22:32 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Kaustabh Chakraborty
  Cc: linux-pm, devicetree, linux-kernel, Krzysztof Kozlowski,
	Yassine Oudjana, Adil Hüsrev Tepe

Add the Samsung S2MU106 fuel gauge (found on the Samsung Galaxy XCover5,
Exynos850) to the s2mu005-battery driver. It has the same direct
voltage, current and state-of-charge registers as the S2MU005 but no
MONOUT averaging, so it gets its own compatible and match data. The
XCover5 does not wire the gauge's alert line, hence patch 2.

This supersedes the standalone s2mu106-fuelgauge series [1], as asked
by Kaustabh and Krzysztof.

[1] https://lore.kernel.org/all/20261117104328.1176951-1-tadilhusrev@gmail.com/

An AI coding assistant (Claude Code) helped compare the register maps
and draft these patches. I reviewed and tested them on the device.

Changes in v2:
- binding: add the compatible to the enum, no s2mu005 fallback
- shorter commit messages
- Link to v1: https://lore.kernel.org/all/20261116074000.355176-1-tadilhusrev@gmail.com/

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

 .../power/supply/samsung,s2mu005-fuel-gauge.yaml   |  1 +
 drivers/power/supply/s2mu005-battery.c             | 71 ++++++++++++++++++----
 2 files changed, 59 insertions(+), 13 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261125-s2mu106-fg-5e2fc4490cbe

Best regards,
--  
Adil Hüsrev Tepe <tadilhusrev@gmail.com>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/3] dt-bindings: power: supply: samsung,s2mu005-fuel-gauge: add S2MU106
  2026-11-27 22:32 [PATCH v2 0/3] power: supply: s2mu005-battery: add S2MU106 Adil Hüsrev Tepe
@ 2026-11-27 22:32 ` Adil Hüsrev Tepe
  2026-11-27 22:32 ` [PATCH v2 2/3] power: supply: s2mu005-battery: make the alert interrupt optional Adil Hüsrev Tepe
  2026-11-27 22:32 ` [PATCH v2 3/3] power: supply: s2mu005-battery: add S2MU106 support Adil Hüsrev Tepe
  2 siblings, 0 replies; 4+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-27 22:32 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Kaustabh Chakraborty
  Cc: linux-pm, devicetree, linux-kernel, Krzysztof Kozlowski,
	Yassine Oudjana, Adil Hüsrev Tepe

The fuel gauge in the Samsung S2MU106 PMIC has the same direct voltage,
current and state-of-charge registers as the S2MU005 one, but lacks the
MONOUT averaging registers, so it is not fully compatible. Add its own
compatible.

Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
---
 .../devicetree/bindings/power/supply/samsung,s2mu005-fuel-gauge.yaml     | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/power/supply/samsung,s2mu005-fuel-gauge.yaml b/Documentation/devicetree/bindings/power/supply/samsung,s2mu005-fuel-gauge.yaml
index 05e420316a2..74dbfcacdbd 100644
--- a/Documentation/devicetree/bindings/power/supply/samsung,s2mu005-fuel-gauge.yaml
+++ b/Documentation/devicetree/bindings/power/supply/samsung,s2mu005-fuel-gauge.yaml
@@ -16,6 +16,7 @@ properties:
   compatible:
     enum:
       - samsung,s2mu005-fuel-gauge
+      - samsung,s2mu106-fuel-gauge
 
   reg:
     maxItems: 1

-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/3] power: supply: s2mu005-battery: make the alert interrupt optional
  2026-11-27 22:32 [PATCH v2 0/3] power: supply: s2mu005-battery: add S2MU106 Adil Hüsrev Tepe
  2026-11-27 22:32 ` [PATCH v2 1/3] dt-bindings: power: supply: samsung,s2mu005-fuel-gauge: " Adil Hüsrev Tepe
@ 2026-11-27 22:32 ` Adil Hüsrev Tepe
  2026-11-27 22:32 ` [PATCH v2 3/3] power: supply: s2mu005-battery: add S2MU106 support Adil Hüsrev Tepe
  2 siblings, 0 replies; 4+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-27 22:32 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Kaustabh Chakraborty
  Cc: linux-pm, devicetree, linux-kernel, Krzysztof Kozlowski,
	Yassine Oudjana, Adil Hüsrev Tepe

The 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.

Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
---
 drivers/power/supply/s2mu005-battery.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/power/supply/s2mu005-battery.c b/drivers/power/supply/s2mu005-battery.c
index a76154e5a09..9798a62ffec 100644
--- a/drivers/power/supply/s2mu005-battery.c
+++ b/drivers/power/supply/s2mu005-battery.c
@@ -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;
 }

-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 3/3] power: supply: s2mu005-battery: add S2MU106 support
  2026-11-27 22:32 [PATCH v2 0/3] power: supply: s2mu005-battery: add S2MU106 Adil Hüsrev Tepe
  2026-11-27 22:32 ` [PATCH v2 1/3] dt-bindings: power: supply: samsung,s2mu005-fuel-gauge: " Adil Hüsrev Tepe
  2026-11-27 22:32 ` [PATCH v2 2/3] power: supply: s2mu005-battery: make the alert interrupt optional Adil Hüsrev Tepe
@ 2026-11-27 22:32 ` Adil Hüsrev Tepe
  2 siblings, 0 replies; 4+ messages in thread
From: Adil Hüsrev Tepe @ 2026-11-27 22:32 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Kaustabh Chakraborty
  Cc: linux-pm, devicetree, linux-kernel, Krzysztof Kozlowski,
	Yassine Oudjana, Adil Hüsrev Tepe

The S2MU106 fuel gauge uses the same STATUS/RVBAT/RCURCC/RSOC registers
and scaling as the S2MU005, but has no MONOUT averaging path; reading the
averaged voltage and current through it returns bogus values. Add a
per-variant descriptor so the S2MU106 exposes only the instantaneous
voltage, current, capacity and status, and derive the status from the
instantaneous current when no average is available.

Signed-off-by: Adil Hüsrev Tepe <tadilhusrev@gmail.com>
---
 drivers/power/supply/s2mu005-battery.c | 61 +++++++++++++++++++++++++++++-----
 1 file changed, 52 insertions(+), 9 deletions(-)

diff --git a/drivers/power/supply/s2mu005-battery.c b/drivers/power/supply/s2mu005-battery.c
index 9798a62ffec..a1bd9ffdd61 100644
--- a/drivers/power/supply/s2mu005-battery.c
+++ b/drivers/power/supply/s2mu005-battery.c
@@ -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, &current_now);
 	if (ret < 0)
 		return ret;
 
-	ret = s2mu005_fg_get_current_avg(priv, &current_avg);
-	if (ret < 0)
-		return ret;
+	if (priv->has_monout) {
+		ret = s2mu005_fg_get_current_avg(priv, &current_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,
 	},
 	{ }
 };

-- 
2.53.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-27 22:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 22:32 [PATCH v2 0/3] power: supply: s2mu005-battery: add S2MU106 Adil Hüsrev Tepe
2026-11-27 22:32 ` [PATCH v2 1/3] dt-bindings: power: supply: samsung,s2mu005-fuel-gauge: " Adil Hüsrev Tepe
2026-11-27 22:32 ` [PATCH v2 2/3] power: supply: s2mu005-battery: make the alert interrupt optional Adil Hüsrev Tepe
2026-11-27 22:32 ` [PATCH v2 3/3] power: supply: s2mu005-battery: add S2MU106 support Adil Hüsrev Tepe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®