Skip to content

Commit 4301acb

Browse files
6by9pelwell
authored andcommitted
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 f58ded0 commit 4301acb

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
@@ -68,6 +68,7 @@ MODULE_PARM_DESC(fstrobe_delay, "Set fstrobe delay from end all lines starting t
6868

6969
/* V_TIMING internal */
7070
#define IMX477_REG_FRAME_LENGTH 0x0340
71+
#define IMX477_VBLANK_MIN 4
7172
#define IMX477_FRAME_LENGTH_MAX 0xffdc
7273

7374
/* H_TIMING internal */
@@ -173,11 +174,8 @@ struct imx477_mode {
173174
/* Analog crop rectangle. */
174175
struct v4l2_rect crop;
175176

176-
/* Highest possible framerate. */
177-
struct v4l2_fract timeperframe_min;
178-
179-
/* Default framerate. */
180-
struct v4l2_fract timeperframe_default;
177+
/* Default frame_length value to use in this mode */
178+
unsigned int frm_length_default;
181179

182180
/* Default register values */
183181
struct imx477_reg_list reg_list;
@@ -1013,14 +1011,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
10131011
.width = 4056,
10141012
.height = 3040,
10151013
},
1016-
.timeperframe_min = {
1017-
.numerator = 100,
1018-
.denominator = 1000
1019-
},
1020-
.timeperframe_default = {
1021-
.numerator = 100,
1022-
.denominator = 1000
1023-
},
1014+
.frm_length_default = 3500,
10241015
.reg_list = {
10251016
.num_of_regs = ARRAY_SIZE(mode_4056x3040_regs),
10261017
.regs = mode_4056x3040_regs,
@@ -1037,14 +1028,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
10371028
.width = 4056,
10381029
.height = 3040,
10391030
},
1040-
.timeperframe_min = {
1041-
.numerator = 100,
1042-
.denominator = 4000
1043-
},
1044-
.timeperframe_default = {
1045-
.numerator = 100,
1046-
.denominator = 3000
1047-
},
1031+
.frm_length_default = 2197,
10481032
.reg_list = {
10491033
.num_of_regs = ARRAY_SIZE(mode_2028x1520_regs),
10501034
.regs = mode_2028x1520_regs,
@@ -1061,14 +1045,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
10611045
.width = 4056,
10621046
.height = 2160,
10631047
},
1064-
.timeperframe_min = {
1065-
.numerator = 100,
1066-
.denominator = 5000
1067-
},
1068-
.timeperframe_default = {
1069-
.numerator = 100,
1070-
.denominator = 3000
1071-
},
1048+
.frm_length_default = 2197,
10721049
.reg_list = {
10731050
.num_of_regs = ARRAY_SIZE(mode_2028x1080_regs),
10741051
.regs = mode_2028x1080_regs,
@@ -1096,14 +1073,7 @@ static const struct imx477_mode supported_modes_10bit[] = {
10961073
.width = 2664,
10971074
.height = 1980,
10981075
},
1099-
.timeperframe_min = {
1100-
.numerator = 100,
1101-
.denominator = 12000
1102-
},
1103-
.timeperframe_default = {
1104-
.numerator = 100,
1105-
.denominator = 12000
1106-
},
1076+
.frm_length_default = 1050,
11071077
.reg_list = {
11081078
.num_of_regs = ARRAY_SIZE(mode_1332x990_regs),
11091079
.regs = mode_1332x990_regs,
@@ -1644,42 +1614,24 @@ static int imx477_get_pad_format(struct v4l2_subdev *sd,
16441614
return 0;
16451615
}
16461616

1647-
static
1648-
unsigned int imx477_get_frame_length(const struct imx477_mode *mode,
1649-
const struct v4l2_fract *timeperframe)
1650-
{
1651-
u64 frame_length;
1652-
1653-
frame_length = (u64)timeperframe->numerator * IMX477_PIXEL_RATE;
1654-
do_div(frame_length,
1655-
(u64)timeperframe->denominator * mode->line_length_pix);
1656-
1657-
if (WARN_ON(frame_length > IMX477_FRAME_LENGTH_MAX))
1658-
frame_length = IMX477_FRAME_LENGTH_MAX;
1659-
1660-
return max_t(unsigned int, frame_length, mode->height);
1661-
}
1662-
16631617
static void imx477_set_framing_limits(struct imx477 *imx477)
16641618
{
1665-
unsigned int frm_length_min, frm_length_default, hblank_min;
1619+
unsigned int hblank_min;
16661620
const struct imx477_mode *mode = imx477->mode;
16671621

1668-
frm_length_min = imx477_get_frame_length(mode, &mode->timeperframe_min);
1669-
frm_length_default =
1670-
imx477_get_frame_length(mode, &mode->timeperframe_default);
1671-
16721622
/* Default to no long exposure multiplier. */
16731623
imx477->long_exp_shift = 0;
16741624

16751625
/* Update limits and set FPS to default */
1676-
__v4l2_ctrl_modify_range(imx477->vblank, frm_length_min - mode->height,
1626+
__v4l2_ctrl_modify_range(imx477->vblank,
1627+
IMX477_VBLANK_MIN,
16771628
((1 << IMX477_LONG_EXP_SHIFT_MAX) *
16781629
IMX477_FRAME_LENGTH_MAX) - mode->height,
1679-
1, frm_length_default - mode->height);
1630+
1, mode->frm_length_default - mode->height);
16801631

16811632
/* Setting this will adjust the exposure limits as well. */
1682-
__v4l2_ctrl_s_ctrl(imx477->vblank, frm_length_default - mode->height);
1633+
__v4l2_ctrl_s_ctrl(imx477->vblank,
1634+
mode->frm_length_default - mode->height);
16831635

16841636
hblank_min = mode->line_length_pix - mode->width;
16851637
__v4l2_ctrl_modify_range(imx477->hblank, hblank_min,
@@ -2147,7 +2099,8 @@ static int imx477_init_controls(struct imx477 *imx477)
21472099
* in the imx477_set_framing_limits() call below.
21482100
*/
21492101
imx477->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx477_ctrl_ops,
2150-
V4L2_CID_VBLANK, 0, 0xffff, 1, 0);
2102+
V4L2_CID_VBLANK, IMX477_VBLANK_MIN,
2103+
0xffff, 1, IMX477_VBLANK_MIN);
21512104
imx477->hblank = v4l2_ctrl_new_std(ctrl_hdlr, &imx477_ctrl_ops,
21522105
V4L2_CID_HBLANK, 0, 0xffff, 1, 0);
21532106

0 commit comments

Comments
 (0)