From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796526539; b=lVKJXPpwYUrxWZbI0XYQNBYTm1zb/8tkw+TSiJQMxJbBZ90wPCkr1yV7IuXvDNBH6dwU k1FdfxvhBHRZ+2wx+Sby6dgsI+IrhMPvJ2ZM4Q4TrvTW7MjvwYdgSrh8+XYqtvijrsqPp QBw2/vp4W0fnXeNMHeN1G2t/Jj/AzbAY1Ld+bYyXAu3leOnRAOAUIvZL4AzPV/NtdmP2V HUlbyjpgaHKw0MrhTsoYiy2evi50IenFn+vOClJxd0hutCEggkKZ5n0GQiWLUrp3KuuT6 s028cBxQJuqDhWziDRPGnNHoPNpvt9c2wQFJ0ow4dmwtxPk8AoGFF312GkCg/ZY7xdQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796526539; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=SXWrrKqEHG88tdIWUbodOcB/ATHm9MIA7Pd91j7QuO4=; b=KQe1fEWJT5ImzSlGTjF45B/Gm39qBLtGtRFPBNxssZ+7YgBmuV0IGNYD+BgrNbxnBin4 KQq61V+kwA7LujlsmxxzgEd8T3K9Wqm5o+SHS3+0pCzYlgAxdL3cr5X04xRaZJZd3AewX pv7h/DEF0dOGeGby4vLrBlcg1Ps9yxEWlJ+zfFOKE5yGY6jm57Kw+axUV04wE/3rlvpaV uqfj2rihCRsD9WpYhacLSucr2QhXHA8wPGuQ3eRqeUodzimDenyZySoMtIP2NhkI4gCHP IoS8LViYPGGUytojaU3A/FFl6Wc1rAEKu0EPMdCjMulzGLVXmfyHlojf3jlPurFTIjg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XwsiB2+O; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 937C9606A6A5; Sun, 6 Dec 2026 03:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XwsiB2+O Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796526539; b=ug7ecomUSTvxhDtLfn6pFge6ujY7si6t8+MREUjCY084NYZI3yxpBR+2IdnVctde0GQq nJZGodrpRL6vghHV/m4/8IGrfplWlMOsWxE091AoXPGErS160PqeZtsA2GN2mCMzPdwRP 91GM80ytb48mli2nEh+3JaAY+38rEa6tQxDOj1JQmS2/zULgdG/5dVO6u35n/HW43baQK ugJ9n5Y5bp24QOB7DjQ0kBMpdv+rBjjk5yLTFJVsGN4ExUTlq2dUMFIRiMAc9G5Vygq1T d6QW/d4+ZpS9oBkPYCnmqiXJkFW1EnotiKOcZ2zs3mP+8qj15zSINPQi/gCTk63FRYw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796526539; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=SXWrrKqEHG88tdIWUbodOcB/ATHm9MIA7Pd91j7QuO4=; b=ve1pB7lIbdWYYr9ZolZ/irXs6hDV2kaiQpX85ltBJEtq/etE0WgaA9BIAf43+tH/dWlu ez8yJXtCu83HOk9f51k4E+HMP7zq1nVDn9slqK6qN8dL3jHORp6ydzCMUX9iItOHuDn/U toXOL39UZfM0iAEu7pQrsb3UyEWLR98NlyauI/4lPPGJQVLZYoUeSHrc31RFoLJBQ8Sau y3N4essThSunNYMCuv0Faj93F3lw2yPDHMU3hepXYS9rQr5OdvipPsvNJ4iZxsdk+Jepd cyBUIRCAh7vyARPD+GUAaQmvaFdUUBnK8r7tEkG7FZ3NR2kvchLkyohv4gjYxiI3qwQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 390A11F00A11; Sun, 6 Dec 2026 03:08:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796526539; bh=SXWrrKqEHG88tdIWUbodOcB/ATHm9MIA7Pd91j7QuO4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=XwsiB2+OxWiUuEjObvLxfqe7U2k4GacndxK2jcKBVcip+C1W4z/5ZIqZdTgpvpW4c Hfdf41nCx+I5PXWIa3TZ7bDxTjJtcmY0afLHOeazUihvkSATQ/Mn2fgSV5SIbQD+Qo E+j+pQ/hG6PqQ5+YZ0Er5QWcfM44xt8LvjbAfEgDUiQavUWzwaJQsK67n3kLWVrMmQ d9frtVmkJzjusT6A86CkaBQ9s3l9GVJldyuueL3x4GomMzxyWW/E6jwtZhI5r/B2Q3 KQFMy8KZmdzxLnI/TxSj6+WjlrI5LwvrFahwxvMObYC46CsDJepEHAqp4HcqXHXmh/ I29/WcojI7PJQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 129BD505AE; Sun, 6 Dec 2026 03:08:57 +0000 (UTC) From: =?utf-8?q?Moln=C3=A1r_M=C3=A1t=C3=A9_via_B4_Relay?= Date: Sun, 06 Dec 2026 04:08:59 +0100 Subject: [PATCH v7 7/9] power: axp20x_battery: Estimate AXP192 capacity from the OCV table X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261206-axp192-v7-7-0200fc77da53@gmail.com> References: <20261206-axp192-v7-0-0200fc77da53@gmail.com> In-Reply-To: <20261206-axp192-v7-0-0200fc77da53@gmail.com> To: Jonathan Cameron , David Lechner , =?utf-8?q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Sebastian Reichel , Liam Girdwood , Mark Brown , Dmitry Torokhov , Lee Jones Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-input@vger.kernel.org, mfd@lists.linux.dev, Aidan MacDonald , Alex Bee , =?utf-8?q?Moln=C3=A1r_M=C3=A1t=C3=A9?= X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796526534; l=4207; i=matemolnar88@gmail.com; s=20261206; h=from:subject:message-id; bh=h+Qu+IJbIL+YLMXUbnjoOaDuPKAcbbKIyz5Qa/HcyR8=; b=VJEQU1q0sVBery87S2fuj5kxmXjI3t3jLNVJ/4sIpuaKuEQ9uQthl7lyQ73kQgHiXPButcApA 0mtguNLV2HnCGoMC/as2K2gncExUB/Whs4D9AUFT4Y1iHwaEbsqOS2p X-Developer-Key: i=matemolnar88@gmail.com; a=ed25519; pk=o0eaP3d+Tu4uOuWOIB+3z9PU2PVp44IJx39jgd4q4F4= X-Endpoint-Received: by B4 Relay for matemolnar88@gmail.com/20261206 with auth_id=1759 X-Original-From: =?utf-8?q?Moln=C3=A1r_M=C3=A1t=C3=A9?= Reply-To: matemolnar88@gmail.com Content-Transfer-Encoding: 8bit From: Molnár Máté The AXP192 has no fuel gauge, so the driver does not report a capacity at all. Userspace then has no idea how full the battery is: UPower, for example, reads 0% and powers the device off as soon as the battery reports discharging. Use the OCV table of the monitored battery, when one is given, to estimate the capacity from the battery voltage. The voltage is corrected for the drop across the battery's internal resistance when the battery info has it. Keep the battery info around for this on PMICs without a fuel gauge instead of releasing it after probe. Signed-off-by: Molnár Máté --- drivers/power/supply/axp20x_battery.c | 58 ++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index b55089a81..3c3cf349f 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -128,6 +129,8 @@ struct axp20x_batt_ps { /* Maximum constant charge current */ unsigned int max_ccc; const struct axp_data *data; + /* Battery info kept for the OCV capacity estimate on PMICs without FG */ + struct power_supply_battery_info *bat_info; bool ts_disable; }; @@ -285,6 +288,50 @@ static int axp717_get_constant_charge_current(struct axp20x_batt_ps *axp, return 0; } +static int axp20x_battery_get_prop(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val); + +/* + * Estimate the capacity from the open circuit voltage for PMICs without a + * fuel gauge, using the OCV table of the monitored battery. The OCV is + * approximated from the battery voltage and current with the battery's + * internal resistance, when it is known. + */ +static int axp20x_battery_ocv_capacity(struct axp20x_batt_ps *axp20x_batt, + int *val) +{ + struct power_supply_battery_info *info = axp20x_batt->bat_info; + union power_supply_propval v, i; + int ret; + + if (!info || !info->ocv_table[0]) + return -ENODATA; + + ret = axp20x_battery_get_prop(axp20x_batt->batt, + POWER_SUPPLY_PROP_VOLTAGE_NOW, &v); + if (ret) + return ret; + + ret = axp20x_battery_get_prop(axp20x_batt->batt, + POWER_SUPPLY_PROP_CURRENT_NOW, &i); + if (ret) + return ret; + + if (info->factory_internal_resistance_uohm > 0) + v.intval -= div_s64((s64)i.intval * + info->factory_internal_resistance_uohm, + 1000000); + + /* ponytail: no temperature sensor wired up, assume 20 C */ + ret = power_supply_batinfo_ocv2cap(info, v.intval, 20); + if (ret < 0) + return ret; + + *val = ret; + return 0; +} + static int axp20x_battery_get_prop(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -423,6 +470,10 @@ static int axp20x_battery_get_prop(struct power_supply *psy, return 0; } + if (!axp20x_batt->data->has_fg) + return axp20x_battery_ocv_capacity(axp20x_batt, + &val->intval); + ret = regmap_read(axp20x_batt->regmap, AXP20X_FG_RES, ®); if (ret) return ret; @@ -955,6 +1006,7 @@ static enum power_supply_property axp192_battery_props[] = { POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_VOLTAGE_MAX, POWER_SUPPLY_PROP_VOLTAGE_MIN, + POWER_SUPPLY_PROP_CAPACITY, }; static const struct power_supply_desc axp192_batt_ps_desc = { @@ -1237,7 +1289,11 @@ static int axp20x_power_probe(struct platform_device *pdev) if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) { axp20x_batt->data->set_bat_info(pdev, axp20x_batt, info); - power_supply_put_battery_info(axp20x_batt->batt, info); + /* Without a fuel gauge the OCV table is used for the capacity */ + if (axp20x_batt->data->has_fg) + power_supply_put_battery_info(axp20x_batt->batt, info); + else + axp20x_batt->bat_info = info; } /* -- 2.43.0