1 /* 2 * Copyright 2018 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 * Authors: AMD 23 * 24 */ 25 26 #include "mod_info_packet.h" 27 #include "core_types.h" 28 #include "dc_types.h" 29 #include "mod_shared.h" 30 31 #define HDMI_INFOFRAME_TYPE_VENDOR 0x81 32 33 enum ColorimetryRGBDP { 34 ColorimetryRGB_DP_sRGB = 0, 35 ColorimetryRGB_DP_AdobeRGB = 3, 36 ColorimetryRGB_DP_P3 = 4, 37 ColorimetryRGB_DP_CustomColorProfile = 5, 38 ColorimetryRGB_DP_ITU_R_BT2020RGB = 6, 39 }; 40 enum ColorimetryYCCDP { 41 ColorimetryYCC_DP_ITU601 = 0, 42 ColorimetryYCC_DP_ITU709 = 1, 43 ColorimetryYCC_DP_AdobeYCC = 5, 44 ColorimetryYCC_DP_ITU2020YCC = 6, 45 ColorimetryYCC_DP_ITU2020YCbCr = 7, 46 }; 47 48 void mod_build_vsc_infopacket(const struct dc_stream_state *stream, 49 struct dc_info_packet *info_packet) 50 { 51 unsigned int vscPacketRevision = 0; 52 unsigned int i; 53 unsigned int pixelEncoding = 0; 54 unsigned int colorimetryFormat = 0; 55 bool stereo3dSupport = false; 56 57 if (stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE && stream->view_format != VIEW_3D_FORMAT_NONE) { 58 vscPacketRevision = 1; 59 stereo3dSupport = true; 60 } 61 62 /*VSC packet set to 2 when DP revision >= 1.2*/ 63 if (stream->psr_version != 0) 64 vscPacketRevision = 2; 65 66 /* Update to revision 5 for extended colorimetry support for DPCD 1.4+ */ 67 if (stream->link->dpcd_caps.dpcd_rev.raw >= 0x14 && 68 stream->link->dpcd_caps.dprx_feature.bits.VSC_SDP_COLORIMETRY_SUPPORTED) 69 vscPacketRevision = 5; 70 71 /* VSC packet not needed based on the features 72 * supported by this DP display 73 */ 74 if (vscPacketRevision == 0) 75 return; 76 77 if (vscPacketRevision == 0x2) { 78 /* Secondary-data Packet ID = 0*/ 79 info_packet->hb0 = 0x00; 80 /* 07h - Packet Type Value indicating Video 81 * Stream Configuration packet 82 */ 83 info_packet->hb1 = 0x07; 84 /* 02h = VSC SDP supporting 3D stereo and PSR 85 * (applies to eDP v1.3 or higher). 86 */ 87 info_packet->hb2 = 0x02; 88 /* 08h = VSC packet supporting 3D stereo + PSR 89 * (HB2 = 02h). 90 */ 91 info_packet->hb3 = 0x08; 92 93 for (i = 0; i < 28; i++) 94 info_packet->sb[i] = 0; 95 96 info_packet->valid = true; 97 } 98 99 if (vscPacketRevision == 0x1) { 100 101 info_packet->hb0 = 0x00; // Secondary-data Packet ID = 0 102 info_packet->hb1 = 0x07; // 07h = Packet Type Value indicating Video Stream Configuration packet 103 info_packet->hb2 = 0x01; // 01h = Revision number. VSC SDP supporting 3D stereo only 104 info_packet->hb3 = 0x01; // 01h = VSC SDP supporting 3D stereo only (HB2 = 01h). 105 106 info_packet->valid = true; 107 } 108 109 if (stereo3dSupport) { 110 /* ==============================================================================================================| 111 * A. STEREO 3D 112 * ==============================================================================================================| 113 * VSC Payload (1 byte) From DP1.2 spec 114 * 115 * Bits 3:0 (Stereo Interface Method Code) | Bits 7:4 (Stereo Interface Method Specific Parameter) 116 * ----------------------------------------------------------------------------------------------------- 117 * 0 = Non Stereo Video | Must be set to 0x0 118 * ----------------------------------------------------------------------------------------------------- 119 * 1 = Frame/Field Sequential | 0x0: L + R view indication based on MISC1 bit 2:1 120 * | 0x1: Right when Stereo Signal = 1 121 * | 0x2: Left when Stereo Signal = 1 122 * | (others reserved) 123 * ----------------------------------------------------------------------------------------------------- 124 * 2 = Stacked Frame | 0x0: Left view is on top and right view on bottom 125 * | (others reserved) 126 * ----------------------------------------------------------------------------------------------------- 127 * 3 = Pixel Interleaved | 0x0: horiz interleaved, right view pixels on even lines 128 * | 0x1: horiz interleaved, right view pixels on odd lines 129 * | 0x2: checker board, start with left view pixel 130 * | 0x3: vertical interleaved, start with left view pixels 131 * | 0x4: vertical interleaved, start with right view pixels 132 * | (others reserved) 133 * ----------------------------------------------------------------------------------------------------- 134 * 4 = Side-by-side | 0x0: left half represents left eye view 135 * | 0x1: left half represents right eye view 136 */ 137 switch (stream->timing.timing_3d_format) { 138 case TIMING_3D_FORMAT_HW_FRAME_PACKING: 139 case TIMING_3D_FORMAT_SW_FRAME_PACKING: 140 case TIMING_3D_FORMAT_TOP_AND_BOTTOM: 141 case TIMING_3D_FORMAT_TB_SW_PACKED: 142 info_packet->sb[0] = 0x02; // Stacked Frame, Left view is on top and right view on bottom. 143 break; 144 case TIMING_3D_FORMAT_DP_HDMI_INBAND_FA: 145 case TIMING_3D_FORMAT_INBAND_FA: 146 info_packet->sb[0] = 0x01; // Frame/Field Sequential, L + R view indication based on MISC1 bit 2:1 147 break; 148 case TIMING_3D_FORMAT_SIDE_BY_SIDE: 149 case TIMING_3D_FORMAT_SBS_SW_PACKED: 150 info_packet->sb[0] = 0x04; // Side-by-side 151 break; 152 default: 153 info_packet->sb[0] = 0x00; // No Stereo Video, Shall be cleared to 0x0. 154 break; 155 } 156 157 } 158 159 /* 05h = VSC SDP supporting 3D stereo, PSR2, and Pixel Encoding/Colorimetry Format indication. 160 * Added in DP1.3, a DP Source device is allowed to indicate the pixel encoding/colorimetry 161 * format to the DP Sink device with VSC SDP only when the DP Sink device supports it 162 * (i.e., VSC_SDP_EXTENSION_FOR_COLORIMETRY_SUPPORTED bit in the DPRX_FEATURE_ENUMERATION_LIST 163 * register (DPCD Address 02210h, bit 3) is set to 1). 164 * (Requires VSC_SDP_EXTENSION_FOR_COLORIMETRY_SUPPORTED bit set to 1 in DPCD 02210h. This 165 * DPCD register is exposed in the new Extended Receiver Capability field for DPCD Rev. 1.4 166 * (and higher). When MISC1. bit 6. is Set to 1, a Source device uses a VSC SDP to indicate 167 * the Pixel Encoding/Colorimetry Format and that a Sink device must ignore MISC1, bit 7, and 168 * MISC0, bits 7:1 (MISC1, bit 7. and MISC0, bits 7:1 become "don't care").) 169 */ 170 if (vscPacketRevision == 0x5) { 171 /* Secondary-data Packet ID = 0 */ 172 info_packet->hb0 = 0x00; 173 /* 07h - Packet Type Value indicating Video Stream Configuration packet */ 174 info_packet->hb1 = 0x07; 175 /* 05h = VSC SDP supporting 3D stereo, PSR2, and Pixel Encoding/Colorimetry Format indication. */ 176 info_packet->hb2 = 0x05; 177 /* 13h = VSC SDP supporting 3D stereo, + PSR2, + Pixel Encoding/Colorimetry Format indication (HB2 = 05h). */ 178 info_packet->hb3 = 0x13; 179 180 info_packet->valid = true; 181 182 /* Set VSC SDP fields for pixel encoding and colorimetry format from DP 1.3 specs 183 * Data Bytes DB 18~16 184 * Bits 3:0 (Colorimetry Format) | Bits 7:4 (Pixel Encoding) 185 * ---------------------------------------------------------------------------------------------------- 186 * 0x0 = sRGB | 0 = RGB 187 * 0x1 = RGB Wide Gamut Fixed Point 188 * 0x2 = RGB Wide Gamut Floating Point 189 * 0x3 = AdobeRGB 190 * 0x4 = DCI-P3 191 * 0x5 = CustomColorProfile 192 * (others reserved) 193 * ---------------------------------------------------------------------------------------------------- 194 * 0x0 = ITU-R BT.601 | 1 = YCbCr444 195 * 0x1 = ITU-R BT.709 196 * 0x2 = xvYCC601 197 * 0x3 = xvYCC709 198 * 0x4 = sYCC601 199 * 0x5 = AdobeYCC601 200 * 0x6 = ITU-R BT.2020 Y'cC'bcC'rc 201 * 0x7 = ITU-R BT.2020 Y'C'bC'r 202 * (others reserved) 203 * ---------------------------------------------------------------------------------------------------- 204 * 0x0 = ITU-R BT.601 | 2 = YCbCr422 205 * 0x1 = ITU-R BT.709 206 * 0x2 = xvYCC601 207 * 0x3 = xvYCC709 208 * 0x4 = sYCC601 209 * 0x5 = AdobeYCC601 210 * 0x6 = ITU-R BT.2020 Y'cC'bcC'rc 211 * 0x7 = ITU-R BT.2020 Y'C'bC'r 212 * (others reserved) 213 * ---------------------------------------------------------------------------------------------------- 214 * 0x0 = ITU-R BT.601 | 3 = YCbCr420 215 * 0x1 = ITU-R BT.709 216 * 0x2 = xvYCC601 217 * 0x3 = xvYCC709 218 * 0x4 = sYCC601 219 * 0x5 = AdobeYCC601 220 * 0x6 = ITU-R BT.2020 Y'cC'bcC'rc 221 * 0x7 = ITU-R BT.2020 Y'C'bC'r 222 * (others reserved) 223 * ---------------------------------------------------------------------------------------------------- 224 * 0x0 =DICOM Part14 Grayscale | 4 = Yonly 225 * Display Function 226 * (others reserved) 227 */ 228 229 /* Set Pixel Encoding */ 230 switch (stream->timing.pixel_encoding) { 231 case PIXEL_ENCODING_RGB: 232 pixelEncoding = 0x0; /* RGB = 0h */ 233 break; 234 case PIXEL_ENCODING_YCBCR444: 235 pixelEncoding = 0x1; /* YCbCr444 = 1h */ 236 break; 237 case PIXEL_ENCODING_YCBCR422: 238 pixelEncoding = 0x2; /* YCbCr422 = 2h */ 239 break; 240 case PIXEL_ENCODING_YCBCR420: 241 pixelEncoding = 0x3; /* YCbCr420 = 3h */ 242 break; 243 default: 244 pixelEncoding = 0x0; /* default RGB = 0h */ 245 break; 246 } 247 248 /* Set Colorimetry format based on pixel encoding */ 249 switch (stream->timing.pixel_encoding) { 250 case PIXEL_ENCODING_RGB: 251 if ((stream->output_color_space == COLOR_SPACE_SRGB) || 252 (stream->output_color_space == COLOR_SPACE_SRGB_LIMITED)) 253 colorimetryFormat = ColorimetryRGB_DP_sRGB; 254 else if (stream->output_color_space == COLOR_SPACE_ADOBERGB) 255 colorimetryFormat = ColorimetryRGB_DP_AdobeRGB; 256 else if ((stream->output_color_space == COLOR_SPACE_2020_RGB_FULLRANGE) || 257 (stream->output_color_space == COLOR_SPACE_2020_RGB_LIMITEDRANGE)) 258 colorimetryFormat = ColorimetryRGB_DP_ITU_R_BT2020RGB; 259 break; 260 261 case PIXEL_ENCODING_YCBCR444: 262 case PIXEL_ENCODING_YCBCR422: 263 case PIXEL_ENCODING_YCBCR420: 264 /* Note: xvYCC probably not supported correctly here on DP since colorspace translation 265 * loses distinction between BT601 vs xvYCC601 in translation 266 */ 267 if (stream->output_color_space == COLOR_SPACE_YCBCR601) 268 colorimetryFormat = ColorimetryYCC_DP_ITU601; 269 else if (stream->output_color_space == COLOR_SPACE_YCBCR709) 270 colorimetryFormat = ColorimetryYCC_DP_ITU709; 271 else if (stream->output_color_space == COLOR_SPACE_ADOBERGB) 272 colorimetryFormat = ColorimetryYCC_DP_AdobeYCC; 273 else if (stream->output_color_space == COLOR_SPACE_2020_YCBCR) 274 colorimetryFormat = ColorimetryYCC_DP_ITU2020YCbCr; 275 break; 276 277 default: 278 colorimetryFormat = ColorimetryRGB_DP_sRGB; 279 break; 280 } 281 282 info_packet->sb[16] = (pixelEncoding << 4) | colorimetryFormat; 283 284 /* Set color depth */ 285 switch (stream->timing.display_color_depth) { 286 case COLOR_DEPTH_666: 287 /* NOTE: This is actually not valid for YCbCr pixel encoding to have 6 bpc 288 * as of DP1.4 spec, but value of 0 probably reserved here for potential future use. 289 */ 290 info_packet->sb[17] = 0; 291 break; 292 case COLOR_DEPTH_888: 293 info_packet->sb[17] = 1; 294 break; 295 case COLOR_DEPTH_101010: 296 info_packet->sb[17] = 2; 297 break; 298 case COLOR_DEPTH_121212: 299 info_packet->sb[17] = 3; 300 break; 301 /*case COLOR_DEPTH_141414: -- NO SUCH FORMAT IN DP SPEC */ 302 case COLOR_DEPTH_161616: 303 info_packet->sb[17] = 4; 304 break; 305 default: 306 info_packet->sb[17] = 0; 307 break; 308 } 309 310 /* all YCbCr are always limited range */ 311 if ((stream->output_color_space == COLOR_SPACE_SRGB_LIMITED) || 312 (stream->output_color_space == COLOR_SPACE_2020_RGB_LIMITEDRANGE) || 313 (pixelEncoding != 0x0)) { 314 info_packet->sb[17] |= 0x80; /* DB17 bit 7 set to 1 for CEA timing. */ 315 } 316 317 /* Content Type (Bits 2:0) 318 * 0 = Not defined. 319 * 1 = Graphics. 320 * 2 = Photo. 321 * 3 = Video. 322 * 4 = Game. 323 */ 324 info_packet->sb[18] = 0; 325 } 326 327 } 328 329