From patchwork Tue Apr 26 12:30:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Hogander, Jouni" X-Patchwork-Id: 12827028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 984F8C433F5 for ; Tue, 26 Apr 2022 12:31:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C5A6710E1FC; Tue, 26 Apr 2022 12:31:10 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8AE3E10E1FC for ; Tue, 26 Apr 2022 12:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650976269; x=1682512269; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3/ul4D1NwEgugOvP7lKzezb80lJFALJ/5t5pO5CRNkY=; b=XSGCH7P3SH6bYRjq2WKo7vvdUCMM/GxhKhAq3KbVXLJQzwYbsYOH8aE/ Kb5h10W2fX4oIy72aQWoopdpvtavjOCUtBv5yb7V7PoN8dj5maOXiJFDG 1iwf6ZfXOc6OFSc0C0TeWO2t+7F2ImtF69mq3vlo82sYshf8b+CgTRMbH 7qDP1QxmsuxAqH7LKDbjSoYOAL2pGiKUKqmw7+297W4PexXnj6oU8iY00 sWylRJ2D1Luh+JyNvnpmOIk8Qo5JbQurc3QpnlhoHIhdFlks1TroluDlB PI1t+z3Jd+DNhf2GTnHhcljQ/o5Ty6vOuiVx3Wtq81DruSu5uuRIlOlz9 w==; X-IronPort-AV: E=McAfee;i="6400,9594,10328"; a="264405588" X-IronPort-AV: E=Sophos;i="5.90,290,1643702400"; d="scan'208";a="264405588" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 05:31:08 -0700 X-IronPort-AV: E=Sophos;i="5.90,290,1643702400"; d="scan'208";a="558287504" Received: from pbasx-mobl2.ger.corp.intel.com (HELO jhogande-mobl1.ger.corp.intel.com) ([10.252.32.62]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 05:31:06 -0700 From: =?utf-8?q?Jouni_H=C3=B6gander?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] drm: New function to get luminance range based on static hdr metadata Date: Tue, 26 Apr 2022 15:30:42 +0300 Message-Id: <20220426123044.320415-2-jouni.hogander@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220426123044.320415-1-jouni.hogander@intel.com> References: <20220426123044.320415-1-jouni.hogander@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jani Nikula , Rodrigo Siqueira , Mika Kahola , =?utf-8?q?Jouni_H=C3=B6gander?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 Cc: Harry Wentland Cc: Lyude Paul Cc: Mika Kahola Cc: Jani Nikula Signed-off-by: Jouni Högander --- 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 From patchwork Tue Apr 26 12:30:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Hogander, Jouni" X-Patchwork-Id: 12827029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 634DFC433F5 for ; Tue, 26 Apr 2022 12:31:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 77A4310E3FF; Tue, 26 Apr 2022 12:31:21 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id E438110E464 for ; Tue, 26 Apr 2022 12:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650976279; x=1682512279; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/he197+ijhYJIkXIWOMmjed28cSvJyuLubAAKobn6N4=; b=j+ZncWdbjgTxh1Q0QH3EKH98xIkIoNoryL1L4CzCR7YWAeLr9boX9/dw RNO4gmUkSdU6XAaKzLoEDnCffhQMW+gMwRYvjSF2B2+f2+MRjKobJoz7Q 6jwoXfKD59NxPoR3BVQneHkfPwSZDpn2MR4o0yJfKAQtXEvAkrLGLAvZ6 MBrn470pyI4nllIo1kekz58Ml+HBzF/EDEhI3qKDzoK3IaQlzoI0bbvps Vb5wFsNqD2SXFQvmqbxaa6ms7yG6d1vV9qqdwZQGlM5ZQlILYJfc2TLar PULTdSbE/K8Q7hmF0MowGrWZynrM111JmOQIpaLyuNP4ibvixieW/gW8G Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10328"; a="263154666" X-IronPort-AV: E=Sophos;i="5.90,290,1643702400"; d="scan'208";a="263154666" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 05:31:18 -0700 X-IronPort-AV: E=Sophos;i="5.90,290,1643702400"; d="scan'208";a="558287587" Received: from pbasx-mobl2.ger.corp.intel.com (HELO jhogande-mobl1.ger.corp.intel.com) ([10.252.32.62]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 05:31:15 -0700 From: =?utf-8?q?Jouni_H=C3=B6gander?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] drm/amdgpu_dm: Use split out luminance calculation function Date: Tue, 26 Apr 2022 15:30:43 +0300 Message-Id: <20220426123044.320415-3-jouni.hogander@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220426123044.320415-1-jouni.hogander@intel.com> References: <20220426123044.320415-1-jouni.hogander@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jani Nikula , Rodrigo Siqueira , Mika Kahola , =?utf-8?q?Jouni_H=C3=B6gander?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 Cc: Harry Wentland Cc: Lyude Paul Cc: Mika Kahola Cc: Jani Nikula Signed-off-by: Jouni Högander --- .../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( From patchwork Tue Apr 26 12:30:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Hogander, Jouni" X-Patchwork-Id: 12827030 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 54015C433F5 for ; Tue, 26 Apr 2022 12:31:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5F1ED10E464; Tue, 26 Apr 2022 12:31:27 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id DD7FD10E464 for ; Tue, 26 Apr 2022 12:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650976281; x=1682512281; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e4th8uJasSx6KPyjfEQUYIDA242GShSGpYteX8kiMr0=; b=Z67nyVGKs4oGYybI2ouvwxl/fyHc3GOAay+VqP4IIYPvOZKzX7HPOVCR BEhhIhkVHq2Q6F5iTQPKzt3yRheMWMSOM7lRWZfX8H2//C5UxkkiHU5EJ eyikWajQeusJEAwaO344xm+ksevNjzZNTbAWf1KLJvWrfZ6Bh3uylguv7 XW+a6h3sxakWT53z6xd49XgzK9t4Mc2hOCPAL36E8UpK9WCoSlOXLqRf0 FJhKWXyjnBpFRLT7LP+FXMjXLTWE6VI+SCKpwh6MHSFe92wBBDcOmfTb0 nT8xXClTEd22wrch+9ebrobKD5jVpWZ1CWsfWEHzkricqRvyqVcLOlCKr Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10328"; a="263154680" X-IronPort-AV: E=Sophos;i="5.90,290,1643702400"; d="scan'208";a="263154680" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 05:31:21 -0700 X-IronPort-AV: E=Sophos;i="5.90,290,1643702400"; d="scan'208";a="558287619" Received: from pbasx-mobl2.ger.corp.intel.com (HELO jhogande-mobl1.ger.corp.intel.com) ([10.252.32.62]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2022 05:31:19 -0700 From: =?utf-8?q?Jouni_H=C3=B6gander?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] drm/i915: Use luminance range from static hdr metadata Date: Tue, 26 Apr 2022 15:30:44 +0300 Message-Id: <20220426123044.320415-4-jouni.hogander@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220426123044.320415-1-jouni.hogander@intel.com> References: <20220426123044.320415-1-jouni.hogander@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Jouni_H=C3=B6gander?= , Jani Nikula , Mika Kahola Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 Cc: Mika Kahola Cc: Jani Nikula Signed-off-by: Jouni Högander --- 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;