All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] HDR aux backlight range calculation
@ 2022-04-26 12:30 Jouni Högander
  2022-04-26 12:30 ` [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata Jouni Högander
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Jouni Högander @ 2022-04-26 12:30 UTC (permalink / raw)
  To: dri-devel; +Cc: Jani Nikula, Rodrigo Siqueira, Mika Kahola, Jouni Högander

This patch set splits out static hdr metadata backlight range parsing
from gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c into gpu/drm/drm-edid.c as
a new function. This new function is then used in admgpu_dm.c and
intel_dp_aux_backlight.c

Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Cc: Harry Wentland <harry.wentland@amd.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Mika Kahola <mika.kahola@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>

Jouni Högander (3):
  drm: New function to get luminance range based on static hdr metadata
  drm/amdgpu_dm: Use split out luminance calculation function
  drm/i915: Use luminance range from static hdr metadata

 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 ++----------
 drivers/gpu/drm/drm_edid.c                    | 55 +++++++++++++++++++
 .../drm/i915/display/intel_dp_aux_backlight.c |  9 ++-
 include/drm/drm_edid.h                        |  4 ++
 4 files changed, 70 insertions(+), 33 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata
  2022-04-26 12:30 [PATCH 0/3] HDR aux backlight range calculation Jouni Högander
@ 2022-04-26 12:30 ` Jouni Högander
  2022-04-26 13:37   ` Jani Nikula
  2022-04-26 12:30 ` [PATCH 2/3] drm/amdgpu_dm: Use split out luminance calculation function Jouni Högander
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Jouni Högander @ 2022-04-26 12:30 UTC (permalink / raw)
  To: dri-devel; +Cc: Jani Nikula, Rodrigo Siqueira, Mika Kahola, Jouni Högander

Split luminance min/max calculation using static hdr metadata from
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:update_connector_ext_caps
into drm/drm_edid.c.

Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Cc: Harry Wentland <harry.wentland@amd.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Mika Kahola <mika.kahola@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
---
 drivers/gpu/drm/drm_edid.c | 55 ++++++++++++++++++++++++++++++++++++++
 include/drm/drm_edid.h     |  4 +++
 2 files changed, 59 insertions(+)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 7a8482b75071..1cb886debbbe 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -4005,6 +4005,61 @@ drm_display_mode_from_cea_vic(struct drm_device *dev,
 }
 EXPORT_SYMBOL(drm_display_mode_from_cea_vic);
 
+/**
+ * drm_luminance_range_from_static_hdr_metadata() - luminance range from static hdr
+ * metadata
+ * @connector: connector we're calculating for
+ * @min: Calculated min value
+ * @max: Calculated max value
+ *
+ * Calculates backlight min and max as described in CTA-861-G
+ *
+ * Returns: True when calculation succeeds.
+ */
+bool
+drm_luminance_range_from_static_hdr_metadata(struct drm_connector *connector,
+					     u32 *min, u32 *max)
+{
+	struct hdr_sink_metadata *hdr_metadata = &connector->hdr_sink_metadata;
+	static const u8 pre_computed_values[] = {
+		50, 51, 52, 53, 55, 56, 57, 58, 59, 61, 62, 63, 65, 66, 68, 69,
+		71, 72, 74, 75, 77, 79, 81, 82, 84, 86, 88, 90, 92, 94, 96, 98};
+	u32 min_cll, max_cll, q, r;
+
+	if (!(hdr_metadata->hdmi_type1.metadata_type &
+	      BIT(HDMI_STATIC_METADATA_TYPE1)))
+		return false;
+
+	max_cll = hdr_metadata->hdmi_type1.max_cll;
+	min_cll = hdr_metadata->hdmi_type1.min_cll;
+
+	/* From the specification (CTA-861-G), for calculating the maximum
+	 * luminance we need to use:
+	 *	Luminance = 50*2**(CV/32)
+	 * Where CV is a one-byte value.
+	 * For calculating this expression we may need float point precision;
+	 * to avoid this complexity level, we take advantage that CV is divided
+	 * by a constant. From the Euclids division algorithm, we know that CV
+	 * can be written as: CV = 32*q + r. Next, we replace CV in the
+	 * Luminance expression and get 50*(2**q)*(2**(r/32)), hence we just
+	 * need to pre-compute the value of r/32. For pre-computing the values
+	 * We just used the following Ruby line:
+	 *	(0...32).each {|cv| puts (50*2**(cv/32.0)).round}
+	 * The results of the above expressions can be verified at
+	 * pre_computed_values.
+	 */
+	q = max_cll >> 5;
+	r = max_cll % 32;
+	*max = (1 << q) * pre_computed_values[r];
+
+	/* min luminance: maxLum * (CV/255)^2 / 100 */
+	q = DIV_ROUND_CLOSEST(min_cll, 255);
+	*min = *max * DIV_ROUND_CLOSEST((q * q), 100);
+
+	return true;
+}
+EXPORT_SYMBOL(drm_luminance_range_from_static_hdr_metadata);
+
 static int
 do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
 {
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index c3204a58fb09..63e441c84d72 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -406,6 +406,10 @@ drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
 				   const struct drm_display_mode *mode,
 				   enum hdmi_quantization_range rgb_quant_range);
 
+bool
+drm_luminance_range_from_static_hdr_metadata(struct drm_connector *connector,
+					     u32 *min, u32 *max);
+
 /**
  * drm_eld_mnl - Get ELD monitor name length in bytes.
  * @eld: pointer to an eld memory structure with mnl set
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] drm/amdgpu_dm: Use split out luminance calculation function
  2022-04-26 12:30 [PATCH 0/3] HDR aux backlight range calculation Jouni Högander
  2022-04-26 12:30 ` [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata Jouni Högander
@ 2022-04-26 12:30 ` Jouni Högander
  2022-04-26 12:30 ` [PATCH 3/3] drm/i915: Use luminance range from static hdr metadata Jouni Högander
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Jouni Högander @ 2022-04-26 12:30 UTC (permalink / raw)
  To: dri-devel; +Cc: Jani Nikula, Rodrigo Siqueira, Mika Kahola, Jouni Högander

Luminance range was split out into drm_edid.c to share the calculation
function. Use this new interface for caps->aux_max_input_signal and
caps->aux_min_input_signal.

Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Cc: Harry Wentland <harry.wentland@amd.com>
Cc: Lyude Paul <lyude@redhat.com>
Cc: Mika Kahola <mika.kahola@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 +++----------------
 1 file changed, 4 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 2ade82cfb1ac..49c03400e962 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -2836,15 +2836,11 @@ static struct drm_mode_config_helper_funcs amdgpu_dm_mode_config_helperfuncs = {
 
 static void update_connector_ext_caps(struct amdgpu_dm_connector *aconnector)
 {
-	u32 max_cll, min_cll, max, min, q, r;
 	struct amdgpu_dm_backlight_caps *caps;
 	struct amdgpu_display_manager *dm;
 	struct drm_connector *conn_base;
 	struct amdgpu_device *adev;
 	struct dc_link *link = NULL;
-	static const u8 pre_computed_values[] = {
-		50, 51, 52, 53, 55, 56, 57, 58, 59, 61, 62, 63, 65, 66, 68, 69,
-		71, 72, 74, 75, 77, 79, 81, 82, 84, 86, 88, 90, 92, 94, 96, 98};
 	int i;
 
 	if (!aconnector || !aconnector->dc_link)
@@ -2866,8 +2862,6 @@ static void update_connector_ext_caps(struct amdgpu_dm_connector *aconnector)
 	caps = &dm->backlight_caps[i];
 	caps->ext_caps = &aconnector->dc_link->dpcd_sink_ext_caps;
 	caps->aux_support = false;
-	max_cll = conn_base->hdr_sink_metadata.hdmi_type1.max_cll;
-	min_cll = conn_base->hdr_sink_metadata.hdmi_type1.min_cll;
 
 	if (caps->ext_caps->bits.oled == 1 /*||
 	    caps->ext_caps->bits.sdr_aux_backlight_control == 1 ||
@@ -2879,31 +2873,10 @@ static void update_connector_ext_caps(struct amdgpu_dm_connector *aconnector)
 	else if (amdgpu_backlight == 1)
 		caps->aux_support = true;
 
-	/* From the specification (CTA-861-G), for calculating the maximum
-	 * luminance we need to use:
-	 *	Luminance = 50*2**(CV/32)
-	 * Where CV is a one-byte value.
-	 * For calculating this expression we may need float point precision;
-	 * to avoid this complexity level, we take advantage that CV is divided
-	 * by a constant. From the Euclids division algorithm, we know that CV
-	 * can be written as: CV = 32*q + r. Next, we replace CV in the
-	 * Luminance expression and get 50*(2**q)*(2**(r/32)), hence we just
-	 * need to pre-compute the value of r/32. For pre-computing the values
-	 * We just used the following Ruby line:
-	 *	(0...32).each {|cv| puts (50*2**(cv/32.0)).round}
-	 * The results of the above expressions can be verified at
-	 * pre_computed_values.
-	 */
-	q = max_cll >> 5;
-	r = max_cll % 32;
-	max = (1 << q) * pre_computed_values[r];
-
-	// min luminance: maxLum * (CV/255)^2 / 100
-	q = DIV_ROUND_CLOSEST(min_cll, 255);
-	min = max * DIV_ROUND_CLOSEST((q * q), 100);
-
-	caps->aux_max_input_signal = max;
-	caps->aux_min_input_signal = min;
+	if (!drm_luminance_range_from_static_hdr_metadata(conn_base,
+							  &caps->aux_min_input_signal,
+							  &caps->aux_max_input_signal))
+		DRM_ERROR("No backligt range in static hdr metadata\n");
 }
 
 void amdgpu_dm_update_connector_after_detect(
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] drm/i915: Use luminance range from static hdr metadata
  2022-04-26 12:30 [PATCH 0/3] HDR aux backlight range calculation Jouni Högander
  2022-04-26 12:30 ` [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata Jouni Högander
  2022-04-26 12:30 ` [PATCH 2/3] drm/amdgpu_dm: Use split out luminance calculation function Jouni Högander
