ov5675: add vflip/hflip control support
PATCH 1/1 ov5675: add vflip/hflip control support
From: Shawnx <[email protected]>
Add V4L2 controls: horizontal/vertical flip
Signed-off-by Shawn Tu <[email protected]>
--- drivers/media/i2c/ov5675.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
drivers/media/i2c/ov5675.c +52 -0
@@ -63,6 +63,11 @@#define OV5675_TEST_PATTERN_ENABLE BIT(7)#define OV5675_TEST_PATTERN_BAR_SHIFT 2 +/* Flip Mirror Controls from sensor */ +#define OV5675_REG_FORMAT1 0x3820 +#define OV5675_REG_FORMAT1_HFLIP BIT(3) +#define OV5675_REG_FORMAT1_VFLIP BIT(4) +#define to_ov5675 (_sd) container_of(_sd, struct ov5675, sd)enum {
@@ -604,6 +609,40 @@ static int ov5675_test_pattern(struct ov5675 *ov5675, u32 pattern) OV5675_REG_VALUE_08BIT, pattern); } +static int ov5675_set_ctrl_hflip (struct ov5675 *ov5675,u32 ctrl_val) +{ +int ret; +u32 val; + + ret =ov5675_read_reg (ov5675,OV5675_REG_FORMAT1 , +OV5675_REG_VALUE_08BIT , &val); +if (ret) +return ret; + +if (ctrl_val) + val &= ~OV5675_REG_FORMAT1_HFLIP ; + +return ov5675_write_reg (ov5675,OV5675_REG_FORMAT1 , +OV5675_REG_VALUE_08BIT , val); +} + +static int ov5675_set_ctrl_vflip (struct ov5675 *ov5675,u8 ctrl_val) +{ +int ret; +u32 val; + + ret =ov5675_read_reg (ov5675,OV5675_REG_FORMAT1 , +OV5675_REG_VALUE_08BIT , &val); +if (ret) +return ret; + +if (ctrl_val) + val |=OV5675_REG_FORMAT1_VFLIP ; + +return ov5675_write_reg (ov5675,OV5675_REG_FORMAT1 , +OV5675_REG_VALUE_08BIT , val); +} +static int ov5675_set_ctrl (struct v4l2_ctrl *ctrl) { struct ov5675 *ov5675 = container_of(ctrl->handler,
@@ -654,6 +693,14 @@ static int ov5675_set_ctrl(struct v4l2_ctrl *ctrl) ret =ov5675_test_pattern (ov5675, ctrl->val);break ; +case V4L2_CID_HFLIP : +ov5675_set_ctrl_hflip (ov5675, ctrl->val); +break ; + +case V4L2_CID_VFLIP : +ov5675_set_ctrl_vflip (ov5675, ctrl->val); +break ; +default : ret = -EINVAL ;break ;
@@ -722,6 +769,11 @@ static int ov5675_init_controls(struct ov5675 *ov5675)V4L2_CID_TEST_PATTERN ,ARRAY_SIZE (ov5675_test_pattern_menu) -1 , 0, 0, ov5675_test_pattern_menu); +v4l2_ctrl_new_std (ctrl_hdlr, &ov5675_ctrl_ops, +V4L2_CID_HFLIP ,0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std (ctrl_hdlr, &ov5675_ctrl_ops, +V4L2_CID_VFLIP ,0 ,1 ,1 ,0 ); +if (ctrl_hdlr->error)return ctrl_hdlr->error;
Signature · 1 line
2.7.4
Sakari Ailus
maintainerHi Shawn,
Thank you for the patch.
Quoted 1 line · Shawnx Tu
From: Shawnx <[email protected]>
Could you fix your name here? It seems to be correct in the Sob tag.
Quoted 30 lines
Add V4L2 controls: horizontal/vertical flip
Signed-off-by Shawn Tu <[email protected]>--- drivers/media/i2c/ov5675.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)drivers/media/i2c/ov5675.c +7
-0@@ -63,6 +63,11 @@#define OV5675_TEST_PATTERN_ENABLE BIT(7)#define OV5675_TEST_PATTERN_BAR_SHIFT 2 +/* Flip Mirror Controls from sensor */ +#define OV5675_REG_FORMAT1 0x3820 +#define OV5675_REG_FORMAT1_HFLIP BIT(3) +#define OV5675_REG_FORMAT1_VFLIP BIT(4) +#define to_ov5675 (_sd) container_of(_sd, struct ov5675, sd)enum {@@ -604,6 +609,40 @@ static int ov5675_test_pattern(struct ov5675 *ov5675, u32 pattern) OV5675_REG_VALUE_08BIT, pattern); } +static int ov5675_set_ctrl_hflip (struct ov5675 *ov5675,u32 ctrl_val) +{
drivers/media/i2c/ov5675.c static int ov5675_test_pattern(struct ov5675 *ov5675, u32 pattern) · line 623
Quoted 10 lines
drivers/media/i2c/ov5675.c +10
-0+int ret; +u32 val; + + ret =ov5675_read_reg (ov5675,OV5675_REG_FORMAT1 , +OV5675_REG_VALUE_08BIT , &val); +if (ret) +return ret; + +if (ctrl_val) + val &= ~OV5675_REG_FORMAT1_HFLIP ;
Shouldn't this be:
val = (val & ~OV5675_REG_FORMAT1_HFLIP) | (ctrl_val ? OV5675_REG_FORMAT1_HFLIP : 0);
Or something alike? Same below.
Quoted 11 lines
drivers/media/i2c/ov5675.c +11
-0+ +return ov5675_write_reg (ov5675,OV5675_REG_FORMAT1 , +OV5675_REG_VALUE_08BIT , val); +} + +static int ov5675_set_ctrl_vflip (struct ov5675 *ov5675,u8 ctrl_val) +{ +int ret; +u32 val; + + ret = ov5675_read_reg(ov5675, OV5675_REG_FORMAT1,
drivers/media/i2c/ov5675.c static int ov5675_test_pattern(struct ov5675 *ov5675, u32 pattern) · line 644
Quoted 10 lines
drivers/media/i2c/ov5675.c +10
-0+ OV5675_REG_VALUE_08BIT, &val); +if (ret) +return ret; + +if (ctrl_val) + val |=OV5675_REG_FORMAT1_VFLIP ; + +return ov5675_write_reg (ov5675,OV5675_REG_FORMAT1 , +OV5675_REG_VALUE_08BIT , val); +}
As this is a raw Bayer sensor, the pattern changes as a function of the flip controls. Could you take that into account, please?
Quoted 31 lines
drivers/media/i2c/ov5675.c +14
-0+static int ov5675_set_ctrl (struct v4l2_ctrl *ctrl) { struct ov5675 *ov5675 = container_of(ctrl->handler,@@ -654,6 +693,14 @@ static int ov5675_set_ctrl(struct v4l2_ctrl *ctrl) ret =ov5675_test_pattern (ov5675, ctrl->val);break ; +case V4L2_CID_HFLIP : +ov5675_set_ctrl_hflip (ov5675, ctrl->val); +break ; + +case V4L2_CID_VFLIP : +ov5675_set_ctrl_vflip (ov5675, ctrl->val); +break ; +default : ret = -EINVAL ;break ;@@ -722,6 +769,11 @@ static int ov5675_init_controls(struct ov5675 *ov5675)V4L2_CID_TEST_PATTERN ,ARRAY_SIZE (ov5675_test_pattern_menu) -1 , 0, 0, ov5675_test_pattern_menu); +v4l2_ctrl_new_std (ctrl_hdlr, &ov5675_ctrl_ops, +V4L2_CID_HFLIP ,0 ,1 ,1 ,0 ); +v4l2_ctrl_new_std (ctrl_hdlr, &ov5675_ctrl_ops, +V4L2_CID_VFLIP ,0 ,1 ,1 ,0 ); +if (ctrl_hdlr->error)return ctrl_hdlr->error;
Signature · 3 lines
Kind regards, Sakari Ailus