The gamma block is one of the components of the video pipeline on some MediaTek SoCs, such as the MT8365. It applies a gamma correction lookup table to the pixel stream.
U-Boot has no use for a gamma curve, so the driver only programs the frame size and enables the block, leaving the lookup table disabled. The driver matches "mediatek,mt8183-disp-gamma", the generic fallback the MT8365 gamma0 node carries behind "mediatek,mt8365-disp-gamma", so a single entry covers every SoC reusing that block. Signed-off-by: Julien Stephan <[email protected]> --- drivers/video/mediatek/mtk_disp_gamma.c | 51 +++++++++++++++++++++++++++++++++ drivers/video/mediatek/mtk_disp_gamma.h | 31 ++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/drivers/video/mediatek/mtk_disp_gamma.c b/drivers/video/mediatek/mtk_disp_gamma.c new file mode 100644 index 00000000000..335e7216277 --- /dev/null +++ b/drivers/video/mediatek/mtk_disp_gamma.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * MediaTek Video GAMMA support + * + * Copyright (c) 2026 BayLibre, SAS. + * Author: Julien Masson <[email protected]> + * Julien Stephan <[email protected]> + */ + +#include <dm/device.h> +#include <fdtdec.h> +#include <linux/bitfield.h> +#include <linux/bitops.h> + +#include "mtk_disp_comp.h" +#include "mtk_disp_gamma.h" + +#define DISP_GAMMA_EN 0x00 +#define GAMMA_EN BIT(0) + +#define DISP_GAMMA_SIZE 0x30 +#define DISP_GAMMA_SIZE_HSIZE GENMASK(28, 16) +#define DISP_GAMMA_SIZE_VSIZE GENMASK(12, 0) + +void mtk_gamma_config(struct udevice *dev, const struct display_timing *timing) +{ + u32 sz; + + sz = FIELD_PREP(DISP_GAMMA_SIZE_HSIZE, timing->hactive.typ) | + FIELD_PREP(DISP_GAMMA_SIZE_VSIZE, timing->vactive.typ); + + mtk_disp_comp_write(dev, DISP_GAMMA_SIZE, sz); +} + +void mtk_gamma_start(struct udevice *dev) +{ + mtk_disp_comp_write(dev, DISP_GAMMA_EN, GAMMA_EN); +} + +static const struct udevice_id mtk_disp_gamma_ids[] = { + { .compatible = "mediatek,mt8183-disp-gamma" }, + { } +}; + +U_BOOT_DRIVER(mtk_disp_gamma) = { + .name = "mtk_disp_gamma", + .id = UCLASS_MISC, + .of_match = mtk_disp_gamma_ids, + .probe = mtk_disp_comp_probe, + .priv_auto = sizeof(struct mtk_disp_comp_priv), +}; diff --git a/drivers/video/mediatek/mtk_disp_gamma.h b/drivers/video/mediatek/mtk_disp_gamma.h new file mode 100644 index 00000000000..8dc171b8b16 --- /dev/null +++ b/drivers/video/mediatek/mtk_disp_gamma.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2026 BayLibre, SAS. + * Author: Julien Masson <[email protected]> + * Julien Stephan <[email protected]> + */ + +#ifndef _MTK_DISP_GAMMA_H +#define _MTK_DISP_GAMMA_H + +struct display_timing; +struct udevice; + +/** + * mtk_gamma_config() - configure the gamma block + * @dev: gamma device + * @timing: display timing, giving the frame size + * + * Set the frame size of the gamma block. + */ +void mtk_gamma_config(struct udevice *dev, const struct display_timing *timing); + +/** + * mtk_gamma_start() - start the gamma block + * @dev: gamma device + * + * Start the gamma block. + */ +void mtk_gamma_start(struct udevice *dev); + +#endif /* _MTK_DISP_GAMMA_H */ -- 2.55.0
