From patchwork Mon Feb 12 13:12:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 199756 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2420235dyd; Mon, 12 Feb 2024 05:18:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IEf1LubZOtQ0VJFzMiXugLUpAnlInPFuQnVv+sqI7HhG7NpZ1s/uvcLB0qaYThpVlL4o6M4 X-Received: by 2002:a05:6214:519e:b0:68d:14ed:13bd with SMTP id kl30-20020a056214519e00b0068d14ed13bdmr2411028qvb.46.1707743895211; Mon, 12 Feb 2024 05:18:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707743895; cv=pass; d=google.com; s=arc-20160816; b=o5v7/bspeR/H97q6SQv7RYQxpkAtrVM/uNrd5BKrta86BogZs7KpARX/GPdLhY41qO QQbjGlEs3fDqHMUDPH5eVJjCOoNWhv+QVuH3J6b+Ds6g+QFmxKSpG8daEB3MZKanxFYx T1IXshaTyu1fpaEsyOxDaFLwm8Z9iEin2gLukFSxuNzY6M7u0LKNcqh1NDF+KF8GI0T5 7mWPKSQaPACUTe45C8+LEsDFclFMZXZZf37oEdeUFQeT33Z06/5c87nf836IM+/KH+YP hOvX4R1k7ymJB6/oCme2ZApxOW+J/sPThtq7W9Lu+meLI6dd9VsK71aLcX8FKwl/k3iS jrGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=5CipoO7iOxkxnFlSNVnwJjmMz18txywoeKvk5Gr0HrA=; fh=SeXJDGM+w99but812TYddbNFsbjxhWHOSPFA4+ykR90=; b=lEAD8/PsEBBo+Z5dtu0cOvFFO2maBkT6qFdfgKCiJ+iVUwLeG+7+pXVhvZbCEUt6ub QLnwobzvbiJFgsANUc0R9AXNhG4v6124LGti9f/tpiRBkVUBJ7bRoWBVttwfsiy/8kq6 loTJc8de+YsW/0CJOJby+NRLJCJ23sfsVKt4jcaDJ3F3/dSAGDwKilaEs7au8C8PVPYb soI9avdXEZOWqsxTiNmiRbihL+lqdyIWLCKO6ZbvSNyfQ6/QKfbowtVecQWbYwL9x62X GejPjDDdPN298cFHjWjTc7E4/wjDQu5JzZMtuSUMnSBe91f07D6ZQ2gyBk5UHU3NS5kv hrbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gxNV4ehr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61627-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61627-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCVWfWDPqMEwsnaD1AyHUmDOlGGTrmB9TJX3zAyI62xYek4cgpJcdFbVJ0AMSWB3Vm/qcHNYIRcqGKvmfzfdqFf6eYdlfg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jo11-20020a056214500b00b0068c8bf7a3d8si350413qvb.334.2024.02.12.05.18.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 05:18:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61627-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gxNV4ehr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-61627-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61627-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E7E1F1C21A02 for ; Mon, 12 Feb 2024 13:18:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 764F13EA76; Mon, 12 Feb 2024 13:14:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gxNV4ehr" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E80FE3DB92; Mon, 12 Feb 2024 13:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707743646; cv=none; b=LTPtz6bAW1SvyyA1NpDYTd/pyB8Y9sdh3oyGfcKQDz7qj6tYSm1vHxrhvYONSgf2VCRSyZamUK9NxB2FIIImNZBYo8WS/5SabYUC+6q0E+SQp2xftrQyx3QRn6r0J7tW/AoYm2WxC/7/QhYbPdbETSKDCPm88yaAf2b5rcjJj2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707743646; c=relaxed/simple; bh=XvHRjcHEGiov3nC8A3+QY9gmoUVMU7VKG4/iarE/bio=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mFsqHvKwYLa9jpVROOBokQGErUnkKcwg96mhlCivnDAQVXNginyejq7XmZ3TmKOrbPDTqfKB0CRtEQVVqbmPa6mOd9C+I57Q49JD8W4JjTFdCAR7QyPkeQ/264PYjZgtU5axnm/DCo7wAwesPngXSX05G/ts89IUpyaKmUKni7o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gxNV4ehr; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 250ABC433F1; Mon, 12 Feb 2024 13:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707743645; bh=XvHRjcHEGiov3nC8A3+QY9gmoUVMU7VKG4/iarE/bio=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gxNV4ehrJRbEcJVUpKlsyn482unviXCacOgGYQ/B6Zluddv9FYzW6QKAZrGdJkCuE bK4bzpkncTD4+x0qzTF4iyGLpWgMvv9HK087A4/MP4x2A3VDOwQJ04UymyF3zSeFSg ZSYPLBvhf99V32yLbdrE3xSmWcQb5UwAioPo7M1q2J/WF5HH3veduwmaBtv9F8DN0c of1PS0uNWHNhSI5Imm4VEm5+ijh6qBf2xAixvpwLxJiBf8l3vS40/AHhncovmmLWw6 183pRJ6kwfGyVUSXNmfHng7j6D/wTVbBG4bjI94DL7Vt9cTTDURSmj4RsPqn7cVGgN CXGIF9oAgFnwA== From: Maxime Ripard Date: Mon, 12 Feb 2024 14:12:56 +0100 Subject: [PATCH v6 13/36] drm/connector: hdmi: Add output BPC to the connector state Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240212-kms-hdmi-connector-state-v6-13-f4bcdc979e6f@kernel.org> References: <20240212-kms-hdmi-connector-state-v6-0-f4bcdc979e6f@kernel.org> In-Reply-To: <20240212-kms-hdmi-connector-state-v6-0-f4bcdc979e6f@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 , Dave Stevenson X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=11447; i=mripard@kernel.org; h=from:subject:message-id; bh=XvHRjcHEGiov3nC8A3+QY9gmoUVMU7VKG4/iarE/bio=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmnJNNWNDXxTDvJsi5rw/bfF+a97V8jvu7I4m2Hz53fs lXkPWPDyo5SFgYxLgZZMUWWGGHzJXGnZr3uZOObBzOHlQlkCAMXpwBMZPk/Robz8fcS6w40r03v 9Dpb+ibVwsNLeJLxYf8FNi/vzF4Yo7aTkeHZ63cs841Kn1spcVSkTw854L+Lab/rR+Hk6tA46VU zjrECAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790699262689121221 X-GMAIL-MSGID: 1790699262689121221 We'll add automatic selection of the output BPC in a following patch, but let's add it to the HDMI connector state already. Reviewed-by: Dave Stevenson Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_atomic.c | 1 + drivers/gpu/drm/drm_atomic_state_helper.c | 7 ++++++- drivers/gpu/drm/drm_connector.c | 20 +++++++++++++++++- .../gpu/drm/tests/drm_atomic_state_helper_test.c | 24 ++++++++++++---------- drivers/gpu/drm/tests/drm_connector_test.c | 15 +++++++++----- include/drm/drm_connector.h | 13 +++++++++++- 6 files changed, 61 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 0c283964cee0..5fcdab90c793 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1148,6 +1148,7 @@ static void drm_atomic_connector_print_state(struct drm_printer *p, 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'); + drm_printf(p, "\toutput_bpc=%u\n", state->hdmi.output_bpc); } if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK) diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c index 08db9956840b..2025d053e54f 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -585,6 +585,10 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_tv_reset); void __drm_atomic_helper_connector_hdmi_reset(struct drm_connector *connector, struct drm_connector_state *new_state) { + unsigned int max_bpc = connector->max_bpc; + + new_state->max_bpc = max_bpc; + new_state->max_requested_bpc = max_bpc; new_state->hdmi.broadcast_rgb = DRM_HDMI_BROADCAST_RGB_AUTO; } EXPORT_SYMBOL(__drm_atomic_helper_connector_hdmi_reset); @@ -701,7 +705,8 @@ int drm_atomic_helper_connector_hdmi_check(struct drm_connector *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) { + if (old_state->hdmi.broadcast_rgb != new_state->hdmi.broadcast_rgb || + old_state->hdmi.output_bpc != new_state->hdmi.output_bpc) { struct drm_crtc *crtc = new_state->crtc; struct drm_crtc_state *crtc_state; diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index 53abf213a045..ca39fd027e20 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -459,6 +459,7 @@ EXPORT_SYMBOL(drmm_connector_init); * @funcs: callbacks for this connector * @connector_type: user visible type of the connector * @ddc: optional pointer to the associated ddc adapter + * @max_bpc: Maximum bits per char the HDMI connector supports * * Initialises a preallocated HDMI connector. Connectors can be * subclassed as part of driver connector objects. @@ -475,7 +476,8 @@ int drmm_connector_hdmi_init(struct drm_device *dev, struct drm_connector *connector, const struct drm_connector_funcs *funcs, int connector_type, - struct i2c_adapter *ddc) + struct i2c_adapter *ddc, + unsigned int max_bpc) { int ret; @@ -483,10 +485,26 @@ int drmm_connector_hdmi_init(struct drm_device *dev, connector_type == DRM_MODE_CONNECTOR_HDMIB)) return -EINVAL; + if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12)) + return -EINVAL; + ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc); if (ret) return ret; + /* + * drm_connector_attach_max_bpc_property() requires the + * connector to have a state. + */ + if (connector->funcs->reset) + connector->funcs->reset(connector); + + drm_connector_attach_max_bpc_property(connector, 8, max_bpc); + connector->max_bpc = max_bpc; + + if (max_bpc > 8) + drm_connector_attach_hdr_output_metadata_property(connector); + return 0; } EXPORT_SYMBOL(drmm_connector_hdmi_init); diff --git a/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c b/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c index 7750c3d214a4..64ba1f6256ba 100644 --- a/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c +++ b/drivers/gpu/drm/tests/drm_atomic_state_helper_test.c @@ -146,7 +146,8 @@ static const struct drm_connector_funcs dummy_connector_funcs = { static struct drm_atomic_helper_connector_hdmi_priv * -drm_atomic_helper_connector_hdmi_init(struct kunit *test) +drm_atomic_helper_connector_hdmi_init(struct kunit *test, + unsigned int max_bpc) { struct drm_atomic_helper_connector_hdmi_priv *priv; struct drm_connector *conn; @@ -188,7 +189,8 @@ drm_atomic_helper_connector_hdmi_init(struct kunit *test) ret = drmm_connector_hdmi_init(drm, conn, &dummy_connector_funcs, DRM_MODE_CONNECTOR_HDMIA, - NULL); + NULL, + max_bpc); KUNIT_ASSERT_EQ(test, ret, 0); drm_connector_helper_add(conn, &dummy_connector_helper_funcs); @@ -223,7 +225,7 @@ static void drm_test_check_broadcast_rgb_crtc_mode_changed(struct kunit *test) struct drm_crtc *crtc; int ret; - priv = drm_atomic_helper_connector_hdmi_init(test); + priv = drm_atomic_helper_connector_hdmi_init(test, 8); KUNIT_ASSERT_NOT_NULL(test, priv); ctx = drm_kunit_helper_acquire_ctx_alloc(test); @@ -284,7 +286,7 @@ static void drm_test_check_broadcast_rgb_crtc_mode_not_changed(struct kunit *tes struct drm_crtc *crtc; int ret; - priv = drm_atomic_helper_connector_hdmi_init(test); + priv = drm_atomic_helper_connector_hdmi_init(test, 8); KUNIT_ASSERT_NOT_NULL(test, priv); ctx = drm_kunit_helper_acquire_ctx_alloc(test); @@ -345,7 +347,7 @@ static void drm_test_check_broadcast_rgb_auto_cea_mode(struct kunit *test) struct drm_crtc *crtc; int ret; - priv = drm_atomic_helper_connector_hdmi_init(test); + priv = drm_atomic_helper_connector_hdmi_init(test, 8); KUNIT_ASSERT_NOT_NULL(test, priv); conn = &priv->connector; @@ -399,7 +401,7 @@ static void drm_test_check_broadcast_rgb_auto_cea_mode_vic_1(struct kunit *test) struct drm_crtc *crtc; int ret; - priv = drm_atomic_helper_connector_hdmi_init(test); + priv = drm_atomic_helper_connector_hdmi_init(test, 8); KUNIT_ASSERT_NOT_NULL(test, priv); conn = &priv->connector; @@ -452,7 +454,7 @@ static void drm_test_check_broadcast_rgb_full_cea_mode(struct kunit *test) struct drm_crtc *crtc; int ret; - priv = drm_atomic_helper_connector_hdmi_init(test); + priv = drm_atomic_helper_connector_hdmi_init(test, 8); KUNIT_ASSERT_NOT_NULL(test, priv); conn = &priv->connector; @@ -508,7 +510,7 @@ static void drm_test_check_broadcast_rgb_full_cea_mode_vic_1(struct kunit *test) struct drm_crtc *crtc; int ret; - priv = drm_atomic_helper_connector_hdmi_init(test); + priv = drm_atomic_helper_connector_hdmi_init(test, 8); KUNIT_ASSERT_NOT_NULL(test, priv); conn = &priv->connector; @@ -563,7 +565,7 @@ static void drm_test_check_broadcast_rgb_limited_cea_mode(struct kunit *test) struct drm_crtc *crtc; int ret; - priv = drm_atomic_helper_connector_hdmi_init(test); + priv = drm_atomic_helper_connector_hdmi_init(test, 8); KUNIT_ASSERT_NOT_NULL(test, priv); conn = &priv->connector; @@ -619,7 +621,7 @@ static void drm_test_check_broadcast_rgb_limited_cea_mode_vic_1(struct kunit *te struct drm_crtc *crtc; int ret; - priv = drm_atomic_helper_connector_hdmi_init(test); + priv = drm_atomic_helper_connector_hdmi_init(test, 8); KUNIT_ASSERT_NOT_NULL(test, priv); conn = &priv->connector; @@ -684,7 +686,7 @@ static void drm_test_check_broadcast_rgb_value(struct kunit *test) struct drm_connector_state *conn_state; struct drm_connector *conn; - priv = drm_atomic_helper_connector_hdmi_init(test); + priv = drm_atomic_helper_connector_hdmi_init(test, 8); KUNIT_ASSERT_NOT_NULL(test, priv); conn = &priv->connector; diff --git a/drivers/gpu/drm/tests/drm_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c index 41d33dea30af..96b19a5954b4 100644 --- a/drivers/gpu/drm/tests/drm_connector_test.c +++ b/drivers/gpu/drm/tests/drm_connector_test.c @@ -186,7 +186,8 @@ static void drm_test_connector_hdmi_init_valid(struct kunit *test) ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, &dummy_funcs, DRM_MODE_CONNECTOR_HDMIA, - &priv->ddc); + &priv->ddc, + 8); KUNIT_EXPECT_EQ(test, ret, 0); } @@ -202,7 +203,8 @@ static void drm_test_connector_hdmi_init_null_ddc(struct kunit *test) ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, &dummy_funcs, DRM_MODE_CONNECTOR_HDMIA, - NULL); + NULL, + 8); KUNIT_EXPECT_EQ(test, ret, 0); } @@ -219,7 +221,8 @@ static void drm_test_connector_hdmi_init_type_valid(struct kunit *test) ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, &dummy_funcs, connector_type, - &priv->ddc); + &priv->ddc, + 8); KUNIT_EXPECT_EQ(test, ret, 0); } @@ -250,7 +253,8 @@ static void drm_test_connector_hdmi_init_type_invalid(struct kunit *test) ret = drmm_connector_hdmi_init(&priv->drm, &priv->connector, &dummy_funcs, connector_type, - &priv->ddc); + &priv->ddc, + 8); KUNIT_EXPECT_LT(test, ret, 0); } @@ -447,7 +451,8 @@ static void drm_test_drm_connector_attach_broadcast_rgb_property_hdmi_connector( ret = drmm_connector_hdmi_init(&priv->drm, connector, &dummy_funcs, DRM_MODE_CONNECTOR_HDMIA, - &priv->ddc); + &priv->ddc, + 8); KUNIT_EXPECT_EQ(test, ret, 0); ret = drm_connector_attach_broadcast_rgb_property(connector); diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index 76eecd449fb8..1b1b6aed04ee 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -1072,6 +1072,11 @@ struct drm_connector_state { * RGB Quantization Range or not? */ bool is_full_range; + + /** + * @output_bpc: Bits per color channel to output. + */ + unsigned int output_bpc; } hdmi; }; @@ -1717,6 +1722,11 @@ struct drm_connector { */ struct drm_property_blob *path_blob_ptr; + /** + * @max_bpc: Maximum bits per color channel the connector supports. + */ + unsigned int max_bpc; + /** * @max_bpc_property: Default connector property for the max bpc to be * driven out of the connector. @@ -1956,7 +1966,8 @@ int drmm_connector_hdmi_init(struct drm_device *dev, struct drm_connector *connector, const struct drm_connector_funcs *funcs, int connector_type, - struct i2c_adapter *ddc); + struct i2c_adapter *ddc, + unsigned int max_bpc); void drm_connector_attach_edid_property(struct drm_connector *connector); int drm_connector_register(struct drm_connector *connector); void drm_connector_unregister(struct drm_connector *connector);