All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@kernel.org>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	 Kieran Bingham <kieran.bingham@ideasonboard.com>,
	 Sakari Ailus <sakari.ailus@linux.intel.com>,
	 Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Michael Riesch <michael.riesch@collabora.com>,
	 Dave Stevenson <dave.stevenson@raspberrypi.com>,
	 Maxime Ripard <mripard@kernel.org>,
	linux-media@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Mattijs Korpershoek <mkorpershoek@kernel.org>
Subject: [PATCH RFC 4/5] media: imx219: Implement .detect() sensor operation
Date: Thu, 01 Oct 2026 14:55:22 +0200	[thread overview]
Message-ID: <20261001-v4l2-sensor-detect-v1-4-a45993be17b8@kernel.org> (raw)
In-Reply-To: <20261001-v4l2-sensor-detect-v1-0-a45993be17b8@kernel.org>

Now that the driver can probe() with a missing sensor, userspace should
be able to query the sensor connection state from the v4l2-subdev.

Implement the .detect() sensor operation so that userspace can do that
using the VIDIOC_SUBDEV_G_CONNECTION_STATUS ioctl.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@kernel.org>
---
 drivers/media/i2c/imx219.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index aeac70123b9b..e198d3fe99c6 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -28,6 +28,7 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-fwnode.h>
 #include <media/v4l2-mediabus.h>
+#include <media/v4l2-subdev.h>
 
 /* Chip ID */
 #define IMX219_REG_CHIP_ID		CCI_REG16(0x0000)
@@ -1023,6 +1024,35 @@ static int imx219_identify_module(struct imx219 *imx219)
 	return 0;
 }
 
+static int imx219_detect(struct v4l2_subdev *sd,
+			 struct v4l2_subdev_connected_status *status)
+{
+	struct imx219 *imx219 = to_imx219(sd);
+	struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
+	struct device *dev = &client->dev;
+	int ret;
+
+	/*
+	 * The sensor must be powered for imx219_identify_module()
+	 * to be able to read the CHIP_ID register
+	 */
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret) {
+		status->status = V4L2_SUBDEV_STATUS_UNKNOWN;
+		return ret;
+	}
+
+	ret = imx219_identify_module(imx219);
+	if (ret)
+		status->status = V4L2_SUBDEV_STATUS_DISCONNECTED;
+	else
+		status->status = V4L2_SUBDEV_STATUS_CONNECTED;
+
+	pm_runtime_put_autosuspend(dev);
+
+	return 0;
+}
+
 static const struct v4l2_subdev_video_ops imx219_video_ops = {
 	.s_stream = v4l2_subdev_s_stream_helper,
 };
@@ -1037,9 +1067,14 @@ static const struct v4l2_subdev_pad_ops imx219_pad_ops = {
 	.disable_streams = imx219_disable_streams,
 };
 
+static const struct v4l2_subdev_sensor_ops imx219_sensor_ops = {
+	.detect = imx219_detect,
+};
+
 static const struct v4l2_subdev_ops imx219_subdev_ops = {
 	.video = &imx219_video_ops,
 	.pad = &imx219_pad_ops,
+	.sensor = &imx219_sensor_ops,
 };
 
 static const struct v4l2_subdev_internal_ops imx219_internal_ops = {

-- 
2.55.0


  parent reply	other threads:[~2026-10-01 12:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-02  7:13   ` Sakari Ailus
2026-10-02  8:53     ` 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-02 12:21       ` Mattijs Korpershoek
2026-10-01 12:55 ` Mattijs Korpershoek [this message]
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
2026-10-02  8:39       ` Mattijs Korpershoek
2026-10-02  7:21     ` Sakari Ailus
2026-10-02  8:45       ` Mattijs Korpershoek
2026-10-02  8:32     ` Mattijs Korpershoek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261001-v4l2-sensor-detect-v1-4-a45993be17b8@kernel.org \
    --to=mkorpershoek@kernel.org \
    --cc=dave.stevenson@raspberrypi.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=michael.riesch@collabora.com \
    --cc=mripard@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.