提交 cb8c2f04 编写于 作者: D Dave Stevenson 提交者: Zheng Zengkai

media: i2c: ov5647: Advertise the correct exposure range

raspberrypi inclusion
category: feature
bugzilla: 50432

--------------------------------

Exposure is clipped by the VTS of the mode, so needs to be updated as
and when this is changed.
Signed-off-by: NDave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: NFang Yafen <yafen@iscas.ac.cn>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 bd5acddc
...@@ -84,6 +84,11 @@ ...@@ -84,6 +84,11 @@
#define OV5647_VBLANK_MIN 4 #define OV5647_VBLANK_MIN 4
#define OV5647_VTS_MAX 32767 #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 { struct regval_list {
u16 addr; u16 addr;
u8 data; u8 data;
...@@ -117,6 +122,7 @@ struct ov5647 { ...@@ -117,6 +122,7 @@ struct ov5647 {
struct v4l2_ctrl *pixel_rate; struct v4l2_ctrl *pixel_rate;
struct v4l2_ctrl *hblank; struct v4l2_ctrl *hblank;
struct v4l2_ctrl *vblank; struct v4l2_ctrl *vblank;
struct v4l2_ctrl *exposure;
bool write_mode_regs; bool write_mode_regs;
}; };
...@@ -1202,7 +1208,7 @@ static int ov5647_set_fmt(struct v4l2_subdev *sd, ...@@ -1202,7 +1208,7 @@ static int ov5647_set_fmt(struct v4l2_subdev *sd,
* If we have changed modes, write the I2C register list on * If we have changed modes, write the I2C register list on
* a stream_on(). * a stream_on().
*/ */
int hblank; int exposure_max, exposure_def, hblank;
if (state->mode != mode) if (state->mode != mode)
state->write_mode_regs = true; state->write_mode_regs = true;
...@@ -1223,6 +1229,15 @@ static int ov5647_set_fmt(struct v4l2_subdev *sd, ...@@ -1223,6 +1229,15 @@ static int ov5647_set_fmt(struct v4l2_subdev *sd,
mode->vts_def - mode->format.height); mode->vts_def - mode->format.height);
__v4l2_ctrl_s_ctrl(state->vblank, __v4l2_ctrl_s_ctrl(state->vblank,
mode->vts_def - mode->format.height); 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); mutex_unlock(&state->lock);
...@@ -1415,6 +1430,19 @@ static int ov5647_s_ctrl(struct v4l2_ctrl *ctrl) ...@@ -1415,6 +1430,19 @@ static int ov5647_s_ctrl(struct v4l2_ctrl *ctrl)
/* v4l2_ctrl_lock() locks our own mutex */ /* 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 * If the device is not powered up by the host driver do
* not apply any controls to H/W at this time. Instead * not apply any controls to H/W at this time. Instead
...@@ -1472,7 +1500,7 @@ static int ov5647_probe(struct i2c_client *client) ...@@ -1472,7 +1500,7 @@ static int ov5647_probe(struct i2c_client *client)
struct v4l2_subdev *sd; struct v4l2_subdev *sd;
struct device_node *np = client->dev.of_node; struct device_node *np = client->dev.of_node;
u32 xclk_freq; u32 xclk_freq;
int hblank; int hblank, exposure_max, exposure_def;
sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL); sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
if (!sensor) if (!sensor)
...@@ -1524,12 +1552,6 @@ static int ov5647_probe(struct i2c_client *client) ...@@ -1524,12 +1552,6 @@ static int ov5647_probe(struct i2c_client *client)
V4L2_EXPOSURE_MANUAL, /* max */ V4L2_EXPOSURE_MANUAL, /* max */
0, /* skip_mask */ 0, /* skip_mask */
V4L2_EXPOSURE_MANUAL); /* default */ 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_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
V4L2_CID_ANALOGUE_GAIN, V4L2_CID_ANALOGUE_GAIN,
16, /* min, 16 = 1.0x */ 16, /* min, 16 = 1.0x */
...@@ -1540,6 +1562,15 @@ static int ov5647_probe(struct i2c_client *client) ...@@ -1540,6 +1562,15 @@ static int ov5647_probe(struct i2c_client *client)
/* Set the default mode before we init the subdev */ /* Set the default mode before we init the subdev */
sensor->mode = OV5647_DEFAULT_MODE; 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 */ /* 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, sensor->pixel_rate = v4l2_ctrl_new_std(&sensor->ctrls, &ov5647_ctrl_ops,
V4L2_CID_PIXEL_RATE, V4L2_CID_PIXEL_RATE,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册