power: supply: axp20x_battery: set charging voltage via DT
Subsystems (2)
PATCH 1/1 power: supply: axp20x_battery: set charging voltage via DT
The driver should use maximum constant charge voltage property from battery description provided by power supply core by default instead of fixed 4.2V. This value can be later changed at runtime.
The battery description is normally set via device tree, as described in Documentation/devicetree/bindings/power/supply/battery.yaml
--- drivers/power/supply/axp20x_battery.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/power/supply/axp20x_battery.c +6 -0
@@ -617,6 +617,12 @@ static int axp20x_power_probe(struct platform_device *pdev)if (!power_supply_get_battery_info (axp20x_batt->batt, &info)) {int vmin = info.voltage_min_design_uv;int ccc = info.constant_charge_current_max_ua; +int vcv = info.constant_charge_voltage_max_uv; + +if (vcv >0 && axp20x_batt->data->set_max_voltage (axp20x_batt, + vcv)) +dev_err (&pdev->dev, +"couldn't set charge constant voltage from DT" );if (vmin >0 &&axp20x_set_voltage_min_design (axp20x_batt, vmin))
Signature · 1 line
2.25.1
Hi Evgeny,
Quoted 17 lines · Evgeny Boger
The driver should use maximum constant charge voltage property from battery description provided by power supply core by default instead of fixed 4.2V. This value can be later changed at runtime.
The battery description is normally set via device tree, as described in
Documentation/devicetree/bindings/power/supply/battery.yamlSigned-off-by Evgeny Boger <[email protected]>--- drivers/power/supply/axp20x_battery.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/power/supply/axp20x_battery.c +0
-0
drivers/power/supply/axp20x_battery.c static int axp20x_power_probe(struct platform_device *pdev) · line 626
Quoted 10 lines
drivers/power/supply/axp20x_battery.c +6
-0@@ -617,6 +617,12 @@ static int axp20x_power_probe(struct platform_device *pdev)if (!power_supply_get_battery_info (axp20x_batt->batt, &info)) {int vmin = info.voltage_min_design_uv;int ccc = info.constant_charge_current_max_ua; +int vcv = info.constant_charge_voltage_max_uv; + +if (vcv >0 && axp20x_batt->data->set_max_voltage (axp20x_batt, + vcv)) +dev_err (&pdev->dev, +"couldn't set charge constant voltage from DT" );
The issue here is that only specific values are possible. e.g. for
axp20x: 4.1 4.15 4.2V, axp22x 4.1 4.2V, there's nothing in-between.
I don't think the battery node should know what the PMIC is capable of outputting.
Would it make sense to find the closest value to the one appropriate for the battery that is supported by the PMIC (lesser or equal to the one specified by the battery obviously)?
Otherwise, I would imagine this function would fail most of the time because it's not the exact voltage supported by the PMIC?
Completely off-topic, but I also see that batteries now support specifying which technology they use so it should be safe to raise the maximum for some technologies above what we currently support in the driver. e.g. axp22x supports 4.22 and 4.24V too but they aren't selectable at the moment.
Cheers,
Quentin
Hi Quentin,
again, thank you for the feedback!
01.12.2021 20:57, Quentin Schulz пишет:
Quoted 33 lines
Hi Evgeny,
Quoted 17 lines · Evgeny Boger
The driver should use maximum constant charge voltage property from battery description provided by power supply core by default instead of fixed 4.2V. This value can be later changed at runtime.
The battery description is normally set via device tree, as described in
Documentation/devicetree/bindings/power/supply/battery.yamlSigned-off-by Evgeny Boger <[email protected]>--- drivers/power/supply/axp20x_battery.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/power/supply/axp20x_battery.c +0
-0drivers/power/supply/axp20x_battery.c static int axp20x_power_probe(struct platform_device *pdev) · line 626
Quoted 10 lines
drivers/power/supply/axp20x_battery.c +6
-0@@ -617,6 +617,12 @@ static int axp20x_power_probe(struct platform_device *pdev)if (!power_supply_get_battery_info (axp20x_batt->batt, &info)) {int vmin = info.voltage_min_design_uv;int ccc = info.constant_charge_current_max_ua; +int vcv = info.constant_charge_voltage_max_uv; + +if (vcv >0 && axp20x_batt->data->set_max_voltage (axp20x_batt, + vcv)) +dev_err (&pdev->dev, +"couldn't set charge constant voltage from DT" );The issue here is that only specific values are possible. e.g. for
axp20x: 4.1 4.15 4.2V, axp22x 4.1 4.2V, there's nothing in-between.
Quoted 2 lines
I don't think the battery node should know what the PMIC is capable of outputting.
Well, in a sense it should. I mean a hardware designer for sure would design a board in a way that a battery and PMIC are compatible. So it would be strange to declare an unsupported charging voltage in battery node.
Quoted 4 lines
Would it make sense to find the closest value to the one appropriate for the battery that is supported by the PMIC (lesser or equal to the one specified by the battery obviously)?
but yes, I think it makes sense. Probably the same should work for userspace too. By the way, I've just realized that the driver probably uses POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN incorrectly to set charging voltage. I think it should be POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE instead?
Quoted 9 lines
Otherwise, I would imagine this function would fail most of the time because it's not the exact voltage supported by the PMIC?
Completely off-topic, but I also see that batteries now support specifying which technology they use so it should be safe to raise the maximum for some technologies above what we currently support in the driver. e.g. axp22x supports 4.22 and 4.24V too but they aren't selectable at the moment.
well, they are all lithium-ion. Even the ones with 4.35V are lithium-ion, just a better quality ones. And then, on the other hand, at wirenboard we limit the charging voltage to 4.1V on perfectly 4.2V-capable battery to prolong the battery lifetime in exchange for some available capacity.
So I think not supporting voltages higher than 4.2V in PMIC is a bit strange. I think it's better not to allow setting the voltage higher than battery maximum via userspace, but it should be allowed to set whatever voltage the board designer want via the device tree.
Quoted 3 lines
Cheers,
Quentin
Signature · 5 lines
С уважением,
Евгений Богер / Evgeny Boger
CTO, Wiren Board Team
https://wirenboard.com/ru
+7 495 150 66 19 (# 33)Hi,
Quoted 2 lines · Quentin Schulz
The issue here is that only specific values are possible. e.g. for
axp20x: 4.1 4.15 4.2V, axp22x 4.1 4.2V, there's nothing in-between.
...
Quoted 6 lines
Would it make sense to find the closest value to the one appropriate for the battery that is supported by the PMIC (lesser or equal to the one specified by the battery obviously)?
Otherwise, I would imagine this function would fail most of the time because it's not the exact voltage supported by the PMIC?
You have to add the values to all device trees for every board an it may produce more devicetree entries when the same board have a different battery attached. OTOH, this allows more flexibility with devicetree overlays.
Quoted 5 lines
Completely off-topic, but I also see that batteries now support specifying which technology they use so it should be safe to raise the maximum for some technologies above what we currently support in the driver. e.g. axp22x supports 4.22 and 4.24V too but they aren't selectable at the moment.
At least axp209 additionaly allows 4.36V, although that may be used only in hand crafted setups. At the moment I'm switching on that from u-boot.
Greetings
Hermann