Skip to content

media: bcm2835-unicam: Forward input status from subdevice - #4437

Merged
pelwell merged 1 commit into
raspberrypi:rpi-5.10.yfrom
JakubVanek:feature/unicam-sensor-status
Jul 8, 2021
Merged

pelwell merged 1 commit into
raspberrypi:rpi-5.10.yfrom
JakubVanek:feature/unicam-sensor-status

Conversation

@JakubVanek

Copy link
Copy Markdown
Contributor

The vidioc_enum_input() v4l2 ioctl is capable of returning
sensor/input status as well. This is used in current
GStreamer HEAD for signal detection 1.

bcm2835-unicam does handle this syscall, but it didn't ask
the subdevice driver about the input status. The input then
appeared as always present.

This commit adds the necessary query. There is a precedent for
this - the R-Car VIN V4L2 driver does a similar call 2.

Signed-off-by: Jakub Vaněk linuxtardis@gmail.com

The vidioc_enum_input() v4l2 ioctl is capable of returning
sensor/input status as well. This is used in current
GStreamer HEAD for signal detection [1].

bcm2835-unicam does handle this syscall, but it didn't ask
the subdevice driver about the input status. The input then
appeared as always present.

This commit adds the necessary query. There is a precedent for
this - the R-Car VIN V4L2 driver does a similar call [2].

[1]: https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/blob/ce0be27caf69aa9d96b73bc2b50737451b6f6936/sys/v4l2/gstv4l2src.c#L553
[2]: https://github.com/raspberrypi/linux/blob/7fb9d006d3ff3baf2e205e0c85c4e4fd0a64fcd0/drivers/media/platform/rcar-vin/rcar-v4l2.c#L548

Signed-off-by: Jakub Vaněk <linuxtardis@gmail.com>
@JakubVanek
JakubVanek force-pushed the feature/unicam-sensor-status branch from d269962 to 5fffd95 Compare July 7, 2021 20:55
@JakubVanek

Copy link
Copy Markdown
Contributor Author

Tested on top of 1814148 with this patch applied. When I detach a HDMI source from TC358743, the status returned from kernel now reflects this:

  • HDMI input plugged in & running:
# v4l2-ctl --list-inputs
ioctl: VIDIOC_ENUMINPUT
	Input       : 0
	Name        : Camera 0
	Type        : 0x00000002 (Camera)
	Audioset    : 0x00000000
	Tuner       : 0x00000000
	Standard    : 0x0000000000000000 ()
	Status      : 0x00000000 (ok)
	Capabilities: 0x00000002 (DV timings)
  • HDMI input unplugged:
# v4l2-ctl --list-inputs
ioctl: VIDIOC_ENUMINPUT
	Input       : 0
	Name        : Camera 0
	Type        : 0x00000002 (Camera)
	Audioset    : 0x00000000
	Tuner       : 0x00000000
	Standard    : 0x0000000000000000 ()
	Status      : 0x00010002 (no signal, no sync lock)
	Capabilities: 0x00000002 (DV timings)

GStreamer 1.18.4 with backported https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/870 also successfully reacts to this:

# gst-launch-1.0 v4l2src ! video/x-raw, format=UYVY, colorimetry=bt601 ! fakesink
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Pipeline is PREROLLED ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
WARNING: from element /GstPipeline:pipeline0/GstV4l2Src:v4l2src0: Signal lost        <== message sent only with this patch
Additional debug info:
../sys/v4l2/gstv4l2src.c(553): gst_v4l2src_query_preferred_size (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
No input source was detected - video frames invalid
INFO:09.0 / 99:99:99.
../sys/v4l2/gstv4l2src.c(558): gst_v4l2src_query_preferred_size (): /GstPipeline:pipeline0/GstV4l2Src:v4l2src0:
Input source detected           <== message sent only with this patch
^Chandling interrupt.
Interrupt: Stopping pipeline ...
Execution ended after 0:00:12.089683329
Setting pipeline to NULL ...
Freeing pipeline ...

@6by9

6by9 commented Jul 8, 2021

Copy link
Copy Markdown
Contributor

Looks reasonable.

The rcar_vin code traps -ENOIOCTLCMD and -ENODEV so as not to return those errors to userspace.

-ENOIOCTLCMD will never happen as you've used v4l2_subdev_has_op to check that the function exists first.

Is -ENODEV possible? That would mean dev->sensor is NULL (or the subdev driver is returning something very odd). I don't believe that can happen as it's assigned in unicam_async_bound, and the V4L2 device isn't registered until register_node is called from unicam_probe_complete, so there's no way to call the IOCTL at that point. So I think you're fine.
@naushir Could you do a 2 minute check of my logic there please?

@naushir

naushir commented Jul 8, 2021

Copy link
Copy Markdown
Contributor

Looks good to me.

@pelwell
pelwell merged commit 64f5ffe into raspberrypi:rpi-5.10.y Jul 8, 2021
@JakubVanek

Copy link
Copy Markdown
Contributor Author

Thank you!

@JakubVanek
JakubVanek deleted the feature/unicam-sensor-status branch July 8, 2021 16:58
popcornmix added a commit to raspberrypi/firmware that referenced this pull request Jul 9, 2021
See: raspberrypi/linux#4433

kernel: media: bcm2835-unicam: Forward input status from subdevice
See: raspberrypi/linux#4437

kernel: bcm2711_thermal: Don't clamp temperature at zero
See: raspberrypi/linux#4438

kernel: vc4/drm: Pick up more upstream patches
See: raspberrypi/linux#4441

kernel: Add overlay for Chipdip I2S master DAC
See: raspberrypi/linux#4444
popcornmix added a commit to Hexxeh/rpi-firmware that referenced this pull request Jul 9, 2021
See: raspberrypi/linux#4433

kernel: media: bcm2835-unicam: Forward input status from subdevice
See: raspberrypi/linux#4437

kernel: bcm2711_thermal: Don't clamp temperature at zero
See: raspberrypi/linux#4438

kernel: vc4/drm: Pick up more upstream patches
See: raspberrypi/linux#4441

kernel: Add overlay for Chipdip I2S master DAC
See: raspberrypi/linux#4444
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.

4 participants