Skip to contentSkip to conversation

Add support for Valkyrie USB LCD displays

PATCH New ZiAo Wang 1 participant 3 messages Oct 28

Subsystems (2)
lore
Share & tools
lore

ZiAo Wang

author
#0 lore raw

v2 cover Add support for Valkyrie USB LCD displays

Hi,

This series adds a DRM/KMS driver for Valkyrie USB LCD displays.

Vendor website here:
https://www.my-valkyrie.com

This driver is devloped from scratch via black-box analysis on vendor software. Currently only supports two variants, I'm sure there are more variants, but I don't have them.

The devices use a vendor-specific USB protocol. The driver exposes them as standard DRM outputs and converts XRGB8888 framebuffer data to UYVY, the only format device accepts.

Patch 1 was authored by Ho Jie Feng and provides the XRGB8888-to-UYVY conversion helper used by the driver. It was previously posted but was not merged because it lacked an in-tree user. It is included here without changes to the original code, with my Signed-off-by added as the submitter. Ho Jie Feng is CC'd on this series.

Original posting:
https://lore.kernel.org/lkml/[email protected]/

Patch 2 adds the Valkyrie DRM driver.

I wish merging this series through the DRM tree.

I tested both supported variants on physical hardware using the Sway compositor and verified that rendering, suspend, and reset work correctly on all of them.

Thanks,
ZiAo Wang

Ho Jie Feng (1):
drm/format-helper: Add XRGB8888 to UYVY conversion

ZiAo Wang (1):
drm/tiny: Add driver for Valkyrie USB LCD displays

 MAINTAINERS                           |    7 +
 drivers/gpu/drm/drm_format_helper.c   |   73 ++
 drivers/gpu/drm/drm_format_internal.h |   21 +
 drivers/gpu/drm/tiny/Kconfig          |   15 +
 drivers/gpu/drm/tiny/Makefile         |    1 +
 drivers/gpu/drm/tiny/valkyrie-lcd.c   | 1416 +++++++++++++++++++++++++
 include/drm/drm_format_helper.h       |    4 +
 7 files changed, 1537 insertions(+)
 create mode 100644 drivers/gpu/drm/tiny/valkyrie-lcd.c

base-commit: 151a134a4e6ec66f69db8750c66006f5207f7a9d

Signature · 1 line
2.56.0
author
#1 lore raw

PATCH v2 1/2 drm/format-helper: Add XRGB8888 to UYVY conversion

From: Ho Jie Feng <[email protected]>

Add a helper for devices that use packed UYVY but accept XRGB8888 framebuffers.

---
 drivers/gpu/drm/drm_format_helper.c   | 73 +++++++++++++++++++++++++++
 drivers/gpu/drm/drm_format_internal.h | 21 ++++++++
 include/drm/drm_format_helper.h       |  4 ++
 3 files changed, 98 insertions(+)
drivers/gpu/drm/drm_format_helper.c +73 -0
index 6cddf05c49..606733ca43 100644
@@ -1379,3 +1379,76 @@ void drm_fb_xrgb8888_to_gray2(struct iosys_map *dst, const unsigned int *dst_pit
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_gray2);
 
