aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2016-06-28 10:43:01 -0400
committerMauro Carvalho Chehab <mchehab@s-opensource.com>2016-07-12 12:35:46 -0400
commitfd74246d2ade37cd477178652448410a35bdaca0 (patch)
treedff71bf9820163b116acb8fb99bff332ccc1432c
parent0a25a0125194639507cf24319d02f5de63d182b5 (diff)
[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>
-rw-r--r--drivers/media/i2c/adv7604.c27
-rw-r--r--drivers/media/i2c/adv7842.c26
2 files changed, 33 insertions, 20 deletions
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index 2d7927150450..4003831de712 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -1102,6 +1102,10 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
1102 struct adv76xx_state *state = to_state(sd); 1102 struct adv76xx_state *state = to_state(sd);
1103 bool rgb_output = io_read(sd, 0x02) & 0x02; 1103 bool rgb_output = io_read(sd, 0x02) & 0x02;
1104 bool hdmi_signal = hdmi_read(sd, 0x05) & 0x80; 1104 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;
1105 1109
1106 v4l2_dbg(2, debug, sd, "%s: RGB quantization range: %d, RGB out: %d, HDMI: %d\n", 1110 v4l2_dbg(2, debug, sd, "%s: RGB quantization range: %d, RGB out: %d, HDMI: %d\n",
1107 __func__, state->rgb_quantization_range, 1111 __func__, state->rgb_quantization_range,
@@ -1109,6 +1113,7 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
1109 1113
1110 adv76xx_set_gain(sd, true, 0x0, 0x0, 0x0); 1114 adv76xx_set_gain(sd, true, 0x0, 0x0, 0x0);
1111 adv76xx_set_offset(sd, true, 0x0, 0x0, 0x0); 1115 adv76xx_set_offset(sd, true, 0x0, 0x0, 0x0);
1116 io_write_clr_set(sd, 0x02, 0x04, rgb_output ? 0 : 4);
1112 1117
1113 switch (state->rgb_quantization_range) { 1118 switch (state->rgb_quantization_range) {
1114 case V4L2_DV_RGB_RANGE_AUTO: 1119 case V4L2_DV_RGB_RANGE_AUTO:
@@ -1158,6 +1163,9 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
1158 break; 1163 break;
1159 } 1164 }
1160 1165
1166 if (y != HDMI_COLORSPACE_RGB)
1167 break;
1168
1161 /* RGB limited range (16-235) */ 1169 /* RGB limited range (16-235) */
1162 io_write_clr_set(sd, 0x02, 0xf0, 0x00); 1170 io_write_clr_set(sd, 0x02, 0xf0, 0x00);
1163 1171
@@ -1169,6 +1177,9 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
1169 break; 1177 break;
1170 } 1178 }
1171 1179
1180 if (y != HDMI_COLORSPACE_RGB)
1181 break;
1182
1172 /* RGB full range (0-255) */ 1183 /* RGB full range (0-255) */
1173 io_write_clr_set(sd, 0x02, 0xf0, 0x10); 1184 io_write_clr_set(sd, 0x02, 0xf0, 0x10);
1174 1185
@@ -1865,6 +1876,7 @@ static void adv76xx_setup_format(struct adv76xx_state *state)
1865 io_write_clr_set(sd, 0x04, 0xe0, adv76xx_op_ch_sel(state)); 1876 io_write_clr_set(sd, 0x04, 0xe0, adv76xx_op_ch_sel(state));
1866 io_write_clr_set(sd, 0x05, 0x01, 1877 io_write_clr_set(sd, 0x05, 0x01,
1867 state->format->swap_cb_cr ? ADV76XX_OP_SWAP_CB_CR : 0); 1878 state->format->swap_cb_cr ? ADV76XX_OP_SWAP_CB_CR : 0);
1879 set_rgb_quantization_range(sd);
1868} 1880}
1869 1881
1870static int adv76xx_get_format(struct v4l2_subdev *sd, 1882static int adv76xx_get_format(struct v4l2_subdev *sd,
@@ -2539,11 +2551,10 @@ static int adv76xx_log_status(struct v4l2_subdev *sd)
2539 rgb_quantization_range_txt[state->rgb_quantization_range]); 2551 rgb_quantization_range_txt[state->rgb_quantization_range]);
2540 v4l2_info(sd, "Input color space: %s\n", 2552 v4l2_info(sd, "Input color space: %s\n",
2541 input_color_space_txt[reg_io_0x02 >> 4]); 2553 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",
2543 (reg_io_0x02 & 0x02) ? "RGB" : "YCbCr", 2555 (reg_io_0x02 & 0x02) ? "RGB" : "YCbCr",
2544 (reg_io_0x02 & 0x04) ? "(16-235)" : "(0-255)",
2545 (((reg_io_0x02 >> 2) & 0x01) ^ (reg_io_0x02 & 0x01)) ? 2556 (((reg_io_0x02 >> 2) & 0x01) ^ (reg_io_0x02 & 0x01)) ?
2546 "enabled" : "disabled", 2557 "(16-235)" : "(0-255)",
2547 (reg_io_0x02 & 0x08) ? "enabled" : "disabled"); 2558 (reg_io_0x02 & 0x08) ? "enabled" : "disabled");
2548 v4l2_info(sd, "Color space conversion: %s\n", 2559 v4l2_info(sd, "Color space conversion: %s\n",
2549 csc_coeff_sel_rb[cp_read(sd, info->cp_csc) >> 4]); 2560 csc_coeff_sel_rb[cp_read(sd, info->cp_csc) >> 4]);
@@ -2731,10 +2742,7 @@ static int adv76xx_core_init(struct v4l2_subdev *sd)
2731 cp_write(sd, 0xcf, 0x01); /* Power down macrovision */ 2742 cp_write(sd, 0xcf, 0x01); /* Power down macrovision */
2732 2743
2733 /* video format */ 2744 /* video format */
2734 io_write_clr_set(sd, 0x02, 0x0f, 2745 io_write_clr_set(sd, 0x02, 0x0f, pdata->alt_gamma << 3);
2735 pdata->alt_gamma << 3 |
2736 pdata->op_656_range << 2 |
2737 pdata->alt_data_sat << 0);
2738 io_write_clr_set(sd, 0x05, 0x0e, pdata->blank_data << 3 | 2746 io_write_clr_set(sd, 0x05, 0x0e, pdata->blank_data << 3 |
2739 pdata->insert_av_codes << 2 | 2747 pdata->insert_av_codes << 2 |
2740 pdata->replicate_av_codes << 1); 2748 pdata->replicate_av_codes << 1);
@@ -3084,10 +3092,8 @@ static int adv76xx_parse_dt(struct adv76xx_state *state)
3084 if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING) 3092 if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
3085 state->pdata.inv_llc_pol = 1; 3093 state->pdata.inv_llc_pol = 1;
3086 3094
3087 if (bus_cfg.bus_type == V4L2_MBUS_BT656) { 3095 if (bus_cfg.bus_type == V4L2_MBUS_BT656)
3088 state->pdata.insert_av_codes = 1; 3096 state->pdata.insert_av_codes = 1;
3089 state->pdata.op_656_range = 1;
3090 }
3091 3097
3092 /* Disable the interrupt for now as no DT-based board uses it. */ 3098 /* Disable the interrupt for now as no DT-based board uses it. */
3093 state->pdata.int1_config = ADV76XX_INT1_CONFIG_DISABLED; 3099 state->pdata.int1_config = ADV76XX_INT1_CONFIG_DISABLED;
@@ -3110,7 +3116,6 @@ static int adv76xx_parse_dt(struct adv76xx_state *state)
3110 state->pdata.disable_pwrdnb = 0; 3116 state->pdata.disable_pwrdnb = 0;
3111 state->pdata.disable_cable_det_rst = 0; 3117 state->pdata.disable_cable_det_rst = 0;
3112 state->pdata.blank_data = 1; 3118 state->pdata.blank_data = 1;
3113 state->pdata.alt_data_sat = 1;
3114 state->pdata.op_format_mode_sel = ADV7604_OP_FORMAT_MODE0; 3119 state->pdata.op_format_mode_sel = ADV7604_OP_FORMAT_MODE0;
3115 state->pdata.bus_order = ADV7604_BUS_ORDER_RGB; 3120 state->pdata.bus_order = ADV7604_BUS_ORDER_RGB;
3116 3121
diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 100bd3f96b59..8c2a52e280af 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -1184,6 +1184,10 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
1184 struct adv7842_state *state = to_state(sd); 1184 struct adv7842_state *state = to_state(sd);
1185 bool rgb_output = io_read(sd, 0x02) & 0x02; 1185 bool rgb_output = io_read(sd, 0x02) & 0x02;
1186 bool hdmi_signal = hdmi_read(sd, 0x05) & 0x80; 1186 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;
1187 1191
1188 v4l2_dbg(2, debug, sd, "%s: RGB quantization range: %d, RGB out: %d, HDMI: %d\n", 1192 v4l2_dbg(2, debug, sd, "%s: RGB quantization range: %d, RGB out: %d, HDMI: %d\n",
1189 __func__, state->rgb_quantization_range, 1193 __func__, state->rgb_quantization_range,
@@ -1191,6 +1195,7 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
1191 1195
1192 adv7842_set_gain(sd, true, 0x0, 0x0, 0x0); 1196 adv7842_set_gain(sd, true, 0x0, 0x0, 0x0);
1193 adv7842_set_offset(sd, true, 0x0, 0x0, 0x0); 1197 adv7842_set_offset(sd, true, 0x0, 0x0, 0x0);
1198 io_write_clr_set(sd, 0x02, 0x04, rgb_output ? 0 : 4);
1194 1199
1195 switch (state->rgb_quantization_range) { 1200 switch (state->rgb_quantization_range) {
1196 case V4L2_DV_RGB_RANGE_AUTO: 1201 case V4L2_DV_RGB_RANGE_AUTO:
@@ -1240,6 +1245,9 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
1240 break; 1245 break;
1241 } 1246 }
1242 1247
1248 if (y != HDMI_COLORSPACE_RGB)
1249 break;
1250
1243 /* RGB limited range (16-235) */ 1251 /* RGB limited range (16-235) */
1244 io_write_and_or(sd, 0x02, 0x0f, 0x00); 1252 io_write_and_or(sd, 0x02, 0x0f, 0x00);
1245 1253
@@ -1251,6 +1259,9 @@ static void set_rgb_quantization_range(struct v4l2_subdev *sd)
1251 break; 1259 break;
1252 } 1260 }
1253 1261
1262 if (y != HDMI_COLORSPACE_RGB)
1263 break;
1264
1254 /* RGB full range (0-255) */ 1265 /* RGB full range (0-255) */
1255 io_write_and_or(sd, 0x02, 0x0f, 0x10); 1266 io_write_and_or(sd, 0x02, 0x0f, 0x10);
1256 1267
@@ -2058,6 +2069,7 @@ static void adv7842_setup_format(struct adv7842_state *state)
2058 io_write_clr_set(sd, 0x04, 0xe0, adv7842_op_ch_sel(state)); 2069 io_write_clr_set(sd, 0x04, 0xe0, adv7842_op_ch_sel(state));
2059 io_write_clr_set(sd, 0x05, 0x01, 2070 io_write_clr_set(sd, 0x05, 0x01,
2060 state->format->swap_cb_cr ? ADV7842_OP_SWAP_CB_CR : 0); 2071 state->format->swap_cb_cr ? ADV7842_OP_SWAP_CB_CR : 0);
2072 set_rgb_quantization_range(sd);
2061} 2073}
2062 2074
2063static int adv7842_get_format(struct v4l2_subdev *sd, 2075static int adv7842_get_format(struct v4l2_subdev *sd,
@@ -2777,11 +2789,11 @@ static int adv7842_cp_log_status(struct v4l2_subdev *sd)
2777 rgb_quantization_range_txt[state->rgb_quantization_range]); 2789 rgb_quantization_range_txt[state->rgb_quantization_range]);
2778 v4l2_info(sd, "Input color space: %s\n", 2790 v4l2_info(sd, "Input color space: %s\n",
2779 input_color_space_txt[reg_io_0x02 >> 4]); 2791 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",
2781 (reg_io_0x02 & 0x02) ? "RGB" : "YCbCr", 2793 (reg_io_0x02 & 0x02) ? "RGB" : "YCbCr",
2782 (reg_io_0x02 & 0x04) ? "(16-235)" : "(0-255)", 2794 (((reg_io_0x02 >> 2) & 0x01) ^ (reg_io_0x02 & 0x01)) ?
2783 ((reg_io_0x02 & 0x04) ^ (reg_io_0x02 & 0x01)) ? 2795 "(16-235)" : "(0-255)",
2784 "enabled" : "disabled"); 2796 (reg_io_0x02 & 0x08) ? "enabled" : "disabled");
2785 v4l2_info(sd, "Color space conversion: %s\n", 2797 v4l2_info(sd, "Color space conversion: %s\n",
2786 csc_coeff_sel_rb[cp_read(sd, 0xf4) >> 4]); 2798 csc_coeff_sel_rb[cp_read(sd, 0xf4) >> 4]);
2787 2799
@@ -2985,11 +2997,7 @@ static int adv7842_core_init(struct v4l2_subdev *sd)
2985 io_write(sd, 0x15, 0x80); /* Power up pads */ 2997 io_write(sd, 0x15, 0x80); /* Power up pads */
2986 2998
2987 /* video format */ 2999 /* video format */
2988 io_write(sd, 0x02, 3000 io_write(sd, 0x02, 0xf0 | pdata->alt_gamma << 3);
2989 0xf0 |
2990 pdata->alt_gamma << 3 |
2991 pdata->op_656_range << 2 |
2992 pdata->alt_data_sat << 0);
2993 io_write_and_or(sd, 0x05, 0xf0, pdata->blank_data << 3 | 3001 io_write_and_or(sd, 0x05, 0xf0, pdata->blank_data << 3 |
2994 pdata->insert_av_codes << 2 | 3002 pdata->insert_av_codes << 2 |
2995 pdata->replicate_av_codes << 1); 3003 pdata->replicate_av_codes << 1);