drm: Add Fresco Logic FL2000 USB display driver
Subsystems (2)
v2 cover drm: Add Fresco Logic FL2000 USB display driver
Hi,
This series adds a DRM driver for USB display adapters built around the Fresco Logic FL2000DX (USB ID 1d5c:2000). These are sold under many brands as cheap USB 3.0 to VGA/HDMI dongles; the HDMI variants pair the FL2000 with an ITE IT66121 HDMI transmitter on the FL2000's I2C bus. Today these adapters only work on Linux with out-of-tree drivers.
The driver started as Artem Mygaiev's out-of-tree fl2000_drm driver, itself partly based on Fresco Logic's reference driver; their copyright lines are kept. I ported it to current kernels, fixed the problems found on real hardware (EDID, crashes on disconnect, frames that were never terminated, imported buffers read from the wrong VRAM), added the analog VGA output and cleaned it up for submission.
I intend to maintain this driver for the long term: patch 1 adds a MAINTAINERS entry with me as maintainer, I have the hardware to test on, and I will keep following review and bug reports on dri-devel.
The series builds the driver up in four steps, each of which compiles on its own:
1. USB driver, FL2000 register access (regmap) and I2C adapter
2. IT66121 HDMI transmitter bridge
3. frame streaming over bulk URBs
4. the KMS pipeline, which makes the display usable, including the analog VGA output of adapters that have both connectors
v1 was an RFC. This version answers its review and is meant to be applied, but some design points are still open and I would like your view on them; the first one could change the series:
1. IT66121 support. The series carries its own small IT66121 bridge (fl2000_it66121.c) instead of reusing drivers/gpu/drm/bridge/ ite-it66121.c, because I could not find a way to use the in-tree driver on a PC: it depends on OF (x86 distribution kernels have no CONFIG_OF), reads bus-width and its next bridge through of_graph, requires a reset GPIO the FL2000 boards do not have, and DRM has no bridge lookup without OF. It also reads the EDID through its DDC engine, which on these boards is not connected to the monitor (the EDID is read with the FL2000 I2C engine instead).
Reusing it would take converting ite-it66121 to the fwnode API with an optional reset GPIO, a fwnode-based bridge lookup in drm_bridge.c, and a small bridge of this driver providing the EDID. Is that the direction you would like, or is a private IT66121 bridge acceptable for a USB device like this one?
2. Hotplug. The bridge attaches with DRM_BRIDGE_ATTACH_NO_CONNECTOR and the HDMI connector comes from drm_bridge_connector. The bridge reports DETECT and EDID only: the IT66121 interrupt reaches the host through the FL2000 interrupt endpoint, which makes the driver send a hotplug event for the device, so there is no DRM_BRIDGE_OP_HPD and the connector is also polled. Would reporting HPD with drm_bridge_hpd_notify() from that path be preferred?
3. Pixel conversion. The stream converts with its own small line converters instead of drm_fb_xrgb8888_to_*(). The framebuffer is usually imported from the primary GPU and sits in write-combined VRAM; the format helpers read such I/O memory with memcpy_fromio(), which takes ~88 ms per 1080p frame, while drm_memcpy_from_wc() into a cached line buffer takes ~8 ms. The converters also apply the FL2000's 32-bit word swap and only touch the damaged rectangle of a shadow frame. Would a helper that reads its source through drm_memcpy_from_wc() be welcome, so this could go away?
4. VGA detection. The chip has a single monitor sense input, which on the adapter I have follows whichever monitor is plugged in, HDMI or VGA. The VGA connector therefore reports a monitor when the chip senses one and the IT66121 hot plug line is low, which means a monitor on VGA is not reported while one is on HDMI (clone mode needs video=VGA-1:e). Is this an acceptable way to do it, and is there a better signal I should look for in the chip?
The rest of the pipeline follows the current helpers: regular atomic plane/CRTC/encoder objects with managed initialisation, GEM SHMEM with shadow-plane access and fbdev emulation through drm_client_setup(). There is no cursor plane and no vblank support. On the USB side the driver matches interface 0 and claims the other two, everything hangs off that binding, and resets and system sleep do not unbind it.
Other known limitations: XRGB8888 goes out as RGB888, and modes the USB link can only carry in RGB565 (2560x1080 on USB 3.0, 640x480 on USB 2.0, as there is no compression) need a framebuffer in that format. RGB565 was seen working at 1280x720 on HDMI and 1024x768 on VGA, but those larger modes have not been tried; and adapters with a VGA connector only, without an IT66121, are not supported: the analog output is only added next to the HDMI one.
Tested on x86_64 (amdgpu laptop, GNOME Wayland) with a UGREEN USB 3.0 adapter with HDMI and VGA connectors: a 1920x1080 monitor on HDMI, and an old 1366x768 monitor without a usable EDID on VGA. EDID, mode setting in XRGB8888 and RGB565, plugging and unplugging monitors, system sleep, USB resets and the desktop work, with one frame per refresh on the link. With Mutter 51.1, which renders in XRGB2101010 when it can, the missing 10-bit formats make it copy the frames on the GPU instead, and that copy path leaks a framebuffer per frame (Mutter issue #5101; the fix is on Mutter's stable branch for its next release, 51.2).
The unplug, unbind, module removal and USB reset paths were also run under KASAN and lockdep against an emulated FL2000 on raw_gadget and dummy_hcd. Every patch builds without warnings with W=1 on top of drm-misc-next, sparse is clean, and the series passes checkpatch --strict.
Tool use, as described in Documentation/process/generated-content.rst: I used an AI coding assistant (Claude Code with Anthropic Claude models) extensively while preparing this series. It helped port the driver to the current APIs, clean it up to kernel style, write the shadow-frame streaming, track down and fix the hangs on unplug,
and draft the commit messages and this letter. I reviewed the result and tested it on the hardware described above; the Signed-off-by lines are mine. The series was generated and checked (per-patch builds, checkpatch) by scripts in the out-of-tree repository this driver is developed in.
---
Changes in v2:
- Sent as a regular series: v1 was an RFC.
- From the review of Thomas Zimmermann:
- No cursor plane, and no blending in the driver.
- No vblank timer, and so no vblank support.
- The EDID is not kept: it is read from the monitor on every probe.
- The formats are XRGB8888, converted to RGB888, and RGB565, sent as it is. The 10-bit ones went: they are not native (the device takes RGB888 or RGB565), and they were only converted down. What the USB link cannot carry at a mode fails in the atomic check of the plane; the CRTC no longer picks a format. (This makes Mutter 51.1 copy its frames through a path that leaks, as said above.)
- The limits are what the timing registers hold, 12 bits (4095).
- mode_fixup adjusts the clock, mode_valid returns MODE_* codes, the helpers are used as drop-ins, and the plane helper goes first in the plane check.
- The interrupt endpoint is only polled once the device is registered, and after system sleep once the state is restored, so no state about that in the driver. The chips themselves are still set up before restoring the state, as restoring it writes to them.
- Forcing the monitor sense went to the HDMI encoder, and the CRTC only enables the interrupts about frames.
- struct fl2000_device, sorted driver flags, drm_dbg(), fewer comments.
- Convert each damage rectangle of the plane instead of their bounding box. A compositor that copies into a rotation of buffers only keeps the damage current, and the pixels between the rectangles could bring back older content.
- Bind through interface 0 and claim the other two with usb_driver_claim_interface(), with everything hanging off that binding, instead of keeping shared state on the usb_device: unloading the module or unbinding the driver left it all behind, pointing into freed memory. This answers question 3 of v1, which is gone. There is no component framework any more, the bridge is attached directly, and the DRM device hangs off the interface.
- USB resets no longer unbind the driver (.pre_reset/.post_reset).
- Keep the stream as long as the DRM device, and guard everything that reaches a register with drm_dev_enter() or drm_bridge_enter().
- Really probe for the IT66121: the detection had its return values inverted and always "found" the chip at the first address, without any transfer.
- Reject modes larger than the limits in the CRTC check. The core only applies max_width/max_height to probed modes, and a mode with an off- screen primary plane could wrap the 32-bit buffer size.
- Do not write the old shadow frame with a new geometry after a failed mode set.
- Remove the EDID read through the IT66121 DDC engine, which never completes on these boards and cannot work behind an I2C engine that reads whole dwords (each read of the DDC status pops the DDC FIFO). The DDC bus release stays.
- Honour the plane's source rectangle: a framebuffer larger than the mode froze the output.
- No phantom VGA monitor from the forced monitor sense when HDMI is unplugged.
- Acknowledge the IT66121 from the FL2000 interrupt and unmask its hot plug, instead of polling it over USB ten times a second. Enable the monitor interrupts at probe, not at the first mode set.
- Keep FL2000 resets and I2C control register writes out of running I2C operations.
- Smaller fixes: URB submission retries bounded (-EAGAIN looped forever), no pointer in urb->transfer_buffer, flush_kernel_vmap_range() before sending a frame, I2C message validation through the adapter quirks, a lost status event when clearing the LBUF flags, interrupt URB interval and endpoint, a NULL dereference on allocation failure, suspend error handling.
Most of these come from the Sashiko review of v1.
- Link to v1: https://patch.msgid.link/[email protected]
---
Angel Gabriel Crispin Valdivia (4):
drm/fl2000: Add USB driver with register and I2C access drm/fl2000: Add ITE IT66121 HDMI transmitter support drm/fl2000: Add frame streaming
drm/fl2000: Add KMS display pipeline
MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/fl2000/Kconfig | 19 + drivers/gpu/drm/fl2000/Makefile | 13 + drivers/gpu/drm/fl2000/fl2000.h | 159 +++++ drivers/gpu/drm/fl2000/fl2000_drm.c | 902 +++++++++++++++++++++++++++ drivers/gpu/drm/fl2000/fl2000_drv.c | 222 +++++++ drivers/gpu/drm/fl2000/fl2000_i2c.c | 179 ++++++ drivers/gpu/drm/fl2000/fl2000_interrupt.c | 226 +++++++ drivers/gpu/drm/fl2000/fl2000_it66121.c | 799 ++++++++++++++++++++++++ drivers/gpu/drm/fl2000/fl2000_it66121.h | 18 + drivers/gpu/drm/fl2000/fl2000_it66121_regs.h | 284 +++++++++ drivers/gpu/drm/fl2000/fl2000_registers.c | 315 ++++++++++ drivers/gpu/drm/fl2000/fl2000_registers.h | 276 ++++++++ drivers/gpu/drm/fl2000/fl2000_streaming.c | 807 ++++++++++++++++++++++++ drivers/gpu/drm/fl2000/fl2000_vga.c | 223 +++++++ 17 files changed, 4451 insertions(+)
---
base-commit: 41ecf852c07391687beb129e12a231760b5d783f
change-id: 20261105-fl2000-upstream-3fc2e1f00d24
Best regards,
Signature · 1 line
Angel Gabriel Crispin Valdivia <[email protected]>
PATCH v2 1/4 drm/fl2000: Add USB driver with register and I2C access
The Fresco Logic FL2000DX is a USB 3.0 display controller used in inexpensive USB to VGA and USB to HDMI adapters (USB ID 1d5c:2000). The FL2000 itself outputs parallel RGB/VGA; HDMI adapters pair it with an ITE IT66121 HDMI transmitter that sits on the FL2000's I2C bus.
This first patch adds the USB side of the driver: it matches interface 0 and claims the other two FL2000 interfaces from its probe, selects the altsetting that has the bulk endpoint, describes the FL2000 registers, provides a regmap on top of the vendor control transfers that access them, and registers an I2C adapter backed by the FL2000 I2C engine. The engine only transfers aligned 32-bit words, so byte accesses are done as read-modify-write of the containing word and the adapter advertises the matching quirks.
Everything hangs off the binding of interface 0 and goes away with it; unbinding any of the interfaces takes the others along.
The driver is based on the out-of-tree fl2000_drm driver by Artem Mygaiev, which carries code from the Fresco Logic reference driver.
--- MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/fl2000/Kconfig | 19 ++ drivers/gpu/drm/fl2000/Makefile | 8 + drivers/gpu/drm/fl2000/fl2000.h | 89 +++++++++ drivers/gpu/drm/fl2000/fl2000_drv.c | 163 ++++++++++++++++ drivers/gpu/drm/fl2000/fl2000_i2c.c | 179 +++++++++++++++++ drivers/gpu/drm/fl2000/fl2000_registers.c | 315 ++++++++++++++++++++++++++++++ drivers/gpu/drm/fl2000/fl2000_registers.h | 276 ++++++++++++++++++++++++++ 10 files changed, 1058 insertions(+)
MAINTAINERS +7 -0
@@ -8324,6 +8324,13 @@ F: include/linux/aperture.h F: include/linux/sysfb.h F: include/video/nomodeset.h +DRM DRIVER FOR FRESCO LOGIC FL2000 USB DISPLAY ADAPTERS +M: Angel Gabriel Crispin Valdivia <[email protected]> +L: [email protected] +S: Maintained +T: git https://gitlab.freedesktop.org/drm/misc/kernel.git +F: drivers/gpu/drm/fl2000/ + DRM DRIVER FOR GENERIC EDP PANELS R: Douglas Anderson <[email protected]> F: Documentation/devicetree/bindings/display/panel/panel-edp.yaml
drivers/gpu/drm/Kconfig +1 -0
@@ -313,6 +313,7 @@ source "drivers/gpu/drm/atmel-hlcdc/Kconfig" source "drivers/gpu/drm/bridge/Kconfig" source "drivers/gpu/drm/etnaviv/Kconfig" source "drivers/gpu/drm/exynos/Kconfig" +source "drivers/gpu/drm/fl2000/Kconfig" source "drivers/gpu/drm/fsl-dcu/Kconfig" source "drivers/gpu/drm/gma500/Kconfig" source "drivers/gpu/drm/gud/Kconfig"
drivers/gpu/drm/Makefile +1 -0
@@ -190,6 +190,7 @@ obj-$(CONFIG_DRM_NOUVEAU) +=nouveau/ obj-$(CONFIG_DRM_EXYNOS) +=exynos/ obj-$(CONFIG_DRM_ROCKCHIP) +=rockchip/ obj-$(CONFIG_DRM_GMA500) += gma500/ +obj-$(CONFIG_DRM_FL2000) += fl2000/ obj-$(CONFIG_DRM_UDL) += udl/ obj-$(CONFIG_DRM_AST) += ast/ obj-$(CONFIG_DRM_ARMADA) += armada/
drivers/gpu/drm/fl2000/Kconfig new file +19 -0
@@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0-only +config DRM_FL2000 + tristate "Fresco Logic FL2000 USB display adapters" + depends on DRM && USB && MMU + depends on USB_ARCH_HAS_HCD + select DRM_BRIDGE_CONNECTOR + select DRM_CLIENT_SELECTION + select DRM_DISPLAY_HELPER + select DRM_GEM_SHMEM_HELPER + select DRM_KMS_HELPER + select I2C + select REGMAP + select REGMAP_I2C + help + This is a KMS driver for USB display adapters based on the + Fresco Logic FL2000DX USB 3.0 to VGA controller, paired with an + ITE IT66121 HDMI transmitter (USB ID 1d5c:2000). + + If M is selected the module will be called fl2000.
drivers/gpu/drm/fl2000/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only + +fl2000-y := \ + fl2000_drv.o \ + fl2000_i2c.o \ + fl2000_registers.o + +obj-$(CONFIG_DRM_FL2000) += fl2000.o
drivers/gpu/drm/fl2000/fl2000.h new file +89 -0
89 lines not on this page · raw message
drivers/gpu/drm/fl2000/fl2000_drv.c new file +163 -0
163 lines not on this page · raw message
drivers/gpu/drm/fl2000/fl2000_i2c.c new file +179 -0
179 lines not on this page · raw message
drivers/gpu/drm/fl2000/fl2000_registers.c new file +315 -0
315 lines not on this page · raw message
drivers/gpu/drm/fl2000/fl2000_registers.h new file +276 -0
276 lines not on this page · raw message
Signature · 1 line
2.56.0
PATCH v2 2/4 drm/fl2000: Add ITE IT66121 HDMI transmitter support
In reply to Angel Gabriel Crispin ValdiviaProbe the IT66121 on the FL2000 I2C bus and expose it as a DRM bridge. It attaches with DRM_BRIDGE_ATTACH_NO_CONNECTOR and reports the hot plug line and the EDID (DRM_BRIDGE_OP_DETECT and DRM_BRIDGE_OP_EDID), so the connector is the display driver's. The transmitter (input bus, AFE, AVI infoframe, HDMI/DVI mode) is programmed in atomic_enable, where the connector that tells HDMI from DVI is known. The EDID is kept while the monitor stays, since reading it over USB takes about a second.
The EDID is read at address 0x50 with the FL2000 I2C engine. On the tested adapter, as on the Fresco Logic reference design, the monitor's DDC lines are wired to the FL2000 I2C bus, and the IT66121 DDC engine never completes. It could not work behind this I2C engine anyway, which transfers aligned dwords: every read of the DDC status register also pops a byte from the DDC FIFO, which is in the same dword. The HDCP engine holds that bus after a chip reset, so the driver releases it once before reading.
The bridge is created and destroyed with the binding of the USB device. It is guarded with drm_bridge_enter(), since a DRM device that userspace keeps open after an unplug still has it in its encoder's chain.
--- drivers/gpu/drm/fl2000/Makefile | 1 + drivers/gpu/drm/fl2000/fl2000_drv.c | 19 +- drivers/gpu/drm/fl2000/fl2000_it66121.c | 799 +++++++++++++++++++++++++++ drivers/gpu/drm/fl2000/fl2000_it66121.h | 18 + drivers/gpu/drm/fl2000/fl2000_it66121_regs.h | 284 ++++++++++ 5 files changed, 1120 insertions(+), 1 deletion(-)
drivers/gpu/drm/fl2000/Makefile +1 -0
@@ -3,6 +3,7 @@ fl2000-y := \ fl2000_drv.o \ fl2000_i2c.o \ + fl2000_it66121.o \ fl2000_registers.o obj-$(CONFIG_DRM_FL2000) += fl2000.o
drivers/gpu/drm/fl2000/fl2000_drv.c +18 -1
@@ -5,6 +5,7 @@*/ #include "fl2000.h" +#include "fl2000_it66121.h" #define USB_VENDOR_FRESCO_LOGIC 0x1D5C#define USB_PRODUCT_FL2000 0x2000
@@ -33,6 +34,7 @@ MODULE_DEVICE_TABLE(usb, fl2000_id_table);struct fl2000_devs {struct regmap *regmap;struct i2c_adapter *adapter; +struct drm_bridge *bridge; };/* Interface 0 is what the driver is probing: claim the others */
@@ -102,13 +104,26 @@ static int fl2000_probe(struct usb_interface *interface, const struct usb_devicereturn PTR_ERR (devs->adapter); } +/* The IT66121 is looked for with the I2C engine, ready as for reading the EDID */ +fl2000_reset (devs->regmap); +fl2000_usb_magic (devs->regmap); + + devs->bridge =it66121_create (devs->adapter); +if (IS_ERR (devs->bridge)) +return PTR_ERR (devs->bridge); + ret =fl2000_claim_interfaces (usb_dev, devs);if (ret) -return ret; + goto err_destroy_bridge;usb_set_intfdata (interface, devs);return 0 ; + +err_destroy_bridge: +it66121_destroy (devs->bridge); + +return ret; }static void fl2000_disconnect (struct usb_interface *interface)
@@ -123,6 +138,8 @@ static void fl2000_disconnect(struct usb_interface *interface)for (int i =0 ; i <FL2000_USBIF_NUM ; i++)usb_set_intfdata (usb_ifnum_to_if (usb_dev, i),NULL ); +it66121_destroy (devs->bridge); +/* Last, as devs goes with interface 0, which may be one of these */ fl2000_release_interfaces (usb_dev, interface); }
drivers/gpu/drm/fl2000/fl2000_it66121.c new file +799 -0
799 lines not on this page · raw message
drivers/gpu/drm/fl2000/fl2000_it66121.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* (C) Copyright 2019, Artem Mygaiev +*/ + +#ifndef FL2000_IT66121_H +#define FL2000_IT66121_H + +struct drm_bridge ; +struct i2c_adapter ; + +struct drm_bridge *it66121_create (struct i2c_adapter *adapter); +void it66121_destroy (struct drm_bridge *bridge); +int it66121_hpd_connected (struct drm_bridge *bridge); +int it66121_ack_interrupts (struct drm_bridge *bridge); +void it66121_resume (struct drm_bridge *bridge); + +#endif /* FL2000_IT66121_H */
drivers/gpu/drm/fl2000/fl2000_it66121_regs.h new file +284 -0
284 lines not on this page · raw message
Signature · 1 line
2.56.0
PATCH v2 3/4 drm/fl2000: Add frame streaming
In reply to Angel Gabriel Crispin ValdiviaFrames are sent as one bulk transfer per frame on endpoint 1 OUT, of altsetting 1 of the AV control interface. Three URBs are kept in flight from a pool of six scatter-gather buffers, and when no new frame is ready the current one is sent again, so the FL2000 always has data to scan out.
The current frame is kept in a shadow buffer in the device's pixel format. Only the damaged rectangle of the part of the framebuffer that the plane selects is converted, into the shadow, and each outgoing buffer is brought up to date from it just before it is submitted, by replaying the damage rectangles it missed or with a full copy when it is too far behind. The send path never waits for a conversion in progress:
it resends the newest complete frame instead.
The framebuffer is often a buffer imported from the primary GPU and lives in its VRAM, mapped write-combined. It is read a scanline at a time with drm_memcpy_from_wc(), which uses streaming loads: a 1080p frame then converts in about 8 ms instead of the ~88 ms of memcpy_fromio(). The FL2000 wants the two 32-bit halves of every 64-bit word swapped, which the converters do as they write. Copies run with the buffer taken off the lists, so list_lock, which is also taken from URB completion, is never held across multi-megabyte work.
The stream is wired up to KMS in the next patch.
--- drivers/gpu/drm/fl2000/Makefile | 3 +- drivers/gpu/drm/fl2000/fl2000.h | 37 ++ drivers/gpu/drm/fl2000/fl2000_streaming.c | 807 ++++++++++++++++++++++++++++++ 3 files changed, 846 insertions(+), 1 deletion(-)
drivers/gpu/drm/fl2000/Makefile +2 -1
@@ -4,6 +4,7 @@ fl2000-y := \ fl2000_drv.o \ fl2000_i2c.o \ fl2000_it66121.o \ - fl2000_registers.o + fl2000_registers.o \ + fl2000_streaming.o obj-$(CONFIG_DRM_FL2000) += fl2000.o
drivers/gpu/drm/fl2000/fl2000.h +37 -0
@@ -41,6 +41,24 @@ enum fl2000_interface { FL2000_USBIF_NUM, }; +/* Called from URB completion handlers, i.e. in atomic context */ +static inline int fl2000_urb_status (struct usb_device *usb_dev,int status) +{ +switch (status) { +case 0 : +case -ECONNRESET : +case -ENOENT : +case -ESHUTDOWN : +/* Success, or the URB was unlinked / the device is going away */ +break ; +default : +dev_err_ratelimited (&usb_dev->dev,"Nonzero urb status, %d\n" , status); +break ; + } + +return status; +} +struct fl2000_timings {u32 hactive;u32 htotal;
@@ -63,6 +81,25 @@ struct fl2000_pll {#define I2C_RDWR_INTERVAL 200#define I2C_RDWR_TIMEOUT (256 * 1000) +/* Streaming transfer task */ +struct fl2000_stream ; +struct fl2000_stream *fl2000_stream_create (struct usb_device *usb_dev); +void fl2000_stream_destroy (struct fl2000_stream *stream); + +/* Streaming interface */ +int fl2000_stream_mode_set (struct fl2000_stream *stream,unsigned int width, +unsigned int height,u32 bytes_pix); +struct drm_rect ; +struct iosys_map ; +void fl2000_stream_compress (struct fl2000_stream *stream,const struct iosys_map *src_map, +bool imported,unsigned int pitch, +const struct drm_rect *src,const struct drm_rect *clip); +void fl2000_stream_note_render (struct fl2000_stream *stream,unsigned int conv_us, +unsigned int damage_px); + +int fl2000_stream_enable (struct fl2000_stream *stream); +void fl2000_stream_disable (struct fl2000_stream *stream); +/* I2C adapter interface creation */ struct i2c_adapter *fl2000_i2c_init (struct usb_interface *interface,struct regmap *regmap);int fl2000_ddc_read_block (struct i2c_adapter *adapter,u8 *buf,unsigned int block,size_t len);
drivers/gpu/drm/fl2000/fl2000_streaming.c new file +807 -0
807 lines not on this page · raw message
Signature · 1 line
2.56.0
PATCH v2 4/4 drm/fl2000: Add KMS display pipeline
In reply to Angel Gabriel Crispin ValdiviaRegister the DRM device from the probe, and connect the pieces:
- a primary plane, a CRTC and an encoder, with GEM SHMEM framebuffers accessed through the shadow-plane helpers. The device takes RGB888 or
RGB565: XRGB8888 is converted to the former and RGB565 goes as it is, and the plane rejects what the USB link cannot carry at the mode. The framebuffer is only read by the CPU, so it does not need to be physically contiguous. The primary plane converts each damaged rectangle into the stream's shadow frame
- mode validation and PLL search in mode_valid and mode_fixup (which adjusts the clock), and FL2000 programming in mode_set_nofb, before the bridge is enabled. The PLL cannot make most pixel clocks exactly:
digital sinks are only offered modes it hits within 500 ppm, while the VGA output accepts 5000 ppm, since an analog monitor does not notice that but does notice a changed htotal
- the HDMI connector from drm_bridge_connector_init() on the encoder the IT66121 bridge is attached to. It is polled, as the bridge has no hot plug interrupt of its own
- the analog VGA output of the chip, which adapters with a VGA connector expose next to the HDMI one: a DAC encoder and a VGA connector on the same CRTC (the two encoders are clones of each other). The chip has one monitor sense input, which follows whichever monitor is plugged in, so the VGA connector reports a monitor when the chip senses one and the IT66121 does not; the EDID is read with the FL2000 I2C engine, and without one the standard timings are offered
- fbdev emulation
- the FL2000 interrupt endpoint, which reports monitor and IT66121 events and triggers a hotplug event
- system sleep and USB resets, which stop the display and start it again without unbinding: the compositor does not see an unplug. The chips may have lost power, so they are set up from scratch
Tested on x86_64 with a UGREEN USB 3.0 adapter with HDMI and VGA connectors (FL2000DX + IT66121FN): a 1920x1080 monitor on HDMI and an old 1366x768 monitor without a usable EDID on VGA. EDID, mode setting in XRGB8888 and RGB565, plugging and unplugging monitors, system sleep, USB resets and a GNOME Wayland desktop work, with one frame per refresh on the link. Adapters with a VGA connector only (no IT66121) are not supported.
--- drivers/gpu/drm/fl2000/Makefile | 5 +- drivers/gpu/drm/fl2000/fl2000.h | 33 ++ drivers/gpu/drm/fl2000/fl2000_drm.c | 902 ++++++++++++++++++++++++++++++ drivers/gpu/drm/fl2000/fl2000_drv.c | 56 +- drivers/gpu/drm/fl2000/fl2000_interrupt.c | 226 ++++++++ drivers/gpu/drm/fl2000/fl2000_vga.c | 223 ++++++++ 6 files changed, 1437 insertions(+), 8 deletions(-)
drivers/gpu/drm/fl2000/Makefile +4 -1
@@ -1,10 +1,13 @@ # SPDX-License-Identifier: GPL-2.0-only fl2000-y := \ + fl2000_drm.o \ fl2000_drv.o \ fl2000_i2c.o \ + fl2000_interrupt.o \ fl2000_it66121.o \ fl2000_registers.o \ - fl2000_streaming.o + fl2000_streaming.o \ + fl2000_vga.o obj-$(CONFIG_DRM_FL2000) += fl2000.o
drivers/gpu/drm/fl2000/fl2000.h +33 -0
@@ -100,6 +100,30 @@ void fl2000_stream_note_render(struct fl2000_stream *stream, unsigned int conv_uint fl2000_stream_enable (struct fl2000_stream *stream);void fl2000_stream_disable (struct fl2000_stream *stream); +/* Interrupt polling task */ +struct fl2000_intr ; +struct fl2000_intr *fl2000_intr_create (struct usb_device *usb_dev,struct regmap *regmap, +struct drm_device *drm); +void fl2000_intr_quiesce (struct fl2000_intr *intr); +void fl2000_intr_suspend (struct fl2000_intr *intr); +int fl2000_intr_start (struct fl2000_intr *intr); +int fl2000_intr_monitor_connected (struct fl2000_intr *intr); +void fl2000_intr_destroy (struct fl2000_intr *intr); + +/* VGA output: a DAC encoder and connector next to the HDMI ones, on the same CRTC */ +struct fl2000_vga { +struct drm_encoder encoder; +struct drm_connector connector; +struct i2c_adapter *adapter; +struct fl2000_intr *intr; +/* The HDMI transmitter shares the chip's monitor sense with this output */ +struct drm_bridge *hdmi_bridge; +}; + +int fl2000_vga_init (struct drm_device *drm,struct fl2000_vga *vga,struct drm_crtc *crtc, +struct drm_encoder *hdmi_encoder,struct i2c_adapter *adapter, +struct fl2000_intr *intr); +/* I2C adapter interface creation */ struct i2c_adapter *fl2000_i2c_init (struct usb_interface *interface,struct regmap *regmap);int fl2000_ddc_read_block (struct i2c_adapter *adapter,u8 *buf,unsigned int block,size_t len);
@@ -123,4 +147,13 @@ int fl2000_stream_interrupts(struct regmap *regmap, bool enable);int fl2000_read_status (struct regmap *regmap,u32 *status);int fl2000_i2c_dword (struct regmap *regmap,bool read,u16 addr,u8 offset,u32 *data); +/* DRM device creation */ +struct fl2000_device ; +struct fl2000_device *fl2000_drm_create (struct usb_interface *interface,struct regmap *regmap, +struct i2c_adapter *adapter,struct drm_bridge *bridge); +void fl2000_drm_destroy (struct fl2000_device *fdev); +void fl2000_drm_hotplug (struct drm_device *drm,u32 events); +int fl2000_drm_suspend (struct fl2000_device *fdev); +int fl2000_drm_resume (struct fl2000_device *fdev); +#endif /* FL2000_H */
drivers/gpu/drm/fl2000/fl2000_drm.c new file +902 -0
902 lines not on this page · raw message
drivers/gpu/drm/fl2000/fl2000_drv.c +49 -7
97 lines not on this page · raw message
drivers/gpu/drm/fl2000/fl2000_interrupt.c new file +226 -0
226 lines not on this page · raw message
drivers/gpu/drm/fl2000/fl2000_vga.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH v2 3/4] drm/fl2000: Add frame streaming
In reply to Angel Gabriel Crispin ValdiviaThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/fl2000: stale damage replay on same-size mode set in fl2000_stream_mode_set() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/fl2000: stale damage replay on same-size mode set in fl2000_stream_mode_set()
--
commit fb468144aa76017b626067d45248552b6ec6cb90
Author: Angel Gabriel Crispin Valdivia <[email protected]>
drm/fl2000: Add frame streaming
This commit adds frame streaming support for the FL2000 USB display adapter, converting damaged framebuffer rectangles into a shadow buffer and sending frames over bulk USB transfers from a pool of scatter-gather buffers.
Quoted 5 lines
drivers/gpu/drm/fl2000/fl2000_streaming.c new file +0
-0
[ ... ]
Quoted 28 lines
drivers/gpu/drm/fl2000/fl2000_streaming.c new file +28
-0+static void fl2000_copy_rect (struct fl2000_stream *stream,void *dst,const struct drm_rect *r) +{ +u32 line_len = stream->width * stream->bytes_pix; +size_t off, span; +int x1, x2, y1, y2; + +/* +* A rectangle can outlive the geometry it was recorded under: a mode +* change that keeps the buffer size keeps the buffers too. +*/ + x1 =clamp (r->x1,0 , (int )stream->width); + x2 =clamp (r->x2,0 , (int )stream->width); + y1 =clamp (r->y1,0 , (int )stream->height); + y2 =clamp (r->y2,0 , (int )stream->height); +if (x1 >= x2 || y1 >= y2) +return ; + + off = (size_t )x1 * stream->bytes_pix; + span = (size_t )(x2 - x1) * stream->bytes_pix; + +for (int y = y1; y < y2; y++) { +size_t start =round_down ((size_t )y * line_len + off,8 ); +size_t end =min_t (size_t,round_up ((size_t )y * line_len + off + span,8 ), + stream->buf_size); + +memcpy (dst + start, stream->shadow + start, end - start); + } +}
[ ... ]
Quoted 35 lines
drivers/gpu/drm/fl2000/fl2000_streaming.c new file +35
-0+int fl2000_stream_mode_set (struct fl2000_stream *stream,unsigned int width, +unsigned int height,u32 bytes_pix) +{ +int ret; +unsigned int size; + +/* Round buffer size up to multiple of 8 to meet HW expectations */ + size =ALIGN (width * height * bytes_pix,8 ); + +guard (mutex)(&stream->shadow_lock); + +/* If there are buffers with same size - keep them */ +if (stream->buf_size != size) { +/* +* Without a shadow nothing writes a frame, and an allocation that fails below +* must not leave the old, smaller one to be written with the new geometry. +*/ +fl2000_stream_put_buffers (stream); +vfree (stream->shadow); + stream->shadow =NULL ; + stream->buf_size =0 ; + + ret =fl2000_stream_get_buffers (stream, size); +if (ret) +return ret; + +/* One full frame in the device format; only the CPU ever reads it */ + stream->shadow =vzalloc (size); +if (!stream->shadow) { +fl2000_stream_put_buffers (stream); +return -ENOMEM ; + } + +/* A buffer carrying zero has never been built and takes the full-copy path */ + stream->shadow_seq++;
drivers/gpu/drm/fl2000/fl2000_streaming.c line 704
Quoted 10 lines
drivers/gpu/drm/fl2000/fl2000_streaming.c new file +10
-0+ + stream->buf_size = size; + } + + stream->bytes_pix = bytes_pix; + stream->width = width; + stream->height = height; + +return 0 ; +}
[Severity: Medium]
When a mode change keeps the same aligned buffer size (for example, 800x600 at 3 bytes/pixel to 1200x600 at 2 bytes/pixel, or a 90-degree rotation), can fl2000_stream_build() corrupt outgoing buffers by replaying old damage rectangles under the new geometry?
When stream->buf_size == size, fl2000_stream_mode_set() keeps stream->shadow and the existing buffers with their current sb->seq values. Rectangles in stream->damage_log from before the mode change were written using the old stride and pixel size, but fl2000_copy_rect() replays them using the new width and bytes_pix, copying the wrong byte ranges from stream->shadow while marking sb->seq caught up. Advancing stream->shadow_seq by FL2000_DAMAGE_LOG (and clearing stream->shadow) when the geometry or format changes would force retained buffers onto the full-copy path.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v2 1/4] drm/fl2000: Add USB driver with register and I2C access
In reply to Angel Gabriel Crispin ValdiviaThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/fl2000: unchecked regmap writes in int register helpers --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/fl2000: unchecked regmap writes in int register helpers --
commit 1083af596ecfae2d3d352f9d352bcede51d3408e
Author: Angel Gabriel Crispin Valdivia <[email protected]>
drm/fl2000: Add USB driver with register and I2C access
This commit adds the initial USB driver for Fresco Logic FL2000 display adapters, including regmap-backed register helpers and an I2C adapter.
Quoted 5 lines
drivers/gpu/drm/fl2000/fl2000_registers.c new file +0
-0
[ ... ]
Quoted 15 lines
drivers/gpu/drm/fl2000/fl2000_registers.c new file +15
-0+int fl2000_set_pll (struct regmap *regmap,struct fl2000_pll *pll) +{ +u32 val; + + val =FIELD_PREP (FL2000_VGA_PLL_PRESCALER , pll->prescaler) | +FIELD_PREP (FL2000_VGA_PLL_MULTIPLIER , pll->multiplier) | +FIELD_PREP (FL2000_VGA_PLL_DIVISOR , pll->divisor) | +FIELD_PREP (FL2000_VGA_PLL_FUNCTION , pll->function); +regmap_write (regmap,FL2000_VGA_PLL_REG , val); + + val =FL2000_VGA_CTRL_ACLK_FORCE_PLL_UP ; +regmap_write_bits (regmap,FL2000_VGA_CTRL_REG_ACLK , val, val); + +return 0 ; +}
[ ... ]
Quoted 89 lines
drivers/gpu/drm/fl2000/fl2000_registers.c new file +89
-0+int fl2000_set_timings (struct regmap *regmap,struct fl2000_timings *timings) +{ +regmap_write (regmap,FL2000_VGA_HSYNC_REG1 , +FIELD_PREP (FL2000_VGA_HSYNC1_HACTIVE , timings->hactive) | +FIELD_PREP (FL2000_VGA_HSYNC1_HTOTAL , timings->htotal)); + +regmap_write (regmap,FL2000_VGA_HSYNC_REG2 , +FIELD_PREP (FL2000_VGA_HSYNC2_HSYNC_WIDTH , timings->hsync_width) | +FIELD_PREP (FL2000_VGA_HSYNC2_HSTART , timings->hstart)); + +regmap_write (regmap,FL2000_VGA_VSYNC_REG1 , +FIELD_PREP (FL2000_VGA_VSYNC1_VACTIVE , timings->vactive) | +FIELD_PREP (FL2000_VGA_VSYNC1_VTOTAL , timings->vtotal)); + +regmap_write (regmap,FL2000_VGA_VSYNC_REG2 , +FIELD_PREP (FL2000_VGA_VSYNC2_VSYNC_WIDTH , timings->vsync_width) | +FIELD_PREP (FL2000_VGA_VSYNC2_VSTART , timings->vstart) | +FIELD_PREP (FL2000_VGA_VSYNC2_START_LATENCY , timings->vstart)); + +return 0 ; +} + +int fl2000_set_pixfmt (struct regmap *regmap,u32 bytes_pix) +{ +u32 mask, val; + + mask =FL2000_VGA_CTRL_PXCLK_DAC_OUTPUT_EN |FL2000_VGA_CTRL_PXCLK_DROP_CNT | +FL2000_VGA_CTRL_PXCLK_VGA565_MODE |FL2000_VGA_CTRL_PXCLK_VGA332_MODE | +FL2000_VGA_CTRL_PXCLK_VGA555_MODE |FL2000_VGA_CTRL_PXCLK_VGA_COMPRESS | +FL2000_VGA_CTRL_PXCLK_CLEAR_WATERMARK ; + val =FL2000_VGA_CTRL_PXCLK_DAC_OUTPUT_EN |FL2000_VGA_CTRL_PXCLK_CLEAR_WATERMARK ; +if (bytes_pix ==2 ) + val |=FL2000_VGA_CTRL_PXCLK_VGA565_MODE ; +regmap_write_bits (regmap,FL2000_VGA_CTRL_REG_PXCLK , mask, val); + +return 0 ; +} + +int fl2000_set_transfers (struct regmap *regmap) +{ +u32 mask; + + mask =FL2000_VGA_CTRL_ACLK_USE_PKT_PENDING |FL2000_VGA_CTRL_ACLK_USE_ZERO_TD | +FL2000_VGA_CTRL_ACLK_USE_ZERO_PKT_LEN ; +regmap_write_bits (regmap,FL2000_VGA_CTRL_REG_ACLK , mask, +FL2000_VGA_CTRL_ACLK_USE_ZERO_PKT_LEN ); + +regmap_write_bits (regmap,FL2000_VGA_ISOCH_REG ,FL2000_VGA_ISOCH_MFRAME_CNT ,0 ); + +return 0 ; +} + +int fl2000_reset (struct regmap *regmap) +{ +regmap_write_bits (regmap,FL2000_RST_CTRL_REG ,FL2000_RST_CTRL_SW_RESET , +FL2000_RST_CTRL_SW_RESET ); + +msleep (FL2000_HW_RST_MDELAY ); + +return 0 ; +} + +int fl2000_afe_magic (struct regmap *regmap) +{ +regmap_write_bits (regmap,FL2000_USB_LPM_REG ,FL2000_USB_LPM_MAGIC ,FL2000_USB_LPM_MAGIC ); + +return 0 ; +} + +int fl2000_usb_magic (struct regmap *regmap) +{ +u32 val; + +/* Writing DONE as 0 would start an I2C operation, see fl2000_i2c_dword() */ + val =FL2000_VGA_I2C_SC_MONITOR_DETECT |FL2000_VGA_I2C_SC_EDID_DETECT | +FL2000_VGA_I2C_SC_DONE ; +regmap_write_bits (regmap,FL2000_VGA_I2C_SC_REG , val, val); + +regmap_write_bits (regmap,FL2000_VGA_CTRL_REG_3 ,FL2000_VGA_CTRL3_WAKEUP_CLR_EN ,0 ); + + val =FL2000_USB_LPM_U1_REJECT |FL2000_USB_LPM_U2_REJECT ; +regmap_write_bits (regmap,FL2000_USB_LPM_REG , val, val); + +regmap_write_bits (regmap,FL2000_USB_CTRL_REG ,FL2000_USB_CTRL_WAKE_NRDY ,0 ); + +return 0 ; +} + +/* The interrupts about monitors: they matter from the moment the device is up, mode or no mode */
drivers/gpu/drm/fl2000/fl2000_registers.c line 214
Quoted 10 lines
drivers/gpu/drm/fl2000/fl2000_registers.c new file +10
-0+int fl2000_enable_sink_interrupts (struct regmap *regmap) +{ +regmap_write_bits (regmap,FL2000_VGA_CTRL_REG_ACLK ,FL2000_VGA_CTRL_ACLK_EDID_MON_INT_EN , +FL2000_VGA_CTRL_ACLK_EDID_MON_INT_EN ); + +regmap_write_bits (regmap,FL2000_VGA_CTRL2_REG_ACLK ,FL2000_VGA_CTRL2_ACLK_HDMI_INT_EN , +FL2000_VGA_CTRL2_ACLK_HDMI_INT_EN ); + +return 0 ; +}
[Severity: Medium]
Should these int-returning register helpers check and propagate errors from regmap_write() and regmap_write_bits(), like fl2000_force_connect() and fl2000_stream_interrupts() do?
Each regmap access runs a synchronous USB control transfer via usb_control_msg_recv() or usb_control_msg_send(). When a transfer fails or times out, these helpers still return 0 and continue issuing further USB control transfers, hiding initialization or modeset failures from callers.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v2 2/4] drm/fl2000: Add ITE IT66121 HDMI transmitter support
In reply to Angel Gabriel Crispin ValdiviaThank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] drm/fl2000: duplicate IT66121 driver and unbound devres in it66121_create() - [Medium] drm/fl2000…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] drm/fl2000: duplicate IT66121 driver and unbound devres in it66121_create()
- [Medium] drm/fl2000: commit message claims EDID caching not in it66121_bridge_edid_read()
- [Medium] drm/fl2000: use-after-free of priv->client in it66121_bridge_detect()
--
commit a3c9c50f6dcb635240f532485f69c80008aed756
Author: Angel Gabriel Crispin Valdivia <[email protected]>
drm/fl2000: Add ITE IT66121 HDMI transmitter support
This commit adds a DRM bridge driver for the ITE IT66121 HDMI transmitter on the FL2000 I2C bus and wires its creation and destruction into the USB driver probe and disconnect paths.
Quoted 5 lines
drivers/gpu/drm/fl2000/fl2000_it66121.c new file +0
-0
[ ... ]
Quoted 16 lines
drivers/gpu/drm/fl2000/fl2000_it66121.c new file +16
-0+int it66121_hpd_connected (struct drm_bridge *bridge) +{ + struct it66121_priv *priv = container_of(bridge, struct it66121_priv, bridge); +unsigned int val; +int idx, ret; + +if (!drm_bridge_enter (bridge, &idx)) +return -ENODEV ; + + ret =regmap_field_read (priv->hpd, &val); +drm_bridge_exit (idx); +if (ret) +return ret; + +return !!val; +}
[ ... ]
Quoted 11 lines
drivers/gpu/drm/fl2000/fl2000_it66121.c new file +11
-0+static enum drm_connector_status it66121_bridge_detect (struct drm_bridge *bridge, +struct drm_connector *connector) +{ + struct it66121_priv *priv = container_of(bridge, struct it66121_priv, bridge); +int ret =it66121_hpd_connected (bridge); + +if (ret >0 ) +return connector_status_connected; + +/* Gone with the USB device */ +if (ret == -ENODEV )
drivers/gpu/drm/fl2000/fl2000_it66121.c line 324
Quoted 10 lines
drivers/gpu/drm/fl2000/fl2000_it66121.c new file +10
-0+return connector_status_disconnected; + +if (ret <0 ) { +/* Not bridge->dev: the chip, not the DRM device, failed to answer */ +dev_err_ratelimited (&priv->client->dev,"Cannot get monitor status (%d)\n" , ret); +return connector_status_unknown; + } + +return connector_status_disconnected; +}
[Severity: Medium]
Can it66121_bridge_detect() cause a use-after-free on priv->client if the USB device is unplugged while regmap_field_read() is in flight?
When a USB control transfer fails during disconnect, fl2000_i2c_dword() maps the error to -EIO:
drivers/gpu/drm/fl2000/fl2000_registers.c:fl2000_i2c_dword() {
...
ret = regmap_write_bits(regmap, FL2000_VGA_I2C_SC_REG, mask, val);
if (ret)
return -EIO;
...
}Because it66121_hpd_connected() calls drm_bridge_exit() before returning that -EIO to it66121_bridge_detect(), a concurrent USB disconnect can finish drm_bridge_unplug() and free priv->client before dev_err_ratelimited() runs:
CPU0 CPU1it66121_bridge_detect()
it66121_hpd_connected()
drm_bridge_enter()
regmap_field_read() -> -EIO
drm_bridge_exit()
fl2000_disconnect()
it66121_destroy()
drm_bridge_unplug()
i2c_unregister_device(priv->client)
dev_err_ratelimited(&priv->client->dev, ...)
<-- use-after-freeQuoted 16 lines
drivers/gpu/drm/fl2000/fl2000_it66121.c new file +16
-0+static const struct drm_edid *it66121_bridge_edid_read (struct drm_bridge *bridge, +struct drm_connector *connector) +{ + struct it66121_priv *priv = container_of(bridge, struct it66121_priv, bridge); +const struct drm_edid *drm_edid; +int idx, ret; + +if (!drm_bridge_enter (bridge, &idx)) +return NULL ; + +if (priv->ddc_held) { +/* Not fatal: the read tells whether the bus is free */ + ret =it66121_release_ddc (priv); +if (ret) +dev_dbg (&priv->client->dev,"Cannot release the DDC bus (%d)\n" , ret); + priv->ddc_held = false;
drivers/gpu/drm/fl2000/fl2000_it66121.c line 351
Quoted 10 lines
drivers/gpu/drm/fl2000/fl2000_it66121.c new file +10
-0+ } + + drm_edid =drm_edid_read_custom (connector, it66121_get_edid_block, priv); +if (!drm_edid) +dev_warn (&priv->client->dev,"EDID read failed, using fallback modes\n" ); + +drm_bridge_exit (idx); + +return drm_edid; +}
[Severity: Medium]
The commit message says "The EDID is kept while the monitor stays, since reading it over USB takes about a second", but does it66121_bridge_edid_read() actually cache the EDID?
struct it66121_priv has no field to store the EDID, and drm_bridge_connector_get_modes_edid() frees the struct drm_edid returned by drm_bridge_edid_read() on each call, so every get_modes() call reads the EDID over USB again.
[ ... ]
Quoted 25 lines
drivers/gpu/drm/fl2000/fl2000_it66121.c new file +25
-0+static struct i2c_client *it66121_i2c_init (struct i2c_adapter *adapter) +{ +/* +* Not "it66121": that name would make the ite-it66121 driver, if built, +* try to bind this client and release our devres when its probe fails. +*/ +struct i2c_board_info board_info = {I2C_BOARD_INFO ("fl2000-it66121" ,0 ) }; + +/* According to datasheet IT66121 addresses are 0x98 or 0x9A including cmd */ +const unsigned short it66121_addr[] = { (0x98 >>1 ), (0x9A >>1 ),I2C_CLIENT_END }; +struct i2c_client *client; + +/* The chip may still be waking up when the USB device has just enumerated */ +for (int i =0 ; i <IT66121_DETECT_TRIES ; i++) { +if (i) +msleep (IT66121_DETECT_DELAY_MS ); + + client =i2c_new_scanned_device (adapter, &board_info, it66121_addr, + it66121_i2c_probe); +if (!IS_ERR (client)) +break ; + } + +return client; +}
[ ... ]
Quoted 10 lines
drivers/gpu/drm/fl2000/fl2000_it66121.c new file +10
-0+struct drm_bridge *it66121_create (struct i2c_adapter *adapter) +{ +int ret; +struct it66121_priv *priv; +struct i2c_client *client; + + client =it66121_i2c_init (adapter); +if (IS_ERR (client)) { +dev_err (&adapter->dev,"No IT66121 found (%pe): adapters without one are not supported\n" , + client);
drivers/gpu/drm/fl2000/fl2000_it66121.c line 772
Quoted 10 lines
drivers/gpu/drm/fl2000/fl2000_it66121.c new file +10
-0+return ERR_CAST (client); + } + +/* +* DRM core takes references on the bridge, so it must be allocated with +* devm_drm_bridge_alloc(). Freeing happens automatically when the last +* reference is dropped after i2c_unregister_device(). +*/ + priv = devm_drm_bridge_alloc(&client->dev, struct it66121_priv, bridge, + &it66121_bridge_funcs);
[Severity: Medium]
Why add a second driver for the ITE IT66121 instead of extending drivers/gpu/drm/bridge/ite-it66121.c, and is it valid to attach devm resources to an unbound i2c_client?
To keep the existing ite-it66121 driver from binding the client, it66121_i2c_init() registers a dummy "fl2000-it66121" device with no driver and attaches devm_drm_bridge_alloc(), devm_regmap_init_i2c() and devm_regmap_field_alloc() to &client->dev outside of any driver probe. The driver core treats devres entries on an unbound device as a bug in really_probe() ("Resources present before probing").
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v2 4/4] drm/fl2000: Add KMS display pipeline
In reply to Angel Gabriel Crispin ValdiviaThank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/fl2000: USB reset callbacks race unlocked drm_mode_config_reset() with ioctls - [Medium]…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [High] drm/fl2000: USB reset callbacks race unlocked drm_mode_config_reset() with ioctls
- [Medium] drm/fl2000: nonzero return from fl2000_resume() in post_reset unbinds driver
- [Medium] drm/fl2000: fl2000_drm_resume() leaves active CRTC unprogrammed if suspend fails
- [Medium] drm/fl2000: unscheduled intr->work in fl2000_intr_read_status() strands HDMI IRQs
--
commit 7aa37254cbf5a2f4dd511499c2b10b545e13febc
Author: Angel Gabriel Crispin Valdivia <[email protected]>
drm/fl2000: Add KMS display pipeline
This commit adds the DRM/KMS display pipeline for the Fresco Logic FL2000 USB display adapter, including plane/CRTC/encoder setup, HDMI and VGA connectors, interrupt handling, and suspend/resume support.
Quoted 5 lines
drivers/gpu/drm/fl2000/fl2000_drm.c new file +0
-0
[ ... ]
Quoted 35 lines
drivers/gpu/drm/fl2000/fl2000_drm.c new file +35
-0+int fl2000_drm_suspend (struct fl2000_device *fdev) +{ +int ret; + +/* No hotplug events while going to sleep */ +fl2000_intr_suspend (fdev->intr); + +/* Saves the state, turns the outputs off and stops the stream */ + ret =drm_mode_config_helper_suspend (&fdev->drm); +if (ret) { +drm_err (&fdev->drm,"Cannot save the display state (%d)\n" , ret); +fl2000_stream_disable (fdev->stream); + } + +return ret; +} + +/** +* fl2000_drm_resume() - bring the display back after system sleep or a USB reset +* @fdev: the DRM device +* +* Called once for the device, when all of it is awake again, also after a reset-resume. The chips +* may have lost power: they are set up as at bind time before the saved state is restored. +* +* Return: 0 on success, a negative error code otherwise +*/ +int fl2000_drm_resume (struct fl2000_device *fdev) +{ +struct regmap *regmap = fdev->regmap; +int ret =0 ; + +/* First, as the IT66121 is reached through the FL2000 I2C engine */ +fl2000_regmap_drop_cache (regmap); + +it66121_resume (fdev->bridge);
drivers/gpu/drm/fl2000/fl2000_drm.c line 712
Quoted 10 lines
drivers/gpu/drm/fl2000/fl2000_drm.c new file +10
-0+ +/* The same order as in fl2000_drm_create() */ +fl2000_chip_setup (fdev); + +/* There is nothing to restore if saving the state failed */ +if (fdev->drm.mode_config.suspend_state) { + ret =drm_mode_config_helper_resume (&fdev->drm); +if (ret) +drm_err (&fdev->drm,"Cannot restore the display after sleep (%d)\n" , ret); + }
[Severity: Medium]
If drm_mode_config_helper_suspend() fails in fl2000_drm_suspend(), does fl2000_drm_resume() leave an active CRTC unprogrammed and its stream stopped?
When drm_mode_config_helper_suspend() fails, fdev->drm.mode_config.suspend_state remains NULL and the DRM software state stays enabled, while fl2000_drm_suspend() disables fdev->stream. On resume, it66121_resume() and fl2000_chip_setup() reset both chips, clearing the PLL, timings, and HDMI transmitter state, but because suspend_state is NULL, drm_mode_config_helper_resume() is skipped. The hardware stays unprogrammed and the stream stays disabled while fdev->crtc.state remains active, so subsequent page flips or plane updates do not trigger a modeset and the display remains blank.
Quoted 4 lines
drivers/gpu/drm/fl2000/fl2000_drv.c +0
-0
[ ... ]
Quoted 23 lines
drivers/gpu/drm/fl2000/fl2000_drv.c +18
-1+static int fl2000_resume (struct usb_interface *interface) { -dev_dbg (&interface->dev,"resume\n" ); +struct fl2000_devs *devs =usb_get_intfdata (interface); + +if (!devs || !devs->suspended) +return 0 ; + + devs->suspended = false; + +return fl2000_drm_resume (devs->fdev); +} + +/* +* A reset of the USB device (the storage function of the adapter asks for one when it times out) +* is the same as far as the display goes. Nonzero would make the USB core unbind the driver. +*/ +static int fl2000_pre_reset (struct usb_interface *interface) +{ +fl2000_suspend (interface,PMSG_SUSPEND );return 0 ; }
drivers/gpu/drm/fl2000/fl2000_drv.c static void fl2000_disconnect(struct usb_interface *interface)
Quoted 10 lines
drivers/gpu/drm/fl2000/fl2000_drv.c +3
-0static struct usb_driver fl2000_driver = { .name =KBUILD_MODNAME , .probe = fl2000_probe, .disconnect = fl2000_disconnect, .suspend = fl2000_suspend, .resume = fl2000_resume, + .reset_resume = fl2000_resume, + .pre_reset = fl2000_pre_reset, + .post_reset = fl2000_resume,
[Severity: High]
Can calling drm_mode_config_helper_suspend() and drm_mode_config_helper_resume() from .pre_reset and .post_reset cause a use-after-free on DRM modeset states when a USB reset runs concurrently with userspace ioctls?
Unlike system sleep, usb_reset_device() runs while userspace is active. drm_mode_config_helper_resume() -> drm_atomic_helper_resume() calls drm_mode_config_reset() before acquiring modeset locks:
drivers/gpu/drm/drm_atomic_helper.c:drm_atomic_helper_resume() {
...
drm_mode_config_reset(dev);
DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
...
}drm_mode_config_reset() destroys and reallocates plane->state, crtc->state, and connector->state without holding any modeset locks:
CPU0 (usb_reset_device) CPU1 (compositor ioctl)fl2000_resume()
fl2000_drm_resume()
drm_mode_config_helper_resume()
drm_atomic_helper_resume()
drm_mode_atomic_ioctl()
drm_atomic_get_crtc_state()
drm_modeset_lock(&crtc->mutex, ...)
drm_mode_config_reset()
atomic_destroy_state()
kfree(crtc->state)
atomic_duplicate_state(crtc)
__drm_atomic_helper_crtc_duplicate_state()
<-- use-after-free / NULL derefIn addition, between fl2000_pre_reset() and .post_reset, drm_mode_config_helper_suspend() leaves the CRTC disabled with all modeset locks released, so concurrent page flips from the running compositor fail with -EINVAL.
[Severity: Medium]
Also, if fl2000_drm_resume() returns an error during .post_reset, does that cause the USB core to unbind the driver and fail to rebind it?
fl2000_pre_reset() ignores the return value of fl2000_suspend() because usb_reset_device() treats a nonzero return as a request to unbind and rebind the interface, but .post_reset is wired directly to fl2000_resume(). usb_reset_device() calls .post_reset in reverse interface order (2, 1, 0):
on interface 2, fl2000_resume() clears devs->suspended and returns any error from fl2000_drm_resume(), setting needs_binding = 1 on interface 2, and then returns 0 on interfaces 1 and 0. usb_unbind_and_rebind_marked_interfaces() then unbinds interface 2 (running fl2000_disconnect() and releasing all interfaces) and only attempts to rebind interface 2, which does not match fl2000_id_table.
Quoted 5 lines
drivers/gpu/drm/fl2000/fl2000_interrupt.c new file +0
-0
[ ... ]
Quoted 22 lines
drivers/gpu/drm/fl2000/fl2000_interrupt.c new file +22
-0+static int fl2000_intr_read_status (struct fl2000_intr *intr,u32 *status) +{ +int ret; + + ret =fl2000_read_status (intr->regmap, status); +if (ret) +return ret; + +atomic_or (*status &FL2000_SINK_EVENTS , &intr->events); + +return 0 ; +} + +/** +* fl2000_intr_monitor_connected() - does the FL2000 sense a monitor on its monitor input +* @intr: interrupt context +* +* The chip powers the DAC and the PLL only while this is the case. On the boards with both +* outputs the input follows whichever monitor is plugged in, so it does not tell VGA from HDMI. +* While HDMI is being driven the sense is forced on and tells nothing: that counts as not sensing, +* or an HDMI monitor going away would look like a VGA one showing up, until the CRTC is disabled. +*
drivers/gpu/drm/fl2000/fl2000_interrupt.c line 62
Quoted 10 lines
drivers/gpu/drm/fl2000/fl2000_interrupt.c new file +10
-0+* Return: 1 if a monitor is sensed, 0 if not, a negative error code if the status cannot be read +*/ +int fl2000_intr_monitor_connected (struct fl2000_intr *intr) +{ +u32 status; +int ret; + + ret =fl2000_intr_read_status (intr, &status); +if (ret) +return ret;
[Severity: Medium]
When fl2000_intr_monitor_connected() reads FL2000_VGA_STATUS_HDMI_EVENT during VGA connector detection, can that strand the event in intr->events without acknowledging the IT66121 interrupt?
Reading FL2000_VGA_STATUS_REG clears the pending interrupt and event bits in the FL2000 hardware. When fl2000_vga_detect_ctx() -> fl2000_intr_monitor_connected() reads the status register (for example during initial probing in fl2000_drm_create() before fl2000_intr_start(), or during periodic polling before the USB interrupt endpoint fires), fl2000_intr_read_status() saves FL2000_SINK_EVENTS into intr->events, but nothing queues intr->work to run fl2000_drm_hotplug() and call it66121_ack_interrupts(). The IT66121 interrupt line then remains asserted and cannot signal further HDMI hotplug events.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4