]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/hisilicon/hibmc: add gamma_set function
authorZhihui Chen <chenzhihui4@huawei.com>
Mon, 23 Dec 2019 07:49:10 +0000 (15:49 +0800)
committerXinliang Liu <xinliang.liu@linaro.org>
Thu, 13 Feb 2020 09:52:41 +0000 (09:52 +0000)
Add gamma_set function, and we can also use it to adjust the brightness
of the display.

Signed-off-by: Zhihui Chen <chenzhihui4@huawei.com>
Signed-off-by: Xinliang Liu <xinliang.liu@linaro.org>
Acked-by: Xinliang Liu <xinliang.liu@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20191223074910.1030-1-chenzhihui4@huawei.com
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h

index c41d8f82e82a278529cd160daf5fb5b8fcbfccce..561b398ca93d132ad97f56adba9d18f45575cc31 100644 (file)
@@ -454,6 +454,42 @@ static void hibmc_crtc_disable_vblank(struct drm_crtc *crtc)
               priv->mmio + HIBMC_RAW_INTERRUPT_EN);
 }
 
+static void hibmc_crtc_load_lut(struct drm_crtc *crtc)
+{
+       struct hibmc_drm_private *priv = crtc->dev->dev_private;
+       void __iomem   *mmio = priv->mmio;
+       u16 *r, *g, *b;
+       unsigned int reg;
+       int i;
+
+       r = crtc->gamma_store;
+       g = r + crtc->gamma_size;
+       b = g + crtc->gamma_size;
+
+       for (i = 0; i < crtc->gamma_size; i++) {
+               unsigned int offset = i << 2;
+               u8 red = *r++ >> 8;
+               u8 green = *g++ >> 8;
+               u8 blue = *b++ >> 8;
+               u32 rgb = (red << 16) | (green << 8) | blue;
+
+               writel(rgb, mmio + HIBMC_CRT_PALETTE + offset);
+       }
+
+       reg = readl(priv->mmio + HIBMC_CRT_DISP_CTL);
+       reg |= HIBMC_FIELD(HIBMC_CTL_DISP_CTL_GAMMA, 1);
+       writel(reg, priv->mmio + HIBMC_CRT_DISP_CTL);
+}
+
+static int hibmc_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
+                               u16 *blue, uint32_t size,
+                               struct drm_modeset_acquire_ctx *ctx)
+{
+       hibmc_crtc_load_lut(crtc);
+
+       return 0;
+}
+
 static const struct drm_crtc_funcs hibmc_crtc_funcs = {
        .page_flip = drm_atomic_helper_page_flip,
        .set_config = drm_atomic_helper_set_config,
@@ -463,6 +499,7 @@ static const struct drm_crtc_funcs hibmc_crtc_funcs = {
        .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
        .enable_vblank = hibmc_crtc_enable_vblank,
        .disable_vblank = hibmc_crtc_disable_vblank,
+       .gamma_set = hibmc_crtc_gamma_set,
 };
 
 static const struct drm_crtc_helper_funcs hibmc_crtc_helper_funcs = {
index b9e20cfcfb5a526bdc0f8e65a9a2237cc6e7313f..9b7e85947113930fbdf1c2d41555b9fac4eb458b 100644 (file)
@@ -91,6 +91,9 @@
 #define HIBMC_CRT_DISP_CTL_TIMING(x)           ((x) << 8)
 #define HIBMC_CRT_DISP_CTL_TIMING_MASK         0x100
 
+#define HIBMC_CTL_DISP_CTL_GAMMA(x)            ((x) << 3)
+#define HIBMC_CTL_DISP_CTL_GAMMA_MASK          0x08
+
 #define HIBMC_CRT_DISP_CTL_PLANE(x)            ((x) << 2)
 #define HIBMC_CRT_DISP_CTL_PLANE_MASK          4
 
 #define CRT_PLL2_HS_148MHZ                     0xB0CCCCCD
 #define CRT_PLL2_HS_193MHZ                     0xC0872B02
 
+#define HIBMC_CRT_PALETTE                       0x80C00
+
 #define HIBMC_FIELD(field, value) (field(value) & field##_MASK)
 #endif