#define OV5647_VBLANK_MIN 4
#define OV5647_VTS_MAX 32767
+#define OV5647_EXPOSURE_MIN 4
+#define OV5647_EXPOSURE_STEP 1
+#define OV5647_EXPOSURE_DEFAULT 1000
+#define OV5647_EXPOSURE_MAX 65535
+
struct regval_list {
u16 addr;
u8 data;
struct v4l2_ctrl *pixel_rate;
struct v4l2_ctrl *hblank;
struct v4l2_ctrl *vblank;
+ struct v4l2_ctrl *exposure;
bool write_mode_regs;
};
* If we have changed modes, write the I2C register list on
* a stream_on().
*/
- int hblank;
+ int exposure_max, exposure_def, hblank;
if (state->mode != mode)
state->write_mode_regs = true;
mode->vts_def - mode->format.height);
__v4l2_ctrl_s_ctrl(state->vblank,
mode->vts_def - mode->format.height);
+
+ exposure_max = mode->vts_def - 4;
+ exposure_def = (exposure_max < OV5647_EXPOSURE_DEFAULT) ?
+ exposure_max : OV5647_EXPOSURE_DEFAULT;
+ __v4l2_ctrl_modify_range(state->exposure,
+ state->exposure->minimum,
+ exposure_max,
+ state->exposure->step,
+ exposure_def);
}
mutex_unlock(&state->lock);
/* v4l2_ctrl_lock() locks our own mutex */
+ if (ctrl->id == V4L2_CID_VBLANK) {
+ int exposure_max, exposure_def;
+
+ /* Update max exposure while meeting expected vblanking */
+ exposure_max = state->mode->format.height + ctrl->val - 4;
+ exposure_def = (exposure_max < OV5647_EXPOSURE_DEFAULT) ?
+ exposure_max : OV5647_EXPOSURE_DEFAULT;
+ __v4l2_ctrl_modify_range(state->exposure,
+ state->exposure->minimum,
+ exposure_max, state->exposure->step,
+ exposure_def);
+ }
+
/*
* If the device is not powered up by the host driver do
* not apply any controls to H/W at this time. Instead
struct v4l2_subdev *sd;
struct device_node *np = client->dev.of_node;
u32 xclk_freq;
- int hblank;
+ int hblank, exposure_max, exposure_def;
sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
if (!sensor)
0, /* skip_mask */
V4L2_EXPOSURE_MANUAL); /* default */
v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
- V4L2_CID_EXPOSURE,
- 4, /* min lines */
- 65535, /* max lines (4+8+4 bits)*/
- 1, /* step */
- 1000); /* default number of lines */
- v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
V4L2_CID_ANALOGUE_GAIN,
16, /* min, 16 = 1.0x */
1023, /* max (10 bits) */
/* Set the default mode before we init the subdev */
sensor->mode = OV5647_DEFAULT_MODE;
+ exposure_max = sensor->mode->vts_def - 4;
+ exposure_def = (exposure_max < OV5647_EXPOSURE_DEFAULT) ?
+ exposure_max : OV5647_EXPOSURE_DEFAULT;
+ sensor->exposure = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
+ V4L2_CID_EXPOSURE,
+ OV5647_EXPOSURE_MIN, exposure_max,
+ OV5647_EXPOSURE_STEP,
+ exposure_def);
+
/* By default, PIXEL_RATE is read only, but it does change per mode */
sensor->pixel_rate = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
V4L2_CID_PIXEL_RATE,