[PATCH v8 07/13] drm/mediatek: gamma: Support specifying number of bits per LUT component

AngeloGioacchino Del Regno posted 13 patches 1 year, 3 months ago
There is a newer version of this series
[PATCH v8 07/13] drm/mediatek: gamma: Support specifying number of bits per LUT component
Posted by AngeloGioacchino Del Regno 1 year, 3 months ago
New SoCs, like MT8195, not only may support bigger lookup tables, but
have got a different register layout to support bigger precision:
support specifying the number of `lut_bits` for each SoC and use it
in mtk_gamma_set_common() to perform the right calculation.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Reviewed-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
---
 drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
index 4f642fed432f..a6f7af1a9e8e 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
@@ -37,6 +37,7 @@ struct mtk_disp_gamma_data {
 	bool has_dither;
 	bool lut_diff;
 	u16 lut_size;
+	u8 lut_bits;
 };
 
 /*
@@ -78,6 +79,7 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs,
 	struct drm_color_lut *lut;
 	void __iomem *lut_base;
 	bool lut_diff;
+	u8 lut_bits;
 	u32 cfg_val, word;
 
 	/* If there's no gamma lut there's nothing to do here. */
@@ -87,10 +89,13 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs,
 	/* If we're called from AAL, dev is NULL */
 	gamma = dev ? dev_get_drvdata(dev) : NULL;
 
-	if (gamma && gamma->data)
+	if (gamma && gamma->data) {
 		lut_diff = gamma->data->lut_diff;
-	else
+		lut_bits = gamma->data->lut_bits;
+	} else {
 		lut_diff = false;
+		lut_bits = LUT_BITS_DEFAULT;
+	}
 
 	cfg_val = readl(regs + DISP_GAMMA_CFG);
 	lut_base = regs + DISP_GAMMA_LUT;
@@ -98,9 +103,9 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs,
 	for (i = 0; i < lut_size; i++) {
 		struct drm_color_lut diff, hwlut;
 
-		hwlut.red = drm_color_lut_extract(lut[i].red, LUT_BITS_DEFAULT);
-		hwlut.green = drm_color_lut_extract(lut[i].green, LUT_BITS_DEFAULT);
-		hwlut.blue = drm_color_lut_extract(lut[i].blue, LUT_BITS_DEFAULT);
+		hwlut.red = drm_color_lut_extract(lut[i].red, lut_bits);
+		hwlut.green = drm_color_lut_extract(lut[i].green, lut_bits);
+		hwlut.blue = drm_color_lut_extract(lut[i].blue, lut_bits);
 
 		if (!lut_diff || (i % 2 == 0)) {
 			word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, hwlut.red);
@@ -108,13 +113,13 @@ void mtk_gamma_set_common(struct device *dev, void __iomem *regs,
 			word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B, hwlut.blue);
 		} else {
 			diff.red = lut[i].red - lut[i - 1].red;
-			diff.red = drm_color_lut_extract(diff.red, LUT_BITS_DEFAULT);
+			diff.red = drm_color_lut_extract(diff.red, lut_bits);
 
 			diff.green = lut[i].green - lut[i - 1].green;
-			diff.green = drm_color_lut_extract(diff.green, LUT_BITS_DEFAULT);
+			diff.green = drm_color_lut_extract(diff.green, lut_bits);
 
 			diff.blue = lut[i].blue - lut[i - 1].blue;
-			diff.blue = drm_color_lut_extract(diff.blue, LUT_BITS_DEFAULT);
+			diff.blue = drm_color_lut_extract(diff.blue, lut_bits);
 
 			word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R, diff.red);
 			word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G, diff.green);
@@ -231,10 +236,12 @@ 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_bits = 10,
 	.lut_size = 512,
 };
 
 static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = {
+	.lut_bits = 10,
 	.lut_diff = true,
 	.lut_size = 512,
 };
-- 
2.41.0
Re: [PATCH v8 07/13] drm/mediatek: gamma: Support specifying number of bits per LUT component
Posted by CK Hu (胡俊光) 1 year, 3 months ago
Hi, Angelo:

