Re: [PATCH 2/5] drm: Add "RGB quantization range" connector property

2020-04-13 Thread Simon Ser
Can you also add docs for this property in "DOC: standard connector
properties" in drm_connector.c?
___
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel


[PATCH 2/5] drm: Add "RGB quantization range" connector property

2020-04-13 Thread Yussuf Khalil
Add a new "RGB quantization range" property with three possible values:
Automatic, Limited, and Full. User-space may use this property to override
the automatic selection of the RGB range as specified by CTA-861. Drivers
should attach this property to all CTA-861 sinks.

Signed-off-by: Yussuf Khalil 
---
 drivers/gpu/drm/drm_atomic_uapi.c |  4 
 drivers/gpu/drm/drm_connector.c   | 35 +++
 include/drm/drm_connector.h   | 23 
 include/drm/drm_mode_config.h |  7 +++
 4 files changed, 69 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic_uapi.c 
b/drivers/gpu/drm/drm_atomic_uapi.c
index a1e5e262bae2..f12b3a40c6cf 100644
--- a/drivers/gpu/drm/drm_atomic_uapi.c
+++ b/drivers/gpu/drm/drm_atomic_uapi.c
@@ -766,6 +766,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 == config->rgb_quantization_range_property) {
+   state->rgb_quantization_range = val;
} else if (connector->funcs->atomic_set_property) {
return connector->funcs->atomic_set_property(connector,
state, property, val);
@@ -842,6 +844,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 == config->rgb_quantization_range_property) {
+   *val = state->rgb_quantization_range;
} 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 644f0ad10671..e60d3b6e5e56 100644
--- a/drivers/gpu/drm/drm_connector.c
+++ b/drivers/gpu/drm/drm_connector.c
@@ -929,6 +929,12 @@ static const struct drm_prop_enum_list dp_colorspaces[] = {
{ DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
 };
 
+static const struct drm_prop_enum_list rgb_quantization_range_options[] = {
+   { DRM_MODE_RGB_QUANTIZATION_RANGE_AUTOMATIC, "Automatic" },
+   { DRM_MODE_RGB_QUANTIZATION_RANGE_LIMITED, "Limited" },
+   { DRM_MODE_RGB_QUANTIZATION_RANGE_FULL, "Full" },
+};
+
 /**
  * DOC: standard connector properties
  *
@@ -1804,6 +1810,35 @@ int drm_mode_create_dp_colorspace_property(struct 
drm_connector *connector)
 }
 EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
 
+/**
+ * drm_mode_create_rgb_quantization_range_property - create RGB quantization
+ * range property
+ * @dev: device to create the RGB quantization range property on.
+ *
+ * Called by a driver the first time it's needed, must be attached to 
connectors
+ * of CEA-861-compliant sinks.
+ *
+ * Returns:
+ * Zero on success, negative errno on failure.
+ */
+int drm_mode_create_rgb_quantization_range_property(struct drm_device *dev)
+{
+   if (dev->mode_config.rgb_quantization_range_property)
+   return 0;
+
+   dev->mode_config.rgb_quantization_range_property =
+   drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
+"RGB quantization range",
+rgb_quantization_range_options,
+
ARRAY_SIZE(rgb_quantization_range_options));
+
+   if (!dev->mode_config.rgb_quantization_range_property)
+   return -ENOMEM;
+
+   return 0;
+}
+EXPORT_SYMBOL(drm_mode_create_rgb_quantization_range_property);
+
 /**
  * drm_mode_create_content_type_property - create content type property
  * @dev: DRM device
diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
index 19ae6bb5c85b..f605e0fbcc0e 100644
--- a/include/drm/drm_connector.h
+++ b/include/drm/drm_connector.h
@@ -303,6 +303,22 @@ struct drm_monitor_range_info {
 #define DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT14
 #define DRM_MODE_COLORIMETRY_BT601_YCC 15
 
+/**
+ * enum drm_rgb_quantization_range - rgb_quantization_range property value
+ *
+ * This enum lists the possible options for the rgb_quantization_range 
property.
+ *
+ * @DRM_MODE_RGB_QUANTIZATION_RANGE_AUTOMATIC: Let the driver select the
+ * appropriate quantization range.
+ * @DRM_MODE_RGB_QUANTIZATION_RANGE_LIMITED:   Force limited range RGB.
+ * @DRM_MODE_RGB_QUANTIZATION_RANGE_FULL:  Force full range RGB.
+ */
+enum drm_rgb_quantization_range {
+   DRM_MODE_RGB_QUANTIZATION_RANGE_AUTOMATIC = 0,
+   DRM_MODE_RGB_QUANTIZATION_RANGE_LIMITED = 1,
+   DRM_MODE_RGB_QUANTIZATION_RANGE_FULL = 2,
+};
+
 /**
  * enum drm_bus_flags - bus_flags info for _display_info
  *
@@ -661,6 +677,12