[PATCH i-g-t v7 15/48] lib/monitor_edids: Add helper to get an EDID by its name

Louis Chauvet
2026-02-23T12:09:05Z

For testing specific EDID, it is useful to be able to retrieve an EDID by
a verbose name.

Reviewed-by: Kory Maincent <kory.maincent@bootlin.com>
Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Louis Chauvet <louis.chauvet@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 6043e7a084b3..34446066346e 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 (strncmp(ALL_EDIDS[i].edid_list[j].name, name, EDID_NAME_MAX_LEN) == 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 e5069868683d..6d9e3fc89592 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.52.0