Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: i2c: ov9282: dynamic flash_duration maximum

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>
[Sakari Ailus: Some lines rewrapped.]
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>

authored by

Richard Leitner and committed by
Hans Verkuil
df60764e b95d8058

+26 -4
+26 -4
drivers/media/i2c/ov9282.c
··· 199 199 * @exp_ctrl: Pointer to exposure control 200 200 * @again_ctrl: Pointer to analog gain control 201 201 * @pixel_rate: Pointer to pixel rate control 202 + * @flash_duration: Pointer to flash duration control 202 203 * @vblank: Vertical blanking in lines 203 204 * @noncontinuous_clock: Selection of CSI2 noncontinuous clock mode 204 205 * @cur_mode: Pointer to current selected sensor mode ··· 222 221 struct v4l2_ctrl *again_ctrl; 223 222 }; 224 223 struct v4l2_ctrl *pixel_rate; 224 + struct v4l2_ctrl *flash_duration; 225 225 u32 vblank; 226 226 bool noncontinuous_clock; 227 227 const struct ov9282_mode *cur_mode; ··· 614 612 mode->vblank_max, 1, mode->vblank); 615 613 } 616 614 615 + static u32 ov9282_exposure_to_us(struct ov9282 *ov9282, u32 exposure) 616 + { 617 + /* calculate exposure time in µs */ 618 + u32 frame_width = ov9282->cur_mode->width + ov9282->hblank_ctrl->val; 619 + u32 trow_us = frame_width / (ov9282->pixel_rate->val / 1000000UL); 620 + 621 + return exposure * trow_us; 622 + } 623 + 617 624 /** 618 625 * ov9282_update_exp_gain() - Set updated exposure and gain 619 626 * @ov9282: pointer to ov9282 device ··· 634 623 static int ov9282_update_exp_gain(struct ov9282 *ov9282, u32 exposure, u32 gain) 635 624 { 636 625 int ret; 626 + u32 exposure_us = ov9282_exposure_to_us(ov9282, exposure); 637 627 638 - dev_dbg(ov9282->dev, "Set exp %u, analog gain %u", 639 - exposure, gain); 628 + dev_dbg(ov9282->dev, "Set exp %u (~%u us), analog gain %u", 629 + exposure, exposure_us, gain); 640 630 641 631 ret = ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 1); 642 632 if (ret) ··· 648 636 goto error_release_group_hold; 649 637 650 638 ret = ov9282_write_reg(ov9282, OV9282_REG_AGAIN, 1, gain); 639 + if (ret) 640 + goto error_release_group_hold; 641 + 642 + ret = __v4l2_ctrl_modify_range(ov9282->flash_duration, 643 + 0, exposure_us, 1, 644 + OV9282_STROBE_FRAME_SPAN_DEFAULT); 651 645 652 646 error_release_group_hold: 653 647 ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 0); ··· 1449 1431 const struct ov9282_mode *mode = ov9282->cur_mode; 1450 1432 struct v4l2_fwnode_device_properties props; 1451 1433 u32 hblank_min; 1434 + u32 exposure_us; 1452 1435 u32 lpfr; 1453 1436 int ret; 1454 1437 ··· 1522 1503 v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, 1523 1504 V4L2_CID_FLASH_STROBE_OE, 0, 1, 1, 0); 1524 1505 1525 - v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION, 1526 - 0, 13900, 1, 8); 1506 + exposure_us = ov9282_exposure_to_us(ov9282, OV9282_EXPOSURE_DEFAULT); 1507 + ov9282->flash_duration = 1508 + v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, 1509 + V4L2_CID_FLASH_DURATION, 0, exposure_us, 1, 1510 + OV9282_STROBE_FRAME_SPAN_DEFAULT); 1527 1511 1528 1512 ret = v4l2_fwnode_device_parse(ov9282->dev, &props); 1529 1513 if (!ret) {