Skip to contentSkip to conversation

drm/tiny: trigger5: Add MCT Trigger 5 USB display driver

PATCH Superseded Ho Jie Feng 3 participants 7 messages Oct 26 – Nov 12

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 drm/tiny: trigger5: Add MCT Trigger 5 USB display driver

Add a DRM driver for MCT Trigger 5 USB display adapters. This supports USB 3 to HDMI/VGA displays adapters with trigger5 chipsets from j5create, StarTech and various others.

The driver implements modesetting and USB framebuffer updates, connector detection, and EDID retrieval.

The protocol is based on reverse-engineering work by Forest Crossman (cyrozap) at: https://github.com/cyrozap/mct-usb-display-adapter-re
and usb packet captures between the Windows driver and the device.

Only the HDMI path has been tested. VGA selection is inferred from the absence of USB audio interfaces.

Tested on JUA355. The list of USB device IDs are taken from the Windows driver INF.

---
Changes in v5:
- Fix warnings found by kernel test robot

Changes in v4:
- Move the driver to drm/tiny
- Remove the buffer resizing to reduce size of file

Changes in v3:
- Flush the vmalloc buffer before submitting the USB transfer.
- Support display panning by using the source offset

Changes in v2:
- Move the buffer resizing to crtc_* functions so that we can report out of memory errors to userspace
- Change the PLL search function so that it is faster and doesn't produce checkpatch warnings
- Update drm functions: crtc reset becomes create_state
- Fix warnings reported by kernel test robot

sashiko review false positives in v1-4:
- atomic in these function names mean that the changes should go through through at once or not at all, nothing to do with atomic context. Furthermore other drivers also have similar patterns
- drm_gem_fb_begin_cpu_access is also required

 MAINTAINERS                     |    7 +
 drivers/gpu/drm/tiny/Kconfig    |   14 +
 drivers/gpu/drm/tiny/Makefile   |    1 +
 drivers/gpu/drm/tiny/trigger5.c | 1115 +++++++++++++++++++++++++++++++
 4 files changed, 1137 insertions(+)
 create mode 100644 drivers/gpu/drm/tiny/trigger5.c
MAINTAINERS +7 -0
index a08087fb6e678..20d4ffab67f8a 100644
@@ -8250,6 +8250,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/display/panel/mantix,mlaf057we51-x.yaml
 F:	drivers/gpu/drm/panel/panel-mantix-mlaf057we51.c
 
+DRM DRIVER FOR MCT TRIGGER 5 USB DISPLAY ADAPTERS
+M:	Ho Jie Feng <[email protected]>
+L:	[email protected]
+S:	Maintained
+T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F:	drivers/gpu/drm/tiny/trigger5.c
+
 DRM DRIVER FOR MGA G200 GRAPHICS CHIPS
 M:	Dave Airlie <[email protected]>
 R:	Thomas Zimmermann <[email protected]>
drivers/gpu/drm/tiny/Kconfig +14 -0
index f0e72d4b6a470..65c2aa817c802 100644
@@ -98,6 +98,20 @@ config DRM_PIXPAPER
 
 	  If M is selected, the module will be built as pixpaper.ko.
 
+config DRM_TRIGGER5
+	tristate "MCT Trigger 5 USB display adapters"
+	depends on DRM && USB && MMU
+	select DRM_CLIENT_SELECTION
+	select DRM_GEM_SHMEM_HELPER
+	select DRM_KMS_HELPER
+	help
+	  DRM driver for USB display adapters based on the MCT Trigger 5
+	  chipset, including the StarTech USB32VGAES and USB32HDES and the
+	  j5create JUA310 and JUA350.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called trigger5.
+
 config TINYDRM_HX8357D
 	tristate "DRM support for HX8357D display panels"
 	depends on DRM && SPI
drivers/gpu/drm/tiny/Makefile +1 -0
index 48d30bf6152f9..675d51b9ec447 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_TRIGGER5)		+= trigger5.o
 obj-$(CONFIG_TINYDRM_HX8357D)		+= hx8357d.o
 obj-$(CONFIG_TINYDRM_ILI9163)		+= ili9163.o
 obj-$(CONFIG_TINYDRM_ILI9225)		+= ili9225.o
drivers/gpu/drm/tiny/trigger5.c new file +1115 -0

1,115 lines not on this page · raw message

base-commit: cf61bef3801c3c9d0d8c39026b7b2fb242898a3a

Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] drm/tiny: trigger5: unclipped src rect in trigger5_plane_atomic_update() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] drm/tiny: trigger5: unclipped src rect in trigger5_plane_atomic_update() --

commit 56412e719e880a97ad42bea1ca53d34f2a12fdb6
Author: Ho Jie Feng <[email protected]>

drm/tiny: trigger5: Add MCT Trigger 5 USB display driver

This commit adds a DRM driver for USB 3 to HDMI and VGA display adapters based on the MCT Trigger 5 chipset, implementing modesetting, USB framebuffer updates, connector detection, and EDID retrieval.

Quoted 5 lines
drivers/gpu/drm/tiny/trigger5.c new file +0 -0
new file mode 100644
index 0000000000000..d0ab06bab8d73

[ ... ]

