mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "CK Hu (胡俊光)" <ck.hu@mediatek.com>
To: "tzimmermann@suse.de" <tzimmermann@suse.de>,
	"chunkuang.hu@kernel.org" <chunkuang.hu@kernel.org>,
	"simona@ffwll.ch" <simona@ffwll.ch>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	"airlied@gmail.com" <airlied@gmail.com>,
	"p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
	"maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>,
	"mripard@kernel.org" <mripard@kernel.org>,
	Nicolas Prado <nfraprado@collabora.com>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>
Cc: "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	Daniel Stone <daniels@collabora.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Ariel D'Alessandro <ariel.dalessandro@collabora.com>,
	"kernel@collabora.com" <kernel@collabora.com>
Subject: Re: [PATCH 05/11] drm/mediatek: ovl: Implement support for Inverse Gamma
Date: Wed, 25 Feb 2026 08:54:05 +0000	[thread overview]
Message-ID: <e6c5ee0f34f6347176f2918e88f6958a493da104.camel@mediatek.com> (raw)
In-Reply-To: <20251223-mtk-ovl-pre-blend-colorops-v1-5-0cb99bd0ab33@collabora.com>

On Tue, 2025-12-23 at 16:44 -0300, Nícolas F. R. A. Prado wrote:
> External email : Please do not click links or open attachments until you have verified the sender or the content.
> 
> 
> The OVL hardware allows selecting between different fixed transfer
> functions for each layer through the Inverse Gamma setting. Available
> functions are scRGB and BT.709. Implement support for it and expose it
> as a colorop through the DRM plane color pipeline uAPI.
> 
> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> ---

[snip]

> 
>  #include <linux/clk.h>
>  #include <linux/component.h>
> @@ -47,6 +50,12 @@
>  #define OVL_CON_CLRFMT_BIT_DEPTH(depth, n)             ((depth) << (4 * (n)))
>  #define OVL_CON_CLRFMT_8_BIT                           (0)
>  #define OVL_CON_CLRFMT_10_BIT                          (1)
> +#define DISP_REG_OVL_WCG_CFG1                  0x2d8
> +#define IGAMMA_EN(layer)                               BIT(0 + 4 * (layer))

BIT(4 * (layer))

> +#define DISP_REG_OVL_WCG_CFG2                  0x2dc
> +#define IGAMMA_MASK(layer)                             GENMASK((layer) * 4 + 1, (layer) * 4)
> +#define IGAMMA_SCRGB                                   0
> +#define IGAMMA_BT709                                   1
>  #define DISP_REG_OVL_ADDR_MT8173               0x0f40
>  #define DISP_REG_OVL_ADDR(ovl, n)              ((ovl)->data->addr + 0x20 * (n))
>  #define DISP_REG_OVL_HDR_ADDR(ovl, n)          ((ovl)->data->addr + 0x20 * (n) + 0x04)
> @@ -492,6 +501,91 @@ static void mtk_ovl_afbc_layer_config(struct mtk_disp_ovl *ovl,
>         }
>  }
> 
> +static int mtk_ovl_colorop_curve_to_reg_val(enum drm_colorop_curve_1d_type curve)
> +{
> +       switch (curve) {
> +       case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF:
> +               return IGAMMA_SCRGB;
> +       case DRM_COLOROP_1D_CURVE_BT2020_OETF:

I don't exactly know what DRM_COLOROP_1D_CURVE_BT2020_OETF mean, but there is DRM_COLOROP_1D_CURVE_BT2020_INV_OETF.
This patch is about inverse gamma, so this should be DRM_COLOROP_1D_CURVE_BT2020_INV_OETF?

> +               return IGAMMA_BT709;
> +       default:
> +               return -EINVAL;
> +       }
> +}
> +
> +static void mtk_ovl_apply_igamma(struct mtk_disp_ovl *ovl, unsigned int idx,
> +                                struct drm_colorop *colorop,
> +                                struct cmdq_pkt *cmdq_pkt)
> +{
> +       int curve_reg_val;
> +
> +       if (colorop->state->bypass) {
> +               /* igamma curve needs to be set to default when igamma is disabled */
> +               curve_reg_val = IGAMMA_SCRGB;

I would like to set igamma curve after disable.
So

if (colorop->state->bypass) {
	mtk_ovl_disable_colorops();
	return;
}
	

> +       } else {
> +               curve_reg_val = mtk_ovl_colorop_curve_to_reg_val(colorop->state->curve_1d_type);
> +               if (curve_reg_val < 0) {
> +                       drm_WARN(ovl->crtc->dev, 1,
> +                                "Invalid curve 1d type %u\n",
> +                                colorop->state->curve_1d_type);
> +                       return;
> +               }
> +       }
> +
> +       mtk_ddp_write_mask(cmdq_pkt,
> +                          field_prep(IGAMMA_MASK(idx), curve_reg_val),
> +                          &ovl->cmdq_reg, ovl->regs, DISP_REG_OVL_WCG_CFG2,
> +                          IGAMMA_MASK(idx));
> +
> +       mtk_ddp_write_mask(cmdq_pkt,
> +                          colorop->state->bypass ? 0 : IGAMMA_EN(idx),
> +                          &ovl->cmdq_reg, ovl->regs, DISP_REG_OVL_WCG_CFG1,
> +                          IGAMMA_EN(idx));
> +}
> +

