mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH RFC 0/5] media: Fault-Tolerant V4L2
@ 2026-10-01 12:55 Mattijs Korpershoek
  2026-10-01 12:55 ` [PATCH RFC 1/5] media: imx219: Move LP-11 state switch to power_on() Mattijs Korpershoek
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Mattijs Korpershoek @ 2026-10-01 12:55 UTC (permalink / raw)
  To: Laurent Pinchart, Kieran Bingham, Sakari Ailus, Mauro Carvalho Chehab
  Cc: Michael Riesch, Dave Stevenson, Maxime Ripard, linux-media,
	linux-kernel, Mattijs Korpershoek

On media-centric camera pipelines, every entity is known at boot time
and described statically (for example via device-tree).

The V4L2 framework assumes that every entity of the camera
pipeline is always present. This is a reasonable assumption for
integrated cameras in laptops or phones. However, in automotive systems,
cameras (e.g. rear-view or surround-view) can be damaged or disconnected.
When the framework assumes all sensors are present, a single missing
camera can prevent the entire pipeline from operating.

This is a known problem and has been discussed at media summit a couple of times:
https://www.linuxtv.org/downloads/presentations/media_summit_2026/Michael%20-%20The%20Butterfly%20Effect.pdf
https://www.linuxtv.org/news.php?entry=2022-11-14-0.hverkuil

For example, in the following pipeline:
"""
  imx219  9-0010 -> ds90ub953 7-0044 -> ds90ub960 pad0 -+
                                                        |-- pad4 -> cdns_csi2rx -> ticsi2rx
  imx219 10-0010 -> ds90ub953 7-0045 -> ds90ub960 pad1 -+
"""

If imx219 9-0010 fails to probe, media-ctl -p will show:
"""
                    ds90ub953 7-0044 -> ds90ub960 pad0 -+
                                                        |-- pad4 -> cdns_csi2rx -> ticsi2rx
  imx219 10-0010 -> ds90ub953 7-0045 -> ds90ub960 pad1 -+
"""

Now, if ds90ub953 7-0044 fails to probe(), media-ctl -p will only show the
following topology:
"""
                                                                    cdns_csi2rx -> ticsi2rx
"""

Which is unexpected - we should be able to use the imx219 10-0010 sensor
if it's connected.
Also, the media graph should reflect the hardware topology, not just
what's currently working. This way, userspace can distinguish
"camera X is disconnected" from "camera X does not exist".

Applications thus need to know if a sensor or an entity is missing, and
to react when it becomes available, or when an available one becomes
missing.

To solve this, we chose to go for a simple solution inspired by
DRM connectors: we created an ioctl for subdevs to report their
current connection status.
This allows applications to discover a sensor state when discovering
the graph.
The current status is then polled or updated on a regular basis and
reported as a uevent every time it changes, allowing applications to
react.
This mandates that the sensor driver can probe even when the device is
not connected.

This has the benefits of being fairly simple to implement, understand
and support in drivers.

The major downside however is that it will require to modify every
driver since we're breaking away from the current pattern of not
probing if the device isn't available.

The last three patches implement this pattern switch for the
imx219 driver.

With this, we can hot-plug the sensor and get notified via a udev
script to start a capture:

Oct 01 12:02:38 am69-sk run_capture[1463]: /dev/v4l-subdev6 is disconnected
[   69.258616] imx219 10-0010: Error reading reg 0x0000: -121
[   69.264182] imx219 10-0010: Error reading reg 0x0000: -121
[   71.306593] imx219 10-0010: Error reading reg 0x0000: -121
[   71.312158] imx219 10-0010: Error reading reg 0x0000: -121
Oct 01 12:02:44 am69-sk run_capture[1480]: /dev/v4l-subdev6 is connected
Oct 01 12:02:44 am69-sk run_capture[1481]: /dev/v4l-subdev6: Setting up routes
Oct 01 12:02:44 am69-sk run_capture[1487]: /dev/v4l-subdev6: Setting up format for imx219 10-0010
Oct 01 12:02:44 am69-sk run_capture[1489]: /dev/v4l-subdev6: Setting up format for remaining entities
Oct 01 12:02:44 am69-sk run_capture[1506]: /dev/v4l-subdev6: Starting capture on /dev/video5

The code for this demo is available at:
https://gitlab.com/-/snippets/6064180

Current known limitations:
- Only leaf entities (typically sensor nodes) are covered. We should
  also address entities that are in the middle of the media graph

- We don't handle the case where we attempt to stream on a disconnected
  sensor.

- The media graph is not updated to reflect the sensor's presence/absence.
  I have assumed that the media graph must reflect the hardware
  description (i.e. the device-tree) of the pipeline, not the actual
  real state (when a sensor is missing for example). Is that a wrong
  assumption?

I don't expect this approach to be useable or mergeable as is but rather
to use this as a starting point for discussions at Plumbers and on the
mailing list.

This has been tested on a SK-AM69 board on top of the following series:
https://lore.kernel.org/all/20260824121451.3348583-1-sakari.ailus@linux.intel.com/

Thanks,
Mattijs

---
Mattijs Korpershoek (5):
      media: imx219: Move LP-11 state switch to power_on()
      media: v4l2-subdev: Add new ioctl for connection status
      media: imx219: Allow driver probe with missing sensor
      media: imx219: Implement .detect() sensor operation
      media: imx219: Add status polling using .detect()

 .../userspace-api/media/v4l/user-func.rst          |   1 +
 .../v4l/vidioc-subdev-g-connection-status.rst      |  89 ++++++++++
 drivers/media/i2c/imx219.c                         | 191 ++++++++++++++-------
 drivers/media/v4l2-core/v4l2-subdev.c              |   8 +
 include/media/v4l2-subdev.h                        |   3 +
 include/uapi/linux/v4l2-subdev.h                   |  12 ++
 6 files changed, 245 insertions(+), 59 deletions(-)
---
base-commit: fe2ec83746e501645709761605c2464a44fd2929
change-id: 20260923-v4l2-sensor-detect-32a0b2936cc1

Best regards,
-- 
Mattijs Korpershoek <mkorpershoek@kernel.org>


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-10-01 17:35 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-01 12:55 [PATCH RFC 0/5] media: Fault-Tolerant V4L2 Mattijs Korpershoek
2026-10-01 12:55 ` [PATCH RFC 1/5] media: imx219: Move LP-11 state switch to power_on() Mattijs Korpershoek
2026-10-01 17:03   ` Dave Stevenson
2026-10-01 12:55 ` [PATCH RFC 2/5] media: v4l2-subdev: Add new ioctl for connection status Mattijs Korpershoek
2026-10-01 12:55 ` [PATCH RFC 3/5] media: imx219: Allow driver probe with missing sensor Mattijs Korpershoek
2026-10-01 16:50   ` Dave Stevenson
2026-10-01 17:35     ` Dave Stevenson
2026-10-01 12:55 ` [PATCH RFC 4/5] media: imx219: Implement .detect() sensor operation Mattijs Korpershoek
2026-10-01 12:55 ` [PATCH RFC 5/5] media: imx219: Add status polling using .detect() Mattijs Korpershoek
2026-10-01 15:58   ` Dave Stevenson
2026-10-01 17:26     ` Dave Stevenson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®