dp_catalog.h 9.3 KB

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