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
6 Signed-off-by: Mathias Anhalt <mathiasanhalt@web.de>
8 drivers/media/i2c/ov9281.c | 58 +++++++++++++++++++++++++++++++++++++-
9 1 file changed, 57 insertions(+), 1 deletion(-)
11 --- a/drivers/media/i2c/ov9281.c
12 +++ b/drivers/media/i2c/ov9281.c
14 #define CHIP_ID 0x9281
15 #define OV9281_REG_CHIP_ID 0x300a
17 +#define OV9281_REG_TIMING_FORMAT_1 0x3820
18 +#define OV9281_REG_TIMING_FORMAT_2 0x3821
19 +#define OV9281_FLIP_BIT BIT(2)
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;
33 @@ -615,6 +621,42 @@ static int ov9281_enable_test_pattern(st
34 OV9281_REG_VALUE_08BIT, val);
37 +static int ov9281_set_ctrl_hflip(struct ov9281 *ov9281, int value)
40 + int ret = ov9281_read_reg(ov9281->client, OV9281_REG_TIMING_FORMAT_2,
41 + OV9281_REG_VALUE_08BIT, ¤t_val);
44 + current_val |= OV9281_FLIP_BIT;
46 + current_val &= ~OV9281_FLIP_BIT;
47 + return ov9281_write_reg(ov9281->client,
48 + OV9281_REG_TIMING_FORMAT_2,
49 + OV9281_REG_VALUE_08BIT,
55 +static int ov9281_set_ctrl_vflip(struct ov9281 *ov9281, int value)
58 + int ret = ov9281_read_reg(ov9281->client, OV9281_REG_TIMING_FORMAT_1,
59 + OV9281_REG_VALUE_08BIT, ¤t_val);
62 + current_val |= OV9281_FLIP_BIT;
64 + current_val &= ~OV9281_FLIP_BIT;
65 + return ov9281_write_reg(ov9281->client,
66 + OV9281_REG_TIMING_FORMAT_1,
67 + OV9281_REG_VALUE_08BIT,
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
80 + case V4L2_CID_HFLIP:
81 + ret = ov9281_set_ctrl_hflip(ov9281, ctrl->val);
83 + case V4L2_CID_VFLIP:
84 + ret = ov9281_set_ctrl_vflip(ov9281, ctrl->val);
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
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);
97 handler->lock = &ov9281->mutex;
98 @@ -1022,6 +1070,14 @@ static int ov9281_initialize_controls(st
100 OV9281_GAIN_DEFAULT);
102 + ov9281->vflip = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
106 + ov9281->hflip = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
110 ov9281->test_pattern =
111 v4l2_ctrl_new_std_menu_items(handler, &ov9281_ctrl_ops,
112 V4L2_CID_TEST_PATTERN,