diff options
author | Bibby Hsieh <bibby.hsieh@mediatek.com> | 2016-07-28 10:22:54 +0800 |
---|---|---|
committer | Philipp Zabel <p.zabel@pengutronix.de> | 2016-08-11 10:52:22 +0200 |
commit | 2f3f4dda747c0619594d13996e65598ab675c60c (patch) | |
tree | 7eeecac304f67c6007d8c3f2da969c8183ff66dc /drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | |
parent | e0a5d33702451329b7da70a15fad3b919e441401 (diff) |
drm/mediatek: Add gamma correction.
Add gamma set function to correct brightness values.
It applies arbitrary mapping curve to compensate the
incorrect transfer function of the panel.
Signed-off-by: Bibby Hsieh <bibby.hsieh@mediatek.com>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Diffstat (limited to 'drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c')
-rw-r--r-- | drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c index ba895c8fd91d..42cd587d6b9b 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c @@ -24,6 +24,7 @@ #include "mtk_drm_drv.h" #include "mtk_drm_plane.h" #include "mtk_drm_ddp_comp.h" +#include "mtk_drm_crtc.h" #define DISP_OD_EN 0x0000 #define DISP_OD_INTEN 0x0008 @@ -42,7 +43,11 @@ #define DISP_AAL_SIZE 0x0030 #define DISP_GAMMA_EN 0x0000 +#define DISP_GAMMA_CFG 0x0020 #define DISP_GAMMA_SIZE 0x0030 +#define DISP_GAMMA_LUT 0x0700 + +#define LUT_10BIT_MASK 0x03ff #define OD_RELAY_MODE BIT(0) @@ -54,6 +59,7 @@ #define AAL_EN BIT(0) #define GAMMA_EN BIT(0) +#define GAMMA_LUT_EN BIT(1) static void mtk_color_config(struct mtk_ddp_comp *comp, unsigned int w, unsigned int h, unsigned int vrefresh) @@ -118,13 +124,38 @@ static void mtk_gamma_stop(struct mtk_ddp_comp *comp) writel_relaxed(0x0, comp->regs + DISP_GAMMA_EN); } +static void mtk_gamma_set(struct mtk_ddp_comp *comp, + struct drm_crtc_state *state) +{ + unsigned int i, reg; + struct drm_color_lut *lut; + void __iomem *lut_base; + u32 word; + + if (state->gamma_lut) { + reg = readl(comp->regs + DISP_GAMMA_CFG); + reg = reg | GAMMA_LUT_EN; + writel(reg, comp->regs + DISP_GAMMA_CFG); + lut_base = comp->regs + DISP_GAMMA_LUT; + lut = (struct drm_color_lut *)state->gamma_lut->data; + for (i = 0; i < MTK_LUT_SIZE; i++) { + word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) + + (((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) + + ((lut[i].blue >> 6) & LUT_10BIT_MASK); + writel(word, (lut_base + i * 4)); + } + } +} + static const struct mtk_ddp_comp_funcs ddp_aal = { + .gamma_set = mtk_gamma_set, .config = mtk_aal_config, .start = mtk_aal_start, .stop = mtk_aal_stop, }; static const struct mtk_ddp_comp_funcs ddp_gamma = { + .gamma_set = mtk_gamma_set, .config = mtk_gamma_config, .start = mtk_gamma_start, .stop = mtk_gamma_stop, |