Skip to content

Commit 9764f34

Browse files
6by9popcornmix
authored andcommitted
media: i2c: imx290: Add H and V flip controls
The sensor supports horizontal and vertical flips, so support them through V4L2_CID_HFLIP and V4L2_CID_VFLIP. This sensor does NOT change the Bayer order when changing the direction of readout, therefore no special handling is required for that. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
1 parent 8483f0d commit 9764f34

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎drivers/media/i2c/imx290.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ enum imx290_clk_index {
3434
#define IMX290_STANDBY 0x3000
3535
#define IMX290_REGHOLD 0x3001
3636
#define IMX290_XMSTA 0x3002
37+
#define IMX290_FLIP_WINMODE 0x3007
3738
#define IMX290_FR_FDG_SEL 0x3009
3839
#define IMX290_BLKLEVEL_LOW 0x300a
3940
#define IMX290_BLKLEVEL_HIGH 0x300b
@@ -107,6 +108,8 @@ struct imx290 {
107108
struct v4l2_ctrl *pixel_rate;
108109
struct v4l2_ctrl *hblank;
109110
struct v4l2_ctrl *vblank;
111+
struct v4l2_ctrl *hflip;
112+
struct v4l2_ctrl *vflip;
110113
struct v4l2_ctrl *exposure;
111114

112115
struct mutex lock;
@@ -600,6 +603,7 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl)
600603
struct imx290 *imx290 = container_of(ctrl->handler,
601604
struct imx290, ctrls);
602605
int ret = 0;
606+
u8 val;
603607

604608
/* V4L2 controls values will be applied only when power is already up */
605609
if (!pm_runtime_get_if_in_use(imx290->dev))
@@ -618,6 +622,16 @@ static int imx290_set_ctrl(struct v4l2_ctrl *ctrl)
618622
case V4L2_CID_VBLANK:
619623
ret = imx290_set_vmax(imx290, ctrl->val);
620624
break;
625+
case V4L2_CID_HFLIP:
626+
case V4L2_CID_VFLIP:
627+
/* WINMODE is in bits [6:4], so need to read-modify-write */
628+
ret = imx290_read_reg(imx290, IMX290_FLIP_WINMODE, &val);
629+
if (ret)
630+
break;
631+
val &= ~0x03;
632+
val |= imx290->vflip->val | (imx290->hflip->val << 1);
633+
ret = imx290_write_reg(imx290, IMX290_FLIP_WINMODE, val);
634+
break;
621635
case V4L2_CID_TEST_PATTERN:
622636
if (ctrl->val) {
623637
imx290_write_reg(imx290, IMX290_BLKLEVEL_LOW, 0x00);
@@ -924,6 +938,9 @@ static int imx290_set_stream(struct v4l2_subdev *sd, int enable)
924938
imx290_stop_streaming(imx290);
925939
pm_runtime_put(imx290->dev);
926940
}
941+
/* vflip and hflip cannot change during streaming */
942+
__v4l2_ctrl_grab(imx290->vflip, enable);
943+
__v4l2_ctrl_grab(imx290->hflip, enable);
927944

928945
unlock_and_return:
929946

@@ -1217,6 +1234,11 @@ static int imx290_probe(struct i2c_client *client)
12171234
IMX290_EXPOSURE_STEP,
12181235
mode->vmax - 4);
12191236

1237+
imx290->hflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
1238+
V4L2_CID_HFLIP, 0, 1, 1, 0);
1239+
imx290->vflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
1240+
V4L2_CID_VFLIP, 0, 1, 1, 0);
1241+
12201242
imx290->link_freq =
12211243
v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops,
12221244
V4L2_CID_LINK_FREQ,

0 commit comments

Comments
 (0)