From patchwork Thu Feb 22 18:13:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 204976 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp130019dyb; Thu, 22 Feb 2024 10:29:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVvqDzOoVQh5CgRbkm3BGQ5di68y1oKQ8+3gQVKumVcO28kMnS5HhbS8wRFY35TH+mEYlyAkwK2HHMylGtHuU4bxhPqYQ== X-Google-Smtp-Source: AGHT+IGo8bFYz39gcYkHYgkz/kumxpO8mkq+obS1cwM/nqw3w7KNKegRuhrw7nwc+6xIoADnbThW X-Received: by 2002:a17:90b:2243:b0:29a:6b65:3e86 with SMTP id hk3-20020a17090b224300b0029a6b653e86mr641706pjb.17.1708626596347; Thu, 22 Feb 2024 10:29:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708626596; cv=pass; d=google.com; s=arc-20160816; b=CUC5z1aMOBTeq0nhQV7YKvcdI2L6Y7l/HSb2JeQubN5NTnC3jelzbF4ww0z7LQRCmn kBiXunkNi5NvYD8UaKewK3PqZTTgcHqzsbL3zCaA/qC5Fo6AIxuhgdx2mOXgaEDgelBT NNDBcqKfXv/nY4OUP+jCkV7BIvYnX/voVjssyb/zA8Hop0AN4nQ0kA5kXSXrxyfDN09c wmeHAy/eFX+1EiCQVw3DS9ra3K70cy1mG7iZ9gWFb9aWqXRncdITVXtnCYlIPLZhqSQM bgtzmz31mj/jIF8anMSluSzNi0bCV/WrimZaoRHuUgwOud382+NRJ9NIfOybAASxaLY7 2tgg== 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=fLKeVAr2dk6pbz0au6ltyMpszNJ95+isirPVuX+EgRo=; fh=8wcoxKk21hICD+6obVirG13fsSSMhKa/pufykSf87d0=; b=qyVTH+QLVmE2MaqUEJByNCZtNrmHTDpvFjS2kPoUqDcCAluSr6GpNm+bvXb3Pn6faH pU8/ozEwqu1sug9lestUFpXiwPQTm8R3uGvd0CrSPxfhSZLENabbeLVpEbIrbdB+5duw r8wjzF6QfpbvBLjzLSm0Fr18SJlIEa8oJL8er2ri6r5VAxxZ1mL4S4JanMMFvmmxSb4X 1D7ArewAPnfEIIrvoh9pmwkyz1FXnalkEAgcTzbPTI9n5bSwfMntJp1NK1nJJO9cZ3Gm N4FRoVClU3cV9Qr2X0YgeifB1wDvH8w6R+8dFoTqWo4mlB8/APfYmqqjL1jypY6nf/DT i79g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KbCrI6L1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77080-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77080-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a8-20020a17090acb8800b002993602c9c8si4032303pju.68.2024.02.22.10.29.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:29:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77080-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KbCrI6L1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77080-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77080-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B5D9AB22E51 for ; Thu, 22 Feb 2024 18:21:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C24B66AFB9; Thu, 22 Feb 2024 18:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KbCrI6L1" 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 7E42915E5C3; Thu, 22 Feb 2024 18:14:54 +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=1708625694; cv=none; b=R0GqsT/CVxmtgz/vT5MtAKnk8sUFrLQ672+BryJFUXRkRvb7ylK7MhhfPijNgOm+YggVKxM8VCrs9xywlx4pfoc29UmOHJoA1wQwOwfRcMRZ7uu7x5vAecMNzvY/Ncpr6npxcttkubLoE3WHMR/DONC1bDe3PfQ8Iby6RKGoP/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625694; c=relaxed/simple; bh=pSNXmp0c3bxRBDh2tzEv2eshg+rV1t1u/wJNsU+JbLE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ICIxrgnyWYSs6+Fx+YQwlz4Wzvv8jGJScdaGYPQ1l6jVAKVmWojGWsfCp9eaCL3ReKLmybvLNZGUdGJY6gZPdk7yVetGL+piVFViGXDBKHy7sghh6ikhPE3SlIkWjfTPwx/J6fpriees1eKxZROc1xLlMjPFsIrOFmY2T1inSQg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KbCrI6L1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB444C43399; Thu, 22 Feb 2024 18:14:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708625694; bh=pSNXmp0c3bxRBDh2tzEv2eshg+rV1t1u/wJNsU+JbLE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KbCrI6L1xZOKL9hHVVKrlVdFJTXH5iTlEvwUTJAtgDU+crqujjOdDgdB++PBFSny1 CkHjIOeAh5NyPaegeAvZw/XvJRUIrBnVk81k3BOTP4L4w3ye7fWfJuTFKPybuglv5z vd5/sas316sT8eYCEC/KFN6ocZB+d5hblXsQvi7rlbCqo5G5R7tFkCM+X6feCLp+++ D7h0Nw6Q3QBoFU9KsYBIUEKaYv86i28yzXdVE8Gng9xIqRD76oVN27SQpWCuRoQS6D +kD9DEd6wcmFKjTzVdPpHsJzVNA04xYyhckOD1wANNZMrVTHEryIYI166B1HFWRLYn pI3zTZC3FKghQ== From: Maxime Ripard Date: Thu, 22 Feb 2024 19:13:55 +0100 Subject: [PATCH v7 09/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: <20240222-kms-hdmi-connector-state-v7-9-8f4af575fce2@kernel.org> References: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@kernel.org> In-Reply-To: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , Sebastian Wick , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , 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=7393; i=mripard@kernel.org; h=from:subject:message-id; bh=pSNXmp0c3bxRBDh2tzEv2eshg+rV1t1u/wJNsU+JbLE=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKnX+97Z3Zk2rUT6zdWeoBmT95Re/tTqdmmSHOf9gnld8 xe8NVzq2VHKwiDGxSArpsgSI2y+JO7UrNedbHzzYOawMoEMYeDiFICJVNUwMnTa+sV6dn9S1Ptq KV947HjbRt/w64dMpDvYO9c0nPp3RYSRYfL5k5xKofIb1Zdbpml5cYT840rUF2yMDiqMi3v8tO4 4AwA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791624841384275725 X-GMAIL-MSGID: 1791624841384275725 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 | 5 +++++ drivers/gpu/drm/drm_atomic_state_helper.c | 20 ++++++++++++++++++++ drivers/gpu/drm/drm_connector.c | 20 +++++++++++++++++++- drivers/gpu/drm/tests/drm_connector_test.c | 12 ++++++++---- include/drm/drm_connector.h | 12 +++++++++++- 5 files changed, 63 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index a91737adf8e7..4e11cfb4518b 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -1143,6 +1143,11 @@ static void drm_atomic_connector_print_state(struct drm_printer *p, drm_printf(p, "\tmax_requested_bpc=%d\n", state->max_requested_bpc); 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) { + drm_printf(p, "\toutput_bpc=%u\n", state->hdmi.output_bpc); + } + if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK) if (state->writeback_job && state->writeback_job->fb) drm_printf(p, "\tfb=%d\n", state->writeback_job->fb->base.id); diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c index 7ad1dffe66d9..460454904fe3 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -584,6 +584,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; } EXPORT_SYMBOL(__drm_atomic_helper_connector_hdmi_reset); @@ -651,6 +655,22 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_tv_check); int drm_atomic_helper_connector_hdmi_check(struct drm_connector *connector, struct drm_atomic_state *state) { + struct drm_connector_state *old_state = + drm_atomic_get_old_connector_state(state, connector); + struct drm_connector_state *new_state = + drm_atomic_get_new_connector_state(state, connector); + + if (old_state->hdmi.output_bpc != new_state->hdmi.output_bpc) { + struct drm_crtc *crtc = new_state->crtc; + struct drm_crtc_state *crtc_state; + + crtc_state = drm_atomic_get_crtc_state(state, crtc); + if (IS_ERR(crtc_state)) + return PTR_ERR(crtc_state); + + crtc_state->mode_changed = true; + } + return 0; } EXPORT_SYMBOL(drm_atomic_helper_connector_hdmi_check); diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index d9961cce8245..da51a2bcb978 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_connector_test.c b/drivers/gpu/drm/tests/drm_connector_test.c index 8f070cacab3b..d8d30aea9fdc 100644 --- a/drivers/gpu/drm/tests/drm_connector_test.c +++ b/drivers/gpu/drm/tests/drm_connector_test.c @@ -184,7 +184,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); } @@ -200,7 +201,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); } @@ -217,7 +219,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); } @@ -248,7 +251,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); } diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index 000a2a156619..d4d2ae15bc1e 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -1037,6 +1037,10 @@ struct drm_connector_state { * @drm_atomic_helper_connector_hdmi_check(). */ struct { + /** + * @output_bpc: Bits per color channel to output. + */ + unsigned int output_bpc; } hdmi; }; @@ -1682,6 +1686,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. @@ -1915,7 +1924,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);