Can v4l2 buffer timestamp be set based on tx2 kernel start up not on u-boot start up?

Hi,
I want to compare v4l2_buf timestamp with system time got with clock_gettime().

But time got with clock_gettime() is starting from tx2 kernel starting.

Time got with v4l2_buf timesstamp is starting from tx2 u-boot starting.

I think there is a u-boot(before kernel starting) time between them.

I also have tried setting cbootargs tegra_keep_boot_clocks=0 or =1 , but can not make it.

I try it on R28.2.1 and R28.3.

But on tx1 R28.2 the time is uniform.

Can I make them count base on the same start point.

Hi,
Is your v4l2 source a USB camera? Or YUV sensor through CSI port?

Hi, DaneLLL
We use tc358748 and a separate camera to capture yuyv video.

@anhuimain
Below code is the timestamp assign to the vb2 buffer.

diff --git a/drivers/media/platform/tegra/camera/vi/channel.c b/drivers/media/platform/tegra/camera/vi/channel.c
index a009026..d15a3c5 100644
--- a/drivers/media/platform/tegra/camera/vi/channel.c
+++ b/drivers/media/platform/tegra/camera/vi/channel.c
@@ -328,8 +328,7 @@ void set_timestamp(struct tegra_channel_buffer *buf,
        buf->buf.timestamp.tv_sec = ts->tv_sec;
        buf->buf.timestamp.tv_usec = ts->tv_nsec / NSEC_PER_USEC;
 #else
-       /* TODO: granular time code information */
-       buf->buf.timecode.seconds = ts->tv_sec;
+       buf->buf.vb2_buf.timestamp = timespec_to_ns(ts);
 #endif
 }

diff --git a/drivers/media/platform/tegra/camera/vi/vi5_fops.c b/drivers/media/platform/tegra/camera/vi/vi5_fops.c
index 2303594..e9fd402 100644
--- a/drivers/media/platform/tegra/camera/vi/vi5_fops.c
+++ b/drivers/media/platform/tegra/camera/vi/vi5_fops.c
@@ -424,8 +424,7 @@ static void vi5_capture_dequeue(struct tegra_channel *chan,
        vb->timestamp.tv_sec = ts.tv_sec;
        vb->timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
 #else
-       /* TODO: granular time code information */
-       vb->timecode.seconds = ts.tv_sec;
+       vb->vb2_buf.timestamp = descr->status.sof_timestamp;
 #endif

Hi, ShaneCCC
Thank you very much.

Now we use tx2 and r28.3 at present.

Is there a similar way with it?

Hi, ShaneCCC
I have found a similar post with my problem.

It is [url]https://devtalk.nvidia.com/default/topic/1038131/jetson-tx2/vi-capture-system-time-offset/1[/url]

I realize the problem is not just the time of different start point. Is that correct?

@anhuimain
The patch is for r32.1, you don’t need to apply it. However this patch tell how the timestamp assign to the vb2 buffer. You can check it. For the TX2 the timestamp is from RTCPU system it must have offset with host system. Maybe you can reassign it after get SOF from the notify call back from RTCUP.

Hi, ShaneCCC

Thank you for pointing out two directions for me. I will try on them.