Add strobe duration and strobe output enable v4l2 ctrl
v10 cover Add strobe duration and strobe output enable v4l2 ctrl
This series adds two new v4l2 controls:
- V4L2_CID_FLASH_DURATION: "Strobe duration": This control enables setting a desired flash/strobe length/duration in µs.
- V4L2_CID_FLASH_STROBE_OE: "Strobe output enable": This control enables the hardware strobe output signal of a v4l2 device.
As a first user of these new controls 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.
---
Changes in v10:
- Avoid bitwise or on error codes in ov9282_set_ctrl_flash_duration() (Thanks Sakari)
- Link to v9: https://patch.msgid.link/[email protected]
Changes in v9:
- Avoid needless multiplication/division in ov9282.c (Thanks Sakari)
- Avoid possible u32 overflow in ov9282.c (Thanks Sakari)
- Link to v8: https://patch.msgid.link/[email protected]
Changes in v8:
- Minor styling changes across the set
- Add missing error handling for ov9282 strobe_frame_span writing
- Rename V4L2_CID_FLASH_HW_STROBE_SIGNAL to V4L2_CID_FLASH_STROBE_OE
- Drop 02/10: FLASH_DURATION handling in v4l2-flash
- Drop 08/10: strobe_source in ov9282
- Link to v7: https://lore.kernel.org/r/[email protected]
Changes in v7:
- Improved v4l2 uAPI documentation (thanks Sakari)
- Link to v6: https://lore.kernel.org/r/[email protected]
Changes in v6:
- Fix "Alignment should match open parenthesis" by Media-CI bot in v4l2-flash-led-class.c
- Fix "format string contains non-ascii character (µ)" by Media-CI bot in ov9282.c
- Introduce new V4L2_CID_FLASH_HW_STROBE_SIGNAL control (as suggested by Sakari)
- Implement V4L2_CID_FLASH_HW_STROBE_SIGNAL instead of
V4L2_CID_FLASH_LED_MODE in ov9282.c (as suggested by Sakari)
- Drop "media: v4l2-flash: fix flash_timeout comment" as this was
applied (thanks Lee)
- Link to v5: https://lore.kernel.org/r/[email protected]
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/[email protected]
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/[email protected]
Changes in v3:
- create separate patch for leds driver changes (thanks Lee)
- Link to v2: https://lore.kernel.org/r/[email protected]
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/[email protected]
---
Richard Leitner (8):
media: v4l: ctrls: add a control for flash/strobe duration
media: v4l: ctrls: add a control for enabling strobe output
Documentation: uAPI: media: add V4L2_CID_FLASH_{DURATION,STROBE_OE}
media: i2c: ov9282: add output enable register definitions
media: i2c: ov9282: add strobe output enable v4l2 control
media: i2c: ov9282: add strobe_duration 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 | 42 +++++ drivers/media/i2c/ov9282.c | 174 ++++++++++++++++++++- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 3 + include/uapi/linux/v4l2-controls.h | 2 + 4 files changed, 215 insertions(+), 6 deletions(-)
---
base-commit: 2f112b1c25da9f5346c2261ed35c5b1e0b906471
change-id: 20250303-ov9282-flash-strobe-ac6bd00c9de6
Best regards,
Signature · 1 line
Richard Leitner <[email protected]>
PATCH v10 1/8 media: v4l: ctrls: add a control for flash/strobe duration
Add a V4L2_CID_FLASH_DURATION control to set the duration of a flash/strobe pulse. This controls the length of the flash/strobe pulse output by device (typically a camera sensor) and connected to the flash controller. This is different to the V4L2_CID_FLASH_TIMEOUT control, which is implemented by the flash controller and defines a limit after which the flash is "forcefully" turned off again.
--- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 1 + include/uapi/linux/v4l2-controls.h | 1 + 2 files changed, 2 insertions(+)
drivers/media/v4l2-core/v4l2-ctrls-defs.c +1 -0
@@ -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! */
include/uapi/linux/v4l2-controls.h +1 -0
@@ -1186,6 +1186,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 */
Signature · 1 line
2.47.3
PATCH v10 2/8 media: v4l: ctrls: add a control for enabling strobe output
In reply to Richard LeitnerAdd a control V4L2_CID_FLASH_STROBE_OE to en- or disable the strobe output of v4l2 devices (most likely sensors).
--- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 2 ++ include/uapi/linux/v4l2-controls.h | 1 + 2 files changed, 3 insertions(+)
drivers/media/v4l2-core/v4l2-ctrls-defs.c +2 -0
@@ -1136,6 +1136,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_FLASH_CHARGE :return "Charge" ;case V4L2_CID_FLASH_READY :return "Ready to Strobe" ;case V4L2_CID_FLASH_DURATION :return "Strobe Duration" ; +case V4L2_CID_FLASH_STROBE_OE :return "Strobe Output Enable" ;/* JPEG encoder controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1282,6 +1283,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_FLASH_STROBE_STATUS :case V4L2_CID_FLASH_CHARGE :case V4L2_CID_FLASH_READY : +case V4L2_CID_FLASH_STROBE_OE :case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER :case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE :case V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE :
include/uapi/linux/v4l2-controls.h +1 -0
@@ -1187,6 +1187,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) +#define V4L2_CID_FLASH_STROBE_OE (V4L2_CID_FLASH_CLASS_BASE + 14)/* JPEG-class control IDs */
Signature · 1 line
2.47.3
PATCH v10 3/8 Documentation: uAPI: media: add V4L2_CID_FLASH_{DURATION,STROBE_OE}
In reply to Richard LeitnerAdd the new strobe duration and hardware strobe output enable to v4l uAPI documentation. Additionally add labels for cross-referencing v4l controls.
--- .../userspace-api/media/v4l/ext-ctrls-flash.rst | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst +42 -0
@@ -57,6 +57,8 @@ Flash Control IDs ``V4L2_CID_FLASH_CLASS (class)`` The FLASH class descriptor. +.. _v4l2-cid-flash-led-mode: + ``V4L2_CID_FLASH_LED_MODE (menu)`` Defines the mode of the flash LED, the high-power white LED attached to the flash controller. Setting this control may not be possible in
@@ -80,6 +82,8 @@ Flash Control IDs +.. _v4l2-cid-flash-strobe-source: + ``V4L2_CID_FLASH_STROBE_SOURCE (menu)`` Defines the source of the flash LED strobe.
@@ -96,6 +100,12 @@ Flash Control IDs - The flash strobe is triggered by an external source. Typically this is a sensor, which makes it possible to synchronise the flash strobe start to exposure start. + This method of controlling flash LED strobe has two additional + prerequisites: the strobe source's :ref:`strobe output + <v4l2-cid-flash-strobe-oe>` must be enabled (if available) + and the flash controller's :ref:`flash LED mode + <v4l2-cid-flash-led-mode>` must be set to + ``V4L2_FLASH_LED_MODE_FLASH``.
@@ -186,3 +196,35 @@ 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: + +``V4L2_CID_FLASH_DURATION (integer)`` + Duration of the flash strobe pulse generated by the strobe source, when + using external strobe. This control shall be implemented by the device + generating the hardware flash strobe signal, typically a camera sensor, + connected to a flash controller. + + The flash controllers :ref:`strobe source <v4l2-cid-flash-strobe-source>` + must be configured to ``V4L2_FLASH_STROBE_SOURCE_EXTERNAL`` for this + mode of operation. For more details please also take a look at the + documentation there. + + The unit should be microseconds (µs) if possible. + +.. _v4l2-cid-flash-strobe-oe: + +``V4L2_CID_FLASH_STROBE_OE (boolean)`` + Enables the output of a hardware strobe signal from the strobe source, + when using external strobe. This control shall be implemented by the device + generating the hardware flash strobe signal, typically a camera sensor, + connected to a flash controller. + + Provided the signal generating device driver supports it, the length of the + strobe signal can be configured by adjusting its + :ref:`flash duration <v4l2-cid-flash-duration>`. + + The flash controllers :ref:`strobe source <v4l2-cid-flash-strobe-source>` + must be configured to ``V4L2_FLASH_STROBE_SOURCE_EXTERNAL`` for this + mode of operation. For more details please also take a look at the + documentation there.
Signature · 1 line
2.47.3
PATCH v10 4/8 media: i2c: ov9282: add output enable register definitions
In reply to Richard LeitnerAdd #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).
--- drivers/media/i2c/ov9282.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
drivers/media/i2c/ov9282.c +26 -3
@@ -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},
Signature · 1 line
2.47.3
PATCH v10 5/8 media: i2c: ov9282: add strobe output enable v4l2 control
In reply to Richard LeitnerAdd V4L2_CID_FLASH_STROBE_OE enable/disable support using the "strobe output enable" feature of the sensor.
All values are based on the OV9281 datasheet v1.53 (january 2019) and tested using an ov9281 VisionComponents module.
--- drivers/media/i2c/ov9282.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/media/i2c/ov9282.c +25 -1
@@ -670,6 +670,23 @@ static int ov9282_set_ctrl_vflip(struct ov9282 *ov9282, int value) current_val); } +static int ov9282_set_ctrl_flash_strobe_oe (struct ov9282 *ov9282,bool enable) +{ +u32 current_val; +int ret; + + ret =ov9282_read_reg (ov9282,OV9282_REG_OUTPUT_ENABLE6 ,1 , ¤t_val); +if (ret) +return ret; + +if (enable) + 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_STROBE_OE : + ret =ov9282_set_ctrl_flash_strobe_oe (ov9282, ctrl->val); +break ;default :dev_err (ov9282->dev,"Invalid control %d" , ctrl->id); ret = -EINVAL ;
@@ -1325,7 +1345,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;
@@ -1390,6 +1410,10 @@ static int ov9282_init_controls(struct ov9282 *ov9282)OV9282_TIMING_HTS_MAX - mode->width, 1, hblank_min); +/* Flash/Strobe controls */ +v4l2_ctrl_new_std (ctrl_hdlr, &ov9282_ctrl_ops, +V4L2_CID_FLASH_STROBE_OE ,0 ,1 ,1 ,0 ); + ret =v4l2_fwnode_device_parse (ov9282->dev, &props);if (!ret) {/* Failure sets ctrl_hdlr->error, which we check afterwards anyway */
Signature · 1 line
2.47.3
PATCH v10 6/8 media: i2c: ov9282: add strobe_duration v4l2 control
In reply to Richard LeitnerAdd 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.
--- drivers/media/i2c/ov9282.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
drivers/media/i2c/ov9282.c +45 -1
@@ -97,6 +97,10 @@#define OV9282_REG_MIPI_CTRL00 0x4800#define OV9282_GATED_CLOCK BIT(5) +/* Flash/Strobe control registers */ +#define OV9282_REG_STROBE_FRAME_SPAN 0x3925 +#define OV9282_STROBE_FRAME_SPAN_DEFAULT 0x0000001a +/* Input clock rate */ #define OV9282_INCLK_RATE 24000000
@@ -687,6 +691,40 @@ static int ov9282_set_ctrl_flash_strobe_oe(struct ov9282 *ov9282, bool enable)return ov9282_write_reg (ov9282,OV9282_REG_OUTPUT_ENABLE6 ,1 , current_val); } +static int ov9282_set_ctrl_flash_duration (struct ov9282 *ov9282,u32 value) +{ +int ret; +/* +* 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); + + ret =ov9282_write_reg (ov9282,OV9282_REG_STROBE_FRAME_SPAN ,1 , + (val >>24 ) &0xff ); +if (ret) +return ret; + + ret =ov9282_write_reg (ov9282,OV9282_REG_STROBE_FRAME_SPAN +1 ,1 , + (val >>16 ) &0xff ); +if (ret) +return ret; + + ret =ov9282_write_reg (ov9282,OV9282_REG_STROBE_FRAME_SPAN +2 ,1 , + (val >>8 ) &0xff ); +if (ret) +return ret; + + ret =ov9282_write_reg (ov9282,OV9282_REG_STROBE_FRAME_SPAN +3 ,1 , + val &0xff ); +return ret; +} +/** * ov9282_set_ctrl() - Set subdevice control * @ctrl: pointer to v4l2_ctrl structure
@@ -756,6 +794,9 @@ static int ov9282_set_ctrl(struct v4l2_ctrl *ctrl)case V4L2_CID_FLASH_STROBE_OE : ret =ov9282_set_ctrl_flash_strobe_oe (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 ;
@@ -1345,7 +1386,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;
@@ -1414,6 +1455,9 @@ static int ov9282_init_controls(struct ov9282 *ov9282)v4l2_ctrl_new_std (ctrl_hdlr, &ov9282_ctrl_ops,V4L2_CID_FLASH_STROBE_OE ,0 ,1 ,1 ,0 ); +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 */
Signature · 1 line
2.47.3
PATCH v10 7/8 media: i2c: ov9282: implement try_ctrl for strobe_duration
In reply to Richard LeitnerAs 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.
--- drivers/media/i2c/ov9282.c | 55 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-)
drivers/media/i2c/ov9282.c +52 -3
@@ -9,6 +9,7 @@#include <linux/clk.h> #include <linux/delay.h> #include <linux/i2c.h> +#include <linux/math.h> #include <linux/module.h> #include <linux/pm_runtime.h> #include <linux/regulator/consumer.h>
@@ -128,6 +129,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,9 +694,8 @@ static int ov9282_set_ctrl_flash_strobe_oe(struct ov9282 *ov9282, bool enable)return ov9282_write_reg (ov9282,OV9282_REG_OUTPUT_ENABLE6 ,1 , 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) { -int ret;/* * Calculate "strobe_frame_span" increments from a given value (µs). * This is quite tricky as "The step width of shift and span is
@@ -703,7 +705,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) +{ +/* +* Calculate back to microseconds from "strobe_frame_span" increments. +* As the calculation in ov9282_us_to_flash_duration uses an integer +* divison round up here. +*/ +u32 frame_width = ov9282->cur_mode->width + ov9282->hblank_ctrl->val; + +return DIV_ROUND_UP (value * frame_width,OV9282_STROBE_SPAN_FACTOR ); +} + +static int ov9282_set_ctrl_flash_duration (struct ov9282 *ov9282,u32 value) +{ +int ret; +u32 val =ov9282_us_to_flash_duration (ov9282, value); ret =ov9282_write_reg (ov9282,OV9282_REG_STROBE_FRAME_SPAN ,1 , (val >>24 ) &0xff );
@@ -807,9 +829,36 @@ 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_const(ctrl->handler, struct ov9282, ctrl_handler); + +if (ctrl->id ==V4L2_CID_FLASH_DURATION ) { +u32 us = ctrl->val; +u32 fd =ov9282_us_to_flash_duration (ov9282, us); + +/* 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, };/**
Signature · 1 line
2.47.3
PATCH v10 8/8 media: i2c: ov9282: dynamic flash_duration maximum
In reply to Richard LeitnerThis 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.
--- drivers/media/i2c/ov9282.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-)
drivers/media/i2c/ov9282.c +26 -4
@@ -199,6 +199,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
@@ -221,6 +222,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;
@@ -612,6 +614,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 / (ov9282->pixel_rate->val /1000000UL ); + +return exposure * trow_us; +} +/** * ov9282_update_exp_gain() - Set updated exposure and gain * @ov9282: pointer to ov9282 device
@@ -623,9 +634,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 us), analog gain %u" , + exposure, exposure_us, gain); ret =ov9282_write_reg (ov9282,OV9282_REG_HOLD ,1 ,1 );if (ret)
@@ -636,6 +648,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_STROBE_FRAME_SPAN_DEFAULT ); error_release_group_hold:ov9282_write_reg (ov9282,OV9282_REG_HOLD ,1 ,0 );
@@ -1432,6 +1450,7 @@ static int ov9282_init_controls(struct ov9282 *ov9282)const struct ov9282_mode *mode = ov9282->cur_mode;struct v4l2_fwnode_device_properties props;u32 hblank_min; +u32 exposure_us;u32 lpfr;int ret;
@@ -1504,8 +1523,11 @@ static int ov9282_init_controls(struct ov9282 *ov9282)v4l2_ctrl_new_std (ctrl_hdlr, &ov9282_ctrl_ops,V4L2_CID_FLASH_STROBE_OE ,0 ,1 ,1 ,0 ); -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_STROBE_FRAME_SPAN_DEFAULT ); ret =v4l2_fwnode_device_parse (ov9282->dev, &props);if (!ret) {
Signature · 1 line
2.47.3
Hi everybody,
just a friendly ping before the holiday season kicks in :-)
regards;rl
Quoted 103 lines · Richard Leitner
This series adds two new v4l2 controls:
-V4L2_CID_FLASH_DURATION: "Strobe duration": This control enables setting a desired flash/strobe length/duration in µs.
-V4L2_CID_FLASH_STROBE_OE: "Strobe output enable": This control enables the hardware strobe output signal of a v4l2 device.As a first user of these new controls 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 <[email protected]>---
Changes in v10:
- Avoid bitwise or on error codes inov9282_set_ctrl_flash_duration()(Thanks Sakari)
- Link to v9: https://patch.msgid.link/[email protected]Changes in v9:
- Avoid needless multiplication/division inov9282.c(Thanks Sakari)
- Avoid possible u32 overflow inov9282.c(Thanks Sakari)
- Link to v8: https://patch.msgid.link/[email protected]Changes in v8:
- Minor styling changes across the set
- Add missing error handling for ov9282strobe_frame_spanwriting
- RenameV4L2_CID_FLASH_HW_STROBE_SIGNALtoV4L2_CID_FLASH_STROBE_OE
- Drop 02/10:FLASH_DURATIONhandling in v4l2-flash
- Drop 08/10:strobe_sourcein ov9282
- Link to v7: https://lore.kernel.org/r/[email protected]Changes in v7:
- Improved v4l2 uAPI documentation (thanks Sakari)
- Link to v6: https://lore.kernel.org/r/[email protected]Changes in v6:
- Fix "Alignment should match open parenthesis" by Media-CI bot inv4l2-flash-led-class.c
- Fix "format string contains non-ascii character (µ)" by Media-CI bot inov9282.c
- Introduce newV4L2_CID_FLASH_HW_STROBE_SIGNALcontrol (as suggested by Sakari)
- ImplementV4L2_CID_FLASH_HW_STROBE_SIGNALinstead of
V4L2_CID_FLASH_LED_MODEinov9282.c(as suggested by Sakari)
- Drop "media: v4l2-flash: fixflash_timeoutcomment" as this was
applied (thanks Lee)
- Link to v5: https://lore.kernel.org/r/[email protected]Changes in v5:
- Improvetry_ctrlforflash_durationby usingDIV_ROUND_UP()andabs()(thanks Sakari)
- Drop "leds: flash: Add support for flash/strobe duration" as this was applied upstream
- Add "media: i2c: ov9282: dynamicflash_durationmaximum" (thanks Sakari)
- Link to v4: https://lore.kernel.org/r/[email protected]Changes in v4:
- FixFLASH_DURATIONimplementation inv4l2-flash-led-class.cby adding a missing brace and enum entry (thanks Sakari)
- Fix format of multiline comment inov9282.c(thanks Sakari)
- Add missing NULL check inov9282.c(thanks Sakari)
- Adaptnr_of_controls_hintfor v4l2 handler inov9282.c(thanks Sakari)
- Add patch for implementingtry_ctrlforstrobe_duration(thanks Sakari)
- Link to v3: https://lore.kernel.org/r/[email protected]Changes in v3:
- create separate patch for leds driver changes (thanks Lee)
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- remove not needed controls in struct ov9282 (thanks Dave)
- Fix commit message of 3/3 regarding framerate get/set (thanks Dave)
- AddV4L2_CID_FLASH_STROBE_SOURCEimpementation to ov9282
- Add newV4L2_CID_FLASH_DURATIONcontrol (as suggested by Laurent)
- UseFLASH_DURATIONinstead ofFLASH_TIMEOUTfor ov9282
- Link to v1: https://lore.kernel.org/r/[email protected]---
Richard Leitner (8):
media: v4l: ctrls: add a control for flash/strobe duration
media: v4l: ctrls: add a control for enabling strobe output
Documentation: uAPI: media: add V4L2_CID_FLASH_{DURATION,STROBE_OE}
media: i2c: ov9282: add output enable register definitions
media: i2c: ov9282: add strobe output enable v4l2 control
media: i2c: ov9282: addstrobe_durationv4l2 control
media: i2c: ov9282: implementtry_ctrlforstrobe_duration
media: i2c: ov9282: dynamicflash_durationmaximum.../userspace-api/media/v4l/ext-ctrls-flash.rst | 42 +++++ drivers/media/i2c/ov9282.c | 174 ++++++++++++++++++++- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 3 + include/uapi/linux/v4l2-controls.h | 2 + 4 files changed, 215 insertions(+), 6 deletions(-)---
base-commit:2f112b1c25da9f5346c2261ed35c5b1e0b906471
change-id: 20250303-ov9282-flash-strobe-ac6bd00c9de6Best regards,
Signature · 1 line
Richard Leitner <[email protected]>
Hi again,
just wanted to mention that I'll be doing a short (10 min) talk on this topic at FOSDEM 2026 in the Embedded, Mobile and Automotive devroom on
sunday: https://fosdem.org/2026/schedule/event/A7P7XE-v4l2-flash-control/
Would be great if I could get some more - maybe final ;) - review on this series before FOSDEM. Thanks!
regards;rl
Quoted 110 lines · Richard Leitner
Hi everybody,
just a friendly ping before the holiday season kicks in :-)
regards;rl
Quoted 103 lines · Richard Leitner
This series adds two new v4l2 controls:
-V4L2_CID_FLASH_DURATION: "Strobe duration": This control enables setting a desired flash/strobe length/duration in µs.
-V4L2_CID_FLASH_STROBE_OE: "Strobe output enable": This control enables the hardware strobe output signal of a v4l2 device.As a first user of these new controls 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 <[email protected]>---
Changes in v10:
- Avoid bitwise or on error codes inov9282_set_ctrl_flash_duration()(Thanks Sakari)
- Link to v9: https://patch.msgid.link/[email protected]Changes in v9:
- Avoid needless multiplication/division inov9282.c(Thanks Sakari)
- Avoid possible u32 overflow inov9282.c(Thanks Sakari)
- Link to v8: https://patch.msgid.link/[email protected]Changes in v8:
- Minor styling changes across the set
- Add missing error handling for ov9282strobe_frame_spanwriting
- RenameV4L2_CID_FLASH_HW_STROBE_SIGNALtoV4L2_CID_FLASH_STROBE_OE
- Drop 02/10:FLASH_DURATIONhandling in v4l2-flash
- Drop 08/10:strobe_sourcein ov9282
- Link to v7: https://lore.kernel.org/r/[email protected]Changes in v7:
- Improved v4l2 uAPI documentation (thanks Sakari)
- Link to v6: https://lore.kernel.org/r/[email protected]Changes in v6:
- Fix "Alignment should match open parenthesis" by Media-CI bot inv4l2-flash-led-class.c
- Fix "format string contains non-ascii character (µ)" by Media-CI bot inov9282.c
- Introduce newV4L2_CID_FLASH_HW_STROBE_SIGNALcontrol (as suggested by Sakari)
- ImplementV4L2_CID_FLASH_HW_STROBE_SIGNALinstead of
V4L2_CID_FLASH_LED_MODEinov9282.c(as suggested by Sakari)
- Drop "media: v4l2-flash: fixflash_timeoutcomment" as this was
applied (thanks Lee)
- Link to v5: https://lore.kernel.org/r/[email protected]Changes in v5:
- Improvetry_ctrlforflash_durationby usingDIV_ROUND_UP()andabs()(thanks Sakari)
- Drop "leds: flash: Add support for flash/strobe duration" as this was applied upstream
- Add "media: i2c: ov9282: dynamicflash_durationmaximum" (thanks Sakari)
- Link to v4: https://lore.kernel.org/r/[email protected]Changes in v4:
- FixFLASH_DURATIONimplementation inv4l2-flash-led-class.cby adding a missing brace and enum entry (thanks Sakari)
- Fix format of multiline comment inov9282.c(thanks Sakari)
- Add missing NULL check inov9282.c(thanks Sakari)
- Adaptnr_of_controls_hintfor v4l2 handler inov9282.c(thanks Sakari)
- Add patch for implementingtry_ctrlforstrobe_duration(thanks Sakari)
- Link to v3: https://lore.kernel.org/r/[email protected]Changes in v3:
- create separate patch for leds driver changes (thanks Lee)
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- remove not needed controls in struct ov9282 (thanks Dave)
- Fix commit message of 3/3 regarding framerate get/set (thanks Dave)
- AddV4L2_CID_FLASH_STROBE_SOURCEimpementation to ov9282
- Add newV4L2_CID_FLASH_DURATIONcontrol (as suggested by Laurent)
- UseFLASH_DURATIONinstead ofFLASH_TIMEOUTfor ov9282
- Link to v1: https://lore.kernel.org/r/[email protected]---
Richard Leitner (8):
media: v4l: ctrls: add a control for flash/strobe duration
media: v4l: ctrls: add a control for enabling strobe output
Documentation: uAPI: media: add V4L2_CID_FLASH_{DURATION,STROBE_OE}
media: i2c: ov9282: add output enable register definitions
media: i2c: ov9282: add strobe output enable v4l2 control
media: i2c: ov9282: addstrobe_durationv4l2 control
media: i2c: ov9282: implementtry_ctrlforstrobe_duration
media: i2c: ov9282: dynamicflash_durationmaximum.../userspace-api/media/v4l/ext-ctrls-flash.rst | 42 +++++ drivers/media/i2c/ov9282.c | 174 ++++++++++++++++++++- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 3 + include/uapi/linux/v4l2-controls.h | 2 + 4 files changed, 215 insertions(+), 6 deletions(-)---
base-commit:2f112b1c25da9f5346c2261ed35c5b1e0b906471
change-id: 20250303-ov9282-flash-strobe-ac6bd00c9de6Best regards,
Signature · 1 line
Richard Leitner <[email protected]>
Hi Sakari, Hi Laurent,
first of all, happy new year 2026 to all of you.
I hope you had a good start to the new year?
Regarding this series: Perhaps you've made it your New Year's resolution to give it another round of review? ;-) Would be great to get some more feedback (or Reviewed-By's).
regards;rl
Quoted 122 lines · Richard Leitner
Hi again,
just wanted to mention that I'll be doing a short (10 min) talk on this topic at FOSDEM 2026 in the Embedded, Mobile and Automotive devroom on
sunday: https://fosdem.org/2026/schedule/event/A7P7XE-v4l2-flash-control/Would be great if I could get some more - maybe final ;) - review on this series before FOSDEM. Thanks!
regards;rl
Quoted 110 lines · Richard Leitner
Hi everybody,
just a friendly ping before the holiday season kicks in :-)
regards;rl
Quoted 103 lines · Richard Leitner
This series adds two new v4l2 controls:
-V4L2_CID_FLASH_DURATION: "Strobe duration": This control enables setting a desired flash/strobe length/duration in µs.
-V4L2_CID_FLASH_STROBE_OE: "Strobe output enable": This control enables the hardware strobe output signal of a v4l2 device.As a first user of these new controls 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 <[email protected]>---
Changes in v10:
- Avoid bitwise or on error codes inov9282_set_ctrl_flash_duration()(Thanks Sakari)
- Link to v9: https://patch.msgid.link/[email protected]Changes in v9:
- Avoid needless multiplication/division inov9282.c(Thanks Sakari)
- Avoid possible u32 overflow inov9282.c(Thanks Sakari)
- Link to v8: https://patch.msgid.link/[email protected]Changes in v8:
- Minor styling changes across the set
- Add missing error handling for ov9282strobe_frame_spanwriting
- RenameV4L2_CID_FLASH_HW_STROBE_SIGNALtoV4L2_CID_FLASH_STROBE_OE
- Drop 02/10:FLASH_DURATIONhandling in v4l2-flash
- Drop 08/10:strobe_sourcein ov9282
- Link to v7: https://lore.kernel.org/r/[email protected]Changes in v7:
- Improved v4l2 uAPI documentation (thanks Sakari)
- Link to v6: https://lore.kernel.org/r/[email protected]Changes in v6:
- Fix "Alignment should match open parenthesis" by Media-CI bot inv4l2-flash-led-class.c
- Fix "format string contains non-ascii character (µ)" by Media-CI bot inov9282.c
- Introduce newV4L2_CID_FLASH_HW_STROBE_SIGNALcontrol (as suggested by Sakari)
- ImplementV4L2_CID_FLASH_HW_STROBE_SIGNALinstead of
V4L2_CID_FLASH_LED_MODEinov9282.c(as suggested by Sakari)
- Drop "media: v4l2-flash: fixflash_timeoutcomment" as this was
applied (thanks Lee)
- Link to v5: https://lore.kernel.org/r/[email protected]Changes in v5:
- Improvetry_ctrlforflash_durationby usingDIV_ROUND_UP()andabs()(thanks Sakari)
- Drop "leds: flash: Add support for flash/strobe duration" as this was applied upstream
- Add "media: i2c: ov9282: dynamicflash_durationmaximum" (thanks Sakari)
- Link to v4: https://lore.kernel.org/r/[email protected]Changes in v4:
- FixFLASH_DURATIONimplementation inv4l2-flash-led-class.cby adding a missing brace and enum entry (thanks Sakari)
- Fix format of multiline comment inov9282.c(thanks Sakari)
- Add missing NULL check inov9282.c(thanks Sakari)
- Adaptnr_of_controls_hintfor v4l2 handler inov9282.c(thanks Sakari)
- Add patch for implementingtry_ctrlforstrobe_duration(thanks Sakari)
- Link to v3: https://lore.kernel.org/r/[email protected]Changes in v3:
- create separate patch for leds driver changes (thanks Lee)
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- remove not needed controls in struct ov9282 (thanks Dave)
- Fix commit message of 3/3 regarding framerate get/set (thanks Dave)
- AddV4L2_CID_FLASH_STROBE_SOURCEimpementation to ov9282
- Add newV4L2_CID_FLASH_DURATIONcontrol (as suggested by Laurent)
- UseFLASH_DURATIONinstead ofFLASH_TIMEOUTfor ov9282
- Link to v1: https://lore.kernel.org/r/[email protected]---
Richard Leitner (8):
media: v4l: ctrls: add a control for flash/strobe duration
media: v4l: ctrls: add a control for enabling strobe output
Documentation: uAPI: media: add V4L2_CID_FLASH_{DURATION,STROBE_OE}
media: i2c: ov9282: add output enable register definitions
media: i2c: ov9282: add strobe output enable v4l2 control
media: i2c: ov9282: addstrobe_durationv4l2 control
media: i2c: ov9282: implementtry_ctrlforstrobe_duration
media: i2c: ov9282: dynamicflash_durationmaximum.../userspace-api/media/v4l/ext-ctrls-flash.rst | 42 +++++ drivers/media/i2c/ov9282.c | 174 ++++++++++++++++++++- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 3 + include/uapi/linux/v4l2-controls.h | 2 + 4 files changed, 215 insertions(+), 6 deletions(-)---
base-commit:2f112b1c25da9f5346c2261ed35c5b1e0b906471
change-id: 20250303-ov9282-flash-strobe-ac6bd00c9de6Best regards,
Signature · 1 line
Richard Leitner <[email protected]>
Sakari Ailus
maintainerHi Richard,
Quoted 8 lines · Richard Leitner
Hi Sakari, Hi Laurent,
first of all, happy new year 2026 to all of you.
I hope you had a good start to the new year?Regarding this series: Perhaps you've made it your New Year's resolution to give it another round of review? ;-) Would be great to get some more feedback (or Reviewed-By's).
Thanks for the ping. I thought this was already merged... oh well. It's in my cleanup branch now.
Thank you for your efforts on this. Having these controls really improves the flash LED control APIs; hopefully there would be also more users for these as well.
Signature · 3 lines
Kind regards, Sakari Ailus
Hi Sakari,
Quoted 8 lines · Sakari Ailus
Hi Richard,
Quoted 5 lines · Richard Leitner
Hi Sakari, Hi Laurent,
first of all, happy new year 2026 to all of you.
I hope you had a good start to the new year?
Quoted 6 lines
Quoted 3 lines
Regarding this series: Perhaps you've made it your New Year's resolution to give it another round of review? ;-) Would be great to get some more feedback (or Reviewed-By's).
Thanks for the ping. I thought this was already merged... oh well. It's in my cleanup branch now.
That's great news! Thanks. If there's anything I need/should do, please reach out.
Quoted 4 lines
Thank you for your efforts on this. Having these controls really improves the flash LED control APIs; hopefully there would be also more users for these as well.
Thank you for reviewing this series and being patient. I learned a lot between v1 and v10 ;-)
Regarding adoption of this new controls: I will do my best to promote
it: https://fosdem.org/2026/schedule/event/A7P7XE-v4l2-flash-control/
;-)
regards;rl
Quoted 5 lines
Signature · 4 lines
-- Kind regards, Sakari Ailus