dp_panel.c 86 KB

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