From: "Adil Hüsrev Tepe" <tadilhusrev@gmail.com>
To: Sebastian Reichel <sre@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Kaustabh Chakraborty <kauschluss@disroot.org>
Cc: "Yassine Oudjana" <y.oudjana@protonmail.com>,
linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Adil Hüsrev Tepe" <tadilhusrev@gmail.com>
Subject: [PATCH v1 3/3] power: supply: s2mu005-battery: add S2MU106 support
Date: Mon, 16 Nov 2026 10:40:00 +0300 [thread overview]
Message-ID: <20261116074000.355176-4-tadilhusrev@gmail.com> (raw)
In-Reply-To: <20261116074000.355176-1-tadilhusrev@gmail.com>
The 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.
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 9798a62ff..a1bd9ffdd 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, ¤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,
},
{ }
};
--
2.53.0
prev parent reply other threads:[~2026-11-16 7:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 7:39 [PATCH v1 0/3] power: supply: s2mu005-battery: add S2MU106 (Samsung Galaxy XCover5) Adil Hüsrev Tepe
2026-11-16 7:39 ` [PATCH v1 1/3] dt-bindings: power: supply: samsung,s2mu005-fuel-gauge: add S2MU106 Adil Hüsrev Tepe
2026-11-16 7:39 ` [PATCH v1 2/3] power: supply: s2mu005-battery: make the alert interrupt optional Adil Hüsrev Tepe
2026-11-16 7:40 ` Adil Hüsrev Tepe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116074000.355176-4-tadilhusrev@gmail.com \
--to=tadilhusrev@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kauschluss@disroot.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sre@kernel.org \
--cc=y.oudjana@protonmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®