diff --git a/aports/device/device-asus-tf101/APKBUILD b/aports/device/device-asus-tf101/APKBUILD
index 06c0d36c7ad058b9c06c8b4a3165522519d8c908..d1a230c1663f71b1660f195b39f2ba4eee1ac572 100644
--- a/aports/device/device-asus-tf101/APKBUILD
+++ b/aports/device/device-asus-tf101/APKBUILD
@@ -2,7 +2,7 @@
 pkgname="device-asus-tf101"
 pkgdesc="Asus Eee Pad Transformer"
 pkgver=0.2
-pkgrel=0
+pkgrel=1
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-leeco-s2/APKBUILD b/aports/device/device-leeco-s2/APKBUILD
index d853afd9799b689393f09bc46a73e9ce956e6acf..dae424c1d89abf91c0ef91bff60d8f530c0b32a6 100644
--- a/aports/device/device-leeco-s2/APKBUILD
+++ b/aports/device/device-leeco-s2/APKBUILD
@@ -2,7 +2,7 @@
 pkgname="device-leeco-s2"
 pkgdesc="LeEco Le 2"
 pkgver=0.1
-pkgrel=1
+pkgrel=2
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-lg-h815/APKBUILD b/aports/device/device-lg-h815/APKBUILD
index bc12d2e85b59fbc44368334981862f9664fad572..76ed3e399996fea172a7c0a9b4077037933203d2 100644
--- a/aports/device/device-lg-h815/APKBUILD
+++ b/aports/device/device-lg-h815/APKBUILD
@@ -2,7 +2,7 @@
 pkgname="device-lg-h815"
 pkgdesc="LG G4 (h815)"
 pkgver=0.1
-pkgrel=1
+pkgrel=2
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-motorola-potter/APKBUILD b/aports/device/device-motorola-potter/APKBUILD
index 2231b04b37369cc81bade5ae9e651577872d1020..74cf210041fd69e2e93542cd6a5e279b54095dcc 100644
--- a/aports/device/device-motorola-potter/APKBUILD
+++ b/aports/device/device-motorola-potter/APKBUILD
@@ -2,7 +2,7 @@
 pkgname="device-motorola-potter"
 pkgdesc="Motorola Moto G5 Plus"
 pkgver=0.1
-pkgrel=1
+pkgrel=2
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-motorola-shamu/APKBUILD b/aports/device/device-motorola-shamu/APKBUILD
index 59be6e38955aeba72ee505544ece18fe2f135694..8fb42bc2edcebd27e55b088d35a513b2a3decf2c 100644
--- a/aports/device/device-motorola-shamu/APKBUILD
+++ b/aports/device/device-motorola-shamu/APKBUILD
@@ -2,7 +2,7 @@
 pkgname="device-motorola-shamu"
 pkgdesc="Motorola Google Nexus 6"
 pkgver=0.3
-pkgrel=0
+pkgrel=1
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-samsung-espresso10/APKBUILD b/aports/device/device-samsung-espresso10/APKBUILD
index 24e88c5e9674a4b20f2eb42f53023edd768a4c83..c82941cacaab7eb85f6b202678d0d9b42b08263f 100644
--- a/aports/device/device-samsung-espresso10/APKBUILD
+++ b/aports/device/device-samsung-espresso10/APKBUILD
@@ -2,7 +2,7 @@
 pkgname="device-samsung-espresso10"
 pkgdesc="Samsung Galaxy Tab 2 (10.1 inch)"
 pkgver=0.1
-pkgrel=2
+pkgrel=3
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-samsung-i9070/APKBUILD b/aports/device/device-samsung-i9070/APKBUILD
index fb4eb43df71b839e7096d9747de8bf0a2e1d6e86..93d8c26043c256652823f5e2931140b072cd69b8 100644
--- a/aports/device/device-samsung-i9070/APKBUILD
+++ b/aports/device/device-samsung-i9070/APKBUILD
@@ -1,7 +1,7 @@
 # Reference: <https://postmarketos.org/devicepkg>
 pkgname=device-samsung-i9070
 pkgver=1
-pkgrel=19
+pkgrel=20
 pkgdesc="Samsung Galaxy S Advance"
 url="https://github.com/postmarketOS"
 arch="noarch"
diff --git a/aports/device/device-samsung-i9195/APKBUILD b/aports/device/device-samsung-i9195/APKBUILD
index c30104d1bf70aaa3b16216b4204680cfb45ec1a9..87723cc233efd2470331c9a24a45cd2997dd5fd1 100644
--- a/aports/device/device-samsung-i9195/APKBUILD
+++ b/aports/device/device-samsung-i9195/APKBUILD
@@ -2,7 +2,7 @@
 pkgname="device-samsung-i9195"
 pkgdesc="Samsung Galaxy S4 Mini"
 pkgver=0.2
