Unable to set battery charge limit

I am having an issue setting the battery charging limit on my LG Gram 17. There is a driver provided in the kernel, but when I try to change the value located at

/sys/devices/platform/lg-laptop/battery_care_limit

with,

[chris@GramC log]$ sudo echo 80 > tee /sys/devices/platform/lg-laptop/battery_care_limit

I get the following error:

bash: tee: Permission denied

The strange thing is that when I modify these values on Manjaro, I have no issues whatsoever.

Does anyone have any ideas what is going on here?

[chris@GramC log]$ inxi -Farz 
System:
  Kernel: 6.6.39-1-lts arch: x86_64 bits: 64 compiler: gcc v: 14.1.1
    clocksource: tsc avail: acpi_pm
    parameters: initrd=\fcd620674633418d90ebfaf1ea036695\6.6.39-1-lts\initrd
    nvme_load=YES nowatchdog rw
    root=UUID=6e3b05b4-6ab5-4e21-8112-8ba27c3922f1 rw
    root=UUID=6e3b05b4-6ab5-4e21-8112-8ba27c3922f1 rw
    root=UUID=6e3b05b4-6ab5-4e21-8112-8ba27c3922f1
    systemd.machine_id=fcd620674633418d90ebfaf1ea036695
  Desktop: KDE Plasma v: 6.1.2 tk: Qt v: N/A info: frameworks v: 6.3.0
    wm: kwin_wayland with: krunner vt: 1 dm: SDDM Distro: EndeavourOS
    base: Arch Linux
Machine:
  Type: Laptop System: LG product: 16ZB90R-G.AA75G v: 0.1
    serial: <superuser required> Chassis: type: 10 v: 0.1
    serial: <superuser required>
  Mobo: LG model: 16ZB90R v: FAB1 serial: <superuser required> part-nu: EVO
    uuid: <superuser required> UEFI: Phoenix v: R4ZH0340 X64 date: 01/03/2023
Battery:
  ID-1: BAT0 charge: 34.5 Wh (43.9%) condition: 78.6/80.0 Wh (98.2%)
    power: 8.1 W volts: 7.6 min: 7.7 model: LG LGC-LGC type: Li-ion
    serial: <filter> status: discharging cycles: 160
CPU:
  Info: model: 13th Gen Intel Core i7-1360P bits: 64 type: MST AMCP
    arch: Raptor Lake level: v3 note: check built: 2022+ process: Intel 7 (10nm)
    family: 6 model-id: 0xBA (186) stepping: 2 microcode: 0x4121
  Topology: cpus: 1x cores: 12 mt: 4 tpc: 2 st: 8 threads: 16 smt: enabled
    cache: L1: 1.1 MiB desc: d-8x32 KiB, 4x48 KiB; i-4x32 KiB, 8x64 KiB
    L2: 9 MiB desc: 4x1.2 MiB, 2x2 MiB L3: 18 MiB desc: 1x18 MiB
  Speed (MHz): avg: 557 high: 968 min/max: 400/5000:3700 scaling:
    driver: intel_pstate governor: powersave cores: 1: 697 2: 400 3: 400 4: 768
    5: 400 6: 400 7: 940 8: 400 9: 400 10: 400 11: 400 12: 968 13: 400 14: 869
    15: 400 16: 676 bogomips: 83584
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
  Vulnerabilities:
  Type: gather_data_sampling status: Not affected
  Type: itlb_multihit status: Not affected
  Type: l1tf status: Not affected
  Type: mds status: Not affected
  Type: meltdown status: Not affected
  Type: mmio_stale_data status: Not affected
  Type: reg_file_data_sampling mitigation: Clear Register File
  Type: retbleed status: Not affected
  Type: spec_rstack_overflow status: Not affected
  Type: spec_store_bypass mitigation: Speculative Store Bypass disabled via
    prctl
  Type: spectre_v1 mitigation: usercopy/swapgs barriers and __user pointer
    sanitization
  Type: spectre_v2 mitigation: Enhanced / Automatic IBRS; IBPB:
    conditional; RSB filling; PBRSB-eIBRS: SW sequence; BHI: BHI_DIS_S
  Type: srbds status: Not affected
  Type: tsx_async_abort status: Not affected
