From: Santhosh Reddy Guddati <santhosh.reddy.guddati@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: mohammed.thasleem@intel.com, bhanuprakash.modem@intel.com,
suraj.kandpal@intel.com,
Santhosh Reddy Guddati <santhosh.reddy.guddati@intel.com>
Subject: [PATCH i-g-t v1 1/2] lib/igt_kms: Move backlight read, write to lib
Date: Tue, 15 Oct 2024 21:53:35 +0530 [thread overview]
Message-ID: <20241015162336.304730-2-santhosh.reddy.guddati@intel.com> (raw)
In-Reply-To: <20241015162336.304730-1-santhosh.reddy.guddati@intel.com>
move backlight_read and backlight_write functions from
kms_pm_backlight to library to re use in other tests.
Signed-off-by: Santhosh Reddy Guddati <santhosh.reddy.guddati@intel.com>
---
lib/igt_kms.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_kms.h | 13 +++++++++++
2 files changed, 73 insertions(+)
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index bb35d4b82..c9c0ca1d3 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -7119,3 +7119,63 @@ void igt_reset_link_params(int drm_fd, igt_output_t *output)
temp = drmModeGetConnector(drm_fd, output->config.connector->connector_id);
drmModeFreeConnector(temp);
}
+
+/**
+ * backlight_read:
+ * @result: Pointer to store the result
+ * @fname: Name of the file to read
+ * @context: Pointer to the context structure
+ */
+int backlight_read(int *result, const char *fname, intel_backlight_context_t *context)
+{
+ int fd;
+ char full[PATH_MAX];
+ char dst[64];
+ int r, e;
+
+ igt_assert(snprintf(full, PATH_MAX, "%s/%s/%s", INTEL_BACKLIGHT_PATH, context->path, fname)
+ < PATH_MAX);
+ fd = open(full, O_RDONLY);
+ if (fd == -1)
+ return -errno;
+
+ r = read(fd, dst, sizeof(dst));
+ e = errno;
+ close(fd);
+
+ if (r < 0)
+ return -e;
+
+ errno = 0;
+ *result = strtol(dst, NULL, 10);
+ return errno;
+}
+
+/**
+ * backlight_write:
+ * @value: Value to write
+ * @fname: Name of the file to write
+ * @context: Pointer to the context structure
+ */
+int backlight_write(int value, const char *fname, intel_backlight_context_t *context)
+{
+ int fd;
+ char full[PATH_MAX];
+ char src[64];
+ int len;
+
+ igt_assert(snprintf(full, PATH_MAX, "%s/%s/%s", INTEL_BACKLIGHT_PATH, context->path, fname)
+ < PATH_MAX);
+ fd = open(full, O_WRONLY);
+ if (fd == -1)
+ return -errno;
+
+ len = snprintf(src, sizeof(src), "%i", value);
+ len = write(fd, src, len);
+ close(fd);
+
+ if (len < 0)
+ return len;
+
+ return 0;
+}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 2b26d2bbf..90b911e4d 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -33,6 +33,7 @@
#include <stdint.h>
#include <stddef.h>
#include <assert.h>
+#include <limits.h>
#include <xf86drmMode.h>
@@ -513,6 +514,16 @@ typedef struct {
uint16_t tile_h_size, tile_v_size;
} igt_tile_info_t;
+#define INTEL_BACKLIGHT_PATH "/sys/class/backlight"
+
+/* Backlight context*/
+typedef struct {
+ int max;
+ int old;
+ igt_output_t *output;
+ char path[PATH_MAX];
+} intel_backlight_context_t;
+
void igt_display_reset_outputs(igt_display_t *display);
void igt_display_require(igt_display_t *display, int drm_fd);
void igt_display_fini(igt_display_t *display);
@@ -1253,5 +1264,7 @@ bool igt_has_force_link_training_failure_debugfs(int drmfd, igt_output_t *output
int igt_get_dp_pending_lt_failures(int drm_fd, igt_output_t *output);
int igt_get_dp_pending_retrain(int drm_fd, igt_output_t *output);
void igt_reset_link_params(int drm_fd, igt_output_t *output);
+int backlight_read(int *result, const char *fname, intel_backlight_context_t *context);
+int backlight_write(int value, const char *fname, intel_backlight_context_t *context);
#endif /* __IGT_KMS_H__ */
--
2.34.1
next prev parent reply other threads:[~2024-10-15 16:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 16:23 [PATCH i-g-t v1 0/2] Move backlight read, write to lib Santhosh Reddy Guddati
2024-10-15 16:23 ` Santhosh Reddy Guddati [this message]
2024-10-16 4:29 ` [PATCH i-g-t v1 1/2] lib/igt_kms: " Kandpal, Suraj
2024-10-17 17:13 ` Reddy Guddati, Santhosh
2024-10-16 4:31 ` Kandpal, Suraj
2024-10-15 16:23 ` [PATCH i-g-t v1 2/2] tests/intel/kms_pm_backlight: Refactor and use functions from lib Santhosh Reddy Guddati
2024-10-15 21:33 ` ✓ CI.xeBAT: success for Move backlight read, write to lib Patchwork
2024-10-15 21:47 ` ✗ Fi.CI.BAT: failure " Patchwork
2024-10-16 4:30 ` [PATCH i-g-t v1 0/2] " Kandpal, Suraj
2024-10-16 9:30 ` ✗ CI.xeFULL: failure for " Patchwork
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=20241015162336.304730-2-santhosh.reddy.guddati@intel.com \
--to=santhosh.reddy.guddati@intel.com \
--cc=bhanuprakash.modem@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=mohammed.thasleem@intel.com \
--cc=suraj.kandpal@intel.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