dp_panel.c 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388
  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. if (dp_panel->dsc_dpcd[0]) {
  1666. dp_panel->sink_dsc_caps.dsc_capable = true;
  1667. dp_panel->sink_dsc_caps.version = dp_panel->dsc_dpcd[1];
  1668. dp_panel->sink_dsc_caps.block_pred_en =
  1669. dp_panel->dsc_dpcd[6] ? true : false;
  1670. if (dp_panel->sink_dsc_caps.version >= 0x11)
  1671. dp_panel->dsc_en = true;
  1672. } else {
  1673. dp_panel->sink_dsc_caps.dsc_capable = false;
  1674. dp_panel->dsc_en = false;
  1675. }
  1676. dp_panel->widebus_en = dp_panel->dsc_en;
  1677. }
  1678. static void dp_panel_read_sink_dsc_caps(struct dp_panel *dp_panel)
  1679. {
  1680. int rlen;
  1681. struct dp_panel_private *panel;
  1682. int dpcd_rev;
  1683. if (!dp_panel) {
  1684. DP_ERR("invalid input\n");
  1685. return;
  1686. }
  1687. dpcd_rev = dp_panel->dpcd[DP_DPCD_REV];
  1688. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1689. if (panel->parser->dsc_feature_enable && dpcd_rev >= 0x14) {
  1690. rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_DSC_SUPPORT,
  1691. dp_panel->dsc_dpcd, (DP_RECEIVER_DSC_CAP_SIZE + 1));
  1692. if (rlen < (DP_RECEIVER_DSC_CAP_SIZE + 1)) {
  1693. DP_DEBUG("dsc dpcd read failed, rlen=%d\n", rlen);
  1694. return;
  1695. }
  1696. print_hex_dump(KERN_DEBUG, "[drm-dp] SINK DSC DPCD: ",
  1697. DUMP_PREFIX_NONE, 8, 1, dp_panel->dsc_dpcd, rlen,
  1698. false);
  1699. dp_panel_decode_dsc_dpcd(dp_panel);
  1700. }
  1701. }
  1702. static void dp_panel_read_sink_fec_caps(struct dp_panel *dp_panel)
  1703. {
  1704. int rlen;
  1705. struct dp_panel_private *panel;
  1706. s64 fec_overhead_fp = drm_fixp_from_fraction(1, 1);
  1707. if (!dp_panel) {
  1708. DP_ERR("invalid input\n");
  1709. return;
  1710. }
  1711. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1712. rlen = drm_dp_dpcd_readb(panel->aux->drm_aux, DP_FEC_CAPABILITY,
  1713. &dp_panel->fec_dpcd);
  1714. if (rlen < 1) {
  1715. DP_ERR("fec capability read failed, rlen=%d\n", rlen);
  1716. return;
  1717. }
  1718. dp_panel->fec_en = dp_panel->fec_dpcd & DP_FEC_CAPABLE;
  1719. if (dp_panel->fec_en)
  1720. fec_overhead_fp = drm_fixp_from_fraction(100000, 97582);
  1721. dp_panel->fec_overhead_fp = fec_overhead_fp;
  1722. return;
  1723. }
  1724. static int dp_panel_read_sink_caps(struct dp_panel *dp_panel,
  1725. struct drm_connector *connector, bool multi_func)
  1726. {
  1727. int rc = 0, rlen, count, downstream_ports;
  1728. const int count_len = 1;
  1729. struct dp_panel_private *panel;
  1730. if (!dp_panel || !connector) {
  1731. DP_ERR("invalid input\n");
  1732. rc = -EINVAL;
  1733. goto end;
  1734. }
  1735. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1736. rc = dp_panel_read_dpcd(dp_panel, multi_func);
  1737. if (rc || !is_link_rate_valid(drm_dp_link_rate_to_bw_code(
  1738. dp_panel->link_info.rate)) || !is_lane_count_valid(
  1739. dp_panel->link_info.num_lanes) ||
  1740. ((drm_dp_link_rate_to_bw_code(dp_panel->link_info.rate)) >
  1741. dp_panel->max_bw_code)) {
  1742. if ((rc == -ETIMEDOUT) || (rc == -ENODEV)) {
  1743. DP_ERR("DPCD read failed, return early\n");
  1744. goto end;
  1745. }
  1746. DP_ERR("panel dpcd read failed/incorrect, set default params\n");
  1747. dp_panel_set_default_link_params(dp_panel);
  1748. }
  1749. downstream_ports = dp_panel->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  1750. DP_DWN_STRM_PORT_PRESENT;
  1751. if (downstream_ports) {
  1752. rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_SINK_COUNT,
  1753. &count, count_len);
  1754. if (rlen == count_len) {
  1755. count = DP_GET_SINK_COUNT(count);
  1756. if (!count) {
  1757. DP_ERR("no downstream ports connected\n");
  1758. panel->link->sink_count.count = 0;
  1759. rc = -ENOTCONN;
  1760. goto end;
  1761. }
  1762. }
  1763. }
  1764. rc = dp_panel_read_edid(dp_panel, connector);
  1765. if (rc) {
  1766. DP_ERR("panel edid read failed, set failsafe mode\n");
  1767. return rc;
  1768. }
  1769. dp_panel->widebus_en = panel->parser->has_widebus;
  1770. dp_panel->dsc_feature_enable = panel->parser->dsc_feature_enable;
  1771. dp_panel->fec_feature_enable = panel->parser->fec_feature_enable;
  1772. dp_panel->fec_en = false;
  1773. dp_panel->dsc_en = false;
  1774. if (dp_panel->fec_feature_enable) {
  1775. dp_panel_read_sink_fec_caps(dp_panel);
  1776. if (dp_panel->dsc_feature_enable && dp_panel->fec_en)
  1777. dp_panel_read_sink_dsc_caps(dp_panel);
  1778. }
  1779. DP_INFO("fec_en=%d, dsc_en=%d, widebus_en=%d\n", dp_panel->fec_en,
  1780. dp_panel->dsc_en, dp_panel->widebus_en);
  1781. end:
  1782. return rc;
  1783. }
  1784. static u32 dp_panel_get_supported_bpp(struct dp_panel *dp_panel,
  1785. u32 mode_edid_bpp, u32 mode_pclk_khz)
  1786. {
  1787. struct drm_dp_link *link_info;
  1788. const u32 max_supported_bpp = 30;
  1789. u32 min_supported_bpp = 18;
  1790. u32 bpp = 0, data_rate_khz = 0;
  1791. if (dp_panel->dsc_en)
  1792. min_supported_bpp = 24;
  1793. bpp = min_t(u32, mode_edid_bpp, max_supported_bpp);
  1794. link_info = &dp_panel->link_info;
  1795. data_rate_khz = link_info->num_lanes * link_info->rate * 8;
  1796. while (bpp > min_supported_bpp) {
  1797. if (mode_pclk_khz * bpp <= data_rate_khz)
  1798. break;
  1799. bpp -= 6;
  1800. }
  1801. return bpp;
  1802. }
  1803. static u32 dp_panel_get_mode_bpp(struct dp_panel *dp_panel,
  1804. u32 mode_edid_bpp, u32 mode_pclk_khz)
  1805. {
  1806. struct dp_panel_private *panel;
  1807. u32 bpp = mode_edid_bpp;
  1808. if (!dp_panel || !mode_edid_bpp || !mode_pclk_khz) {
  1809. DP_ERR("invalid input\n");
  1810. return 0;
  1811. }
  1812. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1813. if (dp_panel->video_test)
  1814. bpp = dp_link_bit_depth_to_bpp(
  1815. panel->link->test_video.test_bit_depth);
  1816. else
  1817. bpp = dp_panel_get_supported_bpp(dp_panel, mode_edid_bpp,
  1818. mode_pclk_khz);
  1819. return bpp;
  1820. }
  1821. static void dp_panel_set_test_mode(struct dp_panel_private *panel,
  1822. struct dp_display_mode *mode)
  1823. {
  1824. struct dp_panel_info *pinfo = NULL;
  1825. struct dp_link_test_video *test_info = NULL;
  1826. if (!panel) {
  1827. DP_ERR("invalid params\n");
  1828. return;
  1829. }
  1830. pinfo = &mode->timing;
  1831. test_info = &panel->link->test_video;
  1832. pinfo->h_active = test_info->test_h_width;
  1833. pinfo->h_sync_width = test_info->test_hsync_width;
  1834. pinfo->h_back_porch = test_info->test_h_start -
  1835. test_info->test_hsync_width;
  1836. pinfo->h_front_porch = test_info->test_h_total -
  1837. (test_info->test_h_start + test_info->test_h_width);
  1838. pinfo->v_active = test_info->test_v_height;
  1839. pinfo->v_sync_width = test_info->test_vsync_width;
  1840. pinfo->v_back_porch = test_info->test_v_start -
  1841. test_info->test_vsync_width;
  1842. pinfo->v_front_porch = test_info->test_v_total -
  1843. (test_info->test_v_start + test_info->test_v_height);
  1844. pinfo->bpp = dp_link_bit_depth_to_bpp(test_info->test_bit_depth);
  1845. pinfo->h_active_low = test_info->test_hsync_pol;
  1846. pinfo->v_active_low = test_info->test_vsync_pol;
  1847. pinfo->refresh_rate = test_info->test_rr_n;
  1848. pinfo->pixel_clk_khz = test_info->test_h_total *
  1849. test_info->test_v_total * pinfo->refresh_rate;
  1850. if (test_info->test_rr_d == 0)
  1851. pinfo->pixel_clk_khz /= 1000;
  1852. else
  1853. pinfo->pixel_clk_khz /= 1001;
  1854. if (test_info->test_h_width == 640)
  1855. pinfo->pixel_clk_khz = 25170;
  1856. }
  1857. static int dp_panel_get_modes(struct dp_panel *dp_panel,
  1858. struct drm_connector *connector, struct dp_display_mode *mode)
  1859. {
  1860. struct dp_panel_private *panel;
  1861. if (!dp_panel) {
  1862. DP_ERR("invalid input\n");
  1863. return -EINVAL;
  1864. }
  1865. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1866. if (dp_panel->video_test) {
  1867. dp_panel_set_test_mode(panel, mode);
  1868. return 1;
  1869. } else if (dp_panel->edid_ctrl->edid) {
  1870. return _sde_edid_update_modes(connector, dp_panel->edid_ctrl);
  1871. }
  1872. /* fail-safe mode */
  1873. memcpy(&mode->timing, &fail_safe,
  1874. sizeof(fail_safe));
  1875. return 1;
  1876. }
  1877. static void dp_panel_handle_sink_request(struct dp_panel *dp_panel)
  1878. {
  1879. struct dp_panel_private *panel;
  1880. if (!dp_panel) {
  1881. DP_ERR("invalid input\n");
  1882. return;
  1883. }
  1884. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1885. if (panel->link->sink_request & DP_TEST_LINK_EDID_READ) {
  1886. u8 checksum;
  1887. if (dp_panel->edid_ctrl->edid)
  1888. checksum = sde_get_edid_checksum(dp_panel->edid_ctrl);
  1889. else
  1890. checksum = dp_panel->connector->checksum;
  1891. panel->link->send_edid_checksum(panel->link, checksum);
  1892. panel->link->send_test_response(panel->link);
  1893. }
  1894. }
  1895. static void dp_panel_tpg_config(struct dp_panel *dp_panel, bool enable)
  1896. {
  1897. u32 hsync_start_x, hsync_end_x;
  1898. struct dp_catalog_panel *catalog;
  1899. struct dp_panel_private *panel;
  1900. struct dp_panel_info *pinfo;
  1901. if (!dp_panel) {
  1902. DP_ERR("invalid input\n");
  1903. return;
  1904. }
  1905. if (dp_panel->stream_id >= DP_STREAM_MAX) {
  1906. DP_ERR("invalid stream id:%d\n", dp_panel->stream_id);
  1907. return;
  1908. }
  1909. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1910. catalog = panel->catalog;
  1911. pinfo = &panel->dp_panel.pinfo;
  1912. if (!panel->panel_on) {
  1913. DP_DEBUG("DP panel not enabled, handle TPG on next panel on\n");
  1914. return;
  1915. }
  1916. if (!enable) {
  1917. panel->catalog->tpg_config(catalog, false);
  1918. return;
  1919. }
  1920. /* TPG config */
  1921. catalog->hsync_period = pinfo->h_sync_width + pinfo->h_back_porch +
  1922. pinfo->h_active + pinfo->h_front_porch;
  1923. catalog->vsync_period = pinfo->v_sync_width + pinfo->v_back_porch +
  1924. pinfo->v_active + pinfo->v_front_porch;
  1925. catalog->display_v_start = ((pinfo->v_sync_width +
  1926. pinfo->v_back_porch) * catalog->hsync_period);
  1927. catalog->display_v_end = ((catalog->vsync_period -
  1928. pinfo->v_front_porch) * catalog->hsync_period) - 1;
  1929. catalog->display_v_start += pinfo->h_sync_width + pinfo->h_back_porch;
  1930. catalog->display_v_end -= pinfo->h_front_porch;
  1931. hsync_start_x = pinfo->h_back_porch + pinfo->h_sync_width;
  1932. hsync_end_x = catalog->hsync_period - pinfo->h_front_porch - 1;
  1933. catalog->v_sync_width = pinfo->v_sync_width;
  1934. catalog->hsync_ctl = (catalog->hsync_period << 16) |
  1935. pinfo->h_sync_width;
  1936. catalog->display_hctl = (hsync_end_x << 16) | hsync_start_x;
  1937. panel->catalog->tpg_config(catalog, true);
  1938. }
  1939. static int dp_panel_config_timing(struct dp_panel *dp_panel)
  1940. {
  1941. int rc = 0;
  1942. u32 data, total_ver, total_hor;
  1943. struct dp_catalog_panel *catalog;
  1944. struct dp_panel_private *panel;
  1945. struct dp_panel_info *pinfo;
  1946. if (!dp_panel) {
  1947. DP_ERR("invalid input\n");
  1948. rc = -EINVAL;
  1949. goto end;
  1950. }
  1951. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  1952. catalog = panel->catalog;
  1953. pinfo = &panel->dp_panel.pinfo;
  1954. DP_DEBUG("width=%d hporch= %d %d %d\n",
  1955. pinfo->h_active, pinfo->h_back_porch,
  1956. pinfo->h_front_porch, pinfo->h_sync_width);
  1957. DP_DEBUG("height=%d vporch= %d %d %d\n",
  1958. pinfo->v_active, pinfo->v_back_porch,
  1959. pinfo->v_front_porch, pinfo->v_sync_width);
  1960. total_hor = pinfo->h_active + pinfo->h_back_porch +
  1961. pinfo->h_front_porch + pinfo->h_sync_width;
  1962. total_ver = pinfo->v_active + pinfo->v_back_porch +
  1963. pinfo->v_front_porch + pinfo->v_sync_width;
  1964. data = total_ver;
  1965. data <<= 16;
  1966. data |= total_hor;
  1967. catalog->total = data;
  1968. data = (pinfo->v_back_porch + pinfo->v_sync_width);
  1969. data <<= 16;
  1970. data |= (pinfo->h_back_porch + pinfo->h_sync_width);
  1971. catalog->sync_start = data;
  1972. data = pinfo->v_sync_width;
  1973. data <<= 16;
  1974. data |= (pinfo->v_active_low << 31);
  1975. data |= pinfo->h_sync_width;
  1976. data |= (pinfo->h_active_low << 15);
  1977. catalog->width_blanking = data;
  1978. data = pinfo->v_active;
  1979. data <<= 16;
  1980. data |= pinfo->h_active;
  1981. catalog->dp_active = data;
  1982. catalog->widebus_en = pinfo->widebus_en;
  1983. panel->catalog->timing_cfg(catalog);
  1984. panel->panel_on = true;
  1985. end:
  1986. return rc;
  1987. }
  1988. static u32 _dp_panel_calc_be_in_lane(struct dp_panel *dp_panel)
  1989. {
  1990. struct dp_panel_info *pinfo;
  1991. struct msm_compression_info *comp_info;
  1992. u32 dsc_htot_byte_cnt, mod_result;
  1993. u32 numerator, denominator;
  1994. s64 temp_fp;
  1995. u32 be_in_lane = 10;
  1996. pinfo = &dp_panel->pinfo;
  1997. comp_info = &pinfo->comp_info;
  1998. if (!dp_panel->mst_state)
  1999. return be_in_lane;
  2000. switch (pinfo->comp_info.comp_ratio) {
  2001. case MSM_DISPLAY_COMPRESSION_RATIO_2_TO_1:
  2002. denominator = 16; /* 2 * bits-in-byte */
  2003. break;
  2004. case MSM_DISPLAY_COMPRESSION_RATIO_3_TO_1:
  2005. denominator = 24; /* 3 * bits-in-byte */
  2006. break;
  2007. default:
  2008. denominator = 8; /* 1 * bits-in-byte */
  2009. }
  2010. numerator = (pinfo->h_active + pinfo->h_back_porch +
  2011. pinfo->h_front_porch + pinfo->h_sync_width) *
  2012. pinfo->bpp;
  2013. temp_fp = drm_fixp_from_fraction(numerator, denominator);
  2014. dsc_htot_byte_cnt = drm_fixp2int_ceil(temp_fp);
  2015. mod_result = dsc_htot_byte_cnt % 12;
  2016. if (mod_result == 0)
  2017. be_in_lane = 8;
  2018. else if (mod_result <= 3)
  2019. be_in_lane = 1;
  2020. else if (mod_result <= 6)
  2021. be_in_lane = 2;
  2022. else if (mod_result <= 9)
  2023. be_in_lane = 4;
  2024. else if (mod_result <= 11)
  2025. be_in_lane = 8;
  2026. else
  2027. be_in_lane = 10;
  2028. return be_in_lane;
  2029. }
  2030. static void dp_panel_config_dsc(struct dp_panel *dp_panel, bool enable)
  2031. {
  2032. struct dp_catalog_panel *catalog;
  2033. struct dp_panel_private *panel;
  2034. struct dp_panel_info *pinfo;
  2035. struct msm_compression_info *comp_info;
  2036. struct dp_dsc_cfg_data *dsc;
  2037. int pps_len;
  2038. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2039. catalog = panel->catalog;
  2040. dsc = &catalog->dsc;
  2041. pinfo = &dp_panel->pinfo;
  2042. comp_info = &pinfo->comp_info;
  2043. if (comp_info->comp_type == MSM_DISPLAY_COMPRESSION_DSC && enable) {
  2044. pps_len = dp_panel_dsc_create_pps_buf_cmd(&comp_info->dsc_info,
  2045. dsc->pps, 0);
  2046. dsc->pps_len = pps_len;
  2047. dp_panel_dsc_prepare_pps_packet(dp_panel);
  2048. dsc->slice_per_pkt = comp_info->dsc_info.slice_per_pkt - 1;
  2049. dsc->bytes_per_pkt = comp_info->dsc_info.bytes_per_pkt;
  2050. dsc->bytes_per_pkt /= comp_info->dsc_info.slice_per_pkt;
  2051. dsc->eol_byte_num = comp_info->dsc_info.eol_byte_num;
  2052. dsc->dto_count = comp_info->dsc_info.pclk_per_line;
  2053. dsc->be_in_lane = _dp_panel_calc_be_in_lane(dp_panel);
  2054. dsc->dsc_en = true;
  2055. dsc->dto_en = true;
  2056. _dp_panel_get_dto_m_n(comp_info->comp_ratio, pinfo->bpp,
  2057. &dsc->dto_n, &dsc->dto_d);
  2058. } else {
  2059. dsc->dsc_en = false;
  2060. dsc->dto_en = false;
  2061. dsc->dto_n = 0;
  2062. dsc->dto_d = 0;
  2063. }
  2064. catalog->stream_id = dp_panel->stream_id;
  2065. catalog->dsc_cfg(catalog);
  2066. if (catalog->dsc.dsc_en && enable)
  2067. catalog->pps_flush(catalog);
  2068. }
  2069. static int dp_panel_edid_register(struct dp_panel_private *panel)
  2070. {
  2071. int rc = 0;
  2072. panel->dp_panel.edid_ctrl = sde_edid_init();
  2073. if (!panel->dp_panel.edid_ctrl) {
  2074. DP_ERR("sde edid init for DP failed\n");
  2075. rc = -ENOMEM;
  2076. }
  2077. return rc;
  2078. }
  2079. static void dp_panel_edid_deregister(struct dp_panel_private *panel)
  2080. {
  2081. sde_edid_deinit((void **)&panel->dp_panel.edid_ctrl);
  2082. }
  2083. static int dp_panel_set_stream_info(struct dp_panel *dp_panel,
  2084. enum dp_stream_id stream_id, u32 ch_start_slot,
  2085. u32 ch_tot_slots, u32 pbn, int vcpi)
  2086. {
  2087. if (!dp_panel || stream_id > DP_STREAM_MAX) {
  2088. DP_ERR("invalid input. stream_id: %d\n", stream_id);
  2089. return -EINVAL;
  2090. }
  2091. dp_panel->vcpi = vcpi;
  2092. dp_panel->stream_id = stream_id;
  2093. dp_panel->channel_start_slot = ch_start_slot;
  2094. dp_panel->channel_total_slots = ch_tot_slots;
  2095. dp_panel->pbn = pbn;
  2096. return 0;
  2097. }
  2098. static int dp_panel_init_panel_info(struct dp_panel *dp_panel)
  2099. {
  2100. int rc = 0;
  2101. struct dp_panel_private *panel;
  2102. struct dp_panel_info *pinfo;
  2103. if (!dp_panel) {
  2104. DP_ERR("invalid input\n");
  2105. rc = -EINVAL;
  2106. goto end;
  2107. }
  2108. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2109. pinfo = &dp_panel->pinfo;
  2110. drm_dp_dpcd_writeb(panel->aux->drm_aux, DP_SET_POWER, DP_SET_POWER_D3);
  2111. /* 200us propagation time for the power down to take effect */
  2112. usleep_range(200, 205);
  2113. drm_dp_dpcd_writeb(panel->aux->drm_aux, DP_SET_POWER, DP_SET_POWER_D0);
  2114. /*
  2115. * According to the DP 1.1 specification, a "Sink Device must exit the
  2116. * power saving state within 1 ms" (Section 2.5.3.1, Table 5-52, "Sink
  2117. * Control Field" (register 0x600).
  2118. */
  2119. usleep_range(1000, 2000);
  2120. drm_dp_link_probe(panel->aux->drm_aux, &dp_panel->link_info);
  2121. end:
  2122. return rc;
  2123. }
  2124. static int dp_panel_deinit_panel_info(struct dp_panel *dp_panel, u32 flags)
  2125. {
  2126. int rc = 0;
  2127. struct dp_panel_private *panel;
  2128. struct drm_msm_ext_hdr_metadata *hdr_meta;
  2129. struct dp_sdp_header *dhdr_vsif_sdp;
  2130. struct sde_connector *sde_conn;
  2131. struct dp_sdp_header *shdr_if_sdp;
  2132. struct dp_catalog_vsc_sdp_colorimetry *vsc_colorimetry;
  2133. struct drm_connector *connector;
  2134. struct sde_connector_state *c_state;
  2135. if (!dp_panel) {
  2136. DP_ERR("invalid input\n");
  2137. return -EINVAL;
  2138. }
  2139. if (flags & DP_PANEL_SRC_INITIATED_POWER_DOWN) {
  2140. DP_DEBUG("retain states in src initiated power down request\n");
  2141. return 0;
  2142. }
  2143. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2144. hdr_meta = &panel->catalog->hdr_meta;
  2145. dhdr_vsif_sdp = &panel->catalog->dhdr_vsif_sdp;
  2146. shdr_if_sdp = &panel->catalog->shdr_if_sdp;
  2147. vsc_colorimetry = &panel->catalog->vsc_colorimetry;
  2148. if (!panel->custom_edid && dp_panel->edid_ctrl->edid)
  2149. sde_free_edid((void **)&dp_panel->edid_ctrl);
  2150. dp_panel_set_stream_info(dp_panel, DP_STREAM_MAX, 0, 0, 0, 0);
  2151. memset(&dp_panel->pinfo, 0, sizeof(dp_panel->pinfo));
  2152. memset(hdr_meta, 0, sizeof(struct drm_msm_ext_hdr_metadata));
  2153. memset(dhdr_vsif_sdp, 0, sizeof(struct dp_sdp_header));
  2154. memset(shdr_if_sdp, 0, sizeof(struct dp_sdp_header));
  2155. memset(vsc_colorimetry, 0,
  2156. sizeof(struct dp_catalog_vsc_sdp_colorimetry));
  2157. panel->panel_on = false;
  2158. connector = dp_panel->connector;
  2159. sde_conn = to_sde_connector(connector);
  2160. c_state = to_sde_connector_state(connector->state);
  2161. connector->hdr_eotf = 0;
  2162. connector->hdr_metadata_type_one = 0;
  2163. connector->hdr_max_luminance = 0;
  2164. connector->hdr_avg_luminance = 0;
  2165. connector->hdr_min_luminance = 0;
  2166. connector->hdr_supported = false;
  2167. connector->hdr_plus_app_ver = 0;
  2168. sde_conn->colorspace_updated = false;
  2169. memset(&c_state->hdr_meta, 0, sizeof(c_state->hdr_meta));
  2170. memset(&c_state->dyn_hdr_meta, 0, sizeof(c_state->dyn_hdr_meta));
  2171. return rc;
  2172. }
  2173. static u32 dp_panel_get_min_req_link_rate(struct dp_panel *dp_panel)
  2174. {
  2175. const u32 encoding_factx10 = 8;
  2176. u32 min_link_rate_khz = 0, lane_cnt;
  2177. struct dp_panel_info *pinfo;
  2178. if (!dp_panel) {
  2179. DP_ERR("invalid input\n");
  2180. goto end;
  2181. }
  2182. lane_cnt = dp_panel->link_info.num_lanes;
  2183. pinfo = &dp_panel->pinfo;
  2184. /* num_lanes * lane_count * 8 >= pclk * bpp * 10 */
  2185. min_link_rate_khz = pinfo->pixel_clk_khz /
  2186. (lane_cnt * encoding_factx10);
  2187. min_link_rate_khz *= pinfo->bpp;
  2188. DP_DEBUG("min lclk req=%d khz for pclk=%d khz, lanes=%d, bpp=%d\n",
  2189. min_link_rate_khz, pinfo->pixel_clk_khz, lane_cnt,
  2190. pinfo->bpp);
  2191. end:
  2192. return min_link_rate_khz;
  2193. }
  2194. static bool dp_panel_hdr_supported(struct dp_panel *dp_panel)
  2195. {
  2196. struct dp_panel_private *panel;
  2197. if (!dp_panel) {
  2198. DP_ERR("invalid input\n");
  2199. return false;
  2200. }
  2201. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2202. return panel->major >= 1 && panel->vsc_supported &&
  2203. (panel->minor >= 4 || panel->vscext_supported);
  2204. }
  2205. static u32 dp_panel_calc_dhdr_pkt_limit(struct dp_panel *dp_panel,
  2206. struct dp_dhdr_maxpkt_calc_input *input)
  2207. {
  2208. s64 mdpclk_fp = drm_fixp_from_fraction(input->mdp_clk, 1000000);
  2209. s64 lclk_fp = drm_fixp_from_fraction(input->lclk, 1000);
  2210. s64 pclk_fp = drm_fixp_from_fraction(input->pclk, 1000);
  2211. s64 nlanes_fp = drm_int2fixp(input->nlanes);
  2212. s64 target_sc = input->mst_target_sc;
  2213. s64 hactive_fp = drm_int2fixp(input->h_active);
  2214. const s64 i1_fp = DRM_FIXED_ONE;
  2215. const s64 i2_fp = drm_int2fixp(2);
  2216. const s64 i10_fp = drm_int2fixp(10);
  2217. const s64 i56_fp = drm_int2fixp(56);
  2218. const s64 i64_fp = drm_int2fixp(64);
  2219. s64 mst_bw_fp = i1_fp;
  2220. s64 fec_factor_fp = i1_fp;
  2221. s64 mst_bw64_fp, mst_bw64_ceil_fp, nlanes56_fp;
  2222. u32 f1, f2, f3, f4, f5, deploy_period, target_period;
  2223. s64 f3_f5_slot_fp;
  2224. u32 calc_pkt_limit;
  2225. const u32 max_pkt_limit = 64;
  2226. if (input->fec_en && input->mst_en)
  2227. fec_factor_fp = drm_fixp_from_fraction(64000, 65537);
  2228. if (input->mst_en)
  2229. mst_bw_fp = drm_fixp_div(target_sc, i64_fp);
  2230. f1 = drm_fixp2int_ceil(drm_fixp_div(drm_fixp_mul(i10_fp, lclk_fp),
  2231. mdpclk_fp));
  2232. f2 = drm_fixp2int_ceil(drm_fixp_div(drm_fixp_mul(i2_fp, lclk_fp),
  2233. mdpclk_fp)) + drm_fixp2int_ceil(drm_fixp_div(
  2234. drm_fixp_mul(i1_fp, lclk_fp), mdpclk_fp));
  2235. mst_bw64_fp = drm_fixp_mul(mst_bw_fp, i64_fp);
  2236. if (drm_fixp2int(mst_bw64_fp) == 0)
  2237. f3_f5_slot_fp = drm_fixp_div(i1_fp, drm_int2fixp(
  2238. drm_fixp2int_ceil(drm_fixp_div(
  2239. i1_fp, mst_bw64_fp))));
  2240. else
  2241. f3_f5_slot_fp = drm_int2fixp(drm_fixp2int(mst_bw_fp));
  2242. mst_bw64_ceil_fp = drm_int2fixp(drm_fixp2int_ceil(mst_bw64_fp));
  2243. f3 = drm_fixp2int(drm_fixp_mul(drm_int2fixp(drm_fixp2int(
  2244. drm_fixp_div(i2_fp, f3_f5_slot_fp)) + 1),
  2245. (i64_fp - mst_bw64_ceil_fp))) + 2;
  2246. if (!input->mst_en) {
  2247. f4 = 1 + drm_fixp2int(drm_fixp_div(drm_int2fixp(50),
  2248. nlanes_fp)) + drm_fixp2int(drm_fixp_div(
  2249. nlanes_fp, i2_fp));
  2250. f5 = 0;
  2251. } else {
  2252. f4 = 0;
  2253. nlanes56_fp = drm_fixp_div(i56_fp, nlanes_fp);
  2254. f5 = drm_fixp2int(drm_fixp_mul(drm_int2fixp(drm_fixp2int(
  2255. drm_fixp_div(i1_fp + nlanes56_fp,
  2256. f3_f5_slot_fp)) + 1), (i64_fp -
  2257. mst_bw64_ceil_fp + i1_fp + nlanes56_fp)));
  2258. }
  2259. deploy_period = f1 + f2 + f3 + f4 + f5 + 19;
  2260. target_period = drm_fixp2int(drm_fixp_mul(fec_factor_fp, drm_fixp_mul(
  2261. hactive_fp, drm_fixp_div(lclk_fp, pclk_fp))));
  2262. calc_pkt_limit = target_period / deploy_period;
  2263. DP_DEBUG("input: %d, %d, %d, %d, %d, 0x%llx, %d, %d\n",
  2264. input->mdp_clk, input->lclk, input->pclk, input->h_active,
  2265. input->nlanes, input->mst_target_sc, input->mst_en ? 1 : 0,
  2266. input->fec_en ? 1 : 0);
  2267. DP_DEBUG("factors: %d, %d, %d, %d, %d\n", f1, f2, f3, f4, f5);
  2268. DP_DEBUG("d_p: %d, t_p: %d, maxPkts: %d%s\n", deploy_period,
  2269. target_period, calc_pkt_limit, calc_pkt_limit > max_pkt_limit ?
  2270. " CAPPED" : "");
  2271. if (calc_pkt_limit > max_pkt_limit)
  2272. calc_pkt_limit = max_pkt_limit;
  2273. DP_DEBUG("packet limit per line = %d\n", calc_pkt_limit);
  2274. return calc_pkt_limit;
  2275. }
  2276. static void dp_panel_setup_colorimetry_sdp(struct dp_panel *dp_panel,
  2277. u32 cspace)
  2278. {
  2279. struct dp_panel_private *panel;
  2280. struct dp_catalog_vsc_sdp_colorimetry *hdr_colorimetry;
  2281. u8 bpc;
  2282. u32 colorimetry = 0;
  2283. u32 dynamic_range = 0;
  2284. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2285. hdr_colorimetry = &panel->catalog->vsc_colorimetry;
  2286. hdr_colorimetry->header.HB0 = 0x00;
  2287. hdr_colorimetry->header.HB1 = 0x07;
  2288. hdr_colorimetry->header.HB2 = 0x05;
  2289. hdr_colorimetry->header.HB3 = 0x13;
  2290. get_sdp_colorimetry_range(panel, cspace, &colorimetry,
  2291. &dynamic_range);
  2292. /* VSC SDP Payload for DB16 */
  2293. hdr_colorimetry->data[16] = (RGB << 4) | colorimetry;
  2294. /* VSC SDP Payload for DB17 */
  2295. hdr_colorimetry->data[17] = (dynamic_range << 7);
  2296. bpc = (dp_panel->pinfo.bpp / 3);
  2297. switch (bpc) {
  2298. default:
  2299. case 10:
  2300. hdr_colorimetry->data[17] |= BIT(1);
  2301. break;
  2302. case 8:
  2303. hdr_colorimetry->data[17] |= BIT(0);
  2304. break;
  2305. case 6:
  2306. hdr_colorimetry->data[17] |= 0;
  2307. break;
  2308. }
  2309. /* VSC SDP Payload for DB18 */
  2310. hdr_colorimetry->data[18] = GRAPHICS;
  2311. }
  2312. static void dp_panel_setup_hdr_if(struct dp_panel_private *panel)
  2313. {
  2314. struct dp_sdp_header *shdr_if;
  2315. shdr_if = &panel->catalog->shdr_if_sdp;
  2316. shdr_if->HB0 = 0x00;
  2317. shdr_if->HB1 = 0x87;
  2318. shdr_if->HB2 = 0x1D;
  2319. shdr_if->HB3 = 0x13 << 2;
  2320. }
  2321. static void dp_panel_setup_dhdr_vsif(struct dp_panel_private *panel)
  2322. {
  2323. struct dp_sdp_header *dhdr_vsif;
  2324. dhdr_vsif = &panel->catalog->dhdr_vsif_sdp;
  2325. dhdr_vsif->HB0 = 0x00;
  2326. dhdr_vsif->HB1 = 0x81;
  2327. dhdr_vsif->HB2 = 0x1D;
  2328. dhdr_vsif->HB3 = 0x13 << 2;
  2329. }
  2330. static void dp_panel_setup_misc_colorimetry(struct dp_panel *dp_panel,
  2331. u32 colorspace)
  2332. {
  2333. struct dp_panel_private *panel;
  2334. struct dp_catalog_panel *catalog;
  2335. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2336. catalog = panel->catalog;
  2337. catalog->misc_val &= ~0x1e;
  2338. catalog->misc_val |= (get_misc_colorimetry_val(panel,
  2339. colorspace) << 1);
  2340. }
  2341. static int dp_panel_set_colorspace(struct dp_panel *dp_panel,
  2342. u32 colorspace)
  2343. {
  2344. int rc = 0;
  2345. struct dp_panel_private *panel;
  2346. if (!dp_panel) {
  2347. pr_err("invalid input\n");
  2348. rc = -EINVAL;
  2349. goto end;
  2350. }
  2351. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2352. if (panel->vsc_supported)
  2353. dp_panel_setup_colorimetry_sdp(dp_panel,
  2354. colorspace);
  2355. else
  2356. dp_panel_setup_misc_colorimetry(dp_panel,
  2357. colorspace);
  2358. /*
  2359. * During the first frame update panel_on will be false and
  2360. * the colorspace will be cached in the connector's state which
  2361. * shall be used in the dp_panel_hw_cfg
  2362. */
  2363. if (panel->panel_on) {
  2364. DP_DEBUG("panel is ON programming colorspace\n");
  2365. rc = panel->catalog->set_colorspace(panel->catalog,
  2366. panel->vsc_supported);
  2367. }
  2368. end:
  2369. return rc;
  2370. }
  2371. static int dp_panel_setup_hdr(struct dp_panel *dp_panel,
  2372. struct drm_msm_ext_hdr_metadata *hdr_meta,
  2373. bool dhdr_update, u64 core_clk_rate, bool flush)
  2374. {
  2375. int rc = 0, max_pkts = 0;
  2376. struct dp_panel_private *panel;
  2377. struct dp_dhdr_maxpkt_calc_input input;
  2378. struct drm_msm_ext_hdr_metadata *catalog_hdr_meta;
  2379. if (!dp_panel) {
  2380. DP_ERR("invalid input\n");
  2381. rc = -EINVAL;
  2382. goto end;
  2383. }
  2384. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2385. catalog_hdr_meta = &panel->catalog->hdr_meta;
  2386. /* use cached meta data in case meta data not provided */
  2387. if (!hdr_meta) {
  2388. if (catalog_hdr_meta->hdr_state)
  2389. goto cached;
  2390. else
  2391. goto end;
  2392. }
  2393. panel->hdr_state = hdr_meta->hdr_state;
  2394. dp_panel_setup_hdr_if(panel);
  2395. if (panel->hdr_state) {
  2396. memcpy(catalog_hdr_meta, hdr_meta,
  2397. sizeof(struct drm_msm_ext_hdr_metadata));
  2398. } else {
  2399. memset(catalog_hdr_meta, 0,
  2400. sizeof(struct drm_msm_ext_hdr_metadata));
  2401. }
  2402. cached:
  2403. if (dhdr_update) {
  2404. dp_panel_setup_dhdr_vsif(panel);
  2405. input.mdp_clk = core_clk_rate;
  2406. input.lclk = dp_panel->link_info.rate;
  2407. input.nlanes = dp_panel->link_info.num_lanes;
  2408. input.pclk = dp_panel->pinfo.pixel_clk_khz;
  2409. input.h_active = dp_panel->pinfo.h_active;
  2410. input.mst_target_sc = dp_panel->mst_target_sc;
  2411. input.mst_en = dp_panel->mst_state;
  2412. input.fec_en = dp_panel->fec_en;
  2413. max_pkts = dp_panel_calc_dhdr_pkt_limit(dp_panel, &input);
  2414. }
  2415. if (panel->panel_on) {
  2416. panel->catalog->stream_id = dp_panel->stream_id;
  2417. panel->catalog->config_hdr(panel->catalog, panel->hdr_state,
  2418. max_pkts, flush);
  2419. if (dhdr_update)
  2420. panel->catalog->dhdr_flush(panel->catalog);
  2421. }
  2422. end:
  2423. return rc;
  2424. }
  2425. static int dp_panel_spd_config(struct dp_panel *dp_panel)
  2426. {
  2427. int rc = 0;
  2428. struct dp_panel_private *panel;
  2429. if (!dp_panel) {
  2430. DP_ERR("invalid input\n");
  2431. rc = -EINVAL;
  2432. goto end;
  2433. }
  2434. if (dp_panel->stream_id >= DP_STREAM_MAX) {
  2435. DP_ERR("invalid stream id:%d\n", dp_panel->stream_id);
  2436. return -EINVAL;
  2437. }
  2438. if (!dp_panel->spd_enabled) {
  2439. DP_DEBUG("SPD Infoframe not enabled\n");
  2440. goto end;
  2441. }
  2442. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2443. panel->catalog->spd_vendor_name = panel->spd_vendor_name;
  2444. panel->catalog->spd_product_description =
  2445. panel->spd_product_description;
  2446. panel->catalog->stream_id = dp_panel->stream_id;
  2447. panel->catalog->config_spd(panel->catalog);
  2448. end:
  2449. return rc;
  2450. }
  2451. static void dp_panel_config_ctrl(struct dp_panel *dp_panel)
  2452. {
  2453. u32 config = 0, tbd;
  2454. u8 *dpcd = dp_panel->dpcd;
  2455. struct dp_panel_private *panel;
  2456. struct dp_catalog_panel *catalog;
  2457. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2458. catalog = panel->catalog;
  2459. config |= (2 << 13); /* Default-> LSCLK DIV: 1/4 LCLK */
  2460. config |= (0 << 11); /* RGB */
  2461. tbd = panel->link->get_test_bits_depth(panel->link,
  2462. dp_panel->pinfo.bpp);
  2463. if (tbd == DP_TEST_BIT_DEPTH_UNKNOWN)
  2464. tbd = DP_TEST_BIT_DEPTH_8;
  2465. config |= tbd << 8;
  2466. /* Num of Lanes */
  2467. config |= ((panel->link->link_params.lane_count - 1) << 4);
  2468. if (drm_dp_enhanced_frame_cap(dpcd))
  2469. config |= 0x40;
  2470. config |= 0x04; /* progressive video */
  2471. config |= 0x03; /* sycn clock & static Mvid */
  2472. catalog->config_ctrl(catalog, config);
  2473. }
  2474. static void dp_panel_config_misc(struct dp_panel *dp_panel)
  2475. {
  2476. struct dp_panel_private *panel;
  2477. struct dp_catalog_panel *catalog;
  2478. struct drm_connector *connector;
  2479. u32 misc_val;
  2480. u32 tb, cc, colorspace;
  2481. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2482. catalog = panel->catalog;
  2483. connector = dp_panel->connector;
  2484. cc = 0;
  2485. tb = panel->link->get_test_bits_depth(panel->link, dp_panel->pinfo.bpp);
  2486. colorspace = connector->state->colorspace;
  2487. cc = (get_misc_colorimetry_val(panel, colorspace) << 1);
  2488. misc_val = cc;
  2489. misc_val |= (tb << 5);
  2490. misc_val |= BIT(0); /* Configure clock to synchronous mode */
  2491. /* if VSC is supported then set bit 6 of MISC1 */
  2492. if (panel->vsc_supported)
  2493. misc_val |= BIT(14);
  2494. catalog->misc_val = misc_val;
  2495. catalog->config_misc(catalog);
  2496. }
  2497. static void dp_panel_config_msa(struct dp_panel *dp_panel)
  2498. {
  2499. struct dp_panel_private *panel;
  2500. struct dp_catalog_panel *catalog;
  2501. u32 rate;
  2502. u32 stream_rate_khz;
  2503. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2504. catalog = panel->catalog;
  2505. catalog->widebus_en = dp_panel->widebus_en;
  2506. rate = drm_dp_bw_code_to_link_rate(panel->link->link_params.bw_code);
  2507. stream_rate_khz = dp_panel->pinfo.pixel_clk_khz;
  2508. catalog->config_msa(catalog, rate, stream_rate_khz);
  2509. }
  2510. static void dp_panel_resolution_info(struct dp_panel_private *panel)
  2511. {
  2512. struct dp_panel_info *pinfo = &panel->dp_panel.pinfo;
  2513. /*
  2514. * print resolution info as this is a result
  2515. * of user initiated action of cable connection
  2516. */
  2517. DP_INFO("DP RESOLUTION: active(back|front|width|low)\n");
  2518. DP_INFO("%d(%d|%d|%d|%d)x%d(%d|%d|%d|%d)@%dfps %dbpp %dKhz %dLR %dLn\n",
  2519. pinfo->h_active, pinfo->h_back_porch, pinfo->h_front_porch,
  2520. pinfo->h_sync_width, pinfo->h_active_low,
  2521. pinfo->v_active, pinfo->v_back_porch, pinfo->v_front_porch,
  2522. pinfo->v_sync_width, pinfo->v_active_low,
  2523. pinfo->refresh_rate, pinfo->bpp, pinfo->pixel_clk_khz,
  2524. panel->link->link_params.bw_code,
  2525. panel->link->link_params.lane_count);
  2526. }
  2527. static void dp_panel_config_sdp(struct dp_panel *dp_panel,
  2528. bool en)
  2529. {
  2530. struct dp_panel_private *panel;
  2531. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2532. panel->catalog->stream_id = dp_panel->stream_id;
  2533. panel->catalog->config_sdp(panel->catalog, en);
  2534. }
  2535. static int dp_panel_hw_cfg(struct dp_panel *dp_panel, bool enable)
  2536. {
  2537. struct dp_panel_private *panel;
  2538. struct drm_connector *connector;
  2539. if (!dp_panel) {
  2540. DP_ERR("invalid input\n");
  2541. return -EINVAL;
  2542. }
  2543. if (dp_panel->stream_id >= DP_STREAM_MAX) {
  2544. DP_ERR("invalid stream_id: %d\n", dp_panel->stream_id);
  2545. return -EINVAL;
  2546. }
  2547. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2548. panel->catalog->stream_id = dp_panel->stream_id;
  2549. connector = dp_panel->connector;
  2550. if (enable) {
  2551. dp_panel_config_ctrl(dp_panel);
  2552. dp_panel_config_misc(dp_panel);
  2553. dp_panel_config_msa(dp_panel);
  2554. if (panel->vsc_supported) {
  2555. dp_panel_setup_colorimetry_sdp(dp_panel,
  2556. connector->state->colorspace);
  2557. dp_panel_config_sdp(dp_panel, true);
  2558. }
  2559. dp_panel_config_dsc(dp_panel, enable);
  2560. dp_panel_config_tr_unit(dp_panel);
  2561. dp_panel_config_timing(dp_panel);
  2562. dp_panel_resolution_info(panel);
  2563. } else {
  2564. dp_panel_config_sdp(dp_panel, false);
  2565. }
  2566. panel->catalog->config_dto(panel->catalog, !enable);
  2567. return 0;
  2568. }
  2569. static int dp_panel_read_sink_sts(struct dp_panel *dp_panel, u8 *sts, u32 size)
  2570. {
  2571. int rlen, rc = 0;
  2572. struct dp_panel_private *panel;
  2573. if (!dp_panel || !sts || !size) {
  2574. DP_ERR("invalid input\n");
  2575. rc = -EINVAL;
  2576. return rc;
  2577. }
  2578. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2579. rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_SINK_COUNT_ESI,
  2580. sts, size);
  2581. if (rlen != size) {
  2582. DP_ERR("dpcd sink sts fail rlen:%d size:%d\n", rlen, size);
  2583. rc = -EINVAL;
  2584. return rc;
  2585. }
  2586. return 0;
  2587. }
  2588. static int dp_panel_update_edid(struct dp_panel *dp_panel, struct edid *edid)
  2589. {
  2590. int rc;
  2591. dp_panel->edid_ctrl->edid = edid;
  2592. sde_parse_edid(dp_panel->edid_ctrl);
  2593. rc = _sde_edid_update_modes(dp_panel->connector, dp_panel->edid_ctrl);
  2594. dp_panel->audio_supported = drm_detect_monitor_audio(edid);
  2595. return rc;
  2596. }
  2597. static bool dp_panel_read_mst_cap(struct dp_panel *dp_panel)
  2598. {
  2599. int rlen;
  2600. struct dp_panel_private *panel;
  2601. u8 dpcd;
  2602. bool mst_cap = false;
  2603. if (!dp_panel) {
  2604. DP_ERR("invalid input\n");
  2605. return 0;
  2606. }
  2607. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2608. rlen = drm_dp_dpcd_read(panel->aux->drm_aux, DP_MSTM_CAP,
  2609. &dpcd, 1);
  2610. if (rlen < 1) {
  2611. DP_ERR("dpcd mstm_cap read failed, rlen=%d\n", rlen);
  2612. goto end;
  2613. }
  2614. mst_cap = (dpcd & DP_MST_CAP) ? true : false;
  2615. end:
  2616. DP_DEBUG("dp mst-cap: %d\n", mst_cap);
  2617. return mst_cap;
  2618. }
  2619. static void dp_panel_convert_to_dp_mode(struct dp_panel *dp_panel,
  2620. const struct drm_display_mode *drm_mode,
  2621. struct dp_display_mode *dp_mode)
  2622. {
  2623. const u32 num_components = 3, default_bpp = 24;
  2624. struct msm_compression_info *comp_info;
  2625. bool dsc_cap = (dp_mode->capabilities & DP_PANEL_CAPS_DSC) ?
  2626. true : false;
  2627. dp_mode->timing.h_active = drm_mode->hdisplay;
  2628. dp_mode->timing.h_back_porch = drm_mode->htotal - drm_mode->hsync_end;
  2629. dp_mode->timing.h_sync_width = drm_mode->htotal -
  2630. (drm_mode->hsync_start + dp_mode->timing.h_back_porch);
  2631. dp_mode->timing.h_front_porch = drm_mode->hsync_start -
  2632. drm_mode->hdisplay;
  2633. dp_mode->timing.h_skew = drm_mode->hskew;
  2634. dp_mode->timing.v_active = drm_mode->vdisplay;
  2635. dp_mode->timing.v_back_porch = drm_mode->vtotal - drm_mode->vsync_end;
  2636. dp_mode->timing.v_sync_width = drm_mode->vtotal -
  2637. (drm_mode->vsync_start + dp_mode->timing.v_back_porch);
  2638. dp_mode->timing.v_front_porch = drm_mode->vsync_start -
  2639. drm_mode->vdisplay;
  2640. dp_mode->timing.refresh_rate = drm_mode->vrefresh;
  2641. dp_mode->timing.pixel_clk_khz = drm_mode->clock;
  2642. dp_mode->timing.v_active_low =
  2643. !!(drm_mode->flags & DRM_MODE_FLAG_NVSYNC);
  2644. dp_mode->timing.h_active_low =
  2645. !!(drm_mode->flags & DRM_MODE_FLAG_NHSYNC);
  2646. dp_mode->timing.bpp =
  2647. dp_panel->connector->display_info.bpc * num_components;
  2648. if (!dp_mode->timing.bpp)
  2649. dp_mode->timing.bpp = default_bpp;
  2650. dp_mode->timing.bpp = dp_panel_get_mode_bpp(dp_panel,
  2651. dp_mode->timing.bpp, dp_mode->timing.pixel_clk_khz);
  2652. dp_mode->timing.widebus_en = dp_panel->widebus_en;
  2653. dp_mode->timing.dsc_overhead_fp = 0;
  2654. if (dp_panel->dsc_en && dsc_cap) {
  2655. comp_info = &dp_mode->timing.comp_info;
  2656. if (dp_panel_dsc_prepare_basic_params(comp_info,
  2657. dp_mode, dp_panel)) {
  2658. DP_DEBUG("prepare DSC basic params failed\n");
  2659. return;
  2660. }
  2661. dp_panel_dsc_populate_static_params(&comp_info->dsc_info,
  2662. dp_panel);
  2663. dp_panel_dsc_pclk_param_calc(dp_panel,
  2664. &comp_info->dsc_info,
  2665. comp_info->comp_ratio,
  2666. dp_mode);
  2667. }
  2668. dp_mode->fec_overhead_fp = dp_panel->fec_overhead_fp;
  2669. }
  2670. static void dp_panel_update_pps(struct dp_panel *dp_panel, char *pps_cmd)
  2671. {
  2672. struct dp_catalog_panel *catalog;
  2673. struct dp_panel_private *panel;
  2674. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2675. catalog = panel->catalog;
  2676. catalog->stream_id = dp_panel->stream_id;
  2677. catalog->pps_flush(catalog);
  2678. }
  2679. struct dp_panel *dp_panel_get(struct dp_panel_in *in)
  2680. {
  2681. int rc = 0;
  2682. struct dp_panel_private *panel;
  2683. struct dp_panel *dp_panel;
  2684. struct sde_connector *sde_conn;
  2685. if (!in->dev || !in->catalog || !in->aux ||
  2686. !in->link || !in->connector) {
  2687. DP_ERR("invalid input\n");
  2688. rc = -EINVAL;
  2689. goto error;
  2690. }
  2691. panel = devm_kzalloc(in->dev, sizeof(*panel), GFP_KERNEL);
  2692. if (!panel) {
  2693. rc = -ENOMEM;
  2694. goto error;
  2695. }
  2696. panel->dev = in->dev;
  2697. panel->aux = in->aux;
  2698. panel->catalog = in->catalog;
  2699. panel->link = in->link;
  2700. panel->parser = in->parser;
  2701. dp_panel = &panel->dp_panel;
  2702. dp_panel->max_bw_code = DP_LINK_BW_8_1;
  2703. dp_panel->spd_enabled = true;
  2704. memcpy(panel->spd_vendor_name, vendor_name, (sizeof(u8) * 8));
  2705. memcpy(panel->spd_product_description, product_desc, (sizeof(u8) * 16));
  2706. dp_panel->connector = in->connector;
  2707. dp_panel->dsc_feature_enable = panel->parser->dsc_feature_enable;
  2708. dp_panel->fec_feature_enable = panel->parser->fec_feature_enable;
  2709. if (in->base_panel) {
  2710. memcpy(dp_panel->dpcd, in->base_panel->dpcd,
  2711. DP_RECEIVER_CAP_SIZE + 1);
  2712. memcpy(dp_panel->dsc_dpcd, in->base_panel->dsc_dpcd,
  2713. DP_RECEIVER_DSC_CAP_SIZE + 1);
  2714. memcpy(&dp_panel->link_info, &in->base_panel->link_info,
  2715. sizeof(dp_panel->link_info));
  2716. dp_panel->mst_state = in->base_panel->mst_state;
  2717. dp_panel->widebus_en = in->base_panel->widebus_en;
  2718. dp_panel->fec_en = in->base_panel->fec_en;
  2719. dp_panel->dsc_en = in->base_panel->dsc_en;
  2720. dp_panel->fec_overhead_fp = in->base_panel->fec_overhead_fp;
  2721. }
  2722. dp_panel->init = dp_panel_init_panel_info;
  2723. dp_panel->deinit = dp_panel_deinit_panel_info;
  2724. dp_panel->hw_cfg = dp_panel_hw_cfg;
  2725. dp_panel->read_sink_caps = dp_panel_read_sink_caps;
  2726. dp_panel->get_min_req_link_rate = dp_panel_get_min_req_link_rate;
  2727. dp_panel->get_mode_bpp = dp_panel_get_mode_bpp;
  2728. dp_panel->get_modes = dp_panel_get_modes;
  2729. dp_panel->handle_sink_request = dp_panel_handle_sink_request;
  2730. dp_panel->set_edid = dp_panel_set_edid;
  2731. dp_panel->set_dpcd = dp_panel_set_dpcd;
  2732. dp_panel->tpg_config = dp_panel_tpg_config;
  2733. dp_panel->spd_config = dp_panel_spd_config;
  2734. dp_panel->setup_hdr = dp_panel_setup_hdr;
  2735. dp_panel->set_colorspace = dp_panel_set_colorspace;
  2736. dp_panel->hdr_supported = dp_panel_hdr_supported;
  2737. dp_panel->set_stream_info = dp_panel_set_stream_info;
  2738. dp_panel->read_sink_status = dp_panel_read_sink_sts;
  2739. dp_panel->update_edid = dp_panel_update_edid;
  2740. dp_panel->read_mst_cap = dp_panel_read_mst_cap;
  2741. dp_panel->convert_to_dp_mode = dp_panel_convert_to_dp_mode;
  2742. dp_panel->update_pps = dp_panel_update_pps;
  2743. sde_conn = to_sde_connector(dp_panel->connector);
  2744. sde_conn->drv_panel = dp_panel;
  2745. dp_panel_edid_register(panel);
  2746. return dp_panel;
  2747. error:
  2748. return ERR_PTR(rc);
  2749. }
  2750. void dp_panel_put(struct dp_panel *dp_panel)
  2751. {
  2752. struct dp_panel_private *panel;
  2753. if (!dp_panel)
  2754. return;
  2755. panel = container_of(dp_panel, struct dp_panel_private, dp_panel);
  2756. dp_panel_edid_deregister(panel);
  2757. devm_kfree(panel->dev, panel);
  2758. }