dp_link.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
  5. *
  6. * Copyright (c) 2008 Keith Packard
  7. *
  8. * Permission to use, copy, modify, distribute, and sell this software and its
  9. * documentation for any purpose is hereby granted without fee, provided that
  10. * the above copyright notice appear in all copies and that both that copyright
  11. * notice and this permission notice appear in supporting documentation, and
  12. * that the name of the copyright holders not be used in advertising or
  13. * publicity pertaining to distribution of the software without specific,
  14. * written prior permission. The copyright holders make no representations
  15. * about the suitability of this software for any purpose. It is provided "as
  16. * is" without express or implied warranty.
  17. *
  18. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  19. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  20. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  22. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  23. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  24. * OF THIS SOFTWARE.
  25. */
  26. #ifndef _DP_LINK_H_
  27. #define _DP_LINK_H_
  28. #include "dp_aux.h"
  29. #define DS_PORT_STATUS_CHANGED 0x200
  30. #define DP_TEST_BIT_DEPTH_UNKNOWN 0xFFFFFFFF
  31. #define DP_LINK_ENUM_STR(x) #x
  32. #define DP_PHY_TEST_PATTERN_CP2520_2 0x6
  33. #define DP_PHY_TEST_PATTERN_CP2520_3 0x7
  34. struct drm_dp_aux;
  35. #define DP_LINK_CAP_ENHANCED_FRAMING (1 << 0)
  36. #define DP_LINK_CAP_CRC (1 << 1)
  37. struct drm_dp_link {
  38. unsigned char revision;
  39. unsigned int rate;
  40. unsigned int num_lanes;
  41. unsigned long capabilities;
  42. };
  43. int dp_link_probe(struct drm_dp_aux *aux, struct drm_dp_link *link);
  44. int dp_link_power_up(struct drm_dp_aux *aux, struct drm_dp_link *link);
  45. int dp_link_power_down(struct drm_dp_aux *aux, struct drm_dp_link *link);
  46. int dp_link_configure(struct drm_dp_aux *aux, struct drm_dp_link *link);
  47. enum dp_link_voltage_level {
  48. DP_LINK_VOLTAGE_LEVEL_0,
  49. DP_LINK_VOLTAGE_LEVEL_1,
  50. DP_LINK_VOLTAGE_LEVEL_2,
  51. DP_LINK_VOLTAGE_LEVEL_3,
  52. };
  53. enum dp_link_preemaphasis_level {
  54. DP_LINK_PRE_EMPHASIS_LEVEL_0,
  55. DP_LINK_PRE_EMPHASIS_LEVEL_1,
  56. DP_LINK_PRE_EMPHASIS_LEVEL_2,
  57. DP_LINK_PRE_EMPHASIS_LEVEL_3,
  58. };
  59. struct dp_link_sink_count {
  60. u32 count;
  61. bool cp_ready;
  62. };
  63. struct dp_link_test_video {
  64. u32 test_video_pattern;
  65. u32 test_bit_depth;
  66. u32 test_dyn_range;
  67. u32 test_h_total;
  68. u32 test_v_total;
  69. u32 test_h_start;
  70. u32 test_v_start;
  71. u32 test_hsync_pol;
  72. u32 test_hsync_width;
  73. u32 test_vsync_pol;
  74. u32 test_vsync_width;
  75. u32 test_h_width;
  76. u32 test_v_height;
  77. u32 test_rr_d;
  78. u32 test_rr_n;
  79. };
  80. struct dp_link_test_audio {
  81. u32 test_audio_sampling_rate;
  82. u32 test_audio_channel_count;
  83. u32 test_audio_pattern_type;
  84. u32 test_audio_period_ch_1;
  85. u32 test_audio_period_ch_2;
  86. u32 test_audio_period_ch_3;
  87. u32 test_audio_period_ch_4;
  88. u32 test_audio_period_ch_5;
  89. u32 test_audio_period_ch_6;
  90. u32 test_audio_period_ch_7;
  91. u32 test_audio_period_ch_8;
  92. };
  93. struct dp_link_hdcp_status {
  94. int hdcp_state;
  95. int hdcp_version;
  96. };
  97. struct dp_link_phy_params {
  98. u32 phy_test_pattern_sel;
  99. u8 v_level;
  100. u8 p_level;
  101. u8 max_v_level;
  102. u8 max_p_level;
  103. };
  104. struct dp_link_params {
  105. u32 lane_count;
  106. u32 bw_code;
  107. };
  108. static inline char *dp_link_get_test_name(u32 test_requested)
  109. {
  110. switch (test_requested) {
  111. case DP_TEST_LINK_TRAINING:
  112. return DP_LINK_ENUM_STR(DP_TEST_LINK_TRAINING);
  113. case DP_TEST_LINK_VIDEO_PATTERN:
  114. return DP_LINK_ENUM_STR(DP_TEST_LINK_VIDEO_PATTERN);
  115. case DP_TEST_LINK_EDID_READ:
  116. return DP_LINK_ENUM_STR(DP_TEST_LINK_EDID_READ);
  117. case DP_TEST_LINK_PHY_TEST_PATTERN:
  118. return DP_LINK_ENUM_STR(DP_TEST_LINK_PHY_TEST_PATTERN);
  119. case DP_TEST_LINK_AUDIO_PATTERN:
  120. return DP_LINK_ENUM_STR(DP_TEST_LINK_AUDIO_PATTERN);
  121. case DS_PORT_STATUS_CHANGED:
  122. return DP_LINK_ENUM_STR(DS_PORT_STATUS_CHANGED);
  123. case DP_LINK_STATUS_UPDATED:
  124. return DP_LINK_ENUM_STR(DP_LINK_STATUS_UPDATED);
  125. default:
  126. return "unknown";
  127. }
  128. }
  129. struct dp_link {
  130. u32 sink_request;
  131. u32 test_response;
  132. struct dp_link_sink_count sink_count;
  133. struct dp_link_test_video test_video;
  134. struct dp_link_test_audio test_audio;
  135. struct dp_link_phy_params phy_params;
  136. struct dp_link_params link_params;
  137. struct dp_link_hdcp_status hdcp_status;
  138. u32 (*get_test_bits_depth)(struct dp_link *dp_link, u32 bpp);
  139. int (*process_request)(struct dp_link *dp_link);
  140. int (*get_colorimetry_config)(struct dp_link *dp_link);
  141. int (*adjust_levels)(struct dp_link *dp_link, u8 *link_status);
  142. int (*send_psm_request)(struct dp_link *dp_link, bool req);
  143. void (*send_test_response)(struct dp_link *dp_link);
  144. int (*psm_config)(struct dp_link *dp_link,
  145. struct drm_dp_link *link_info, bool enable);
  146. void (*send_edid_checksum)(struct dp_link *dp_link, u8 checksum);
  147. };
  148. static inline char *dp_link_get_phy_test_pattern(u32 phy_test_pattern_sel)
  149. {
  150. switch (phy_test_pattern_sel) {
  151. case DP_PHY_TEST_PATTERN_NONE:
  152. return DP_LINK_ENUM_STR(DP_PHY_TEST_PATTERN_NONE);
  153. case DP_PHY_TEST_PATTERN_D10_2:
  154. return DP_LINK_ENUM_STR(
  155. DP_PHY_TEST_PATTERN_D10_2);
  156. case DP_PHY_TEST_PATTERN_ERROR_COUNT:
  157. return DP_LINK_ENUM_STR(
  158. DP_PHY_TEST_PATTERN_ERROR_COUNT);
  159. case DP_PHY_TEST_PATTERN_PRBS7:
  160. return DP_LINK_ENUM_STR(DP_PHY_TEST_PATTERN_PRBS7);
  161. case DP_PHY_TEST_PATTERN_80BIT_CUSTOM:
  162. return DP_LINK_ENUM_STR(
  163. DP_PHY_TEST_PATTERN_80BIT_CUSTOM);
  164. case DP_PHY_TEST_PATTERN_CP2520:
  165. return DP_LINK_ENUM_STR(DP_PHY_TEST_PATTERN_CP2520);
  166. case DP_PHY_TEST_PATTERN_CP2520_2:
  167. return DP_LINK_ENUM_STR(DP_PHY_TEST_PATTERN_CP2520_2);
  168. case DP_PHY_TEST_PATTERN_CP2520_3:
  169. return DP_LINK_ENUM_STR(DP_PHY_TEST_PATTERN_CP2520_3);
  170. default:
  171. return "unknown";
  172. }
  173. }
  174. /**
  175. * mdss_dp_test_bit_depth_to_bpp() - convert test bit depth to bpp
  176. * @tbd: test bit depth
  177. *
  178. * Returns the bits per pixel (bpp) to be used corresponding to the
  179. * git bit depth value. This function assumes that bit depth has
  180. * already been validated.
  181. */
  182. static inline u32 dp_link_bit_depth_to_bpp(u32 tbd)
  183. {
  184. u32 bpp;
  185. /*
  186. * Few simplistic rules and assumptions made here:
  187. * 1. Bit depth is per color component
  188. * 2. If bit depth is unknown return 0
  189. * 3. Assume 3 color components
  190. */
  191. switch (tbd) {
  192. case DP_TEST_BIT_DEPTH_6:
  193. bpp = 18;
  194. break;
  195. case DP_TEST_BIT_DEPTH_8:
  196. bpp = 24;
  197. break;
  198. case DP_TEST_BIT_DEPTH_10:
  199. bpp = 30;
  200. break;
  201. case DP_TEST_BIT_DEPTH_UNKNOWN:
  202. default:
  203. bpp = 0;
  204. }
  205. return bpp;
  206. }
  207. /**
  208. * dp_link_get() - get the functionalities of dp test module
  209. *
  210. *
  211. * return: a pointer to dp_link struct
  212. */
  213. struct dp_link *dp_link_get(struct device *dev, struct dp_aux *aux, u32 dp_core_revision);
  214. /**
  215. * dp_link_put() - releases the dp test module's resources
  216. *
  217. * @dp_link: an instance of dp_link module
  218. *
  219. */
  220. void dp_link_put(struct dp_link *dp_link);
  221. #endif /* _DP_LINK_H_ */