dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/hisilicon/hibmc: add gamma_set function
@ 2019-12-23  7:49 Zhihui Chen
  2020-02-13 10:11 ` Xinliang Liu
  0 siblings, 1 reply; 2+ messages in thread
From: Zhihui Chen @ 2019-12-23  7:49 UTC (permalink / raw)
  To: xinliang.liu, zourongrong, dri-devel
  Cc: puck.chen, kong.kongxinwei, baowenyi, Zhihui Chen, allan.wang

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>
---
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_de.c    | 37 +++++++++++++++++++
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h  |  5 +++
 2 files changed, 42 insertions(+)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
index 24de937c1cb1..f1ce6cb099d0 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
@@ -456,6 +456,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,
@@ -465,6 +501,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 = {
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
index b9e20cfcfb5a..9b7e85947113 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
@@ -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
 
@@ -193,5 +196,7 @@
 #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
-- 
2.20.1


_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/hisilicon/hibmc: add gamma_set function
  2019-12-23  7:49 [PATCH] drm/hisilicon/hibmc: add gamma_set function Zhihui Chen
@ 2020-02-13 10:11 ` Xinliang Liu
  0 siblings, 0 replies; 2+ messages in thread
From: Xinliang Liu @ 2020-02-13 10:11 UTC (permalink / raw)
  To: Zhihui Chen
  Cc: puck.chen, baowenyi, dri-devel, kong.kongxinwei, zourongrong, allan.wang


[-- Attachment #1.1: Type: text/plain, Size: 3607 bytes --]

On Mon, 23 Dec 2019 at 15:50, Zhihui Chen <chenzhihui4@huawei.com> wrote:

> 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>
>

Thanks for the patch.
Acked-by: Xinliang Liu <xinliang.liu@linaro.org>
Applied to drm-misc-next.


> ---
>  .../gpu/drm/hisilicon/hibmc/hibmc_drm_de.c    | 37 +++++++++++++++++++
>  .../gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h  |  5 +++
>  2 files changed, 42 insertions(+)
>
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> index 24de937c1cb1..f1ce6cb099d0 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c
> @@ -456,6 +456,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,
> @@ -465,6 +501,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 = {
> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
> b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
> index b9e20cfcfb5a..9b7e85947113 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
> @@ -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
>
> @@ -193,5 +196,7 @@
>  #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
> --
> 2.20.1
>
>
>

[-- Attachment #1.2: Type: text/html, Size: 4823 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-13 10:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-23  7:49 [PATCH] drm/hisilicon/hibmc: add gamma_set function Zhihui Chen
2020-02-13 10:11 ` Xinliang Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).