+static void drm_fb_xrgb8888_to_uyvy_line(void *dbuf, const void *sbuf, unsigned int width)
+{
+	u8 *transfer_buffer = dbuf;
+	const __le32 *temp_buffer = sbuf;
+	unsigned int i, dst_offset = 0;
+	unsigned int pixel1, pixel2;
+	unsigned int r1, g1, b1, r2, g2, b2;
+	unsigned int r, g, b;
+	unsigned int v, y1, u, y2;
+
+	for (i = 0; i < width; i += 2) {
+		pixel1 = le32_to_cpup(&temp_buffer[i]);
+		pixel2 = le32_to_cpup(&temp_buffer[i + 1]);
+
+		r1 = (pixel1 & 0x00ff0000) >> 16;
+		g1 = (pixel1 & 0x0000ff00) >> 8;
+		b1 =  pixel1 & 0x000000ff;
+		r2 = (pixel2 & 0x00ff0000) >> 16;
+		g2 = (pixel2 & 0x0000ff00) >> 8;
+		b2 =  pixel2 & 0x000000ff;
+
+		y1 = drm_pixel_rgb_to_y_bt601(r1, g1, b1);
+		y2 = drm_pixel_rgb_to_y_bt601(r2, g2, b2);
+
+		r = r1 + r2;
+		g = g1 + g2;
+		b = b1 + b2;
+
+		v = drm_pixel_rgb2_to_v_bt601(r, g, b);
+		u = drm_pixel_rgb2_to_u_bt601(r, g, b);
+
+		transfer_buffer[dst_offset++] = u;
+		transfer_buffer[dst_offset++] = y1;
+		transfer_buffer[dst_offset++] = v;
+		transfer_buffer[dst_offset++] = y2;
+	}
+}
+
+/**
+ * drm_fb_xrgb8888_to_uyvy - Convert XRGB8888 to UYVY clip buffer
+ * @dst: Array of UYVY destination buffers
+ * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
+ *             within @dst; can be NULL if scanlines are stored next to each other.
+ * @src: Array of XRGB8888 source buffers
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy; x1 and x2 must be even
+ * @state: Transform and conversion state
+ *
+ * This function copies parts of a framebuffer to display memory and converts the
+ * color format during the process. The parameters @dst, @dst_pitch and @src refer
+ * to arrays. Each array must have at least as many entries as there are planes in
+ * @fb's format. Each entry stores the value for the format's respective color plane
+ * at the same index.
+ *
+ * This function does not apply clipping on @dst (i.e. the destination is at the
+ * top-left corner).
+ *
+ * Drivers can use this function for UYVY devices that don't support XRGB8888
+ * natively. ITU BT.601 is being used for the RGB -> YUV conversion.
+ */
+void drm_fb_xrgb8888_to_uyvy(struct iosys_map *dst, const unsigned int *dst_pitch,
+			     const struct iosys_map *src, const struct drm_framebuffer *fb,
+			     const struct drm_rect *clip, struct drm_format_conv_state *state)
+{
+	static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
+		2,
+	};
+
+	drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
+		    drm_fb_xrgb8888_to_uyvy_line);
+}
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_uyvy);
+
drivers/gpu/drm/drm_format_internal.h +21 -0
index ce29dd05bc..7a4cfb0d18 100644
@@ -159,6 +159,27 @@ static inline u32 drm_pixel_xrgb8888_to_abgr2101010(u32 pix)
 	       drm_pixel_xrgb8888_to_xbgr2101010(pix);
 }
 
+static inline u32 drm_pixel_rgb_to_y_bt601(u32 r, u32 g, u32 b)
+{
+	const u32 luma = (16U << 16) + 16829 * r + 33039 * g + 6416 * b + 32768;
+
+	return luma >> 16;
+}
+
+static inline u32 drm_pixel_rgb2_to_u_bt601(u32 r2, u32 g2, u32 b2)
+{
+	const u32 u = (128U << 17) - 9714 * r2 - 19071 * g2 + 28784 * b2 + 65536;
+
+	return u >> 17;
+}
+
+static inline u32 drm_pixel_rgb2_to_v_bt601(u32 r2, u32 g2, u32 b2)
+{
+	const u32 v = (128U << 17) + 28784 * r2 - 24103 * g2 - 4681 * b2 + 65536;
+
+	return v >> 17;
+}
+
 /*
  * Conversion from ARGB8888
  */
include/drm/drm_format_helper.h +4 -0
index 2b5c1aef80..e50f96e074 100644
@@ -136,4 +136,8 @@ void drm_fb_xrgb8888_to_gray2(struct iosys_map *dst, const unsigned int *dst_pit
 			      const struct iosys_map *src, const struct drm_framebuffer *fb,
 			      const struct drm_rect *clip, struct drm_format_conv_state *state);
 
+void drm_fb_xrgb8888_to_uyvy(struct iosys_map *dst, const unsigned int *dst_pitch,
+			     const struct iosys_map *src, const struct drm_framebuffer *fb,
+			     const struct drm_rect *clip, struct drm_format_conv_state *state);
+
 #endif /* __LINUX_DRM_FORMAT_HELPER_H */
Signature · 1 line
2.56.0
author
#2 lore raw

PATCH v2 2/2 drm/tiny: Add driver for Valkyrie USB LCD displays

In reply to ZiAo Wang

Valkyrie USB LCD displays rely on vendor-specific Windows software to display images and do not expose a standard display interface, preventing them from being used as regular displays on Linux.

Add a DRM/KMS driver developed from scratch by reverse-engineering the vendor's software and USB protocol. The driver exposes these devices as standard DRM display outputs with fixed native modes, initially supporting the 320x240 and 360x960 variants.

