sde_hw_dsc_1_2.c 9.0 KB

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