diff mbox series

[libdrm] modetest: Try and open device using drmOpenDevice first

Message ID 20230522004513.168431-1-marex@denx.de (mailing list archive)
State New, archived
Headers show
Series [libdrm] modetest: Try and open device using drmOpenDevice first | expand

Commit Message

Marek Vasut May 22, 2023, 12:45 a.m. UTC
This way, it is possible to use modetest -D to specify a card in /dev/dri/cardN
which is esp. useful on systems which have multiple cards, with identical modules
and where it is otherwise impossible to discern the different cards via drmOpen().
One such example is i.MX8M Plus, which has three such cards, one for DSI, one for
LVDS, and one for HDMI.

Signed-off-by: Marek Vasut <marex@denx.de>
---
 tests/util/kms.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/tests/util/kms.c b/tests/util/kms.c
index 34a84180..31087522 100644
--- a/tests/util/kms.c
+++ b/tests/util/kms.c
@@ -38,6 +38,7 @@ 
  */
 
 #include <errno.h>
+#include <fcntl.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -142,6 +143,16 @@  int util_open(const char *device, const char *module)
 	} else {
 		unsigned int i;
 
+		printf("trying to open device '%s'...", device);
+
+		fd = open(device, O_RDWR | O_CLOEXEC);
+		if (fd < 0) {
+			printf("failed\n");
+		} else {
+			printf("done\n");
+			return fd;
+		}
+
 		for (i = 0; i < ARRAY_SIZE(modules); i++) {
 			printf("trying to open device '%s'...", modules[i]);