sde_edid_parser.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <drm/drm_edid.h>
  6. #include <linux/hdmi.h>
  7. #include "sde_kms.h"
  8. #include "sde_edid_parser.h"
  9. #include "sde/sde_connector.h"
  10. #define DBC_START_OFFSET 4
  11. #define EDID_DTD_LEN 18
  12. enum data_block_types {
  13. RESERVED,
  14. AUDIO_DATA_BLOCK,
  15. VIDEO_DATA_BLOCK,
  16. VENDOR_SPECIFIC_DATA_BLOCK,
  17. SPEAKER_ALLOCATION_DATA_BLOCK,
  18. VESA_DTC_DATA_BLOCK,
  19. RESERVED2,
  20. USE_EXTENDED_TAG
  21. };
  22. static u8 *sde_find_edid_extension(struct edid *edid, int ext_id)
  23. {
  24. u8 *edid_ext = NULL;
  25. int i;
  26. /* No EDID or EDID extensions */
  27. if (edid == NULL || edid->extensions == 0)
  28. return NULL;
  29. /* Find CEA extension */
  30. for (i = 0; i < edid->extensions; i++) {
  31. edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
  32. if (edid_ext[0] == ext_id)
  33. break;
  34. }
  35. if (i == edid->extensions)
  36. return NULL;
  37. return edid_ext;
  38. }
  39. static u8 *sde_find_cea_extension(struct edid *edid)
  40. {
  41. return sde_find_edid_extension(edid, SDE_CEA_EXT);
  42. }
  43. static int
  44. sde_cea_db_payload_len(const u8 *db)
  45. {
  46. return db[0] & 0x1f;
  47. }
  48. static int
  49. sde_cea_db_tag(const u8 *db)
  50. {
  51. return db[0] >> 5;
  52. }
  53. static int
  54. sde_cea_revision(const u8 *cea)
  55. {
  56. return cea[1];
  57. }
  58. static int
  59. sde_cea_db_offsets(const u8 *cea, int *start, int *end)
  60. {
  61. /* Data block offset in CEA extension block */
  62. *start = 4;
  63. *end = cea[2];
  64. if (*end == 0)
  65. *end = 127;
  66. if (*end < 4 || *end > 127)
  67. return -ERANGE;
  68. return 0;
  69. }
  70. #define sde_for_each_cea_db(cea, i, start, end) \
  71. for ((i) = (start); \
  72. (i) < (end) && (i) + sde_cea_db_payload_len(&(cea)[(i)]) < (end); \
  73. (i) += sde_cea_db_payload_len(&(cea)[(i)]) + 1)
  74. static bool sde_cea_db_is_hdmi_hf_vsdb(const u8 *db)
  75. {
  76. int hdmi_id;
  77. if (sde_cea_db_tag(db) != VENDOR_SPECIFIC_DATA_BLOCK)
  78. return false;
  79. if (sde_cea_db_payload_len(db) < 7)
  80. return false;
  81. hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
  82. return hdmi_id == HDMI_FORUM_IEEE_OUI;
  83. }
  84. static u8 *sde_edid_find_extended_tag_block(struct edid *edid, int blk_id)
  85. {
  86. u8 *db = NULL;
  87. u8 *cea = NULL;
  88. if (!edid) {
  89. SDE_ERROR("%s: invalid input\n", __func__);
  90. return NULL;
  91. }
  92. cea = sde_find_cea_extension(edid);
  93. if (cea && sde_cea_revision(cea) >= 3) {
  94. int i, start, end;
  95. if (sde_cea_db_offsets(cea, &start, &end))
  96. return NULL;
  97. sde_for_each_cea_db(cea, i, start, end) {
  98. db = &cea[i];
  99. if ((sde_cea_db_tag(db) == SDE_EXTENDED_TAG) &&
  100. (db[1] == blk_id))
  101. return db;
  102. }
  103. }
  104. return NULL;
  105. }
  106. static u8 *
  107. sde_edid_find_block(struct edid *edid, int blk_id)
  108. {
  109. u8 *db = NULL;
  110. u8 *cea = NULL;
  111. if (!edid) {
  112. SDE_ERROR("%s: invalid input\n", __func__);
  113. return NULL;
  114. }
  115. cea = sde_find_cea_extension(edid);
  116. if (cea && sde_cea_revision(cea) >= 3) {
  117. int i, start, end;
  118. if (sde_cea_db_offsets(cea, &start, &end))
  119. return NULL;
  120. sde_for_each_cea_db(cea, i, start, end) {
  121. db = &cea[i];
  122. if (sde_cea_db_tag(db) == blk_id)
  123. return db;
  124. }
  125. }
  126. return NULL;
  127. }
  128. static const u8 *_sde_edid_find_block(const u8 *in_buf, u32 start_offset,
  129. u8 type, u8 *len)
  130. {
  131. /* the start of data block collection, start of Video Data Block */
  132. u32 offset = start_offset;
  133. u32 dbc_offset = in_buf[2];
  134. SDE_EDID_DEBUG("%s +", __func__);
  135. /*
  136. * * edid buffer 1, byte 2 being 4 means no non-DTD/Data block
  137. * collection present.
  138. * * edid buffer 1, byte 2 being 0 means no non-DTD/DATA block
  139. * collection present and no DTD data present.
  140. */
  141. if ((dbc_offset == 0) || (dbc_offset == 4)) {
  142. SDE_EDID_DEBUG("EDID: no DTD or non-DTD data present\n");
  143. return NULL;
  144. }
  145. while (offset < dbc_offset) {
  146. u8 block_len = in_buf[offset] & 0x1F;
  147. if ((offset + block_len <= dbc_offset) &&
  148. (in_buf[offset] >> 5) == type) {
  149. *len = block_len;
  150. SDE_EDID_DEBUG("block=%d found @ 0x%x w/ len=%d\n",
  151. type, offset, block_len);
  152. return in_buf + offset;
  153. }
  154. offset += 1 + block_len;
  155. }
  156. return NULL;
  157. }
  158. static void sde_edid_extract_vendor_id(struct sde_edid_ctrl *edid_ctrl)
  159. {
  160. char *vendor_id;
  161. u32 id_codes;
  162. SDE_EDID_DEBUG("%s +", __func__);
  163. if (!edid_ctrl) {
  164. SDE_ERROR("%s: invalid input\n", __func__);
  165. return;
  166. }
  167. vendor_id = edid_ctrl->vendor_id;
  168. id_codes = ((u32)edid_ctrl->edid->mfg_id[0] << 8) +
  169. edid_ctrl->edid->mfg_id[1];
  170. vendor_id[0] = 'A' - 1 + ((id_codes >> 10) & 0x1F);
  171. vendor_id[1] = 'A' - 1 + ((id_codes >> 5) & 0x1F);
  172. vendor_id[2] = 'A' - 1 + (id_codes & 0x1F);
  173. vendor_id[3] = 0;
  174. SDE_EDID_DEBUG("vendor id is %s ", vendor_id);
  175. SDE_EDID_DEBUG("%s -", __func__);
  176. }
  177. static void sde_edid_set_y420_support(struct drm_connector *connector,
  178. u32 video_format)
  179. {
  180. u8 cea_mode = 0;
  181. struct drm_display_mode *mode;
  182. u32 mode_fmt_flags = 0;
  183. /* Need to add Y420 support flag to the modes */
  184. list_for_each_entry(mode, &connector->probed_modes, head) {
  185. /* Cache the format flags before clearing */
  186. mode_fmt_flags = mode->flags;
  187. /* Clear the RGB/YUV format flags before calling upstream API */
  188. mode->flags &= ~SDE_DRM_MODE_FLAG_FMT_MASK;
  189. cea_mode = drm_match_cea_mode(mode);
  190. /* Restore the format flags */
  191. mode->flags = mode_fmt_flags;
  192. if ((cea_mode != 0) && (cea_mode == video_format)) {
  193. SDE_EDID_DEBUG("%s found match for %d ", __func__,
  194. video_format);
  195. mode->flags |= DRM_MODE_FLAG_SUPPORTS_YUV;
  196. }
  197. }
  198. }
  199. static void sde_edid_parse_Y420CMDB(
  200. struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl,
  201. const u8 *db)
  202. {
  203. u32 offset = 0;
  204. u8 cmdb_len = 0;
  205. u8 svd_len = 0;
  206. const u8 *svd = NULL;
  207. u32 i = 0, j = 0;
  208. u32 video_format = 0;
  209. if (!edid_ctrl) {
  210. SDE_ERROR("%s: edid_ctrl is NULL\n", __func__);
  211. return;
  212. }
  213. if (!db) {
  214. SDE_ERROR("%s: invalid input\n", __func__);
  215. return;
  216. }
  217. SDE_EDID_DEBUG("%s +\n", __func__);
  218. cmdb_len = db[0] & 0x1f;
  219. /* Byte 3 to L+1 contain SVDs */
  220. offset += 2;
  221. svd = sde_edid_find_block(edid_ctrl->edid, VIDEO_DATA_BLOCK);
  222. if (svd) {
  223. /*moving to the next byte as vic info begins there*/
  224. svd_len = svd[0] & 0x1f;
  225. ++svd;
  226. }
  227. for (i = 0; i < svd_len; i++, j++) {
  228. video_format = *(svd + i) & 0x7F;
  229. if (cmdb_len == 1) {
  230. /* If cmdb_len is 1, it means all SVDs support YUV */
  231. sde_edid_set_y420_support(connector, video_format);
  232. } else if (db[offset] & (1 << j)) {
  233. sde_edid_set_y420_support(connector, video_format);
  234. if (j & 0x80) {
  235. j = j/8;
  236. offset++;
  237. if (offset >= cmdb_len)
  238. break;
  239. }
  240. }
  241. }
  242. SDE_EDID_DEBUG("%s -\n", __func__);
  243. }
  244. static void sde_edid_parse_Y420VDB(
  245. struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl,
  246. const u8 *db)
  247. {
  248. u8 len = db[0] & 0x1f;
  249. u32 i = 0;
  250. u32 video_format = 0;
  251. if (!edid_ctrl) {
  252. SDE_ERROR("%s: invalid input\n", __func__);
  253. return;
  254. }
  255. SDE_EDID_DEBUG("%s +\n", __func__);
  256. /* Offset to byte 3 */
  257. db += 2;
  258. for (i = 0; i < len - 1; i++) {
  259. video_format = *(db + i) & 0x7F;
  260. /*
  261. * mode was already added in get_modes()
  262. * only need to set the Y420 support flag
  263. */
  264. sde_edid_set_y420_support(connector, video_format);
  265. }
  266. SDE_EDID_DEBUG("%s -", __func__);
  267. }
  268. static void sde_edid_set_mode_format(
  269. struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl)
  270. {
  271. const u8 *db = NULL;
  272. struct drm_display_mode *mode;
  273. SDE_EDID_DEBUG("%s +\n", __func__);
  274. /* Set YUV mode support flags for YCbcr420VDB */
  275. db = sde_edid_find_extended_tag_block(edid_ctrl->edid,
  276. Y420_VIDEO_DATA_BLOCK);
  277. if (db)
  278. sde_edid_parse_Y420VDB(connector, edid_ctrl, db);
  279. else
  280. SDE_EDID_DEBUG("YCbCr420 VDB is not present\n");
  281. /* Set RGB supported on all modes where YUV is not set */
  282. list_for_each_entry(mode, &connector->probed_modes, head) {
  283. if (!(mode->flags & DRM_MODE_FLAG_SUPPORTS_YUV))
  284. mode->flags |= DRM_MODE_FLAG_SUPPORTS_RGB;
  285. }
  286. db = sde_edid_find_extended_tag_block(edid_ctrl->edid,
  287. Y420_CAPABILITY_MAP_DATA_BLOCK);
  288. if (db)
  289. sde_edid_parse_Y420CMDB(connector, edid_ctrl, db);
  290. else
  291. SDE_EDID_DEBUG("YCbCr420 CMDB is not present\n");
  292. SDE_EDID_DEBUG("%s -\n", __func__);
  293. }
  294. static void _sde_edid_update_dc_modes(
  295. struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl)
  296. {
  297. int i, start, end;
  298. u8 *edid_ext, *hdmi;
  299. struct drm_display_info *disp_info;
  300. u32 hdmi_dc_yuv_modes = 0;
  301. SDE_EDID_DEBUG("%s +\n", __func__);
  302. if (!connector || !edid_ctrl) {
  303. SDE_ERROR("invalid input\n");
  304. return;
  305. }
  306. disp_info = &connector->display_info;
  307. edid_ext = sde_find_cea_extension(edid_ctrl->edid);
  308. if (!edid_ext) {
  309. SDE_DEBUG("no cea extension\n");
  310. return;
  311. }
  312. if (sde_cea_db_offsets(edid_ext, &start, &end))
  313. return;
  314. sde_for_each_cea_db(edid_ext, i, start, end) {
  315. if (sde_cea_db_is_hdmi_hf_vsdb(&edid_ext[i])) {
  316. hdmi = &edid_ext[i];
  317. if (sde_cea_db_payload_len(hdmi) < 7)
  318. continue;
  319. if (hdmi[7] & DRM_EDID_YCBCR420_DC_30) {
  320. hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_30;
  321. SDE_EDID_DEBUG("Y420 30-bit supported\n");
  322. }
  323. if (hdmi[7] & DRM_EDID_YCBCR420_DC_36) {
  324. hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_36;
  325. SDE_EDID_DEBUG("Y420 36-bit supported\n");
  326. }
  327. if (hdmi[7] & DRM_EDID_YCBCR420_DC_48) {
  328. hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_36;
  329. SDE_EDID_DEBUG("Y420 48-bit supported\n");
  330. }
  331. }
  332. }
  333. disp_info->edid_hdmi_dc_modes |= hdmi_dc_yuv_modes;
  334. SDE_EDID_DEBUG("%s -\n", __func__);
  335. }
  336. static void _sde_edid_extract_audio_data_blocks(
  337. struct sde_edid_ctrl *edid_ctrl)
  338. {
  339. u8 len = 0;
  340. u8 adb_max = 0;
  341. const u8 *adb = NULL;
  342. u32 offset = DBC_START_OFFSET;
  343. u8 *cea = NULL;
  344. if (!edid_ctrl) {
  345. SDE_ERROR("invalid edid_ctrl\n");
  346. return;
  347. }
  348. SDE_EDID_DEBUG("%s +", __func__);
  349. cea = sde_find_cea_extension(edid_ctrl->edid);
  350. if (!cea) {
  351. SDE_DEBUG("CEA extension not found\n");
  352. return;
  353. }
  354. edid_ctrl->adb_size = 0;
  355. memset(edid_ctrl->audio_data_block, 0,
  356. sizeof(edid_ctrl->audio_data_block));
  357. do {
  358. len = 0;
  359. adb = _sde_edid_find_block(cea, offset, AUDIO_DATA_BLOCK,
  360. &len);
  361. if ((adb == NULL) || (len > MAX_AUDIO_DATA_BLOCK_SIZE ||
  362. adb_max >= MAX_NUMBER_ADB)) {
  363. if (!edid_ctrl->adb_size) {
  364. SDE_DEBUG("No/Invalid Audio Data Block\n");
  365. return;
  366. }
  367. continue;
  368. }
  369. memcpy(edid_ctrl->audio_data_block + edid_ctrl->adb_size,
  370. adb + 1, len);
  371. offset = (adb - cea) + 1 + len;
  372. edid_ctrl->adb_size += len;
  373. adb_max++;
  374. } while (adb);
  375. SDE_EDID_DEBUG("%s -", __func__);
  376. }
  377. static void sde_edid_parse_hdr_plus_info(struct drm_connector *connector,
  378. const u8 *db)
  379. {
  380. struct sde_connector *c_conn;
  381. c_conn = to_sde_connector(connector);
  382. c_conn->hdr_plus_app_ver = db[5] & VSVDB_HDR10_PLUS_APP_VER_MASK;
  383. }
  384. static void sde_edid_parse_vsvdb_info(struct drm_connector *connector,
  385. const u8 *db)
  386. {
  387. u8 db_len = 0;
  388. u32 ieee_code = 0;
  389. SDE_EDID_DEBUG("%s +\n", __func__);
  390. db_len = sde_cea_db_payload_len(db);
  391. if (db_len < 5)
  392. return;
  393. /* Bytes 2-4: IEEE 24-bit code, LSB first */
  394. ieee_code = db[2] | (db[3] << 8) | (db[4] << 16);
  395. if (ieee_code == VSVDB_HDR10_PLUS_IEEE_CODE)
  396. sde_edid_parse_hdr_plus_info(connector, db);
  397. SDE_EDID_DEBUG("%s -\n", __func__);
  398. }
  399. static bool sde_edid_is_luminance_value_present(u32 block_length,
  400. enum luminance_value value)
  401. {
  402. return block_length > NO_LUMINANCE_DATA && value <= block_length;
  403. }
  404. /*
  405. * sde_edid_parse_hdr_db - Parse the HDR extended block
  406. * @connector: connector for the external sink
  407. * @db: start of the HDR extended block
  408. *
  409. * Parses the HDR extended block to extract sink info for @connector.
  410. */
  411. static void
  412. sde_edid_parse_hdr_db(struct drm_connector *connector, const u8 *db)
  413. {
  414. u8 len = 0;
  415. struct sde_connector *c_conn;
  416. c_conn = to_sde_connector(connector);
  417. if (!db)
  418. return;
  419. len = db[0] & 0x1f;
  420. /* Byte 3: Electro-Optical Transfer Functions */
  421. c_conn->hdr_eotf = db[2] & 0x3F;
  422. /* Byte 4: Static Metadata Descriptor Type 1 */
  423. c_conn->hdr_metadata_type_one = (db[3] & BIT(0));
  424. /* Byte 5: Desired Content Maximum Luminance */
  425. if (sde_edid_is_luminance_value_present(len, MAXIMUM_LUMINANCE))
  426. c_conn->hdr_max_luminance = db[MAXIMUM_LUMINANCE];
  427. /* Byte 6: Desired Content Max Frame-average Luminance */
  428. if (sde_edid_is_luminance_value_present(len, FRAME_AVERAGE_LUMINANCE))
  429. c_conn->hdr_avg_luminance = db[FRAME_AVERAGE_LUMINANCE];
  430. /* Byte 7: Desired Content Min Luminance */
  431. if (sde_edid_is_luminance_value_present(len, MINIMUM_LUMINANCE))
  432. c_conn->hdr_min_luminance = db[MINIMUM_LUMINANCE];
  433. c_conn->hdr_supported = true;
  434. SDE_EDID_DEBUG("HDR electro-optical %d\n", c_conn->hdr_eotf);
  435. SDE_EDID_DEBUG("metadata desc 1 %d\n", c_conn->hdr_metadata_type_one);
  436. SDE_EDID_DEBUG("max luminance %d\n", c_conn->hdr_max_luminance);
  437. SDE_EDID_DEBUG("avg luminance %d\n", c_conn->hdr_avg_luminance);
  438. SDE_EDID_DEBUG("min luminance %d\n", c_conn->hdr_min_luminance);
  439. }
  440. /*
  441. * drm_extract_clrmetry_db - Parse the HDMI colorimetry extended block
  442. * @connector: connector corresponding to the HDMI sink
  443. * @db: start of the HDMI colorimetry extended block
  444. *
  445. * Parses the HDMI colorimetry block to extract sink info for @connector.
  446. */
  447. static void
  448. sde_parse_clrmetry_db(struct drm_connector *connector, const u8 *db)
  449. {
  450. struct sde_connector *c_conn;
  451. c_conn = to_sde_connector(connector);
  452. if (!db) {
  453. DRM_ERROR("invalid db\n");
  454. return;
  455. }
  456. /* Byte 3 Bit 0: xvYCC_601 */
  457. if (db[2] & BIT(0))
  458. c_conn->color_enc_fmt |= DRM_EDID_CLRMETRY_xvYCC_601;
  459. /* Byte 3 Bit 1: xvYCC_709 */
  460. if (db[2] & BIT(1))
  461. c_conn->color_enc_fmt |= DRM_EDID_CLRMETRY_xvYCC_709;
  462. /* Byte 3 Bit 2: sYCC_601 */
  463. if (db[2] & BIT(2))
  464. c_conn->color_enc_fmt |= DRM_EDID_CLRMETRY_sYCC_601;
  465. /* Byte 3 Bit 3: ADOBE_YCC_601 */
  466. if (db[2] & BIT(3))
  467. c_conn->color_enc_fmt |= DRM_EDID_CLRMETRY_ADOBE_YCC_601;
  468. /* Byte 3 Bit 4: ADOBE_RGB */
  469. if (db[2] & BIT(4))
  470. c_conn->color_enc_fmt |= DRM_EDID_CLRMETRY_ADOBE_RGB;
  471. /* Byte 3 Bit 5: BT2020_CYCC */
  472. if (db[2] & BIT(5))
  473. c_conn->color_enc_fmt |= DRM_EDID_CLRMETRY_BT2020_CYCC;
  474. /* Byte 3 Bit 6: BT2020_YCC */
  475. if (db[2] & BIT(6))
  476. c_conn->color_enc_fmt |= DRM_EDID_CLRMETRY_BT2020_YCC;
  477. /* Byte 3 Bit 7: BT2020_RGB */
  478. if (db[2] & BIT(7))
  479. c_conn->color_enc_fmt |= DRM_EDID_CLRMETRY_BT2020_RGB;
  480. /* Byte 4 Bit 7: DCI-P3 */
  481. if (db[3] & BIT(7))
  482. c_conn->color_enc_fmt |= DRM_EDID_CLRMETRY_DCI_P3;
  483. DRM_DEBUG_KMS("colorimetry fmts = 0x%x\n", c_conn->color_enc_fmt);
  484. }
  485. /*
  486. * sde_edid_parse_extended_blk_info - Parse the HDMI extended tag blocks
  487. * @connector: connector corresponding to external sink
  488. * @edid: handle to the EDID structure
  489. * Parses the all extended tag blocks extract sink info for @connector.
  490. */
  491. static void
  492. sde_edid_parse_extended_blk_info(struct drm_connector *connector,
  493. struct edid *edid)
  494. {
  495. const u8 *cea = sde_find_cea_extension(edid);
  496. const u8 *db = NULL;
  497. if (cea && sde_cea_revision(cea) >= 3) {
  498. int i, start, end;
  499. if (sde_cea_db_offsets(cea, &start, &end))
  500. return;
  501. sde_for_each_cea_db(cea, i, start, end) {
  502. db = &cea[i];
  503. if (sde_cea_db_tag(db) == USE_EXTENDED_TAG) {
  504. SDE_EDID_DEBUG("found ext tag block = %d\n",
  505. db[1]);
  506. switch (db[1]) {
  507. case VENDOR_SPECIFIC_VIDEO_DATA_BLOCK:
  508. sde_edid_parse_vsvdb_info(connector,
  509. db);
  510. break;
  511. case HDR_STATIC_METADATA_DATA_BLOCK:
  512. sde_edid_parse_hdr_db(connector, db);
  513. break;
  514. case COLORIMETRY_EXTENDED_DATA_BLOCK:
  515. sde_parse_clrmetry_db(connector, db);
  516. default:
  517. break;
  518. }
  519. }
  520. }
  521. }
  522. }
  523. static void _sde_edid_extract_speaker_allocation_data(
  524. struct sde_edid_ctrl *edid_ctrl)
  525. {
  526. u8 len;
  527. const u8 *sadb = NULL;
  528. u8 *cea = NULL;
  529. if (!edid_ctrl) {
  530. SDE_ERROR("invalid edid_ctrl\n");
  531. return;
  532. }
  533. SDE_EDID_DEBUG("%s +", __func__);
  534. cea = sde_find_cea_extension(edid_ctrl->edid);
  535. if (!cea) {
  536. SDE_DEBUG("CEA extension not found\n");
  537. return;
  538. }
  539. sadb = _sde_edid_find_block(cea, DBC_START_OFFSET,
  540. SPEAKER_ALLOCATION_DATA_BLOCK, &len);
  541. if ((sadb == NULL) || (len != MAX_SPKR_ALLOC_DATA_BLOCK_SIZE)) {
  542. SDE_DEBUG("No/Invalid Speaker Allocation Data Block\n");
  543. return;
  544. }
  545. memcpy(edid_ctrl->spkr_alloc_data_block, sadb + 1, len);
  546. edid_ctrl->sadb_size = len;
  547. SDE_EDID_DEBUG("speaker alloc data SP byte = %08x %s%s%s%s%s%s%s\n",
  548. sadb[1],
  549. (sadb[1] & BIT(0)) ? "FL/FR," : "",
  550. (sadb[1] & BIT(1)) ? "LFE," : "",
  551. (sadb[1] & BIT(2)) ? "FC," : "",
  552. (sadb[1] & BIT(3)) ? "RL/RR," : "",
  553. (sadb[1] & BIT(4)) ? "RC," : "",
  554. (sadb[1] & BIT(5)) ? "FLC/FRC," : "",
  555. (sadb[1] & BIT(6)) ? "RLC/RRC," : "");
  556. SDE_EDID_DEBUG("%s -", __func__);
  557. }
  558. struct sde_edid_ctrl *sde_edid_init(void)
  559. {
  560. struct sde_edid_ctrl *edid_ctrl = NULL;
  561. SDE_EDID_DEBUG("%s +\n", __func__);
  562. edid_ctrl = kzalloc(sizeof(*edid_ctrl), GFP_KERNEL);
  563. if (!edid_ctrl) {
  564. SDE_ERROR("edid_ctrl alloc failed\n");
  565. return NULL;
  566. }
  567. memset((edid_ctrl), 0, sizeof(*edid_ctrl));
  568. SDE_EDID_DEBUG("%s -\n", __func__);
  569. return edid_ctrl;
  570. }
  571. void sde_free_edid(void **input)
  572. {
  573. struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input);
  574. SDE_EDID_DEBUG("%s +", __func__);
  575. kfree(edid_ctrl->edid);
  576. edid_ctrl->edid = NULL;
  577. }
  578. void sde_edid_deinit(void **input)
  579. {
  580. struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input);
  581. SDE_EDID_DEBUG("%s +", __func__);
  582. sde_free_edid((void *)&edid_ctrl);
  583. kfree(edid_ctrl);
  584. SDE_EDID_DEBUG("%s -", __func__);
  585. }
  586. int _sde_edid_update_modes(struct drm_connector *connector,
  587. void *input)
  588. {
  589. int rc = 0;
  590. struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input);
  591. SDE_EDID_DEBUG("%s +", __func__);
  592. if (edid_ctrl->edid) {
  593. drm_connector_update_edid_property(connector,
  594. edid_ctrl->edid);
  595. rc = drm_add_edid_modes(connector, edid_ctrl->edid);
  596. sde_edid_set_mode_format(connector, edid_ctrl);
  597. _sde_edid_update_dc_modes(connector, edid_ctrl);
  598. sde_edid_parse_extended_blk_info(connector,
  599. edid_ctrl->edid);
  600. SDE_EDID_DEBUG("%s -", __func__);
  601. return rc;
  602. }
  603. drm_connector_update_edid_property(connector, NULL);
  604. SDE_EDID_DEBUG("%s null edid -", __func__);
  605. return rc;
  606. }
  607. u8 sde_get_edid_checksum(void *input)
  608. {
  609. struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input);
  610. struct edid *edid = NULL, *last_block = NULL;
  611. u8 *raw_edid = NULL;
  612. if (!edid_ctrl || !edid_ctrl->edid) {
  613. SDE_ERROR("invalid edid input\n");
  614. return 0;
  615. }
  616. edid = edid_ctrl->edid;
  617. raw_edid = (u8 *)edid;
  618. raw_edid += (edid->extensions * EDID_LENGTH);
  619. last_block = (struct edid *)raw_edid;
  620. if (last_block)
  621. return last_block->checksum;
  622. SDE_ERROR("Invalid block, no checksum\n");
  623. return 0;
  624. }
  625. bool sde_detect_hdmi_monitor(void *input)
  626. {
  627. struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input);
  628. return drm_detect_hdmi_monitor(edid_ctrl->edid);
  629. }
  630. void sde_parse_edid(void *input)
  631. {
  632. struct sde_edid_ctrl *edid_ctrl;
  633. if (!input) {
  634. SDE_ERROR("Invalid input\n");
  635. return;
  636. }
  637. edid_ctrl = (struct sde_edid_ctrl *)(input);
  638. if (edid_ctrl->edid) {
  639. sde_edid_extract_vendor_id(edid_ctrl);
  640. _sde_edid_extract_audio_data_blocks(edid_ctrl);
  641. _sde_edid_extract_speaker_allocation_data(edid_ctrl);
  642. } else {
  643. SDE_ERROR("edid not present\n");
  644. }
  645. }
  646. void sde_get_edid(struct drm_connector *connector,
  647. struct i2c_adapter *adapter, void **input)
  648. {
  649. struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input);
  650. edid_ctrl->edid = drm_get_edid(connector, adapter);
  651. SDE_EDID_DEBUG("%s +\n", __func__);
  652. if (!edid_ctrl->edid)
  653. SDE_ERROR("EDID read failed\n");
  654. if (edid_ctrl->edid)
  655. sde_parse_edid(edid_ctrl);
  656. SDE_EDID_DEBUG("%s -\n", __func__);
  657. };