dp_panel.c 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022, Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #include "dp_panel.h"
  7. #include <linux/unistd.h>
  8. #include <drm/drm_fixed.h>
  9. #include "dp_debug.h"
  10. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0))
  11. #include <drm/display/drm_dsc.h>
  12. #else
  13. #include <drm/drm_dsc.h>
  14. #endif
  15. #include "sde_dsc_helper.h"
  16. #include <drm/drm_edid.h>
  17. #define DP_KHZ_TO_HZ 1000
  18. #define DP_PANEL_DEFAULT_BPP 24
  19. #define DP_MAX_DS_PORT_COUNT 1
  20. #define DSC_TGT_BPP 8
  21. #define DPRX_FEATURE_ENUMERATION_LIST 0x2210
  22. #define DPRX_EXTENDED_DPCD_FIELD 0x2200
  23. #define VSC_SDP_EXTENSION_FOR_COLORIMETRY_SUPPORTED BIT(3)
  24. #define VSC_EXT_VESA_SDP_SUPPORTED BIT(4)
  25. #define VSC_EXT_VESA_SDP_CHAINING_SUPPORTED BIT(5)
  26. enum dp_panel_hdr_pixel_encoding {
  27. RGB,
  28. YCbCr444,
  29. YCbCr422,
  30. YCbCr420,
  31. YONLY,
  32. RAW,
  33. };
  34. enum dp_panel_hdr_rgb_colorimetry {
  35. sRGB,
  36. RGB_WIDE_GAMUT_FIXED_POINT,
  37. RGB_WIDE_GAMUT_FLOATING_POINT,
  38. ADOBERGB,
  39. DCI_P3,
  40. CUSTOM_COLOR_PROFILE,
  41. ITU_R_BT_2020_RGB,
  42. };
  43. enum dp_panel_hdr_dynamic_range {
  44. VESA,
  45. CEA,
  46. };
  47. enum dp_panel_hdr_content_type {
  48. NOT_DEFINED,
  49. GRAPHICS,
  50. PHOTO,
  51. VIDEO,
  52. GAME,
  53. };
  54. enum dp_panel_hdr_state {
  55. HDR_DISABLED,
  56. HDR_ENABLED,
  57. };
  58. struct dp_panel_private {
  59. struct device *dev;
  60. struct dp_panel dp_panel;
  61. struct dp_aux *aux;
  62. struct dp_link *link;
  63. struct dp_parser *parser;
  64. struct dp_catalog_panel *catalog;
  65. bool panel_on;
  66. bool vsc_supported;
  67. bool vscext_supported;
  68. bool vscext_chaining_supported;
  69. enum dp_panel_hdr_state hdr_state;
  70. u8 spd_vendor_name[8];
  71. u8 spd_product_description[16];
  72. u8 major;
  73. u8 minor;
  74. };
  75. static const struct dp_panel_info fail_safe = {
  76. .h_active = 640,
  77. .v_active = 480,
  78. .h_back_porch = 48,
  79. .h_front_porch = 16,
  80. .h_sync_width = 96,
  81. .h_active_low = 0,
  82. .v_back_porch = 33,
  83. .v_front_porch = 10,
  84. .v_sync_width = 2,
  85. .v_active_low = 0,
  86. .h_skew = 0,
  87. .refresh_rate = 60,
  88. .pixel_clk_khz = 25200,
  89. .bpp = 24,
  90. };
  91. /* OEM NAME */
  92. static const u8 vendor_name[8] = {81, 117, 97, 108, 99, 111, 109, 109};
  93. /* MODEL NAME */
  94. static const u8 product_desc[16] = {83, 110, 97, 112, 100, 114, 97, 103,
  95. 111, 110, 0, 0, 0, 0, 0, 0};
  96. struct dp_dhdr_maxpkt_calc_input {
  97. u32 mdp_clk;
  98. u32 lclk;
  99. u32 pclk;
  100. u32 h_active;
  101. u32 nlanes;
  102. s64 mst_target_sc;
  103. bool mst_en;
  104. bool fec_en;
  105. };
  106. struct tu_algo_data {
  107. s64 lclk_fp;
  108. s64 orig_lclk_fp;
  109. s64 pclk_fp;
  110. s64 orig_pclk_fp;
  111. s64 lwidth;
  112. s64 lwidth_fp;
  113. int orig_lwidth;
  114. s64 hbp_relative_to_pclk;
  115. s64 hbp_relative_to_pclk_fp;
  116. int orig_hbp;
  117. int nlanes;
  118. int bpp;
  119. int pixelEnc;
  120. int dsc_en;
  121. int async_en;
  122. int fec_en;
  123. int bpc;
  124. int rb2;
  125. uint delay_start_link_extra_pixclk;
  126. int extra_buffer_margin;
  127. s64 ratio_fp;
  128. s64 original_ratio_fp;
  129. s64 err_fp;
  130. s64 n_err_fp;
  131. s64 n_n_err_fp;
  132. int tu_size;
  133. int tu_size_desired;
  134. int tu_size_minus1;
  135. int valid_boundary_link;
  136. s64 resulting_valid_fp;
  137. s64 total_valid_fp;
  138. s64 effective_valid_fp;
  139. s64 effective_valid_recorded_fp;
  140. int n_tus;
  141. int n_tus_per_lane;
  142. int paired_tus;
  143. int remainder_tus;
  144. int remainder_tus_upper;
  145. int remainder_tus_lower;
  146. int extra_bytes;
  147. int filler_size;
  148. int delay_start_link;
  149. int extra_pclk_cycles;
  150. int extra_pclk_cycles_in_link_clk;
  151. s64 ratio_by_tu_fp;
  152. s64 average_valid2_fp;
  153. int new_valid_boundary_link;
  154. int remainder_symbols_exist;
  155. int n_symbols;
  156. s64 n_remainder_symbols_per_lane_fp;
  157. s64 last_partial_tu_fp;
  158. s64 TU_ratio_err_fp;
  159. int n_tus_incl_last_incomplete_tu;
  160. int extra_pclk_cycles_tmp;
  161. int extra_pclk_cycles_in_link_clk_tmp;
  162. int extra_required_bytes_new_tmp;
  163. int filler_size_tmp;
  164. int lower_filler_size_tmp;
  165. int delay_start_link_tmp;
  166. bool boundary_moderation_en;
  167. int boundary_mod_lower_err;
  168. int upper_boundary_count;
  169. int lower_boundary_count;
  170. int i_upper_boundary_count;
  171. int i_lower_boundary_count;
  172. int valid_lower_boundary_link;
  173. int even_distribution_BF;
  174. int even_distribution_legacy;
  175. int even_distribution;
  176. int hbp_delayStartCheck;
  177. int pre_tu_hw_pipe_delay;
  178. int post_tu_hw_pipe_delay;
  179. int link_config_hactive_time;
  180. int delay_start_link_lclk;
  181. int tu_active_cycles;
  182. s64 parity_symbols;
  183. int resolution_line_time;
  184. int last_partial_lclk;
  185. int min_hblank_violated;
  186. s64 delay_start_time_fp;
  187. s64 hbp_time_fp;
  188. s64 hactive_time_fp;
  189. s64 diff_abs_fp;
  190. int second_loop_set;
  191. s64 ratio;
  192. };
  193. /**
  194. * Mapper function which outputs colorimetry and dynamic range
  195. * to be used for a given colorspace value when the vsc sdp
  196. * packets are used to change the colorimetry.
  197. */
  198. static void get_sdp_colorimetry_range(struct dp_panel_private *panel,
  199. u32 colorspace, u32 *colorimetry, u32 *dynamic_range)
  200. {
  201. u32 cc;
  202. /*
  203. * Some rules being used for assignment of dynamic
  204. * range for colorimetry using SDP:
  205. *
  206. * 1) If compliance test is ongoing return sRGB with
  207. * CEA primaries
  208. * 2) For BT2020 cases, dynamic range shall be CEA
  209. * 3) For DCI-P3 cases, as per HW team dynamic range
  210. * shall be VESA for RGB and CEA for YUV content
  211. * Hence defaulting to RGB and picking VESA
  212. * 4) Default shall be sRGB with VESA
  213. */
  214. cc = panel->link->get_colorimetry_config(panel->link);
  215. if (cc) {
  216. *colorimetry = sRGB;
  217. *dynamic_range = CEA;
  218. return;
  219. }
  220. switch (colorspace) {
  221. case DRM_MODE_COLORIMETRY_BT2020_RGB:
  222. *colorimetry = ITU_R_BT_2020_RGB;
  223. *dynamic_range = CEA;
  224. break;
  225. case DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65:
  226. case DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER:
  227. *colorimetry = DCI_P3;
  228. *dynamic_range = VESA;
  229. break;
  230. default:
  231. *colorimetry = sRGB;
  232. *dynamic_range = VESA;
  233. }
  234. }
  235. /**
  236. * Mapper function which outputs colorimetry to be used for a
  237. * given colorspace value when misc field of MSA is used to
  238. * change the colorimetry. Currently only RGB formats have been
  239. * added. This API will be extended to YUV once its supported on DP.
  240. */
  241. static u8 get_misc_colorimetry_val(struct dp_panel_private *panel,
  242. u32 colorspace)
  243. {
  244. u8 colorimetry;
  245. u32 cc;
  246. cc = panel->link->get_colorimetry_config(panel->link);
  247. /*
  248. * If there is a non-zero value then compliance test-case
  249. * is going on, otherwise we can honor the colorspace setting
  250. */
  251. if (cc)
  252. return cc;
  253. switch (colorspace) {
  254. case DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65:
  255. case DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER:
  256. colorimetry = 0x7;
  257. break;
  258. case DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED:
  259. colorimetry = 0x3;
  260. break;
  261. case DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT:
  262. colorimetry = 0xb;
  263. break;
  264. case DRM_MODE_COLORIMETRY_OPRGB:
  265. colorimetry = 0xc;
  266. break;
  267. default:
  268. colorimetry = 0;
  269. }
  270. return colorimetry;
  271. }
  272. static int _tu_param_compare(s64 a, s64 b)
  273. {
  274. u32 a_int, a_frac, a_sign;
  275. u32 b_int, b_frac, b_sign;
  276. s64 a_temp, b_temp, minus_1;
  277. if (a == b)
  278. return 0;
  279. minus_1 = drm_fixp_from_fraction(-1, 1);
  280. a_int = (a >> 32) & 0x7FFFFFFF;
  281. a_frac = a & 0xFFFFFFFF;
  282. a_sign = (a >> 32) & 0x80000000 ? 1 : 0;
  283. b_int = (b >> 32) & 0x7FFFFFFF;
  284. b_frac = b & 0xFFFFFFFF;
  285. b_sign = (b >> 32) & 0x80000000 ? 1 : 0;
  286. if (a_sign > b_sign)
  287. return 2;
  288. else if (b_sign > a_sign)
  289. return 1;
  290. if (!a_sign && !b_sign) { /* positive */
  291. if (a > b)
  292. return 1;
  293. else
  294. return 2;
  295. } else { /* negative */
  296. a_temp = drm_fixp_mul(a, minus_1);
  297. b_temp = drm_fixp_mul(b, minus_1);
  298. if (a_temp > b_temp)
  299. return 2;
  300. else
  301. return 1;
  302. }
  303. }
  304. static s64 fixp_subtract(s64 a, s64 b)
  305. {
  306. s64 minus_1 = drm_fixp_from_fraction(-1, 1);
  307. if (a >= b)
  308. return a - b;
  309. return drm_fixp_mul(b - a, minus_1);
  310. }
  311. static inline int fixp2int_ceil(s64 a)
  312. {
  313. return (a ? drm_fixp2int_ceil(a) : 0);
  314. }
  315. static void dp_panel_update_tu_timings(struct dp_tu_calc_input *in,
  316. struct tu_algo_data *tu)
  317. {
  318. int nlanes = in->nlanes;
  319. int dsc_num_slices = in->num_of_dsc_slices;
  320. int dsc_num_bytes = 0;
  321. int numerator;
  322. s64 pclk_dsc_fp;
  323. s64 dwidth_dsc_fp;
  324. s64 hbp_dsc_fp;
  325. s64 overhead_dsc;
  326. int tot_num_eoc_symbols = 0;
  327. int tot_num_hor_bytes = 0;
  328. int tot_num_dummy_bytes = 0;
  329. int dwidth_dsc_bytes = 0;
  330. int eoc_bytes = 0;
  331. s64 temp1_fp, temp2_fp, temp3_fp;
  332. tu->lclk_fp = drm_fixp_from_fraction(in->lclk, 1);
  333. tu->orig_lclk_fp = tu->lclk_fp;
  334. tu->pclk_fp = drm_fixp_from_fraction(in->pclk_khz, 1000);
  335. tu->orig_pclk_fp = tu->pclk_fp;
  336. tu->lwidth = in->hactive;
  337. tu->hbp_relative_to_pclk = in->hporch;
  338. tu->nlanes = in->nlanes;
  339. tu->bpp = in->bpp;
  340. tu->pixelEnc = in->pixel_enc;
  341. tu->dsc_en = in->dsc_en;
  342. tu->fec_en = in->fec_en;
  343. tu->async_en = in->async_en;
  344. tu->lwidth_fp = drm_fixp_from_fraction(in->hactive, 1);
  345. tu->orig_lwidth = in->hactive;
  346. tu->hbp_relative_to_pclk_fp = drm_fixp_from_fraction(in->hporch, 1);
  347. tu->orig_hbp = in->hporch;
  348. tu->rb2 = (in->hporch <= 80) ? 1 : 0;
  349. if (tu->pixelEnc == 420) {
  350. temp1_fp = drm_fixp_from_fraction(2, 1);
  351. tu->pclk_fp = drm_fixp_div(tu->pclk_fp, temp1_fp);
  352. tu->lwidth_fp = drm_fixp_div(tu->lwidth_fp, temp1_fp);
  353. tu->hbp_relative_to_pclk_fp =
  354. drm_fixp_div(tu->hbp_relative_to_pclk_fp, 2);
  355. }
  356. if (tu->pixelEnc == 422) {
  357. switch (tu->bpp) {
  358. case 24:
  359. tu->bpp = 16;
  360. tu->bpc = 8;
  361. break;
  362. case 30:
  363. tu->bpp = 20;
  364. tu->bpc = 10;
  365. break;
  366. default:
  367. tu->bpp = 16;
  368. tu->bpc = 8;
  369. break;
  370. }
  371. } else
  372. tu->bpc = tu->bpp/3;
  373. if (!in->dsc_en)
  374. goto fec_check;
  375. temp1_fp = drm_fixp_from_fraction(in->compress_ratio, 100);
  376. temp2_fp = drm_fixp_from_fraction(in->bpp, 1);
  377. temp3_fp = drm_fixp_div(temp2_fp, temp1_fp);
  378. temp2_fp = drm_fixp_mul(tu->lwidth_fp, temp3_fp);
  379. temp1_fp = drm_fixp_from_fraction(8, 1);
  380. temp3_fp = drm_fixp_div(temp2_fp, temp1_fp);
  381. numerator = drm_fixp2int(temp3_fp);
  382. dsc_num_bytes = numerator / dsc_num_slices;
  383. eoc_bytes = dsc_num_bytes % nlanes;
  384. tot_num_eoc_symbols = nlanes * dsc_num_slices;
  385. tot_num_hor_bytes = dsc_num_bytes * dsc_num_slices;
  386. tot_num_dummy_bytes = (nlanes - eoc_bytes) * dsc_num_slices;
  387. if (dsc_num_bytes == 0)
  388. DP_WARN("incorrect no of bytes per slice=%d\n", dsc_num_bytes);
  389. dwidth_dsc_bytes = (tot_num_hor_bytes +
  390. tot_num_eoc_symbols +
  391. (eoc_bytes == 0 ? 0 : tot_num_dummy_bytes));
  392. overhead_dsc = dwidth_dsc_bytes / tot_num_hor_bytes;
  393. dwidth_dsc_fp = drm_fixp_from_fraction(dwidth_dsc_bytes, 3);
  394. temp2_fp = drm_fixp_mul(tu->pclk_fp, dwidth_dsc_fp);
  395. temp1_fp = drm_fixp_div(temp2_fp, tu->lwidth_fp);
  396. pclk_dsc_fp = temp1_fp;
  397. temp1_fp = drm_fixp_div(pclk_dsc_fp, tu->pclk_fp);
  398. temp2_fp = drm_fixp_mul(tu->hbp_relative_to_pclk_fp, temp1_fp);
  399. hbp_dsc_fp = temp2_fp;
  400. /* output */
  401. tu->pclk_fp = pclk_dsc_fp;
  402. tu->lwidth_fp = dwidth_dsc_fp;
  403. tu->hbp_relative_to_pclk_fp = hbp_dsc_fp;
  404. fec_check:
  405. if (in->fec_en) {
  406. temp1_fp = drm_fixp_from_fraction(976, 1000); /* 0.976 */
  407. tu->lclk_fp = drm_fixp_mul(tu->lclk_fp, temp1_fp);
  408. }
  409. }
  410. static void _tu_valid_boundary_calc(struct tu_algo_data *tu)
  411. {
  412. s64 temp1_fp, temp2_fp, temp, temp1, temp2;
  413. int compare_result_1, compare_result_2, compare_result_3;
  414. temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
  415. temp2_fp = drm_fixp_mul(tu->ratio_fp, temp1_fp);
  416. tu->new_valid_boundary_link = fixp2int_ceil(temp2_fp);
  417. temp = (tu->i_upper_boundary_count *
  418. tu->new_valid_boundary_link +
  419. tu->i_lower_boundary_count *
  420. (tu->new_valid_boundary_link - 1));
  421. tu->average_valid2_fp = drm_fixp_from_fraction(temp,
  422. (tu->i_upper_boundary_count +
  423. tu->i_lower_boundary_count));
  424. temp1_fp = drm_fixp_from_fraction(tu->bpp, 8);
  425. temp2_fp = tu->lwidth_fp;
  426. temp1_fp = drm_fixp_mul(temp2_fp, temp1_fp);
  427. temp2_fp = drm_fixp_div(temp1_fp, tu->average_valid2_fp);
  428. tu->n_tus = drm_fixp2int(temp2_fp);
  429. if ((temp2_fp & 0xFFFFFFFF) > 0xFFFFF000)
  430. tu->n_tus += 1;
  431. temp1_fp = drm_fixp_from_fraction(tu->n_tus, 1);
  432. temp2_fp = drm_fixp_mul(temp1_fp, tu->average_valid2_fp);
  433. temp1_fp = drm_fixp_from_fraction(tu->n_symbols, 1);
  434. temp2_fp = temp1_fp - temp2_fp;
  435. temp1_fp = drm_fixp_from_fraction(tu->nlanes, 1);
  436. temp2_fp = drm_fixp_div(temp2_fp, temp1_fp);
  437. tu->n_remainder_symbols_per_lane_fp = temp2_fp;
  438. temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
  439. tu->last_partial_tu_fp =
  440. drm_fixp_div(tu->n_remainder_symbols_per_lane_fp,
  441. temp1_fp);
  442. if (tu->n_remainder_symbols_per_lane_fp != 0)
  443. tu->remainder_symbols_exist = 1;
  444. else
  445. tu->remainder_symbols_exist = 0;
  446. temp1_fp = drm_fixp_from_fraction(tu->n_tus, tu->nlanes);
  447. tu->n_tus_per_lane = drm_fixp2int(temp1_fp);
  448. tu->paired_tus = (int)((tu->n_tus_per_lane) /
  449. (tu->i_upper_boundary_count +
  450. tu->i_lower_boundary_count));
  451. tu->remainder_tus = tu->n_tus_per_lane - tu->paired_tus *
  452. (tu->i_upper_boundary_count +
  453. tu->i_lower_boundary_count);
  454. if ((tu->remainder_tus - tu->i_upper_boundary_count) > 0) {
  455. tu->remainder_tus_upper = tu->i_upper_boundary_count;
  456. tu->remainder_tus_lower = tu->remainder_tus -
  457. tu->i_upper_boundary_count;
  458. } else {
  459. tu->remainder_tus_upper = tu->remainder_tus;
  460. tu->remainder_tus_lower = 0;
  461. }
  462. temp = tu->paired_tus * (tu->i_upper_boundary_count *
  463. tu->new_valid_boundary_link +
  464. tu->i_lower_boundary_count *
  465. (tu->new_valid_boundary_link - 1)) +
  466. (tu->remainder_tus_upper *
  467. tu->new_valid_boundary_link) +
  468. (tu->remainder_tus_lower *
  469. (tu->new_valid_boundary_link - 1));
  470. tu->total_valid_fp = drm_fixp_from_fraction(temp, 1);
  471. if (tu->remainder_symbols_exist) {
  472. temp1_fp = tu->total_valid_fp +
  473. tu->n_remainder_symbols_per_lane_fp;
  474. temp2_fp = drm_fixp_from_fraction(tu->n_tus_per_lane, 1);
  475. temp2_fp = temp2_fp + tu->last_partial_tu_fp;
  476. temp1_fp = drm_fixp_div(temp1_fp, temp2_fp);
  477. } else {
  478. temp2_fp = drm_fixp_from_fraction(tu->n_tus_per_lane, 1);
  479. temp1_fp = drm_fixp_div(tu->total_valid_fp, temp2_fp);
  480. }
  481. tu->effective_valid_fp = temp1_fp;
  482. temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
  483. temp2_fp = drm_fixp_mul(tu->ratio_fp, temp1_fp);
  484. tu->n_n_err_fp = fixp_subtract(tu->effective_valid_fp, temp2_fp);
  485. temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
  486. temp2_fp = drm_fixp_mul(tu->ratio_fp, temp1_fp);
  487. tu->n_err_fp = fixp_subtract(tu->average_valid2_fp, temp2_fp);
  488. tu->even_distribution = tu->n_tus % tu->nlanes == 0 ? 1 : 0;
  489. temp1_fp = drm_fixp_from_fraction(tu->bpp, 8);
  490. temp2_fp = tu->lwidth_fp;
  491. temp1_fp = drm_fixp_mul(temp2_fp, temp1_fp);
  492. temp2_fp = drm_fixp_div(temp1_fp, tu->average_valid2_fp);
  493. tu->n_tus_incl_last_incomplete_tu = fixp2int_ceil(temp2_fp);
  494. temp1 = 0;
  495. temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
  496. temp2_fp = drm_fixp_mul(tu->original_ratio_fp, temp1_fp);
  497. temp1_fp = tu->average_valid2_fp - temp2_fp;
  498. temp2_fp = drm_fixp_from_fraction(tu->n_tus_incl_last_incomplete_tu, 1);
  499. temp1_fp = drm_fixp_mul(temp2_fp, temp1_fp);
  500. temp1 = fixp2int_ceil(temp1_fp);
  501. temp = tu->i_upper_boundary_count * tu->nlanes;
  502. temp1_fp = drm_fixp_from_fraction(tu->tu_size, 1);
  503. temp2_fp = drm_fixp_mul(tu->original_ratio_fp, temp1_fp);
  504. temp1_fp = drm_fixp_from_fraction(tu->new_valid_boundary_link, 1);
  505. temp2_fp = temp1_fp - temp2_fp;
  506. temp1_fp = drm_fixp_from_fraction(temp, 1);
  507. temp2_fp = drm_fixp_mul(temp1_fp, temp2_fp);
  508. temp2 = fixp2int_ceil(temp2_fp);
  509. tu->extra_required_bytes_new_tmp = (int)(temp1 + temp2);
  510. temp1_fp = drm_fixp_from_fraction(8, tu->bpp);
  511. temp2_fp = drm_fixp_from_fraction(
  512. tu->extra_required_bytes_new_tmp, 1);
  513. temp1_fp = drm_fixp_mul(temp2_fp, temp1_fp);
  514. tu->extra_pclk_cycles_tmp = fixp2int_ceil(temp1_fp);
  515. temp1_fp = drm_fixp_from_fraction(tu->extra_pclk_cycles_tmp, 1);
  516. temp2_fp = drm_fixp_div(tu->lclk_fp, tu->pclk_fp);
  517. temp1_fp = drm_fixp_mul(temp1_fp, temp2_fp);
  518. tu->extra_pclk_cycles_in_link_clk_tmp = fixp2int_ceil(temp1_fp);
  519. tu->filler_size_tmp = tu->tu_size - tu->new_valid_boundary_link;
  520. tu->lower_filler_size_tmp = tu->filler_size_tmp + 1;
  521. tu->delay_start_link_tmp = tu->extra_pclk_cycles_in_link_clk_tmp +
  522. tu->lower_filler_size_tmp +
  523. tu->extra_buffer_margin;
  524. temp1_fp = drm_fixp_from_fraction(tu->delay_start_link_tmp, 1);
  525. tu->delay_start_time_fp = drm_fixp_div(temp1_fp, tu->lclk_fp);
  526. if (tu->rb2)
  527. {
  528. temp1_fp = drm_fixp_mul(tu->delay_start_time_fp, tu->lclk_fp);
  529. tu->delay_start_link_lclk = fixp2int_ceil(temp1_fp);
  530. if (tu->remainder_tus > tu->i_upper_boundary_count) {
  531. temp = (tu->remainder_tus - tu->i_upper_boundary_count) * (tu->new_valid_boundary_link - 1);
  532. temp += (tu->i_upper_boundary_count * tu->new_valid_boundary_link);
  533. temp *= tu->nlanes;
  534. } else {
  535. temp = tu->nlanes * tu->remainder_tus * tu->new_valid_boundary_link;
  536. }
  537. temp1 = tu->i_lower_boundary_count * (tu->new_valid_boundary_link - 1);
  538. temp1 += tu->i_upper_boundary_count * tu->new_valid_boundary_link;
  539. temp1 *= tu->paired_tus * tu->nlanes;
  540. temp1_fp = drm_fixp_from_fraction(tu->n_symbols - temp1 - temp, tu->nlanes);
  541. tu->last_partial_lclk = fixp2int_ceil(temp1_fp);
  542. tu->tu_active_cycles = (int)((tu->n_tus_per_lane * tu->tu_size) + tu->last_partial_lclk);
  543. tu->post_tu_hw_pipe_delay = 4 /*BS_on_the_link*/ + 1 /*BE_next_ren*/;
  544. temp = tu->pre_tu_hw_pipe_delay + tu->delay_start_link_lclk + tu->tu_active_cycles + tu->post_tu_hw_pipe_delay;
  545. if (tu->fec_en == 1)
  546. {
  547. if (tu->nlanes == 1)
  548. {
  549. temp1_fp = drm_fixp_from_fraction(temp, 500);
  550. tu->parity_symbols = fixp2int_ceil(temp1_fp) * 12 + 1;
  551. }
  552. else
  553. {
  554. temp1_fp = drm_fixp_from_fraction(temp, 250);
  555. tu->parity_symbols = fixp2int_ceil(temp1_fp) * 6 + 1;
  556. }
  557. }
  558. else //no fec BW impact
  559. {
  560. tu->parity_symbols = 0;
  561. }
  562. tu->link_config_hactive_time = temp + tu->parity_symbols;
  563. if (tu->resolution_line_time >= tu->link_config_hactive_time + 1 /*margin*/)
  564. tu->hbp_delayStartCheck = 1;
  565. else
  566. tu->hbp_delayStartCheck = 0;
  567. } else {
  568. compare_result_3 = _tu_param_compare(tu->hbp_time_fp, tu->delay_start_time_fp);
  569. if (compare_result_3 < 2)
  570. tu->hbp_delayStartCheck = 1;
  571. else
  572. tu->hbp_delayStartCheck = 0;
  573. }
  574. compare_result_1 = _tu_param_compare(tu->n_n_err_fp, tu->diff_abs_fp);
  575. if (compare_result_1 == 2)
  576. compare_result_1 = 1;
  577. else
  578. compare_result_1 = 0;
  579. compare_result_2 = _tu_param_compare(tu->n_n_err_fp, tu->err_fp);
  580. if (compare_result_2 == 2)
  581. compare_result_2 = 1;
  582. else
  583. compare_result_2 = 0;
  584. if (((tu->even_distribution == 1) ||
  585. ((tu->even_distribution_BF == 0) &&
  586. (tu->even_distribution_legacy == 0))) &&
  587. tu->n_err_fp >= 0 && tu->n_n_err_fp >= 0 &&
  588. compare_result_2 &&
  589. (compare_result_1 || (tu->min_hblank_violated == 1)) &&
  590. (tu->new_valid_boundary_link - 1) > 0 &&
  591. (tu->hbp_delayStartCheck == 1) &&
  592. (tu->delay_start_link_tmp <= 1023)) {
  593. tu->upper_boundary_count = tu->i_upper_boundary_count;
  594. tu->lower_boundary_count = tu->i_lower_boundary_count;
  595. tu->err_fp = tu->n_n_err_fp;
  596. tu->boundary_moderation_en = true;
  597. tu->tu_size_desired = tu->tu_size;
  598. tu->valid_boundary_link = tu->new_valid_boundary_link;
  599. tu->effective_valid_recorded_fp = tu->effective_valid_fp;
  600. tu->even_distribution_BF = 1;
  601. tu->delay_start_link = tu->delay_start_link_tmp;
  602. } else if (tu->boundary_mod_lower_err == 0) {
  603. compare_result_1 = _tu_param_compare(tu->n_n_err_fp,
  604. tu->diff_abs_fp);
  605. if (compare_result_1 == 2)
  606. tu->boundary_mod_lower_err = 1;
  607. }
  608. }
  609. static void _dp_calc_boundary(struct tu_algo_data *tu)
  610. {
  611. s64 temp1_fp = 0, temp2_fp = 0;
  612. do {
  613. tu->err_fp = drm_fixp_from_fraction(1000, 1);
  614. temp1_fp = drm_fixp_div(tu->lclk_fp, tu->pclk_fp);
  615. temp2_fp = drm_fixp_from_fraction(
  616. tu->delay_start_link_extra_pixclk, 1);
  617. temp1_fp = drm_fixp_mul(temp2_fp, temp1_fp);
  618. tu->extra_buffer_margin = fixp2int_ceil(temp1_fp);
  619. temp1_fp = drm_fixp_from_fraction(tu->bpp, 8);
  620. temp1_fp = drm_fixp_mul(tu->lwidth_fp, temp1_fp);
  621. tu->n_symbols = fixp2int_ceil(temp1_fp);
  622. for (tu->tu_size = 32; tu->tu_size <= 64; tu->tu_size++) {
  623. for (tu->i_upper_boundary_count = 1;
  624. tu->i_upper_boundary_count <= 15;
  625. tu->i_upper_boundary_count++) {
  626. for (tu->i_lower_boundary_count = 1;
  627. tu->i_lower_boundary_count <= 15;
  628. tu->i_lower_boundary_count++) {
  629. _tu_valid_boundary_calc(tu);
  630. }
  631. }
  632. }
  633. tu->delay_start_link_extra_pixclk--;
  634. } while (!tu->boundary_moderation_en &&
  635. tu->boundary_mod_lower_err == 1 &&
  636. tu->delay_start_link_extra_pixclk != 0 &&
  637. ((tu->second_loop_set == 0 && tu->rb2 == 1) || tu->rb2 == 0));
  638. }
  639. static void _dp_calc_extra_bytes(struct tu_algo_data *tu)
  640. {
  641. u64 temp = 0;
  642. s64 temp1_fp = 0, temp2_fp = 0;
  643. temp1_fp = drm_fixp_from_fraction(tu->tu_size_desired, 1);
  644. temp2_fp = drm_fixp_mul(tu->original_ratio_fp, temp1_fp);
  645. temp1_fp = drm_fixp_from_fraction(tu->valid_boundary_link, 1);
  646. temp2_fp = temp1_fp - temp2_fp;
  647. temp1_fp = drm_fixp_from_fraction(tu->n_tus + 1, 1);
  648. temp2_fp = drm_fixp_mul(temp1_fp, temp2_fp);
  649. temp = drm_fixp2int(temp2_fp);
  650. if (temp)
  651. tu->extra_bytes = fixp2int_ceil(temp2_fp);
  652. else
  653. tu->extra_bytes = 0;
  654. temp1_fp = drm_fixp_from_fraction(tu->extra_bytes, 1);
  655. temp2_fp = drm_fixp_from_fraction(8, tu->bpp);
  656. temp1_fp = drm_fixp_mul(temp1_fp, temp2_fp);
  657. tu->extra_pclk_cycles = fixp2int_ceil(temp1_fp);
  658. temp1_fp = drm_fixp_div(tu->lclk_fp, tu->pclk_fp);
  659. temp2_fp = drm_fixp_from_fraction(tu->extra_pclk_cycles, 1);
  660. temp1_fp = drm_fixp_mul(temp2_fp, temp1_fp);
  661. tu->extra_pclk_cycles_in_link_clk = fixp2int_ceil(temp1_fp);
  662. }
  663. static void _dp_panel_calc_tu(struct dp_tu_calc_input *in,
  664. struct dp_vc_tu_mapping_table *tu_table)
  665. {
  666. struct tu_algo_data tu;
  667. int compare_result_1, compare_result_2;
  668. u64 temp = 0, temp1;
  669. s64 temp_fp = 0, temp1_fp = 0, temp2_fp = 0;
  670. s64 LCLK_FAST_SKEW_fp = drm_fixp_from_fraction(6, 10000); /* 0.0006 */
  671. s64 RATIO_SCALE_fp = drm_fixp_from_fraction(1001, 1000);
  672. u8 DP_BRUTE_FORCE = 1;
  673. s64 BRUTE_FORCE_THRESHOLD_fp = drm_fixp_from_fraction(1, 10); /* 0.1 */
  674. uint EXTRA_PIXCLK_CYCLE_DELAY = 4;
  675. s64 HBLANK_MARGIN = drm_fixp_from_fraction(4, 1);
  676. s64 HBLANK_MARGIN_EXTRA = 0;
  677. memset(&tu, 0, sizeof(tu));
  678. dp_panel_update_tu_timings(in, &tu);
  679. tu.err_fp = drm_fixp_from_fraction(1000, 1); /* 1000 */
  680. temp1_fp = drm_fixp_from_fraction(4, 1);
  681. temp2_fp = drm_fixp_mul(temp1_fp, tu.lclk_fp);
  682. temp_fp = drm_fixp_div(temp2_fp, tu.pclk_fp);
  683. tu.extra_buffer_margin = fixp2int_ceil(temp_fp);
  684. if (in->compress_ratio == 375 && tu.bpp == 30)
  685. temp1_fp = drm_fixp_from_fraction(24, 8);
  686. else
  687. temp1_fp = drm_fixp_from_fraction(tu.bpp, 8);
  688. temp2_fp = drm_fixp_mul(tu.pclk_fp, temp1_fp);
  689. temp1_fp = drm_fixp_from_fraction(tu.nlanes, 1);
  690. temp2_fp = drm_fixp_div(temp2_fp, temp1_fp);
  691. tu.ratio_fp = drm_fixp_div(temp2_fp, tu.lclk_fp);
  692. tu.original_ratio_fp = tu.ratio_fp;
  693. tu.boundary_moderation_en = false;
  694. tu.upper_boundary_count = 0;
  695. tu.lower_boundary_count = 0;
  696. tu.i_upper_boundary_count = 0;
  697. tu.i_lower_boundary_count = 0;
  698. tu.valid_lower_boundary_link = 0;
  699. tu.even_distribution_BF = 0;
  700. tu.even_distribution_legacy = 0;
  701. tu.even_distribution = 0;
  702. tu.hbp_delayStartCheck = 0;
  703. tu.pre_tu_hw_pipe_delay = 0;
  704. tu.post_tu_hw_pipe_delay = 0;
  705. tu.link_config_hactive_time = 0;
  706. tu.delay_start_link_lclk = 0;
  707. tu.tu_active_cycles = 0;
  708. tu.resolution_line_time = 0;
  709. tu.last_partial_lclk = 0;
  710. tu.delay_start_time_fp = 0;
  711. tu.second_loop_set = 0;
  712. tu.err_fp = drm_fixp_from_fraction(1000, 1);
  713. tu.n_err_fp = 0;
  714. tu.n_n_err_fp = 0;
  715. temp = drm_fixp2int(tu.lwidth_fp);
  716. if ((((u32)temp % tu.nlanes) != 0) && (_tu_param_compare(tu.ratio_fp, DRM_FIXED_ONE) == 2)
  717. && (tu.dsc_en == 0)) {
  718. tu.ratio_fp = drm_fixp_mul(tu.ratio_fp, RATIO_SCALE_fp);
  719. if (_tu_param_compare(tu.ratio_fp, DRM_FIXED_ONE) == 1)
  720. tu.ratio_fp = DRM_FIXED_ONE;
  721. }
  722. if (_tu_param_compare(tu.ratio_fp, DRM_FIXED_ONE) == 1)
  723. tu.ratio_fp = DRM_FIXED_ONE;
  724. if (HBLANK_MARGIN_EXTRA != 0) {
  725. HBLANK_MARGIN += HBLANK_MARGIN_EXTRA;
  726. DP_DEBUG("Info: increase HBLANK_MARGIN to %d. (PLUS%d)\n", HBLANK_MARGIN,
  727. HBLANK_MARGIN_EXTRA);
  728. }
  729. for (tu.tu_size = 32; tu.tu_size <= 64; tu.tu_size++) {
  730. temp1_fp = drm_fixp_from_fraction(tu.tu_size, 1);
  731. temp2_fp = drm_fixp_mul(tu.ratio_fp, temp1_fp);
  732. temp = fixp2int_ceil(temp2_fp);
  733. temp1_fp = drm_fixp_from_fraction(temp, 1);
  734. tu.n_err_fp = temp1_fp - temp2_fp;
  735. if (tu.n_err_fp < tu.err_fp) {
  736. tu.err_fp = tu.n_err_fp;
  737. tu.tu_size_desired = tu.tu_size;
  738. }
  739. }
  740. tu.tu_size_minus1 = tu.tu_size_desired - 1;
  741. temp1_fp = drm_fixp_from_fraction(tu.tu_size_desired, 1);
  742. temp2_fp = drm_fixp_mul(tu.ratio_fp, temp1_fp);
  743. tu.valid_boundary_link = fixp2int_ceil(temp2_fp);
  744. temp1_fp = drm_fixp_from_fraction(tu.bpp, 8);
  745. temp2_fp = tu.lwidth_fp;
  746. temp2_fp = drm_fixp_mul(temp2_fp, temp1_fp);
  747. temp1_fp = drm_fixp_from_fraction(tu.valid_boundary_link, 1);
  748. temp2_fp = drm_fixp_div(temp2_fp, temp1_fp);
  749. tu.n_tus = drm_fixp2int(temp2_fp);
  750. if ((temp2_fp & 0xFFFFFFFF) > 0xFFFFF000)
  751. tu.n_tus += 1;
  752. tu.even_distribution_legacy = tu.n_tus % tu.nlanes == 0 ? 1 : 0;
  753. DP_DEBUG("Info: n_sym = %d, num_of_tus = %d\n",
  754. tu.valid_boundary_link, tu.n_tus);
  755. _dp_calc_extra_bytes(&tu);
  756. tu.filler_size = tu.tu_size_desired - tu.valid_boundary_link;
  757. temp1_fp = drm_fixp_from_fraction(tu.tu_size_desired, 1);
  758. tu.ratio_by_tu_fp = drm_fixp_mul(tu.ratio_fp, temp1_fp);
  759. tu.delay_start_link = tu.extra_pclk_cycles_in_link_clk +
  760. tu.filler_size + tu.extra_buffer_margin;
  761. tu.resulting_valid_fp =
  762. drm_fixp_from_fraction(tu.valid_boundary_link, 1);
  763. temp1_fp = drm_fixp_from_fraction(tu.tu_size_desired, 1);
  764. temp2_fp = drm_fixp_div(tu.resulting_valid_fp, temp1_fp);
  765. tu.TU_ratio_err_fp = temp2_fp - tu.original_ratio_fp;
  766. temp1_fp = drm_fixp_from_fraction((tu.hbp_relative_to_pclk - HBLANK_MARGIN), 1);
  767. tu.hbp_time_fp = drm_fixp_div(temp1_fp, tu.pclk_fp);
  768. temp1_fp = drm_fixp_from_fraction(tu.delay_start_link, 1);
  769. tu.delay_start_time_fp = drm_fixp_div(temp1_fp, tu.lclk_fp);
  770. compare_result_1 = _tu_param_compare(tu.hbp_time_fp,
  771. tu.delay_start_time_fp);
  772. if (compare_result_1 == 2) /* hbp_time_fp < delay_start_time_fp */
  773. tu.min_hblank_violated = 1;
  774. tu.hactive_time_fp = drm_fixp_div(tu.lwidth_fp, tu.pclk_fp);
  775. compare_result_2 = _tu_param_compare(tu.hactive_time_fp,
  776. tu.delay_start_time_fp);
  777. if (compare_result_2 == 2)
  778. tu.min_hblank_violated = 1;
  779. /* brute force */
  780. tu.delay_start_link_extra_pixclk = EXTRA_PIXCLK_CYCLE_DELAY;
  781. tu.diff_abs_fp = tu.resulting_valid_fp - tu.ratio_by_tu_fp;
  782. temp = drm_fixp2int(tu.diff_abs_fp);
  783. if (!temp && tu.diff_abs_fp <= 0xffff)
  784. tu.diff_abs_fp = 0;
  785. /* if(diff_abs < 0) diff_abs *= -1 */
  786. if (tu.diff_abs_fp < 0)
  787. tu.diff_abs_fp = drm_fixp_mul(tu.diff_abs_fp, -1);
  788. tu.boundary_mod_lower_err = 0;
  789. temp1_fp = drm_fixp_div(tu.orig_lclk_fp, tu.orig_pclk_fp);
  790. temp2_fp = drm_fixp_from_fraction(tu.orig_lwidth + tu.orig_hbp, 2);
  791. temp_fp = drm_fixp_mul(temp1_fp, temp2_fp);
  792. tu.resolution_line_time = drm_fixp2int(temp_fp);
  793. tu.pre_tu_hw_pipe_delay = fixp2int_ceil(temp1_fp) + 2 /*cdc fifo write jitter+2*/
  794. + 3 /*pre-delay start cycles*/
  795. + 3 /*post-delay start cycles*/ + 1 /*BE on the link*/;
  796. tu.post_tu_hw_pipe_delay = 4 /*BS_on_the_link*/ + 1 /*BE_next_ren*/;
  797. temp1_fp = drm_fixp_from_fraction(tu.bpp, 8);
  798. temp1_fp = drm_fixp_mul(tu.lwidth_fp, temp1_fp);
  799. tu.n_symbols = fixp2int_ceil(temp1_fp);
  800. if (tu.rb2)
  801. {
  802. temp1_fp = drm_fixp_mul(tu.delay_start_time_fp, tu.lclk_fp);
  803. tu.delay_start_link_lclk = fixp2int_ceil(temp1_fp);
  804. tu.new_valid_boundary_link = tu.valid_boundary_link;
  805. tu.i_upper_boundary_count = 1;
  806. tu.i_lower_boundary_count = 0;
  807. temp1 = tu.i_upper_boundary_count * tu.new_valid_boundary_link;
  808. temp1 += tu.i_lower_boundary_count * (tu.new_valid_boundary_link - 1);
  809. tu.average_valid2_fp = drm_fixp_from_fraction(temp1, (tu.i_upper_boundary_count + tu.i_lower_boundary_count));
  810. temp1_fp = drm_fixp_from_fraction(tu.bpp, 8);
  811. temp1_fp = drm_fixp_mul(tu.lwidth_fp, temp1_fp);
  812. temp2_fp = drm_fixp_div(temp1_fp, tu.average_valid2_fp);
  813. tu.n_tus = drm_fixp2int(temp2_fp);
  814. tu.n_tus_per_lane = tu.n_tus / tu.nlanes;
  815. tu.paired_tus = (int)((tu.n_tus_per_lane) / (tu.i_upper_boundary_count + tu.i_lower_boundary_count));
  816. tu.remainder_tus = tu.n_tus_per_lane - tu.paired_tus * (tu.i_upper_boundary_count + tu.i_lower_boundary_count);
  817. if (tu.remainder_tus > tu.i_upper_boundary_count) {
  818. temp = (tu.remainder_tus - tu.i_upper_boundary_count) * (tu.new_valid_boundary_link - 1);
  819. temp += (tu.i_upper_boundary_count * tu.new_valid_boundary_link);
  820. temp *= tu.nlanes;
  821. } else {
  822. temp = tu.nlanes * tu.remainder_tus * tu.new_valid_boundary_link;
  823. }
  824. temp1 = tu.i_lower_boundary_count * (tu.new_valid_boundary_link - 1);
  825. temp1 += tu.i_upper_boundary_count * tu.new_valid_boundary_link;
  826. temp1 *= tu.paired_tus * tu.nlanes;
  827. temp1_fp = drm_fixp_from_fraction(tu.n_symbols - temp1 - temp, tu.nlanes);
  828. tu.last_partial_lclk = fixp2int_ceil(temp1_fp);
  829. tu.tu_active_cycles = (int)((tu.n_tus_per_lane * tu.tu_size) + tu.last_partial_lclk);
  830. temp = tu.pre_tu_hw_pipe_delay + tu.delay_start_link_lclk + tu.tu_active_cycles + tu.post_tu_hw_pipe_delay;
  831. if (tu.fec_en == 1)
  832. {
  833. if (tu.nlanes == 1)
  834. {
  835. temp1_fp = drm_fixp_from_fraction(temp, 500);
  836. tu.parity_symbols = fixp2int_ceil(temp1_fp) * 12 + 1;
  837. }
  838. else
  839. {
  840. temp1_fp = drm_fixp_from_fraction(temp, 250);
  841. tu.parity_symbols = fixp2int_ceil(temp1_fp) * 6 + 1;
  842. }
  843. }
  844. else //no fec BW impact
  845. {
  846. tu.parity_symbols = 0;
  847. }
  848. tu.link_config_hactive_time = temp + tu.parity_symbols;
  849. if (tu.link_config_hactive_time + 1 /*margin*/ >= tu.resolution_line_time)
  850. tu.min_hblank_violated = 1;
  851. }
  852. tu.delay_start_time_fp = 0;
  853. if ((tu.diff_abs_fp != 0 &&
  854. ((tu.diff_abs_fp > BRUTE_FORCE_THRESHOLD_fp) ||
  855. (tu.even_distribution_legacy == 0) ||
  856. (DP_BRUTE_FORCE == 1))) ||
  857. (tu.min_hblank_violated == 1)) {
  858. _dp_calc_boundary(&tu);
  859. if (tu.boundary_moderation_en) {
  860. temp1_fp = drm_fixp_from_fraction(
  861. (tu.upper_boundary_count *
  862. tu.valid_boundary_link +
  863. tu.lower_boundary_count *
  864. (tu.valid_boundary_link - 1)), 1);
  865. temp2_fp = drm_fixp_from_fraction(
  866. (tu.upper_boundary_count +
  867. tu.lower_boundary_count), 1);
  868. tu.resulting_valid_fp =
  869. drm_fixp_div(temp1_fp, temp2_fp);
  870. temp1_fp = drm_fixp_from_fraction(
  871. tu.tu_size_desired, 1);
  872. tu.ratio_by_tu_fp =
  873. drm_fixp_mul(tu.original_ratio_fp, temp1_fp);
  874. tu.valid_lower_boundary_link =
  875. tu.valid_boundary_link - 1;
  876. temp1_fp = drm_fixp_from_fraction(tu.bpp, 8);
  877. temp1_fp = drm_fixp_mul(tu.lwidth_fp, temp1_fp);
  878. temp2_fp = drm_fixp_div(temp1_fp,
  879. tu.resulting_valid_fp);
  880. tu.n_tus = drm_fixp2int(temp2_fp);
  881. tu.tu_size_minus1 = tu.tu_size_desired - 1;
  882. tu.even_distribution_BF = 1;
  883. temp1_fp =
  884. drm_fixp_from_fraction(tu.tu_size_desired, 1);
  885. temp2_fp =
  886. drm_fixp_div(tu.resulting_valid_fp, temp1_fp);
  887. tu.TU_ratio_err_fp = temp2_fp - tu.original_ratio_fp;
  888. }
  889. }
  890. if (tu.async_en) {
  891. temp2_fp = drm_fixp_mul(LCLK_FAST_SKEW_fp, tu.lwidth_fp);
  892. temp = fixp2int_ceil(temp2_fp);
  893. temp1_fp = drm_fixp_from_fraction(tu.nlanes, 1);
  894. temp2_fp = drm_fixp_mul(tu.original_ratio_fp, temp1_fp);
  895. temp1_fp = drm_fixp_from_fraction(tu.bpp, 8);
  896. temp2_fp = drm_fixp_div(temp1_fp, temp2_fp);
  897. temp1_fp = drm_fixp_from_fraction(temp, 1);
  898. temp2_fp = drm_fixp_mul(temp1_fp, temp2_fp);
  899. temp = drm_fixp2int(temp2_fp);
  900. tu.delay_start_link += (int)temp;
  901. }
  902. temp1_fp = drm_fixp_from_fraction(tu.delay_start_link, 1);
  903. tu.delay_start_time_fp = drm_fixp_div(temp1_fp, tu.lclk_fp);
  904. /* OUTPUTS */
  905. tu_table->valid_boundary_link = tu.valid_boundary_link;
  906. tu_table->delay_start_link = tu.delay_start_link;
  907. tu_table->boundary_moderation_en = tu.boundary_moderation_en;
  908. tu_table->valid_lower_boundary_link = tu.valid_lower_boundary_link;
  909. tu_table->upper_boundary_count = tu.upper_boundary_count;
  910. tu_table->lower_boundary_count = tu.lower_boundary_count;
  911. tu_table->tu_size_minus1 = tu.tu_size_minus1;
  912. DP_DEBUG("TU: valid_boundary_link: %d\n", tu_table->valid_boundary_link);
  913. DP_DEBUG("TU: delay_start_link: %d\n", tu_table->delay_start_link);
  914. DP_DEBUG("TU: boundary_moderation_en: %d\n",
  915. tu_table->boundary_moderation_en);
  916. DP_DEBUG("TU: valid_lower_boundary_link: %d\n",
  917. tu_table->valid_lower_boundary_link);
  918. DP_DEBUG("TU: upper_boundary_count: %d\n",
  919. tu_table->upper_boundary_count);
  920. DP_DEBUG("TU: lower_boundary_count: %d\n",
  921. tu_table->lower_boundary_count);
  922. DP_DEBUG("TU: tu_size_minus1: %d\n", tu_table->tu_size_minus1);
  923. }
  924. static void dp_panel_calc_tu_parameters(struct dp_panel *dp_panel,
  925. struct dp_vc_tu_mapping_table *tu_table)
  926. {
  927. struct dp_tu_calc_input in;
  928. struct dp_panel_info *pinfo;
  929. struct dp_panel_private *panel;
  930. int bw_code;
  931. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  932. pinfo = &dp_panel->pinfo;
  933. bw_code = panel->link->link_params.bw_code;
  934. in.lclk = drm_dp_bw_code_to_link_rate(bw_code) / 1000;
  935. in.pclk_khz = pinfo->pixel_clk_khz;
  936. in.hactive = pinfo->h_active;
  937. in.hporch = pinfo->h_back_porch + pinfo->h_front_porch +
  938. pinfo->h_sync_width;
  939. in.nlanes = panel->link->link_params.lane_count;
  940. in.bpp = pinfo->bpp;
  941. in.pixel_enc = 444;
  942. in.dsc_en = pinfo->comp_info.enabled;
  943. in.async_en = 0;
  944. in.fec_en = dp_panel->fec_en;
  945. in.num_of_dsc_slices = pinfo->comp_info.dsc_info.slice_per_pkt;
  946. if (pinfo->comp_info.enabled)
  947. in.compress_ratio = mult_frac(100, pinfo->comp_info.src_bpp,
  948. pinfo->comp_info.tgt_bpp);
  949. _dp_panel_calc_tu(&in, tu_table);
  950. }
  951. void dp_panel_calc_tu_test(struct dp_tu_calc_input *in,
  952. struct dp_vc_tu_mapping_table *tu_table)
  953. {
  954. _dp_panel_calc_tu(in, tu_table);
  955. }
  956. static void dp_panel_config_tr_unit(struct dp_panel *dp_panel)
  957. {
  958. struct dp_panel_private *panel;
  959. struct dp_catalog_panel *catalog;
  960. u32 dp_tu = 0x0;
  961. u32 valid_boundary = 0x0;
  962. u32 valid_boundary2 = 0x0;
  963. struct dp_vc_tu_mapping_table tu_calc_table;
  964. if (!dp_panel) {
  965. DP_ERR("invalid input\n");
  966. return;
  967. }
  968. if (dp_panel->stream_id != DP_STREAM_0)
  969. return;
  970. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  971. catalog = panel->catalog;
  972. dp_panel_calc_tu_parameters(dp_panel, &tu_calc_table);
  973. dp_tu |= tu_calc_table.tu_size_minus1;
  974. valid_boundary |= tu_calc_table.valid_boundary_link;
  975. valid_boundary |= (tu_calc_table.delay_start_link << 16);
  976. valid_boundary2 |= (tu_calc_table.valid_lower_boundary_link << 1);
  977. valid_boundary2 |= (tu_calc_table.upper_boundary_count << 16);
  978. valid_boundary2 |= (tu_calc_table.lower_boundary_count << 20);
  979. if (tu_calc_table.boundary_moderation_en)
  980. valid_boundary2 |= BIT(0);
  981. DP_DEBUG("dp_tu=0x%x, valid_boundary=0x%x, valid_boundary2=0x%x\n",
  982. dp_tu, valid_boundary, valid_boundary2);
  983. catalog->dp_tu = dp_tu;
  984. catalog->valid_boundary = valid_boundary;
  985. catalog->valid_boundary2 = valid_boundary2;
  986. catalog->update_transfer_unit(catalog);
  987. }
  988. static void dp_panel_get_dto_params(u32 src_bpp, u32 tgt_bpp, u32 *num, u32 *denom)
  989. {
  990. if ((tgt_bpp == 12) && (src_bpp == 24)) {
  991. *num = 1;
  992. *denom = 2;
  993. } else if ((tgt_bpp == 15) && (src_bpp == 30)) {
  994. *num = 5;
  995. *denom = 8;
  996. } else if ((tgt_bpp == 8) && ((src_bpp == 24) || (src_bpp == 30))) {
  997. *num = 1;
  998. *denom = 3;
  999. } else if ((tgt_bpp == 10) && (src_bpp == 30)) {
  1000. *num = 5;
  1001. *denom = 12;
  1002. } else {
  1003. DP_ERR("dto params not found\n");
  1004. *num = 0;
  1005. *denom = 1;
  1006. }
  1007. }
  1008. static void dp_panel_dsc_prepare_pps_packet(struct dp_panel *dp_panel)
  1009. {
  1010. struct dp_panel_private *panel;
  1011. struct dp_dsc_cfg_data *dsc;
  1012. u8 *pps, *parity;
  1013. u32 *pps_word, *parity_word;
  1014. int i, index_4;
  1015. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1016. dsc = &panel->catalog->dsc;
  1017. pps = dsc->pps;
  1018. pps_word = dsc->pps_word;
  1019. parity = dsc->parity;
  1020. parity_word = dsc->parity_word;
  1021. memset(parity, 0, sizeof(dsc->parity));
  1022. dsc->pps_word_len = dsc->pps_len >> 2;
  1023. dsc->parity_len = dsc->pps_word_len;
  1024. dsc->parity_word_len = (dsc->parity_len >> 2) + 1;
  1025. for (i = 0; i < dsc->pps_word_len; i++) {
  1026. index_4 = i << 2;
  1027. pps_word[i] = pps[index_4 + 0] << 0 |
  1028. pps[index_4 + 1] << 8 |
  1029. pps[index_4 + 2] << 16 |
  1030. pps[index_4 + 3] << 24;
  1031. parity[i] = dp_header_get_parity(pps_word[i]);
  1032. }
  1033. for (i = 0; i < dsc->parity_word_len; i++) {
  1034. index_4 = i << 2;
  1035. parity_word[i] = parity[index_4 + 0] << 0 |
  1036. parity[index_4 + 1] << 8 |
  1037. parity[index_4 + 2] << 16 |
  1038. parity[index_4 + 3] << 24;
  1039. }
  1040. }
  1041. static void _dp_panel_dsc_get_num_extra_pclk(struct msm_compression_info *comp_info)
  1042. {
  1043. unsigned int dto_n = 0, dto_d = 0, remainder;
  1044. int ack_required, last_few_ack_required, accum_ack;
  1045. int last_few_pclk, last_few_pclk_required;
  1046. struct msm_display_dsc_info *dsc = &comp_info->dsc_info;
  1047. int start, temp, line_width = dsc->config.pic_width/2;
  1048. s64 temp1_fp, temp2_fp;
  1049. dp_panel_get_dto_params(comp_info->src_bpp, comp_info->tgt_bpp, &dto_n, &dto_d);
  1050. ack_required = dsc->pclk_per_line;
  1051. /* number of pclk cycles left outside of the complete DTO set */
  1052. last_few_pclk = line_width % dto_d;
  1053. /* number of pclk cycles outside of the complete dto */
  1054. temp1_fp = drm_fixp_from_fraction(line_width, dto_d);
  1055. temp2_fp = drm_fixp_from_fraction(dto_n, 1);
  1056. temp1_fp = drm_fixp_mul(temp1_fp, temp2_fp);
  1057. temp = drm_fixp2int(temp1_fp);
  1058. last_few_ack_required = ack_required - temp;
  1059. /*
  1060. * check how many more pclk is needed to
  1061. * accommodate the last few ack required
  1062. */
  1063. remainder = dto_n;
  1064. accum_ack = 0;
  1065. last_few_pclk_required = 0;
  1066. while (accum_ack < last_few_ack_required) {
  1067. last_few_pclk_required++;
  1068. if (remainder >= dto_n)
  1069. start = remainder;
  1070. else
  1071. start = remainder + dto_d;
  1072. remainder = start - dto_n;
  1073. if (remainder < dto_n)
  1074. accum_ack++;
  1075. }
  1076. /* if fewer pclk than required */
  1077. if (last_few_pclk < last_few_pclk_required)
  1078. dsc->extra_width = last_few_pclk_required - last_few_pclk;
  1079. else
  1080. dsc->extra_width = 0;
  1081. DP_DEBUG("extra pclks required: %d\n", dsc->extra_width);
  1082. }
  1083. static void _dp_panel_dsc_bw_overhead_calc(struct dp_panel *dp_panel,
  1084. struct msm_display_dsc_info *dsc,
  1085. struct dp_display_mode *dp_mode, u32 dsc_byte_cnt)
  1086. {
  1087. int num_slices, tot_num_eoc_symbols;
  1088. int tot_num_hor_bytes, tot_num_dummy_bytes;
  1089. int dwidth_dsc_bytes, eoc_bytes;
  1090. u32 num_lanes;
  1091. struct dp_panel_private *panel;
  1092. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1093. num_lanes = panel->link->link_params.lane_count;
  1094. num_slices = dsc->slice_per_pkt;
  1095. eoc_bytes = dsc_byte_cnt % num_lanes;
  1096. tot_num_eoc_symbols = num_lanes * num_slices;
  1097. tot_num_hor_bytes = dsc_byte_cnt * num_slices;
  1098. tot_num_dummy_bytes = (num_lanes - eoc_bytes) * num_slices;
  1099. if (!eoc_bytes)
  1100. tot_num_dummy_bytes = 0;
  1101. dwidth_dsc_bytes = tot_num_hor_bytes + tot_num_eoc_symbols +
  1102. tot_num_dummy_bytes;
  1103. DP_DEBUG("dwidth_dsc_bytes:%d, tot_num_hor_bytes:%d\n",
  1104. dwidth_dsc_bytes, tot_num_hor_bytes);
  1105. dp_mode->dsc_overhead_fp = drm_fixp_from_fraction(dwidth_dsc_bytes,
  1106. tot_num_hor_bytes);
  1107. dp_mode->timing.dsc_overhead_fp = dp_mode->dsc_overhead_fp;
  1108. }
  1109. static void dp_panel_dsc_pclk_param_calc(struct dp_panel *dp_panel,
  1110. struct msm_compression_info *comp_info,
  1111. struct dp_display_mode *dp_mode)
  1112. {
  1113. int comp_ratio = 100, intf_width;
  1114. int slice_per_pkt, slice_per_intf;
  1115. s64 temp1_fp, temp2_fp;
  1116. s64 numerator_fp, denominator_fp;
  1117. s64 dsc_byte_count_fp;
  1118. u32 dsc_byte_count, temp1, temp2;
  1119. struct msm_display_dsc_info *dsc = &comp_info->dsc_info;
  1120. intf_width = dp_mode->timing.h_active;
  1121. if (!dsc || !dsc->config.slice_width || !dsc->slice_per_pkt ||
  1122. (intf_width < dsc->config.slice_width))
  1123. return;
  1124. slice_per_pkt = dsc->slice_per_pkt;
  1125. slice_per_intf = DIV_ROUND_UP(intf_width,
  1126. dsc->config.slice_width);
  1127. comp_ratio = mult_frac(100, comp_info->src_bpp, comp_info->tgt_bpp);
  1128. temp1_fp = drm_fixp_from_fraction(comp_ratio, 100);
  1129. temp2_fp = drm_fixp_from_fraction(slice_per_pkt * 8, 1);
  1130. denominator_fp = drm_fixp_mul(temp1_fp, temp2_fp);
  1131. numerator_fp = drm_fixp_from_fraction(
  1132. intf_width * dsc->config.bits_per_component * 3, 1);
  1133. dsc_byte_count_fp = drm_fixp_div(numerator_fp, denominator_fp);
  1134. dsc_byte_count = fixp2int_ceil(dsc_byte_count_fp);
  1135. temp1 = dsc_byte_count * slice_per_intf;
  1136. temp2 = temp1;
  1137. if (temp1 % 3 != 0)
  1138. temp1 += 3 - (temp1 % 3);
  1139. dsc->eol_byte_num = temp1 - temp2;
  1140. temp1_fp = drm_fixp_from_fraction(slice_per_intf, 6);
  1141. temp2_fp = drm_fixp_mul(dsc_byte_count_fp, temp1_fp);
  1142. dsc->pclk_per_line = fixp2int_ceil(temp2_fp);
  1143. _dp_panel_dsc_get_num_extra_pclk(comp_info);
  1144. dsc->pclk_per_line--;
  1145. _dp_panel_dsc_bw_overhead_calc(dp_panel, dsc, dp_mode, dsc_byte_count);
  1146. }
  1147. struct dp_dsc_slices_per_line {
  1148. u32 min_ppr;
  1149. u32 max_ppr;
  1150. u8 num_slices;
  1151. };
  1152. struct dp_dsc_peak_throughput {
  1153. u32 index;
  1154. u32 peak_throughput;
  1155. };
  1156. struct dp_dsc_slice_caps_bit_map {
  1157. u32 num_slices;
  1158. u32 bit_index;
  1159. };
  1160. const struct dp_dsc_slices_per_line slice_per_line_tbl[] = {
  1161. {0, 340, 1 },
  1162. {340, 680, 2 },
  1163. {680, 1360, 4 },
  1164. {1360, 3200, 8 },
  1165. {3200, 4800, 12 },
  1166. {4800, 6400, 16 },
  1167. {6400, 8000, 20 },
  1168. {8000, 9600, 24 }
  1169. };
  1170. const struct dp_dsc_peak_throughput peak_throughput_mode_0_tbl[] = {
  1171. {0, 0},
  1172. {1, 340},
  1173. {2, 400},
  1174. {3, 450},
  1175. {4, 500},
  1176. {5, 550},
  1177. {6, 600},
  1178. {7, 650},
  1179. {8, 700},
  1180. {9, 750},
  1181. {10, 800},
  1182. {11, 850},
  1183. {12, 900},
  1184. {13, 950},
  1185. {14, 1000},
  1186. };
  1187. const struct dp_dsc_slice_caps_bit_map slice_caps_bit_map_tbl[] = {
  1188. {1, 0},
  1189. {2, 1},
  1190. {4, 3},
  1191. {6, 4},
  1192. {8, 5},
  1193. {10, 6},
  1194. {12, 7},
  1195. {16, 0},
  1196. {20, 1},
  1197. {24, 2},
  1198. };
  1199. static bool dp_panel_check_slice_support(u32 num_slices, u32 raw_data_1,
  1200. u32 raw_data_2)
  1201. {
  1202. const struct dp_dsc_slice_caps_bit_map *bcap;
  1203. u32 raw_data;
  1204. int i;
  1205. if (num_slices <= 12)
  1206. raw_data = raw_data_1;
  1207. else
  1208. raw_data = raw_data_2;
  1209. for (i = 0; i < ARRAY_SIZE(slice_caps_bit_map_tbl); i++) {
  1210. bcap = &slice_caps_bit_map_tbl[i];
  1211. if (bcap->num_slices == num_slices) {
  1212. raw_data &= (1 << bcap->bit_index);
  1213. if (raw_data)
  1214. return true;
  1215. else
  1216. return false;
  1217. }
  1218. }
  1219. return false;
  1220. }
  1221. static int dp_panel_dsc_prepare_basic_params(
  1222. struct msm_compression_info *comp_info,
  1223. const struct dp_display_mode *dp_mode,
  1224. struct dp_panel *dp_panel)
  1225. {
  1226. int i;
  1227. const struct dp_dsc_slices_per_line *rec;
  1228. const struct dp_dsc_peak_throughput *tput;
  1229. u32 slice_width;
  1230. u32 ppr = dp_mode->timing.pixel_clk_khz/1000;
  1231. u32 max_slice_width;
  1232. u32 ppr_max_index;
  1233. u32 peak_throughput;
  1234. u32 ppr_per_slice;
  1235. u32 slice_caps_1;
  1236. u32 slice_caps_2;
  1237. u32 dsc_version_major, dsc_version_minor;
  1238. bool dsc_version_supported = false;
  1239. dsc_version_major = dp_panel->sink_dsc_caps.version & 0xF;
  1240. dsc_version_minor = (dp_panel->sink_dsc_caps.version >> 4) & 0xF;
  1241. dsc_version_supported = (dsc_version_major == 0x1 &&
  1242. (dsc_version_minor == 0x1 || dsc_version_minor == 0x2))
  1243. ? true : false;
  1244. DP_DEBUG("DSC version: %d.%d, dpcd value: %x\n",
  1245. dsc_version_major, dsc_version_minor,
  1246. dp_panel->sink_dsc_caps.version);
  1247. if (!dsc_version_supported) {
  1248. dsc_version_major = 1;
  1249. dsc_version_minor = 1;
  1250. DP_ERR("invalid sink DSC version, fallback to %d.%d\n",
  1251. dsc_version_major, dsc_version_minor);
  1252. }
  1253. comp_info->dsc_info.config.dsc_version_major = dsc_version_major;
  1254. comp_info->dsc_info.config.dsc_version_minor = dsc_version_minor;
  1255. comp_info->dsc_info.scr_rev = 0x0;
  1256. comp_info->dsc_info.slice_per_pkt = 0;
  1257. for (i = 0; i < ARRAY_SIZE(slice_per_line_tbl); i++) {
  1258. rec = &slice_per_line_tbl[i];
  1259. if ((ppr > rec->min_ppr) && (ppr <= rec->max_ppr)) {
  1260. comp_info->dsc_info.slice_per_pkt = rec->num_slices;
  1261. i++;
  1262. break;
  1263. }
  1264. }
  1265. if (comp_info->dsc_info.slice_per_pkt == 0)
  1266. return -EINVAL;
  1267. ppr_max_index = dp_panel->dsc_dpcd[11] &= 0xf;
  1268. if (!ppr_max_index || ppr_max_index >= 15) {
  1269. DP_DEBUG("Throughput mode 0 not supported");
  1270. return -EINVAL;
  1271. }
  1272. tput = &peak_throughput_mode_0_tbl[ppr_max_index];
  1273. peak_throughput = tput->peak_throughput;
  1274. max_slice_width = dp_panel->dsc_dpcd[12] * 320;
  1275. slice_width = (dp_mode->timing.h_active /
  1276. comp_info->dsc_info.slice_per_pkt);
  1277. ppr_per_slice = ppr/comp_info->dsc_info.slice_per_pkt;
  1278. slice_caps_1 = dp_panel->dsc_dpcd[4];
  1279. slice_caps_2 = dp_panel->dsc_dpcd[13] & 0x7;
  1280. /*
  1281. * There are 3 conditions to check for sink support:
  1282. * 1. The slice width cannot exceed the maximum.
  1283. * 2. The ppr per slice cannot exceed the maximum.
  1284. * 3. The number of slices must be explicitly supported.
  1285. */
  1286. while (slice_width >= max_slice_width ||
  1287. ppr_per_slice > peak_throughput ||
  1288. !dp_panel_check_slice_support(
  1289. comp_info->dsc_info.slice_per_pkt, slice_caps_1,
  1290. slice_caps_2)) {
  1291. if (i == ARRAY_SIZE(slice_per_line_tbl))
  1292. return -EINVAL;
  1293. rec = &slice_per_line_tbl[i];
  1294. comp_info->dsc_info.slice_per_pkt = rec->num_slices;
  1295. slice_width = (dp_mode->timing.h_active /
  1296. comp_info->dsc_info.slice_per_pkt);
  1297. ppr_per_slice = ppr/comp_info->dsc_info.slice_per_pkt;
  1298. i++;
  1299. }
  1300. comp_info->dsc_info.config.block_pred_enable =
  1301. dp_panel->sink_dsc_caps.block_pred_en;
  1302. comp_info->dsc_info.config.pic_width = dp_mode->timing.h_active;
  1303. comp_info->dsc_info.config.pic_height = dp_mode->timing.v_active;
  1304. comp_info->dsc_info.config.slice_width = slice_width;
  1305. if (comp_info->dsc_info.config.pic_height % 108 == 0)
  1306. comp_info->dsc_info.config.slice_height = 108;
  1307. else if (comp_info->dsc_info.config.pic_height % 16 == 0)
  1308. comp_info->dsc_info.config.slice_height = 16;
  1309. else if (comp_info->dsc_info.config.pic_height % 12 == 0)
  1310. comp_info->dsc_info.config.slice_height = 12;
  1311. else
  1312. comp_info->dsc_info.config.slice_height = 15;
  1313. comp_info->dsc_info.config.bits_per_component =
  1314. (dp_mode->timing.bpp / 3);
  1315. comp_info->dsc_info.config.bits_per_pixel = DSC_TGT_BPP << 4;
  1316. comp_info->dsc_info.config.slice_count =
  1317. DIV_ROUND_UP(dp_mode->timing.h_active, slice_width);
  1318. comp_info->comp_type = MSM_DISPLAY_COMPRESSION_DSC;
  1319. comp_info->tgt_bpp = DSC_TGT_BPP;
  1320. comp_info->src_bpp = dp_mode->timing.bpp;
  1321. comp_info->comp_ratio = dp_mode->timing.bpp / DSC_TGT_BPP;
  1322. comp_info->enabled = true;
  1323. return 0;
  1324. }
  1325. static int dp_panel_read_dpcd(struct dp_panel *dp_panel, bool multi_func)
  1326. {
  1327. int rlen, rc = 0;
  1328. struct dp_panel_private *panel;
  1329. struct drm_dp_link *link_info;
  1330. struct drm_dp_aux *drm_aux;
  1331. u8 *dpcd, rx_feature, temp;
  1332. u32 dfp_count = 0, offset = DP_DPCD_REV;
  1333. if (!dp_panel) {
  1334. DP_ERR("invalid input\n");
  1335. rc = -EINVAL;
  1336. goto end;
  1337. }
  1338. dpcd = dp_panel->dpcd;
  1339. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1340. drm_aux = panel->aux->drm_aux;
  1341. link_info = &dp_panel->link_info;
  1342. /* reset vsc data */
  1343. panel->vsc_supported = false;
  1344. panel->vscext_supported = false;
  1345. panel->vscext_chaining_supported = false;
  1346. rlen = drm_dp_dpcd_read(drm_aux, DP_TRAINING_AUX_RD_INTERVAL, &temp, 1);
  1347. if (rlen != 1) {
  1348. DP_ERR("error reading DP_TRAINING_AUX_RD_INTERVAL\n");
  1349. rc = -EINVAL;
  1350. goto end;
  1351. }
  1352. /* check for EXTENDED_RECEIVER_CAPABILITY_FIELD_PRESENT */
  1353. if (temp & BIT(7)) {
  1354. DP_DEBUG("using EXTENDED_RECEIVER_CAPABILITY_FIELD\n");
  1355. offset = DPRX_EXTENDED_DPCD_FIELD;
  1356. }
  1357. rlen = drm_dp_dpcd_read(drm_aux, offset,
  1358. dp_panel->dpcd, (DP_RECEIVER_CAP_SIZE + 1));
  1359. if (rlen < (DP_RECEIVER_CAP_SIZE + 1)) {
  1360. DP_ERR("dpcd read failed, rlen=%d\n", rlen);
  1361. if (rlen == -ETIMEDOUT)
  1362. rc = rlen;
  1363. else
  1364. rc = -EINVAL;
  1365. goto end;
  1366. }
  1367. print_hex_dump_debug("[drm-dp] SINK DPCD: ",
  1368. DUMP_PREFIX_NONE, 8, 1, dp_panel->dpcd, rlen, false);
  1369. rlen = drm_dp_dpcd_read(panel->aux->drm_aux,
  1370. DPRX_FEATURE_ENUMERATION_LIST, &rx_feature, 1);
  1371. if (rlen != 1) {
  1372. DP_DEBUG("failed to read DPRX_FEATURE_ENUMERATION_LIST\n");
  1373. rx_feature = 0;
  1374. } else {
  1375. panel->vsc_supported = !!(rx_feature &
  1376. VSC_SDP_EXTENSION_FOR_COLORIMETRY_SUPPORTED);
  1377. panel->vscext_supported = !!(rx_feature &
  1378. VSC_EXT_VESA_SDP_SUPPORTED);
  1379. panel->vscext_chaining_supported = !!(rx_feature &
  1380. VSC_EXT_VESA_SDP_CHAINING_SUPPORTED);
  1381. DP_DEBUG("vsc=%d, vscext=%d, vscext_chaining=%d\n",
  1382. panel->vsc_supported, panel->vscext_supported,
  1383. panel->vscext_chaining_supported);
  1384. }
  1385. link_info->revision = dpcd[DP_DPCD_REV];
  1386. panel->major = (link_info->revision >> 4) & 0x0f;
  1387. panel->minor = link_info->revision & 0x0f;
  1388. /* override link params updated in dp_panel_init_panel_info */
  1389. link_info->rate = min_t(unsigned long, panel->parser->max_lclk_khz,
  1390. drm_dp_bw_code_to_link_rate(dpcd[DP_MAX_LINK_RATE]));
  1391. link_info->num_lanes = dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;
  1392. if (is_link_rate_valid(panel->dp_panel.link_bw_code)) {
  1393. DP_DEBUG("debug link bandwidth code: 0x%x\n",
  1394. panel->dp_panel.link_bw_code);
  1395. link_info->rate = drm_dp_bw_code_to_link_rate(
  1396. panel->dp_panel.link_bw_code);
  1397. }
  1398. if (is_lane_count_valid(panel->dp_panel.lane_count)) {
  1399. DP_DEBUG("debug lane count: %d\n", panel->dp_panel.lane_count);
  1400. link_info->num_lanes = panel->dp_panel.lane_count;
  1401. }
  1402. if (multi_func)
  1403. link_info->num_lanes = min_t(unsigned int,
  1404. link_info->num_lanes, 2);
  1405. DP_DEBUG("version:%d.%d, rate:%d, lanes:%d\n", panel->major,
  1406. panel->minor, link_info->rate, link_info->num_lanes);
  1407. if (drm_dp_enhanced_frame_cap(dpcd))
  1408. link_info->capabilities |= DP_LINK_CAP_ENHANCED_FRAMING;
  1409. rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_TEST_SINK_MISC, &temp, 1);
  1410. if ((rlen == 1) && (temp & DP_TEST_CRC_SUPPORTED))
  1411. link_info->capabilities |= DP_LINK_CAP_CRC;
  1412. dfp_count = dpcd[DP_DOWN_STREAM_PORT_COUNT] &
  1413. DP_DOWN_STREAM_PORT_COUNT;
  1414. if ((dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT)
  1415. && (dpcd[DP_DPCD_REV] > 0x10)) {
  1416. rlen = drm_dp_dpcd_read(panel->aux->drm_aux,
  1417. DP_DOWNSTREAM_PORT_0, dp_panel->ds_ports,
  1418. DP_MAX_DOWNSTREAM_PORTS);
  1419. if (rlen < DP_MAX_DOWNSTREAM_PORTS) {
  1420. DP_ERR("ds port status failed, rlen=%d\n", rlen);
  1421. rc = -EINVAL;
  1422. goto end;
  1423. }
  1424. }
  1425. if (dfp_count > DP_MAX_DS_PORT_COUNT)
  1426. DP_DEBUG("DS port count %d greater that max (%d) supported\n",
  1427. dfp_count, DP_MAX_DS_PORT_COUNT);
  1428. end:
  1429. return rc;
  1430. }
  1431. static int dp_panel_set_default_link_params(struct dp_panel *dp_panel)
  1432. {
  1433. struct drm_dp_link *link_info;
  1434. const int default_bw_code = 162000;
  1435. const int default_num_lanes = 1;
  1436. if (!dp_panel) {
  1437. DP_ERR("invalid input\n");
  1438. return -EINVAL;
  1439. }
  1440. link_info = &dp_panel->link_info;
  1441. link_info->rate = default_bw_code;
  1442. link_info->num_lanes = default_num_lanes;
  1443. DP_DEBUG("link_rate=%d num_lanes=%d\n",
  1444. link_info->rate, link_info->num_lanes);
  1445. return 0;
  1446. }
  1447. static int dp_panel_read_edid(struct dp_panel *dp_panel,
  1448. struct drm_connector *connector)
  1449. {
  1450. int ret = 0;
  1451. struct dp_panel_private *panel;
  1452. struct edid *edid;
  1453. if (!dp_panel) {
  1454. DP_ERR("invalid input\n");
  1455. return -EINVAL;
  1456. }
  1457. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1458. sde_get_edid(connector, &panel->aux->drm_aux->ddc,
  1459. (void **)&dp_panel->edid_ctrl);
  1460. if (!dp_panel->edid_ctrl->edid) {
  1461. DP_ERR("EDID read failed\n");
  1462. ret = -EINVAL;
  1463. goto end;
  1464. }
  1465. end:
  1466. edid = dp_panel->edid_ctrl->edid;
  1467. dp_panel->audio_supported = drm_detect_monitor_audio(edid);
  1468. return ret;
  1469. }
  1470. static void dp_panel_decode_dsc_dpcd(struct dp_panel *dp_panel)
  1471. {
  1472. if (dp_panel->dsc_dpcd[0]) {
  1473. dp_panel->sink_dsc_caps.dsc_capable = true;
  1474. dp_panel->sink_dsc_caps.version = dp_panel->dsc_dpcd[1];
  1475. dp_panel->sink_dsc_caps.block_pred_en =
  1476. dp_panel->dsc_dpcd[6] ? true : false;
  1477. dp_panel->sink_dsc_caps.color_depth =
  1478. dp_panel->dsc_dpcd[10];
  1479. if (dp_panel->sink_dsc_caps.version >= 0x11)
  1480. dp_panel->dsc_en = true;
  1481. } else {
  1482. dp_panel->sink_dsc_caps.dsc_capable = false;
  1483. dp_panel->dsc_en = false;
  1484. }
  1485. }
  1486. static void dp_panel_read_sink_dsc_caps(struct dp_panel *dp_panel)
  1487. {
  1488. int rlen;
  1489. struct dp_panel_private *panel;
  1490. int dpcd_rev;
  1491. if (!dp_panel) {
  1492. DP_ERR("invalid input\n");
  1493. return;
  1494. }
  1495. dpcd_rev = dp_panel->dpcd[DP_DPCD_REV];
  1496. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1497. if (panel->parser->dsc_feature_enable && dpcd_rev >= 0x14) {
  1498. rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_DSC_SUPPORT,
  1499. dp_panel->dsc_dpcd, (DP_RECEIVER_DSC_CAP_SIZE + 1));
  1500. if (rlen < (DP_RECEIVER_DSC_CAP_SIZE + 1)) {
  1501. DP_DEBUG("dsc dpcd read failed, rlen=%d\n", rlen);
  1502. return;
  1503. }
  1504. print_hex_dump_debug("[drm-dp] SINK DSC DPCD: ",
  1505. DUMP_PREFIX_NONE, 8, 1, dp_panel->dsc_dpcd, rlen,
  1506. false);
  1507. dp_panel_decode_dsc_dpcd(dp_panel);
  1508. }
  1509. }
  1510. static void dp_panel_read_sink_fec_caps(struct dp_panel *dp_panel)
  1511. {
  1512. int rlen;
  1513. struct dp_panel_private *panel;
  1514. s64 fec_overhead_fp = drm_fixp_from_fraction(1, 1);
  1515. if (!dp_panel) {
  1516. DP_ERR("invalid input\n");
  1517. return;
  1518. }
  1519. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1520. rlen = drm_dp_dpcd_readb(panel->aux->drm_aux, DP_FEC_CAPABILITY,
  1521. &dp_panel->fec_dpcd);
  1522. if (rlen < 1) {
  1523. DP_ERR("fec capability read failed, rlen=%d\n", rlen);
  1524. return;
  1525. }
  1526. dp_panel->fec_en = dp_panel->fec_dpcd & DP_FEC_CAPABLE;
  1527. if (dp_panel->fec_en)
  1528. fec_overhead_fp = drm_fixp_from_fraction(100000, 97582);
  1529. dp_panel->fec_overhead_fp = fec_overhead_fp;
  1530. return;
  1531. }
  1532. static int dp_panel_read_sink_caps(struct dp_panel *dp_panel,
  1533. struct drm_connector *connector, bool multi_func)
  1534. {
  1535. int rc = 0, rlen, count, downstream_ports;
  1536. const int count_len = 1;
  1537. struct dp_panel_private *panel;
  1538. if (!dp_panel || !connector) {
  1539. DP_ERR("invalid input\n");
  1540. rc = -EINVAL;
  1541. goto end;
  1542. }
  1543. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1544. rc = dp_panel_read_dpcd(dp_panel, multi_func);
  1545. if (rc || !is_link_rate_valid(drm_dp_link_rate_to_bw_code(
  1546. dp_panel->link_info.rate)) || !is_lane_count_valid(
  1547. dp_panel->link_info.num_lanes) ||
  1548. ((drm_dp_link_rate_to_bw_code(dp_panel->link_info.rate)) >
  1549. dp_panel->max_bw_code)) {
  1550. if ((rc == -ETIMEDOUT) || (rc == -ENODEV)) {
  1551. DP_ERR("DPCD read failed, return early\n");
  1552. goto end;
  1553. }
  1554. DP_ERR("panel dpcd read failed/incorrect, set default params\n");
  1555. dp_panel_set_default_link_params(dp_panel);
  1556. }
  1557. downstream_ports = dp_panel->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  1558. DP_DWN_STRM_PORT_PRESENT;
  1559. if (downstream_ports) {
  1560. rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_SINK_COUNT,
  1561. &count, count_len);
  1562. if (rlen == count_len) {
  1563. count = DP_GET_SINK_COUNT(count);
  1564. if (!count) {
  1565. DP_ERR("no downstream ports connected\n");
  1566. panel->link->sink_count.count = 0;
  1567. rc = -ENOTCONN;
  1568. goto end;
  1569. }
  1570. }
  1571. }
  1572. /* There is no need to read EDID from MST branch */
  1573. if (panel->parser->has_mst && dp_panel->read_mst_cap(dp_panel))
  1574. goto skip_edid;
  1575. rc = dp_panel_read_edid(dp_panel, connector);
  1576. if (rc) {
  1577. DP_ERR("panel edid read failed, set failsafe mode\n");
  1578. return rc;
  1579. }
  1580. skip_edid:
  1581. dp_panel->widebus_en = panel->parser->has_widebus;
  1582. dp_panel->dsc_feature_enable = panel->parser->dsc_feature_enable;
  1583. dp_panel->fec_feature_enable = panel->parser->fec_feature_enable;
  1584. dp_panel->fec_en = false;
  1585. dp_panel->dsc_en = false;
  1586. if (dp_panel->dpcd[DP_DPCD_REV] >= DP_DPCD_REV_14 &&
  1587. dp_panel->fec_feature_enable) {
  1588. dp_panel_read_sink_fec_caps(dp_panel);
  1589. if (dp_panel->dsc_feature_enable && dp_panel->fec_en)
  1590. dp_panel_read_sink_dsc_caps(dp_panel);
  1591. }
  1592. DP_INFO("fec_en=%d, dsc_en=%d, widebus_en=%d\n", dp_panel->fec_en,
  1593. dp_panel->dsc_en, dp_panel->widebus_en);
  1594. end:
  1595. return rc;
  1596. }
  1597. static u32 dp_panel_get_supported_bpp(struct dp_panel *dp_panel,
  1598. u32 mode_edid_bpp, u32 mode_pclk_khz, bool dsc_en)
  1599. {
  1600. struct dp_link_params *link_params;
  1601. struct dp_panel_private *panel;
  1602. const u32 max_supported_bpp = 30;
  1603. u32 min_supported_bpp = 18;
  1604. u32 bpp = 0, link_bitrate = 0, mode_bitrate;
  1605. s64 rate_fp = 0;
  1606. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1607. if (dsc_en)
  1608. min_supported_bpp = 24;
  1609. bpp = min_t(u32, mode_edid_bpp, max_supported_bpp);
  1610. link_params = &panel->link->link_params;
  1611. rate_fp = drm_int2fixp(drm_dp_bw_code_to_link_rate(link_params->bw_code) *
  1612. link_params->lane_count * 8);
  1613. if (dp_panel->fec_en)
  1614. rate_fp = drm_fixp_div(rate_fp, dp_panel->fec_overhead_fp);
  1615. link_bitrate = drm_fixp2int(rate_fp);
  1616. for (; bpp > min_supported_bpp; bpp -= 6) {
  1617. if (dsc_en) {
  1618. if (bpp == 30 && !(dp_panel->sink_dsc_caps.color_depth & DP_DSC_10_BPC))
  1619. continue;
  1620. else if (bpp == 24 && !(dp_panel->sink_dsc_caps.color_depth & DP_DSC_8_BPC))
  1621. continue;
  1622. mode_bitrate = mode_pclk_khz * DSC_TGT_BPP;
  1623. } else {
  1624. mode_bitrate = mode_pclk_khz * bpp;
  1625. }
  1626. if (mode_bitrate <= link_bitrate)
  1627. break;
  1628. }
  1629. if (bpp < min_supported_bpp)
  1630. DP_ERR("bpp %d is below minimum supported bpp %d\n", bpp,
  1631. min_supported_bpp);
  1632. if (dsc_en && bpp != 24 && bpp != 30 && bpp != 36)
  1633. DP_ERR("bpp %d is not supported when dsc is enabled\n", bpp);
  1634. return bpp;
  1635. }
  1636. static u32 dp_panel_get_mode_bpp(struct dp_panel *dp_panel,
  1637. u32 mode_edid_bpp, u32 mode_pclk_khz, bool dsc_en)
  1638. {
  1639. struct dp_panel_private *panel;
  1640. u32 bpp = mode_edid_bpp;
  1641. if (!dp_panel || !mode_edid_bpp || !mode_pclk_khz) {
  1642. DP_ERR("invalid input\n");
  1643. return 0;
  1644. }
  1645. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1646. if (dp_panel->video_test)
  1647. bpp = dp_link_bit_depth_to_bpp(
  1648. panel->link->test_video.test_bit_depth);
  1649. else
  1650. bpp = dp_panel_get_supported_bpp(dp_panel, mode_edid_bpp,
  1651. mode_pclk_khz, dsc_en);
  1652. return bpp;
  1653. }
  1654. static void dp_panel_set_test_mode(struct dp_panel_private *panel,
  1655. struct dp_display_mode *mode)
  1656. {
  1657. struct dp_panel_info *pinfo = NULL;
  1658. struct dp_link_test_video *test_info = NULL;
  1659. if (!panel) {
  1660. DP_ERR("invalid params\n");
  1661. return;
  1662. }
  1663. pinfo = &mode->timing;
  1664. test_info = &panel->link->test_video;
  1665. pinfo->h_active = test_info->test_h_width;
  1666. pinfo->h_sync_width = test_info->test_hsync_width;
  1667. pinfo->h_back_porch = test_info->test_h_start -
  1668. test_info->test_hsync_width;
  1669. pinfo->h_front_porch = test_info->test_h_total -
  1670. (test_info->test_h_start + test_info->test_h_width);
  1671. pinfo->v_active = test_info->test_v_height;
  1672. pinfo->v_sync_width = test_info->test_vsync_width;
  1673. pinfo->v_back_porch = test_info->test_v_start -
  1674. test_info->test_vsync_width;
  1675. pinfo->v_front_porch = test_info->test_v_total -
  1676. (test_info->test_v_start + test_info->test_v_height);
  1677. pinfo->bpp = dp_link_bit_depth_to_bpp(test_info->test_bit_depth);
  1678. pinfo->h_active_low = test_info->test_hsync_pol;
  1679. pinfo->v_active_low = test_info->test_vsync_pol;
  1680. pinfo->refresh_rate = test_info->test_rr_n;
  1681. pinfo->pixel_clk_khz = test_info->test_h_total *
  1682. test_info->test_v_total * pinfo->refresh_rate;
  1683. if (test_info->test_rr_d == 0)
  1684. pinfo->pixel_clk_khz /= 1000;
  1685. else
  1686. pinfo->pixel_clk_khz /= 1001;
  1687. if (test_info->test_h_width == 640)
  1688. pinfo->pixel_clk_khz = 25170;
  1689. }
  1690. static int dp_panel_get_modes(struct dp_panel *dp_panel,
  1691. struct drm_connector *connector, struct dp_display_mode *mode)
  1692. {
  1693. struct dp_panel_private *panel;
  1694. if (!dp_panel) {
  1695. DP_ERR("invalid input\n");
  1696. return -EINVAL;
  1697. }
  1698. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1699. if (dp_panel->video_test) {
  1700. dp_panel_set_test_mode(panel, mode);
  1701. return 1;
  1702. } else if (dp_panel->edid_ctrl->edid) {
  1703. return _sde_edid_update_modes(connector, dp_panel->edid_ctrl);
  1704. }
  1705. /* fail-safe mode */
  1706. memcpy(&mode->timing, &fail_safe,
  1707. sizeof(fail_safe));
  1708. return 1;
  1709. }
  1710. static void dp_panel_handle_sink_request(struct dp_panel *dp_panel)
  1711. {
  1712. struct dp_panel_private *panel;
  1713. if (!dp_panel) {
  1714. DP_ERR("invalid input\n");
  1715. return;
  1716. }
  1717. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1718. if (panel->link->sink_request & DP_TEST_LINK_EDID_READ) {
  1719. u8 checksum;
  1720. if (dp_panel->edid_ctrl->edid)
  1721. checksum = sde_get_edid_checksum(dp_panel->edid_ctrl);
  1722. else
  1723. checksum = dp_panel->connector->real_edid_checksum;
  1724. panel->link->send_edid_checksum(panel->link, checksum);
  1725. panel->link->send_test_response(panel->link);
  1726. }
  1727. }
  1728. static void dp_panel_tpg_config(struct dp_panel *dp_panel, u32 pattern)
  1729. {
  1730. u32 hsync_start_x, hsync_end_x, hactive;
  1731. struct dp_catalog_panel *catalog;
  1732. struct dp_panel_private *panel;
  1733. struct dp_panel_info *pinfo;
  1734. if (!dp_panel) {
  1735. DP_ERR("invalid input\n");
  1736. return;
  1737. }
  1738. if (dp_panel->stream_id >= DP_STREAM_MAX) {
  1739. DP_ERR("invalid stream id:%d\n", dp_panel->stream_id);
  1740. return;
  1741. }
  1742. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1743. catalog = panel->catalog;
  1744. pinfo = &panel->dp_panel.pinfo;
  1745. if (!panel->panel_on) {
  1746. DP_DEBUG("DP panel not enabled, handle TPG on next panel on\n");
  1747. return;
  1748. }
  1749. if (!pattern) {
  1750. panel->catalog->tpg_config(catalog, pattern);
  1751. return;
  1752. }
  1753. hactive = pinfo->h_active;
  1754. if (pinfo->widebus_en)
  1755. hactive >>= 1;
  1756. /* TPG config */
  1757. catalog->hsync_period = pinfo->h_sync_width + pinfo->h_back_porch +
  1758. hactive + pinfo->h_front_porch;
  1759. catalog->vsync_period = pinfo->v_sync_width + pinfo->v_back_porch +
  1760. pinfo->v_active + pinfo->v_front_porch;
  1761. catalog->display_v_start = ((pinfo->v_sync_width +
  1762. pinfo->v_back_porch) * catalog->hsync_period);
  1763. catalog->display_v_end = ((catalog->vsync_period -
  1764. pinfo->v_front_porch) * catalog->hsync_period) - 1;
  1765. catalog->display_v_start += pinfo->h_sync_width + pinfo->h_back_porch;
  1766. catalog->display_v_end -= pinfo->h_front_porch;
  1767. hsync_start_x = pinfo->h_back_porch + pinfo->h_sync_width;
  1768. hsync_end_x = catalog->hsync_period - pinfo->h_front_porch - 1;
  1769. catalog->v_sync_width = pinfo->v_sync_width;
  1770. catalog->hsync_ctl = (catalog->hsync_period << 16) |
  1771. pinfo->h_sync_width;
  1772. catalog->display_hctl = (hsync_end_x << 16) | hsync_start_x;
  1773. panel->catalog->tpg_config(catalog, pattern);
  1774. }
  1775. static int dp_panel_config_timing(struct dp_panel *dp_panel)
  1776. {
  1777. int rc = 0;
  1778. u32 data, total_ver, total_hor;
  1779. struct dp_catalog_panel *catalog;
  1780. struct dp_panel_private *panel;
  1781. struct dp_panel_info *pinfo;
  1782. if (!dp_panel) {
  1783. DP_ERR("invalid input\n");
  1784. rc = -EINVAL;
  1785. goto end;
  1786. }
  1787. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1788. catalog = panel->catalog;
  1789. pinfo = &panel->dp_panel.pinfo;
  1790. DP_DEBUG("width=%d hporch= %d %d %d\n",
  1791. pinfo->h_active, pinfo->h_back_porch,
  1792. pinfo->h_front_porch, pinfo->h_sync_width);
  1793. DP_DEBUG("height=%d vporch= %d %d %d\n",
  1794. pinfo->v_active, pinfo->v_back_porch,
  1795. pinfo->v_front_porch, pinfo->v_sync_width);
  1796. total_hor = pinfo->h_active + pinfo->h_back_porch +
  1797. pinfo->h_front_porch + pinfo->h_sync_width;
  1798. total_ver = pinfo->v_active + pinfo->v_back_porch +
  1799. pinfo->v_front_porch + pinfo->v_sync_width;
  1800. data = total_ver;
  1801. data <<= 16;
  1802. data |= total_hor;
  1803. catalog->total = data;
  1804. data = (pinfo->v_back_porch + pinfo->v_sync_width);
  1805. data <<= 16;
  1806. data |= (pinfo->h_back_porch + pinfo->h_sync_width);
  1807. catalog->sync_start = data;
  1808. data = pinfo->v_sync_width;
  1809. data <<= 16;
  1810. data |= (pinfo->v_active_low << 31);
  1811. data |= pinfo->h_sync_width;
  1812. data |= (pinfo->h_active_low << 15);
  1813. catalog->width_blanking = data;
  1814. data = pinfo->v_active;
  1815. data <<= 16;
  1816. data |= pinfo->h_active;
  1817. catalog->dp_active = data;
  1818. catalog->widebus_en = pinfo->widebus_en;
  1819. panel->catalog->timing_cfg(catalog);
  1820. panel->panel_on = true;
  1821. end:
  1822. return rc;
  1823. }
  1824. static u32 _dp_panel_calc_be_in_lane(struct dp_panel *dp_panel)
  1825. {
  1826. struct msm_compression_info *comp_info;
  1827. u32 htotal, mod_result;
  1828. u32 be_in_lane = 10;
  1829. comp_info = &dp_panel->pinfo.comp_info;
  1830. if (!dp_panel->mst_state)
  1831. return be_in_lane;
  1832. htotal = comp_info->dsc_info.bytes_per_pkt * comp_info->dsc_info.pkt_per_line;
  1833. mod_result = htotal % 12;
  1834. if (mod_result == 0)
  1835. be_in_lane = 8;
  1836. else if (mod_result <= 3)
  1837. be_in_lane = 1;
  1838. else if (mod_result <= 6)
  1839. be_in_lane = 2;
  1840. else if (mod_result <= 9)
  1841. be_in_lane = 4;
  1842. else if (mod_result <= 11)
  1843. be_in_lane = 8;
  1844. else
  1845. be_in_lane = 10;
  1846. return be_in_lane;
  1847. }
  1848. static void dp_panel_config_dsc(struct dp_panel *dp_panel, bool enable)
  1849. {
  1850. struct dp_catalog_panel *catalog;
  1851. struct dp_panel_private *panel;
  1852. struct dp_panel_info *pinfo;
  1853. struct msm_compression_info *comp_info;
  1854. struct dp_dsc_cfg_data *dsc;
  1855. int rc;
  1856. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1857. catalog = panel->catalog;
  1858. dsc = &catalog->dsc;
  1859. pinfo = &dp_panel->pinfo;
  1860. comp_info = &pinfo->comp_info;
  1861. if (comp_info->comp_type == MSM_DISPLAY_COMPRESSION_DSC && enable) {
  1862. rc = sde_dsc_create_pps_buf_cmd(&comp_info->dsc_info,
  1863. dsc->pps, 0, sizeof(dsc->pps));
  1864. if (rc) {
  1865. DP_ERR("failed to create pps cmd %d\n", rc);
  1866. return;
  1867. }
  1868. dsc->pps_len = DSC_1_1_PPS_PARAMETER_SET_ELEMENTS;
  1869. dp_panel_dsc_prepare_pps_packet(dp_panel);
  1870. dsc->slice_per_pkt = comp_info->dsc_info.slice_per_pkt - 1;
  1871. dsc->bytes_per_pkt = comp_info->dsc_info.bytes_per_pkt;
  1872. dsc->bytes_per_pkt /= comp_info->dsc_info.slice_per_pkt;
  1873. dsc->eol_byte_num = comp_info->dsc_info.eol_byte_num;
  1874. dsc->dto_count = comp_info->dsc_info.pclk_per_line;
  1875. dsc->be_in_lane = _dp_panel_calc_be_in_lane(dp_panel);
  1876. dsc->dsc_en = true;
  1877. dsc->dto_en = true;
  1878. dsc->continuous_pps = dp_panel->dsc_continuous_pps;
  1879. dp_panel_get_dto_params(comp_info->src_bpp, comp_info->tgt_bpp, &dsc->dto_n,
  1880. &dsc->dto_d);
  1881. } else {
  1882. dsc->dsc_en = false;
  1883. dsc->dto_en = false;
  1884. dsc->dto_n = 0;
  1885. dsc->dto_d = 0;
  1886. dsc->continuous_pps = false;
  1887. }
  1888. catalog->stream_id = dp_panel->stream_id;
  1889. catalog->dsc_cfg(catalog);
  1890. if (catalog->dsc.dsc_en && enable)
  1891. catalog->pps_flush(catalog);
  1892. }
  1893. static int dp_panel_edid_register(struct dp_panel_private *panel)
  1894. {
  1895. int rc = 0;
  1896. panel->dp_panel.edid_ctrl = sde_edid_init();
  1897. if (!panel->dp_panel.edid_ctrl) {
  1898. DP_ERR("sde edid init for DP failed\n");
  1899. rc = -ENOMEM;
  1900. }
  1901. return rc;
  1902. }
  1903. static void dp_panel_edid_deregister(struct dp_panel_private *panel)
  1904. {
  1905. sde_edid_deinit((void **)&panel->dp_panel.edid_ctrl);
  1906. }
  1907. static int dp_panel_set_stream_info(struct dp_panel *dp_panel,
  1908. enum dp_stream_id stream_id, u32 ch_start_slot,
  1909. u32 ch_tot_slots, u32 pbn, int vcpi)
  1910. {
  1911. if (!dp_panel || stream_id > DP_STREAM_MAX) {
  1912. DP_ERR("invalid input. stream_id: %d\n", stream_id);
  1913. return -EINVAL;
  1914. }
  1915. dp_panel->vcpi = vcpi;
  1916. dp_panel->stream_id = stream_id;
  1917. dp_panel->channel_start_slot = ch_start_slot;
  1918. dp_panel->channel_total_slots = ch_tot_slots;
  1919. dp_panel->pbn = pbn;
  1920. return 0;
  1921. }
  1922. static int dp_panel_init_panel_info(struct dp_panel *dp_panel)
  1923. {
  1924. int rc = 0;
  1925. struct dp_panel_private *panel;
  1926. struct dp_panel_info *pinfo;
  1927. if (!dp_panel) {
  1928. DP_ERR("invalid input\n");
  1929. rc = -EINVAL;
  1930. goto end;
  1931. }
  1932. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1933. pinfo = &dp_panel->pinfo;
  1934. drm_dp_dpcd_writeb(panel->aux->drm_aux, DP_SET_POWER, DP_SET_POWER_D3);
  1935. /* 200us propagation time for the power down to take effect */
  1936. usleep_range(200, 205);
  1937. drm_dp_dpcd_writeb(panel->aux->drm_aux, DP_SET_POWER, DP_SET_POWER_D0);
  1938. /*
  1939. * According to the DP 1.1 specification, a "Sink Device must exit the
  1940. * power saving state within 1 ms" (Section 2.5.3.1, Table 5-52, "Sink
  1941. * Control Field" (register 0x600).
  1942. */
  1943. usleep_range(1000, 2000);
  1944. end:
  1945. return rc;
  1946. }
  1947. static int dp_panel_deinit_panel_info(struct dp_panel *dp_panel, u32 flags)
  1948. {
  1949. int rc = 0;
  1950. struct dp_panel_private *panel;
  1951. struct drm_msm_ext_hdr_metadata *hdr_meta;
  1952. struct dp_sdp_header *dhdr_vsif_sdp;
  1953. struct sde_connector *sde_conn;
  1954. struct dp_sdp_header *shdr_if_sdp;
  1955. struct dp_catalog_vsc_sdp_colorimetry *vsc_colorimetry;
  1956. struct drm_connector *connector;
  1957. struct sde_connector_state *c_state;
  1958. if (flags & DP_PANEL_SRC_INITIATED_POWER_DOWN) {
  1959. DP_DEBUG("retain states in src initiated power down request\n");
  1960. return 0;
  1961. }
  1962. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1963. hdr_meta = &panel->catalog->hdr_meta;
  1964. dhdr_vsif_sdp = &panel->catalog->dhdr_vsif_sdp;
  1965. shdr_if_sdp = &panel->catalog->shdr_if_sdp;
  1966. vsc_colorimetry = &panel->catalog->vsc_colorimetry;
  1967. if (dp_panel->edid_ctrl->edid)
  1968. sde_free_edid((void **)&dp_panel->edid_ctrl);
  1969. dp_panel_set_stream_info(dp_panel, DP_STREAM_MAX, 0, 0, 0, 0);
  1970. memset(&dp_panel->pinfo, 0, sizeof(dp_panel->pinfo));
  1971. memset(hdr_meta, 0, sizeof(struct drm_msm_ext_hdr_metadata));
  1972. memset(dhdr_vsif_sdp, 0, sizeof(struct dp_sdp_header));
  1973. memset(shdr_if_sdp, 0, sizeof(struct dp_sdp_header));
  1974. memset(vsc_colorimetry, 0,
  1975. sizeof(struct dp_catalog_vsc_sdp_colorimetry));
  1976. panel->panel_on = false;
  1977. connector = dp_panel->connector;
  1978. sde_conn = to_sde_connector(connector);
  1979. c_state = to_sde_connector_state(connector->state);
  1980. sde_conn->hdr_eotf = 0;
  1981. sde_conn->hdr_metadata_type_one = 0;
  1982. sde_conn->hdr_max_luminance = 0;
  1983. sde_conn->hdr_avg_luminance = 0;
  1984. sde_conn->hdr_min_luminance = 0;
  1985. sde_conn->hdr_supported = false;
  1986. sde_conn->hdr_plus_app_ver = 0;
  1987. sde_conn->colorspace_updated = false;
  1988. memset(&c_state->hdr_meta, 0, sizeof(c_state->hdr_meta));
  1989. memset(&c_state->dyn_hdr_meta, 0, sizeof(c_state->dyn_hdr_meta));
  1990. dp_panel->link_bw_code = 0;
  1991. dp_panel->lane_count = 0;
  1992. return rc;
  1993. }
  1994. static bool dp_panel_hdr_supported(struct dp_panel *dp_panel)
  1995. {
  1996. struct dp_panel_private *panel;
  1997. if (!dp_panel) {
  1998. DP_ERR("invalid input\n");
  1999. return false;
  2000. }
  2001. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2002. return panel->major >= 1 && panel->vsc_supported &&
  2003. (panel->minor >= 4 || panel->vscext_supported);
  2004. }
  2005. static u32 dp_panel_calc_dhdr_pkt_limit(struct dp_panel *dp_panel,
  2006. struct dp_dhdr_maxpkt_calc_input *input)
  2007. {
  2008. s64 mdpclk_fp = drm_fixp_from_fraction(input->mdp_clk, 1000000);
  2009. s64 lclk_fp = drm_fixp_from_fraction(input->lclk, 1000);
  2010. s64 pclk_fp = drm_fixp_from_fraction(input->pclk, 1000);
  2011. s64 nlanes_fp = drm_int2fixp(input->nlanes);
  2012. s64 target_sc = input->mst_target_sc;
  2013. s64 hactive_fp = drm_int2fixp(input->h_active);
  2014. const s64 i1_fp = DRM_FIXED_ONE;
  2015. const s64 i2_fp = drm_int2fixp(2);
  2016. const s64 i10_fp = drm_int2fixp(10);
  2017. const s64 i56_fp = drm_int2fixp(56);
  2018. const s64 i64_fp = drm_int2fixp(64);
  2019. s64 mst_bw_fp = i1_fp;
  2020. s64 fec_factor_fp = i1_fp;
  2021. s64 mst_bw64_fp, mst_bw64_ceil_fp, nlanes56_fp;
  2022. u32 f1, f2, f3, f4, f5, deploy_period, target_period;
  2023. s64 f3_f5_slot_fp;
  2024. u32 calc_pkt_limit;
  2025. const u32 max_pkt_limit = 64;
  2026. if (input->fec_en && input->mst_en)
  2027. fec_factor_fp = drm_fixp_from_fraction(64000, 65537);
  2028. if (input->mst_en)
  2029. mst_bw_fp = drm_fixp_div(target_sc, i64_fp);
  2030. f1 = fixp2int_ceil(drm_fixp_div(drm_fixp_mul(i10_fp, lclk_fp),
  2031. mdpclk_fp));
  2032. f2 = fixp2int_ceil(drm_fixp_div(drm_fixp_mul(i2_fp, lclk_fp),
  2033. mdpclk_fp)) + fixp2int_ceil(drm_fixp_div(
  2034. drm_fixp_mul(i1_fp, lclk_fp), mdpclk_fp));
  2035. mst_bw64_fp = drm_fixp_mul(mst_bw_fp, i64_fp);
  2036. if (drm_fixp2int(mst_bw64_fp) == 0)
  2037. f3_f5_slot_fp = drm_fixp_div(i1_fp, drm_int2fixp(
  2038. fixp2int_ceil(drm_fixp_div(
  2039. i1_fp, mst_bw64_fp))));
  2040. else
  2041. f3_f5_slot_fp = drm_int2fixp(drm_fixp2int(mst_bw_fp));
  2042. mst_bw64_ceil_fp = drm_int2fixp(fixp2int_ceil(mst_bw64_fp));
  2043. f3 = drm_fixp2int(drm_fixp_mul(drm_int2fixp(drm_fixp2int(
  2044. drm_fixp_div(i2_fp, f3_f5_slot_fp)) + 1),
  2045. (i64_fp - mst_bw64_ceil_fp))) + 2;
  2046. if (!input->mst_en) {
  2047. f4 = 1 + drm_fixp2int(drm_fixp_div(drm_int2fixp(50),
  2048. nlanes_fp)) + drm_fixp2int(drm_fixp_div(
  2049. nlanes_fp, i2_fp));
  2050. f5 = 0;
  2051. } else {
  2052. f4 = 0;
  2053. nlanes56_fp = drm_fixp_div(i56_fp, nlanes_fp);
  2054. f5 = drm_fixp2int(drm_fixp_mul(drm_int2fixp(drm_fixp2int(
  2055. drm_fixp_div(i1_fp + nlanes56_fp,
  2056. f3_f5_slot_fp)) + 1), (i64_fp -
  2057. mst_bw64_ceil_fp + i1_fp + nlanes56_fp)));
  2058. }
  2059. deploy_period = f1 + f2 + f3 + f4 + f5 + 19;
  2060. target_period = drm_fixp2int(drm_fixp_mul(fec_factor_fp, drm_fixp_mul(
  2061. hactive_fp, drm_fixp_div(lclk_fp, pclk_fp))));
  2062. calc_pkt_limit = target_period / deploy_period;
  2063. DP_DEBUG("input: %d, %d, %d, %d, %d, 0x%llx, %d, %d\n",
  2064. input->mdp_clk, input->lclk, input->pclk, input->h_active,
  2065. input->nlanes, input->mst_target_sc, input->mst_en ? 1 : 0,
  2066. input->fec_en ? 1 : 0);
  2067. DP_DEBUG("factors: %d, %d, %d, %d, %d\n", f1, f2, f3, f4, f5);
  2068. DP_DEBUG("d_p: %d, t_p: %d, maxPkts: %d%s\n", deploy_period,
  2069. target_period, calc_pkt_limit, calc_pkt_limit > max_pkt_limit ?
  2070. " CAPPED" : "");
  2071. if (calc_pkt_limit > max_pkt_limit)
  2072. calc_pkt_limit = max_pkt_limit;
  2073. DP_DEBUG("packet limit per line = %d\n", calc_pkt_limit);
  2074. return calc_pkt_limit;
  2075. }
  2076. static void dp_panel_setup_colorimetry_sdp(struct dp_panel *dp_panel,
  2077. u32 cspace)
  2078. {
  2079. struct dp_panel_private *panel;
  2080. struct dp_catalog_vsc_sdp_colorimetry *hdr_colorimetry;
  2081. u8 bpc;
  2082. u32 colorimetry = 0;
  2083. u32 dynamic_range = 0;
  2084. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2085. hdr_colorimetry = &panel->catalog->vsc_colorimetry;
  2086. hdr_colorimetry->header.HB0 = 0x00;
  2087. hdr_colorimetry->header.HB1 = 0x07;
  2088. hdr_colorimetry->header.HB2 = 0x05;
  2089. hdr_colorimetry->header.HB3 = 0x13;
  2090. get_sdp_colorimetry_range(panel, cspace, &colorimetry,
  2091. &dynamic_range);
  2092. /* VSC SDP Payload for DB16 */
  2093. hdr_colorimetry->data[16] = (RGB << 4) | colorimetry;
  2094. /* VSC SDP Payload for DB17 */
  2095. hdr_colorimetry->data[17] = (dynamic_range << 7);
  2096. bpc = (dp_panel->pinfo.bpp / 3);
  2097. switch (bpc) {
  2098. default:
  2099. case 10:
  2100. hdr_colorimetry->data[17] |= BIT(1);
  2101. break;
  2102. case 8:
  2103. hdr_colorimetry->data[17] |= BIT(0);
  2104. break;
  2105. case 6:
  2106. hdr_colorimetry->data[17] |= 0;
  2107. break;
  2108. }
  2109. /* VSC SDP Payload for DB18 */
  2110. hdr_colorimetry->data[18] = GRAPHICS;
  2111. }
  2112. static void dp_panel_setup_hdr_if(struct dp_panel_private *panel)
  2113. {
  2114. struct dp_sdp_header *shdr_if;
  2115. shdr_if = &panel->catalog->shdr_if_sdp;
  2116. shdr_if->HB0 = 0x00;
  2117. shdr_if->HB1 = 0x87;
  2118. shdr_if->HB2 = 0x1D;
  2119. shdr_if->HB3 = 0x13 << 2;
  2120. }
  2121. static void dp_panel_setup_dhdr_vsif(struct dp_panel_private *panel)
  2122. {
  2123. struct dp_sdp_header *dhdr_vsif;
  2124. dhdr_vsif = &panel->catalog->dhdr_vsif_sdp;
  2125. dhdr_vsif->HB0 = 0x00;
  2126. dhdr_vsif->HB1 = 0x81;
  2127. dhdr_vsif->HB2 = 0x1D;
  2128. dhdr_vsif->HB3 = 0x13 << 2;
  2129. }
  2130. static void dp_panel_setup_misc_colorimetry(struct dp_panel *dp_panel,
  2131. u32 colorspace)
  2132. {
  2133. struct dp_panel_private *panel;
  2134. struct dp_catalog_panel *catalog;
  2135. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2136. catalog = panel->catalog;
  2137. catalog->misc_val &= ~0x1e;
  2138. catalog->misc_val |= (get_misc_colorimetry_val(panel,
  2139. colorspace) << 1);
  2140. }
  2141. static int dp_panel_set_colorspace(struct dp_panel *dp_panel,
  2142. u32 colorspace)
  2143. {
  2144. int rc = 0;
  2145. struct dp_panel_private *panel;
  2146. if (!dp_panel) {
  2147. pr_err("invalid input\n");
  2148. rc = -EINVAL;
  2149. goto end;
  2150. }
  2151. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2152. if (panel->vsc_supported)
  2153. dp_panel_setup_colorimetry_sdp(dp_panel,
  2154. colorspace);
  2155. else
  2156. dp_panel_setup_misc_colorimetry(dp_panel,
  2157. colorspace);
  2158. /*
  2159. * During the first frame update panel_on will be false and
  2160. * the colorspace will be cached in the connector's state which
  2161. * shall be used in the dp_panel_hw_cfg
  2162. */
  2163. if (panel->panel_on) {
  2164. DP_DEBUG("panel is ON programming colorspace\n");
  2165. rc = panel->catalog->set_colorspace(panel->catalog,
  2166. panel->vsc_supported);
  2167. }
  2168. end:
  2169. return rc;
  2170. }
  2171. static int dp_panel_setup_hdr(struct dp_panel *dp_panel,
  2172. struct drm_msm_ext_hdr_metadata *hdr_meta,
  2173. bool dhdr_update, u64 core_clk_rate, bool flush)
  2174. {
  2175. int rc = 0, max_pkts = 0;
  2176. struct dp_panel_private *panel;
  2177. struct dp_dhdr_maxpkt_calc_input input;
  2178. struct drm_msm_ext_hdr_metadata *catalog_hdr_meta;
  2179. if (!dp_panel) {
  2180. DP_ERR("invalid input\n");
  2181. rc = -EINVAL;
  2182. goto end;
  2183. }
  2184. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2185. catalog_hdr_meta = &panel->catalog->hdr_meta;
  2186. /* use cached meta data in case meta data not provided */
  2187. if (!hdr_meta) {
  2188. if (catalog_hdr_meta->hdr_state)
  2189. goto cached;
  2190. else
  2191. goto end;
  2192. }
  2193. panel->hdr_state = hdr_meta->hdr_state;
  2194. dp_panel_setup_hdr_if(panel);
  2195. if (panel->hdr_state) {
  2196. memcpy(catalog_hdr_meta, hdr_meta,
  2197. sizeof(struct drm_msm_ext_hdr_metadata));
  2198. } else {
  2199. memset(catalog_hdr_meta, 0,
  2200. sizeof(struct drm_msm_ext_hdr_metadata));
  2201. }
  2202. cached:
  2203. if (dhdr_update) {
  2204. dp_panel_setup_dhdr_vsif(panel);
  2205. input.mdp_clk = core_clk_rate;
  2206. input.lclk = drm_dp_bw_code_to_link_rate(
  2207. panel->link->link_params.bw_code);
  2208. input.nlanes = panel->link->link_params.lane_count;
  2209. input.pclk = dp_panel->pinfo.pixel_clk_khz;
  2210. input.h_active = dp_panel->pinfo.h_active;
  2211. input.mst_target_sc = dp_panel->mst_target_sc;
  2212. input.mst_en = dp_panel->mst_state;
  2213. input.fec_en = dp_panel->fec_en;
  2214. max_pkts = dp_panel_calc_dhdr_pkt_limit(dp_panel, &input);
  2215. }
  2216. if (panel->panel_on) {
  2217. panel->catalog->stream_id = dp_panel->stream_id;
  2218. panel->catalog->config_hdr(panel->catalog, panel->hdr_state,
  2219. max_pkts, flush);
  2220. if (dhdr_update)
  2221. panel->catalog->dhdr_flush(panel->catalog);
  2222. }
  2223. end:
  2224. return rc;
  2225. }
  2226. static int dp_panel_spd_config(struct dp_panel *dp_panel)
  2227. {
  2228. int rc = 0;
  2229. struct dp_panel_private *panel;
  2230. if (!dp_panel) {
  2231. DP_ERR("invalid input\n");
  2232. rc = -EINVAL;
  2233. goto end;
  2234. }
  2235. if (dp_panel->stream_id >= DP_STREAM_MAX) {
  2236. DP_ERR("invalid stream id:%d\n", dp_panel->stream_id);
  2237. return -EINVAL;
  2238. }
  2239. if (!dp_panel->spd_enabled) {
  2240. DP_DEBUG("SPD Infoframe not enabled\n");
  2241. goto end;
  2242. }
  2243. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2244. panel->catalog->spd_vendor_name = panel->spd_vendor_name;
  2245. panel->catalog->spd_product_description =
  2246. panel->spd_product_description;
  2247. panel->catalog->stream_id = dp_panel->stream_id;
  2248. panel->catalog->config_spd(panel->catalog);
  2249. end:
  2250. return rc;
  2251. }
  2252. static void dp_panel_config_ctrl(struct dp_panel *dp_panel)
  2253. {
  2254. u32 config = 0, tbd;
  2255. u8 *dpcd = dp_panel->dpcd;
  2256. struct dp_panel_private *panel;
  2257. struct dp_catalog_panel *catalog;
  2258. struct msm_compression_info *comp_info;
  2259. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2260. catalog = panel->catalog;
  2261. comp_info = &dp_panel->pinfo.comp_info;
  2262. config |= (2 << 13); /* Default-> LSCLK DIV: 1/4 LCLK */
  2263. config |= (0 << 11); /* RGB */
  2264. tbd = panel->link->get_test_bits_depth(panel->link,
  2265. dp_panel->pinfo.bpp);
  2266. if (tbd == DP_TEST_BIT_DEPTH_UNKNOWN || comp_info->enabled)
  2267. tbd = (DP_TEST_BIT_DEPTH_8 >> DP_TEST_BIT_DEPTH_SHIFT);
  2268. config |= tbd << 8;
  2269. /* Num of Lanes */
  2270. config |= ((panel->link->link_params.lane_count - 1) << 4);
  2271. if (drm_dp_enhanced_frame_cap(dpcd))
  2272. config |= 0x40;
  2273. config |= 0x04; /* progressive video */
  2274. config |= 0x03; /* sycn clock & static Mvid */
  2275. catalog->config_ctrl(catalog, config);
  2276. }
  2277. static void dp_panel_config_misc(struct dp_panel *dp_panel)
  2278. {
  2279. struct dp_panel_private *panel;
  2280. struct dp_catalog_panel *catalog;
  2281. struct drm_connector *connector;
  2282. u32 misc_val;
  2283. u32 tb, cc, colorspace;
  2284. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2285. catalog = panel->catalog;
  2286. connector = dp_panel->connector;
  2287. cc = 0;
  2288. tb = panel->link->get_test_bits_depth(panel->link, dp_panel->pinfo.bpp);
  2289. colorspace = connector->state->colorspace;
  2290. cc = (get_misc_colorimetry_val(panel, colorspace) << 1);
  2291. misc_val = cc;
  2292. misc_val |= (tb << 5);
  2293. misc_val |= BIT(0); /* Configure clock to synchronous mode */
  2294. /* if VSC is supported then set bit 6 of MISC1 */
  2295. if (panel->vsc_supported)
  2296. misc_val |= BIT(14);
  2297. catalog->misc_val = misc_val;
  2298. catalog->config_misc(catalog);
  2299. }
  2300. static void dp_panel_config_msa(struct dp_panel *dp_panel)
  2301. {
  2302. struct dp_panel_private *panel;
  2303. struct dp_catalog_panel *catalog;
  2304. u32 rate;
  2305. u32 stream_rate_khz;
  2306. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2307. catalog = panel->catalog;
  2308. catalog->widebus_en = dp_panel->widebus_en;
  2309. rate = drm_dp_bw_code_to_link_rate(panel->link->link_params.bw_code);
  2310. stream_rate_khz = dp_panel->pinfo.pixel_clk_khz;
  2311. catalog->config_msa(catalog, rate, stream_rate_khz);
  2312. }
  2313. static void dp_panel_resolution_info(struct dp_panel_private *panel)
  2314. {
  2315. struct dp_panel_info *pinfo = &panel->dp_panel.pinfo;
  2316. /*
  2317. * print resolution info as this is a result
  2318. * of user initiated action of cable connection
  2319. */
  2320. DP_INFO("DP RESOLUTION: active(back|front|width|low)\n");
  2321. DP_INFO("%d(%d|%d|%d|%d)x%d(%d|%d|%d|%d)@%dfps %dbpp %dKhz %dLR %dLn\n",
  2322. pinfo->h_active, pinfo->h_back_porch, pinfo->h_front_porch,
  2323. pinfo->h_sync_width, pinfo->h_active_low,
  2324. pinfo->v_active, pinfo->v_back_porch, pinfo->v_front_porch,
  2325. pinfo->v_sync_width, pinfo->v_active_low,
  2326. pinfo->refresh_rate, pinfo->bpp, pinfo->pixel_clk_khz,
  2327. panel->link->link_params.bw_code,
  2328. panel->link->link_params.lane_count);
  2329. }
  2330. static void dp_panel_config_sdp(struct dp_panel *dp_panel,
  2331. bool en)
  2332. {
  2333. struct dp_panel_private *panel;
  2334. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2335. panel->catalog->stream_id = dp_panel->stream_id;
  2336. panel->catalog->config_sdp(panel->catalog, en);
  2337. }
  2338. static int dp_panel_hw_cfg(struct dp_panel *dp_panel, bool enable)
  2339. {
  2340. struct dp_panel_private *panel;
  2341. struct drm_connector *connector;
  2342. if (!dp_panel) {
  2343. DP_ERR("invalid input\n");
  2344. return -EINVAL;
  2345. }
  2346. if (dp_panel->stream_id >= DP_STREAM_MAX) {
  2347. DP_ERR("invalid stream_id: %d\n", dp_panel->stream_id);
  2348. return -EINVAL;
  2349. }
  2350. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2351. panel->catalog->stream_id = dp_panel->stream_id;
  2352. connector = dp_panel->connector;
  2353. if (enable) {
  2354. dp_panel_config_ctrl(dp_panel);
  2355. dp_panel_config_misc(dp_panel);
  2356. dp_panel_config_msa(dp_panel);
  2357. if (panel->vsc_supported) {
  2358. dp_panel_setup_colorimetry_sdp(dp_panel,
  2359. connector->state->colorspace);
  2360. dp_panel_config_sdp(dp_panel, true);
  2361. }
  2362. dp_panel_config_dsc(dp_panel, enable);
  2363. dp_panel_config_tr_unit(dp_panel);
  2364. dp_panel_config_timing(dp_panel);
  2365. dp_panel_resolution_info(panel);
  2366. } else {
  2367. dp_panel_config_sdp(dp_panel, false);
  2368. }
  2369. panel->catalog->config_dto(panel->catalog, !enable);
  2370. return 0;
  2371. }
  2372. static int dp_panel_read_sink_sts(struct dp_panel *dp_panel, u8 *sts, u32 size)
  2373. {
  2374. int rlen, rc = 0;
  2375. struct dp_panel_private *panel;
  2376. if (!dp_panel || !sts || !size) {
  2377. DP_ERR("invalid input\n");
  2378. rc = -EINVAL;
  2379. return rc;
  2380. }
  2381. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2382. rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_SINK_COUNT_ESI,
  2383. sts, size);
  2384. if (rlen != size) {
  2385. DP_ERR("dpcd sink sts fail rlen:%d size:%d\n", rlen, size);
  2386. rc = -EINVAL;
  2387. return rc;
  2388. }
  2389. return 0;
  2390. }
  2391. static int dp_panel_update_edid(struct dp_panel *dp_panel, struct edid *edid)
  2392. {
  2393. int rc;
  2394. dp_panel->edid_ctrl->edid = edid;
  2395. sde_parse_edid(dp_panel->edid_ctrl);
  2396. rc = _sde_edid_update_modes(dp_panel->connector, dp_panel->edid_ctrl);
  2397. dp_panel->audio_supported = drm_detect_monitor_audio(edid);
  2398. return rc;
  2399. }
  2400. static bool dp_panel_read_mst_cap(struct dp_panel *dp_panel)
  2401. {
  2402. int rlen;
  2403. struct dp_panel_private *panel;
  2404. u8 dpcd;
  2405. bool mst_cap = false;
  2406. if (!dp_panel) {
  2407. DP_ERR("invalid input\n");
  2408. return 0;
  2409. }
  2410. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2411. rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_MSTM_CAP,
  2412. &dpcd, 1);
  2413. if (rlen < 1) {
  2414. DP_ERR("dpcd mstm_cap read failed, rlen=%d\n", rlen);
  2415. goto end;
  2416. }
  2417. mst_cap = (dpcd & DP_MST_CAP) ? true : false;
  2418. end:
  2419. DP_DEBUG("dp mst-cap: %d\n", mst_cap);
  2420. return mst_cap;
  2421. }
  2422. static void dp_panel_convert_to_dp_mode(struct dp_panel *dp_panel,
  2423. const struct drm_display_mode *drm_mode,
  2424. struct dp_display_mode *dp_mode)
  2425. {
  2426. const u32 num_components = 3, default_bpp = 24;
  2427. struct msm_compression_info *comp_info;
  2428. bool dsc_en = (dp_mode->capabilities & DP_PANEL_CAPS_DSC) ? true : false;
  2429. int rc;
  2430. dp_mode->timing.h_active = drm_mode->hdisplay;
  2431. dp_mode->timing.h_back_porch = drm_mode->htotal - drm_mode->hsync_end;
  2432. dp_mode->timing.h_sync_width = drm_mode->htotal -
  2433. (drm_mode->hsync_start + dp_mode->timing.h_back_porch);
  2434. dp_mode->timing.h_front_porch = drm_mode->hsync_start -
  2435. drm_mode->hdisplay;
  2436. dp_mode->timing.h_skew = drm_mode->hskew;
  2437. dp_mode->timing.v_active = drm_mode->vdisplay;
  2438. dp_mode->timing.v_back_porch = drm_mode->vtotal - drm_mode->vsync_end;
  2439. dp_mode->timing.v_sync_width = drm_mode->vtotal -
  2440. (drm_mode->vsync_start + dp_mode->timing.v_back_porch);
  2441. dp_mode->timing.v_front_porch = drm_mode->vsync_start -
  2442. drm_mode->vdisplay;
  2443. dp_mode->timing.refresh_rate = drm_mode_vrefresh(drm_mode);
  2444. dp_mode->timing.pixel_clk_khz = drm_mode->clock;
  2445. dp_mode->timing.v_active_low =
  2446. !!(drm_mode->flags & DRM_MODE_FLAG_NVSYNC);
  2447. dp_mode->timing.h_active_low =
  2448. !!(drm_mode->flags & DRM_MODE_FLAG_NHSYNC);
  2449. dp_mode->timing.bpp =
  2450. dp_panel->connector->display_info.bpc * num_components;
  2451. if (!dp_mode->timing.bpp)
  2452. dp_mode->timing.bpp = default_bpp;
  2453. dp_mode->timing.widebus_en = dp_panel->widebus_en;
  2454. dp_mode->timing.dsc_overhead_fp = 0;
  2455. comp_info = &dp_mode->timing.comp_info;
  2456. comp_info->src_bpp = default_bpp;
  2457. comp_info->tgt_bpp = default_bpp;
  2458. comp_info->comp_type = MSM_DISPLAY_COMPRESSION_NONE;
  2459. comp_info->comp_ratio = 1;
  2460. comp_info->enabled = false;
  2461. /* As YUV was not supported now, so set the default format to RGB */
  2462. dp_mode->output_format = DP_OUTPUT_FORMAT_RGB;
  2463. /*
  2464. * If a given videomode can be only supported in YCBCR420, set
  2465. * the output format to YUV420. While now our driver did not
  2466. * support YUV display over DP, so just place this flag here.
  2467. * When we want to support YUV, we can use this flag to do
  2468. * a lot of settings, like CDM, CSC and pixel_clock.
  2469. */
  2470. if (drm_mode_is_420_only(&dp_panel->connector->display_info,
  2471. drm_mode)) {
  2472. dp_mode->output_format = DP_OUTPUT_FORMAT_YCBCR420;
  2473. DP_DEBUG("YCBCR420 was not supported");
  2474. }
  2475. dp_mode->timing.bpp = dp_panel_get_mode_bpp(dp_panel,
  2476. dp_mode->timing.bpp, dp_mode->timing.pixel_clk_khz, dsc_en);
  2477. if (dsc_en) {
  2478. if (dp_panel_dsc_prepare_basic_params(comp_info,
  2479. dp_mode, dp_panel)) {
  2480. DP_DEBUG("prepare DSC basic params failed\n");
  2481. return;
  2482. }
  2483. rc = sde_dsc_populate_dsc_config(&comp_info->dsc_info.config, 0);
  2484. if (rc) {
  2485. DP_DEBUG("failed populating dsc params \n");
  2486. return;
  2487. }
  2488. rc = sde_dsc_populate_dsc_private_params(&comp_info->dsc_info,
  2489. dp_mode->timing.h_active);
  2490. if (rc) {
  2491. DP_DEBUG("failed populating other dsc params\n");
  2492. return;
  2493. }
  2494. dp_panel_dsc_pclk_param_calc(dp_panel, comp_info, dp_mode);
  2495. }
  2496. dp_mode->fec_overhead_fp = dp_panel->fec_overhead_fp;
  2497. }
  2498. static void dp_panel_update_pps(struct dp_panel *dp_panel, char *pps_cmd)
  2499. {
  2500. struct dp_catalog_panel *catalog;
  2501. struct dp_panel_private *panel;
  2502. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2503. catalog = panel->catalog;
  2504. catalog->stream_id = dp_panel->stream_id;
  2505. catalog->pps_flush(catalog);
  2506. }
  2507. int dp_panel_get_src_crc(struct dp_panel *dp_panel, u16 *crc)
  2508. {
  2509. struct dp_catalog_panel *catalog;
  2510. struct dp_panel_private *panel;
  2511. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2512. catalog = panel->catalog;
  2513. return catalog->get_src_crc(catalog, crc);
  2514. }
  2515. int dp_panel_get_sink_crc(struct dp_panel *dp_panel, u16 *crc)
  2516. {
  2517. int rc = 0;
  2518. struct dp_panel_private *panel;
  2519. struct drm_dp_aux *drm_aux;
  2520. u8 crc_bytes[6];
  2521. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2522. drm_aux = panel->aux->drm_aux;
  2523. /*
  2524. * At DP_TEST_CRC_R_CR, there's 6 bytes containing CRC data, 2 bytes
  2525. * per component (RGB or CrYCb).
  2526. */
  2527. rc = drm_dp_dpcd_read(drm_aux, DP_TEST_CRC_R_CR, crc_bytes, 6);
  2528. if (rc < 0)
  2529. return rc;
  2530. rc = 0;
  2531. crc[0] = crc_bytes[0] | crc_bytes[1] << 8;
  2532. crc[1] = crc_bytes[2] | crc_bytes[3] << 8;
  2533. crc[2] = crc_bytes[4] | crc_bytes[5] << 8;
  2534. return rc;
  2535. }
  2536. int dp_panel_sink_crc_enable(struct dp_panel *dp_panel, bool enable)
  2537. {
  2538. int rc = 0;
  2539. struct dp_panel_private *panel;
  2540. struct drm_dp_aux *drm_aux;
  2541. ssize_t ret;
  2542. u8 buf;
  2543. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2544. drm_aux = panel->aux->drm_aux;
  2545. if (dp_panel->link_info.capabilities & DP_LINK_CAP_CRC) {
  2546. ret = drm_dp_dpcd_readb(drm_aux, DP_TEST_SINK, &buf);
  2547. if (ret < 0)
  2548. return ret;
  2549. ret = drm_dp_dpcd_writeb(drm_aux, DP_TEST_SINK, buf | DP_TEST_SINK_START);
  2550. if (ret < 0)
  2551. return ret;
  2552. drm_dp_dpcd_readb(drm_aux, DP_TEST_SINK, &buf);
  2553. DP_DEBUG("Enabled CRC: %x\n", buf);
  2554. }
  2555. return rc;
  2556. }
  2557. struct dp_panel *dp_panel_get(struct dp_panel_in *in)
  2558. {
  2559. int rc = 0;
  2560. struct dp_panel_private *panel;
  2561. struct dp_panel *dp_panel;
  2562. struct sde_connector *sde_conn;
  2563. if (!in->dev || !in->catalog || !in->aux ||
  2564. !in->link || !in->connector) {
  2565. DP_ERR("invalid input\n");
  2566. rc = -EINVAL;
  2567. goto error;
  2568. }
  2569. panel = devm_kzalloc(in->dev, sizeof(*panel), GFP_KERNEL);
  2570. if (!panel) {
  2571. rc = -ENOMEM;
  2572. goto error;
  2573. }
  2574. panel->dev = in->dev;
  2575. panel->aux = in->aux;
  2576. panel->catalog = in->catalog;
  2577. panel->link = in->link;
  2578. panel->parser = in->parser;
  2579. dp_panel = &panel->dp_panel;
  2580. dp_panel->max_bw_code = DP_LINK_BW_8_1;
  2581. dp_panel->spd_enabled = true;
  2582. dp_panel->link_bw_code = 0;
  2583. dp_panel->lane_count = 0;
  2584. memcpy(panel->spd_vendor_name, vendor_name, (sizeof(u8) * 8));
  2585. memcpy(panel->spd_product_description, product_desc, (sizeof(u8) * 16));
  2586. dp_panel->connector = in->connector;
  2587. dp_panel->dsc_feature_enable = panel->parser->dsc_feature_enable;
  2588. dp_panel->fec_feature_enable = panel->parser->fec_feature_enable;
  2589. dp_panel->dsc_continuous_pps = panel->parser->dsc_continuous_pps;
  2590. if (in->base_panel) {
  2591. memcpy(dp_panel->dpcd, in->base_panel->dpcd,
  2592. DP_RECEIVER_CAP_SIZE + 1);
  2593. memcpy(dp_panel->dsc_dpcd, in->base_panel->dsc_dpcd,
  2594. DP_RECEIVER_DSC_CAP_SIZE + 1);
  2595. memcpy(&dp_panel->link_info, &in->base_panel->link_info,
  2596. sizeof(dp_panel->link_info));
  2597. dp_panel->mst_state = in->base_panel->mst_state;
  2598. dp_panel->widebus_en = in->base_panel->widebus_en;
  2599. dp_panel->fec_en = in->base_panel->fec_en;
  2600. dp_panel->dsc_en = in->base_panel->dsc_en;
  2601. dp_panel->fec_overhead_fp = in->base_panel->fec_overhead_fp;
  2602. dp_panel->sink_dsc_caps = in->base_panel->sink_dsc_caps;
  2603. }
  2604. dp_panel->init = dp_panel_init_panel_info;
  2605. dp_panel->deinit = dp_panel_deinit_panel_info;
  2606. dp_panel->hw_cfg = dp_panel_hw_cfg;
  2607. dp_panel->read_sink_caps = dp_panel_read_sink_caps;
  2608. dp_panel->get_mode_bpp = dp_panel_get_mode_bpp;
  2609. dp_panel->get_modes = dp_panel_get_modes;
  2610. dp_panel->handle_sink_request = dp_panel_handle_sink_request;
  2611. dp_panel->tpg_config = dp_panel_tpg_config;
  2612. dp_panel->spd_config = dp_panel_spd_config;
  2613. dp_panel->setup_hdr = dp_panel_setup_hdr;
  2614. dp_panel->set_colorspace = dp_panel_set_colorspace;
  2615. dp_panel->hdr_supported = dp_panel_hdr_supported;
  2616. dp_panel->set_stream_info = dp_panel_set_stream_info;
  2617. dp_panel->read_sink_status = dp_panel_read_sink_sts;
  2618. dp_panel->update_edid = dp_panel_update_edid;
  2619. dp_panel->read_mst_cap = dp_panel_read_mst_cap;
  2620. dp_panel->convert_to_dp_mode = dp_panel_convert_to_dp_mode;
  2621. dp_panel->update_pps = dp_panel_update_pps;
  2622. dp_panel->get_src_crc = dp_panel_get_src_crc;
  2623. dp_panel->get_sink_crc = dp_panel_get_sink_crc;
  2624. dp_panel->sink_crc_enable = dp_panel_sink_crc_enable;
  2625. sde_conn = to_sde_connector(dp_panel->connector);
  2626. sde_conn->drv_panel = dp_panel;
  2627. dp_panel_edid_register(panel);
  2628. return dp_panel;
  2629. error:
  2630. return ERR_PTR(rc);
  2631. }
  2632. void dp_panel_put(struct dp_panel *dp_panel)
  2633. {
  2634. struct dp_panel_private *panel;
  2635. struct sde_connector *sde_conn;
  2636. if (!dp_panel)
  2637. return;
  2638. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2639. dp_panel_edid_deregister(panel);
  2640. sde_conn = to_sde_connector(dp_panel->connector);
  2641. if (sde_conn)
  2642. sde_conn->drv_panel = NULL;
  2643. devm_kfree(panel->dev, panel);
  2644. }