@@ -50,6 +50,8 @@
#define OV5647_REG_AEC_AGC 0x3503
#define OV5647_REG_GAIN_HI 0x350a
#define OV5647_REG_GAIN_LO 0x350b
+#define OV5647_REG_VTS_HI 0x380e
+#define OV5647_REG_VTS_LO 0x380f
#define OV5647_REG_FRAME_OFF_NUMBER 0x4202
#define OV5647_REG_MIPI_CTRL00 0x4800
#define OV5647_REG_MIPI_CTRL14 0x4814
@@ -68,6 +70,9 @@
#define OV5647_PIXEL_ARRAY_WIDTH 2592U
#define OV5647_PIXEL_ARRAY_HEIGHT 1944U
+#define OV5647_VBLANK_MIN 4
+#define OV5647_VTS_MAX 32767
+
struct regval_list {
u16 addr;
u8 data;
@@ -78,6 +83,7 @@ struct ov5647_mode {
struct v4l2_rect crop;
u64 pixel_rate;
int hts;
+ int vts;
struct regval_list *reg_list;
unsigned int num_regs;
};
@@ -101,6 +107,7 @@ struct ov5647 {
struct ov5647_mode *current_mode;
struct v4l2_ctrl *pixel_rate;
struct v4l2_ctrl *hblank;
+ struct v4l2_ctrl *vblank;
};
static inline struct ov5647 *to_sensor(struct v4l2_subdev *sd)
@@ -152,8 +159,6 @@ static struct regval_list ov5647_640x480_sbggr8[] = {
{0x3b07, 0x0c},
{0x380c, 0x07},
{0x380d, 0x68},
- {0x380e, 0x03},
- {0x380f, 0xd8},
{0x3814, 0x31},
{0x3815, 0x31},
{0x3708, 0x64},
@@ -589,6 +594,7 @@ static struct ov5647_mode ov5647_sbggr8_modes[] = {
},
.pixel_rate = 77291670,
.hts = 1896,
+ .vts = 0x3d8,
.reg_list = ov5647_640x480_sbggr8,
.num_regs = ARRAY_SIZE(ov5647_640x480_sbggr8)
},
@@ -612,6 +618,7 @@ static struct ov5647_mode ov5647_sbggr10_modes[] = {
},
.pixel_rate = 87500000,
.hts = 2844,
+ .vts = 0x7b0,
.reg_list = ov5647_2592x1944_sbggr10,
.num_regs = ARRAY_SIZE(ov5647_2592x1944_sbggr10)
},
@@ -632,6 +639,7 @@ static struct ov5647_mode ov5647_sbggr10_modes[] = {
},
.pixel_rate = 81666700,
.hts = 2416,
+ .vts = 0x450,
.reg_list = ov5647_1080p30_sbggr10,
.num_regs = ARRAY_SIZE(ov5647_1080p30_sbggr10)
},
@@ -652,6 +660,7 @@ static struct ov5647_mode ov5647_sbggr10_modes[] = {
},
.pixel_rate = 81666700,
.hts = 1896,
+ .vts = 0x59b,
.reg_list = ov5647_2x2binned_sbggr10,
.num_regs = ARRAY_SIZE(ov5647_2x2binned_sbggr10)
},
@@ -672,6 +681,7 @@ static struct ov5647_mode ov5647_sbggr10_modes[] = {
},
.pixel_rate = 55000000,
.hts = 1852,
+ .vts = 0x1f8,
.reg_list = ov5647_640x480_sbggr10,
.num_regs = ARRAY_SIZE(ov5647_640x480_sbggr10)
},
@@ -695,6 +705,22 @@ static const struct ov5647_format_list ov5647_formats[] = {
#define OV5647_DEFAULT_MODE (&ov5647_formats[0].modes[0])
#define OV5647_DEFAULT_FORMAT (ov5647_formats[0].modes[0].format)
+static int ov5647_write16(struct v4l2_subdev *sd, u16 reg, u16 val)
+{
+ unsigned char data[4] = { reg >> 8, reg & 0xff, val >> 8, val & 0xff};
+ struct i2c_client *client = v4l2_get_subdevdata(sd);
+ int ret;
+
+ ret = i2c_master_send(client, data, 4);
+ if (ret < 0) {
+ dev_dbg(&client->dev, "%s: i2c write error, reg: %x\n",
+ __func__, reg);
+ return ret;
+ }
+
+ return 0;
+}
+
static int ov5647_write(struct v4l2_subdev *sd, u16 reg, u8 val)
{
unsigned char data[3] = { reg >> 8, reg & 0xff, val};
@@ -1116,6 +1142,11 @@ static int ov5647_set_pad_fmt(struct v4l2_subdev *sd,
hblank = mode->hts - mode->format.width;
__v4l2_ctrl_modify_range(sensor->hblank, hblank, hblank, 1, hblank);
+ __v4l2_ctrl_modify_range(sensor->vblank, OV5647_VBLANK_MIN,
+ OV5647_VTS_MAX - mode->format.height,
+ 1, mode->vts - mode->format.height);
+ __v4l2_ctrl_s_ctrl(sensor->vblank, mode->vts - mode->format.height);
+
*fmt = mode->format;
mutex_unlock(&sensor->lock);
@@ -1323,6 +1354,9 @@ static int ov5647_s_ctrl(struct v4l2_ctrl *ctrl)
case V4L2_CID_HBLANK:
/* Read-only, but we adjust it based on mode. */
return 0;
+ case V4L2_CID_VBLANK:
+ return ov5647_write16(sd, OV5647_REG_VTS_HI,
+ sensor->mode->format.height + ctrl->val);
default:
dev_info(&client->dev,
"Control (id:0x%x, val:0x%x) not supported\n",
@@ -1342,7 +1376,7 @@ static int ov5647_init_controls(struct ov5647 *sensor)
struct i2c_client *client = v4l2_get_subdevdata(&sensor->sd);
int hblank;
- v4l2_ctrl_handler_init(&sensor->ctrls, 7);
+ v4l2_ctrl_handler_init(&sensor->ctrls, 8);
v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
V4L2_CID_AUTOGAIN, 0, 1, 1, 0);
@@ -1381,6 +1415,12 @@ static int ov5647_init_controls(struct ov5647 *sensor)
goto handler_free;
sensor->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+ sensor->vblank = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
+ V4L2_CID_VBLANK, OV5647_VBLANK_MIN,
+ OV5647_VTS_MAX - sensor->mode->format.height,
+ 1, sensor->mode->vts -
+ sensor->mode->format.height);
+
if (sensor->ctrls.error)
goto handler_free;