Skip to content

Commit b0e8939

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 b201a9b commit b0e8939

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;
@@ -833,14 +831,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
833831
.width = 4056,
834832
.height = 3040,
835833
},
836-
.timeperframe_min = {
837-
.numerator = 100,
838-
.denominator = 1000
839-
},
840-
.timeperframe_default = {
841-
.numerator = 100,
842-
.denominator = 1000
843-
},
834+
.framerate_default = 10,
844835
.reg_list = {
845836
.num_of_regs = ARRAY_SIZE(mode_4056x3040_regs),
846837
.regs = mode_4056x3040_regs,
@@ -857,14 +848,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
857848
.width = 4056,
858849
.height = 3040,
859850
},
860-
.timeperframe_min = {
861-
.numerator = 100,
862-
.denominator = 4000
863-
},
864-
.timeperframe_default = {
865-
.numerator = 100,
866-
.denominator = 3000
867-
},
851+
.framerate_default = 30,
868852
.reg_list = {
869853
.num_of_regs = ARRAY_SIZE(mode_2028x1520_regs),
870854
.regs = mode_2028x1520_regs,
@@ -881,14 +865,7 @@ static const struct imx477_mode supported_modes_12bit[] = {
881865
.width = 4056,
882866
.height = 2160,
883867
},
884-
.timeperframe_min = {
885-
.numerator = 100,
886-
.denominator = 5000
887-
},
888-
.timeperframe_default = {
889-
.numerator = 100,
890-
.denominator = 3000
891-
},
868+
.framerate_default = 30,
892869
.reg_list = {
893870
.num_of_regs = ARRAY_SIZE(mode_2028x1080_regs),
894871
.regs = mode_2028x1080_regs,
@@ -916,14 +893,7 @@ static const struct imx477_mode supported_modes_10bit[] = {
916893
.width = 2664,
917894
.height = 1980,
918895
},
919-
.timeperframe_min = {
920-
.numerator = 100,
921-
.denominator = 12000
922-
},
923-
.timeperframe_default = {
924-
.numerator = 100,
925-
.denominator = 12000
926-
},
896+
.framerate_default = 120,
927897
.reg_list = {
928898
.num_of_regs = ARRAY_SIZE(mode_1332x990_regs),
929899
.regs = mode_1332x990_regs,
@@ -1459,13 +1429,13 @@ static int imx477_get_pad_format(struct v4l2_subdev *sd,
14591429

14601430
static
14611431
unsigned int imx477_get_frame_length(const struct imx477_mode *mode,
1462-
const struct v4l2_fract *timeperframe)
1432+
unsigned int framerate_default)
14631433
{
14641434
u64 frame_length;
14651435

1466-
frame_length = (u64)timeperframe->numerator * IMX477_PIXEL_RATE;
1436+
frame_length = IMX477_PIXEL_RATE;
14671437
do_div(frame_length,
1468-
(u64)timeperframe->denominator * mode->line_length_pix);
1438+
(u64)framerate_default * mode->line_length_pix);
14691439

14701440
if (WARN_ON(frame_length > IMX477_FRAME_LENGTH_MAX))
14711441
frame_length = IMX477_FRAME_LENGTH_MAX;
@@ -1475,21 +1445,20 @@ unsigned int imx477_get_frame_length(const struct imx477_mode *mode,
14751445

14761446
static void imx477_set_framing_limits(struct imx477 *imx477)
14771447
{
1478-
unsigned int frm_length_min, frm_length_default, hblank_min;
1448+
unsigned int frm_length_default, hblank_min;
14791449
const struct imx477_mode *mode = imx477->mode;
14801450

1481-
frm_length_min = imx477_get_frame_length(mode, &mode->timeperframe_min);
14821451
frm_length_default =
1483-
imx477_get_frame_length(mode, &mode->timeperframe_default);
1452+
imx477_get_frame_length(mode, mode->framerate_default);
14841453

14851454
/* Default to no long exposure multiplier. */
14861455
imx477->long_exp_shift = 0;
14871456

14881457
/* Update limits and set FPS to default */
1489-
__v4l2_ctrl_modify_range(imx477->vblank, frm_length_min - mode->height,
1458+
__v4l2_ctrl_modify_range(imx477->vblank, 1,
14901459
((1 << IMX477_LONG_EXP_SHIFT_MAX) *
14911460
IMX477_FRAME_LENGTH_MAX) - mode->height,
1492-
1, frm_length_default - mode->height);
1461+
IMX477_VBLANK_MIN, frm_length_default - mode->height);
14931462

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

0 commit comments

Comments
 (0)