From a91ebe6e28025d053bdab48c2e0d419adade796e Mon Sep 17 00:00:00 2001 From: Dezhi Kong Date: Thu, 1 Aug 2019 19:07:18 +0800 Subject: [PATCH] drm: merge commit related to gamma [1/1] PD#SWPL-11059 Problem: gamma setting in DRM Solution: merge commit related to gamma Author: Ao Xu Date: Tue Oct 30 19:18:21 2018 +0800 drm: add meson private property gamma_lut When setting CTM, gamma is also set again. Setting gamma frequently will lead to visual glitches. Add a private value to record whether gamma_lut blob is changed. Bug: b/113682067 Test: Ran on device and changed gamma to verify there are no glitches Author: Fergus Simpson Date: Fri Aug 10 13:18:36 2018 -0700 [Estelle] Enable top/bottom color clamping Modifies amvecm's color clipping to allow either the lower or upper limit to be set. This sets clipping registers that hold the top and bottom 10-bit clipping values for each color channel. This does not cause the artifacts that we've been seeing while trying enable the gamma tables. Usage (set a clip of 32/255): echo 20080020 > /sys/class/amvecm/color_bottom Bug: 109942195 Test: Flashed to device and tested with a internal changes that use the registers. Author: Frank Chen Date: Wed Aug 8 15:21:17 2018 +0800 remove gamma_enable in am_meson_crtc_create Verify: verify by u200 Change-Id: I4221b3b4671516e7afd4dea14ce3cd71b4b66433 Signed-off-by: Dezhi Kong --- drivers/amlogic/drm/meson_crtc.c | 22 +++++++++-- drivers/amlogic/drm/meson_drv.h | 1 + drivers/amlogic/media/enhancement/amvecm/amvecm.c | 46 +++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/drivers/amlogic/drm/meson_crtc.c b/drivers/amlogic/drm/meson_crtc.c index 1021e1a..011f871 100644 --- a/drivers/amlogic/drm/meson_crtc.c +++ b/drivers/amlogic/drm/meson_crtc.c @@ -194,7 +194,7 @@ static void am_meson_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_color_lut *lut; struct am_meson_crtc *amcrtc = to_am_meson_crtc(crtc); struct drm_atomic_state *old_atomic_state = old_state->state; - + struct meson_drm *priv = amcrtc->priv; struct meson_vpu_pipeline *pipeline = amcrtc->pipeline; #ifdef CONFIG_AMLOGIC_MEDIA_ENHANCEMENT int gamma_lut_size = 0; @@ -209,15 +209,32 @@ static void am_meson_crtc_atomic_flush(struct drm_crtc *crtc, #ifdef CONFIG_AMLOGIC_MEDIA_ENHANCEMENT am_meson_ctm_set(0, ctm); #endif + } else { + DRM_DEBUG("%s Disable CTM!\n", __func__); + #ifdef CONFIG_AMLOGIC_MEDIA_ENHANCEMENT + am_meson_ctm_disable(); + #endif } + } + if (crtc->state->gamma_lut != priv->gamma_lut_blob) { + DRM_DEBUG("%s GAMMA LUT blob changed!\n", __func__); + drm_property_unreference_blob(priv->gamma_lut_blob); + priv->gamma_lut_blob = NULL; if (crtc->state->gamma_lut) { - DRM_INFO("%s color_mgmt_changed 2!\n", __func__); + DRM_INFO("%s Set GAMMA\n", __func__); + priv->gamma_lut_blob = drm_property_reference_blob( + crtc->state->gamma_lut); lut = (struct drm_color_lut *) crtc->state->gamma_lut->data; #ifdef CONFIG_AMLOGIC_MEDIA_ENHANCEMENT gamma_lut_size = amvecm_drm_get_gamma_size(0); amvecm_drm_gamma_set(0, lut, gamma_lut_size); #endif + } else { + DRM_DEBUG("%s Disable GAMMA!\n", __func__); + #ifdef CONFIG_AMLOGIC_MEDIA_ENHANCEMENT + amvecm_drm_gamma_disable(0); + #endif } } @@ -258,7 +275,6 @@ int am_meson_crtc_create(struct am_meson_crtc *amcrtc) #ifdef CONFIG_AMLOGIC_MEDIA_ENHANCEMENT amvecm_drm_init(0); - amvecm_drm_gamma_enable(0); gamma_lut_size = amvecm_drm_get_gamma_size(0); drm_mode_crtc_set_gamma_size(crtc, gamma_lut_size); drm_crtc_enable_color_mgmt(crtc, 0, true, gamma_lut_size); diff --git a/drivers/amlogic/drm/meson_drv.h b/drivers/amlogic/drm/meson_drv.h index 331e06f..4260a3c 100644 --- a/drivers/amlogic/drm/meson_drv.h +++ b/drivers/amlogic/drm/meson_drv.h @@ -51,6 +51,7 @@ struct meson_drm { struct drm_gem_object *fbdev_bo; struct drm_plane *primary_plane; struct drm_plane *cursor_plane; + struct drm_property_blob *gamma_lut_blob; #ifdef CONFIG_DRM_MESON_USE_ION struct ion_client *gem_client; diff --git a/drivers/amlogic/media/enhancement/amvecm/amvecm.c b/drivers/amlogic/media/enhancement/amvecm/amvecm.c index ca44621..8deeedd 100644 --- a/drivers/amlogic/media/enhancement/amvecm/amvecm.c +++ b/drivers/amlogic/media/enhancement/amvecm/amvecm.c @@ -4878,6 +4878,47 @@ static int cm2_luma_array[eCM2ColorMd_max][2]; static int cm2_sat_array[eCM2ColorMd_max][2]; static int cm2_hue_by_hs_array[eCM2ColorMd_max][2]; +#define MAX_CLIP_VAL ((1<<30)-1) +static ssize_t amvecm_clamp_color_top_show(struct class *cla, + struct class_attribute *attr, char *buf) +{ + return sprintf(buf, "0x%08x\n", READ_VPP_REG(VPP_CLIP_MISC0)); +} +static ssize_t amvecm_clamp_color_top_store(struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) +{ + size_t r; + uint32_t val; + + r = sscanf(buf, "%x\n", &val); + if ((r != 1) || (val > MAX_CLIP_VAL)) + return -EINVAL; + + WRITE_VPP_REG(VPP_CLIP_MISC0, val); + return count; +} + +static ssize_t amvecm_clamp_color_bottom_show(struct class *cla, + struct class_attribute *attr, char *buf) +{ + return sprintf(buf, "0x%08x\n", READ_VPP_REG(VPP_CLIP_MISC1)); +} +static ssize_t amvecm_clamp_color_bottom_store(struct class *cla, + struct class_attribute *attr, + const char *buf, size_t count) +{ + size_t r; + uint32_t val; + + r = sscanf(buf, "%x\n", &val); + if ((r != 1) || (val > MAX_CLIP_VAL)) + return -EINVAL; + + WRITE_VPP_REG(VPP_CLIP_MISC1, val); + return count; +} + static ssize_t amvecm_cm2_hue_show(struct class *cla, struct class_attribute *attr, char *buf) { @@ -6704,6 +6745,11 @@ static struct class_attribute amvecm_class_attrs[] = { __ATTR(lc, 0644, amvecm_lc_show, amvecm_lc_store), + __ATTR(color_top, 0644, + amvecm_clamp_color_top_show, amvecm_clamp_color_top_store), + __ATTR(color_bottom, 0644, + amvecm_clamp_color_bottom_show, + amvecm_clamp_color_bottom_store), __ATTR_NULL }; -- 2.7.4