* [PATCH v5 01/10] media: v4l: ctrls: add a control for flash/strobe duration
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
@ 2025-06-17 7:31 ` Richard Leitner
2025-06-17 7:31 ` [PATCH v5 02/10] media: v4l2-flash: add support " Richard Leitner
` (9 subsequent siblings)
10 siblings, 0 replies; 22+ messages in thread
From: Richard Leitner @ 2025-06-17 7:31 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds,
Richard Leitner
Add a control V4L2_CID_FLASH_DURATION to set the duration of a
flash/strobe pulse. This is different to the V4L2_CID_FLASH_TIMEOUT
control, as the timeout defines a limit after which the flash is
"forcefully" turned off again.
On the other hand the new V4L2_CID_FLASH_DURATION is the desired length
of the flash/strobe pulse.
Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
---
drivers/media/v4l2-core/v4l2-ctrls-defs.c | 1 +
include/uapi/linux/v4l2-controls.h | 1 +
2 files changed, 2 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
index 1ea52011247accc51d0261f56eab1cf13c0624a0..f9ed7273a9f3eafe01c31b638e1c8d9fcf5424af 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
@@ -1135,6 +1135,7 @@ const char *v4l2_ctrl_get_name(u32 id)
case V4L2_CID_FLASH_FAULT: return "Faults";
case V4L2_CID_FLASH_CHARGE: return "Charge";
case V4L2_CID_FLASH_READY: return "Ready to Strobe";
+ case V4L2_CID_FLASH_DURATION: return "Strobe Duration";
/* JPEG encoder controls */
/* Keep the order of the 'case's the same as in v4l2-controls.h! */
diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h
index 72e32814ea83dee5f1202c1249eac7cf3b85a22a..72c6bd26e2dfa23a0224e745e5cd07c9fca0c8b5 100644
--- a/include/uapi/linux/v4l2-controls.h
+++ b/include/uapi/linux/v4l2-controls.h
@@ -1180,6 +1180,7 @@ enum v4l2_flash_strobe_source {
#define V4L2_CID_FLASH_CHARGE (V4L2_CID_FLASH_CLASS_BASE + 11)
#define V4L2_CID_FLASH_READY (V4L2_CID_FLASH_CLASS_BASE + 12)
+#define V4L2_CID_FLASH_DURATION (V4L2_CID_FLASH_CLASS_BASE + 13)
/* JPEG-class control IDs */
--
2.47.2
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v5 02/10] media: v4l2-flash: add support for flash/strobe duration
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
2025-06-17 7:31 ` [PATCH v5 01/10] media: v4l: ctrls: add a control for flash/strobe duration Richard Leitner
@ 2025-06-17 7:31 ` Richard Leitner
2025-06-17 7:31 ` [PATCH v5 03/10] media: v4l2-flash: fix flash_timeout comment Richard Leitner
` (8 subsequent siblings)
10 siblings, 0 replies; 22+ messages in thread
From: Richard Leitner @ 2025-06-17 7:31 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds,
Richard Leitner
Add support for the new V4L2_CID_FLASH_DURATION control to the v4l2
flash led class.
Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
---
drivers/media/v4l2-core/v4l2-flash-led-class.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c b/drivers/media/v4l2-core/v4l2-flash-led-class.c
index 355595a0fefac72c2f6941a30fa430d37dbdccfe..69b6c2026e0ad905aaebcdabe1e7002fc48f9e2c 100644
--- a/drivers/media/v4l2-core/v4l2-flash-led-class.c
+++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c
@@ -29,6 +29,7 @@ enum ctrl_init_data_id {
INDICATOR_INTENSITY,
FLASH_TIMEOUT,
STROBE_SOURCE,
+ FLASH_DURATION,
/*
* Only above values are applicable to
* the 'ctrls' array in the struct v4l2_flash.
@@ -298,6 +299,12 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c)
* microamperes for flash intensity units.
*/
return led_set_flash_brightness(fled_cdev, c->val);
+ case V4L2_CID_FLASH_DURATION:
+ /*
+ * No conversion is needed as LED Flash class also uses
+ * microseconds for flash duration units.
+ */
+ return led_set_flash_duration(fled_cdev, c->val);
}
return -EINVAL;
@@ -424,6 +431,14 @@ static void __fill_ctrl_init_data(struct v4l2_flash *v4l2_flash,
ctrl_cfg->flags = V4L2_CTRL_FLAG_VOLATILE |
V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;
}
+
+ /* Init FLASH_DURATION ctrl data */
+ if (has_flash_op(fled_cdev, duration_set)) {
+ ctrl_init_data[FLASH_DURATION].cid = V4L2_CID_FLASH_DURATION;
+ ctrl_cfg = &ctrl_init_data[FLASH_DURATION].config;
+ __lfs_to_v4l2_ctrl_config(&fled_cdev->duration, ctrl_cfg);
+ ctrl_cfg->id = V4L2_CID_FLASH_DURATION;
+ }
}
static int v4l2_flash_init_controls(struct v4l2_flash *v4l2_flash,
@@ -543,6 +558,16 @@ static int __sync_device_with_v4l2_controls(struct v4l2_flash *v4l2_flash)
return ret;
}
+ if (ctrls[FLASH_DURATION]) {
+ if (WARN_ON_ONCE(!fled_cdev))
+ return -EINVAL;
+
+ ret = led_set_flash_duration(fled_cdev,
+ ctrls[FLASH_DURATION]->val);
+ if (ret < 0)
+ return ret;
+ }
+
/*
* For some hardware arrangements setting strobe source may affect
* torch mode. Synchronize strobe source setting only if not in torch
--
2.47.2
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v5 03/10] media: v4l2-flash: fix flash_timeout comment
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
2025-06-17 7:31 ` [PATCH v5 01/10] media: v4l: ctrls: add a control for flash/strobe duration Richard Leitner
2025-06-17 7:31 ` [PATCH v5 02/10] media: v4l2-flash: add support " Richard Leitner
@ 2025-06-17 7:31 ` Richard Leitner
2025-06-19 9:37 ` (subset) " Lee Jones
2025-06-17 7:31 ` [PATCH v5 04/10] Documentation: uAPI: media: add V4L2_CID_FLASH_DURATION Richard Leitner
` (7 subsequent siblings)
10 siblings, 1 reply; 22+ messages in thread
From: Richard Leitner @ 2025-06-17 7:31 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds,
Richard Leitner
The comment for the flash_timeout setter mentioned it is the "flash
duration". Fix this by changing it to "flash timeout".
Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
---
include/linux/led-class-flash.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h
index 21ec856c36bc67decda46aa8ff1c040ffdcf1181..775a96217518936633541c7a5d394502dbf04f83 100644
--- a/include/linux/led-class-flash.h
+++ b/include/linux/led-class-flash.h
@@ -197,7 +197,7 @@ int led_update_flash_brightness(struct led_classdev_flash *fled_cdev);
* @fled_cdev: the flash LED to set
* @timeout: the flash timeout to set it to
*
- * Set the flash strobe duration.
+ * Set the flash strobe timeout.
*
* Returns: 0 on success or negative error value on failure
*/
--
2.47.2
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: (subset) [PATCH v5 03/10] media: v4l2-flash: fix flash_timeout comment
2025-06-17 7:31 ` [PATCH v5 03/10] media: v4l2-flash: fix flash_timeout comment Richard Leitner
@ 2025-06-19 9:37 ` Lee Jones
2025-06-19 9:38 ` Lee Jones
0 siblings, 1 reply; 22+ messages in thread
From: Lee Jones @ 2025-06-19 9:37 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart, Richard Leitner
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds
On Tue, 17 Jun 2025 09:31:37 +0200, Richard Leitner wrote:
> The comment for the flash_timeout setter mentioned it is the "flash
> duration". Fix this by changing it to "flash timeout".
>
>
Applied, thanks!
[03/10] media: v4l2-flash: fix flash_timeout comment
commit: 6012ce6b30567aa8ec8dc5b648b7841f9f74ca7c
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: (subset) [PATCH v5 03/10] media: v4l2-flash: fix flash_timeout comment
2025-06-19 9:37 ` (subset) " Lee Jones
@ 2025-06-19 9:38 ` Lee Jones
2025-07-01 6:36 ` Richard Leitner
0 siblings, 1 reply; 22+ messages in thread
From: Lee Jones @ 2025-06-19 9:38 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Pavel Machek,
Laurent Pinchart, Richard Leitner
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds
On Thu, 19 Jun 2025, Lee Jones wrote:
> On Tue, 17 Jun 2025 09:31:37 +0200, Richard Leitner wrote:
> > The comment for the flash_timeout setter mentioned it is the "flash
> > duration". Fix this by changing it to "flash timeout".
> >
> >
>
> Applied, thanks!
>
> [03/10] media: v4l2-flash: fix flash_timeout comment
> commit: 6012ce6b30567aa8ec8dc5b648b7841f9f74ca7c
I fixed the erroneous subject line on application.
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: (subset) [PATCH v5 03/10] media: v4l2-flash: fix flash_timeout comment
2025-06-19 9:38 ` Lee Jones
@ 2025-07-01 6:36 ` Richard Leitner
0 siblings, 0 replies; 22+ messages in thread
From: Richard Leitner @ 2025-07-01 6:36 UTC (permalink / raw)
To: Lee Jones
Cc: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Pavel Machek,
Laurent Pinchart, Hans Verkuil, linux-media, linux-kernel,
linux-leds
On Thu, Jun 19, 2025 at 10:38:49AM +0100, Lee Jones wrote:
> On Thu, 19 Jun 2025, Lee Jones wrote:
>
> > On Tue, 17 Jun 2025 09:31:37 +0200, Richard Leitner wrote:
> > > The comment for the flash_timeout setter mentioned it is the "flash
> > > duration". Fix this by changing it to "flash timeout".
> > >
> > >
> >
> > Applied, thanks!
> >
> > [03/10] media: v4l2-flash: fix flash_timeout comment
> > commit: 6012ce6b30567aa8ec8dc5b648b7841f9f74ca7c
>
> I fixed the erroneous subject line on application.
Thanks :-)
>
> --
> Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v5 04/10] Documentation: uAPI: media: add V4L2_CID_FLASH_DURATION
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
` (2 preceding siblings ...)
2025-06-17 7:31 ` [PATCH v5 03/10] media: v4l2-flash: fix flash_timeout comment Richard Leitner
@ 2025-06-17 7:31 ` Richard Leitner
2025-06-17 7:31 ` [PATCH v5 05/10] media: i2c: ov9282: add output enable register definitions Richard Leitner
` (6 subsequent siblings)
10 siblings, 0 replies; 22+ messages in thread
From: Richard Leitner @ 2025-06-17 7:31 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds,
Richard Leitner
Add the new strobe_duration control to v4l uAPI documentation.
Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
---
Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst b/Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst
index d22c5efb806a183a3ad67ec3e6550b002a51659a..03a58ef94be7c870f55d5a9bb09503995dbfb402 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst
@@ -186,3 +186,8 @@ Flash Control IDs
charged before strobing. LED flashes often require a cooldown period
after strobe during which another strobe will not be possible. This
is a read-only control.
+
+``V4L2_CID_FLASH_DURATION (integer)``
+ Duration the flash should be on when the flash LED is in flash mode
+ (V4L2_FLASH_LED_MODE_FLASH). The unit should be microseconds (µs)
+ if possible.
--
2.47.2
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v5 05/10] media: i2c: ov9282: add output enable register definitions
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
` (3 preceding siblings ...)
2025-06-17 7:31 ` [PATCH v5 04/10] Documentation: uAPI: media: add V4L2_CID_FLASH_DURATION Richard Leitner
@ 2025-06-17 7:31 ` Richard Leitner
2025-06-17 7:31 ` [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control Richard Leitner
` (5 subsequent siblings)
10 siblings, 0 replies; 22+ messages in thread
From: Richard Leitner @ 2025-06-17 7:31 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds,
Richard Leitner
Add #define's for the output enable registers (0x3004, 0x3005, 0x3006),
also known as SC_CTRL_04, SC_CTRL_05, SC_CTRL_04. Use those register
definitions instead of the raw values in the `common_regs` struct.
All values are based on the OV9281 datasheet v1.53 (january 2019).
Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
---
drivers/media/i2c/ov9282.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c
index c882a021cf18852237bf9b9524d3de0c5b48cbcb..f42e0d439753e74d14e3a3592029e48f49234927 100644
--- a/drivers/media/i2c/ov9282.c
+++ b/drivers/media/i2c/ov9282.c
@@ -37,6 +37,29 @@
#define OV9282_REG_ID 0x300a
#define OV9282_ID 0x9281
+/* Output enable registers */
+#define OV9282_REG_OUTPUT_ENABLE4 0x3004
+#define OV9282_OUTPUT_ENABLE4_GPIO2 BIT(1)
+#define OV9282_OUTPUT_ENABLE4_D9 BIT(0)
+
+#define OV9282_REG_OUTPUT_ENABLE5 0x3005
+#define OV9282_OUTPUT_ENABLE5_D8 BIT(7)
+#define OV9282_OUTPUT_ENABLE5_D7 BIT(6)
+#define OV9282_OUTPUT_ENABLE5_D6 BIT(5)
+#define OV9282_OUTPUT_ENABLE5_D5 BIT(4)
+#define OV9282_OUTPUT_ENABLE5_D4 BIT(3)
+#define OV9282_OUTPUT_ENABLE5_D3 BIT(2)
+#define OV9282_OUTPUT_ENABLE5_D2 BIT(1)
+#define OV9282_OUTPUT_ENABLE5_D1 BIT(0)
+
+#define OV9282_REG_OUTPUT_ENABLE6 0x3006
+#define OV9282_OUTPUT_ENABLE6_D0 BIT(7)
+#define OV9282_OUTPUT_ENABLE6_PCLK BIT(6)
+#define OV9282_OUTPUT_ENABLE6_HREF BIT(5)
+#define OV9282_OUTPUT_ENABLE6_STROBE BIT(3)
+#define OV9282_OUTPUT_ENABLE6_ILPWM BIT(2)
+#define OV9282_OUTPUT_ENABLE6_VSYNC BIT(1)
+
/* Exposure control */
#define OV9282_REG_EXPOSURE 0x3500
#define OV9282_EXPOSURE_MIN 1
@@ -213,9 +236,9 @@ static const struct ov9282_reg common_regs[] = {
{0x0302, 0x32},
{0x030e, 0x02},
{0x3001, 0x00},
- {0x3004, 0x00},
- {0x3005, 0x00},
- {0x3006, 0x04},
+ {OV9282_REG_OUTPUT_ENABLE4, 0x00},
+ {OV9282_REG_OUTPUT_ENABLE5, 0x00},
+ {OV9282_REG_OUTPUT_ENABLE6, OV9282_OUTPUT_ENABLE6_ILPWM},
{0x3011, 0x0a},
{0x3013, 0x18},
{0x301c, 0xf0},
--
2.47.2
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
` (4 preceding siblings ...)
2025-06-17 7:31 ` [PATCH v5 05/10] media: i2c: ov9282: add output enable register definitions Richard Leitner
@ 2025-06-17 7:31 ` Richard Leitner
2025-07-09 21:12 ` Sakari Ailus
2025-06-17 7:31 ` [PATCH v5 07/10] media: i2c: ov9282: add strobe_duration " Richard Leitner
` (4 subsequent siblings)
10 siblings, 1 reply; 22+ messages in thread
From: Richard Leitner @ 2025-06-17 7:31 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds,
Richard Leitner
Add V4L2_CID_FLASH_LED_MODE support using the "strobe output enable"
feature of the sensor. This implements following modes:
- V4L2_FLASH_LED_MODE_NONE, which disables the strobe output
- V4L2_FLASH_LED_MODE_FLASH, which enables the strobe output
All values are based on the OV9281 datasheet v1.53 (january 2019) and
tested using an ov9281 VisionComponents module.
Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
---
drivers/media/i2c/ov9282.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c
index f42e0d439753e74d14e3a3592029e48f49234927..b6de96997426f7225a061bfdc841aa062e8d0891 100644
--- a/drivers/media/i2c/ov9282.c
+++ b/drivers/media/i2c/ov9282.c
@@ -670,6 +670,23 @@ static int ov9282_set_ctrl_vflip(struct ov9282 *ov9282, int value)
current_val);
}
+static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode)
+{
+ u32 current_val;
+ int ret = ov9282_read_reg(ov9282, OV9282_REG_OUTPUT_ENABLE6, 1,
+ ¤t_val);
+ if (ret)
+ return ret;
+
+ if (mode == V4L2_FLASH_LED_MODE_FLASH)
+ current_val |= OV9282_OUTPUT_ENABLE6_STROBE;
+ else
+ current_val &= ~OV9282_OUTPUT_ENABLE6_STROBE;
+
+ return ov9282_write_reg(ov9282, OV9282_REG_OUTPUT_ENABLE6, 1,
+ current_val);
+}
+
/**
* ov9282_set_ctrl() - Set subdevice control
* @ctrl: pointer to v4l2_ctrl structure
@@ -736,6 +753,9 @@ static int ov9282_set_ctrl(struct v4l2_ctrl *ctrl)
ret = ov9282_write_reg(ov9282, OV9282_REG_TIMING_HTS, 2,
(ctrl->val + ov9282->cur_mode->width) >> 1);
break;
+ case V4L2_CID_FLASH_LED_MODE:
+ ret = ov9282_set_ctrl_flash_led_mode(ov9282, ctrl->val);
+ break;
default:
dev_err(ov9282->dev, "Invalid control %d", ctrl->id);
ret = -EINVAL;
@@ -1326,7 +1346,7 @@ static int ov9282_init_controls(struct ov9282 *ov9282)
u32 lpfr;
int ret;
- ret = v4l2_ctrl_handler_init(ctrl_hdlr, 10);
+ ret = v4l2_ctrl_handler_init(ctrl_hdlr, 11);
if (ret)
return ret;
@@ -1391,6 +1411,13 @@ static int ov9282_init_controls(struct ov9282 *ov9282)
OV9282_TIMING_HTS_MAX - mode->width,
1, hblank_min);
+ /* Flash/Strobe controls */
+ v4l2_ctrl_new_std_menu(ctrl_hdlr, &ov9282_ctrl_ops,
+ V4L2_CID_FLASH_LED_MODE,
+ V4L2_FLASH_LED_MODE_TORCH,
+ (1 << V4L2_FLASH_LED_MODE_TORCH),
+ V4L2_FLASH_LED_MODE_NONE);
+
ret = v4l2_fwnode_device_parse(ov9282->dev, &props);
if (!ret) {
/* Failure sets ctrl_hdlr->error, which we check afterwards anyway */
--
2.47.2
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control
2025-06-17 7:31 ` [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control Richard Leitner
@ 2025-07-09 21:12 ` Sakari Ailus
2025-07-10 6:50 ` Richard Leitner
0 siblings, 1 reply; 22+ messages in thread
From: Sakari Ailus @ 2025-07-09 21:12 UTC (permalink / raw)
To: Richard Leitner
Cc: Dave Stevenson, Mauro Carvalho Chehab, Lee Jones, Pavel Machek,
Laurent Pinchart, Hans Verkuil, linux-media, linux-kernel,
linux-leds
Hi Richard,
Thanks for the update.
On Tue, Jun 17, 2025 at 09:31:40AM +0200, Richard Leitner wrote:
> Add V4L2_CID_FLASH_LED_MODE support using the "strobe output enable"
> feature of the sensor. This implements following modes:
>
> - V4L2_FLASH_LED_MODE_NONE, which disables the strobe output
> - V4L2_FLASH_LED_MODE_FLASH, which enables the strobe output
I really think you should use a different control for this. The sensor can
strobe the flash but it won't control its mode.
How about calling it V4L2_FLASH_STROBE_ENABLE?
--
Kind regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control
2025-07-09 21:12 ` Sakari Ailus
@ 2025-07-10 6:50 ` Richard Leitner
2025-07-10 8:14 ` Sakari Ailus
0 siblings, 1 reply; 22+ messages in thread
From: Richard Leitner @ 2025-07-10 6:50 UTC (permalink / raw)
To: Sakari Ailus
Cc: Dave Stevenson, Mauro Carvalho Chehab, Lee Jones, Pavel Machek,
Laurent Pinchart, Hans Verkuil, linux-media, linux-kernel,
linux-leds
Hi Sakari,
thanks for the feedback :)
On Wed, Jul 09, 2025 at 09:12:57PM +0000, Sakari Ailus wrote:
> Hi Richard,
>
> Thanks for the update.
>
> On Tue, Jun 17, 2025 at 09:31:40AM +0200, Richard Leitner wrote:
> > Add V4L2_CID_FLASH_LED_MODE support using the "strobe output enable"
> > feature of the sensor. This implements following modes:
> >
> > - V4L2_FLASH_LED_MODE_NONE, which disables the strobe output
> > - V4L2_FLASH_LED_MODE_FLASH, which enables the strobe output
>
> I really think you should use a different control for this. The sensor can
> strobe the flash but it won't control its mode.
>
> How about calling it V4L2_FLASH_STROBE_ENABLE?
I agree on that. But tbh V4L2_FLASH_STROBE_ENABLE somehow sounds wrong
to me. As the strobe output in the ov9282 case goes high for the strobe
duration, what do you think about calling it V4L2_FLASH_STROBE_PULSE?
Or should it be V4L2_FLASH_LED_MODE_STROBE_PULSE?
Regarding disabling the strobe output: Is sticking with V4L2_FLASH_LED_MODE_NONE
fine? Or do you prefer an additional V4L2_FLASH_(MODE_)STROBE_DISABLE
or something similar?
regards;rl
>
> --
> Kind regards,
>
> Sakari Ailus
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control
2025-07-10 6:50 ` Richard Leitner
@ 2025-07-10 8:14 ` Sakari Ailus
2025-07-11 7:41 ` Richard Leitner
0 siblings, 1 reply; 22+ messages in thread
From: Sakari Ailus @ 2025-07-10 8:14 UTC (permalink / raw)
To: Richard Leitner
Cc: Dave Stevenson, Mauro Carvalho Chehab, Lee Jones, Pavel Machek,
Laurent Pinchart, Hans Verkuil, linux-media, linux-kernel,
linux-leds
Hi Richard,
On Thu, Jul 10, 2025 at 08:50:24AM +0200, Richard Leitner wrote:
> Hi Sakari,
>
> thanks for the feedback :)
>
> On Wed, Jul 09, 2025 at 09:12:57PM +0000, Sakari Ailus wrote:
> > Hi Richard,
> >
> > Thanks for the update.
> >
> > On Tue, Jun 17, 2025 at 09:31:40AM +0200, Richard Leitner wrote:
> > > Add V4L2_CID_FLASH_LED_MODE support using the "strobe output enable"
> > > feature of the sensor. This implements following modes:
> > >
> > > - V4L2_FLASH_LED_MODE_NONE, which disables the strobe output
> > > - V4L2_FLASH_LED_MODE_FLASH, which enables the strobe output
> >
> > I really think you should use a different control for this. The sensor can
> > strobe the flash but it won't control its mode.
> >
> > How about calling it V4L2_FLASH_STROBE_ENABLE?
>
> I agree on that. But tbh V4L2_FLASH_STROBE_ENABLE somehow sounds wrong
> to me. As the strobe output in the ov9282 case goes high for the strobe
> duration, what do you think about calling it V4L2_FLASH_STROBE_PULSE?
That's how the hardware strobe is supposed to work, there's nothing unusual
in that. How about V4L2_FLASH_HW_STROBE_ENABLE?
> Or should it be V4L2_FLASH_LED_MODE_STROBE_PULSE?
>
> Regarding disabling the strobe output: Is sticking with V4L2_FLASH_LED_MODE_NONE
> fine? Or do you prefer an additional V4L2_FLASH_(MODE_)STROBE_DISABLE
> or something similar?
This isn't about the LED flash mode and we shouldn't suggest it is.
--
Regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control
2025-07-10 8:14 ` Sakari Ailus
@ 2025-07-11 7:41 ` Richard Leitner
2025-07-30 20:39 ` Sakari Ailus
0 siblings, 1 reply; 22+ messages in thread
From: Richard Leitner @ 2025-07-11 7:41 UTC (permalink / raw)
To: Sakari Ailus
Cc: Dave Stevenson, Mauro Carvalho Chehab, Lee Jones, Pavel Machek,
Laurent Pinchart, Hans Verkuil, linux-media, linux-kernel,
linux-leds
Hi Sakari,
On Thu, Jul 10, 2025 at 08:14:07AM +0000, Sakari Ailus wrote:
> Hi Richard,
>
> On Thu, Jul 10, 2025 at 08:50:24AM +0200, Richard Leitner wrote:
> > Hi Sakari,
> >
> > thanks for the feedback :)
> >
> > On Wed, Jul 09, 2025 at 09:12:57PM +0000, Sakari Ailus wrote:
> > > Hi Richard,
> > >
> > > Thanks for the update.
> > >
> > > On Tue, Jun 17, 2025 at 09:31:40AM +0200, Richard Leitner wrote:
> > > > Add V4L2_CID_FLASH_LED_MODE support using the "strobe output enable"
> > > > feature of the sensor. This implements following modes:
> > > >
> > > > - V4L2_FLASH_LED_MODE_NONE, which disables the strobe output
> > > > - V4L2_FLASH_LED_MODE_FLASH, which enables the strobe output
> > >
> > > I really think you should use a different control for this. The sensor can
> > > strobe the flash but it won't control its mode.
> > >
> > > How about calling it V4L2_FLASH_STROBE_ENABLE?
> >
> > I agree on that. But tbh V4L2_FLASH_STROBE_ENABLE somehow sounds wrong
> > to me. As the strobe output in the ov9282 case goes high for the strobe
> > duration, what do you think about calling it V4L2_FLASH_STROBE_PULSE?
>
> That's how the hardware strobe is supposed to work, there's nothing unusual
> in that. How about V4L2_FLASH_HW_STROBE_ENABLE?
Ah. Sorry. I believe I completely misunderstood your previous point.
You're not referring to a new menu entry in V4L2_CID_FLASH_LED_MODE,
but rather proposing a completely new boolean control, correct?
As this would be separating the V4L2_CID's of "strobe signal source"
(aka sensor) and "strobe signal consumer" (aka flash device/LEDs), that
makes perfect sense to me now! :)
What are your thoughts on naming it V4L2_FLASH_HW_STROBE_SIGNAL?
The main reason behind removing the "ENABLE" suffix is that none of
the V4L2_CID_FLASH_* controls currently include "ENABLE" in their
names. Altough, for example, V4L2_CID_FLASH_CHARGE performs a
similar function (en-/disabling the charging of the capacitor).
On the other hand, adding "SIGNAL" to the control name, in my opinion,
makes it clearer that it only enables a signal and not some kind of
flash device or LED.
>
> > Or should it be V4L2_FLASH_LED_MODE_STROBE_PULSE?
> >
> > Regarding disabling the strobe output: Is sticking with V4L2_FLASH_LED_MODE_NONE
> > fine? Or do you prefer an additional V4L2_FLASH_(MODE_)STROBE_DISABLE
> > or something similar?
>
> This isn't about the LED flash mode and we shouldn't suggest it is.
Thanks for the clarification. I guess I got your point now :)
regards;rl
>
> --
> Regards,
>
> Sakari Ailus
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control
2025-07-11 7:41 ` Richard Leitner
@ 2025-07-30 20:39 ` Sakari Ailus
2025-08-04 13:33 ` Richard Leitner
0 siblings, 1 reply; 22+ messages in thread
From: Sakari Ailus @ 2025-07-30 20:39 UTC (permalink / raw)
To: Richard Leitner
Cc: Dave Stevenson, Mauro Carvalho Chehab, Lee Jones, Pavel Machek,
Laurent Pinchart, Hans Verkuil, linux-media, linux-kernel,
linux-leds
Hi Richard,
On Fri, Jul 11, 2025 at 09:41:52AM +0200, Richard Leitner wrote:
> Hi Sakari,
>
> On Thu, Jul 10, 2025 at 08:14:07AM +0000, Sakari Ailus wrote:
> > Hi Richard,
> >
> > On Thu, Jul 10, 2025 at 08:50:24AM +0200, Richard Leitner wrote:
> > > Hi Sakari,
> > >
> > > thanks for the feedback :)
> > >
> > > On Wed, Jul 09, 2025 at 09:12:57PM +0000, Sakari Ailus wrote:
> > > > Hi Richard,
> > > >
> > > > Thanks for the update.
> > > >
> > > > On Tue, Jun 17, 2025 at 09:31:40AM +0200, Richard Leitner wrote:
> > > > > Add V4L2_CID_FLASH_LED_MODE support using the "strobe output enable"
> > > > > feature of the sensor. This implements following modes:
> > > > >
> > > > > - V4L2_FLASH_LED_MODE_NONE, which disables the strobe output
> > > > > - V4L2_FLASH_LED_MODE_FLASH, which enables the strobe output
> > > >
> > > > I really think you should use a different control for this. The sensor can
> > > > strobe the flash but it won't control its mode.
> > > >
> > > > How about calling it V4L2_FLASH_STROBE_ENABLE?
> > >
> > > I agree on that. But tbh V4L2_FLASH_STROBE_ENABLE somehow sounds wrong
> > > to me. As the strobe output in the ov9282 case goes high for the strobe
> > > duration, what do you think about calling it V4L2_FLASH_STROBE_PULSE?
> >
> > That's how the hardware strobe is supposed to work, there's nothing unusual
> > in that. How about V4L2_FLASH_HW_STROBE_ENABLE?
>
> Ah. Sorry. I believe I completely misunderstood your previous point.
> You're not referring to a new menu entry in V4L2_CID_FLASH_LED_MODE,
> but rather proposing a completely new boolean control, correct?
Correct.
>
> As this would be separating the V4L2_CID's of "strobe signal source"
> (aka sensor) and "strobe signal consumer" (aka flash device/LEDs), that
> makes perfect sense to me now! :)
>
> What are your thoughts on naming it V4L2_FLASH_HW_STROBE_SIGNAL?
Seems reasonable.
In order to use the control, the user space would need to know when to use
it, i.e. when the latching point would be in order to hit a particular
frame. If the strobe can start before the exposure (and presumably it needs
to), the latching point is before that point of time. I wonder if pixels
(as in the pixel array) would be reasonable unit for this as well.
Does the sensor datasheet shed any light on this? It might be good to add a
control for that as well.
>
> The main reason behind removing the "ENABLE" suffix is that none of
> the V4L2_CID_FLASH_* controls currently include "ENABLE" in their
> names. Altough, for example, V4L2_CID_FLASH_CHARGE performs a
> similar function (en-/disabling the charging of the capacitor).
>
> On the other hand, adding "SIGNAL" to the control name, in my opinion,
> makes it clearer that it only enables a signal and not some kind of
> flash device or LED.
--
Kind regards,
Sakari Ailus
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control
2025-07-30 20:39 ` Sakari Ailus
@ 2025-08-04 13:33 ` Richard Leitner
0 siblings, 0 replies; 22+ messages in thread
From: Richard Leitner @ 2025-08-04 13:33 UTC (permalink / raw)
To: Sakari Ailus
Cc: Dave Stevenson, Mauro Carvalho Chehab, Lee Jones, Pavel Machek,
Laurent Pinchart, Hans Verkuil, linux-media, linux-kernel,
linux-leds
On Wed, Jul 30, 2025 at 08:39:46PM +0000, Sakari Ailus wrote:
> Hi Richard,
>
> On Fri, Jul 11, 2025 at 09:41:52AM +0200, Richard Leitner wrote:
> > Hi Sakari,
> >
> > On Thu, Jul 10, 2025 at 08:14:07AM +0000, Sakari Ailus wrote:
> > > Hi Richard,
> > >
> > > On Thu, Jul 10, 2025 at 08:50:24AM +0200, Richard Leitner wrote:
> > > > Hi Sakari,
> > > >
> > > > thanks for the feedback :)
> > > >
> > > > On Wed, Jul 09, 2025 at 09:12:57PM +0000, Sakari Ailus wrote:
> > > > > Hi Richard,
> > > > >
> > > > > Thanks for the update.
> > > > >
> > > > > On Tue, Jun 17, 2025 at 09:31:40AM +0200, Richard Leitner wrote:
> > > > > > Add V4L2_CID_FLASH_LED_MODE support using the "strobe output enable"
> > > > > > feature of the sensor. This implements following modes:
> > > > > >
> > > > > > - V4L2_FLASH_LED_MODE_NONE, which disables the strobe output
> > > > > > - V4L2_FLASH_LED_MODE_FLASH, which enables the strobe output
> > > > >
> > > > > I really think you should use a different control for this. The sensor can
> > > > > strobe the flash but it won't control its mode.
> > > > >
> > > > > How about calling it V4L2_FLASH_STROBE_ENABLE?
> > > >
> > > > I agree on that. But tbh V4L2_FLASH_STROBE_ENABLE somehow sounds wrong
> > > > to me. As the strobe output in the ov9282 case goes high for the strobe
> > > > duration, what do you think about calling it V4L2_FLASH_STROBE_PULSE?
> > >
> > > That's how the hardware strobe is supposed to work, there's nothing unusual
> > > in that. How about V4L2_FLASH_HW_STROBE_ENABLE?
> >
> > Ah. Sorry. I believe I completely misunderstood your previous point.
> > You're not referring to a new menu entry in V4L2_CID_FLASH_LED_MODE,
> > but rather proposing a completely new boolean control, correct?
>
> Correct.
>
> >
> > As this would be separating the V4L2_CID's of "strobe signal source"
> > (aka sensor) and "strobe signal consumer" (aka flash device/LEDs), that
> > makes perfect sense to me now! :)
> >
> > What are your thoughts on naming it V4L2_FLASH_HW_STROBE_SIGNAL?
>
> Seems reasonable.
Thanks again for your response. I already sent out a v6 with that
control name. I hope that's fine.
>
> In order to use the control, the user space would need to know when to use
> it, i.e. when the latching point would be in order to hit a particular
> frame. If the strobe can start before the exposure (and presumably it needs
> to), the latching point is before that point of time. I wonder if pixels
> (as in the pixel array) would be reasonable unit for this as well.
>
> Does the sensor datasheet shed any light on this? It might be good to add a
> control for that as well.
I'm not sure if pixels is a good unit for that. The strobe duration and
strobe timeout are both defined as µs. Therefore I would prefer to also
use µs for the strobe shift/offset.
The sensor features a control named "strobe shift" which allows to move the
point of time when the strobe starts before/after the start of the exposure.
I've named it V4L2_FLASH_HW_STROBE_SIGNAL_SHIFT in my downstream tree.
What do you think about it?
I have had planned to submit support for the strobe shift/offset control
as soon as this series got accepted. Mainly to keept the series smaller
and easier to handle (at least for me). Tbh I still want to stick to that
approach. Is that fine with you? Or should I include those patches
in this series?
>
> >
> > The main reason behind removing the "ENABLE" suffix is that none of
> > the V4L2_CID_FLASH_* controls currently include "ENABLE" in their
> > names. Altough, for example, V4L2_CID_FLASH_CHARGE performs a
> > similar function (en-/disabling the charging of the capacitor).
> >
> > On the other hand, adding "SIGNAL" to the control name, in my opinion,
> > makes it clearer that it only enables a signal and not some kind of
> > flash device or LED.
>
> --
> Kind regards,
>
> Sakari Ailus
Thanks again for reviewing the series!
regards;rl
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v5 07/10] media: i2c: ov9282: add strobe_duration v4l2 control
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
` (5 preceding siblings ...)
2025-06-17 7:31 ` [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control Richard Leitner
@ 2025-06-17 7:31 ` Richard Leitner
2025-06-17 7:31 ` [PATCH v5 08/10] media: i2c: ov9282: add strobe_source " Richard Leitner
` (3 subsequent siblings)
10 siblings, 0 replies; 22+ messages in thread
From: Richard Leitner @ 2025-06-17 7:31 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds,
Richard Leitner
Add V4L2_CID_FLASH_DURATION support using the "strobe_frame_span"
feature of the sensor. This is implemented by transforming the given µs
value by an interpolated formula to a "span step width" value and
writing it to register PWM_CTRL_25, PWM_CTRL_26, PWM_CTRL_27,
PWM_CTRL_28 (0x3925, 0x3926, 0x3927, 0x3928).
The maximum control value is set to the period of the current default
framerate.
All register values are based on the OV9281 datasheet v1.53 (jan 2019)
and tested using an ov9281 VisionComponents module.
Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
---
drivers/media/i2c/ov9282.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c
index b6de96997426f7225a061bfdc841aa062e8d0891..871cd7e796531c1f958790eba733290d39e99f0c 100644
--- a/drivers/media/i2c/ov9282.c
+++ b/drivers/media/i2c/ov9282.c
@@ -97,6 +97,10 @@
#define OV9282_REG_MIPI_CTRL00 0x4800
#define OV9282_GATED_CLOCK BIT(5)
+/* Flash/Strobe control registers */
+#define OV9282_REG_FLASH_DURATION 0x3925
+#define OV9282_FLASH_DURATION_DEFAULT 0x0000001a
+
/* Input clock rate */
#define OV9282_INCLK_RATE 24000000
@@ -687,6 +691,25 @@ static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode)
current_val);
}
+static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, u32 value)
+{
+ /*
+ * Calculate "strobe_frame_span" increments from a given value (µs).
+ * This is quite tricky as "The step width of shift and span is
+ * programmable under system clock domain.", but it's not documented
+ * how to program this step width (at least in the datasheet available
+ * to the author at time of writing).
+ * The formula below is interpolated from different modes/framerates
+ * and should work quite well for most settings.
+ */
+ u32 val = value * 192 / (ov9282->cur_mode->width + ov9282->hblank_ctrl->val);
+
+ ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION, 1, (val >> 24) & 0xff);
+ ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION + 1, 1, (val >> 16) & 0xff);
+ ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION + 2, 1, (val >> 8) & 0xff);
+ return ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION + 3, 1, val & 0xff);
+}
+
/**
* ov9282_set_ctrl() - Set subdevice control
* @ctrl: pointer to v4l2_ctrl structure
@@ -756,6 +779,9 @@ static int ov9282_set_ctrl(struct v4l2_ctrl *ctrl)
case V4L2_CID_FLASH_LED_MODE:
ret = ov9282_set_ctrl_flash_led_mode(ov9282, ctrl->val);
break;
+ case V4L2_CID_FLASH_DURATION:
+ ret = ov9282_set_ctrl_flash_duration(ov9282, ctrl->val);
+ break;
default:
dev_err(ov9282->dev, "Invalid control %d", ctrl->id);
ret = -EINVAL;
@@ -1346,7 +1372,7 @@ static int ov9282_init_controls(struct ov9282 *ov9282)
u32 lpfr;
int ret;
- ret = v4l2_ctrl_handler_init(ctrl_hdlr, 11);
+ ret = v4l2_ctrl_handler_init(ctrl_hdlr, 12);
if (ret)
return ret;
@@ -1418,6 +1444,9 @@ static int ov9282_init_controls(struct ov9282 *ov9282)
(1 << V4L2_FLASH_LED_MODE_TORCH),
V4L2_FLASH_LED_MODE_NONE);
+ v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION,
+ 0, 13900, 1, 8);
+
ret = v4l2_fwnode_device_parse(ov9282->dev, &props);
if (!ret) {
/* Failure sets ctrl_hdlr->error, which we check afterwards anyway */
--
2.47.2
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v5 08/10] media: i2c: ov9282: add strobe_source v4l2 control
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
` (6 preceding siblings ...)
2025-06-17 7:31 ` [PATCH v5 07/10] media: i2c: ov9282: add strobe_duration " Richard Leitner
@ 2025-06-17 7:31 ` Richard Leitner
2025-06-17 7:31 ` [PATCH v5 09/10] media: i2c: ov9282: implement try_ctrl for strobe_duration Richard Leitner
` (2 subsequent siblings)
10 siblings, 0 replies; 22+ messages in thread
From: Richard Leitner @ 2025-06-17 7:31 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds,
Richard Leitner
Add read-only V4L2_CID_FLASH_STROBE_SOURCE control. Its value is fixed
to V4L2_FLASH_STROBE_SOURCE_EXTERNAL as the camera sensor triggers the
strobe based on its register settings.
Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
---
drivers/media/i2c/ov9282.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c
index 871cd7e796531c1f958790eba733290d39e99f0c..2d77b9108bcd2499a40418919e260e7d53a9a64e 100644
--- a/drivers/media/i2c/ov9282.c
+++ b/drivers/media/i2c/ov9282.c
@@ -1368,11 +1368,12 @@ static int ov9282_init_controls(struct ov9282 *ov9282)
struct v4l2_ctrl_handler *ctrl_hdlr = &ov9282->ctrl_handler;
const struct ov9282_mode *mode = ov9282->cur_mode;
struct v4l2_fwnode_device_properties props;
+ struct v4l2_ctrl *ctrl;
u32 hblank_min;
u32 lpfr;
int ret;
- ret = v4l2_ctrl_handler_init(ctrl_hdlr, 12);
+ ret = v4l2_ctrl_handler_init(ctrl_hdlr, 13);
if (ret)
return ret;
@@ -1447,6 +1448,14 @@ static int ov9282_init_controls(struct ov9282 *ov9282)
v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION,
0, 13900, 1, 8);
+ ctrl = v4l2_ctrl_new_std_menu(ctrl_hdlr, &ov9282_ctrl_ops,
+ V4L2_CID_FLASH_STROBE_SOURCE,
+ V4L2_FLASH_STROBE_SOURCE_EXTERNAL,
+ ~(1 << V4L2_FLASH_STROBE_SOURCE_EXTERNAL),
+ V4L2_FLASH_STROBE_SOURCE_EXTERNAL);
+ if (ctrl)
+ ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
ret = v4l2_fwnode_device_parse(ov9282->dev, &props);
if (!ret) {
/* Failure sets ctrl_hdlr->error, which we check afterwards anyway */
--
2.47.2
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v5 09/10] media: i2c: ov9282: implement try_ctrl for strobe_duration
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
` (7 preceding siblings ...)
2025-06-17 7:31 ` [PATCH v5 08/10] media: i2c: ov9282: add strobe_source " Richard Leitner
@ 2025-06-17 7:31 ` Richard Leitner
2025-06-18 13:04 ` kernel test robot
2025-06-17 7:31 ` [PATCH v5 10/10] media: i2c: ov9282: dynamic flash_duration maximum Richard Leitner
2025-07-09 5:24 ` [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
10 siblings, 1 reply; 22+ messages in thread
From: Richard Leitner @ 2025-06-17 7:31 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds,
Richard Leitner
As the granularity of the hardware supported values is lower than the
control value, implement a try_ctrl() function for
V4L2_CID_FLASH_DURATION. This function calculates the nearest possible
µs strobe duration for the given value and returns it back to the
caller.
Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
---
drivers/media/i2c/ov9282.c | 54 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c
index 2d77b9108bcd2499a40418919e260e7d53a9a64e..1f4bca29cd793e99c473aff9c8b7e200e3d598bc 100644
--- a/drivers/media/i2c/ov9282.c
+++ b/drivers/media/i2c/ov9282.c
@@ -128,6 +128,8 @@
#define OV9282_REG_MIN 0x00
#define OV9282_REG_MAX 0xfffff
+#define OV9282_STROBE_SPAN_FACTOR 192
+
static const char * const ov9282_supply_names[] = {
"avdd", /* Analog power */
"dovdd", /* Digital I/O power */
@@ -691,7 +693,7 @@ static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode)
current_val);
}
-static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, u32 value)
+static u32 ov9282_us_to_flash_duration(struct ov9282 *ov9282, u32 value)
{
/*
* Calculate "strobe_frame_span" increments from a given value (µs).
@@ -702,7 +704,27 @@ static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, u32 value)
* The formula below is interpolated from different modes/framerates
* and should work quite well for most settings.
*/
- u32 val = value * 192 / (ov9282->cur_mode->width + ov9282->hblank_ctrl->val);
+ u32 frame_width = ov9282->cur_mode->width + ov9282->hblank_ctrl->val;
+
+ return value * OV9282_STROBE_SPAN_FACTOR / frame_width;
+}
+
+static u32 ov9282_flash_duration_to_us(struct ov9282 *ov9282, u32 value)
+{
+ /*
+ * As the calculation in ov9282_us_to_flash_duration uses an integer
+ * divison calculate in ns here to get more precision. Then check if
+ * we need to compensate that divison by incrementing the µs result.
+ */
+ u32 frame_width = ov9282->cur_mode->width + ov9282->hblank_ctrl->val;
+ u64 ns = value * 1000 * frame_width / OV9282_STROBE_SPAN_FACTOR;
+
+ return DIV_ROUND_UP(ns, 1000);
+}
+
+static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, u32 value)
+{
+ u32 val = ov9282_us_to_flash_duration(ov9282, value);
ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION, 1, (val >> 24) & 0xff);
ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION + 1, 1, (val >> 16) & 0xff);
@@ -792,9 +814,37 @@ static int ov9282_set_ctrl(struct v4l2_ctrl *ctrl)
return ret;
}
+static int ov9282_try_ctrl(struct v4l2_ctrl *ctrl)
+{
+ struct ov9282 *ov9282 =
+ container_of(ctrl->handler, struct ov9282, ctrl_handler);
+
+ if (ctrl->id == V4L2_CID_FLASH_DURATION) {
+ u32 fd = ov9282_us_to_flash_duration(ov9282, ctrl->val);
+ u32 us = ctrl->val;
+
+ /* get nearest strobe_duration value */
+ u32 us0 = ov9282_flash_duration_to_us(ov9282, fd);
+ u32 us1 = ov9282_flash_duration_to_us(ov9282, (fd + 1));
+
+ if (abs(us1 - us) < abs(us - us0))
+ ctrl->val = us1;
+ else
+ ctrl->val = us0;
+
+ if (us != ctrl->val) {
+ dev_dbg(ov9282->dev, "using next valid strobe_duration %u instead of %u\n",
+ ctrl->val, us);
+ }
+ }
+
+ return 0;
+}
+
/* V4l2 subdevice control ops*/
static const struct v4l2_ctrl_ops ov9282_ctrl_ops = {
.s_ctrl = ov9282_set_ctrl,
+ .try_ctrl = ov9282_try_ctrl,
};
/**
--
2.47.2
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH v5 09/10] media: i2c: ov9282: implement try_ctrl for strobe_duration
2025-06-17 7:31 ` [PATCH v5 09/10] media: i2c: ov9282: implement try_ctrl for strobe_duration Richard Leitner
@ 2025-06-18 13:04 ` kernel test robot
0 siblings, 0 replies; 22+ messages in thread
From: kernel test robot @ 2025-06-18 13:04 UTC (permalink / raw)
To: Richard Leitner, Sakari Ailus, Dave Stevenson,
Mauro Carvalho Chehab, Lee Jones, Pavel Machek, Laurent Pinchart
Cc: oe-kbuild-all, linux-media, Hans Verkuil, linux-kernel,
linux-leds, Richard Leitner
Hi Richard,
kernel test robot noticed the following build errors:
[auto build test ERROR on d9946fe286439c2aeaa7953b8c316efe5b83d515]
url: https://github.com/intel-lab-lkp/linux/commits/Richard-Leitner/media-v4l-ctrls-add-a-control-for-flash-strobe-duration/20250617-153657
base: d9946fe286439c2aeaa7953b8c316efe5b83d515
patch link: https://lore.kernel.org/r/20250617-ov9282-flash-strobe-v5-9-9762da74d065%40linux.dev
patch subject: [PATCH v5 09/10] media: i2c: ov9282: implement try_ctrl for strobe_duration
config: i386-randconfig-051-20250618 (https://download.01.org/0day-ci/archive/20250618/202506182043.reVJKofN-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250618/202506182043.reVJKofN-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506182043.reVJKofN-lkp@intel.com/
All errors (new ones prefixed by >>):
ld: drivers/media/i2c/ov9282.o: in function `ov9282_flash_duration_to_us':
>> drivers/media/i2c/ov9282.c:722: undefined reference to `__udivdi3'
>> ld: drivers/media/i2c/ov9282.c:722: undefined reference to `__udivdi3'
vim +722 drivers/media/i2c/ov9282.c
711
712 static u32 ov9282_flash_duration_to_us(struct ov9282 *ov9282, u32 value)
713 {
714 /*
715 * As the calculation in ov9282_us_to_flash_duration uses an integer
716 * divison calculate in ns here to get more precision. Then check if
717 * we need to compensate that divison by incrementing the µs result.
718 */
719 u32 frame_width = ov9282->cur_mode->width + ov9282->hblank_ctrl->val;
720 u64 ns = value * 1000 * frame_width / OV9282_STROBE_SPAN_FACTOR;
721
> 722 return DIV_ROUND_UP(ns, 1000);
723 }
724
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v5 10/10] media: i2c: ov9282: dynamic flash_duration maximum
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
` (8 preceding siblings ...)
2025-06-17 7:31 ` [PATCH v5 09/10] media: i2c: ov9282: implement try_ctrl for strobe_duration Richard Leitner
@ 2025-06-17 7:31 ` Richard Leitner
2025-07-09 5:24 ` [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
10 siblings, 0 replies; 22+ messages in thread
From: Richard Leitner @ 2025-06-17 7:31 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds,
Richard Leitner
This patch sets the current exposure time as maximum for the
flash_duration control. As Flash/Strobes which are longer than the
exposure time have no effect.
Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
---
drivers/media/i2c/ov9282.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c
index 1f4bca29cd793e99c473aff9c8b7e200e3d598bc..2fd0d63b8071d434c05a98f4d0169c4fb83f7cfe 100644
--- a/drivers/media/i2c/ov9282.c
+++ b/drivers/media/i2c/ov9282.c
@@ -198,6 +198,7 @@ struct ov9282_mode {
* @exp_ctrl: Pointer to exposure control
* @again_ctrl: Pointer to analog gain control
* @pixel_rate: Pointer to pixel rate control
+ * @flash_duration: Pointer to flash duration control
* @vblank: Vertical blanking in lines
* @noncontinuous_clock: Selection of CSI2 noncontinuous clock mode
* @cur_mode: Pointer to current selected sensor mode
@@ -220,6 +221,7 @@ struct ov9282 {
struct v4l2_ctrl *again_ctrl;
};
struct v4l2_ctrl *pixel_rate;
+ struct v4l2_ctrl *flash_duration;
u32 vblank;
bool noncontinuous_clock;
const struct ov9282_mode *cur_mode;
@@ -611,6 +613,15 @@ static int ov9282_update_controls(struct ov9282 *ov9282,
mode->vblank_max, 1, mode->vblank);
}
+static u32 ov9282_exposure_to_us(struct ov9282 *ov9282, u32 exposure)
+{
+ /* calculate exposure time in µs */
+ u32 frame_width = ov9282->cur_mode->width + ov9282->hblank_ctrl->val;
+ u32 trow_us = (frame_width * 1000000UL) / ov9282->pixel_rate->val;
+
+ return exposure * trow_us;
+}
+
/**
* ov9282_update_exp_gain() - Set updated exposure and gain
* @ov9282: pointer to ov9282 device
@@ -622,9 +633,10 @@ static int ov9282_update_controls(struct ov9282 *ov9282,
static int ov9282_update_exp_gain(struct ov9282 *ov9282, u32 exposure, u32 gain)
{
int ret;
+ u32 exposure_us = ov9282_exposure_to_us(ov9282, exposure);
- dev_dbg(ov9282->dev, "Set exp %u, analog gain %u",
- exposure, gain);
+ dev_dbg(ov9282->dev, "Set exp %u (~%u µs), analog gain %u",
+ exposure, exposure_us, gain);
ret = ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 1);
if (ret)
@@ -635,6 +647,12 @@ static int ov9282_update_exp_gain(struct ov9282 *ov9282, u32 exposure, u32 gain)
goto error_release_group_hold;
ret = ov9282_write_reg(ov9282, OV9282_REG_AGAIN, 1, gain);
+ if (ret)
+ goto error_release_group_hold;
+
+ ret = __v4l2_ctrl_modify_range(ov9282->flash_duration,
+ 0, exposure_us, 1,
+ OV9282_FLASH_DURATION_DEFAULT);
error_release_group_hold:
ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 0);
@@ -1420,6 +1438,7 @@ static int ov9282_init_controls(struct ov9282 *ov9282)
struct v4l2_fwnode_device_properties props;
struct v4l2_ctrl *ctrl;
u32 hblank_min;
+ u32 exposure_us;
u32 lpfr;
int ret;
@@ -1495,8 +1514,11 @@ static int ov9282_init_controls(struct ov9282 *ov9282)
(1 << V4L2_FLASH_LED_MODE_TORCH),
V4L2_FLASH_LED_MODE_NONE);
- v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION,
- 0, 13900, 1, 8);
+ exposure_us = ov9282_exposure_to_us(ov9282, OV9282_EXPOSURE_DEFAULT);
+ ov9282->flash_duration = v4l2_ctrl_new_std(ctrl_hdlr,
+ &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION,
+ 0, exposure_us,
+ 1, OV9282_FLASH_DURATION_DEFAULT);
ctrl = v4l2_ctrl_new_std_menu(ctrl_hdlr, &ov9282_ctrl_ops,
V4L2_CID_FLASH_STROBE_SOURCE,
--
2.47.2
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282
2025-06-17 7:31 [PATCH v5 00/10] Add strobe/flash duration v4l2 ctrl & use it for ov9282 Richard Leitner
` (9 preceding siblings ...)
2025-06-17 7:31 ` [PATCH v5 10/10] media: i2c: ov9282: dynamic flash_duration maximum Richard Leitner
@ 2025-07-09 5:24 ` Richard Leitner
10 siblings, 0 replies; 22+ messages in thread
From: Richard Leitner @ 2025-07-09 5:24 UTC (permalink / raw)
To: Sakari Ailus, Dave Stevenson, Mauro Carvalho Chehab, Lee Jones,
Pavel Machek, Laurent Pinchart
Cc: Hans Verkuil, linux-media, linux-kernel, linux-leds
Hi,
just a friendly ping on this series.
Any feedback/reviews/ack or suggestions for improvement are greatly appreciated.
Thanks!
regards;rl
On Tue, Jun 17, 2025 at 09:31:34AM +0200, Richard Leitner wrote:
> This series adds a new v4l2 controls named "strobe duration" with id
> V4L2_CID_FLASH_DURATION. This control enables setting a desired
> flash/strobe length/duration in µs.
>
> As a first user of this new control add basic flash/strobe support for
> ov9282 sensors using their "hardware strobe output". The duration
> calculation is only interpolated from various measurements, as no
> documentation was found.
>
> Further flash/strobe-related controls as well as a migration to v4l2-cci
> helpers for ov9282 will likely be implemented in future series.
>
> All register addresses/values are based on the OV9281 datasheet v1.53
> (january 2019). This series was tested using an ov9281 VisionComponents
> camera module.
>
> Signed-off-by: Richard Leitner <richard.leitner@linux.dev>
> ---
> Changes in v5:
> - Improve try_ctrl for flash_duration by using DIV_ROUND_UP() and abs() (thanks Sakari)
> - Drop "leds: flash: Add support for flash/strobe duration" as this was applied upstream
> - Add "media: i2c: ov9282: dynamic flash_duration maximum" (thanks Sakari)
> - Link to v4: https://lore.kernel.org/r/20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev
>
> Changes in v4:
> - Fix FLASH_DURATION implementation in v4l2-flash-led-class.c by adding a
> missing brace and enum entry (thanks Sakari)
> - Fix format of multiline comment in ov9282.c (thanks Sakari)
> - Add missing NULL check in ov9282.c (thanks Sakari)
> - Adapt nr_of_controls_hint for v4l2 handler in ov9282.c (thanks Sakari)
> - Add patch for implementing try_ctrl for strobe_duration (thanks Sakari)
> - Link to v3: https://lore.kernel.org/r/20250429-ov9282-flash-strobe-v3-0-2105ce179952@linux.dev
>
> Changes in v3:
> - create separate patch for leds driver changes (thanks Lee)
> - Link to v2: https://lore.kernel.org/r/20250314-ov9282-flash-strobe-v2-0-14d7a281342d@linux.dev
>
> Changes in v2:
> - remove not needed controls in struct ov9282 (thanks Dave)
> - Fix commit message of 3/3 regarding framerate get/set (thanks Dave)
> - Add V4L2_CID_FLASH_STROBE_SOURCE impementation to ov9282
> - Add new V4L2_CID_FLASH_DURATION control (as suggested by Laurent)
> - Use FLASH_DURATION instead of FLASH_TIMEOUT for ov9282
> - Link to v1: https://lore.kernel.org/r/20250303-ov9282-flash-strobe-v1-0-0fd57a1564ba@linux.dev
>
> ---
> Richard Leitner (10):
> media: v4l: ctrls: add a control for flash/strobe duration
> media: v4l2-flash: add support for flash/strobe duration
> media: v4l2-flash: fix flash_timeout comment
> Documentation: uAPI: media: add V4L2_CID_FLASH_DURATION
> media: i2c: ov9282: add output enable register definitions
> media: i2c: ov9282: add led_mode v4l2 control
> media: i2c: ov9282: add strobe_duration v4l2 control
> media: i2c: ov9282: add strobe_source v4l2 control
> media: i2c: ov9282: implement try_ctrl for strobe_duration
> media: i2c: ov9282: dynamic flash_duration maximum
>
> .../userspace-api/media/v4l/ext-ctrls-flash.rst | 5 +
> drivers/media/i2c/ov9282.c | 172 ++++++++++++++++++++-
> drivers/media/v4l2-core/v4l2-ctrls-defs.c | 1 +
> drivers/media/v4l2-core/v4l2-flash-led-class.c | 25 +++
> include/linux/led-class-flash.h | 2 +-
> include/uapi/linux/v4l2-controls.h | 1 +
> 6 files changed, 199 insertions(+), 7 deletions(-)
> ---
> base-commit: d9946fe286439c2aeaa7953b8c316efe5b83d515
> change-id: 20250303-ov9282-flash-strobe-ac6bd00c9de6
>
> Best regards,
> --
> Richard Leitner <richard.leitner@linux.dev>
>
>
^ permalink raw reply [flat|nested] 22+ messages in thread