sde_hw_dsc_1_2.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. /* common register */
  100. SDE_REG_WRITE(dsc_c, DSC_CMN_MAIN_CNF, 0);
  101. }
  102. static void sde_hw_dsc_config(struct sde_hw_dsc *hw_dsc,
  103. struct msm_display_dsc_info *dsc, u32 mode,
  104. bool ich_reset_override)
  105. {
  106. struct sde_hw_blk_reg_map *dsc_c;
  107. u32 idx;
  108. u32 data = 0;
  109. u32 slice_count_per_enc;
  110. if (!hw_dsc || !dsc)
  111. return;
  112. if (_dsc_subblk_offset(hw_dsc, SDE_DSC_ENC, &idx))
  113. return;
  114. dsc_c = &hw_dsc->hw;
  115. slice_count_per_enc = dsc->config.slice_count;
  116. if (mode & DSC_MODE_SPLIT_PANEL)
  117. data |= BIT(0);
  118. if (mode & DSC_MODE_MULTIPLEX) {
  119. slice_count_per_enc = dsc->config.slice_count >> 1;
  120. data |= BIT(1);
  121. }
  122. data |= (slice_count_per_enc & 0x3) << 7;
  123. SDE_REG_WRITE(dsc_c, DSC_CMN_MAIN_CNF, data);
  124. data = (dsc->initial_lines & 0xff);
  125. data |= ((mode & DSC_MODE_VIDEO) ? 1 : 0) << 9;
  126. data |= (ich_reset_override ? 1 : 0) << 10;
  127. data |= (_dsc_calc_ob_max_addr(hw_dsc, slice_count_per_enc) << 18);
  128. SDE_REG_WRITE(dsc_c, ENC_DF_CTRL + idx, data);
  129. data = (dsc->config.dsc_version_minor & 0xf) << 28;
  130. if (dsc->config.dsc_version_minor == 0x2) {
  131. if (dsc->config.native_422)
  132. data |= BIT(22);
  133. if (dsc->config.native_420)
  134. data |= BIT(21);
  135. }
  136. data |= (dsc->config.block_pred_enable ? 1 : 0) << 20;
  137. data |= (dsc->config.bits_per_pixel << 10);
  138. data |= (dsc->config.line_buf_depth & 0xf) << 6;
  139. data |= dsc->config.convert_rgb << 4;
  140. data |= dsc->config.bits_per_component & 0xf;
  141. SDE_REG_WRITE(dsc_c, DSC_MAIN_CONF + idx, data);
  142. data = (dsc->config.pic_width & 0xffff) |
  143. ((dsc->config.pic_height & 0xffff) << 16);
  144. SDE_REG_WRITE(dsc_c, DSC_PICTURE_SIZE + idx, data);
  145. data = (dsc->config.slice_width & 0xffff) |
  146. ((dsc->config.slice_height & 0xffff) << 16);
  147. SDE_REG_WRITE(dsc_c, DSC_SLICE_SIZE + idx, data);
  148. SDE_REG_WRITE(dsc_c, DSC_MISC_SIZE + idx,
  149. (dsc->config.slice_chunk_size) & 0xffff);
  150. data = (dsc->config.initial_xmit_delay & 0xffff) |
  151. ((dsc->config.initial_dec_delay & 0x3ff) << 16);
  152. SDE_REG_WRITE(dsc_c, DSC_HRD_DELAYS + idx, data);
  153. SDE_REG_WRITE(dsc_c, DSC_RC_SCALE + idx,
  154. dsc->config.initial_scale_value & 0x3f);
  155. data = (dsc->config.scale_increment_interval & 0xffff) |
  156. ((dsc->config.scale_decrement_interval & 0x7ff) << 16);
  157. SDE_REG_WRITE(dsc_c, DSC_RC_SCALE_INC_DEC + idx, data);
  158. data = (dsc->config.first_line_bpg_offset & 0x1f) |
  159. ((dsc->config.second_line_bpg_offset & 0x1f) << 5);
  160. SDE_REG_WRITE(dsc_c, DSC_RC_OFFSETS_1 + idx, data);
  161. data = (dsc->config.nfl_bpg_offset & 0xffff) |
  162. ((dsc->config.slice_bpg_offset & 0xffff) << 16);
  163. SDE_REG_WRITE(dsc_c, DSC_RC_OFFSETS_2 + idx, data);
  164. data = (dsc->config.initial_offset & 0xffff) |
  165. ((dsc->config.final_offset & 0xffff) << 16);
  166. SDE_REG_WRITE(dsc_c, DSC_RC_OFFSETS_3 + idx, data);
  167. data = (dsc->config.nsl_bpg_offset & 0xffff) |
  168. ((dsc->config.second_line_offset_adj & 0xffff) << 16);
  169. SDE_REG_WRITE(dsc_c, DSC_RC_OFFSETS_4 + idx, data);
  170. data = (dsc->config.flatness_min_qp & 0x1f);
  171. data |= (dsc->config.flatness_max_qp & 0x1f) << 5;
  172. data |= (dsc->det_thresh_flatness & 0xff) << 10;
  173. SDE_REG_WRITE(dsc_c, DSC_FLATNESS_QP + idx, data);
  174. SDE_REG_WRITE(dsc_c, DSC_RC_MODEL_SIZE + idx,
  175. (dsc->config.rc_model_size) & 0xffff);
  176. data = dsc->config.rc_edge_factor & 0xf;
  177. data |= (dsc->config.rc_quant_incr_limit0 & 0x1f) << 8;
  178. data |= (dsc->config.rc_quant_incr_limit1 & 0x1f) << 13;
  179. data |= (dsc->config.rc_tgt_offset_high & 0xf) << 20;
  180. data |= (dsc->config.rc_tgt_offset_low & 0xf) << 24;
  181. SDE_REG_WRITE(dsc_c, DSC_RC_CONFIG + idx, data);
  182. /* program the dsc wrapper */
  183. if (_dsc_subblk_offset(hw_dsc, SDE_DSC_CTL, &idx))
  184. return;
  185. data = BIT(0); /* encoder enable */
  186. if (dsc->config.native_422)
  187. data |= BIT(8);
  188. else if (dsc->config.native_420)
  189. data |= BIT(9);
  190. if (!dsc->config.convert_rgb)
  191. data |= BIT(10);
  192. if (dsc->config.bits_per_component == 8)
  193. data |= BIT(11);
  194. if (mode & DSC_MODE_SPLIT_PANEL)
  195. data |= BIT(12);
  196. if (mode & DSC_MODE_MULTIPLEX)
  197. data |= BIT(13);
  198. if (!(mode & DSC_MODE_VIDEO))
  199. data |= BIT(17);
  200. SDE_REG_WRITE(dsc_c, DSC_CFG + idx, data);
  201. }
  202. static void sde_hw_dsc_config_thresh(struct sde_hw_dsc *hw_dsc,
  203. struct msm_display_dsc_info *dsc)
  204. {
  205. struct sde_hw_blk_reg_map *dsc_c;
  206. u32 idx, off;
  207. int i, j = 0;
  208. struct drm_dsc_rc_range_parameters *rc;
  209. u32 data = 0, min_qp = 0, max_qp = 0, bpg_off = 0;
  210. if (!hw_dsc || !dsc)
  211. return;
  212. if (_dsc_subblk_offset(hw_dsc, SDE_DSC_ENC, &idx))
  213. return;
  214. dsc_c = &hw_dsc->hw;
  215. rc = dsc->config.rc_range_params;
  216. off = 0;
  217. for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++) {
  218. data |= dsc->config.rc_buf_thresh[i] << (8*j);
  219. j++;
  220. if ((j == 4) || (i == DSC_NUM_BUF_RANGES - 2)) {
  221. SDE_REG_WRITE(dsc_c, DSC_RC_BUF_THRESH_0 + idx + off,
  222. data);
  223. off += 4;
  224. j = 0;
  225. data = 0;
  226. }
  227. }
  228. off = 0;
  229. for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
  230. min_qp |= (rc[i].range_min_qp & 0x1f) << 5*j;
  231. max_qp |= (rc[i].range_max_qp & 0x1f) << 5*j;
  232. bpg_off |= (rc[i].range_bpg_offset & 0x3f) << 6*j;
  233. j++;
  234. if (j == 5) {
  235. SDE_REG_WRITE(dsc_c, DSC_RC_MIN_QP_0 + idx + off,
  236. min_qp);
  237. SDE_REG_WRITE(dsc_c, DSC_RC_MAX_QP_0 + idx + off,
  238. max_qp);
  239. SDE_REG_WRITE(dsc_c,
  240. DSC_RC_RANGE_BPG_OFFSETS_0 + idx + off,
  241. bpg_off);
  242. off += 4;
  243. j = 0;
  244. min_qp = 0;
  245. max_qp = 0;
  246. bpg_off = 0;
  247. }
  248. }
  249. }
  250. static void sde_hw_dsc_bind_pingpong_blk(
  251. struct sde_hw_dsc *hw_dsc,
  252. bool enable,
  253. const enum sde_pingpong pp)
  254. {
  255. struct sde_hw_blk_reg_map *dsc_c;
  256. int idx;
  257. int mux_cfg = 0xF; /* Disabled */
  258. if (!hw_dsc)
  259. return;
  260. if (_dsc_subblk_offset(hw_dsc, SDE_DSC_CTL, &idx))
  261. return;
  262. dsc_c = &hw_dsc->hw;
  263. if (enable)
  264. mux_cfg = (pp - PINGPONG_0) & 0x7;
  265. SDE_REG_WRITE(dsc_c, DSC_CTL + idx, mux_cfg);
  266. }
  267. void sde_dsc1_2_setup_ops(struct sde_hw_dsc_ops *ops,
  268. const unsigned long features)
  269. {
  270. ops->dsc_disable = sde_hw_dsc_disable;
  271. ops->dsc_config = sde_hw_dsc_config;
  272. ops->dsc_config_thresh = sde_hw_dsc_config_thresh;
  273. ops->bind_pingpong_blk = sde_hw_dsc_bind_pingpong_blk;
  274. }