]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
media: uvcvideo: Relax the constrains for interpolating the hw clock
authorRicardo Ribalda <ribalda@chromium.org>
Wed, 13 May 2026 11:49:22 +0000 (11:49 +0000)
committerHans Verkuil <hverkuil+cisco@kernel.org>
Thu, 21 May 2026 19:14:07 +0000 (21:14 +0200)
In the initial version we set the min value to 250msec. Looks like
100msec can also provide a good value.

Now that we are at it, add a macro to make it cleaner.

Fixes: 6243c83be6ee8 ("media: uvcvideo: Allow hw clock updates with buffers not full")
Cc: stable@vger.kernel.org
Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Tested-by: Yunke Cao <yunkec@google.com>
Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
Link: https://patch.msgid.link/20260513-uvc-hwtimestamp-v3-3-7a64838b0b02@chromium.org
Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
drivers/media/usb/uvc/uvc_video.c

index bb3ee942e570100bbd54e7747e9cf1c74b079046..d2e61be35bf6fe6e54d85cb614986147b12314e6 100644 (file)
@@ -494,6 +494,13 @@ static int uvc_commit_video(struct uvc_streaming *stream,
  * Clocks and timestamps
  */
 
+/*
+ * The accuracy of the hardware timestamping depends on having enough data to
+ * interpolate between the different clock domains. This value is sof cycles,
+ * this is, milliseconds.
+ */
+#define UVC_MIN_HW_TIMESTAMP_DIFF 100
+
 static inline ktime_t uvc_video_get_time(void)
 {
        if (uvc_clock_param == CLOCK_MONOTONIC)
@@ -843,13 +850,13 @@ void uvc_video_clock_update(struct uvc_streaming *stream,
         * buffer, but RAM is expensive these days, specially the infinitely
         * big.
         *
-        * The value of 1/4th of a second was determined by running Android's
-        * CTS on different devices.
+        * The value of UVC_MIN_HW_TIMESTAMP_DIFF was determined by running
+        * Android's CTS on different devices.
         *
-        * dev_sof runs at 1KHz, and we have a fixed point precision of
-        * 16 bits.
+        * y1 and y2 are dev_sof with a fixed point precision of 16 bits.
         */
-       if (clock->size != clock->count && (y2 - y1) < ((1000 / 4) << 16))
+       if (clock->size != clock->count &&
+           (y2 - y1) < (UVC_MIN_HW_TIMESTAMP_DIFF << 16))
                goto done;
 
        y = (u64)(y2 - y1) * (1ULL << 31) + (u64)y1 * (u64)x2