The driver initializes and controls the displays through USB control transfers, and converts and streams framebuffer contents as UYVY data over a USB bulk OUT endpoint in chunks of up to 65536 bytes.

Use GEM shmem buffers and atomic modesetting to integrate with the DRM subsystem, and provide fbdev emulation for compatibility with legacy framebuffer applications.

---
v2:
- Drop patch 2 which add device into HID_IGNORE list Thank for Jie Feng points out that this VID/PID is an common one.

- Switch vblank event send to using existing helper
- Adds an extra log about disconnect issue

- Fix: missing drm_atomic_helper_shutdown() in vk_disconnect()

- Fix: vk_crtc_atomic_check() skips validation when CRTC is inactive Split crtc enable and crtc active condition in two different stage, and reorder checks in vk_crtc_plane_atomic_check

- Fix: vk_device_enable_pre() leaves device_state true on failure Take device_state resetting out of device functions, make the lifetime more clear.

- Fix: valkyrie-lcd: broken resume recovery when drm suspend fails Now driver will always try to re-bootstrap device when resuming.

- Not adding drm_dev_set_dma_dev, as this driver don't use PRIME framebuffer

v1:
https://lore.kernel.org/linux-input/[email protected]

 MAINTAINERS                         |    7 +
 drivers/gpu/drm/tiny/Kconfig        |   15 +
 drivers/gpu/drm/tiny/Makefile       |    1 +
 drivers/gpu/drm/tiny/valkyrie-lcd.c | 1416 +++++++++++++++++++++++++++
 4 files changed, 1439 insertions(+)
 create mode 100644 drivers/gpu/drm/tiny/valkyrie-lcd.c
MAINTAINERS +7 -0
index 365bec8eb7..1b91f813bb 100644
@@ -8815,6 +8815,13 @@ S:	Supported
 T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
 F:	drivers/gpu/drm/udl/
 
+DRM DRIVER FOR VALKYRIE USB LCD DISPLAYS
+M:	ZiAo Wang <[email protected]>
+L:	[email protected]
+S:	Maintained
+T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F:	drivers/gpu/drm/tiny/valkyrie-lcd.c
+
 DRM DRIVER FOR VIRTUAL KERNEL MODESETTING (VKMS)
 M:	Louis Chauvet <[email protected]>
 R:	Haneen Mohammed <[email protected]>
drivers/gpu/drm/tiny/Kconfig +15 -0
index f0e72d4b6a..1e4be6d72c 100644
@@ -98,6 +98,21 @@ config DRM_PIXPAPER
 
 	  If M is selected, the module will be built as pixpaper.ko.
 
+config DRM_VALKYRIE_LCD
+	tristate "DRM support for Valkyrie USB LCDs"
+	depends on DRM && USB && MMU
+	select DRM_CLIENT_SELECTION
+	select DRM_KMS_HELPER
+	select DRM_GEM_SHMEM_HELPER
+	help
+	  Enable support for Valkyrie USB LCD displays with USB ID 345f:9132.
+	  The driver provides DRM/KMS output for the 320x240 and 360x960
+	  display variants. It supports native UYVY and software-converted
+	  XRGB8888 framebuffers.
+
+	  To compile this driver as a module, choose M here. The module
+	  will be called valkyrie-lcd.
+
 config TINYDRM_HX8357D
 	tristate "DRM support for HX8357D display panels"
 	depends on DRM && SPI
drivers/gpu/drm/tiny/Makefile +1 -0
index 48d30bf615..e768abb4dc 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_DRM_CIRRUS_QEMU)		+= cirrus-qemu.o
 obj-$(CONFIG_DRM_GM12U320)		+= gm12u320.o
 obj-$(CONFIG_DRM_PANEL_MIPI_DBI)	+= panel-mipi-dbi.o
 obj-$(CONFIG_DRM_PIXPAPER)              += pixpaper.o
+obj-$(CONFIG_DRM_VALKYRIE_LCD)		+= valkyrie-lcd.o
 obj-$(CONFIG_TINYDRM_HX8357D)		+= hx8357d.o
 obj-$(CONFIG_TINYDRM_ILI9163)		+= ili9163.o
 obj-$(CONFIG_TINYDRM_ILI9225)		+= ili9225.o
drivers/gpu/drm/tiny/valkyrie-lcd.c new file +1416 -0

1,416 lines not on this page · raw message

Signature · 1 line
2.56.0