Quoted 19 lines
drivers/gpu/drm/tiny/trigger5.c new file +19 -0
+static enum drm_mode_status
+trigger5_crtc_mode_valid(struct drm_crtc *crtc,
+			 const struct drm_display_mode *mode)
+{
+	struct trigger5_pll pll;
+	u64 err, ppm;
+
+	if (mode->hsync_end <= mode->hsync_start ||
+	    mode->htotal <= mode->hsync_end ||
+	    mode->htotal > U16_MAX + 1)
+		return MODE_H_ILLEGAL;
+
+	if (mode->vsync_end <= mode->vsync_start ||
+	    mode->vtotal <= mode->vsync_end ||
+	    mode->vtotal > U16_MAX + 1)
+		return MODE_V_ILLEGAL;
+
+	if (trigger5_mode_buf_len(mode) > TRIGGER5_TRANSFER_BUF_SIZE)
+		return MODE_MEM;

[ ... ]

Quoted 3 lines
drivers/gpu/drm/tiny/trigger5.c new file +3 -0
+static int trigger5_plane_atomic_check(struct drm_plane *plane,
+				       struct drm_atomic_commit *state)
+{

[ ... ]

Quoted 7 lines
drivers/gpu/drm/tiny/trigger5.c new file +7 -0
+	ret = drm_atomic_helper_check_plane_state(new_plane_state,
+						  new_crtc_state,
+						  DRM_PLANE_NO_SCALING,
+						  DRM_PLANE_NO_SCALING,
+						  false, false);
+	if (ret || !new_plane_state->visible)
+		return ret;

[ ... ]

Quoted 3 lines
drivers/gpu/drm/tiny/trigger5.c new file +3 -0
+static void trigger5_plane_atomic_update(struct drm_plane *plane,
+					 struct drm_atomic_commit *atomic_state)
+{

[ ... ]

Quoted 27 lines
drivers/gpu/drm/tiny/trigger5.c new file +27 -0
+	current_transfer =
+		&trigger5->transfers[trigger5->current_transfer];
+	previous_transfer = &trigger5->transfers[1 - trigger5->current_transfer];
+
+	src_rect = drm_plane_state_src(state);
+
+	/* Match drm_atomic_helper_damage_iter_init() rounding. */
+	src_rect.x1 >>= 16;
+	src_rect.y1 >>= 16;
+	src_rect.x2 = (src_rect.x2 >> 16) + !!(src_rect.x2 & 0xffff);
+	src_rect.y2 = (src_rect.y2 >> 16) + !!(src_rect.y2 & 0xffff);
+
+	/* Latency reduction: requeue with the latest frame data. */
+	if (cancel_work(&previous_transfer->transfer_work)) {
+		complete(&previous_transfer->frame_complete);
+
+		trigger5_merge_rect(&current_rect, &previous_transfer->transfer_rect);
+
+		current_transfer = previous_transfer;
+		trigger5->current_transfer = !trigger5->current_transfer;
+	}
+
+	/* Damage deferred by an earlier failed update. */
+	trigger5_merge_rect(&current_rect, &trigger5->pending_rect);
+	trigger5_clear_rect(&trigger5->pending_rect);
+
+	/* Clip merged damage to the new resolution. */

drivers/gpu/drm/tiny/trigger5.c line 692

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+	if (!drm_rect_intersect(&current_rect, &src_rect))
+		goto exit;
+
+	width = drm_rect_width(&current_rect);
+	height = drm_rect_height(&current_rect);
+	payload_len = array3_size(width, height, 3);
+	frame_len = size_add(payload_len, sizeof(*header));
+
+	if (drm_WARN_ON_ONCE(plane->dev, frame_len > current_transfer->buf.len))
+		goto exit;

[Severity: Medium]
Can src_rect in trigger5_plane_atomic_update() exceed the active CRTC mode dimensions and overflow the 8 MiB limit checked in trigger5_crtc_mode_valid()?

In trigger5_plane_atomic_check(), drm_atomic_helper_check_plane_state() clips new_plane_state->dst to (0, 0)-(mode->hdisplay, mode->vdisplay) and stores the clipped source coordinates in new_plane_state->src, while leaving the unclipped new_plane_state->src_x, src_y, src_w, and src_h unchanged. Because drm_atomic_helper_check_plane_state() checks drm_rect_equals(dst, &clip) after clipping dst, a plane update on a larger framebuffer with crtc_x <= 0, crtc_y <= 0, and unclipped src_w/src_h larger than mode->hdisplay and mode->vdisplay passes validation.

In addition, drm_atomic_helper_check_plane_state() does not reject non-zero 16.16 fixed-point fractional bits in src_x or src_y when panning within a larger framebuffer. Rounding src_rect.x1/y1 down and src_rect.x2/y2 up expands the dimensions of src_rect by an extra pixel to mode->hdisplay + 1 and mode->vdisplay + 1.

Because trigger5_plane_atomic_update() builds src_rect from the unclipped drm_plane_state_src(state) rather than the clipped state->src, current_rect after drm_rect_intersect(&current_rect, &src_rect) can exceed mode->hdisplay x mode->vdisplay. When frame_len exceeds current_transfer->buf.len, this triggers drm_WARN_ON_ONCE() and jumps to exit after trigger5->pending_rect was already cleared and previous_transfer->transfer_work was potentially cancelled, dropping that damage. When frame_len still fits within current_transfer->buf.len, the bulk header is sent with width and height larger than the configured mode and offsets computed relative to the unclipped off-screen src_rect.x1/y1.

Should trigger5_plane_atomic_update() use state->src instead of drm_plane_state_src(state), and should trigger5_plane_atomic_check() reject fractional source coordinates or unclipped planes?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Ho Jie Feng

Hi,

sorry for letting you wait for so long. You'll find a review below.

The driver looks quite good already. Details below.  To give one advice, I'd recommend to do away with the complicated transfer-worker logic and simply send everything as part of the plane update, if possible.

Am 26.10.26 um 12:28 schrieb Ho Jie Feng:

Quoted 38 lines

Add a DRM driver for MCT Trigger 5 USB display adapters. This supports USB 3 to HDMI/VGA displays adapters with trigger5 chipsets from j5create, StarTech and various others.

The driver implements modesetting and USB framebuffer updates, connector detection, and EDID retrieval.

The protocol is based on reverse-engineering work by Forest Crossman (cyrozap) at: https://github.com/cyrozap/mct-usb-display-adapter-re
and usb packet captures between the Windows driver and the device.

Only the HDMI path has been tested. VGA selection is inferred from the absence of USB audio interfaces.

Tested on JUA355. The list of USB device IDs are taken from the Windows driver INF.

---
Changes in v5:
- Fix warnings found by kernel test robot

Changes in v4:
- Move the driver to drm/tiny
- Remove the buffer resizing to reduce size of file

Changes in v3:
- Flush the vmalloc buffer before submitting the USB transfer.
- Support display panning by using the source offset

Changes in v2:
- Move the buffer resizing to crtc_* functions so that we can report out of memory errors to userspace
- Change the PLL search function so that it is faster and doesn't produce checkpatch warnings
- Update drm functions: crtc reset becomes create_state
- Fix warnings reported by kernel test robot

Quoted 4 lines

sashiko review false positives in v1-4:
- atomic in these function names mean that the changes should go through through at once or not at all, nothing to do with atomic context. Furthermore other drivers also have similar patterns

Exactly. Somehow Sashiko doesn't get this. It thinks atomic means "atomic context".

Quoted 154 lines

- drm_gem_fb_begin_cpu_access is also required

  MAINTAINERS                     |    7 +
  drivers/gpu/drm/tiny/Kconfig    |   14 +
  drivers/gpu/drm/tiny/Makefile   |    1 +
  drivers/gpu/drm/tiny/trigger5.c | 1115 +++++++++++++++++++++++++++++++
  4 files changed, 1137 insertions(+)

create mode 100644 drivers/gpu/drm/tiny/trigger5.c

MAINTAINERS +7 -0
index a08087fb6e678..20d4ffab67f8a 100644
@@ -8250,6 +8250,13 @@ S:	Maintained
  F:	Documentation/devicetree/bindings/display/panel/mantix,mlaf057we51-x.yaml
  F:	drivers/gpu/drm/panel/panel-mantix-mlaf057we51.c
 
+DRM DRIVER FOR MCT TRIGGER 5 USB DISPLAY ADAPTERS
+M:	Ho Jie Feng <[email protected]>
+L:	[email protected]
+S:	Maintained
+T:	git https://gitlab.freedesktop.org/drm/misc/kernel.git
+F:	drivers/gpu/drm/tiny/trigger5.c
+
  DRM DRIVER FOR MGA G200 GRAPHICS CHIPS
  M:	Dave Airlie <[email protected]>
  R:	Thomas Zimmermann <[email protected]>
drivers/gpu/drm/tiny/Kconfig +14 -0
index f0e72d4b6a470..65c2aa817c802 100644
@@ -98,6 +98,20 @@ config DRM_PIXPAPER
 
  	  If M is selected, the module will be built as pixpaper.ko.
 
+config DRM_TRIGGER5
+	tristate "MCT Trigger 5 USB display adapters"
+	depends on DRM && USB && MMU
+	select DRM_CLIENT_SELECTION
+	select DRM_GEM_SHMEM_HELPER
+	select DRM_KMS_HELPER
+	help
+	  DRM driver for USB display adapters based on the MCT Trigger 5
+	  chipset, including the StarTech USB32VGAES and USB32HDES and the
+	  j5create JUA310 and JUA350.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called trigger5.
+
  config TINYDRM_HX8357D
  	tristate "DRM support for HX8357D display panels"
  	depends on DRM && SPI
drivers/gpu/drm/tiny/Makefile +1 -0
index 48d30bf6152f9..675d51b9ec447 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_TRIGGER5)		+= trigger5.o
  obj-$(CONFIG_TINYDRM_HX8357D)		+= hx8357d.o
  obj-$(CONFIG_TINYDRM_ILI9163)		+= ili9163.o
  obj-$(CONFIG_TINYDRM_ILI9225)		+= ili9225.o
drivers/gpu/drm/tiny/trigger5.c new file +84 -0
new file mode 100644
index 0000000000000..d0ab06bab8d73
@@ -0,0 +1,1115 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <linux/array_size.h>
+#include <linux/completion.h>
+#include <linux/err.h>
+#include <linux/highmem.h>
+#include <linux/iosys-map.h>
+#include <linux/jiffies.h>
+#include <linux/limits.h>
+#include <linux/math.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/overflow.h>
+#include <linux/scatterlist.h>
+#include <linux/sizes.h>
+#include <linux/slab.h>
+#include <linux/timer.h>
+#include <linux/types.h>
+#include <linux/usb.h>
+#include <linux/vmalloc.h>
+#include <linux/workqueue.h>
+
+#include <drm/clients/drm_client_setup.h>
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_atomic_state_helper.h>
+#include <drm/drm_connector.h>
+#include <drm/drm_crtc.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_damage_helper.h>
+#include <drm/drm_device.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_edid.h>
+#include <drm/drm_encoder.h>
+#include <drm/drm_fbdev_shmem.h>
+#include <drm/drm_format_helper.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_framebuffer.h>
+#include <drm/drm_gem.h>
+#include <drm/drm_gem_atomic_helper.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_gem_shmem_helper.h>
+#include <drm/drm_managed.h>
+#include <drm/drm_modeset_helper.h>
+#include <drm/drm_modeset_helper_vtables.h>
+#include <drm/drm_plane.h>
+#include <drm/drm_print.h>
+#include <drm/drm_probe_helper.h>
+#include <drm/drm_rect.h>
+
+#define DRIVER_NAME		"trigger5"
+#define DRIVER_DESC		"MCT Trigger 5 USB display adapter"
+
+#define DRIVER_MAJOR		1
+#define DRIVER_MINOR		0
+
+#define TRIGGER5_NUM_TRANSFERS	2
+#define TRIGGER5_TRANSFER_BUF_SIZE SZ_8M
+
+struct trigger5_transfer_buf {
+	void *data;
+	struct sg_table sgt;
+	size_t len;
+};
+
+struct trigger5_transfer {
+	struct trigger5_device *trigger5;
+
+	struct trigger5_transfer_buf buf;
+	size_t frame_len;
+	struct drm_rect transfer_rect;
+
+	struct timer_list timer;
+	struct usb_sg_request sgr;
+
+	struct work_struct transfer_work;
+	struct completion frame_complete;
+};
+
+struct trigger5_device {
+	struct drm_device drm;
+	struct usb_interface *intf;
+	unsigned int bulk_pipe;
+

drivers/gpu/drm/tiny/trigger5.c line 94

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+	struct drm_connector connector;
+	struct drm_plane plane;
+	struct drm_crtc crtc;
+	struct drm_encoder encoder;
+
+	u16 frame_counter;
+
+	int current_transfer;
+	struct drm_rect pending_rect;
+	struct workqueue_struct *transfer_wq;

Do you really need your own queue?

I'd recommend to push work on one of the system work queues.

drivers/gpu/drm/tiny/trigger5.c line 95

Quoted 1 line
drivers/gpu/drm/tiny/trigger5.c new file +1 -0
+	bool display_enabled;

This field only seems to control the dependency between transfer and keepalive.

Quoted 52 lines
drivers/gpu/drm/tiny/trigger5.c new file +52 -0
+	struct delayed_work keepalive_work;
+
+	struct trigger5_transfer transfers[TRIGGER5_NUM_TRANSFERS];
+};
+
+struct trigger5_pll {
+	u8 prediv;
+	u8 mul1;
+	u8 mul2;
+	u8 div1;
+	u8 div2;
+} __packed;
+
+struct trigger5_mode_request {
+	__be16 height;
+	__be16 width;
+	__be16 line_total_pixels; /* minus one */
+	__be16 line_sync_pulse; /* minus one */
+	__be16 line_back_porch; /* minus one */
+	__be16 unknown1;
+	__be16 unknown2;
+	__be16 width_minus_one;
+	__be16 frame_total_lines; /* minus one */
+	__be16 frame_sync_pulse; /* minus one */
+	__be16 frame_back_porch; /* minus one */
+	__be16 unknown3;
+	__be16 unknown4;
+	__be16 height_minus_one;
+	struct trigger5_pll pll;
+	u8 hsync_polarity;
+	u8 vsync_polarity;
+} __packed;
+
+/* gm12u320.c uses the same header format */
+struct trigger5_bulk_header {
+	u8 magic; /* 0xfb */
+	u8 length; /* 0x14 */
+	__le16 counter; /* lower 12-bit counter, upper 4-bit packet flags */
+	__le16 horizontal_offset; /* lower 13-bit offset, upper 3-bit unknown */
+	__le16 vertical_offset; /* lower 13-bit offset, upper 3-bit unknown */
+	__le16 width; /* lower 13-bit width, upper 3-bit unknown */
+	__le16 height; /* lower 13-bit height, upper 3-bit unknown */
+	__le32 payload_length; /* lower 28-bit length, upper 4-bit flags */
+	u8 flags; /* bit 0 must be set */
+	u8 unknown1;
+	u8 unknown2;
+	u8 checksum;
+} __packed;
+
+#define TRIGGER5_REQUEST_KEEPALIVE		0x91
+#define TRIGGER5_REQUEST_GET_REGISTER		0xA5
+#define TRIGGER5_REQUEST_GET_STATUS		0xA6

drivers/gpu/drm/tiny/trigger5.c line 157

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+#define TRIGGER5_REQUEST_GET_EDID		0xA8
+#define TRIGGER5_REQUEST_SET_MODE		0xC3
+#define TRIGGER5_REQUEST_SET_REGISTER		0xC4
+#define TRIGGER5_REQUEST_SET_CURSOR_POSITION	0xC8
+#define TRIGGER5_REQUEST_FIRMWARE_RESET		0xD1
+
+#define TRIGGER5_KEEPALIVE_INTERVAL_MS	2000
+#define TRIGGER5_BULK_TIMEOUT_MS		5000
+
+#define to_trigger5(x) container_of(x, struct trigger5_device, drm)

container_of_const() is nowadays the preferred macro.

Quoted 294 lines
drivers/gpu/drm/tiny/trigger5.c new file +294 -0
+
+static void trigger5_stop_io(struct trigger5_device *trigger5)
+{
+	WRITE_ONCE(trigger5->display_enabled, false);
+	flush_workqueue(trigger5->transfer_wq);
+	cancel_delayed_work_sync(&trigger5->keepalive_work);
+}
+
+static int trigger5_usb_suspend(struct usb_interface *interface,
+				pm_message_t message)
+{
+	struct trigger5_device *trigger5 = usb_get_intfdata(interface);
+	int ret;
+
+	ret = drm_mode_config_helper_suspend(&trigger5->drm);
+	if (ret)
+		return ret;
+
+	trigger5_stop_io(trigger5);
+
+	return 0;
+}
+
+static int trigger5_usb_resume(struct usb_interface *interface)
+{
+	struct trigger5_device *trigger5 = usb_get_intfdata(interface);
+
+	return drm_mode_config_helper_resume(&trigger5->drm);
+}
+
+DEFINE_DRM_GEM_FOPS(trigger5_driver_fops);
+
+static const struct drm_driver trigger5_drm_driver = {
+	.driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
+
+	/* GEM hooks */
+	.fops = &trigger5_driver_fops,
+	DRM_GEM_SHMEM_DRIVER_OPS,
+	DRM_FBDEV_SHMEM_DRIVER_OPS,
+
+	.name = DRIVER_NAME,
+	.desc = DRIVER_DESC,
+	.major = DRIVER_MAJOR,
+	.minor = DRIVER_MINOR,
+};
+
+static const struct drm_mode_config_funcs trigger5_mode_config_funcs = {
+	.fb_create = drm_gem_fb_create_with_dirty,
+	.atomic_check = drm_atomic_helper_check,
+	.atomic_commit = drm_atomic_helper_commit,
+};
+
+static u64 trigger5_calculate_pll(struct trigger5_pll *pll, int clock)
+{
+	u64 ref_clock = 10000000;
+	u64 target_clock = (u64)clock * 1000;
+	u64 calculated_clock, calculated_err, best_err = U64_MAX;
+	int prediv_div2, prediv, mul1, mul2, div1, div2;
+
+	/* Use values found in the capture */
+	for (prediv_div2 = 0x02; prediv_div2 <= 0x100; prediv_div2 <<= 1) {
+		for (mul1 = 1; mul1 <= 0x32; mul1++) {
+			for (mul2 = mul1; mul2 <= 0x32; mul2++) {
+				for (div1 = 1; div1 <= 0x32; div1++) {
+					if (!best_err)
+						break;
+					calculated_clock =
+						div_u64(ref_clock * mul1 * mul2,
+							prediv_div2 * div1);
+					calculated_err =
+						abs_diff(calculated_clock,
+							 target_clock);
+					if (prediv_div2 <= 0x10) {
+						div2 = prediv_div2;
+						prediv = 1;
+					} else {
+						div2 = 0x10;
+						prediv = prediv_div2 >> 4;
+					}
+					if (calculated_err < best_err) {
+						best_err =
+							calculated_err;
+						pll->mul1 = mul1;
+						pll->mul2 = mul2;
+						pll->div1 = div1;
+						pll->div2 = div2;
+						pll->prediv = prediv;
+					}
+				}
+			}
+		}
+	}
+	return best_err;
+}
+
+static void trigger5_bulk_timeout(struct timer_list *t)
+{
+	struct trigger5_transfer *transfer =
+		timer_container_of(transfer, t, timer);
+
+	usb_sg_cancel(&transfer->sgr);
+}
+
+static void trigger5_transfer_work(struct work_struct *work)
+{
+	struct trigger5_transfer *transfer =
+		container_of(work, struct trigger5_transfer, transfer_work);
+	struct trigger5_device *trigger5 = transfer->trigger5;
+	struct usb_device *udev = interface_to_usbdev(trigger5->intf);
+	int idx, ret;
+
+	if (!drm_dev_enter(&trigger5->drm, &idx))
+		goto complete;
+
+	/* Submit bulk transfer with a five-second timeout. */
+	ret = usb_sg_init(&transfer->sgr, udev, trigger5->bulk_pipe, 0,
+			  transfer->buf.sgt.sgl,
+			  transfer->buf.sgt.nents, transfer->frame_len,
+			  GFP_KERNEL);
+	if (ret) {
+		drm_err_ratelimited(&trigger5->drm,
+				    "failed to initialize USB transfer: %d\n",
+				    ret);
+		goto exit;
+	}
+
+	mod_timer(&transfer->timer,
+		  jiffies + msecs_to_jiffies(TRIGGER5_BULK_TIMEOUT_MS));
+	usb_sg_wait(&transfer->sgr);
+	timer_delete_sync(&transfer->timer);
+
+	if (transfer->sgr.status)
+		drm_err_ratelimited(&trigger5->drm,
+				    "USB transfer failed: %d\n",
+				    transfer->sgr.status);
+	else if (transfer->sgr.bytes != transfer->frame_len)
+		drm_err_ratelimited(&trigger5->drm,
+				    "short USB transfer: %zu/%zu bytes\n",
+				    transfer->sgr.bytes, transfer->frame_len);
+	else if (READ_ONCE(trigger5->display_enabled))
+		/* Keepalive must only be sent after a frame has been sent */
+		queue_delayed_work(trigger5->transfer_wq,
+				   &trigger5->keepalive_work,
+				   msecs_to_jiffies(TRIGGER5_KEEPALIVE_INTERVAL_MS));
+
+exit:
+	drm_dev_exit(idx);
+complete:
+	complete(&transfer->frame_complete);
+}
+
+static void trigger5_keepalive_work(struct work_struct *work)
+{
+	struct trigger5_device *trigger5 =
+		container_of(to_delayed_work(work), struct trigger5_device,
+			     keepalive_work);
+	struct usb_device *udev = interface_to_usbdev(trigger5->intf);
+	u8 response;
+	int idx, ret;
+
+	if (!READ_ONCE(trigger5->display_enabled))
+		return;
+
+	if (!drm_dev_enter(&trigger5->drm, &idx))
+		return;
+
+	ret = usb_control_msg_recv(udev, 0, TRIGGER5_REQUEST_KEEPALIVE,
+				   USB_DIR_IN | USB_TYPE_VENDOR |
+					   USB_RECIP_DEVICE,
+				   0x0002, 0x0000, &response,
+				   sizeof(response), USB_CTRL_GET_TIMEOUT,
+				   GFP_KERNEL);
+	if (ret)
+		drm_err_ratelimited(&trigger5->drm,
+				    "keepalive request failed: %d\n", ret);
+
+	if (READ_ONCE(trigger5->display_enabled))
+		mod_delayed_work(trigger5->transfer_wq,
+				 &trigger5->keepalive_work,
+				 msecs_to_jiffies(TRIGGER5_KEEPALIVE_INTERVAL_MS));
+
+	drm_dev_exit(idx);
+}
+
+static void trigger5_free_bulk_buffer(struct trigger5_transfer_buf *buf)
+{
+	if (!buf->data)
+		return;
+	sg_free_table(&buf->sgt);
+	vfree(buf->data);
+	buf->data = NULL;
+	buf->len = 0;
+}
+
+static int trigger5_alloc_bulk_buffer(struct trigger5_transfer_buf *buf,
+				      size_t len)
+{
+	unsigned int num_pages;
+	int ret, i;
+	struct page **pages;
+	u8 *data;
+	void *ptr;
+
+	/* Large transfer buffer requires vmalloc and a scatterlist. */
+	data = vmalloc_32(len);
+	if (!data)
+		return -ENOMEM;
+
+	num_pages = DIV_ROUND_UP(len, PAGE_SIZE);
+	pages = kmalloc_array(num_pages, sizeof(struct page *), GFP_KERNEL);
+	if (!pages) {
+		ret = -ENOMEM;
+		goto err_vfree;
+	}
+	for (i = 0, ptr = data; i < num_pages; i++, ptr += PAGE_SIZE)
+		pages[i] = vmalloc_to_page(ptr);
+	ret = sg_alloc_table_from_pages(&buf->sgt, pages,
+					num_pages, 0, len, GFP_KERNEL);
+	kfree(pages);
+	if (ret)
+		goto err_vfree;
+
+	buf->data = data;
+	buf->len = len;
+
+	return 0;
+err_vfree:
+	vfree(data);
+	return ret;
+}
+
+static void trigger5_init_transfer(struct trigger5_device *trigger5,
+				   struct trigger5_transfer *transfer)
+{
+	init_completion(&transfer->frame_complete);
+	complete(&transfer->frame_complete);
+	timer_setup(&transfer->timer, trigger5_bulk_timeout, 0);
+	INIT_WORK(&transfer->transfer_work, trigger5_transfer_work);
+	transfer->trigger5 = trigger5;
+}
+
+static size_t trigger5_mode_buf_len(const struct drm_display_mode *mode)
+{
+	return size_add(array3_size(mode->hdisplay, mode->vdisplay, 3),
+			sizeof(struct trigger5_bulk_header));
+}
+
+static void trigger5_crtc_atomic_enable(struct drm_crtc *crtc,
+					struct drm_atomic_commit *state)
+{
+	struct trigger5_device *trigger5 = to_trigger5(crtc->dev);
+	struct usb_device *udev = interface_to_usbdev(trigger5->intf);
+	struct drm_crtc_state *crtc_state =
+		drm_atomic_get_new_crtc_state(state, crtc);
+	struct drm_display_mode *mode = &crtc_state->mode;
+	struct trigger5_mode_request request = {};
+	u8 data[4];
+	u64 clk;
+	int idx, ret;
+
+	if (!drm_dev_enter(crtc->dev, &idx))
+		return;
+
+	trigger5_stop_io(trigger5);
+
+	/* Sequence recovered from USB captures. */
+	ret = usb_control_msg_recv(udev, 0,
+				   TRIGGER5_REQUEST_FIRMWARE_RESET,
+				   USB_DIR_IN | USB_TYPE_VENDOR |
+					   USB_RECIP_DEVICE,
+				   0x0000, 0x0000, data, 1,
+				   USB_CTRL_GET_TIMEOUT, GFP_KERNEL);
+	if (ret)
+		goto err;
+
+	request.height = cpu_to_be16(mode->vdisplay);
+	request.height_minus_one = cpu_to_be16(mode->vdisplay - 1);
+	request.width = cpu_to_be16(mode->hdisplay);
+	request.width_minus_one = cpu_to_be16(mode->hdisplay - 1);
+
+	request.line_total_pixels = cpu_to_be16(mode->htotal - 1);
+	request.line_sync_pulse =
+		cpu_to_be16(mode->hsync_end - mode->hsync_start - 1);
+	request.line_back_porch =
+		cpu_to_be16(mode->htotal - mode->hsync_end - 1);
+
+	request.frame_total_lines = cpu_to_be16(mode->vtotal - 1);
+	request.frame_sync_pulse =
+		cpu_to_be16(mode->vsync_end - mode->vsync_start - 1);
+	request.frame_back_porch =
+		cpu_to_be16(mode->vtotal - mode->vsync_end - 1);
+	request.unknown1 = cpu_to_be16(0xff);
+	request.unknown2 = cpu_to_be16(0xff);
+	request.unknown3 = cpu_to_be16(0xff);

drivers/gpu/drm/tiny/trigger5.c line 461

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+	request.unknown4 = cpu_to_be16(0xff);
+
+	request.hsync_polarity = (mode->flags & DRM_MODE_FLAG_PHSYNC) ? 0 : 1;
+	request.vsync_polarity = (mode->flags & DRM_MODE_FLAG_PVSYNC) ? 0 : 1;
+
+	trigger5_calculate_pll(&request.pll, mode->clock);
+	clk = div_u64(10000000ULL * request.pll.mul1 * request.pll.mul2,
+		      (u32)request.pll.prediv * request.pll.div1 *
+			      request.pll.div2 * 1000);
+	drm_dbg_kms(&trigger5->drm,

Drivers should use drm_dbg()

Quoted 40 lines
drivers/gpu/drm/tiny/trigger5.c new file +40 -0
+		    "pll: %02x %02x %02x %02x %02x -> %llu kHz (want %d kHz)\n",
+		    request.pll.prediv, request.pll.mul1, request.pll.mul2,
+		    request.pll.div1, request.pll.div2, clk, mode->clock);
+
+	/* wValue can be any value since we are sending a custom mode */
+	ret = usb_control_msg_send(udev, 0, TRIGGER5_REQUEST_SET_MODE,
+				   USB_DIR_OUT | USB_TYPE_VENDOR |
+					   USB_RECIP_DEVICE,
+				   0, 0, &request, sizeof(request),
+				   USB_CTRL_SET_TIMEOUT, GFP_KERNEL);
+	if (ret)
+		goto err;
+
+	ret = usb_control_msg_recv(udev, 0,
+				   TRIGGER5_REQUEST_FIRMWARE_RESET,
+				   USB_DIR_IN | USB_TYPE_VENDOR |
+					   USB_RECIP_DEVICE,
+				   0x0201, 0x0000, data, 1,
+				   USB_CTRL_GET_TIMEOUT, GFP_KERNEL);
+	if (ret)
+		goto err;
+
+	ret = usb_control_msg_recv(udev, 0,
+				   TRIGGER5_REQUEST_GET_REGISTER,
+				   USB_DIR_IN | USB_TYPE_VENDOR |
+					   USB_RECIP_DEVICE,
+				   0x0000, 0xec34, data, sizeof(data),
+				   USB_CTRL_GET_TIMEOUT, GFP_KERNEL);
+	if (ret)
+		goto err;
+
+	data[0] = 0x60;
+	data[1] = 0x00;
+	data[2] = 0x00;
+	data[3] = 0x10;
+	ret = usb_control_msg_send(udev, 0,
+				   TRIGGER5_REQUEST_SET_REGISTER,
+				   USB_DIR_OUT | USB_TYPE_VENDOR |
+					   USB_RECIP_DEVICE,
+				   0x0000, 0xec34, data, sizeof(data),

drivers/gpu/drm/tiny/trigger5.c line 511

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+				   USB_CTRL_SET_TIMEOUT, GFP_KERNEL);
+	if (ret)
+		goto err;
+
+	WRITE_ONCE(trigger5->display_enabled, true);
+
+	goto exit;
+
+err:
+	drm_err(&trigger5->drm, "failed to configure display mode: %d\n", ret);

No error messages in the display-update code paths please.  Maybe use drm_err_once().  Otherwise you might spam the kernel logs with endless error messages or give malicious user space a way to do that. Here and in other functions.

Quoted 63 lines
drivers/gpu/drm/tiny/trigger5.c new file +63 -0
+exit:
+	drm_dev_exit(idx);
+}
+
+static void trigger5_crtc_atomic_disable(struct drm_crtc *crtc,
+					 struct drm_atomic_commit *state)
+{
+	struct trigger5_device *trigger5 = to_trigger5(crtc->dev);
+	struct usb_device *udev = interface_to_usbdev(trigger5->intf);
+	u8 data;
+	int idx, ret;
+
+	if (!drm_dev_enter(crtc->dev, &idx))
+		return;
+
+	trigger5_stop_io(trigger5);
+
+	ret = usb_control_msg_recv(udev, 0,
+				   TRIGGER5_REQUEST_FIRMWARE_RESET,
+				   USB_DIR_IN | USB_TYPE_VENDOR |
+					   USB_RECIP_DEVICE,
+				   0x0001, 0x0000, &data, 1,
+				   USB_CTRL_GET_TIMEOUT, GFP_KERNEL);
+	if (ret)
+		drm_err(&trigger5->drm, "failed to disable display: %d\n", ret);
+
+	drm_dev_exit(idx);
+}
+
+static enum drm_mode_status
+trigger5_crtc_mode_valid(struct drm_crtc *crtc,
+			 const struct drm_display_mode *mode)
+{
+	struct trigger5_pll pll;
+	u64 err, ppm;
+
+	if (mode->hsync_end <= mode->hsync_start ||
+	    mode->htotal <= mode->hsync_end ||
+	    mode->htotal > U16_MAX + 1)
+		return MODE_H_ILLEGAL;
+
+	if (mode->vsync_end <= mode->vsync_start ||
+	    mode->vtotal <= mode->vsync_end ||
+	    mode->vtotal > U16_MAX + 1)
+		return MODE_V_ILLEGAL;
+
+	if (trigger5_mode_buf_len(mode) > TRIGGER5_TRANSFER_BUF_SIZE)
+		return MODE_MEM;
+
+	err = trigger5_calculate_pll(&pll, mode->clock);
+	ppm = div64_u64(err * 1000, mode->clock);
+	if (ppm > 10000)
+		return MODE_CLOCK_RANGE;
+
+	return MODE_OK;
+}
+
+static int trigger5_plane_atomic_check(struct drm_plane *plane,
+				       struct drm_atomic_commit *state)
+{
+	struct drm_plane_state *new_plane_state =
+		drm_atomic_get_new_plane_state(state, plane);
+	struct drm_shadow_plane_state *shadow_plane_state =

drivers/gpu/drm/tiny/trigger5.c line 584

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+		to_drm_shadow_plane_state(new_plane_state);
+	struct drm_crtc *crtc = new_plane_state->crtc;
+	struct drm_crtc_state *new_crtc_state;
+	size_t len;
+	int ret;
+
+	if (!new_plane_state->fb)
+		return 0;
+
+	new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);

The pointer crtc can be NULL!  Then you cannot use it here. The pattern for this code is

  new_crtc_state = NULL;

  if (crtc)
    new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc)

The call to _check_plane_state() will then work correctly and make the plane as !visible.

Quoted 76 lines
drivers/gpu/drm/tiny/trigger5.c new file +76 -0
+
+	ret = drm_atomic_helper_check_plane_state(new_plane_state,
+						  new_crtc_state,
+						  DRM_PLANE_NO_SCALING,
+						  DRM_PLANE_NO_SCALING,
+						  false, false);
+	if (ret || !new_plane_state->visible)
+		return ret;
+
+	/* For drm_fb_xrgb8888_to_rgb888 temp buffer */
+	len = new_plane_state->fb->width * sizeof(u32);
+	if (!drm_format_conv_state_reserve(&shadow_plane_state->fmtcnv_state,
+					   len, GFP_KERNEL))
+		return -ENOMEM;
+
+	return 0;
+}
+
+static u8 trigger5_bulk_header_checksum(const struct trigger5_bulk_header *header)
+{
+	const u8 *data = (const u8 *)header;
+	u16 checksum = 0;
+	size_t i;
+
+	for (i = 0; i < sizeof(struct trigger5_bulk_header) - 1; i++)
+		checksum += data[i];
+	checksum &= 0xff;
+	checksum = 0x100 - checksum;
+	return checksum & 0xff;
+}
+
+static void trigger5_clear_rect(struct drm_rect *rect)
+{
+	rect->x1 = INT_MAX;
+	rect->y1 = INT_MAX;
+	rect->x2 = 0;
+	rect->y2 = 0;
+}
+
+static void trigger5_merge_rect(struct drm_rect *r1, const struct drm_rect *r2)
+{
+	r1->x1 = min(r1->x1, r2->x1);
+	r1->y1 = min(r1->y1, r2->y1);
+	r1->x2 = max(r1->x2, r2->x2);
+	r1->y2 = max(r1->y2, r2->y2);
+}
+
+static void trigger5_plane_atomic_update(struct drm_plane *plane,
+					 struct drm_atomic_commit *atomic_state)
+{
+	struct drm_plane_state *old_state =
+		drm_atomic_get_old_plane_state(atomic_state, plane);
+	struct drm_plane_state *state =
+		drm_atomic_get_new_plane_state(atomic_state, plane);
+	struct drm_shadow_plane_state *shadow_plane_state =
+		to_drm_shadow_plane_state(state);
+	struct trigger5_device *trigger5 = to_trigger5(plane->dev);
+	struct trigger5_transfer *current_transfer, *previous_transfer;
+	struct trigger5_bulk_header *header;
+	struct drm_rect current_rect, src_rect;
+	struct iosys_map data_map;
+	size_t frame_len, payload_len;
+	int width, height;
+	int idx, ret;
+
+	if (!drm_atomic_helper_damage_merged(old_state, state, &current_rect))
+		return;
+
+	if (!drm_dev_enter(plane->dev, &idx))
+		return;
+
+	current_transfer =
+		&trigger5->transfers[trigger5->current_transfer];
+	previous_transfer = &trigger5->transfers[1 - trigger5->current_transfer];
+
+	src_rect = drm_plane_state_src(state);

drivers/gpu/drm/tiny/trigger5.c line 670

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+
+	/* Match drm_atomic_helper_damage_iter_init() rounding. */
+	src_rect.x1 >>= 16;
+	src_rect.y1 >>= 16;
+	src_rect.x2 = (src_rect.x2 >> 16) + !!(src_rect.x2 & 0xffff);
+	src_rect.y2 = (src_rect.y2 >> 16) + !!(src_rect.y2 & 0xffff);
+
+	/* Latency reduction: requeue with the latest frame data. */
+	if (cancel_work(&previous_transfer->transfer_work)) {
+		complete(&previous_transfer->frame_complete);

I would not recommend this logic.  For rapid successive updates, your driver might end up canceling transfers and not sending any data for extended periods.  Better take each frame on its own.

Quoted 61 lines
drivers/gpu/drm/tiny/trigger5.c new file +61 -0
+
+		trigger5_merge_rect(&current_rect, &previous_transfer->transfer_rect);
+
+		current_transfer = previous_transfer;
+		trigger5->current_transfer = !trigger5->current_transfer;
+	}
+
+	/* Damage deferred by an earlier failed update. */
+	trigger5_merge_rect(&current_rect, &trigger5->pending_rect);
+	trigger5_clear_rect(&trigger5->pending_rect);
+
+	/* Clip merged damage to the new resolution. */
+	if (!drm_rect_intersect(&current_rect, &src_rect))
+		goto exit;
+
+	width = drm_rect_width(&current_rect);
+	height = drm_rect_height(&current_rect);
+	payload_len = array3_size(width, height, 3);
+	frame_len = size_add(payload_len, sizeof(*header));
+
+	if (drm_WARN_ON_ONCE(plane->dev, frame_len > current_transfer->buf.len))
+		goto exit;
+
+	/*
+	 * This should almost never wait because we have should have a
+	 * pending transfer ready to be de-queued above in case the transfer
+	 * hasn't finished, but do a bounded wait just in case it gets stuck
+	 */
+	if (!wait_for_completion_timeout(&current_transfer->frame_complete,
+					 msecs_to_jiffies(20)))
+		goto exit_save_pending;
+
+	current_transfer->transfer_rect = current_rect;
+
+	current_transfer->frame_len = frame_len;
+	header = current_transfer->buf.data;
+	header->magic = 0xfb;
+	header->length = 0x14;
+	/* flags 0: uncompressed 24-bit RGB888. */
+	header->counter =
+		cpu_to_le16((trigger5->frame_counter++) & 0xfff);
+	header->horizontal_offset = cpu_to_le16(current_rect.x1 - src_rect.x1);
+	header->vertical_offset = cpu_to_le16(current_rect.y1 - src_rect.y1);
+	header->width = cpu_to_le16(width);
+	header->height = cpu_to_le16(height);
+	header->payload_length = cpu_to_le32((u32)payload_len);
+	header->flags = 0x1;
+	header->unknown1 = 0;
+	header->unknown2 = 0;
+	header->checksum = trigger5_bulk_header_checksum(header);
+
+	iosys_map_set_vaddr(&data_map,
+			    current_transfer->buf.data + sizeof(*header));
+
+	ret = drm_gem_fb_begin_cpu_access(state->fb, DMA_FROM_DEVICE);
+	if (ret < 0) {
+		complete(&current_transfer->frame_complete);
+		goto exit_save_pending;
+	}
+
+	drm_fb_xrgb8888_to_rgb888(&data_map, NULL,

drivers/gpu/drm/tiny/trigger5.c line 741

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+				  &shadow_plane_state->data[0],
+				  state->fb, &current_rect,
+				  &shadow_plane_state->fmtcnv_state);
+
+	drm_gem_fb_end_cpu_access(state->fb, DMA_FROM_DEVICE);
+
+	flush_kernel_vmap_range(current_transfer->buf.data, frame_len);
+
+	queue_work(trigger5->transfer_wq, &current_transfer->transfer_work);
+	trigger5->current_transfer = !trigger5->current_transfer;

Why do you need a separate work item for the transfer. Can't you just send from here?  We do this in udl.

drivers/gpu/drm/tiny/trigger5.c line 753

Quoted 12 lines
drivers/gpu/drm/tiny/trigger5.c new file +12 -0
+	goto exit;
+
+	/* Retry the dropped damage on the next update. */
+exit_save_pending:
+	trigger5->pending_rect = current_rect;
+exit:
+	drm_dev_exit(idx);
+}
+
+static const struct drm_mode_config_helper_funcs
+trigger5_mode_config_helper_funcs = {
+	.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,

This helper will first switch on the CRTC and then update the plane.  But there's a comment somewhere that says "Keepalive must only be sent after a frame has been sent". The keepalive message is started in CRTC enable before sending the frame, (right?)  Isn't that a contradiction?

Quoted 20 lines
drivers/gpu/drm/tiny/trigger5.c new file +20 -0
+};
+
+static const struct drm_crtc_helper_funcs trigger5_crtc_helper_funcs = {
+	.mode_valid = trigger5_crtc_mode_valid,
+	.atomic_disable = trigger5_crtc_atomic_disable,
+	.atomic_check = drm_crtc_helper_atomic_check,
+	.atomic_enable = trigger5_crtc_atomic_enable,
+};
+
+static const struct drm_crtc_funcs trigger5_crtc_funcs = {
+	.atomic_create_state = drm_atomic_helper_crtc_create_state,
+	.destroy = drm_crtc_cleanup,
+	.set_config = drm_atomic_helper_set_config,
+	.page_flip = drm_atomic_helper_page_flip,
+	.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
+};
+
+static const struct drm_plane_helper_funcs trigger5_plane_helper_funcs = {
+	DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,

drivers/gpu/drm/tiny/trigger5.c line 783

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+	.atomic_check = trigger5_plane_atomic_check,
+	.atomic_update = trigger5_plane_atomic_update,
+};
+
+static const struct drm_plane_funcs trigger5_plane_funcs = {
+	.update_plane = drm_atomic_helper_update_plane,
+	.disable_plane = drm_atomic_helper_disable_plane,
+	.destroy = drm_plane_cleanup,
+	DRM_GEM_SHADOW_PLANE_FUNCS,
+};

