LG Gram under Linux

90% of the machine works out of the box with a recent Debian. Wifi, USB, the SD card reader, even suspend/resume.

The model I have is the 2020 17" model; 17Z90N (which is the US not the Australian model). I've installed a 1Tb NVME drive, and am running Debian Unstable on it.

Two things amaze me: it's only around 1.3kg; and the battery lasts a long time. This without very much compromise on performance: a kernel compile (using the config below, -j 8. and gcc 10) takes around 9 minutes; I do see some thermal throttling during such a compilation.

The few things that do not work out of the box are:

Apart from the fingerprint reader, all these can be fixed. Battery care needs a patch that is in kernel 5.15 --- Debian Testing And Unstable have this.

Reader Mode

Reader mode is meant to reduce the amount of blue light reaching your eyes, by lowering the colour-temperature of the screen. There are three things to do:
  1. Act on the button to reduce the colour temp
  2. Update the LED on the button
  3. Fix the permissions so ordinary users can do this
Fixing the permissions is done with a udev rules file. I'm assuming that if you're running X11 you're in the video group:

ACTION=="add",SUBSYSTEM=="platform", \
   RUN+="/bin/chgrp video /sys/devices/platform/lg-laptop/reader_mode"
ACTION=="add",SUBSYSTEM=="platform",\
    RUN+="/bin/chmod 0664 /sys/devices/platform/lg-laptop/reader_mode"

Put this into /etc/udev/rules.d/90-lg-platform.rules — it will make it possible for the person logged into the laptop to change the LED.

Install the sct tool (on Debian or Ubuntu, apt install sct) Create a script in ~/bin/readermode or another convenient place.


#!/bin/sh
led=/sys/devices/platform/lg-laptop/reader_mode
TOGGLE=$HOME/.toggle_readermode

if [ ! -e $TOGGLE ]
then
	> $TOGGLE
	sct 4800
	echo 1 > $led
else
	rm $TOGGLE
	echo 0 > $led
	sct
fi

Finally bind Fn-F9 to run ~/bin/readermode. I run XFCE4, and can do this from Settings->Keyboard->Application Shortcuts.

Touchpad disabling

LG provide Fn-F5 for disabling the touchpad, so you can type easily without moving the mouse all over the place.

To make it work, create a new file ~/bin/touchpad_toggle containing this:

#!/bin/sh
# This shell script is PUBLIC DOMAIN. You may do whatever you want with it.

TOGGLE=$HOME/.toggle_touchpad

ELAN=`xinput list | sed -n 's/.*ELAN0E03:00 04F3:3121.*id=\([0-9]*\).*/\1/p'`
TP=`xinput list | sed -n 's/.*ELAN0E03:00 04F3:3121 Touchpad.*id=\([0-9]*\).*/\1/p'`


if [ ! -e $TOGGLE ]; then
    touch $TOGGLE
    for x in $ELAN
    do
	xinput disable $x
    done
    echo 0 > /sys/devices/platform/lg-laptop/leds/tpad_led/brightness
    notify-send -u low -t 1000 -i mouse --icon=/usr/share/icons/HighContrast/256x256/status/touchpad-disabled.png "Trackpad disabled"
else
    rm $TOGGLE
    xinput enable $TP
    echo 1 > /sys/devices/platform/lg-laptop/leds/tpad_led/brightness
    notify-send -u low -t 1000 -i mouse --icon=/usr/share/icons/HighContrast/256x256/devices/input-touchpad.png "Trackpad enabled"
fi

Battery Care

Batteries last a lot longer if they're ony charged to 80%. LG provide a method for doing this; for recent LG Gram models, you'll have to wait for the patch. When you get a suitable kernel (5.15 or later), add


# Restrict charging to 80%
echo 80 > /sys/devices/platform/lg-laptop/battery_care_limit
to /etc/rc.local (make sure it's mode 0744) and enable rc.local by adding a Systemd unit thus (or use sysV init):
[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes
 SysVStartPriority=99

[Install]
WantedBy=multi-user.target


in a file called /etc/systemd/rc.local.service

Next time you reboot, the charge will max out at 80%.

Thunderbolt Hotplug

Some docks seem to work correctly if plugged in at boot, but if they are unplugged and replugged stop working. This is because the BIOS doesn't reserve space for the PCIe hotplug registers.

To fix, add GRUB_CMDLINE_LINUX_DEFAULT="pci=assign-busses,realloc,hpbussize=0x10,hpmmiosize=128M,hpmmioprefsize=1G" to /etc/default/grub and run sudo update-grub

Other Tweaks

To maximise battery life, I've also added these lines to /etc/rc.local
#!/bin/sh
# Power saving tunables
#
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
#echo '0' > /proc/sys/kernel/nmi_watchdog
# i915
echo 'auto' > '/sys/bus/i2c/devices/i2c-9/device/power/control'
# USB3 port
echo 'auto' > '/sys/bus/pci/devices/0000:00:14.0/power/control'
#Thunderbolt port
echo 'auto' > '/sys/bus/pci/devices/0000:00:07.0/power/control'
# WIFI
echo 'auto' > '/sys/bus/pci/devices/0000:00:14.3/power/control'
# SPI
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.5/power/control'
#??
echo 'auto' > '/sys/bus/pci/devices/0000:00:04.0/power/control'
# 

echo 'auto' > '/sys/bus/pci/devices/0000:00:00.0/power/control'
#
# NVME Disks
echo 'auto' > '/sys/bus/pci/devices/0000:2c:00.0/power/control';
echo 'auto' > '/sys/bus/pci/devices/0000:2c:00.0/power/control'

I get 10-12 hours under light use. Compiling kernels, or running videoconf sessions reduce that a lot,

Kernel config

A suitable config is at gram-config. You may need to add more devices to the ones recognised for USB.

Fingerprint Reader

The fingerprint reader is different from the ones on earlier Gram models. It appears to be on the SPI bus, rather than on USB. There is no driver