dp_panel.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef _DP_PANEL_H_
  7. #define _DP_PANEL_H_
  8. #include <drm/sde_drm.h>
  9. #include "dp_aux.h"
  10. #include "dp_link.h"
  11. #include "sde_edid_parser.h"
  12. #include "sde_connector.h"
  13. #include "msm_drv.h"
  14. #define DP_RECEIVER_DSC_CAP_SIZE 15
  15. #define DP_RECEIVER_FEC_STATUS_SIZE 3
  16. #define DP_RECEIVER_EXT_CAP_SIZE 4
  17. /*
  18. * A source initiated power down flag is set
  19. * when the DP is powered off while physical
  20. * DP cable is still connected i.e. without
  21. * HPD or not initiated by sink like HPD_IRQ.
  22. * This can happen if framework reboots or
  23. * device suspends.
  24. */
  25. #define DP_PANEL_SRC_INITIATED_POWER_DOWN BIT(0)
  26. #define DP_EXT_REC_CAP_FIELD BIT(7)
  27. enum dp_lane_count {
  28. DP_LANE_COUNT_1 = 1,
  29. DP_LANE_COUNT_2 = 2,
  30. DP_LANE_COUNT_4 = 4,
  31. };
  32. enum dp_output_format {
  33. DP_OUTPUT_FORMAT_RGB,
  34. DP_OUTPUT_FORMAT_YCBCR420,
  35. DP_OUTPUT_FORMAT_YCBCR422,
  36. DP_OUTPUT_FORMAT_YCBCR444,
  37. DP_OUTPUT_FORMAT_INVALID,
  38. };
  39. #define DP_MAX_DOWNSTREAM_PORTS 0x10
  40. struct dp_panel_info {
  41. u32 h_active;
  42. u32 v_active;
  43. u32 h_back_porch;
  44. u32 h_front_porch;
  45. u32 h_sync_width;
  46. u32 h_active_low;
  47. u32 v_back_porch;
  48. u32 v_front_porch;
  49. u32 v_sync_width;
  50. u32 v_active_low;
  51. u32 h_skew;
  52. u32 refresh_rate;
  53. u32 pixel_clk_khz;
  54. u32 bpp;
  55. bool widebus_en;
  56. struct msm_compression_info comp_info;
  57. s64 dsc_overhead_fp;
  58. };
  59. struct dp_display_mode {
  60. struct dp_panel_info timing;
  61. u32 capabilities;
  62. s64 fec_overhead_fp;
  63. s64 dsc_overhead_fp;
  64. /**
  65. * @output_format:
  66. *
  67. * This is used to indicate DP output format.
  68. * The output format can be read from drm_mode.
  69. */
  70. enum dp_output_format output_format;
  71. u32 lm_count;
  72. };
  73. struct dp_panel;
  74. struct dp_panel_in {
  75. struct device *dev;
  76. struct dp_aux *aux;
  77. struct dp_link *link;
  78. struct dp_catalog_panel *catalog;
  79. struct drm_connector *connector;
  80. struct dp_panel *base_panel;
  81. struct dp_parser *parser;
  82. };
  83. struct dp_dsc_caps {
  84. bool dsc_capable;
  85. u8 version;
  86. bool block_pred_en;
  87. u8 color_depth;
  88. };
  89. struct dp_audio;
  90. #define DP_PANEL_CAPS_DSC BIT(0)
  91. struct dp_panel {
  92. /* dpcd raw data */
  93. u8 dpcd[DP_RECEIVER_CAP_SIZE + DP_RECEIVER_EXT_CAP_SIZE + 1];
  94. u8 ds_ports[DP_MAX_DOWNSTREAM_PORTS];
  95. u8 dsc_dpcd[DP_RECEIVER_DSC_CAP_SIZE + 1];
  96. u8 fec_dpcd;
  97. u8 fec_sts_dpcd[DP_RECEIVER_FEC_STATUS_SIZE + 1];
  98. struct drm_dp_link link_info;
  99. struct sde_edid_ctrl *edid_ctrl;
  100. struct dp_panel_info pinfo;
  101. bool video_test;
  102. bool spd_enabled;
  103. u32 vic;
  104. u32 max_pclk_khz;
  105. s64 mst_target_sc;
  106. /* debug */
  107. u32 max_bw_code;
  108. u32 lane_count;
  109. u32 link_bw_code;
  110. u32 max_supported_bpp;
  111. /* By default, stream_id is assigned to DP_INVALID_STREAM.
  112. * Client sets the stream id value using set_stream_id interface.
  113. */
  114. enum dp_stream_id stream_id;
  115. int vcpi;
  116. u32 channel_start_slot;
  117. u32 channel_total_slots;
  118. u32 pbn;
  119. u32 dsc_blks_in_use;
  120. u32 max_lm;
  121. /* DRM connector assosiated with this panel */
  122. struct drm_connector *connector;
  123. struct dp_audio *audio;
  124. bool audio_supported;
  125. struct dp_dsc_caps sink_dsc_caps;
  126. bool dsc_feature_enable;
  127. bool fec_feature_enable;
  128. bool dsc_en;
  129. bool fec_en;
  130. bool widebus_en;
  131. bool dsc_continuous_pps;
  132. bool mst_state;
  133. bool pclk_on;
  134. /* override debug option */
  135. bool mst_hide;
  136. bool mode_override;
  137. int hdisplay;
  138. int vdisplay;
  139. int vrefresh;
  140. int aspect_ratio;
  141. s64 fec_overhead_fp;
  142. int (*init)(struct dp_panel *dp_panel);
  143. int (*deinit)(struct dp_panel *dp_panel, u32 flags);
  144. int (*hw_cfg)(struct dp_panel *dp_panel, bool enable);
  145. int (*read_sink_caps)(struct dp_panel *dp_panel,
  146. struct drm_connector *connector, bool multi_func);
  147. u32 (*get_mode_bpp)(struct dp_panel *dp_panel, u32 mode_max_bpp,
  148. u32 mode_pclk_khz, bool dsc_en);
  149. int (*get_modes)(struct dp_panel *dp_panel,
  150. struct drm_connector *connector, struct dp_display_mode *mode);
  151. void (*handle_sink_request)(struct dp_panel *dp_panel);
  152. int (*setup_hdr)(struct dp_panel *dp_panel,
  153. struct drm_msm_ext_hdr_metadata *hdr_meta,
  154. bool dhdr_update, u64 core_clk_rate, bool flush);
  155. int (*set_colorspace)(struct dp_panel *dp_panel,
  156. u32 colorspace);
  157. void (*tpg_config)(struct dp_panel *dp_panel, u32 pattern);
  158. int (*spd_config)(struct dp_panel *dp_panel);
  159. bool (*hdr_supported)(struct dp_panel *dp_panel);
  160. int (*set_stream_info)(struct dp_panel *dp_panel,
  161. enum dp_stream_id stream_id, u32 ch_start_slot,
  162. u32 ch_tot_slots, u32 pbn, int vcpi);
  163. int (*read_sink_status)(struct dp_panel *dp_panel, u8 *sts, u32 size);
  164. int (*update_edid)(struct dp_panel *dp_panel, struct edid *edid);
  165. bool (*read_mst_cap)(struct dp_panel *dp_panel);
  166. void (*convert_to_dp_mode)(struct dp_panel *dp_panel,
  167. const struct drm_display_mode *drm_mode,
  168. struct dp_display_mode *dp_mode);
  169. void (*update_pps)(struct dp_panel *dp_panel, char *pps_cmd);
  170. int (*sink_crc_enable)(struct dp_panel *dp_panel, bool enable);
  171. int (*get_src_crc)(struct dp_panel *dp_panel, u16 *crc);
  172. int (*get_sink_crc)(struct dp_panel *dp_panel, u16 *crc);
  173. bool (*get_panel_on)(struct dp_panel *dp_panel);
  174. };
  175. struct dp_tu_calc_input {
  176. u64 lclk; /* 162, 270, 540 and 810 */
  177. u64 pclk_khz; /* in KHz */
  178. u64 hactive; /* active h-width */
  179. u64 hporch; /* bp + fp + pulse */
  180. int nlanes; /* no.of.lanes */
  181. int bpp; /* bits */
  182. int pixel_enc; /* 444, 420, 422 */
  183. int dsc_en; /* dsc on/off */
  184. int async_en; /* async mode */
  185. int fec_en; /* fec */
  186. int compress_ratio; /* 2:1 = 200, 3:1 = 300, 3.75:1 = 375 */
  187. int num_of_dsc_slices; /* number of slices per line */
  188. };
  189. struct dp_vc_tu_mapping_table {
  190. u32 vic;
  191. u8 lanes;
  192. u8 lrate; /* DP_LINK_RATE -> 162(6), 270(10), 540(20), 810 (30) */
  193. u8 bpp;
  194. u32 valid_boundary_link;
  195. u32 delay_start_link;
  196. bool boundary_moderation_en;
  197. u32 valid_lower_boundary_link;
  198. u32 upper_boundary_count;
  199. u32 lower_boundary_count;
  200. u32 tu_size_minus1;
  201. };
  202. /**
  203. * is_link_rate_valid() - validates the link rate
  204. * @lane_rate: link rate requested by the sink
  205. *
  206. * Returns true if the requested link rate is supported.
  207. */
  208. static inline bool is_link_rate_valid(u32 bw_code)
  209. {
  210. return ((bw_code == DP_LINK_BW_1_62) ||
  211. (bw_code == DP_LINK_BW_2_7) ||
  212. (bw_code == DP_LINK_BW_5_4) ||
  213. (bw_code == DP_LINK_BW_8_1));
  214. }
  215. /**
  216. * dp_link_is_lane_count_valid() - validates the lane count
  217. * @lane_count: lane count requested by the sink
  218. *
  219. * Returns true if the requested lane count is supported.
  220. */
  221. static inline bool is_lane_count_valid(u32 lane_count)
  222. {
  223. return (lane_count == DP_LANE_COUNT_1) ||
  224. (lane_count == DP_LANE_COUNT_2) ||
  225. (lane_count == DP_LANE_COUNT_4);
  226. }
  227. struct dp_panel *dp_panel_get(struct dp_panel_in *in);
  228. void dp_panel_put(struct dp_panel *dp_panel);
  229. void dp_panel_calc_tu_test(struct dp_tu_calc_input *in,
  230. struct dp_vc_tu_mapping_table *tu_table);
  231. #endif /* _DP_PANEL_H_ */