From 7fb880aca6978d694b2b8e085bebbfe58f58f1bc Mon Sep 17 00:00:00 2001 From: Alistair Francis Date: Sun, 19 Apr 2026 20:37:42 +1000 Subject: [PATCH] device-google-sargo: Reload I2C drivers on error It's common for the I2C touch driver on the Google Pixel 3a to crash resulting in touch input not working, see [1]. This patch adds a systemd service that can be used to monitor for errors and reload the drivers on error, the original idea came from [2]. The actual script is not systemd specific, so that the script can be ported to openrc if required. 1: https://gitlab.com/sdm670-mainline/linux/-/work_items/6 2: https://gitlab.com/sdm670-mainline/linux/-/work_items/6#note_3104050714 Signed-off-by: Alistair Francis Part-of: --- device/community/device-google-sargo/APKBUILD | 13 +++++++++- .../reload-rmi-touch.service | 10 ++++++++ .../device-google-sargo/reload-rmi-touch.sh | 25 +++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 device/community/device-google-sargo/reload-rmi-touch.service create mode 100644 device/community/device-google-sargo/reload-rmi-touch.sh diff --git a/device/community/device-google-sargo/APKBUILD b/device/community/device-google-sargo/APKBUILD index 85dd78f50..52fe7906d 100644 --- a/device/community/device-google-sargo/APKBUILD +++ b/device/community/device-google-sargo/APKBUILD @@ -3,7 +3,7 @@ maintainer="Richard Acayan " pkgname=device-google-sargo pkgdesc="Google Pixel 3a" pkgver=18 -pkgrel=0 +pkgrel=1 url="https://postmarketos.org" license="MIT" arch="aarch64" @@ -36,10 +36,13 @@ source=" no-hexagonrpcd-on-suspend.sh plasmacamerarc q6voiced.conf + reload-rmi-touch.service + reload-rmi-touch.sh " subpackages=" $pkgname-openrc $pkgname-plasma-camera:plasma_camera + $pkgname-systemd " build() { @@ -59,6 +62,12 @@ package() { # The q6voiced configuration can only be used if the ADSP is brought up # via non-free firmware. install -Dm644 "$srcdir"/q6voiced.conf "$pkgdir"/etc/conf.d/q6voiced + + install -Dm755 "$srcdir"/reload-rmi-touch.sh \ + "$pkgdir"/usr/lib/$pkgname/reload-rmi-touch + + install -Dm644 "$srcdir"/reload-rmi-touch.service \ + -t "$pkgdir"/usr/lib/systemd/system } openrc() { @@ -84,4 +93,6 @@ b6208c254b6e44ac4f6d748a38cc6b05da0db2c90235ada2011b138b82ccc3372687df2f5ad97e88 2972005a9cf6ca57061965075593dddfa8ee479bc6c21cd41851b1a14768cb1cddbd31a17975ae17adc36d40d294ccbc6bf83defbd69fc7b363f638d8564fbbc no-hexagonrpcd-on-suspend.sh 53bec3338d875ecedf2ae981cf9a0f9066e276f09570b3bd06217414461126a76942b70e01c3bb18831fbefeb188621dd5a341ab2604e8fb0c6de8a3025177e2 plasmacamerarc 3a4a9322839d4b3ef9d79668a37840a9f444954759ae3c512e694051d2f9a2573db42ad6c4c1a5c75eeb861232a27ba1a8cef9b503decd54ead25a96e3dd6f98 q6voiced.conf +20b932e853ea65f9e61bee775af8efec4846766f69f04b73cd104b3aa889d5b8570f26dbcf971d3abff75b3c057c9b585687af5846cb2be8d694f9bca35981b2 reload-rmi-touch.service +d04653b5d22a43c6b694608b507d792c03842b77865003cecf291a83bef3762531765227b88275036b24f1307ba5a798f225d68915e4d0773ec36fc6d1650702 reload-rmi-touch.sh " diff --git a/device/community/device-google-sargo/reload-rmi-touch.service b/device/community/device-google-sargo/reload-rmi-touch.service new file mode 100644 index 000000000..de4dce6f8 --- /dev/null +++ b/device/community/device-google-sargo/reload-rmi-touch.service @@ -0,0 +1,10 @@ +[Unit] +Description=Reload RMI touch driver on I2C errors + +[Service] +ExecStart=/usr/lib/device-google-sargo/reload-rmi-touch +Restart=always +RestartSec=5 + +[Install] +WantedBy=default.target diff --git a/device/community/device-google-sargo/reload-rmi-touch.sh b/device/community/device-google-sargo/reload-rmi-touch.sh new file mode 100644 index 000000000..07fb696c7 --- /dev/null +++ b/device/community/device-google-sargo/reload-rmi-touch.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Reload RMI touch driver on I2C errors. + +trap 'exit 0' INT TERM + +last_reload=0 + +while IFS= read -r line; do + case "$line" in + *"geni_i2c a84000.i2c:"*"failed"*) + echo "I2C touch error detected on geni_i2c a84000.i2c" + now=$(date +%s) + # Debounce: only reload if it's been at least 30 seconds since the + # last reload, in case errors come in bursts. + if [ $((now - last_reload)) -ge 30 ]; then + echo "Reloading RMI touch driver" + modprobe -r rmi_i2c + modprobe -r rmi_core + modprobe rmi_core + modprobe rmi_i2c + last_reload=$(date +%s) + fi + ;; + esac +done < /dev/kmsg