Add strobe/flash duration v4l2 ctrl & use it for ov9282
v3 cover Add strobe/flash duration v4l2 ctrl & use it for ov9282
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.
---
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 (9):
media: v4l: ctrls: add a control for flash/strobe duration
leds: flash: add support for flash/stobe 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
.../userspace-api/media/v4l/ext-ctrls-flash.rst | 5 ++ drivers/leds/led-class-flash.c | 15 ++++ drivers/media/i2c/ov9282.c | 92 +++++++++++++++++++++- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 1 + drivers/media/v4l2-core/v4l2-flash-led-class.c | 13 +++ include/linux/led-class-flash.h | 18 ++++- include/uapi/linux/v4l2-controls.h | 1 + 7 files changed, 141 insertions(+), 4 deletions(-)
---
base-commit: ca91b9500108d4cf083a635c2e11c884d5dd20ea
change-id: 20250303-ov9282-flash-strobe-ac6bd00c9de6
prerequisite-change-id: 20250225-b4-ov9282-gain-ef1cdaba5bfd:v1
prerequisite-patch-id: 86f2582378ff7095ab65ce4bb25a143eb639e840
prerequisite-patch-id: b06eb6ec697aaf0b3155b4b2370f171d0d304ae2
prerequisite-patch-id: b123047d71bfb9b93f743bbdd6893d5a98495801
Best regards,
Signature · 1 line
Richard Leitner <[email protected]>
PATCH v3 1/9 media: v4l: ctrls: add a control for flash/strobe duration
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.
--- 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
@@ -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 */
Signature · 1 line
2.47.2
PATCH v3 2/9 leds: flash: add support for flash/stobe duration
In reply to Richard LeitnerAdd support for the new V4L2_CID_FLASH_DURATION control to the leds driver.
--- drivers/leds/led-class-flash.c | 15 +++++++++++++++ include/linux/led-class-flash.h | 16 ++++++++++++++++ 2 files changed, 31 insertions(+)
drivers/leds/led-class-flash.c +15 -0
@@ -440,6 +440,21 @@ int led_update_flash_brightness(struct led_classdev_flash *fled_cdev) }EXPORT_SYMBOL_GPL (led_update_flash_brightness); +int led_set_flash_duration (struct led_classdev_flash *fled_cdev,u32 duration) +{ +struct led_classdev *led_cdev = &fled_cdev->led_cdev; +struct led_flash_setting *s = &fled_cdev->duration; + + s->val = duration; +led_clamp_align (s); + +if (!(led_cdev->flags &LED_SUSPENDED )) +return call_flash_op (fled_cdev, duration_set, s->val); + +return 0 ; +} +EXPORT_SYMBOL_GPL (led_set_flash_duration); +MODULE_AUTHOR ("Jacek Anaszewski <[email protected]>" );MODULE_DESCRIPTION ("LED Flash class interface" );MODULE_LICENSE ("GPL v2" );
include/linux/led-class-flash.h +16 -0
@@ -45,6 +45,8 @@ struct led_flash_ops {int (*timeout_set)(struct led_classdev_flash *fled_cdev,u32 timeout);/* get the flash LED fault */ int (*fault_get)(struct led_classdev_flash *fled_cdev,u32 *fault); +/* set flash duration */ +int (*duration_set)(struct led_classdev_flash *fled_cdev,u32 duration); };/*
@@ -75,6 +77,9 @@ struct led_classdev_flash {/* flash timeout value in microseconds along with its constraints */ struct led_flash_setting timeout; +/* flash timeout value in microseconds along with its constraints */ +struct led_flash_setting duration; +/* LED Flash class sysfs groups */ const struct attribute_group *sysfs_groups[LED_FLASH_SYSFS_GROUPS_SIZE ]; };
@@ -209,4 +214,15 @@ int led_set_flash_timeout(struct led_classdev_flash *fled_cdev, u32 timeout);*/ int led_get_flash_fault (struct led_classdev_flash *fled_cdev,u32 *fault); +/** +* led_set_flash_duration - set flash LED duration +* @fled_cdev: the flash LED to set +* @timeout: the flash duration to set it to +* +* Set the flash strobe duration. +* +* Returns: 0 on success or negative error value on failure +*/ +int led_set_flash_duration (struct led_classdev_flash *fled_cdev,u32 duration); +#endif /* __LINUX_FLASH_LEDS_H_INCLUDED */
Signature · 1 line
2.47.2
PATCH v3 3/9 media: v4l2-flash: add support for flash/strobe duration
In reply to Richard LeitnerAdd support for the new V4L2_CID_FLASH_DURATION control to the v4l2 flash led class.
--- drivers/media/v4l2-core/v4l2-flash-led-class.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/media/v4l2-core/v4l2-flash-led-class.c +13 -0
@@ -298,6 +298,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 +430,13 @@ 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, timeout_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,
Signature · 1 line
2.47.2
PATCH v3 4/9 media: v4l2-flash: fix flash_timeout comment
In reply to Richard LeitnerThe comment for the flash_timeout setter mentioned it is the "flash duration". Fix this by changing it to "flash timeout".
--- include/linux/led-class-flash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/led-class-flash.h +1 -1
@@ -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 */
Signature · 1 line
2.47.2
PATCH v3 5/9 Documentation: uAPI: media: add V4L2_CID_FLASH_DURATION
In reply to Richard LeitnerAdd the new strobe_duration control to v4l uAPI documentation.
--- Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst +5 -0
@@ -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.
Signature · 1 line
2.47.2
PATCH v3 6/9 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.2
PATCH v3 7/9 media: i2c: ov9282: add led_mode v4l2 control
In reply to Richard LeitnerAdd 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.
--- drivers/media/i2c/ov9282.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/media/i2c/ov9282.c +27 -0
@@ -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 ;
@@ -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 */
Signature · 1 line
2.47.2
PATCH v3 8/9 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 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/media/i2c/ov9282.c +28 -0
@@ -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,24 @@ 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,int 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 +778,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 ;
@@ -1418,6 +1443,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 */
Signature · 1 line
2.47.2
PATCH v3 9/9 media: i2c: ov9282: add strobe_source v4l2 control
In reply to Richard LeitnerAdd 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.
--- drivers/media/i2c/ov9282.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/i2c/ov9282.c +8 -0
@@ -1367,6 +1367,7 @@ 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;
@@ -1446,6 +1447,13 @@ 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 ); + 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 */
Signature · 1 line
2.47.2
Sakari Ailus
maintainerRe: [PATCH v3 3/9] media: v4l2-flash: add support for flash/strobe duration
In reply to Richard LeitnerHi Richard,
Quoted 26 lines · Richard Leitner
Add support for the new
V4L2_CID_FLASH_DURATIONcontrol to the v4l2 flash led class.Signed-off-by Richard Leitner <[email protected]>--- drivers/media/v4l2-core/v4l2-flash-led-class.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)drivers/media/v4l2-core/v4l2-flash-led-class.c +6
-0@@ -298,6 +298,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 ;
drivers/media/v4l2-core/v4l2-flash-led-class.c static void __fill_ctrl_init_data(struct v4l2_flash *v4l2_flash, · line 439
Quoted 10 lines
drivers/media/v4l2-core/v4l2-flash-led-class.c +7
-0@@ -424,6 +430,13 @@ 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, timeout_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 ;
Has this been compile tested? :-)
Quoted 4 lines
drivers/media/v4l2-core/v4l2-flash-led-class.c +0
-0} static int v4l2_flash_init_controls(struct v4l2_flash *v4l2_flash,
Signature · 3 lines
Regards, Sakari Ailus
Sakari Ailus
maintainerRe: [PATCH v3 8/9] media: i2c: ov9282: add strobe_duration v4l2 control
In reply to Richard LeitnerHi Richard,
Quoted 33 lines · Richard Leitner
Add
V4L2_CID_FLASH_DURATIONsupport 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 registerPWM_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 <[email protected]>--- drivers/media/i2c/ov9282.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/media/i2c/ov9282.c +4
-0@@ -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
drivers/media/i2c/ov9282.c static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode) · line 696
Quoted 6 lines
drivers/media/i2c/ov9282.c +3
-0@@ -687,6 +691,24 @@ 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,int value) +{ +/* Calculate "strobe_frame_span" increments from a given value (µs).
/*
* Multi-line
* comment.
*/
drivers/media/i2c/ov9282.c static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode) · line 709
Quoted 13 lines
drivers/media/i2c/ov9282.c +13
-0+* 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 );
The granularity of the hardware supported values is lower than that of the control. Could you add try_ctrl op to provide the actual value back to the user space?
Quoted 16 lines
drivers/media/i2c/ov9282.c +5
-0+} +/** * ov9282_set_ctrl() - Set subdevice control * @ctrl: pointer to v4l2_ctrl structure @@ -756,6 +778,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 ;
drivers/media/i2c/ov9282.c static int ov9282_init_controls(struct ov9282 *ov9282) · line 1446
Quoted 4 lines
drivers/media/i2c/ov9282.c +1
-0@@ -1418,6 +1443,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,
Should the number of controls in the handler be updated?
Quoted 6 lines
drivers/media/i2c/ov9282.c +2
-0+ 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 · 3 lines
Regards, Sakari Ailus
Re: [PATCH v3 3/9] media: v4l2-flash: add support for flash/strobe duration
In reply to Sakari AilusHi Sakari,
thanks for your quick feedback!
Quoted 27 lines · Sakari Ailus
Hi Richard,
Quoted 24 lines · Richard Leitner
Add support for the new
V4L2_CID_FLASH_DURATIONcontrol to the v4l2 flash led class.Signed-off-by Richard Leitner <[email protected]>--- drivers/media/v4l2-core/v4l2-flash-led-class.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)drivers/media/v4l2-core/v4l2-flash-led-class.c +6
-0@@ -298,6 +298,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); }
Quoted 14 lines
drivers/media/v4l2-core/v4l2-flash-led-class.c static void __fill_ctrl_init_data(struct v4l2_flash *v4l2_flash, · line 439
Quoted 12 lines
drivers/media/v4l2-core/v4l2-flash-led-class.c +7
-0return -EINVAL ;@@ -424,6 +430,13 @@ 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, timeout_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 ;Has this been compile tested? :-)
Oooh... Damn. That's embarrasing. SORRY! There should have been at least another '}' in this patch.... Seems I somehow messed up my last rebase.
Will fix that in v4. Sorry again :-/
Quoted 10 lines
Quoted 5 lines
drivers/media/v4l2-core/v4l2-flash-led-class.c +0
-0} static int v4l2_flash_init_controls(struct v4l2_flash *v4l2_flash,Signature · 3 lines
Regards, Sakari Ailus
regards;rl
Sakari Ailus
maintainerRe: [PATCH v3 9/9] media: i2c: ov9282: add strobe_source v4l2 control
In reply to Richard LeitnerHi Richard,
Quoted 22 lines · Richard Leitner
Add read-only
V4L2_CID_FLASH_STROBE_SOURCEcontrol. Its value is fixed toV4L2_FLASH_STROBE_SOURCE_EXTERNALas the camera sensor triggers the strobe based on its register settings.Signed-off-by Richard Leitner <[email protected]>--- drivers/media/i2c/ov9282.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/media/i2c/ov9282.c +1
-0@@ -1367,6 +1367,7 @@ 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;
drivers/media/i2c/ov9282.c static int ov9282_init_controls(struct ov9282 *ov9282) · line 1455
Quoted 9 lines
drivers/media/i2c/ov9282.c +6
-0@@ -1446,6 +1447,13 @@ 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 ); + ctrl->flags |=V4L2_CTRL_FLAG_READ_ONLY ;
Note that v4l2_ctrl_new_std_menu() may return NULL.
Quoted 5 lines
drivers/media/i2c/ov9282.c +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
Sakari Ailus
Sakari Ailus
maintainerRe: [PATCH v3 3/9] media: v4l2-flash: add support for flash/strobe duration
In reply to Richard LeitnerQuoted 9 lines · Richard Leitner
Quoted 8 lines
drivers/media/v4l2-core/v4l2-flash-led-class.c static void __fill_ctrl_init_data(struct v4l2_flash *v4l2_flash, · line 439
Quoted 6 lines
drivers/media/v4l2-core/v4l2-flash-led-class.c +6
-0+/* Init FLASH_DURATION ctrl data */ +if (has_flash_op (fled_cdev, timeout_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 ;Has this been compile tested? :-)
Quoted 4 lines
Oooh... Damn. That's embarrasing. SORRY! There should have been at least another '}' in this patch.... Seems I somehow messed up my last rebase.
Will fix that in v4. Sorry again :-/
No worries, it happens to everyone sometimes.
Signature · 1 line
Sakari Ailus
Re: [PATCH v3 8/9] media: i2c: ov9282: add strobe_duration v4l2 control
In reply to Sakari AilusHi Sakari,
thanks for the review!
Quoted 39 lines · Sakari Ailus
Hi Richard,
Quoted 36 lines · Richard Leitner
Add
V4L2_CID_FLASH_DURATIONsupport 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 registerPWM_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 <[email protected]>--- drivers/media/i2c/ov9282.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)drivers/media/i2c/ov9282.c +4
-0@@ -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,24 @@ static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode) current_val); }
Quoted 8 lines
drivers/media/i2c/ov9282.c static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode) · line 696
Quoted 3 lines
drivers/media/i2c/ov9282.c +3
-0+static int ov9282_set_ctrl_flash_duration (struct ov9282 *ov9282,int value) +{ +/* Calculate "strobe_frame_span" increments from a given value (µs). /*
* Multi-line
* comment.
*/
sure. will adapt that in v4.
Quoted 10 lines
Quoted 10 lines
drivers/media/i2c/ov9282.c +9
-0+* 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); +
Quoted 8 lines
drivers/media/i2c/ov9282.c static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode) · line 709
Quoted 4 lines
drivers/media/i2c/ov9282.c +4
-0+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 );The granularity of the hardware supported values is lower than that of the control. Could you add
try_ctrlop to provide the actual value back to the user space?
Tbh, I've never implemented a try_ctrl before, but sure. I will dig into it and add it for the ov9282 FLASH_DURATION in v4.
Quoted 20 lines
Quoted 20 lines
drivers/media/i2c/ov9282.c +5
-0+} +/** * ov9282_set_ctrl() - Set subdevice control * @ctrl: pointer to v4l2_ctrl structure @@ -756,6 +778,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 ;@@ -1418,6 +1443,9 @@ static int ov9282_init_controls(struct ov9282 *ov9282) (1 <<V4L2_FLASH_LED_MODE_TORCH ), V4L2_FLASH_LED_MODE_NONE);
Quoted 3 lines
drivers/media/i2c/ov9282.c static int ov9282_init_controls(struct ov9282 *ov9282) · line 1446
Quoted 1 line
drivers/media/i2c/ov9282.c +1
-0+ v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION,Should the number of controls in the handler be updated?
What do you mean by "number of controls in the handler" exactly? Which handler?
Quoted 11 lines
Quoted 6 lines
drivers/media/i2c/ov9282.c +2
-0+ 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 · 3 lines
Regards, Sakari Ailus
regards;rl
Re: [PATCH v3 9/9] media: i2c: ov9282: add strobe_source v4l2 control
In reply to Sakari AilusHi Sakari,
thanks for your comment!
Quoted 28 lines · Sakari Ailus
Hi Richard,
Quoted 25 lines · Richard Leitner
Add read-only
V4L2_CID_FLASH_STROBE_SOURCEcontrol. Its value is fixed toV4L2_FLASH_STROBE_SOURCE_EXTERNALas the camera sensor triggers the strobe based on its register settings.Signed-off-by Richard Leitner <[email protected]>--- drivers/media/i2c/ov9282.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/media/i2c/ov9282.c +1
-0@@ -1367,6 +1367,7 @@ 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;@@ -1446,6 +1447,13 @@ 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 );
Quoted 8 lines
drivers/media/i2c/ov9282.c static int ov9282_init_controls(struct ov9282 *ov9282) · line 1455
Quoted 6 lines
drivers/media/i2c/ov9282.c +6
-0+ 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 ); + ctrl->flags |=V4L2_CTRL_FLAG_READ_ONLY ;Note that
v4l2_ctrl_new_std_menu()may return NULL.
Good catch. Thanks! Will add a check in v4.
Quoted 9 lines
Quoted 6 lines
drivers/media/i2c/ov9282.c +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
Sakari Ailus
regards;rl
Sakari Ailus
maintainerRe: [PATCH v3 8/9] media: i2c: ov9282: add strobe_duration v4l2 control
In reply to Richard LeitnerHi Richard,
Quoted 3 lines · Richard Leitner
Hi Sakari,
thanks for the review!
You're welcome.
Quoted 6 lines
Quoted 3 lines
drivers/media/i2c/ov9282.c static int ov9282_init_controls(struct ov9282 *ov9282) · line 1446
Quoted 1 line
drivers/media/i2c/ov9282.c +1
-0+ v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION,Should the number of controls in the handler be updated?
What do you mean by "number of controls in the handler" exactly? Which handler?
A number of buckets allocated in control handler's initialisation is based on the number of controls given to the init function. You should update that number when adding controls.
Signature · 3 lines
Regards, Sakari Ailus
Re: [PATCH v3 8/9] media: i2c: ov9282: add strobe_duration v4l2 control
Quoted 13 lines · Sakari Ailus
Hi Richard,
Quoted 3 lines · Richard Leitner
Hi Sakari,
thanks for the review!
You're welcome.
Quoted 4 lines
Quoted 3 lines
drivers/media/i2c/ov9282.c static int ov9282_init_controls(struct ov9282 *ov9282) · line 1446
Quoted 1 line
drivers/media/i2c/ov9282.c +1
-0+ v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION,Should the number of controls in the handler be updated?
Quoted 6 lines
Quoted 2 lines
What do you mean by "number of controls in the handler" exactly? Which handler?
A number of buckets allocated in control handler's initialisation is based on the number of controls given to the init function. You should update that number when adding controls.
Ah, now I got it. :-)
Thanks for the clarification. Will fix that in v4 for all newly added controls!
regards;rl
Quoted 5 lines
Signature · 4 lines
-- Regards, Sakari Ailus