dp_link.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2012-2019, 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_MAX = DP_LINK_VOLTAGE_LEVEL_2,
  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. DP_LINK_PRE_EMPHASIS_MAX = DP_LINK_PRE_EMPHASIS_LEVEL_3,
  57. };
  58. struct dp_link_sink_count {
  59. u32 count;
  60. bool cp_ready;
  61. };
  62. struct dp_link_test_video {
  63. u32 test_video_pattern;
  64. u32 test_bit_depth;
  65. u32 test_dyn_range;
  66. u32 test_h_total;
  67. u32 test_v_total;
  68. u32 test_h_start;
  69. u32 test_v_start;
  70. u32 test_hsync_pol;
  71. u32 test_hsync_width;
  72. u32 test_vsync_pol;
  73. u32 test_vsync_width;
  74. u32 test_h_width;
  75. u32 test_v_height;
  76. u32 test_rr_d;
  77. u32 test_rr_n;
  78. };
  79. struct dp_link_test_audio {
  80. u32 test_audio_sampling_rate;
  81. u32 test_audio_channel_count;
  82. u32 test_audio_pattern_type;
  83. u32 test_audio_period_ch_1;
  84. u32 test_audio_period_ch_2;
  85. u32 test_audio_period_ch_3;
  86. u32 test_audio_period_ch_4;
  87. u32 test_audio_period_ch_5;
  88. u32 test_audio_period_ch_6;
  89. u32 test_audio_period_ch_7;
  90. u32 test_audio_period_ch_8;
  91. };
  92. struct dp_link_hdcp_status {
  93. int hdcp_state;
  94. int hdcp_version;
  95. };
  96. struct dp_link_phy_params {
  97. u32 phy_test_pattern_sel;
  98. u8 v_level;
  99. u8 p_level;
  100. };
  101. struct dp_link_params {
  102. u32 lane_count;
  103. u32 bw_code;
  104. };
  105. static inline char *dp_link_get_test_name(u32 test_requested)
  106. {
  107. switch (test_requested) {
  108. case DP_TEST_LINK_TRAINING:
  109. return DP_LINK_ENUM_STR(DP_TEST_LINK_TRAINING);
  110. case DP_TEST_LINK_VIDEO_PATTERN:
  111. return DP_LINK_ENUM_STR(DP_TEST_LINK_VIDEO_PATTERN);
  112. case DP_TEST_LINK_EDID_READ:
  113. return DP_LINK_ENUM_STR(DP_TEST_LINK_EDID_READ);
  114. case DP_TEST_LINK_PHY_TEST_PATTERN:
  115. return DP_LINK_ENUM_STR(DP_TEST_LINK_PHY_TEST_PATTERN);
  116. case DP_TEST_LINK_AUDIO_PATTERN:
  117. return DP_LINK_ENUM_STR(DP_TEST_LINK_AUDIO_PATTERN);
  118. case DS_PORT_STATUS_CHANGED:
  119. return DP_LINK_ENUM_STR(DS_PORT_STATUS_CHANGED);
  120. case DP_LINK_STATUS_UPDATED:
  121. return DP_LINK_ENUM_STR(DP_LINK_STATUS_UPDATED);
  122. default:
  123. return "unknown";
  124. }
  125. }
  126. struct dp_link {
  127. u32 sink_request;
  128. u32 test_response;
  129. struct dp_link_sink_count sink_count;
  130. struct dp_link_test_video test_video;
  131. struct dp_link_test_audio test_audio;
  132. struct dp_link_phy_params phy_params;
  133. struct dp_link_params link_params;
  134. struct dp_link_hdcp_status hdcp_status;
  135. u32 (*get_test_bits_depth)(struct dp_link *dp_link, u32 bpp);
  136. int (*process_request)(struct dp_link *dp_link);
  137. int (*get_colorimetry_config)(struct dp_link *dp_link);
  138. int (*adjust_levels)(struct dp_link *dp_link, u8 *link_status);
  139. int (*send_psm_request)(struct dp_link *dp_link, bool req);
  140. void (*send_test_response)(struct dp_link *dp_link);
  141. int (*psm_config)(struct dp_link *dp_link,
  142. struct drm_dp_link *link_info, bool enable);
  143. void (*send_edid_checksum)(struct dp_link *dp_link, u8 checksum);
  144. };
  145. static inline char *dp_link_get_phy_test_pattern(u32 phy_test_pattern_sel)
  146. {
  147. switch (phy_test_pattern_sel) {
  148. case DP_PHY_TEST_PATTERN_NONE:
  149. return DP_LINK_ENUM_STR(DP_PHY_TEST_PATTERN_NONE);
  150. case DP_PHY_TEST_PATTERN_D10_2:
  151. return DP_LINK_ENUM_STR(
  152. DP_PHY_TEST_PATTERN_D10_2);
  153. case DP_PHY_TEST_PATTERN_ERROR_COUNT:
  154. return DP_LINK_ENUM_STR(
  155. DP_PHY_TEST_PATTERN_ERROR_COUNT);
  156. case DP_PHY_TEST_PATTERN_PRBS7:
  157. return DP_LINK_ENUM_STR(DP_PHY_TEST_PATTERN_PRBS7);
  158. case DP_PHY_TEST_PATTERN_80BIT_CUSTOM:
  159. return DP_LINK_ENUM_STR(
  160. DP_PHY_TEST_PATTERN_80BIT_CUSTOM);
  161. case DP_PHY_TEST_PATTERN_CP2520:
  162. return DP_LINK_ENUM_STR(DP_PHY_TEST_PATTERN_CP2520);
  163. case DP_PHY_TEST_PATTERN_CP2520_2:
  164. return DP_LINK_ENUM_STR(DP_PHY_TEST_PATTERN_CP2520_2);
  165. case DP_PHY_TEST_PATTERN_CP2520_3:
  166. return DP_LINK_ENUM_STR(DP_PHY_TEST_PATTERN_CP2520_3);
  167. default:
  168. return "unknown";
  169. }
  170. }
  171. /**
  172. * mdss_dp_test_bit_depth_to_bpp() - convert test bit depth to bpp
  173. * @tbd: test bit depth
  174. *
  175. * Returns the bits per pixel (bpp) to be used corresponding to the
  176. * git bit depth value. This function assumes that bit depth has
  177. * already been validated.
  178. */
  179. static inline u32 dp_link_bit_depth_to_bpp(u32 tbd)
  180. {
  181. u32 bpp;
  182. /*
  183. * Few simplistic rules and assumptions made here:
  184. * 1. Bit depth is per color component
  185. * 2. If bit depth is unknown return 0
  186. * 3. Assume 3 color components
  187. */
  188. switch (tbd) {
  189. case DP_TEST_BIT_DEPTH_6:
  190. bpp = 18;
  191. break;
  192. case DP_TEST_BIT_DEPTH_8:
  193. bpp = 24;
  194. break;
  195. case DP_TEST_BIT_DEPTH_10:
  196. bpp = 30;
  197. break;
  198. case DP_TEST_BIT_DEPTH_UNKNOWN:
  199. default:
  200. bpp = 0;
  201. }
  202. return bpp;
  203. }
  204. /**
  205. * dp_link_get() - get the functionalities of dp test module
  206. *
  207. *
  208. * return: a pointer to dp_link struct
  209. */
  210. struct dp_link *dp_link_get(struct device *dev, struct dp_aux *aux);
  211. /**
  212. * dp_link_put() - releases the dp test module's resources
  213. *
  214. * @dp_link: an instance of dp_link module
  215. *
  216. */
  217. void dp_link_put(struct dp_link *dp_link);
  218. #endif /* _DP_LINK_H_ */