diff mbox series

[06/11] drm/edid: Extract drm_gtf2_mode()

Message ID 20220826213501.31490-7-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm/edid: Range descriptor stuff | expand

Commit Message

Ville Syrjälä Aug. 26, 2022, 9:34 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Extract the GTF vs. GTF2 logic into a separate function.
We'll have a second user soon.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_edid.c | 47 ++++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 17 deletions(-)

Comments

Jani Nikula Aug. 29, 2022, 8:45 a.m. UTC | #1
On Sat, 27 Aug 2022, Ville Syrjala <ville.syrjala@linux.intel.com> wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Extract the GTF vs. GTF2 logic into a separate function.
> We'll have a second user soon.
>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

Reviewed-by: Jani Nikula <jani.nikula@intel.com>

> ---
>  drivers/gpu/drm/drm_edid.c | 47 ++++++++++++++++++++++++--------------
>  1 file changed, 30 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index b459fdf12b58..0c7cbe9b44f5 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -3113,6 +3113,35 @@ static int drm_mode_hsync(const struct drm_display_mode *mode)
>  	return DIV_ROUND_CLOSEST(mode->clock, mode->htotal);
>  }
>  
> +static struct drm_display_mode *
> +drm_gtf2_mode(struct drm_device *dev,
> +	      const struct drm_edid *drm_edid,
> +	      int hsize, int vsize, int vrefresh_rate)
> +{
> +	struct drm_display_mode *mode;
> +
> +	/*
> +	 * This is potentially wrong if there's ever a monitor with
> +	 * more than one ranges section, each claiming a different
> +	 * secondary GTF curve.  Please don't do that.
> +	 */
> +	mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
> +	if (!mode)
> +		return NULL;
> +
> +	if (drm_mode_hsync(mode) > drm_gtf2_hbreak(drm_edid)) {
> +		drm_mode_destroy(dev, mode);
> +		mode = drm_gtf_mode_complex(dev, hsize, vsize,
> +					    vrefresh_rate, 0, 0,
> +					    drm_gtf2_m(drm_edid),
> +					    drm_gtf2_2c(drm_edid),
> +					    drm_gtf2_k(drm_edid),
> +					    drm_gtf2_2j(drm_edid));
> +	}
> +
> +	return mode;
> +}
> +
>  /*
>   * Take the standard timing params (in this case width, aspect, and refresh)
>   * and convert them into a real mode using CVT/GTF/DMT.
> @@ -3201,23 +3230,7 @@ static struct drm_display_mode *drm_mode_std(struct drm_connector *connector,
>  		mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
>  		break;
>  	case LEVEL_GTF2:
> -		/*
> -		 * This is potentially wrong if there's ever a monitor with
> -		 * more than one ranges section, each claiming a different
> -		 * secondary GTF curve.  Please don't do that.
> -		 */
> -		mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
> -		if (!mode)
> -			return NULL;
> -		if (drm_mode_hsync(mode) > drm_gtf2_hbreak(drm_edid)) {
> -			drm_mode_destroy(dev, mode);
> -			mode = drm_gtf_mode_complex(dev, hsize, vsize,
> -						    vrefresh_rate, 0, 0,
> -						    drm_gtf2_m(drm_edid),
> -						    drm_gtf2_2c(drm_edid),
> -						    drm_gtf2_k(drm_edid),
> -						    drm_gtf2_2j(drm_edid));
> -		}
> +		mode = drm_gtf2_mode(dev, drm_edid, hsize, vsize, vrefresh_rate);
>  		break;
>  	case LEVEL_CVT:
>  		mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index b459fdf12b58..0c7cbe9b44f5 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -3113,6 +3113,35 @@  static int drm_mode_hsync(const struct drm_display_mode *mode)
 	return DIV_ROUND_CLOSEST(mode->clock, mode->htotal);
 }
 
+static struct drm_display_mode *
+drm_gtf2_mode(struct drm_device *dev,
+	      const struct drm_edid *drm_edid,
+	      int hsize, int vsize, int vrefresh_rate)
+{
+	struct drm_display_mode *mode;
+
+	/*
+	 * This is potentially wrong if there's ever a monitor with
+	 * more than one ranges section, each claiming a different
+	 * secondary GTF curve.  Please don't do that.
+	 */
+	mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
+	if (!mode)
+		return NULL;
+
+	if (drm_mode_hsync(mode) > drm_gtf2_hbreak(drm_edid)) {
+		drm_mode_destroy(dev, mode);
+		mode = drm_gtf_mode_complex(dev, hsize, vsize,
+					    vrefresh_rate, 0, 0,
+					    drm_gtf2_m(drm_edid),
+					    drm_gtf2_2c(drm_edid),
+					    drm_gtf2_k(drm_edid),
+					    drm_gtf2_2j(drm_edid));
+	}
+
+	return mode;
+}
+
 /*
  * Take the standard timing params (in this case width, aspect, and refresh)
  * and convert them into a real mode using CVT/GTF/DMT.
@@ -3201,23 +3230,7 @@  static struct drm_display_mode *drm_mode_std(struct drm_connector *connector,
 		mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
 		break;
 	case LEVEL_GTF2:
-		/*
-		 * This is potentially wrong if there's ever a monitor with
-		 * more than one ranges section, each claiming a different
-		 * secondary GTF curve.  Please don't do that.
-		 */
-		mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
-		if (!mode)
-			return NULL;
-		if (drm_mode_hsync(mode) > drm_gtf2_hbreak(drm_edid)) {
-			drm_mode_destroy(dev, mode);
-			mode = drm_gtf_mode_complex(dev, hsize, vsize,
-						    vrefresh_rate, 0, 0,
-						    drm_gtf2_m(drm_edid),
-						    drm_gtf2_2c(drm_edid),
-						    drm_gtf2_k(drm_edid),
-						    drm_gtf2_2j(drm_edid));
-		}
+		mode = drm_gtf2_mode(dev, drm_edid, hsize, vsize, vrefresh_rate);
 		break;
 	case LEVEL_CVT:
 		mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,