[snip]

> 
> +static const struct drm_colorop_funcs mtk_ovl_colorop_funcs = {
> +       .destroy = drm_colorop_destroy,
> +};
> +
> +static const u64 igamma_supported_tfs =
> +       BIT(DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF) |
> +       BIT(DRM_COLOROP_1D_CURVE_BT2020_OETF);
> +
> +#define MAX_COLOR_PIPELINE_OPS 3

Why is 3? Is this hardware limitation?
Provide some information about this value,
so we know it's possible to change it or not.

> +
> +static int
> +mtk_ovl_initialize_plane_color_pipeline(struct drm_plane *plane,
> +                                       struct drm_prop_enum_list *pipeline)
> +{
> +       struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS];
> +       struct drm_device *dev = plane->dev;
> +       int i = 0;
> +       int ret;
> +
> +       memset(ops, 0, sizeof(ops));
> +
> +       /* 1st op: OVL's Inverse Gamma */
> +       ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
> +       if (!ops[i]) {
> +               ret = -ENOMEM;
> +               goto err_alloc;
> +       }
> +
> +       ret = drm_plane_colorop_curve_1d_init(dev, ops[i], plane,
> +                                             &mtk_ovl_colorop_funcs,
> +                                             igamma_supported_tfs,
> +                                             DRM_COLOROP_FLAG_ALLOW_BYPASS);

If other sub driver (maybe ovl adapter) also has inverse gamma,
most part of this function looks common and only mtk_ovl_colorop_funcs and igamma_supported_tfs are sub driver specific.
So move the common part to mtk_crtc.c and sub driver provide function to query mtk_ovl_colorop_funcs and igamma_supported_tfs.
(mtk_ovl_colorop_funcs looks not a sub driver specific function, maybe it could be common part)

Regards,
CK

