dp_link.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _DP_LINK_H_
  6. #define _DP_LINK_H_
  7. #include "dp_aux.h"
  8. #define DS_PORT_STATUS_CHANGED 0x200
  9. #define DP_TEST_BIT_DEPTH_UNKNOWN 0xFFFFFFFF
  10. #define DP_LINK_ENUM_STR(x) #x
  11. enum dp_link_voltage_level {
  12. DP_LINK_VOLTAGE_LEVEL_0,
  13. DP_LINK_VOLTAGE_LEVEL_1,
  14. DP_LINK_VOLTAGE_LEVEL_2,
  15. DP_LINK_VOLTAGE_MAX = DP_LINK_VOLTAGE_LEVEL_2,
  16. };
  17. enum dp_link_preemaphasis_level {
  18. DP_LINK_PRE_EMPHASIS_LEVEL_0,
  19. DP_LINK_PRE_EMPHASIS_LEVEL_1,
  20. DP_LINK_PRE_EMPHASIS_LEVEL_2,
  21. DP_LINK_PRE_EMPHASIS_MAX = DP_LINK_PRE_EMPHASIS_LEVEL_2,
  22. };
  23. struct dp_link_sink_count {
  24. u32 count;
  25. bool cp_ready;
  26. };
  27. struct dp_link_test_video {
  28. u32 test_video_pattern;
  29. u32 test_bit_depth;
  30. u32 test_dyn_range;
  31. u32 test_h_total;
  32. u32 test_v_total;
  33. u32 test_h_start;
  34. u32 test_v_start;
  35. u32 test_hsync_pol;
  36. u32 test_hsync_width;
  37. u32 test_vsync_pol;
  38. u32 test_vsync_width;
  39. u32 test_h_width;
  40. u32 test_v_height;
  41. u32 test_rr_d;
  42. u32 test_rr_n;
  43. };
  44. struct dp_link_test_audio {
  45. u32 test_audio_sampling_rate;
  46. u32 test_audio_channel_count;
  47. u32 test_audio_pattern_type;
  48. u32 test_audio_period_ch_1;
  49. u32 test_audio_period_ch_2;
  50. u32 test_audio_period_ch_3;
  51. u32 test_audio_period_ch_4;
  52. u32 test_audio_period_ch_5;
  53. u32 test_audio_period_ch_6;
  54. u32 test_audio_period_ch_7;
  55. u32 test_audio_period_ch_8;
  56. };
  57. struct dp_link_hdcp_status {
  58. int hdcp_state;
  59. int hdcp_version;
  60. };
  61. struct dp_link_phy_params {
  62. u32 phy_test_pattern_sel;
  63. u8 v_level;
  64. u8 p_level;
  65. };
  66. struct dp_link_params {
  67. u32 lane_count;
  68. u32 bw_code;
  69. };
  70. static inline char *dp_link_get_test_name(u32 test_requested)
  71. {
  72. switch (test_requested) {
  73. case DP_TEST_LINK_TRAINING:
  74. return DP_LINK_ENUM_STR(DP_TEST_LINK_TRAINING);
  75. case DP_TEST_LINK_VIDEO_PATTERN:
  76. return DP_LINK_ENUM_STR(DP_TEST_LINK_VIDEO_PATTERN);
  77. case DP_TEST_LINK_EDID_READ:
  78. return DP_LINK_ENUM_STR(DP_TEST_LINK_EDID_READ);
  79. case DP_TEST_LINK_PHY_TEST_PATTERN:
  80. return DP_LINK_ENUM_STR(DP_TEST_LINK_PHY_TEST_PATTERN);
  81. case DP_TEST_LINK_AUDIO_PATTERN:
  82. return DP_LINK_ENUM_STR(DP_TEST_LINK_AUDIO_PATTERN);
  83. case DS_PORT_STATUS_CHANGED:
  84. return DP_LINK_ENUM_STR(DS_PORT_STATUS_CHANGED);
  85. case DP_LINK_STATUS_UPDATED:
  86. return DP_LINK_ENUM_STR(DP_LINK_STATUS_UPDATED);
  87. default:
  88. return "unknown";
  89. }
  90. }
  91. struct dp_link {
  92. u32 sink_request;
  93. u32 test_response;
  94. struct dp_link_sink_count sink_count;
  95. struct dp_link_test_video test_video;
  96. struct dp_link_test_audio test_audio;
  97. struct dp_link_phy_params phy_params;
  98. struct dp_link_params link_params;
  99. struct dp_link_hdcp_status hdcp_status;
  100. u32 (*get_test_bits_depth)(struct dp_link *dp_link, u32 bpp);
  101. int (*process_request)(struct dp_link *dp_link);
  102. int (*get_colorimetry_config)(struct dp_link *dp_link);
  103. int (*adjust_levels)(struct dp_link *dp_link, u8 *link_status);
  104. int (*send_psm_request)(struct dp_link *dp_link, bool req);
  105. void (*send_test_response)(struct dp_link *dp_link);
  106. int (*psm_config)(struct dp_link *dp_link,
  107. struct drm_dp_link *link_info, bool enable);
  108. void (*send_edid_checksum)(struct dp_link *dp_link, u8 checksum);
  109. };
  110. static inline char *dp_link_get_phy_test_pattern(u32 phy_test_pattern_sel)
  111. {
  112. switch (phy_test_pattern_sel) {
  113. case DP_TEST_PHY_PATTERN_NONE:
  114. return DP_LINK_ENUM_STR(DP_TEST_PHY_PATTERN_NONE);
  115. case DP_TEST_PHY_PATTERN_D10_2_NO_SCRAMBLING:
  116. return DP_LINK_ENUM_STR(
  117. DP_TEST_PHY_PATTERN_D10_2_NO_SCRAMBLING);
  118. case DP_TEST_PHY_PATTERN_SYMBOL_ERR_MEASUREMENT_CNT:
  119. return DP_LINK_ENUM_STR(
  120. DP_TEST_PHY_PATTERN_SYMBOL_ERR_MEASUREMENT_CNT);
  121. case DP_TEST_PHY_PATTERN_PRBS7:
  122. return DP_LINK_ENUM_STR(DP_TEST_PHY_PATTERN_PRBS7);
  123. case DP_TEST_PHY_PATTERN_80_BIT_CUSTOM_PATTERN:
  124. return DP_LINK_ENUM_STR(
  125. DP_TEST_PHY_PATTERN_80_BIT_CUSTOM_PATTERN);
  126. case DP_TEST_PHY_PATTERN_CP2520_PATTERN_1:
  127. return DP_LINK_ENUM_STR(DP_TEST_PHY_PATTERN_CP2520_PATTERN_1);
  128. case DP_TEST_PHY_PATTERN_CP2520_PATTERN_2:
  129. return DP_LINK_ENUM_STR(DP_TEST_PHY_PATTERN_CP2520_PATTERN_2);
  130. case DP_TEST_PHY_PATTERN_CP2520_PATTERN_3:
  131. return DP_LINK_ENUM_STR(DP_TEST_PHY_PATTERN_CP2520_PATTERN_3);
  132. default:
  133. return "unknown";
  134. }
  135. }
  136. /**
  137. * mdss_dp_test_bit_depth_to_bpp() - convert test bit depth to bpp
  138. * @tbd: test bit depth
  139. *
  140. * Returns the bits per pixel (bpp) to be used corresponding to the
  141. * git bit depth value. This function assumes that bit depth has
  142. * already been validated.
  143. */
  144. static inline u32 dp_link_bit_depth_to_bpp(u32 tbd)
  145. {
  146. u32 bpp;
  147. /*
  148. * Few simplistic rules and assumptions made here:
  149. * 1. Bit depth is per color component
  150. * 2. If bit depth is unknown return 0
  151. * 3. Assume 3 color components
  152. */
  153. switch (tbd) {
  154. case DP_TEST_BIT_DEPTH_6:
  155. bpp = 18;
  156. break;
  157. case DP_TEST_BIT_DEPTH_8:
  158. bpp = 24;
  159. break;
  160. case DP_TEST_BIT_DEPTH_10:
  161. bpp = 30;
  162. break;
  163. case DP_TEST_BIT_DEPTH_UNKNOWN:
  164. default:
  165. bpp = 0;
  166. }
  167. return bpp;
  168. }
  169. /**
  170. * dp_link_get() - get the functionalities of dp test module
  171. *
  172. *
  173. * return: a pointer to dp_link struct
  174. */
  175. struct dp_link *dp_link_get(struct device *dev, struct dp_aux *aux);
  176. /**
  177. * dp_link_put() - releases the dp test module's resources
  178. *
  179. * @dp_link: an instance of dp_link module
  180. *
  181. */
  182. void dp_link_put(struct dp_link *dp_link);
  183. #endif /* _DP_LINK_H_ */