mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression
@ 2026-09-28  0:52 Matheus Alves de Almeida
  2026-09-28  0:52 ` [PATCH 1/5] drm/vkms: make argb_u16_to_RGB565 round resulting values Matheus Alves de Almeida
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Matheus Alves de Almeida @ 2026-09-28  0:52 UTC (permalink / raw)
  To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, dri-devel, linux-kernel, Matheus Alves de Almeida

Hi,

This series adds support for RGB332, BGR233 and BGR565 writeback. This
is done with new helpers added to make conversion easier. It also fixes
a regression in the RGB565 write conversion.

The argb_u16_to_RGB565() code currently truncates the resulting
channels. This behavior was originally fixed by commit
ab87f558dcfb ("drm/vkms: Fix RGB565 pixel conversion"),
but the fix was lost during a refactor in commit
cc4fd2934d41 ("drm/vkms: Isolate writeback pixel conversion functions").
The rounding behavior has been restored using the new 
argb_u16_to_channels() helper.

Matheus Alves de Almeida (5):
  drm/vkms: make argb_u16_to_RGB565 round resulting values
  drm/vkms: support BGR565 writeback
  drm/vkms: add a helper for channel to argb_u16 conversion
  drm/vkms: add support for RGB332
  drm/vkms: add support for BGR233

 drivers/gpu/drm/vkms/vkms_formats.c   | 136 ++++++++++++++++++++------
 drivers/gpu/drm/vkms/vkms_plane.c     |   2 +
 drivers/gpu/drm/vkms/vkms_writeback.c |   5 +-
 3 files changed, 112 insertions(+), 31 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] drm/vkms: make argb_u16_to_RGB565 round resulting values
  2026-09-28  0:52 [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
@ 2026-09-28  0:52 ` Matheus Alves de Almeida
  2026-09-28  0:52 ` [PATCH 2/5] drm/vkms: support BGR565 writeback Matheus Alves de Almeida
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Matheus Alves de Almeida @ 2026-09-28  0:52 UTC (permalink / raw)
  To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, dri-devel, linux-kernel, Matheus Alves de Almeida

Currently, argb_u16_to_RGB565() truncates the resulting channel values.
Use drm_fixp2int_round() to round them to the nearest representable
RGB565 values.

Restore the rounding behavior from commit
ab87f558dcfb ("drm/vkms: Fix RGB565 pixel conversion") while adding a
separate helper for channel conversion.

Fixes: cc4fd2934d41 ("drm/vkms: Isolate writeback pixel conversion functions")
Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>
---
 drivers/gpu/drm/vkms/vkms_formats.c | 35 ++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index dfb8e13cb..6d7853e87 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -639,20 +639,35 @@ static void argb_u16_to_XRGB16161616(u8 *out_pixel, const struct pixel_argb_u16
 	pixel[0] = cpu_to_le16(in_pixel->b);
 }
 
-static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
+static u16 u16_to_channel(int size, u16 in)
 {
-	__le16 *pixel = (__le16 *)out_pixel;
+	s64 fp_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp((1 << size) - 1));
+	s64 fp_channel = drm_int2fixp(in);
 
-	s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31));
-	s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63));
+	return drm_fixp2int_round(drm_fixp_div(fp_channel, fp_ratio));
+}
+
+static void argb_u16_to_channels(u16 *out_r, u16 *out_g, u16 *out_b, u16 *out_a,
+				 unsigned int r_size, unsigned int g_size,
+				 unsigned int b_size, unsigned int a_size,
+				 const struct pixel_argb_u16 *in_pixel)
+{
+	if (r_size)
+		*out_r = u16_to_channel(r_size, in_pixel->r);
+	if (g_size)
+		*out_g = u16_to_channel(g_size, in_pixel->g);
+	if (b_size)
+		*out_b = u16_to_channel(b_size, in_pixel->b);
+	if (a_size)
+		*out_a = u16_to_channel(a_size, in_pixel->a);
+}
 
-	s64 fp_r = drm_int2fixp(in_pixel->r);
-	s64 fp_g = drm_int2fixp(in_pixel->g);
-	s64 fp_b = drm_int2fixp(in_pixel->b);
+static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
+{
+	__le16 *pixel = (__le16 *)out_pixel;
+	u16 r, g, b;
 
-	u16 r = drm_fixp2int(drm_fixp_div(fp_r, fp_rb_ratio));
-	u16 g = drm_fixp2int(drm_fixp_div(fp_g, fp_g_ratio));
-	u16 b = drm_fixp2int(drm_fixp_div(fp_b, fp_rb_ratio));
+	argb_u16_to_channels(&r, &g, &b, NULL, 5, 6, 5, 0, in_pixel);
 
 	*pixel = cpu_to_le16(r << 11 | g << 5 | b);
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/5] drm/vkms: support BGR565 writeback
  2026-09-28  0:52 [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
  2026-09-28  0:52 ` [PATCH 1/5] drm/vkms: make argb_u16_to_RGB565 round resulting values Matheus Alves de Almeida
