dp_catalog.h 8.9 KB

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