Skip to content

Commit 369c3cd

Browse files
committed
media: imx477: Precompute frame length values
The frame length default value doesn't change dynamically, and neither does any of the other parameters that configure it, so precompute it instead of working from a frame duration to get to the value. The minimum value was also computed, when actually the sensor will take any value down to 4 lines. Signed-off-by: Dave Stevenson <[email protected]>
1 parent 7a9f97a commit 369c3cd

File tree

1 file changed

+15
-62
lines changed

1 file changed

+15
-62
lines changed

drivers/media/i2c/imx477.c

Lines changed: 15 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ MODULE_PARM_DESC(trigger_mode, "Set vsync trigger mode: 1=source, 2=sink");
5252

5353
/* V_TIMING internal */
5454
#define IMX477_REG_FRAME_LENGTH 0x0340
55+
#define IMX477_VBLANK_MIN 4
5556
#define IMX477_FRAME_LENGTH_MAX 0xffdc
5657

5758
/* H_TIMING internal */
@@ -157,11 +158,8 @@ struct imx477_mode {
157158
/* Analog crop rectangle. */
158159
struct v4l2_rect crop;
159160

160-
/* Highest possible framerate. */
161-
struct v4l2_fract timeperframe_min;
162-
163-
/* Default framerate. */
164-
struct v4l2_fract timeperframe_default;
161+
/* Default frame_length value to use in this mode */
162+
unsigned int frm_length_default;
165163

166164
/* Default register values */
167165
struct imx477_reg_list reg_list;
@@ -997,14 +995,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
997995
.width = 4056,
998996
.height = 3040,
999997
},
1000-
.timeperframe_min = {
1001-
.numerator = 100,
1002-
.denominator = 1000
1003-
},
1004-
.timeperframe_default = {
1005-
.numerator = 100,
1006-
.denominator = 1000
1007-
},
998+
.frm_length_default = 3500,
1008999
.reg_list = {
10091000
.num_of_regs = ARRAY_SIZE(mode_4056x3040_regs),
10101001
.regs = mode_4056x3040_regs,
@@ -1021,14 +1012,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
10211012
.width = 4056,
10221013
.height = 3040,
10231014
},
1024-
.timeperframe_min = {
1025-
.numerator = 100,
1026-
.denominator = 4000
1027-
},
1028-
.timeperframe_default = {
1029-
.numerator = 100,
1030-
.denominator = 3000
1031-
},
1015+
.frm_length_default = 2197,
10321016
.reg_list = {
10331017
.num_of_regs = ARRAY_SIZE(mode_2028x1520_regs),
10341018
.regs = mode_2028x1520_regs,
@@ -1045,14 +1029,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
10451029
.width = 4056,
10461030
.height = 2160,
10471031
},
1048-
.timeperframe_min = {
1049-
.numerator = 100,
1050-
.denominator = 5000
1051-
},
1052-
.timeperframe_default = {
1053-
.numerator = 100,
1054-
.denominator = 3000
1055-
},
1032+
.frm_length_default = 2197,
10561033
.reg_list = {
10571034
.num_of_regs = ARRAY_SIZE(mode_2028x1080_regs),
10581035
.regs = mode_2028x1080_regs,
@@ -1080,14 +1057,7 @@ static const struct imx477_mode supported_modes_10bit[] = {
10801057
.width = 2664,
10811058
.height = 1980,
10821059
},
1083-
.timeperframe_min = {
1084-
.numerator = 100,
1085-
.denominator = 12000
1086-
},
1087-
.timeperframe_default = {
1088-
.numerator = 100,
1089-
.denominator = 12000
1090-
},
1060+
.frm_length_default = 1050,
10911061
.reg_list = {
10921062
.num_of_regs = ARRAY_SIZE(mode_1332x990_regs),
10931063
.regs = mode_1332x990_regs,
@@ -1628,42 +1598,24 @@ static int imx477_get_pad_format(struct v4l2_subdev *sd,
16281598
return 0;
16291599
}
16301600

1631-
static
1632-
unsigned int imx477_get_frame_length(const struct imx477_mode *mode,
1633-
const struct v4l2_fract *timeperframe)
1634-
{
1635-
u64 frame_length;
1636-
1637-
frame_length = (u64)timeperframe->numerator * IMX477_PIXEL_RATE;
1638-
do_div(frame_length,
1639-
(u64)timeperframe->denominator * mode->line_length_pix);
1640-
1641-
if (WARN_ON(frame_length > IMX477_FRAME_LENGTH_MAX))
1642-
frame_length = IMX477_FRAME_LENGTH_MAX;
1643-
1644-
return max_t(unsigned int, frame_length, mode->height);
1645-
}
1646-
16471601
static void imx477_set_framing_limits(struct imx477 *imx477)
16481602
{
1649-
unsigned int frm_length_min, frm_length_default, hblank_min;
1603+
unsigned int hblank_min;
16501604
const struct imx477_mode *mode = imx477->mode;
16511605

1652-
frm_length_min = imx477_get_frame_length(mode, &mode->timeperframe_min);
1653-
frm_length_default =
1654-
imx477_get_frame_length(mode, &mode->timeperframe_default);
1655-
16561606
/* Default to no long exposure multiplier. */
16571607
imx477->long_exp_shift = 0;
16581608

16591609
/* Update limits and set FPS to default */
1660-
__v4l2_ctrl_modify_range(imx477->vblank, frm_length_min - mode->height,
1610+
__v4l2_ctrl_modify_range(imx477->vblank,
1611+
IMX477_VBLANK_MIN,
16611612
((1 << IMX477_LONG_EXP_SHIFT_MAX) *
16621613
IMX477_FRAME_LENGTH_MAX) - mode->height,
1663-
1, frm_length_default - mode->height);
1614+
1, mode->frm_length_default - mode->height);
16641615

16651616
/* Setting this will adjust the exposure limits as well. */
1666-
__v4l2_ctrl_s_ctrl(imx477->vblank, frm_length_default - mode->height);
1617+
__v4l2_ctrl_s_ctrl(imx477->vblank,
1618+
mode->frm_length_default - mode->height);
16671619

16681620
hblank_min = mode->line_length_pix - mode->width;
16691621
__v4l2_ctrl_modify_range(imx477->hblank, hblank_min,
@@ -2106,7 +2058,8 @@ static int imx477_init_controls(struct imx477 *imx477)
21062058
* in the imx477_set_framing_limits() call below.
21072059
*/
21082060
imx477->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx477_ctrl_ops,
2109-
V4L2_CID_VBLANK, 0, 0xffff, 1, 0);
2061+
V4L2_CID_VBLANK, IMX477_VBLANK_MIN,
2062+
0xffff, 1, IMX477_VBLANK_MIN);
21102063
imx477->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx477_ctrl_ops,
21112064
V4L2_CID_HBLANK, 0, 0xffff, 1, 0);
21122065

0 commit comments

Comments
 (0)