Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3726535pxj; Tue, 15 Jun 2021 07:24:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwloIlUS2Ll2Nh0tvH105OHiEhxXay9xEbwPTYNgERHm5bKYITUdA2cZ/hpkJs1GBYqPHNn X-Received: by 2002:aa7:db94:: with SMTP id u20mr23692071edt.381.1623767061150; Tue, 15 Jun 2021 07:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623767061; cv=none; d=google.com; s=arc-20160816; b=JfjrHFa9rcS+wQdZth+U+Yp59W6LGbR9ZEgGvziRFI/HSHPLlWSIcneiS4nixt89CB bEW14XjArLQGUDm8uvd4GAsBv7lh5b5Ksal2758s0pvhKX0i7F5WEpvNie2jzzXOzyo/ uisSrYKcVIWzqNsg3NGSOSyILWechLyw3kjcM8UAd87z2wyTh/H7FbuY7UAtyHZOMQD6 7uFW0GHnmcCW9xmX50a+sIV+F91QZs6vb59waCpsNM7XH3oS1P0qq8m48zc24WkUN/D8 lk/84gfRDh1VN9PytTpZ5+N6RwtZQTmY4yf6eei97gjykVcZi/mKwWlhFIBmfcWooaRo h7FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=igIcqI717PF+KSIpQzHGGECyoj6tZQU4pHwtQvfRRC4=; b=Ycw0T52bA3UgG1YjXCIwg42bz+7bolnpydKwr31llNPCPNlEkUp9PdBKZkGbHlrbeX W4hXg2qFGyQmQLU3P+ldfCTmEmMfwJtLQiwvZtLaKHIxiAmDIxnXqvDdPMoK6RavMBGH mL2TN7UOs1CZRjyKCfZNeLggSYVy3ryCp0AGHxXcbLiRvHhRZAGWhqr5SdJvplBvnFzE NfhXIV8o9swgIMVlurVwHhudcv/3aaXr0qGaAhIHtmIm7oBb7bPQ4LQNzi8G9tYVkI3s lev26pDenxx6190GLz7xxrRk9J2Q2fnAZgYEli+k++0Av2cjvUbOdZpvlhmXTgJJWFSc KfVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si14101413edy.330.2021.06.15.07.23.57; Tue, 15 Jun 2021 07:24:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231881AbhFOOW4 (ORCPT + 99 others); Tue, 15 Jun 2021 10:22:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231726AbhFOOUu (ORCPT ); Tue, 15 Jun 2021 10:20:50 -0400 Received: from srv6.fidu.org (srv6.fidu.org [IPv6:2a01:4f8:231:de0::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2164BC0611C3 for ; Tue, 15 Jun 2021 07:14:50 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by srv6.fidu.org (Postfix) with ESMTP id E18C2C800BA; Tue, 15 Jun 2021 16:14:38 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at srv6.fidu.org Received: from srv6.fidu.org ([127.0.0.1]) by localhost (srv6.fidu.org [127.0.0.1]) (amavisd-new, port 10026) with LMTP id UpiFaJekt_VD; Tue, 15 Jun 2021 16:14:38 +0200 (CEST) Received: from wsembach-tuxedo.fritz.box (p200300e37F3949009F7CF2Abd5Da2787.dip0.t-ipconnect.de [IPv6:2003:e3:7f39:4900:9f7c:f2ab:d5da:2787]) (Authenticated sender: wse@tuxedocomputers.com) by srv6.fidu.org (Postfix) with ESMTPA id 6A7CEC800B5; Tue, 15 Jun 2021 16:14:38 +0200 (CEST) From: Werner Sembach To: harry.wentland@amd.com, sunpeng.li@amd.com, alexander.deucher@amd.com, christian.koenig@amd.com, airlied@linux.ie, daniel@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org Cc: Werner Sembach Subject: [PATCH v3 12/14] drm/uAPI: Add "preferred color format" drm property as setting for userspace Date: Tue, 15 Jun 2021 16:14:23 +0200 Message-Id: <20210615141426.6001-13-wse@tuxedocomputers.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615141426.6001-1-wse@tuxedocomputers.com> References: <20210615141426.6001-1-wse@tuxedocomputers.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new general drm property "preferred color format" which can be used by userspace to tell the graphic drivers to which color format to use. Possible options are: - auto (default/current behaviour) - rgb - ycbcr444 - ycbcr422 (not supported by both amdgpu and i915) - ycbcr420 In theory the auto option should choose the best available option for the current setup, but because of bad internal conversion some monitors look better with rgb and some with ycbcr444. Also, because of bad shielded connectors and/or cables, it might be preferable to use the less bandwidth heavy ycbcr422 and ycbcr420 formats for a signal that is less deceptible to interference. In the future, automatic color calibration for screens might also depend on this option being available. Signed-off-by: Werner Sembach --- drivers/gpu/drm/drm_atomic_helper.c | 4 +++ drivers/gpu/drm/drm_atomic_uapi.c | 4 +++ drivers/gpu/drm/drm_connector.c | 46 ++++++++++++++++++++++++++++- include/drm/drm_connector.h | 17 +++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index bc3487964fb5..90d62f305257 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -687,6 +687,10 @@ drm_atomic_helper_check_modeset(struct drm_device *dev, if (old_connector_state->max_requested_bpc != new_connector_state->max_requested_bpc) new_crtc_state->connectors_changed = true; + + if (old_connector_state->preferred_color_format != + new_connector_state->preferred_color_format) + new_crtc_state->connectors_changed = true; } if (funcs->atomic_check) diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c index 438e9585b225..c536f5e22016 100644 --- a/drivers/gpu/drm/drm_atomic_uapi.c +++ b/drivers/gpu/drm/drm_atomic_uapi.c @@ -796,6 +796,8 @@ static int drm_atomic_connector_set_property(struct drm_connector *connector, fence_ptr); } else if (property == connector->max_bpc_property) { state->max_requested_bpc = val; + } else if (property == connector->preferred_color_format_property) { + state->preferred_color_format = val; } else if (connector->funcs->atomic_set_property) { return connector->funcs->atomic_set_property(connector, state, property, val); @@ -873,6 +875,8 @@ drm_atomic_connector_get_property(struct drm_connector *connector, *val = 0; } else if (property == connector->max_bpc_property) { *val = state->max_requested_bpc; + } else if (property == connector->preferred_color_format_property) { + *val = state->preferred_color_format; } else if (connector->funcs->atomic_get_property) { return connector->funcs->atomic_get_property(connector, state, property, val); diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index b4aff7d6910f..1dc537514c71 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -889,6 +889,14 @@ static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = { { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */ }; +static const struct drm_prop_enum_list drm_preferred_color_format_enum_list[] = { + { 0, "auto" }, + { DRM_COLOR_FORMAT_RGB444, "rgb" }, + { DRM_COLOR_FORMAT_YCRCB444, "ycbcr444" }, + { DRM_COLOR_FORMAT_YCRCB422, "ycbcr422" }, + { DRM_COLOR_FORMAT_YCRCB420, "ycbcr420" }, +}; + static const struct drm_prop_enum_list drm_active_color_format_enum_list[] = { { 0, "unknown" }, { DRM_COLOR_FORMAT_RGB444, "rgb" }, @@ -1219,11 +1227,19 @@ static const struct drm_prop_enum_list dp_colorspaces[] = { * Drivers shall use drm_connector_attach_active_bpc_property() to install * this property. * + * preferred color format: + * This property is used by userspace to change the used color format. When + * used the driver will use the selected format if valid for the hardware, + * sink, and current resolution and refresh rate combination. Drivers to + * use the function drm_connector_attach_preferred_color_format_property() + * to create and attach the property to the connector during + * initialization. + * * active color format: * This read-only property tells userspace the color format actually used * by the hardware display engine on "the cable" on a connector. The chosen * value depends on hardware capabilities, both display engine and - * connected monitor. Drivers shall use + * connected monitor, and the "preferred color format". Drivers shall use * drm_connector_attach_active_color_format_property() to install this * property. * @@ -2232,6 +2248,34 @@ void drm_connector_set_active_bpc_property(struct drm_connector *connector, int } EXPORT_SYMBOL(drm_connector_set_active_bpc_property); +/** + * drm_connector_attach_preferred_color_format_property - attach "preferred color format" property + * @connector: connector to attach active color format property on. + * + * This is used to add support for selecting a color format on a connector. + * + * Returns: + * Zero on success, negative errno on failure. + */ +int drm_connector_attach_preferred_color_format_property(struct drm_connector *connector) +{ + struct drm_device *dev = connector->dev; + struct drm_property *prop; + + if (!connector->preferred_color_format_property) { + prop = drm_property_create_enum(dev, 0, "preferred color format", drm_preferred_color_format_enum_list, ARRAY_SIZE(drm_preferred_color_format_enum_list)); + if (!prop) + return -ENOMEM; + + connector->preferred_color_format_property = prop; + drm_object_attach_property(&connector->base, prop, 0); + connector->state->preferred_color_format = 0; + } + + return 0; +} +EXPORT_SYMBOL(drm_connector_attach_preferred_color_format_property); + /** * drm_connector_attach_active_color_format_property - attach "active color format" property * @connector: connector to attach active color format property on. diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h index 5cb122812727..e52e0d2c3c4e 100644 --- a/include/drm/drm_connector.h +++ b/include/drm/drm_connector.h @@ -799,6 +799,16 @@ struct drm_connector_state { */ u8 max_bpc; + /** + * preferred_color_format: Property set by userspace to tell the GPU + * driver which color format to use. It only gets applied if hardware, + * meaning both the computer and the monitor, and the driver support the + * given format at the current resolution and refresh rate. Userspace + * can check for (un-)successful application via the active_color_format + * property. + */ + u32 preferred_color_format; + /** * @hdr_output_metadata: * DRM blob property for HDR output metadata @@ -1404,6 +1414,12 @@ struct drm_connector { */ struct drm_property *active_bpc_property; + /** + * @preferred_color_format_property: Default connector property for the + * preferred color format to be driven out of the connector. + */ + struct drm_property *preferred_color_format_property; + /** * @active_color_format_property: Default connector property for the * active color format to be driven out of the connector. @@ -1740,6 +1756,7 @@ int drm_connector_attach_max_bpc_property(struct drm_connector *connector, int min, int max); int drm_connector_attach_active_bpc_property(struct drm_connector *connector, int min, int max); void drm_connector_set_active_bpc_property(struct drm_connector *connector, int active_bpc); +int drm_connector_attach_preferred_color_format_property(struct drm_connector *connector); int drm_connector_attach_active_color_format_property(struct drm_connector *connector); void drm_connector_set_active_color_format_property(struct drm_connector *connector, u32 active_color_format); int drm_connector_attach_active_color_range_property(struct drm_connector *connector); -- 2.25.1