diff mbox

[4/6] drm/i915: Color manager: brightness/contrast

Message ID 1392899847-2641-5-git-send-email-shashank.sharma@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sharma, Shashank Feb. 20, 2014, 12:37 p.m. UTC
This patch is third extension to color manager framework.
It adds implementataion of color manager property "Brightness
and Contrast correctio"n in intel color manager framework.
Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
---
 drivers/gpu/drm/i915/intel_clrmgr.c |   98 ++++++++++++++++++++++++++++++++++-
 1 file changed, 96 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_clrmgr.c b/drivers/gpu/drm/i915/intel_clrmgr.c
index 1297e60..db13e2b 100644
--- a/drivers/gpu/drm/i915/intel_clrmgr.c
+++ b/drivers/gpu/drm/i915/intel_clrmgr.c
@@ -134,25 +134,119 @@  static int get_no_of_pipes(struct drm_device *dev)
 	return 0;
 }
 
+/* Check Sprite status */
+static bool is_sprite_enabled(struct drm_i915_private *dev_priv,
+			enum pipe pipe, enum plane plane)
+{
+	int reg;
+	u32 val;
+
+	reg = SPCNTR(pipe, plane);
+	val = I915_READ(reg);
+	return val & SP_ENABLE;
+}
+
 static bool intel_clrmgr_disable_hs(struct drm_device *dev, int identifier)
 {
 	return true;
 }
 
-static bool intel_clrmgr_disable_cb(struct drm_device *dev, int identifier)
+static bool intel_clrmgr_enable_hs(struct drm_device *dev, int identifier)
 {
 	return true;
 }
 
-static bool intel_clrmgr_enable_hs(struct drm_device *dev, int identifier)
+/* Tune Contrast Brightness Value for Sprite */
+int intel_sprite_cb_adjust(struct drm_device *dev,
+		struct cont_brightlut *cb_ptr)
+{
+	drm_i915_private_t *dev_priv = dev->dev_private;
+
+	if (!dev_priv || !cb_ptr) {
+		DRM_ERROR("Contrast Brightness: Invalid Arguments\n");
+		return -EINVAL;
+	}
+
+	switch (cb_ptr->sprite_no) {
+	/* Sprite plane */
+	case sprite_a:
+		if (is_sprite_enabled(dev_priv, PIPE_A, SPRITE_PLANE_A))
+			I915_WRITE(SPRITEA_CB_REG, cb_ptr->val);
+		break;
+
+	case sprite_b:
+		if (is_sprite_enabled(dev_priv, PIPE_A, SPRITE_PLANE_B))
+			I915_WRITE(SPRITEB_CB_REG, cb_ptr->val);
+		break;
+
+	case sprite_c:
+		if (is_sprite_enabled(dev_priv, PIPE_B, SPRITE_PLANE_C))
+			I915_WRITE(SPRITEC_CB_REG, cb_ptr->val);
+		break;
+
+	case sprite_d:
+		if (is_sprite_enabled(dev_priv, PIPE_B, SPRITE_PLANE_D))
+			I915_WRITE(SPRITED_CB_REG, cb_ptr->val);
+		break;
+
+	default:
+		DRM_ERROR("Invalid Sprite Number\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+/* Disable correction for contrast/brightness */
+static bool intel_clrmgr_disable_cb(struct drm_device *dev, int identifier)
 {
+	struct cont_brightlut cb;
+	drm_i915_private_t *dev_priv = dev->dev_private;
+	struct clrmgr_pipe_status *pstatus = dev_priv->clrmgr_status.pstatus;
+
+	if (!pstatus) {
+		DRM_ERROR("Clrmgr: color manager not initialized");
+		return false;
+	}
+
+	cb.sprite_no = identifier;
+	cb.val = CB_DEFAULT_VAL;
+
+	if (intel_sprite_cb_adjust(dev, &cb)) {
+		DRM_ERROR("\nClrmgr: Contrast/Brigtness disable failed");
+		return false;
+	}
+
+	pstatus->cb_enabled = false;
 	return true;
+
 }
+
+/* Enable correction for contrast/brightness */
 static bool intel_clrmgr_enable_cb(struct drm_device *dev, int identifier)
 {
+	struct cont_brightlut cb;
+	drm_i915_private_t *dev_priv = dev->dev_private;
+	struct clrmgr_pipe_status *pstatus = dev_priv->clrmgr_status.pstatus;
+
+	if (!pstatus) {
+		DRM_ERROR("Clrmgr: color manager not initialized");
+		return false;
+	}
+
+	cb.sprite_no = identifier;
+	cb.val = clrmgr_luts[clrmgr_cb][CB_MAX_COEFF_COUNT-1];
+
+	if (intel_sprite_cb_adjust(dev, &cb)) {
+		DRM_ERROR("\nClrmgr: Contrast/Brigtness enable failed");
+		return false;
+	}
+
+	pstatus->cb_enabled = true;
 	return true;
 }
 
+
 /* Reset palette registers for gamma disabling */
 static int intel_clrmgr_reset_lut(struct drm_device *dev)
 {