diff mbox series

[v2] drm/rockchip: vop: Fix color for RGB888/BGR888 format on VOP full

Message ID 20231026191500.2994225-1-jonas@kwiboo.se (mailing list archive)
State New, archived
Headers show
Series [v2] drm/rockchip: vop: Fix color for RGB888/BGR888 format on VOP full | expand

Commit Message

Jonas Karlman Oct. 26, 2023, 7:14 p.m. UTC
Use of DRM_FORMAT_RGB888 and DRM_FORMAT_BGR888 on e.g. RK3288, RK3328
and RK3399 result in wrong colors being displayed.

The issue can be observed using modetest:

  modetest -s <connector_id>@<crtc_id>:1920x1080-60@RG24
  modetest -s <connector_id>@<crtc_id>:1920x1080-60@BG24

Vendor 4.4 kernel apply an inverted rb swap for these formats on VOP
full framework (IP version 3.x) compared to VOP little framework (2.x).

Fix colors by applying different rb swap for VOP full framework (3.x)
and VOP little framework (2.x) similar to vendor 4.4 kernel.

Fixes: 85a359f25388 ("drm/rockchip: Add BGR formats to VOP")
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
Changes in v2:
- Add comment about different rb swap for IP version 3.x and 2.x
- Add fixes tag

 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Christopher Obbard Oct. 26, 2023, 8:02 p.m. UTC | #1
Hi Jonas,

On Thu, 2023-10-26 at 19:14 +0000, Jonas Karlman wrote:
> Use of DRM_FORMAT_RGB888 and DRM_FORMAT_BGR888 on e.g. RK3288, RK3328
> and RK3399 result in wrong colors being displayed.
> 
> The issue can be observed using modetest:
> 
>   modetest -s <connector_id>@<crtc_id>:1920x1080-60@RG24
>   modetest -s <connector_id>@<crtc_id>:1920x1080-60@BG24
> 
> Vendor 4.4 kernel apply an inverted rb swap for these formats on VOP
> full framework (IP version 3.x) compared to VOP little framework (2.x).
> 
> Fix colors by applying different rb swap for VOP full framework (3.x)
> and VOP little framework (2.x) similar to vendor 4.4 kernel.
> 
> Fixes: 85a359f25388 ("drm/rockchip: Add BGR formats to VOP")
> Signed-off-by: Jonas Karlman <jonas@kwiboo.se>

Reviewed-by: Christopher Obbard <chris.obbard@collabora.com>
Tested-by: Christopher Obbard <chris.obbard@collabora.com>

Since you missed adding my *-by tags in v2.