-pkgrel=0
+pkgrel=1
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-samsung-maguro/APKBUILD b/aports/device/device-samsung-maguro/APKBUILD
index 75f27acee975fc3ffa3ac946eadde74a12e4ba6f..89226d63780719fe2eff832e6cf391cb35fee806 100644
--- a/aports/device/device-samsung-maguro/APKBUILD
+++ b/aports/device/device-samsung-maguro/APKBUILD
@@ -1,7 +1,7 @@
 # Reference: <https://postmarketos.org/devicepkg>
 pkgname=device-samsung-maguro
 pkgver=2
-pkgrel=16
+pkgrel=17
 pkgdesc="Google Galaxy Nexus (GSM)"
 url="https://github.com/postmarketOS"
 arch="noarch"
diff --git a/aports/device/device-samsung-manta/APKBUILD b/aports/device/device-samsung-manta/APKBUILD
index f958d1a13e0cbb1524b059961f52b18af2d1d318..2e275921f0c1ce4aa3111cadf4eaa93b8616a4ed 100644
--- a/aports/device/device-samsung-manta/APKBUILD
+++ b/aports/device/device-samsung-manta/APKBUILD
@@ -2,7 +2,7 @@
 pkgname="device-samsung-manta"
 pkgdesc="Google Nexus 10"
 pkgver=0.1
-pkgrel=0
+pkgrel=1
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-samsung-s6500d/APKBUILD b/aports/device/device-samsung-s6500d/APKBUILD
index 2b1612144000a2a6ad7a035e68d285ba0eb51161..171a1b2036fdf9010d142b84ca0c4effe07dcd2e 100644
--- a/aports/device/device-samsung-s6500d/APKBUILD
+++ b/aports/device/device-samsung-s6500d/APKBUILD
@@ -2,7 +2,7 @@
 pkgname="device-samsung-s6500d"
 pkgdesc="Samsung Galaxy Mini 2"
 pkgver=0.1
-pkgrel=1
+pkgrel=2
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-semc-anzu/APKBUILD b/aports/device/device-semc-anzu/APKBUILD
index ecaaf0883581662fbbb63bf418a19b44205192db..6b5651e53bc8b0253a75596edc7fc40f38c2bf5f 100644
--- a/aports/device/device-semc-anzu/APKBUILD
+++ b/aports/device/device-semc-anzu/APKBUILD
@@ -2,7 +2,7 @@
 pkgname=device-semc-anzu
 pkgdesc="Xperia Arc"
 pkgver=1
-pkgrel=0
+pkgrel=1
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-teclast-x80pro/APKBUILD b/aports/device/device-teclast-x80pro/APKBUILD
index ff036f5a7dbead81564a3a8b1075814668cf992f..1705cccc5e5d28d3c71574250962864bf236d897 100644
--- a/aports/device/device-teclast-x80pro/APKBUILD
+++ b/aports/device/device-teclast-x80pro/APKBUILD
@@ -4,7 +4,7 @@
 pkgname="device-teclast-x80pro"
 pkgdesc="Teclast X80Pro"
 pkgver=1.0
-pkgrel=0
+pkgrel=1
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/device/device-xiaomi-ido/APKBUILD b/aports/device/device-xiaomi-ido/APKBUILD
index 5700c3d2a9f3b76aedd10875923c6793a175c681..e3a72b03a9fed5e61665952b8904d70b28173b4c 100644
--- a/aports/device/device-xiaomi-ido/APKBUILD
+++ b/aports/device/device-xiaomi-ido/APKBUILD
@@ -2,7 +2,7 @@
 pkgname="device-xiaomi-ido"
 pkgdesc="Xiaomi Xiaomi RedMi 3"
 pkgver=0.1
-pkgrel=1
+pkgrel=2
 url="https://postmarketos.org"
 license="MIT"
 arch="noarch"
diff --git a/aports/main/devicepkg-dev/APKBUILD b/aports/main/devicepkg-dev/APKBUILD
index c4983f7557e2f6e44f220a3892f84a9950f82988..650e3efcd6049cf44b443a6dab4107a4440ee395 100644
--- a/aports/main/devicepkg-dev/APKBUILD
+++ b/aports/main/devicepkg-dev/APKBUILD
@@ -1,5 +1,5 @@
 pkgname="devicepkg-dev"
-pkgver=0.1
+pkgver=0.2
 pkgrel=0
 pkgdesc="Provides default device package functions"
 url="https://github.com/postmarketOS"
