#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
#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;
struct v4l2_rect crop;
u64 pixel_rate;
int hts;
+ int vts;
const struct regval_list *reg_list;
unsigned int num_regs;
};
const struct ov5647_mode *mode;
struct v4l2_ctrl *pixel_rate;
struct v4l2_ctrl *hblank;
+ struct v4l2_ctrl *vblank;
};
static inline struct ov5647 *to_sensor(struct v4l2_subdev *sd)
{0x3b07, 0x0c},
{0x380c, 0x07},
{0x380d, 0x68},
- {0x380e, 0x03},
- {0x380f, 0xd8},
{0x3814, 0x31},
{0x3815, 0x31},
{0x3708, 0x64},
},
.pixel_rate = 77291670,
.hts = 1896,
+ .vts = 0x3d8,
.reg_list = ov5647_640x480_8bpp,
.num_regs = ARRAY_SIZE(ov5647_640x480_8bpp)
},
},
.pixel_rate = 87500000,
.hts = 2844,
+ .vts = 0x7b0,
.reg_list = ov5647_2592x1944_10bpp,
.num_regs = ARRAY_SIZE(ov5647_2592x1944_10bpp)
},
},
.pixel_rate = 81666700,
.hts = 2416,
+ .vts = 0x450,
.reg_list = ov5647_1080p30_10bpp,
.num_regs = ARRAY_SIZE(ov5647_1080p30_10bpp)
},
},
.pixel_rate = 81666700,
.hts = 1896,
+ .vts = 0x59b,
.reg_list = ov5647_2x2binned_10bpp,
.num_regs = ARRAY_SIZE(ov5647_2x2binned_10bpp)
},
},
.pixel_rate = 55000000,
.hts = 1852,
+ .vts = 0x1f8,
.reg_list = ov5647_640x480_10bpp,
.num_regs = ARRAY_SIZE(ov5647_640x480_10bpp)
},
#define OV5647_DEFAULT_MODE (&ov5647_formats[1].modes[3])
#define OV5647_DEFAULT_FORMAT (ov5647_formats[1].modes[3].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};
if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
*v4l2_subdev_get_try_format(sd, cfg, format->pad) = mode->format;
} else {
- int hblank;
+ int hblank, vblank;
sensor->mode = mode;
__v4l2_ctrl_modify_range(sensor->pixel_rate, mode->pixel_rate,
hblank = mode->hts - mode->format.width;
__v4l2_ctrl_modify_range(sensor->hblank, hblank, hblank, 1,
hblank);
+
+ vblank = mode->vts - mode->format.height;
+ __v4l2_ctrl_modify_range(sensor->vblank, OV5647_VBLANK_MIN,
+ OV5647_VTS_MAX - mode->format.height,
+ 1, vblank);
+ __v4l2_ctrl_s_ctrl(sensor->vblank, vblank);
}
*fmt = mode->format;
mutex_unlock(&sensor->lock);
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",
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);
V4L2_CID_HBLANK, hblank, hblank, 1,
hblank);
+ 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;