* [PATCH v7 1/9] dt-bindings: iio: adc: axp209: Add AXP192 compatible
2026-12-06 3:08 [PATCH v7 0/9] Add the remaining AXP192 PMIC support Molnár Máté via B4 Relay
@ 2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:08 ` [PATCH v7 2/9] dt-bindings: power: axp20x-battery: " Molnár Máté via B4 Relay
` (7 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Molnár Máté via B4 Relay @ 2026-12-06 3:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chen-Yu Tsai,
Sebastian Reichel, Liam Girdwood, Mark Brown, Dmitry Torokhov,
Lee Jones
Cc: linux-iio, devicetree, linux-kernel, linux-pm, linux-input, mfd,
Aidan MacDonald, Alex Bee, Molnár Máté,
Chen-Yu Tsai
From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
The AXP192 is identical to the AXP20x, except for two additional
GPIO ADC channels.
Acked-by: Rob Herring <robh@kernel.org>
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Signed-off-by: Molnár Máté <matemolnar88@gmail.com>
---
.../bindings/iio/adc/x-powers,axp209-adc.yaml | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml b/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml
index de91cb03f..b3ab1a9e1 100644
--- a/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml
+++ b/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml
@@ -14,6 +14,23 @@ description: |
Device is a child of an axp209 multifunction device
ADC channels and their indexes per variant:
+ AXP192
+ ------
+ 0 | acin_v
+ 1 | acin_i
+ 2 | vbus_v
+ 3 | vbus_i
+ 4 | pmic_temp
+ 5 | gpio0_v
+ 6 | gpio1_v
+ 7 | gpio2_v
+ 8 | gpio3_v
+ 9 | ipsout_v
+ 10 | batt_v
+ 11 | batt_chrg_i
+ 12 | batt_dischrg_i
+ 13 | ts_v
+
AXP209
------
0 | acin_v
@@ -60,6 +77,7 @@ description: |
properties:
compatible:
oneOf:
+ - const: x-powers,axp192-adc
- const: x-powers,axp209-adc
- const: x-powers,axp221-adc
- const: x-powers,axp717-adc
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v7 2/9] dt-bindings: power: axp20x-battery: Add AXP192 compatible
2026-12-06 3:08 [PATCH v7 0/9] Add the remaining AXP192 PMIC support Molnár Máté via B4 Relay
2026-12-06 3:08 ` [PATCH v7 1/9] dt-bindings: iio: adc: axp209: Add AXP192 compatible Molnár Máté via B4 Relay
@ 2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:08 ` [PATCH v7 3/9] regulator: axp20x: Add support for AXP192 Molnár Máté via B4 Relay
` (6 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Molnár Máté via B4 Relay @ 2026-12-06 3:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chen-Yu Tsai,
Sebastian Reichel, Liam Girdwood, Mark Brown, Dmitry Torokhov,
Lee Jones
Cc: linux-iio, devicetree, linux-kernel, linux-pm, linux-input, mfd,
Aidan MacDonald, Alex Bee, Molnár Máté
From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
The AXP192's battery charger is similar to the others supported by
the axp20x_battery driver.
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Signed-off-by: Molnár Máté <matemolnar88@gmail.com>
---
.../bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml
index a90d558e7..f7f6cd3f7 100644
--- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml
+++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml
@@ -17,6 +17,7 @@ maintainers:
properties:
compatible:
oneOf:
+ - const: x-powers,axp192-battery-power-supply
- const: x-powers,axp202-battery-power-supply
- const: x-powers,axp209-battery-power-supply
- const: x-powers,axp221-battery-power-supply
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v7 3/9] regulator: axp20x: Add support for AXP192
2026-12-06 3:08 [PATCH v7 0/9] Add the remaining AXP192 PMIC support Molnár Máté via B4 Relay
2026-12-06 3:08 ` [PATCH v7 1/9] dt-bindings: iio: adc: axp209: Add AXP192 compatible Molnár Máté via B4 Relay
2026-12-06 3:08 ` [PATCH v7 2/9] dt-bindings: power: axp20x-battery: " Molnár Máté via B4 Relay
@ 2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:22 ` sashiko-bot
2026-12-06 3:08 ` [PATCH v7 4/9] power: axp20x_battery: Add constant charge current table Molnár Máté via B4 Relay
` (5 subsequent siblings)
8 siblings, 1 reply; 16+ messages in thread
From: Molnár Máté via B4 Relay @ 2026-12-06 3:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chen-Yu Tsai,
Sebastian Reichel, Liam Girdwood, Mark Brown, Dmitry Torokhov,
Lee Jones
Cc: linux-iio, devicetree, linux-kernel, linux-pm, linux-input, mfd,
Aidan MacDonald, Alex Bee, Andy Shevchenko,
Molnár Máté
From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Add support for the AXP192 PMIC.
Acked-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Signed-off-by: Molnár Máté <matemolnar88@gmail.com>
---
drivers/regulator/axp20x-regulator.c | 100 +++++++++++++++++++++++++++++++----
1 file changed, 91 insertions(+), 9 deletions(-)
diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
index 53b1e0499..efd4a3bc3 100644
--- a/drivers/regulator/axp20x-regulator.c
+++ b/drivers/regulator/axp20x-regulator.c
@@ -26,6 +26,29 @@
#include <linux/regulator/machine.h>
#include <linux/regulator/of_regulator.h>
+#define AXP192_GPIO0_FUNC_MASK GENMASK(2, 0)
+
+#define AXP192_IO_ENABLED 0x02
+#define AXP192_IO_DISABLED 0x06
+
+#define AXP192_WORKMODE_DCDC1_MASK BIT_MASK(3)
+#define AXP192_WORKMODE_DCDC2_MASK BIT_MASK(2)
+#define AXP192_WORKMODE_DCDC3_MASK BIT_MASK(1)
+
+#define AXP192_DCDC1_V_OUT_MASK GENMASK(6, 0)
+#define AXP192_DCDC2_V_OUT_MASK GENMASK(5, 0)
+#define AXP192_DCDC3_V_OUT_MASK GENMASK(6, 0)
+#define AXP192_LDO2_V_OUT_MASK GENMASK(7, 4)
+#define AXP192_LDO3_V_OUT_MASK GENMASK(3, 0)
+#define AXP192_LDO_IO0_V_OUT_MASK GENMASK(7, 4)
+
+#define AXP192_PWR_OUT_EXTEN_MASK BIT_MASK(6)
+#define AXP192_PWR_OUT_DCDC2_MASK BIT_MASK(4)
+#define AXP192_PWR_OUT_LDO3_MASK BIT_MASK(3)
+#define AXP192_PWR_OUT_LDO2_MASK BIT_MASK(2)
+#define AXP192_PWR_OUT_DCDC3_MASK BIT_MASK(1)
+#define AXP192_PWR_OUT_DCDC1_MASK BIT_MASK(0)
+
#define AXP20X_GPIO0_FUNC_MASK GENMASK(3, 0)
#define AXP20X_GPIO1_FUNC_MASK GENMASK(3, 0)
@@ -460,25 +483,32 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)
switch (axp20x->variant) {
case AXP209_ID:
- if (id == AXP20X_DCDC2) {
+ if (id == AXP20X_LDO3) {
slew_rates = axp209_dcdc2_ldo3_slew_rates;
rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates);
reg = AXP20X_DCDC2_LDO3_V_RAMP;
- mask = AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK |
- AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK;
+ mask = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK |
+ AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK;
enable = (ramp > 0) ?
- AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN : 0;
+ AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN : 0;
break;
}
- if (id == AXP20X_LDO3) {
+ fallthrough;
+
+ case AXP192_ID:
+ /*
+ * AXP192 and AXP209 share the same DCDC2 ramp configuration
+ */
+ if ((axp20x->variant == AXP209_ID && id == AXP20X_DCDC2) ||
+ (axp20x->variant == AXP192_ID && id == AXP192_DCDC2)) {
slew_rates = axp209_dcdc2_ldo3_slew_rates;
rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates);
reg = AXP20X_DCDC2_LDO3_V_RAMP;
- mask = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK |
- AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK;
+ mask = AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK |
+ AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK;
enable = (ramp > 0) ?
- AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN : 0;
+ AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN : 0;
break;
}
@@ -500,7 +530,8 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)
if (ramp > slew_rates[i])
break;
- if (id == AXP20X_DCDC2)
+ if ((axp20x->variant == AXP209_ID && id == AXP20X_DCDC2) ||
+ (axp20x->variant == AXP192_ID && id == AXP192_DCDC2))
cfg = AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE(i);
else
cfg = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE(i);
@@ -596,6 +627,29 @@ static const struct regulator_ops axp20x_ops_sw = {
.is_enabled = regulator_is_enabled_regmap,
};
+static const struct regulator_desc axp192_regulators[] = {
+ AXP_DESC(AXP192, DCDC1, "dcdc1", "vin1", 700, 3500, 25,
+ AXP192_DCDC1_V_OUT, AXP192_DCDC1_V_OUT_MASK,
+ AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_DCDC1_MASK),
+ AXP_DESC(AXP192, DCDC2, "dcdc2", "vin2", 700, 2275, 25,
+ AXP192_DCDC2_V_OUT, AXP192_DCDC2_V_OUT_MASK,
+ AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_DCDC2_MASK),
+ AXP_DESC(AXP192, DCDC3, "dcdc3", "vin3", 700, 3500, 25,
+ AXP192_DCDC3_V_OUT, AXP192_DCDC3_V_OUT_MASK,
+ AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_DCDC3_MASK),
+ AXP_DESC_FIXED(AXP192, LDO1, "ldo1", "acin", 1250),
+ AXP_DESC(AXP192, LDO2, "ldo2", "ldoin", 1800, 3300, 100,
+ AXP192_LDO2_3_V_OUT, AXP192_LDO2_V_OUT_MASK,
+ AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_LDO2_MASK),
+ AXP_DESC(AXP192, LDO3, "ldo3", "ldoin", 1800, 3300, 100,
+ AXP192_LDO2_3_V_OUT, AXP192_LDO3_V_OUT_MASK,
+ AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_LDO3_MASK),
+ AXP_DESC_IO(AXP192, LDO_IO0, "ldo_io0", "ips", 700, 3300, 100,
+ AXP192_LDO_IO0_V_OUT, AXP192_LDO_IO0_V_OUT_MASK,
+ AXP192_GPIO0_CTRL, AXP192_GPIO0_FUNC_MASK,
+ AXP192_IO_ENABLED, AXP192_IO_DISABLED),
+};
+
static const struct linear_range axp20x_ldo4_ranges[] = {
REGULATOR_LINEAR_RANGE(1250000,
AXP20X_LDO4_V_OUT_1250mV_START,
@@ -1314,6 +1368,12 @@ static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq)
u32 min, max, def, step;
switch (axp20x->variant) {
+ case AXP192_ID:
+ min = 900;
+ max = 2025;
+ def = 1500;
+ step = 75;
+ break;
case AXP202_ID:
case AXP209_ID:
min = 750;
@@ -1418,6 +1478,24 @@ static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 work
unsigned int mask;
switch (axp20x->variant) {
+ case AXP192_ID:
+ switch (id) {
+ case AXP192_DCDC1:
+ mask = AXP192_WORKMODE_DCDC1_MASK;
+ break;
+ case AXP192_DCDC2:
+ mask = AXP192_WORKMODE_DCDC2_MASK;
+ break;
+ case AXP192_DCDC3:
+ mask = AXP192_WORKMODE_DCDC3_MASK;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ workmode <<= ffs(mask) - 1;
+ break;
+
case AXP202_ID:
case AXP209_ID:
if ((id != AXP20X_DCDC2) && (id != AXP20X_DCDC3))
@@ -1568,6 +1646,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev)
bool drivevbus = false;
switch (axp20x->variant) {
+ case AXP192_ID:
+ regulators = axp192_regulators;
+ nregulators = AXP192_REG_ID_MAX;
+ break;
case AXP202_ID:
case AXP209_ID:
regulators = axp20x_regulators;
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v7 3/9] regulator: axp20x: Add support for AXP192
2026-12-06 3:08 ` [PATCH v7 3/9] regulator: axp20x: Add support for AXP192 Molnár Máté via B4 Relay
@ 2026-12-06 3:22 ` sashiko-bot
0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-06 3:22 UTC (permalink / raw)
To: Molnár Máté
Cc: devicetree, linux-input, mfd, robh, conor+dt, dmitry.torokhov,
lee
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] regulator: axp20x: AXP192 LDO_IO0 range overflows 4-bit
vsel_mask
- [Medium] regulator: axp20x: AXP192 ldoin-supply and dcdc-freq conflict
with DT binding
--
commit 0cc2f3cfe23f4355e786325437951c33f7ce7afb
Author: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
regulator: axp20x: Add support for AXP192
This commit adds regulator support for the AXP192 PMIC to the axp20x
regulator driver, including regulator descriptors, DCDC2 ramp delay,
DCDC frequency, and DCDC workmode configuration.
> diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c
> index 53b1e0499c00a..efd4a3bc35d39 100644
> --- a/drivers/regulator/axp20x-regulator.c
> +++ b/drivers/regulator/axp20x-regulator.c
[ ... ]
> +#define AXP192_LDO_IO0_V_OUT_MASK GENMASK(7, 4)
[ ... ]
> @@ -596,6 +627,29 @@ static const struct regulator_ops axp20x_ops_sw = {
> .is_enabled = regulator_is_enabled_regmap,
> };
>
> +static const struct regulator_desc axp192_regulators[] = {
> + AXP_DESC(AXP192, DCDC1, "dcdc1", "vin1", 700, 3500, 25,
> + AXP192_DCDC1_V_OUT, AXP192_DCDC1_V_OUT_MASK,
> + AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_DCDC1_MASK),
> + AXP_DESC(AXP192, DCDC2, "dcdc2", "vin2", 700, 2275, 25,
> + AXP192_DCDC2_V_OUT, AXP192_DCDC2_V_OUT_MASK,
> + AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_DCDC2_MASK),
> + AXP_DESC(AXP192, DCDC3, "dcdc3", "vin3", 700, 3500, 25,
> + AXP192_DCDC3_V_OUT, AXP192_DCDC3_V_OUT_MASK,
> + AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_DCDC3_MASK),
> + AXP_DESC_FIXED(AXP192, LDO1, "ldo1", "acin", 1250),
> + AXP_DESC(AXP192, LDO2, "ldo2", "ldoin", 1800, 3300, 100,
> + AXP192_LDO2_3_V_OUT, AXP192_LDO2_V_OUT_MASK,
> + AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_LDO2_MASK),
> + AXP_DESC(AXP192, LDO3, "ldo3", "ldoin", 1800, 3300, 100,
> + AXP192_LDO2_3_V_OUT, AXP192_LDO3_V_OUT_MASK,
> + AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_LDO3_MASK),
> + AXP_DESC_IO(AXP192, LDO_IO0, "ldo_io0", "ips", 700, 3300, 100,
> + AXP192_LDO_IO0_V_OUT, AXP192_LDO_IO0_V_OUT_MASK,
> + AXP192_GPIO0_CTRL, AXP192_GPIO0_FUNC_MASK,
> + AXP192_IO_ENABLED, AXP192_IO_DISABLED),
> +};
[Severity: High]
Does the 700 to 3300 mV range for AXP192_LDO_IO0 overflow the 4-bit
AXP192_LDO_IO0_V_OUT_MASK?
AXP_DESC_IO() gives 27 voltages (selectors 0..26) in 100 mV steps, while
GENMASK(7, 4) holds only 0..15. regulator_set_voltage_sel_regmap()
shifts selectors 16..26 past bit 7, so regmap_update_bits() truncates
them and wraps 2300..3300 mV back to selectors 0..10.
Register 0x91 bits 7:4 encode 1800..3300 mV (like AXP20X_LDO5), so
selectors 0..15 also output 1100 mV more than requested, risking
overvoltage on attached peripherals. Should the minimum voltage be
1800 mV instead?
[ ... ]
> @@ -1314,6 +1368,12 @@ static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq)
> u32 min, max, def, step;
>
> switch (axp20x->variant) {
> + case AXP192_ID:
> + min = 900;
> + max = 2025;
> + def = 1500;
> + step = 75;
> + break;
[Severity: Medium]
Do the AXP192 DCDC frequency range and ldoin-supply conflict with
Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml?
The binding puts x-powers,axp192 in the else branch of its allOf rule
for x-powers,dcdc-freq (1800..4050 kHz, default 3000 kHz), which rejects
values below 1800 kHz including the 1500 kHz default and allows values
above 2025 kHz that axp20x_set_dcdc_freq() clamps with a warning.
In axp192_regulators[], LDO2 and LDO3 also expect an ldoin-supply
property that is absent from the binding while additionalProperties is
false, causing dtbs_check failures for AXP192 boards.
The binding also omits x-powers,axp192 from the x-powers,drive-vbus-en
disallow list and the regulator-ramp-delay description. Should the
binding be updated alongside this driver change?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-axp192-v7-0-0200fc77da53@gmail.com?part=3
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v7 4/9] power: axp20x_battery: Add constant charge current table
2026-12-06 3:08 [PATCH v7 0/9] Add the remaining AXP192 PMIC support Molnár Máté via B4 Relay
` (2 preceding siblings ...)
2026-12-06 3:08 ` [PATCH v7 3/9] regulator: axp20x: Add support for AXP192 Molnár Máté via B4 Relay
@ 2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:24 ` sashiko-bot
2026-12-06 3:08 ` [PATCH v7 5/9] power: axp20x_battery: Support battery status without fuel gauge Molnár Máté via B4 Relay
` (4 subsequent siblings)
8 siblings, 1 reply; 16+ messages in thread
From: Molnár Máté via B4 Relay @ 2026-12-06 3:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chen-Yu Tsai,
Sebastian Reichel, Liam Girdwood, Mark Brown, Dmitry Torokhov,
Lee Jones
Cc: linux-iio, devicetree, linux-kernel, linux-pm, linux-input, mfd,
Aidan MacDonald, Alex Bee, Molnár Máté
From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
Add a table-based lookup method for constant charge current,
which is necessary when the setting cannot be represented as
a linear range.
This also replaces the hard-coded 300 mA default ccc setting
if the DT-specified value is unsupported; the minimum value
for the device is now set exactly instead of relying on the
value being rounded down to a supported value.
Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
[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é <matemolnar88@gmail.com>
---
drivers/power/supply/axp20x_battery.c | 59 ++++++++++++++++++++++++++++-------
1 file changed, 47 insertions(+), 12 deletions(-)
diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
index 4af1a209c..f31b735ed 100644
--- a/drivers/power/supply/axp20x_battery.c
+++ b/drivers/power/supply/axp20x_battery.c
@@ -98,6 +98,14 @@ struct axp_data {
int ccc_offset;
unsigned int ccc_reg;
unsigned int ccc_mask;
+ /*
+ * Lookup table for constant charge current, if provided this is used
+ * instead of ccc_scale/ccc_offset.
+ *
+ * The table is indexed by the field AXP20X_CHRG_CTRL1_TGT_CURR so it
+ * must have AXP20X_CHRG_CTRL1_TGT_CURR+1 elements.
+ */
+ const int *ccc_table;
bool has_fg_valid;
const struct power_supply_desc *bat_ps_desc;
int (*get_max_voltage)(struct axp20x_batt_ps *batt, int *val);
@@ -253,7 +261,10 @@ static int axp20x_get_constant_charge_current(struct axp20x_batt_ps *axp,
*val &= AXP20X_CHRG_CTRL1_TGT_CURR;
- *val = *val * axp->data->ccc_scale + axp->data->ccc_offset;
+ if (axp->data->ccc_table)
+ *val = axp->data->ccc_table[*val];
+ else
+ *val = *val * axp->data->ccc_scale + axp->data->ccc_offset;
return 0;
}
@@ -675,16 +686,35 @@ static int axp717_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt,
AXP717_CHRG_CV_VOLT_MASK, val);
}
+static int axp20x_get_constant_charge_current_sel(struct axp20x_batt_ps *axp_batt,
+ int charge_current)
+{
+ int i;
+
+ if (axp_batt->data->ccc_table) {
+ for (i = AXP20X_CHRG_CTRL1_TGT_CURR; i >= 0; i--) {
+ if (axp_batt->data->ccc_table[i] <= charge_current)
+ return i;
+ }
+
+ return -EINVAL;
+ }
+
+ i = (charge_current - axp_batt->data->ccc_offset) / axp_batt->data->ccc_scale;
+ if (i > AXP20X_CHRG_CTRL1_TGT_CURR || i < 0)
+ return -EINVAL;
+
+ return i;
+}
+
static int axp20x_set_constant_charge_current(struct axp20x_batt_ps *axp_batt,
int charge_current)
{
if (charge_current > axp_batt->max_ccc)
return -EINVAL;
- charge_current = (charge_current - axp_batt->data->ccc_offset) /
- axp_batt->data->ccc_scale;
-
- if (charge_current > AXP20X_CHRG_CTRL1_TGT_CURR || charge_current < 0)
+ charge_current = axp20x_get_constant_charge_current_sel(axp_batt, charge_current);
+ if (charge_current < 0)
return -EINVAL;
return regmap_update_bits(axp_batt->regmap, AXP20X_CHRG_CTRL1,
@@ -714,14 +744,14 @@ static int axp20x_set_max_constant_charge_current(struct axp20x_batt_ps *axp,
{
bool lower_max = false;
- charge_current = (charge_current - axp->data->ccc_offset) /
- axp->data->ccc_scale;
-
- if (charge_current > AXP20X_CHRG_CTRL1_TGT_CURR || charge_current < 0)
+ charge_current = axp20x_get_constant_charge_current_sel(axp, charge_current);
+ if (charge_current < 0)
return -EINVAL;
- charge_current = charge_current * axp->data->ccc_scale +
- axp->data->ccc_offset;
+ if (axp->data->ccc_table)
+ charge_current = axp->data->ccc_table[charge_current];
+ else
+ charge_current = charge_current * axp->data->ccc_scale + axp->data->ccc_offset;
if (charge_current > axp->max_ccc)
dev_warn(axp->dev,
@@ -972,7 +1002,12 @@ static void axp209_set_battery_info(struct platform_device *pdev,
if (ccc <= 0 || axp20x_set_constant_charge_current(axp_batt, ccc)) {
dev_err(&pdev->dev,
"couldn't set ccc from DT: fallback to min value\n");
- ccc = 300000;
+
+ if (axp_batt->data->ccc_table)
+ ccc = axp_batt->data->ccc_table[0];
+ else
+ ccc = axp_batt->data->ccc_offset;
+
axp_batt->max_ccc = ccc;
axp20x_set_constant_charge_current(axp_batt, ccc);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v7 4/9] power: axp20x_battery: Add constant charge current table
2026-12-06 3:08 ` [PATCH v7 4/9] power: axp20x_battery: Add constant charge current table Molnár Máté via B4 Relay
@ 2026-12-06 3:24 ` sashiko-bot
0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-06 3:24 UTC (permalink / raw)
To: Molnár Máté
Cc: devicetree, linux-input, mfd, robh, conor+dt, dmitry.torokhov,
lee
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] power: supply: axp20x_battery: missing upper bound check for
ccc_table
--
commit f993b38bb97cab5bf0e1a39f154f674939512710
Author: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
power: axp20x_battery: Add constant charge current table
This commit adds a lookup table option for constant charge current on
variants whose values do not follow a linear range, and updates the DT
fallback to use the device's minimum configured current.
> diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
> index 4af1a209c9cf3..f31b735ed6548 100644
> --- a/drivers/power/supply/axp20x_battery.c
> +++ b/drivers/power/supply/axp20x_battery.c
[ ... ]
> @@ -675,16 +686,35 @@ static int axp717_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt,
> AXP717_CHRG_CV_VOLT_MASK, val);
> }
>
> +static int axp20x_get_constant_charge_current_sel(struct axp20x_batt_ps *axp_batt,
> + int charge_current)
> +{
> + int i;
> +
> + if (axp_batt->data->ccc_table) {
> + for (i = AXP20X_CHRG_CTRL1_TGT_CURR; i >= 0; i--) {
> + if (axp_batt->data->ccc_table[i] <= charge_current)
> + return i;
> + }
> +
> + return -EINVAL;
> + }
> +
> + i = (charge_current - axp_batt->data->ccc_offset) / axp_batt->data->ccc_scale;
> + if (i > AXP20X_CHRG_CTRL1_TGT_CURR || i < 0)
> + return -EINVAL;
> +
> + return i;
> +}
[Severity: Medium]
Should the ccc_table path reject charge_current values above
ccc_table[AXP20X_CHRG_CTRL1_TGT_CURR] with -EINVAL?
Unlike the linear branch below, the reverse scan matches any value above
the maximum table entry on the first iteration and returns selector
AXP20X_CHRG_CTRL1_TGT_CURR. An out-of-range high write to
constant_charge_current_max via axp20x_set_max_constant_charge_current()
then silently raises max_ccc to the hardware maximum instead of returning
-EINVAL, and an unsupported high DT value in axp209_set_battery_info()
programs the hardware maximum instead of falling back to ccc_table[0].
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-axp192-v7-0-0200fc77da53@gmail.com?part=4
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v7 5/9] power: axp20x_battery: Support battery status without fuel gauge
2026-12-06 3:08 [PATCH v7 0/9] Add the remaining AXP192 PMIC support Molnár Máté via B4 Relay
` (3 preceding siblings ...)
2026-12-06 3:08 ` [PATCH v7 4/9] power: axp20x_battery: Add constant charge current table Molnár Máté via B4 Relay
@ 2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:23 ` sashiko-bot
2026-12-06 3:08 ` [PATCH v7 6/9] power: axp20x_battery: Add support for AXP192 Molnár Máté via B4 Relay
` (3 subsequent siblings)
8 siblings, 1 reply; 16+ messages in thread
From: Molnár Máté via B4 Relay @ 2026-12-06 3:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chen-Yu Tsai,
Sebastian Reichel, Liam Girdwood, Mark Brown, Dmitry Torokhov,
Lee Jones
Cc: linux-iio, devicetree, linux-kernel, linux-pm, linux-input, mfd,
Aidan MacDonald, Alex Bee, Molnár Máté
From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
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 <aidanmacdonald.0x0@gmail.com>
[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é <matemolnar88@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v7 5/9] power: axp20x_battery: Support battery status without fuel gauge
2026-12-06 3:08 ` [PATCH v7 5/9] power: axp20x_battery: Support battery status without fuel gauge Molnár Máté via B4 Relay
@ 2026-12-06 3:23 ` sashiko-bot
0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-06 3:23 UTC (permalink / raw)
To: Molnár Máté
Cc: devicetree, linux-input, mfd, robh, conor+dt, dmitry.torokhov,
lee
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] power: axp20x_battery_get_prop() ignores charger enable and
battery presence
- [Low] power: supply: axp20x_battery: axp717_data omits has_fg flag
- [Low] power: axp20x_battery: omit has_fg flag on axp717_data
--
commit a493fb18308210a804a2cff64dc6cfb93847bd0d
Author: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
power: axp20x_battery: Support battery status without fuel gauge
This commit adds a has_fg flag to struct axp_data and uses battery voltage
relative to the maximum charge voltage to determine POWER_SUPPLY_STATUS_FULL
when a chip has no fuel gauge.
> diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
> index f31b735ed6548..f7485ac6a9aca 100644
> --- a/drivers/power/supply/axp20x_battery.c
> +++ b/drivers/power/supply/axp20x_battery.c
[ ... ]
> @@ -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;
[Severity: Medium]
Can this report POWER_SUPPLY_STATUS_FULL when charging is disabled or no
battery is attached?
axp20x_battery_set_prop() allows userspace to disable charging by clearing
AXP20X_CHRG_CTRL1_ENABLE, so the recharge threshold no longer holds and a
partially charged battery above V_tgt - 0.1 V is reported as full.
This path also does not check AXP20X_PWR_OP_BATT_PRESENT before inferring
full status from the battery 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,
[Severity: Low]
Should axp717_data also set .has_fg = true?
AXP717 has a hardware fuel gauge (axp717_battery_get_prop() reads
AXP717_BATT_PERCENT_DATA).
Later in this series, commit "power: axp20x_battery: Estimate AXP192
capacity from the OCV table" gates power_supply_put_battery_info() on
has_fg in axp20x_power_probe(), so leaving has_fg false causes AXP717 to
retain unused battery_info allocations.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-axp192-v7-0-0200fc77da53@gmail.com?part=5
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v7 6/9] power: axp20x_battery: Add support for AXP192
2026-12-06 3:08 [PATCH v7 0/9] Add the remaining AXP192 PMIC support Molnár Máté via B4 Relay
` (4 preceding siblings ...)
2026-12-06 3:08 ` [PATCH v7 5/9] power: axp20x_battery: Support battery status without fuel gauge Molnár Máté via B4 Relay
@ 2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:08 ` [PATCH v7 7/9] power: axp20x_battery: Estimate AXP192 capacity from the OCV table Molnár Máté via B4 Relay
` (2 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Molnár Máté via B4 Relay @ 2026-12-06 3:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chen-Yu Tsai,
Sebastian Reichel, Liam Girdwood, Mark Brown, Dmitry Torokhov,
Lee Jones
Cc: linux-iio, devicetree, linux-kernel, linux-pm, linux-input, mfd,
Aidan MacDonald, Alex Bee, Molnár Máté
From: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
The AXP192 has a battery charger similar to other X-Powers PMICs,
but unlike the other supported devices, it does not have a fuel
gauge and can't report battery capacity directly.
Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
[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é <matemolnar88@gmail.com>
---
drivers/power/supply/axp20x_battery.c | 44 +++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
index f7485ac6a..b55089a81 100644
--- a/drivers/power/supply/axp20x_battery.c
+++ b/drivers/power/supply/axp20x_battery.c
@@ -944,6 +944,29 @@ static int axp717_battery_prop_writeable(struct power_supply *psy,
psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX;
}
+static enum power_supply_property axp192_battery_props[] = {
+ POWER_SUPPLY_PROP_PRESENT,
+ POWER_SUPPLY_PROP_ONLINE,
+ POWER_SUPPLY_PROP_STATUS,
+ POWER_SUPPLY_PROP_VOLTAGE_NOW,
+ POWER_SUPPLY_PROP_CURRENT_NOW,
+ POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
+ POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
+ POWER_SUPPLY_PROP_HEALTH,
+ POWER_SUPPLY_PROP_VOLTAGE_MAX,
+ POWER_SUPPLY_PROP_VOLTAGE_MIN,
+};
+
+static const struct power_supply_desc axp192_batt_ps_desc = {
+ .name = "axp192-battery",
+ .type = POWER_SUPPLY_TYPE_BATTERY,
+ .properties = axp192_battery_props,
+ .num_properties = ARRAY_SIZE(axp192_battery_props),
+ .property_is_writeable = axp20x_battery_prop_writeable,
+ .get_property = axp20x_battery_get_prop,
+ .set_property = axp20x_battery_set_prop,
+};
+
static const struct power_supply_desc axp209_batt_ps_desc = {
.name = "axp20x-battery",
.type = POWER_SUPPLY_TYPE_BATTERY,
@@ -1086,6 +1109,24 @@ static void axp717_set_battery_info(struct platform_device *pdev,
}
}
+static const int axp192_ccc_table[AXP20X_CHRG_CTRL1_TGT_CURR + 1] = {
+ 100000, 190000, 280000, 360000,
+ 450000, 550000, 630000, 700000,
+ 780000, 880000, 960000, 1000000,
+ 1080000, 1160000, 1240000, 1320000,
+};
+
+static const struct axp_data axp192_data = {
+ .ccc_reg = AXP20X_CHRG_CTRL1,
+ .ccc_mask = AXP20X_CHRG_CTRL1_TGT_CURR,
+ .ccc_table = axp192_ccc_table,
+ .bat_ps_desc = &axp192_batt_ps_desc,
+ .get_max_voltage = axp20x_battery_get_max_voltage,
+ .set_max_voltage = axp20x_battery_set_max_voltage,
+ .cfg_iio_chan = axp209_bat_cfg_iio_channels,
+ .set_bat_info = axp209_set_battery_info,
+};
+
static const struct axp_data axp209_data = {
.ccc_scale = 100000,
.ccc_offset = 300000,
@@ -1141,6 +1182,9 @@ static const struct axp_data axp813_data = {
static const struct of_device_id axp20x_battery_ps_id[] = {
{
+ .compatible = "x-powers,axp192-battery-power-supply",
+ .data = (void *)&axp192_data,
+ }, {
.compatible = "x-powers,axp209-battery-power-supply",
.data = (void *)&axp209_data,
}, {
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH v7 7/9] power: axp20x_battery: Estimate AXP192 capacity from the OCV table
2026-12-06 3:08 [PATCH v7 0/9] Add the remaining AXP192 PMIC support Molnár Máté via B4 Relay
` (5 preceding siblings ...)
2026-12-06 3:08 ` [PATCH v7 6/9] power: axp20x_battery: Add support for AXP192 Molnár Máté via B4 Relay
@ 2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:24 ` sashiko-bot
2026-12-06 3:09 ` [PATCH v7 8/9] Input: axp20x-pek: Add AXP192 support Molnár Máté via B4 Relay
2026-12-06 3:09 ` [PATCH v7 9/9] mfd: axp20x: Add the AXP192 power key cell Molnár Máté via B4 Relay
8 siblings, 1 reply; 16+ messages in thread
From: Molnár Máté via B4 Relay @ 2026-12-06 3:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chen-Yu Tsai,
Sebastian Reichel, Liam Girdwood, Mark Brown, Dmitry Torokhov,
Lee Jones
Cc: linux-iio, devicetree, linux-kernel, linux-pm, linux-input, mfd,
Aidan MacDonald, Alex Bee, Molnár Máté
From: Molnár Máté <matemolnar88@gmail.com>
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é <matemolnar88@gmail.com>
---
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 <linux/err.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
+#include <linux/math64.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
@@ -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
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v7 7/9] power: axp20x_battery: Estimate AXP192 capacity from the OCV table
2026-12-06 3:08 ` [PATCH v7 7/9] power: axp20x_battery: Estimate AXP192 capacity from the OCV table Molnár Máté via B4 Relay
@ 2026-12-06 3:24 ` sashiko-bot
0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-06 3:24 UTC (permalink / raw)
To: Molnár Máté
Cc: devicetree, linux-input, mfd, robh, conor+dt, dmitry.torokhov,
lee
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] power: axp20x_battery: probe race on bat_info and batt in ocv
capacity path
- [Low] power: axp20x_battery: missing has_fg in axp717_data retains
unused bat_info
- [Low] power: axp20x_battery: unconditional CURRENT_NOW read in ocv
capacity path
- [Low] power: axp20x_battery: stray board codename in
axp20x_battery_ocv_capacity()
- [Low] power: axp20x_battery: axp192_battery_props duplicates
axp20x_battery_props
--
commit a78f3397c5935dce53f82b239be5baaf83190c73
Author: Molnár Máté <matemolnar88@gmail.com>
power: axp20x_battery: Estimate AXP192 capacity from the OCV table
This commit estimates battery capacity from the battery's OCV table on
PMICs without a fuel gauge, exposes POWER_SUPPLY_PROP_CAPACITY on AXP192,
and keeps the parsed battery info around after probe for those PMICs.
> diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
> index b55089a81e17d..3c3cf349f9dda 100644
> --- a/drivers/power/supply/axp20x_battery.c
> +++ b/drivers/power/supply/axp20x_battery.c
[ ... ]
> @@ -285,6 +288,50 @@ static int axp717_get_constant_charge_current(struct axp20x_batt_ps *axp,
[ ... ]
> + 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);
[Severity: Low]
Should the POWER_SUPPLY_PROP_CURRENT_NOW read be moved inside the
factory_internal_resistance_uohm check?
When factory-internal-resistance-micro-ohms is omitted from devicetree,
power_supply_get_battery_info() leaves factory_internal_resistance_uohm at
-EINVAL and i.intval is discarded. Reading CURRENT_NOW unconditionally
triggers unnecessary volatile I2C reads on every capacity query and fails
capacity estimation if the unused current channel returns an error.
> +
> + /* ponytail: no temperature sensor wired up, assume 20 C */
> + ret = power_supply_batinfo_ocv2cap(info, v.intval, 20);
[Severity: Low]
This isn't a bug, but "ponytail" looks like a leftover out-of-tree board
codename in a generic PMIC driver comment.
[ ... ]
> @@ -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,
> };
[Severity: Low]
With POWER_SUPPLY_PROP_CAPACITY added, axp192_battery_props[] is now
identical to axp20x_battery_props[]. Can axp192_batt_ps_desc reuse
axp20x_battery_props directly and drop the duplicate array?
> @@ -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);
[Severity: Low]
Does gating power_supply_put_battery_info() on data->has_fg retain an
unused battery_info allocation on AXP717?
axp717_data omits .has_fg = true even though AXP717 has a hardware fuel
gauge and axp717_battery_get_prop() reads AXP717_BATT_PERCENT_DATA
directly without ever using axp20x_batt->bat_info.
> + else
> + axp20x_batt->bat_info = info;
> }
[Severity: Medium]
Can concurrent sysfs readers race with axp20x_power_probe() on
axp20x_batt->bat_info and axp20x_batt->batt?
devm_power_supply_register() calls device_add() and sets
psy->initialized = true before returning, so userspace (such as udev or
UPower) can read capacity while probe is still storing axp20x_batt->batt
and axp20x_batt->bat_info:
CPU0 CPU1
axp20x_power_probe()
devm_power_supply_register()
device_add()
psy->initialized = true
axp20x_batt->batt = psy
...
axp20x_batt->bat_info = info
sysfs read capacity
axp20x_battery_ocv_capacity()
info = axp20x_batt->bat_info
axp20x_battery_get_prop(
axp20x_batt->batt, ...)
<-- NULL deref if reordered
Both pointers are written and read with plain accesses and no locking or
release/acquire ordering. Early readers before bat_info is stored get
spurious -ENODATA, and on weakly-ordered architectures CPU1 can observe a
non-NULL bat_info alongside uninitialized *info fields or a stale NULL
axp20x_batt->batt, leading to a NULL pointer dereference in
power_supply_get_drvdata().
In addition, __power_supply_register() already parses and stores
psy->battery_info before device_add() for POWER_SUPPLY_TYPE_BATTERY
devices, so keeping bat_info duplicates that allocation. Passing psy from
axp20x_battery_get_prop() into axp20x_battery_ocv_capacity() and reading
psy->battery_info avoids the probe race, the bat_info field, and the
duplicate allocation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-axp192-v7-0-0200fc77da53@gmail.com?part=7
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v7 8/9] Input: axp20x-pek: Add AXP192 support
2026-12-06 3:08 [PATCH v7 0/9] Add the remaining AXP192 PMIC support Molnár Máté via B4 Relay
` (6 preceding siblings ...)
2026-12-06 3:08 ` [PATCH v7 7/9] power: axp20x_battery: Estimate AXP192 capacity from the OCV table Molnár Máté via B4 Relay
@ 2026-12-06 3:09 ` Molnár Máté via B4 Relay
2026-12-06 3:21 ` sashiko-bot
2026-12-06 3:09 ` [PATCH v7 9/9] mfd: axp20x: Add the AXP192 power key cell Molnár Máté via B4 Relay
8 siblings, 1 reply; 16+ messages in thread
From: Molnár Máté via B4 Relay @ 2026-12-06 3:09 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chen-Yu Tsai,
Sebastian Reichel, Liam Girdwood, Mark Brown, Dmitry Torokhov,
Lee Jones
Cc: linux-iio, devicetree, linux-kernel, linux-pm, linux-input, mfd,
Aidan MacDonald, Alex Bee, Molnár Máté
From: Molnár Máté <matemolnar88@gmail.com>
The AXP192 has no rising/falling edge interrupts for the power key.
It only raises short-press and long-press events, after the key has
been released. Add an axp192-pek variant that reports each of those as
a complete press, so userspace sees a normal KEY_POWER press/release.
Set the variant info before the input device is registered, as the
interrupt handler now uses it.
Signed-off-by: Molnár Máté <matemolnar88@gmail.com>
---
drivers/input/misc/axp20x-pek.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
index a02cdabcf..739da57ca 100644
--- a/drivers/input/misc/axp20x-pek.c
+++ b/drivers/input/misc/axp20x-pek.c
@@ -35,6 +35,11 @@ struct axp20x_info {
unsigned int startup_mask;
const struct axp20x_time *shutdown_time;
unsigned int shutdown_mask;
+ /*
+ * The PMIC only reports short and long presses after the button is
+ * released, not the edges, so each event is a complete press.
+ */
+ bool press_events_only;
};
struct axp20x_pek {
@@ -78,6 +83,14 @@ static const struct axp20x_info axp20x_info = {
.shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK,
};
+static const struct axp20x_info axp192_info = {
+ .startup_time = startup_time,
+ .startup_mask = AXP20X_PEK_STARTUP_MASK,
+ .shutdown_time = shutdown_time,
+ .shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK,
+ .press_events_only = true,
+};
+
static const struct axp20x_info axp221_info = {
.startup_time = axp221_startup_time,
.startup_mask = AXP20X_PEK_STARTUP_MASK,
@@ -200,6 +213,15 @@ static irqreturn_t axp20x_pek_irq(int irq, void *pwr)
struct input_dev *idev = pwr;
struct axp20x_pek *axp20x_pek = input_get_drvdata(idev);
+ if (axp20x_pek->info->press_events_only) {
+ input_report_key(idev, KEY_POWER, true);
+ input_sync(idev);
+ input_report_key(idev, KEY_POWER, false);
+ input_sync(idev);
+
+ return IRQ_HANDLED;
+ }
+
/*
* The power-button is connected to ground so a falling edge (dbf)
* means it is pressed.
@@ -311,6 +333,7 @@ static int axp20x_pek_probe(struct platform_device *pdev)
return -ENOMEM;
axp20x_pek->axp20x = dev_get_drvdata(pdev->dev.parent);
+ axp20x_pek->info = (struct axp20x_info *)match->driver_data;
if (axp20x_pek_should_register_input(axp20x_pek)) {
error = axp20x_pek_probe_input_device(axp20x_pek, pdev);
@@ -318,8 +341,6 @@ static int axp20x_pek_probe(struct platform_device *pdev)
return error;
}
- axp20x_pek->info = (struct axp20x_info *)match->driver_data;
-
platform_set_drvdata(pdev, axp20x_pek);
return 0;
@@ -393,6 +414,10 @@ static const struct platform_device_id axp_pek_id_match[] = {
.name = "axp20x-pek",
.driver_data = (kernel_ulong_t)&axp20x_info,
},
+ {
+ .name = "axp192-pek",
+ .driver_data = (kernel_ulong_t)&axp192_info,
+ },
{
.name = "axp221-pek",
.driver_data = (kernel_ulong_t)&axp221_info,
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v7 8/9] Input: axp20x-pek: Add AXP192 support
2026-12-06 3:09 ` [PATCH v7 8/9] Input: axp20x-pek: Add AXP192 support Molnár Máté via B4 Relay
@ 2026-12-06 3:21 ` sashiko-bot
0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-06 3:21 UTC (permalink / raw)
To: Molnár Máté
Cc: devicetree, linux-input, mfd, robh, conor+dt, dmitry.torokhov,
lee
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] Input: axp20x-pek: wrong startup_time table used for
axp192_info
--
commit cdefc58fa41ce85f7aa8b01d02fa130c1b3b21dd
Author: Molnár Máté <matemolnar88@gmail.com>
Input: axp20x-pek: Add AXP192 support
This commit adds an axp192-pek variant that reports each short-press or
long-press interrupt as a complete KEY_POWER press/release sequence, and
initializes axp20x_pek->info before registering the input device.
> diff --git a/drivers/input/misc/axp20x-pek.c b/drivers/input/misc/axp20x-pek.c
> index a02cdabcf22b1..739da57ca08cf 100644
> --- a/drivers/input/misc/axp20x-pek.c
> +++ b/drivers/input/misc/axp20x-pek.c
[ ... ]
> @@ -78,6 +83,14 @@ static const struct axp20x_info axp20x_info = {
> .shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK,
> };
>
> +static const struct axp20x_info axp192_info = {
> + .startup_time = startup_time,
> + .startup_mask = AXP20X_PEK_STARTUP_MASK,
> + .shutdown_time = shutdown_time,
> + .shutdown_mask = AXP20X_PEK_SHUTDOWN_MASK,
> + .press_events_only = true,
> +};
[Severity: Medium]
Does the shared startup_time table match AXP192's hardware encoding?
In startup_time[], idx 1 (0b01) maps to 3000 ms, whereas on AXP192
register 0x36 bits [7:6] = 0b01 is 512 ms (the reset default) and there
is no 3000 ms setting. Reading startup reports 3000 ms instead of 512
ms, and writing 512 programs 128 ms while writing 3000 programs 512 ms.
Defining a dedicated axp192_startup_time table mapping idx 0..3 to 128,
512, 1000, and 2000 ms (like axp221_startup_time) would match the AXP192
encoding.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-axp192-v7-0-0200fc77da53@gmail.com?part=8
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v7 9/9] mfd: axp20x: Add the AXP192 power key cell
2026-12-06 3:08 [PATCH v7 0/9] Add the remaining AXP192 PMIC support Molnár Máté via B4 Relay
` (7 preceding siblings ...)
2026-12-06 3:09 ` [PATCH v7 8/9] Input: axp20x-pek: Add AXP192 support Molnár Máté via B4 Relay
@ 2026-12-06 3:09 ` Molnár Máté via B4 Relay
2026-12-06 3:18 ` sashiko-bot
8 siblings, 1 reply; 16+ messages in thread
From: Molnár Máté via B4 Relay @ 2026-12-06 3:09 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Chen-Yu Tsai,
Sebastian Reichel, Liam Girdwood, Mark Brown, Dmitry Torokhov,
Lee Jones
Cc: linux-iio, devicetree, linux-kernel, linux-pm, linux-input, mfd,
Aidan MacDonald, Alex Bee, Molnár Máté
From: Molnár Máté <matemolnar88@gmail.com>
Register the power key for the AXP192. It only has short and long press
interrupts, which are passed to the axp192-pek variant of the
axp20x-pek driver under the usual PEK_DBF/PEK_DBR names.
Signed-off-by: Molnár Máté <matemolnar88@gmail.com>
---
drivers/mfd/axp20x.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
index 4d770e718..f9bf06ddb 100644
--- a/drivers/mfd/axp20x.c
+++ b/drivers/mfd/axp20x.c
@@ -363,6 +363,12 @@ static const struct resource axp288_fuel_gauge_resources[] = {
DEFINE_RES_IRQ(AXP288_IRQ_WL1),
};
+/* The AXP192 has no PEK edge interrupts, only short and long press events */
+static const struct resource axp192_pek_resources[] = {
+ DEFINE_RES_IRQ_NAMED(AXP192_IRQ_PEK_LONG, "PEK_DBR"),
+ DEFINE_RES_IRQ_NAMED(AXP192_IRQ_PEK_SHORT, "PEK_DBF"),
+};
+
static const struct resource axp313a_pek_resources[] = {
DEFINE_RES_IRQ_NAMED(AXP313A_IRQ_PEK_RIS_EDGE, "PEK_DBR"),
DEFINE_RES_IRQ_NAMED(AXP313A_IRQ_PEK_FAL_EDGE, "PEK_DBF"),
@@ -956,6 +962,10 @@ static const struct mfd_cell axp192_cells[] = {
.of_compatible = "x-powers,axp192-usb-power-supply",
.num_resources = ARRAY_SIZE(axp192_usb_power_supply_resources),
.resources = axp192_usb_power_supply_resources,
+ }, {
+ .name = "axp192-pek",
+ .num_resources = ARRAY_SIZE(axp192_pek_resources),
+ .resources = axp192_pek_resources,
},
{ .name = "axp20x-regulator" },
};
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH v7 9/9] mfd: axp20x: Add the AXP192 power key cell
2026-12-06 3:09 ` [PATCH v7 9/9] mfd: axp20x: Add the AXP192 power key cell Molnár Máté via B4 Relay
@ 2026-12-06 3:18 ` sashiko-bot
0 siblings, 0 replies; 16+ messages in thread
From: sashiko-bot @ 2026-12-06 3:18 UTC (permalink / raw)
To: Molnár Máté
Cc: devicetree, linux-input, mfd, robh, conor+dt, dmitry.torokhov,
lee
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mfd: axp20x: axp192-pek binds wrong startup_time table (3000
ms vs 512 ms)
--
commit b429e0305e2c580e4921542de1958ebb7c2e1469
Author: Molnár Máté <matemolnar88@gmail.com>
mfd: axp20x: Add the AXP192 power key cell
This commit registers the axp192-pek MFD cell and its short and long press
IRQ resources for the AXP192 PMIC.
> diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
> index 4d770e7187160..f9bf06ddbe09f 100644
> --- a/drivers/mfd/axp20x.c
> +++ b/drivers/mfd/axp20x.c
[ ... ]
> @@ -956,6 +962,10 @@ static const struct mfd_cell axp192_cells[] = {
> .of_compatible = "x-powers,axp192-usb-power-supply",
> .num_resources = ARRAY_SIZE(axp192_usb_power_supply_resources),
> .resources = axp192_usb_power_supply_resources,
> + }, {
> + .name = "axp192-pek",
> + .num_resources = ARRAY_SIZE(axp192_pek_resources),
> + .resources = axp192_pek_resources,
> },
> { .name = "axp20x-regulator" },
> };
[Severity: Medium]
Does binding axp192-pek expose the wrong startup_time table on AXP192?
In commit "Input: axp20x-pek: Add AXP192 support", axp192_info in
drivers/input/misc/axp20x-pek.c reuses the AXP20x startup_time table, where
idx 1 is 3000 ms. On AXP192, register 0x36 bits [7:6] encode 0b01 as
512 ms instead (128, 512, 1000, and 2000 ms).
As a result, reading the startup sysfs attribute reports 3000 ms instead of
512 ms for the hardware default, and writing 512 selects 128 ms while
writing 3000 programs 512 ms. Adding an AXP192-specific startup_time table
that maps idx 1 to 512 ms would fix this.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-axp192-v7-0-0200fc77da53@gmail.com?part=9
^ permalink raw reply [flat|nested] 16+ messages in thread