07c3e15c95831426a2c44af93de045be0d17b16f
[openwrt/staging/rmilecki.git] /
1 From 03c77d0b8ef969c88e00729dbbf488eba081aa7d Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Tue, 15 Jun 2021 18:34:38 +0100
4 Subject: [PATCH] media: i2c: imx258: Make image geometry meet sensor
5 requirements
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 The output image is defined as being 4208x3118 pixels in size.
11 Y_ADD_STA register was set to 0, and Y_ADD_END to 3118, giving
12 3119 lines total.
13
14 The datasheet lists a requirement for Y_ADD_STA to be a multiple
15 of a power of 2 depending on binning/scaling mode (2 for full pixel,
16 4 for x2-bin/scale, 8 for (x2-bin)+(x2-subsample) or x4-bin, or 16
17 for (x4-bin)+(x2-subsample)).
18 (Y_ADD_END – Y_ADD_STA + 1) also has to be a similar power of 2.
19
20 The current configuration for the full res modes breaks that second
21 requirement, and we can't increase Y_ADD_STA to 1 to retain exactly
22 the same field of view as that then breaks the first requirement.
23 For the binned modes, they are worse off as 3118 is not a multiple of
24 4.
25
26 Increase the main mode to 4208x3120 so that it is the same FOV as the
27 binned modes, with Y_ADD_STA at 0.
28 Fix Y_ADD_STA and Y_ADD_END for the binned modes so that they meet the
29 sensor requirements.
30
31 This does change the Bayer order as the default configuration is for
32 H&V flips to be enabled, so readout is from Y_STA_END to Y_ADD_STA,
33 and this patch has changed Y_STA_END.
34
35 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
36 ---
37 drivers/media/i2c/imx258.c | 26 +++++++++++++-------------
38 1 file changed, 13 insertions(+), 13 deletions(-)
39
40 --- a/drivers/media/i2c/imx258.c
41 +++ b/drivers/media/i2c/imx258.c
42 @@ -110,7 +110,7 @@ struct imx258_mode {
43 struct imx258_reg_list reg_list;
44 };
45
46 -/* 4208x3118 needs 1267Mbps/lane, 4 lanes */
47 +/* 4208x3120 needs 1267Mbps/lane, 4 lanes */
48 static const struct imx258_reg mipi_data_rate_1267mbps[] = {
49 { 0x0301, 0x05 },
50 { 0x0303, 0x02 },
51 @@ -147,7 +147,7 @@ static const struct imx258_reg mipi_data
52 { 0x0823, 0x00 },
53 };
54
55 -static const struct imx258_reg mode_4208x3118_regs[] = {
56 +static const struct imx258_reg mode_4208x3120_regs[] = {
57 { 0x0136, 0x13 },
58 { 0x0137, 0x33 },
59 { 0x3051, 0x00 },
60 @@ -209,7 +209,7 @@ static const struct imx258_reg mode_4208
61 { 0x0348, 0x10 },
62 { 0x0349, 0x6F },
63 { 0x034A, 0x0C },
64 - { 0x034B, 0x2E },
65 + { 0x034B, 0x2F },
66 { 0x0381, 0x01 },
67 { 0x0383, 0x01 },
68 { 0x0385, 0x01 },
69 @@ -328,7 +328,7 @@ static const struct imx258_reg mode_2104
70 { 0x0348, 0x10 },
71 { 0x0349, 0x6F },
72 { 0x034A, 0x0C },
73 - { 0x034B, 0x2E },
74 + { 0x034B, 0x2F },
75 { 0x0381, 0x01 },
76 { 0x0383, 0x01 },
77 { 0x0385, 0x01 },
78 @@ -447,7 +447,7 @@ static const struct imx258_reg mode_1048
79 { 0x0348, 0x10 },
80 { 0x0349, 0x6F },
81 { 0x034A, 0x0C },
82 - { 0x034B, 0x2E },
83 + { 0x034B, 0x2F },
84 { 0x0381, 0x01 },
85 { 0x0383, 0x01 },
86 { 0x0385, 0x01 },
87 @@ -561,12 +561,12 @@ static const struct imx258_link_freq_con
88 static const struct imx258_mode supported_modes[] = {
89 {
90 .width = 4208,
91 - .height = 3118,
92 + .height = 3120,
93 .vts_def = IMX258_VTS_30FPS,
94 .vts_min = IMX258_VTS_30FPS,
95 .reg_list = {
96 - .num_of_regs = ARRAY_SIZE(mode_4208x3118_regs),
97 - .regs = mode_4208x3118_regs,
98 + .num_of_regs = ARRAY_SIZE(mode_4208x3120_regs),
99 + .regs = mode_4208x3120_regs,
100 },
101 .link_freq_index = IMX258_LINK_FREQ_1267MBPS,
102 },
103 @@ -709,7 +709,7 @@ static int imx258_open(struct v4l2_subde
104 /* Initialize try_fmt */
105 try_fmt->width = supported_modes[0].width;
106 try_fmt->height = supported_modes[0].height;
107 - try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
108 + try_fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
109 try_fmt->field = V4L2_FIELD_NONE;
110
111 return 0;
112 @@ -821,7 +821,7 @@ static int imx258_enum_mbus_code(struct
113 if (code->index > 0)
114 return -EINVAL;
115
116 - code->code = MEDIA_BUS_FMT_SGRBG10_1X10;
117 + code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
118
119 return 0;
120 }
121 @@ -833,7 +833,7 @@ static int imx258_enum_frame_size(struct
122 if (fse->index >= ARRAY_SIZE(supported_modes))
123 return -EINVAL;
124
125 - if (fse->code != MEDIA_BUS_FMT_SGRBG10_1X10)
126 + if (fse->code != MEDIA_BUS_FMT_SBGGR10_1X10)
127 return -EINVAL;
128
129 fse->min_width = supported_modes[fse->index].width;
130 @@ -849,7 +849,7 @@ static void imx258_update_pad_format(con
131 {
132 fmt->format.width = mode->width;
133 fmt->format.height = mode->height;
134 - fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
135 + fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10;
136 fmt->format.field = V4L2_FIELD_NONE;
137 }
138
139 @@ -897,7 +897,7 @@ static int imx258_set_pad_format(struct
140 mutex_lock(&imx258->mutex);
141
142 /* Only one raw bayer(GBRG) order is supported */
143 - fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
144 + fmt->format.code = MEDIA_BUS_FMT_SBGGR10_1X10;
145
146 mode = v4l2_find_nearest_size(supported_modes,
147 ARRAY_SIZE(supported_modes), width, height,