mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 18:09:56 +00:00
media: i2c: ov5647: Advertise the correct exposure range
Exposure is clipped by the VTS of the mode, so needs to be updated as and when this is changed. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
This commit is contained in:
committed by
popcornmix
parent
079d8d1a91
commit
5961afa218
@@ -84,6 +84,11 @@
|
||||
#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;
|
||||
@@ -117,6 +122,7 @@ struct ov5647 {
|
||||
struct v4l2_ctrl *pixel_rate;
|
||||
struct v4l2_ctrl *hblank;
|
||||
struct v4l2_ctrl *vblank;
|
||||
struct v4l2_ctrl *exposure;
|
||||
bool write_mode_regs;
|
||||
};
|
||||
|
||||
@@ -1202,7 +1208,7 @@ static int ov5647_set_fmt(struct v4l2_subdev *sd,
|
||||
* 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;
|
||||
@@ -1223,6 +1229,15 @@ static int ov5647_set_fmt(struct v4l2_subdev *sd,
|
||||
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);
|
||||
@@ -1415,6 +1430,19 @@ static int ov5647_s_ctrl(struct v4l2_ctrl *ctrl)
|
||||
|
||||
/* 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
|
||||
@@ -1472,7 +1500,7 @@ static int ov5647_probe(struct i2c_client *client)
|
||||
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)
|
||||
@@ -1524,12 +1552,6 @@ static int ov5647_probe(struct i2c_client *client)
|
||||
V4L2_EXPOSURE_MANUAL, /* max */
|
||||
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 */
|
||||
@@ -1540,6 +1562,15 @@ static int ov5647_probe(struct i2c_client *client)
|
||||
/* 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,
|
||||
|
||||
Reference in New Issue
Block a user