sde_dsc_helper.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2020 The Linux Foundation. All rights reserved.
  4. */
  5. #include "msm_drv.h"
  6. #include "sde_dsc_helper.h"
  7. #include "sde_kms.h"
  8. #define SDE_DSC_PPS_SIZE 128
  9. enum sde_dsc_ratio_type {
  10. DSC_V11_8BPC_8BPP,
  11. DSC_V11_10BPC_8BPP,
  12. DSC_V11_10BPC_10BPP,
  13. DSC_V11_SCR1_8BPC_8BPP,
  14. DSC_V11_SCR1_10BPC_8BPP,
  15. DSC_V11_SCR1_10BPC_10BPP,
  16. DSC_V12_444_8BPC_8BPP = DSC_V11_SCR1_8BPC_8BPP,
  17. DSC_V12_444_10BPC_8BPP = DSC_V11_SCR1_10BPC_8BPP,
  18. DSC_V12_444_10BPC_10BPP = DSC_V11_SCR1_10BPC_10BPP,
  19. DSC_V12_422_8BPC_7BPP,
  20. DSC_V12_422_8BPC_8BPP,
  21. DSC_V12_422_10BPC_7BPP,
  22. DSC_V12_422_10BPC_10BPP,
  23. DSC_V12_420_8BPC_6BPP,
  24. DSC_V12_420_10BPC_6BPP,
  25. DSC_V12_420_10BPC_7_5BPP,
  26. DSC_RATIO_TYPE_MAX
  27. };
  28. static u16 sde_dsc_rc_buf_thresh[DSC_NUM_BUF_RANGES - 1] =
  29. {0x0e, 0x1c, 0x2a, 0x38, 0x46, 0x54,
  30. 0x62, 0x69, 0x70, 0x77, 0x79, 0x7b, 0x7d, 0x7e};
  31. /*
  32. * Rate control - Min QP values for each ratio type in sde_dsc_ratio_type
  33. */
  34. static char sde_dsc_rc_range_min_qp[DSC_RATIO_TYPE_MAX][DSC_NUM_BUF_RANGES] = {
  35. /* DSC v1.1 */
  36. {0, 0, 1, 1, 3, 3, 3, 3, 3, 3, 5, 5, 5, 7, 13},
  37. {0, 4, 5, 5, 7, 7, 7, 7, 7, 7, 9, 9, 9, 11, 17},
  38. {0, 4, 5, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 11, 15},
  39. /* DSC v1.1 SCR and DSC v1.2 RGB 444 */
  40. {0, 0, 1, 1, 3, 3, 3, 3, 3, 3, 5, 5, 5, 9, 12},
  41. {0, 4, 5, 5, 7, 7, 7, 7, 7, 7, 9, 9, 9, 13, 16},
  42. {0, 4, 5, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 11, 15},
  43. /* DSC v1.2 YUV422 */
  44. {0, 0, 1, 1, 3, 3, 3, 3, 3, 3, 5, 5, 5, 7, 10},
  45. {0, 4, 5, 5, 7, 7, 7, 7, 7, 7, 9, 9, 9, 13, 16},
  46. {0, 4, 9, 9, 11, 11, 11, 11, 11, 11, 13, 13, 13, 17, 20},
  47. {0, 2, 3, 4, 5, 5, 5, 6, 6, 7, 8, 8, 9, 11, 12},
  48. /* DSC v1.2 YUV420 */
  49. {0, 0, 1, 1, 3, 3, 3, 3, 3, 3, 5, 5, 5, 7, 10},
  50. {0, 2, 3, 4, 6, 7, 7, 7, 7, 7, 9, 9, 9, 11, 14},
  51. {0, 2, 3, 4, 5, 5, 5, 6, 6, 7, 8, 8, 9, 11, 12},
  52. };
  53. /*
  54. * Rate control - Max QP values for each ratio type in sde_dsc_ratio_type
  55. */
  56. static char sde_dsc_rc_range_max_qp[DSC_RATIO_TYPE_MAX][DSC_NUM_BUF_RANGES] = {
  57. /* DSC v1.1 */
  58. {4, 4, 5, 6, 7, 7, 7, 8, 9, 10, 11, 12, 13, 13, 15},
  59. {4, 8, 9, 10, 11, 11, 11, 12, 13, 14, 15, 16, 17, 17, 19},
  60. {7, 8, 9, 10, 11, 11, 11, 12, 13, 13, 14, 14, 15, 15, 16},
  61. /* DSC v1.1 SCR and DSC v1.2 RGB 444 */
  62. {4, 4, 5, 6, 7, 7, 7, 8, 9, 10, 10, 11, 11, 12, 13},
  63. {8, 8, 9, 10, 11, 11, 11, 12, 13, 14, 14, 15, 15, 16, 17},
  64. {7, 8, 9, 10, 11, 11, 11, 12, 13, 13, 14, 14, 15, 15, 16},
  65. /* DSC v1.2 YUV422 */
  66. {3, 4, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10, 11, 11, 12},
  67. {2, 4, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 10, 11},
  68. {7, 8, 9, 10, 11, 11, 11, 12, 13, 13, 14, 14, 15, 15, 16},
  69. {2, 5, 5, 6, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 13},
  70. /* DSC v1.2 YUV420 */
  71. {2, 4, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 10, 12},
  72. {2, 5, 7, 8, 9, 10, 11, 12, 12, 13, 13, 13, 13, 14, 15},
  73. {2, 5, 5, 6, 6, 7, 7, 8, 9, 9, 10, 11, 11, 12, 13},
  74. };
  75. /*
  76. * Rate control - bpg offset values for each ratio type in sde_dsc_ratio_type
  77. */
  78. static char sde_dsc_rc_range_bpg[DSC_RATIO_TYPE_MAX][DSC_NUM_BUF_RANGES] = {
  79. /* DSC v1.1 */
  80. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -12, -12, -12, -12},
  81. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -12, -12, -12, -12},
  82. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -10, -12, -12, -12},
  83. /* DSC v1.1 SCR and DSC V1.2 RGB 444 */
  84. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -12, -12, -12, -12},
  85. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -12, -12, -12, -12},
  86. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -10, -12, -12, -12},
  87. /* DSC v1.2 YUV422 */
  88. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -10, -12, -12, -12},
  89. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -12, -12, -12, -12},
  90. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -10, -12, -12, -12},
  91. {10, 8, 6, 4, 2, 0, -2, -4, -6, -8, -10, -10, -12, -12, -12},
  92. /* DSC v1.2 YUV420 */
  93. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -12, -12, -12, -12},
  94. {2, 0, 0, -2, -4, -6, -8, -8, -8, -10, -10, -12, -12, -12, -12},
  95. {10, 8, 6, 4, 2, 0, -2, -4, -6, -8, -10, -10, -12, -12, -12},
  96. };
  97. /**
  98. * Maps to lookup the sde_dsc_ratio_type index used in rate control tables
  99. */
  100. static struct sde_dsc_v1_1_table_index_lut {
  101. int scr_ver;
  102. u32 bpc;
  103. u32 bpp;
  104. u32 type;
  105. } sde_dsc_v1_1_index_map[] = {
  106. {0, 8, 8, DSC_V11_8BPC_8BPP},
  107. {0, 10, 8, DSC_V11_10BPC_8BPP},
  108. {0, 10, 10, DSC_V11_10BPC_10BPP},
  109. {1, 8, 8, DSC_V11_SCR1_8BPC_8BPP},
  110. {1, 10, 8, DSC_V11_SCR1_10BPC_8BPP},
  111. {1, 10, 10, DSC_V11_SCR1_10BPC_10BPP},
  112. };
  113. static struct sde_dsc_v1_2_table_index_lut {
  114. u32 fmt;
  115. u32 bpc;
  116. u32 bpp;
  117. u32 type;
  118. } sde_dsc_v1_2_index_map[] = {
  119. {MSM_CHROMA_444, 8, 8, DSC_V12_444_8BPC_8BPP},
  120. {MSM_CHROMA_444, 10, 8, DSC_V12_444_10BPC_8BPP},
  121. {MSM_CHROMA_444, 10, 10, DSC_V12_444_10BPC_10BPP},
  122. {MSM_CHROMA_422, 8, 7, DSC_V12_422_8BPC_7BPP},
  123. {MSM_CHROMA_422, 8, 8, DSC_V12_422_8BPC_8BPP},
  124. {MSM_CHROMA_422, 10, 7, DSC_V12_422_10BPC_7BPP},
  125. {MSM_CHROMA_422, 10, 10, DSC_V12_422_10BPC_10BPP},
  126. {MSM_CHROMA_420, 8, 6, DSC_V12_420_8BPC_6BPP},
  127. {MSM_CHROMA_420, 10, 6, DSC_V12_420_10BPC_6BPP},
  128. };
  129. static int _get_rc_table_index(struct drm_dsc_config *dsc, int scr_ver)
  130. {
  131. u32 bpp, bpc, i, fmt = MSM_CHROMA_444;
  132. if (dsc->dsc_version_major != 0x1) {
  133. SDE_ERROR("unsupported major version %d\n",
  134. dsc->dsc_version_major);
  135. return -EINVAL;
  136. }
  137. bpc = dsc->bits_per_component;
  138. bpp = DSC_BPP(*dsc);
  139. if (dsc->native_422)
  140. fmt = MSM_CHROMA_422;
  141. else if (dsc->native_420)
  142. fmt = MSM_CHROMA_420;
  143. if (dsc->dsc_version_minor == 0x1) {
  144. for (i = 0; i < ARRAY_SIZE(sde_dsc_v1_1_index_map); i++) {
  145. if (bpc == sde_dsc_v1_1_index_map[i].bpc &&
  146. bpp == sde_dsc_v1_1_index_map[i].bpp &&
  147. scr_ver == sde_dsc_v1_1_index_map[i].scr_ver)
  148. return sde_dsc_v1_1_index_map[i].type;
  149. }
  150. } else if (dsc->dsc_version_minor == 0x2) {
  151. for (i = 0; i < ARRAY_SIZE(sde_dsc_v1_2_index_map); i++) {
  152. if (bpc == sde_dsc_v1_2_index_map[i].bpc &&
  153. bpp == sde_dsc_v1_2_index_map[i].bpp &&
  154. fmt == sde_dsc_v1_2_index_map[i].fmt)
  155. return sde_dsc_v1_2_index_map[i].type;
  156. }
  157. }
  158. SDE_ERROR("unsupported DSC v%d.%dr%d, bpc:%d, bpp:%d, fmt:0x%x\n",
  159. dsc->dsc_version_major, dsc->dsc_version_minor,
  160. scr_ver, bpc, bpp, fmt);
  161. return -EINVAL;
  162. }
  163. u8 _get_dsc_v1_2_bpg_offset(struct drm_dsc_config *dsc)
  164. {
  165. u8 bpg_offset = 0;
  166. u8 uncompressed_bpg_rate;
  167. u8 bpp = DSC_BPP(*dsc);
  168. if (dsc->slice_height < 8)
  169. bpg_offset = 2 * (dsc->slice_height - 1);
  170. else if (dsc->slice_height < 20)
  171. bpg_offset = 12;
  172. else if (dsc->slice_height <= 30)
  173. bpg_offset = 13;
  174. else if (dsc->slice_height < 42)
  175. bpg_offset = 14;
  176. else
  177. bpg_offset = 15;
  178. if (dsc->native_422)
  179. uncompressed_bpg_rate = 3 * bpp * 4;
  180. else if (dsc->native_420)
  181. uncompressed_bpg_rate = 3 * bpp;
  182. else
  183. uncompressed_bpg_rate = (3 * bpp + 2) * 3;
  184. if (bpg_offset < (uncompressed_bpg_rate - (3 * bpp)))
  185. return bpg_offset;
  186. else
  187. return (uncompressed_bpg_rate - (3 * bpp));
  188. }
  189. int sde_dsc_populate_dsc_config(struct drm_dsc_config *dsc, int scr_ver) {
  190. int bpp, bpc;
  191. int groups_per_line, groups_total;
  192. int min_rate_buffer_size;
  193. int hrd_delay;
  194. int pre_num_extra_mux_bits, num_extra_mux_bits;
  195. int slice_bits;
  196. int data;
  197. int final_value, final_scale;
  198. int i, ratio_idx;
  199. dsc->rc_model_size = 8192;
  200. if ((dsc->dsc_version_major == 0x1) &&
  201. (dsc->dsc_version_minor == 0x1)) {
  202. if (scr_ver == 0x1)
  203. dsc->first_line_bpg_offset = 15;
  204. else
  205. dsc->first_line_bpg_offset = 12;
  206. } else if (dsc->dsc_version_minor == 0x2) {
  207. dsc->first_line_bpg_offset = _get_dsc_v1_2_bpg_offset(dsc);
  208. }
  209. dsc->rc_edge_factor = 6;
  210. dsc->rc_tgt_offset_high = 3;
  211. dsc->rc_tgt_offset_low = 3;
  212. dsc->simple_422 = 0;
  213. dsc->convert_rgb = 1;
  214. dsc->vbr_enable = 0;
  215. bpp = DSC_BPP(*dsc);
  216. bpc = dsc->bits_per_component;
  217. ratio_idx = _get_rc_table_index(dsc, scr_ver);
  218. if (ratio_idx == -EINVAL)
  219. return ratio_idx;
  220. for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++)
  221. dsc->rc_buf_thresh[i] = sde_dsc_rc_buf_thresh[i];
  222. for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
  223. dsc->rc_range_params[i].range_min_qp =
  224. sde_dsc_rc_range_min_qp[ratio_idx][i];
  225. dsc->rc_range_params[i].range_max_qp =
  226. sde_dsc_rc_range_max_qp[ratio_idx][i];
  227. dsc->rc_range_params[i].range_bpg_offset =
  228. sde_dsc_rc_range_bpg[ratio_idx][i];
  229. }
  230. if (bpp == 8) {
  231. dsc->initial_offset = 6144;
  232. dsc->initial_xmit_delay = 512;
  233. } else if (bpp == 10) {
  234. dsc->initial_offset = 5632;
  235. dsc->initial_xmit_delay = 410;
  236. } else {
  237. dsc->initial_offset = 2048;
  238. dsc->initial_xmit_delay = 341;
  239. }
  240. dsc->line_buf_depth = bpc + 1;
  241. if (bpc == 8) {
  242. dsc->flatness_min_qp = 3;
  243. dsc->flatness_max_qp = 12;
  244. dsc->rc_quant_incr_limit0 = 11;
  245. dsc->rc_quant_incr_limit1 = 11;
  246. dsc->mux_word_size = DSC_MUX_WORD_SIZE_8_10_BPC;
  247. } else if (bpc == 10) { /* 10bpc */
  248. dsc->flatness_min_qp = 7;
  249. dsc->flatness_max_qp = 16;
  250. dsc->rc_quant_incr_limit0 = 15;
  251. dsc->rc_quant_incr_limit1 = 15;
  252. dsc->mux_word_size = DSC_MUX_WORD_SIZE_8_10_BPC;
  253. } else { /* 12 bpc */
  254. dsc->flatness_min_qp = 11;
  255. dsc->flatness_max_qp = 20;
  256. dsc->rc_quant_incr_limit0 = 19;
  257. dsc->rc_quant_incr_limit1 = 19;
  258. dsc->mux_word_size = DSC_MUX_WORD_SIZE_12_BPC;
  259. }
  260. if ((dsc->dsc_version_minor == 0x2) && (dsc->native_420)) {
  261. dsc->second_line_bpg_offset = 12;
  262. dsc->second_line_offset_adj = 512;
  263. dsc->nsl_bpg_offset = 2048 *
  264. (DIV_ROUND_UP(dsc->second_line_bpg_offset,
  265. (dsc->slice_height - 1)));
  266. }
  267. groups_per_line = DIV_ROUND_UP(dsc->slice_width, 3);
  268. dsc->slice_chunk_size = dsc->slice_width * bpp / 8;
  269. if ((dsc->slice_width * bpp) % 8)
  270. dsc->slice_chunk_size++;
  271. /* rbs-min */
  272. min_rate_buffer_size = dsc->rc_model_size - dsc->initial_offset +
  273. dsc->initial_xmit_delay * bpp +
  274. groups_per_line * dsc->first_line_bpg_offset;
  275. hrd_delay = DIV_ROUND_UP(min_rate_buffer_size, bpp);
  276. dsc->initial_dec_delay = hrd_delay - dsc->initial_xmit_delay;
  277. dsc->initial_scale_value = 8 * dsc->rc_model_size /
  278. (dsc->rc_model_size - dsc->initial_offset);
  279. slice_bits = 8 * dsc->slice_chunk_size * dsc->slice_height;
  280. groups_total = groups_per_line * dsc->slice_height;
  281. data = dsc->first_line_bpg_offset * 2048;
  282. dsc->nfl_bpg_offset = DIV_ROUND_UP(data, (dsc->slice_height - 1));
  283. pre_num_extra_mux_bits = 3 * (dsc->mux_word_size + (4 * bpc + 4) - 2);
  284. num_extra_mux_bits = pre_num_extra_mux_bits - (dsc->mux_word_size -
  285. ((slice_bits - pre_num_extra_mux_bits) % dsc->mux_word_size));
  286. data = 2048 * (dsc->rc_model_size - dsc->initial_offset
  287. + num_extra_mux_bits);
  288. dsc->slice_bpg_offset = DIV_ROUND_UP(data, groups_total);
  289. data = dsc->initial_xmit_delay * bpp;
  290. final_value = dsc->rc_model_size - data + num_extra_mux_bits;
  291. final_scale = 8 * dsc->rc_model_size /
  292. (dsc->rc_model_size - final_value);
  293. dsc->final_offset = final_value;
  294. data = (final_scale - 9) * (dsc->nfl_bpg_offset +
  295. dsc->slice_bpg_offset);
  296. dsc->scale_increment_interval = (2048 * dsc->final_offset) / data;
  297. dsc->scale_decrement_interval = groups_per_line /
  298. (dsc->initial_scale_value - 8);
  299. return 0;
  300. }
  301. int sde_dsc_populate_dsc_private_params(struct msm_display_dsc_info *dsc_info,
  302. int intf_width)
  303. {
  304. int mod_offset;
  305. int slice_per_pkt, slice_per_intf;
  306. int bytes_in_slice, total_bytes_per_intf;
  307. u16 bpp;
  308. u32 bytes_in_dsc_pair;
  309. u32 total_bytes_in_dsc_pair;
  310. if (!dsc_info || !dsc_info->config.slice_width ||
  311. !dsc_info->config.slice_height ||
  312. intf_width < dsc_info->config.slice_width) {
  313. SDE_ERROR("invalid input, intf_width=%d slice_width=%d\n",
  314. intf_width, dsc_info ? dsc_info->config.slice_width :
  315. -1);
  316. return -EINVAL;
  317. }
  318. mod_offset = dsc_info->config.slice_width % 3;
  319. switch (mod_offset) {
  320. case 0:
  321. dsc_info->slice_last_group_size = 2;
  322. break;
  323. case 1:
  324. dsc_info->slice_last_group_size = 0;
  325. break;
  326. case 2:
  327. dsc_info->slice_last_group_size = 1;
  328. break;
  329. default:
  330. break;
  331. }
  332. dsc_info->det_thresh_flatness =
  333. 2 << (dsc_info->config.bits_per_component - 8);
  334. slice_per_pkt = dsc_info->slice_per_pkt;
  335. slice_per_intf = DIV_ROUND_UP(intf_width,
  336. dsc_info->config.slice_width);
  337. /*
  338. * If slice_per_pkt is greater than slice_per_intf then default to 1.
  339. * This can happen during partial update.
  340. */
  341. if (slice_per_pkt > slice_per_intf)
  342. slice_per_pkt = 1;
  343. bpp = DSC_BPP(dsc_info->config);
  344. bytes_in_slice = DIV_ROUND_UP(dsc_info->config.slice_width *
  345. bpp, 8);
  346. total_bytes_per_intf = bytes_in_slice * slice_per_intf;
  347. dsc_info->eol_byte_num = total_bytes_per_intf % 3;
  348. dsc_info->pclk_per_line = DIV_ROUND_UP(total_bytes_per_intf, 3);
  349. dsc_info->bytes_in_slice = bytes_in_slice;
  350. dsc_info->bytes_per_pkt = bytes_in_slice * slice_per_pkt;
  351. dsc_info->pkt_per_line = slice_per_intf / slice_per_pkt;
  352. bytes_in_dsc_pair = DIV_ROUND_UP(bytes_in_slice * 2, 3);
  353. if (bytes_in_dsc_pair % 8) {
  354. dsc_info->dsc_4hsmerge_padding = 8 - (bytes_in_dsc_pair % 8);
  355. total_bytes_in_dsc_pair = bytes_in_dsc_pair +
  356. dsc_info->dsc_4hsmerge_padding;
  357. if (total_bytes_in_dsc_pair % 16)
  358. dsc_info->dsc_4hsmerge_alignment = 16 -
  359. (total_bytes_in_dsc_pair % 16);
  360. }
  361. return 0;
  362. }
  363. int sde_dsc_create_pps_buf_cmd(struct msm_display_dsc_info *dsc_info,
  364. char *buf, int pps_id, u32 len)
  365. {
  366. struct drm_dsc_config *dsc = &dsc_info->config;
  367. char *bp = buf;
  368. char data;
  369. u32 i, bpp;
  370. if (len < SDE_DSC_PPS_SIZE)
  371. return -EINVAL;
  372. memset(buf, 0, len);
  373. /* pps0 */
  374. *bp++ = (dsc->dsc_version_minor |
  375. dsc->dsc_version_major << 4);
  376. *bp++ = (pps_id & 0xff); /* pps1 */
  377. bp++; /* pps2, reserved */
  378. data = dsc->line_buf_depth & 0x0f;
  379. data |= ((dsc->bits_per_component & 0xf) << DSC_PPS_BPC_SHIFT);
  380. *bp++ = data; /* pps3 */
  381. bpp = dsc->bits_per_pixel;
  382. data = (bpp >> DSC_PPS_MSB_SHIFT);
  383. data &= 0x03; /* upper two bits */
  384. data |= ((dsc->block_pred_enable & 0x1) << 5);
  385. data |= ((dsc->convert_rgb & 0x1) << 4);
  386. data |= ((dsc->simple_422 & 0x1) << 3);
  387. data |= ((dsc->vbr_enable & 0x1) << 2);
  388. *bp++ = data; /* pps4 */
  389. *bp++ = (bpp & DSC_PPS_LSB_MASK); /* pps5 */
  390. *bp++ = ((dsc->pic_height >> 8) & 0xff); /* pps6 */
  391. *bp++ = (dsc->pic_height & 0x0ff); /* pps7 */
  392. *bp++ = ((dsc->pic_width >> 8) & 0xff); /* pps8 */
  393. *bp++ = (dsc->pic_width & 0x0ff); /* pps9 */
  394. *bp++ = ((dsc->slice_height >> 8) & 0xff);/* pps10 */
  395. *bp++ = (dsc->slice_height & 0x0ff); /* pps11 */
  396. *bp++ = ((dsc->slice_width >> 8) & 0xff); /* pps12 */
  397. *bp++ = (dsc->slice_width & 0x0ff); /* pps13 */
  398. *bp++ = ((dsc->slice_chunk_size >> 8) & 0xff);/* pps14 */
  399. *bp++ = (dsc->slice_chunk_size & 0x0ff); /* pps15 */
  400. *bp++ = (dsc->initial_xmit_delay >> 8) & 0x3; /* pps16 */
  401. *bp++ = (dsc->initial_xmit_delay & 0xff);/* pps17 */
  402. *bp++ = ((dsc->initial_dec_delay >> 8) & 0xff); /* pps18 */
  403. *bp++ = (dsc->initial_dec_delay & 0xff);/* pps19 */
  404. bp++; /* pps20, reserved */
  405. *bp++ = (dsc->initial_scale_value & 0x3f); /* pps21 */
  406. *bp++ = ((dsc->scale_increment_interval >> 8) & 0xff); /* pps22 */
  407. *bp++ = (dsc->scale_increment_interval & 0xff); /* pps23 */
  408. *bp++ = ((dsc->scale_decrement_interval >> 8) & 0xf); /* pps24 */
  409. *bp++ = (dsc->scale_decrement_interval & 0x0ff);/* pps25 */
  410. bp++; /* pps26, reserved */
  411. *bp++ = (dsc->first_line_bpg_offset & 0x1f);/* pps27 */
  412. *bp++ = ((dsc->nfl_bpg_offset >> 8) & 0xff);/* pps28 */
  413. *bp++ = (dsc->nfl_bpg_offset & 0x0ff); /* pps29 */
  414. *bp++ = ((dsc->slice_bpg_offset >> 8) & 0xff);/* pps30 */
  415. *bp++ = (dsc->slice_bpg_offset & 0x0ff);/* pps31 */
  416. *bp++ = ((dsc->initial_offset >> 8) & 0xff);/* pps32 */
  417. *bp++ = (dsc->initial_offset & 0x0ff); /* pps33 */
  418. *bp++ = ((dsc->final_offset >> 8) & 0xff);/* pps34 */
  419. *bp++ = (dsc->final_offset & 0x0ff); /* pps35 */
  420. *bp++ = (dsc->flatness_min_qp & 0x1f); /* pps36 */
  421. *bp++ = (dsc->flatness_max_qp & 0x1f); /* pps37 */
  422. *bp++ = ((dsc->rc_model_size >> 8) & 0xff);/* pps38 */
  423. *bp++ = (dsc->rc_model_size & 0x0ff); /* pps39 */
  424. *bp++ = (dsc->rc_edge_factor & 0x0f); /* pps40 */
  425. *bp++ = (dsc->rc_quant_incr_limit0 & 0x1f); /* pps41 */
  426. *bp++ = (dsc->rc_quant_incr_limit1 & 0x1f); /* pps42 */
  427. data = ((dsc->rc_tgt_offset_high & 0xf) << 4);
  428. data |= (dsc->rc_tgt_offset_low & 0x0f);
  429. *bp++ = data; /* pps43 */
  430. for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++)
  431. *bp++ = (dsc->rc_buf_thresh[i] & 0xff); /* pps44 - pps57 */
  432. for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
  433. /* pps58 - pps87 */
  434. data = (dsc->rc_range_params[i].range_min_qp & 0x1f);
  435. data <<= 3;
  436. data |= ((dsc->rc_range_params[i].range_max_qp >> 2) & 0x07);
  437. *bp++ = data;
  438. data = (dsc->rc_range_params[i].range_max_qp & 0x03);
  439. data <<= 6;
  440. data |= (dsc->rc_range_params[i].range_bpg_offset & 0x3f);
  441. *bp++ = data;
  442. }
  443. if (dsc->dsc_version_minor == 0x2) {
  444. if (dsc->native_422)
  445. data = BIT(0);
  446. else if (dsc->native_420)
  447. data = BIT(1);
  448. *bp++ = data; /* pps88 */
  449. *bp++ = dsc->second_line_bpg_offset; /* pps89 */
  450. *bp++ = ((dsc->nsl_bpg_offset >> 8) & 0xff);/* pps90 */
  451. *bp++ = (dsc->nsl_bpg_offset & 0x0ff); /* pps91 */
  452. *bp++ = ((dsc->second_line_offset_adj >> 8) & 0xff); /* pps92*/
  453. *bp++ = (dsc->second_line_offset_adj & 0x0ff); /* pps93 */
  454. /* rest bytes are reserved and set to 0 */
  455. }
  456. return 0;
  457. }