dp_panel.c 89 KB

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