diff mbox series

[v3,5/9] drm/mediatek: Add gamma support different lut_bits for other SoC

Message ID 20220911153734.24243-6-jason-jh.lin@mediatek.com (mailing list archive)
State New, archived
Headers show
Series Add gamma lut support for mt8195 | expand

Commit Message

Jason-JH Lin (林睿祥) Sept. 11, 2022, 3:37 p.m. UTC
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(-)

Comments

AngeloGioacchino Del Regno Sept. 12, 2022, 10:25 a.m. UTC | #1
Il 11/09/22 17:37, Jason-JH.Lin ha scritto:
> 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 e69d0b205b9a..155fb5d94d79 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;

Please fix this double assignment like shown in the comment for patch [4/9].

Thanks,
Angelo
Jason-JH Lin (林睿祥) Sept. 14, 2022, 1:36 a.m. UTC | #2
Hi Angelo,

Thanks for the reviews.

On Mon, 2022-09-12 at 12:25 +0200, AngeloGioacchino Del Regno wrote:
> Il 11/09/22 17:37, Jason-JH.Lin ha scritto:
> > 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 e69d0b205b9a..155fb5d94d79 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;
> 
> Please fix this double assignment like shown in the comment for patch
> [4/9].
> 
> Thanks,
> Angelo
> 
OK, I'll fix this.
Regards,
Jason-JH.Lin
diff mbox series

Patch

diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
index e69d0b205b9a..155fb5d94d79 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[] = {