Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp814298rdg; Wed, 11 Oct 2023 06:23:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkFhYheJnlC/hU2vK5rLGYXkmpJbCVogqhSymR/LfiUvECCsymXhoQF7z+L5JxfbL49e3k X-Received: by 2002:a17:902:7248:b0:1c1:d730:f0c2 with SMTP id c8-20020a170902724800b001c1d730f0c2mr19980840pll.61.1697030627192; Wed, 11 Oct 2023 06:23:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697030627; cv=none; d=google.com; s=arc-20160816; b=wBxLWFN88IJdwSWJPNJvHV7YyBeK0N6YMtM6OKW/SRvhaeiEkgvFE688rdpyeWFXOz M31qnM+O2vYFsAg/rMR+DnviQG/4Ip2Evs4BSP36S370t+KWMVl4ez1q0wKqJwaR6mg/ l478IJfju2SIic+ijKFXsRjQWbuwYmXSywK70NDJyl8U6TVKhOGqUgMatJo+SIOTs7IC j6V4fCN07yPVDs/JSbM7PM0vrpJo0ql8cD5kLcuiEunIKSxaEFM9UiEVUZrRY5QB06a7 vxG8o8LhbVYiALNe3F9TRDb8nwofOGvgPtZW/9OjqiOJG2gKK5IgU6on/6ifXQAVMB/7 fi4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=aPMFXAItQQgSeDMu106EsctnKTGFX+nLv6VS+2VQ9ec=; fh=4ICepj7NcVp0iYfwtYn/k84hx+OtJ1T1D+vachLc7jU=; b=qyopC57yVsUIRP/Ppe24Y1GhZdiLTHuzvnYPi8QxKMK02xDtPS+q2iiRQ8aD5PGx1d II8m+L5svaX4JMWrI8w1LUM1HVWcP3s8EG7VIWQewo/1oQYvuRUOjW8dxHdu5RRCFkUe tsShqXwLVeKqZhiurW/gOAXvfRxycA1YUcT0ASy3X5fXigHcUcIjQAUZt6gWPQWPSPvm IEtP145dVQfWIkOZauSJViXYo8fnKsBcSf3nI0LevaSvX11nPKstLNvqlmEbGKykH5Ma Y8ZpYlJ8ROeIVxMbvy498H9l3Y7jXdgO3fTWQx2JGhQJCeWtKhIQd1jbqI201vLeQi55 0KdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=WH0kF8xh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id lf4-20020a170902fb4400b001c3a6902ff1si13285173plb.288.2023.10.11.06.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 06:23:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=WH0kF8xh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 37DD3836CE76; Wed, 11 Oct 2023 06:23:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232297AbjJKNXe (ORCPT + 99 others); Wed, 11 Oct 2023 09:23:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231524AbjJKNXd (ORCPT ); Wed, 11 Oct 2023 09:23:33 -0400 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B87A90 for ; Wed, 11 Oct 2023 06:23:30 -0700 (PDT) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-1dd2e4f744dso968125fac.0 for ; Wed, 11 Oct 2023 06:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1697030609; x=1697635409; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=aPMFXAItQQgSeDMu106EsctnKTGFX+nLv6VS+2VQ9ec=; b=WH0kF8xhjYJcbkgydHhlchThr9wz3l+mO5YjSGATOGd9OcrK7UHPihj7x2Nz6Llbsh byHkMW3wPvyGwuLUCXeH5YyIOV4LCvlV/StpECbiMwvfxo9VpVB+/MBNOKJ29OGG/TD6 YlrMXZhSGwhc8GaFSaUiUVhB1ffv95A5BmSiI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697030609; x=1697635409; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aPMFXAItQQgSeDMu106EsctnKTGFX+nLv6VS+2VQ9ec=; b=ms5g6TccJRMBgfMd9mEkIGhFLRuyJDsIen1UawAgQnC5OQ7UOG+5EXLAmN2MwQ3Ft7 aNEPVT4VQ7WR1fDQmYdRHHrxwxukgymSP6BPV0Sa6NdK9Aidqeo0u1j6ULXWydeUB4Ja Q0qR5WmVwlalX7S/e3DOXTYJ9lo/cQZk/zIZm+3R8pdbui/Xp7XieOKWy6BtvJhlSBlX UADj9h5l1RzXRXMMSXpfMlmolt2HIc9gYt/tIx7Lt30kYkm3Z2nDM58ES2Uz3l2T/TW6 SBLZ8XM8LX7kfDj/6wsj8LMIQmyW4JEvCsOa1ySbaXmUJuk9Fy6ojELLWwx2+q+ObYaN Cb2Q== X-Gm-Message-State: AOJu0Yxg4rxUQTm36PAfSpxHX9tjFV1SHBFAf07yBGjmAjZQhUrZu0VY lOe1JfUf2FEQ9T4knIAZ+KA4KMxuNbGA+HEFF8TY/g== X-Received: by 2002:a05:6870:c689:b0:1e1:e6ee:94b6 with SMTP id cv9-20020a056870c68900b001e1e6ee94b6mr23108366oab.4.1697030609252; Wed, 11 Oct 2023 06:23:29 -0700 (PDT) MIME-Version: 1.0 References: <20221207-rpi-hdmi-improvements-v3-0-bdd54f66884e@cerno.tech> <20221207-rpi-hdmi-improvements-v3-3-bdd54f66884e@cerno.tech> In-Reply-To: <20221207-rpi-hdmi-improvements-v3-3-bdd54f66884e@cerno.tech> From: Daniel Vetter Date: Wed, 11 Oct 2023 15:23:18 +0200 Message-ID: Subject: Re: [PATCH v3 3/9] drm/vc4: hdmi: Add Broadcast RGB property to allow override of RGB range To: Maxime Ripard Cc: Emma Anholt , Maxime Ripard , David Airlie , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dave Stevenson , Hans Verkuil Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Wed, 11 Oct 2023 06:23:44 -0700 (PDT) X-Spam-Level: ** On Mon, 6 Mar 2023 at 11:49, Maxime Ripard wrote: > > From: Dave Stevenson > > Copy Intel's "Broadcast RGB" property semantics to add manual override > of the HDMI pixel range for monitors that don't abide by the content > of the AVI Infoframe. > > Signed-off-by: Dave Stevenson > Signed-off-by: Maxime Ripard Stumbled over this grepping around, but would have been nice to lift this into drm code and document the property. It's one of the legacy ones from the table of horrors after all ... Shouldn't be an uapi problem because it's copypasted to much, just not great. -Sima > --- > drivers/gpu/drm/vc4/vc4_hdmi.c | 97 ++++++++++++++++++++++++++++++++++++++++-- > drivers/gpu/drm/vc4/vc4_hdmi.h | 9 ++++ > 2 files changed, 102 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c > index 522cfbc83fe4..d23c0c3df2ee 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.c > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c > @@ -154,10 +154,16 @@ static bool vc4_hdmi_mode_needs_scrambling(const struct drm_display_mode *mode, > } > > static bool vc4_hdmi_is_full_range_rgb(struct vc4_hdmi *vc4_hdmi, > - const struct drm_display_mode *mode) > + struct vc4_hdmi_connector_state *vc4_state) > { > + const struct drm_display_mode *mode = &vc4_hdmi->saved_adjusted_mode; > struct drm_display_info *display = &vc4_hdmi->connector.display_info; > > + if (vc4_state->broadcast_rgb == VC4_HDMI_BROADCAST_RGB_LIMITED) > + return false; > + else if (vc4_state->broadcast_rgb == VC4_HDMI_BROADCAST_RGB_FULL) > + return true; > + > return !display->is_hdmi || > drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL; > } > @@ -528,8 +534,12 @@ static int vc4_hdmi_connector_atomic_check(struct drm_connector *connector, > { > struct drm_connector_state *old_state = > drm_atomic_get_old_connector_state(state, connector); > + struct vc4_hdmi_connector_state *old_vc4_state = > + conn_state_to_vc4_hdmi_conn_state(old_state); > struct drm_connector_state *new_state = > drm_atomic_get_new_connector_state(state, connector); > + struct vc4_hdmi_connector_state *new_vc4_state = > + conn_state_to_vc4_hdmi_conn_state(new_state); > struct drm_crtc *crtc = new_state->crtc; > > if (!crtc) > @@ -562,6 +572,7 @@ static int vc4_hdmi_connector_atomic_check(struct drm_connector *connector, > } > > if (old_state->colorspace != new_state->colorspace || > + old_vc4_state->broadcast_rgb != new_vc4_state->broadcast_rgb || > !drm_connector_atomic_hdr_metadata_equal(old_state, new_state)) { > struct drm_crtc_state *crtc_state; > > @@ -575,6 +586,49 @@ static int vc4_hdmi_connector_atomic_check(struct drm_connector *connector, > return 0; > } > > +static int vc4_hdmi_connector_get_property(struct drm_connector *connector, > + const struct drm_connector_state *state, > + struct drm_property *property, > + uint64_t *val) > +{ > + struct drm_device *drm = connector->dev; > + struct vc4_hdmi *vc4_hdmi = > + connector_to_vc4_hdmi(connector); > + const struct vc4_hdmi_connector_state *vc4_conn_state = > + conn_state_to_vc4_hdmi_conn_state(state); > + > + if (property == vc4_hdmi->broadcast_rgb_property) { > + *val = vc4_conn_state->broadcast_rgb; > + } else { > + drm_dbg(drm, "Unknown property [PROP:%d:%s]\n", > + property->base.id, property->name); > + return -EINVAL; > + } > + > + return 0; > +} > + > +static int vc4_hdmi_connector_set_property(struct drm_connector *connector, > + struct drm_connector_state *state, > + struct drm_property *property, > + uint64_t val) > +{ > + struct drm_device *drm = connector->dev; > + struct vc4_hdmi *vc4_hdmi = > + connector_to_vc4_hdmi(connector); > + struct vc4_hdmi_connector_state *vc4_conn_state = > + conn_state_to_vc4_hdmi_conn_state(state); > + > + if (property == vc4_hdmi->broadcast_rgb_property) { > + vc4_conn_state->broadcast_rgb = val; > + return 0; > + } > + > + drm_dbg(drm, "Unknown property [PROP:%d:%s]\n", > + property->base.id, property->name); > + return -EINVAL; > +} > + > static void vc4_hdmi_connector_reset(struct drm_connector *connector) > { > struct vc4_hdmi_connector_state *old_state = > @@ -594,6 +648,7 @@ static void vc4_hdmi_connector_reset(struct drm_connector *connector) > new_state->base.max_bpc = 8; > new_state->base.max_requested_bpc = 8; > new_state->output_format = VC4_HDMI_OUTPUT_RGB; > + new_state->broadcast_rgb = VC4_HDMI_BROADCAST_RGB_AUTO; > drm_atomic_helper_connector_tv_margins_reset(connector); > } > > @@ -611,6 +666,7 @@ vc4_hdmi_connector_duplicate_state(struct drm_connector *connector) > new_state->tmds_char_rate = vc4_state->tmds_char_rate; > new_state->output_bpc = vc4_state->output_bpc; > new_state->output_format = vc4_state->output_format; > + new_state->broadcast_rgb = vc4_state->broadcast_rgb; > __drm_atomic_helper_connector_duplicate_state(connector, &new_state->base); > > return &new_state->base; > @@ -621,6 +677,8 @@ static const struct drm_connector_funcs vc4_hdmi_connector_funcs = { > .reset = vc4_hdmi_connector_reset, > .atomic_duplicate_state = vc4_hdmi_connector_duplicate_state, > .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, > + .atomic_get_property = vc4_hdmi_connector_get_property, > + .atomic_set_property = vc4_hdmi_connector_set_property, > }; > > static const struct drm_connector_helper_funcs vc4_hdmi_connector_helper_funcs = { > @@ -629,6 +687,33 @@ static const struct drm_connector_helper_funcs vc4_hdmi_connector_helper_funcs = > .atomic_check = vc4_hdmi_connector_atomic_check, > }; > > +static const struct drm_prop_enum_list broadcast_rgb_names[] = { > + { VC4_HDMI_BROADCAST_RGB_AUTO, "Automatic" }, > + { VC4_HDMI_BROADCAST_RGB_FULL, "Full" }, > + { VC4_HDMI_BROADCAST_RGB_LIMITED, "Limited 16:235" }, > +}; > + > +static void > +vc4_hdmi_attach_broadcast_rgb_property(struct drm_device *dev, > + struct vc4_hdmi *vc4_hdmi) > +{ > + struct drm_property *prop = vc4_hdmi->broadcast_rgb_property; > + > + if (!prop) { > + prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, > + "Broadcast RGB", > + broadcast_rgb_names, > + ARRAY_SIZE(broadcast_rgb_names)); > + if (!prop) > + return; > + > + vc4_hdmi->broadcast_rgb_property = prop; > + } > + > + drm_object_attach_property(&vc4_hdmi->connector.base, prop, > + VC4_HDMI_BROADCAST_RGB_AUTO); > +} > + > static int vc4_hdmi_connector_init(struct drm_device *dev, > struct vc4_hdmi *vc4_hdmi) > { > @@ -675,6 +760,8 @@ static int vc4_hdmi_connector_init(struct drm_device *dev, > if (vc4_hdmi->variant->supports_hdr) > drm_connector_attach_hdr_output_metadata_property(connector); > > + vc4_hdmi_attach_broadcast_rgb_property(dev, vc4_hdmi); > + > drm_connector_attach_encoder(connector, encoder); > > return 0; > @@ -829,7 +916,7 @@ static void vc4_hdmi_set_avi_infoframe(struct drm_encoder *encoder) > > drm_hdmi_avi_infoframe_quant_range(&frame.avi, > connector, mode, > - vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode) ? > + vc4_hdmi_is_full_range_rgb(vc4_hdmi, vc4_state) ? > HDMI_QUANTIZATION_RANGE_FULL : > HDMI_QUANTIZATION_RANGE_LIMITED); > drm_hdmi_avi_infoframe_colorimetry(&frame.avi, cstate); > @@ -1069,6 +1156,8 @@ static void vc4_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi, > struct drm_connector_state *state, > const struct drm_display_mode *mode) > { > + struct vc4_hdmi_connector_state *vc4_state = > + conn_state_to_vc4_hdmi_conn_state(state); > struct drm_device *drm = vc4_hdmi->connector.dev; > unsigned long flags; > u32 csc_ctl; > @@ -1082,7 +1171,7 @@ static void vc4_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi, > csc_ctl = VC4_SET_FIELD(VC4_HD_CSC_CTL_ORDER_BGR, > VC4_HD_CSC_CTL_ORDER); > > - if (!vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode)) { > + if (!vc4_hdmi_is_full_range_rgb(vc4_hdmi, vc4_state)) { > /* CEA VICs other than #1 requre limited range RGB > * output unless overridden by an AVI infoframe. > * Apply a colorspace conversion to squash 0-255 down > @@ -1235,7 +1324,7 @@ static void vc5_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi, > case VC4_HDMI_OUTPUT_RGB: > if_xbar = 0x354021; > > - if (!vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode)) > + if (!vc4_hdmi_is_full_range_rgb(vc4_hdmi, vc4_state)) > vc5_hdmi_set_csc_coeffs(vc4_hdmi, vc5_hdmi_csc_full_rgb_to_limited_rgb); > else > vc5_hdmi_set_csc_coeffs(vc4_hdmi, vc5_hdmi_csc_full_rgb_unity); > diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.h b/drivers/gpu/drm/vc4/vc4_hdmi.h > index 5d249ac54cd1..89800c48aa24 100644 > --- a/drivers/gpu/drm/vc4/vc4_hdmi.h > +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h > @@ -117,6 +117,12 @@ enum vc4_hdmi_output_format { > VC4_HDMI_OUTPUT_YUV420, > }; > > +enum vc4_hdmi_broadcast_rgb { > + VC4_HDMI_BROADCAST_RGB_AUTO, > + VC4_HDMI_BROADCAST_RGB_FULL, > + VC4_HDMI_BROADCAST_RGB_LIMITED, > +}; > + > /* General HDMI hardware state. */ > struct vc4_hdmi { > struct vc4_hdmi_audio audio; > @@ -129,6 +135,8 @@ struct vc4_hdmi { > > struct delayed_work scrambling_work; > > + struct drm_property *broadcast_rgb_property; > + > struct i2c_adapter *ddc; > void __iomem *hdmicore_regs; > void __iomem *hd_regs; > @@ -238,6 +246,7 @@ struct vc4_hdmi_connector_state { > unsigned long long tmds_char_rate; > unsigned int output_bpc; > enum vc4_hdmi_output_format output_format; > + enum vc4_hdmi_broadcast_rgb broadcast_rgb; > }; > > #define conn_state_to_vc4_hdmi_conn_state(_state) \ > > -- > 2.39.2 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch