dp_catalog.h 8.9 KB

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