Skip to content

drm/vc4: Use the HVS field bit for interlaced scanout position - #7763

Merged
pelwell merged 1 commit into
raspberrypi:rpi-6.18.yfrom
popcornmix:vc4-interlace-field
Nov 17, 2026
Merged

pelwell merged 1 commit into
raspberrypi:rpi-6.18.yfrom
popcornmix:vc4-interlace-field

Conversation

@popcornmix

Copy link
Copy Markdown
Collaborator

Fixes #7757.

vc4_crtc_get_scanout_position() chose the field for the half-line correction from the parity of the HVS frame counter, which is free running and not cleared on channel reset. The HVS status register it already reads has a field bit (SCALER6_DISPX_STATUS_OFIELD on BCM2712, bit 27 of SCALER_DISPSTATX on earlier HVS). Use that instead, on all generations.

Tested on Pi 5 (Pi 500+), Pi 4 and Pi 3B+, measuring the median change between consecutive vblank timestamp intervals:

before after
Pi 5 HDMI 1080i60/1080i50/480i/576i 2 lines in every modeset 0–1 µs
Pi 4 HDMI, same modes 0 or 2 lines, depending on the modeset 0–1 µs
Pi 3B+ HDMI, same modes 0 (by luck) 0–1 µs
Pi 4 composite NTSC/PAL (tested with the same logic on rpi-7.4.y) 0–1 µs 1–2 µs

vc4_crtc_get_scanout_position() adds half a line to hpos on one of the
two fields of an interlaced mode, and picks that field from the parity
of the HVS frame counter. The frame counter is free running and is not
cleared when the channel is reset, so its parity has no fixed relation
to the field being output. Depending on the history of the channel the
correction lands on the wrong field, and the vblank timestamps then
alternate by two lines.

The HVS status register already read in this function reports the
active field: SCALER6_DISPX_STATUS_OFIELD on BCM2712, and bit 27 of
SCALER_DISPSTATX on earlier generations. Use it instead. The correction
applies when the bit is clear.

Measured as the median change between consecutive vblank timestamp
intervals over 200 fields, with 1080i60, 1080i50, 480i and 576i on
HDMI, and NTSC and PAL on Pi 4 composite:

  - frame counter parity: 0 or 2 lines, depending on the modeset
    (Pi 5 and Pi 4; Pi 3 happened to be right in every run)
  - field bit, set: 2 lines on Pi 3, Pi 4 and Pi 5
  - field bit, clear: 0-2 us on Pi 3, Pi 4 and Pi 5 in every run

Fixes: e538092 ("drm/vc4: Enable precise vblank timestamping for interlaced modes.")
Fixes: 7687a12 ("drm/vc4: hvs: Add support for BCM2712 HVS")
Link: raspberrypi#7757
Signed-off-by: Dom Cobley <popcornmix@gmail.com>
@popcornmix

Copy link
Copy Markdown
Collaborator Author

Reported working in #7757

@pelwell
pelwell merged commit aa4df0e into raspberrypi:rpi-6.18.y Nov 17, 2026
12 checks passed
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Nov 17, 2026
kernel: spi: rp2040-gpio-bridge: Fix fast_xfer with strict RP1 pinmux
See: raspberrypi/linux#7728

kernel: drm/vc4: hdmi: Reset the MAI FIFO when preparing audio
See: raspberrypi/linux#7751

kernel: configs: Enable NET_SWITCHDEV and ADIN1110 support
See: raspberrypi/linux#7687

kernel: drm/vc4: Use the HVS field bit for interlaced scanout position
See: raspberrypi/linux#7763

kernel: xhci: drop the VL805 XHCI_EP_CTX_BROKEN_DCS cycle-state quirk
See: raspberrypi/linux#7754
popcornmix added a commit to raspberrypi/rpi-firmware that referenced this pull request Nov 17, 2026
kernel: spi: rp2040-gpio-bridge: Fix fast_xfer with strict RP1 pinmux
See: raspberrypi/linux#7728

kernel: drm/vc4: hdmi: Reset the MAI FIFO when preparing audio
See: raspberrypi/linux#7751

kernel: configs: Enable NET_SWITCHDEV and ADIN1110 support
See: raspberrypi/linux#7687

kernel: drm/vc4: Use the HVS field bit for interlaced scanout position
See: raspberrypi/linux#7763

kernel: xhci: drop the VL805 XHCI_EP_CTX_BROKEN_DCS cycle-state quirk
See: raspberrypi/linux#7754
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

drm/vc4: BCM2712: interlaced vblank timestamps alternate by 2 lines in some modesets (FRCNT parity is not the field)

2 participants