@@ -16,5 +16,5 @@ package() {
 	install -Dm755 "$srcdir/devicepkg_package.sh" \
 		"$pkgdir/usr/bin/devicepkg_package"
 }
-sha512sums="e6f96f8942fa8124ca7461bcf9c78879e08ef00da4a728735046503cae86548505594e078eb14056af74616b17332474f1473f72127299773e075bfd970af13b  devicepkg_build.sh
+sha512sums="638d50e6388eabf0da6bf0cff2fe9719ad8a808946f0077228db57fa13a26d9eeb39c1f2689c9a6f93ff9b3bcfdcfb7c358b180bba90e5bba8b9a9e78d25ed18  devicepkg_build.sh
 c732792596f56860f6ab9ddd53b9a7a80224400dd20097b20cebe17a6e7330e9178783f09db16132a28a555f83e29ef3643bfe069638b62998912a9a7ffefdc0  devicepkg_package.sh"
diff --git a/aports/main/devicepkg-dev/devicepkg_build.sh b/aports/main/devicepkg-dev/devicepkg_build.sh
index 15cb3508b102e991a25c19049f22d165c0efc162..3b95083e56be8e8156bc263d935351c2229da598 100644
--- a/aports/main/devicepkg-dev/devicepkg_build.sh
+++ b/aports/main/devicepkg-dev/devicepkg_build.sh
@@ -20,6 +20,50 @@ fi
 # shellcheck disable=SC1090,SC1091
 . "$srcdir/deviceinfo"
 
+# Convert an input calibration matrix from pixel coordinates to 0-1 coordinates
+# and echo it for libinput.
+# Parameters:
+# $1: x multiplier for x coordinate
+# $2: y multiplier for x coordinate
+# $3: pixel offset for x coordinate
+# $4: x multiplier for y coordinate
+# $5: y multiplier for y coordinate
+# $6: pixel offset for y coordinate
+echo_libinput_calibration()
+{
+	# Check if we have got the required number of parameters.
+	if [ $# -ne 6 ]; then
+		echo "WARNING: There must be exactly 6 (or 0) values for the touchscreen calibration." >&2
+		echo "WARNING: No calibration matrix for x11/libinput will be generated." >&2
+		return
+	fi
+
+	# Check if we have got a screen width and screen height.
+	# shellcheck disable=SC2154
+	if [ -z "$deviceinfo_screen_width" ] || [ -z "$deviceinfo_screen_height" ]; then
+		echo "WARNING: Screen width and height are required to generate a calibration matrix for x11/libinput." >&2
+		echo "WARNING: No calibration matrix for x11/libinput will be generated." >&2
+		return
+	fi
+
+	# Perform the actual conversion: divide both offsets by width/height.
+	# As the "dc" command from "bc" is incompatible to the one provided by busybox,
+	# this calls busybox explicitly.
+	# shellcheck disable=SC2154
+	x_offset=$(busybox dc "$3" "$deviceinfo_screen_width" / p)
+	# shellcheck disable=SC2154
+	y_offset=$(busybox dc "$6" "$deviceinfo_screen_height" / p)
+	# Check if we have got results from dc. If there was an error, dc should have
+	# printed an error message that hopefully gives the user a hint why it failed.
+	if [ -z "$x_offset" ] || [ -z "$y_offset" ]; then
+		echo "WARNING: Calculating the offsets for the calibration matrix for x11/libinput failed." >&2
+		echo "No calibration matrix for x11/libinput will be generated." >&2
+		return
+	fi
+
+	echo "ENV{LIBINPUT_CALIBRATION_MATRIX}=\"$1 $2 $x_offset $4 $5 $y_offset\", \\"
+}
+
 # shellcheck disable=SC2154
 if [ ! -z "$deviceinfo_dev_touchscreen" ]; then
 	# Create touchscreen udev rule
@@ -28,6 +72,11 @@ if [ ! -z "$deviceinfo_dev_touchscreen" ]; then
 		# shellcheck disable=SC2154
 		if [ ! -z "$deviceinfo_dev_touchscreen_calibration" ]; then
 			echo "ENV{WL_CALIBRATION}=\"$deviceinfo_dev_touchscreen_calibration\", \\"
+
+			# The following intentionally expands the touchscreen calibration into the
+			# 6 values that should be there.
+			# shellcheck disable=SC2086
+			echo_libinput_calibration $deviceinfo_dev_touchscreen_calibration
 		fi
 		echo "ENV{ID_INPUT}=\"1\", ENV{ID_INPUT_TOUCHSCREEN}=\"1\""
 	} > "$srcdir/90-$pkgname.rules"