drm/tiny: trigger5: Add MCT Trigger 5 USB display driver
Subsystems (2)
PATCH v6 1/1 drm/tiny: trigger5: Add MCT Trigger 5 USB display driver
From: Ho Jie Feng <[email protected]>
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.
---
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/[email protected]/
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
MAINTAINERS +7 -0
@@ -8453,6 +8453,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
@@ -109,6 +109,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
@@ -8,6 +8,7 @@ obj-$(CONFIG_DRM_GLANDA) += glandagpu.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 +990 -0
990 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] drm/tiny: trigger5: broken USB reset lifecycle in trigger5_reset() - [Medium] drm/tiny: trigger5…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] drm/tiny: trigger5: broken USB reset lifecycle in trigger5_reset()
- [Medium] drm/tiny: trigger5: unclipped src_rect in trigger5_plane_atomic_update()
- [Medium] drm/tiny: trigger5: bulk stream desync on mid-frame trigger5_submit_urb() error
--
commit efc535dee28f1fcc3c108a02e819d423382ef63b
Author: Ho Jie Feng <[email protected]>
drm/tiny: trigger5: Add MCT Trigger 5 USB display driver
This commit adds a DRM driver for MCT Trigger 5 USB 3 to HDMI/VGA display adapters, implementing modesetting, EDID retrieval, and bulk URB frame updates.
Quoted 5 lines
drivers/gpu/drm/tiny/trigger5.c new file +0
-0
[ ... ]
Quoted 41 lines
drivers/gpu/drm/tiny/trigger5.c new file +41
-0+static void trigger5_reset (struct trigger5_device *trigger5,int err) +{ +if (!atomic_xchg (&trigger5->needs_reset,1 )) +usb_queue_reset_device (trigger5->intf); + +drm_err (&trigger5->drm,"USB transfer failed: %d, resetting adapter\n" , + err); +} + +static void trigger5_urb_complete (struct urb *urb) +{ +struct trigger5_transfer *transfer = urb->context; +struct trigger5_device *trigger5 = transfer->trigger5; + +switch (urb->status) { +case -ENOENT : +case -ECONNRESET : +case -ESHUTDOWN : +break ; +case 0 : +if (urb->actual_length == urb->transfer_buffer_length) +break ; + fallthrough; +default : +trigger5_reset (trigger5, urb->status); +break ; + } + +complete (&transfer->done); +} + +static struct trigger5_transfer * +trigger5_get_next_urb(struct trigger5_device *trigger5) +{ + struct trigger5_transfer *transfer = + &trigger5->transfers[trigger5->next_transfer]; + + if (atomic_read(&trigger5->needs_reset)) + return ERR_PTR(-EIO); + + if (!wait_for_completion_timeout(&transfer->done,
drivers/gpu/drm/tiny/trigger5.c line 283
Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10
-0+ msecs_to_jiffies(TRIGGER5_BULK_TIMEOUT_MS))) { +trigger5_reset (trigger5, -ETIMEDOUT ); +return ERR_PTR (-ETIMEDOUT ); + } + + trigger5->next_transfer = + (trigger5->next_transfer +1 ) %TRIGGER5_NUM_URBS ; + +return transfer; +}
[Severity: High]
Does trigger5_reset() cause the active DRM device to be permanently unplugged or stuck returning -EIO after any USB transfer failure?
trigger5_driver does not define .pre_reset and .post_reset callbacks (.reset_resume is only used when resuming a suspended device), so usb_reset_device() falls back to usb_forced_unbind_intf(), which runs trigger5_usb_disconnect() -> drm_dev_unplug() and kills the active DRM device instead of resetting the adapter in place.
In addition, nothing in the driver ever clears trigger5->needs_reset once trigger5_reset() sets it to 1, so if the queued reset does not unbind the device (for example if usb_lock_device_for_reset() fails or after a reset_resume), trigger5_get_next_urb() rejects all future display updates with -EIO.
Two smaller issues in this path: trigger5_get_next_urb() only checks trigger5->needs_reset before wait_for_completion_timeout(), so if the URB being waited on completes with an error it still returns the transfer to the caller; and on a short transfer in trigger5_urb_complete(), falling through from case 0 passes urb->status (0) to trigger5_reset().
[ ... ]
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 25 lines
drivers/gpu/drm/tiny/trigger5.c new file +25
-0+ 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; + + width =drm_rect_width (¤t_rect); + height =drm_rect_height (¤t_rect); + payload_len =array3_size (width, height,3 ); + lines_per_urb =TRIGGER5_URB_BUF_SIZE / (width *3 ); + +if (drm_gem_fb_begin_cpu_access (state->fb,DMA_FROM_DEVICE ) <0 ) + goto exit; + + transfer =trigger5_get_next_urb (trigger5); +if (IS_ERR (transfer)) + goto exit_end_cpu_access; + + header = transfer->urb->transfer_buffer;
drivers/gpu/drm/tiny/trigger5.c line 450
Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10
-0+ 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);
[Severity: Medium]
Should src_rect come from the clipped state->src (via drm_rect_fp_to_int(&src_rect, &state->src)) rather than the unclipped drm_plane_state_src(state)?
In trigger5_plane_atomic_check(), drm_atomic_helper_check_plane_state() clips state->dst to the active CRTC mode and stores the visible source rectangle in state->src, while leaving state->src_x/y/w/h unclipped. Because drm_atomic_helper_damage_iter_init() also initializes its plane_src from the unclipped drm_plane_state_src(state), intersecting current_rect with drm_plane_state_src(state) here does not clip damage to the active CRTC mode when a larger framebuffer (up to 8191x8191) is panned with negative crtc_x/crtc_y, and outward rounding of fractional 16.16 src coordinates expands src_rect by an extra pixel. This computes horizontal_offset and vertical_offset relative to the off-screen origin and can send frame dimensions and payload_length exceeding the active display mode and TRIGGER5_MAX_FRAME_SIZE.
Quoted 17 lines
drivers/gpu/drm/tiny/trigger5.c new file +17
-0+ header->flags =0x1 ; + header->unknown1 =0 ; + header->unknown2 =0 ; + header->checksum =trigger5_bulk_header_checksum (header); + +if (trigger5_submit_urb (transfer,sizeof (*header))) + goto exit_end_cpu_access; + + clip = current_rect; +for (y = current_rect.y1; y < current_rect.y2; y += lines_per_urb) { + clip.y1 = y; + clip.y2 =min (y + lines_per_urb, current_rect.y2); + + transfer =trigger5_get_next_urb (trigger5); +if (IS_ERR (transfer)) +break ; +
drivers/gpu/drm/tiny/trigger5.c line 477
Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10
-0+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 ; + }
[Severity: Medium]
Does breaking out of this loop when trigger5_submit_urb() fails leave the adapter's bulk stream out of sync?
At that point the 20-byte trigger5_bulk_header URB declaring header->payload_length bytes has already been submitted, and unlike trigger5_urb_complete() or trigger5_get_next_urb(), trigger5_submit_urb() does not call trigger5_reset() on usb_submit_urb() failure. The device will keep waiting for the remaining bytes of the aborted frame and treat subsequent frame headers and pixel data as part of the old payload.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 75 lines · On Fri, 13 Nov 2026 at 00:15, <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] drm/tiny: trigger5: broken USB reset lifecycle intrigger5_reset()
- [Medium] drm/tiny: trigger5: unclippedsrc_rectintrigger5_plane_atomic_update()
- [Medium] drm/tiny: trigger5: bulk stream desync on mid-frametrigger5_submit_urb()error
--commit
efc535dee28f1fcc3c108a02e819d423382ef63b
Author: Ho Jie Feng <[email protected]>drm/tiny: trigger5: Add MCT Trigger 5 USB display driver
This commit adds a DRM driver for MCT Trigger 5 USB 3 to HDMI/VGA display adapters, implementing modesetting, EDID retrieval, and bulk URB frame updates.
Quoted 5 lines
drivers/gpu/drm/tiny/trigger5.c new file +0
-0[ ... ]
Quoted 47 lines
drivers/gpu/drm/tiny/trigger5.c new file +47
-0+static void trigger5_reset (struct trigger5_device *trigger5,int err) +{ +if (!atomic_xchg (&trigger5->needs_reset,1 )) +usb_queue_reset_device (trigger5->intf); + +drm_err (&trigger5->drm,"USB transfer failed: %d, resetting adapter\n" , + err); +} + +static void trigger5_urb_complete (struct urb *urb) +{ +struct trigger5_transfer *transfer = urb->context; +struct trigger5_device *trigger5 = transfer->trigger5; + +switch (urb->status) { +case -ENOENT : +case -ECONNRESET : +case -ESHUTDOWN : +break ; +case 0 : +if (urb->actual_length == urb->transfer_buffer_length) +break ; + fallthrough; +default : +trigger5_reset (trigger5, urb->status); +break ; + } + +complete (&transfer->done); +} + +static struct trigger5_transfer * +trigger5_get_next_urb (struct trigger5_device *trigger5) +{ +struct trigger5_transfer *transfer = + &trigger5->transfers[trigger5->next_transfer]; + +if (atomic_read (&trigger5->needs_reset)) +return ERR_PTR (-EIO ); + +if (!wait_for_completion_timeout (&transfer->done, +msecs_to_jiffies (TRIGGER5_BULK_TIMEOUT_MS ))) { +trigger5_reset (trigger5, -ETIMEDOUT ); +return ERR_PTR (-ETIMEDOUT ); + } + + trigger5->next_transfer =
Quoted 8 lines
drivers/gpu/drm/tiny/trigger5.c line 283
Quoted 4 lines
drivers/gpu/drm/tiny/trigger5.c new file +4
-0+ (trigger5->next_transfer +1 ) %TRIGGER5_NUM_URBS ; + +return transfer; +}[Severity: High]
Doestrigger5_reset()cause the active DRM device to be permanently unplugged or stuck returning-EIOafter any USB transfer failure?
Don't know. In any case, assuming the device isn't faulty, a user replug should recover it.
Quoted 5 lines
trigger5_driverdoes not define .pre_reset and .post_reset callbacks (.reset_resume is only used when resuming a suspended device), sousb_reset_device()falls back tousb_forced_unbind_intf(), which runstrigger5_usb_disconnect()->drm_dev_unplug()and kills the active DRM device instead of resetting the adapter in place.
This is intentionally kept simple for the first revision to be upstreamed. A reset is simple to implement and correctly recovers the device in my tests.
Quoted 5 lines
In addition, nothing in the driver ever clears
trigger5->needs_resetoncetrigger5_reset()sets it to 1, so if the queued reset does not unbind the device (for example ifusb_lock_device_for_reset()fails or after areset_resume),trigger5_get_next_urb()rejects all future display updates with-EIO.
The only reason it fails should be that the device is unplugged, so the point about reset failing is moot here.
Quoted 5 lines
Two smaller issues in this path:
trigger5_get_next_urb()only checkstrigger5->needs_resetbeforewait_for_completion_timeout(), so if the URB being waited on completes with an error it still returns the transfer to the caller; and on a short transfer intrigger5_urb_complete(), falling through from case 0 passesurb->status(0) totrigger5_reset().
This passes at most one more URB to a failing device?
trigger5_reset is only put in there in case the dongle fails. However, I have never observed it to fail in that way, apart from intentionally introducing some fault condition such as putting a keepalive in the middle of the frame. Since in this v6, keepalive is disarmed and never sent, it will not happen.
This reset seems to be the most reliable way to recover from something wrong from my experiments. I do not know enough about the behaviour when hardware is faulty or some weird condition appears enough to say that it works in *all* conditions.
Quoted 49 lines
[ ... ]
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 25 lines
drivers/gpu/drm/tiny/trigger5.c new file +25
-0+ 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; + + width =drm_rect_width (¤t_rect); + height =drm_rect_height (¤t_rect); + payload_len =array3_size (width, height,3 ); + lines_per_urb =TRIGGER5_URB_BUF_SIZE / (width *3 ); + +if (drm_gem_fb_begin_cpu_access (state->fb,DMA_FROM_DEVICE ) <0 ) + goto exit; + + transfer =trigger5_get_next_urb (trigger5); +if (IS_ERR (transfer)) + goto exit_end_cpu_access; + + header = transfer->urb->transfer_buffer;drivers/gpu/drm/tiny/trigger5.c line 450
Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10
-0+ 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);[Severity: Medium]
Shouldsrc_rectcome from the clippedstate->src(viadrm_rect_fp_to_int(&src_rect, &state->src)) rather than the unclippeddrm_plane_state_src(state)?
Quoted 12 lines
In
trigger5_plane_atomic_check(),drm_atomic_helper_check_plane_state()clipsstate->dstto the active CRTC mode and stores the visible source rectangle instate->src, while leaving state->src_x/y/w/h unclipped. Becausedrm_atomic_helper_damage_iter_init()also initializes itsplane_srcfrom the unclippeddrm_plane_state_src(state), intersectingcurrent_rectwithdrm_plane_state_src(state)here does not clip damage to the active CRTC mode when a larger framebuffer (up to 8191x8191) is panned with negative crtc_x/crtc_y, and outward rounding of fractional 16.16 src coordinates expandssrc_rectby an extra pixel. This computeshorizontal_offsetandvertical_offsetrelative to the off-screen origin and can send frame dimensions andpayload_lengthexceeding the active display mode andTRIGGER5_MAX_FRAME_SIZE.
Real bug, but unlikely there are weird userspace DRM users weird enough to hit this bug.
Quoted 32 lines
Quoted 17 lines
drivers/gpu/drm/tiny/trigger5.c new file +17
-0+ header->flags =0x1 ; + header->unknown1 =0 ; + header->unknown2 =0 ; + header->checksum =trigger5_bulk_header_checksum (header); + +if (trigger5_submit_urb (transfer,sizeof (*header))) + goto exit_end_cpu_access; + + clip = current_rect; +for (y = current_rect.y1; y < current_rect.y2; y += lines_per_urb) { + clip.y1 = y; + clip.y2 =min (y + lines_per_urb, current_rect.y2); + + transfer =trigger5_get_next_urb (trigger5); +if (IS_ERR (transfer)) +break ; +drivers/gpu/drm/tiny/trigger5.c line 477
Quoted 10 lines
drivers/gpu/drm/tiny/trigger5.c new file +10
-0+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 ; + }[Severity: Medium]
Does breaking out of this loop whentrigger5_submit_urb()fails leave the adapter's bulk stream out of sync?
Quoted 6 lines
At that point the 20-byte
trigger5_bulk_headerURB declaringheader->payload_lengthbytes has already been submitted, and unliketrigger5_urb_complete()ortrigger5_get_next_urb(),trigger5_submit_urb()does not calltrigger5_reset()onusb_submit_urb()failure. The device will keep waiting for the remaining bytes of the aborted frame and treat subsequent frame headers and pixel data as part of the old payload.
Known bug, however, on submit urb failure it should queue a reset. I am not sure what is the best way to recover the device beyond queuing a reset, since further URB submissions to pad the frame to its entirety might fail too.
Quoted 2 lines
--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1