[igt-dev] [PATCH i-g-t v5 1/3] lib/igt_kms: Add helper to parse mode string

Abhinav Kumar quic_abhinavk at quicinc.com
Thu Aug 4 19:15:50 UTC 2022



On 7/29/2022 5:35 PM, Rohith Iyer wrote:
> Add helper method to parse a mode string and verify
> correct number of arguments. This standardizes parsing mode strings.
> 
> Changes made in V4:
>   - Corrected documentation
>   - Changed *mode_string to a const char from char
> 
> Changes made in V5:
>   - Removed angle brackets in documentation which cause parse error in
>     builddoc
> 
> Signed-off-by: Rohith Iyer <quic_rohiiyer at quicinc.com>

Since petri's previous comments have been addressed and make builddoc 
works with these changes and CI is happy, this LGTM now,

Reviewed-by: Abhinav Kumar <quic_abhinavk at quicinc.com>
> ---
>   lib/igt_kms.c | 26 ++++++++++++++++++++++++++
>   lib/igt_kms.h |  1 +
>   2 files changed, 27 insertions(+)
> 
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index 14064614..1ba3bd2a 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -5777,3 +5777,29 @@ bool igt_check_bigjoiner_support(igt_display_t *display)
>   
>   	return true;
>   }
> +
> +/**
> + * igt_parse_mode_string:
> + * @mode_string: modeline string
> + * @mode: a pointer to a drm mode structure
> + *
> + * Parse mode string and populate mode
> + *
> + * Format: clock(MHz),hdisp,hsync-start,hsync-end,htotal,vdisp,vsync-start,
> + * vsync-end,vtotal
> + *
> + * Returns: true if the correct number of arguments are entered, else false.
> + */
> +bool igt_parse_mode_string(const char *mode_string, drmModeModeInfo *mode)
> +{
> +	float force_clock;
> +
> +	if (sscanf(mode_string, "%f,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu",
> +	   &force_clock, &mode->hdisplay, &mode->hsync_start, &mode->hsync_end, &mode->htotal,
> +	   &mode->vdisplay, &mode->vsync_start, &mode->vsync_end, &mode->vtotal) != 9)
> +		return false;
> +
> +	mode->clock = force_clock * 1000;
> +
> +	return true;
> +}
> diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> index 5856a4b3..a2cf0937 100644
> --- a/lib/igt_kms.h
> +++ b/lib/igt_kms.h
> @@ -974,5 +974,6 @@ void igt_sort_connector_modes(drmModeConnector *connector,
>   bool igt_max_bpc_constraint(igt_display_t *display, enum pipe pipe,
>   		igt_output_t *output, int bpc);
>   bool igt_check_bigjoiner_support(igt_display_t *display);
> +bool igt_parse_mode_string(const char *mode_string, drmModeModeInfo *mode);
>   
>   #endif /* __IGT_KMS_H__ */


More information about the igt-dev mailing list