drm_eld.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright © 2023 Intel Corporation
  4. */
  5. #ifndef __DRM_ELD_H__
  6. #define __DRM_ELD_H__
  7. #include <linux/types.h>
  8. struct cea_sad;
  9. /* ELD Header Block */
  10. #define DRM_ELD_HEADER_BLOCK_SIZE 4
  11. #define DRM_ELD_VER 0
  12. # define DRM_ELD_VER_SHIFT 3
  13. # define DRM_ELD_VER_MASK (0x1f << 3)
  14. # define DRM_ELD_VER_CEA861D (2 << 3) /* supports 861D or below */
  15. # define DRM_ELD_VER_CANNED (0x1f << 3)
  16. #define DRM_ELD_BASELINE_ELD_LEN 2 /* in dwords! */
  17. /* ELD Baseline Block for ELD_Ver == 2 */
  18. #define DRM_ELD_CEA_EDID_VER_MNL 4
  19. # define DRM_ELD_CEA_EDID_VER_SHIFT 5
  20. # define DRM_ELD_CEA_EDID_VER_MASK (7 << 5)
  21. # define DRM_ELD_CEA_EDID_VER_NONE (0 << 5)
  22. # define DRM_ELD_CEA_EDID_VER_CEA861 (1 << 5)
  23. # define DRM_ELD_CEA_EDID_VER_CEA861A (2 << 5)
  24. # define DRM_ELD_CEA_EDID_VER_CEA861BCD (3 << 5)
  25. # define DRM_ELD_MNL_SHIFT 0
  26. # define DRM_ELD_MNL_MASK (0x1f << 0)
  27. #define DRM_ELD_SAD_COUNT_CONN_TYPE 5
  28. # define DRM_ELD_SAD_COUNT_SHIFT 4
  29. # define DRM_ELD_SAD_COUNT_MASK (0xf << 4)
  30. # define DRM_ELD_CONN_TYPE_SHIFT 2
  31. # define DRM_ELD_CONN_TYPE_MASK (3 << 2)
  32. # define DRM_ELD_CONN_TYPE_HDMI (0 << 2)
  33. # define DRM_ELD_CONN_TYPE_DP (1 << 2)
  34. # define DRM_ELD_SUPPORTS_AI (1 << 1)
  35. # define DRM_ELD_SUPPORTS_HDCP (1 << 0)
  36. #define DRM_ELD_AUD_SYNCH_DELAY 6 /* in units of 2 ms */
  37. # define DRM_ELD_AUD_SYNCH_DELAY_MAX 0xfa /* 500 ms */
  38. #define DRM_ELD_SPEAKER 7
  39. # define DRM_ELD_SPEAKER_MASK 0x7f
  40. # define DRM_ELD_SPEAKER_RLRC (1 << 6)
  41. # define DRM_ELD_SPEAKER_FLRC (1 << 5)
  42. # define DRM_ELD_SPEAKER_RC (1 << 4)
  43. # define DRM_ELD_SPEAKER_RLR (1 << 3)
  44. # define DRM_ELD_SPEAKER_FC (1 << 2)
  45. # define DRM_ELD_SPEAKER_LFE (1 << 1)
  46. # define DRM_ELD_SPEAKER_FLR (1 << 0)
  47. #define DRM_ELD_PORT_ID 8 /* offsets 8..15 inclusive */
  48. # define DRM_ELD_PORT_ID_LEN 8
  49. #define DRM_ELD_MANUFACTURER_NAME0 16
  50. #define DRM_ELD_MANUFACTURER_NAME1 17
  51. #define DRM_ELD_PRODUCT_CODE0 18
  52. #define DRM_ELD_PRODUCT_CODE1 19
  53. #define DRM_ELD_MONITOR_NAME_STRING 20 /* offsets 20..(20+mnl-1) inclusive */
  54. #define DRM_ELD_CEA_SAD(mnl, sad) (20 + (mnl) + 3 * (sad))
  55. /**
  56. * drm_eld_mnl - Get ELD monitor name length in bytes.
  57. * @eld: pointer to an eld memory structure with mnl set
  58. */
  59. static inline int drm_eld_mnl(const u8 *eld)
  60. {
  61. return (eld[DRM_ELD_CEA_EDID_VER_MNL] & DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;
  62. }
  63. int drm_eld_sad_get(const u8 *eld, int sad_index, struct cea_sad *cta_sad);
  64. int drm_eld_sad_set(u8 *eld, int sad_index, const struct cea_sad *cta_sad);
  65. /**
  66. * drm_eld_sad - Get ELD SAD structures.
  67. * @eld: pointer to an eld memory structure with sad_count set
  68. */
  69. static inline const u8 *drm_eld_sad(const u8 *eld)
  70. {
  71. unsigned int ver, mnl;
  72. ver = (eld[DRM_ELD_VER] & DRM_ELD_VER_MASK) >> DRM_ELD_VER_SHIFT;
  73. if (ver != 2 && ver != 31)
  74. return NULL;
  75. mnl = drm_eld_mnl(eld);
  76. if (mnl > 16)
  77. return NULL;
  78. return eld + DRM_ELD_CEA_SAD(mnl, 0);
  79. }
  80. /**
  81. * drm_eld_sad_count - Get ELD SAD count.
  82. * @eld: pointer to an eld memory structure with sad_count set
  83. */
  84. static inline int drm_eld_sad_count(const u8 *eld)
  85. {
  86. return (eld[DRM_ELD_SAD_COUNT_CONN_TYPE] & DRM_ELD_SAD_COUNT_MASK) >>
  87. DRM_ELD_SAD_COUNT_SHIFT;
  88. }
  89. /**
  90. * drm_eld_calc_baseline_block_size - Calculate baseline block size in bytes
  91. * @eld: pointer to an eld memory structure with mnl and sad_count set
  92. *
  93. * This is a helper for determining the payload size of the baseline block, in
  94. * bytes, for e.g. setting the Baseline_ELD_Len field in the ELD header block.
  95. */
  96. static inline int drm_eld_calc_baseline_block_size(const u8 *eld)
  97. {
  98. return DRM_ELD_MONITOR_NAME_STRING - DRM_ELD_HEADER_BLOCK_SIZE +
  99. drm_eld_mnl(eld) + drm_eld_sad_count(eld) * 3;
  100. }
  101. /**
  102. * drm_eld_size - Get ELD size in bytes
  103. * @eld: pointer to a complete eld memory structure
  104. *
  105. * The returned value does not include the vendor block. It's vendor specific,
  106. * and comprises of the remaining bytes in the ELD memory buffer after
  107. * drm_eld_size() bytes of header and baseline block.
  108. *
  109. * The returned value is guaranteed to be a multiple of 4.
  110. */
  111. static inline int drm_eld_size(const u8 *eld)
  112. {
  113. return DRM_ELD_HEADER_BLOCK_SIZE + eld[DRM_ELD_BASELINE_ELD_LEN] * 4;
  114. }
  115. /**
  116. * drm_eld_get_spk_alloc - Get speaker allocation
  117. * @eld: pointer to an ELD memory structure
  118. *
  119. * The returned value is the speakers mask. User has to use %DRM_ELD_SPEAKER
  120. * field definitions to identify speakers.
  121. */
  122. static inline u8 drm_eld_get_spk_alloc(const u8 *eld)
  123. {
  124. return eld[DRM_ELD_SPEAKER] & DRM_ELD_SPEAKER_MASK;
  125. }
  126. /**
  127. * drm_eld_get_conn_type - Get device type hdmi/dp connected
  128. * @eld: pointer to an ELD memory structure
  129. *
  130. * The caller need to use %DRM_ELD_CONN_TYPE_HDMI or %DRM_ELD_CONN_TYPE_DP to
  131. * identify the display type connected.
  132. */
  133. static inline u8 drm_eld_get_conn_type(const u8 *eld)
  134. {
  135. return eld[DRM_ELD_SAD_COUNT_CONN_TYPE] & DRM_ELD_CONN_TYPE_MASK;
  136. }
  137. #endif /* __DRM_ELD_H__ */