Re: [PATCH 2/2] power: supply: add support for S2MU005 battery fuel gauge device
From: Kaustabh Chakraborty
Date: Fri Feb 06 2026 - 08:04:58 EST
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, ¤t_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;
[...]
>> 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;
So I have tested this. Should it not be discharging when power is not
connected (current_now > 0). Doing this shows 'fully-charged' in upower,
with the charging symbol in GNOME even if the charger is not connected.
In such case, the logic in the current revision of the driver is
correct, where it assumes the battery to be full ONLY if it is charging.
>
> 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;
>
> Greetings,
>
> -- Sebastian