mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mirela Rabulea <mirela.rabulea@nxp.com>
To: mchehab@kernel.org, sakari.ailus@linux.intel.com,
	hverkuil-cisco@xs4all.nl,
	laurent.pinchart+renesas@ideasonboard.com, ribalda@chromium.org,
	jai.luthra@ideasonboard.com, laurentiu.palcu@nxp.com
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	LnxRevLi@nxp.com, julien.vuillaumier@nxp.com,
	celine.laurencin@nxp.com
Subject: [RFC v2 5/5] media: v4l2-ctrls: Add __v4l2_s_ctrl_single_to_multi helper function
Date: Mon, 18 Aug 2025 18:58:09 +0300	[thread overview]
Message-ID: <20250818155809.469479-6-mirela.rabulea@nxp.com> (raw)
In-Reply-To: <20250818155809.469479-1-mirela.rabulea@nxp.com>

Helper function to be used in new sensor drivers to implement s_ctrl
for single controls for backward compatibility.

This function finds the corresponding multi-capture control for a given
single-capture control, and updates only the value corresponding to the
first capture with the same value as the single-capture control value.

Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
---

Changes in v2:
	New patch
	We need to choose either this patch or patch #4

 drivers/media/v4l2-core/v4l2-ctrls-core.c | 12 ++++++++++++
 include/media/v4l2-ctrls.h                | 17 +++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index 8d706070c041..f16809a04c29 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -2823,3 +2823,15 @@ int __v4l2_s_ctrl_multi_to_single(struct v4l2_ctrl *ctrl_multi)
 }
 EXPORT_SYMBOL(__v4l2_s_ctrl_multi_to_single);
 
+int __v4l2_s_ctrl_single_to_multi(struct v4l2_ctrl *ctrl_single)
+{
+	struct v4l2_ctrl *ctrl_multi = __v4l2_get_multi_ctrl(ctrl_single);
+
+	if (!ctrl_multi || !ctrl_single)
+		return -EINVAL;
+
+	ctrl_multi->p_cur.p_u32[0] = ctrl_single->val;
+	return __v4l2_ctrl_s_ctrl_compound(ctrl_multi, V4L2_CTRL_TYPE_U32,
+					  ctrl_multi->p_cur.p_u32);
+}
+EXPORT_SYMBOL(__v4l2_s_ctrl_single_to_multi);
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index d3a9dde47349..ea9973178556 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -1663,6 +1663,23 @@ struct v4l2_ctrl *__v4l2_get_single_ctrl(struct v4l2_ctrl *ctrl_multi);
  */
 int __v4l2_s_ctrl_multi_to_single(struct v4l2_ctrl *ctrl_multi);
 
+/**
+ * __v4l2_s_ctrl_single_to_multi() - Set the multi-capture control for a
+ *				     given single-capture control
+ *
+ * @ctrl_single: pointer to &struct v4l2_ctrl for the single-capture control
+ *
+ * This function finds the corresponding multi-capture control for a given
+ * single-capture control, and updates only the value corresponding to the
+ * first capture with the same value as the single-capture control value.
+ *
+ * This function assumes the control's handler is already locked,
+ * allowing it to be used from within the &v4l2_ctrl_ops functions.
+ *
+ * Return: 0 on success, a negative error code on failure.
+ */
+int __v4l2_s_ctrl_single_to_multi(struct v4l2_ctrl *ctrl_single);
+
 /**
  * v4l2_ctrl_type_op_equal - Default v4l2_ctrl_type_ops equal callback.
  *
-- 
2.43.0


      parent reply	other threads:[~2025-08-18 15:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-18 15:58 [RFC v2 0/5] Add standard exposure and gain controls for multiple captures Mirela Rabulea
2025-08-18 15:58 ` [RFC v2 1/5] media: Add " Mirela Rabulea
2025-08-18 15:58 ` [RFC v2 2/5] Documentation: media: Describe " Mirela Rabulea
2025-08-18 15:58 ` [RFC v2 3/5] media: v4l2-ctrls: Add v4l2 helper functions for single-capture controls Mirela Rabulea
2025-08-18 15:58 ` [RFC v2 4/5] media: v4l2-ctrls: Use the single-capture control helpers in v4l2 core Mirela Rabulea
2025-08-18 15:58 ` Mirela Rabulea [this message]

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=20250818155809.469479-6-mirela.rabulea@nxp.com \
    --to=mirela.rabulea@nxp.com \
    --cc=LnxRevLi@nxp.com \
    --cc=celine.laurencin@nxp.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jai.luthra@ideasonboard.com \
    --cc=julien.vuillaumier@nxp.com \
    --cc=laurent.pinchart+renesas@ideasonboard.com \
    --cc=laurentiu.palcu@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=ribalda@chromium.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 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®