Skip to content

Instantly share code, notes, and snippets.

@naddeoa
Last active February 14, 2024 22:03
Show Gist options
  • Save naddeoa/16d07928e3d5d60960aa91dc67f0ad32 to your computer and use it in GitHub Desktop.
Save naddeoa/16d07928e3d5d60960aa91dc67f0ad32 to your computer and use it in GitHub Desktop.
I just got an XPS and I ran into the issue where the touch screen stops working after resume. After doing a little digging, I was able to find out that this is fixed in the Linux kernel by a developer named Mika Westerberg. I got in touch with him and he was able to set me off on the right track for developing a proper work around that I could u…
[Unit]
Description=Potentially dangerous fix touchscreen after resume on the XPS 13 9350
After=suspend.target
[Service]
Type=simple
ExecStart=/home/anthony/path/to/xps-touchscreen-workaround.sh
[Install]
WantedBy=suspend.target
#!/bin/bash
# Create a kill switch that will break this script when the installed kernel version breaks. There
# is already a patch for this in the linux kernel. No telling how something like this will interract
# with that. If your new kernel version still doesn't have the fix then update the WORKS_ON_KERNEL value
# with `uname -r` and the script will work again.
#
# Maililng list with patch: https://marc.info/?l=linux-gpio&m=147610677825233&w=2
# Commit on github: https://github.com/torvalds/linux/commit/c538b9436751a0be2e1246b48353bc23156bdbcc
WORKS_ON_KERNEL="4.4.0-47-generic"
if ! [ "$WORKS_ON_KERNEL" = "`uname -r`" ]; then
echo "The kernel is no longer $WORKS_ON_KERNEL. This script has an 'if' that stops it from working when the kernel changes because the actual fix for this issue might be in your new kernel. If it isn't, then modify $0 to allow it to keep running."
exit 1
fi
# On the XPS 13 9350, my pin is 103. Run the netire command without awk to see full output
PIN_NUMBER=`grep CPU_GP_1 /sys/kernel/debug/pinctrl/INT344B\:00/pins | awk '{print $2}'`
# This is the pin ranges. You need it to use the start of the ranges to properly address the right pin
STARTING_PIN=`cat /sys/kernel/debug/pinctrl/INT344B\:00/gpio-ranges | sed -n 's/.*GPIOS.*\[\(.*\) -.*PINS.*/\1/p'`
# This is the pin that we're actually going to request modifying
EFFECTIVE_PIN=$((STARTING_PIN + PIN_NUMBER))
echo "Determined $EFFECTIVE_PIN was the right pin because CPU_GP_1 was $PIN_NUMBER and the gpio range starts at $STARTING_PIN"
# First, we lock it
echo $EFFECTIVE_PIN > /sys/class/gpio/export
# Then, we set it to high (1). The entire issue was caused by it being set to low (0) by mistake during suspend
echo high > "/sys/class/gpio/gpio$EFFECTIVE_PIN/direction"
# Then we release the lock
echo $EFFECTIVE_PIN > /sys/class/gpio/unexport
@ingumsky
Copy link

I'm on Elementary OS (a distro based on Ubuntu 16.04) and XPS 9350 Touchscreen works perfectly for me with 4.4.0-57-generic kernel. You can check it out if it'll work for you as well.

@libsamek
Copy link

libsamek commented Jan 3, 2017

Very nice, works for me on XPS 13 9350 and Ubuntu 16.10 (4.8.0-22-generic).

Thank you very much for providing this fix!

@t-muehlberger
Copy link

@naddeoa How did you find out what GPIO is responsible for enabling the Display? I have a Thinkpad X1 Yoga Gen 3 with the same issue. The touchscreen does not work after resume. It also does not show up in lsusb. Do you think that a similar solution could work for my machine too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment