<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div dir="auto"><strong style="font-size: 11pt;">From:</strong><span style="font-size: 11pt;"> Reddy Guddati, Santhosh <santhosh.reddy.guddati@intel.com></span><br>
</div>
<div id="mail-editor-reference-message-container" dir="auto">
<div id="divRplyFwdMsg" style="font-size: 11pt;" dir="auto"><strong>Sent:</strong> Wednesday, October 2, 2024 8:26:33 pm<br>
<strong>To:</strong> igt-dev@lists.freedesktop.org <igt-dev@lists.freedesktop.org><br>
<strong>Cc:</strong> Samala, Pranay <pranay.samala@intel.com>; Kandpal, Suraj <suraj.kandpal@intel.com>; Reddy Guddati, Santhosh <santhosh.reddy.guddati@intel.com><br>
<strong>Subject:</strong> [PATCH i-g-t v3 1/1] tests/kms_hdr: Test brightness manipulation in HDR mode<br>
</div>
<br>
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><font size="2"><span style="font-size:11pt;">
<div class="PlainText" dir="auto">Add subtest for backlight control on hdr enabled edp panels<br>
by changing brightness via sysfs.<br>
<br>
v2: adjust brightness range, refactor and restore brightness (Pranay)<br>
<br>
v3: reuse functions, add flags to avoid duplicate code (Suraj)<br>
<br>
Signed-off-by: Santhosh Reddy Guddati <santhosh.reddy.guddati@intel.com><br>
---<br>
 tests/kms_hdr.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++-<br>
 1 file changed, 82 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/tests/kms_hdr.c b/tests/kms_hdr.c<br>
index f123c6b36..0f07e770b 100644<br>
--- a/tests/kms_hdr.c<br>
+++ b/tests/kms_hdr.c<br>
@@ -64,6 +64,10 @@<br>
  * Description: Tests static toggle with suspend<br>
  * Functionality: colorspace, static_hdr, suspend<br>
  *<br>
+ * SUBTEST: brightness-with-hdr<br>
+ * Description: Tests brightness with HDR<br>
+ * Functionality: colorspace, static_hdr<br>
+ *<br>
  * SUBTEST: static-%s<br>
  * Description: Tests %arg[1].<br>
  * Functionality: colorspace, static_hdr<br>
@@ -81,6 +85,8 @@ IGT_TEST_DESCRIPTION("Test HDR metadata interfaces and bpc switch");<br>
 #define HDR_STATIC_METADATA_BLOCK       0x06<br>
 #define USE_EXTENDED_TAG                0x07<br>
 <br>
+#define INTEL_BACKLIGHT_PATH "/sys/class/backlight/intel_backlight"<br>
+<br>
 /* DRM HDR definitions. Not in the UAPI header, unfortunately. */<br>
 enum hdmi_metadata_type {<br>
         HDMI_STATIC_METADATA_TYPE1 = 0,<br>
@@ -100,6 +106,7 @@ enum {<br>
         TEST_SWAP = 1 << 3,<br>
         TEST_INVALID_METADATA_SIZES = 1 << 4,<br>
         TEST_INVALID_HDR = 1 << 5,<br>
+       TEST_BRIGHTNESS = 1 << 6,<br>
 };<br>
 <br>
 /* BPC connector state. */<br>
@@ -448,6 +455,72 @@ static void fill_hdr_output_metadata_st2048(struct hdr_output_metadata *meta)<br>
         meta->hdmi_metadata_type1.max_cll = 500;   /* 500 nits */<br>
 }<br>
 <br>
+/* TODO: Move adjust_brightness to lib/igt_sysfs to reuse in other tests. */<br>
+static void adjust_brightness(data_t *data, uint32_t flags)</div>
<div class="PlainText" dir="auto"><br>
</div>
<div class="PlainText" dir="auto">-----------------</div>
<div class="PlainText" dir="auto"> Do we not have a function in kms_brightness to manipulate brightness let's reuse that rather than writing the whole function here</div>
<div class="PlainText" dir="auto"><br>
</div>
<div class="PlainText" dir="auto">Regards,</div>
<div class="PlainText" dir="auto">Suraj Kandpal</div>
<div class="PlainText" dir="auto"><br>
</div>
<div class="PlainText" dir="auto">----------------------<br>
+{<br>
+       char brightness_path[1024];<br>
+       int brightness_fd;<br>
+       char brightness_value[64];<br>
+       int current_brightness;<br>
+       int max_brightness;<br>
+       int read_brightness;<br>
+       int fd, i;<br>
+<br>
+       /* Get max brightness */<br>
+       snprintf(brightness_path, sizeof(brightness_path),<br>
+                "%s/%s", INTEL_BACKLIGHT_PATH, "max_brightness");<br>
+       fd = open(brightness_path, O_RDONLY);<br>
+       igt_assert_f(fd >= 0, "Failed to open %s\n", brightness_path);<br>
+<br>
+       igt_assert(read(fd, brightness_value, sizeof(brightness_value)) > 0);<br>
+<br>
+       max_brightness = atoi(brightness_value);<br>
+<br>
+       close(fd);<br>
+<br>
+       /* Get current brightness */<br>
+       snprintf(brightness_path, sizeof(brightness_path),<br>
+                "%s/%s", INTEL_BACKLIGHT_PATH, "brightness");<br>
+       fd = open(brightness_path, O_RDONLY);<br>
+       igt_assert_f(fd >= 0, "Failed to open %s\n", brightness_path);<br>
+<br>
+       igt_assert(read(fd, brightness_value, sizeof(brightness_value)) > 0);<br>
+<br>
+       current_brightness = atoi(brightness_value);<br>
+<br>
+       close(fd);<br>
+<br>
+       for (i = 0; i <= max_brightness; i += 50) {<br>
+               fd = open(brightness_path, O_WRONLY);<br>
+               igt_assert_f(fd >= 0, "Failed to open %s\n", brightness_path);<br>
+<br>
+               snprintf(brightness_value, sizeof(brightness_value), "%d", i);<br>
+               igt_assert(write(fd, brightness_value, strlen(brightness_value)) > 0);<br>
+<br>
+               close(fd);<br>
+<br>
+               /* Verify brightness adjustment */<br>
+               fd = open(brightness_path, O_RDONLY);<br>
+               igt_assert(fd >= 0);<br>
+<br>
+               igt_assert(read(fd, brightness_value, sizeof(brightness_value)) > 0);<br>
+<br>
+               read_brightness = atoi(brightness_value);<br>
+<br>
+               igt_assert_eq(read_brightness, i);<br>
+<br>
+               close(fd);<br>
+       }<br>
+<br>
+       fd = open(brightness_path, O_WRONLY);<br>
+       igt_assert_f(fd >= 0, "Failed to open %s\n", brightness_path);<br>
+<br>
+       snprintf(brightness_value, sizeof(brightness_value), "%d", current_brightness);<br>
+       igt_assert(write(brightness_fd, brightness_value, strlen(brightness_value)) > 0);<br>
+<br>
+       close(fd);<br>
+}<br>
+<br>
 static void test_static_toggle(data_t *data, enum pipe pipe,<br>
                                igt_output_t *output,<br>
                                uint32_t flags)<br>
@@ -483,6 +556,9 @@ static void test_static_toggle(data_t *data, enum pipe pipe,<br>
                 igt_assert_eq(system("dmesg|tail -n 1000|grep -E \"Unknown EOTF [0-9]+\""), 0);<br>
                 goto cleanup;<br>
         }<br>
+       if (flags & TEST_BRIGHTNESS)<br>
+               adjust_brightness(data, flags);<br>
+<br>
         igt_assert_output_bpc_equal(data->fd, pipe, output->name, 10);<br>
 <br>
         /* Verify that the CRC are equal after DPMS or suspend. */<br>
@@ -685,7 +761,8 @@ static void test_hdr(data_t *data, uint32_t flags)<br>
 <br>
                         igt_dynamic_f("pipe-%s-%s",<br>
                                       kmstest_pipe_name(pipe), output->name) {<br>
-                               if (flags & (TEST_NONE | TEST_DPMS | TEST_SUSPEND | TEST_INVALID_HDR))<br>
+                               if (flags & (TEST_NONE | TEST_DPMS | TEST_SUSPEND |<br>
+                                            TEST_INVALID_HDR | TEST_BRIGHTNESS))<br>
                                         test_static_toggle(data, pipe, output, flags);<br>
                                 if (flags & TEST_SWAP)<br>
                                         test_static_swap(data, pipe, output);<br>
@@ -734,6 +811,10 @@ igt_main<br>
         igt_subtest_with_dynamic("static-toggle-suspend")<br>
                 test_hdr(&data, TEST_SUSPEND);<br>
 <br>
+       igt_describe("Tests brightness while entering and exiting HDR mode");<br>
+       igt_subtest_with_dynamic("brightness-with-hdr")<br>
+               test_hdr(&data, TEST_BRIGHTNESS);<br>
+<br>
         igt_describe("Tests swapping static HDR metadata");<br>
         igt_subtest_with_dynamic("static-swap")<br>
                 test_hdr(&data, TEST_SWAP);<br>
-- <br>
2.34.1<br>
<br>
</div>
</span></font><br>
</div>
</body>
</html>