Disable wake up from suspend for all (USB) devices except the laptop's own keyboard

I’m trying to disable wake up from suspend for all (USB) devices except the laptop’s own keyboard. Anyone did this?

I’m toggling settings in /proc/acpi like this (if enabled, checking with e.g. “cat /proc/acpi/wakeup | egrep -i pci | egrep XHC0 | awk '{print $3}”):

sudo sh -c “echo XHC0 > /proc/acpi/wakeup”
sudo sh -c “echo XHC1 > /proc/acpi/wakeup”
sudo sh -c “echo XHC2 > /proc/acpi/wakeup”
sudo sh -c “echo XHC3 > /proc/acpi/wakeup”
sudo sh -c “echo XHC4 > /proc/acpi/wakeup”

And to:

sudo sh -c “echo ‘enabled’ > /sys/bus/usb/devices/1-4.3/power/wakeup”
sudo sh -c “echo ‘enabled’ > /sys/bus/usb/devices/1-4.1/power/wakeup”
sudo sh -c “echo ‘enabled’ > /sys/bus/usb/devices/1-4/power/wakeup”

These are some external USB devices:

sudo sh -c “echo ‘disabled’ > /sys/bus/usb/devices/1-2.2.4.3.2/power/wakeup”
sudo sh -c “echo ‘disabled’ > /sys/bus/usb/devices/1-2.2.1/power/wakeup”

But it seems this is overly aggressive as it only allows the laptop’s power button to wake up from suspend not the keyboard. Anyone can help?

Thanks!

Hardware/software:

Which Linux distro are you using?

Ubuntu

Which release version?

22.04

Which kernel are you using?

6.8.0-40-generic x86_64

Which BIOS version are you using?

3.03

Which Framework Laptop 16 model are you using? (AMD Ryzen™ 7040 Series)

Ryzen™ 9 7940HS