> +       if (ret)
> +               goto err_colorop_init;
> +
> +       pipeline->type = ops[0]->base.id;
> +       pipeline->name = kasprintf(GFP_KERNEL, "Color Pipeline %d", ops[0]->base.id);
> +
> +       return 0;
> +
> +err_colorop_init:
> +       kfree(ops[i]);
> +
> +err_alloc:
> +       i--;
> +       for (; i >= 0; i--) {
> +               drm_colorop_cleanup(ops[i]);
> +               kfree(ops[i]);
> +       }
> +
> +       return ret;
> +}
> +
> 


  reply	other threads:[~2026-02-25  8:54 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-23 19:44 [PATCH 00/11] Plane Color Pipeline support for MediaTek Nícolas F. R. A. Prado
2025-12-23 19:44 ` [PATCH 01/11] drm/mediatek: Introduce DDP plane_colorops_init() hook Nícolas F. R. A. Prado
2026-02-06 10:07   ` AngeloGioacchino Del Regno
2026-02-06 14:13     ` Nícolas F. R. A. Prado
2025-12-23 19:44 ` [PATCH 02/11] drm/mediatek: Initialize colorops when creating plane Nícolas F. R. A. Prado
2026-02-06 10:07   ` AngeloGioacchino Del Regno
2025-12-23 19:44 ` [PATCH 03/11] drm/mediatek: ovl: Add supports_plane_colorops flag Nícolas F. R. A. Prado
2025-12-24  2:17   ` Macpaul Lin (林智斌)
2026-02-06 10:07   ` AngeloGioacchino Del Regno
2026-02-06 14:10     ` Nícolas F. R. A. Prado
2025-12-23 19:44 ` [PATCH 04/11] drm/mediatek: ovl: Enable per-plane color operations on MT8195 Nícolas F. R. A. Prado
2025-12-24  2:19   ` Macpaul Lin (林智斌)
2026-02-06 10:07   ` AngeloGioacchino Del Regno
2026-02-06 14:11     ` Nícolas F. R. A. Prado
2025-12-23 19:44 ` [PATCH 05/11] drm/mediatek: ovl: Implement support for Inverse Gamma Nícolas F. R. A. Prado
2026-02-25  8:54   ` CK Hu (胡俊光) [this message]
2026-02-25  9:40     ` CK Hu (胡俊光)
2025-12-23 19:44 ` [PATCH 06/11] drm/mediatek: Add plane_colorops_init() DDP hook for OVL Nícolas F. R. A. Prado
2025-12-24  2:20   ` Macpaul Lin (林智斌)
2026-02-25  8:58   ` CK Hu (胡俊光)
2025-12-23 19:44 ` [PATCH 07/11] drm/colorop: Introduce HLG EOTF Nícolas F. R. A. Prado
2025-12-24  2:21   ` Macpaul Lin (林智斌)
2026-02-06  8:51   ` Pekka Paalanen
2026-02-06 14:02     ` Nícolas F. R. A. Prado
2025-12-23 19:44 ` [PATCH 08/11] drm/mediatek: ovl: Implement support for Gamma Nícolas F. R. A. Prado
2026-03-03  6:53   ` CK Hu (胡俊光)
2026-03-18 13:04     ` Nícolas F. R. A. Prado
2025-12-23 19:44 ` [PATCH 09/11] drm/colorop: Introduce 3x3 Matrix Nícolas F. R. A. Prado
2026-02-06  9:27   ` Pekka Paalanen
2026-02-06 14:05     ` Nícolas F. R. A. Prado
2025-12-23 19:44 ` [PATCH 10/11] drm/mediatek: ovl: Enable support for R2R Color Space Conversion Nícolas F. R. A. Prado
2026-03-03  7:16   ` CK Hu (胡俊光)
2026-03-18 13:18     ` Nícolas F. R. A. Prado
2025-12-23 19:44 ` [PATCH 11/11] drm/mediatek: Check 3x3 Matrix colorop has DATA set Nícolas F. R. A. Prado
2026-03-03  7:21   ` CK Hu (胡俊光)
2025-12-29 18:53 ` [PATCH 00/11] Plane Color Pipeline support for MediaTek Shengyu Qu
2026-01-01 12:37   ` Shengyu Qu
2026-01-02 18:40     ` Harry Wentland
2026-02-06  9:09       ` Pekka Paalanen
2026-02-06 13:28         ` Nícolas F. R. A. Prado
2026-02-26  6:24           ` CK Hu (胡俊光)
2026-02-26 10:26             ` AngeloGioacchino Del Regno
2026-02-26 10:51               ` AngeloGioacchino Del Regno
2026-03-18 12:43                 ` Nícolas F. R. A. Prado
2026-01-07 20:01   ` Xaver Hugl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e6c5ee0f34f6347176f2918e88f6958a493da104.camel@mediatek.com \
    --to=ck.hu@mediatek.com \
    --cc=airlied@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=ariel.dalessandro@collabora.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=daniels@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel@collabora.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mripard@kernel.org \
    --cc=nfraprado@collabora.com \
    --cc=p.zabel@pengutronix.de \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®