From: Shashank Sharma <shashank.sha...@intel.com>

In valleyview we have three possible sprite plane level
color correction:
    1. Contrast
    2. Brightness

What this patch does:
1. This patch adds software infrastructure to register plane level
   color correction properties per plane. Adding a new function,
   intel_attach_plane_color_correction to register the plane level
   color correction properties.
2. Adding a pointer in intel_plane structure to store this property.
3. Adding structure gen6_plane_color_corrections, which contains different
   plane level correction values for VLV.

Signed-off-by: Shashank Sharma <shashank.sha...@intel.com>
---
 drivers/gpu/drm/i915/intel_clrmgr.c | 125 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_clrmgr.h |   8 +++
 drivers/gpu/drm/i915/intel_drv.h    |   3 +
 3 files changed, 136 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_clrmgr.c 
b/drivers/gpu/drm/i915/intel_clrmgr.c
index 8d02a62..0aa3734 100644
--- a/drivers/gpu/drm/i915/intel_clrmgr.c
+++ b/drivers/gpu/drm/i915/intel_clrmgr.c
@@ -53,6 +53,41 @@ struct clrmgr_property gen6_pipe_color_corrections[] = {
        },
 };
 
+/*
+* Gen6 plane level properties:
+* - Contrast adjustment for all sprite planes.
+* - Brightness adjustment for all sprite planes.
+* - Hue and Saturation adjustment for all sprite planes.
+*/
+struct clrmgr_property gen6_plane_color_corrections[] = {
+
+       {
+               .tweak_id = contrast,
+               .type = DRM_MODE_PROP_RANGE,
+               .max = CLRMGR_PROP_RANGE_MAX,
+               .min = 0,
+               .len = VLV_CB_MAX_VALS,
+               .name = "contrast",
+       },
+       {
+               .tweak_id = brightness,
+               .type = DRM_MODE_PROP_RANGE,
+               .max = CLRMGR_PROP_RANGE_MAX,
+               .min = 0,
+               .len = VLV_CB_MAX_VALS,
+               .name = "brightness",
+       },
+       {
+               .tweak_id = hue_saturation,
+               .type = DRM_MODE_PROP_RANGE,
+               .max = CLRMGR_PROP_RANGE_MAX,
+               .min = 0,
+               .len = VLV_HS_MAX_VALS,
+               .name = "hue-saturation",
+       }
+};
+
+
 struct drm_property *intel_clrmgr_register(struct drm_device *dev,
        struct drm_mode_object *obj, struct clrmgr_property *cp)
 {
@@ -92,6 +127,96 @@ error:
        return NULL;
 }
 
+bool intel_clrmgr_register_plane_property(struct intel_plane *intel_plane,
+               struct clrmgr_reg_request *features)
+{
+       u32 count = 0;
+       struct clrmgr_property *cp;
+       struct clrmgr_regd_prop *regd_property;
+       struct drm_property *property;
+       struct drm_device *dev = intel_plane->base.dev;
+       struct drm_mode_object *obj = &intel_plane->base.base;
+       struct clrmgr_status *status = intel_plane->color_status;
+
+       /* Color manager initialized? */
+       if (!status) {
+               DRM_ERROR("Register request without plane init ?\n");
+               return false;
+       }
+
+       /* Validate input */
+       if (!features || !features->no_of_properties) {
+               DRM_ERROR("Invalid input to register plane property\n");
+               return false;
+       }
+
+       /* Create drm property */
+       while (count < features->no_of_properties) {
+               cp = &features->cp[count++];
+               property = intel_clrmgr_register(dev, obj, cp);
+               if (!property) {
+                       DRM_ERROR("Failed to register property %s\n",
+                               property->name);
+                       goto error;
+               }
+
+               /* Add the property in global pipe status */
+               regd_property = kzalloc(sizeof(struct clrmgr_regd_prop),
+                                                       GFP_KERNEL);
+               regd_property->property = property;
+               regd_property->enabled = false;
+               regd_property->set_property = cp->set_property;
+               status->cp[status->no_of_properties++] = regd_property;
+       }
+
+       /* Successfully registered all */
+       DRM_DEBUG_DRIVER("Registered color properties on plane %d\n",
+               intel_plane->plane);
+       return true;
+
+error:
+       if (--count) {
+               DRM_ERROR("Can only register following properties:\n");
+               while (count--)
+                       DRM_ERROR("%s", status->cp[count]->property->name);
+       } else
+               DRM_ERROR("Can not register any property\n");
+       return false;
+}
+
+void
+intel_attach_plane_color_correction(struct intel_plane *intel_plane)
+{
+       struct clrmgr_reg_request *features;
+
+       /* Color manager initialized? */
+       if (!intel_plane->color_status) {
+               DRM_ERROR("Color manager not initialized for plane %d\n",
+                       intel_plane->plane);
+               return;
+       }
+
+       DRM_DEBUG_DRIVER("\n");
+       features = kzalloc(sizeof(struct clrmgr_reg_request), GFP_KERNEL);
+       if (!features) {
+               DRM_ERROR("No memory for plane color features\n");
+               return;
+       }
+
+       features->no_of_properties = ARRAY_SIZE(gen6_plane_color_corrections);
+       memcpy(features->cp, gen6_plane_color_corrections,
+                               features->no_of_properties *
+                                       sizeof(struct clrmgr_property));
+
+       /* Register plane level color properties */
+       if (!intel_clrmgr_register_plane_property(intel_plane, features))
+               DRM_ERROR("Register plane color property failed\n");
+       else
+               DRM_DEBUG_DRIVER("Attached colot corrections for plane %d\n",
+                       intel_plane->plane);
+       kfree(features);
+}
+
 bool intel_clrmgr_register_pipe_property(struct intel_crtc *intel_crtc,
                struct clrmgr_reg_request *features)
 
diff --git a/drivers/gpu/drm/i915/intel_clrmgr.h 
b/drivers/gpu/drm/i915/intel_clrmgr.h
index 7cb2798..28fea24 100644
--- a/drivers/gpu/drm/i915/intel_clrmgr.h
+++ b/drivers/gpu/drm/i915/intel_clrmgr.h
@@ -38,6 +38,8 @@
 /* Framework defs */
 #define CLRMGR_PROP_MAX                                10
 #define CLRMGR_PROP_NAME_MAX                           128
+#define CLRMGR_PROP_RANGE_MAX                          0xFFFFFFFFFFFFFFFF
+
 
 /* CSC / Wide gamut */
 #define VLV_CSC_MATRIX_MAX_VALS                        9
@@ -48,6 +50,12 @@
 #define VLV_10BIT_GAMMA_MAX_VALS               (VLV_10BIT_GAMMA_MAX_INDEX + \
                                                CLRMGR_GAMMA_GCMAX_VAL)
 
+/* Sprite Contrast and Brightness Registers */
+#define VLV_CB_MAX_VALS                                1
+
+/* Sprite Hue and Saturation Registers */
+#define VLV_HS_MAX_VALS                                1
+
 /* Color manager features */
 enum clrmgr_tweaks {
        csc = 0,
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 698801a..ed35cdf 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -474,6 +474,9 @@ struct intel_plane {
                               struct drm_intel_sprite_colorkey *key);
        void (*get_colorkey)(struct drm_plane *plane,
                             struct drm_intel_sprite_colorkey *key);
+
+       /* color-correction */
+       struct clrmgr_status *color_status;
 };
 
 struct intel_watermark_params {
-- 
1.9.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to