There is an issue that X280 may wake up while it’s connected to the ThinkPad USB-C hub. Here is the workaround for this issue.
Scripts under /lib/systemd/system-sleep directory will be executed before and after suspend. Thus we can put a script /lib/systemd/system-sleep and manipulate /proc/acpi/wakeup and /sys/bus/usb/devices/*/power/wakeup before suspend.
sudo touch /lib/systemd/system-sleep/prevent-unwanted-wakeup sudo chmod +x /lib/systemd/system-sleep/prevent-unwanted-wakeup
Edit /lib/systemd/system-sleep/prevent-unwanted-wakeup
#!/usr/bin/env ruby
# encoding: utf-8
def disable_acpi_wakeup(only_on_arr = nil)
arr_to_disable = []
File.open("/proc/acpi/wakeup", "rb"){|file|
content = file.read()
content.each_line{|line|
line.chomp!
arr = line.gsub("\t", " ").split(" ")
if arr[2] == "*enabled"
arr_to_disable.push(arr[0])
end
}
}
if only_on_arr != nil
arr_to_disable = arr_to_disable & only_on_arr
end
arr_to_disable.each{|item|
File.open("/proc/acpi/wakeup", "wb"){|file|
file.write(item)
}
}
end
def disable_usb_wakeup(node = "*")
arr_to_disable = []
Dir.glob("/sys/bus/usb/devices/#{node}/power/wakeup"){|path|
File.open(path, "rb"){|file|
content = file.read()
content.chomp!
if content == "enabled"
arr_to_disable.push(path)
end
}
}
arr_to_disable.each{|item|
File.open(item, "wb"){|file|
file.write("disabled")
}
}
end
if ARGV[0] == "pre" && ARGV[1] == "suspend"
# disable_acpi_wakeup() # Disable all wakeup type in /proc/acpi/wakeup
disable_acpi_wakeup(["XHC"]) # Disable USB wakeup
# disable_usb_wakeup("1-7") # Disable wakeup from Bluetooth (a USB device)
elsif ARGV[0] == "post" && ARGV[1] == "suspend"
end
Ubuntu will run
-
/lib/systemd/system-sleep/prevent-unwanted-wakeup pre suspendbefore entering suspend mode -
/lib/systemd/system-sleep/prevent-unwanted-wakeup post suspendafter wakeup