I suggest to put the plane code and _funcs before the CRTC code and _funcs.

Quoted 34 lines
drivers/gpu/drm/tiny/trigger5.c new file +34 -0
+
+static const struct drm_encoder_funcs trigger5_encoder_funcs = {
+	.destroy = drm_encoder_cleanup,
+};
+
+static const u32 trigger5_plane_formats[] = {
+	DRM_FORMAT_XRGB8888,
+};
+
+static int trigger5_read_edid(void *data, u8 *buf, unsigned int block,
+			      size_t len)
+{
+	struct trigger5_device *trigger5 = data;
+	struct usb_device *udev = interface_to_usbdev(trigger5->intf);
+	int idx, ret;
+
+	if (!drm_dev_enter(&trigger5->drm, &idx))
+		return -ENODEV;
+
+	ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
+			      TRIGGER5_REQUEST_GET_EDID,
+			      USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+			      block, 0, buf, len, USB_CTRL_GET_TIMEOUT);
+	drm_dev_exit(idx);
+
+	if (ret < 0)
+		return ret;
+	if (ret != len)
+		return -EIO;
+
+	return 0;
+}
+
+static int trigger5_connector_get_modes(struct drm_connector *connector)

drivers/gpu/drm/tiny/trigger5.c line 827

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+{
+	struct trigger5_device *trigger5 = to_trigger5(connector->dev);
+	const struct drm_edid *edid;
+	int count;
+
+	edid = drm_edid_read_custom(connector, trigger5_read_edid, trigger5);
+	drm_edid_connector_update(connector, edid);
+	count = drm_edid_connector_add_modes(connector);
+	if (!count)
+		count = drm_add_modes_noedid(connector, 1920, 1200);

Please don't call drm_add_modes_noedid().  DRM helpers will set up safe modes if no EDID could be found.  In you driver simply return he value of count and let the helpers do their job.

Quoted 197 lines
drivers/gpu/drm/tiny/trigger5.c new file +197 -0
+	drm_edid_free(edid);
+
+	return count;
+}
+
+static enum drm_connector_status
+trigger5_detect(struct drm_connector *connector, bool force)
+{
+	struct trigger5_device *trigger5 = to_trigger5(connector->dev);
+	struct usb_device *udev = interface_to_usbdev(trigger5->intf);
+	u8 status[2];
+	int idx, ret;
+
+	if (!drm_dev_enter(&trigger5->drm, &idx))
+		return connector_status_disconnected;
+
+	ret = usb_control_msg_recv(udev, 0, TRIGGER5_REQUEST_GET_STATUS,
+				   USB_DIR_IN | USB_TYPE_VENDOR |
+					   USB_RECIP_DEVICE,
+				   0xff, 0x3, status, sizeof(status),
+				   USB_CTRL_GET_TIMEOUT, GFP_KERNEL);
+	drm_dev_exit(idx);
+
+	if (ret)
+		return connector_status_unknown;
+
+	return status[1] == 1 ? connector_status_connected :
+			     connector_status_disconnected;
+}
+
+static const struct drm_connector_helper_funcs trigger5_connector_helper_funcs = {
+	.get_modes = trigger5_connector_get_modes,
+};
+
+static const struct drm_connector_funcs trigger5_connector_funcs = {
+	.fill_modes = drm_helper_probe_single_connector_modes,
+	.destroy = drm_connector_cleanup,
+	.detect = trigger5_detect,
+	.reset = drm_atomic_helper_connector_reset,
+	.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
+	.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
+};
+
+static int trigger5_connector_init(struct trigger5_device *trigger5,
+				   int connector_type)
+{
+	int ret;
+
+	drm_connector_helper_add(&trigger5->connector,
+				 &trigger5_connector_helper_funcs);
+	ret = drm_connector_init(&trigger5->drm, &trigger5->connector,
+				 &trigger5_connector_funcs, connector_type);
+	trigger5->connector.polled =
+		DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
+	return ret;
+}
+
+static int trigger5_usb_probe(struct usb_interface *interface,
+			      const struct usb_device_id *id)
+{
+	int ret;
+	struct trigger5_device *trigger5;
+	struct usb_endpoint_descriptor *bulk_out;
+	struct drm_device *dev;
+	struct device *dma_dev;
+	struct usb_device *udev = interface_to_usbdev(interface);
+	/* Heuristic: Presence of audio interfaces indicates HDMI. */
+	bool is_hdmi = udev->actconfig->desc.bNumInterfaces > 1;
+
+	trigger5 = devm_drm_dev_alloc(&interface->dev, &trigger5_drm_driver,
+				      struct trigger5_device, drm);
+	if (IS_ERR(trigger5))
+		return PTR_ERR(trigger5);
+
+	trigger5->intf = interface;
+
+	ret = usb_find_bulk_out_endpoint(interface->cur_altsetting, &bulk_out);
+	if (ret)
+		return ret;
+	trigger5->bulk_pipe =
+		usb_sndbulkpipe(udev, usb_endpoint_num(bulk_out));
+
+	dev = &trigger5->drm;
+
+	dma_dev = usb_intf_get_dma_device(interface);
+	if (dma_dev) {
+		drm_dev_set_dma_dev(dev, dma_dev);
+		put_device(dma_dev);
+	} else {
+		drm_warn(dev,
+			 "buffer sharing not supported"); /* not an error */
+	}
+
+	ret = drmm_mode_config_init(dev);
+	if (ret)
+		return ret;
+
+	/*
+	 * The device has a built-in mode list, however we ignore
+	 * the mode list because the device accepts custom modes
+	 */
+	dev->mode_config.min_width = 1;
+	dev->mode_config.max_width = 8191;
+	dev->mode_config.min_height = 1;
+	dev->mode_config.max_height = 8191;
+
+	dev->mode_config.funcs = &trigger5_mode_config_funcs;
+	dev->mode_config.helper_private = &trigger5_mode_config_helper_funcs;
+
+	trigger5_clear_rect(&trigger5->pending_rect);
+
+	ret = drm_universal_plane_init(dev, &trigger5->plane, 0,
+				       &trigger5_plane_funcs,
+				       trigger5_plane_formats,
+				       ARRAY_SIZE(trigger5_plane_formats), NULL,
+				       DRM_PLANE_TYPE_PRIMARY, NULL);
+	if (ret)
+		return ret;
+
+	drm_plane_helper_add(&trigger5->plane, &trigger5_plane_helper_funcs);
+	drm_plane_enable_fb_damage_clips(&trigger5->plane);
+
+	ret = drm_crtc_init_with_planes(dev, &trigger5->crtc, &trigger5->plane,
+					NULL, &trigger5_crtc_funcs, NULL);
+	if (ret)
+		return ret;
+
+	drm_crtc_helper_add(&trigger5->crtc, &trigger5_crtc_helper_funcs);
+
+	ret = trigger5_connector_init(trigger5, is_hdmi ?
+					      DRM_MODE_CONNECTOR_HDMIA :
+					      DRM_MODE_CONNECTOR_VGA);
+	if (ret)
+		return ret;
+
+	ret = drm_encoder_init(dev, &trigger5->encoder, &trigger5_encoder_funcs,
+			       is_hdmi ? DRM_MODE_ENCODER_TMDS :
+					 DRM_MODE_ENCODER_DAC, NULL);
+	if (ret)
+		return ret;
+	trigger5->encoder.possible_crtcs = drm_crtc_mask(&trigger5->crtc);
+
+	ret = drm_connector_attach_encoder(&trigger5->connector,
+					   &trigger5->encoder);
+	if (ret)
+		return ret;
+
+	trigger5_init_transfer(trigger5, &trigger5->transfers[0]);
+	trigger5_init_transfer(trigger5, &trigger5->transfers[1]);
+	ret = trigger5_alloc_bulk_buffer(&trigger5->transfers[0].buf,
+					 TRIGGER5_TRANSFER_BUF_SIZE);
+	if (ret)
+		goto err_free_buffers;
+	ret = trigger5_alloc_bulk_buffer(&trigger5->transfers[1].buf,
+					 TRIGGER5_TRANSFER_BUF_SIZE);
+	if (ret)
+		goto err_free_buffers;
+
+	trigger5->transfer_wq = alloc_ordered_workqueue(DRIVER_NAME, 0);
+	if (!trigger5->transfer_wq) {
+		ret = -ENOMEM;
+		goto err_free_buffers;
+	}
+
+	INIT_DELAYED_WORK(&trigger5->keepalive_work,
+			  trigger5_keepalive_work);
+
+	drm_mode_config_reset(dev);
+
+	usb_set_intfdata(interface, trigger5);
+
+	drm_kms_helper_poll_init(dev);
+
+	ret = drm_dev_register(dev, 0);
+	if (ret)
+		goto err_poll_fini;
+
+	drm_client_setup(dev, NULL);
+
+	return 0;
+
+err_poll_fini:
+	drm_kms_helper_poll_fini(dev);
+	usb_set_intfdata(interface, NULL);
+	destroy_workqueue(trigger5->transfer_wq);
+err_free_buffers:
+	trigger5_free_bulk_buffer(&trigger5->transfers[0].buf);
+	trigger5_free_bulk_buffer(&trigger5->transfers[1].buf);
+	return ret;
+}
+
+static void trigger5_usb_disconnect(struct usb_interface *interface)
+{
+	struct trigger5_device *trigger5 = usb_get_intfdata(interface);
+	struct drm_device *dev = &trigger5->drm;
+
+	drm_kms_helper_poll_fini(dev);

drivers/gpu/drm/tiny/trigger5.c line 1034

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+	drm_dev_unplug(dev);
+	drm_atomic_helper_shutdown(dev);
+	trigger5_stop_io(trigger5);
+	destroy_workqueue(trigger5->transfer_wq);
+	trigger5_free_bulk_buffer(&trigger5->transfers[0].buf);
+	trigger5_free_bulk_buffer(&trigger5->transfers[1].buf);
+}
+
+static const struct usb_device_id id_table[] = {
+	/* From Windows driver INF file */

Please remove that comment.  It's likely to bit rot quickly.  Maybe mention it in the commit description, if you think it is important.

Best regards
Thomas

Quoted 83 lines
drivers/gpu/drm/tiny/trigger5.c new file +81 -0
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5800, 0) }, /* HDMI */
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5801, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5802, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5803, 0) },
+	{ USB_DEVICE(0x0711, 0x5804) }, /* VGA */
+	{ USB_DEVICE(0x0711, 0x5805) },
+	{ USB_DEVICE(0x0711, 0x5806) },
+	{ USB_DEVICE(0x0711, 0x5807) },
+	{ USB_DEVICE(0x0711, 0x5808) },
+	{ USB_DEVICE(0x0711, 0x5809) },
+	{ USB_DEVICE(0x0711, 0x580A) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580B, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580C, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580D, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580E, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580F, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5810, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5811, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5812, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5813, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5814, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5815, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5816, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5817, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5818, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5819, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581A, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581B, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581C, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581D, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581E, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581F, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5820, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5821, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5822, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5823, 0) },
+	{ USB_DEVICE(0x0711, 0x5824) },
+	{ USB_DEVICE(0x0711, 0x5825) },
+	{ USB_DEVICE(0x0711, 0x5826) },
+	{ USB_DEVICE(0x0711, 0x5827) },
+	{ USB_DEVICE(0x0711, 0x5828) },
+	{ USB_DEVICE(0x0711, 0x5829) },
+	{ USB_DEVICE(0x0711, 0x582A) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582B, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582C, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582D, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582E, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582F, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5830, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5831, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5832, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5833, 0) },
+	{ USB_DEVICE(0x0711, 0x5834) },
+	{ USB_DEVICE(0x0711, 0x5835) },
+	{ USB_DEVICE(0x0711, 0x5836) },
+	{ USB_DEVICE(0x0711, 0x5837) },
+	{ USB_DEVICE(0x0711, 0x5838) },
+	{ USB_DEVICE(0x0711, 0x5839) },
+	{ USB_DEVICE(0x0711, 0x583A) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583B, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583C, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583D, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583E, 0) },
+	{ USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583F, 0) },
+	{},
+};
+MODULE_DEVICE_TABLE(usb, id_table);
+
+static struct usb_driver trigger5_driver = {
+	.name = DRIVER_NAME,
+	.probe = trigger5_usb_probe,
+	.disconnect = trigger5_usb_disconnect,
+	.suspend = trigger5_usb_suspend,
+	.resume = trigger5_usb_resume,
+	.reset_resume = trigger5_usb_resume,
+	.id_table = id_table,
+};
+module_usb_driver(trigger5_driver);
+MODULE_AUTHOR("Ho Jie Feng <[email protected]>");
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");

