dp_panel.c 89 KB

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