Skip to content

Commit 34bb609

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 <dave.stevenson@raspberrypi.com>
1 parent 8791851 commit 34bb609

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;
@@ -795,14 +793,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
795793
.width = 4056,
796794
.height = 3040,
797795
},
798-
.timeperframe_min = {
799-
.numerator = 100,
800-
.denominator = 1000
801-
},
802-
.timeperframe_default = {
803-
.numerator = 100,
804-
.denominator = 1000
805-
},
796+
.framerate_default = 10,
806797
.reg_list = {
807798
.num_of_regs = ARRAY_SIZE(mode_4056x3040_regs),
808799
.regs = mode_4056x3040_regs,
@@ -819,14 +810,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
819810
.width = 4056,
820811
.height = 3040,
821812
},
822-
.timeperframe_min = {
823-
.numerator = 100,
824-
.denominator = 4000
825-
},
826-
.timeperframe_default = {
827-
.numerator = 100,
828-
.denominator = 3000
829-
},
813+
.framerate_default = 30,
830814
.reg_list = {
831815
.num_of_regs = ARRAY_SIZE(mode_2028x1520_regs),
832816
.regs = mode_2028x1520_regs,
@@ -843,14 +827,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
843827
.width = 4056,
844828
.height = 2160,
845829
},
846-
.timeperframe_min = {
847-
.numerator = 100,
848-
.denominator = 5000
849-
},
850-
.timeperframe_default = {
851-
.numerator = 100,
852-
.denominator = 3000
853-
},
830+
.framerate_default = 30,
854831
.reg_list = {
855832
.num_of_regs = ARRAY_SIZE(mode_2028x1080_regs),
856833
.regs = mode_2028x1080_regs,
@@ -878,14 +855,7 @@ static const struct imx477_mode supported_modes_10bit[] = {
878855
.width = 2664,
879856
.height = 1980,
880857
},
881-
.timeperframe_min = {
882-
.numerator = 100,
883-
.denominator = 12000
884-
},
885-
.timeperframe_default = {
886-
.numerator = 100,
887-
.denominator = 12000
888-
},
858+
.framerate_default = 120,
889859
.reg_list = {
890860
.num_of_regs = ARRAY_SIZE(mode_1332x990_regs),
891861
.regs = mode_1332x990_regs,
@@ -1419,13 +1389,13 @@ static int imx477_get_pad_format(struct v4l2_subdev *sd,
14191389

14201390
static
14211391
unsigned int imx477_get_frame_length(const struct imx477_mode *mode,
1422-
const struct v4l2_fract *timeperframe)
1392+
unsigned int framerate_default)
14231393
{
14241394
u64 frame_length;
14251395

1426-
frame_length = (u64)timeperframe->numerator * IMX477_PIXEL_RATE;
1396+
frame_length = IMX477_PIXEL_RATE;
14271397
do_div(frame_length,
1428-
(u64)timeperframe->denominator * mode->line_length_pix);
1398+
(u64)framerate_default * mode->line_length_pix);
14291399

14301400
if (WARN_ON(frame_length > IMX477_FRAME_LENGTH_MAX))
14311401
frame_length = IMX477_FRAME_LENGTH_MAX;
@@ -1435,21 +1405,20 @@ unsigned int imx477_get_frame_length(const struct imx477_mode *mode,
14351405

14361406
static void imx477_set_framing_limits(struct imx477 *imx477)
14371407
{
1438-
unsigned int frm_length_min, frm_length_default, hblank_min;
1408+
unsigned int frm_length_default, hblank_min;
14391409
const struct imx477_mode *mode = imx477->mode;
14401410

1441-
frm_length_min = imx477_get_frame_length(mode, &mode->timeperframe_min);
14421411
frm_length_default =
1443-
imx477_get_frame_length(mode, &mode->timeperframe_default);
1412+
imx477_get_frame_length(mode, mode->framerate_default);
14441413

14451414
/* Default to no long exposure multiplier. */
14461415
imx477->long_exp_shift = 0;
14471416

14481417
/* Update limits and set FPS to default */
1449-
__v4l2_ctrl_modify_range(imx477->vblank, frm_length_min - mode->height,
1418+
__v4l2_ctrl_modify_range(imx477->vblank, 1,
14501419
((1 << IMX477_LONG_EXP_SHIFT_MAX) *
14511420
IMX477_FRAME_LENGTH_MAX) - mode->height,
1452-
1, frm_length_default - mode->height);
1421+
IMX477_VBLANK_MIN, frm_length_default - mode->height);
14531422

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

0 commit comments

Comments
 (0)