From: Shashank Sharma <shashank.sharma@intel.com>
To: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
emil.l.velikov@gmail.com, matthew.d.roper@intel.com,
robert.bradford@intel.com, jim.bish@intel.com
Cc: annie.j.matheson@intel.com, kausalmalladi@gmail.com,
daniel.vetter@intel.com
Subject: [PATCH v6 15/23] drm/i915: CHV: Pipe level CSC correction
Date: Fri, 16 Oct 2015 19:59:03 +0530 [thread overview]
Message-ID: <1445005751-14918-16-git-send-email-shashank.sharma@intel.com> (raw)
In-Reply-To: <1445005751-14918-1-git-send-email-shashank.sharma@intel.com>
CHV/BSW supports Color Space Conversion (CSC) using a 3x3 matrix
that needs to be programmed into CGM (Color Gamut Mapping) registers.
This patch does the following:
1. Attaches CSC property to CRTC
2. Adds the core function to program CSC correction values
3. Adds CSC correction macros
Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
Signed-off-by: Kausal Malladi <kausalmalladi@gmail.com>
Signed-off-by: Kumar, Kiran S <kiran.s.kumar@intel.com>
---
drivers/gpu/drm/i915/i915_reg.h | 8 +++
drivers/gpu/drm/i915/intel_color_manager.c | 99 ++++++++++++++++++++++++++++++
drivers/gpu/drm/i915/intel_color_manager.h | 19 ++++++
3 files changed, 126 insertions(+)
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
index 1e46562..3db42f4 100644
--- a/drivers/gpu/drm/i915/i915_reg.h
+++ b/drivers/gpu/drm/i915/i915_reg.h
@@ -8166,4 +8166,12 @@ enum skl_disp_power_wells {
#define _PIPE_DEGAMMA_BASE(pipe) \
(_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA, PIPEC_CGM_DEGAMMA))
+#define PIPEA_CGM_CSC (VLV_DISPLAY_BASE + 0x67900)
+#define PIPEB_CGM_CSC (VLV_DISPLAY_BASE + 0x69900)
+#define PIPEC_CGM_CSC (VLV_DISPLAY_BASE + 0x6B900)
+#define _PIPE_CSC_BASE(pipe) \
+ (_PIPE3(pipe, PIPEA_CGM_CSC, PIPEB_CGM_CSC, PIPEC_CGM_CSC))
+
+
+
#endif /* _I915_REG_H_ */
diff --git a/drivers/gpu/drm/i915/intel_color_manager.c b/drivers/gpu/drm/i915/intel_color_manager.c
index 1bbad79..6661c53 100644
--- a/drivers/gpu/drm/i915/intel_color_manager.c
+++ b/drivers/gpu/drm/i915/intel_color_manager.c
@@ -27,6 +27,98 @@
#include "intel_color_manager.h"
+static s32 chv_prepare_csc_coeff(s64 csc_value)
+{
+ s32 csc_int_value;
+ u32 csc_fract_value;
+ s32 csc_s3_12_format;
+
+ if (csc_value >= 0) {
+ csc_value += CHV_CSC_FRACT_ROUNDOFF;
+ if (csc_value > CHV_CSC_COEFF_MAX)
+ csc_value = CHV_CSC_COEFF_MAX;
+ } else {
+ csc_value = -csc_value;
+ csc_value += CHV_CSC_FRACT_ROUNDOFF;
+ if (csc_value > CHV_CSC_COEFF_MAX + 1)
+ csc_value = CHV_CSC_COEFF_MAX + 1;
+ csc_value = -csc_value;
+ }
+
+ csc_int_value = csc_value >> CHV_CSC_COEFF_SHIFT;
+ csc_int_value <<= CHV_CSC_COEFF_INT_SHIFT;
+ if (csc_value < 0)
+ csc_int_value |= CSC_COEFF_SIGN;
+
+ csc_fract_value = csc_value;
+ csc_fract_value >>= CHV_CSC_COEFF_FRACT_SHIFT;
+ csc_s3_12_format = csc_int_value | csc_fract_value;
+
+ return csc_s3_12_format;
+}
+
+static int chv_set_csc(struct drm_device *dev, struct drm_property_blob *blob,
+ struct drm_crtc *crtc)
+{
+ struct drm_ctm *csc_data;
+ struct drm_i915_private *dev_priv = dev->dev_private;
+ u32 reg;
+ enum pipe pipe;
+ s32 word = 0, temp;
+ int count = 0;
+
+ if (WARN_ON(!blob))
+ return -EINVAL;
+
+ if (blob->length != sizeof(struct drm_ctm)) {
+ DRM_ERROR("Invalid length of data received\n");
+ return -EINVAL;
+ }
+
+ csc_data = (struct drm_ctm *)blob->data;
+ pipe = to_intel_crtc(crtc)->pipe;
+
+ /* Disable CSC functionality */
+ reg = _PIPE_CGM_CONTROL(pipe);
+ I915_WRITE(reg, I915_READ(reg) & (~CGM_CSC_EN));
+
+ DRM_DEBUG_DRIVER("Disabled CSC Functionality on Pipe %c\n",
+ pipe_name(pipe));
+
+ reg = _PIPE_CSC_BASE(pipe);
+
+ /*
+ * First 8 of 9 CSC correction values go in pair, to first
+ * 4 CSC register (bit 0:15 and 16:31)
+ */
+ while (count < CSC_MAX_VALS - 1) {
+ temp = chv_prepare_csc_coeff(
+ csc_data->ctm_coeff[count]);
+ SET_BITS(word, GET_BITS(temp, 16, 16), 0, 16);
+ count++;
+
+ temp = chv_prepare_csc_coeff(
+ csc_data->ctm_coeff[count]);
+ SET_BITS(word, GET_BITS(temp, 16, 16), 16, 16);
+ count++;
+
+ I915_WRITE(reg, word);
+ reg += 4;
+ }
+
+ /* 9th coeff goes to 5th register, bit 0:16 */
+ temp = chv_prepare_csc_coeff(
+ csc_data->ctm_coeff[count]);
+ SET_BITS(word, GET_BITS(temp, 16, 16), 0, 16);
+ I915_WRITE(reg, word);
+
+ /* Enable CSC functionality */
+ reg = _PIPE_CGM_CONTROL(pipe);
+ I915_WRITE(reg, I915_READ(reg) | CGM_CSC_EN);
+ DRM_DEBUG_DRIVER("CSC enabled on Pipe %c\n", pipe_name(pipe));
+ return 0;
+}
+
static int chv_set_degamma(struct drm_device *dev,
struct drm_property_blob *blob, struct drm_crtc *crtc)
{
@@ -247,4 +339,11 @@ void intel_attach_color_properties_to_crtc(struct drm_device *dev,
config->cm_palette_before_ctm_property, 0);
DRM_DEBUG_DRIVER("degamma property attached to CRTC\n");
}
+
+ /* CSC */
+ if (config->cm_ctm_property) {
+ drm_object_attach_property(mode_obj,
+ config->cm_ctm_property, 0);
+ DRM_DEBUG_DRIVER("CSC property attached to CRTC\n");
+ }
}
diff --git a/drivers/gpu/drm/i915/intel_color_manager.h b/drivers/gpu/drm/i915/intel_color_manager.h
index 77a2119..7b96512 100644
--- a/drivers/gpu/drm/i915/intel_color_manager.h
+++ b/drivers/gpu/drm/i915/intel_color_manager.h
@@ -63,10 +63,29 @@
#define CHV_GAMMA_SHIFT_GREEN 16
#define CHV_MAX_GAMMA ((1 << 24) - 1)
+/*
+ * CSC on CHV
+ * Fractional part is 32 bit, and we need only 12 MSBs for programming
+ * into registers. ROUNDOFF is required to minimize loss of precision.
+ */
+#define CHV_CSC_FRACT_ROUNDOFF (1 << 19)
+/*
+ * CSC values are 64-bit values. For CHV, the maximum CSC value that
+ * user can program is 7.99999..., which can be represented in fixed point
+ * S31.32 format like this, with all fractional bits as 1
+ */
+#define CHV_CSC_COEFF_MAX 0x00000007FFFFFFFF
+#define CHV_CSC_COEFF_SHIFT 32
+#define CHV_CSC_COEFF_INT_SHIFT 28
+#define CSC_COEFF_SIGN (1 << 31)
+#define CHV_CSC_COEFF_FRACT_SHIFT 4
+#define CSC_MAX_VALS 9
+
/* Degamma on CHV */
#define CHV_DEGAMMA_MSB_SHIFT 2
#define CHV_DEGAMMA_GREEN_SHIFT 16
/* CHV CGM Block */
#define CGM_GAMMA_EN (1 << 2)
+#define CGM_CSC_EN (1 << 1)
#define CGM_DEGAMMA_EN (1 << 0)
--
1.9.1
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2015-10-16 14:29 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-16 14:28 [PATCH v6 00/23] Color Management for DRM framework Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 01/23] drm: Create Color Management DRM properties Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 02/23] drm: Create Color Management query properties Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 03/23] drm: Add color correction blobs in CRTC state Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 04/23] drm: Add set property support for color manager Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 05/23] drm: Add get " Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 06/23] drm: Add drm structures for palette color property Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 07/23] drm: Add structure for CTM " Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 08/23] drm/i915: Add set property interface for CRTC Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 09/23] drm/i915: Create color management files Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 10/23] drm/i915: Register color correction capabilities Shashank Sharma
2015-10-16 14:28 ` [PATCH v6 11/23] drm/i915: CHV: Load gamma color correction values Shashank Sharma
2015-10-16 14:29 ` [PATCH v6 12/23] drm/i915: CHV: Load degamma " Shashank Sharma
2015-10-16 14:29 ` [PATCH v6 13/23] drm/i915: CHV: Pipe level Gamma correction Shashank Sharma
2015-10-16 14:29 ` [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction Shashank Sharma
2015-10-19 18:08 ` Smith, Gary K
2015-10-19 18:54 ` Daniel Vetter
2015-10-19 20:39 ` Bish, Jim
2015-10-19 21:57 ` [Intel-gfx] " Daniel Vetter
2015-10-19 22:23 ` Smith, Gary K
2015-10-19 22:27 ` Smith, Gary K
2015-10-19 23:48 ` [Intel-gfx] " Matheson, Annie J
2015-10-20 4:09 ` Sharma, Shashank
2015-10-20 7:27 ` Daniel Vetter
2015-10-20 8:15 ` [Intel-gfx] " Sharma, Shashank
2015-10-20 12:11 ` Sharma, Shashank
2015-10-16 14:29 ` Shashank Sharma [this message]
2015-10-16 14:29 ` [PATCH v6 16/23] drm/i915: Commit color correction to CRTC Shashank Sharma
2015-10-16 14:29 ` [PATCH v6 17/23] drm/i915: Attach color properties " Shashank Sharma
2015-10-16 14:29 ` [PATCH v6 18/23] drm/i915: BDW: Load gamma correction values Shashank Sharma
2015-10-16 14:29 ` [PATCH v6 19/23] drm/i915: BDW: Pipe level Gamma correction Shashank Sharma
2015-10-16 14:29 ` [PATCH v6 20/23] drm/i915: BDW: Load degamma correction values Shashank Sharma
2015-10-16 14:29 ` [PATCH v6 21/23] drm/i915: BDW: Pipe level degamma correction Shashank Sharma
2015-10-16 14:29 ` [PATCH v6 22/23] drm/i915: BDW: Pipe level CSC correction Shashank Sharma
2015-10-16 14:29 ` [PATCH v6 23/23] drm/i915: disable plane gamma Shashank Sharma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1445005751-14918-16-git-send-email-shashank.sharma@intel.com \
--to=shashank.sharma@intel.com \
--cc=annie.j.matheson@intel.com \
--cc=daniel.vetter@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=emil.l.velikov@gmail.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jim.bish@intel.com \
--cc=kausalmalladi@gmail.com \
--cc=matthew.d.roper@intel.com \
--cc=robert.bradford@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox