diff mbox

[06/11] drm/i915: Add contrast and brightness correction

Message ID 1406138705-17334-7-git-send-email-shashank.sharma@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sharma, Shashank July 23, 2014, 6:05 p.m. UTC
From: Shashank Sharma <shashank.sharma@intel.com>

This patch adds support for color property to set sprite plane
contrast and brightness for intel color manager framework.
As, in valleyview the register for contrast and brightess
adjustment is same, one common function has been added to serve
both. It adds three functions:
  1. intel_clrmgr_set_contrast: This is a wrapper function
     which checks the platform type, and calls the valleyview
     specific set_contrast function. As different platforms have different
     methods of setting contrast, this function is required.The support for
     other platfroms can be plugged-in here in the wrapper function.
     Adding this function as .set_property for contrast and brightness
     color properties.
  2. intel_clrmgr_set_brightness: This is again a wrapper function for
     brightness setting.
  3. vlv_set_cb: Core function to program brightness/contrast as per
     vlv specs. This function takes one 64bit value as input, and extracts
     contrast/brightness values, and applies.

Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
---
 drivers/gpu/drm/i915/i915_reg.h     |  3 ++
 drivers/gpu/drm/i915/intel_clrmgr.c | 84 +++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_clrmgr.h | 38 ++++++++++++++++-
 3 files changed, 123 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 9501ad8..414a113 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -6100,6 +6100,9 @@  enum punit_power_well {
 #define VLV_PIPEB_GCMAX	(dev_priv->info.display_mmio_offset + 0x71010)
 #define VLV_PIPE_GCMAX(pipe)	_PIPE(pipe, VLV_PIPEA_GCMAX, VLV_PIPEB_GCMAX)
 
+/* Contrast and brightness */
+#define VLV_SPRITE_CB_BASE	(dev_priv->info.display_mmio_offset + 0x721d0)
+
 /* VLV MIPI registers */
 
 #define _MIPIA_PORT_CTRL			(VLV_DISPLAY_BASE + 0x61190)
diff --git a/drivers/gpu/drm/i915/intel_clrmgr.c b/drivers/gpu/drm/i915/intel_clrmgr.c
index 38ba878..781df59 100644
--- a/drivers/gpu/drm/i915/intel_clrmgr.c
+++ b/drivers/gpu/drm/i915/intel_clrmgr.c
@@ -70,6 +70,7 @@  struct clrmgr_property gen6_plane_color_corrections[] = {
 		.min = 0,
 		.len = VLV_CB_MAX_VALS,
 		.name = "contrast",
+		.set_property = intel_clrmgr_set_contrast,
 	},
 	{
 		.tweak_id = brightness,
@@ -78,6 +79,7 @@  struct clrmgr_property gen6_plane_color_corrections[] = {
 		.min = 0,
 		.len = VLV_CB_MAX_VALS,
 		.name = "brightness",
+		.set_property = intel_clrmgr_set_brightness,
 	},
 	{
 		.tweak_id = hue_saturation,
@@ -90,6 +92,88 @@  struct clrmgr_property gen6_plane_color_corrections[] = {
 };
 
 /*
+* vlv_set_cb
+* Valleyview specific common functtion for contsrast/brightness
+* setting. The method and registes are same for both.
+* Valleyview supports contrast/brightness correction only on
+* sprite planes.
+* inputs:
+* - intel_crtc *
+* - cb: registered property for contrast.
+* - data: value to be applied
+*/
+bool vlv_set_cb(struct intel_plane *intel_plane, struct clrmgr_regd_prop *cb,
+	u64 *data, enum clrmgr_tweaks tweak)
+{
+
+	u32 val, new_val, reg, sprite;
+	struct drm_device *dev = intel_plane->base.dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_property *property = cb->property;
+
+	sprite = intel_plane->plane;
+	if (!(SPCNTR(intel_plane->pipe, sprite) & SP_ENABLE)) {
+		DRM_ERROR("Sprite plane %d not enabled\n", sprite);
+		return false;
+	}
+
+	/* Apply correction only if sprite is enabled */
+	DRM_DEBUG_DRIVER("Applying cb correction on Sprite\n");
+	reg = SPRITE_CB(intel_plane->pipe, sprite);
+
+	if (tweak == contrast) {
+		/* Contrast value is lower 9 bit value */
+		new_val = *data & VLV_CONTRAST_MASK;
+		DRM_DEBUG_DRIVER("Setting Contrast to 0x%x", new_val);
+
+		/* Contrast correction position is bit [26:18] */
+		val = I915_READ(reg) &
+			~(VLV_CONTRAST_MASK << VLV_CONTRAST_SHIFT);
+		val |= (new_val << VLV_CONTRAST_SHIFT);
+	} else {
+		new_val = *data & VLV_BRIGHTNESS_MASK;
+		DRM_DEBUG_DRIVER("Setting Brightness to 0x%x", new_val);
+
+		/* Brightness correction is lower 8 [7:0] register bits */
+		val = I915_READ(reg) | new_val;
+	}
+
+	/* Contrast and brightness are single value properties */
+	I915_WRITE(reg, val);
+	property->values[property->num_values - 1] = *data;
+	DRM_DEBUG_DRIVER("Set Contrast/Brightness correction successful");
+	return true;
+}
+
+bool intel_clrmgr_set_brightness(void *plane,
+	struct clrmgr_regd_prop *bright, u64 *data)
+{
+	struct intel_plane *intel_plane = plane;
+	struct drm_device *dev = intel_plane->base.dev;
+
+	if (IS_VALLEYVIEW(dev))
+		return vlv_set_cb(intel_plane, bright, data, brightness);
+
+	/* Todo: Support other gen devices */
+	DRM_ERROR("Color correction is supported only on VLV for now\n");
+	return false;
+}
+
+bool intel_clrmgr_set_contrast(void *plane,
+	struct clrmgr_regd_prop *ctrst, u64 *data)
+{
+	struct intel_plane *intel_plane = plane;
+	struct drm_device *dev = intel_plane->base.dev;
+
+	if (IS_VALLEYVIEW(dev))
+		return vlv_set_cb(intel_plane, ctrst, data, contrast);
+
+	/* Todo: Support other gen devices */
+	DRM_ERROR("Color correction is supported only on VLV for now\n");
+	return false;
+}
+
+/*
 * vlv_set_10bit_gamma
 * Valleyview specific gamma correction method.
 * Programs the palette registers in 10bit method
diff --git a/drivers/gpu/drm/i915/intel_clrmgr.h b/drivers/gpu/drm/i915/intel_clrmgr.h
index fd8b98e..d1fc787 100644
--- a/drivers/gpu/drm/i915/intel_clrmgr.h
+++ b/drivers/gpu/drm/i915/intel_clrmgr.h
@@ -67,10 +67,16 @@ 
 #define VLV_GAMMA_GCMAX_MASK				0x1FFFF
 #define VLV_CLRMGR_GAMMA_GCMAX_MAX			0x400
 
+/* Offset for sprite planes */
+#define SPRITE_COLOR_OFFSET				0x100
 
-
-/* Sprite Contrast and Brightness Registers */
+/* Sprite Contrast and Brightness common defs */
 #define VLV_CB_MAX_VALS				1
+#define SPRITE_CB(p, s)				(VLV_SPRITE_CB_BASE + \
+					(p * 2 + s) * SPRITE_COLOR_OFFSET)
+#define VLV_CONTRAST_MASK				0x1FF
+#define VLV_CONTRAST_SHIFT				18
+#define VLV_BRIGHTNESS_MASK				0xFF
 
 /* Sprite Hue and Saturation Registers */
 #define VLV_HS_MAX_VALS				1
@@ -135,6 +141,34 @@  struct clrmgr_reg_request {
 };
 
 /*
+* intel_clrmgr_set_contrast
+* Set contrast level.
+* Different gen devices have different methods for
+* contrast setting. This is a wrapper function to
+* call device specific set contrast function
+* inputs:
+* - plane: void*, can be typecasted to intel_plane*
+* - ctrst: registered color property for contrast
+* - data: new value
+*/
+bool intel_clrmgr_set_contrast(void *plane,
+	struct clrmgr_regd_prop *ctrst, u64 *data);
+
+/*
+* intel_clrmgr_set_brightness
+* Set brightness level.
+* Different gen devices have different methods for
+* brightness setting. This is a wrapper function to
+* call device specific set brightess function
+* inputs:
+* - plane: void*, can be typecasted to intel_plane*
+* - bright: registered color property for brightness
+* - data: new value
+*/
+bool intel_clrmgr_set_brightness(void *plane,
+	struct clrmgr_regd_prop *bright, u64 *data);
+
+/*
 * intel_clrmgr_set_gamma
 * Gamma correction method is different across various
 * gen devices. This is a wrapper function which will call