Camera capture works only after streaming with v4l2-ctl

I wrote a camera driver for OV9734 and am trying to get it to capture images. It passes all the v4l2 tests.

When I try to record even a single image using gstreamer, the whole camera subsystem locks up and produces errors and no image. This is the command line I’m using:

gst-launch-1.0 -v nvcamerasrc num-buffers=1 ! 'video/x-raw(memory:NVMM),width=(i)1280,height=(i)720' ! nvjpegenc ! filesink location=sample.jpg

Similar behavior happens when I try to record video. However, I found one way to make the camera work—when I first run v4l2-ctl and stream a some frames, then afterwards everything works!

v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=RG10 --stream-mmap --stream-count=100 -d /dev/video0
gst-launch-1.0 -v nvcamerasrc num-buffers=1 ! 'video/x-raw(memory:NVMM),width=(i)1280,height=(i)720' ! nvjpegenc ! filesink location=sample.jpg

When I run the first command and it fails, here are the logs:

Command line: https://gist.github.com/nsabovic/f5149de33a8d4416000a0c7bfe73ae9f#file-failed-command-line-log

dmesg: https://gist.github.com/nsabovic/f5149de33a8d4416000a0c7bfe73ae9f#file-failed-dmesg-log

trace: https://gist.github.com/nsabovic/f5149de33a8d4416000a0c7bfe73ae9f#file-failed-trace-log

argus-daemon and nvcamera-daemon: https://gist.github.com/nsabovic/f5149de33a8d4416000a0c7bfe73ae9f#file-failed-argus-daemon-nvcamera-daemon-log

When I run both command and it succeeds, here are the logs:

Command line: https://gist.github.com/nsabovic/f5149de33a8d4416000a0c7bfe73ae9f#file-succeeded-command-line-log

dmesg: https://gist.github.com/nsabovic/f5149de33a8d4416000a0c7bfe73ae9f#file-succeeded-dmesg-log

trace: https://gist.github.com/nsabovic/f5149de33a8d4416000a0c7bfe73ae9f#file-succeeded-trace-log

argus-daemon and nvcamera-daemon: https://gist.github.com/nsabovic/f5149de33a8d4416000a0c7bfe73ae9f#file-succeeded-argus-daemon-nvcamera-daemon-log

Here’s the part of the DTSI file that describes the mode, in case it helps: https://gist.github.com/nsabovic/f5149de33a8d4416000a0c7bfe73ae9f#file-dts-mode-excerpt-dtsi

What is going on here? What do I need to change in the driver to have it work reliably?

The failed trace show CSI didn’t get validate data from sensor. Make sure the sensor driver is initial correct to output correct data.