dp_catalog.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef _DP_CATALOG_H_
  7. #define _DP_CATALOG_H_
  8. #include <drm/drm_dp_helper.h>
  9. #include <drm/sde_drm.h>
  10. #include "dp_parser.h"
  11. /* interrupts */
  12. #define DP_INTR_HPD BIT(0)
  13. #define DP_INTR_AUX_I2C_DONE BIT(3)
  14. #define DP_INTR_WRONG_ADDR BIT(6)
  15. #define DP_INTR_TIMEOUT BIT(9)
  16. #define DP_INTR_NACK_DEFER BIT(12)
  17. #define DP_INTR_WRONG_DATA_CNT BIT(15)
  18. #define DP_INTR_I2C_NACK BIT(18)
  19. #define DP_INTR_I2C_DEFER BIT(21)
  20. #define DP_INTR_PLL_UNLOCKED BIT(24)
  21. #define DP_INTR_AUX_ERROR BIT(27)
  22. #define DP_INTR_READY_FOR_VIDEO BIT(0)
  23. #define DP_INTR_IDLE_PATTERN_SENT BIT(3)
  24. #define DP_INTR_FRAME_END BIT(6)
  25. #define DP_INTR_CRC_UPDATED BIT(9)
  26. #define DP_INTR_MST_DP0_VCPF_SENT BIT(0)
  27. #define DP_INTR_MST_DP1_VCPF_SENT BIT(3)
  28. #define DP_MAX_TIME_SLOTS 64
  29. /* stream id */
  30. enum dp_stream_id {
  31. DP_STREAM_0,
  32. DP_STREAM_1,
  33. DP_STREAM_MAX,
  34. };
  35. struct dp_catalog_vsc_sdp_colorimetry {
  36. struct dp_sdp_header header;
  37. u8 data[32];
  38. };
  39. struct dp_catalog_aux {
  40. u32 data;
  41. u32 isr;
  42. u32 (*read_data)(struct dp_catalog_aux *aux);
  43. int (*write_data)(struct dp_catalog_aux *aux);
  44. int (*write_trans)(struct dp_catalog_aux *aux);
  45. int (*clear_trans)(struct dp_catalog_aux *aux, bool read);
  46. void (*reset)(struct dp_catalog_aux *aux);
  47. void (*enable)(struct dp_catalog_aux *aux, bool enable);
  48. void (*update_aux_cfg)(struct dp_catalog_aux *aux,
  49. struct dp_aux_cfg *cfg, enum dp_phy_aux_config_type type);
  50. void (*setup)(struct dp_catalog_aux *aux,
  51. struct dp_aux_cfg *aux_cfg);
  52. void (*get_irq)(struct dp_catalog_aux *aux, bool cmd_busy);
  53. void (*clear_hw_interrupts)(struct dp_catalog_aux *aux);
  54. };
  55. struct dp_catalog_ctrl {
  56. u32 isr;
  57. u32 isr5;
  58. void (*state_ctrl)(struct dp_catalog_ctrl *ctrl, u32 state);
  59. void (*config_ctrl)(struct dp_catalog_ctrl *ctrl, u8 ln_cnt);
  60. void (*lane_mapping)(struct dp_catalog_ctrl *ctrl, bool flipped,
  61. char *lane_map);
  62. void (*lane_pnswap)(struct dp_catalog_ctrl *ctrl, u8 ln_pnswap);
  63. void (*mainlink_ctrl)(struct dp_catalog_ctrl *ctrl, bool enable);
  64. void (*set_pattern)(struct dp_catalog_ctrl *ctrl, u32 pattern);
  65. void (*reset)(struct dp_catalog_ctrl *ctrl);
  66. void (*usb_reset)(struct dp_catalog_ctrl *ctrl, bool flip);
  67. bool (*mainlink_ready)(struct dp_catalog_ctrl *ctrl);
  68. void (*enable_irq)(struct dp_catalog_ctrl *ctrl, bool enable);
  69. void (*phy_reset)(struct dp_catalog_ctrl *ctrl);
  70. void (*phy_lane_cfg)(struct dp_catalog_ctrl *ctrl, bool flipped,
  71. u8 lane_cnt);
  72. void (*update_vx_px)(struct dp_catalog_ctrl *ctrl, u8 v_level,
  73. u8 p_level, bool high);
  74. void (*get_interrupt)(struct dp_catalog_ctrl *ctrl);
  75. u32 (*read_hdcp_status)(struct dp_catalog_ctrl *ctrl);
  76. void (*send_phy_pattern)(struct dp_catalog_ctrl *ctrl,
  77. u32 pattern);
  78. u32 (*read_phy_pattern)(struct dp_catalog_ctrl *ctrl);
  79. void (*mst_config)(struct dp_catalog_ctrl *ctrl, bool enable);
  80. void (*trigger_act)(struct dp_catalog_ctrl *ctrl);
  81. void (*read_act_complete_sts)(struct dp_catalog_ctrl *ctrl, bool *sts);
  82. void (*channel_alloc)(struct dp_catalog_ctrl *ctrl,
  83. u32 ch, u32 ch_start_timeslot, u32 tot_ch_cnt);
  84. void (*update_rg)(struct dp_catalog_ctrl *ctrl, u32 ch, u32 x_int,
  85. u32 y_frac_enum);
  86. void (*channel_dealloc)(struct dp_catalog_ctrl *ctrl,
  87. u32 ch, u32 ch_start_timeslot, u32 tot_ch_cnt);
  88. void (*fec_config)(struct dp_catalog_ctrl *ctrl, bool enable);
  89. void (*mainlink_levels)(struct dp_catalog_ctrl *ctrl, u8 lane_cnt);
  90. int (*late_phy_init)(struct dp_catalog_ctrl *ctrl,
  91. u8 lane_cnt, bool flipped);
  92. };
  93. struct dp_catalog_hpd {
  94. void (*config_hpd)(struct dp_catalog_hpd *hpd, bool en);
  95. u32 (*get_interrupt)(struct dp_catalog_hpd *hpd);
  96. };
  97. #define HEADER_BYTE_2_BIT 0
  98. #define PARITY_BYTE_2_BIT 8
  99. #define HEADER_BYTE_1_BIT 16
  100. #define PARITY_BYTE_1_BIT 24
  101. #define HEADER_BYTE_3_BIT 16
  102. #define PARITY_BYTE_3_BIT 24
  103. enum dp_catalog_audio_sdp_type {
  104. DP_AUDIO_SDP_STREAM,
  105. DP_AUDIO_SDP_TIMESTAMP,
  106. DP_AUDIO_SDP_INFOFRAME,
  107. DP_AUDIO_SDP_COPYMANAGEMENT,
  108. DP_AUDIO_SDP_ISRC,
  109. DP_AUDIO_SDP_MAX,
  110. };
  111. enum dp_catalog_audio_header_type {
  112. DP_AUDIO_SDP_HEADER_1,
  113. DP_AUDIO_SDP_HEADER_2,
  114. DP_AUDIO_SDP_HEADER_3,
  115. DP_AUDIO_SDP_HEADER_MAX,
  116. };
  117. struct dp_catalog_audio {
  118. enum dp_catalog_audio_sdp_type sdp_type;
  119. enum dp_catalog_audio_header_type sdp_header;
  120. u32 data;
  121. enum dp_stream_id stream_id;
  122. void (*init)(struct dp_catalog_audio *audio);
  123. void (*enable)(struct dp_catalog_audio *audio);
  124. void (*config_acr)(struct dp_catalog_audio *audio);
  125. void (*config_sdp)(struct dp_catalog_audio *audio);
  126. void (*set_header)(struct dp_catalog_audio *audio);
  127. void (*get_header)(struct dp_catalog_audio *audio);
  128. };
  129. struct dp_dsc_cfg_data {
  130. bool dsc_en;
  131. bool continuous_pps;
  132. char pps[128];
  133. u32 pps_len;
  134. u32 pps_word[32];
  135. u32 pps_word_len;
  136. u8 parity[32];
  137. u8 parity_len;
  138. u32 parity_word[8];
  139. u32 parity_word_len;
  140. u32 slice_per_pkt;
  141. u32 bytes_per_pkt;
  142. u32 eol_byte_num;
  143. u32 be_in_lane;
  144. u32 dto_en;
  145. u32 dto_n;
  146. u32 dto_d;
  147. u32 dto_count;
  148. };
  149. struct dp_catalog_panel {
  150. u32 total;
  151. u32 sync_start;
  152. u32 width_blanking;
  153. u32 dp_active;
  154. u8 *spd_vendor_name;
  155. u8 *spd_product_description;
  156. struct dp_catalog_vsc_sdp_colorimetry vsc_colorimetry;
  157. struct dp_sdp_header dhdr_vsif_sdp;
  158. struct dp_sdp_header shdr_if_sdp;
  159. struct drm_msm_ext_hdr_metadata hdr_meta;
  160. /* TPG */
  161. u32 hsync_period;
  162. u32 vsync_period;
  163. u32 display_v_start;
  164. u32 display_v_end;
  165. u32 v_sync_width;
  166. u32 hsync_ctl;
  167. u32 display_hctl;
  168. /* TU */
  169. u32 dp_tu;
  170. u32 valid_boundary;
  171. u32 valid_boundary2;
  172. u32 misc_val;
  173. enum dp_stream_id stream_id;
  174. bool widebus_en;
  175. struct dp_dsc_cfg_data dsc;
  176. int (*timing_cfg)(struct dp_catalog_panel *panel);
  177. void (*config_hdr)(struct dp_catalog_panel *panel, bool en,
  178. u32 dhdr_max_pkts, bool flush);
  179. void (*config_sdp)(struct dp_catalog_panel *panel, bool en);
  180. int (*set_colorspace)(struct dp_catalog_panel *panel,
  181. bool vsc_supported);
  182. void (*tpg_config)(struct dp_catalog_panel *panel, u32 pattern);
  183. void (*config_spd)(struct dp_catalog_panel *panel);
  184. void (*config_misc)(struct dp_catalog_panel *panel);
  185. void (*config_msa)(struct dp_catalog_panel *panel,
  186. u32 rate, u32 stream_rate_khz);
  187. void (*update_transfer_unit)(struct dp_catalog_panel *panel);
  188. void (*config_ctrl)(struct dp_catalog_panel *panel, u32 cfg);
  189. void (*config_dto)(struct dp_catalog_panel *panel, bool ack);
  190. void (*dsc_cfg)(struct dp_catalog_panel *panel);
  191. void (*pps_flush)(struct dp_catalog_panel *panel);
  192. void (*dhdr_flush)(struct dp_catalog_panel *panel);
  193. bool (*dhdr_busy)(struct dp_catalog_panel *panel);
  194. };
  195. struct dp_catalog;
  196. struct dp_catalog_sub {
  197. u32 (*read)(struct dp_catalog *dp_catalog,
  198. struct dp_io_data *io_data, u32 offset);
  199. void (*write)(struct dp_catalog *dp_catalog,
  200. struct dp_io_data *io_data, u32 offset, u32 data);
  201. void (*put)(struct dp_catalog *catalog);
  202. };
  203. struct dp_catalog_io {
  204. struct dp_io_data *dp_ahb;
  205. struct dp_io_data *dp_aux;
  206. struct dp_io_data *dp_link;
  207. struct dp_io_data *dp_p0;
  208. struct dp_io_data *dp_phy;
  209. struct dp_io_data *dp_ln_tx0;
  210. struct dp_io_data *dp_ln_tx1;
  211. struct dp_io_data *dp_mmss_cc;
  212. struct dp_io_data *dp_pll;
  213. struct dp_io_data *usb3_dp_com;
  214. struct dp_io_data *hdcp_physical;
  215. struct dp_io_data *dp_p1;
  216. struct dp_io_data *dp_tcsr;
  217. };
  218. struct dp_catalog {
  219. struct dp_catalog_aux aux;
  220. struct dp_catalog_ctrl ctrl;
  221. struct dp_catalog_audio audio;
  222. struct dp_catalog_panel panel;
  223. struct dp_catalog_hpd hpd;
  224. struct dp_catalog_sub *sub;
  225. void (*set_exe_mode)(struct dp_catalog *dp_catalog, char *mode);
  226. int (*get_reg_dump)(struct dp_catalog *dp_catalog,
  227. char *mode, u8 **out_buf, u32 *out_buf_len);
  228. };
  229. static inline u8 dp_ecc_get_g0_value(u8 data)
  230. {
  231. u8 c[4];
  232. u8 g[4];
  233. u8 ret_data = 0;
  234. u8 i;
  235. for (i = 0; i < 4; i++)
  236. c[i] = (data >> i) & 0x01;
  237. g[0] = c[3];
  238. g[1] = c[0] ^ c[3];
  239. g[2] = c[1];
  240. g[3] = c[2];
  241. for (i = 0; i < 4; i++)
  242. ret_data = ((g[i] & 0x01) << i) | ret_data;
  243. return ret_data;
  244. }
  245. static inline u8 dp_ecc_get_g1_value(u8 data)
  246. {
  247. u8 c[4];
  248. u8 g[4];
  249. u8 ret_data = 0;
  250. u8 i;
  251. for (i = 0; i < 4; i++)
  252. c[i] = (data >> i) & 0x01;
  253. g[0] = c[0] ^ c[3];
  254. g[1] = c[0] ^ c[1] ^ c[3];
  255. g[2] = c[1] ^ c[2];
  256. g[3] = c[2] ^ c[3];
  257. for (i = 0; i < 4; i++)
  258. ret_data = ((g[i] & 0x01) << i) | ret_data;
  259. return ret_data;
  260. }
  261. static inline u8 dp_header_get_parity(u32 data)
  262. {
  263. u8 x0 = 0;
  264. u8 x1 = 0;
  265. u8 ci = 0;
  266. u8 iData = 0;
  267. u8 i = 0;
  268. u8 parity_byte;
  269. u8 num_byte = (data > 0xFF) ? 8 : 2;
  270. for (i = 0; i < num_byte; i++) {
  271. iData = (data >> i*4) & 0xF;
  272. ci = iData ^ x1;
  273. x1 = x0 ^ dp_ecc_get_g1_value(ci);
  274. x0 = dp_ecc_get_g0_value(ci);
  275. }
  276. parity_byte = x1 | (x0 << 4);
  277. return parity_byte;
  278. }
  279. struct dp_catalog *dp_catalog_get(struct device *dev, struct dp_parser *parser);
  280. void dp_catalog_put(struct dp_catalog *catalog);
  281. struct dp_catalog_sub *dp_catalog_get_v420(struct device *dev,
  282. struct dp_catalog *catalog, struct dp_catalog_io *io);
  283. struct dp_catalog_sub *dp_catalog_get_v200(struct device *dev,
  284. struct dp_catalog *catalog, struct dp_catalog_io *io);
  285. u32 dp_catalog_get_dp_core_version(struct dp_catalog *dp_catalog);
  286. u32 dp_catalog_get_dp_phy_version(struct dp_catalog *dp_catalog);
  287. #endif /* _DP_CATALOG_H_ */