Un-crank your neck first
Before debugging, put the screen back to normal manually so you can read it:
xrandr -o normal
On Wayland, use GNOME Settings → Displays → Orientation → Landscape, or gsettings set org.gnome.settings-daemon.peripherals.touchscreen orientation-lock false.
Find the sensor's identification strings
The fix needs three pieces of identification so that udev can match the rule to your specific hardware.
The IIO driver name
sudo udevadm info -n /dev/iio:device0
Look at the E: MODALIAS line. You'll see something like acpi:KIOX010A:* — KIOX010A is the Kionix accelerometer ACPI ID in many cheap tablets.
The machine's manufacturer and product name
sudo dmidecode -s system-manufacturer
sudo dmidecode -s system-product-name
Anything unique from these two strings can be used as the match pattern.
Work out the right matrix
The ACCEL_MOUNT_MATRIX is three space-separated rows of three values each, separated by semicolons. Each row is how the sensor's X, Y, Z axes map to the display's X, Y, Z axes. Values are -1, 0, or 1. 0, 1, 0; 1, 0, 0; 0, 0, 1 for example swaps X and Y.
The iio-sensor-proxy source is the authoritative reference for what each matrix maps to, but in practice you figure it out empirically:
- Start with the identity matrix:
1, 0, 0; 0, 1, 0; 0, 0, 1. - If rotating the laptop to portrait produces the wrong orientation, swap X and Y:
0, 1, 0; 1, 0, 0; 0, 0, 1. - If the rotation direction is reversed (180° off), negate the appropriate rows.
It takes two or three iterations. A handy debugging aid is the monitor-sensor tool:
monitor-sensor
It prints the current orientation GNOME is seeing. Watch what it reports as you physically rotate the machine and you'll know which matrix entries are wrong.
Write the hwdb drop-in
sudo nano /etc/udev/hwdb.d/61-sensor-local.hwdb
Paste, adjusting the match strings to your hardware:
sensor:modalias:acpi:KIOX010A*:dmi:*:svnYourVendor*:pnYourProduct*
ACCEL_MOUNT_MATRIX=0, 1, 0; 1, 0, 0; 0, 0, 1
The second line must begin with a single space — that's the continuation-of-match syntax in hwdb. Don't use a tab.
Reload hwdb and the sensor daemon
sudo systemd-hwdb update
sudo udevadm trigger -v -p DEVNAME=/dev/iio:device0
sudo systemctl restart iio-sensor-proxy
Rotate the machine. GNOME should now follow.
If it still isn't right
- Double-check the match patterns. Run
udevadm info -n /dev/iio:device0again and make sure every wildcard in your rule has a corresponding string in the real modalias / dmi output. - Try one of the standard 8 orientations. The matrices used by iio-sensor-proxy are limited to a specific set — the axes are always swapped/negated, never scaled. If your first guess doesn't work, systematically try the other 7.
- Some firmwares lie. A subset of cheap tablets report their accelerometer values with scaling factors that need the matrix to be negated. When empirical iteration doesn't converge, search the upstream iio-sensor-proxy database for any entry that matches your ACPI ID and start from that matrix.
Once you find a working matrix, please consider submitting a PR to the upstream hwdb. Every device added there means one less person has to work this out by themselves.