dp_panel.c 89 KB

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