Re: [PATCH v6] drm/tiny: trigger5: Add MCT Trigger 5 USB display driver
From: Jie Feng
Date: Fri Nov 27 2026 - 12:58:00 EST
Hi,
On Fri, 27 Nov 2026 at 17:49, Thomas Zimmermann <tzimmermann@xxxxxxx> wrote:
>
> Hi,
>
> I think the driver looks much better now. I left a few notes below that
> you might want to address.
>
>
> Am 12.11.26 um 16:45 schrieb Jie Feng:
> > From: Ho Jie Feng <hjf3108@xxxxxxxxx>
> >
> > 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.
> >
> > Signed-off-by: Ho Jie Feng <hjf3108@xxxxxxxxx>
> > ---
> > Patchwork:
> > https://patchwork.freedesktop.org/series/176855/
> >
> > Changes in v6:
> > - Replace the USB transfer worker and vmalloc frame buffers
> > with eight URBs that send the frame in chunks
> > - Remove keepalive work, it is not needed if it is never sent,
> > and disarm any keepalive it already has
> > - Use container_of_const(), drm_dbg(), and drm_err_once()
> > - Group plane code and function tables before CRTC code and tables.
> > - Use the standard NULL-CRTC plane-check pattern and remove redundant
> > mode checks, the driver-specific no-EDID fallback, and the INF comment.
> >
> > Link to v5:
> > https://lore.kernel.org/dri-devel/20261026112843.69795-1-hjf3108@xxxxxxxxx/
> > 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 | 990 ++++++++++++++++++++++++++++++++
> > 4 files changed, 1012 insertions(+)
> > create mode 100644 drivers/gpu/drm/tiny/trigger5.c
> >
...
> > +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 *transfer;
> > + struct trigger5_bulk_header *header;
> > + struct drm_rect current_rect, src_rect, clip;
> > + struct iosys_map data_map;
> > + size_t payload_len;
> > + int width, height, lines_per_urb;
> > + int idx, y;
> > +
> > + if (!drm_atomic_helper_damage_merged(old_state, state, ¤t_rect))
> > + return;
>
> Never use _damage_merged in your display update code. (^1) Userspace
> supplies damage rectangles for ares that have changed in the current
> frame. Merging them creates a bounding box around all of them. IOW you
> add areas that have not changed. For example, have a blinking cursor
> near the lower left corner and move the mouse around the window's
> menubar, and your driver easily transfers half of the screen or more for
> nothing.
Talking about cursor, this hardware supports a cursor plane and a form
of lossless image compression, I might add those in a follow up patch.
> Therefore always iterate over the damage rectangles and handle them one
> by one. Don't be concerned with overlapping damage regions. I did some
> tests with Gnome and could not find any operlaps. It appears that Gnome
> already submits an optimized list damage regions. Overlapping can also
> be detected algorithmically and filtered out by our damage handlers.
> But a merged bounding box cannot be optimized.
>
> ^1: White lie, as we use _damage_merged for ast's cursor. But this code
> really is different.
The hardware seems to only accept 3 damage rects per vblank according
to my tests. Since I do not know in between which of the 3 damage
rects the frame is being output, I think we should just use
_damage_merged to avoid any sort of screen tearing. In this case the
compositor might get wrong feedback if the damage rects are small, so
should I pad some extra rects so that it gets correct feedback of the
current speed of vblank?
This kind of behaviour looks to be quite common, the hardware for
ms91xx only accepts 1 damage rect per vblank, so _damage_merged is
mandatory there.
> > +
> > + if (!drm_dev_enter(plane->dev, &idx))
> > + return;
> > +
> > + 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);
> > +
> > + /* Clip merged damage to the new resolution. */
> > + if (!drm_rect_intersect(¤t_rect, &src_rect))
> > + goto exit;
> > +
...
> > + iosys_map_set_vaddr(&data_map, transfer->urb->transfer_buffer);
> > + drm_fb_xrgb8888_to_rgb888(&data_map, NULL,
> > + &shadow_plane_state->data[0],
> > + state->fb, &clip,
> > + &shadow_plane_state->fmtcnv_state);
> > +
> > + if (trigger5_submit_urb(transfer,
> > + width * 3 * drm_rect_height(&clip)))
> > + break;
> > + }
>
> Good to see that the worker has been removed.
>
> > +
> > +exit_end_cpu_access:
> > + drm_gem_fb_end_cpu_access(state->fb, DMA_FROM_DEVICE);
> > +exit:
> > + drm_dev_exit(idx);
> > +}
> > +
> > +static const struct drm_plane_helper_funcs trigger5_plane_helper_funcs = {
> > + DRM_GEM_SHADOW_PLANE_HELPER_FUNCS,
> > + .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,
> > +};
> > +
> > +static const u32 trigger5_plane_formats[] = {
> > + DRM_FORMAT_XRGB8888,
>
> I suggest to support RGB888 as well. It's not common nowadays. But it's
> the native format and does run slightly faster is used. Can be a
> follow-up patch.
>
> > +};
> > +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)
> > + return MODE_H_ILLEGAL;
> > +
> > + if (mode->vsync_end <= mode->vsync_start ||
> > + mode->vtotal <= mode->vsync_end)
> > + return MODE_V_ILLEGAL;
>
> You don't nee that basic stuff. See [2]. Just test for hardware specifics.
>
> [2]
> https://elixir.bootlin.com/linux/v7.3.4/source/drivers/gpu/drm/drm_modes.c#L1652
Nice that this is already handled. The checks are actually for the
fields in the struct with /* minus one */ comments.
> > +
> > + if (trigger5_mode_buf_len(mode) > TRIGGER5_MAX_FRAME_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;
> > +}
> > +
...
> > +
> > + ret = trigger5_alloc_urbs(trigger5);
> > + if (ret)
> > + goto err_free_urbs;
>
> I still thing that URBs should not be pre-allocated and you should go
> for something like i try with udl. But that's fine tuning for later.
> Pre-alloc is fine for now.
I can send in a follow up patch once the udl design is finalised,
along with RGB888.
> Best regards
> Thomas
>
Best regards,
Jie Feng