drm_dsc_helper.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565
  1. // SPDX-License-Identifier: MIT
  2. /*
  3. * Copyright © 2018 Intel Corp
  4. *
  5. * Author:
  6. * Manasi Navare <manasi.d.navare@intel.com>
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/errno.h>
  12. #include <linux/byteorder/generic.h>
  13. #include <drm/display/drm_dp_helper.h>
  14. #include <drm/display/drm_dsc_helper.h>
  15. #include <drm/drm_fixed.h>
  16. #include <drm/drm_print.h>
  17. /**
  18. * DOC: dsc helpers
  19. *
  20. * VESA specification for DP 1.4 adds a new feature called Display Stream
  21. * Compression (DSC) used to compress the pixel bits before sending it on
  22. * DP/eDP/MIPI DSI interface. DSC is required to be enabled so that the existing
  23. * display interfaces can support high resolutions at higher frames rates uisng
  24. * the maximum available link capacity of these interfaces.
  25. *
  26. * These functions contain some common logic and helpers to deal with VESA
  27. * Display Stream Compression standard required for DSC on Display Port/eDP or
  28. * MIPI display interfaces.
  29. */
  30. /**
  31. * drm_dsc_dp_pps_header_init() - Initializes the PPS Header
  32. * for DisplayPort as per the DP 1.4 spec.
  33. * @pps_header: Secondary data packet header for DSC Picture
  34. * Parameter Set as defined in &struct dp_sdp_header
  35. *
  36. * DP 1.4 spec defines the secondary data packet for sending the
  37. * picture parameter infoframes from the source to the sink.
  38. * This function populates the SDP header defined in
  39. * &struct dp_sdp_header.
  40. */
  41. void drm_dsc_dp_pps_header_init(struct dp_sdp_header *pps_header)
  42. {
  43. memset(pps_header, 0, sizeof(*pps_header));
  44. pps_header->HB1 = DP_SDP_PPS;
  45. pps_header->HB2 = DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1;
  46. }
  47. EXPORT_SYMBOL(drm_dsc_dp_pps_header_init);
  48. /**
  49. * drm_dsc_dp_rc_buffer_size - get rc buffer size in bytes
  50. * @rc_buffer_block_size: block size code, according to DPCD offset 62h
  51. * @rc_buffer_size: number of blocks - 1, according to DPCD offset 63h
  52. *
  53. * return:
  54. * buffer size in bytes, or 0 on invalid input
  55. */
  56. int drm_dsc_dp_rc_buffer_size(u8 rc_buffer_block_size, u8 rc_buffer_size)
  57. {
  58. int size = 1024 * (rc_buffer_size + 1);
  59. switch (rc_buffer_block_size) {
  60. case DP_DSC_RC_BUF_BLK_SIZE_1:
  61. return 1 * size;
  62. case DP_DSC_RC_BUF_BLK_SIZE_4:
  63. return 4 * size;
  64. case DP_DSC_RC_BUF_BLK_SIZE_16:
  65. return 16 * size;
  66. case DP_DSC_RC_BUF_BLK_SIZE_64:
  67. return 64 * size;
  68. default:
  69. return 0;
  70. }
  71. }
  72. EXPORT_SYMBOL(drm_dsc_dp_rc_buffer_size);
  73. /**
  74. * drm_dsc_pps_payload_pack() - Populates the DSC PPS
  75. *
  76. * @pps_payload:
  77. * Bitwise struct for DSC Picture Parameter Set. This is defined
  78. * by &struct drm_dsc_picture_parameter_set
  79. * @dsc_cfg:
  80. * DSC Configuration data filled by driver as defined by
  81. * &struct drm_dsc_config
  82. *
  83. * DSC source device sends a picture parameter set (PPS) containing the
  84. * information required by the sink to decode the compressed frame. Driver
  85. * populates the DSC PPS struct using the DSC configuration parameters in
  86. * the order expected by the DSC Display Sink device. For the DSC, the sink
  87. * device expects the PPS payload in big endian format for fields
  88. * that span more than 1 byte.
  89. */
  90. void drm_dsc_pps_payload_pack(struct drm_dsc_picture_parameter_set *pps_payload,
  91. const struct drm_dsc_config *dsc_cfg)
  92. {
  93. int i;
  94. /* Protect against someone accidentally changing struct size */
  95. BUILD_BUG_ON(sizeof(*pps_payload) !=
  96. DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1 + 1);
  97. memset(pps_payload, 0, sizeof(*pps_payload));
  98. /* PPS 0 */
  99. pps_payload->dsc_version =
  100. dsc_cfg->dsc_version_minor |
  101. dsc_cfg->dsc_version_major << DSC_PPS_VERSION_MAJOR_SHIFT;
  102. /* PPS 1, 2 is 0 */
  103. /* PPS 3 */
  104. pps_payload->pps_3 =
  105. dsc_cfg->line_buf_depth |
  106. dsc_cfg->bits_per_component << DSC_PPS_BPC_SHIFT;
  107. /* PPS 4 */
  108. pps_payload->pps_4 =
  109. ((dsc_cfg->bits_per_pixel & DSC_PPS_BPP_HIGH_MASK) >>
  110. DSC_PPS_MSB_SHIFT) |
  111. dsc_cfg->vbr_enable << DSC_PPS_VBR_EN_SHIFT |
  112. dsc_cfg->simple_422 << DSC_PPS_SIMPLE422_SHIFT |
  113. dsc_cfg->convert_rgb << DSC_PPS_CONVERT_RGB_SHIFT |
  114. dsc_cfg->block_pred_enable << DSC_PPS_BLOCK_PRED_EN_SHIFT;
  115. /* PPS 5 */
  116. pps_payload->bits_per_pixel_low =
  117. (dsc_cfg->bits_per_pixel & DSC_PPS_LSB_MASK);
  118. /*
  119. * The DSC panel expects the PPS packet to have big endian format
  120. * for data spanning 2 bytes. Use a macro cpu_to_be16() to convert
  121. * to big endian format. If format is little endian, it will swap
  122. * bytes to convert to Big endian else keep it unchanged.
  123. */
  124. /* PPS 6, 7 */
  125. pps_payload->pic_height = cpu_to_be16(dsc_cfg->pic_height);
  126. /* PPS 8, 9 */
  127. pps_payload->pic_width = cpu_to_be16(dsc_cfg->pic_width);
  128. /* PPS 10, 11 */
  129. pps_payload->slice_height = cpu_to_be16(dsc_cfg->slice_height);
  130. /* PPS 12, 13 */
  131. pps_payload->slice_width = cpu_to_be16(dsc_cfg->slice_width);
  132. /* PPS 14, 15 */
  133. pps_payload->chunk_size = cpu_to_be16(dsc_cfg->slice_chunk_size);
  134. /* PPS 16 */
  135. pps_payload->initial_xmit_delay_high =
  136. ((dsc_cfg->initial_xmit_delay &
  137. DSC_PPS_INIT_XMIT_DELAY_HIGH_MASK) >>
  138. DSC_PPS_MSB_SHIFT);
  139. /* PPS 17 */
  140. pps_payload->initial_xmit_delay_low =
  141. (dsc_cfg->initial_xmit_delay & DSC_PPS_LSB_MASK);
  142. /* PPS 18, 19 */
  143. pps_payload->initial_dec_delay =
  144. cpu_to_be16(dsc_cfg->initial_dec_delay);
  145. /* PPS 20 is 0 */
  146. /* PPS 21 */
  147. pps_payload->initial_scale_value =
  148. dsc_cfg->initial_scale_value;
  149. /* PPS 22, 23 */
  150. pps_payload->scale_increment_interval =
  151. cpu_to_be16(dsc_cfg->scale_increment_interval);
  152. /* PPS 24 */
  153. pps_payload->scale_decrement_interval_high =
  154. ((dsc_cfg->scale_decrement_interval &
  155. DSC_PPS_SCALE_DEC_INT_HIGH_MASK) >>
  156. DSC_PPS_MSB_SHIFT);
  157. /* PPS 25 */
  158. pps_payload->scale_decrement_interval_low =
  159. (dsc_cfg->scale_decrement_interval & DSC_PPS_LSB_MASK);
  160. /* PPS 26[7:0], PPS 27[7:5] RESERVED */
  161. /* PPS 27 */
  162. pps_payload->first_line_bpg_offset =
  163. dsc_cfg->first_line_bpg_offset;
  164. /* PPS 28, 29 */
  165. pps_payload->nfl_bpg_offset =
  166. cpu_to_be16(dsc_cfg->nfl_bpg_offset);
  167. /* PPS 30, 31 */
  168. pps_payload->slice_bpg_offset =
  169. cpu_to_be16(dsc_cfg->slice_bpg_offset);
  170. /* PPS 32, 33 */
  171. pps_payload->initial_offset =
  172. cpu_to_be16(dsc_cfg->initial_offset);
  173. /* PPS 34, 35 */
  174. pps_payload->final_offset = cpu_to_be16(dsc_cfg->final_offset);
  175. /* PPS 36 */
  176. pps_payload->flatness_min_qp = dsc_cfg->flatness_min_qp;
  177. /* PPS 37 */
  178. pps_payload->flatness_max_qp = dsc_cfg->flatness_max_qp;
  179. /* PPS 38, 39 */
  180. pps_payload->rc_model_size = cpu_to_be16(dsc_cfg->rc_model_size);
  181. /* PPS 40 */
  182. pps_payload->rc_edge_factor = DSC_RC_EDGE_FACTOR_CONST;
  183. /* PPS 41 */
  184. pps_payload->rc_quant_incr_limit0 =
  185. dsc_cfg->rc_quant_incr_limit0;
  186. /* PPS 42 */
  187. pps_payload->rc_quant_incr_limit1 =
  188. dsc_cfg->rc_quant_incr_limit1;
  189. /* PPS 43 */
  190. pps_payload->rc_tgt_offset = DSC_RC_TGT_OFFSET_LO_CONST |
  191. DSC_RC_TGT_OFFSET_HI_CONST << DSC_PPS_RC_TGT_OFFSET_HI_SHIFT;
  192. /* PPS 44 - 57 */
  193. for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++)
  194. pps_payload->rc_buf_thresh[i] =
  195. dsc_cfg->rc_buf_thresh[i];
  196. /* PPS 58 - 87 */
  197. /*
  198. * For DSC sink programming the RC Range parameter fields
  199. * are as follows: Min_qp[15:11], max_qp[10:6], offset[5:0]
  200. */
  201. for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
  202. pps_payload->rc_range_parameters[i] =
  203. cpu_to_be16((dsc_cfg->rc_range_params[i].range_min_qp <<
  204. DSC_PPS_RC_RANGE_MINQP_SHIFT) |
  205. (dsc_cfg->rc_range_params[i].range_max_qp <<
  206. DSC_PPS_RC_RANGE_MAXQP_SHIFT) |
  207. (dsc_cfg->rc_range_params[i].range_bpg_offset));
  208. }
  209. /* PPS 88 */
  210. pps_payload->native_422_420 = dsc_cfg->native_422 |
  211. dsc_cfg->native_420 << DSC_PPS_NATIVE_420_SHIFT;
  212. /* PPS 89 */
  213. pps_payload->second_line_bpg_offset =
  214. dsc_cfg->second_line_bpg_offset;
  215. /* PPS 90, 91 */
  216. pps_payload->nsl_bpg_offset =
  217. cpu_to_be16(dsc_cfg->nsl_bpg_offset);
  218. /* PPS 92, 93 */
  219. pps_payload->second_line_offset_adj =
  220. cpu_to_be16(dsc_cfg->second_line_offset_adj);
  221. /* PPS 94 - 127 are O */
  222. }
  223. EXPORT_SYMBOL(drm_dsc_pps_payload_pack);
  224. /**
  225. * drm_dsc_set_const_params() - Set DSC parameters considered typically
  226. * constant across operation modes
  227. *
  228. * @vdsc_cfg:
  229. * DSC Configuration data partially filled by driver
  230. */
  231. void drm_dsc_set_const_params(struct drm_dsc_config *vdsc_cfg)
  232. {
  233. if (!vdsc_cfg->rc_model_size)
  234. vdsc_cfg->rc_model_size = DSC_RC_MODEL_SIZE_CONST;
  235. vdsc_cfg->rc_edge_factor = DSC_RC_EDGE_FACTOR_CONST;
  236. vdsc_cfg->rc_tgt_offset_high = DSC_RC_TGT_OFFSET_HI_CONST;
  237. vdsc_cfg->rc_tgt_offset_low = DSC_RC_TGT_OFFSET_LO_CONST;
  238. if (vdsc_cfg->bits_per_component <= 10)
  239. vdsc_cfg->mux_word_size = DSC_MUX_WORD_SIZE_8_10_BPC;
  240. else
  241. vdsc_cfg->mux_word_size = DSC_MUX_WORD_SIZE_12_BPC;
  242. }
  243. EXPORT_SYMBOL(drm_dsc_set_const_params);
  244. /* From DSC_v1.11 spec, rc_parameter_Set syntax element typically constant */
  245. static const u16 drm_dsc_rc_buf_thresh[] = {
  246. 896, 1792, 2688, 3584, 4480, 5376, 6272, 6720, 7168, 7616,
  247. 7744, 7872, 8000, 8064
  248. };
  249. /**
  250. * drm_dsc_set_rc_buf_thresh() - Set thresholds for the RC model
  251. * in accordance with the DSC 1.2 specification.
  252. *
  253. * @vdsc_cfg: DSC Configuration data partially filled by driver
  254. */
  255. void drm_dsc_set_rc_buf_thresh(struct drm_dsc_config *vdsc_cfg)
  256. {
  257. int i;
  258. BUILD_BUG_ON(ARRAY_SIZE(drm_dsc_rc_buf_thresh) !=
  259. DSC_NUM_BUF_RANGES - 1);
  260. BUILD_BUG_ON(ARRAY_SIZE(drm_dsc_rc_buf_thresh) !=
  261. ARRAY_SIZE(vdsc_cfg->rc_buf_thresh));
  262. for (i = 0; i < ARRAY_SIZE(drm_dsc_rc_buf_thresh); i++)
  263. vdsc_cfg->rc_buf_thresh[i] = drm_dsc_rc_buf_thresh[i] >> 6;
  264. /*
  265. * For 6bpp, RC Buffer threshold 12 and 13 need a different value
  266. * as per C Model
  267. */
  268. if (vdsc_cfg->bits_per_pixel == 6 << 4) {
  269. vdsc_cfg->rc_buf_thresh[12] = 7936 >> 6;
  270. vdsc_cfg->rc_buf_thresh[13] = 8000 >> 6;
  271. }
  272. }
  273. EXPORT_SYMBOL(drm_dsc_set_rc_buf_thresh);
  274. struct rc_parameters {
  275. u16 initial_xmit_delay;
  276. u8 first_line_bpg_offset;
  277. u16 initial_offset;
  278. u8 flatness_min_qp;
  279. u8 flatness_max_qp;
  280. u8 rc_quant_incr_limit0;
  281. u8 rc_quant_incr_limit1;
  282. struct drm_dsc_rc_range_parameters rc_range_params[DSC_NUM_BUF_RANGES];
  283. };
  284. struct rc_parameters_data {
  285. u8 bpp;
  286. u8 bpc;
  287. struct rc_parameters params;
  288. };
  289. #define DSC_BPP(bpp) ((bpp) << 4)
  290. /*
  291. * Rate Control Related Parameter Recommended Values from DSC_v1.1 spec prior
  292. * to DSC 1.1 fractional bpp underflow SCR (DSC_v1.1_E1.pdf)
  293. *
  294. * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
  295. */
  296. static const struct rc_parameters_data rc_parameters_pre_scr[] = {
  297. {
  298. .bpp = DSC_BPP(6), .bpc = 8,
  299. { 683, 15, 6144, 3, 13, 11, 11, {
  300. { 0, 2, 0 }, { 1, 4, -2 }, { 3, 6, -2 }, { 4, 6, -4 },
  301. { 5, 7, -6 }, { 5, 7, -6 }, { 6, 7, -6 }, { 6, 8, -8 },
  302. { 7, 9, -8 }, { 8, 10, -10 }, { 9, 11, -10 }, { 10, 12, -12 },
  303. { 10, 13, -12 }, { 12, 14, -12 }, { 15, 15, -12 }
  304. }
  305. }
  306. },
  307. {
  308. .bpp = DSC_BPP(8), .bpc = 8,
  309. { 512, 12, 6144, 3, 12, 11, 11, {
  310. { 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
  311. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  312. { 3, 9, -8 }, { 3, 10, -10 }, { 5, 11, -10 }, { 5, 12, -12 },
  313. { 5, 13, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
  314. }
  315. }
  316. },
  317. {
  318. .bpp = DSC_BPP(8), .bpc = 10,
  319. { 512, 12, 6144, 7, 16, 15, 15, {
  320. /*
  321. * DSC model/pre-SCR-cfg has 8 for range_max_qp[0], however
  322. * VESA DSC 1.1 Table E-5 sets it to 4.
  323. */
  324. { 0, 4, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
  325. { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  326. { 7, 13, -8 }, { 7, 14, -10 }, { 9, 15, -10 }, { 9, 16, -12 },
  327. { 9, 17, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
  328. }
  329. }
  330. },
  331. {
  332. .bpp = DSC_BPP(8), .bpc = 12,
  333. { 512, 12, 6144, 11, 20, 19, 19, {
  334. { 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
  335. { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  336. { 11, 17, -8 }, { 11, 18, -10 }, { 13, 19, -10 },
  337. { 13, 20, -12 }, { 13, 21, -12 }, { 15, 21, -12 },
  338. { 21, 23, -12 }
  339. }
  340. }
  341. },
  342. {
  343. .bpp = DSC_BPP(10), .bpc = 8,
  344. { 410, 12, 5632, 3, 12, 11, 11, {
  345. { 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
  346. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  347. { 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 11, -10 },
  348. { 5, 12, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
  349. }
  350. }
  351. },
  352. {
  353. .bpp = DSC_BPP(10), .bpc = 10,
  354. { 410, 12, 5632, 7, 16, 15, 15, {
  355. { 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
  356. { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  357. { 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 15, -10 },
  358. { 9, 16, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
  359. }
  360. }
  361. },
  362. {
  363. .bpp = DSC_BPP(10), .bpc = 12,
  364. { 410, 12, 5632, 11, 20, 19, 19, {
  365. { 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
  366. { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  367. { 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
  368. { 13, 19, -10 }, { 13, 20, -12 }, { 15, 21, -12 },
  369. { 21, 23, -12 }
  370. }
  371. }
  372. },
  373. {
  374. .bpp = DSC_BPP(12), .bpc = 8,
  375. { 341, 15, 2048, 3, 12, 11, 11, {
  376. { 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
  377. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  378. { 3, 9, -8 }, { 3, 10, -10 }, { 5, 11, -10 },
  379. { 5, 12, -12 }, { 5, 13, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
  380. }
  381. }
  382. },
  383. {
  384. .bpp = DSC_BPP(12), .bpc = 10,
  385. { 341, 15, 2048, 7, 16, 15, 15, {
  386. { 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
  387. { 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  388. { 7, 13, -8 }, { 7, 14, -10 }, { 9, 15, -10 }, { 9, 16, -12 },
  389. { 9, 17, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
  390. }
  391. }
  392. },
  393. {
  394. .bpp = DSC_BPP(12), .bpc = 12,
  395. { 341, 15, 2048, 11, 20, 19, 19, {
  396. { 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
  397. { 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  398. { 11, 17, -8 }, { 11, 18, -10 }, { 13, 19, -10 },
  399. { 13, 20, -12 }, { 13, 21, -12 }, { 15, 21, -12 },
  400. { 21, 23, -12 }
  401. }
  402. }
  403. },
  404. {
  405. .bpp = DSC_BPP(15), .bpc = 8,
  406. { 273, 15, 2048, 3, 12, 11, 11, {
  407. { 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
  408. { 1, 2, 2 }, { 1, 3, 0 }, { 1, 4, -2 }, { 2, 4, -4 },
  409. { 3, 4, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 5, 7, -10 },
  410. { 5, 8, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
  411. }
  412. }
  413. },
  414. {
  415. .bpp = DSC_BPP(15), .bpc = 10,
  416. { 273, 15, 2048, 7, 16, 15, 15, {
  417. { 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
  418. { 5, 6, 2 }, { 5, 7, 0 }, { 5, 8, -2 }, { 6, 8, -4 },
  419. { 7, 8, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 9, 11, -10 },
  420. { 9, 12, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
  421. }
  422. }
  423. },
  424. {
  425. .bpp = DSC_BPP(15), .bpc = 12,
  426. { 273, 15, 2048, 11, 20, 19, 19, {
  427. { 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
  428. { 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
  429. { 11, 12, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
  430. { 13, 15, -10 }, { 13, 16, -12 }, { 15, 21, -12 },
  431. { 21, 23, -12 }
  432. }
  433. }
  434. },
  435. { /* sentinel */ }
  436. };
  437. /*
  438. * Selected Rate Control Related Parameter Recommended Values from DSC v1.2, v1.2a, v1.2b and
  439. * DSC_v1.1_E1 specs.
  440. *
  441. * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
  442. */
  443. static const struct rc_parameters_data rc_parameters_1_2_444[] = {
  444. {
  445. .bpp = DSC_BPP(6), .bpc = 8,
  446. { 768, 15, 6144, 3, 13, 11, 11, {
  447. { 0, 4, 0 }, { 1, 6, -2 }, { 3, 8, -2 }, { 4, 8, -4 },
  448. { 5, 9, -6 }, { 5, 9, -6 }, { 6, 9, -6 }, { 6, 10, -8 },
  449. { 7, 11, -8 }, { 8, 12, -10 }, { 9, 12, -10 }, { 10, 12, -12 },
  450. { 10, 12, -12 }, { 11, 12, -12 }, { 13, 14, -12 }
  451. }
  452. }
  453. },
  454. {
  455. .bpp = DSC_BPP(6), .bpc = 10,
  456. { 768, 15, 6144, 7, 17, 15, 15, {
  457. { 0, 8, 0 }, { 3, 10, -2 }, { 7, 12, -2 }, { 8, 12, -4 },
  458. { 9, 13, -6 }, { 9, 13, -6 }, { 10, 13, -6 }, { 10, 14, -8 },
  459. { 11, 15, -8 }, { 12, 16, -10 }, { 13, 16, -10 },
  460. { 14, 16, -12 }, { 14, 16, -12 }, { 15, 16, -12 },
  461. { 17, 18, -12 }
  462. }
  463. }
  464. },
  465. {
  466. .bpp = DSC_BPP(6), .bpc = 12,
  467. { 768, 15, 6144, 11, 21, 19, 19, {
  468. { 0, 12, 0 }, { 5, 14, -2 }, { 11, 16, -2 }, { 12, 16, -4 },
  469. { 13, 17, -6 }, { 13, 17, -6 }, { 14, 17, -6 }, { 14, 18, -8 },
  470. { 15, 19, -8 }, { 16, 20, -10 }, { 17, 20, -10 },
  471. { 18, 20, -12 }, { 18, 20, -12 }, { 19, 20, -12 },
  472. { 21, 22, -12 }
  473. }
  474. }
  475. },
  476. {
  477. .bpp = DSC_BPP(6), .bpc = 14,
  478. { 768, 15, 6144, 15, 25, 23, 23, {
  479. { 0, 16, 0 }, { 7, 18, -2 }, { 15, 20, -2 }, { 16, 20, -4 },
  480. { 17, 21, -6 }, { 17, 21, -6 }, { 18, 21, -6 }, { 18, 22, -8 },
  481. { 19, 23, -8 }, { 20, 24, -10 }, { 21, 24, -10 },
  482. { 22, 24, -12 }, { 22, 24, -12 }, { 23, 24, -12 },
  483. { 25, 26, -12 }
  484. }
  485. }
  486. },
  487. {
  488. .bpp = DSC_BPP(6), .bpc = 16,
  489. { 768, 15, 6144, 19, 29, 27, 27, {
  490. { 0, 20, 0 }, { 9, 22, -2 }, { 19, 24, -2 }, { 20, 24, -4 },
  491. { 21, 25, -6 }, { 21, 25, -6 }, { 22, 25, -6 }, { 22, 26, -8 },
  492. { 23, 27, -8 }, { 24, 28, -10 }, { 25, 28, -10 },
  493. { 26, 28, -12 }, { 26, 28, -12 }, { 27, 28, -12 },
  494. { 29, 30, -12 }
  495. }
  496. }
  497. },
  498. {
  499. .bpp = DSC_BPP(8), .bpc = 8,
  500. { 512, 12, 6144, 3, 12, 11, 11, {
  501. { 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
  502. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  503. { 3, 9, -8 }, { 3, 10, -10 }, { 5, 10, -10 }, { 5, 11, -12 },
  504. { 5, 11, -12 }, { 9, 12, -12 }, { 12, 13, -12 }
  505. }
  506. }
  507. },
  508. {
  509. .bpp = DSC_BPP(8), .bpc = 10,
  510. { 512, 12, 6144, 7, 16, 15, 15, {
  511. { 0, 8, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
  512. { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  513. { 7, 13, -8 }, { 7, 14, -10 }, { 9, 14, -10 }, { 9, 15, -12 },
  514. { 9, 15, -12 }, { 13, 16, -12 }, { 16, 17, -12 }
  515. }
  516. }
  517. },
  518. {
  519. .bpp = DSC_BPP(8), .bpc = 12,
  520. { 512, 12, 6144, 11, 20, 19, 19, {
  521. { 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
  522. { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  523. { 11, 17, -8 }, { 11, 18, -10 }, { 13, 18, -10 },
  524. { 13, 19, -12 }, { 13, 19, -12 }, { 17, 20, -12 },
  525. { 20, 21, -12 }
  526. }
  527. }
  528. },
  529. {
  530. .bpp = DSC_BPP(8), .bpc = 14,
  531. { 512, 12, 6144, 15, 24, 23, 23, {
  532. { 0, 12, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 12, 17, -2 },
  533. { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
  534. { 15, 21, -8 }, { 15, 22, -10 }, { 17, 22, -10 },
  535. { 17, 23, -12 }, { 17, 23, -12 }, { 21, 24, -12 },
  536. { 24, 25, -12 }
  537. }
  538. }
  539. },
  540. {
  541. .bpp = DSC_BPP(8), .bpc = 16,
  542. { 512, 12, 6144, 19, 28, 27, 27, {
  543. { 0, 12, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 15, 20, -2 },
  544. { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
  545. { 19, 25, -8 }, { 19, 26, -10 }, { 21, 26, -10 },
  546. { 21, 27, -12 }, { 21, 27, -12 }, { 25, 28, -12 },
  547. { 28, 29, -12 }
  548. }
  549. }
  550. },
  551. {
  552. .bpp = DSC_BPP(10), .bpc = 8,
  553. { 410, 15, 5632, 3, 12, 11, 11, {
  554. { 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
  555. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  556. { 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 10, -10 },
  557. { 5, 11, -12 }, { 7, 11, -12 }, { 11, 12, -12 }
  558. }
  559. }
  560. },
  561. {
  562. .bpp = DSC_BPP(10), .bpc = 10,
  563. { 410, 15, 5632, 7, 16, 15, 15, {
  564. { 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
  565. { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  566. { 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 14, -10 },
  567. { 9, 15, -12 }, { 11, 15, -12 }, { 15, 16, -12 }
  568. }
  569. }
  570. },
  571. {
  572. .bpp = DSC_BPP(10), .bpc = 12,
  573. { 410, 15, 5632, 11, 20, 19, 19, {
  574. { 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
  575. { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  576. { 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
  577. { 13, 18, -10 }, { 13, 19, -12 }, { 15, 19, -12 },
  578. { 19, 20, -12 }
  579. }
  580. }
  581. },
  582. {
  583. .bpp = DSC_BPP(10), .bpc = 14,
  584. { 410, 15, 5632, 15, 24, 23, 23, {
  585. { 0, 11, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 13, 18, -2 },
  586. { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
  587. { 15, 21, -8 }, { 15, 21, -10 }, { 17, 22, -10 },
  588. { 17, 22, -10 }, { 17, 23, -12 }, { 19, 23, -12 },
  589. { 23, 24, -12 }
  590. }
  591. }
  592. },
  593. {
  594. .bpp = DSC_BPP(10), .bpc = 16,
  595. { 410, 15, 5632, 19, 28, 27, 27, {
  596. { 0, 11, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 16, 20, -2 },
  597. { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
  598. { 19, 25, -8 }, { 19, 25, -10 }, { 21, 26, -10 },
  599. { 21, 26, -10 }, { 21, 27, -12 }, { 23, 27, -12 },
  600. { 27, 28, -12 }
  601. }
  602. }
  603. },
  604. {
  605. .bpp = DSC_BPP(12), .bpc = 8,
  606. { 341, 15, 2048, 3, 12, 11, 11, {
  607. { 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
  608. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  609. { 3, 8, -8 }, { 3, 9, -10 }, { 5, 9, -10 }, { 5, 9, -12 },
  610. { 5, 9, -12 }, { 7, 10, -12 }, { 10, 11, -12 }
  611. }
  612. }
  613. },
  614. {
  615. .bpp = DSC_BPP(12), .bpc = 10,
  616. { 341, 15, 2048, 7, 16, 15, 15, {
  617. { 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
  618. { 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  619. { 7, 12, -8 }, { 7, 13, -10 }, { 9, 13, -10 }, { 9, 13, -12 },
  620. { 9, 13, -12 }, { 11, 14, -12 }, { 14, 15, -12 }
  621. }
  622. }
  623. },
  624. {
  625. .bpp = DSC_BPP(12), .bpc = 12,
  626. { 341, 15, 2048, 11, 20, 19, 19, {
  627. { 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
  628. { 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  629. { 11, 16, -8 }, { 11, 17, -10 }, { 13, 17, -10 },
  630. { 13, 17, -12 }, { 13, 17, -12 }, { 15, 18, -12 },
  631. { 18, 19, -12 }
  632. }
  633. }
  634. },
  635. {
  636. .bpp = DSC_BPP(12), .bpc = 14,
  637. { 341, 15, 2048, 15, 24, 23, 23, {
  638. { 0, 6, 2 }, { 7, 10, 0 }, { 9, 13, 0 }, { 11, 16, -2 },
  639. { 14, 17, -4 }, { 15, 18, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
  640. { 15, 20, -8 }, { 15, 21, -10 }, { 17, 21, -10 },
  641. { 17, 21, -12 }, { 17, 21, -12 }, { 19, 22, -12 },
  642. { 22, 23, -12 }
  643. }
  644. }
  645. },
  646. {
  647. .bpp = DSC_BPP(12), .bpc = 16,
  648. { 341, 15, 2048, 19, 28, 27, 27, {
  649. { 0, 6, 2 }, { 6, 11, 0 }, { 11, 15, 0 }, { 14, 18, -2 },
  650. { 18, 21, -4 }, { 19, 22, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
  651. { 19, 24, -8 }, { 19, 25, -10 }, { 21, 25, -10 },
  652. { 21, 25, -12 }, { 21, 25, -12 }, { 23, 26, -12 },
  653. { 26, 27, -12 }
  654. }
  655. }
  656. },
  657. {
  658. .bpp = DSC_BPP(15), .bpc = 8,
  659. { 273, 15, 2048, 3, 12, 11, 11, {
  660. { 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
  661. { 1, 2, 2 }, { 1, 3, 0 }, { 1, 3, -2 }, { 2, 4, -4 },
  662. { 2, 5, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 4, 7, -10 },
  663. { 5, 7, -12 }, { 7, 8, -12 }, { 8, 9, -12 }
  664. }
  665. }
  666. },
  667. {
  668. .bpp = DSC_BPP(15), .bpc = 10,
  669. { 273, 15, 2048, 7, 16, 15, 15, {
  670. { 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
  671. { 5, 6, 2 }, { 5, 7, 0 }, { 5, 7, -2 }, { 6, 8, -4 },
  672. { 6, 9, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 8, 11, -10 },
  673. { 9, 11, -12 }, { 11, 12, -12 }, { 12, 13, -12 }
  674. }
  675. }
  676. },
  677. {
  678. .bpp = DSC_BPP(15), .bpc = 12,
  679. { 273, 15, 2048, 11, 20, 19, 19, {
  680. { 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
  681. { 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
  682. { 11, 13, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
  683. { 13, 15, -10 }, { 13, 15, -12 }, { 15, 16, -12 },
  684. { 16, 17, -12 }
  685. }
  686. }
  687. },
  688. {
  689. .bpp = DSC_BPP(15), .bpc = 14,
  690. { 273, 15, 2048, 15, 24, 23, 23, {
  691. { 0, 4, 10 }, { 3, 8, 8 }, { 6, 11, 6 }, { 9, 14, 4 },
  692. { 13, 15, 2 }, { 13, 15, 0 }, { 13, 16, -2 }, { 14, 16, -4 },
  693. { 15, 17, -6 }, { 15, 17, -8 }, { 16, 18, -10 },
  694. { 17, 19, -10 }, { 17, 19, -12 }, { 19, 20, -12 },
  695. { 20, 21, -12 }
  696. }
  697. }
  698. },
  699. {
  700. .bpp = DSC_BPP(15), .bpc = 16,
  701. { 273, 15, 2048, 19, 28, 27, 27, {
  702. { 0, 4, 10 }, { 4, 9, 8 }, { 8, 13, 6 }, { 12, 17, 4 },
  703. { 17, 19, 2 }, { 17, 20, 0 }, { 17, 20, -2 }, { 18, 20, -4 },
  704. { 19, 21, -6 }, { 19, 21, -8 }, { 20, 22, -10 },
  705. { 21, 23, -10 }, { 21, 23, -12 }, { 23, 24, -12 },
  706. { 24, 25, -12 }
  707. }
  708. }
  709. },
  710. { /* sentinel */ }
  711. };
  712. /*
  713. * Selected Rate Control Related Parameter Recommended Values for 4:2:2 from
  714. * DSC v1.2, v1.2a, v1.2b
  715. *
  716. * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
  717. */
  718. static const struct rc_parameters_data rc_parameters_1_2_422[] = {
  719. {
  720. .bpp = DSC_BPP(6), .bpc = 8,
  721. { 512, 15, 6144, 3, 12, 11, 11, {
  722. { 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
  723. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  724. { 3, 9, -8 }, { 3, 10, -10 }, { 5, 10, -10 }, { 5, 11, -12 },
  725. { 5, 11, -12 }, { 9, 12, -12 }, { 12, 13, -12 }
  726. }
  727. }
  728. },
  729. {
  730. .bpp = DSC_BPP(6), .bpc = 10,
  731. { 512, 15, 6144, 7, 16, 15, 15, {
  732. { 0, 8, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
  733. { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  734. { 7, 13, -8 }, { 7, 14, -10 }, { 9, 14, -10 }, { 9, 15, -12 },
  735. { 9, 15, -12 }, { 13, 16, -12 }, { 16, 17, -12 }
  736. }
  737. }
  738. },
  739. {
  740. .bpp = DSC_BPP(6), .bpc = 12,
  741. { 512, 15, 6144, 11, 20, 19, 19, {
  742. { 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
  743. { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  744. { 11, 17, -8 }, { 11, 18, -10 }, { 13, 18, -10 },
  745. { 13, 19, -12 }, { 13, 19, -12 }, { 17, 20, -12 },
  746. { 20, 21, -12 }
  747. }
  748. }
  749. },
  750. {
  751. .bpp = DSC_BPP(6), .bpc = 14,
  752. { 512, 15, 6144, 15, 24, 23, 23, {
  753. { 0, 12, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 12, 17, -2 },
  754. { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
  755. { 15, 21, -8 }, { 15, 22, -10 }, { 17, 22, -10 },
  756. { 17, 23, -12 }, { 17, 23, -12 }, { 21, 24, -12 },
  757. { 24, 25, -12 }
  758. }
  759. }
  760. },
  761. {
  762. .bpp = DSC_BPP(6), .bpc = 16,
  763. { 512, 15, 6144, 19, 28, 27, 27, {
  764. { 0, 12, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 15, 20, -2 },
  765. { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
  766. { 19, 25, -8 }, { 19, 26, -10 }, { 21, 26, -10 },
  767. { 21, 27, -12 }, { 21, 27, -12 }, { 25, 28, -12 },
  768. { 28, 29, -12 }
  769. }
  770. }
  771. },
  772. {
  773. .bpp = DSC_BPP(7), .bpc = 8,
  774. { 410, 15, 5632, 3, 12, 11, 11, {
  775. { 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
  776. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  777. { 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 10, -10 },
  778. { 5, 11, -12 }, { 7, 11, -12 }, { 11, 12, -12 }
  779. }
  780. }
  781. },
  782. {
  783. .bpp = DSC_BPP(7), .bpc = 10,
  784. { 410, 15, 5632, 7, 16, 15, 15, {
  785. { 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
  786. { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  787. { 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 14, -10 },
  788. { 9, 15, -12 }, { 11, 15, -12 }, { 15, 16, -12 }
  789. }
  790. }
  791. },
  792. {
  793. .bpp = DSC_BPP(7), .bpc = 12,
  794. { 410, 15, 5632, 11, 20, 19, 19, {
  795. { 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
  796. { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  797. { 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
  798. { 13, 18, -10 }, { 13, 19, -12 }, { 15, 19, -12 },
  799. { 19, 20, -12 }
  800. }
  801. }
  802. },
  803. {
  804. .bpp = DSC_BPP(7), .bpc = 14,
  805. { 410, 15, 5632, 15, 24, 23, 23, {
  806. { 0, 11, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 13, 18, -2 },
  807. { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
  808. { 15, 21, -8 }, { 15, 21, -10 }, { 17, 22, -10 },
  809. { 17, 22, -10 }, { 17, 23, -12 }, { 19, 23, -12 },
  810. { 23, 24, -12 }
  811. }
  812. }
  813. },
  814. {
  815. .bpp = DSC_BPP(7), .bpc = 16,
  816. { 410, 15, 5632, 19, 28, 27, 27, {
  817. { 0, 11, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 16, 20, -2 },
  818. { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
  819. { 19, 25, -8 }, { 19, 25, -10 }, { 21, 26, -10 },
  820. { 21, 26, -10 }, { 21, 27, -12 }, { 23, 27, -12 },
  821. { 27, 28, -12 }
  822. }
  823. }
  824. },
  825. {
  826. .bpp = DSC_BPP(8), .bpc = 8,
  827. { 341, 15, 2048, 3, 12, 11, 11, {
  828. { 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
  829. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  830. { 3, 8, -8 }, { 3, 9, -10 }, { 5, 9, -10 }, { 5, 9, -12 },
  831. { 5, 9, -12 }, { 7, 10, -12 }, { 10, 11, -12 }
  832. }
  833. }
  834. },
  835. {
  836. .bpp = DSC_BPP(8), .bpc = 10,
  837. { 341, 15, 2048, 7, 16, 15, 15, {
  838. { 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
  839. { 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  840. { 7, 12, -8 }, { 7, 13, -10 }, { 9, 13, -10 }, { 9, 13, -12 },
  841. { 9, 13, -12 }, { 11, 14, -12 }, { 14, 15, -12 }
  842. }
  843. }
  844. },
  845. {
  846. .bpp = DSC_BPP(8), .bpc = 12,
  847. { 341, 15, 2048, 11, 20, 19, 19, {
  848. { 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
  849. { 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  850. { 11, 16, -8 }, { 11, 17, -10 }, { 13, 17, -10 },
  851. { 13, 17, -12 }, { 13, 17, -12 }, { 15, 18, -12 },
  852. { 18, 19, -12 }
  853. }
  854. }
  855. },
  856. {
  857. .bpp = DSC_BPP(8), .bpc = 14,
  858. { 341, 15, 2048, 15, 24, 23, 23, {
  859. { 0, 6, 2 }, { 7, 10, 0 }, { 9, 13, 0 }, { 11, 16, -2 },
  860. { 14, 17, -4 }, { 15, 18, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
  861. { 15, 20, -8 }, { 15, 21, -10 }, { 17, 21, -10 },
  862. { 17, 21, -12 }, { 17, 21, -12 }, { 19, 22, -12 },
  863. { 22, 23, -12 }
  864. }
  865. }
  866. },
  867. {
  868. .bpp = DSC_BPP(8), .bpc = 16,
  869. { 341, 15, 2048, 19, 28, 27, 27, {
  870. { 0, 6, 2 }, { 6, 11, 0 }, { 11, 15, 0 }, { 14, 18, -2 },
  871. { 18, 21, -4 }, { 19, 22, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
  872. { 19, 24, -8 }, { 19, 25, -10 }, { 21, 25, -10 },
  873. { 21, 25, -12 }, { 21, 25, -12 }, { 23, 26, -12 },
  874. { 26, 27, -12 }
  875. }
  876. }
  877. },
  878. {
  879. .bpp = DSC_BPP(10), .bpc = 8,
  880. { 273, 15, 2048, 3, 12, 11, 11, {
  881. { 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
  882. { 1, 2, 2 }, { 1, 3, 0 }, { 1, 3, -2 }, { 2, 4, -4 },
  883. { 2, 5, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 4, 7, -10 },
  884. { 5, 7, -12 }, { 7, 8, -12 }, { 8, 9, -12 }
  885. }
  886. }
  887. },
  888. {
  889. .bpp = DSC_BPP(10), .bpc = 10,
  890. { 273, 15, 2048, 7, 16, 15, 15, {
  891. { 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
  892. { 5, 6, 2 }, { 5, 7, 0 }, { 5, 7, -2 }, { 6, 8, -4 },
  893. { 6, 9, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 8, 11, -10 },
  894. { 9, 11, -12 }, { 11, 12, -12 }, { 12, 13, -12 }
  895. }
  896. }
  897. },
  898. {
  899. .bpp = DSC_BPP(10), .bpc = 12,
  900. { 273, 15, 2048, 11, 20, 19, 19, {
  901. { 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
  902. { 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
  903. { 11, 13, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
  904. { 13, 15, -10 }, { 13, 15, -12 }, { 15, 16, -12 },
  905. { 16, 17, -12 }
  906. }
  907. }
  908. },
  909. {
  910. .bpp = DSC_BPP(10), .bpc = 14,
  911. { 273, 15, 2048, 15, 24, 23, 23, {
  912. { 0, 4, 10 }, { 3, 8, 8 }, { 6, 11, 6 }, { 9, 14, 4 },
  913. { 13, 15, 2 }, { 13, 15, 0 }, { 13, 16, -2 }, { 14, 16, -4 },
  914. { 15, 17, -6 }, { 15, 17, -8 }, { 16, 18, -10 },
  915. { 17, 19, -10 }, { 17, 19, -12 }, { 19, 20, -12 },
  916. { 20, 21, -12 }
  917. }
  918. }
  919. },
  920. {
  921. .bpp = DSC_BPP(10), .bpc = 16,
  922. { 273, 15, 2048, 19, 28, 27, 27, {
  923. { 0, 4, 10 }, { 4, 9, 8 }, { 8, 13, 6 }, { 12, 17, 4 },
  924. { 17, 19, 2 }, { 17, 20, 0 }, { 17, 20, -2 }, { 18, 20, -4 },
  925. { 19, 21, -6 }, { 19, 21, -8 }, { 20, 22, -10 },
  926. { 21, 23, -10 }, { 21, 23, -12 }, { 23, 24, -12 },
  927. { 24, 25, -12 }
  928. }
  929. }
  930. },
  931. { /* sentinel */ }
  932. };
  933. /*
  934. * Selected Rate Control Related Parameter Recommended Values for 4:2:2 from
  935. * DSC v1.2, v1.2a, v1.2b
  936. *
  937. * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
  938. */
  939. static const struct rc_parameters_data rc_parameters_1_2_420[] = {
  940. {
  941. .bpp = DSC_BPP(4), .bpc = 8,
  942. { 512, 12, 6144, 3, 12, 11, 11, {
  943. { 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
  944. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  945. { 3, 9, -8 }, { 3, 10, -10 }, { 5, 10, -10 }, { 5, 11, -12 },
  946. { 5, 11, -12 }, { 9, 12, -12 }, { 12, 13, -12 }
  947. }
  948. }
  949. },
  950. {
  951. .bpp = DSC_BPP(4), .bpc = 10,
  952. { 512, 12, 6144, 7, 16, 15, 15, {
  953. { 0, 8, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
  954. { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  955. { 7, 13, -8 }, { 7, 14, -10 }, { 9, 14, -10 }, { 9, 15, -12 },
  956. { 9, 15, -12 }, { 13, 16, -12 }, { 16, 17, -12 }
  957. }
  958. }
  959. },
  960. {
  961. .bpp = DSC_BPP(4), .bpc = 12,
  962. { 512, 12, 6144, 11, 20, 19, 19, {
  963. { 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
  964. { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  965. { 11, 17, -8 }, { 11, 18, -10 }, { 13, 18, -10 },
  966. { 13, 19, -12 }, { 13, 19, -12 }, { 17, 20, -12 },
  967. { 20, 21, -12 }
  968. }
  969. }
  970. },
  971. {
  972. .bpp = DSC_BPP(4), .bpc = 14,
  973. { 512, 12, 6144, 15, 24, 23, 23, {
  974. { 0, 12, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 12, 17, -2 },
  975. { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
  976. { 15, 21, -8 }, { 15, 22, -10 }, { 17, 22, -10 },
  977. { 17, 23, -12 }, { 17, 23, -12 }, { 21, 24, -12 },
  978. { 24, 25, -12 }
  979. }
  980. }
  981. },
  982. {
  983. .bpp = DSC_BPP(4), .bpc = 16,
  984. { 512, 12, 6144, 19, 28, 27, 27, {
  985. { 0, 12, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 15, 20, -2 },
  986. { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
  987. { 19, 25, -8 }, { 19, 26, -10 }, { 21, 26, -10 },
  988. { 21, 27, -12 }, { 21, 27, -12 }, { 25, 28, -12 },
  989. { 28, 29, -12 }
  990. }
  991. }
  992. },
  993. {
  994. .bpp = DSC_BPP(5), .bpc = 8,
  995. { 410, 15, 5632, 3, 12, 11, 11, {
  996. { 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
  997. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  998. { 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 10, -10 },
  999. { 5, 11, -12 }, { 7, 11, -12 }, { 11, 12, -12 }
  1000. }
  1001. }
  1002. },
  1003. {
  1004. .bpp = DSC_BPP(5), .bpc = 10,
  1005. { 410, 15, 5632, 7, 16, 15, 15, {
  1006. { 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
  1007. { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  1008. { 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 14, -10 },
  1009. { 9, 15, -12 }, { 11, 15, -12 }, { 15, 16, -12 }
  1010. }
  1011. }
  1012. },
  1013. {
  1014. .bpp = DSC_BPP(5), .bpc = 12,
  1015. { 410, 15, 5632, 11, 20, 19, 19, {
  1016. { 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
  1017. { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  1018. { 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
  1019. { 13, 18, -10 }, { 13, 19, -12 }, { 15, 19, -12 },
  1020. { 19, 20, -12 }
  1021. }
  1022. }
  1023. },
  1024. {
  1025. .bpp = DSC_BPP(5), .bpc = 14,
  1026. { 410, 15, 5632, 15, 24, 23, 23, {
  1027. { 0, 11, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 13, 18, -2 },
  1028. { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
  1029. { 15, 21, -8 }, { 15, 21, -10 }, { 17, 22, -10 },
  1030. { 17, 22, -10 }, { 17, 23, -12 }, { 19, 23, -12 },
  1031. { 23, 24, -12 }
  1032. }
  1033. }
  1034. },
  1035. {
  1036. .bpp = DSC_BPP(5), .bpc = 16,
  1037. { 410, 15, 5632, 19, 28, 27, 27, {
  1038. { 0, 11, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 16, 20, -2 },
  1039. { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
  1040. { 19, 25, -8 }, { 19, 25, -10 }, { 21, 26, -10 },
  1041. { 21, 26, -10 }, { 21, 27, -12 }, { 23, 27, -12 },
  1042. { 27, 28, -12 }
  1043. }
  1044. }
  1045. },
  1046. {
  1047. .bpp = DSC_BPP(6), .bpc = 8,
  1048. { 341, 15, 2048, 3, 12, 11, 11, {
  1049. { 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
  1050. { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
  1051. { 3, 8, -8 }, { 3, 9, -10 }, { 5, 9, -10 }, { 5, 9, -12 },
  1052. { 5, 9, -12 }, { 7, 10, -12 }, { 10, 12, -12 }
  1053. }
  1054. }
  1055. },
  1056. {
  1057. .bpp = DSC_BPP(6), .bpc = 10,
  1058. { 341, 15, 2048, 7, 16, 15, 15, {
  1059. { 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
  1060. { 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
  1061. { 7, 12, -8 }, { 7, 13, -10 }, { 9, 13, -10 }, { 9, 13, -12 },
  1062. { 9, 13, -12 }, { 11, 14, -12 }, { 14, 15, -12 }
  1063. }
  1064. }
  1065. },
  1066. {
  1067. .bpp = DSC_BPP(6), .bpc = 12,
  1068. { 341, 15, 2048, 11, 20, 19, 19, {
  1069. { 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
  1070. { 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
  1071. { 11, 16, -8 }, { 11, 17, -10 }, { 13, 17, -10 },
  1072. { 13, 17, -12 }, { 13, 17, -12 }, { 15, 18, -12 },
  1073. { 18, 19, -12 }
  1074. }
  1075. }
  1076. },
  1077. {
  1078. .bpp = DSC_BPP(6), .bpc = 14,
  1079. { 341, 15, 2048, 15, 24, 23, 23, {
  1080. { 0, 6, 2 }, { 7, 10, 0 }, { 9, 13, 0 }, { 11, 16, -2 },
  1081. { 14, 17, -4 }, { 15, 18, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
  1082. { 15, 20, -8 }, { 15, 21, -10 }, { 17, 21, -10 },
  1083. { 17, 21, -12 }, { 17, 21, -12 }, { 19, 22, -12 },
  1084. { 22, 23, -12 }
  1085. }
  1086. }
  1087. },
  1088. {
  1089. .bpp = DSC_BPP(6), .bpc = 16,
  1090. { 341, 15, 2048, 19, 28, 27, 27, {
  1091. { 0, 6, 2 }, { 6, 11, 0 }, { 11, 15, 0 }, { 14, 18, -2 },
  1092. { 18, 21, -4 }, { 19, 22, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
  1093. { 19, 24, -8 }, { 19, 25, -10 }, { 21, 25, -10 },
  1094. { 21, 25, -12 }, { 21, 25, -12 }, { 23, 26, -12 },
  1095. { 26, 27, -12 }
  1096. }
  1097. }
  1098. },
  1099. {
  1100. .bpp = DSC_BPP(8), .bpc = 8,
  1101. { 256, 15, 2048, 3, 12, 11, 11, {
  1102. { 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
  1103. { 1, 2, 2 }, { 1, 3, 0 }, { 1, 3, -2 }, { 2, 4, -4 },
  1104. { 2, 5, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 4, 7, -10 },
  1105. { 5, 7, -12 }, { 7, 8, -12 }, { 8, 9, -12 }
  1106. }
  1107. }
  1108. },
  1109. {
  1110. .bpp = DSC_BPP(8), .bpc = 10,
  1111. { 256, 15, 2048, 7, 16, 15, 15, {
  1112. { 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
  1113. { 5, 6, 2 }, { 5, 7, 0 }, { 5, 7, -2 }, { 6, 8, -4 },
  1114. { 6, 9, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 8, 11, -10 },
  1115. { 9, 11, -12 }, { 11, 12, -12 }, { 12, 13, -12 }
  1116. }
  1117. }
  1118. },
  1119. {
  1120. .bpp = DSC_BPP(8), .bpc = 12,
  1121. { 256, 15, 2048, 11, 20, 19, 19, {
  1122. { 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
  1123. { 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
  1124. { 11, 13, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
  1125. { 13, 15, -10 }, { 13, 15, -12 }, { 15, 16, -12 },
  1126. { 16, 17, -12 }
  1127. }
  1128. }
  1129. },
  1130. {
  1131. .bpp = DSC_BPP(8), .bpc = 14,
  1132. { 256, 15, 2048, 15, 24, 23, 23, {
  1133. { 0, 4, 10 }, { 3, 8, 8 }, { 6, 11, 6 }, { 9, 14, 4 },
  1134. { 13, 15, 2 }, { 13, 15, 0 }, { 13, 16, -2 }, { 14, 16, -4 },
  1135. { 15, 17, -6 }, { 15, 17, -8 }, { 16, 18, -10 },
  1136. { 17, 19, -10 }, { 17, 19, -12 }, { 19, 20, -12 },
  1137. { 20, 21, -12 }
  1138. }
  1139. }
  1140. },
  1141. {
  1142. .bpp = DSC_BPP(8), .bpc = 16,
  1143. { 256, 15, 2048, 19, 28, 27, 27, {
  1144. { 0, 4, 10 }, { 4, 9, 8 }, { 8, 13, 6 }, { 12, 17, 4 },
  1145. { 17, 19, 2 }, { 17, 20, 0 }, { 17, 20, -2 }, { 18, 20, -4 },
  1146. { 19, 21, -6 }, { 19, 21, -8 }, { 20, 22, -10 },
  1147. { 21, 23, -10 }, { 21, 23, -12 }, { 23, 24, -12 },
  1148. { 24, 25, -12 }
  1149. }
  1150. }
  1151. },
  1152. { /* sentinel */ }
  1153. };
  1154. static const struct rc_parameters *get_rc_params(const struct rc_parameters_data *rc_parameters,
  1155. u16 dsc_bpp,
  1156. u8 bits_per_component)
  1157. {
  1158. int i;
  1159. for (i = 0; rc_parameters[i].bpp; i++)
  1160. if (rc_parameters[i].bpp == dsc_bpp &&
  1161. rc_parameters[i].bpc == bits_per_component)
  1162. return &rc_parameters[i].params;
  1163. return NULL;
  1164. }
  1165. /**
  1166. * drm_dsc_setup_rc_params() - Set parameters and limits for RC model in
  1167. * accordance with the DSC 1.1 or 1.2 specification and DSC C Model
  1168. * Required bits_per_pixel and bits_per_component to be set before calling this
  1169. * function.
  1170. *
  1171. * @vdsc_cfg: DSC Configuration data partially filled by driver
  1172. * @type: operating mode and standard to follow
  1173. *
  1174. * Return: 0 or -error code in case of an error
  1175. */
  1176. int drm_dsc_setup_rc_params(struct drm_dsc_config *vdsc_cfg, enum drm_dsc_params_type type)
  1177. {
  1178. const struct rc_parameters_data *data;
  1179. const struct rc_parameters *rc_params;
  1180. int i;
  1181. if (WARN_ON_ONCE(!vdsc_cfg->bits_per_pixel ||
  1182. !vdsc_cfg->bits_per_component))
  1183. return -EINVAL;
  1184. switch (type) {
  1185. case DRM_DSC_1_2_444:
  1186. data = rc_parameters_1_2_444;
  1187. break;
  1188. case DRM_DSC_1_1_PRE_SCR:
  1189. data = rc_parameters_pre_scr;
  1190. break;
  1191. case DRM_DSC_1_2_422:
  1192. data = rc_parameters_1_2_422;
  1193. break;
  1194. case DRM_DSC_1_2_420:
  1195. data = rc_parameters_1_2_420;
  1196. break;
  1197. default:
  1198. return -EINVAL;
  1199. }
  1200. rc_params = get_rc_params(data,
  1201. vdsc_cfg->bits_per_pixel,
  1202. vdsc_cfg->bits_per_component);
  1203. if (!rc_params)
  1204. return -EINVAL;
  1205. vdsc_cfg->first_line_bpg_offset = rc_params->first_line_bpg_offset;
  1206. vdsc_cfg->initial_xmit_delay = rc_params->initial_xmit_delay;
  1207. vdsc_cfg->initial_offset = rc_params->initial_offset;
  1208. vdsc_cfg->flatness_min_qp = rc_params->flatness_min_qp;
  1209. vdsc_cfg->flatness_max_qp = rc_params->flatness_max_qp;
  1210. vdsc_cfg->rc_quant_incr_limit0 = rc_params->rc_quant_incr_limit0;
  1211. vdsc_cfg->rc_quant_incr_limit1 = rc_params->rc_quant_incr_limit1;
  1212. for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
  1213. vdsc_cfg->rc_range_params[i].range_min_qp =
  1214. rc_params->rc_range_params[i].range_min_qp;
  1215. vdsc_cfg->rc_range_params[i].range_max_qp =
  1216. rc_params->rc_range_params[i].range_max_qp;
  1217. /*
  1218. * Range BPG Offset uses 2's complement and is only a 6 bits. So
  1219. * mask it to get only 6 bits.
  1220. */
  1221. vdsc_cfg->rc_range_params[i].range_bpg_offset =
  1222. rc_params->rc_range_params[i].range_bpg_offset &
  1223. DSC_RANGE_BPG_OFFSET_MASK;
  1224. }
  1225. return 0;
  1226. }
  1227. EXPORT_SYMBOL(drm_dsc_setup_rc_params);
  1228. /**
  1229. * drm_dsc_compute_rc_parameters() - Write rate control
  1230. * parameters to the dsc configuration defined in
  1231. * &struct drm_dsc_config in accordance with the DSC 1.2
  1232. * specification. Some configuration fields must be present
  1233. * beforehand.
  1234. *
  1235. * @vdsc_cfg:
  1236. * DSC Configuration data partially filled by driver
  1237. */
  1238. int drm_dsc_compute_rc_parameters(struct drm_dsc_config *vdsc_cfg)
  1239. {
  1240. unsigned long groups_per_line = 0;
  1241. unsigned long groups_total = 0;
  1242. unsigned long num_extra_mux_bits = 0;
  1243. unsigned long slice_bits = 0;
  1244. unsigned long hrd_delay = 0;
  1245. unsigned long final_scale = 0;
  1246. unsigned long rbs_min = 0;
  1247. if (vdsc_cfg->native_420 || vdsc_cfg->native_422) {
  1248. /* Number of groups used to code each line of a slice */
  1249. groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width / 2,
  1250. DSC_RC_PIXELS_PER_GROUP);
  1251. /* chunksize in Bytes */
  1252. vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width / 2 *
  1253. vdsc_cfg->bits_per_pixel,
  1254. (8 * 16));
  1255. } else {
  1256. /* Number of groups used to code each line of a slice */
  1257. groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width,
  1258. DSC_RC_PIXELS_PER_GROUP);
  1259. /* chunksize in Bytes */
  1260. vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width *
  1261. vdsc_cfg->bits_per_pixel,
  1262. (8 * 16));
  1263. }
  1264. if (vdsc_cfg->convert_rgb)
  1265. num_extra_mux_bits = 3 * (vdsc_cfg->mux_word_size +
  1266. (4 * vdsc_cfg->bits_per_component + 4)
  1267. - 2);
  1268. else if (vdsc_cfg->native_422)
  1269. num_extra_mux_bits = 4 * vdsc_cfg->mux_word_size +
  1270. (4 * vdsc_cfg->bits_per_component + 4) +
  1271. 3 * (4 * vdsc_cfg->bits_per_component) - 2;
  1272. else
  1273. num_extra_mux_bits = 3 * vdsc_cfg->mux_word_size +
  1274. (4 * vdsc_cfg->bits_per_component + 4) +
  1275. 2 * (4 * vdsc_cfg->bits_per_component) - 2;
  1276. /* Number of bits in one Slice */
  1277. slice_bits = 8 * vdsc_cfg->slice_chunk_size * vdsc_cfg->slice_height;
  1278. while ((num_extra_mux_bits > 0) &&
  1279. ((slice_bits - num_extra_mux_bits) % vdsc_cfg->mux_word_size))
  1280. num_extra_mux_bits--;
  1281. if (groups_per_line < vdsc_cfg->initial_scale_value - 8)
  1282. vdsc_cfg->initial_scale_value = groups_per_line + 8;
  1283. /* scale_decrement_interval calculation according to DSC spec 1.11 */
  1284. if (vdsc_cfg->initial_scale_value > 8)
  1285. vdsc_cfg->scale_decrement_interval = groups_per_line /
  1286. (vdsc_cfg->initial_scale_value - 8);
  1287. else
  1288. vdsc_cfg->scale_decrement_interval = DSC_SCALE_DECREMENT_INTERVAL_MAX;
  1289. vdsc_cfg->final_offset = vdsc_cfg->rc_model_size -
  1290. (vdsc_cfg->initial_xmit_delay *
  1291. vdsc_cfg->bits_per_pixel + 8) / 16 + num_extra_mux_bits;
  1292. if (vdsc_cfg->final_offset >= vdsc_cfg->rc_model_size) {
  1293. DRM_DEBUG_KMS("FinalOfs < RcModelSze for this InitialXmitDelay\n");
  1294. return -ERANGE;
  1295. }
  1296. final_scale = (vdsc_cfg->rc_model_size * 8) /
  1297. (vdsc_cfg->rc_model_size - vdsc_cfg->final_offset);
  1298. if (vdsc_cfg->slice_height > 1)
  1299. /*
  1300. * NflBpgOffset is 16 bit value with 11 fractional bits
  1301. * hence we multiply by 2^11 for preserving the
  1302. * fractional part
  1303. */
  1304. vdsc_cfg->nfl_bpg_offset = DIV_ROUND_UP((vdsc_cfg->first_line_bpg_offset << 11),
  1305. (vdsc_cfg->slice_height - 1));
  1306. else
  1307. vdsc_cfg->nfl_bpg_offset = 0;
  1308. /* Number of groups used to code the entire slice */
  1309. groups_total = groups_per_line * vdsc_cfg->slice_height;
  1310. /* slice_bpg_offset is 16 bit value with 11 fractional bits */
  1311. vdsc_cfg->slice_bpg_offset = DIV_ROUND_UP(((vdsc_cfg->rc_model_size -
  1312. vdsc_cfg->initial_offset +
  1313. num_extra_mux_bits) << 11),
  1314. groups_total);
  1315. if (final_scale > 9) {
  1316. /*
  1317. * ScaleIncrementInterval =
  1318. * finaloffset/((NflBpgOffset + SliceBpgOffset)*8(finalscale - 1.125))
  1319. * as (NflBpgOffset + SliceBpgOffset) has 11 bit fractional value,
  1320. * we need divide by 2^11 from pstDscCfg values
  1321. */
  1322. vdsc_cfg->scale_increment_interval =
  1323. (vdsc_cfg->final_offset * (1 << 11)) /
  1324. ((vdsc_cfg->nfl_bpg_offset +
  1325. vdsc_cfg->slice_bpg_offset) *
  1326. (final_scale - 9));
  1327. } else {
  1328. /*
  1329. * If finalScaleValue is less than or equal to 9, a value of 0 should
  1330. * be used to disable the scale increment at the end of the slice
  1331. */
  1332. vdsc_cfg->scale_increment_interval = 0;
  1333. }
  1334. /*
  1335. * DSC spec mentions that bits_per_pixel specifies the target
  1336. * bits/pixel (bpp) rate that is used by the encoder,
  1337. * in steps of 1/16 of a bit per pixel
  1338. */
  1339. rbs_min = vdsc_cfg->rc_model_size - vdsc_cfg->initial_offset +
  1340. DIV_ROUND_UP(vdsc_cfg->initial_xmit_delay *
  1341. vdsc_cfg->bits_per_pixel, 16) +
  1342. groups_per_line * vdsc_cfg->first_line_bpg_offset;
  1343. hrd_delay = DIV_ROUND_UP((rbs_min * 16), vdsc_cfg->bits_per_pixel);
  1344. vdsc_cfg->rc_bits = (hrd_delay * vdsc_cfg->bits_per_pixel) / 16;
  1345. vdsc_cfg->initial_dec_delay = hrd_delay - vdsc_cfg->initial_xmit_delay;
  1346. return 0;
  1347. }
  1348. EXPORT_SYMBOL(drm_dsc_compute_rc_parameters);
  1349. /**
  1350. * drm_dsc_get_bpp_int() - Get integer bits per pixel value for the given DRM DSC config
  1351. * @vdsc_cfg: Pointer to DRM DSC config struct
  1352. *
  1353. * Return: Integer BPP value
  1354. */
  1355. u32 drm_dsc_get_bpp_int(const struct drm_dsc_config *vdsc_cfg)
  1356. {
  1357. WARN_ON_ONCE(vdsc_cfg->bits_per_pixel & 0xf);
  1358. return vdsc_cfg->bits_per_pixel >> 4;
  1359. }
  1360. EXPORT_SYMBOL(drm_dsc_get_bpp_int);
  1361. /**
  1362. * drm_dsc_initial_scale_value() - Calculate the initial scale value for the given DSC config
  1363. * @dsc: Pointer to DRM DSC config struct
  1364. *
  1365. * Return: Calculated initial scale value
  1366. */
  1367. u8 drm_dsc_initial_scale_value(const struct drm_dsc_config *dsc)
  1368. {
  1369. return 8 * dsc->rc_model_size / (dsc->rc_model_size - dsc->initial_offset);
  1370. }
  1371. EXPORT_SYMBOL(drm_dsc_initial_scale_value);
  1372. /**
  1373. * drm_dsc_flatness_det_thresh() - Calculate the flatness_det_thresh for the given DSC config
  1374. * @dsc: Pointer to DRM DSC config struct
  1375. *
  1376. * Return: Calculated flatness det thresh value
  1377. */
  1378. u32 drm_dsc_flatness_det_thresh(const struct drm_dsc_config *dsc)
  1379. {
  1380. return 2 << (dsc->bits_per_component - 8);
  1381. }
  1382. EXPORT_SYMBOL(drm_dsc_flatness_det_thresh);
  1383. static void drm_dsc_dump_config_main_params(struct drm_printer *p, int indent,
  1384. const struct drm_dsc_config *cfg)
  1385. {
  1386. drm_printf_indent(p, indent,
  1387. "dsc-cfg: version: %d.%d, picture: w=%d, h=%d, slice: count=%d, w=%d, h=%d, size=%d\n",
  1388. cfg->dsc_version_major, cfg->dsc_version_minor,
  1389. cfg->pic_width, cfg->pic_height,
  1390. cfg->slice_count, cfg->slice_width, cfg->slice_height, cfg->slice_chunk_size);
  1391. drm_printf_indent(p, indent,
  1392. "dsc-cfg: mode: block-pred=%s, vbr=%s, rgb=%s, simple-422=%s, native-422=%s, native-420=%s\n",
  1393. str_yes_no(cfg->block_pred_enable), str_yes_no(cfg->vbr_enable),
  1394. str_yes_no(cfg->convert_rgb),
  1395. str_yes_no(cfg->simple_422), str_yes_no(cfg->native_422), str_yes_no(cfg->native_420));
  1396. drm_printf_indent(p, indent,
  1397. "dsc-cfg: color-depth: uncompressed-bpc=%d, compressed-bpp=" FXP_Q4_FMT " line-buf-bpp=%d\n",
  1398. cfg->bits_per_component, FXP_Q4_ARGS(cfg->bits_per_pixel), cfg->line_buf_depth);
  1399. drm_printf_indent(p, indent,
  1400. "dsc-cfg: rc-model: size=%d, bits=%d, mux-word-size: %d, initial-delays: xmit=%d, dec=%d\n",
  1401. cfg->rc_model_size, cfg->rc_bits, cfg->mux_word_size,
  1402. cfg->initial_xmit_delay, cfg->initial_dec_delay);
  1403. drm_printf_indent(p, indent,
  1404. "dsc-cfg: offsets: initial=%d, final=%d, slice-bpg=%d\n",
  1405. cfg->initial_offset, cfg->final_offset, cfg->slice_bpg_offset);
  1406. drm_printf_indent(p, indent,
  1407. "dsc-cfg: line-bpg-offsets: first=%d, non-first=%d, second=%d, non-second=%d, second-adj=%d\n",
  1408. cfg->first_line_bpg_offset, cfg->nfl_bpg_offset,
  1409. cfg->second_line_bpg_offset, cfg->nsl_bpg_offset, cfg->second_line_offset_adj);
  1410. drm_printf_indent(p, indent,
  1411. "dsc-cfg: rc-tgt-offsets: low=%d, high=%d, rc-edge-factor: %d, rc-quant-incr-limits: [0]=%d, [1]=%d\n",
  1412. cfg->rc_tgt_offset_low, cfg->rc_tgt_offset_high,
  1413. cfg->rc_edge_factor, cfg->rc_quant_incr_limit0, cfg->rc_quant_incr_limit1);
  1414. drm_printf_indent(p, indent,
  1415. "dsc-cfg: initial-scale: %d, scale-intervals: increment=%d, decrement=%d\n",
  1416. cfg->initial_scale_value, cfg->scale_increment_interval, cfg->scale_decrement_interval);
  1417. drm_printf_indent(p, indent,
  1418. "dsc-cfg: flatness: min-qp=%d, max-qp=%d\n",
  1419. cfg->flatness_min_qp, cfg->flatness_max_qp);
  1420. }
  1421. static void drm_dsc_dump_config_rc_params(struct drm_printer *p, int indent,
  1422. const struct drm_dsc_config *cfg)
  1423. {
  1424. const u16 *bt = cfg->rc_buf_thresh;
  1425. const struct drm_dsc_rc_range_parameters *rp = cfg->rc_range_params;
  1426. BUILD_BUG_ON(ARRAY_SIZE(cfg->rc_buf_thresh) != 14);
  1427. BUILD_BUG_ON(ARRAY_SIZE(cfg->rc_range_params) != 15);
  1428. drm_printf_indent(p, indent,
  1429. "dsc-cfg: rc-level: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14\n");
  1430. drm_printf_indent(p, indent,
  1431. "dsc-cfg: rc-buf-thresh: %3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d\n",
  1432. bt[0], bt[1], bt[2], bt[3], bt[4], bt[5], bt[6], bt[7],
  1433. bt[8], bt[9], bt[10], bt[11], bt[12], bt[13]);
  1434. drm_printf_indent(p, indent,
  1435. "dsc-cfg: rc-min-qp: %3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d\n",
  1436. rp[0].range_min_qp, rp[1].range_min_qp, rp[2].range_min_qp, rp[3].range_min_qp,
  1437. rp[4].range_min_qp, rp[5].range_min_qp, rp[6].range_min_qp, rp[7].range_min_qp,
  1438. rp[8].range_min_qp, rp[9].range_min_qp, rp[10].range_min_qp, rp[11].range_min_qp,
  1439. rp[12].range_min_qp, rp[13].range_min_qp, rp[14].range_min_qp);
  1440. drm_printf_indent(p, indent,
  1441. "dsc-cfg: rc-max-qp: %3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d\n",
  1442. rp[0].range_max_qp, rp[1].range_max_qp, rp[2].range_max_qp, rp[3].range_max_qp,
  1443. rp[4].range_max_qp, rp[5].range_max_qp, rp[6].range_max_qp, rp[7].range_max_qp,
  1444. rp[8].range_max_qp, rp[9].range_max_qp, rp[10].range_max_qp, rp[11].range_max_qp,
  1445. rp[12].range_max_qp, rp[13].range_max_qp, rp[14].range_max_qp);
  1446. drm_printf_indent(p, indent,
  1447. "dsc-cfg: rc-bpg-offset: %3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d,%3d\n",
  1448. rp[0].range_bpg_offset, rp[1].range_bpg_offset, rp[2].range_bpg_offset, rp[3].range_bpg_offset,
  1449. rp[4].range_bpg_offset, rp[5].range_bpg_offset, rp[6].range_bpg_offset, rp[7].range_bpg_offset,
  1450. rp[8].range_bpg_offset, rp[9].range_bpg_offset, rp[10].range_bpg_offset, rp[11].range_bpg_offset,
  1451. rp[12].range_bpg_offset, rp[13].range_bpg_offset, rp[14].range_bpg_offset);
  1452. }
  1453. /**
  1454. * drm_dsc_dump_config - Dump the provided DSC configuration
  1455. * @p: The printer used for output
  1456. * @indent: Tab indentation level (max 5)
  1457. * @cfg: DSC configuration to print
  1458. *
  1459. * Print the provided DSC configuration in @cfg.
  1460. */
  1461. void drm_dsc_dump_config(struct drm_printer *p, int indent,
  1462. const struct drm_dsc_config *cfg)
  1463. {
  1464. drm_dsc_dump_config_main_params(p, indent, cfg);
  1465. drm_dsc_dump_config_rc_params(p, indent, cfg);
  1466. }
  1467. EXPORT_SYMBOL(drm_dsc_dump_config);