From 7fa7c0b24aa134d5fdb65dc2a984c734b499f70e Mon Sep 17 00:00:00 2001
From: fritsch <peter.fruehberger@gmail.com>
Date: Sun, 29 Nov 2015 16:38:14 +0100
Subject: [PATCH] Intel: Implement Video Color Range (testing)

---
 drivers/gpu/drm/i915/i915_drv.h    |  1 +
 drivers/gpu/drm/i915/intel_drv.h   |  8 ++++++++
 drivers/gpu/drm/i915/intel_hdmi.c  | 17 +++++++++++++++--
 drivers/gpu/drm/i915/intel_modes.c |  1 +
 4 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index a01e515..9e4b8d0 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3450,6 +3450,7 @@ int intel_freq_opcode(struct drm_i915_private *dev_priv, int val);
 #define INTEL_BROADCAST_RGB_AUTO 0
 #define INTEL_BROADCAST_RGB_FULL 1
 #define INTEL_BROADCAST_RGB_LIMITED 2
+#define INTEL_BROADCAST_RGB_VIDEO 3
 
 static inline uint32_t i915_vgacntrl_reg(struct drm_device *dev)
 {
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index f2a1142..210e7a7 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -372,6 +372,13 @@ struct intel_crtc_state {
 	 */
 	bool limited_color_range;
 
+	/*
+	 *
+	 * Use reduced/limited/broadcast rgb range without compressing.
+	 *
+	 */
+	bool video_color_range;
+
 	/* DP has a bunch of special case unfortunately, so mark the pipe
 	 * accordingly. */
 	bool has_dp_encoder;
@@ -682,6 +689,7 @@ struct intel_hdmi {
 	int ddc_bus;
 	bool limited_color_range;
 	bool color_range_auto;
+	bool color_range_video;
 	bool has_hdmi_sink;
 	bool has_audio;
 	enum hdmi_force_audio force_audio;
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 81cdd9f..417f9be 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -464,7 +464,8 @@ static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
 	}
 
 	if (intel_hdmi->rgb_quant_range_selectable) {
-		if (intel_crtc->config->limited_color_range)
+		if (intel_crtc->config->limited_color_range ||
+		    intel_crtc->config->video_color_range)
 			frame.avi.quantization_range =
 				HDMI_QUANTIZATION_RANGE_LIMITED;
 		else
@@ -1266,6 +1267,8 @@ bool intel_hdmi_compute_config(struct intel_encoder *encoder,
 		pipe_config->limited_color_range =
 			intel_hdmi->limited_color_range;
 	}
+	if (intel_hdmi->color_range_video)
+               pipe_config->video_color_range = true;
 
 	if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) {
 		pipe_config->pixel_multiplier = 2;
@@ -1485,25 +1488,35 @@ intel_hdmi_set_property(struct drm_connector *connector,
 	if (property == dev_priv->broadcast_rgb_property) {
 		bool old_auto = intel_hdmi->color_range_auto;
 		bool old_range = intel_hdmi->limited_color_range;
+		bool old_range_video = intel_hdmi->color_range_video;
 
 		switch (val) {
 		case INTEL_BROADCAST_RGB_AUTO:
 			intel_hdmi->color_range_auto = true;
+			intel_hdmi->color_range_video = false;
 			break;
 		case INTEL_BROADCAST_RGB_FULL:
 			intel_hdmi->color_range_auto = false;
 			intel_hdmi->limited_color_range = false;
+			intel_hdmi->color_range_video = false;
 			break;
 		case INTEL_BROADCAST_RGB_LIMITED:
 			intel_hdmi->color_range_auto = false;
 			intel_hdmi->limited_color_range = true;
+			intel_hdmi->color_range_video = false;
+			break;
+		case INTEL_BROADCAST_RGB_VIDEO:
+			intel_hdmi->color_range_auto = false;
+			intel_hdmi->limited_color_range = false;
+			intel_hdmi->color_range_video = true;
 			break;
 		default:
 			return -EINVAL;
 		}
 
 		if (old_auto == intel_hdmi->color_range_auto &&
-		    old_range == intel_hdmi->limited_color_range)
+		    old_range == intel_hdmi->limited_color_range &&
+		    old_range_video == intel_hdmi->color_range_video)
 			return 0;
 
 		goto done;
diff --git a/drivers/gpu/drm/i915/intel_modes.c b/drivers/gpu/drm/i915/intel_modes.c
index 38a4c8c..c49681a 100644
--- a/drivers/gpu/drm/i915/intel_modes.c
+++ b/drivers/gpu/drm/i915/intel_modes.c
@@ -103,6 +103,7 @@ static const struct drm_prop_enum_list broadcast_rgb_names[] = {
 	{ INTEL_BROADCAST_RGB_AUTO, "Automatic" },
 	{ INTEL_BROADCAST_RGB_FULL, "Full" },
 	{ INTEL_BROADCAST_RGB_LIMITED, "Limited 16:235" },
+	{ INTEL_BROADCAST_RGB_VIDEO, "Video 16:235 pass-through" },
 };
 
 void
-- 
2.5.0