On Tue, 2023-08-01 at 13:58 +0200, AngeloGioacchino Del Regno wrote:
> New SoCs, like MT8195, not only may support bigger lookup tables, but
> have got a different register layout to support bigger precision:
> support specifying the number of `lut_bits` for each SoC and use it
> in mtk_gamma_set_common() to perform the right calculation.
> 
> Signed-off-by: AngeloGioacchino Del Regno <
> angelogioacchino.delregno@collabora.com>
> Reviewed-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
> Reviewed-by: Alexandre Mergnat <amergnat@baylibre.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_disp_gamma.c | 23 +++++++++++++++----
> ----
>  1 file changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
> b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
> index 4f642fed432f..a6f7af1a9e8e 100644
> --- a/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
> +++ b/drivers/gpu/drm/mediatek/mtk_disp_gamma.c
> @@ -37,6 +37,7 @@ struct mtk_disp_gamma_data {
>  	bool has_dither;
>  	bool lut_diff;
>  	u16 lut_size;
> +	u8 lut_bits;
>  };
>  
>  /*
> @@ -78,6 +79,7 @@ void mtk_gamma_set_common(struct device *dev, void
> __iomem *regs,
>  	struct drm_color_lut *lut;
>  	void __iomem *lut_base;
>  	bool lut_diff;
> +	u8 lut_bits;
>  	u32 cfg_val, word;
>  
>  	/* If there's no gamma lut there's nothing to do here. */
> @@ -87,10 +89,13 @@ void mtk_gamma_set_common(struct device *dev,
> void __iomem *regs,
>  	/* If we're called from AAL, dev is NULL */
>  	gamma = dev ? dev_get_drvdata(dev) : NULL;
>  
> -	if (gamma && gamma->data)
> +	if (gamma && gamma->data) {
>  		lut_diff = gamma->data->lut_diff;
> -	else
> +		lut_bits = gamma->data->lut_bits;
> +	} else {
>  		lut_diff = false;
> +		lut_bits = LUT_BITS_DEFAULT;

LUT_BITS_DEFAULT is only for AAL driver, so place this definition in
AAL driver and pass it into this function.

Regards,
CK

> +	}
>  
>  	cfg_val = readl(regs + DISP_GAMMA_CFG);
>  	lut_base = regs + DISP_GAMMA_LUT;
> @@ -98,9 +103,9 @@ void mtk_gamma_set_common(struct device *dev, void
> __iomem *regs,
>  	for (i = 0; i < lut_size; i++) {
>  		struct drm_color_lut diff, hwlut;
>  
> -		hwlut.red = drm_color_lut_extract(lut[i].red,
> LUT_BITS_DEFAULT);
> -		hwlut.green = drm_color_lut_extract(lut[i].green,
> LUT_BITS_DEFAULT);
> -		hwlut.blue = drm_color_lut_extract(lut[i].blue,
> LUT_BITS_DEFAULT);
> +		hwlut.red = drm_color_lut_extract(lut[i].red,
> lut_bits);
> +		hwlut.green = drm_color_lut_extract(lut[i].green,
> lut_bits);
> +		hwlut.blue = drm_color_lut_extract(lut[i].blue,
> lut_bits);
>  
>  		if (!lut_diff || (i % 2 == 0)) {
>  			word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R,
> hwlut.red);
> @@ -108,13 +113,13 @@ void mtk_gamma_set_common(struct device *dev,
> void __iomem *regs,
>  			word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_B,
> hwlut.blue);
>  		} else {
>  			diff.red = lut[i].red - lut[i - 1].red;
> -			diff.red = drm_color_lut_extract(diff.red,
> LUT_BITS_DEFAULT);
> +			diff.red = drm_color_lut_extract(diff.red,
> lut_bits);
>  
>  			diff.green = lut[i].green - lut[i - 1].green;
> -			diff.green = drm_color_lut_extract(diff.green,
> LUT_BITS_DEFAULT);
> +			diff.green = drm_color_lut_extract(diff.green,
> lut_bits);
>  
>  			diff.blue = lut[i].blue - lut[i - 1].blue;
> -			diff.blue = drm_color_lut_extract(diff.blue,
> LUT_BITS_DEFAULT);
> +			diff.blue = drm_color_lut_extract(diff.blue,
> lut_bits);
>  
>  			word = FIELD_PREP(DISP_GAMMA_LUT_10BIT_R,
> diff.red);
>  			word |= FIELD_PREP(DISP_GAMMA_LUT_10BIT_G,
> diff.green);
> @@ -231,10 +236,12 @@ 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_bits = 10,
>  	.lut_size = 512,
>  };
>  
>  static const struct mtk_disp_gamma_data mt8183_gamma_driver_data = {
> +	.lut_bits = 10,
>  	.lut_diff = true,
>  	.lut_size = 512,
>  };