<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>497200</bug_id>
          
          <creation_ts>2024-12-08 14:08:00 +0000</creation_ts>
          <short_desc>Support &quot;charge_types&quot; alongside &quot;charge_start/end_threshold&quot;, no effect otherwise on certain laptops</short_desc>
          <delta_ts>2025-03-04 22:48:11 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>4</classification_id>
          <classification>Plasma</classification>
          <product>plasmashell</product>
          <component>Power management &amp; brightness</component>
          <version>6.2.4</version>
          <rep_platform>Other</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>wishlist</bug_severity>
          <target_milestone>1.0</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Faidon Liambotis">paravoid</reporter>
          <assigned_to name="Plasma Bugs List">plasma-bugs-null</assigned_to>
          <cc>jpetso</cc>
    
    <cc>natalie_clarius</cc>
    
    <cc>nate</cc>
          
          <cf_commitlink>https://invent.kde.org/plasma/powerdevil/-/commit/b6fcaca955820f91b94032184cd0173dac9787ae</cf_commitlink>
          <cf_versionfixedin>6.3.3</cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2379748</commentid>
    <comment_count>0</comment_count>
    <who name="Faidon Liambotis">paravoid</who>
    <bug_when>2024-12-08 14:08:00 +0000</bug_when>
    <thetext>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&apos;t exist on my system), and the kernel&apos;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&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2379832</commentid>
    <comment_count>1</comment_count>
    <who name="Jakob Petsovits">jpetso</who>
    <bug_when>2024-12-08 23:54:46 +0000</bug_when>
    <thetext>Thanks for the notice. I&apos;m not yet quite sure how best to tackle this, but I agree it&apos;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` .</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2379833</commentid>
    <comment_count>2</comment_count>
    <who name="Faidon Liambotis">paravoid</who>
    <bug_when>2024-12-09 00:09:05 +0000</bug_when>
    <thetext>(In reply to Jakob Petsovits from comment #1)
&gt; Thanks for the notice. I&apos;m not yet quite sure how best to tackle this, but I
&gt; agree it&apos;s something that should be implemented somehow.

Thanks for the quick response and confirmation!

&gt; Note: the `charge_types` file does not necessarily exist for all laptops
&gt; with charge threshold kernel support - also on kernel 6.12, my ThinkPad
&gt; 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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2380542</commentid>
    <comment_count>3</comment_count>
    <who name="Faidon Liambotis">paravoid</who>
    <bug_when>2024-12-12 00:31:12 +0000</bug_when>
    <thetext>(Responding to the priority modification.)

I can understand the &quot;wishlist&quot; part for supporting setting/modifying charge types.

But as I mentioned, if charge_types is not set to &quot;Custom&quot;, charge thresholds are ignored by the firmware (even if set). Powerdevil shows these charge thresholds, making statements like &quot;Battery is configured to charge up to approximately 85%&quot; even when that is not the case. IMHO, this part is a bug, not a wishlist item.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2382855</commentid>
    <comment_count>4</comment_count>
    <who name="Faidon Liambotis">paravoid</who>
    <bug_when>2024-12-19 23:49:48 +0000</bug_when>
    <thetext>I reported this originally against powerdevil, because powerdevil&apos;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?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2382873</commentid>
    <comment_count>5</comment_count>
    <who name="Jakob Petsovits">jpetso</who>
    <bug_when>2024-12-20 01:37:59 +0000</bug_when>
    <thetext>(In reply to Faidon Liambotis from comment #4)
&gt; I reported this originally against powerdevil, because powerdevil&apos;s
&gt; daemon/chargethresholdhelper_linux.cpp seems to be the one reading
&gt; from/writing to sysfs. Was this wrong? Should I be reporting these kind of
&gt; 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&apos;s where they&apos;ll be going forward.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2396058</commentid>
    <comment_count>6</comment_count>
    <who name="Bug Janitor Service">bug-janitor</who>
    <bug_when>2025-02-08 20:49:18 +0000</bug_when>
    <thetext>A possibly relevant merge request was started @ https://invent.kde.org/plasma/powerdevil/-/merge_requests/510</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2396060</commentid>
    <comment_count>7</comment_count>
    <who name="Jakob Petsovits">jpetso</who>
    <bug_when>2025-02-08 20:54:15 +0000</bug_when>
    <thetext>Looking for testers of the change proposed in the merge request that was linked in the previous comment! I don&apos;t have a laptop of this sort, so I can&apos;t quite test if it really fixes your issue.

Note that the change only sets the value for `charge_types`, it doesn&apos;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).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2404128</commentid>
    <comment_count>8</comment_count>
    <who name="Jakob Petsovits">jpetso</who>
    <bug_when>2025-03-02 22:44:36 +0000</bug_when>
    <thetext>Git commit 54c5159156984265ab6485a2e55152d242eeb130 by Jakob Petsovits.
Committed on 02/03/2025 at 22:37.
Pushed by jpetso into branch &apos;master&apos;.

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&apos;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&apos;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&apos;t be
touched without an explicit interaction.

M  +75   -13   daemon/chargethresholdhelper_linux.cpp

https://invent.kde.org/plasma/powerdevil/-/commit/54c5159156984265ab6485a2e55152d242eeb130</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2404129</commentid>
    <comment_count>9</comment_count>
    <who name="Jakob Petsovits">jpetso</who>
    <bug_when>2025-03-02 22:49:15 +0000</bug_when>
    <thetext>Git commit b6fcaca955820f91b94032184cd0173dac9787ae by Jakob Petsovits.
Committed on 02/03/2025 at 22:44.
Pushed by jpetso into branch &apos;Plasma/6.3&apos;.

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&apos;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&apos;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&apos;t be
touched without an explicit interaction.


(cherry picked from commit 54c5159156984265ab6485a2e55152d242eeb130)

Co-authored-by: Jakob Petsovits &lt;jpetso@petsovits.com&gt;

M  +75   -13   daemon/chargethresholdhelper_linux.cpp

https://invent.kde.org/plasma/powerdevil/-/commit/b6fcaca955820f91b94032184cd0173dac9787ae</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>