dp_panel.c 88 KB

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