base-commit: cf61bef3801c3c9d0d8c39026b7b2fb242898a3a

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
author
#3 lore raw
Quoted 4 lines · Thomas Zimmermann

Hi,

sorry for letting you wait for so long. You'll find a review below.

Thanks for the review! Since this driver shares many similarities with the ms91xx driver I am submitting too, I will be making the changes in that driver too.

Quoted 3 lines

The driver looks quite good already. Details below. To give one advice, I'd recommend to do away with the complicated transfer-worker logic and simply send everything as part of the plane update, if possible.

More details about this below.

Quoted 39 lines

Am 26.10.26 um 12:28 schrieb Ho Jie Feng:

Quoted 38 lines

Add a DRM driver for MCT Trigger 5 USB display adapters. This supports USB 3 to HDMI/VGA displays adapters with trigger5 chipsets from j5create, StarTech and various others.

The driver implements modesetting and USB framebuffer updates, connector detection, and EDID retrieval.

The protocol is based on reverse-engineering work by Forest Crossman (cyrozap) at: https://github.com/cyrozap/mct-usb-display-adapter-re
and usb packet captures between the Windows driver and the device.

Only the HDMI path has been tested. VGA selection is inferred from the absence of USB audio interfaces.

Tested on JUA355. The list of USB device IDs are taken from the Windows driver INF.

