[PATCH i-g-t v3 1/3] lib/igt_kms: Move backlight read and write to lib

Kandpal, Suraj suraj.kandpal at intel.com
Thu Oct 24 04:01:35 UTC 2024



> -----Original Message-----
> From: Reddy Guddati, Santhosh <santhosh.reddy.guddati at intel.com>
> Sent: Tuesday, October 22, 2024 5:41 PM
> To: igt-dev at lists.freedesktop.org
> Cc: Thasleem, Mohammed <mohammed.thasleem at intel.com>; Modem,
> Bhanuprakash <bhanuprakash.modem at intel.com>; Kandpal, Suraj
> <suraj.kandpal at intel.com>; Samala, Pranay <pranay.samala at intel.com>;
> Reddy Guddati, Santhosh <santhosh.reddy.guddati at intel.com>
> Subject: [PATCH i-g-t v3 1/3] lib/igt_kms: Move backlight read and write to lib
> 
> move backlight_read and backlight_write functions from kms_pm_backlight
> to library to reuse in other tests.
> 
> move and rename struct context to intel_backlight_context_t.
> 

Remove the extra space here otherwise 
LGTM,
Reviewed-by: Suraj Kandpal <suraj.kandpal at intel.com>

> v2: Rename backlight_read to igt_backlight_read and backlight_write to
> backlight_write (Suraj).
> Add a new member to intel_backlight_context_t to cache vendor specific
> backlight path.
> 
> Signed-off-by: Santhosh Reddy Guddati <santhosh.reddy.guddati at intel.com>
> ---
>  lib/igt_kms.c | 66
> +++++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_kms.h | 12 ++++++++++
>  2 files changed, 78 insertions(+)
> 
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c index bb35d4b82..5d8096a17 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -7119,3 +7119,69 @@ void igt_reset_link_params(int drm_fd,
> igt_output_t *output)
>  	temp = drmModeGetConnector(drm_fd, output->config.connector-
> >connector_id);
>  	drmModeFreeConnector(temp);
>  }
> +
> +/**
> + * igt_backlight_read:
> + * @result:	Pointer to store the result
> + * @fname:	Name of the file to read
> + * @context:	Pointer to the context structure
> + */
> +int igt_backlight_read(int *result, const char *fname,
> +igt_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",
> +			    context->backlight_dir_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;
> +}
> +
> +/**
> + * igt_backlight_write:
> + * @value:		Value to write
> + * @fname:		Name of the file to write
> + * @context:	Pointer to the context structure
> + */
> +int igt_backlight_write(int value, const char *fname,
> +igt_backlight_context_t *context) {
> +	int fd;
> +	char full[PATH_MAX];
> +	char src[64];
> +	int len;
> +
> +	igt_assert(snprintf(full, PATH_MAX, "%s/%s/%s",
> +			    context->backlight_dir_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..bd154d1c1 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,15 @@ typedef struct {
>  	uint16_t tile_h_size, tile_v_size;
>  } igt_tile_info_t;
> 
> +/* Backlight context*/
> +typedef struct {
> +	int max;
> +	int old;
> +	igt_output_t *output;
> +	char path[PATH_MAX];
> +	char backlight_dir_path[PATH_MAX];
> +} igt_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 +1263,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 igt_backlight_read(int *result, const char *fname,
> +igt_backlight_context_t *context); int igt_backlight_write(int value,
> +const char *fname, igt_backlight_context_t *context);
> 
>  #endif /* __IGT_KMS_H__ */
> --
> 2.34.1



More information about the igt-dev mailing list