* [RFC v2 0/5] Add standard exposure and gain controls for multiple captures
@ 2025-08-18 15:58 Mirela Rabulea
2025-08-18 15:58 ` [RFC v2 1/5] media: Add " Mirela Rabulea
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Mirela Rabulea @ 2025-08-18 15:58 UTC (permalink / raw)
To: mchehab, sakari.ailus, hverkuil-cisco, laurent.pinchart+renesas,
ribalda, jai.luthra, laurentiu.palcu
Cc: linux-media, linux-kernel, LnxRevLi, julien.vuillaumier,
celine.laurencin
All controls are in the same class.
They can be set atomically via VIDIOC_S_EXT_CTRLS, this could turn out
to be useful in case of sensors with context switching.
Each element of the array will hold an u32 value (exposure or gain)
for one capture. The size of the array is up to the sensor driver which
will implement the controls and initialize them via v4l2_ctrl_new_custom().
With this approach, the user-space will have to set valid values
for all the captures represented in the array. The order of elements inside
the array is from the longest to the shortest exposure.
The v4l2-core only supports one scalar min/max/step value for the
entire array, and each element is validated and adjusted to be within
these bounds in v4l2_ctrl_type_op_validate(). The significance for the
maximum value for the exposure control could be "the max value for the
long exposure" or "the max value for the sum of all exposures". If none
of these is ok, the sensor driver can adjust the values as supported and
the user space can use the TRY operation to query the sensor for the
minimum or maximum values.
Changes in v2:
- Update documentation according to review comments
- Patch #3 adds v4l2 helpers for backward compatibility with single-capture controls
- Patch #4 uses those helpers in the v4l2 core functions,
to aleviate the backward compatibility task from new drivers implementing
only multi-capture controls
- Patch #5 is a less aggresive alternative to patch #4, without v4l2 core
changes, but which requires more actions in the drivers, including a s_ctrl
implementation for single-capture controls, but using the helpers
- We will have to pick either patch #4 or patch #5
Mirela Rabulea (2):
media: Add exposure and gain controls for multiple captures
Documentation: media: Describe exposure and gain controls for multiple
captures
media: v4l2-ctrls: Add v4l2 helper functions for single-capture
controls
media: v4l2-ctrls: Use the single-capture control helpers in v4l2 core
media: v4l2-ctrls: Add __v4l2_s_ctrl_single_to_multi helper function
.../media/v4l/ext-ctrls-image-source.rst | 21 +++
drivers/media/v4l2-core/v4l2-ctrls-api.c | 28 +++-
drivers/media/v4l2-core/v4l2-ctrls-core.c | 120 +++++++++++++++++-
drivers/media/v4l2-core/v4l2-ctrls-defs.c | 8 ++
include/media/v4l2-ctrls.h | 93 ++++++++++++++
include/uapi/linux/v4l2-controls.h | 3 +
6 files changed, 268 insertions(+), 5 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC v2 1/5] media: Add exposure and gain controls for multiple captures
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 ` Mirela Rabulea
2025-08-18 15:58 ` [RFC v2 2/5] Documentation: media: Describe " Mirela Rabulea
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Mirela Rabulea @ 2025-08-18 15:58 UTC (permalink / raw)
To: mchehab, sakari.ailus, hverkuil-cisco, laurent.pinchart+renesas,
ribalda, jai.luthra, laurentiu.palcu
Cc: linux-media, linux-kernel, LnxRevLi, julien.vuillaumier,
celine.laurencin
Add V4L2_CID_EXPOSURE_MULTI, V4L2_CID_AGAIN_MULTI and
V4L2_CID_DGAIN_MULTI for exposure and gain control for
multiple exposure sensors.
Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
---
drivers/media/v4l2-core/v4l2-ctrls-defs.c | 8 ++++++++
include/uapi/linux/v4l2-controls.h | 3 +++
2 files changed, 11 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
index 1ea52011247a..65c468a3b01c 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
@@ -1155,6 +1155,9 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_TEST_PATTERN_BLUE: return "Blue Pixel Value";
case V4L2_CID_TEST_PATTERN_GREENB: return "Green (Blue) Pixel Value";
case V4L2_CID_NOTIFY_GAINS: return "Notify Gains";
+ case V4L2_CID_EXPOSURE_MULTI: return "Exposure, Multiple Captures";
+ case V4L2_CID_AGAIN_MULTI: return "Analog Gain, Multiple Captures";
+ case V4L2_CID_DGAIN_MULTI: return "Digital Gain, Multiple Captures";
/* Image processing controls */
/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1607,6 +1610,11 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
*type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
break;
+ case V4L2_CID_EXPOSURE_MULTI:
+ case V4L2_CID_AGAIN_MULTI:
+ case V4L2_CID_DGAIN_MULTI:
+ *type = V4L2_CTRL_TYPE_U32;
+ break;
default:
*type = V4L2_CTRL_TYPE_INTEGER;
break;
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index f836512e9deb..6583c7bdbef2 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -1226,6 +1226,9 @@ enum v4l2_jpeg_chroma_subsampling {
#define V4L2_CID_TEST_PATTERN_GREENB (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 7)
#define V4L2_CID_UNIT_CELL_SIZE (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 8)
#define V4L2_CID_NOTIFY_GAINS (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 9)
+#define V4L2_CID_EXPOSURE_MULTI (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 10)
+#define V4L2_CID_AGAIN_MULTI (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 11)
+#define V4L2_CID_DGAIN_MULTI (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 12)
/* Image processing controls */
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC v2 2/5] Documentation: media: Describe exposure and gain controls for multiple captures
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 ` Mirela Rabulea
2025-08-18 15:58 ` [RFC v2 3/5] media: v4l2-ctrls: Add v4l2 helper functions for single-capture controls Mirela Rabulea
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Mirela Rabulea @ 2025-08-18 15:58 UTC (permalink / raw)
To: mchehab, sakari.ailus, hverkuil-cisco, laurent.pinchart+renesas,
ribalda, jai.luthra, laurentiu.palcu
Cc: linux-media, linux-kernel, LnxRevLi, julien.vuillaumier,
celine.laurencin
The standard controls for exposure and gains allow a
single value, for a single capture. For sensors with HDR
capabilities or context switching, this is not enough, so
add new controls that allow multiple values, one for each
capture.
Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
---
Changes in v2:
Mention order inside array, from longest to shortest exposure
Mention not to implement the -single controls if -multi controls are implemented
.../media/v4l/ext-ctrls-image-source.rst | 21 +++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst b/Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst
index 71f23f131f97..2526d4d19cbb 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-image-source.rst
@@ -92,3 +92,24 @@ Image Source Control IDs
representing a gain of exactly 1.0. For example, if this default value
is reported as being (say) 128, then a value of 192 would represent
a gain of exactly 1.5.
+
+``V4L2_CID_EXPOSURE_MULTI (__u32 array)``
+ Same as V4L2_CID_EXPOSURE, but for multiple exposure sensors. Each
+ element of the array holds the exposure value for one capture, from
+ the longest to the shortest exposure. Drivers for HDR sensors that
+ implement the V4L2_CID_EXPOSURE_MULTI control should not implement
+ V4L2_CID_EXPOSURE.
+
+``V4L2_CID_AGAIN_MULTI (__u32 array)``
+ Same as V4L2_CID_ANALOGUE_GAIN, but for multiple exposure sensors. Each
+ element of the array holds the analog gain value for one capture, from
+ the longest to the shortest exposure. Drivers for HDR sensors that
+ implement the V4L2_CID_AGAIN_MULTI control should not implement
+ V4L2_CID_ANALOGUE_GAIN.
+
+``V4L2_CID_DGAIN_MULTI (__u32 array)``
+ Same as V4L2_CID_DIGITAL_GAIN, but for multiple exposure sensors. Each
+ element of the array holds the digital gain value for one capture, from
+ the longest to the shortest exposure. Drivers for HDR sensors that
+ implement the V4L2_CID_DGAIN_MULTI control should not implement
+ V4L2_CID_DIGITAL_GAIN.
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC v2 3/5] media: v4l2-ctrls: Add v4l2 helper functions for single-capture controls
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 ` 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 ` [RFC v2 5/5] media: v4l2-ctrls: Add __v4l2_s_ctrl_single_to_multi helper function Mirela Rabulea
4 siblings, 0 replies; 6+ messages in thread
From: Mirela Rabulea @ 2025-08-18 15:58 UTC (permalink / raw)
To: mchehab, sakari.ailus, hverkuil-cisco, laurent.pinchart+renesas,
ribalda, jai.luthra, laurentiu.palcu
Cc: linux-media, linux-kernel, LnxRevLi, julien.vuillaumier,
celine.laurencin
Add v4l2 helper functions to support backward compatibility
with older user-space applications that are still using the
single-capture exposure and gain controls.
After the addition of multi-capture exposure and gain controls,
the following scenarios are possible:
1. Old applications & old sensor drivers
Both the application and the driver are using single-capture controls,
no problem here.
2. Old applications & new sensor drivers
The application is using single-capture controls and we want the drivers
to implement only the new multi-capture controls. In this case the
driver should use the v4l2_ctrl_new_single_cap_ctrls helper to create
the old single-capture controls, for backward compatibility.
3. New application & old sensor drivers
The new application can query if the driver supports multi-capture
controls, if it doesn't, the application may fallback to single-capture
controls.
4. New application & new sensor drivers
Both the application and the driver are using multi-capture controls,
again, no problem here.
Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
---
Changes in v2:
New patch
drivers/media/v4l2-core/v4l2-ctrls-core.c | 85 +++++++++++++++++++++++
include/media/v4l2-ctrls.h | 76 ++++++++++++++++++++
2 files changed, 161 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index 98b960775e87..41f307e3afa6 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -2719,3 +2719,88 @@ int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
return hdl->error;
}
EXPORT_SYMBOL(v4l2_ctrl_new_fwnode_properties);
+
+int v4l2_ctrl_new_single_cap_ctrls(struct v4l2_ctrl_handler *hdl,
+ const struct v4l2_ctrl_ops *ctrl_ops)
+{
+ if (hdl->error)
+ return hdl->error;
+
+ v4l2_ctrl_new_std(hdl, ctrl_ops, V4L2_CID_EXPOSURE,
+ 0, 0, 1, 0);
+
+ v4l2_ctrl_new_std(hdl, ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
+ 0, 0, 1, 0);
+
+ v4l2_ctrl_new_std(hdl, ctrl_ops, V4L2_CID_DIGITAL_GAIN,
+ 0, 0, 1, 0);
+
+ return hdl->error;
+}
+EXPORT_SYMBOL(v4l2_ctrl_new_single_cap_ctrls);
+
+struct v4l2_ctrl *__v4l2_get_multi_ctrl(struct v4l2_ctrl *ctrl_single)
+{
+ struct v4l2_ctrl_handler *hdl = ctrl_single->handler;
+ struct v4l2_ctrl_ref *ref;
+
+ switch (ctrl_single->id) {
+ case V4L2_CID_EXPOSURE:
+ ref = find_ref(hdl, V4L2_CID_EXPOSURE_MULTI);
+ break;
+ case V4L2_CID_ANALOGUE_GAIN:
+ ref = find_ref(hdl, V4L2_CID_AGAIN_MULTI);
+ break;
+ case V4L2_CID_DIGITAL_GAIN:
+ ref = find_ref(hdl, V4L2_CID_DGAIN_MULTI);
+ break;
+ default:
+ return NULL;
+ }
+
+ return ref->ctrl;
+}
+EXPORT_SYMBOL(__v4l2_get_multi_ctrl);
+
+struct v4l2_ctrl *__v4l2_get_single_ctrl(struct v4l2_ctrl *ctrl_multi)
+{
+ struct v4l2_ctrl_handler *hdl = ctrl_multi->handler;
+ struct v4l2_ctrl_ref *ref;
+
+ switch (ctrl_multi->id) {
+ case V4L2_CID_EXPOSURE_MULTI:
+ ref = find_ref(hdl, V4L2_CID_EXPOSURE);
+ break;
+ case V4L2_CID_AGAIN_MULTI:
+ ref = find_ref(hdl, V4L2_CID_ANALOGUE_GAIN);
+ break;
+ case V4L2_CID_DGAIN_MULTI:
+ ref = find_ref(hdl, V4L2_CID_DIGITAL_GAIN);
+ break;
+ default:
+ return NULL;
+ }
+
+ return ref->ctrl;
+}
+EXPORT_SYMBOL(__v4l2_get_single_ctrl);
+
+int __v4l2_s_ctrl_multi_to_single(struct v4l2_ctrl *ctrl_multi)
+{
+ struct v4l2_ctrl *ctrl_single = NULL;
+
+ if (!ctrl_multi)
+ return -EINVAL;
+
+ ctrl_single = __v4l2_get_single_ctrl(ctrl_multi);
+ /* don't fail if no corresponding single control is found */
+ if (!ctrl_single)
+ return 0;
+
+ /* update the value of the single control, without calling s_ctrl */
+ ctrl_single->cur.val = ctrl_multi->p_cur.p_u32[0];
+
+ return 0;
+}
+EXPORT_SYMBOL(__v4l2_s_ctrl_multi_to_single);
+
diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
index 4a294a5c7bdd..d3a9dde47349 100644
--- a/include/media/v4l2-ctrls.h
+++ b/include/media/v4l2-ctrls.h
@@ -1587,6 +1587,82 @@ int v4l2_ctrl_new_fwnode_properties(struct v4l2_ctrl_handler *hdl,
const struct v4l2_ctrl_ops *ctrl_ops,
const struct v4l2_fwnode_device_properties *p);
+/**
+ * v4l2_ctrl_new_single_cap_ctrls() - Register single capture controls for
+ * backward compatibility
+ *
+ * @hdl: pointer to &struct v4l2_ctrl_handler to register controls on
+ * @ctrl_ops: pointer to &struct v4l2_ctrl_ops to register controls with
+ *
+ * This function registers the single capture controls for exposure
+ * and gains, for backward compatibility with userspace applications that
+ * do not use yet the new, multi-capture controls.
+ *
+ * Currently, the following v4l2 controls are parsed and registered:
+ * - V4L2_CID_EXPOSURE
+ * - V4L2_CID_ANALOGUE_GAIN
+ * - V4L2_CID_DIGITAL_GAIN;
+ *
+ * Controls already registered by the caller with the @hdl control handler are
+ * not overwritten. Callers should register the controls they want to handle
+ * themselves before calling this function.
+ *
+ * Return: 0 on success, a negative error code on failure.
+ */
+int v4l2_ctrl_new_single_cap_ctrls(struct v4l2_ctrl_handler *hdl,
+ const struct v4l2_ctrl_ops *ctrl_ops);
+
+/**
+ * __v4l2_get_multi_ctrl() - Return the multi-capture controls 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.
+ *
+ * This function assumes the control's handler is already locked,
+ * allowing it to be used from within the &v4l2_ctrl_ops functions.
+ *
+ * Return: a pointer to the multi-capture control if found, NULL otherwise.
+ */
+struct v4l2_ctrl *__v4l2_get_multi_ctrl(struct v4l2_ctrl *ctrl_single);
+
+/**
+ * __v4l2_get_single_ctrl() - Return the single-capture controls for a given
+ * multi-capture control
+ *
+ * @ctrl_multi: pointer to &struct v4l2_ctrl for the multi-capture control
+ *
+ * This function finds the corresponding single-capture control for a given
+ * multi-capture control.
+ *
+ * This function assumes the control's handler is already locked,
+ * allowing it to be used from within the &v4l2_ctrl_ops functions.
+ *
+ * Return: a pointer to the single-capture control if found, NULL otherwise.
+ */
+struct v4l2_ctrl *__v4l2_get_single_ctrl(struct v4l2_ctrl *ctrl_multi);
+
+/**
+ * __v4l2_s_ctrl_multi_to_single() - Set the single-capture control for a
+ * given multi-capture control
+ *
+ * @ctrl_multi: pointer to &struct v4l2_ctrl for the multi-capture control
+ *
+ * This function finds the corresponding single-capture control for a given
+ * multi-capture control, and updates single-capture control with the value
+ * from the first element of the multie-capture control, to ensure
+ * backward compatibility with older user-space applications that still use
+ * the single-capture exposure and gain controls.
+ *
+ * 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_multi_to_single(struct v4l2_ctrl *ctrl_multi);
+
/**
* v4l2_ctrl_type_op_equal - Default v4l2_ctrl_type_ops equal callback.
*
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC v2 4/5] media: v4l2-ctrls: Use the single-capture control helpers in v4l2 core
2025-08-18 15:58 [RFC v2 0/5] Add standard exposure and gain controls for multiple captures Mirela Rabulea
` (2 preceding siblings ...)
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 ` Mirela Rabulea
2025-08-18 15:58 ` [RFC v2 5/5] media: v4l2-ctrls: Add __v4l2_s_ctrl_single_to_multi helper function Mirela Rabulea
4 siblings, 0 replies; 6+ messages in thread
From: Mirela Rabulea @ 2025-08-18 15:58 UTC (permalink / raw)
To: mchehab, sakari.ailus, hverkuil-cisco, laurent.pinchart+renesas,
ribalda, jai.luthra, laurentiu.palcu
Cc: linux-media, linux-kernel, LnxRevLi, julien.vuillaumier,
celine.laurencin
Use the following v4l2 helpers to support backward compatibility
with single-capture controls, such that new drivers that only
implement explicitly the multi-capture control won't have to
worry about keeping them in sync with old single capture controls:
__v4l2_get_multi_ctrl
Used by the v2l2 core in try_or_set_cluster and
__v4l2_ctrl_handler_setup to redirect s_ctrl towards the multi controls
instead of single controls, so that the new sensor drivers do not need
to implement the single-capture controls in s_ctrl.
__v4l2_get_single_ctrl
Used by the v2l2 core in __v4l2_ctrl_modify_range, to modify also the
range of single-capture control when multi-capture control range
changes, so drivers won't have to worry about it.
__v4l2_s_ctrl_multi_to_single
Used by the v2l2 core in __v4l2_ctrl_s_ctrl_compound, to transparently
keep the value of single-capture control in sync with the value of the
multi-capture control, so drivers won't have to worry about it. The
__v4l2_ctrl_s_ctrl_compound() and __v4l2_ctrl_modify_range() are
usually called during sensor mode change to update the exposure
according to the current mode, the sensor driver only needs to update
the multi-controls, and the v4l2-core will update the single-controls.
Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
---
Changes in v2:
New patch
We need to choose either this patch (do as much as we can in the v4l2 core
for backward compatibility for old userspace apps using single-capture controls)
or patch #5 (let the new drivers still implement s_ctrl for single-capture controls,
but using the helpers, also driver needs to take care to keep ranges and values
in sync)
drivers/media/v4l2-core/v4l2-ctrls-api.c | 28 ++++++++++++++++++++---
drivers/media/v4l2-core/v4l2-ctrls-core.c | 23 +++++++++++++++++--
2 files changed, 46 insertions(+), 5 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c b/drivers/media/v4l2-core/v4l2-ctrls-api.c
index 49a5c7538a09..4f4cb53b8fb0 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-api.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c
@@ -947,6 +947,8 @@ EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_string);
int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
enum v4l2_ctrl_type type, const void *p)
{
+ int ret;
+
lockdep_assert_held(ctrl->handler->lock);
/* It's a driver bug if this happens. */
@@ -956,7 +958,14 @@ int __v4l2_ctrl_s_ctrl_compound(struct v4l2_ctrl *ctrl,
if (WARN_ON(ctrl->is_dyn_array))
return -EINVAL;
memcpy(ctrl->p_new.p, p, ctrl->elems * ctrl->elem_size);
- return set_ctrl(NULL, ctrl, 0);
+ ret = set_ctrl(NULL, ctrl, 0);
+ if (!ret)
+ return ret;
+ /*
+ * this can be removed when backward compatibility with legacy
+ * single exposure and gain controls is no longer needed
+ */
+ return __v4l2_s_ctrl_multi_to_single(ctrl);
}
EXPORT_SYMBOL(__v4l2_ctrl_s_ctrl_compound);
@@ -968,6 +977,7 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
{
bool value_changed;
bool range_changed = false;
+ struct v4l2_ctrl *ctrl_single = NULL;
int ret;
lockdep_assert_held(ctrl->handler->lock);
@@ -982,8 +992,11 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
case V4L2_CTRL_TYPE_U8:
case V4L2_CTRL_TYPE_U16:
case V4L2_CTRL_TYPE_U32:
- if (ctrl->is_array)
- return -EINVAL;
+ if (ctrl->is_array) {
+ ctrl_single = __v4l2_get_single_ctrl(ctrl);
+ if (!ctrl_single)
+ return -EINVAL;
+ }
ret = check_range(ctrl->type, min, max, step, def);
if (ret)
return ret;
@@ -1015,6 +1028,15 @@ int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
ret = set_ctrl(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
else if (range_changed)
send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
+ if (ret)
+ return ret;
+ /*
+ * this can be removed when backward compatibility with legacy
+ * single exposure and gain controls is no longer needed
+ */
+ if (ctrl_single)
+ ret = __v4l2_ctrl_modify_range(ctrl_single, min, max, step, def);
+
return ret;
}
EXPORT_SYMBOL(__v4l2_ctrl_modify_range);
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-core.c b/drivers/media/v4l2-core/v4l2-ctrls-core.c
index 41f307e3afa6..8d706070c041 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-core.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-core.c
@@ -2478,6 +2478,7 @@ int try_or_set_cluster(struct v4l2_fh *fh, struct v4l2_ctrl *master,
bool update_flag;
int ret;
int i;
+ struct v4l2_ctrl *master_multi = NULL;
/*
* Go through the cluster and either validate the new value or
@@ -2508,7 +2509,16 @@ int try_or_set_cluster(struct v4l2_fh *fh, struct v4l2_ctrl *master,
/* Don't set if there is no change */
if (ret || !set || !cluster_changed(master))
return ret;
- ret = call_op(master, s_ctrl);
+
+ /*
+ * for sensor drivers that no longer handle single-capture controls in
+ * s_ctrl, set the corresponding multi-capture control instead
+ */
+ master_multi = __v4l2_get_multi_ctrl(master);
+ if (master_multi)
+ ret = call_op(master_multi, s_ctrl);
+ else
+ ret = call_op(master, s_ctrl);
if (ret)
return ret;
@@ -2590,6 +2600,7 @@ int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
list_for_each_entry(ctrl, &hdl->ctrls, node) {
struct v4l2_ctrl *master = ctrl->cluster[0];
+ struct v4l2_ctrl *master_multi = __v4l2_get_multi_ctrl(master);
int i;
/* Skip if this control was already handled by a cluster. */
@@ -2605,7 +2616,15 @@ int __v4l2_ctrl_handler_setup(struct v4l2_ctrl_handler *hdl)
master->cluster[i]->done = true;
}
}
- ret = call_op(master, s_ctrl);
+ /*
+ * for sensor drivers that no longer handle single-capture
+ * controls in s_ctrl, set the corresponding multi-capture
+ * control instead
+ */
+ if (master_multi)
+ ret = call_op(master_multi, s_ctrl);
+ else
+ ret = call_op(master, s_ctrl);
if (ret)
break;
}
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC v2 5/5] media: v4l2-ctrls: Add __v4l2_s_ctrl_single_to_multi helper function
2025-08-18 15:58 [RFC v2 0/5] Add standard exposure and gain controls for multiple captures Mirela Rabulea
` (3 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: Mirela Rabulea @ 2025-08-18 15:58 UTC (permalink / raw)
To: mchehab, sakari.ailus, hverkuil-cisco, laurent.pinchart+renesas,
ribalda, jai.luthra, laurentiu.palcu
Cc: linux-media, linux-kernel, LnxRevLi, julien.vuillaumier,
celine.laurencin
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-08-18 15:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [RFC v2 5/5] media: v4l2-ctrls: Add __v4l2_s_ctrl_single_to_multi helper function Mirela Rabulea
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®