---
Changes in v5:
- Fix warnings found by kernel test robot

Changes in v4:
- Move the driver to drm/tiny
- Remove the buffer resizing to reduce size of file

Changes in v3:
- Flush the vmalloc buffer before submitting the USB transfer.
- Support display panning by using the source offset

Changes in v2:
- Move the buffer resizing to crtc_* functions so that we can report out of memory errors to userspace
- Change the PLL search function so that it is faster and doesn't produce checkpatch warnings
- Update drm functions: crtc reset becomes create_state
- Fix warnings reported by kernel test robot

Quoted 7 lines
Quoted 4 lines

sashiko review false positives in v1-4:
- atomic in these function names mean that the changes should go through through at once or not at all, nothing to do with atomic context. Furthermore other drivers also have similar patterns

Exactly. Somehow Sashiko doesn't get this. It thinks atomic means "atomic context".

It's the old sashiko using the older gemini 3.5 model, the newer one using gemimi-4-argon
doesn't seem to make the same mistake, so that's great.

Quoted 27 lines
Quoted 14 lines

- drm_gem_fb_begin_cpu_access is also required

  MAINTAINERS                     |    7 +
  drivers/gpu/drm/tiny/Kconfig    |   14 +
  drivers/gpu/drm/tiny/Makefile   |    1 +
  drivers/gpu/drm/tiny/trigger5.c | 1115 +++++++++++++++++++++++++++++++
  4 files changed, 1137 insertions(+)

create mode 100644 drivers/gpu/drm/tiny/trigger5.c
...

drivers/gpu/drm/tiny/trigger5.c new file +5 -0
+struct trigger5_device {
+     struct drm_device drm;
+     struct usb_interface *intf;
+     unsigned int bulk_pipe;
+

drivers/gpu/drm/tiny/trigger5.c line 94

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+     struct drm_connector connector;
+     struct drm_plane plane;
+     struct drm_crtc crtc;
+     struct drm_encoder encoder;
+
+     u16 frame_counter;
+
+     int current_transfer;
+     struct drm_rect pending_rect;
+     struct workqueue_struct *transfer_wq;

Do you really need your own queue?

Quoted 1 line

I'd recommend to push work on one of the system work queues.

Most of the time in the usb transfer is spent on waiting, I didn't feel like blocking a system work queue on a mostly waiting task. Also, the failure path can wait up to 5s, so I want the failure impact to be small on the rest of the system.

Quoted 4 lines
Quoted 1 line

+ bool display_enabled;

This field only seems to control the dependency between transfer and keepalive.

It signals the keepalive worker to stop immediately if display is not enabled. The keepalive is only launched with queue_delayed_work after a transfer.

Quoted 23 lines
Quoted 2 lines

...
+#define to_trigger5(x) container_of(x, struct trigger5_device, drm)

container_of_const() is nowadays the preferred macro.

Quoted 2 lines

...
+ drm_dbg_kms(&trigger5->drm,

Drivers should use drm_dbg()

Quoted 2 lines

...
+ drm_err(&trigger5->drm, "failed to configure display mode: %d\n", ret);

No error messages in the display-update code paths please. Maybe use drm_err_once(). Otherwise you might spam the kernel logs with endless error messages or give malicious user space a way to do that. Here and in other functions.

Quoted 1 line

+ new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);

The pointer crtc can be NULL! Then you cannot use it here. The pattern for this code is

Quoted 7 lines
   new_crtc_state = NULL;

if (crtc)
new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc)

The call to _check_plane_state() will then work correctly and make the plane as !visible.

The above changes will be made in v6 (and the ms91xx patch)