Graphics:
  Device-1: Intel Raptor Lake-P [Iris Xe Graphics] vendor: LG driver: i915
    v: kernel arch: Gen-13 process: Intel 7 (10nm) built: 2022+ ports:
    active: eDP-1 empty: DP-1,DP-2,HDMI-A-1 bus-ID: 00:02.0 chip-ID: 8086:a7a0
    class-ID: 0300
  Device-2: Realtek LG Camera driver: uvcvideo type: USB rev: 2.0
    speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 3-2:2 chip-ID: 0bda:5641
    class-ID: 0e02 serial: <filter>
  Display: wayland server: X.org v: 1.21.1.13 with: Xwayland v: 24.1.1
    compositor: kwin_wayland driver: X: loaded: modesetting
    alternate: fbdev,intel,vesa dri: iris gpu: i915 display-ID: 0
  Monitor-1: eDP-1 res: 1707x1067 size: N/A modes: N/A
  API: EGL v: 1.5 hw: drv: intel iris platforms: device: 0 drv: iris
    device: 1 drv: swrast surfaceless: drv: iris wayland: drv: iris x11:
    drv: iris inactive: gbm
  API: OpenGL v: 4.6 compat-v: 4.5 vendor: intel mesa v: 24.1.3-arch1.1
    glx-v: 1.4 direct-render: yes renderer: Mesa Intel Graphics (RPL-P)
    device-ID: 8086:a7a0 memory: 7.49 GiB unified: yes display-ID: :1.0
  API: Vulkan Message: No Vulkan data available.
Audio:
  Device-1: Intel Raptor Lake-P/U/H cAVS vendor: LG
    driver: sof-audio-pci-intel-tgl
    alternate: snd_hda_intel,snd_sof_pci_intel_tgl bus-ID: 00:1f.3
    chip-ID: 8086:51ca class-ID: 0401
  API: ALSA v: k6.6.39-1-lts status: kernel-api
    tools: alsactl,alsamixer,amixer
  Server-1: PipeWire v: 1.2.1 status: active with: 1: pipewire-pulse
    status: active 2: wireplumber status: active 3: pipewire-alsa type: plugin
    4: pw-jack type: plugin tools: pactl,pw-cat,pw-cli,wpctl
Network:
  Device-1: Intel Raptor Lake PCH CNVi WiFi driver: iwlwifi v: kernel
    bus-ID: 00:14.3 chip-ID: 8086:51f1 class-ID: 0280
  IF: wlan0 state: up mac: <filter>
  Info: services: NetworkManager, systemd-timesyncd, wpa_supplicant
Bluetooth:
  Device-1: Intel AX211 Bluetooth driver: btusb v: 0.8 type: USB rev: 2.0
    speed: 12 Mb/s lanes: 1 mode: 1.1 bus-ID: 3-10:5 chip-ID: 8087:0033
    class-ID: e001
  Report: btmgmt ID: hci0 rfk-id: 0 state: up address: <filter> bt-v: 5.3
    lmp-v: 12 status: discoverable: no pairing: no class-ID: 6c010c
Drives:
  Local Storage: total: 476.94 GiB used: 9.44 GiB (2.0%)
  SMART Message: Unable to run smartctl. Root privileges required.
  ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Samsung
    model: MZVL4512HBLU-00B07 size: 476.94 GiB block-size: physical: 512 B
    logical: 512 B speed: 63.2 Gb/s lanes: 4 tech: SSD serial: <filter>
    fw-rev: HXC7102Q temp: 33.9 C scheme: GPT
Partition:
  ID-1: / raw-size: 475.93 GiB size: 467.39 GiB (98.21%) used: 9.27 GiB (2.0%)
    fs: ext4 dev: /dev/nvme0n1p2 maj-min: 259:2
Swap:
  Alert: No swap data was found.
Sensors:
  System Temperatures: cpu: 45.0 C mobo: N/A
  Fan Speeds (rpm): N/A
