1 From 26934caec8e9a365d71e437333998002b2f2879c Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 17 Feb 2022 16:24:51 +0000
4 Subject: [PATCH] media: i2c: ov7251: Set VTS instead of having full
7 The driver did have a full copy of the registers for each of
8 the 30, 60, and 90 fps modes. The main difference between them were
9 registers 0x380e/f which set the total height of the frame (VTS).
11 Remove the excess register settings, and Set that register value
12 explicitly for each mode.
14 This has dropped a change for the 30fps mode to registers 0x3016,
15 0x3017, 0x3018, 0x301a, 0x301b, and 0x301c. The data available
16 doesn't describe these registers, but the sensor seems fully
17 functional without the alternate settings.
19 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
21 drivers/media/i2c/ov7251.c | 286 +++----------------------------------
22 1 file changed, 21 insertions(+), 265 deletions(-)
24 --- a/drivers/media/i2c/ov7251.c
25 +++ b/drivers/media/i2c/ov7251.c
27 #define OV7251_AEC_AGC_ADJ_1 0x350b
28 /* HTS is registers 0x380c and 0x380d */
29 #define OV7251_HTS 0x3a0
30 +#define OV7251_VTS_HIGH 0x380e
31 +#define OV7251_VTS_LOW 0x380f
32 #define OV7251_TIMING_FORMAT1 0x3820
33 #define OV7251_TIMING_FORMAT1_VFLIP BIT(2)
34 #define OV7251_TIMING_FORMAT2 0x3821
35 @@ -82,6 +84,7 @@ struct ov7251_mode_info {
40 struct v4l2_fract timeperframe;
43 @@ -204,263 +207,7 @@ static const struct reg_value ov7251_glo
47 -static const struct reg_value ov7251_setting_vga_30fps[] = {
99 - { 0x3808, 0x02 }, /* width high */
100 - { 0x3809, 0x80 }, /* width low */
101 - { 0x380a, 0x01 }, /* height high */
102 - { 0x380b, 0xe0 }, /* height low */
103 - { 0x380c, 0x03 }, /* total horiz timing high */
104 - { 0x380d, 0xa0 }, /* total horiz timing low */
105 - { 0x380e, 0x06 }, /* total vertical timing high */
106 - { 0x380f, 0xbc }, /* total vertical timing low */
175 -static const struct reg_value ov7251_setting_vga_60fps[] = {
227 - { 0x3808, 0x02 }, /* width high */
228 - { 0x3809, 0x80 }, /* width low */
229 - { 0x380a, 0x01 }, /* height high */
230 - { 0x380b, 0xe0 }, /* height low */
231 - { 0x380c, 0x03 }, /* total horiz timing high */
232 - { 0x380d, 0xa0 }, /* total horiz timing low */
233 - { 0x380e, 0x03 }, /* total vertical timing high */
234 - { 0x380f, 0x5c }, /* total vertical timing low */
303 -static const struct reg_value ov7251_setting_vga_90fps[] = {
304 +static const struct reg_value ov7251_setting_vga[] = {
308 @@ -518,8 +265,6 @@ static const struct reg_value ov7251_set
309 { 0x380b, 0xe0 }, /* height low */
310 { 0x380c, 0x03 }, /* total horiz timing high */
311 { 0x380d, 0xa0 }, /* total horiz timing low */
312 - { 0x380e, 0x02 }, /* total vertical timing high */
313 - { 0x380f, 0x3c }, /* total vertical timing low */
317 @@ -601,10 +346,11 @@ static const struct ov7251_mode_info ov7
321 - .data = ov7251_setting_vga_30fps,
322 - .data_size = ARRAY_SIZE(ov7251_setting_vga_30fps),
323 + .data = ov7251_setting_vga,
324 + .data_size = ARRAY_SIZE(ov7251_setting_vga),
325 .exposure_max = 1704,
331 @@ -613,10 +359,11 @@ static const struct ov7251_mode_info ov7
335 - .data = ov7251_setting_vga_60fps,
336 - .data_size = ARRAY_SIZE(ov7251_setting_vga_60fps),
337 + .data = ov7251_setting_vga,
338 + .data_size = ARRAY_SIZE(ov7251_setting_vga),
345 @@ -625,10 +372,11 @@ static const struct ov7251_mode_info ov7
349 - .data = ov7251_setting_vga_90fps,
350 - .data_size = ARRAY_SIZE(ov7251_setting_vga_90fps),
351 + .data = ov7251_setting_vga,
352 + .data_size = ARRAY_SIZE(ov7251_setting_vga),
359 @@ -1289,6 +1037,14 @@ static int ov7251_s_stream(struct v4l2_s
360 ov7251->current_mode->height);
363 + ret = ov7251_write_reg(ov7251, OV7251_VTS_HIGH,
364 + ov7251->current_mode->vts >> 8);
366 + goto err_power_down;
367 + ret = ov7251_write_reg(ov7251, OV7251_VTS_LOW,
368 + ov7251->current_mode->vts & 0xff);
370 + goto err_power_down;
371 ret = __v4l2_ctrl_handler_setup(&ov7251->ctrls);
373 dev_err(ov7251->dev, "could not sync v4l2 controls\n");