Quoted 35 lines
Quoted 35 lines
drivers/gpu/drm/tiny/trigger5.c new file +35 -0
+static void trigger5_plane_atomic_update(struct drm_plane *plane,
+                                      struct drm_atomic_commit *atomic_state)
+{
+     struct drm_plane_state *old_state =
+             drm_atomic_get_old_plane_state(atomic_state, plane);
+     struct drm_plane_state *state =
+             drm_atomic_get_new_plane_state(atomic_state, plane);
+     struct drm_shadow_plane_state *shadow_plane_state =
+             to_drm_shadow_plane_state(state);
+     struct trigger5_device *trigger5 = to_trigger5(plane->dev);
+     struct trigger5_transfer *current_transfer, *previous_transfer;
+     struct trigger5_bulk_header *header;
+     struct drm_rect current_rect, src_rect;
+     struct iosys_map data_map;
+     size_t frame_len, payload_len;
+     int width, height;
+     int idx, ret;
+
+     if (!drm_atomic_helper_damage_merged(old_state, state, &current_rect))
+             return;
+
+     if (!drm_dev_enter(plane->dev, &idx))
+             return;
+
+     current_transfer =
+             &trigger5->transfers[trigger5->current_transfer];
+     previous_transfer = &trigger5->transfers[1 - trigger5->current_transfer];
+
+     src_rect = drm_plane_state_src(state);
+
+     /* Match drm_atomic_helper_damage_iter_init() rounding. */
+     src_rect.x1 >>= 16;
+     src_rect.y1 >>= 16;
+     src_rect.x2 = (src_rect.x2 >> 16) + !!(src_rect.x2 & 0xffff);
+     src_rect.y2 = (src_rect.y2 >> 16) + !!(src_rect.y2 & 0xffff);
Quoted 8 lines

drivers/gpu/drm/tiny/trigger5.c line 670

Quoted 4 lines
drivers/gpu/drm/tiny/trigger5.c new file +4 -0
+
+     /* Latency reduction: requeue with the latest frame data. */
+     if (cancel_work(&previous_transfer->transfer_work)) {
+             complete(&previous_transfer->frame_complete);

I would not recommend this logic. For rapid successive updates, your driver might end up canceling transfers and not sending any data for extended periods. Better take each frame on its own.

The only small window when that could happen is that it might keep cancelling after the first frame finishing and before the next frame queued work item runs.

It could be solved with triple-buffering, but the additional memory footprint might be worth considering.

Quoted 67 lines
Quoted 67 lines
drivers/gpu/drm/tiny/trigger5.c new file +66 -0
+
+             trigger5_merge_rect(&current_rect, &previous_transfer->transfer_rect);
+
+             current_transfer = previous_transfer;
+             trigger5->current_transfer = !trigger5->current_transfer;
+     }
+
+     /* Damage deferred by an earlier failed update. */
+     trigger5_merge_rect(&current_rect, &trigger5->pending_rect);
+     trigger5_clear_rect(&trigger5->pending_rect);
+
+     /* Clip merged damage to the new resolution. */
+     if (!drm_rect_intersect(&current_rect, &src_rect))
+             goto exit;
+
+     width = drm_rect_width(&current_rect);
+     height = drm_rect_height(&current_rect);
+     payload_len = array3_size(width, height, 3);
+     frame_len = size_add(payload_len, sizeof(*header));
+
+     if (drm_WARN_ON_ONCE(plane->dev, frame_len > current_transfer->buf.len))
+             goto exit;
+
+     /*
+      * This should almost never wait because we have should have a
+      * pending transfer ready to be de-queued above in case the transfer
+      * hasn't finished, but do a bounded wait just in case it gets stuck
+      */
+     if (!wait_for_completion_timeout(&current_transfer->frame_complete,
+                                      msecs_to_jiffies(20)))
+             goto exit_save_pending;
+
+     current_transfer->transfer_rect = current_rect;
+
+     current_transfer->frame_len = frame_len;
+     header = current_transfer->buf.data;
+     header->magic = 0xfb;
+     header->length = 0x14;
+     /* flags 0: uncompressed 24-bit RGB888. */
+     header->counter =
+             cpu_to_le16((trigger5->frame_counter++) & 0xfff);
+     header->horizontal_offset = cpu_to_le16(current_rect.x1 - src_rect.x1);
+     header->vertical_offset = cpu_to_le16(current_rect.y1 - src_rect.y1);
+     header->width = cpu_to_le16(width);
+     header->height = cpu_to_le16(height);
+     header->payload_length = cpu_to_le32((u32)payload_len);
+     header->flags = 0x1;
+     header->unknown1 = 0;
+     header->unknown2 = 0;
+     header->checksum = trigger5_bulk_header_checksum(header);
+
+     iosys_map_set_vaddr(&data_map,
+                         current_transfer->buf.data + sizeof(*header));
+
+     ret = drm_gem_fb_begin_cpu_access(state->fb, DMA_FROM_DEVICE);
+     if (ret < 0) {
+             complete(&current_transfer->frame_complete);
+             goto exit_save_pending;
+     }
+
+     drm_fb_xrgb8888_to_rgb888(&data_map, NULL,
+                               &shadow_plane_state->data[0],
+                               state->fb, &current_rect,
+                               &shadow_plane_state->fmtcnv_state);
+
+     drm_gem_fb_end_cpu_access(state->fb, DMA_FROM_DEVICE);
Quoted 8 lines

drivers/gpu/drm/tiny/trigger5.c line 741

Quoted 5 lines
drivers/gpu/drm/tiny/trigger5.c new file +5 -0
+
+     flush_kernel_vmap_range(current_transfer->buf.data, frame_len);
+
+     queue_work(trigger5->transfer_wq, &current_transfer->transfer_work);
+     trigger5->current_transfer = !trigger5->current_transfer;

Why do you need a separate work item for the transfer. Can't you just send from here? We do this in udl.

I want to make the send async, so drm_fb_xrgb8888_to_rgb888 can run in parallel with the usb transfer. This is done since drm_fb_*_to_* functions are slow when copying on write-combined memory due to dma-buf sharing between the main GPU and this device.

udl does usb_submit_urb, which is async, but the usb_sg_wait has no async counterpart, so I opted for putting it in a worker.

I saw there's a TODO within the format helpers for io memory, so maybe in a future patch I could change it to use drm_memcpy_from_wc to speed it up. Currently it couldn't run at full 1080p at 60fps on bare-metal, but on a VM it is fine due to not copying from WC memory.

There's also the other issue of some compositors calling _update in the render loop or something that causes visible stutter when a device's _update callback is slow.

The ideal way to solve this, with both low latency and low memory footprint is to take inspiration from gm12u320 and store the fb and update rect in the device struct, and let a worker obtain the latest one from the struct. The transfer is then sent in blocks, while overlapping the drm copy and usb transfer in parallel. I think this is a bit too much complexity for a drm/tiny driver though.

Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/tiny/trigger5.c new file +9 -0
+     goto exit;
+
+     /* Retry the dropped damage on the next update. */
+exit_save_pending:
+     trigger5->pending_rect = current_rect;
+exit:
+     drm_dev_exit(idx);
+}
+
Quoted 8 lines

drivers/gpu/drm/tiny/trigger5.c line 753

Quoted 3 lines
drivers/gpu/drm/tiny/trigger5.c new file +3 -0
+static const struct drm_mode_config_helper_funcs
+trigger5_mode_config_helper_funcs = {
+     .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,

This helper will first switch on the CRTC and then update the plane. But there's a comment somewhere that says "Keepalive must only be sent after a frame has been sent". The keepalive message is started in CRTC enable before sending the frame, (right?) Isn't that a contradiction?

CRTC enable only sets display_enabled, but the first keepalive will only be launched in the transfer worker after the usb transfer finished.

Quoted 25 lines

drivers/gpu/drm/tiny/trigger5.c line 783

Quoted 7 lines
drivers/gpu/drm/tiny/trigger5.c new file +7 -0
+
+static const struct drm_plane_funcs trigger5_plane_funcs = {
+     .update_plane = drm_atomic_helper_update_plane,
+     .disable_plane = drm_atomic_helper_disable_plane,
+     .destroy = drm_plane_cleanup,
+     DRM_GEM_SHADOW_PLANE_FUNCS,
+};

I suggest to put the plane code and _funcs before the CRTC code and _funcs.

drivers/gpu/drm/tiny/trigger5.c line 827

Quoted 12 lines

...

drivers/gpu/drm/tiny/trigger5.c new file +11 -0
+static int trigger5_connector_get_modes(struct drm_connector *connector)
+{
+     struct trigger5_device *trigger5 = to_trigger5(connector->dev);
+     const struct drm_edid *edid;
+     int count;
+
+     edid = drm_edid_read_custom(connector, trigger5_read_edid, trigger5);
+     drm_edid_connector_update(connector, edid);
+     count = drm_edid_connector_add_modes(connector);
+     if (!count)
+             count = drm_add_modes_noedid(connector, 1920, 1200);

Please don't call drm_add_modes_noedid(). DRM helpers will set up safe modes if no EDID could be found. In you driver simply return he value of count and let the helpers do their job.

Quoted 6 lines

drivers/gpu/drm/tiny/trigger5.c line 1034

Quoted 3 lines

...

drivers/gpu/drm/tiny/trigger5.c new file +2 -0
+static const struct usb_device_id id_table[] = {
+     /* From Windows driver INF file */

Please remove that comment. It's likely to bit rot quickly. Maybe mention it in the commit description, if you think it is important.

Will be implemented in v6.

Quoted 96 lines

Best regards
Thomas

Quoted 82 lines
drivers/gpu/drm/tiny/trigger5.c new file +81 -0
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5800, 0) }, /* HDMI */
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5801, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5802, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5803, 0) },
+     { USB_DEVICE(0x0711, 0x5804) }, /* VGA */
+     { USB_DEVICE(0x0711, 0x5805) },
+     { USB_DEVICE(0x0711, 0x5806) },
+     { USB_DEVICE(0x0711, 0x5807) },
+     { USB_DEVICE(0x0711, 0x5808) },
+     { USB_DEVICE(0x0711, 0x5809) },
+     { USB_DEVICE(0x0711, 0x580A) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580B, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580C, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580D, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580E, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580F, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5810, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5811, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5812, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5813, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5814, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5815, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5816, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5817, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5818, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5819, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581A, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581B, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581C, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581D, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581E, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581F, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5820, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5821, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5822, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5823, 0) },
+     { USB_DEVICE(0x0711, 0x5824) },
+     { USB_DEVICE(0x0711, 0x5825) },
+     { USB_DEVICE(0x0711, 0x5826) },
+     { USB_DEVICE(0x0711, 0x5827) },
+     { USB_DEVICE(0x0711, 0x5828) },
+     { USB_DEVICE(0x0711, 0x5829) },
+     { USB_DEVICE(0x0711, 0x582A) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582B, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582C, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582D, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582E, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582F, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5830, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5831, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5832, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5833, 0) },
+     { USB_DEVICE(0x0711, 0x5834) },
+     { USB_DEVICE(0x0711, 0x5835) },
+     { USB_DEVICE(0x0711, 0x5836) },
+     { USB_DEVICE(0x0711, 0x5837) },
+     { USB_DEVICE(0x0711, 0x5838) },
+     { USB_DEVICE(0x0711, 0x5839) },
+     { USB_DEVICE(0x0711, 0x583A) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583B, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583C, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583D, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583E, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583F, 0) },
+     {},
+};
+MODULE_DEVICE_TABLE(usb, id_table);
+
+static struct usb_driver trigger5_driver = {
+     .name = DRIVER_NAME,
+     .probe = trigger5_usb_probe,
+     .disconnect = trigger5_usb_disconnect,
+     .suspend = trigger5_usb_suspend,
+     .resume = trigger5_usb_resume,
+     .reset_resume = trigger5_usb_resume,
+     .id_table = id_table,
+};
+module_usb_driver(trigger5_driver);
+MODULE_AUTHOR("Ho Jie Feng <[email protected]>");
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
Quoted 1 line

base-commit: cf61bef3801c3c9d0d8c39026b7b2fb242898a3a

--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)

#4 lore raw

Hi

Am 10.11.26 um 16:49 schrieb Jie Feng:

Quoted 7 lines · Thomas Zimmermann
Quoted 3 lines

Hi,

sorry for letting you wait for so long. You'll find a review below.

Thanks for the review! Since this driver shares many similarities with the ms91xx driver I am submitting too, I will be making the changes in that driver too.

I've briefly seen that other driver. Let's focus on one of them first. The other will then be easier, I guess.

Quoted 242 lines
Quoted 4 lines

The driver looks quite good already. Details below. To give one advice, I'd recommend to do away with the complicated transfer-worker logic and simply send everything as part of the plane update, if possible.

More details about this below.

Quoted 39 lines

Am 26.10.26 um 12:28 schrieb Ho Jie Feng:

Quoted 38 lines

Add a DRM driver for MCT Trigger 5 USB display adapters. This supports USB 3 to HDMI/VGA displays adapters with trigger5 chipsets from j5create, StarTech and various others.

The driver implements modesetting and USB framebuffer updates, connector detection, and EDID retrieval.

The protocol is based on reverse-engineering work by Forest Crossman (cyrozap) at: https://github.com/cyrozap/mct-usb-display-adapter-re
and usb packet captures between the Windows driver and the device.

Only the HDMI path has been tested. VGA selection is inferred from the absence of USB audio interfaces.

Tested on JUA355. The list of USB device IDs are taken from the Windows driver INF.

---
Changes in v5:
- Fix warnings found by kernel test robot

Changes in v4:
- Move the driver to drm/tiny
- Remove the buffer resizing to reduce size of file

Changes in v3:
- Flush the vmalloc buffer before submitting the USB transfer.
- Support display panning by using the source offset

Changes in v2:
- Move the buffer resizing to crtc_* functions so that we can report out of memory errors to userspace
- Change the PLL search function so that it is faster and doesn't produce checkpatch warnings
- Update drm functions: crtc reset becomes create_state
- Fix warnings reported by kernel test robot

Quoted 6 lines
Quoted 4 lines

sashiko review false positives in v1-4:
- atomic in these function names mean that the changes should go through through at once or not at all, nothing to do with atomic context. Furthermore other drivers also have similar patterns

Exactly. Somehow Sashiko doesn't get this. It thinks atomic means "atomic context".

It's the old sashiko using the older gemini 3.5 model, the newer one using gemimi-4-argon
doesn't seem to make the same mistake, so that's great.

Quoted 26 lines
Quoted 14 lines

- drm_gem_fb_begin_cpu_access is also required

   MAINTAINERS                     |    7 +
   drivers/gpu/drm/tiny/Kconfig    |   14 +
   drivers/gpu/drm/tiny/Makefile   |    1 +
   drivers/gpu/drm/tiny/trigger5.c | 1115 +++++++++++++++++++++++++++++++
   4 files changed, 1137 insertions(+)

create mode 100644 drivers/gpu/drm/tiny/trigger5.c
...

