sde_hw_dsc_1_2.c 9.8 KB

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