@ 2022-04-26 12:30 ` Jouni Högander
  2022-04-27 18:57 ` [PATCH 0/3] HDR aux backlight range calculation Lyude Paul
  2022-04-29 23:34 ` Lyude Paul
  4 siblings, 0 replies; 9+ messages in thread
From: Jouni Högander @ 2022-04-26 12:30 UTC (permalink / raw)
  To: dri-devel; +Cc: Jouni Högander, Jani Nikula, Mika Kahola

Instead of using fixed 0 - 512 range use
drm_luminance_range_from_static_hdr_metadata to obtain panel range. If
that fails fall back to static 0 - 512.

Cc: Lyude Paul <lyude@redhat.com>
Cc: Mika Kahola <mika.kahola@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
---
 drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
index fb6cf30ee628..6673af455808 100644
--- a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
+++ b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c
@@ -293,8 +293,13 @@ intel_dp_aux_hdr_setup_backlight(struct intel_connector *connector, enum pipe pi
 		}
 	}
 
-	panel->backlight.max = 512;
-	panel->backlight.min = 0;
+	if (!drm_luminance_range_from_static_hdr_metadata(&connector->base,
+							  &panel->backlight.min,
+							  &panel->backlight.max)) {
+		drm_err(&i915->drm, "No backlight range data in static hdr metadata, using fixed 0,512\n");
+		panel->backlight.max = 512;
+		panel->backlight.min = 0;
+	}
 	panel->backlight.level = intel_dp_aux_hdr_get_backlight(connector, pipe);
 	panel->backlight.enabled = panel->backlight.level != 0;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata
  2022-04-26 12:30 ` [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata Jouni Högander
@ 2022-04-26 13:37   ` Jani Nikula
  2022-04-26 18:27     ` Navare, Manasi D
  0 siblings, 1 reply; 9+ messages in thread
From: Jani Nikula @ 2022-04-26 13:37 UTC (permalink / raw)
  To: Jouni Högander, dri-devel
  Cc: Jouni Högander, Rodrigo Siqueira, Mika Kahola

On Tue, 26 Apr 2022, Jouni Högander <jouni.hogander@intel.com> wrote:
> Split luminance min/max calculation using static hdr metadata from
> drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:update_connector_ext_caps
> into drm/drm_edid.c.

IMO all of this should be computed at EDID parsing time once and stored
in the metadata. Maybe in drm_parse_hdr_metadata_block().

Over time we've added a bunch of functions to do this type of stuff, and
all drivers call them at slightly different times and different ways,
and it just grows complicated.

(Also, I think basically everything that comes out of the EDID or
DisplayID should be stored in connector->display_info instead of being
spread around like we currently do. But that's for another patch series,
another time.)

BR,
Jani.

>
> Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
> Cc: Harry Wentland <harry.wentland@amd.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: Mika Kahola <mika.kahola@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
> ---
>  drivers/gpu/drm/drm_edid.c | 55 ++++++++++++++++++++++++++++++++++++++
>  include/drm/drm_edid.h     |  4 +++
>  2 files changed, 59 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index 7a8482b75071..1cb886debbbe 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -4005,6 +4005,61 @@ drm_display_mode_from_cea_vic(struct drm_device *dev,
>  }
>  EXPORT_SYMBOL(drm_display_mode_from_cea_vic);
>  
> +/**
> + * drm_luminance_range_from_static_hdr_metadata() - luminance range from static hdr
> + * metadata
> + * @connector: connector we're calculating for
> + * @min: Calculated min value
> + * @max: Calculated max value
> + *
> + * Calculates backlight min and max as described in CTA-861-G
> + *
> + * Returns: True when calculation succeeds.
> + */
> +bool
> +drm_luminance_range_from_static_hdr_metadata(struct drm_connector *connector,
> +					     u32 *min, u32 *max)
> +{
> +	struct hdr_sink_metadata *hdr_metadata = &connector->hdr_sink_metadata;
> +	static const u8 pre_computed_values[] = {
> +		50, 51, 52, 53, 55, 56, 57, 58, 59, 61, 62, 63, 65, 66, 68, 69,
> +		71, 72, 74, 75, 77, 79, 81, 82, 84, 86, 88, 90, 92, 94, 96, 98};
> +	u32 min_cll, max_cll, q, r;
> +
> +	if (!(hdr_metadata->hdmi_type1.metadata_type &
> +	      BIT(HDMI_STATIC_METADATA_TYPE1)))
> +		return false;
> +
> +	max_cll = hdr_metadata->hdmi_type1.max_cll;
> +	min_cll = hdr_metadata->hdmi_type1.min_cll;
> +
> +	/* From the specification (CTA-861-G), for calculating the maximum
> +	 * luminance we need to use:
> +	 *	Luminance = 50*2**(CV/32)
> +	 * Where CV is a one-byte value.
> +	 * For calculating this expression we may need float point precision;
> +	 * to avoid this complexity level, we take advantage that CV is divided
> +	 * by a constant. From the Euclids division algorithm, we know that CV
> +	 * can be written as: CV = 32*q + r. Next, we replace CV in the
> +	 * Luminance expression and get 50*(2**q)*(2**(r/32)), hence we just
> +	 * need to pre-compute the value of r/32. For pre-computing the values
> +	 * We just used the following Ruby line:
> +	 *	(0...32).each {|cv| puts (50*2**(cv/32.0)).round}
> +	 * The results of the above expressions can be verified at
> +	 * pre_computed_values.
> +	 */
> +	q = max_cll >> 5;
> +	r = max_cll % 32;
> +	*max = (1 << q) * pre_computed_values[r];
> +
> +	/* min luminance: maxLum * (CV/255)^2 / 100 */
> +	q = DIV_ROUND_CLOSEST(min_cll, 255);
> +	*min = *max * DIV_ROUND_CLOSEST((q * q), 100);
> +
> +	return true;
> +}
> +EXPORT_SYMBOL(drm_luminance_range_from_static_hdr_metadata);
> +
>  static int
>  do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
>  {
> diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
> index c3204a58fb09..63e441c84d72 100644
> --- a/include/drm/drm_edid.h
> +++ b/include/drm/drm_edid.h
> @@ -406,6 +406,10 @@ drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
>  				   const struct drm_display_mode *mode,
>  				   enum hdmi_quantization_range rgb_quant_range);
>  
> +bool
> +drm_luminance_range_from_static_hdr_metadata(struct drm_connector *connector,
> +					     u32 *min, u32 *max);
> +
>  /**
>   * drm_eld_mnl - Get ELD monitor name length in bytes.
>   * @eld: pointer to an eld memory structure with mnl set

-- 
Jani Nikula, Intel Open Source Graphics Center

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata
  2022-04-26 13:37   ` Jani Nikula
@ 2022-04-26 18:27     ` Navare, Manasi D
  0 siblings, 0 replies; 9+ messages in thread
From: Navare, Manasi D @ 2022-04-26 18:27 UTC (permalink / raw)
  To: Nikula, Jani, Hogander, Jouni, dri-devel
  Cc: Hogander, Jouni, Rodrigo Siqueira, Kahola, Mika

Yes I agree that this data parsed from EDID/Display ID should be stored in structs defined in drm_display_info.
Like for the VRR range that we parse from EDID, we store that in a struct monitor_range in drm_display_info.

Manasi

-----Original Message-----
From: dri-devel <dri-devel-bounces@lists.freedesktop.org> On Behalf Of Jani Nikula
Sent: Tuesday, April 26, 2022 6:38 AM
To: Hogander, Jouni <jouni.hogander@intel.com>; dri-devel@lists.freedesktop.org
Cc: Hogander, Jouni <jouni.hogander@intel.com>; Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>; Kahola, Mika <mika.kahola@intel.com>
Subject: Re: [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata

On Tue, 26 Apr 2022, Jouni Högander <jouni.hogander@intel.com> wrote:
> Split luminance min/max calculation using static hdr metadata from 
> drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:update_connector_ext
> _caps
> into drm/drm_edid.c.

IMO all of this should be computed at EDID parsing time once and stored in the metadata. Maybe in drm_parse_hdr_metadata_block().

Over time we've added a bunch of functions to do this type of stuff, and all drivers call them at slightly different times and different ways, and it just grows complicated.

(Also, I think basically everything that comes out of the EDID or DisplayID should be stored in connector->display_info instead of being spread around like we currently do. But that's for another patch series, another time.)

BR,
Jani.

>
> Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
> Cc: Harry Wentland <harry.wentland@amd.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: Mika Kahola <mika.kahola@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
> ---
>  drivers/gpu/drm/drm_edid.c | 55 ++++++++++++++++++++++++++++++++++++++
>  include/drm/drm_edid.h     |  4 +++
>  2 files changed, 59 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c 
> index 7a8482b75071..1cb886debbbe 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -4005,6 +4005,61 @@ drm_display_mode_from_cea_vic(struct drm_device 
> *dev,  }  EXPORT_SYMBOL(drm_display_mode_from_cea_vic);
>  
> +/**
> + * drm_luminance_range_from_static_hdr_metadata() - luminance range 
> +from static hdr
> + * metadata
> + * @connector: connector we're calculating for
> + * @min: Calculated min value
> + * @max: Calculated max value
> + *
> + * Calculates backlight min and max as described in CTA-861-G
> + *
> + * Returns: True when calculation succeeds.
> + */
> +bool
> +drm_luminance_range_from_static_hdr_metadata(struct drm_connector *connector,
> +					     u32 *min, u32 *max)
> +{
> +	struct hdr_sink_metadata *hdr_metadata = &connector->hdr_sink_metadata;
> +	static const u8 pre_computed_values[] = {
> +		50, 51, 52, 53, 55, 56, 57, 58, 59, 61, 62, 63, 65, 66, 68, 69,
> +		71, 72, 74, 75, 77, 79, 81, 82, 84, 86, 88, 90, 92, 94, 96, 98};
> +	u32 min_cll, max_cll, q, r;
> +
> +	if (!(hdr_metadata->hdmi_type1.metadata_type &
> +	      BIT(HDMI_STATIC_METADATA_TYPE1)))
> +		return false;
> +
> +	max_cll = hdr_metadata->hdmi_type1.max_cll;
> +	min_cll = hdr_metadata->hdmi_type1.min_cll;
> +
> +	/* From the specification (CTA-861-G), for calculating the maximum
> +	 * luminance we need to use:
> +	 *	Luminance = 50*2**(CV/32)
> +	 * Where CV is a one-byte value.
> +	 * For calculating this expression we may need float point precision;
> +	 * to avoid this complexity level, we take advantage that CV is divided
> +	 * by a constant. From the Euclids division algorithm, we know that CV
> +	 * can be written as: CV = 32*q + r. Next, we replace CV in the
> +	 * Luminance expression and get 50*(2**q)*(2**(r/32)), hence we just
> +	 * need to pre-compute the value of r/32. For pre-computing the values
> +	 * We just used the following Ruby line:
> +	 *	(0...32).each {|cv| puts (50*2**(cv/32.0)).round}
> +	 * The results of the above expressions can be verified at
> +	 * pre_computed_values.
> +	 */
> +	q = max_cll >> 5;
> +	r = max_cll % 32;
> +	*max = (1 << q) * pre_computed_values[r];
> +
> +	/* min luminance: maxLum * (CV/255)^2 / 100 */
> +	q = DIV_ROUND_CLOSEST(min_cll, 255);
> +	*min = *max * DIV_ROUND_CLOSEST((q * q), 100);
> +
> +	return true;
> +}
> +EXPORT_SYMBOL(drm_luminance_range_from_static_hdr_metadata);
> +
>  static int
>  do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)  
> { diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 
> c3204a58fb09..63e441c84d72 100644
> --- a/include/drm/drm_edid.h
> +++ b/include/drm/drm_edid.h
> @@ -406,6 +406,10 @@ drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
>  				   const struct drm_display_mode *mode,
>  				   enum hdmi_quantization_range rgb_quant_range);
>  
> +bool
> +drm_luminance_range_from_static_hdr_metadata(struct drm_connector *connector,
> +					     u32 *min, u32 *max);
> +
>  /**
>   * drm_eld_mnl - Get ELD monitor name length in bytes.
>   * @eld: pointer to an eld memory structure with mnl set

--
Jani Nikula, Intel Open Source Graphics Center

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3] HDR aux backlight range calculation
  2022-04-26 12:30 [PATCH 0/3] HDR aux backlight range calculation Jouni Högander
                   ` (2 preceding siblings ...)
  2022-04-26 12:30 ` [PATCH 3/3] drm/i915: Use luminance range from static hdr metadata Jouni Högander
@ 2022-04-27 18:57 ` Lyude Paul
  2022-04-29 23:34 ` Lyude Paul
  4 siblings, 0 replies; 9+ messages in thread
From: Lyude Paul @ 2022-04-27 18:57 UTC (permalink / raw)
  To: Jouni Högander, dri-devel; +Cc: Jani Nikula, Rodrigo Siqueira, Mika Kahola

Hey! I will try to test this out ASAP on all of the HDR backlight machines I
have (so, many :) at some point this week, will let you know when

On Tue, 2022-04-26 at 15:30 +0300, Jouni Högander wrote:
> This patch set splits out static hdr metadata backlight range parsing
> from gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c into gpu/drm/drm-edid.c as
> a new function. This new function is then used in admgpu_dm.c and
> intel_dp_aux_backlight.c
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
> Cc: Harry Wentland <harry.wentland@amd.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: Mika Kahola <mika.kahola@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> 
> Jouni Högander (3):
>   drm: New function to get luminance range based on static hdr metadata
>   drm/amdgpu_dm: Use split out luminance calculation function
>   drm/i915: Use luminance range from static hdr metadata
> 
>  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 ++----------
>  drivers/gpu/drm/drm_edid.c                    | 55 +++++++++++++++++++
>  .../drm/i915/display/intel_dp_aux_backlight.c |  9 ++-
>  include/drm/drm_edid.h                        |  4 ++
>  4 files changed, 70 insertions(+), 33 deletions(-)
> 

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3] HDR aux backlight range calculation
  2022-04-26 12:30 [PATCH 0/3] HDR aux backlight range calculation Jouni Högander
                   ` (3 preceding siblings ...)
  2022-04-27 18:57 ` [PATCH 0/3] HDR aux backlight range calculation Lyude Paul
@ 2022-04-29 23:34 ` Lyude Paul
  2022-05-02  5:25   ` Hogander, Jouni
  4 siblings, 1 reply; 9+ messages in thread
From: Lyude Paul @ 2022-04-29 23:34 UTC (permalink / raw)
  To: Jouni Högander, dri-devel; +Cc: Jani Nikula, Rodrigo Siqueira, Mika Kahola

Cool! Tested this on three different laptops, and it seems to work great on
all of them. so, this series is:

Tested-by: Lyude Paul <lyude@redhat.com>

Would review, but I basically have the same comments as jani

On Tue, 2022-04-26 at 15:30 +0300, Jouni Högander wrote:
> This patch set splits out static hdr metadata backlight range parsing
> from gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c into gpu/drm/drm-edid.c as
> a new function. This new function is then used in admgpu_dm.c and
> intel_dp_aux_backlight.c
> 
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
> Cc: Harry Wentland <harry.wentland@amd.com>
> Cc: Lyude Paul <lyude@redhat.com>
> Cc: Mika Kahola <mika.kahola@intel.com>
> Cc: Jani Nikula <jani.nikula@intel.com>
> 
> Jouni Högander (3):
>   drm: New function to get luminance range based on static hdr metadata
>   drm/amdgpu_dm: Use split out luminance calculation function
>   drm/i915: Use luminance range from static hdr metadata
> 
>  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 ++----------
>  drivers/gpu/drm/drm_edid.c                    | 55 +++++++++++++++++++
>  .../drm/i915/display/intel_dp_aux_backlight.c |  9 ++-
>  include/drm/drm_edid.h                        |  4 ++
>  4 files changed, 70 insertions(+), 33 deletions(-)
> 

-- 
Cheers,
 Lyude Paul (she/her)
 Software Engineer at Red Hat


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3] HDR aux backlight range calculation
  2022-04-29 23:34 ` Lyude Paul
@ 2022-05-02  5:25   ` Hogander, Jouni
  0 siblings, 0 replies; 9+ messages in thread
From: Hogander, Jouni @ 2022-05-02  5:25 UTC (permalink / raw)
  To: dri-devel, lyude; +Cc: Nikula, Jani, Rodrigo.Siqueira, Kahola, Mika

On Fri, 2022-04-29 at 19:34 -0400, Lyude Paul wrote:
> Cool! Tested this on three different laptops, and it seems to work
> great on
> all of them. so, this series is:
> 
> Tested-by: Lyude Paul <lyude@redhat.com>

Thank you all for review/testing support. I will come back with updated
patch set later.

> 
> Would review, but I basically have the same comments as jani
> 
> On Tue, 2022-04-26 at 15:30 +0300, Jouni Högander wrote:
> > This patch set splits out static hdr metadata backlight range
> > parsing
> > from gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c into gpu/drm/drm-
> > edid.c as
> > a new function. This new function is then used in admgpu_dm.c and
> > intel_dp_aux_backlight.c
> > 
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> > Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
> > Cc: Harry Wentland <harry.wentland@amd.com>
> > Cc: Lyude Paul <lyude@redhat.com>
> > Cc: Mika Kahola <mika.kahola@intel.com>
> > Cc: Jani Nikula <jani.nikula@intel.com>
> > 
> > Jouni Högander (3):
> >   drm: New function to get luminance range based on static hdr
> > metadata
> >   drm/amdgpu_dm: Use split out luminance calculation function
> >   drm/i915: Use luminance range from static hdr metadata
> > 
> >  .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 35 ++----------
> >  drivers/gpu/drm/drm_edid.c                    | 55
> > +++++++++++++++++++
> >  .../drm/i915/display/intel_dp_aux_backlight.c |  9 ++-
> >  include/drm/drm_edid.h                        |  4 ++
> >  4 files changed, 70 insertions(+), 33 deletions(-)
> > 


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-05-02  5:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-26 12:30 [PATCH 0/3] HDR aux backlight range calculation Jouni Högander
2022-04-26 12:30 ` [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata Jouni Högander
2022-04-26 13:37   ` Jani Nikula
2022-04-26 18:27     ` Navare, Manasi D
2022-04-26 12:30 ` [PATCH 2/3] drm/amdgpu_dm: Use split out luminance calculation function Jouni Högander
2022-04-26 12:30 ` [PATCH 3/3] drm/i915: Use luminance range from static hdr metadata Jouni Högander
2022-04-27 18:57 ` [PATCH 0/3] HDR aux backlight range calculation Lyude Paul
2022-04-29 23:34 ` Lyude Paul
2022-05-02  5:25   ` Hogander, Jouni

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.