drivers/gpu/drm/tiny/trigger5.c new file +5 -0
+struct trigger5_device {
+     struct drm_device drm;
+     struct usb_interface *intf;
+     unsigned int bulk_pipe;
+

drivers/gpu/drm/tiny/trigger5.c line 94

Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10 -0
+     struct drm_connector connector;
+     struct drm_plane plane;
+     struct drm_crtc crtc;
+     struct drm_encoder encoder;
+
+     u16 frame_counter;
+
+     int current_transfer;
+     struct drm_rect pending_rect;
+     struct workqueue_struct *transfer_wq;

Do you really need your own queue?

Quoted 1 line

I'd recommend to push work on one of the system work queues.

Most of the time in the usb transfer is spent on waiting, I didn't feel like blocking a system work queue on a mostly waiting task. Also, the failure path can wait up to 5s, so I want the failure impact to be small on the rest of the system.

Quoted 3 lines
Quoted 1 line

+ bool display_enabled;

This field only seems to control the dependency between transfer and keepalive.

It signals the keepalive worker to stop immediately if display is not enabled. The keepalive is only launched with queue_delayed_work after a transfer.

Quoted 19 lines
Quoted 2 lines

...
+#define to_trigger5(x) container_of(x, struct trigger5_device, drm)

container_of_const() is nowadays the preferred macro.

Quoted 2 lines

...
+ drm_dbg_kms(&trigger5->drm,

Drivers should use drm_dbg()

Quoted 2 lines

...
+ drm_err(&trigger5->drm, "failed to configure display mode: %d\n", ret);

No error messages in the display-update code paths please. Maybe use drm_err_once(). Otherwise you might spam the kernel logs with endless error messages or give malicious user space a way to do that. Here and in other functions.

Quoted 1 line

+ new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);

The pointer crtc can be NULL! Then you cannot use it here. The pattern for this code is

Quoted 7 lines

new_crtc_state = NULL;

if (crtc)
new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc)

The call to _check_plane_state() will then work correctly and make the plane as !visible.

The above changes will be made in v6 (and the ms91xx patch)

Quoted 34 lines
Quoted 34 lines
drivers/gpu/drm/tiny/trigger5.c new file +34 -0
+static void trigger5_plane_atomic_update(struct drm_plane *plane,
+                                      struct drm_atomic_commit *atomic_state)
+{
+     struct drm_plane_state *old_state =
+             drm_atomic_get_old_plane_state(atomic_state, plane);
+     struct drm_plane_state *state =
+             drm_atomic_get_new_plane_state(atomic_state, plane);
+     struct drm_shadow_plane_state *shadow_plane_state =
+             to_drm_shadow_plane_state(state);
+     struct trigger5_device *trigger5 = to_trigger5(plane->dev);
+     struct trigger5_transfer *current_transfer, *previous_transfer;
+     struct trigger5_bulk_header *header;
+     struct drm_rect current_rect, src_rect;
+     struct iosys_map data_map;
+     size_t frame_len, payload_len;
+     int width, height;
+     int idx, ret;
+
+     if (!drm_atomic_helper_damage_merged(old_state, state, &current_rect))
+             return;
+
+     if (!drm_dev_enter(plane->dev, &idx))
+             return;
+
+     current_transfer =
+             &trigger5->transfers[trigger5->current_transfer];
+     previous_transfer = &trigger5->transfers[1 - trigger5->current_transfer];
+
+     src_rect = drm_plane_state_src(state);
+
+     /* Match drm_atomic_helper_damage_iter_init() rounding. */
+     src_rect.x1 >>= 16;
+     src_rect.y1 >>= 16;
+     src_rect.x2 = (src_rect.x2 >> 16) + !!(src_rect.x2 & 0xffff);
Quoted 8 lines

drivers/gpu/drm/tiny/trigger5.c line 670

Quoted 5 lines
drivers/gpu/drm/tiny/trigger5.c new file +5 -0
+     src_rect.y2 = (src_rect.y2 >> 16) + !!(src_rect.y2 & 0xffff);
+
+     /* Latency reduction: requeue with the latest frame data. */
+     if (cancel_work(&previous_transfer->transfer_work)) {
+             complete(&previous_transfer->frame_complete);

I would not recommend this logic. For rapid successive updates, your driver might end up canceling transfers and not sending any data for extended periods. Better take each frame on its own.

The only small window when that could happen is that it might keep cancelling after the first frame finishing and before the next frame queued work item runs.

It could be solved with triple-buffering, but the additional memory footprint might be worth considering.

Quoted 65 lines
Quoted 65 lines
drivers/gpu/drm/tiny/trigger5.c new file +65 -0
+
+             trigger5_merge_rect(&current_rect, &previous_transfer->transfer_rect);
+
+             current_transfer = previous_transfer;
+             trigger5->current_transfer = !trigger5->current_transfer;
+     }
+
+     /* Damage deferred by an earlier failed update. */
+     trigger5_merge_rect(&current_rect, &trigger5->pending_rect);
+     trigger5_clear_rect(&trigger5->pending_rect);
+
+     /* Clip merged damage to the new resolution. */
+     if (!drm_rect_intersect(&current_rect, &src_rect))
+             goto exit;
+
+     width = drm_rect_width(&current_rect);
+     height = drm_rect_height(&current_rect);
+     payload_len = array3_size(width, height, 3);
+     frame_len = size_add(payload_len, sizeof(*header));
+
+     if (drm_WARN_ON_ONCE(plane->dev, frame_len > current_transfer->buf.len))
+             goto exit;
+
+     /*
+      * This should almost never wait because we have should have a
+      * pending transfer ready to be de-queued above in case the transfer
+      * hasn't finished, but do a bounded wait just in case it gets stuck
+      */
+     if (!wait_for_completion_timeout(&current_transfer->frame_complete,
+                                      msecs_to_jiffies(20)))
+             goto exit_save_pending;
+
+     current_transfer->transfer_rect = current_rect;
+
+     current_transfer->frame_len = frame_len;
+     header = current_transfer->buf.data;
+     header->magic = 0xfb;
+     header->length = 0x14;
+     /* flags 0: uncompressed 24-bit RGB888. */
+     header->counter =
+             cpu_to_le16((trigger5->frame_counter++) & 0xfff);
+     header->horizontal_offset = cpu_to_le16(current_rect.x1 - src_rect.x1);
+     header->vertical_offset = cpu_to_le16(current_rect.y1 - src_rect.y1);
+     header->width = cpu_to_le16(width);
+     header->height = cpu_to_le16(height);
+     header->payload_length = cpu_to_le32((u32)payload_len);
+     header->flags = 0x1;
+     header->unknown1 = 0;
+     header->unknown2 = 0;
+     header->checksum = trigger5_bulk_header_checksum(header);
+
+     iosys_map_set_vaddr(&data_map,
+                         current_transfer->buf.data + sizeof(*header));
+
+     ret = drm_gem_fb_begin_cpu_access(state->fb, DMA_FROM_DEVICE);
+     if (ret < 0) {
+             complete(&current_transfer->frame_complete);
+             goto exit_save_pending;
+     }
+
+     drm_fb_xrgb8888_to_rgb888(&data_map, NULL,
+                               &shadow_plane_state->data[0],
+                               state->fb, &current_rect,
+                               &shadow_plane_state->fmtcnv_state);
+
Quoted 8 lines

drivers/gpu/drm/tiny/trigger5.c line 741

Quoted 6 lines
drivers/gpu/drm/tiny/trigger5.c new file +6 -0
+     drm_gem_fb_end_cpu_access(state->fb, DMA_FROM_DEVICE);
+
+     flush_kernel_vmap_range(current_transfer->buf.data, frame_len);
+
+     queue_work(trigger5->transfer_wq, &current_transfer->transfer_work);
+     trigger5->current_transfer = !trigger5->current_transfer;

Why do you need a separate work item for the transfer. Can't you just send from here? We do this in udl.

Quoted 4 lines

I want to make the send async, so drm_fb_xrgb8888_to_rgb888 can run in parallel with the usb transfer. This is done since drm_fb_*_to_* functions are slow when copying on write-combined memory due to dma-buf sharing between the main GPU and this device.

We do this in other drivers as well. Neither is supposed to be fast. There's always this memcpy from the imported buffer.

Quoted 3 lines

udl does usb_submit_urb, which is async, but the usb_sg_wait has no async counterpart, so I opted for putting it in a worker.

Why do you use usb_sg_wait() in the first place? It appears to be a loop around usb_submit_urb() plus the waiting. (The comment at [1] is actually quite funny.)

[1] https://elixir.bootlin.com/linux/v7.3.1/source/drivers/usb/core/message.c#L761

Quoted 6 lines

I saw there's a TODO within the format helpers for io memory, so maybe in a future patch I could change it to use drm_memcpy_from_wc to speed it up. Currently it couldn't run at full 1080p at 60fps on bare-metal, but on a VM it is fine due to not copying from WC memory.

Quoted 7 lines

There's also the other issue of some compositors calling _update in the render loop or something that causes visible stutter when a device's _update callback is slow.

The ideal way to solve this, with both low latency and low memory footprint is to take inspiration from gm12u320 and store the fb and update rect in the device struct, and let a worker obtain the latest one from the struct.

It's not. None of our USB-based drivers are well optimized. You can take some inspiration from them, but don't take them as they are.

At the end of each page flip, DRM sends out a FLIP_COMPLETE event, [2] telling the compositor that it's done with the display update. This gives the compositor an idea about the performance of the device.  It can adapt to that and end out less updates. By moving out the actual work into a separate thread, you break that feedback. The compositor will see an early complete from the page flip and queue up the next frame immediately. The driver will pile up updates for the worker to send out. Hence, leave the copying and sending operations in the regular update code.  If you build this with usb_submit_urb(), there's no waiting necessary.

[2] https://elixir.bootlin.com/linux/v7.3.1/source/include/uapi/drm/drm.h#L1395

What I have in mind for udl is this logic:

1. send the current frame's updates as usual using usb_submit_urb()
  - transfer runs in parallel to current display update
  - count the number of submitted urbs
2. in each complete handler, decrement the urb count.
3. in the next frame's atomic_begin, wait until the urb counter reaches zero
  - most parallelism
  - max out USB
  - maintains correct transfer statistics and events
4. if the second frame takes longer than expected, the FLIP_COMPLETE event wil be late; the compositor can throttle the page-flip rate

I made a nicely working prototype from this.

Best regards
Thomas

Quoted 152 lines

The transfer is then sent in blocks, while overlapping the drm copy and usb transfer in parallel. I think this is a bit too much complexity for a drm/tiny driver though.

Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/tiny/trigger5.c new file +8 -0
+     goto exit;
+
+     /* Retry the dropped damage on the next update. */
+exit_save_pending:
+     trigger5->pending_rect = current_rect;
+exit:
+     drm_dev_exit(idx);
+}
Quoted 8 lines

drivers/gpu/drm/tiny/trigger5.c line 753

Quoted 4 lines
drivers/gpu/drm/tiny/trigger5.c new file +4 -0
+
+static const struct drm_mode_config_helper_funcs
+trigger5_mode_config_helper_funcs = {
+     .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,

This helper will first switch on the CRTC and then update the plane. But there's a comment somewhere that says "Keepalive must only be sent after a frame has been sent". The keepalive message is started in CRTC enable before sending the frame, (right?) Isn't that a contradiction?

CRTC enable only sets display_enabled, but the first keepalive will only be launched in the transfer worker after the usb transfer finished.

Quoted 23 lines

drivers/gpu/drm/tiny/trigger5.c line 783

Quoted 7 lines
drivers/gpu/drm/tiny/trigger5.c new file +7 -0
+
+static const struct drm_plane_funcs trigger5_plane_funcs = {
+     .update_plane = drm_atomic_helper_update_plane,
+     .disable_plane = drm_atomic_helper_disable_plane,
+     .destroy = drm_plane_cleanup,
+     DRM_GEM_SHADOW_PLANE_FUNCS,
+};

I suggest to put the plane code and _funcs before the CRTC code and _funcs.

drivers/gpu/drm/tiny/trigger5.c line 827

Quoted 12 lines

...

drivers/gpu/drm/tiny/trigger5.c new file +11 -0
+static int trigger5_connector_get_modes(struct drm_connector *connector)
+{
+     struct trigger5_device *trigger5 = to_trigger5(connector->dev);
+     const struct drm_edid *edid;
+     int count;
+
+     edid = drm_edid_read_custom(connector, trigger5_read_edid, trigger5);
+     drm_edid_connector_update(connector, edid);
+     count = drm_edid_connector_add_modes(connector);
+     if (!count)
+             count = drm_add_modes_noedid(connector, 1920, 1200);

Please don't call drm_add_modes_noedid(). DRM helpers will set up safe modes if no EDID could be found. In you driver simply return he value of count and let the helpers do their job.

Quoted 5 lines

drivers/gpu/drm/tiny/trigger5.c line 1034

Quoted 3 lines

...

drivers/gpu/drm/tiny/trigger5.c new file +2 -0
+static const struct usb_device_id id_table[] = {
+     /* From Windows driver INF file */

Please remove that comment. It's likely to bit rot quickly. Maybe mention it in the commit description, if you think it is important.

Will be implemented in v6.

Quoted 95 lines

Best regards
Thomas

Quoted 82 lines
drivers/gpu/drm/tiny/trigger5.c new file +81 -0
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5800, 0) }, /* HDMI */
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5801, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5802, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5803, 0) },
+     { USB_DEVICE(0x0711, 0x5804) }, /* VGA */
+     { USB_DEVICE(0x0711, 0x5805) },
+     { USB_DEVICE(0x0711, 0x5806) },
+     { USB_DEVICE(0x0711, 0x5807) },
+     { USB_DEVICE(0x0711, 0x5808) },
+     { USB_DEVICE(0x0711, 0x5809) },
+     { USB_DEVICE(0x0711, 0x580A) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580B, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580C, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580D, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580E, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x580F, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5810, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5811, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5812, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5813, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5814, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5815, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5816, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5817, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5818, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5819, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581A, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581B, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581C, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581D, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581E, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x581F, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5820, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5821, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5822, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5823, 0) },
+     { USB_DEVICE(0x0711, 0x5824) },
+     { USB_DEVICE(0x0711, 0x5825) },
+     { USB_DEVICE(0x0711, 0x5826) },
+     { USB_DEVICE(0x0711, 0x5827) },
+     { USB_DEVICE(0x0711, 0x5828) },
+     { USB_DEVICE(0x0711, 0x5829) },
+     { USB_DEVICE(0x0711, 0x582A) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582B, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582C, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582D, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582E, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x582F, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5830, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5831, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5832, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x5833, 0) },
+     { USB_DEVICE(0x0711, 0x5834) },
+     { USB_DEVICE(0x0711, 0x5835) },
+     { USB_DEVICE(0x0711, 0x5836) },
+     { USB_DEVICE(0x0711, 0x5837) },
+     { USB_DEVICE(0x0711, 0x5838) },
+     { USB_DEVICE(0x0711, 0x5839) },
+     { USB_DEVICE(0x0711, 0x583A) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583B, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583C, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583D, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583E, 0) },
+     { USB_DEVICE_INTERFACE_NUMBER(0x0711, 0x583F, 0) },
+     {},
+};
+MODULE_DEVICE_TABLE(usb, id_table);
+
+static struct usb_driver trigger5_driver = {
+     .name = DRIVER_NAME,
+     .probe = trigger5_usb_probe,
+     .disconnect = trigger5_usb_disconnect,
+     .suspend = trigger5_usb_suspend,
+     .resume = trigger5_usb_resume,
+     .reset_resume = trigger5_usb_resume,
+     .id_table = id_table,
+};
+module_usb_driver(trigger5_driver);
+MODULE_AUTHOR("Ho Jie Feng <[email protected]>");
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
Quoted 1 line

