Skip to content

Commit 5f2bdbe

Browse files
6by9popcornmix
authored andcommitted
media: i2c: adv7180: Add support for V4L2_CID_LINK_FREQ
For CSI2 receivers that need to know the link frequency, add it as a control to the driver. Interlaced modes are 216Mbp/s or 108MHz, whilst going through the I2P to deinterlace gives 432Mb/s or 216MHz. Signed-off-by: Dave Stevenson <[email protected]>
1 parent fa7c380 commit 5f2bdbe

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

drivers/media/i2c/adv7180.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@
189189
/* Initial number of frames to skip to avoid possible garbage */
190190
#define ADV7180_NUM_OF_SKIP_FRAMES 2
191191

192+
enum adv7180_link_freq_idx {
193+
INTERLACED_IDX,
194+
I2P_IDX,
195+
};
196+
197+
static const s64 adv7180_link_freqs[] = {
198+
[INTERLACED_IDX] = 108000000,
199+
[I2P_IDX] = 216000000,
200+
};
201+
192202
static int dbg_input;
193203
module_param(dbg_input, int, 0644);
194204
MODULE_PARM_DESC(dbg_input, "Input number (0-31)");
@@ -228,6 +238,7 @@ struct adv7180_state {
228238
const struct adv7180_chip_info *chip_info;
229239
enum v4l2_field field;
230240
bool force_bt656_4;
241+
struct v4l2_ctrl *link_freq;
231242
};
232243
#define to_adv7180_sd(_ctrl) (&container_of(_ctrl->handler, \
233244
struct adv7180_state, \
@@ -629,6 +640,9 @@ static int adv7180_s_ctrl(struct v4l2_ctrl *ctrl)
629640

630641
if (ret)
631642
return ret;
643+
if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
644+
goto unlock;
645+
632646
val = ctrl->val;
633647
switch (ctrl->id) {
634648
case V4L2_CID_BRIGHTNESS:
@@ -670,6 +684,7 @@ static int adv7180_s_ctrl(struct v4l2_ctrl *ctrl)
670684
ret = -EINVAL;
671685
}
672686

687+
unlock:
673688
mutex_unlock(&state->mutex);
674689
return ret;
675690
}
@@ -690,7 +705,7 @@ static const struct v4l2_ctrl_config adv7180_ctrl_fast_switch = {
690705

691706
static int adv7180_init_controls(struct adv7180_state *state)
692707
{
693-
v4l2_ctrl_handler_init(&state->ctrl_hdl, 4);
708+
v4l2_ctrl_handler_init(&state->ctrl_hdl, 5);
694709

695710
v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
696711
V4L2_CID_BRIGHTNESS, ADV7180_BRI_MIN,
@@ -712,6 +727,17 @@ static int adv7180_init_controls(struct adv7180_state *state)
712727
0, ARRAY_SIZE(test_pattern_menu) - 1,
713728
test_pattern_menu);
714729

730+
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
731+
state->link_freq =
732+
v4l2_ctrl_new_int_menu(&state->ctrl_hdl,
733+
&adv7180_ctrl_ops,
734+
V4L2_CID_LINK_FREQ,
735+
ARRAY_SIZE(adv7180_link_freqs) - 1,
736+
0, adv7180_link_freqs);
737+
if (state->link_freq)
738+
state->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
739+
}
740+
715741
state->sd.ctrl_handler = &state->ctrl_hdl;
716742
if (state->ctrl_hdl.error) {
717743
int err = state->ctrl_hdl.error;
@@ -844,6 +870,10 @@ static int adv7180_set_pad_format(struct v4l2_subdev *sd,
844870
adv7180_set_power(state, false);
845871
adv7180_set_field_mode(state);
846872
adv7180_set_power(state, true);
873+
if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2)
874+
__v4l2_ctrl_s_ctrl(state->link_freq,
875+
(state->field == V4L2_FIELD_NONE) ?
876+
I2P_IDX : INTERLACED_IDX);
847877
}
848878
} else {
849879
framefmt = v4l2_subdev_state_get_format(sd_state, 0);

0 commit comments

Comments
 (0)