# Reference: <https://postmarketos.org/devicepkg>
# Maintainer: Asriel Dreemurr <asriel.danctnix@gmail.com>
# Co-Maintainer: Danct12 <danct12@disroot.org>
pkgname=device-xiaomi-santoni
pkgdesc="Xiaomi Redmi 4X"
pkgver=0.8
pkgrel=3
url="https://postmarketos.org"
license="MIT"
arch="aarch64"
options="!check !archcheck"
depends="postmarketos-base linux-xiaomi-santoni mkbootimg msm-fb-refresher"
makedepends="devicepkg-dev"
subpackages="$pkgname-nonfree-firmware:nonfree_firmware"
source="
	ucm/90-device-xiaomi-santoni-audio.rules
	ucm/HiFi
	ucm/msm8920-sku7-snd-card.conf
	deviceinfo
	directfbrc
	fb.modes"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname

	install -Dm644 "$srcdir"/fb.modes "$pkgdir"/etc/fb.modes
	install -Dm644 "$srcdir"/directfbrc "$pkgdir"/etc/directfbrc

	# Disable v4l udev rules (video4linux), because without the camera
	#         firmware blobs this makes udev helper hang (#1033)
	mkdir -p "$pkgdir"/etc/udev/rules.d
	ln -s /dev/null "$pkgdir"/etc/udev/rules.d/60-persistent-v4l.rules

}

nonfree_firmware() {
	pkgdesc="Wi-Fi, ADSP Firmware"
	depends="firmware-xiaomi-santoni wcnss-wlan adsp-audio pulseaudio pulseaudio-alsa alsa-plugins-pulse alsa-utils"
	install="$pkgname-nonfree-firmware.post-install"
	mkdir "$subpkgdir"

	# Install UCM files for santoni
	install -Dm644 -t "$subpkgdir"/usr/share/alsa/ucm2/conf.d/msm8920-sku7-snd-card \
		"$srcdir"/HiFi \
		"$srcdir"/msm8920-sku7-snd-card.conf
	install -Dm644 "$srcdir"/90-device-xiaomi-santoni-audio.rules \
		"$subpkgdir"/etc/udev/rules.d/90-device-xiaomi-santoni-audio.rules
}

sha512sums="
dc4bf7871307e659f220aebc3c9f7d74b861f46e1f3df1be37d724af984e46d91e553dbd36c2bd4482aa17dbe4d76d28dabe214952638f00830907466b110146  90-device-xiaomi-santoni-audio.rules
3452fe367e7b199d610fb3d8e9113b35e04071afc7585080edb6fe584ecc29591d8f3ab53ed4583c1ccea5882aa51050d6e56a5db7ef88f6c9af648ba1ef88af  HiFi
7c702cf159699cea761ce7cb1ca21b79c59ceb3cdf1e410b537c4aa3a5aaa3be171b4c5555a713ac7a0e0f6dc389680cd5368a7783d14025fdc14d5f27fb922b  msm8920-sku7-snd-card.conf
c115cb9ff7664369e0b857502534f7f249f97f00cab5b124b5080d3878e5a338529f14e85f19eb5fb6c35de43b6d0fdfba172729ed45f05c04b8abe53d1c4a33  deviceinfo
3db3ec596e159be926ea2b5b2496c18e9bc7be24a64a232a56c89a0c9ee710aa2efb2b6fa9fc08efa34759e8242e6c629d08a4ce688ec8aa125830717c191515  directfbrc
b634d13cac1f10535a31c142c7391986ab402ae9910d8093989920f4c2dbd63722ee8595f11962bffd9d314e2835a1ead955a91355856f044911ddcf1e428427  fb.modes
"
