Skip to content

Commit fd74246

Browse files
Hans Verkuilmchehab
authored andcommitted
[media] adv7604/adv7842: fix quantization range handling
Fix a number of bugs that appeared when support for mediabus formats was added: - Support for V4L2_DV_RGB_RANGE_FULL/LIMITED should only be enabled for HDMI RGB formats, not for YCbCr formats. Since, as the name says, this setting is for RGB only. So read the InfoFrame to check the format. - the quantization range for the pixelport depends on whether the mediabus code is RGB or not: if it is RGB, then produce full range RGB values, otherwise produce limited range YCbCr values. This means that the op_656_range and alt_data_sat fields of the platform data are no longer used and these will be removed in a following patch. - when setting up a new format the RGB quantization range settings were never updated. Do so, since this depends on the format. - fix the log_status output which was confusing and incorrect. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
1 parent 0a25a01 commit fd74246

2 files changed

Lines changed: 33 additions & 20 deletions

File tree

‎drivers/media/i2c/adv7604.c‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,13 +1102,18 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
11021102
struct adv76xx_state *state = to_state(sd);
11031103
bool rgb_output = io_read(sd, 0x02) & 0x02;
11041104
bool hdmi_signal = hdmi_read(sd, 0x05) & 0x80;
1105+
u8 y = HDMI_COLORSPACE_RGB;
1106+
1107+
if (hdmi_signal && (io_read(sd, 0x60) & 1))
1108+
y = infoframe_read(sd, 0x01) >> 5;
11051109

11061110
v4l2_dbg(2, debug, sd, "%s: RGB quantization range: %d, RGB out: %d, HDMI: %d\n",
11071111
__func__, state->rgb_quantization_range,
11081112
rgb_output, hdmi_signal);
11091113

11101114
adv76xx_set_gain(sd, true, 0x0, 0x0, 0x0);
11111115
adv76xx_set_offset(sd, true, 0x0, 0x0, 0x0);
1116+
io_write_clr_set(sd, 0x02, 0x04, rgb_output ? 0 : 4);
11121117

11131118
switch (state->rgb_quantization_range) {
11141119
case V4L2_DV_RGB_RANGE_AUTO:
@@ -1158,6 +1163,9 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
11581163
break;
11591164
}
11601165

1166+
if (y != HDMI_COLORSPACE_RGB)
1167+
break;
1168+
11611169
/* RGB limited range (16-235) */
11621170
io_write_clr_set(sd, 0x02, 0xf0, 0x00);
11631171

@@ -1169,6 +1177,9 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
11691177
break;
11701178
}
11711179

1180+
if (y != HDMI_COLORSPACE_RGB)
1181+
break;
1182+
11721183
/* RGB full range (0-255) */
11731184
io_write_clr_set(sd, 0x02, 0xf0, 0x10);
11741185

@@ -1865,6 +1876,7 @@ static void adv76xx_setup_format(struct adv76xx_state *state)
18651876
io_write_clr_set(sd, 0x04, 0xe0, adv76xx_op_ch_sel(state));
18661877
io_write_clr_set(sd, 0x05, 0x01,
18671878
state->format->swap_cb_cr ? ADV76XX_OP_SWAP_CB_CR : 0);
1879+
set_rgb_quantization_range(sd);
18681880
}
18691881

