dp_panel.c 86 KB

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