Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: media: imx500: Simplify the vblank control init #6388

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 5 additions & 27 deletions drivers/media/i2c/imx500.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@ struct imx500_mode {
/* Analog crop rectangle. */
struct v4l2_rect crop;

/* Default framerate. */
unsigned int framerate_default;

/* Default register values */
struct imx500_reg_list reg_list;
};
Expand Down Expand Up @@ -905,7 +902,6 @@ static const struct imx500_mode imx500_supported_modes[] = {
.width = 4056,
.height = 3040,
},
.framerate_default = 10,
.reg_list = {
.num_of_regs = ARRAY_SIZE(mode_4056x3040_regs),
.regs = mode_4056x3040_regs,
Expand All @@ -922,7 +918,6 @@ static const struct imx500_mode imx500_supported_modes[] = {
.width = 4056,
.height = 3040,
},
.framerate_default = 30,
.reg_list = {
.num_of_regs = ARRAY_SIZE(mode_2028x1520_regs),
.regs = mode_2028x1520_regs,
Expand Down Expand Up @@ -1744,40 +1739,22 @@ static int imx500_get_pad_format(struct v4l2_subdev *sd,
return 0;
}

static unsigned int imx500_get_frame_length(const struct imx500_mode *mode,
unsigned int framerate_default)
{
u64 frame_length;

frame_length = IMX500_PIXEL_RATE;
do_div(frame_length, (u64)framerate_default * mode->line_length_pix);

if (WARN_ON(frame_length > IMX500_FRAME_LENGTH_MAX))
frame_length = IMX500_FRAME_LENGTH_MAX;

return max_t(unsigned int, frame_length, mode->height);
}

static void imx500_set_framing_limits(struct imx500 *imx500)
{
unsigned int frm_length_default, hblank_min;
unsigned int hblank_min;
const struct imx500_mode *mode = imx500->mode;

frm_length_default =
imx500_get_frame_length(mode, mode->framerate_default);

/* Default to no long exposure multiplier. */
imx500->long_exp_shift = 0;

/* Update limits and set FPS to default */
__v4l2_ctrl_modify_range(
imx500->vblank, IMX500_VBLANK_MIN,
((1 << IMX500_LONG_EXP_SHIFT_MAX) * IMX500_FRAME_LENGTH_MAX) -
mode->height,
1, frm_length_default - mode->height);
mode->height, 1, IMX500_VBLANK_MIN);

/* Setting this will adjust the exposure limits as well. */
__v4l2_ctrl_s_ctrl(imx500->vblank, frm_length_default - mode->height);
__v4l2_ctrl_s_ctrl(imx500->vblank, IMX500_VBLANK_MIN);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically not needed as __v4l2_ctrl_modify_range will update the value if the current value is out of range and call s_ctrl.

There was a debate previously over whether setting the mode should reset the frame rate controls or not, but I don't think there was ever a final decision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, but I'd prefer to leave it in to preserve existing code that I've been testing with 😄


hblank_min = mode->line_length_pix - mode->width;
__v4l2_ctrl_modify_range(imx500->hblank, hblank_min, hblank_min, 1,
Expand Down Expand Up @@ -2499,7 +2476,8 @@ static int imx500_init_controls(struct imx500 *imx500)
* in the imx500_set_framing_limits() call below.
*/
imx500->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx500_ctrl_ops,
V4L2_CID_VBLANK, 0, 0xffff, 1, 0);
V4L2_CID_VBLANK, IMX500_VBLANK_MIN,
0xffff, 1, IMX500_VBLANK_MIN);
imx500->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx500_ctrl_ops,
V4L2_CID_HBLANK, 0, 0xffff, 1, 0);

Expand Down