dp_panel.c 101 KB

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