1 From 7e58b9c99676d641ef76edd9c097f1c3c4e6c464 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 21 Dec 2023 18:03:34 +0000
4 Subject: [PATCH] media: i2c: adv7180: Add support for V4L2_CID_LINK_FREQ
6 For CSI2 receivers that need to know the link frequency,
7 add it as a control to the driver.
8 Interlaced modes are 216Mbp/s or 108MHz, whilst going through
9 the I2P to deinterlace gives 432Mb/s or 216MHz.
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
13 drivers/media/i2c/adv7180.c | 32 +++++++++++++++++++++++++++++++-
14 1 file changed, 31 insertions(+), 1 deletion(-)
16 --- a/drivers/media/i2c/adv7180.c
17 +++ b/drivers/media/i2c/adv7180.c
19 /* Initial number of frames to skip to avoid possible garbage */
20 #define ADV7180_NUM_OF_SKIP_FRAMES 2
22 +enum adv7180_link_freq_idx {
27 +static const s64 adv7180_link_freqs[] = {
28 + [INTERLACED_IDX] = 108000000,
29 + [I2P_IDX] = 216000000,
33 module_param(dbg_input, int, 0644);
34 MODULE_PARM_DESC(dbg_input, "Input number (0-31)");
35 @@ -228,6 +238,7 @@ struct adv7180_state {
36 const struct adv7180_chip_info *chip_info;
37 enum v4l2_field field;
39 + struct v4l2_ctrl *link_freq;
41 #define to_adv7180_sd(_ctrl) (&container_of(_ctrl->handler, \
42 struct adv7180_state, \
43 @@ -629,6 +640,9 @@ static int adv7180_s_ctrl(struct v4l2_ct
47 + if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
52 case V4L2_CID_BRIGHTNESS:
53 @@ -670,6 +684,7 @@ static int adv7180_s_ctrl(struct v4l2_ct
58 mutex_unlock(&state->mutex);
61 @@ -690,7 +705,7 @@ static const struct v4l2_ctrl_config adv
63 static int adv7180_init_controls(struct adv7180_state *state)
65 - v4l2_ctrl_handler_init(&state->ctrl_hdl, 4);
66 + v4l2_ctrl_handler_init(&state->ctrl_hdl, 5);
68 v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
69 V4L2_CID_BRIGHTNESS, ADV7180_BRI_MIN,
70 @@ -712,6 +727,17 @@ static int adv7180_init_controls(struct
71 0, ARRAY_SIZE(test_pattern_menu) - 1,
74 + if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
76 + v4l2_ctrl_new_int_menu(&state->ctrl_hdl,
79 + ARRAY_SIZE(adv7180_link_freqs) - 1,
80 + 0, adv7180_link_freqs);
81 + if (state->link_freq)
82 + state->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
85 state->sd.ctrl_handler = &state->ctrl_hdl;
86 if (state->ctrl_hdl.error) {
87 int err = state->ctrl_hdl.error;
88 @@ -844,6 +870,10 @@ static int adv7180_set_pad_format(struct
89 adv7180_set_power(state, false);
90 adv7180_set_field_mode(state);
91 adv7180_set_power(state, true);
92 + if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2)
93 + __v4l2_ctrl_s_ctrl(state->link_freq,
94 + (state->field == V4L2_FIELD_NONE) ?
95 + I2P_IDX : INTERLACED_IDX);
98 framefmt = v4l2_subdev_state_get_format(sd_state, 0);