Skip to content

Commit 2d5aea5

Browse files
Umang JainHans Verkuil
authored andcommitted
media: imx335: Refactor power sequence to set controls
Additional controls might require the sensor to be powered up to set the control value. Currently, only the exposure control powers up the sensor. Move the power up sequence out of the switch-case block. In a subsequent patch, test pattern control will be added that needs the sensor to be powered up. Hence, refactor the power sequence to be present outside the switch-case block. The VBLANK control is also moved out of the switch-case in order to be handled early on, to propagate the changes to other controls. Signed-off-by: Umang Jain <[email protected]> Signed-off-by: Sakari Ailus <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent a95253d commit 2d5aea5

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

drivers/media/i2c/imx335.c

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -527,26 +527,31 @@ static int imx335_set_ctrl(struct v4l2_ctrl *ctrl)
527527
u32 exposure;
528528
int ret;
529529

530-
switch (ctrl->id) {
531-
case V4L2_CID_VBLANK:
530+
/* Propagate change of current control to all related controls */
531+
if (ctrl->id == V4L2_CID_VBLANK) {
532532
imx335->vblank = imx335->vblank_ctrl->val;
533533

534534
dev_dbg(imx335->dev, "Received vblank %u, new lpfr %u\n",
535535
imx335->vblank,
536536
imx335->vblank + imx335->cur_mode->height);
537537

538-
ret = __v4l2_ctrl_modify_range(imx335->exp_ctrl,
539-
IMX335_EXPOSURE_MIN,
540-
imx335->vblank +
541-
imx335->cur_mode->height -
542-
IMX335_EXPOSURE_OFFSET,
543-
1, IMX335_EXPOSURE_DEFAULT);
544-
break;
545-
case V4L2_CID_EXPOSURE:
546-
/* Set controls only if sensor is in power on state */
547-
if (!pm_runtime_get_if_in_use(imx335->dev))
548-
return 0;
538+
return __v4l2_ctrl_modify_range(imx335->exp_ctrl,
539+
IMX335_EXPOSURE_MIN,
540+
imx335->vblank +
541+
imx335->cur_mode->height -
542+
IMX335_EXPOSURE_OFFSET,
543+
1, IMX335_EXPOSURE_DEFAULT);
544+
}
545+
546+
/*
547+
* Applying V4L2 control value only happens
548+
* when power is up for streaming.
549+
*/
550+
if (pm_runtime_get_if_in_use(imx335->dev) == 0)
551+
return 0;
549552

553+
switch (ctrl->id) {
554+
case V4L2_CID_EXPOSURE:
550555
exposure = ctrl->val;
551556
analog_gain = imx335->again_ctrl->val;
552557

@@ -555,14 +560,14 @@ static int imx335_set_ctrl(struct v4l2_ctrl *ctrl)
555560

556561
ret = imx335_update_exp_gain(imx335, exposure, analog_gain);
557562

558-
pm_runtime_put(imx335->dev);
559-
560563
break;
561564
default:
562565
dev_err(imx335->dev, "Invalid control %d\n", ctrl->id);
563566
ret = -EINVAL;
564567
}
565568

569+
pm_runtime_put(imx335->dev);
570+
566571
return ret;
567572
}
568573

0 commit comments

Comments
 (0)