Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Louis Chauvet <louis.chauvet@bootlin.com>
To: igt-dev@lists.freedesktop.org, ihf@google.com,
	markyacoub@google.com,  thomas.petazzoni@bootlin.com,
	Louis Chauvet <louis.chauvet@bootlin.com>
Subject: [PATCH i-g-t RFC 08/13] lib/monitor_edids: Introduce helpers to get EDID from a monitor EDID
Date: Wed, 05 Jun 2024 16:30:20 +0200	[thread overview]
Message-ID: <20240605-dev-remove-static-ports-v1-8-665f25b7a4db@bootlin.com> (raw)
In-Reply-To: <20240605-dev-remove-static-ports-v1-0-665f25b7a4db@bootlin.com>

Add two helpers around monitor_edid list: extracting an edid and edid list
for a specific connector type

Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
 lib/monitor_edids/monitor_edids_helper.c | 61 +++++++++++++++++++++++++++++++-
 lib/monitor_edids/monitor_edids_helper.h |  3 ++
 2 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/lib/monitor_edids/monitor_edids_helper.c b/lib/monitor_edids/monitor_edids_helper.c
index 1cbf1c22f0bb..cbd6d6fd54db 100644
--- a/lib/monitor_edids/monitor_edids_helper.c
+++ b/lib/monitor_edids/monitor_edids_helper.c
@@ -14,7 +14,10 @@
 #include <string.h>
 #include <assert.h>
 
-#include "igt_core.h"
+#include "igt.h"
+#include "igt_edid.h"
+#include "dp_edids.h"
+#include "hdmi_edids.h"
 
 static uint8_t convert_hex_char_to_byte(char c)
 {
@@ -90,3 +93,59 @@ void free_chamelium_edid_from_monitor_edid(struct chamelium_edid *edid)
 	free(edid);
 	edid = NULL;
 }
+
+struct edid *edid_from_monitor_edid(const monitor_edid *monitor_edid)
+{
+	uint8_t *raw_edid;
+	size_t edid_size;
+	int i;
+
+	edid_size = strlen(monitor_edid->edid) / 2; /* each ascii is a nibble. */
+	raw_edid = malloc(edid_size);
+	igt_assert(raw_edid);
+
+	for (i = 0; i < edid_size; i++) {
+		raw_edid[i] = convert_hex_char_to_byte(monitor_edid->edid[i * 2]) << 4 |
+			      convert_hex_char_to_byte(monitor_edid->edid[i * 2 + 1]);
+	}
+
+	if (edid_get_size((struct edid *)raw_edid) > edid_size) {
+		uint8_t *new_edid;
+
+		igt_warn("The edid size stored in the raw edid is shorter than the edid stored in the table.");
+		new_edid = realloc(raw_edid, edid_get_size((struct edid *)raw_edid));
+		igt_assert(new_edid);
+		raw_edid = new_edid;
+	}
+
+	return (struct edid *)raw_edid;
+}
+
+struct monitor_edid *get_edids_for_connector_type(uint32_t type, size_t *count, bool four_k)
+{
+	if (four_k) {
+		switch (type) {
+		case DRM_MODE_CONNECTOR_DisplayPort:
+			*count = ARRAY_SIZE(DP_EDIDS_4K);
+			return DP_EDIDS_4K;
+		case DRM_MODE_CONNECTOR_HDMIA:
+			*count = ARRAY_SIZE(HDMI_EDIDS_4K);
+			return HDMI_EDIDS_4K;
+		default:
+			igt_assert_f(0, "No 4k EDID for the connector %s\n",
+				     kmstest_connector_type_str(type));
+		}
+	} else {
+		switch (type) {
+		case DRM_MODE_CONNECTOR_DisplayPort:
+			*count = ARRAY_SIZE(DP_EDIDS_NON_4K);
+			return DP_EDIDS_NON_4K;
+		case DRM_MODE_CONNECTOR_HDMIA:
+			*count = ARRAY_SIZE(HDMI_EDIDS_NON_4K);
+			return HDMI_EDIDS_NON_4K;
+		default:
+			igt_assert_f(0, "No EDID for the connector %s\n",
+				     kmstest_connector_type_str(type));
+		}
+	}
+}
diff --git a/lib/monitor_edids/monitor_edids_helper.h b/lib/monitor_edids/monitor_edids_helper.h
index 63a183409293..ff5672058816 100644
--- a/lib/monitor_edids/monitor_edids_helper.h
+++ b/lib/monitor_edids/monitor_edids_helper.h
@@ -30,4 +30,7 @@ get_chameleon_edid_from_monitor_edid(struct chamelium *chamelium,
 				     const monitor_edid *edid);
 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_edid_for_connector_type(uint32_t type, size_t *count, bool four_k);
+
 #endif /* TESTS_CHAMELIUM_MONITOR_EDIDS_MONITOR_EDIDS_HELPER_H_ */
\ No newline at end of file

-- 
2.43.2


  parent reply	other threads:[~2024-06-05 14:30 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-05 14:30 [PATCH i-g-t RFC 00/13] tests/chamelium: Integrate the chamelium v3 Louis Chauvet
2024-06-05 14:30 ` [PATCH i-g-t RFC 01/13] tests/chamelium: Extract chamelium v2 tests into its own directory Louis Chauvet
2024-06-05 14:30 ` [PATCH i-g-t RFC 02/13] lib/chamelium: Extract chamelium v2 wrapper " Louis Chauvet
2024-06-05 14:30 ` [PATCH i-g-t RFC 03/13] lib/chamelium: Change build options to split chamelium v2 and v3 Louis Chauvet
2024-06-05 14:30 ` [PATCH i-g-t RFC 04/13] lib/chamelium: Introduce the foundation for the chamelium v3 library Louis Chauvet
2024-06-11 16:45   ` Kamil Konieczny
2024-06-05 14:30 ` [PATCH i-g-t RFC 05/13] lib/chamelium: Implement all RPC calls for the chamelium v3 Louis Chauvet
2024-06-05 14:30 ` [PATCH i-g-t RFC 06/13] lib/chamelium: Introduce a simple chamelium v3 test Louis Chauvet
2024-06-05 14:30 ` [PATCH i-g-t RFC 07/13] tests/chamelium: Introduce basic edid test Louis Chauvet
2024-06-05 14:30 ` Louis Chauvet [this message]
2024-06-05 14:30 ` [PATCH i-g-t RFC 09/13] tests/chamelium: Introduce 4k stress edid Louis Chauvet
2024-06-05 14:30 ` [PATCH i-g-t RFC 10/13] tests/chamelium: Introduce non-4k " Louis Chauvet
2024-06-05 14:30 ` [PATCH i-g-t RFC 11/13] tests/chamelium: Introduce test resolution Louis Chauvet
2024-06-05 14:30 ` [PATCH i-g-t RFC 12/13] tests/chamelium: Introduce test sleep Louis Chauvet
2024-06-05 14:30 ` [PATCH i-g-t RFC 13/13] tests/chamelium: Add MST test Louis Chauvet
2024-06-05 16:36 ` ✗ Fi.CI.BUILD: failure for tests/chamelium: Integrate the chamelium v3 Patchwork
2024-06-07 19:05 ` ✗ GitLab.Pipeline: warning " Patchwork
2024-06-11 16:51 ` [PATCH i-g-t RFC 00/13] " Kamil Konieczny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240605-dev-remove-static-ports-v1-8-665f25b7a4db@bootlin.com \
    --to=louis.chauvet@bootlin.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=ihf@google.com \
    --cc=markyacoub@google.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox