From 5972f35f65fd4566cb9e10de2012114b95940467 Mon Sep 17 00:00:00 2001
From: Jianhua Lu <lujianhua000@gmail.com>
Date: Mon, 16 Sep 2024 21:19:55 +0800
Subject: [PATCH] device-xiaomi-elish: add sensors support

---
 .../81-libssc-xiaomi-elish.rules                 |  3 +++
 device/testing/device-xiaomi-elish/APKBUILD      | 16 ++++++++++++++--
 .../device-xiaomi-elish.post-install             |  1 +
 .../device-xiaomi-elish/hexagonrpcd.confd        |  2 ++
 4 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 device/testing/device-xiaomi-elish/81-libssc-xiaomi-elish.rules
 create mode 100644 device/testing/device-xiaomi-elish/hexagonrpcd.confd

diff --git a/device/testing/device-xiaomi-elish/81-libssc-xiaomi-elish.rules b/device/testing/device-xiaomi-elish/81-libssc-xiaomi-elish.rules
new file mode 100644
index 00000000000..9e013792d37
--- /dev/null
+++ b/device/testing/device-xiaomi-elish/81-libssc-xiaomi-elish.rules
@@ -0,0 +1,3 @@
+# iio-sensor-proxy with libssc: accelerometer mount matrix
+SUBSYSTEM=="misc", KERNEL=="fastrpc-*", ENV{ACCEL_MOUNT_MATRIX}+="-1, 0, 0; 0, -1, 0; 0, 0, -1"
+
diff --git a/device/testing/device-xiaomi-elish/APKBUILD b/device/testing/device-xiaomi-elish/APKBUILD
index 59c4854cd8f..8e642f793be 100644
--- a/device/testing/device-xiaomi-elish/APKBUILD
+++ b/device/testing/device-xiaomi-elish/APKBUILD
@@ -2,14 +2,15 @@
 # Maintainer: Jianhua Lu <lujianhua000@gmail.com>
 pkgname=device-xiaomi-elish
 pkgdesc="Xiaomi Mi Pad 5 Pro"
-pkgver=2
-pkgrel=1
+pkgver=3
+pkgrel=0
 url="https://postmarketos.org"
 license="MIT"
 arch="aarch64"
 options="!check !archcheck"
 depends="
 	bootmac
+	hexagonrpcd
 	make-dynpart-mappings
 	mesa-vulkan-freedreno
 	mkbootimg
@@ -18,11 +19,14 @@ depends="
 	swclock-offset
 "
 makedepends="devicepkg-dev"
+replaces="hexagonrpcd-openrc"
 install="$pkgname.post-install $pkgname.post-upgrade"
 source="
+	81-libssc-xiaomi-elish.rules
 	alsa-ucm-conf/elish.conf
 	alsa-ucm-conf/HiFi.conf
 	deviceinfo
+	hexagonrpcd.confd
 	modules-initfs
 "
 
@@ -49,6 +53,11 @@ package() {
 	mkdir -p "$pkgdir/usr/share/alsa/ucm2/conf.d/sm8250"
 	ln -s ../../Xiaomi/elish/elish.conf \
 		"$pkgdir/usr/share/alsa/ucm2/conf.d/sm8250/Xiaomi Mi Pad 5 Pro.conf"
+
+	install -Dm644 "$srcdir"/81-libssc-xiaomi-elish.rules \
+		"$pkgdir"/usr/lib/udev/rules.d/81-libssc-xiaomi-elish.rules
+	install -Dm644 "$srcdir"/hexagonrpcd.confd \
+		"$pkgdir"/etc/conf.d/hexagonrpcd-sdsp
 }
 
 kernel_boe() {
@@ -70,6 +79,7 @@ nonfree_firmware() {
 		firmware-xiaomi-elish-adsp
 		firmware-xiaomi-elish-cdsp
 		firmware-xiaomi-elish-cirrus
+		firmware-xiaomi-elish-hexagonfs
 		firmware-xiaomi-elish-slpi
 		firmware-xiaomi-elish-touchscreen
 		firmware-xiaomi-elish-venus
@@ -80,8 +90,10 @@ nonfree_firmware() {
 }
 
 sha512sums="
+4da3a68ba3370bf09a405df1caee890a732331a805676dc4849f85a27954c3f7675dd164948a61483d48b5adf96ec009340757e53df4a3bf38195c66b2bc6097  81-libssc-xiaomi-elish.rules
 7b5def03dc5da28c7449719f0619f9d9ddbd988235b8591304ae4fea0989189d65ca1bc0d43664115f595137ba7896359b1b5f48fd6e350cac5d41ef9b1df869  elish.conf
 ed9a509f70715fd6c6614ee5fddbdb0ed2aa69f4a2983af9dbec26bdeb18fe93e3d1a65e03c618550c61da1416c79eb9440fb1bcd4961f85059b27904c4395cc  HiFi.conf
 c8130d9a740437608c0ed56263ff5424e12f78ca71dd71c683fdcafe856b980fc14b492e964e177d06dcc4048466da6f29dd6f0dc85d021a0f963fdbf33e26c5  deviceinfo
+7d5a1b8c43b15d1711225f4680a67f365ca6515ddbf8239902c7886a20cf06d7da0f195760108ddeb4b039866e1c415981d413dee15eed4423a256d40a46a516  hexagonrpcd.confd
 08429bea885350e34c4d7f7aec02e440080a78db3ac10d8a757012ffa5dcafe93a12db24e37201d02cd423db9c33cf0bafcd0c03935dfa159a2e89ccafe93f3e  modules-initfs
 "
diff --git a/device/testing/device-xiaomi-elish/device-xiaomi-elish.post-install b/device/testing/device-xiaomi-elish/device-xiaomi-elish.post-install
index 1ce77a59412..867eab4e8b4 100644
--- a/device/testing/device-xiaomi-elish/device-xiaomi-elish.post-install
+++ b/device/testing/device-xiaomi-elish/device-xiaomi-elish.post-install
@@ -1,2 +1,3 @@
 #!/bin/sh
 rc-update add qbootctl default
+rc-update add hexagonrpcd-sdsp default
diff --git a/device/testing/device-xiaomi-elish/hexagonrpcd.confd b/device/testing/device-xiaomi-elish/hexagonrpcd.confd
new file mode 100644
index 00000000000..9411b6f0db2
--- /dev/null
+++ b/device/testing/device-xiaomi-elish/hexagonrpcd.confd
@@ -0,0 +1,2 @@
+# Xiaomi Mi Pad 5 Pro specific hexagonrpcd firmware directory
+hexagonrpcd_fw_dir="/usr/share/qcom/sm8250/xiaomi/elish/"
-- 
GitLab