Message ID | 20220912013006.27541-6-jason-jh.lin@mediatek.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add gamma lut support for mt8195 | expand |
Hi, Jason: On Mon, 2022-09-12 at 09:30 +0800, Jason-JH.Lin wrote: > Add lut_bits in gamma driver data for each SoC and adjust the usage > of lut_bits in mtk_drm_gamma_set_common(). > > Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com> > --- > drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 36 ++++++++++++++++----- > -- > 1 file changed, 25 insertions(+), 11 deletions(-) > > diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c > b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c > index 0a1022032b71..be82d15a5204 100644 > --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c > +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c > @@ -25,11 +25,14 @@ > > #define LUT_10BIT_MASK 0x03ff > #define LUT_SIZE_DEFAULT 512 /* for setting > gamma lut from AAL */ > +#define LUT_BITS_DEFAULT 10 > +#define LUT_INPUT_BITS 16 /* input lut > bit from application */ I think we should use drm_color_lut_extract() to let the input bits transparent. So add one patch to use drm_color_lut_extract(), and then apply this patch. Regards, CK > > struct mtk_disp_gamma_data { > bool has_dither; > bool lut_diff; > u16 lut_size; > + u8 lut_bits; > }; > > /* > @@ -72,17 +75,23 @@ void mtk_gamma_set_common(struct device *dev, > void __iomem *regs, struct drm_crt > struct mtk_disp_gamma *gamma = dev_get_drvdata(dev); > bool lut_diff = false; > u16 lut_size = LUT_SIZE_DEFAULT; > + u8 lut_bits = LUT_BITS_DEFAULT; > + u8 shift_bits; > unsigned int i, reg; > struct drm_color_lut *lut; > void __iomem *lut_base; > - u32 word; > + u32 word, mask; > u32 diff[3] = {0}; > > if (gamma && gamma->data) { > lut_diff = gamma->data->lut_diff; > lut_size = gamma->data->lut_size; > + lut_bits = gamma->data->lut_bits; > } > > + shift_bits = LUT_INPUT_BITS - lut_bits; > + mask = GENMASK(lut_bits - 1, 0); > + > if (state->gamma_lut) { > reg = readl(regs + DISP_GAMMA_CFG); > reg = reg | GAMMA_LUT_EN; > @@ -92,17 +101,20 @@ void mtk_gamma_set_common(struct device *dev, > void __iomem *regs, struct drm_crt > for (i = 0; i < lut_size; i++) { > > if (!lut_diff || (i % 2 == 0)) { > - word = (((lut[i].red >> 6) & > LUT_10BIT_MASK) << 20) + > - (((lut[i].green >> 6) & > LUT_10BIT_MASK) << 10) + > - ((lut[i].blue >> 6) & > LUT_10BIT_MASK); > + word = (((lut[i].red >> shift_bits) & > mask) << 20) + > + (((lut[i].green >> shift_bits) > & mask) << 10) + > + ((lut[i].blue >> shift_bits) & > mask); > } else { > - diff[0] = (lut[i].red >> 6) - (lut[i - > 1].red >> 6); > - diff[1] = (lut[i].green >> 6) - (lut[i > - 1].green >> 6); > - diff[2] = (lut[i].blue >> 6) - (lut[i - > 1].blue >> 6); > - > - word = ((diff[0] & LUT_10BIT_MASK) << > 20) + > - ((diff[1] & LUT_10BIT_MASK) << > 10) + > - (diff[2] & LUT_10BIT_MASK); > + diff[0] = (lut[i].red >> shift_bits) - > + (lut[i - 1].red >> > shift_bits); > + diff[1] = (lut[i].green >> shift_bits) > - > + (lut[i - 1].green >> > shift_bits); > + diff[2] = (lut[i].blue >> shift_bits) - > + (lut[i - 1].blue >> > shift_bits); > + > + word = ((diff[0] & mask) << 20) + > + ((diff[1] & mask) << 10) + > + (diff[2] & mask); > } > writel(word, (lut_base + i * 4)); > } > @@ -209,11 +221,13 @@ static int mtk_disp_gamma_remove(struct > platform_device *pdev) > static const struct mtk_disp_gamma_data mt8173_gamma_driver_data = { > .has_dither = true, > .lut_size = 512, > + .lut_bits = 10, > }; > > static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = { > .lut_diff = true, > .lut_size = 512, > + .lut_bits = 10, > }; > > static const struct of_device_id mtk_disp_gamma_driver_dt_match[] = > {
Hi CK, Thanks for the reviews. On Mon, 2022-09-12 at 11:40 +0800, CK Hu wrote: > Hi, Jason: > > On Mon, 2022-09-12 at 09:30 +0800, Jason-JH.Lin wrote: > > Add lut_bits in gamma driver data for each SoC and adjust the usage > > of lut_bits in mtk_drm_gamma_set_common(). > > > > Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com> > > --- > > drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 36 ++++++++++++++++--- > > -- > > -- > > 1 file changed, 25 insertions(+), 11 deletions(-) > > > > diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c > > b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c > > index 0a1022032b71..be82d15a5204 100644 > > --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c > > +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c > > @@ -25,11 +25,14 @@ > > > > #define LUT_10BIT_MASK 0x03ff > > #define LUT_SIZE_DEFAULT 512 /* for setting > > gamma lut from AAL */ > > +#define LUT_BITS_DEFAULT 10 > > +#define LUT_INPUT_BITS 16 /* input lut > > bit from application */ > > I think we should use drm_color_lut_extract() to let the input bits > transparent. So add one patch to use drm_color_lut_extract(), and > then > apply this patch. > > Regards, > CK OK, I'll separate it to 2 patches, 1 is using drm_color_lut_extract() to handle with input lut data and the other is adding gamma support lut_bits and shift_bits. Regards, Jason-JH.Lin
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c index 0a1022032b71..be82d15a5204 100644 --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c @@ -25,11 +25,14 @@ #define LUT_10BIT_MASK 0x03ff #define LUT_SIZE_DEFAULT 512 /* for setting gamma lut from AAL */ +#define LUT_BITS_DEFAULT 10 +#define LUT_INPUT_BITS 16 /* input lut bit from application */ struct mtk_disp_gamma_data { bool has_dither; bool lut_diff; u16 lut_size; + u8 lut_bits; }; /* @@ -72,17 +75,23 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt struct mtk_disp_gamma *gamma = dev_get_drvdata(dev); bool lut_diff = false; u16 lut_size = LUT_SIZE_DEFAULT; + u8 lut_bits = LUT_BITS_DEFAULT; + u8 shift_bits; unsigned int i, reg; struct drm_color_lut *lut; void __iomem *lut_base; - u32 word; + u32 word, mask; u32 diff[3] = {0}; if (gamma && gamma->data) { lut_diff = gamma->data->lut_diff; lut_size = gamma->data->lut_size; + lut_bits = gamma->data->lut_bits; } + shift_bits = LUT_INPUT_BITS - lut_bits; + mask = GENMASK(lut_bits - 1, 0); + if (state->gamma_lut) { reg = readl(regs + DISP_GAMMA_CFG); reg = reg | GAMMA_LUT_EN; @@ -92,17 +101,20 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs, struct drm_crt for (i = 0; i < lut_size; i++) { if (!lut_diff || (i % 2 == 0)) { - word = (((lut[i].red >> 6) & LUT_10BIT_MASK) << 20) + - (((lut[i].green >> 6) & LUT_10BIT_MASK) << 10) + - ((lut[i].blue >> 6) & LUT_10BIT_MASK); + word = (((lut[i].red >> shift_bits) & mask) << 20) + + (((lut[i].green >> shift_bits) & mask) << 10) + + ((lut[i].blue >> shift_bits) & mask); } else { - diff[0] = (lut[i].red >> 6) - (lut[i - 1].red >> 6); - diff[1] = (lut[i].green >> 6) - (lut[i - 1].green >> 6); - diff[2] = (lut[i].blue >> 6) - (lut[i - 1].blue >> 6); - - word = ((diff[0] & LUT_10BIT_MASK) << 20) + - ((diff[1] & LUT_10BIT_MASK) << 10) + - (diff[2] & LUT_10BIT_MASK); + diff[0] = (lut[i].red >> shift_bits) - + (lut[i - 1].red >> shift_bits); + diff[1] = (lut[i].green >> shift_bits) - + (lut[i - 1].green >> shift_bits); + diff[2] = (lut[i].blue >> shift_bits) - + (lut[i - 1].blue >> shift_bits); + + word = ((diff[0] & mask) << 20) + + ((diff[1] & mask) << 10) + + (diff[2] & mask); } writel(word, (lut_base + i * 4)); } @@ -209,11 +221,13 @@ static int mtk_disp_gamma_remove(struct platform_device *pdev) static const struct mtk_disp_gamma_data mt8173_gamma_driver_data = { .has_dither = true, .lut_size = 512, + .lut_bits = 10, }; static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = { .lut_diff = true, .lut_size = 512, + .lut_bits = 10, }; static const struct of_device_id mtk_disp_gamma_driver_dt_match[] = {
Add lut_bits in gamma driver data for each SoC and adjust the usage of lut_bits in mtk_drm_gamma_set_common(). Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com> --- drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 36 ++++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-)