Bug 497200 - Support "charge_types" alongside "charge_start/end_threshold", no effect otherwise on certain laptops
Summary: Support "charge_types" alongside "charge_start/end_threshold", no effect othe...
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Power management & brightness (show other bugs)
Version: 6.2.4
Platform: Other Linux
: NOR wishlist
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-12-08 14:08 UTC by Faidon Liambotis
Modified: 2025-03-04 22:48 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.3.3
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Faidon Liambotis 2024-12-08 14:08:00 UTC
SUMMARY

I own a Dell Latitude laptop. While it has been possible to set charging thresholds with `smbios-battery-ctl` for a few years now, Linux 6.12 added support for the standard sysfs charge start/end thresholds in the `dell_laptop` driver. This made powerdevil automatically detect said thresholds and report them to the UI automatically. Neat!

```
# cat /sys/class/power_supply/BAT0/charge_control_{start,end}_threshold
70
85
```

However, the way the firmware works, exposed now by the driver, is that there is a [`charge_types` attribute](https://lwn.net/Articles/989502/):
```
# cat /sys/class/power_supply/BAT0/charge_types 
Trickle Fast Standard Adaptive [Custom]
```
The values are documented [in the patchset to be identical to `charge_type`](https://patchwork.kernel.org/project/linux-pm/patch/20241108232438.269156-3-hdegoede@redhat.com/) (which doesn't exist on my system), and the kernel's [sysfs documentation page](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power).

Two things here:

- First, **a bug**: unless `charge_types` is set to `Custom`, **the start/end thresholds sysfs entries have a value but take no effect**. powerdevil incorrectly reports these thresholds (and allows one to change them). So at minimum it should support reading, and perhaps writing, the value `Custom`.

- Second, a **feature request**: it'd be awesome for powerdevil to support setting these different values. I primarily use `Custom` with 70-85 during normal use, but when I leave for a long day (e.g. a trip), I set it to `Fast`. Also see #14.

SOFTWARE/OS VERSIONS
Operating System: Debian GNU/Linux 12
KDE Plasma Version: 6.2.4
Kernel Version: 6.12.3-amd64 (64-bit)
Powerdevil 6.2.3, but verified with the code in the master branch.
Comment 1 Jakob Petsovits 2024-12-08 23:54:46 UTC
Thanks for the notice. I'm not yet quite sure how best to tackle this, but I agree it's something that should be implemented somehow.

Note: the `charge_types` file does not necessarily exist for all laptops with charge threshold kernel support - also on kernel 6.12, my ThinkPad provides `charge_control_{start,end}_threshold` but lacks `charge_types` .
Comment 2 Faidon Liambotis 2024-12-09 00:09:05 UTC
(In reply to Jakob Petsovits from comment #1)
> Thanks for the notice. I'm not yet quite sure how best to tackle this, but I
> agree it's something that should be implemented somehow.

Thanks for the quick response and confirmation!

> Note: the `charge_types` file does not necessarily exist for all laptops
> with charge threshold kernel support - also on kernel 6.12, my ThinkPad
> provides `charge_control_{start,end}_threshold` but lacks `charge_types` .

Indeed. Git grepping through Linux master, it looks like `charge_types` is implemented only by the `dell_laptop` driver. `charge_type` (singular) is implemented by a bunch of power supply drivers (mostly chargers, as far as I can tell), including UCSI (USB-C). `thinkpad_acpi` exposes neither.
Comment 3 Faidon Liambotis 2024-12-12 00:31:12 UTC
(Responding to the priority modification.)

I can understand the "wishlist" part for supporting setting/modifying charge types.

But as I mentioned, if charge_types is not set to "Custom", charge thresholds are ignored by the firmware (even if set). Powerdevil shows these charge thresholds, making statements like "Battery is configured to charge up to approximately 85%" even when that is not the case. IMHO, this part is a bug, not a wishlist item.
Comment 4 Faidon Liambotis 2024-12-19 23:49:48 UTC
I reported this originally against powerdevil, because powerdevil's daemon/chargethresholdhelper_linux.cpp seems to be the one reading from/writing to sysfs. Was this wrong? Should I be reporting these kind of issues to plasmashell instead?
Comment 5 Jakob Petsovits 2024-12-20 01:37:59 UTC
(In reply to Faidon Liambotis from comment #4)
> I reported this originally against powerdevil, because powerdevil's
> daemon/chargethresholdhelper_linux.cpp seems to be the one reading
> from/writing to sysfs. Was this wrong? Should I be reporting these kind of
> issues to plasmashell instead?

No, powerdevil was correct at the time. Nate performed a bulk move of powerdevil bugs into a new component within the plasmashell product, so that's where they'll be going forward.
Comment 6 Bug Janitor Service 2025-02-08 20:49:18 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/510
Comment 7 Jakob Petsovits 2025-02-08 20:54:15 UTC
Looking for testers of the change proposed in the merge request that was linked in the previous comment! I don't have a laptop of this sort, so I can't quite test if it really fixes your issue.

Note that the change only sets the value for `charge_types`, it doesn't read the current one. The idea is that the proposed MR can go into Plasma 6.3 as a bugfix, whereas selecting one of the possible types would require additional code and target an upcoming feature release instead (currently 6.4).
Comment 8 Jakob Petsovits 2025-03-02 22:44:36 UTC
Git commit 54c5159156984265ab6485a2e55152d242eeb130 by Jakob Petsovits.
Committed on 02/03/2025 at 22:37.
Pushed by jpetso into branch 'master'.

daemon: Fix charge threshold support for Dell laptops, maybe more

Some kernel drivers expose `charge_types` in addition to start/end
charge thresholds for power supply batteries. A prominent example
is the `dell_laptop` starting with Linux 6.12, which supports
(at least some) Dell Latitude laptops.

This commit will attempt to write a charge type on Linux systems
if the battery's `charge_types` file exists in sysfs.
It will write `Standard` as charge type if the configuration asks
for fully charging the laptop, and `Custom` for all other charge
threshold values.

The KAuth helper also now supports writing explicitly provided
charge types, however the settings UI does not make use of this yet.

This commit does not (yet) implement reading current or supported
charge types, because that's not useful without a settings UI.
Note that charge threshold settings are only applied when values
are changed, so any pre-existing charge type (e.g. `Fast`) won't be
touched without an explicit interaction.

M  +75   -13   daemon/chargethresholdhelper_linux.cpp

https://invent.kde.org/plasma/powerdevil/-/commit/54c5159156984265ab6485a2e55152d242eeb130
Comment 9 Jakob Petsovits 2025-03-02 22:49:15 UTC
Git commit b6fcaca955820f91b94032184cd0173dac9787ae by Jakob Petsovits.
Committed on 02/03/2025 at 22:44.
Pushed by jpetso into branch 'Plasma/6.3'.

daemon: Fix charge threshold support for Dell laptops, maybe more

Some kernel drivers expose `charge_types` in addition to start/end
charge thresholds for power supply batteries. A prominent example
is the `dell_laptop` starting with Linux 6.12, which supports
(at least some) Dell Latitude laptops.

This commit will attempt to write a charge type on Linux systems
if the battery's `charge_types` file exists in sysfs.
It will write `Standard` as charge type if the configuration asks
for fully charging the laptop, and `Custom` for all other charge
threshold values.

The KAuth helper also now supports writing explicitly provided
charge types, however the settings UI does not make use of this yet.

This commit does not (yet) implement reading current or supported
charge types, because that's not useful without a settings UI.
Note that charge threshold settings are only applied when values
are changed, so any pre-existing charge type (e.g. `Fast`) won't be
touched without an explicit interaction.


(cherry picked from commit 54c5159156984265ab6485a2e55152d242eeb130)

Co-authored-by: Jakob Petsovits <jpetso@petsovits.com>

M  +75   -13   daemon/chargethresholdhelper_linux.cpp

https://invent.kde.org/plasma/powerdevil/-/commit/b6fcaca955820f91b94032184cd0173dac9787ae