Skip to content

Commit e71eccc

Browse files
committed
media: i2c: imx477: Extend V4L2_CID_VBLANK range
The driver was using a struct v4l2_fract for the min frame time to determine the range for V4L2_CID_VBLANK, and a second to set the default VBLANK value for each mode. However actually the sensor will accept any VBLANK value down to 1 line, and using a struct v4l2_fract to hold the default framerate (which is an integer in all cases) is rather overkill. Drop the minimum frame time, and use a simple integer to set the default. This actually increases the max frame rate in all modes slightly. Signed-off-by: Dave Stevenson <[email protected]>
1 parent ad61893 commit e71eccc

File tree

1 file changed

+13
-44
lines changed

1 file changed

+13
-44
lines changed

drivers/media/i2c/imx477.c

Lines changed: 13 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ MODULE_PARM_DESC(trigger_mode, "Set vsync trigger mode: 1=source, 2=sink");
5353
/* V_TIMING internal */
5454
#define IMX477_REG_FRAME_LENGTH 0x0340
5555
#define IMX477_FRAME_LENGTH_MAX 0xffdc
56+
#define IMX477_VBLANK_MIN 4
5657

5758
/* H_TIMING internal */
5859
#define IMX477_REG_LINE_LENGTH 0x0342
@@ -154,11 +155,8 @@ struct imx477_mode {
154155
/* Analog crop rectangle. */
155156
struct v4l2_rect crop;
156157

157-
/* Highest possible framerate. */
158-
struct v4l2_fract timeperframe_min;
159-
160158
/* Default framerate. */
161-
struct v4l2_fract timeperframe_default;
159+
unsigned int framerate_default;
162160

163161
/* Default register values */
164162
struct imx477_reg_list reg_list;
@@ -866,14 +864,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
866864
.width = 4056,
867865
.height = 3040,
868866
},
869-
.timeperframe_min = {
870-
.numerator = 100,
871-
.denominator = 1000
872-
},
873-
.timeperframe_default = {
874-
.numerator = 100,
875-
.denominator = 1000
876-
},
867+
.framerate_default = 10,
877868
.reg_list = {
878869
.num_of_regs = ARRAY_SIZE(mode_4056x3040_regs),
879870
.regs = mode_4056x3040_regs,
@@ -890,14 +881,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
890881
.width = 4056,
891882
.height = 3040,
892883
},
893-
.timeperframe_min = {
894-
.numerator = 100,
895-
.denominator = 4000
896-
},
897-
.timeperframe_default = {
898-
.numerator = 100,
899-
.denominator = 3000
900-
},
884+
.framerate_default = 30,
901885
.reg_list = {
902886
.num_of_regs = ARRAY_SIZE(mode_2028x1520_regs),
903887
.regs = mode_2028x1520_regs,
@@ -914,14 +898,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
914898
.width = 4056,
915899
.height = 2160,
916900
},
917-
.timeperframe_min = {
918-
.numerator = 100,
919-
.denominator = 5000
920-
},
921-
.timeperframe_default = {
922-
.numerator = 100,
923-
.denominator = 3000
924-
},
901+
.framerate_default = 30,
925902
.reg_list = {
926903
.num_of_regs = ARRAY_SIZE(mode_2028x1080_regs),
927904
.regs = mode_2028x1080_regs,
@@ -949,14 +926,7 @@ static const struct imx477_mode supported_modes_10bit[] = {
949926
.width = 2664,
950927
.height = 1980,
951928
},
952-
.timeperframe_min = {
953-
.numerator = 100,
954-
.denominator = 12000
955-
},
956-
.timeperframe_default = {
957-
.numerator = 100,
958-
.denominator = 12000
959-
},
929+
.framerate_default = 120,
960930
.reg_list = {
961931
.num_of_regs = ARRAY_SIZE(mode_1332x990_regs),
962932
.regs = mode_1332x990_regs,
@@ -1492,13 +1462,13 @@ static int imx477_get_pad_format(struct v4l2_subdev *sd,
14921462

14931463
static
14941464
unsigned int imx477_get_frame_length(const struct imx477_mode *mode,
1495-
const struct v4l2_fract *timeperframe)
1465+
unsigned int framerate_default)
14961466
{
14971467
u64 frame_length;
14981468

1499-
frame_length = (u64)timeperframe->numerator * IMX477_PIXEL_RATE;
1469+
frame_length = IMX477_PIXEL_RATE;
15001470
do_div(frame_length,
1501-
(u64)timeperframe->denominator * mode->line_length_pix);
1471+
(u64)framerate_default * mode->line_length_pix);
15021472

15031473
if (WARN_ON(frame_length > IMX477_FRAME_LENGTH_MAX))
15041474
frame_length = IMX477_FRAME_LENGTH_MAX;
@@ -1508,21 +1478,20 @@ unsigned int imx477_get_frame_length(const struct imx477_mode *mode,
15081478

15091479
static void imx477_set_framing_limits(struct imx477 *imx477)
15101480
{
1511-
unsigned int frm_length_min, frm_length_default, hblank_min;
1481+
unsigned int frm_length_default, hblank_min;
15121482
const struct imx477_mode *mode = imx477->mode;
15131483

1514-
frm_length_min = imx477_get_frame_length(mode, &mode->timeperframe_min);
15151484
frm_length_default =
1516-
imx477_get_frame_length(mode, &mode->timeperframe_default);
1485+
imx477_get_frame_length(mode, mode->framerate_default);
15171486

15181487
/* Default to no long exposure multiplier. */
15191488
imx477->long_exp_shift = 0;
15201489

15211490
/* Update limits and set FPS to default */
1522-
__v4l2_ctrl_modify_range(imx477->vblank, frm_length_min - mode->height,
1491+
__v4l2_ctrl_modify_range(imx477->vblank, 1,
15231492
((1 << IMX477_LONG_EXP_SHIFT_MAX) *
15241493
IMX477_FRAME_LENGTH_MAX) - mode->height,
1525-
1, frm_length_default - mode->height);
1494+
IMX477_VBLANK_MIN, frm_length_default - mode->height);
15261495

15271496
/* Setting this will adjust the exposure limits as well. */
15281497
__v4l2_ctrl_s_ctrl(imx477->vblank, frm_length_default - mode->height);

0 commit comments

Comments
 (0)