From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?utf-8?q?Moln=C3=A1r_M=C3=A1t=C3=A9?= Date: Sun, 06 Dec 2026 04:08:57 +0100 Subject: [PATCH v7 5/9] power: axp20x_battery: Support battery status without fuel gauge MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20261206-axp192-v7-5-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=3431; i=matemolnar88@gmail.com; s=20261206; h=from:subject:message-id; bh=VrjYBKS/vVtYCZnCha3sxBNctnfLASAsDmOz6G2K9kg=; b=rQQIep2KKNUHHjBGWi4fMz36WFch+b0w0PHPbEQQsygnlavV/QPAHlUOSxHjs5NzpCCzVTJw1 7naQUJaR1QzB+mhOwinDwTBz5LjRElwxRS9H/y/lmQd1xl8Z1pzPM5a 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 List-Id: B4 Relay Submissions From: Aidan MacDonald Add a "has_fg" flag to indicate that the chip has a fuel gauge. Report battery full status on chips with no fuel gauge using the battery voltage. Signed-off-by: Aidan MacDonald [Molnár Máté: rebased onto the current driver, which now has per-variant descriptors and callbacks; dropped the review tags because of the rework] Signed-off-by: Molnár Máté --- drivers/power/supply/axp20x_battery.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index f31b735ed..f7485ac6a 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -106,6 +106,7 @@ struct axp_data { * must have AXP20X_CHRG_CTRL1_TGT_CURR+1 elements. */ const int *ccc_table; + bool has_fg; bool has_fg_valid; const struct power_supply_desc *bat_ps_desc; int (*get_max_voltage)(struct axp20x_batt_ps *batt, int *val); @@ -289,7 +290,7 @@ static int axp20x_battery_get_prop(struct power_supply *psy, union power_supply_propval *val) { struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy); - int ret = 0, reg, val1; + int ret = 0, reg, val1, val2; switch (psp) { case POWER_SUPPLY_PROP_PRESENT: @@ -323,6 +324,34 @@ static int axp20x_battery_get_prop(struct power_supply *psy, return 0; } + /* + * If the chip does not have a fuel gauge, we check battery full status + * using voltage instead. + */ + if (!axp20x_batt->data->has_fg) { + ret = axp20x_batt->data->get_max_voltage(axp20x_batt, &val1); + if (ret) + return ret; + + ret = iio_read_channel_processed(axp20x_batt->batt_v, &val2); + if (ret) + return ret; + + /* IIO subsystem reports voltage in mV but we need uV */ + val2 *= 1000; + + /* + * According to the AXP192 datasheet, charging will restart if + * the battery voltage drops below V_rch = V_tgt - 0.1 V, so we + * report the battery is full if its voltage is at least V_rch. + */ + if (val2 >= val1 - 100000) + val->intval = POWER_SUPPLY_STATUS_FULL; + else + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; + break; + } + ret = regmap_read(axp20x_batt->regmap, AXP20X_FG_RES, &val1); if (ret) return ret; @@ -1062,6 +1091,7 @@ static const struct axp_data axp209_data = { .ccc_offset = 300000, .ccc_reg = AXP20X_CHRG_CTRL1, .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR, + .has_fg = true, .bat_ps_desc = &axp209_batt_ps_desc, .get_max_voltage = axp20x_battery_get_max_voltage, .set_max_voltage = axp20x_battery_set_max_voltage, @@ -1075,6 +1105,7 @@ static const struct axp_data axp221_data = { .ccc_reg = AXP20X_CHRG_CTRL1, .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR, .has_fg_valid = true, + .has_fg = true, .bat_ps_desc = &axp209_batt_ps_desc, .get_max_voltage = axp22x_battery_get_max_voltage, .set_max_voltage = axp22x_battery_set_max_voltage, @@ -1100,6 +1131,7 @@ static const struct axp_data axp813_data = { .ccc_reg = AXP20X_CHRG_CTRL1, .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR, .has_fg_valid = true, + .has_fg = true, .bat_ps_desc = &axp209_batt_ps_desc, .get_max_voltage = axp813_battery_get_max_voltage, .set_max_voltage = axp20x_battery_set_max_voltage, -- 2.43.0 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=OM1eOPcMagFNK6/lpLjP6R5fZHZnARb+MEFEOMyhS9fm7MB7LMMR9dcmHH++2GN5ewKK yKhePue/zk5xYgr/HcRHultC4XBtlqoujuDWWjRC072LSfDSJ32i6ySm34cLvZMTCFbNS 476utqKboTOG699+SzTOvdcuN9RMjy9Q7Ghk6O1GmgAl1N9643qrB5RUEO9WHBn7j7cgO C0xh0LsQjuZpkfITA8Y0cAka/m5jR5fVUNwijdSBg6wWJgTMZXDOkPYV/3R1T5/IoUYl8 bhTaCYFVLeCUZT5743Dkku8Ig4y8AgZ3VNxs4Ti4Y74mwGQtk22EtMaQcAF9fCIPitg== 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:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Endpoint-Received:X-Original-From:Reply-To; bh=z+yykFFZsf5IONryJBJ11O4YKmZ5slNMsmIt8+0xUMo=; b=lJM0gv9xecRlk+X1+jRzTWiiijDFe0Ro+o3qvej5c440l3Q32rps9gvd6w8lsj5Bsce0 7hQMFNL3PCvQ5NXyWGtCb05EJrqrjaefkbB+cUljLC++JEsxCO1CvrGaoRl2KTvauNJdt 8GptJlZLdUmvc8C4/hOBEMnr+bZ6tub/IfXFLI4NCqIkzelO8Vj+EkhvgFxNyOEvswyy1 4jh8Mz2xSJW+I499Xd0AuSOn70h31hUpSt00mpJRoElorx8syXRpk1ZaoooHT7XwYAUL1 qbbGrwYsywXYaOkJSe/ebVjJb/X6ffcpvZT7p7Ng28ZdkpzqIyCp91xgDeRxyy4xGzw== 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=hsEpX+wL; 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 A0E43606A6AB; 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=hsEpX+wL 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=qua8YEJaQeoRjzU5IQYTo4GPzHYMQwWCYjTYS/WFGUzQuquAecDUdJ2JdiaZyG5rDzcf E2PTpsIwyjib3L+f73kEu3zD1NMpX1hTd15qyyvu2f3Qsk8hCLnQFlK84bBnO19aAISgt 1Qo+FQ3tjNP10qduTBGJJqLWZMwb28hsWpDlcjdxUJ7Hogp5TUlLTeznJMnejZpLkHKws CIxZxJ81baI2SaT9H4l0tzyYufBo2rI/Xe6wmYK++IdT98xYZsjlXhv6rNA3oldFE1nE7 mg0ZEH0Pasu5X6HuFBAo14OPHX0S0LXvPvc+Y/GwcrhiuEPOA5QSFPNVs+kNn7DO2Ow== 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: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=z+yykFFZsf5IONryJBJ11O4YKmZ5slNMsmIt8+0xUMo=; b=jMAPLwWRZvAxjr8rIYi6gCJChsfmWqTkjL/Z8o+cSH/pqBu/qPRZW+G/HkSMaNht3tkT NRTQ63/2xTbQzharrmK0t+5shFOxPJsC4ym2oXq+B4WBVsAhaeMFWqM3R8wvcEggu8Eh1 +90FdHasTckfocsQh7nSxOKOWA90gjRkgBu9xBLpl+AgUUsraVe2cPv9BC+QZWam7wzi+ OVMtneNGBDpxApIQSt8vkvSoN90HgZF/pdIiReAF+O7B9Uv//op5E04ww3dZtMIMGEOwQ /o2kwxn9927FPzS3e3DBcxJpIfsEjJcnsdXd+LvW3BpYK6rDNbzziVyva+QtAObA1Iw== 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 78F471F00A07; Sun, 6 Dec 2026 03:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796526539; bh=z+yykFFZsf5IONryJBJ11O4YKmZ5slNMsmIt8+0xUMo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=hsEpX+wLXEbgrxF0duqbDiaEKNIA0uXnyg5/NbwCJUd5GsMrNdICofRS1GSu+3R2N HrIDhSrL4e2gBTkF5+bSjiFjIov27k1/hpJhrsg2BF9QhPmYYUnZMzA8Tb9V/+g+Ni PcGBSEEttSoB8Mca7e3T7gRBIpEaGw7eIgw4EMJIP9dLi5DFAnF21iPgc2ud2rlrkf IVj9gtVCF2SGybJtJQsfzGTzAGkGfMM53Eb2ZMYM059ec+udgUJBbMO8H6VmxtX9LV zrArEP7gSq0izjzXMq2kK2rQMoMZqAoxfSIA+8YxmoPzGWjikBCee/7WcCOCqH2R0g svyFYeY7WKOAQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id B2394505A6; Sun, 6 Dec 2026 03:08:56 +0000 (UTC) From: =?utf-8?q?Moln=C3=A1r_M=C3=A1t=C3=A9_via_B4_Relay?= Date: Sun, 06 Dec 2026 04:08:57 +0100 Subject: [PATCH v7 5/9] power: axp20x_battery: Support battery status without fuel gauge X-Mailing-List: devicetree@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" Content-Transfer-Encoding: 8bit Message-Id: <20261206-axp192-v7-5-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=3431; i=matemolnar88@gmail.com; s=20261206; h=from:subject:message-id; bh=VrjYBKS/vVtYCZnCha3sxBNctnfLASAsDmOz6G2K9kg=; b=rQQIep2KKNUHHjBGWi4fMz36WFch+b0w0PHPbEQQsygnlavV/QPAHlUOSxHjs5NzpCCzVTJw1 7naQUJaR1QzB+mhOwinDwTBz5LjRElwxRS9H/y/lmQd1xl8Z1pzPM5a 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 From: Aidan MacDonald Add a "has_fg" flag to indicate that the chip has a fuel gauge. Report battery full status on chips with no fuel gauge using the battery voltage. Signed-off-by: Aidan MacDonald [Molnár Máté: rebased onto the current driver, which now has per-variant descriptors and callbacks; dropped the review tags because of the rework] Signed-off-by: Molnár Máté --- drivers/power/supply/axp20x_battery.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index f31b735ed..f7485ac6a 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -106,6 +106,7 @@ struct axp_data { * must have AXP20X_CHRG_CTRL1_TGT_CURR+1 elements. */ const int *ccc_table; + bool has_fg; bool has_fg_valid; const struct power_supply_desc *bat_ps_desc; int (*get_max_voltage)(struct axp20x_batt_ps *batt, int *val); @@ -289,7 +290,7 @@ static int axp20x_battery_get_prop(struct power_supply *psy, union power_supply_propval *val) { struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy); - int ret = 0, reg, val1; + int ret = 0, reg, val1, val2; switch (psp) { case POWER_SUPPLY_PROP_PRESENT: @@ -323,6 +324,34 @@ static int axp20x_battery_get_prop(struct power_supply *psy, return 0; } + /* + * If the chip does not have a fuel gauge, we check battery full status + * using voltage instead. + */ + if (!axp20x_batt->data->has_fg) { + ret = axp20x_batt->data->get_max_voltage(axp20x_batt, &val1); + if (ret) + return ret; + + ret = iio_read_channel_processed(axp20x_batt->batt_v, &val2); + if (ret) + return ret; + + /* IIO subsystem reports voltage in mV but we need uV */ + val2 *= 1000; + + /* + * According to the AXP192 datasheet, charging will restart if + * the battery voltage drops below V_rch = V_tgt - 0.1 V, so we + * report the battery is full if its voltage is at least V_rch. + */ + if (val2 >= val1 - 100000) + val->intval = POWER_SUPPLY_STATUS_FULL; + else + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; + break; + } + ret = regmap_read(axp20x_batt->regmap, AXP20X_FG_RES, &val1); if (ret) return ret; @@ -1062,6 +1091,7 @@ static const struct axp_data axp209_data = { .ccc_offset = 300000, .ccc_reg = AXP20X_CHRG_CTRL1, .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR, + .has_fg = true, .bat_ps_desc = &axp209_batt_ps_desc, .get_max_voltage = axp20x_battery_get_max_voltage, .set_max_voltage = axp20x_battery_set_max_voltage, @@ -1075,6 +1105,7 @@ static const struct axp_data axp221_data = { .ccc_reg = AXP20X_CHRG_CTRL1, .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR, .has_fg_valid = true, + .has_fg = true, .bat_ps_desc = &axp209_batt_ps_desc, .get_max_voltage = axp22x_battery_get_max_voltage, .set_max_voltage = axp22x_battery_set_max_voltage, @@ -1100,6 +1131,7 @@ static const struct axp_data axp813_data = { .ccc_reg = AXP20X_CHRG_CTRL1, .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR, .has_fg_valid = true, + .has_fg = true, .bat_ps_desc = &axp209_batt_ps_desc, .get_max_voltage = axp813_battery_get_max_voltage, .set_max_voltage = axp20x_battery_set_max_voltage, -- 2.43.0