Trackpad / keyboard suspend and wakeup issues

I want to share how I fixed an issue with my laptop waking itself up from sleep due to the keyboard and trackpad buttons being pressed through the lid while the lid is closed as a result of pressure on the lid from my overloaded backpack. This was making my battery drain quickly during commutes.

Product: Framework Laptop 16 DIY Edition (AMD Ryzen™ 7040 Series) System: Ryzen™ 7 7840HS / OS: Linux Mint 22.2 Cinnamon

First I disabled all the XHC* devices from waking the device. You can see which devices are configured to wake up your device here:

cat /proc/acpi/wakeup

In my case XHC2 was already disabled so I ran these commands. This is not persistent across restarts.

sudo sh -c 'echo XHC0 > /proc/acpi/wakeup'
sudo sh -c 'echo XHC1 > /proc/acpi/wakeup'
sudo sh -c 'echo XHC3 > /proc/acpi/wakeup'
sudo sh -c 'echo XHC4 > /proc/acpi/wakeup'

This worked only for the keyboard, not the trackpad buttons. (Disabling the other, non XHC* devices from /proc/acpi/wakeup did not do anything useful.)

This command worked for the trackpad buttons, and it is also not persistent across restarts.

sudo sh -c 'echo disabled > /sys/devices/platform/AMDI0010:03/i2c-1/i2c-PIXA3854:00/power/wakeup'

(Chat GPT just knew the command, so if this isn’t the name of the device for your trackpad, good luck and maybe Chat GPT can help you too.)

To make it permanent, i.e. keep this behavior across restarts, I had to create a service.

Some advice on the internet said to put commands in “/etc/rc.local” but that file is obsolete now and Linux Mint does not run it. I thought it was weird to create a service just to run a startup script, but I guess this is the idiomatic way to run startup scripts with systemd.

First I made a script that the service will run on startup. The #! line is important as the script will be run from systemd rather than a bash shell, so this is needed to indicate it’s a bash script. Also one should not call “sudo” in this script as it’s already run as root.

I named this file /etc/disable-wake-devices.sh

#!/usr/bin/env bash

# Commands to disable XHC* devices from waking the device. One of these XHC* should be the keyboard.

echo XHC0 > /proc/acpi/wakeup
echo XHC1 > /proc/acpi/wakeup
echo XHC3 > /proc/acpi/wakeup
echo XHC4 > /proc/acpi/wakeup

# Command that works to disable the trackpad from waking the device from sleep.

echo disabled > /sys/devices/platform/AMDI0010:03/i2c-1/i2c-PIXA3854:00/power/wakeup

Then I created the service.

I created /etc/systemd/system/disable-wake-devices.service

Contents:

[Unit]
Description=Disable devices from waking from sleep
ConditionFileIsExecutable=/etc/disable-wake-devices.sh
After=network.target
[Service]
Type=oneshot
ExecStart=/etc/disable-wake-devices.sh
TimeoutSec=0
StandardOutput=journal
[Install]
WantedBy=multi-user.target

Then I create and start the service in one command:

sudo systemctl enable --now /etc/systemd/system/disable-wake-devices.service

And check the status:

sudo systemctl status disable-wake-devices.service

Update: very related post with similar solutions: [SOLVED] Laptop waking from sleep in backpack - see here if you are interested in preventing opening of the lid from waking from sleep in addition to the trackpad/keyboard.