[igt-dev] [PATCH i-g-t v1 1/3] lib/igt_kms: Add helper to parse mode string

Rohith Iyer quic_rohiiyer at quicinc.com
Wed Jul 13 22:22:33 UTC 2022


Add helper method to parse a mode string from command line, and verify
correct number of arguments. This standardizes parsing mode strings.

Signed-off-by: Rohith Iyer <quic_rohiiyer at quicinc.com>
---
 lib/igt_kms.c | 26 ++++++++++++++++++++++++++
 lib/igt_kms.h |  1 +
 2 files changed, 27 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index d8867f09..6df6658a 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -5739,3 +5739,29 @@ bool igt_check_bigjoiner_support(igt_display_t *display)
 
 	return true;
 }
+
+/**
+ * igt_parse_mode_string:
+ * @mode_string: a pointer to the optarg
+ * @mode: a pointer to a drm mode structure
+ *
+ * Parse mode string from command line and populate mode
+ *
+ * Format: <clock(MHz)>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,<vdisp>,<vsync-start>,
+ * <vsync-end>,<vtotal>
+ *
+ * Returns: true if the correct number of arguments are entered, else false.
+ */
+bool igt_parse_mode_string(char *mode_string, drmModeModeInfo *mode)
+{
+	float force_clock;
+
+	if (sscanf(mode_string, "%f,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu",
+	   &force_clock, &mode->hdisplay, &mode->hsync_start, &mode->hsync_end, &mode->htotal,
+	   &mode->vdisplay, &mode->vsync_start, &mode->vsync_end, &mode->vtotal) != 9)
+		return false;
+
+	mode->clock = force_clock * 1000;
+
+	return true;
+}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 4b67708d..8d946a25 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -972,5 +972,6 @@ void igt_sort_connector_modes(drmModeConnector *connector,
 		int (*comparator)(const void *, const void*));
 
 bool igt_check_bigjoiner_support(igt_display_t *display);
+bool igt_parse_mode_string(char *mode_string, drmModeModeInfo *mode);
 
 #endif /* __IGT_KMS_H__ */
-- 
2.31.0



More information about the igt-dev mailing list