sde_hw_dsc_1_2.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include "sde_hw_mdss.h"
  6. #include "sde_hwio.h"
  7. #include "sde_hw_catalog.h"
  8. #include "sde_hw_dsc.h"
  9. #include "sde_hw_pingpong.h"
  10. #include "sde_dbg.h"
  11. #include "sde_kms.h"
  12. #define DSC_CMN_MAIN_CNF 0x00
  13. /* SDE_DSC_ENC regsiter offsets */
  14. #define ENC_DF_CTRL 0x00
  15. #define ENC_GENERAL_STATUS 0x04
  16. #define ENC_HSLICE_STATUS 0x08
  17. #define ENC_OUT_STATUS 0x0C
  18. #define ENC_INT_STAT 0x10
  19. #define ENC_INT_CLR 0x14
  20. #define ENC_INT_MASK 0x18
  21. #define DSC_MAIN_CONF 0x30
  22. #define DSC_PICTURE_SIZE 0x34
  23. #define DSC_SLICE_SIZE 0x38
  24. #define DSC_MISC_SIZE 0x3C
  25. #define DSC_HRD_DELAYS 0x40
  26. #define DSC_RC_SCALE 0x44
  27. #define DSC_RC_SCALE_INC_DEC 0x48
  28. #define DSC_RC_OFFSETS_1 0x4C
  29. #define DSC_RC_OFFSETS_2 0x50
  30. #define DSC_RC_OFFSETS_3 0x54
  31. #define DSC_RC_OFFSETS_4 0x58
  32. #define DSC_FLATNESS_QP 0x5C
  33. #define DSC_RC_MODEL_SIZE 0x60
  34. #define DSC_RC_CONFIG 0x64
  35. #define DSC_RC_BUF_THRESH_0 0x68
  36. #define DSC_RC_BUF_THRESH_1 0x6C
  37. #define DSC_RC_BUF_THRESH_2 0x70
  38. #define DSC_RC_BUF_THRESH_3 0x74
  39. #define DSC_RC_MIN_QP_0 0x78
  40. #define DSC_RC_MIN_QP_1 0x7C
  41. #define DSC_RC_MIN_QP_2 0x80
  42. #define DSC_RC_MAX_QP_0 0x84
  43. #define DSC_RC_MAX_QP_1 0x88
  44. #define DSC_RC_MAX_QP_2 0x8C
  45. #define DSC_RC_RANGE_BPG_OFFSETS_0 0x90
  46. #define DSC_RC_RANGE_BPG_OFFSETS_1 0x94
  47. #define DSC_RC_RANGE_BPG_OFFSETS_2 0x98
  48. /* SDE_DSC_CTL regsiter offsets */
  49. #define DSC_CTL 0x00
  50. #define DSC_CFG 0x04
  51. #define DSC_DATA_IN_SWAP 0x08
  52. #define DSC_CLK_CTRL 0x0C
  53. static int _dsc_calc_ob_max_addr(struct sde_hw_dsc *hw_dsc, int num_ss)
  54. {
  55. enum sde_dsc idx;
  56. idx = hw_dsc->idx;
  57. if ((idx == DSC_0) || (idx == DSC_1)) {
  58. if (num_ss == 1)
  59. return 2399;
  60. else if (num_ss == 2)
  61. return 1199;
  62. } else if ((idx == DSC_2) || (idx == DSC_3)) {
  63. if (num_ss == 1)
  64. return 1199;
  65. else if (num_ss == 2)
  66. return 599;
  67. }
  68. return 0;
  69. }
  70. static inline _dsc_subblk_offset(struct sde_hw_dsc *hw_dsc, int s_id,
  71. u32 *idx)
  72. {
  73. const struct sde_dsc_sub_blks *sblk;
  74. if (!hw_dsc)
  75. return -EINVAL;
  76. sblk = hw_dsc->caps->sblk;
  77. switch (s_id) {
  78. case SDE_DSC_ENC:
  79. *idx = sblk->enc.base;
  80. break;
  81. case SDE_DSC_CTL:
  82. *idx = sblk->ctl.base;
  83. break;
  84. default:
  85. return -EINVAL;
  86. }
  87. return 0;
  88. }
  89. static void sde_hw_dsc_disable(struct sde_hw_dsc *hw_dsc)
  90. {
  91. struct sde_hw_blk_reg_map *dsc_c;
  92. u32 idx;
  93. if (!hw_dsc)
  94. return;
  95. if (_dsc_subblk_offset(hw_dsc, SDE_DSC_CTL, &idx))
  96. return;
  97. dsc_c = &hw_dsc->hw;
  98. SDE_REG_WRITE(dsc_c, DSC_CFG + idx, 0);
  99. if (_dsc_subblk_offset(hw_dsc, SDE_DSC_ENC, &idx))
  100. return;
  101. SDE_REG_WRITE(dsc_c, ENC_DF_CTRL + idx, 0);
  102. SDE_REG_WRITE(dsc_c, DSC_MAIN_CONF + idx, 0);
  103. }
  104. static void sde_hw_dsc_config(struct sde_hw_dsc *hw_dsc,
  105. struct msm_display_dsc_info *dsc, u32 mode,
  106. bool ich_reset_override)
  107. {
  108. struct sde_hw_blk_reg_map *dsc_c;
  109. u32 idx;
  110. u32 data = 0;
  111. u32 slice_count_per_enc;
  112. if (!hw_dsc || !dsc)
  113. return;
  114. if (_dsc_subblk_offset(hw_dsc, SDE_DSC_ENC, &idx))
  115. return;
  116. dsc_c = &hw_dsc->hw;
  117. slice_count_per_enc = dsc->config.slice_count;
  118. if (mode & DSC_MODE_SPLIT_PANEL)
  119. data |= BIT(0);
  120. if (mode & DSC_MODE_MULTIPLEX)
  121. data |= BIT(1);
  122. if (dsc->dsc_4hsmerge_en)
  123. slice_count_per_enc = dsc->config.slice_count >> 2;
  124. else if ((mode & DSC_MODE_MULTIPLEX) || (dsc->half_panel_pu))
  125. slice_count_per_enc = dsc->config.slice_count >> 1;
  126. data |= (slice_count_per_enc & 0x3) << 7;
  127. SDE_REG_WRITE(dsc_c, DSC_CMN_MAIN_CNF, data);
  128. data = (dsc->initial_lines & 0xff);
  129. data |= ((mode & DSC_MODE_VIDEO) ? 1 : 0) << 9;
  130. if (ich_reset_override)
  131. data |= 0xC00; // set bit 10 and 11
  132. data |= (_dsc_calc_ob_max_addr(hw_dsc, slice_count_per_enc) << 18);
  133. SDE_REG_WRITE(dsc_c, ENC_DF_CTRL + idx, data);
  134. data = (dsc->config.dsc_version_minor & 0xf) << 28;
  135. if (dsc->config.dsc_version_minor == 0x2) {
  136. if (dsc->config.native_422)
  137. data |= BIT(22);
  138. if (dsc->config.native_420)
  139. data |= BIT(21);
  140. }
  141. data |= (dsc->config.block_pred_enable ? 1 : 0) << 20;
  142. data |= (dsc->config.bits_per_pixel << 10);
  143. data |= (dsc->config.line_buf_depth & 0xf) << 6;
  144. data |= dsc->config.convert_rgb << 4;
  145. data |= dsc->config.bits_per_component & 0xf;
  146. SDE_REG_WRITE(dsc_c, DSC_MAIN_CONF + idx, data);
  147. data = (dsc->config.pic_width & 0xffff) |
  148. ((dsc->config.pic_height & 0xffff) << 16);
  149. SDE_REG_WRITE(dsc_c, DSC_PICTURE_SIZE + idx, data);
  150. data = (dsc->config.slice_width & 0xffff) |
  151. ((dsc->config.slice_height & 0xffff) << 16);
  152. SDE_REG_WRITE(dsc_c, DSC_SLICE_SIZE + idx, data);
  153. SDE_REG_WRITE(dsc_c, DSC_MISC_SIZE + idx,
  154. (dsc->config.slice_chunk_size) & 0xffff);
  155. data = (dsc->config.initial_xmit_delay & 0xffff) |
  156. ((dsc->config.initial_dec_delay & 0xffff) << 16);
  157. SDE_REG_WRITE(dsc_c, DSC_HRD_DELAYS + idx, data);
  158. SDE_REG_WRITE(dsc_c, DSC_RC_SCALE + idx,
  159. dsc->config.initial_scale_value & 0x3f);
  160. data = (dsc->config.scale_increment_interval & 0xffff) |
  161. ((dsc->config.scale_decrement_interval & 0x7ff) << 16);
  162. SDE_REG_WRITE(dsc_c, DSC_RC_SCALE_INC_DEC + idx, data);
  163. data = (dsc->config.first_line_bpg_offset & 0x1f) |
  164. ((dsc->config.second_line_bpg_offset & 0x1f) << 5);
  165. SDE_REG_WRITE(dsc_c, DSC_RC_OFFSETS_1 + idx, data);
  166. data = (dsc->config.nfl_bpg_offset & 0xffff) |
  167. ((dsc->config.slice_bpg_offset & 0xffff) << 16);
  168. SDE_REG_WRITE(dsc_c, DSC_RC_OFFSETS_2 + idx, data);
  169. data = (dsc->config.initial_offset & 0xffff) |
  170. ((dsc->config.final_offset & 0xffff) << 16);
  171. SDE_REG_WRITE(dsc_c, DSC_RC_OFFSETS_3 + idx, data);
  172. data = (dsc->config.nsl_bpg_offset & 0xffff) |
  173. ((dsc->config.second_line_offset_adj & 0xffff) << 16);
  174. SDE_REG_WRITE(dsc_c, DSC_RC_OFFSETS_4 + idx, data);
  175. data = (dsc->config.flatness_min_qp & 0x1f);
  176. data |= (dsc->config.flatness_max_qp & 0x1f) << 5;
  177. data |= (dsc->det_thresh_flatness & 0xff) << 10;
  178. SDE_REG_WRITE(dsc_c, DSC_FLATNESS_QP + idx, data);
  179. SDE_REG_WRITE(dsc_c, DSC_RC_MODEL_SIZE + idx,
  180. (dsc->config.rc_model_size) & 0xffff);
  181. data = dsc->config.rc_edge_factor & 0xf;
  182. data |= (dsc->config.rc_quant_incr_limit0 & 0x1f) << 8;
  183. data |= (dsc->config.rc_quant_incr_limit1 & 0x1f) << 13;
  184. data |= (dsc->config.rc_tgt_offset_high & 0xf) << 20;
  185. data |= (dsc->config.rc_tgt_offset_low & 0xf) << 24;
  186. SDE_REG_WRITE(dsc_c, DSC_RC_CONFIG + idx, data);
  187. /* program the dsc wrapper */
  188. if (_dsc_subblk_offset(hw_dsc, SDE_DSC_CTL, &idx))
  189. return;
  190. data = BIT(0); /* encoder enable */
  191. if (dsc->config.native_422)
  192. data |= BIT(8);
  193. else if (dsc->config.native_420)
  194. data |= BIT(9);
  195. if (!dsc->config.convert_rgb)
  196. data |= BIT(10);
  197. if (dsc->config.bits_per_component == 8)
  198. data |= BIT(11);
  199. if (mode & DSC_MODE_SPLIT_PANEL)
  200. data |= BIT(12);
  201. if (mode & DSC_MODE_MULTIPLEX)
  202. data |= BIT(13);
  203. if (!(mode & DSC_MODE_VIDEO))
  204. data |= BIT(17);
  205. if (dsc->dsc_4hsmerge_en) {
  206. data |= dsc->dsc_4hsmerge_padding << 18;
  207. data |= dsc->dsc_4hsmerge_alignment << 22;
  208. data |= BIT(16);
  209. }
  210. SDE_REG_WRITE(dsc_c, DSC_CFG + idx, data);
  211. }
  212. static void sde_hw_dsc_config_thresh(struct sde_hw_dsc *hw_dsc,
  213. struct msm_display_dsc_info *dsc)
  214. {
  215. struct sde_hw_blk_reg_map *dsc_c;
  216. u32 idx, off;
  217. int i, j = 0;
  218. struct drm_dsc_rc_range_parameters *rc;
  219. u32 data = 0, min_qp = 0, max_qp = 0, bpg_off = 0;
  220. if (!hw_dsc || !dsc)
  221. return;
  222. if (_dsc_subblk_offset(hw_dsc, SDE_DSC_ENC, &idx))
  223. return;
  224. dsc_c = &hw_dsc->hw;
  225. rc = dsc->config.rc_range_params;
  226. off = 0;
  227. for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++) {
  228. data |= dsc->config.rc_buf_thresh[i] << (8*j);
  229. j++;
  230. if ((j == 4) || (i == DSC_NUM_BUF_RANGES - 2)) {
  231. SDE_REG_WRITE(dsc_c, DSC_RC_BUF_THRESH_0 + idx + off,
  232. data);
  233. off += 4;
  234. j = 0;
  235. data = 0;
  236. }
  237. }
  238. off = 0;
  239. for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
  240. min_qp |= (rc[i].range_min_qp & 0x1f) << 5*j;
  241. max_qp |= (rc[i].range_max_qp & 0x1f) << 5*j;
  242. bpg_off |= (rc[i].range_bpg_offset & 0x3f) << 6*j;
  243. j++;
  244. if (j == 5) {
  245. SDE_REG_WRITE(dsc_c, DSC_RC_MIN_QP_0 + idx + off,
  246. min_qp);
  247. SDE_REG_WRITE(dsc_c, DSC_RC_MAX_QP_0 + idx + off,
  248. max_qp);
  249. SDE_REG_WRITE(dsc_c,
  250. DSC_RC_RANGE_BPG_OFFSETS_0 + idx + off,
  251. bpg_off);
  252. off += 4;
  253. j = 0;
  254. min_qp = 0;
  255. max_qp = 0;
  256. bpg_off = 0;
  257. }
  258. }
  259. }
  260. static void sde_hw_dsc_bind_pingpong_blk(
  261. struct sde_hw_dsc *hw_dsc,
  262. bool enable,
  263. const enum sde_pingpong pp)
  264. {
  265. struct sde_hw_blk_reg_map *dsc_c;
  266. int idx;
  267. int mux_cfg = 0xF; /* Disabled */
  268. if (!hw_dsc)
  269. return;
  270. if (_dsc_subblk_offset(hw_dsc, SDE_DSC_CTL, &idx))
  271. return;
  272. dsc_c = &hw_dsc->hw;
  273. if (enable)
  274. mux_cfg = (pp - PINGPONG_0) & 0x7;
  275. SDE_REG_WRITE(dsc_c, DSC_CTL + idx, mux_cfg);
  276. }
  277. void sde_dsc1_2_setup_ops(struct sde_hw_dsc_ops *ops,
  278. const unsigned long features)
  279. {
  280. ops->dsc_disable = sde_hw_dsc_disable;
  281. ops->dsc_config = sde_hw_dsc_config;
  282. ops->dsc_config_thresh = sde_hw_dsc_config_thresh;
  283. ops->bind_pingpong_blk = sde_hw_dsc_bind_pingpong_blk;
  284. }