diff mbox series

[v2,02/15] drm/edid: abstract cea data block collection size

Message ID 5339ab3249400a3c41001967e7ff2611b58e0425.1654674560.git.jani.nikula@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/edid: expand on struct drm_edid usage | expand

Commit Message

Jani Nikula June 8, 2022, 7:50 a.m. UTC
Add a function to get the cea data block collection size.

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
 drivers/gpu/drm/drm_edid.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Comments

Ville Syrjala June 10, 2022, 6:58 p.m. UTC | #1
On Wed, Jun 08, 2022 at 10:50:32AM +0300, Jani Nikula wrote:
> Add a function to get the cea data block collection size.
> 
> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>

Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> ---
>  drivers/gpu/drm/drm_edid.c | 24 +++++++++++++++++++++---
>  1 file changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index c57f6333ea7d..002816509fc8 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -4482,6 +4482,20 @@ __cea_db_iter_current_block(const struct cea_db_iter *iter)
>  	return NULL;
>  }
>  
> +/*
> + * References:
> + * - CTA-861-H section 7.3.3 CTA Extension Version 3
> + */
> +static int cea_db_collection_size(const u8 *cta)
> +{
> +	u8 d = cta[2];
> +
> +	if (d < 4 || d > 127)
> +		return 0;
> +
> +	return d - 4;
> +}
> +
>  /*
>   * References:
>   * - VESA E-EDID v1.4
> @@ -4492,15 +4506,19 @@ static const void *__cea_db_iter_edid_next(struct cea_db_iter *iter)
>  	const u8 *ext;
>  
>  	drm_edid_iter_for_each(ext, &iter->edid_iter) {
> +		int size;
> +
>  		/* Only support CTA Extension revision 3+ */
>  		if (ext[0] != CEA_EXT || cea_revision(ext) < 3)
>  			continue;
>  
> -		iter->index = 4;
> -		iter->end = ext[2];
> -		if (iter->end < 4 || iter->end > 127)
> +		size = cea_db_collection_size(ext);
> +		if (!size)
>  			continue;
>  
> +		iter->index = 4;
> +		iter->end = iter->index + size;
> +
>  		return ext;
>  	}
>  
> -- 
> 2.30.2
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index c57f6333ea7d..002816509fc8 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -4482,6 +4482,20 @@  __cea_db_iter_current_block(const struct cea_db_iter *iter)
 	return NULL;
 }
 
+/*
+ * References:
+ * - CTA-861-H section 7.3.3 CTA Extension Version 3
+ */
+static int cea_db_collection_size(const u8 *cta)
+{
+	u8 d = cta[2];
+
+	if (d < 4 || d > 127)
+		return 0;
+
+	return d - 4;
+}
+
 /*
  * References:
  * - VESA E-EDID v1.4
@@ -4492,15 +4506,19 @@  static const void *__cea_db_iter_edid_next(struct cea_db_iter *iter)
 	const u8 *ext;
 
 	drm_edid_iter_for_each(ext, &iter->edid_iter) {
+		int size;
+
 		/* Only support CTA Extension revision 3+ */
 		if (ext[0] != CEA_EXT || cea_revision(ext) < 3)
 			continue;
 
-		iter->index = 4;
-		iter->end = ext[2];
-		if (iter->end < 4 || iter->end > 127)
+		size = cea_db_collection_size(ext);
+		if (!size)
 			continue;
 
+		iter->index = 4;
+		iter->end = iter->index + size;
+
 		return ext;
 	}