lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <DG3P3DHVSC0J.2LVZT4D9SA2QH@disroot.org>
Date: Sun, 01 Feb 2026 19:59:17 +0530
From: "Kaustabh Chakraborty" <kauschluss@...root.org>
To: "Sebastian Reichel" <sebastian.reichel@...labora.com>, "Kaustabh
 Chakraborty" <kauschluss@...root.org>
Cc: "Yassine Oudjana" <y.oudjana@...tonmail.com>, "Rob Herring"
 <robh@...nel.org>, "Krzysztof Kozlowski" <krzk+dt@...nel.org>, "Conor
 Dooley" <conor+dt@...nel.org>, <linux-pm@...r.kernel.org>,
 <devicetree@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/2] power: supply: add support for S2MU005 battery fuel
 gauge device

On 2026-02-01 12:14 +01:00, Sebastian Reichel wrote:
> Hi,
>
> On Sat, Jan 31, 2026 at 04:44:36PM +0530, Kaustabh Chakraborty wrote:
>> On 2026-01-29 02:59 +01:00, Sebastian Reichel wrote:
>> >> +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.
>
> A typical charging setup is:
>
> 1. charge to 100%
> 2. stop charging
> 3. wait for charge to drop under 95% (or some other treshold)
> 4. restart charging
> 5. go to 1

Yes, I believe that's what's happening internally. I just tested it and
the threshold seems to be much higher, at ~97%. I will update it in the
next revision then.

>> 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.
>
> For the setup I described above, you consider everything above the
> treshold as POWER_SUPPLY_STATUS_FULL independent of the current
> direction. So you need to reorder:
>
> if (capacity >= 90)
>     return POWER_SUPPLY_STATUS_FULL;
>
> if (current_now < 0)
>     return POWER_SUPPLY_STATUS_DISCHARGING;
> else if (current_now == 0)
>     return POWER_SUPPLY_STATUS_NOT_CHARGING;
> else
>     return POWER_SUPPLY_STATUS_CHARGING;

Understood. I will re-implement it in this order then.

>
> Greetings,
>
> -- Sebastian


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