- Go 96%
- Makefile 4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| cmd | ||
| docs | ||
| internal | ||
| packaging | ||
| .gitignore | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
lgctl: fan, battery charge limit, power profile and speakers for LG Gram laptops on Linux
lgctl gives Linux users of LG Gram laptops the controls that LG only
ships in its Windows app: fan mode (silent / normal / boost), the
battery charge limit (stop at 80 %), and the system power profile,
plus live temperatures, CPU frequency and power. On the 2023 Gram Style
it also brings the internal speakers to life (see below). It comes as a
command-line tool (lgctl) and a small desktop window (lgctl-gui, "LG
Control" in your application menu, with a tray icon).
Developed and tested on an LG Gram 16Z90RS (Intel Core i7-1360P) running
Fedora 44 with the COSMIC desktop. It should work on any LG Gram supported by
the kernel's lg_laptop driver and on any desktop (GNOME, KDE Plasma, COSMIC,
Sway...), as long as power profiles are provided by power-profiles-daemon or
tuned-ppd.
What it does, and how
Everything goes through standard kernel interfaces, no daemon (the speaker fix is a one-shot systemd unit):
| Setting / reading | Where it lives |
|---|---|
| Fan mode (0/1/2) | /sys/devices/platform/lg-laptop/fan_mode (kernel lg_laptop) |
| Charge limit (80/100) | /sys/class/power_supply/BAT0/charge_control_end_threshold |
| Power profile | net.hadess.PowerProfiles on the system D-Bus (ppd / tuned-ppd) |
| Battery level, health | /sys/class/power_supply/BAT0/* (energy_full vs. design, cycles) |
| CPU temperatures | hwmon coretemp |
| CPU frequency | cpufreq scaling_cur_freq |
| CPU package power | RAPL intel-rapl:0/energy_uj, sampled once per second |
| GPU frequency | i915 gt/gt0/rps_act_freq_mhz |
| NVMe, chassis | hwmon nvme, acpitz |
| Speaker amplifiers | HDA codec hwdep /dev/snd/hwC0D0 (root), see below |
The fan and charge settings are stored by the LG firmware, so they survive a reboot. The firmware reports no real fan speed (its ACPI value is a constant), so none is shown. Changing the power profile goes through the daemon, so the desktop's own selector stays in sync.
Speakers on the LG Gram Style (16Z90RS)
The 2023 Gram Style has a Realtek ALC298 codec with the speakers behind I2C
amplifiers that must be programmed before they make a sound. The kernel does
this only for models in its quirk table: the 14-inch (1854:0490) is there
since Linux 7.0 (ALC298_FIXUP_LG_GRAM_STYLE_14), the 16-inch (1854:0492)
is not yet, so its speakers are silent under Linux while headphones and HDMI
work. A one-line kernel patch adding the 16-inch ID is being submitted; until
it reaches your distribution, lgctl replays the kernel's own sequence from
userspace:
lgctl speakers status: codec, last apply, service state
sudo lgctl speakers apply initialise and enable the amplifiers
lgctl speakers start same, through the systemd unit (polkit, no sudo)
lgctl-speakers.service runs the apply at boot and after resume. The RPM
enables it automatically on a 16Z90RS; from source, sudo make install-system
does. The GUI and its tray menu show when the fix was last applied and offer
"Apply now"; the polkit rule in packaging/50-lgctl.rules lets members of
wheel do that without a password.
The tray menu also switches the power profile and the fan mode. The "Startup"
card of the window decides whether LG Control starts at login and whether it
starts in the tray only or with its window; the choice is written to
~/.config/autostart/lgctl-tray.desktop, which overrides the system entry.
Writing to the codec's hwdep device requires CAP_SYS_RAWIO, which is why
this one command needs root. "Applied" means the sequence ran since boot: the
amplifiers cannot be read back. Only the two amplifiers the 16-inch actually
has (0x38, 0x39) are programmed by default; --amps all also drives the
0x3c/0x3d pair of the 14-inch. lgctl speakers refuses to run on a codec
it does not recognise unless given --force.
Usage
lgctl status
lgctl fan silent|normal|boost fan mode
lgctl charge 80|100 charge limit
lgctl profile battery|balanced|performance
lgctl watch [seconds] live view, Ctrl-C to quit
lgctl speakers [apply|on|off|start] speaker amplifiers (Gram Style)
lgctl setup how to run without sudo
lgctl version
lgctl-gui the window ("LG Control" in the menu)
lgctl-gui --tray start hidden in the tray (autostart entry)
Example status:
profile balanced
fan normal (0)
battery 100% not charging on AC, limit 80%
health 101% 80.7 / 80.0 Wh design, 4 cycles
cpu 56 °C package cores 50 52 54 54 54 54 55 55 55 55 50 50
cpu freq 853 MHz avg, 1466 MHz max
cpu power 4.6 W (PL1 28 W)
gpu idle
nvme 45 °C chassis 32 °C
Install
RPM (Fedora and derivatives)
Grab the RPM from the releases page, then:
sudo dnf install ./lgctl-*.rpm
The package installs both binaries, the menu entry, the tray autostart entry,
the icon, the udev and polkit rules and the speaker unit, and reloads udev, so
everything works right away for members of the wheel group. Remove the
autostart entry (/etc/xdg/autostart/lgctl-tray.desktop) if you do not want
the tray icon at login.
From source
sudo dnf install golang gcc mesa-libGL-devel libXcursor-devel libXrandr-devel \
libXinerama-devel libXi-devel libXxf86vm-devel libxkbcommon-devel wayland-devel
make # builds lgctl and lgctl-gui
make install-user # binaries, menu and autostart entries, icon under ~/.local (no root)
sudo make install-system # /usr/bin/lgctl, udev + polkit rules, speaker unit (enabled)
make rpm # builds the RPM (needs rpm-build rpmdevtools systemd-rpm-macros)
Running without sudo
The fan mode, the charge limit and the CPU energy counter are root-only by
default. lgctl setup prints three udev rules that hand them to the wheel
group, which is what the RPM installs. By hand:
lgctl setup --rules | sudo tee /etc/udev/rules.d/90-lgctl.rules > /dev/null
sudo udevadm control --reload
sudo udevadm trigger /sys/devices/platform/lg-laptop /sys/class/power_supply/BAT0 /sys/class/powercap/intel-rapl:0
The power profile never needs root: the daemon's policy allows the active session to change it.
Requirements
- An LG Gram with the
lg_laptopkernel module loaded (automatic on supported models;ls /sys/devices/platform/lg-laptopshould listfan_mode). power-profiles-daemonortuned-ppdfor the power profile.- An Intel CPU for the RAPL power reading (other readings degrade gracefully).
Tips for Intel iGPU laptops
Two things learned while building this, both relevant to gaming on an LG Gram:
- The Performance profile shipped by tuned (
throughput-performance) is a server profile: it pins the CPU at its maximum frequency, which steals power budget from the integrated GPU. Games run better in Balanced. A laptop friendly Performance profile is simplyinclude=balancedplusenergy_performance_preference=performance. - The Battery profile disables turbo entirely.
include=powersaveplusboost=1keeps the machine usable on battery.
See /usr/lib/tuned/profiles/ for the shipped profiles and
/etc/tuned/ppd.conf to map your own onto the desktop's three modes.
License
MIT. Contributions and reports from other LG Gram models are welcome.