> ---
> Changes in v2:
> - Add comment about different rb swap for IP version 3.x and 2.x
> - Add fixes tag
> 
>  drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> index b3d0b6ae9294..ed2ed25959a2 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> @@ -247,14 +247,22 @@ static inline void vop_cfg_done(struct vop *vop)
>  	VOP_REG_SET(vop, common, cfg_done, 1);
>  }
>  
> -static bool has_rb_swapped(uint32_t format)
> +static bool has_rb_swapped(uint32_t version, uint32_t format)
>  {
>  	switch (format) {
>  	case DRM_FORMAT_XBGR8888:
>  	case DRM_FORMAT_ABGR8888:
> -	case DRM_FORMAT_BGR888:
>  	case DRM_FORMAT_BGR565:
>  		return true;
> +	/*
> +	 * full framework (IP version 3.x) only need rb swapped for RGB888
> and
> +	 * little framework (IP version 2.x) only need rb swapped for
> BGR888,
> +	 * check for 3.x to also only rb swap BGR888 for unknown vop
> version
> +	 */
> +	case DRM_FORMAT_RGB888:
> +		return VOP_MAJOR(version) == 3;
> +	case DRM_FORMAT_BGR888:
> +		return VOP_MAJOR(version) != 3;
>  	default:
>  		return false;
>  	}
> @@ -1035,7 +1043,7 @@ static void vop_plane_atomic_update(struct drm_plane
> *plane,
>  	VOP_WIN_SET(vop, win, dsp_info, dsp_info);
>  	VOP_WIN_SET(vop, win, dsp_st, dsp_st);
>  
> -	rb_swap = has_rb_swapped(fb->format->format);
> +	rb_swap = has_rb_swapped(vop->data->version, fb->format->format);
>  	VOP_WIN_SET(vop, win, rb_swap, rb_swap);
>  
>  	/*
Jonas Karlman Oct. 26, 2023, 8:33 p.m. UTC | #2
Hi Chris,

On 2023-10-26 22:02, Christopher Obbard wrote:
> Hi Jonas,
> 
> On Thu, 2023-10-26 at 19:14 +0000, Jonas Karlman wrote:
>> Use of DRM_FORMAT_RGB888 and DRM_FORMAT_BGR888 on e.g. RK3288, RK3328
>> and RK3399 result in wrong colors being displayed.
>>
>> The issue can be observed using modetest:
>>
>>   modetest -s <connector_id>@<crtc_id>:1920x1080-60@RG24
>>   modetest -s <connector_id>@<crtc_id>:1920x1080-60@BG24
>>
>> Vendor 4.4 kernel apply an inverted rb swap for these formats on VOP
>> full framework (IP version 3.x) compared to VOP little framework (2.x).
>>
>> Fix colors by applying different rb swap for VOP full framework (3.x)
>> and VOP little framework (2.x) similar to vendor 4.4 kernel.
>>
>> Fixes: 85a359f25388 ("drm/rockchip: Add BGR formats to VOP")
>> Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
> 
> Reviewed-by: Christopher Obbard <chris.obbard@collabora.com>
> Tested-by: Christopher Obbard <chris.obbard@collabora.com>
> 
> Since you missed adding my *-by tags in v2.
> 

Thanks, and sorry about that ;-)

Regards,
Jonas
Diederik de Haas Nov. 20, 2023, 2:31 p.m. UTC | #3
On Thursday, 26 October 2023 21:14:58 CET Jonas Karlman wrote:
> Use of DRM_FORMAT_RGB888 and DRM_FORMAT_BGR888 on e.g. RK3288, RK3328
> and RK3399 result in wrong colors being displayed.
> 
> The issue can be observed using modetest:
> 
>   modetest -s <connector_id>@<crtc_id>:1920x1080-60@RG24
>   modetest -s <connector_id>@<crtc_id>:1920x1080-60@BG24

On my Rock64 (rk3328) I was able to see the problem without this patch and see 
it displaying correctly with it, so 

Tested-by: Diederik de Haas <didi.debian@cknow.org>
Heiko Stübner Nov. 20, 2023, 4:13 p.m. UTC | #4
On Thu, 26 Oct 2023 19:14:58 +0000, Jonas Karlman wrote:
> Use of DRM_FORMAT_RGB888 and DRM_FORMAT_BGR888 on e.g. RK3288, RK3328
> and RK3399 result in wrong colors being displayed.
> 
> The issue can be observed using modetest:
> 
>   modetest -s <connector_id>@<crtc_id>:1920x1080-60@RG24
>   modetest -s <connector_id>@<crtc_id>:1920x1080-60@BG24
> 
> [...]

Applied, thanks!

[1/1] drm/rockchip: vop: Fix color for RGB888/BGR888 format on VOP full
      commit: bb0a05acd6121ff0e810b44fdc24dbdfaa46b642

Best regards,
diff mbox series

Patch

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index b3d0b6ae9294..ed2ed25959a2 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -247,14 +247,22 @@  static inline void vop_cfg_done(struct vop *vop)
 	VOP_REG_SET(vop, common, cfg_done, 1);
 }
 
-static bool has_rb_swapped(uint32_t format)
+static bool has_rb_swapped(uint32_t version, uint32_t format)
 {
 	switch (format) {
 	case DRM_FORMAT_XBGR8888:
 	case DRM_FORMAT_ABGR8888:
-	case DRM_FORMAT_BGR888:
 	case DRM_FORMAT_BGR565:
 		return true;
+	/*
+	 * full framework (IP version 3.x) only need rb swapped for RGB888 and
+	 * little framework (IP version 2.x) only need rb swapped for BGR888,
+	 * check for 3.x to also only rb swap BGR888 for unknown vop version
+	 */
+	case DRM_FORMAT_RGB888:
+		return VOP_MAJOR(version) == 3;
+	case DRM_FORMAT_BGR888:
+		return VOP_MAJOR(version) != 3;
 	default:
 		return false;
 	}
@@ -1035,7 +1043,7 @@  static void vop_plane_atomic_update(struct drm_plane *plane,
 	VOP_WIN_SET(vop, win, dsp_info, dsp_info);
 	VOP_WIN_SET(vop, win, dsp_st, dsp_st);
 
-	rb_swap = has_rb_swapped(fb->format->format);
+	rb_swap = has_rb_swapped(vop->data->version, fb->format->format);
 	VOP_WIN_SET(vop, win, rb_swap, rb_swap);
 
 	/*