sde_hw_dsc_1_2.c 10 KB

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