dp_link.h 6.7 KB

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