18701882
static int adv76xx_get_format(struct v4l2_subdev *sd,
@@ -2539,11 +2551,10 @@ static int adv76xx_log_status(struct v4l2_subdev *sd)
25392551
rgb_quantization_range_txt[state->rgb_quantization_range]);
25402552
v4l2_info(sd, "Input color space: %s\n",
25412553
input_color_space_txt[reg_io_0x02 >> 4]);
2542-
v4l2_info(sd, "Output color space: %s %s, saturator %s, alt-gamma %s\n",
2554+
v4l2_info(sd, "Output color space: %s %s, alt-gamma %s\n",
25432555
(reg_io_0x02 & 0x02) ? "RGB" : "YCbCr",
2544-
(reg_io_0x02 & 0x04) ? "(16-235)" : "(0-255)",
25452556
(((reg_io_0x02 >> 2) & 0x01) ^ (reg_io_0x02 & 0x01)) ?
2546-
"enabled" : "disabled",
2557+
"(16-235)" : "(0-255)",
25472558
(reg_io_0x02 & 0x08) ? "enabled" : "disabled");
25482559
v4l2_info(sd, "Color space conversion: %s\n",
25492560
csc_coeff_sel_rb[cp_read(sd, info->cp_csc) >> 4]);
@@ -2731,10 +2742,7 @@ static int adv76xx_core_init(struct v4l2_subdev *sd)
27312742
cp_write(sd, 0xcf, 0x01); /* Power down macrovision */
27322743

27332744
/* video format */
2734-
io_write_clr_set(sd, 0x02, 0x0f,
2735-
pdata->alt_gamma << 3 |
2736-
pdata->op_656_range << 2 |
2737-
pdata->alt_data_sat << 0);
2745+
io_write_clr_set(sd, 0x02, 0x0f, pdata->alt_gamma << 3);
27382746
io_write_clr_set(sd, 0x05, 0x0e, pdata->blank_data << 3 |
27392747
pdata->insert_av_codes << 2 |
27402748
pdata->replicate_av_codes << 1);
@@ -3084,10 +3092,8 @@ static int adv76xx_parse_dt(struct adv76xx_state *state)
30843092
if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
30853093
state->pdata.inv_llc_pol = 1;
30863094

3087-
if (bus_cfg.bus_type == V4L2_MBUS_BT656) {
3095+
if (bus_cfg.bus_type == V4L2_MBUS_BT656)
30883096
state->pdata.insert_av_codes = 1;
3089-
state->pdata.op_656_range = 1;
3090-
}
30913097

30923098
/* Disable the interrupt for now as no DT-based board uses it. */
30933099
state->pdata.int1_config = ADV76XX_INT1_CONFIG_DISABLED;
@@ -3110,7 +3116,6 @@ static int adv76xx_parse_dt(struct adv76xx_state *state)
31103116
state->pdata.disable_pwrdnb = 0;
31113117
state->pdata.disable_cable_det_rst = 0;
31123118
state->pdata.blank_data = 1;
3113-
state->pdata.alt_data_sat = 1;
31143119
state->pdata.op_format_mode_sel = ADV7604_OP_FORMAT_MODE0;
31153120
state->pdata.bus_order = ADV7604_BUS_ORDER_RGB;
31163121

‎drivers/media/i2c/adv7842.c‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,13 +1184,18 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
11841184
struct adv7842_state *state = to_state(sd);
11851185
bool rgb_output = io_read(sd, 0x02) & 0x02;
11861186
bool hdmi_signal = hdmi_read(sd, 0x05) & 0x80;
1187+
u8 y = HDMI_COLORSPACE_RGB;
1188+
1189+
if (hdmi_signal && (io_read(sd, 0x60) & 1))
1190+
y = infoframe_read(sd, 0x01) >> 5;
11871191

11881192
v4l2_dbg(2, debug, sd, "%s: RGB quantization range: %d, RGB out: %d, HDMI: %d\n",
11891193
__func__, state->rgb_quantization_range,
11901194
rgb_output, hdmi_signal);
11911195

11921196
adv7842_set_gain(sd, true, 0x0, 0x0, 0x0);
11931197
adv7842_set_offset(sd, true, 0x0, 0x0, 0x0);
1198+
io_write_clr_set(sd, 0x02, 0x04, rgb_output ? 0 : 4);
11941199

11951200
switch (state->rgb_quantization_range) {
11961201
case V4L2_DV_RGB_RANGE_AUTO:
@@ -1240,6 +1245,9 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
12401245
break;
12411246
}
12421247

1248+
if (y != HDMI_COLORSPACE_RGB)
1249+
break;
1250+
12431251
/* RGB limited range (16-235) */
12441252
io_write_and_or(sd, 0x02, 0x0f, 0x00);
12451253

@@ -1251,6 +1259,9 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
12511259
break;
12521260
}
12531261

1262+
if (y != HDMI_COLORSPACE_RGB)
1263+
break;
1264+
12541265
/* RGB full range (0-255) */
12551266
io_write_and_or(sd, 0x02, 0x0f, 0x10);
12561267

@@ -2058,6 +2069,7 @@ static void adv7842_setup_format(struct adv7842_state *state)
20582069
io_write_clr_set(sd, 0x04, 0xe0, adv7842_op_ch_sel(state));
20592070
io_write_clr_set(sd, 0x05, 0x01,
20602071
state->format->swap_cb_cr ? ADV7842_OP_SWAP_CB_CR : 0);
2072+
set_rgb_quantization_range(sd);
20612073
}
20622074

20632075
static int adv7842_get_format(struct v4l2_subdev *sd,
@@ -2777,11 +2789,11 @@ static int adv7842_cp_log_status(struct v4l2_subdev *sd)
27772789
rgb_quantization_range_txt[state->rgb_quantization_range]);
27782790
v4l2_info(sd, "Input color space: %s\n",
27792791
input_color_space_txt[reg_io_0x02 >> 4]);
2780-
v4l2_info(sd, "Output color space: %s %s, saturator %s\n",
2792+
v4l2_info(sd, "Output color space: %s %s, alt-gamma %s\n",
27812793
(reg_io_0x02 & 0x02) ? "RGB" : "YCbCr",
2782-
(reg_io_0x02 & 0x04) ? "(16-235)" : "(0-255)",
2783-
((reg_io_0x02 & 0x04) ^ (reg_io_0x02 & 0x01)) ?
2784-
"enabled" : "disabled");
2794+
(((reg_io_0x02 >> 2) & 0x01) ^ (reg_io_0x02 & 0x01)) ?
2795+
"(16-235)" : "(0-255)",
2796+
(reg_io_0x02 & 0x08) ? "enabled" : "disabled");
27852797
v4l2_info(sd, "Color space conversion: %s\n",
27862798
csc_coeff_sel_rb[cp_read(sd, 0xf4) >> 4]);
27872799

@@ -2985,11 +2997,7 @@ static int adv7842_core_init(struct v4l2_subdev *sd)
29852997
io_write(sd, 0x15, 0x80); /* Power up pads */
29862998

29872999
/* video format */
2988-
io_write(sd, 0x02,
2989-
0xf0 |
2990-
pdata->alt_gamma << 3 |
2991-
pdata->op_656_range << 2 |
2992-
pdata->alt_data_sat << 0);
3000+
io_write(sd, 0x02, 0xf0 | pdata->alt_gamma << 3);
29933001
io_write_and_or(sd, 0x05, 0xf0, pdata->blank_data << 3 |
29943002
pdata->insert_av_codes << 2 |
29953003
pdata->replicate_av_codes << 1);

0 commit comments

Comments
 (0)