Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 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 | { |
| 254 | u32 offset = 0; |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame^] | 255 | u8 cmdb_len = 0; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 256 | u8 svd_len = 0; |
| 257 | const u8 *svd = NULL; |
| 258 | u32 i = 0, j = 0; |
| 259 | u32 video_format = 0; |
| 260 | |
| 261 | if (!edid_ctrl) { |
| 262 | SDE_ERROR("%s: edid_ctrl is NULL\n", __func__); |
| 263 | return; |
| 264 | } |
| 265 | |
| 266 | if (!db) { |
| 267 | SDE_ERROR("%s: invalid input\n", __func__); |
| 268 | return; |
| 269 | } |
| 270 | SDE_EDID_DEBUG("%s +\n", __func__); |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame^] | 271 | cmdb_len = db[0] & 0x1f; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 272 | |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 273 | /* Byte 3 to L+1 contain SVDs */ |
| 274 | offset += 2; |
| 275 | |
| 276 | svd = sde_edid_find_block(edid_ctrl->edid, VIDEO_DATA_BLOCK); |
| 277 | |
| 278 | if (svd) { |
| 279 | /*moving to the next byte as vic info begins there*/ |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 280 | svd_len = svd[0] & 0x1f; |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame^] | 281 | ++svd; |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | for (i = 0; i < svd_len; i++, j++) { |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame^] | 285 | video_format = *(svd + i) & 0x7F; |
| 286 | if (cmdb_len == 1) { |
| 287 | /* If cmdb_len is 1, it means all SVDs support YUV */ |
| 288 | sde_edid_set_y420_support(connector, video_format); |
| 289 | } else if (db[offset] & (1 << j)) { |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 290 | sde_edid_set_y420_support(connector, video_format); |
| 291 | |
Abhinav Kumar | 417da8f | 2017-07-14 02:13:22 -0700 | [diff] [blame^] | 292 | if (j & 0x80) { |
| 293 | j = j/8; |
| 294 | offset++; |
| 295 | if (offset >= cmdb_len) |
| 296 | break; |
| 297 | } |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | SDE_EDID_DEBUG("%s -\n", __func__); |
| 302 | |
| 303 | } |
| 304 | |
| 305 | static void sde_edid_parse_Y420VDB( |
| 306 | struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl, |
| 307 | const u8 *db) |
| 308 | { |
| 309 | u8 len = db[0] & 0x1f; |
| 310 | u32 i = 0; |
| 311 | u32 video_format = 0; |
| 312 | |
| 313 | if (!edid_ctrl) { |
| 314 | SDE_ERROR("%s: invalid input\n", __func__); |
| 315 | return; |
| 316 | } |
| 317 | |
| 318 | SDE_EDID_DEBUG("%s +\n", __func__); |
| 319 | |
| 320 | /* Offset to byte 3 */ |
| 321 | db += 2; |
| 322 | for (i = 0; i < len - 1; i++) { |
| 323 | video_format = *(db + i) & 0x7F; |
| 324 | /* |
| 325 | * mode was already added in get_modes() |
| 326 | * only need to set the Y420 support flag |
| 327 | */ |
| 328 | sde_edid_set_y420_support(connector, video_format); |
| 329 | } |
| 330 | SDE_EDID_DEBUG("%s -", __func__); |
| 331 | } |
| 332 | |
| 333 | static void sde_edid_set_mode_format( |
| 334 | struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl) |
| 335 | { |
| 336 | const u8 *db = NULL; |
| 337 | struct drm_display_mode *mode; |
| 338 | |
| 339 | SDE_EDID_DEBUG("%s +\n", __func__); |
| 340 | /* Set YUV mode support flags for YCbcr420VDB */ |
| 341 | db = sde_edid_find_extended_tag_block(edid_ctrl->edid, |
| 342 | Y420_VIDEO_DATA_BLOCK); |
| 343 | if (db) |
| 344 | sde_edid_parse_Y420VDB(connector, edid_ctrl, db); |
| 345 | else |
| 346 | SDE_EDID_DEBUG("YCbCr420 VDB is not present\n"); |
| 347 | |
| 348 | /* Set RGB supported on all modes where YUV is not set */ |
| 349 | list_for_each_entry(mode, &connector->probed_modes, head) { |
| 350 | if (!(mode->flags & DRM_MODE_FLAG_SUPPORTS_YUV)) |
| 351 | mode->flags |= DRM_MODE_FLAG_SUPPORTS_RGB; |
| 352 | } |
| 353 | |
| 354 | |
| 355 | db = sde_edid_find_extended_tag_block(edid_ctrl->edid, |
| 356 | Y420_CAPABILITY_MAP_DATA_BLOCK); |
| 357 | if (db) |
| 358 | sde_edid_parse_Y420CMDB(connector, edid_ctrl, db); |
| 359 | else |
| 360 | SDE_EDID_DEBUG("YCbCr420 CMDB is not present\n"); |
| 361 | |
| 362 | SDE_EDID_DEBUG("%s -\n", __func__); |
| 363 | } |
| 364 | |
Abhinav Kumar | cd18751 | 2017-06-30 01:02:36 -0700 | [diff] [blame] | 365 | static void _sde_edid_update_dc_modes( |
| 366 | struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl) |
| 367 | { |
| 368 | int i, start, end; |
| 369 | u8 *edid_ext, *hdmi; |
| 370 | struct drm_display_info *disp_info; |
| 371 | u32 hdmi_dc_yuv_modes = 0; |
| 372 | |
| 373 | SDE_EDID_DEBUG("%s +\n", __func__); |
| 374 | |
| 375 | if (!connector || !edid_ctrl) { |
| 376 | SDE_ERROR("invalid input\n"); |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | disp_info = &connector->display_info; |
| 381 | |
| 382 | edid_ext = sde_find_cea_extension(edid_ctrl->edid); |
| 383 | |
| 384 | if (!edid_ext) { |
| 385 | SDE_ERROR("no cea extension\n"); |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | if (sde_cea_db_offsets(edid_ext, &start, &end)) |
| 390 | return; |
| 391 | |
| 392 | sde_for_each_cea_db(edid_ext, i, start, end) { |
| 393 | if (sde_cea_db_is_hdmi_hf_vsdb(&edid_ext[i])) { |
| 394 | |
| 395 | hdmi = &edid_ext[i]; |
| 396 | |
| 397 | if (sde_cea_db_payload_len(hdmi) < 7) |
| 398 | continue; |
| 399 | |
| 400 | if (hdmi[7] & DRM_EDID_YCBCR420_DC_30) { |
| 401 | hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_30; |
| 402 | SDE_EDID_DEBUG("Y420 30-bit supported\n"); |
| 403 | } |
| 404 | |
| 405 | if (hdmi[7] & DRM_EDID_YCBCR420_DC_36) { |
| 406 | hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_36; |
| 407 | SDE_EDID_DEBUG("Y420 36-bit supported\n"); |
| 408 | } |
| 409 | |
| 410 | if (hdmi[7] & DRM_EDID_YCBCR420_DC_48) { |
| 411 | hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_36; |
| 412 | SDE_EDID_DEBUG("Y420 48-bit supported\n"); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | disp_info->edid_hdmi_dc_modes |= hdmi_dc_yuv_modes; |
| 418 | |
| 419 | SDE_EDID_DEBUG("%s -\n", __func__); |
| 420 | } |
| 421 | |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 422 | static void _sde_edid_extract_audio_data_blocks( |
| 423 | struct sde_edid_ctrl *edid_ctrl) |
| 424 | { |
| 425 | u8 len = 0; |
| 426 | u8 adb_max = 0; |
| 427 | const u8 *adb = NULL; |
| 428 | u32 offset = DBC_START_OFFSET; |
| 429 | u8 *cea = NULL; |
| 430 | |
| 431 | if (!edid_ctrl) { |
| 432 | SDE_ERROR("invalid edid_ctrl\n"); |
| 433 | return; |
| 434 | } |
| 435 | SDE_EDID_DEBUG("%s +", __func__); |
| 436 | cea = sde_find_cea_extension(edid_ctrl->edid); |
| 437 | if (!cea) { |
| 438 | SDE_DEBUG("CEA extension not found\n"); |
| 439 | return; |
| 440 | } |
| 441 | |
| 442 | edid_ctrl->adb_size = 0; |
| 443 | |
| 444 | memset(edid_ctrl->audio_data_block, 0, |
| 445 | sizeof(edid_ctrl->audio_data_block)); |
| 446 | |
| 447 | do { |
| 448 | len = 0; |
| 449 | adb = _sde_edid_find_block(cea, offset, AUDIO_DATA_BLOCK, |
| 450 | &len); |
| 451 | |
| 452 | if ((adb == NULL) || (len > MAX_AUDIO_DATA_BLOCK_SIZE || |
| 453 | adb_max >= MAX_NUMBER_ADB)) { |
| 454 | if (!edid_ctrl->adb_size) { |
| 455 | SDE_DEBUG("No/Invalid Audio Data Block\n"); |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | continue; |
| 460 | } |
| 461 | |
| 462 | memcpy(edid_ctrl->audio_data_block + edid_ctrl->adb_size, |
| 463 | adb + 1, len); |
| 464 | offset = (adb - cea) + 1 + len; |
| 465 | |
| 466 | edid_ctrl->adb_size += len; |
| 467 | adb_max++; |
| 468 | } while (adb); |
| 469 | SDE_EDID_DEBUG("%s -", __func__); |
| 470 | } |
| 471 | |
| 472 | static void _sde_edid_extract_speaker_allocation_data( |
| 473 | struct sde_edid_ctrl *edid_ctrl) |
| 474 | { |
| 475 | u8 len; |
| 476 | const u8 *sadb = NULL; |
| 477 | u8 *cea = NULL; |
| 478 | |
| 479 | if (!edid_ctrl) { |
| 480 | SDE_ERROR("invalid edid_ctrl\n"); |
| 481 | return; |
| 482 | } |
| 483 | SDE_EDID_DEBUG("%s +", __func__); |
| 484 | cea = sde_find_cea_extension(edid_ctrl->edid); |
| 485 | if (!cea) { |
| 486 | SDE_DEBUG("CEA extension not found\n"); |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | sadb = _sde_edid_find_block(cea, DBC_START_OFFSET, |
| 491 | SPEAKER_ALLOCATION_DATA_BLOCK, &len); |
| 492 | if ((sadb == NULL) || (len != MAX_SPKR_ALLOC_DATA_BLOCK_SIZE)) { |
| 493 | SDE_DEBUG("No/Invalid Speaker Allocation Data Block\n"); |
| 494 | return; |
| 495 | } |
| 496 | |
| 497 | memcpy(edid_ctrl->spkr_alloc_data_block, sadb + 1, len); |
| 498 | edid_ctrl->sadb_size = len; |
| 499 | |
| 500 | SDE_EDID_DEBUG("speaker alloc data SP byte = %08x %s%s%s%s%s%s%s\n", |
| 501 | sadb[1], |
| 502 | (sadb[1] & BIT(0)) ? "FL/FR," : "", |
| 503 | (sadb[1] & BIT(1)) ? "LFE," : "", |
| 504 | (sadb[1] & BIT(2)) ? "FC," : "", |
| 505 | (sadb[1] & BIT(3)) ? "RL/RR," : "", |
| 506 | (sadb[1] & BIT(4)) ? "RC," : "", |
| 507 | (sadb[1] & BIT(5)) ? "FLC/FRC," : "", |
| 508 | (sadb[1] & BIT(6)) ? "RLC/RRC," : ""); |
| 509 | SDE_EDID_DEBUG("%s -", __func__); |
| 510 | } |
| 511 | |
| 512 | struct sde_edid_ctrl *sde_edid_init(void) |
| 513 | { |
| 514 | struct sde_edid_ctrl *edid_ctrl = NULL; |
| 515 | |
| 516 | SDE_EDID_DEBUG("%s +\n", __func__); |
| 517 | edid_ctrl = kzalloc(sizeof(*edid_ctrl), GFP_KERNEL); |
| 518 | if (!edid_ctrl) { |
| 519 | SDE_ERROR("edid_ctrl alloc failed\n"); |
| 520 | return NULL; |
| 521 | } |
| 522 | memset((edid_ctrl), 0, sizeof(*edid_ctrl)); |
| 523 | SDE_EDID_DEBUG("%s -\n", __func__); |
| 524 | return edid_ctrl; |
| 525 | } |
| 526 | |
| 527 | void sde_free_edid(void **input) |
| 528 | { |
| 529 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input); |
| 530 | |
| 531 | SDE_EDID_DEBUG("%s +", __func__); |
| 532 | kfree(edid_ctrl->edid); |
| 533 | edid_ctrl->edid = NULL; |
| 534 | } |
| 535 | |
| 536 | void sde_edid_deinit(void **input) |
| 537 | { |
| 538 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input); |
| 539 | |
| 540 | SDE_EDID_DEBUG("%s +", __func__); |
| 541 | sde_free_edid((void *)&edid_ctrl); |
| 542 | kfree(edid_ctrl); |
| 543 | SDE_EDID_DEBUG("%s -", __func__); |
| 544 | } |
| 545 | |
| 546 | int _sde_edid_update_modes(struct drm_connector *connector, |
| 547 | void *input) |
| 548 | { |
| 549 | int rc = 0; |
| 550 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input); |
| 551 | |
| 552 | SDE_EDID_DEBUG("%s +", __func__); |
| 553 | if (edid_ctrl->edid) { |
| 554 | drm_mode_connector_update_edid_property(connector, |
| 555 | edid_ctrl->edid); |
| 556 | |
| 557 | rc = drm_add_edid_modes(connector, edid_ctrl->edid); |
| 558 | sde_edid_set_mode_format(connector, edid_ctrl); |
Abhinav Kumar | cd18751 | 2017-06-30 01:02:36 -0700 | [diff] [blame] | 559 | _sde_edid_update_dc_modes(connector, edid_ctrl); |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 560 | SDE_EDID_DEBUG("%s -", __func__); |
| 561 | return rc; |
| 562 | } |
| 563 | |
| 564 | drm_mode_connector_update_edid_property(connector, NULL); |
| 565 | SDE_EDID_DEBUG("%s null edid -", __func__); |
| 566 | return rc; |
| 567 | } |
| 568 | |
Padmanabhan Komanduru | d5eae9d | 2017-06-22 19:23:36 +0530 | [diff] [blame] | 569 | u32 sde_get_sink_bpc(void *input) |
| 570 | { |
| 571 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input); |
| 572 | struct edid *edid = edid_ctrl->edid; |
| 573 | |
| 574 | if ((edid->revision < 3) || !(edid->input & DRM_EDID_INPUT_DIGITAL)) |
| 575 | return 0; |
| 576 | |
| 577 | if (edid->revision < 4) { |
| 578 | if (edid->input & DRM_EDID_DIGITAL_TYPE_DVI) |
| 579 | return 8; |
| 580 | else |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) { |
| 585 | case DRM_EDID_DIGITAL_DEPTH_6: |
| 586 | return 6; |
| 587 | case DRM_EDID_DIGITAL_DEPTH_8: |
| 588 | return 8; |
| 589 | case DRM_EDID_DIGITAL_DEPTH_10: |
| 590 | return 10; |
| 591 | case DRM_EDID_DIGITAL_DEPTH_12: |
| 592 | return 12; |
| 593 | case DRM_EDID_DIGITAL_DEPTH_14: |
| 594 | return 14; |
| 595 | case DRM_EDID_DIGITAL_DEPTH_16: |
| 596 | return 16; |
| 597 | case DRM_EDID_DIGITAL_DEPTH_UNDEF: |
| 598 | default: |
| 599 | return 0; |
| 600 | } |
| 601 | } |
| 602 | |
Padmanabhan Komanduru | cc9a1851 | 2017-05-03 13:59:02 -0700 | [diff] [blame] | 603 | bool sde_detect_hdmi_monitor(void *input) |
| 604 | { |
| 605 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input); |
| 606 | |
| 607 | return drm_detect_hdmi_monitor(edid_ctrl->edid); |
| 608 | } |
| 609 | |
| 610 | void sde_get_edid(struct drm_connector *connector, |
| 611 | struct i2c_adapter *adapter, void **input) |
| 612 | { |
| 613 | struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input); |
| 614 | |
| 615 | edid_ctrl->edid = drm_get_edid(connector, adapter); |
| 616 | SDE_EDID_DEBUG("%s +\n", __func__); |
| 617 | |
| 618 | if (!edid_ctrl->edid) |
| 619 | SDE_ERROR("EDID read failed\n"); |
| 620 | |
| 621 | if (edid_ctrl->edid) { |
| 622 | sde_edid_extract_vendor_id(edid_ctrl); |
| 623 | _sde_edid_extract_audio_data_blocks(edid_ctrl); |
| 624 | _sde_edid_extract_speaker_allocation_data(edid_ctrl); |
| 625 | } |
| 626 | SDE_EDID_DEBUG("%s -\n", __func__); |
| 627 | }; |