[PATCH i-g-t v4 2/5] lib/monitor_edids: Add helper to get an EDID by its name
Louis Chauvet
louis.chauvet at bootlin.com
Fri Jan 10 18:05:42 UTC 2025
For testing specific EDID, it is useful to be able to retrieve an EDID by
a verbose name.
Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
---
lib/monitor_edids/monitor_edids_helper.c | 30 ++++++++++++++++++++++++++++++
lib/monitor_edids/monitor_edids_helper.h | 1 +
2 files changed, 31 insertions(+)
diff --git a/lib/monitor_edids/monitor_edids_helper.c b/lib/monitor_edids/monitor_edids_helper.c
index 6043e7a084b320263f1c0525369aaa59a5d32bcc..01feb34a5516916b615a741f773316159c38fccf 100644
--- a/lib/monitor_edids/monitor_edids_helper.c
+++ b/lib/monitor_edids/monitor_edids_helper.c
@@ -20,6 +20,16 @@
#include "drmtest.h"
#include "hdmi_edids.h"
+struct {
+ struct monitor_edid *edid_list;
+ int list_size;
+} ALL_EDIDS[] = {
+ {DP_EDIDS_NON_4K, DP_EDIDS_NON_4K_COUNT},
+ {DP_EDIDS_4K, DP_EDIDS_4K_COUNT},
+ {HDMI_EDIDS_NON_4K, HDMI_EDIDS_NON_4K_COUNT},
+ {HDMI_EDIDS_4K, HDMI_EDIDS_4K_COUNT},
+};
+
static uint8_t convert_hex_char_to_byte(char c)
{
if (c >= '0' && c <= '9')
@@ -170,3 +180,23 @@ struct monitor_edid *get_edids_for_connector_type(uint32_t type, size_t *count,
}
}
}
+
+/**
+ * get_edid_by_name:
+ * @name: Name to search in available EDIDs
+ *
+ * Return the struct edid associated with a specific name. As with edid_from_monitor_edid, the
+ * caller must ensure to free the EDID after use. If no EDID with the exact name is found, returns
+ * NULL.
+ */
+struct edid *get_edid_by_name(const char *name)
+{
+ for (int i = 0; i < ARRAY_SIZE(ALL_EDIDS); i++) {
+ for (int j = 0; j < ALL_EDIDS[i].list_size; j++) {
+ if (strcmp(ALL_EDIDS[i].edid_list[j].name, name) == 0)
+ return edid_from_monitor_edid(&ALL_EDIDS[i].edid_list[j]);
+ }
+ }
+
+ return NULL;
+}
diff --git a/lib/monitor_edids/monitor_edids_helper.h b/lib/monitor_edids/monitor_edids_helper.h
index e5069868683d97053d8e66666e83692f1b733db3..6d9e3fc89592229cac5122c9275fcf226465ab3e 100644
--- a/lib/monitor_edids/monitor_edids_helper.h
+++ b/lib/monitor_edids/monitor_edids_helper.h
@@ -34,5 +34,6 @@ void free_chamelium_edid_from_monitor_edid(struct chamelium_edid *edid);
struct edid *edid_from_monitor_edid(const monitor_edid *monitor_edid);
struct monitor_edid *get_edids_for_connector_type(uint32_t type, size_t *count, bool four_k);
+struct edid *get_edid_by_name(const char *name);
#endif /* TESTS_CHAMELIUM_MONITOR_EDIDS_MONITOR_EDIDS_HELPER_H_ */
--
2.47.1
More information about the igt-dev
mailing list