bcm27xx: switch to 5.15
[openwrt/staging/noltari.git] / target / linux / bcm27xx / patches-5.10 / 950-0273-media-i2c-imx290-Add-H-and-V-flip-controls.patch
1 From ab78051da1ad984c5b424c1e75f487d2a2f2c026 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 11 Jun 2020 18:34:16 +0100
4 Subject: [PATCH] media: i2c: imx290: Add H and V flip controls
5
6 The sensor supports horizontal and vertical flips, so support them
7 through V4L2_CID_HFLIP and V4L2_CID_VFLIP.
8
9 This sensor does NOT change the Bayer order when changing the
10 direction of readout, therefore no special handling is required for
11 that.
12
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
14 ---
15 drivers/media/i2c/imx290.c | 22 ++++++++++++++++++++++
16 1 file changed, 22 insertions(+)
17
18 --- a/drivers/media/i2c/imx290.c
19 +++ b/drivers/media/i2c/imx290.c
20 @@ -34,6 +34,7 @@ enum imx290_clk_index {
21 #define IMX290_STANDBY 0x3000
22 #define IMX290_REGHOLD 0x3001
23 #define IMX290_XMSTA 0x3002
24 +#define IMX290_FLIP_WINMODE 0x3007
25 #define IMX290_FR_FDG_SEL 0x3009
26 #define IMX290_BLKLEVEL_LOW 0x300a
27 #define IMX290_BLKLEVEL_HIGH 0x300b
28 @@ -107,6 +108,8 @@ struct imx290 {
29 struct v4l2_ctrl *pixel_rate;
30 struct v4l2_ctrl *hblank;
31 struct v4l2_ctrl *vblank;
32 + struct v4l2_ctrl *hflip;
33 + struct v4l2_ctrl *vflip;
34 struct v4l2_ctrl *exposure;
35
36 struct mutex lock;
37 @@ -600,6 +603,7 @@ static int imx290_set_ctrl(struct v4l2_c
38 struct imx290 *imx290 = container_of(ctrl->handler,
39 struct imx290, ctrls);
40 int ret = 0;
41 + u8 val;
42
43 /* V4L2 controls values will be applied only when power is already up */
44 if (!pm_runtime_get_if_in_use(imx290->dev))
45 @@ -618,6 +622,16 @@ static int imx290_set_ctrl(struct v4l2_c
46 case V4L2_CID_VBLANK:
47 ret = imx290_set_vmax(imx290, ctrl->val);
48 break;
49 + case V4L2_CID_HFLIP:
50 + case V4L2_CID_VFLIP:
51 + /* WINMODE is in bits [6:4], so need to read-modify-write */
52 + ret = imx290_read_reg(imx290, IMX290_FLIP_WINMODE, &val);
53 + if (ret)
54 + break;
55 + val &= ~0x03;
56 + val |= imx290->vflip->val | (imx290->hflip->val << 1);
57 + ret = imx290_write_reg(imx290, IMX290_FLIP_WINMODE, val);
58 + break;
59 case V4L2_CID_TEST_PATTERN:
60 if (ctrl->val) {
61 imx290_write_reg(imx290, IMX290_BLKLEVEL_LOW, 0x00);
62 @@ -924,6 +938,9 @@ static int imx290_set_stream(struct v4l2
63 imx290_stop_streaming(imx290);
64 pm_runtime_put(imx290->dev);
65 }
66 + /* vflip and hflip cannot change during streaming */
67 + __v4l2_ctrl_grab(imx290->vflip, enable);
68 + __v4l2_ctrl_grab(imx290->hflip, enable);
69
70 unlock_and_return:
71
72 @@ -1217,6 +1234,11 @@ static int imx290_probe(struct i2c_clien
73 IMX290_EXPOSURE_STEP,
74 mode->vmax - 4);
75
76 + imx290->hflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
77 + V4L2_CID_HFLIP, 0, 1, 1, 0);
78 + imx290->vflip = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops,
79 + V4L2_CID_VFLIP, 0, 1, 1, 0);
80 +
81 imx290->link_freq =
82 v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops,
83 V4L2_CID_LINK_FREQ,