From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from layka.disroot.org (layka.disroot.org [178.21.23.139]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A19FD313E10; Fri, 6 Feb 2026 13:04:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.21.23.139 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770383094; cv=none; b=Ebnd5T+1H3eGJ0ENRlGCJ2bMYyJZ90/EnArNh2+JqNeiloU7MB7XaD7++7p6XpwSDVIdNmfmwGUHrq2W8XIt2inJQYCneIwqJFB/3VQXBGNpx7oiAUtu5Fxur+l7rmNMEw6Pkt0sHM9c/4/4H1qegMei8ZN+o8+LNjZ91KpUw/w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770383094; c=relaxed/simple; bh=ApWPhL6JQBKOjYvyWVNeD4gaRhQWHkve1pRyR2n+Sdo=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=FQYoJzPThKsVksvmbihBOT3KMtDJKU8MejN1O9KZmqArgPjjxQEK9NqAP4iVT7T51VLMTfyFp9iMS2qmzv+TfL/Xr+HTI2K7OYuBMOJGGViVBtUn7/adf1tDDvgXlPDkQcp9WnTGzPUdsHtCtOvVc1Z/sD60zQe+plrX5ppcBJg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org; spf=pass smtp.mailfrom=disroot.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.b=X49wI0kX; arc=none smtp.client-ip=178.21.23.139 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=disroot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=disroot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=disroot.org header.i=@disroot.org header.b="X49wI0kX" Received: from [127.0.0.1] (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id A90A525F3F; Fri, 6 Feb 2026 14:04:51 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id cfgujahYoJKc; Fri, 6 Feb 2026 14:04:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1770383091; bh=ApWPhL6JQBKOjYvyWVNeD4gaRhQWHkve1pRyR2n+Sdo=; h=Date:Cc:Subject:From:To:References:In-Reply-To; b=X49wI0kX9/xFhK147Q1nKOBVuMw59bC30WOKQwfWva0RLzTbdUe1L8LgIuGApjbcF 1I548ua2067P1/kaDqtD55RV7/x+5fA67RxtAajfdHvSJkhIbgSv9FjUI05fTWyl0G kmkgbIGEQlrExgUASdflLJP1nVubJwDf1thQ3X6rBQi190pgb1R6vX3wgQy68qQQec n5ffj9hetUofNH8G3tF6r9SRtVdMEUVvD0EVloIGSB9dJ2YDfP4BqqBTmWknzqdTh4 yUaL1esaswwpSMijGLGqIWUf5INPVnO8jSoO6SKTp+uCmI7Ts7blad3TG4k3VQJ4KU 4RUN5TEGfGH7g== Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 06 Feb 2026 18:34:45 +0530 Message-Id: Cc: "Yassine Oudjana" , "Rob Herring" , "Krzysztof Kozlowski" , "Conor Dooley" , , , Subject: Re: [PATCH 2/2] power: supply: add support for S2MU005 battery fuel gauge device From: "Kaustabh Chakraborty" To: "Sebastian Reichel" , "Kaustabh Chakraborty" References: <20260126-s2mu005-fuelgauge-v1-0-68a146ed0819@disroot.org> <20260126-s2mu005-fuelgauge-v1-2-68a146ed0819@disroot.org> In-Reply-To: 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 =3D s2mu005_fg_get_current_now(priv, ¤t_now); >> >> + if (ret) >> >> + return ret; >> >> + >> >> + if (current_now <=3D 0) { >> >> + *value =3D POWER_SUPPLY_STATUS_DISCHARGING; >> >> + return 0; >> >> + } >> >> + >> >> + ret =3D s2mu005_fg_get_capacity(priv, &capacity); >> >> + if (ret) >> >> + return ret; >> >> + >> >> + if (capacity < 90) >> >> + *value =3D POWER_SUPPLY_STATUS_CHARGING; >> >> + else >> >> + *value =3D 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. >>=20 >> 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 >=3D 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 =3D=3D 0) > return POWER_SUPPLY_STATUS_NOT_CHARGING; > else > return POWER_SUPPLY_STATUS_CHARGING; > > Greetings, > > -- Sebastian