提交 bfd90eef 编写于 作者: M Mathias Anhalt 提交者: Zheng Zengkai

Added hflip and vflip controls to ov9281

raspberrypi inclusion
category: feature
bugzilla: 50432

--------------------------------
Signed-off-by: NMathias Anhalt <mathiasanhalt@web.de>
Signed-off-by: NFang Yafen <yafen@iscas.ac.cn>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 a0f5c5f2
......@@ -40,6 +40,10 @@
#define CHIP_ID 0x9281
#define OV9281_REG_CHIP_ID 0x300a
#define OV9281_REG_TIMING_FORMAT_1 0x3820
#define OV9281_REG_TIMING_FORMAT_2 0x3821
#define OV9281_FLIP_BIT BIT(2)
#define OV9281_REG_CTRL_MODE 0x0100
#define OV9281_MODE_SW_STANDBY 0x0
#define OV9281_MODE_STREAMING BIT(0)
......@@ -123,6 +127,8 @@ struct ov9281 {
struct v4l2_ctrl *digi_gain;
struct v4l2_ctrl *hblank;
struct v4l2_ctrl *vblank;
struct v4l2_ctrl *hflip;
struct v4l2_ctrl *vflip;
struct v4l2_ctrl *pixel_rate;
struct v4l2_ctrl *test_pattern;
struct mutex mutex;
......@@ -615,6 +621,42 @@ static int ov9281_enable_test_pattern(struct ov9281 *ov9281, u32 pattern)
OV9281_REG_VALUE_08BIT, val);
}
static int ov9281_set_ctrl_hflip(struct ov9281 *ov9281, int value)
{
u32 current_val;
int ret = ov9281_read_reg(ov9281->client, OV9281_REG_TIMING_FORMAT_2,
OV9281_REG_VALUE_08BIT, &current_val);
if (!ret) {
if (value)
current_val |= OV9281_FLIP_BIT;
else
current_val &= ~OV9281_FLIP_BIT;
return ov9281_write_reg(ov9281->client,
OV9281_REG_TIMING_FORMAT_2,
OV9281_REG_VALUE_08BIT,
current_val);
}
return ret;
}
static int ov9281_set_ctrl_vflip(struct ov9281 *ov9281, int value)
{
u32 current_val;
int ret = ov9281_read_reg(ov9281->client, OV9281_REG_TIMING_FORMAT_1,
OV9281_REG_VALUE_08BIT, &current_val);
if (!ret) {
if (value)
current_val |= OV9281_FLIP_BIT;
else
current_val &= ~OV9281_FLIP_BIT;
return ov9281_write_reg(ov9281->client,
OV9281_REG_TIMING_FORMAT_1,
OV9281_REG_VALUE_08BIT,
current_val);
}
return ret;
}
static const struct v4l2_rect *
__ov9281_get_pad_crop(struct ov9281 *ov9281, struct v4l2_subdev_pad_config *cfg,
unsigned int pad, enum v4l2_subdev_format_whence which)
......@@ -933,6 +975,12 @@ static int ov9281_set_ctrl(struct v4l2_ctrl *ctrl)
return 0;
switch (ctrl->id) {
case V4L2_CID_HFLIP:
ret = ov9281_set_ctrl_hflip(ov9281, ctrl->val);
break;
case V4L2_CID_VFLIP:
ret = ov9281_set_ctrl_vflip(ov9281, ctrl->val);
break;
case V4L2_CID_EXPOSURE:
/* 4 least significant bits of expsoure are fractional part */
ret = ov9281_write_reg(ov9281->client, OV9281_REG_EXPOSURE,
......@@ -981,7 +1029,7 @@ static int ov9281_initialize_controls(struct ov9281 *ov9281)
handler = &ov9281->ctrl_handler;
mode = ov9281->cur_mode;
ret = v4l2_ctrl_handler_init(handler, 8);
ret = v4l2_ctrl_handler_init(handler, 9);
if (ret)
return ret;
handler->lock = &ov9281->mutex;
......@@ -1022,6 +1070,14 @@ static int ov9281_initialize_controls(struct ov9281 *ov9281)
OV9281_GAIN_STEP,
OV9281_GAIN_DEFAULT);
ov9281->vflip = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
V4L2_CID_VFLIP,
0, 1, 1, 0);
ov9281->hflip = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
V4L2_CID_HFLIP,
0, 1, 1, 0);
ov9281->test_pattern =
v4l2_ctrl_new_std_menu_items(handler, &ov9281_ctrl_ops,
V4L2_CID_TEST_PATTERN,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册