bcm27xx: add support for linux v5.15
[openwrt/staging/noltari.git] / target / linux / bcm27xx / patches-5.15 / 950-0368-Added-hflip-and-vflip-controls-to-ov9281.patch
1 From 0eab0865261fd1da54330c59de9e0929e27ec330 Mon Sep 17 00:00:00 2001
2 From: Mathias Anhalt <mathiasanhalt@web.de>
3 Date: Wed, 3 Feb 2021 20:34:09 +0100
4 Subject: [PATCH] Added hflip and vflip controls to ov9281
5
6 Signed-off-by: Mathias Anhalt <mathiasanhalt@web.de>
7 ---
8 drivers/media/i2c/ov9281.c | 58 +++++++++++++++++++++++++++++++++++++-
9 1 file changed, 57 insertions(+), 1 deletion(-)
10
11 --- a/drivers/media/i2c/ov9281.c
12 +++ b/drivers/media/i2c/ov9281.c
13 @@ -40,6 +40,10 @@
14 #define CHIP_ID 0x9281
15 #define OV9281_REG_CHIP_ID 0x300a
16
17 +#define OV9281_REG_TIMING_FORMAT_1 0x3820
18 +#define OV9281_REG_TIMING_FORMAT_2 0x3821
19 +#define OV9281_FLIP_BIT BIT(2)
20 +
21 #define OV9281_REG_CTRL_MODE 0x0100
22 #define OV9281_MODE_SW_STANDBY 0x0
23 #define OV9281_MODE_STREAMING BIT(0)
24 @@ -123,6 +127,8 @@ struct ov9281 {
25 struct v4l2_ctrl *digi_gain;
26 struct v4l2_ctrl *hblank;
27 struct v4l2_ctrl *vblank;
28 + struct v4l2_ctrl *hflip;
29 + struct v4l2_ctrl *vflip;
30 struct v4l2_ctrl *pixel_rate;
31 struct v4l2_ctrl *test_pattern;
32 struct mutex mutex;
33 @@ -615,6 +621,42 @@ static int ov9281_enable_test_pattern(st
34 OV9281_REG_VALUE_08BIT, val);
35 }
36
37 +static int ov9281_set_ctrl_hflip(struct ov9281 *ov9281, int value)
38 +{
39 + u32 current_val;
40 + int ret = ov9281_read_reg(ov9281->client, OV9281_REG_TIMING_FORMAT_2,
41 + OV9281_REG_VALUE_08BIT, &current_val);
42 + if (!ret) {
43 + if (value)
44 + current_val |= OV9281_FLIP_BIT;
45 + else
46 + current_val &= ~OV9281_FLIP_BIT;
47 + return ov9281_write_reg(ov9281->client,
48 + OV9281_REG_TIMING_FORMAT_2,
49 + OV9281_REG_VALUE_08BIT,
50 + current_val);
51 + }
52 + return ret;
53 +}
54 +
55 +static int ov9281_set_ctrl_vflip(struct ov9281 *ov9281, int value)
56 +{
57 + u32 current_val;
58 + int ret = ov9281_read_reg(ov9281->client, OV9281_REG_TIMING_FORMAT_1,
59 + OV9281_REG_VALUE_08BIT, &current_val);
60 + if (!ret) {
61 + if (value)
62 + current_val |= OV9281_FLIP_BIT;
63 + else
64 + current_val &= ~OV9281_FLIP_BIT;
65 + return ov9281_write_reg(ov9281->client,
66 + OV9281_REG_TIMING_FORMAT_1,
67 + OV9281_REG_VALUE_08BIT,
68 + current_val);
69 + }
70 + return ret;
71 +}
72 +
73 static const struct v4l2_rect *
74 __ov9281_get_pad_crop(struct ov9281 *ov9281, struct v4l2_subdev_pad_config *cfg,
75 unsigned int pad, enum v4l2_subdev_format_whence which)
76 @@ -933,6 +975,12 @@ static int ov9281_set_ctrl(struct v4l2_c
77 return 0;
78
79 switch (ctrl->id) {
80 + case V4L2_CID_HFLIP:
81 + ret = ov9281_set_ctrl_hflip(ov9281, ctrl->val);
82 + break;
83 + case V4L2_CID_VFLIP:
84 + ret = ov9281_set_ctrl_vflip(ov9281, ctrl->val);
85 + break;
86 case V4L2_CID_EXPOSURE:
87 /* 4 least significant bits of expsoure are fractional part */
88 ret = ov9281_write_reg(ov9281->client, OV9281_REG_EXPOSURE,
89 @@ -981,7 +1029,7 @@ static int ov9281_initialize_controls(st
90
91 handler = &ov9281->ctrl_handler;
92 mode = ov9281->cur_mode;
93 - ret = v4l2_ctrl_handler_init(handler, 8);
94 + ret = v4l2_ctrl_handler_init(handler, 9);
95 if (ret)
96 return ret;
97 handler->lock = &ov9281->mutex;
98 @@ -1022,6 +1070,14 @@ static int ov9281_initialize_controls(st
99 OV9281_GAIN_STEP,
100 OV9281_GAIN_DEFAULT);
101
102 + ov9281->vflip = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
103 + V4L2_CID_VFLIP,
104 + 0, 1, 1, 0);
105 +
106 + ov9281->hflip = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
107 + V4L2_CID_HFLIP,
108 + 0, 1, 1, 0);
109 +
110 ov9281->test_pattern =
111 v4l2_ctrl_new_std_menu_items(handler, &ov9281_ctrl_ops,
112 V4L2_CID_TEST_PATTERN,