base-commit: cf61bef3801c3c9d0d8c39026b7b2fb242898a3a

--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)
author
#5 lore raw
Quoted 7 lines · Thomas Zimmermann

Hi

Am 10.11.26 um 16:49 schrieb Jie Feng:

Quoted 3 lines · Thomas Zimmermann
Quoted 2 lines

Hi,

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

sorry for letting you wait for so long. You'll find a review below.

Thanks for the review! Since this driver shares many similarities with the ms91xx driver I am submitting too, I will be making the changes in that driver too.

I've briefly seen that other driver. Let's focus on one of them first. The other will then be easier, I guess.

Sure, let's focus on the review here, this is a much smaller driver.

Quoted 31 lines
Quoted 21 lines
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/tiny/trigger5.c new file +11 -0
+     ret = drm_gem_fb_begin_cpu_access(state->fb, DMA_FROM_DEVICE);
+     if (ret < 0) {
+             complete(&current_transfer->frame_complete);
+             goto exit_save_pending;
+     }
+
+     drm_fb_xrgb8888_to_rgb888(&data_map, NULL,
+                               &shadow_plane_state->data[0],
+                               state->fb, &current_rect,
+                               &shadow_plane_state->fmtcnv_state);
+
Quoted 8 lines

drivers/gpu/drm/tiny/trigger5.c line 741

Quoted 6 lines
drivers/gpu/drm/tiny/trigger5.c new file +6 -0
+     drm_gem_fb_end_cpu_access(state->fb, DMA_FROM_DEVICE);
+
+     flush_kernel_vmap_range(current_transfer->buf.data, frame_len);
+
+     queue_work(trigger5->transfer_wq, &current_transfer->transfer_work);
+     trigger5->current_transfer = !trigger5->current_transfer;

Why do you need a separate work item for the transfer. Can't you just send from here? We do this in udl.

Quoted 4 lines

I want to make the send async, so drm_fb_xrgb8888_to_rgb888 can run in parallel with the usb transfer. This is done since drm_fb_*_to_* functions are slow when copying on write-combined memory due to dma-buf sharing between the main GPU and this device.

We do this in other drivers as well. Neither is supposed to be fast. There's always this memcpy from the imported buffer.

Quoted 1 line
Quoted 4 lines
Quoted 2 lines

udl does usb_submit_urb, which is async, but the usb_sg_wait has no async counterpart, so I opted for putting it in a worker.

Why do you use usb_sg_wait() in the first place? It appears to be a loop

This part is referenced from gud. I thought it makes sense since I need a large vmalloc buffer, so using usb_sg_* looked like the right approach instead of asking for kmalloc(8MB).

Alternative I considered are:
- usb_alloc_noncoherent: but that requires implementing a fallback if a controller doesn't support scatter gather DMA, while usb_sg_* does handle all of these cases.
- pool of fixed kmalloc buffers: 64K seems too small, too many URBs for a 1080p frame, and tuning the number so that kmalloc will likely to succeed on a fragmented system while keeping the number of URBs per 1080p frame small doesn't seem like the right approach to me.

Are there other possible approaches to this?

Quoted 5 lines

around usb_submit_urb() plus the waiting. (The comment at [1] is actually quite funny.

[1]
https://elixir.bootlin.com/linux/v7.3.1/source/drivers/usb/core/message.c#L761

Indeed!

Quoted 17 lines
Quoted 6 lines

I saw there's a TODO within the format helpers for io memory, so maybe in a future patch I could change it to use drm_memcpy_from_wc to speed it up. Currently it couldn't run at full 1080p at 60fps on bare-metal, but on a VM it is fine due to not copying from WC memory.

Quoted 7 lines

There's also the other issue of some compositors calling _update in the render loop or something that causes visible stutter when a device's _update callback is slow.

The ideal way to solve this, with both low latency and low memory footprint is to take inspiration from gm12u320 and store the fb and update rect in the device struct, and let a worker obtain the latest one from the struct.

It's not. None of our USB-based drivers are well optimized. You can take some inspiration from them, but don't take them as they are.

Quoted 10 lines

At the end of each page flip, DRM sends out a FLIP_COMPLETE event, [2] telling the compositor that it's done with the display update. This gives the compositor an idea about the performance of the device. It can adapt to that and end out less updates. By moving out the actual work into a separate thread, you break that feedback. The compositor will see an early complete from the page flip and queue up the next frame immediately. The driver will pile up updates for the worker to send out. Hence, leave the copying and sending operations in the regular update code. If you build this with usb_submit_urb(), there's no waiting necessary.

In that case, assuming I keep the usb_sg_wait, doing something like wait_for_completion(previous_transfer) would be more correct.

Quoted 5 lines

[2]
https://elixir.bootlin.com/linux/v7.3.1/source/include/uapi/drm/drm.h#L1395

What I have in mind for udl is this logic:

Quoted 10 lines

1. send the current frame's updates as usual using usb_submit_urb()
- transfer runs in parallel to current display update
- count the number of submitted urbs
2. in each complete handler, decrement the urb count.
3. in the next frame's atomic_begin, wait until the urb counter reaches zero
- most parallelism
- max out USB
- maintains correct transfer statistics and events
4. if the second frame takes longer than expected, the FLIP_COMPLETE event wil be late; the compositor can throttle the page-flip rate

For this one, wait_for_completion(previous_transfer) looks to be similar in behaviour.

Quoted 14 lines

I made a nicely working prototype from this.

Best regards
Thomas

Quoted 8 lines

The transfer is then sent in blocks, while overlapping the drm copy and usb transfer in parallel. I think this is a bit too much complexity for a drm/tiny driver though.

...

#6 lore raw

Hi

Am 11.11.26 um 18:07 schrieb Jie Feng:

Quoted 37 lines · Thomas Zimmermann
Quoted 4 lines

Hi

Am 10.11.26 um 16:49 schrieb Jie Feng:

Quoted 1 line · Thomas Zimmermann
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Hi,

sorry for letting you wait for so long. You'll find a review below.

Thanks for the review! Since this driver shares many similarities with the ms91xx driver I am submitting too, I will be making the changes in that driver too.

I've briefly seen that other driver. Let's focus on one of them first. The other will then be easier, I guess.

Sure, let's focus on the review here, this is a much smaller driver.

Quoted 23 lines
Quoted 23 lines
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/tiny/trigger5.c new file +11 -0
+     ret = drm_gem_fb_begin_cpu_access(state->fb, DMA_FROM_DEVICE);
+     if (ret < 0) {
+             complete(&current_transfer->frame_complete);
+             goto exit_save_pending;
+     }
+
+     drm_fb_xrgb8888_to_rgb888(&data_map, NULL,
+                               &shadow_plane_state->data[0],
+                               state->fb, &current_rect,
+                               &shadow_plane_state->fmtcnv_state);
+
Quoted 8 lines

drivers/gpu/drm/tiny/trigger5.c line 741

Quoted 6 lines
drivers/gpu/drm/tiny/trigger5.c new file +6 -0
+     drm_gem_fb_end_cpu_access(state->fb, DMA_FROM_DEVICE);
+
+     flush_kernel_vmap_range(current_transfer->buf.data, frame_len);
+
+     queue_work(trigger5->transfer_wq, &current_transfer->transfer_work);
+     trigger5->current_transfer = !trigger5->current_transfer;

Why do you need a separate work item for the transfer. Can't you just send from here? We do this in udl.

I want to make the send async, so drm_fb_xrgb8888_to_rgb888 can run in parallel with the usb transfer. This is done since drm_fb_*_to_* functions are slow when copying on write-combined memory due to dma-buf sharing between the main GPU and this device.

Quoted 8 lines
Quoted 7 lines

We do this in other drivers as well. Neither is supposed to be fast. There's always this memcpy from the imported buffer.

Quoted 2 lines

udl does usb_submit_urb, which is async, but the usb_sg_wait has no async counterpart, so I opted for putting it in a worker.

Why do you use usb_sg_wait() in the first place? It appears to be a loop

This part is referenced from gud. I thought it makes sense since I need a large

Gud isn't really up to date and needs maintenance.  IIRC pushing the transfer out of the regular display pipeline worked around limitations in user space, which couldn't handle the long transfer times over USB.  But that problem has been fixed long ago.

Quoted 13 lines

vmalloc buffer, so using usb_sg_* looked like the right approach instead of asking for kmalloc(8MB).

Alternative I considered are:
- usb_alloc_noncoherent: but that requires implementing a fallback if a controller doesn't support scatter gather DMA, while usb_sg_* does handle all of these cases.
- pool of fixed kmalloc buffers: 64K seems too small, too many URBs for a 1080p frame, and tuning the number so that kmalloc will likely to succeed on a fragmented system while keeping the number of URBs per 1080p frame small doesn't seem like the right approach to me.

Quoted 1 line

Are there other possible approaches to this?

Most updates are small. Optimizing or full-screen redraws might not be worth the effort. Apart from that, set a reasonable size limit for the send buffer, and put in as many scan lines as possible. Then do this for the next until the damage rectangle has been covered.

Quoted 32 lines
Quoted 6 lines

around usb_submit_urb() plus the waiting. (The comment at [1] is actually quite funny.

[1]
https://elixir.bootlin.com/linux/v7.3.1/source/drivers/usb/core/message.c#L761

Indeed!

Quoted 15 lines
Quoted 5 lines

I saw there's a TODO within the format helpers for io memory, so maybe in a future patch I could change it to use drm_memcpy_from_wc to speed it up. Currently it couldn't run at full 1080p at 60fps on bare-metal, but on a VM it is fine due to not copying from WC memory.

Quoted 7 lines

There's also the other issue of some compositors calling _update in the render loop or something that causes visible stutter when a device's _update callback is slow.

The ideal way to solve this, with both low latency and low memory footprint is to take inspiration from gm12u320 and store the fb and update rect in the device struct, and let a worker obtain the latest one from the struct.

It's not. None of our USB-based drivers are well optimized. You can take some inspiration from them, but don't take them as they are.

Quoted 10 lines

At the end of each page flip, DRM sends out a FLIP_COMPLETE event, [2] telling the compositor that it's done with the display update. This gives the compositor an idea about the performance of the device. It can adapt to that and end out less updates. By moving out the actual work into a separate thread, you break that feedback. The compositor will see an early complete from the page flip and queue up the next frame immediately. The driver will pile up updates for the worker to send out. Hence, leave the copying and sending operations in the regular update code. If you build this with usb_submit_urb(), there's no waiting necessary.

Quoted 2 lines

In that case, assuming I keep the usb_sg_wait, doing something like wait_for_completion(previous_transfer) would be more correct.

Please do away with the worker and the USB waiting.

Quoted 16 lines
Quoted 6 lines

[2]
https://elixir.bootlin.com/linux/v7.3.1/source/include/uapi/drm/drm.h#L1395

What I have in mind for udl is this logic:

Quoted 10 lines

1. send the current frame's updates as usual using usb_submit_urb()
- transfer runs in parallel to current display update
- count the number of submitted urbs
2. in each complete handler, decrement the urb count.
3. in the next frame's atomic_begin, wait until the urb counter reaches zero
- most parallelism
- max out USB
- maintains correct transfer statistics and events
4. if the second frame takes longer than expected, the FLIP_COMPLETE event wil be late; the compositor can throttle the page-flip rate

Quoted 2 lines

For this one, wait_for_completion(previous_transfer) looks to be similar in behaviour.

That's not in your current patch AFAICT. And it makes the worker pointless.

Another issue is that your driver might want to add wait timeouts at some point, so that stuck devices can dealt with. Having the worker in the loop make it only harder.

Best regards
Thomas

Quoted 14 lines
Quoted 14 lines

I made a nicely working prototype from this.

Best regards
Thomas

Quoted 7 lines

The transfer is then sent in blocks, while overlapping the drm copy and usb transfer in parallel. I think this is a bit too much complexity for a drm/tiny driver though.

...

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)