Narender Ankam | 5295bf4 | 2019-11-20 14:00:50 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <drm/drm_edid.h> |
| 14 | |
| 15 | #include "sde_kms.h" |
| 16 | #include "sde_edid_parser.h" |
| 17 | |
| 18 | #define DBC_START_OFFSET 4 |
| 19 | #define EDID_DTD_LEN 18 |
| 20 | |
| 21 | enum data_block_types { |
| 22 | RESERVED, |
| 23 | AUDIO_DATA_BLOCK, |
| 24 | VIDEO_DATA_BLOCK, |
| 25 | VENDOR_SPECIFIC_DATA_BLOCK, |
| 26 | SPEAKER_ALLOCATION_DATA_BLOCK, |
| 27 | VESA_DTC_DATA_BLOCK, |
| 28 | RESERVED2, |
| 29 | USE_EXTENDED_TAG |
| 30 | }; |
| 31 | |
| 32 | static u8 *sde_find_edid_extension(struct edid *edid, int ext_id) |
| 33 | { |
| 34 | u8 *edid_ext = NULL; |
| 35 | int i; |
| 36 | |
| 37 | /* No EDID or EDID extensions */ |
| 38 | if (edid == NULL || edid->extensions == 0) |
| 39 | return NULL; |
| 40 | |
| 41 | /* Find CEA extension */ |
| 42 | for (i = 0; i < edid->extensions; i++) { |
| 43 | edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1); |
| 44 | if (edid_ext[0] == ext_id) |
| 45 | break; |
| 46 | } |
| 47 | |
| 48 | if (i == edid->extensions) |
| 49 | return NULL; |
| 50 | |
| 51 | return edid_ext; |
| 52 | } |
| 53 | |
| 54 | static u8 *sde_find_cea_extension(struct edid *edid) |
| 55 | { |
| 56 | return sde_find_edid_extension(edid, SDE_CEA_EXT); |
| 57 | } |
| 58 | |
| 59 | static int |
| 60 | sde_cea_db_payload_len(const u8 *db) |
| 61 | { |
| 62 | return db[0] & 0x1f; |
| 63 | } |
| 64 | |
| 65 | static int |
| 66 | sde_cea_db_tag(const u8 *db) |
| 67 | { |
| 68 | return db[0] >> 5; |
| 69 | } |
| 70 | |
| 71 | static int |
| 72 | sde_cea_revision(const u8 *cea) |
| 73 | { |
| 74 | return cea[1]; |
| 75 | } |
| 76 | |
| 77 | static int |
| 78 | sde_cea_db_offsets(const u8 *cea, int *start, int *end) |
| 79 | { |
| 80 | /* Data block offset in CEA extension block */ |
| 81 | *start = 4; |
| 82 | *end = cea[2]; |
| 83 | if (*end == 0) |
| 84 | *end = 127; |
| 85 | if (*end < 4 || *end > 127) |
| 86 | return -ERANGE; |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | #define sde_for_each_cea_db(cea, i, start, end) \ |
| 91 | for ((i) = (start); \ |
| 92 | (i) < (end) && (i) + sde_cea_db_payload_len(&(cea)[(i)]) < (end); \ |
| 93 | (i) += sde_cea_db_payload_len(&(cea)[(i)]) + 1) |
| 94 | |
Abhinav Kumar | cd18751 | 2017-06-30 01:02:36 -0700 | [diff] [blame] | 95 | static bool sde_cea_db_is_hdmi_hf_vsdb(const u8 *db) |
| 96 | { |
| 97 | int hdmi_id; |
| 98 | |
| 99 | if (sde_cea_db_tag(db) != VENDOR_SPECIFIC_DATA_BLOCK) |
| 100 | return false; |
| 101 | |
| 102 | if (sde_cea_db_payload_len(db) < 7) |
| 103 | return false; |
| 104 | |
| 105 | hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16); |
| 106 | |
| 107 | return hdmi_id == HDMI_IEEE_OUI_HF; |
| 108 | } |
| 109 | |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 110 | static u8 *sde_edid_find_extended_tag_block(struct edid *edid, int blk_id) |
| 111 | { |
| 112 | u8 *db = NULL; |
| 113 | u8 *cea = NULL; |
| 114 | |
| 115 | if (!edid) { |
| 116 | SDE_ERROR("%s: invalid input\n", __func__); |
| 117 | return NULL; |
| 118 | } |
| 119 | |
| 120 | cea = sde_find_cea_extension(edid); |
| 121 | |
| 122 | if (cea && sde_cea_revision(cea) >= 3) { |
| 123 | int i, start, end; |
| 124 | |
| 125 | if (sde_cea_db_offsets(cea, &start, &end)) |
| 126 | return NULL; |
| 127 | |
| 128 | sde_for_each_cea_db(cea, i, start, end) { |
| 129 | db = &cea[i]; |
| 130 | if ((sde_cea_db_tag(db) == SDE_EXTENDED_TAG) && |
| 131 | (db[1] == blk_id)) |
| 132 | return db; |
| 133 | } |
| 134 | } |
| 135 | return NULL; |
| 136 | } |
| 137 | |
| 138 | static u8 * |
| 139 | sde_edid_find_block(struct edid *edid, int blk_id) |
| 140 | { |
| 141 | u8 *db = NULL; |
| 142 | u8 *cea = NULL; |
| 143 | |
| 144 | if (!edid) { |
| 145 | SDE_ERROR("%s: invalid input\n", __func__); |
| 146 | return NULL; |
| 147 | } |
| 148 | |
| 149 | cea = sde_find_cea_extension(edid); |
| 150 | |
| 151 | if (cea && sde_cea_revision(cea) >= 3) { |
| 152 | int i, start, end; |
| 153 | |
| 154 | if (sde_cea_db_offsets(cea, &start, &end)) |
| 155 | return NULL; |
| 156 | |
| 157 | sde_for_each_cea_db(cea, i, start, end) { |
| 158 | db = &cea[i]; |
| 159 | if (sde_cea_db_tag(db) == blk_id) |
| 160 | return db; |
| 161 | } |
| 162 | } |
| 163 | return NULL; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | static const u8 *_sde_edid_find_block(const u8 *in_buf, u32 start_offset, |
| 168 | u8 type, u8 *len) |
| 169 | { |
| 170 | /* the start of data block collection, start of Video Data Block */ |
| 171 | u32 offset = start_offset; |
| 172 | u32 dbc_offset = in_buf[2]; |
| 173 | |
| 174 | SDE_EDID_DEBUG("%s +", __func__); |
| 175 | /* |
| 176 | * * edid buffer 1, byte 2 being 4 means no non-DTD/Data block |
| 177 | * collection present. |
| 178 | * * edid buffer 1, byte 2 being 0 means no non-DTD/DATA block |
| 179 | * collection present and no DTD data present. |
| 180 | */ |
| 181 | if ((dbc_offset == 0) || (dbc_offset == 4)) { |
| 182 | SDE_ERROR("EDID: no DTD or non-DTD data present\n"); |
| 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | while (offset < dbc_offset) { |
| 187 | u8 block_len = in_buf[offset] & 0x1F; |
| 188 | |
| 189 | if ((offset + block_len <= dbc_offset) && |
| 190 | (in_buf[offset] >> 5) == type) { |
| 191 | *len = block_len; |
| 192 | SDE_EDID_DEBUG("block=%d found @ 0x%x w/ len=%d\n", |
| 193 | type, offset, block_len); |
| 194 | |
| 195 | return in_buf + offset; |
| 196 | } |
| 197 | offset += 1 + block_len; |
| 198 | } |
| 199 | |
| 200 | return NULL; |
| 201 | } |
| 202 | |
| 203 | static void sde_edid_extract_vendor_id(struct sde_edid_ctrl *edid_ctrl) |
| 204 | { |
| 205 | char *vendor_id; |
| 206 | u32 id_codes; |
| 207 | |
| 208 | SDE_EDID_DEBUG("%s +", __func__); |
| 209 | if (!edid_ctrl) { |
| 210 | SDE_ERROR("%s: invalid input\n", __func__); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | vendor_id = edid_ctrl->vendor_id; |
| 215 | id_codes = ((u32)edid_ctrl->edid->mfg_id[0] << 8) + |
| 216 | edid_ctrl->edid->mfg_id[1]; |
| 217 | |
| 218 | vendor_id[0] = 'A' - 1 + ((id_codes >> 10) & 0x1F); |
| 219 | vendor_id[1] = 'A' - 1 + ((id_codes >> 5) & 0x1F); |
| 220 | vendor_id[2] = 'A' - 1 + (id_codes & 0x1F); |
| 221 | vendor_id[3] = 0; |
| 222 | SDE_EDID_DEBUG("vendor id is %s ", vendor_id); |
| 223 | SDE_EDID_DEBUG("%s -", __func__); |
| 224 | } |
| 225 | |
| 226 | static void sde_edid_set_y420_support(struct drm_connector *connector, |
| 227 | u32 video_format) |
| 228 | { |
| 229 | u8 cea_mode = 0; |
| 230 | struct drm_display_mode *mode; |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame] | 231 | u32 mode_fmt_flags = 0; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 232 | |
| 233 | /* Need to add Y420 support flag to the modes */ |
| 234 | list_for_each_entry(mode, &connector->probed_modes, head) { |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame] | 235 | /* Cache the format flags before clearing */ |
| 236 | mode_fmt_flags = mode->flags; |
| 237 | /* Clear the RGB/YUV format flags before calling upstream API */ |
| 238 | mode->flags &= ~SDE_DRM_MODE_FLAG_FMT_MASK; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 239 | cea_mode = drm_match_cea_mode(mode); |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame] | 240 | /* Restore the format flags */ |
| 241 | mode->flags = mode_fmt_flags; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 242 | if ((cea_mode != 0) && (cea_mode == video_format)) { |
| 243 | SDE_EDID_DEBUG("%s found match for %d ", __func__, |
| 244 | video_format); |
| 245 | mode->flags |= DRM_MODE_FLAG_SUPPORTS_YUV; |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | static void sde_edid_parse_Y420CMDB( |
| 251 | struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl, |
| 252 | const u8 *db) |
| 253 | { |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame] | 254 | u8 cmdb_len = 0; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 255 | u8 svd_len = 0; |
| 256 | const u8 *svd = NULL; |
Narender Ankam | 5295bf4 | 2019-11-20 14:00:50 +0530 | [diff] [blame] | 257 | u32 i = 0; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 258 | u32 video_format = 0; |
Narender Ankam | 5295bf4 | 2019-11-20 14:00:50 +0530 | [diff] [blame] | 259 | u32 num_cmdb_svd = 0; |
| 260 | const u32 mult = 8; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 261 | |
| 262 | if (!edid_ctrl) { |
| 263 | SDE_ERROR("%s: edid_ctrl is NULL\n", __func__); |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | if (!db) { |
| 268 | SDE_ERROR("%s: invalid input\n", __func__); |
| 269 | return; |
| 270 | } |
| 271 | SDE_EDID_DEBUG("%s +\n", __func__); |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame] | 272 | cmdb_len = db[0] & 0x1f; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 273 | |
Narender Ankam | 5295bf4 | 2019-11-20 14:00:50 +0530 | [diff] [blame] | 274 | if (cmdb_len < 1) |
| 275 | return; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 276 | |
| 277 | svd = sde_edid_find_block(edid_ctrl->edid, VIDEO_DATA_BLOCK); |
| 278 | |
| 279 | if (svd) { |
| 280 | /*moving to the next byte as vic info begins there*/ |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 281 | svd_len = svd[0] & 0x1f; |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame] | 282 | ++svd; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Narender Ankam | 5295bf4 | 2019-11-20 14:00:50 +0530 | [diff] [blame] | 285 | if (cmdb_len == 1) |
| 286 | num_cmdb_svd = svd_len; |
| 287 | else { |
| 288 | num_cmdb_svd = (cmdb_len - 1) * mult; |
| 289 | if (num_cmdb_svd > svd_len) |
| 290 | num_cmdb_svd = svd_len; |
| 291 | } |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 292 | |
Narender Ankam | 5295bf4 | 2019-11-20 14:00:50 +0530 | [diff] [blame] | 293 | for (i = 0; i < num_cmdb_svd; i++) { |
| 294 | video_format = *(svd + i) & 0x7F; |
| 295 | /* |
| 296 | * If cmdb_len is 1, it means all SVDs support YUV |
| 297 | * Else, we check each byte of the cmdb bitmap bitwise |
| 298 | * and match those bits with the formats populated |
| 299 | * during the parsing of the Video Data Blocks. |
| 300 | * Refer to CTA 861-F section 7.5.11 YCBCR 4:2:0 Capability |
| 301 | * Map Data Block for more details on this. |
| 302 | */ |
| 303 | if (cmdb_len == 1 || (db[2 + i / mult] & (1 << (i % mult)))) |
| 304 | sde_edid_set_y420_support(connector, video_format); |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | SDE_EDID_DEBUG("%s -\n", __func__); |
| 308 | |
| 309 | } |
| 310 | |
| 311 | static void sde_edid_parse_Y420VDB( |
| 312 | struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl, |
| 313 | const u8 *db) |
| 314 | { |
| 315 | u8 len = db[0] & 0x1f; |
| 316 | u32 i = 0; |
| 317 | u32 video_format = 0; |
| 318 | |
| 319 | if (!edid_ctrl) { |
| 320 | SDE_ERROR("%s: invalid input\n", __func__); |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | SDE_EDID_DEBUG("%s +\n", __func__); |
| 325 | |
| 326 | /* Offset to byte 3 */ |
| 327 | db += 2; |
| 328 | for (i = 0; i < len - 1; i++) { |
| 329 | video_format = *(db + i) & 0x7F; |
| 330 | /* |
| 331 | * mode was already added in get_modes() |
| 332 | * only need to set the Y420 support flag |
| 333 | */ |
| 334 | sde_edid_set_y420_support(connector, video_format); |
| 335 | } |
| 336 | SDE_EDID_DEBUG("%s -", __func__); |
| 337 | } |
| 338 | |
| 339 | static void sde_edid_set_mode_format( |
| 340 | struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl) |
| 341 | { |
| 342 | const u8 *db = NULL; |
| 343 | struct drm_display_mode *mode; |
| 344 | |
| 345 | SDE_EDID_DEBUG("%s +\n", __func__); |
| 346 | /* Set YUV mode support flags for YCbcr420VDB */ |
| 347 | db = sde_edid_find_extended_tag_block(edid_ctrl->edid, |
| 348 | Y420_VIDEO_DATA_BLOCK); |
| 349 | if (db) |
| 350 | sde_edid_parse_Y420VDB(connector, edid_ctrl, db); |
| 351 | else |
| 352 | SDE_EDID_DEBUG("YCbCr420 VDB is not present\n"); |
| 353 | |
| 354 | /* Set RGB supported on all modes where YUV is not set */ |
| 355 | list_for_each_entry(mode, &connector->probed_modes, head) { |
| 356 | if (!(mode->flags & DRM_MODE_FLAG_SUPPORTS_YUV)) |
| 357 | mode->flags |= DRM_MODE_FLAG_SUPPORTS_RGB; |
| 358 | } |
| 359 | |
| 360 | |
| 361 | db = sde_edid_find_extended_tag_block(edid_ctrl->edid, |
| 362 | Y420_CAPABILITY_MAP_DATA_BLOCK); |
| 363 | if (db) |
| 364 | sde_edid_parse_Y420CMDB(connector, edid_ctrl, db); |
| 365 | else |
| 366 | SDE_EDID_DEBUG("YCbCr420 CMDB is not present\n"); |
| 367 | |
Narender Ankam | 4b76612 | 2019-11-20 14:12:50 +0530 | [diff] [blame^] | 368 | /* |
| 369 | * As per HDMI 2.0 spec, a sink supporting any modes |
| 370 | * requiring more than 340Mhz clock rate should support |
| 371 | * SCDC as well. This is required because we need the SCDC |
| 372 | * channel to set the TMDS clock ratio. However in cases |
| 373 | * where the TV publishes such a mode in its list of modes |
| 374 | * but does not have SCDC support as per HDMI HFVSDB block |
| 375 | * remove RGB mode support from the flags. Currently, in |
| 376 | * the list of modes not having deep color support only RGB |
| 377 | * modes shall requre a clock of 340Mhz and above such as the |
| 378 | * 4K@60fps case. All other modes shall be YUV. |
| 379 | * Deep color case is handled separately while choosing the |
| 380 | * best mode in the _sde_hdmi_choose_best_format API where |
| 381 | * we enable deep color only if it satisfies both source and |
| 382 | * sink requirements. However, that API assumes that at least |
| 383 | * RGB mode is supported on the mode. Hence, it would be better |
| 384 | * to remove the format support flags while parsing the EDID |
| 385 | * itself if it doesn't satisfy the HDMI spec requirement. |
| 386 | */ |
| 387 | |
| 388 | list_for_each_entry(mode, &connector->probed_modes, head) { |
| 389 | if ((mode->clock > MIN_SCRAMBLER_REQ_RATE) && |
| 390 | !connector->scdc_present) { |
| 391 | mode->flags &= ~DRM_MODE_FLAG_SUPPORTS_RGB; |
| 392 | } |
| 393 | } |
| 394 | |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 395 | SDE_EDID_DEBUG("%s -\n", __func__); |
| 396 | } |
| 397 | |
Abhinav Kumar | cd18751 | 2017-06-30 01:02:36 -0700 | [diff] [blame] | 398 | static void _sde_edid_update_dc_modes( |
| 399 | struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl) |
| 400 | { |
| 401 | int i, start, end; |
| 402 | u8 *edid_ext, *hdmi; |
| 403 | struct drm_display_info *disp_info; |
| 404 | u32 hdmi_dc_yuv_modes = 0; |
| 405 | |
| 406 | SDE_EDID_DEBUG("%s +\n", __func__); |
| 407 | |
| 408 | if (!connector || !edid_ctrl) { |
| 409 | SDE_ERROR("invalid input\n"); |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | disp_info = &connector->display_info; |
| 414 | |
| 415 | edid_ext = sde_find_cea_extension(edid_ctrl->edid); |
| 416 | |
| 417 | if (!edid_ext) { |
| 418 | SDE_ERROR("no cea extension\n"); |
| 419 | return; |
| 420 | } |
| 421 | |
| 422 | if (sde_cea_db_offsets(edid_ext, &start, &end)) |
| 423 | return; |
| 424 | |
| 425 | sde_for_each_cea_db(edid_ext, i, start, end) { |
| 426 | if (sde_cea_db_is_hdmi_hf_vsdb(&edid_ext[i])) { |
| 427 | |
| 428 | hdmi = &edid_ext[i]; |
| 429 | |
| 430 | if (sde_cea_db_payload_len(hdmi) < 7) |
| 431 | continue; |
| 432 | |
| 433 | if (hdmi[7] & DRM_EDID_YCBCR420_DC_30) { |
| 434 | hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_30; |
| 435 | SDE_EDID_DEBUG("Y420 30-bit supported\n"); |
| 436 | } |
| 437 | |
| 438 | if (hdmi[7] & DRM_EDID_YCBCR420_DC_36) { |
| 439 | hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_36; |
| 440 | SDE_EDID_DEBUG("Y420 36-bit supported\n"); |
| 441 | } |
| 442 | |
| 443 | if (hdmi[7] & DRM_EDID_YCBCR420_DC_48) { |
| 444 | hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_36; |
| 445 | SDE_EDID_DEBUG("Y420 48-bit supported\n"); |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | disp_info->edid_hdmi_dc_modes |= hdmi_dc_yuv_modes; |
| 451 | |
| 452 | SDE_EDID_DEBUG("%s -\n", __func__); |
| 453 | } |
| 454 | |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 455 | static void _sde_edid_extract_audio_data_blocks( |
| 456 | struct sde_edid_ctrl *edid_ctrl) |
| 457 | { |
| 458 | u8 len = 0; |
| 459 | u8 adb_max = 0; |
| 460 | const u8 *adb = NULL; |
| 461 | u32 offset = DBC_START_OFFSET; |
| 462 | u8 *cea = NULL; |
| 463 | |
| 464 | if (!edid_ctrl) { |
| 465 | SDE_ERROR("invalid edid_ctrl\n"); |
| 466 | return; |
| 467 | } |
| 468 | SDE_EDID_DEBUG("%s +", __func__); |
| 469 | cea = sde_find_cea_extension(edid_ctrl->edid); |
| 470 | if (!cea) { |
| 471 | SDE_DEBUG("CEA extension not found\n"); |
| 472 | return; |
| 473 | } |
| 474 | |
| 475 | edid_ctrl->adb_size = 0; |
| 476 | |
| 477 | memset(edid_ctrl->audio_data_block, 0, |
| 478 | sizeof(edid_ctrl->audio_data_block)); |
| 479 | |
| 480 | do { |
| 481 | len = 0; |
| 482 | adb = _sde_edid_find_block(cea, offset, AUDIO_DATA_BLOCK, |
| 483 | &len); |
| 484 | |
| 485 | if ((adb == NULL) || (len > MAX_AUDIO_DATA_BLOCK_SIZE || |
| 486 | adb_max >= MAX_NUMBER_ADB)) { |
| 487 | if (!edid_ctrl->adb_size) { |
| 488 | SDE_DEBUG("No/Invalid Audio Data Block\n"); |
| 489 | return; |
| 490 | } |
| 491 | |
| 492 | continue; |
| 493 | } |
| 494 | |
| 495 | memcpy(edid_ctrl->audio_data_block + edid_ctrl->adb_size, |
| 496 | adb + 1, len); |
| 497 | offset = (adb - cea) + 1 + len; |
| 498 | |
| 499 | edid_ctrl->adb_size += len; |
| 500 | adb_max++; |
| 501 | } while (adb); |
| 502 | SDE_EDID_DEBUG("%s -", __func__); |
| 503 | } |
| 504 | |
| 505 | static void _sde_edid_extract_speaker_allocation_data( |
| 506 | struct sde_edid_ctrl *edid_ctrl) |
| 507 | { |
| 508 | u8 len; |
| 509 | const u8 *sadb = NULL; |
| 510 | u8 *cea = NULL; |
| 511 | |
| 512 | if (!edid_ctrl) { |
| 513 | SDE_ERROR("invalid edid_ctrl\n"); |
| 514 | return; |
| 515 | } |
| 516 | SDE_EDID_DEBUG("%s +", __func__); |
| 517 | cea = sde_find_cea_extension(edid_ctrl->edid); |
| 518 | if (!cea) { |
| 519 | SDE_DEBUG("CEA extension not found\n"); |
| 520 | return; |
| 521 | } |
| 522 | |
| 523 | sadb = _sde_edid_find_block(cea, DBC_START_OFFSET, |
| 524 | SPEAKER_ALLOCATION_DATA_BLOCK, &len); |
| 525 | if ((sadb == NULL) || (len != MAX_SPKR_ALLOC_DATA_BLOCK_SIZE)) { |
| 526 | SDE_DEBUG("No/Invalid Speaker Allocation Data Block\n"); |
| 527 | return; |
| 528 | } |
| 529 | |
| 530 | memcpy(edid_ctrl->spkr_alloc_data_block, sadb + 1, len); |
| 531 | edid_ctrl->sadb_size = len; |
| 532 | |
| 533 | SDE_EDID_DEBUG("speaker alloc data SP byte = %08x %s%s%s%s%s%s%s\n", |
| 534 | sadb[1], |
| 535 | (sadb[1] & BIT(0)) ? "FL/FR," : "", |
| 536 | (sadb[1] & BIT(1)) ? "LFE," : "", |
| 537 | (sadb[1] & BIT(2)) ? "FC," : "", |
| 538 | (sadb[1] & BIT(3)) ? "RL/RR," : "", |
| 539 | (sadb[1] & BIT(4)) ? "RC," : "", |
| 540 | (sadb[1] & BIT(5)) ? "FLC/FRC," : "", |
| 541 | (sadb[1] & BIT(6)) ? "RLC/RRC," : ""); |
| 542 | SDE_EDID_DEBUG("%s -", __func__); |
| 543 | } |
| 544 | |
| 545 | struct sde_edid_ctrl *sde_edid_init(void) |
| 546 | { |
| 547 | struct sde_edid_ctrl *edid_ctrl = NULL; |
| 548 | |
| 549 | SDE_EDID_DEBUG("%s +\n", __func__); |
| 550 | edid_ctrl = kzalloc(sizeof(*edid_ctrl), GFP_KERNEL); |
| 551 | if (!edid_ctrl) { |
| 552 | SDE_ERROR("edid_ctrl alloc failed\n"); |
| 553 | return NULL; |
| 554 | } |
| 555 | memset((edid_ctrl), 0, sizeof(*edid_ctrl)); |
| 556 | SDE_EDID_DEBUG("%s -\n", __func__); |
| 557 | return edid_ctrl; |
| 558 | } |
| 559 | |
| 560 | void sde_free_edid(void **input) |
| 561 | { |
| 562 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input); |
| 563 | |
| 564 | SDE_EDID_DEBUG("%s +", __func__); |
| 565 | kfree(edid_ctrl->edid); |
| 566 | edid_ctrl->edid = NULL; |
| 567 | } |
| 568 | |
| 569 | void sde_edid_deinit(void **input) |
| 570 | { |
| 571 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input); |
| 572 | |
| 573 | SDE_EDID_DEBUG("%s +", __func__); |
| 574 | sde_free_edid((void *)&edid_ctrl); |
| 575 | kfree(edid_ctrl); |
| 576 | SDE_EDID_DEBUG("%s -", __func__); |
| 577 | } |
| 578 | |
| 579 | int _sde_edid_update_modes(struct drm_connector *connector, |
| 580 | void *input) |
| 581 | { |
| 582 | int rc = 0; |
| 583 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input); |
Narender Ankam | db5e8d8 | 2019-11-20 14:07:04 +0530 | [diff] [blame] | 584 | struct drm_display_info *disp_info; |
| 585 | |
| 586 | disp_info = &connector->display_info; |
| 587 | |
| 588 | if (disp_info) |
| 589 | disp_info->edid_hdmi_dc_modes = 0; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 590 | |
| 591 | SDE_EDID_DEBUG("%s +", __func__); |
| 592 | if (edid_ctrl->edid) { |
| 593 | drm_mode_connector_update_edid_property(connector, |
| 594 | edid_ctrl->edid); |
| 595 | |
| 596 | rc = drm_add_edid_modes(connector, edid_ctrl->edid); |
| 597 | sde_edid_set_mode_format(connector, edid_ctrl); |
Abhinav Kumar | cd18751 | 2017-06-30 01:02:36 -0700 | [diff] [blame] | 598 | _sde_edid_update_dc_modes(connector, edid_ctrl); |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 599 | SDE_EDID_DEBUG("%s -", __func__); |
| 600 | return rc; |
| 601 | } |
| 602 | |
| 603 | drm_mode_connector_update_edid_property(connector, NULL); |
| 604 | SDE_EDID_DEBUG("%s null edid -", __func__); |
| 605 | return rc; |
| 606 | } |
| 607 | |
Padmanabhan Komanduru | c21c8c4 | 2017-09-06 17:14:08 +0530 | [diff] [blame] | 608 | u8 sde_get_edid_checksum(void *input) |
| 609 | { |
| 610 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input); |
| 611 | struct edid *edid = NULL, *last_block = NULL; |
| 612 | u8 *raw_edid = NULL; |
| 613 | |
| 614 | if (!edid_ctrl || !edid_ctrl->edid) { |
| 615 | SDE_ERROR("invalid edid input\n"); |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | edid = edid_ctrl->edid; |
| 620 | |
| 621 | raw_edid = (u8 *)edid; |
| 622 | raw_edid += (edid->extensions * EDID_LENGTH); |
| 623 | last_block = (struct edid *)raw_edid; |
| 624 | |
| 625 | if (last_block) |
| 626 | return last_block->checksum; |
| 627 | |
| 628 | SDE_ERROR("Invalid block, no checksum\n"); |
| 629 | return 0; |
| 630 | } |
| 631 | |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 632 | bool sde_detect_hdmi_monitor(void *input) |
| 633 | { |
| 634 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input); |
| 635 | |
| 636 | return drm_detect_hdmi_monitor(edid_ctrl->edid); |
| 637 | } |
| 638 | |
| 639 | void sde_get_edid(struct drm_connector *connector, |
| 640 | struct i2c_adapter *adapter, void **input) |
| 641 | { |
| 642 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input); |
| 643 | |
| 644 | edid_ctrl->edid = drm_get_edid(connector, adapter); |
| 645 | SDE_EDID_DEBUG("%s +\n", __func__); |
| 646 | |
| 647 | if (!edid_ctrl->edid) |
| 648 | SDE_ERROR("EDID read failed\n"); |
| 649 | |
| 650 | if (edid_ctrl->edid) { |
| 651 | sde_edid_extract_vendor_id(edid_ctrl); |
| 652 | _sde_edid_extract_audio_data_blocks(edid_ctrl); |
| 653 | _sde_edid_extract_speaker_allocation_data(edid_ctrl); |
| 654 | } |
| 655 | SDE_EDID_DEBUG("%s -\n", __func__); |
| 656 | }; |