Commit ed351ad9 authored by Chiranjeevi Rapolu's avatar Chiranjeevi Rapolu Committed by Mauro Carvalho Chehab

media: ov5670: Limit vblank to permissible range

Previously, vblank range given to user was too big, falling outside
of permissible range for a given resolution. Sometimes, too low vblank
resulted in errors.

Now, limit vblank to only permissible range for a given resolution.
This change limits lower-bounds of vblank, doesn't affect upper bounds.
Signed-off-by: default avatarChiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 070ed82e
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#define OV5670_REG_VTS 0x380e #define OV5670_REG_VTS 0x380e
#define OV5670_VTS_30FPS 0x0808 /* default for 30 fps */ #define OV5670_VTS_30FPS 0x0808 /* default for 30 fps */
#define OV5670_VTS_MAX 0xffff #define OV5670_VTS_MAX 0xffff
#define OV5670_VBLANK_MIN 56
/* horizontal-timings from sensor */ /* horizontal-timings from sensor */
#define OV5670_REG_HTS 0x380c #define OV5670_REG_HTS 0x380c
...@@ -100,8 +99,11 @@ struct ov5670_mode { ...@@ -100,8 +99,11 @@ struct ov5670_mode {
/* Frame height in pixels */ /* Frame height in pixels */
u32 height; u32 height;
/* Vertical timining size */ /* Default vertical timining size */
u32 vts; u32 vts_def;
/* Min vertical timining size */
u32 vts_min;
/* Link frequency needed for this resolution */ /* Link frequency needed for this resolution */
u32 link_freq_index; u32 link_freq_index;
...@@ -1737,7 +1739,8 @@ static const struct ov5670_mode supported_modes[] = { ...@@ -1737,7 +1739,8 @@ static const struct ov5670_mode supported_modes[] = {
{ {
.width = 2592, .width = 2592,
.height = 1944, .height = 1944,
.vts = OV5670_VTS_30FPS, .vts_def = OV5670_VTS_30FPS,
.vts_min = OV5670_VTS_30FPS,
.reg_list = { .reg_list = {
.num_of_regs = ARRAY_SIZE(mode_2592x1944_regs), .num_of_regs = ARRAY_SIZE(mode_2592x1944_regs),
.regs = mode_2592x1944_regs, .regs = mode_2592x1944_regs,
...@@ -1747,7 +1750,8 @@ static const struct ov5670_mode supported_modes[] = { ...@@ -1747,7 +1750,8 @@ static const struct ov5670_mode supported_modes[] = {
{ {
.width = 1296, .width = 1296,
.height = 972, .height = 972,
.vts = OV5670_VTS_30FPS, .vts_def = OV5670_VTS_30FPS,
.vts_min = 996,
.reg_list = { .reg_list = {
.num_of_regs = ARRAY_SIZE(mode_1296x972_regs), .num_of_regs = ARRAY_SIZE(mode_1296x972_regs),
.regs = mode_1296x972_regs, .regs = mode_1296x972_regs,
...@@ -1757,7 +1761,8 @@ static const struct ov5670_mode supported_modes[] = { ...@@ -1757,7 +1761,8 @@ static const struct ov5670_mode supported_modes[] = {
{ {
.width = 648, .width = 648,
.height = 486, .height = 486,
.vts = OV5670_VTS_30FPS, .vts_def = OV5670_VTS_30FPS,
.vts_min = 516,
.reg_list = { .reg_list = {
.num_of_regs = ARRAY_SIZE(mode_648x486_regs), .num_of_regs = ARRAY_SIZE(mode_648x486_regs),
.regs = mode_648x486_regs, .regs = mode_648x486_regs,
...@@ -1767,7 +1772,8 @@ static const struct ov5670_mode supported_modes[] = { ...@@ -1767,7 +1772,8 @@ static const struct ov5670_mode supported_modes[] = {
{ {
.width = 2560, .width = 2560,
.height = 1440, .height = 1440,
.vts = OV5670_VTS_30FPS, .vts_def = OV5670_VTS_30FPS,
.vts_min = OV5670_VTS_30FPS,
.reg_list = { .reg_list = {
.num_of_regs = ARRAY_SIZE(mode_2560x1440_regs), .num_of_regs = ARRAY_SIZE(mode_2560x1440_regs),
.regs = mode_2560x1440_regs, .regs = mode_2560x1440_regs,
...@@ -1777,7 +1783,8 @@ static const struct ov5670_mode supported_modes[] = { ...@@ -1777,7 +1783,8 @@ static const struct ov5670_mode supported_modes[] = {
{ {
.width = 1280, .width = 1280,
.height = 720, .height = 720,
.vts = OV5670_VTS_30FPS, .vts_def = OV5670_VTS_30FPS,
.vts_min = 1020,
.reg_list = { .reg_list = {
.num_of_regs = ARRAY_SIZE(mode_1280x720_regs), .num_of_regs = ARRAY_SIZE(mode_1280x720_regs),
.regs = mode_1280x720_regs, .regs = mode_1280x720_regs,
...@@ -1787,7 +1794,8 @@ static const struct ov5670_mode supported_modes[] = { ...@@ -1787,7 +1794,8 @@ static const struct ov5670_mode supported_modes[] = {
{ {
.width = 640, .width = 640,
.height = 360, .height = 360,
.vts = OV5670_VTS_30FPS, .vts_def = OV5670_VTS_30FPS,
.vts_min = 510,
.reg_list = { .reg_list = {
.num_of_regs = ARRAY_SIZE(mode_640x360_regs), .num_of_regs = ARRAY_SIZE(mode_640x360_regs),
.regs = mode_640x360_regs, .regs = mode_640x360_regs,
...@@ -2046,6 +2054,7 @@ static int ov5670_init_controls(struct ov5670 *ov5670) ...@@ -2046,6 +2054,7 @@ static int ov5670_init_controls(struct ov5670 *ov5670)
struct v4l2_ctrl_handler *ctrl_hdlr; struct v4l2_ctrl_handler *ctrl_hdlr;
s64 vblank_max; s64 vblank_max;
s64 vblank_def; s64 vblank_def;
s64 vblank_min;
s64 exposure_max; s64 exposure_max;
int ret; int ret;
...@@ -2070,9 +2079,10 @@ static int ov5670_init_controls(struct ov5670 *ov5670) ...@@ -2070,9 +2079,10 @@ static int ov5670_init_controls(struct ov5670 *ov5670)
link_freq_configs[0].pixel_rate); link_freq_configs[0].pixel_rate);
vblank_max = OV5670_VTS_MAX - ov5670->cur_mode->height; vblank_max = OV5670_VTS_MAX - ov5670->cur_mode->height;
vblank_def = ov5670->cur_mode->vts - ov5670->cur_mode->height; vblank_def = ov5670->cur_mode->vts_def - ov5670->cur_mode->height;
vblank_min = ov5670->cur_mode->vts_min - ov5670->cur_mode->height;
ov5670->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, ov5670->vblank = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
V4L2_CID_VBLANK, OV5670_VBLANK_MIN, V4L2_CID_VBLANK, vblank_min,
vblank_max, 1, vblank_def); vblank_max, 1, vblank_def);
ov5670->hblank = v4l2_ctrl_new_std( ov5670->hblank = v4l2_ctrl_new_std(
...@@ -2094,7 +2104,7 @@ static int ov5670_init_controls(struct ov5670 *ov5670) ...@@ -2094,7 +2104,7 @@ static int ov5670_init_controls(struct ov5670 *ov5670)
OV5670_DGTL_GAIN_STEP, OV5670_DGTL_GAIN_DEFAULT); OV5670_DGTL_GAIN_STEP, OV5670_DGTL_GAIN_DEFAULT);
/* Get min, max, step, default from sensor */ /* Get min, max, step, default from sensor */
exposure_max = ov5670->cur_mode->vts - 8; exposure_max = ov5670->cur_mode->vts_def - 8;
ov5670->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops, ov5670->exposure = v4l2_ctrl_new_std(ctrl_hdlr, &ov5670_ctrl_ops,
V4L2_CID_EXPOSURE, V4L2_CID_EXPOSURE,
OV5670_EXPOSURE_MIN, OV5670_EXPOSURE_MIN,
...@@ -2242,9 +2252,11 @@ static int ov5670_set_pad_format(struct v4l2_subdev *sd, ...@@ -2242,9 +2252,11 @@ static int ov5670_set_pad_format(struct v4l2_subdev *sd,
ov5670->pixel_rate, ov5670->pixel_rate,
link_freq_configs[mode->link_freq_index].pixel_rate); link_freq_configs[mode->link_freq_index].pixel_rate);
/* Update limits and set FPS to default */ /* Update limits and set FPS to default */
vblank_def = ov5670->cur_mode->vts - ov5670->cur_mode->height; vblank_def = ov5670->cur_mode->vts_def -
ov5670->cur_mode->height;
__v4l2_ctrl_modify_range( __v4l2_ctrl_modify_range(
ov5670->vblank, OV5670_VBLANK_MIN, ov5670->vblank,
ov5670->cur_mode->vts_min - ov5670->cur_mode->height,
OV5670_VTS_MAX - ov5670->cur_mode->height, 1, OV5670_VTS_MAX - ov5670->cur_mode->height, 1,
vblank_def); vblank_def);
__v4l2_ctrl_s_ctrl(ov5670->vblank, vblank_def); __v4l2_ctrl_s_ctrl(ov5670->vblank, vblank_def);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment