From patchwork Wed Jul 23 18:05:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sharma, Shashank" X-Patchwork-Id: 4612451 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3070A9F2B8 for ; Wed, 23 Jul 2014 18:02:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D2E38201CE for ; Wed, 23 Jul 2014 18:02:08 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id EAEC5201C7 for ; Wed, 23 Jul 2014 18:02:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 68AE76E685; Wed, 23 Jul 2014 11:02:04 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id E78616E684 for ; Wed, 23 Jul 2014 11:02:02 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 23 Jul 2014 11:01:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,718,1400050800"; d="scan'208";a="574341223" Received: from shashanks-desktop.iind.intel.com ([10.223.26.11]) by fmsmga002.fm.intel.com with ESMTP; 23 Jul 2014 11:00:44 -0700 From: shashank.sharma@intel.com To: intel-gfx@lists.freedesktop.org, ville.syrjala@linux.intel.com, damien.lespiau@intel.com, daniel.vetter@intel.com, shobhit.kumar@intel.com, satheeshakrishna.m@intel.com Date: Wed, 23 Jul 2014 23:35:00 +0530 Message-Id: <1406138705-17334-7-git-send-email-shashank.sharma@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1406138705-17334-1-git-send-email-shashank.sharma@intel.com> References: <1406138705-17334-1-git-send-email-shashank.sharma@intel.com> Cc: =indranil.mukherjee@intel.com Subject: [Intel-gfx] [PATCH 06/11] drm/i915: Add contrast and brightness correction X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Shashank Sharma 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 --- 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 --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