pkgname=firmware-xiaomi-surya
pkgver=1
pkgrel=0
pkgdesc="Firmware for Xiaomi POCO X3 NFC"
subpackages="
	$pkgname-adsp
	$pkgname-cdsp
	$pkgname-ipa
	$pkgname-modem
	$pkgname-touchscreen
	$pkgname-wlan
	"
url="https://github.com/sm7150-mainline/firmware-xiaomi-surya"
arch="aarch64"
license="proprietary"
options="!check !strip !archcheck !tracedeps pmb:cross-native"
_commit="47ee12fa953d87d10f61f67b51addd8e26d17899"
source="$pkgname-$_commit.tar.gz::$url/archive/$_commit/$pkgname-$_commit.tar.gz"
builddir="$srcdir/$pkgname-$_commit"

package() {
	# parent package is empty
	mkdir -p "$pkgdir"
}

adsp() {
	pkgdesc="Xiaomi POCO X3 NFC adsp firmware"

	install -Dm644 "$builddir"/adsp* -t \
		"$subpkgdir/lib/firmware/qcom/sm7150/surya"
}

cdsp() {
	pkgdesc="Xiaomi POCO X3 NFC cdsp firmware"

	install -Dm644 "$builddir"/cdsp* -t \
		"$subpkgdir/lib/firmware/qcom/sm7150/surya"
}

ipa() {
	pkgdesc="Xiaomi POCO X3 NFC ipa firmware"

	install -Dm644 "$builddir"/ipa_fws.* -t \
		"$subpkgdir/lib/firmware/qcom/sm7150/surya"
}

modem() {
	pkgdesc="Xiaomi POCO X3 NFC modem firmware"

	# cp because of the modem_pr directory
	mkdir -p "$subpkgdir/lib/firmware/qcom/sm7150/surya"
	cp -r "$builddir"/modem* \
		"$subpkgdir/lib/firmware/qcom/sm7150/surya"
	find "$subpkgdir/lib/firmware/qcom/sm7150/surya" \
		-type f -exec chmod 0644 {} \;
}

touchscreen() {
	pkgdesc="Xiaomi POCO X3 NFC touchscreen firmware"

	install -Dm644 "$builddir"/novatek_ts_huaxing_fw.bin -t \
		"$subpkgdir/lib/firmware"
}

wlan() {
	pkgdesc="Xiaomi POCO X3 NFC wlan firmware"

	install -Dm644 "$builddir"/wlanmdsp.mbn -t \
		"$subpkgdir/lib/firmware/qcom/sm7150/surya"
}

sha512sums="
cb540920f977a519e696009c62dbc70c12587d0523c57b5e0fa44432e391dadbc8b08d269ef4ab06f420a892dc98fd42900b8745b683824b91b86b4b483526b0  firmware-xiaomi-surya-47ee12fa953d87d10f61f67b51addd8e26d17899.tar.gz
"
