From patchwork Tue Oct 31 16:48:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 160236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b90f:0:b0:403:3b70:6f57 with SMTP id t15csp372795vqg; Tue, 31 Oct 2023 09:49:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQYKc6b0LKozkh68McvWRk5KyqArJqu7Qp9iA25ObIQ9Wt0VARXLi1xELYH65ObhcJH+Aq X-Received: by 2002:a17:90a:3c86:b0:27c:fb84:101a with SMTP id g6-20020a17090a3c8600b0027cfb84101amr11792995pjc.29.1698770960225; Tue, 31 Oct 2023 09:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698770960; cv=none; d=google.com; s=arc-20160816; b=DjWAz1FwwyI+tiebuZDF07J1Ov/SZpGa90le7SzEVwj1SXsOtrLZXdNmrbB/fsv5Aw jM26d/Mss6TrYPzfI8lPozBhaZxZ5jFp8dhKO2ppbfUI1eR1MbdjtfHDlg63HSWp6Lpn dwF/Ac6PXS559ROaBsDyhKg34Zvc1eW0B9QoB02fOp+QOFK7HoF3G6a8oGzulalEFExe 1XDlF31WmzJo8RBB02jyUVmVPlOviHpjlWN9JCFJXBhthqsgq8yc5a9/25ODHeod3kCn bLdi2xGMCBX2Zaf46YTlG40tDkqSy8EEt/KX0RZksYe0J5LcVNZfTe+7m+zdUkx5cGlX 9dhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=DkoGd76vWK0a5MKcI4iPByAhNWL5+q3+Kiy6usyP0GQ=; fh=e6/uyeFf2k7v8JUtB6fPyaAS5iN3eSA1hjtg35V2Rzw=; b=iv0yURN09OcO01WrRQt1QHiWjNx+YmZRrtgGFypyrwsSbEl7P46x6AWTaGdsIP+OR8 JpjeH8EqLmVHFRott+MKzc/rC7W5Jbz9CIP0lxUJRmnJTlB3q1PUX2/X51HPl1DwjwSq aYkD9srIh2dCkZsr4uUriYtxcOg09JcIqX8IobtEgRCcr+oBIEwZL7a94nqbtAsFOoJK Ts5IcnQrMNgTcu1PzBs6Pe0uaAgmWNYHRciuVVmc9r2+Rds1ZExN2/q0dzvH+WEnkhgA nX8Q3O+YAuMeja8gWA8Yw/oLPfd88GeAdXeIUgENXNvBTjZSr3F78Ojmv4xzaCEC461+ BEBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b5jlh4WK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id bv22-20020a17090af19600b0027e31647f2bsi1160568pjb.65.2023.10.31.09.49.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 09:49:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=b5jlh4WK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2CCE7801B40B; Tue, 31 Oct 2023 09:49:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346410AbjJaQtN (ORCPT + 33 others); Tue, 31 Oct 2023 12:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346470AbjJaQst (ORCPT ); Tue, 31 Oct 2023 12:48:49 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2761C2; Tue, 31 Oct 2023 09:48:46 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2E82C433C8; Tue, 31 Oct 2023 16:48:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698770926; bh=TzJM3Cq+aKhNUMbLeP67D/3B1e/vg4ASjkjOAY8gJTE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=b5jlh4WKBTgffrO82bOhCN3p+UZr8fkCIbrqyNltFBYvqsXuD8stXXgO04Ac/mHH7 ATAEAK1zpg2PBLKRbjhWJoO9AI7My3BxFZteWlO2tZzdC/bHzAKp2h1bUYTaC7u/SN V4O+cO2Q18+GIVAQZmveHux8yy+CctpRAykxc8fFKAUX++W4zG6+19Rpp50dl58Lq1 zsEFl/7hbsrmoo7MRP4RLpFIT2j8fLKgb6ERumRRnBOrS1w61GM8CP4qEn89fiWrvH a49SrnXwHD6jjOWcphYrMKD5BrCqfJCx2YHXpIYTwxQ5np8zbjK7+HAfrOFQ3JqIdz YUFYiV93N/Ivg== From: Maxime Ripard Date: Tue, 31 Oct 2023 17:48:17 +0100 Subject: [PATCH RFC v3 04/37] drm/connector: hdmi: Add RGB Quantization Range to the connector state MIME-Version: 1.0 Message-Id: <20231031-kms-hdmi-connector-state-v3-4-328b0fae43a7@kernel.org> References: <20231031-kms-hdmi-connector-state-v3-0-328b0fae43a7@kernel.org> In-Reply-To: <20231031-kms-hdmi-connector-state-v3-0-328b0fae43a7@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Emma Anholt , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4775; i=mripard@kernel.org; h=from:subject:message-id; bh=TzJM3Cq+aKhNUMbLeP67D/3B1e/vg4ASjkjOAY8gJTE=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmO+nerrkxezbjAwpLrYujqTVMaX3rwOOrM9XBJVDibt 6/d7svkjlIWBjEuBlkxRZYYYfMlcadmve5k45sHM4eVCWQIAxenAEzkegsjw4o7Tx4uvLrYVfqg VLeVQrnz+ewtYfPcDe4ubZV980R4eS7Df39xvbl7T2X/1oub9a70QbOBWeZzfQOnw6L8r5nTSg0 sGAA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_FILL_THIS_FORM_SHORT,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 31 Oct 2023 09:49:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781290458238967079 X-GMAIL-MSGID: 1781290458238967079 HDMI controller drivers will need to figure out the RGB range they need to configure based on a mode and property values. Let's expose that in the HDMI connector state so drivers can just use that value. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_atomic.c | 4 ++- drivers/gpu/drm/drm_atomic_state_helper.c | 44 +++++++++++++++++++++++++++++++ include/drm/drm_atomic_state_helper.h | 1 + include/drm/drm_connector.h | 6 +++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index b1b56dcaa76b..55cb117cd49a 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1143,9 +1143,11 @@ static void drm_atomic_connector_print_state(struct drm_printer *p, drm_printf(p, "\tcolorspace=%s\n", drm_get_colorspace_name(state->colorspace)); if (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA || - connector->connector_type == DRM_MODE_CONNECTOR_HDMIB) + connector->connector_type == DRM_MODE_CONNECTOR_HDMIB) { drm_printf(p, "\tbroadcast_rgb=%s\n", drm_hdmi_connector_get_broadcast_rgb_name(state->hdmi.broadcast_rgb)); + drm_printf(p, "\tis_full_range=%c\n", state->hdmi.is_full_range ? 'y' : 'n'); + } if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK) if (state->writeback_job && state->writeback_job->fb) diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c index 37193c6f9fca..c3f124af64dc 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -622,6 +623,47 @@ int drm_atomic_helper_connector_tv_check(struct drm_connector *connector, } EXPORT_SYMBOL(drm_atomic_helper_connector_tv_check); +static const struct drm_display_mode * +connector_state_get_mode(const struct drm_connector_state *conn_state) +{ + struct drm_atomic_state *state; + struct drm_crtc_state *crtc_state; + struct drm_crtc *crtc; + + state = conn_state->state; + if (!state) + return NULL; + + crtc = conn_state->crtc; + if (!crtc) + return NULL; + + crtc_state = drm_atomic_get_new_crtc_state(state, crtc); + if (!crtc_state) + return NULL; + + return &crtc_state->mode; +} + +static bool hdmi_is_full_range(const struct drm_connector *connector, + const struct drm_connector_state *state) +{ + const struct drm_display_info *display = &connector->display_info; + const struct drm_display_mode *mode = + connector_state_get_mode(state); + + if (state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_FULL) + return true; + + if (state->hdmi.broadcast_rgb == DRM_HDMI_BROADCAST_RGB_LIMITED) + return false; + + if (!display->is_hdmi) + return true; + + return drm_default_rgb_quant_range(mode); +} + /** * drm_atomic_helper_connector_hdmi_check() - Helper to check HDMI connector atomic state * @connector: DRM Connector @@ -642,6 +684,8 @@ int drm_atomic_helper_connector_hdmi_check(struct drm_connector *connector, struct drm_connector_state *new_state = drm_atomic_get_new_connector_state(state, connector); + new_state->hdmi.is_full_range = hdmi_is_full_range(connector, new_state); + if (old_state->hdmi.broadcast_rgb != new_state->hdmi.broadcast_rgb) { struct drm_crtc *crtc = new_state->crtc; struct drm_crtc_state *crtc_state; diff --git a/include/drm/drm_atomic_state_helper.h b/include/drm/drm_atomic_state_helper.h index d59d2b3aef9a..8072ac18e536 100644 --- a/include/drm/drm_atomic_state_helper.h +++ b/include/drm/drm_atomic_state_helper.h @@ -88,6 +88,7 @@ void __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state); void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, struct drm_connector_state *state); + void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj, struct drm_private_state *state); diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index 168009f588ab..fc1fa754a40d 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -1053,6 +1053,12 @@ struct drm_connector_state { * Broadcast RGB selection value. */ enum drm_hdmi_broadcast_rgb broadcast_rgb; + + /** + * @is_full_range: Is the output supposed to use a full + * RGB Quantization Range or not? + */ + bool is_full_range; } hdmi; };