Repos:
  Packages: pm: pacman pkgs: 1028 libs: 249 tools: yay
  Active pacman repo servers in: /etc/pacman.d/endeavouros-mirrorlist
    1: https://mirror.moson.org/endeavouros/repo/$repo/$arch
    2: https://mirror.rznet.fr/endeavouros/repo/$repo/$arch
    3: https://mirror.alpix.eu/endeavouros/repo/$repo/$arch
    4: https://md.mirrors.hacktegic.com/endeavouros/repo/$repo/$arch
    5: https://mirror.accum.se/mirror/endeavouros/repo/$repo/$arch
    6: https://mirrors.c0urier.net/linux/endeavouros/repo/$repo/$arch
    7: https://ftp.belnet.be/mirror/endeavouros/repo/$repo/$arch
    8: https://fosszone.csd.auth.gr/endeavouros/repo/$repo/$arch
    9: https://mirrors.nxtgen.com/endeavouros-mirror/repo/$repo/$arch
    10: https://mirror.jingk.ai/endeavouros/repo/$repo/$arch
    11: https://mirrors.gigenet.com/endeavouros/repo/$repo/$arch
    12: https://mirror.funami.tech/endeavouros/repo/$repo/$arch
    13: https://mirrors.urbanwave.co.za/endeavouros/repo/$repo/$arch
    14: https://mirror.freedif.org/EndeavourOS/repo/$repo/$arch
    15: https://mirror.albony.xyz/endeavouros/repo/$repo/$arch
    16: https://mirrors.jlu.edu.cn/endeavouros/repo/$repo/$arch
    17: https://mirror.archlinux.tw/EndeavourOS/repo/$repo/$arch
    18: https://www.miraa.jp/endeavouros/repo/$repo/$arch
    19: https://mirror.sjtu.edu.cn/endeavouros/repo/$repo/$arch
    20: https://mirrors.tuna.tsinghua.edu.cn/endeavouros/repo/$repo/$arch
  Active pacman repo servers in: /etc/pacman.d/mirrorlist
    1: https://mirrors.n-ix.net/archlinux/$repo/os/$arch
    2: https://mirror.netcologne.de/archlinux/$repo/os/$arch
    3: https://de.mirrors.cicku.me/archlinux/$repo/os/$arch
    4: https://arch.phinau.de/$repo/os/$arch
    5: https://mirrors.niyawe.de/archlinux/$repo/os/$arch
    6: https://mirror.moson.org/arch/$repo/os/$arch
    7: https://packages.oth-regensburg.de/archlinux/$repo/os/$arch
    8: https://mirror.cmt.de/archlinux/$repo/os/$arch
    9: https://mirror.ubrco.de/archlinux/$repo/os/$arch
    10: https://archlinux.thaller.ws/$repo/os/$arch
    11: https://pkg.fef.moe/archlinux/$repo/os/$arch
    12: https://os.codefionn.eu/archlinux/$repo/os/$arch
    13: https://mirror.pseudoform.org/$repo/os/$arch
    14: https://ftp.fau.de/archlinux/$repo/os/$arch
    15: https://mirror.metalgamer.eu/archlinux/$repo/os/$arch
    16: https://arch.unixpeople.org/$repo/os/$arch
    17: https://arch.jensgutermuth.de/$repo/os/$arch
    18: https://mirror.informatik.tu-freiberg.de/arch/$repo/os/$arch
    19: https://mirrors.xtom.de/archlinux/$repo/os/$arch
    20: https://mirror.fra10.de.leaseweb.net/archlinux/$repo/os/$arch
Info:
  Memory: total: 16 GiB note: est. available: 15.34 GiB used: 7.44 GiB (48.5%)
  Processes: 336 Power: uptime: 22h 35m states: freeze,mem,disk
    suspend: s2idle avail: deep wakeups: 6 hibernate: platform avail: shutdown,
    reboot, suspend, test_resume image: 6.13 GiB services: org_kde_powerdevil,
    power-profiles-daemon, upowerd Init: systemd v: 256 default: graphical
    tool: systemctl
  Compilers: gcc: 14.1.1 Shell: Bash v: 5.2.26 running-in: konsole
    inxi: 3.3.35

sudo in wrong place? echo blah | sudo tee blah blah

Also | instead of > ??

Maybe controveverstial but stuff like this I would run as root (re-install if not work out). I would want this in every session if it was needed. (PS no expert and willing to destroy my system at times) BTW this seems ok to run this way (could be really wrong)

