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