@ 2026-09-28  0:52 ` Matheus Alves de Almeida
  2026-09-28  0:52 ` [PATCH 3/5] drm/vkms: add a helper for channel to argb_u16 conversion Matheus Alves de Almeida
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Matheus Alves de Almeida @ 2026-09-28  0:52 UTC (permalink / raw)
  To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, dri-devel, linux-kernel, Matheus Alves de Almeida

While BGR565 read is currently supported, the format code is missing
support for BGR565 write.

Implement argb_u16_to_BGR565(), add it to get_pixel_write_function()
and advertise BGR565 support in vkms_wb_formats.

Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>
---
 drivers/gpu/drm/vkms/vkms_formats.c   | 12 ++++++++++++
 drivers/gpu/drm/vkms/vkms_writeback.c |  3 ++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index 6d7853e87..b44900761 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -672,6 +672,16 @@ static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pi
 	*pixel = cpu_to_le16(r << 11 | g << 5 | b);
 }
 
+static void argb_u16_to_BGR565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
+{
+	__le16 *pixel = (__le16 *)out_pixel;
+	u16 r, g, b;
+
+	argb_u16_to_channels(&r, &g, &b, NULL, 5, 6, 5, 0, in_pixel);
+
+	*pixel = cpu_to_le16(b << 11 | g << 5 | r);
+}
+
 /**
  * vkms_writeback_row() - Generic loop for all supported writeback format. It is executed just
  * after the blending to write a line in the writeback buffer.
@@ -972,6 +982,8 @@ pixel_write_t get_pixel_write_function(u32 format)
 		return &argb_u16_to_XRGB16161616;
 	case DRM_FORMAT_RGB565:
 		return &argb_u16_to_RGB565;
+	case DRM_FORMAT_BGR565:
+		return &argb_u16_to_BGR565;
 	default:
 		/*
 		 * This is a bug in vkms_writeback_atomic_check. All the supported
diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c
index ecf29a2c0..f64b90908 100644
--- a/drivers/gpu/drm/vkms/vkms_writeback.c
+++ b/drivers/gpu/drm/vkms/vkms_writeback.c
@@ -21,7 +21,8 @@ static const u32 vkms_wb_formats[] = {
 	DRM_FORMAT_ABGR8888,
 	DRM_FORMAT_XRGB16161616,
 	DRM_FORMAT_ARGB16161616,
-	DRM_FORMAT_RGB565
+	DRM_FORMAT_RGB565,
+	DRM_FORMAT_BGR565
 };
 
 static const struct drm_connector_funcs vkms_wb_connector_funcs = {
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/5] drm/vkms: add a helper for channel to argb_u16 conversion
  2026-09-28  0:52 [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
  2026-09-28  0:52 ` [PATCH 1/5] drm/vkms: make argb_u16_to_RGB565 round resulting values Matheus Alves de Almeida
  2026-09-28  0:52 ` [PATCH 2/5] drm/vkms: support BGR565 writeback Matheus Alves de Almeida
@ 2026-09-28  0:52 ` Matheus Alves de Almeida
  2026-09-28  0:53 ` [PATCH 4/5] drm/vkms: add support for RGB332 Matheus Alves de Almeida
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Matheus Alves de Almeida @ 2026-09-28  0:52 UTC (permalink / raw)
  To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, dri-devel, linux-kernel, Matheus Alves de Almeida

Other pixel formats have similar conversions to the one implemented in
the RGB565 helper.

Add a channels_to_argb_u16() helper to convert individual channels into
the internal representation, and use it in argb_u16_from_BGR565() and
argb_u16_from_RGB565().

Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>
---
 drivers/gpu/drm/vkms/vkms_formats.c | 50 +++++++++++++++++------------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index b44900761..6e4f58207 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -229,24 +229,42 @@ static struct pixel_argb_u16 argb_u16_from_le16161616(__le16 a, __le16 r, __le16
 				       le16_to_cpu(b));
 }
 
-static struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel)
+static u16 channel_to_u16(unsigned int size, u16 in)
+{
+	s64 fp_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp((1 << size) - 1));
+	s64 fp_channel = drm_int2fixp(in);
+
+	return drm_fixp2int_round(drm_fixp_mul(fp_channel, fp_ratio));
+}
+
+static struct pixel_argb_u16 channels_to_argb_u16(u16 in_r, u16 in_g, u16 in_b, u16 in_a,
+						  unsigned int size_r, unsigned int size_g,
+						  unsigned int size_b, unsigned int size_a)
 {
 	struct pixel_argb_u16 out_pixel;
 
-	s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31));
-	s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63));
+	out_pixel.r = size_r ? channel_to_u16(size_r, in_r) : in_r;
+	out_pixel.g = size_g ? channel_to_u16(size_g, in_g) : in_g;
+	out_pixel.b = size_b ? channel_to_u16(size_b, in_b) : in_b;
+	out_pixel.a = size_a ? channel_to_u16(size_a, in_a) : in_a;
 
+	return out_pixel;
+}
+
+static struct pixel_argb_u16 argb_u16_from_RGB565(const __le16 *pixel)
+{
 	u16 rgb_565 = le16_to_cpu(*pixel);
-	s64 fp_r = drm_int2fixp((rgb_565 >> 11) & 0x1f);
-	s64 fp_g = drm_int2fixp((rgb_565 >> 5) & 0x3f);
-	s64 fp_b = drm_int2fixp(rgb_565 & 0x1f);
 
-	out_pixel.a = (u16)0xffff;
-	out_pixel.r = drm_fixp2int_round(drm_fixp_mul(fp_r, fp_rb_ratio));
-	out_pixel.g = drm_fixp2int_round(drm_fixp_mul(fp_g, fp_g_ratio));
-	out_pixel.b = drm_fixp2int_round(drm_fixp_mul(fp_b, fp_rb_ratio));
+	return channels_to_argb_u16((rgb_565 >> 11) & 0x1f, (rgb_565 >> 5) & 0x3f,
+				    rgb_565 & 0x1f, 0xffff, 5, 6, 5, 0);
+}
 
-	return out_pixel;
+static struct pixel_argb_u16 argb_u16_from_BGR565(const __le16 *pixel)
+{
+	u16 bgr_565 = le16_to_cpu(*pixel);
+
+	return channels_to_argb_u16(bgr_565 & 0x1f, (bgr_565 >> 5) & 0x3f,
+				    (bgr_565 >> 11) & 0x1f, 0xffff, 5, 6, 5, 0);
 }
 
 static struct pixel_argb_u16 argb_u16_from_gray8(u8 gray)
@@ -259,16 +277,6 @@ static struct pixel_argb_u16 argb_u16_from_grayu16(u16 gray)
 	return argb_u16_from_u16161616(0xFFFF, gray, gray, gray);
 }
 
-static struct pixel_argb_u16 argb_u16_from_BGR565(const __le16 *pixel)
-{
-	struct pixel_argb_u16 out_pixel;
-
-	out_pixel = argb_u16_from_RGB565(pixel);
-	swap(out_pixel.r, out_pixel.b);
-
-	return out_pixel;
-}
-
 VISIBLE_IF_KUNIT
 struct pixel_argb_u16 argb_u16_from_yuv161616(const struct conversion_matrix *matrix,
 					      u16 y, u16 channel_1, u16 channel_2)
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/5] drm/vkms: add support for RGB332
  2026-09-28  0:52 [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
                   ` (2 preceding siblings ...)
  2026-09-28  0:52 ` [PATCH 3/5] drm/vkms: add a helper for channel to argb_u16 conversion Matheus Alves de Almeida
@ 2026-09-28  0:53 ` Matheus Alves de Almeida
  2026-09-28  0:53 ` [PATCH 5/5] drm/vkms: add support for BGR233 Matheus Alves de Almeida
  2026-10-12 19:18 ` [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
  5 siblings, 0 replies; 7+ messages in thread
From: Matheus Alves de Almeida @ 2026-09-28  0:53 UTC (permalink / raw)
  To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, dri-devel, linux-kernel, Matheus Alves de Almeida

Add support for reading and writing the RGB332 pixel format.

Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>
---
 drivers/gpu/drm/vkms/vkms_formats.c   | 21 +++++++++++++++++++++
 drivers/gpu/drm/vkms/vkms_plane.c     |  1 +
 drivers/gpu/drm/vkms/vkms_writeback.c |  3 ++-
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index 6e4f58207..0c3bb0618 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -267,6 +267,12 @@ static struct pixel_argb_u16 argb_u16_from_BGR565(const __le16 *pixel)
 				    (bgr_565 >> 11) & 0x1f, 0xffff, 5, 6, 5, 0);
 }
 
+static struct pixel_argb_u16 argb_u16_from_RGB332(u8 pixel)
+{
+	return channels_to_argb_u16((pixel >> 5) & 0x7, (pixel >> 2) & 0x7,
+				    pixel & 0x3, 0xffff, 3, 3, 2, 0);
+}
+
 static struct pixel_argb_u16 argb_u16_from_gray8(u8 gray)
 {
 	return argb_u16_from_u8888(255, gray, gray, gray);
@@ -475,6 +481,8 @@ READ_LINE_le16161616(XBGR16161616_read_line, px, cpu_to_le16(0xFFFF), px[0], px[
 READ_LINE(RGB565_read_line, px, __le16, argb_u16_from_RGB565, px)
 READ_LINE(BGR565_read_line, px, __le16, argb_u16_from_BGR565, px)
 
+READ_LINE(RGB332_read_line, px, u8, argb_u16_from_RGB332, *px)
+
 READ_LINE(R8_read_line, px, u8, argb_u16_from_gray8, *px)
 
 /*
@@ -690,6 +698,15 @@ static void argb_u16_to_BGR565(u8 *out_pixel, const struct pixel_argb_u16 *in_pi
 	*pixel = cpu_to_le16(b << 11 | g << 5 | r);
 }
 
+static void argb_u16_to_RGB332(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
+{
+	u16 r, g, b;
+
+	argb_u16_to_channels(&r, &g, &b, NULL, 3, 3, 2, 0, in_pixel);
+
+	*out_pixel = r << 5 | g << 2 | b;
+}
+
 /**
  * vkms_writeback_row() - Generic loop for all supported writeback format. It is executed just
  * after the blending to write a line in the writeback buffer.
@@ -752,6 +769,8 @@ pixel_read_line_t get_pixel_read_line_function(u32 format)
 		return &RGB565_read_line;
 	case DRM_FORMAT_BGR565:
 		return &BGR565_read_line;
+	case DRM_FORMAT_RGB332:
+		return &RGB332_read_line;
 	case DRM_FORMAT_NV12:
 	case DRM_FORMAT_NV16:
 	case DRM_FORMAT_NV24:
@@ -992,6 +1011,8 @@ pixel_write_t get_pixel_write_function(u32 format)
 		return &argb_u16_to_RGB565;
 	case DRM_FORMAT_BGR565:
 		return &argb_u16_to_BGR565;
+	case DRM_FORMAT_RGB332:
+		return &argb_u16_to_RGB332;
 	default:
 		/*
 		 * This is a bug in vkms_writeback_atomic_check. All the supported
diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c
index 68cb2a333..fff2d4eb5 100644
--- a/drivers/gpu/drm/vkms/vkms_plane.c
+++ b/drivers/gpu/drm/vkms/vkms_plane.c
@@ -29,6 +29,7 @@ static const u32 vkms_formats[] = {
 	DRM_FORMAT_ABGR16161616,
 	DRM_FORMAT_RGB565,
 	DRM_FORMAT_BGR565,
+	DRM_FORMAT_RGB332,
 	DRM_FORMAT_NV12,
 	DRM_FORMAT_NV16,
 	DRM_FORMAT_NV24,
diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c
index f64b90908..54330803e 100644
--- a/drivers/gpu/drm/vkms/vkms_writeback.c
+++ b/drivers/gpu/drm/vkms/vkms_writeback.c
@@ -22,7 +22,8 @@ static const u32 vkms_wb_formats[] = {
 	DRM_FORMAT_XRGB16161616,
 	DRM_FORMAT_ARGB16161616,
 	DRM_FORMAT_RGB565,
-	DRM_FORMAT_BGR565
+	DRM_FORMAT_BGR565,
+	DRM_FORMAT_RGB332
 };
 
 static const struct drm_connector_funcs vkms_wb_connector_funcs = {
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/5] drm/vkms: add support for BGR233
  2026-09-28  0:52 [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
                   ` (3 preceding siblings ...)
  2026-09-28  0:53 ` [PATCH 4/5] drm/vkms: add support for RGB332 Matheus Alves de Almeida
@ 2026-09-28  0:53 ` Matheus Alves de Almeida
  2026-10-12 19:18 ` [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
  5 siblings, 0 replies; 7+ messages in thread
From: Matheus Alves de Almeida @ 2026-09-28  0:53 UTC (permalink / raw)
  To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, dri-devel, linux-kernel, Matheus Alves de Almeida

Add support for reading and writing the BGR233 pixel format.

Signed-off-by: Matheus Alves de Almeida <matheus.aalmeida@inf.ufrgs.br>
---
 drivers/gpu/drm/vkms/vkms_formats.c   | 20 ++++++++++++++++++++
 drivers/gpu/drm/vkms/vkms_plane.c     |  1 +
 drivers/gpu/drm/vkms/vkms_writeback.c |  3 ++-
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index 0c3bb0618..de25c8a19 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -273,6 +273,12 @@ static struct pixel_argb_u16 argb_u16_from_RGB332(u8 pixel)
 				    pixel & 0x3, 0xffff, 3, 3, 2, 0);
 }
 
+static struct pixel_argb_u16 argb_u16_from_BGR233(u8 pixel)
+{
+	return channels_to_argb_u16(pixel & 0x7, (pixel >> 3) & 0x7,
+				    (pixel >> 6) & 0x3, 0xffff, 3, 3, 2, 0);
+}
+
 static struct pixel_argb_u16 argb_u16_from_gray8(u8 gray)
 {
 	return argb_u16_from_u8888(255, gray, gray, gray);
@@ -482,6 +488,7 @@ READ_LINE(RGB565_read_line, px, __le16, argb_u16_from_RGB565, px)
 READ_LINE(BGR565_read_line, px, __le16, argb_u16_from_BGR565, px)
 
 READ_LINE(RGB332_read_line, px, u8, argb_u16_from_RGB332, *px)
+READ_LINE(BGR233_read_line, px, u8, argb_u16_from_BGR233, *px)
 
 READ_LINE(R8_read_line, px, u8, argb_u16_from_gray8, *px)
 
@@ -707,6 +714,15 @@ static void argb_u16_to_RGB332(u8 *out_pixel, const struct pixel_argb_u16 *in_pi
 	*out_pixel = r << 5 | g << 2 | b;
 }
 
+static void argb_u16_to_BGR233(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel)
+{
+	u16 r, g, b;
+
+	argb_u16_to_channels(&r, &g, &b, NULL, 3, 3, 2, 0, in_pixel);
+
+	*out_pixel = b << 6 | g << 3 | r;
+}
+
 /**
  * vkms_writeback_row() - Generic loop for all supported writeback format. It is executed just
  * after the blending to write a line in the writeback buffer.
@@ -771,6 +787,8 @@ pixel_read_line_t get_pixel_read_line_function(u32 format)
 		return &BGR565_read_line;
 	case DRM_FORMAT_RGB332:
 		return &RGB332_read_line;
+	case DRM_FORMAT_BGR233:
+		return &BGR233_read_line;
 	case DRM_FORMAT_NV12:
 	case DRM_FORMAT_NV16:
 	case DRM_FORMAT_NV24:
@@ -1013,6 +1031,8 @@ pixel_write_t get_pixel_write_function(u32 format)
 		return &argb_u16_to_BGR565;
 	case DRM_FORMAT_RGB332:
 		return &argb_u16_to_RGB332;
+	case DRM_FORMAT_BGR233:
+		return &argb_u16_to_BGR233;
 	default:
 		/*
 		 * This is a bug in vkms_writeback_atomic_check. All the supported
diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c
index fff2d4eb5..89beda57e 100644
--- a/drivers/gpu/drm/vkms/vkms_plane.c
+++ b/drivers/gpu/drm/vkms/vkms_plane.c
@@ -30,6 +30,7 @@ static const u32 vkms_formats[] = {
 	DRM_FORMAT_RGB565,
 	DRM_FORMAT_BGR565,
 	DRM_FORMAT_RGB332,
+	DRM_FORMAT_BGR233,
 	DRM_FORMAT_NV12,
 	DRM_FORMAT_NV16,
 	DRM_FORMAT_NV24,
diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c
index 54330803e..37042445d 100644
--- a/drivers/gpu/drm/vkms/vkms_writeback.c
+++ b/drivers/gpu/drm/vkms/vkms_writeback.c
@@ -23,7 +23,8 @@ static const u32 vkms_wb_formats[] = {
 	DRM_FORMAT_ARGB16161616,
 	DRM_FORMAT_RGB565,
 	DRM_FORMAT_BGR565,
-	DRM_FORMAT_RGB332
+	DRM_FORMAT_RGB332,
+	DRM_FORMAT_BGR233
 };
 
 static const struct drm_connector_funcs vkms_wb_connector_funcs = {
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression
  2026-09-28  0:52 [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
                   ` (4 preceding siblings ...)
  2026-09-28  0:53 ` [PATCH 5/5] drm/vkms: add support for BGR233 Matheus Alves de Almeida
@ 2026-10-12 19:18 ` Matheus Alves de Almeida
  5 siblings, 0 replies; 7+ messages in thread
From: Matheus Alves de Almeida @ 2026-10-12 19:18 UTC (permalink / raw)
  To: Louis Chauvet, Haneen Mohammed, Simona Vetter, Melissa Wen
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, dri-devel, linux-kernel

Em 2026-09-27 21:52, Matheus Alves de Almeida escreveu:
> Hi,
> 
> This series adds support for RGB332, BGR233 and BGR565 writeback. This
> is done with new helpers added to make conversion easier. It also fixes
> a regression in the RGB565 write conversion.
> 
> The argb_u16_to_RGB565() code currently truncates the resulting
> channels. This behavior was originally fixed by commit
> ab87f558dcfb ("drm/vkms: Fix RGB565 pixel conversion"),
> but the fix was lost during a refactor in commit
> cc4fd2934d41 ("drm/vkms: Isolate writeback pixel conversion functions").
> The rounding behavior has been restored using the new
> argb_u16_to_channels() helper.
> 
> Matheus Alves de Almeida (5):
>   drm/vkms: make argb_u16_to_RGB565 round resulting values
>   drm/vkms: support BGR565 writeback
>   drm/vkms: add a helper for channel to argb_u16 conversion
>   drm/vkms: add support for RGB332
>   drm/vkms: add support for BGR233
> 
>  drivers/gpu/drm/vkms/vkms_formats.c   | 136 ++++++++++++++++++++------
>  drivers/gpu/drm/vkms/vkms_plane.c     |   2 +
>  drivers/gpu/drm/vkms/vkms_writeback.c |   5 +-
>  3 files changed, 112 insertions(+), 31 deletions(-)

Hi,

Gentle ping on this. Has anyone been able to take a look at it yet?

Thanks,
Matheus

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-10-12 19:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-28  0:52 [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida
2026-09-28  0:52 ` [PATCH 1/5] drm/vkms: make argb_u16_to_RGB565 round resulting values Matheus Alves de Almeida
2026-09-28  0:52 ` [PATCH 2/5] drm/vkms: support BGR565 writeback Matheus Alves de Almeida
2026-09-28  0:52 ` [PATCH 3/5] drm/vkms: add a helper for channel to argb_u16 conversion Matheus Alves de Almeida
2026-09-28  0:53 ` [PATCH 4/5] drm/vkms: add support for RGB332 Matheus Alves de Almeida
2026-09-28  0:53 ` [PATCH 5/5] drm/vkms: add support for BGR233 Matheus Alves de Almeida
2026-10-12 19:18 ` [PATCH 0/5] drm/vkms: support more formats and fix RGB565 regression Matheus Alves de Almeida

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®