dp_panel.c 89 KB

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