Skip to content

Commit 5978efa

Browse files
Umang Jainpopcornmix
authored andcommitted
media: imx335: Support vertical flip
Support vertical flip by setting REG_VREVERSE. Additional registers also needs to be set per mode, according to the readout direction (normal/inverted) as mentioned in the data sheet. Since the register IMX335_REG_AREA3_ST_ADR_1 is based on the flip (and is set via vflip related registers), it has been moved out of the 2592x1944 mode regs. Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Tommaso Merciai <tomm.merciai@gmail.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
1 parent b89e5e0 commit 5978efa

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

drivers/media/i2c/imx335.c

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
#define IMX335_AGAIN_STEP 1
5757
#define IMX335_AGAIN_DEFAULT 0
5858

59+
/* Vertical flip */
60+
#define IMX335_REG_VREVERSE CCI_REG8(0x304f)
61+
5962
#define IMX335_REG_TPG_TESTCLKEN CCI_REG8(0x3148)
6063

6164
#define IMX335_REG_INCLKSEL1 CCI_REG16_LE(0x314c)
@@ -155,6 +158,8 @@ static const char * const imx335_supply_name[] = {
155158
* @vblank_max: Maximum vertical blanking in lines
156159
* @pclk: Sensor pixel clock
157160
* @reg_list: Register list for sensor mode
161+
* @vflip_normal: Register list vflip (normal readout)
162+
* @vflip_inverted: Register list vflip (inverted readout)
158163
*/
159164
struct imx335_mode {
160165
u32 width;
@@ -166,6 +171,8 @@ struct imx335_mode {
166171
u32 vblank_max;
167172
u64 pclk;
168173
struct imx335_reg_list reg_list;
174+
struct imx335_reg_list vflip_normal;
175+
struct imx335_reg_list vflip_inverted;
169176
};
170177

171178
/**
@@ -183,6 +190,7 @@ struct imx335_mode {
183190
* @pclk_ctrl: Pointer to pixel clock control
184191
* @hblank_ctrl: Pointer to horizontal blanking control
185192
* @vblank_ctrl: Pointer to vertical blanking control
193+
* @vflip: Pointer to vertical flip control
186194
* @exp_ctrl: Pointer to exposure control
187195
* @again_ctrl: Pointer to analog gain control
188196
* @vblank: Vertical blanking in lines
@@ -207,6 +215,7 @@ struct imx335 {
207215
struct v4l2_ctrl *pclk_ctrl;
208216
struct v4l2_ctrl *hblank_ctrl;
209217
struct v4l2_ctrl *vblank_ctrl;
218+
struct v4l2_ctrl *vflip;
210219
struct {
211220
struct v4l2_ctrl *exp_ctrl;
212221
struct v4l2_ctrl *again_ctrl;
@@ -259,7 +268,6 @@ static const struct cci_reg_sequence mode_2592x1944_regs[] = {
259268
{ IMX335_REG_HTRIMMING_START, 48 },
260269
{ IMX335_REG_HNUM, 2592 },
261270
{ IMX335_REG_Y_OUT_SIZE, 1944 },
262-
{ IMX335_REG_AREA3_ST_ADR_1, 176 },
263271
{ IMX335_REG_AREA3_WIDTH_1, 3928 },
264272
{ IMX335_REG_OPB_SIZE_V, 0 },
265273
{ IMX335_REG_XVS_XHS_DRV, 0x00 },
@@ -333,6 +341,26 @@ static const struct cci_reg_sequence mode_2592x1944_regs[] = {
333341
{ CCI_REG8(0x3a00), 0x00 },
334342
};
335343

344+
static const struct cci_reg_sequence mode_2592x1944_vflip_normal[] = {
345+
{ IMX335_REG_AREA3_ST_ADR_1, 176 },
346+
347+
/* Undocumented V-Flip related registers on Page 55 of datasheet. */
348+
{ CCI_REG8(0x3081), 0x02, },
349+
{ CCI_REG8(0x3083), 0x02, },
350+
{ CCI_REG16_LE(0x30b6), 0x00 },
351+
{ CCI_REG16_LE(0x3116), 0x08 },
352+
};
353+
354+
static const struct cci_reg_sequence mode_2592x1944_vflip_inverted[] = {
355+
{ IMX335_REG_AREA3_ST_ADR_1, 4112 },
356+
357+
/* Undocumented V-Flip related registers on Page 55 of datasheet. */
358+
{ CCI_REG8(0x3081), 0xfe, },
359+
{ CCI_REG8(0x3083), 0xfe, },
360+
{ CCI_REG16_LE(0x30b6), 0x1fa },
361+
{ CCI_REG16_LE(0x3116), 0x002 },
362+
};
363+
336364
static const struct cci_reg_sequence raw10_framefmt_regs[] = {
337365
{ IMX335_REG_ADBIT, 0x00 },
338366
{ IMX335_REG_MDBIT, 0x00 },
@@ -419,6 +447,14 @@ static const struct imx335_mode supported_mode = {
419447
.num_of_regs = ARRAY_SIZE(mode_2592x1944_regs),
420448
.regs = mode_2592x1944_regs,
421449
},
450+
.vflip_normal = {
451+
.num_of_regs = ARRAY_SIZE(mode_2592x1944_vflip_normal),
452+
.regs = mode_2592x1944_vflip_normal,
453+
},
454+
.vflip_inverted = {
455+
.num_of_regs = ARRAY_SIZE(mode_2592x1944_vflip_inverted),
456+
.regs = mode_2592x1944_vflip_inverted,
457+
},
422458
};
423459

424460
/**
@@ -492,6 +528,26 @@ static int imx335_update_exp_gain(struct imx335 *imx335, u32 exposure, u32 gain)
492528
return ret;
493529
}
494530

531+
static int imx335_update_vertical_flip(struct imx335 *imx335, u32 vflip)
532+
{
533+
int ret = 0;
534+
535+
if (vflip)
536+
cci_multi_reg_write(imx335->cci,
537+
imx335->cur_mode->vflip_inverted.regs,
538+
imx335->cur_mode->vflip_inverted.num_of_regs,
539+
&ret);
540+
else
541+
cci_multi_reg_write(imx335->cci,
542+
imx335->cur_mode->vflip_normal.regs,
543+
imx335->cur_mode->vflip_normal.num_of_regs,
544+
&ret);
545+
if (ret)
546+
return ret;
547+
548+
return cci_write(imx335->cci, IMX335_REG_VREVERSE, vflip, NULL);
549+
}
550+
495551
static int imx335_update_test_pattern(struct imx335 *imx335, u32 pattern_index)
496552
{
497553
int ret = 0;
@@ -584,6 +640,10 @@ static int imx335_set_ctrl(struct v4l2_ctrl *ctrl)
584640

585641
ret = imx335_update_exp_gain(imx335, exposure, analog_gain);
586642

643+
break;
644+
case V4L2_CID_VFLIP:
645+
ret = imx335_update_vertical_flip(imx335, ctrl->val);
646+
587647
break;
588648
case V4L2_CID_TEST_PATTERN:
589649
ret = imx335_update_test_pattern(imx335, ctrl->val);
@@ -1166,7 +1226,7 @@ static int imx335_init_controls(struct imx335 *imx335)
11661226
return ret;
11671227

11681228
/* v4l2_fwnode_device_properties can add two more controls */
1169-
ret = v4l2_ctrl_handler_init(ctrl_hdlr, 9);
1229+
ret = v4l2_ctrl_handler_init(ctrl_hdlr, 10);
11701230
if (ret)
11711231
return ret;
11721232

@@ -1201,6 +1261,13 @@ static int imx335_init_controls(struct imx335 *imx335)
12011261

12021262
v4l2_ctrl_cluster(2, &imx335->exp_ctrl);
12031263

1264+
imx335->vflip = v4l2_ctrl_new_std(ctrl_hdlr,
1265+
&imx335_ctrl_ops,
1266+
V4L2_CID_VFLIP,
1267+
0, 1, 1, 0);
1268+
if (imx335->vflip)
1269+
imx335->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;
1270+
12041271
imx335->vblank_ctrl = v4l2_ctrl_new_std(ctrl_hdlr,
12051272
&imx335_ctrl_ops,
12061273
V4L2_CID_VBLANK,

0 commit comments

Comments
 (0)