public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Kaustabh Chakraborty" <kauschluss@disroot.org>
To: "Sebastian Reichel" <sebastian.reichel@collabora.com>,
	"Kaustabh Chakraborty" <kauschluss@disroot.org>
Cc: "Yassine Oudjana" <y.oudjana@protonmail.com>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>, <linux-pm@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] power: supply: add support for S2MU005 battery fuel gauge device
Date: Sat, 31 Jan 2026 16:44:36 +0530	[thread overview]
Message-ID: <DG2QBROWWMLI.2EE3CBLLPAJHR@disroot.org> (raw)
In-Reply-To: <aXq7NohfIy3c5AWL@venus>

On 2026-01-29 02:59 +01:00, Sebastian Reichel wrote:
> Hi,
>
> On Mon, Jan 26, 2026 at 09:09:49PM +0530, Kaustabh Chakraborty wrote:
>> From: Yassine Oudjana <y.oudjana@protonmail.com>
>> 
>> Samsung's S2MU005 PMIC, which contains battery charger functionality
>> also includes a battery fuel gauge device, which is separate from the
>> PMIC itself, and typically connected to an I2C bus. Add a generic driver
>> to support said device.
>> 
>> Signed-off-by: Yassine Oudjana <y.oudjana@protonmail.com>
>> Co-developed-by: Kaustabh Chakraborty <kauschluss@disroot.org>
>> Signed-off-by: Kaustabh Chakraborty <kauschluss@disroot.org>
>> ---

[...]

>> +
>> +static const struct regmap_config s2mu005_fg_regmap_config = {
>> +	.reg_bits = 8,
>> +	.val_bits = 8,
>> +};
>
> Looks like all register addresses are 2 byte aligned and you are
> always using regmap_raw_read to get 16bit values. So just use
> .val_bits = 16 here?

Sure.

>> +static int s2mu005_fg_get_status(struct s2mu005_fg *priv, int *value)
>> +{
>> +	int current_now;
>> +	int capacity;
>> +	int ret;
>> +
>> +	ret = s2mu005_fg_get_current_now(priv, &current_now);
>> +	if (ret)
>> +		return ret;
>> +
>> +	if (current_now <= 0) {
>> +		*value = POWER_SUPPLY_STATUS_DISCHARGING;
>> +		return 0;
>> +	}
>> +
>> +	ret = s2mu005_fg_get_capacity(priv, &capacity);
>> +	if (ret)
>> +		return ret;
>> +
>> +	if (capacity < 90)
>> +		*value = POWER_SUPPLY_STATUS_CHARGING;
>> +	else
>> +		*value = POWER_SUPPLY_STATUS_FULL;
>
> Usually there is some kind of hysteresis that stops charging
> when the battery is full and then restarts charging once the
> battery drops under a certain capacity. As this code first
> checks the current to determine if the battery is discharging
> and only then checks if the battery is full - does your code
> toggle between FULL and DISCHARGING?

(Perhaps I misunderstood your query, let me know if I did)

It has been a while since I last tested this - but as far as I can
recall, after a certain threshold, the current would constantly bounce
between -ve and +ve. I believe it was somewhere around 90% to 95% and
above. If that's what 'hysteresis' is, then yes.

An older revision of this driver (I don't have it anymore) used to add
up the consecutive values of current in order to reduce the effect of
this inconsistency, but it was still unreliable.

Moreover, I do not possess any documentation for this device, so it's
not possible for me to know what or how.

  reply	other threads:[~2026-01-31 11:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-26 15:39 [PATCH 0/2] Add support for Samsung S2MU005 battery fuel gauge device Kaustabh Chakraborty
2026-01-26 15:39 ` [PATCH 1/2] dt-bindings: power: supply: document Samsung S2MU005 battery fuel gauge Kaustabh Chakraborty
2026-01-26 20:06   ` Conor Dooley
2026-01-26 20:15     ` Kaustabh Chakraborty
2026-01-26 15:39 ` [PATCH 2/2] power: supply: add support for S2MU005 battery fuel gauge device Kaustabh Chakraborty
2026-01-29  1:59   ` Sebastian Reichel
2026-01-31 11:14     ` Kaustabh Chakraborty [this message]
2026-02-01 11:14       ` Sebastian Reichel
2026-02-01 14:29         ` Kaustabh Chakraborty
2026-02-06 13:04         ` Kaustabh Chakraborty

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=DG2QBROWWMLI.2EE3CBLLPAJHR@disroot.org \
    --to=kauschluss@disroot.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sebastian.reichel@collabora.com \
    --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