That didnt change anything. The value stays at 0 no matter what I do.

@smokey: doesn’t work either to run as root

cd /
sudo touch test.conf
echo 2112 | sudo tee test.conf
cat test.conf
2112

Definitely works here.

What does:

cat /sys/devices/platform/lg-laptop/battery_care_limit

return?

:edit: Some strange copy and paste issue from atuin - fixed!

[chris@GramC log]$ cat /sys/devices/platform/lg-laptop/battery_care_limit
0

Um had another thought which just struck me but are there any settings in BIOS that could be affecting it? I remember having to change this at least once on a laptop

Any idea which one? Nothing popped out to me as something that would be affecting this

No sorry been about a year and a half since I had a laptop but I remember the last couple I had having settings in BIOS about charging and changing them as I had it always on power

Post the exact terminal contents when you try anything.
As explained, sudo echo does not work.

What method do you use for modifications?

Here you go:

[chris@GramC ~]$ echo 80 | sudo tee /sys/devices/platform/lg-laptop/battery_care_limit
[sudo] password for user: 
80

checking to see if the value has been really modified:

[chris@GramC ~]$ cat /sys/devices/platform/lg-laptop/battery_care_limit
0

the value I am referring to is for the driver I am having issues with here. Setting a battery max charge with the method above on Manjaro works without issue.

1 Like

Permissions maybe?

ls -l /sys/devices/platform/lg-laptop/battery_care_limit
sudo file /sys/devices/platform/lg-laptop/battery_care_limit

:thinking:

That is what I thought too. And here you go:

[chris@GramC ~]$ ls -l /sys/devices/platform/lg-laptop/battery_care_limit
-rw-r--r-- 1 root root 4096 17. Jul 23:19 /sys/devices/platform/lg-laptop/battery_care_limit

chris@GramC ~]$ sudo file /sys/devices/platform/lg-laptop/battery_care_limit
/sys/devices/platform/lg-laptop/battery_care_limit: ASCII text

The strange thing is that the file is clearly being modified (I tried writing to it again with the code in the previous post) and the timestamp was changed to reflect this.

My bet goes to the vendor firmware.
We can only guess. This should not happen :face_with_head_bandage:

lsattr /sys/devices/platform/lg-laptop/battery_care_limit

Might need sudo added, but what does it show?

They say

Battery care limit

Writing 80/100 to /sys/devices/platform/lg-laptop/battery_care_limit sets the maximum capacity to charge the battery. Limiting the charge reduces battery capacity loss over time.

This value is reset to 100 when the kernel boots.

Maybe look for that driver name, if it is loaded (with lsmod), and compare with Manjaro.

Also try writing 100, instead of 80. It says default is reset on boot, so the content should be 100.
It does not make sense.

Try other LG hacks, if you can modify contents (as listed in the link).

[chris@GramC ~]$ lsattr /sys/devices/platform/lg-laptop/battery_care_limit
lsattr: Operation not supported While reading flags on /sys/devices/platform/lg-laptop/battery_care_limit

Oh well…

Small update on my troubles. Running tlp-stat gives the following result:

...

+++ Battery Care
Plugin: lg-legacy
Supported features: none available
Driver usage:
*  vendor (lg_laptop) = inactive (laptop not supported) <<<<---------

+++ Battery Status: BAT0
/sys/class/power_supply/BAT0/manufacturer                   =  LG 
/sys/class/power_supply/BAT0/model_name                     = LGC-LGC
/sys/class/power_supply/BAT0/cycle_count                    =    162
/sys/class/power_supply/BAT0/energy_full_design             =  80000 [mWh]
/sys/class/power_supply/BAT0/energy_full                    =  76500 [mWh]
/sys/class/power_supply/BAT0/energy_now                     =  68140 [mWh]
/sys/class/power_supply/BAT0/power_now                      =   6562 [mW]
/sys/class/power_supply/BAT0/status                         = Discharging

It is beyond me why on one arch based distro it is supported and another it isn’t…

IT’s the same old “divide and conquer”.
Linux vendors fight one another.

I wonder why someone that asks for assistance from supposed experts, do not do as suggested, but do as they like.
Another mystery of human nature…

:thinking: