dsi_panel.c 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/delay.h>
  6. #include <linux/slab.h>
  7. #include <linux/gpio.h>
  8. #include <linux/of_gpio.h>
  9. #include <linux/pwm.h>
  10. #include <video/mipi_display.h>
  11. #include "dsi_panel.h"
  12. #include "dsi_ctrl_hw.h"
  13. #include "dsi_parser.h"
  14. #include "sde_dbg.h"
  15. #include "sde_dsc_helper.h"
  16. #include "sde_vdc_helper.h"
  17. /**
  18. * topology is currently defined by a set of following 3 values:
  19. * 1. num of layer mixers
  20. * 2. num of compression encoders
  21. * 3. num of interfaces
  22. */
  23. #define TOPOLOGY_SET_LEN 3
  24. #define MAX_TOPOLOGY 5
  25. #define DSI_PANEL_DEFAULT_LABEL "Default dsi panel"
  26. #define DEFAULT_PANEL_JITTER_NUMERATOR 2
  27. #define DEFAULT_PANEL_JITTER_DENOMINATOR 1
  28. #define DEFAULT_PANEL_JITTER_ARRAY_SIZE 2
  29. #define MAX_PANEL_JITTER 10
  30. #define DEFAULT_PANEL_PREFILL_LINES 25
  31. #define HIGH_REFRESH_RATE_THRESHOLD_TIME_US 500
  32. #define MIN_PREFILL_LINES 40
  33. #define RSCC_MODE_THRESHOLD_TIME_US 40
  34. #define DCS_COMMAND_THRESHOLD_TIME_US 40
  35. static void dsi_dce_prepare_pps_header(char *buf, u32 pps_delay_ms)
  36. {
  37. char *bp;
  38. bp = buf;
  39. /* First 7 bytes are cmd header */
  40. *bp++ = 0x0A;
  41. *bp++ = 1;
  42. *bp++ = 0;
  43. *bp++ = 0;
  44. *bp++ = pps_delay_ms;
  45. *bp++ = 0;
  46. *bp++ = 128;
  47. }
  48. static int dsi_dsc_create_pps_buf_cmd(struct msm_display_dsc_info *dsc,
  49. char *buf, int pps_id, u32 size)
  50. {
  51. dsi_dce_prepare_pps_header(buf, dsc->pps_delay_ms);
  52. buf += DSI_CMD_PPS_HDR_SIZE;
  53. return sde_dsc_create_pps_buf_cmd(dsc, buf, pps_id,
  54. size);
  55. }
  56. static int dsi_vdc_create_pps_buf_cmd(struct msm_display_vdc_info *vdc,
  57. char *buf, int pps_id, u32 size)
  58. {
  59. dsi_dce_prepare_pps_header(buf, vdc->pps_delay_ms);
  60. buf += DSI_CMD_PPS_HDR_SIZE;
  61. return sde_vdc_create_pps_buf_cmd(vdc, buf, pps_id,
  62. size);
  63. }
  64. static int dsi_panel_vreg_get(struct dsi_panel *panel)
  65. {
  66. int rc = 0;
  67. int i;
  68. struct regulator *vreg = NULL;
  69. for (i = 0; i < panel->power_info.count; i++) {
  70. vreg = devm_regulator_get(panel->parent,
  71. panel->power_info.vregs[i].vreg_name);
  72. rc = PTR_ERR_OR_ZERO(vreg);
  73. if (rc) {
  74. DSI_ERR("failed to get %s regulator\n",
  75. panel->power_info.vregs[i].vreg_name);
  76. goto error_put;
  77. }
  78. panel->power_info.vregs[i].vreg = vreg;
  79. }
  80. return rc;
  81. error_put:
  82. for (i = i - 1; i >= 0; i--) {
  83. devm_regulator_put(panel->power_info.vregs[i].vreg);
  84. panel->power_info.vregs[i].vreg = NULL;
  85. }
  86. return rc;
  87. }
  88. static int dsi_panel_vreg_put(struct dsi_panel *panel)
  89. {
  90. int rc = 0;
  91. int i;
  92. for (i = panel->power_info.count - 1; i >= 0; i--)
  93. devm_regulator_put(panel->power_info.vregs[i].vreg);
  94. return rc;
  95. }
  96. static int dsi_panel_gpio_request(struct dsi_panel *panel)
  97. {
  98. int rc = 0;
  99. struct dsi_panel_reset_config *r_config = &panel->reset_config;
  100. if (gpio_is_valid(r_config->reset_gpio)) {
  101. rc = gpio_request(r_config->reset_gpio, "reset_gpio");
  102. if (rc) {
  103. DSI_ERR("request for reset_gpio failed, rc=%d\n", rc);
  104. goto error;
  105. }
  106. }
  107. if (gpio_is_valid(r_config->disp_en_gpio)) {
  108. rc = gpio_request(r_config->disp_en_gpio, "disp_en_gpio");
  109. if (rc) {
  110. DSI_ERR("request for disp_en_gpio failed, rc=%d\n", rc);
  111. goto error_release_reset;
  112. }
  113. }
  114. if (gpio_is_valid(panel->bl_config.en_gpio)) {
  115. rc = gpio_request(panel->bl_config.en_gpio, "bklt_en_gpio");
  116. if (rc) {
  117. DSI_ERR("request for bklt_en_gpio failed, rc=%d\n", rc);
  118. goto error_release_disp_en;
  119. }
  120. }
  121. if (gpio_is_valid(r_config->lcd_mode_sel_gpio)) {
  122. rc = gpio_request(r_config->lcd_mode_sel_gpio, "mode_gpio");
  123. if (rc) {
  124. DSI_ERR("request for mode_gpio failed, rc=%d\n", rc);
  125. goto error_release_mode_sel;
  126. }
  127. }
  128. if (gpio_is_valid(panel->panel_test_gpio)) {
  129. rc = gpio_request(panel->panel_test_gpio, "panel_test_gpio");
  130. if (rc) {
  131. DSI_WARN("request for panel_test_gpio failed, rc=%d\n",
  132. rc);
  133. panel->panel_test_gpio = -1;
  134. rc = 0;
  135. }
  136. }
  137. goto error;
  138. error_release_mode_sel:
  139. if (gpio_is_valid(panel->bl_config.en_gpio))
  140. gpio_free(panel->bl_config.en_gpio);
  141. error_release_disp_en:
  142. if (gpio_is_valid(r_config->disp_en_gpio))
  143. gpio_free(r_config->disp_en_gpio);
  144. error_release_reset:
  145. if (gpio_is_valid(r_config->reset_gpio))
  146. gpio_free(r_config->reset_gpio);
  147. error:
  148. return rc;
  149. }
  150. static int dsi_panel_gpio_release(struct dsi_panel *panel)
  151. {
  152. int rc = 0;
  153. struct dsi_panel_reset_config *r_config = &panel->reset_config;
  154. if (gpio_is_valid(r_config->reset_gpio))
  155. gpio_free(r_config->reset_gpio);
  156. if (gpio_is_valid(r_config->disp_en_gpio))
  157. gpio_free(r_config->disp_en_gpio);
  158. if (gpio_is_valid(panel->bl_config.en_gpio))
  159. gpio_free(panel->bl_config.en_gpio);
  160. if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio))
  161. gpio_free(panel->reset_config.lcd_mode_sel_gpio);
  162. if (gpio_is_valid(panel->panel_test_gpio))
  163. gpio_free(panel->panel_test_gpio);
  164. return rc;
  165. }
  166. static int dsi_panel_trigger_esd_attack_sub(int reset_gpio)
  167. {
  168. if (!gpio_is_valid(reset_gpio)) {
  169. DSI_INFO("failed to pull down the reset gpio\n");
  170. return -EINVAL;
  171. }
  172. gpio_set_value(reset_gpio, 0);
  173. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1);
  174. DSI_INFO("GPIO pulled low to simulate ESD\n");
  175. return 0;
  176. }
  177. static int dsi_panel_vm_trigger_esd_attack(struct dsi_panel *panel)
  178. {
  179. struct dsi_parser_utils *utils = &panel->utils;
  180. int reset_gpio;
  181. int rc = 0;
  182. reset_gpio = utils->get_named_gpio(utils->data,
  183. "qcom,platform-reset-gpio", 0);
  184. if (!gpio_is_valid(reset_gpio)) {
  185. DSI_ERR("[%s] reset gpio not provided\n", panel->name);
  186. return -EINVAL;
  187. }
  188. rc = gpio_request(reset_gpio, "reset_gpio");
  189. if (rc) {
  190. DSI_ERR("request for reset_gpio failed, rc=%d\n", rc);
  191. return rc;
  192. }
  193. rc = dsi_panel_trigger_esd_attack_sub(reset_gpio);
  194. gpio_free(reset_gpio);
  195. return rc;
  196. }
  197. static int dsi_panel_trigger_esd_attack(struct dsi_panel *panel)
  198. {
  199. struct dsi_panel_reset_config *r_config;
  200. if (!panel) {
  201. DSI_ERR("Invalid panel param\n");
  202. return -EINVAL;
  203. }
  204. r_config = &panel->reset_config;
  205. if (!r_config) {
  206. DSI_ERR("Invalid panel reset configuration\n");
  207. return -EINVAL;
  208. }
  209. return dsi_panel_trigger_esd_attack_sub(r_config->reset_gpio);
  210. }
  211. static int dsi_panel_reset(struct dsi_panel *panel)
  212. {
  213. int rc = 0;
  214. struct dsi_panel_reset_config *r_config = &panel->reset_config;
  215. int i;
  216. if (!gpio_is_valid(r_config->reset_gpio))
  217. goto skip_reset_gpio;
  218. if (gpio_is_valid(panel->reset_config.disp_en_gpio)) {
  219. rc = gpio_direction_output(panel->reset_config.disp_en_gpio, 1);
  220. if (rc) {
  221. DSI_ERR("unable to set dir for disp gpio rc=%d\n", rc);
  222. goto exit;
  223. }
  224. }
  225. if (r_config->count) {
  226. rc = gpio_direction_output(r_config->reset_gpio,
  227. r_config->sequence[0].level);
  228. if (rc) {
  229. DSI_ERR("unable to set dir for rst gpio rc=%d\n", rc);
  230. goto exit;
  231. }
  232. }
  233. for (i = 0; i < r_config->count; i++) {
  234. gpio_set_value(r_config->reset_gpio,
  235. r_config->sequence[i].level);
  236. if (r_config->sequence[i].sleep_ms)
  237. usleep_range(r_config->sequence[i].sleep_ms * 1000,
  238. (r_config->sequence[i].sleep_ms * 1000) + 100);
  239. }
  240. skip_reset_gpio:
  241. if (gpio_is_valid(panel->bl_config.en_gpio)) {
  242. rc = gpio_direction_output(panel->bl_config.en_gpio, 1);
  243. if (rc)
  244. DSI_ERR("unable to set dir for bklt gpio rc=%d\n", rc);
  245. }
  246. if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio)) {
  247. bool out = true;
  248. if ((panel->reset_config.mode_sel_state == MODE_SEL_DUAL_PORT)
  249. || (panel->reset_config.mode_sel_state
  250. == MODE_GPIO_LOW))
  251. out = false;
  252. else if ((panel->reset_config.mode_sel_state
  253. == MODE_SEL_SINGLE_PORT) ||
  254. (panel->reset_config.mode_sel_state
  255. == MODE_GPIO_HIGH))
  256. out = true;
  257. rc = gpio_direction_output(
  258. panel->reset_config.lcd_mode_sel_gpio, out);
  259. if (rc)
  260. DSI_ERR("unable to set dir for mode gpio rc=%d\n", rc);
  261. }
  262. if (gpio_is_valid(panel->panel_test_gpio)) {
  263. rc = gpio_direction_input(panel->panel_test_gpio);
  264. if (rc)
  265. DSI_WARN("unable to set dir for panel test gpio rc=%d\n",
  266. rc);
  267. }
  268. exit:
  269. return rc;
  270. }
  271. static int dsi_panel_set_pinctrl_state(struct dsi_panel *panel, bool enable)
  272. {
  273. int rc = 0;
  274. struct pinctrl_state *state;
  275. if (panel->host_config.ext_bridge_mode)
  276. return 0;
  277. if (!panel->pinctrl.pinctrl)
  278. return 0;
  279. if (enable)
  280. state = panel->pinctrl.active;
  281. else
  282. state = panel->pinctrl.suspend;
  283. rc = pinctrl_select_state(panel->pinctrl.pinctrl, state);
  284. if (rc)
  285. DSI_ERR("[%s] failed to set pin state, rc=%d\n",
  286. panel->name, rc);
  287. return rc;
  288. }
  289. static int dsi_panel_power_on(struct dsi_panel *panel)
  290. {
  291. int rc = 0;
  292. rc = dsi_pwr_enable_regulator(&panel->power_info, true);
  293. if (rc) {
  294. DSI_ERR("[%s] failed to enable vregs, rc=%d\n",
  295. panel->name, rc);
  296. goto exit;
  297. }
  298. rc = dsi_panel_set_pinctrl_state(panel, true);
  299. if (rc) {
  300. DSI_ERR("[%s] failed to set pinctrl, rc=%d\n", panel->name, rc);
  301. goto error_disable_vregs;
  302. }
  303. rc = dsi_panel_reset(panel);
  304. if (rc) {
  305. DSI_ERR("[%s] failed to reset panel, rc=%d\n", panel->name, rc);
  306. goto error_disable_gpio;
  307. }
  308. goto exit;
  309. error_disable_gpio:
  310. if (gpio_is_valid(panel->reset_config.disp_en_gpio))
  311. gpio_set_value(panel->reset_config.disp_en_gpio, 0);
  312. if (gpio_is_valid(panel->bl_config.en_gpio))
  313. gpio_set_value(panel->bl_config.en_gpio, 0);
  314. (void)dsi_panel_set_pinctrl_state(panel, false);
  315. error_disable_vregs:
  316. (void)dsi_pwr_enable_regulator(&panel->power_info, false);
  317. exit:
  318. return rc;
  319. }
  320. static int dsi_panel_power_off(struct dsi_panel *panel)
  321. {
  322. int rc = 0;
  323. if (gpio_is_valid(panel->reset_config.disp_en_gpio))
  324. gpio_set_value(panel->reset_config.disp_en_gpio, 0);
  325. if (gpio_is_valid(panel->reset_config.reset_gpio) &&
  326. !panel->reset_gpio_always_on)
  327. gpio_set_value(panel->reset_config.reset_gpio, 0);
  328. if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio))
  329. gpio_set_value(panel->reset_config.lcd_mode_sel_gpio, 0);
  330. if (gpio_is_valid(panel->panel_test_gpio)) {
  331. rc = gpio_direction_input(panel->panel_test_gpio);
  332. if (rc)
  333. DSI_WARN("set dir for panel test gpio failed rc=%d\n",
  334. rc);
  335. }
  336. rc = dsi_panel_set_pinctrl_state(panel, false);
  337. if (rc) {
  338. DSI_ERR("[%s] failed set pinctrl state, rc=%d\n", panel->name,
  339. rc);
  340. }
  341. rc = dsi_pwr_enable_regulator(&panel->power_info, false);
  342. if (rc)
  343. DSI_ERR("[%s] failed to enable vregs, rc=%d\n",
  344. panel->name, rc);
  345. return rc;
  346. }
  347. static int dsi_panel_tx_cmd_set(struct dsi_panel *panel,
  348. enum dsi_cmd_set_type type)
  349. {
  350. int rc = 0, i = 0;
  351. ssize_t len;
  352. struct dsi_cmd_desc *cmds;
  353. u32 count;
  354. enum dsi_cmd_set_state state;
  355. struct dsi_display_mode *mode;
  356. if (!panel || !panel->cur_mode)
  357. return -EINVAL;
  358. mode = panel->cur_mode;
  359. cmds = mode->priv_info->cmd_sets[type].cmds;
  360. count = mode->priv_info->cmd_sets[type].count;
  361. state = mode->priv_info->cmd_sets[type].state;
  362. SDE_EVT32(type, state, count);
  363. if (count == 0) {
  364. DSI_DEBUG("[%s] No commands to be sent for state(%d)\n",
  365. panel->name, type);
  366. goto error;
  367. }
  368. cmds->ctrl_flags = 0;
  369. for (i = 0; i < count; i++) {
  370. if (state == DSI_CMD_SET_STATE_LP)
  371. cmds->msg.flags |= MIPI_DSI_MSG_USE_LPM;
  372. if (type == DSI_CMD_SET_VID_SWITCH_OUT)
  373. cmds->msg.flags |= MIPI_DSI_MSG_ASYNC_OVERRIDE;
  374. len = dsi_host_transfer_sub(panel->host, cmds);
  375. if (len < 0) {
  376. rc = len;
  377. DSI_ERR("failed to set cmds(%d), rc=%d\n", type, rc);
  378. goto error;
  379. }
  380. if (cmds->post_wait_ms)
  381. usleep_range(cmds->post_wait_ms*1000,
  382. ((cmds->post_wait_ms*1000)+10));
  383. cmds++;
  384. }
  385. error:
  386. return rc;
  387. }
  388. static int dsi_panel_pinctrl_deinit(struct dsi_panel *panel)
  389. {
  390. int rc = 0;
  391. if (panel->host_config.ext_bridge_mode)
  392. return 0;
  393. devm_pinctrl_put(panel->pinctrl.pinctrl);
  394. return rc;
  395. }
  396. static int dsi_panel_pinctrl_init(struct dsi_panel *panel)
  397. {
  398. int rc = 0;
  399. if (panel->host_config.ext_bridge_mode)
  400. return 0;
  401. /* TODO: pinctrl is defined in dsi dt node */
  402. panel->pinctrl.pinctrl = devm_pinctrl_get(panel->parent);
  403. if (IS_ERR_OR_NULL(panel->pinctrl.pinctrl)) {
  404. rc = PTR_ERR(panel->pinctrl.pinctrl);
  405. DSI_ERR("failed to get pinctrl, rc=%d\n", rc);
  406. goto error;
  407. }
  408. panel->pinctrl.active = pinctrl_lookup_state(panel->pinctrl.pinctrl,
  409. "panel_active");
  410. if (IS_ERR_OR_NULL(panel->pinctrl.active)) {
  411. rc = PTR_ERR(panel->pinctrl.active);
  412. DSI_ERR("failed to get pinctrl active state, rc=%d\n", rc);
  413. goto error;
  414. }
  415. panel->pinctrl.suspend =
  416. pinctrl_lookup_state(panel->pinctrl.pinctrl, "panel_suspend");
  417. if (IS_ERR_OR_NULL(panel->pinctrl.suspend)) {
  418. rc = PTR_ERR(panel->pinctrl.suspend);
  419. DSI_ERR("failed to get pinctrl suspend state, rc=%d\n", rc);
  420. goto error;
  421. }
  422. panel->pinctrl.pwm_pin =
  423. pinctrl_lookup_state(panel->pinctrl.pinctrl, "pwm_pin");
  424. if (IS_ERR_OR_NULL(panel->pinctrl.pwm_pin)) {
  425. panel->pinctrl.pwm_pin = NULL;
  426. DSI_DEBUG("failed to get pinctrl pwm_pin");
  427. }
  428. error:
  429. return rc;
  430. }
  431. static int dsi_panel_wled_register(struct dsi_panel *panel,
  432. struct dsi_backlight_config *bl)
  433. {
  434. struct backlight_device *bd;
  435. bd = backlight_device_get_by_type(BACKLIGHT_RAW);
  436. if (!bd) {
  437. DSI_ERR("[%s] fail raw backlight register rc=%d\n",
  438. panel->name, -EPROBE_DEFER);
  439. return -EPROBE_DEFER;
  440. }
  441. bl->raw_bd = bd;
  442. return 0;
  443. }
  444. static int dsi_panel_update_backlight(struct dsi_panel *panel,
  445. u32 bl_lvl)
  446. {
  447. int rc = 0;
  448. unsigned long mode_flags = 0;
  449. struct mipi_dsi_device *dsi = NULL;
  450. if (!panel || (bl_lvl > 0xffff)) {
  451. DSI_ERR("invalid params\n");
  452. return -EINVAL;
  453. }
  454. dsi = &panel->mipi_device;
  455. if (unlikely(panel->bl_config.lp_mode)) {
  456. mode_flags = dsi->mode_flags;
  457. dsi->mode_flags |= MIPI_DSI_MODE_LPM;
  458. }
  459. if (panel->bl_config.bl_inverted_dbv)
  460. bl_lvl = (((bl_lvl & 0xff) << 8) | (bl_lvl >> 8));
  461. rc = mipi_dsi_dcs_set_display_brightness(dsi, bl_lvl);
  462. if (rc < 0)
  463. DSI_ERR("failed to update dcs backlight:%d\n", bl_lvl);
  464. if (unlikely(panel->bl_config.lp_mode))
  465. dsi->mode_flags = mode_flags;
  466. return rc;
  467. }
  468. static int dsi_panel_update_pwm_backlight(struct dsi_panel *panel,
  469. u32 bl_lvl)
  470. {
  471. int rc = 0;
  472. u32 duty = 0;
  473. u32 period_ns = 0;
  474. struct dsi_backlight_config *bl;
  475. if (!panel) {
  476. DSI_ERR("Invalid Params\n");
  477. return -EINVAL;
  478. }
  479. bl = &panel->bl_config;
  480. if (!bl->pwm_bl) {
  481. DSI_ERR("pwm device not found\n");
  482. return -EINVAL;
  483. }
  484. period_ns = bl->pwm_period_usecs * NSEC_PER_USEC;
  485. duty = bl_lvl * period_ns;
  486. duty /= bl->bl_max_level;
  487. rc = pwm_config(bl->pwm_bl, duty, period_ns);
  488. if (rc) {
  489. DSI_ERR("[%s] failed to change pwm config, rc=%d\n", panel->name,
  490. rc);
  491. goto error;
  492. }
  493. if (bl_lvl == 0 && bl->pwm_enabled) {
  494. pwm_disable(bl->pwm_bl);
  495. bl->pwm_enabled = false;
  496. return 0;
  497. }
  498. if (bl_lvl != 0 && !bl->pwm_enabled) {
  499. rc = pwm_enable(bl->pwm_bl);
  500. if (rc) {
  501. DSI_ERR("[%s] failed to enable pwm, rc=%d\n", panel->name,
  502. rc);
  503. goto error;
  504. }
  505. bl->pwm_enabled = true;
  506. }
  507. error:
  508. return rc;
  509. }
  510. int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl)
  511. {
  512. int rc = 0;
  513. struct dsi_backlight_config *bl = &panel->bl_config;
  514. if (panel->host_config.ext_bridge_mode)
  515. return 0;
  516. DSI_DEBUG("backlight type:%d lvl:%d\n", bl->type, bl_lvl);
  517. switch (bl->type) {
  518. case DSI_BACKLIGHT_WLED:
  519. rc = backlight_device_set_brightness(bl->raw_bd, bl_lvl);
  520. break;
  521. case DSI_BACKLIGHT_DCS:
  522. rc = dsi_panel_update_backlight(panel, bl_lvl);
  523. break;
  524. case DSI_BACKLIGHT_EXTERNAL:
  525. break;
  526. case DSI_BACKLIGHT_PWM:
  527. rc = dsi_panel_update_pwm_backlight(panel, bl_lvl);
  528. break;
  529. default:
  530. DSI_ERR("Backlight type(%d) not supported\n", bl->type);
  531. rc = -ENOTSUPP;
  532. }
  533. return rc;
  534. }
  535. static u32 dsi_panel_get_brightness(struct dsi_backlight_config *bl)
  536. {
  537. u32 cur_bl_level;
  538. struct backlight_device *bd = bl->raw_bd;
  539. /* default the brightness level to 50% */
  540. cur_bl_level = bl->bl_max_level >> 1;
  541. switch (bl->type) {
  542. case DSI_BACKLIGHT_WLED:
  543. /* Try to query the backlight level from the backlight device */
  544. if (bd->ops && bd->ops->get_brightness)
  545. cur_bl_level = bd->ops->get_brightness(bd);
  546. break;
  547. case DSI_BACKLIGHT_DCS:
  548. case DSI_BACKLIGHT_EXTERNAL:
  549. case DSI_BACKLIGHT_PWM:
  550. default:
  551. /*
  552. * Ideally, we should read the backlight level from the
  553. * panel. For now, just set it default value.
  554. */
  555. break;
  556. }
  557. DSI_DEBUG("cur_bl_level=%d\n", cur_bl_level);
  558. return cur_bl_level;
  559. }
  560. void dsi_panel_bl_handoff(struct dsi_panel *panel)
  561. {
  562. struct dsi_backlight_config *bl = &panel->bl_config;
  563. bl->bl_level = dsi_panel_get_brightness(bl);
  564. }
  565. static int dsi_panel_pwm_register(struct dsi_panel *panel)
  566. {
  567. int rc = 0;
  568. struct dsi_backlight_config *bl = &panel->bl_config;
  569. bl->pwm_bl = devm_of_pwm_get(panel->parent, panel->panel_of_node, NULL);
  570. if (IS_ERR_OR_NULL(bl->pwm_bl)) {
  571. rc = PTR_ERR(bl->pwm_bl);
  572. DSI_ERR("[%s] failed to request pwm, rc=%d\n", panel->name,
  573. rc);
  574. return rc;
  575. }
  576. if (panel->pinctrl.pwm_pin) {
  577. rc = pinctrl_select_state(panel->pinctrl.pinctrl,
  578. panel->pinctrl.pwm_pin);
  579. if (rc)
  580. DSI_ERR("[%s] failed to set pwm pinctrl, rc=%d\n",
  581. panel->name, rc);
  582. }
  583. return 0;
  584. }
  585. static int dsi_panel_bl_register(struct dsi_panel *panel)
  586. {
  587. int rc = 0;
  588. struct dsi_backlight_config *bl = &panel->bl_config;
  589. if (panel->host_config.ext_bridge_mode)
  590. return 0;
  591. switch (bl->type) {
  592. case DSI_BACKLIGHT_WLED:
  593. rc = dsi_panel_wled_register(panel, bl);
  594. break;
  595. case DSI_BACKLIGHT_DCS:
  596. break;
  597. case DSI_BACKLIGHT_EXTERNAL:
  598. break;
  599. case DSI_BACKLIGHT_PWM:
  600. rc = dsi_panel_pwm_register(panel);
  601. break;
  602. default:
  603. DSI_ERR("Backlight type(%d) not supported\n", bl->type);
  604. rc = -ENOTSUPP;
  605. goto error;
  606. }
  607. error:
  608. return rc;
  609. }
  610. static void dsi_panel_pwm_unregister(struct dsi_panel *panel)
  611. {
  612. struct dsi_backlight_config *bl = &panel->bl_config;
  613. devm_pwm_put(panel->parent, bl->pwm_bl);
  614. }
  615. static int dsi_panel_bl_unregister(struct dsi_panel *panel)
  616. {
  617. int rc = 0;
  618. struct dsi_backlight_config *bl = &panel->bl_config;
  619. if (panel->host_config.ext_bridge_mode)
  620. return 0;
  621. switch (bl->type) {
  622. case DSI_BACKLIGHT_WLED:
  623. break;
  624. case DSI_BACKLIGHT_DCS:
  625. break;
  626. case DSI_BACKLIGHT_EXTERNAL:
  627. break;
  628. case DSI_BACKLIGHT_PWM:
  629. dsi_panel_pwm_unregister(panel);
  630. break;
  631. default:
  632. DSI_ERR("Backlight type(%d) not supported\n", bl->type);
  633. rc = -ENOTSUPP;
  634. goto error;
  635. }
  636. error:
  637. return rc;
  638. }
  639. static int dsi_panel_parse_timing(struct dsi_mode_info *mode,
  640. struct dsi_parser_utils *utils)
  641. {
  642. int rc = 0;
  643. u64 tmp64 = 0;
  644. struct dsi_display_mode *display_mode;
  645. struct dsi_display_mode_priv_info *priv_info;
  646. display_mode = container_of(mode, struct dsi_display_mode, timing);
  647. priv_info = display_mode->priv_info;
  648. rc = utils->read_u64(utils->data,
  649. "qcom,mdss-dsi-panel-clockrate", &tmp64);
  650. if (rc == -EOVERFLOW) {
  651. tmp64 = 0;
  652. rc = utils->read_u32(utils->data,
  653. "qcom,mdss-dsi-panel-clockrate", (u32 *)&tmp64);
  654. }
  655. mode->clk_rate_hz = !rc ? tmp64 : 0;
  656. display_mode->priv_info->clk_rate_hz = mode->clk_rate_hz;
  657. mode->pclk_scale.numer = 1;
  658. mode->pclk_scale.denom = 1;
  659. display_mode->priv_info->pclk_scale = mode->pclk_scale;
  660. rc = utils->read_u32(utils->data, "qcom,mdss-mdp-transfer-time-us",
  661. &mode->mdp_transfer_time_us);
  662. if (!rc)
  663. display_mode->priv_info->mdp_transfer_time_us =
  664. mode->mdp_transfer_time_us;
  665. else
  666. display_mode->priv_info->mdp_transfer_time_us = 0;
  667. priv_info->disable_rsc_solver = utils->read_bool(utils->data, "qcom,disable-rsc-solver");
  668. rc = utils->read_u32(utils->data,
  669. "qcom,mdss-dsi-panel-framerate",
  670. &mode->refresh_rate);
  671. if (rc) {
  672. DSI_ERR("failed to read qcom,mdss-dsi-panel-framerate, rc=%d\n",
  673. rc);
  674. goto error;
  675. }
  676. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-panel-width",
  677. &mode->h_active);
  678. if (rc) {
  679. DSI_ERR("failed to read qcom,mdss-dsi-panel-width, rc=%d\n",
  680. rc);
  681. goto error;
  682. }
  683. rc = utils->read_u32(utils->data,
  684. "qcom,mdss-dsi-h-front-porch",
  685. &mode->h_front_porch);
  686. if (rc) {
  687. DSI_ERR("failed to read qcom,mdss-dsi-h-front-porch, rc=%d\n",
  688. rc);
  689. goto error;
  690. }
  691. rc = utils->read_u32(utils->data,
  692. "qcom,mdss-dsi-h-back-porch",
  693. &mode->h_back_porch);
  694. if (rc) {
  695. DSI_ERR("failed to read qcom,mdss-dsi-h-back-porch, rc=%d\n",
  696. rc);
  697. goto error;
  698. }
  699. rc = utils->read_u32(utils->data,
  700. "qcom,mdss-dsi-h-pulse-width",
  701. &mode->h_sync_width);
  702. if (rc) {
  703. DSI_ERR("failed to read qcom,mdss-dsi-h-pulse-width, rc=%d\n",
  704. rc);
  705. goto error;
  706. }
  707. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-h-sync-skew",
  708. &mode->h_skew);
  709. if (rc)
  710. DSI_DEBUG("qcom,mdss-dsi-h-sync-skew is not defined, rc=%d\n",
  711. rc);
  712. DSI_DEBUG("panel horz active:%d front_portch:%d back_porch:%d sync_skew:%d\n",
  713. mode->h_active, mode->h_front_porch, mode->h_back_porch,
  714. mode->h_sync_width);
  715. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-panel-height",
  716. &mode->v_active);
  717. if (rc) {
  718. DSI_ERR("failed to read qcom,mdss-dsi-panel-height, rc=%d\n",
  719. rc);
  720. goto error;
  721. }
  722. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-v-back-porch",
  723. &mode->v_back_porch);
  724. if (rc) {
  725. DSI_ERR("failed to read qcom,mdss-dsi-v-back-porch, rc=%d\n",
  726. rc);
  727. goto error;
  728. }
  729. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-v-front-porch",
  730. &mode->v_front_porch);
  731. if (rc) {
  732. DSI_ERR("failed to read qcom,mdss-dsi-v-back-porch, rc=%d\n",
  733. rc);
  734. goto error;
  735. }
  736. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-v-pulse-width",
  737. &mode->v_sync_width);
  738. if (rc) {
  739. DSI_ERR("failed to read qcom,mdss-dsi-v-pulse-width, rc=%d\n",
  740. rc);
  741. goto error;
  742. }
  743. rc = utils->read_u32(utils->data, "qcom,qsync-mode-min-refresh-rate", &mode->qsync_min_fps);
  744. if (rc) {
  745. DSI_DEBUG("qsync min fps not defined in timing node\n");
  746. rc = 0;
  747. }
  748. DSI_DEBUG("panel vert active:%d front_portch:%d back_porch:%d pulse_width:%d\n",
  749. mode->v_active, mode->v_front_porch, mode->v_back_porch,
  750. mode->v_sync_width);
  751. error:
  752. return rc;
  753. }
  754. static int dsi_panel_parse_pixel_format(struct dsi_host_common_cfg *host,
  755. struct dsi_parser_utils *utils,
  756. const char *name)
  757. {
  758. int rc = 0;
  759. u32 bpp = 0;
  760. enum dsi_pixel_format fmt;
  761. const char *packing;
  762. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-bpp", &bpp);
  763. if (rc) {
  764. DSI_ERR("[%s] failed to read qcom,mdss-dsi-bpp, rc=%d\n",
  765. name, rc);
  766. return rc;
  767. }
  768. host->bpp = bpp;
  769. switch (bpp) {
  770. case 3:
  771. fmt = DSI_PIXEL_FORMAT_RGB111;
  772. break;
  773. case 8:
  774. fmt = DSI_PIXEL_FORMAT_RGB332;
  775. break;
  776. case 12:
  777. fmt = DSI_PIXEL_FORMAT_RGB444;
  778. break;
  779. case 16:
  780. fmt = DSI_PIXEL_FORMAT_RGB565;
  781. break;
  782. case 18:
  783. fmt = DSI_PIXEL_FORMAT_RGB666;
  784. break;
  785. case 24:
  786. default:
  787. fmt = DSI_PIXEL_FORMAT_RGB888;
  788. break;
  789. }
  790. if (fmt == DSI_PIXEL_FORMAT_RGB666) {
  791. packing = utils->get_property(utils->data,
  792. "qcom,mdss-dsi-pixel-packing",
  793. NULL);
  794. if (packing && !strcmp(packing, "loose"))
  795. fmt = DSI_PIXEL_FORMAT_RGB666_LOOSE;
  796. }
  797. host->dst_format = fmt;
  798. return rc;
  799. }
  800. static int dsi_panel_parse_lane_states(struct dsi_host_common_cfg *host,
  801. struct dsi_parser_utils *utils,
  802. const char *name)
  803. {
  804. int rc = 0;
  805. bool lane_enabled;
  806. u32 num_of_lanes = 0;
  807. lane_enabled = utils->read_bool(utils->data,
  808. "qcom,mdss-dsi-lane-0-state");
  809. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_0 : 0);
  810. lane_enabled = utils->read_bool(utils->data,
  811. "qcom,mdss-dsi-lane-1-state");
  812. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_1 : 0);
  813. lane_enabled = utils->read_bool(utils->data,
  814. "qcom,mdss-dsi-lane-2-state");
  815. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_2 : 0);
  816. lane_enabled = utils->read_bool(utils->data,
  817. "qcom,mdss-dsi-lane-3-state");
  818. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_3 : 0);
  819. if (host->data_lanes & DSI_DATA_LANE_0)
  820. num_of_lanes++;
  821. if (host->data_lanes & DSI_DATA_LANE_1)
  822. num_of_lanes++;
  823. if (host->data_lanes & DSI_DATA_LANE_2)
  824. num_of_lanes++;
  825. if (host->data_lanes & DSI_DATA_LANE_3)
  826. num_of_lanes++;
  827. host->num_data_lanes = num_of_lanes;
  828. if (host->data_lanes == 0) {
  829. DSI_ERR("[%s] No data lanes are enabled, rc=%d\n", name, rc);
  830. rc = -EINVAL;
  831. }
  832. return rc;
  833. }
  834. static int dsi_panel_parse_color_swap(struct dsi_host_common_cfg *host,
  835. struct dsi_parser_utils *utils,
  836. const char *name)
  837. {
  838. int rc = 0;
  839. const char *swap_mode;
  840. swap_mode = utils->get_property(utils->data,
  841. "qcom,mdss-dsi-color-order", NULL);
  842. if (swap_mode) {
  843. if (!strcmp(swap_mode, "rgb_swap_rgb")) {
  844. host->swap_mode = DSI_COLOR_SWAP_RGB;
  845. } else if (!strcmp(swap_mode, "rgb_swap_rbg")) {
  846. host->swap_mode = DSI_COLOR_SWAP_RBG;
  847. } else if (!strcmp(swap_mode, "rgb_swap_brg")) {
  848. host->swap_mode = DSI_COLOR_SWAP_BRG;
  849. } else if (!strcmp(swap_mode, "rgb_swap_grb")) {
  850. host->swap_mode = DSI_COLOR_SWAP_GRB;
  851. } else if (!strcmp(swap_mode, "rgb_swap_gbr")) {
  852. host->swap_mode = DSI_COLOR_SWAP_GBR;
  853. } else {
  854. DSI_ERR("[%s] Unrecognized color order-%s\n",
  855. name, swap_mode);
  856. rc = -EINVAL;
  857. }
  858. } else {
  859. DSI_DEBUG("[%s] Falling back to default color order\n", name);
  860. host->swap_mode = DSI_COLOR_SWAP_RGB;
  861. }
  862. /* bit swap on color channel is not defined in dt */
  863. host->bit_swap_red = false;
  864. host->bit_swap_green = false;
  865. host->bit_swap_blue = false;
  866. return rc;
  867. }
  868. static int dsi_panel_parse_triggers(struct dsi_host_common_cfg *host,
  869. struct dsi_parser_utils *utils,
  870. const char *name)
  871. {
  872. const char *trig;
  873. int rc = 0;
  874. trig = utils->get_property(utils->data,
  875. "qcom,mdss-dsi-mdp-trigger", NULL);
  876. if (trig) {
  877. if (!strcmp(trig, "none")) {
  878. host->mdp_cmd_trigger = DSI_TRIGGER_NONE;
  879. } else if (!strcmp(trig, "trigger_te")) {
  880. host->mdp_cmd_trigger = DSI_TRIGGER_TE;
  881. } else if (!strcmp(trig, "trigger_sw")) {
  882. host->mdp_cmd_trigger = DSI_TRIGGER_SW;
  883. } else if (!strcmp(trig, "trigger_sw_te")) {
  884. host->mdp_cmd_trigger = DSI_TRIGGER_SW_TE;
  885. } else {
  886. DSI_ERR("[%s] Unrecognized mdp trigger type (%s)\n",
  887. name, trig);
  888. rc = -EINVAL;
  889. }
  890. } else {
  891. DSI_DEBUG("[%s] Falling back to default MDP trigger\n",
  892. name);
  893. host->mdp_cmd_trigger = DSI_TRIGGER_SW;
  894. }
  895. trig = utils->get_property(utils->data,
  896. "qcom,mdss-dsi-dma-trigger", NULL);
  897. if (trig) {
  898. if (!strcmp(trig, "none")) {
  899. host->dma_cmd_trigger = DSI_TRIGGER_NONE;
  900. } else if (!strcmp(trig, "trigger_te")) {
  901. host->dma_cmd_trigger = DSI_TRIGGER_TE;
  902. } else if (!strcmp(trig, "trigger_sw")) {
  903. host->dma_cmd_trigger = DSI_TRIGGER_SW;
  904. } else if (!strcmp(trig, "trigger_sw_seof")) {
  905. host->dma_cmd_trigger = DSI_TRIGGER_SW_SEOF;
  906. } else if (!strcmp(trig, "trigger_sw_te")) {
  907. host->dma_cmd_trigger = DSI_TRIGGER_SW_TE;
  908. } else {
  909. DSI_ERR("[%s] Unrecognized mdp trigger type (%s)\n",
  910. name, trig);
  911. rc = -EINVAL;
  912. }
  913. } else {
  914. DSI_DEBUG("[%s] Falling back to default MDP trigger\n", name);
  915. host->dma_cmd_trigger = DSI_TRIGGER_SW;
  916. }
  917. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-te-pin-select",
  918. &host->te_mode);
  919. if (rc) {
  920. DSI_WARN("[%s] fallback to default te-pin-select\n", name);
  921. host->te_mode = 1;
  922. rc = 0;
  923. }
  924. return rc;
  925. }
  926. static int dsi_panel_parse_misc_host_config(struct dsi_host_common_cfg *host,
  927. struct dsi_parser_utils *utils,
  928. const char *name)
  929. {
  930. u32 val = 0, line_no = 0, window = 0;
  931. int rc = 0;
  932. bool panel_cphy_mode = false;
  933. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-t-clk-post", &val);
  934. if (!rc) {
  935. host->t_clk_post = val;
  936. DSI_DEBUG("[%s] t_clk_post = %d\n", name, val);
  937. }
  938. val = 0;
  939. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-t-clk-pre", &val);
  940. if (!rc) {
  941. host->t_clk_pre = val;
  942. DSI_DEBUG("[%s] t_clk_pre = %d\n", name, val);
  943. }
  944. host->ignore_rx_eot = utils->read_bool(utils->data,
  945. "qcom,mdss-dsi-rx-eot-ignore");
  946. host->append_tx_eot = utils->read_bool(utils->data,
  947. "qcom,mdss-dsi-tx-eot-append");
  948. host->ext_bridge_mode = utils->read_bool(utils->data,
  949. "qcom,mdss-dsi-ext-bridge-mode");
  950. host->force_hs_clk_lane = utils->read_bool(utils->data,
  951. "qcom,mdss-dsi-force-clock-lane-hs");
  952. panel_cphy_mode = utils->read_bool(utils->data,
  953. "qcom,panel-cphy-mode");
  954. host->phy_type = panel_cphy_mode ? DSI_PHY_TYPE_CPHY
  955. : DSI_PHY_TYPE_DPHY;
  956. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-dma-schedule-line",
  957. &line_no);
  958. if (rc)
  959. host->dma_sched_line = 0;
  960. else
  961. host->dma_sched_line = line_no;
  962. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-dma-schedule-window",
  963. &window);
  964. if (rc)
  965. host->dma_sched_window = 0;
  966. else
  967. host->dma_sched_window = window;
  968. DSI_DEBUG("[%s] DMA scheduling parameters Line: %d Window: %d\n", name,
  969. host->dma_sched_line, host->dma_sched_window);
  970. return 0;
  971. }
  972. static void dsi_panel_parse_split_link_config(struct dsi_host_common_cfg *host,
  973. struct dsi_parser_utils *utils,
  974. const char *name)
  975. {
  976. int rc = 0;
  977. u32 val = 0;
  978. bool supported = false;
  979. struct dsi_split_link_config *split_link = &host->split_link;
  980. supported = utils->read_bool(utils->data, "qcom,split-link-enabled");
  981. if (!supported) {
  982. DSI_DEBUG("[%s] Split link is not supported\n", name);
  983. split_link->enabled = false;
  984. return;
  985. }
  986. rc = utils->read_u32(utils->data, "qcom,sublinks-count", &val);
  987. if (rc || val < 1) {
  988. DSI_DEBUG("[%s] Using default sublinks count\n", name);
  989. split_link->num_sublinks = 2;
  990. } else {
  991. split_link->num_sublinks = val;
  992. }
  993. rc = utils->read_u32(utils->data, "qcom,lanes-per-sublink", &val);
  994. if (rc || val < 1) {
  995. DSI_DEBUG("[%s] Using default lanes per sublink\n", name);
  996. split_link->lanes_per_sublink = 2;
  997. } else {
  998. split_link->lanes_per_sublink = val;
  999. }
  1000. supported = utils->read_bool(utils->data, "qcom,split-link-sublink-swap");
  1001. if (!supported)
  1002. split_link->sublink_swap = false;
  1003. DSI_DEBUG("[%s] Split link is supported %d-%d\n", name,
  1004. split_link->num_sublinks, split_link->lanes_per_sublink);
  1005. split_link->enabled = true;
  1006. }
  1007. static int dsi_panel_parse_host_config(struct dsi_panel *panel)
  1008. {
  1009. int rc = 0;
  1010. struct dsi_parser_utils *utils = &panel->utils;
  1011. rc = dsi_panel_parse_pixel_format(&panel->host_config, utils,
  1012. panel->name);
  1013. if (rc) {
  1014. DSI_ERR("[%s] failed to get pixel format, rc=%d\n",
  1015. panel->name, rc);
  1016. goto error;
  1017. }
  1018. rc = dsi_panel_parse_lane_states(&panel->host_config, utils,
  1019. panel->name);
  1020. if (rc) {
  1021. DSI_ERR("[%s] failed to parse lane states, rc=%d\n",
  1022. panel->name, rc);
  1023. goto error;
  1024. }
  1025. rc = dsi_panel_parse_color_swap(&panel->host_config, utils,
  1026. panel->name);
  1027. if (rc) {
  1028. DSI_ERR("[%s] failed to parse color swap config, rc=%d\n",
  1029. panel->name, rc);
  1030. goto error;
  1031. }
  1032. rc = dsi_panel_parse_triggers(&panel->host_config, utils,
  1033. panel->name);
  1034. if (rc) {
  1035. DSI_ERR("[%s] failed to parse triggers, rc=%d\n",
  1036. panel->name, rc);
  1037. goto error;
  1038. }
  1039. rc = dsi_panel_parse_misc_host_config(&panel->host_config, utils,
  1040. panel->name);
  1041. if (rc) {
  1042. DSI_ERR("[%s] failed to parse misc host config, rc=%d\n",
  1043. panel->name, rc);
  1044. goto error;
  1045. }
  1046. dsi_panel_parse_split_link_config(&panel->host_config, utils,
  1047. panel->name);
  1048. error:
  1049. return rc;
  1050. }
  1051. static int dsi_panel_parse_avr_caps(struct dsi_panel *panel,
  1052. struct device_node *of_node)
  1053. {
  1054. struct dsi_avr_capabilities *avr_caps = &panel->avr_caps;
  1055. struct dsi_parser_utils *utils = &panel->utils;
  1056. int val, rc = 0;
  1057. val = utils->count_u32_elems(utils->data, "qcom,dsi-qsync-avr-step-list");
  1058. if (val <= 0) {
  1059. DSI_DEBUG("[%s] optional avr step list not defined, val:%d\n", panel->name, val);
  1060. return rc;
  1061. } else if (val > 1 && val != panel->dfps_caps.dfps_list_len) {
  1062. DSI_ERR("[%s] avr step list size %d not same as dfps list %d\n",
  1063. val, panel->dfps_caps.dfps_list_len);
  1064. return -EINVAL;
  1065. }
  1066. avr_caps->avr_step_fps_list = kcalloc(val, sizeof(u32), GFP_KERNEL);
  1067. if (!avr_caps->avr_step_fps_list)
  1068. return -ENOMEM;
  1069. rc = utils->read_u32_array(utils->data, "qcom,dsi-qsync-avr-step-list",
  1070. avr_caps->avr_step_fps_list, val);
  1071. if (rc) {
  1072. kfree(avr_caps->avr_step_fps_list);
  1073. return rc;
  1074. }
  1075. avr_caps->avr_step_fps_list_len = val;
  1076. return rc;
  1077. }
  1078. static int dsi_panel_parse_qsync_caps(struct dsi_panel *panel,
  1079. struct device_node *of_node)
  1080. {
  1081. int rc = 0;
  1082. u32 val = 0, i;
  1083. struct dsi_qsync_capabilities *qsync_caps = &panel->qsync_caps;
  1084. struct dsi_parser_utils *utils = &panel->utils;
  1085. const char *name = panel->name;
  1086. qsync_caps->qsync_support = utils->read_bool(utils->data, "qcom,qsync-enable");
  1087. if (!qsync_caps->qsync_support) {
  1088. DSI_DEBUG("qsync feature not enabled\n");
  1089. goto error;
  1090. }
  1091. /**
  1092. * "mdss-dsi-qsync-min-refresh-rate" is defined in cmd mode and
  1093. * video mode when there is only one qsync min fps present.
  1094. */
  1095. rc = of_property_read_u32(of_node,
  1096. "qcom,mdss-dsi-qsync-min-refresh-rate",
  1097. &val);
  1098. if (rc)
  1099. DSI_DEBUG("[%s] qsync min fps not defined rc:%d\n",
  1100. panel->name, rc);
  1101. qsync_caps->qsync_min_fps = val;
  1102. /**
  1103. * "dsi-supported-qsync-min-fps-list" may be defined in video
  1104. * mode, only in dfps case when "qcom,dsi-supported-dfps-list"
  1105. * is defined.
  1106. */
  1107. qsync_caps->qsync_min_fps_list_len = utils->count_u32_elems(utils->data,
  1108. "qcom,dsi-supported-qsync-min-fps-list");
  1109. if (qsync_caps->qsync_min_fps_list_len < 1)
  1110. goto qsync_support;
  1111. /**
  1112. * qcom,dsi-supported-qsync-min-fps-list cannot be defined
  1113. * along with qcom,mdss-dsi-qsync-min-refresh-rate.
  1114. */
  1115. if (qsync_caps->qsync_min_fps_list_len >= 1 &&
  1116. qsync_caps->qsync_min_fps) {
  1117. DSI_ERR("[%s] Both qsync nodes are defined\n",
  1118. name);
  1119. rc = -EINVAL;
  1120. goto error;
  1121. }
  1122. if (panel->dfps_caps.dfps_list_len !=
  1123. qsync_caps->qsync_min_fps_list_len) {
  1124. DSI_ERR("[%s] Qsync min fps list mismatch with dfps\n", name);
  1125. rc = -EINVAL;
  1126. goto error;
  1127. }
  1128. qsync_caps->qsync_min_fps_list =
  1129. kcalloc(qsync_caps->qsync_min_fps_list_len, sizeof(u32),
  1130. GFP_KERNEL);
  1131. if (!qsync_caps->qsync_min_fps_list) {
  1132. rc = -ENOMEM;
  1133. goto error;
  1134. }
  1135. rc = utils->read_u32_array(utils->data,
  1136. "qcom,dsi-supported-qsync-min-fps-list",
  1137. qsync_caps->qsync_min_fps_list,
  1138. qsync_caps->qsync_min_fps_list_len);
  1139. if (rc) {
  1140. DSI_ERR("[%s] Qsync min fps list parse failed\n", name);
  1141. rc = -EINVAL;
  1142. goto error;
  1143. }
  1144. qsync_caps->qsync_min_fps = qsync_caps->qsync_min_fps_list[0];
  1145. for (i = 1; i < qsync_caps->qsync_min_fps_list_len; i++) {
  1146. if (qsync_caps->qsync_min_fps_list[i] <
  1147. qsync_caps->qsync_min_fps)
  1148. qsync_caps->qsync_min_fps =
  1149. qsync_caps->qsync_min_fps_list[i];
  1150. }
  1151. qsync_support:
  1152. /* allow qsync support only if DFPS is with VFP approach */
  1153. if ((panel->dfps_caps.dfps_support) &&
  1154. !(panel->dfps_caps.type == DSI_DFPS_IMMEDIATE_VFP)) {
  1155. qsync_caps->qsync_support = false;
  1156. qsync_caps->qsync_min_fps = 0;
  1157. }
  1158. error:
  1159. if (rc < 0) {
  1160. qsync_caps->qsync_min_fps = 0;
  1161. qsync_caps->qsync_min_fps_list_len = 0;
  1162. }
  1163. return rc;
  1164. }
  1165. static int dsi_panel_parse_dyn_clk_list(struct dsi_display_mode *mode,
  1166. struct dsi_parser_utils *utils)
  1167. {
  1168. int i, rc = 0;
  1169. struct msm_dyn_clk_list *bit_clk_list;
  1170. if (!mode || !mode->priv_info) {
  1171. DSI_ERR("invalid arguments\n");
  1172. return -EINVAL;
  1173. }
  1174. bit_clk_list = &mode->priv_info->bit_clk_list;
  1175. bit_clk_list->count = utils->count_u32_elems(utils->data, "qcom,dsi-dyn-clk-list");
  1176. if (bit_clk_list->count < 1 || bit_clk_list->count > 100) {
  1177. DSI_ERR("invalid number of bit clock values, must be between 1 and 100\n");
  1178. return -EINVAL;
  1179. }
  1180. bit_clk_list->rates = kcalloc(bit_clk_list->count, sizeof(u32), GFP_KERNEL);
  1181. if (!bit_clk_list->rates) {
  1182. DSI_ERR("failed to allocate space for bit clock list\n");
  1183. rc = -ENOMEM;
  1184. goto error;
  1185. }
  1186. bit_clk_list->front_porches = kcalloc(bit_clk_list->count, sizeof(u32), GFP_KERNEL);
  1187. if (!bit_clk_list->front_porches) {
  1188. DSI_ERR("failed to allocate space for front porch list\n");
  1189. rc = -ENOMEM;
  1190. goto error;
  1191. }
  1192. bit_clk_list->pixel_clks_khz = kcalloc(bit_clk_list->count, sizeof(u32), GFP_KERNEL);
  1193. if (!bit_clk_list->pixel_clks_khz) {
  1194. DSI_ERR("failed to allocate space for pclk list\n");
  1195. rc = -ENOMEM;
  1196. goto error;
  1197. }
  1198. rc = utils->read_u32_array(utils->data, "qcom,dsi-dyn-clk-list",
  1199. bit_clk_list->rates, bit_clk_list->count);
  1200. if (rc) {
  1201. DSI_ERR("failed to parse supported bit clk list values, rc=%d\n", rc);
  1202. goto error;
  1203. }
  1204. for (i = 0; i < bit_clk_list->count; i++)
  1205. DSI_DEBUG("bit clk rate[%d]:%d\n", i, bit_clk_list->rates[i]);
  1206. return 0;
  1207. error:
  1208. bit_clk_list->count = 0;
  1209. kfree(bit_clk_list->rates);
  1210. kfree(bit_clk_list->front_porches);
  1211. kfree(bit_clk_list->pixel_clks_khz);
  1212. return rc;
  1213. }
  1214. static int dsi_panel_parse_dyn_clk_caps(struct dsi_panel *panel)
  1215. {
  1216. int rc = 0;
  1217. bool supported = false;
  1218. struct dsi_dyn_clk_caps *dyn_clk_caps = &panel->dyn_clk_caps;
  1219. struct dsi_parser_utils *utils = &panel->utils;
  1220. const char *type;
  1221. supported = utils->read_bool(utils->data, "qcom,dsi-dyn-clk-enable");
  1222. if (!supported) {
  1223. dyn_clk_caps->dyn_clk_support = false;
  1224. return rc;
  1225. }
  1226. dyn_clk_caps->dyn_clk_support = true;
  1227. type = utils->get_property(utils->data,
  1228. "qcom,dsi-dyn-clk-type", NULL);
  1229. if (!type) {
  1230. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_LEGACY;
  1231. dyn_clk_caps->maintain_const_fps = false;
  1232. return 0;
  1233. }
  1234. if (!strcmp(type, "constant-fps-adjust-hfp")) {
  1235. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_HFP;
  1236. dyn_clk_caps->maintain_const_fps = true;
  1237. } else if (!strcmp(type, "constant-fps-adjust-vfp")) {
  1238. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_VFP;
  1239. dyn_clk_caps->maintain_const_fps = true;
  1240. } else {
  1241. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_LEGACY;
  1242. dyn_clk_caps->maintain_const_fps = false;
  1243. }
  1244. DSI_DEBUG("Dynamic clock type is [%s]\n", type);
  1245. return 0;
  1246. }
  1247. static int dsi_panel_parse_dfps_caps(struct dsi_panel *panel)
  1248. {
  1249. int rc = 0;
  1250. bool supported = false;
  1251. struct dsi_dfps_capabilities *dfps_caps = &panel->dfps_caps;
  1252. struct dsi_parser_utils *utils = &panel->utils;
  1253. const char *name = panel->name;
  1254. const char *type;
  1255. u32 i;
  1256. supported = utils->read_bool(utils->data,
  1257. "qcom,mdss-dsi-pan-enable-dynamic-fps");
  1258. if (!supported) {
  1259. DSI_DEBUG("[%s] DFPS is not supported\n", name);
  1260. dfps_caps->dfps_support = false;
  1261. return rc;
  1262. }
  1263. type = utils->get_property(utils->data,
  1264. "qcom,mdss-dsi-pan-fps-update", NULL);
  1265. if (!type) {
  1266. DSI_ERR("[%s] dfps type not defined\n", name);
  1267. rc = -EINVAL;
  1268. goto error;
  1269. } else if (!strcmp(type, "dfps_suspend_resume_mode")) {
  1270. dfps_caps->type = DSI_DFPS_SUSPEND_RESUME;
  1271. } else if (!strcmp(type, "dfps_immediate_clk_mode")) {
  1272. dfps_caps->type = DSI_DFPS_IMMEDIATE_CLK;
  1273. } else if (!strcmp(type, "dfps_immediate_porch_mode_hfp")) {
  1274. dfps_caps->type = DSI_DFPS_IMMEDIATE_HFP;
  1275. } else if (!strcmp(type, "dfps_immediate_porch_mode_vfp")) {
  1276. dfps_caps->type = DSI_DFPS_IMMEDIATE_VFP;
  1277. } else {
  1278. DSI_ERR("[%s] dfps type is not recognized\n", name);
  1279. rc = -EINVAL;
  1280. goto error;
  1281. }
  1282. dfps_caps->dfps_list_len = utils->count_u32_elems(utils->data,
  1283. "qcom,dsi-supported-dfps-list");
  1284. if (dfps_caps->dfps_list_len < 1) {
  1285. DSI_ERR("[%s] dfps refresh list not present\n", name);
  1286. rc = -EINVAL;
  1287. goto error;
  1288. }
  1289. dfps_caps->dfps_list = kcalloc(dfps_caps->dfps_list_len, sizeof(u32),
  1290. GFP_KERNEL);
  1291. if (!dfps_caps->dfps_list) {
  1292. rc = -ENOMEM;
  1293. goto error;
  1294. }
  1295. rc = utils->read_u32_array(utils->data,
  1296. "qcom,dsi-supported-dfps-list",
  1297. dfps_caps->dfps_list,
  1298. dfps_caps->dfps_list_len);
  1299. if (rc) {
  1300. DSI_ERR("[%s] dfps refresh rate list parse failed\n", name);
  1301. rc = -EINVAL;
  1302. goto error;
  1303. }
  1304. dfps_caps->dfps_support = true;
  1305. /* calculate max and min fps */
  1306. dfps_caps->max_refresh_rate = dfps_caps->dfps_list[0];
  1307. dfps_caps->min_refresh_rate = dfps_caps->dfps_list[0];
  1308. for (i = 1; i < dfps_caps->dfps_list_len; i++) {
  1309. if (dfps_caps->dfps_list[i] < dfps_caps->min_refresh_rate)
  1310. dfps_caps->min_refresh_rate = dfps_caps->dfps_list[i];
  1311. else if (dfps_caps->dfps_list[i] > dfps_caps->max_refresh_rate)
  1312. dfps_caps->max_refresh_rate = dfps_caps->dfps_list[i];
  1313. }
  1314. error:
  1315. return rc;
  1316. }
  1317. static int dsi_panel_parse_video_host_config(struct dsi_video_engine_cfg *cfg,
  1318. struct dsi_parser_utils *utils,
  1319. const char *name)
  1320. {
  1321. int rc = 0;
  1322. const char *traffic_mode;
  1323. u32 vc_id = 0;
  1324. u32 val = 0;
  1325. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-h-sync-pulse", &val);
  1326. if (rc) {
  1327. DSI_DEBUG("[%s] fallback to default h-sync-pulse\n", name);
  1328. cfg->pulse_mode_hsa_he = false;
  1329. } else if (val == 1) {
  1330. cfg->pulse_mode_hsa_he = true;
  1331. } else if (val == 0) {
  1332. cfg->pulse_mode_hsa_he = false;
  1333. } else {
  1334. DSI_ERR("[%s] Unrecognized value for mdss-dsi-h-sync-pulse\n",
  1335. name);
  1336. rc = -EINVAL;
  1337. goto error;
  1338. }
  1339. cfg->hfp_lp11_en = utils->read_bool(utils->data,
  1340. "qcom,mdss-dsi-hfp-power-mode");
  1341. cfg->hbp_lp11_en = utils->read_bool(utils->data,
  1342. "qcom,mdss-dsi-hbp-power-mode");
  1343. cfg->hsa_lp11_en = utils->read_bool(utils->data,
  1344. "qcom,mdss-dsi-hsa-power-mode");
  1345. cfg->last_line_interleave_en = utils->read_bool(utils->data,
  1346. "qcom,mdss-dsi-last-line-interleave");
  1347. cfg->eof_bllp_lp11_en = utils->read_bool(utils->data,
  1348. "qcom,mdss-dsi-bllp-eof-power-mode");
  1349. cfg->bllp_lp11_en = utils->read_bool(utils->data,
  1350. "qcom,mdss-dsi-bllp-power-mode");
  1351. traffic_mode = utils->get_property(utils->data,
  1352. "qcom,mdss-dsi-traffic-mode",
  1353. NULL);
  1354. if (!traffic_mode) {
  1355. DSI_DEBUG("[%s] Falling back to default traffic mode\n", name);
  1356. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  1357. } else if (!strcmp(traffic_mode, "non_burst_sync_pulse")) {
  1358. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  1359. } else if (!strcmp(traffic_mode, "non_burst_sync_event")) {
  1360. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_START_EVENTS;
  1361. } else if (!strcmp(traffic_mode, "burst_mode")) {
  1362. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_BURST_MODE;
  1363. } else {
  1364. DSI_ERR("[%s] Unrecognized traffic mode-%s\n", name,
  1365. traffic_mode);
  1366. rc = -EINVAL;
  1367. goto error;
  1368. }
  1369. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-virtual-channel-id",
  1370. &vc_id);
  1371. if (rc) {
  1372. DSI_DEBUG("[%s] Fallback to default vc id\n", name);
  1373. cfg->vc_id = 0;
  1374. } else {
  1375. cfg->vc_id = vc_id;
  1376. }
  1377. error:
  1378. return rc;
  1379. }
  1380. static int dsi_panel_parse_cmd_host_config(struct dsi_cmd_engine_cfg *cfg,
  1381. struct dsi_parser_utils *utils,
  1382. const char *name)
  1383. {
  1384. u32 val = 0;
  1385. int rc = 0;
  1386. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-wr-mem-start", &val);
  1387. if (rc) {
  1388. DSI_DEBUG("[%s] Fallback to default wr-mem-start\n", name);
  1389. cfg->wr_mem_start = 0x2C;
  1390. } else {
  1391. cfg->wr_mem_start = val;
  1392. }
  1393. val = 0;
  1394. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-wr-mem-continue",
  1395. &val);
  1396. if (rc) {
  1397. DSI_DEBUG("[%s] Fallback to default wr-mem-continue\n", name);
  1398. cfg->wr_mem_continue = 0x3C;
  1399. } else {
  1400. cfg->wr_mem_continue = val;
  1401. }
  1402. /* TODO: fix following */
  1403. cfg->max_cmd_packets_interleave = 0;
  1404. val = 0;
  1405. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-te-dcs-command",
  1406. &val);
  1407. if (rc) {
  1408. DSI_DEBUG("[%s] fallback to default te-dcs-cmd\n", name);
  1409. cfg->insert_dcs_command = true;
  1410. } else if (val == 1) {
  1411. cfg->insert_dcs_command = true;
  1412. } else if (val == 0) {
  1413. cfg->insert_dcs_command = false;
  1414. } else {
  1415. DSI_ERR("[%s] Unrecognized value for mdss-dsi-te-dcs-command\n",
  1416. name);
  1417. rc = -EINVAL;
  1418. goto error;
  1419. }
  1420. cfg->mdp_idle_ctrl_en =
  1421. utils->read_bool(utils->data, "qcom,mdss-dsi-mdp-idle-ctrl-en");
  1422. if (cfg->mdp_idle_ctrl_en) {
  1423. val = 0;
  1424. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-mdp-idle-ctrl-len", &val);
  1425. if (rc) {
  1426. DSI_DEBUG("[%s] mdp idle ctrl len is not defined\n", name);
  1427. cfg->mdp_idle_ctrl_len = 0;
  1428. cfg->mdp_idle_ctrl_en = false;
  1429. rc = 0;
  1430. } else {
  1431. cfg->mdp_idle_ctrl_len = val;
  1432. }
  1433. }
  1434. error:
  1435. return rc;
  1436. }
  1437. static int dsi_panel_parse_panel_mode(struct dsi_panel *panel)
  1438. {
  1439. int rc = 0;
  1440. struct dsi_parser_utils *utils = &panel->utils;
  1441. bool panel_mode_switch_enabled;
  1442. enum dsi_op_mode panel_mode;
  1443. const char *mode;
  1444. mode = utils->get_property(utils->data,
  1445. "qcom,mdss-dsi-panel-type", NULL);
  1446. if (!mode) {
  1447. DSI_DEBUG("[%s] Fallback to default panel mode\n", panel->name);
  1448. panel_mode = DSI_OP_VIDEO_MODE;
  1449. } else if (!strcmp(mode, "dsi_video_mode")) {
  1450. panel_mode = DSI_OP_VIDEO_MODE;
  1451. } else if (!strcmp(mode, "dsi_cmd_mode")) {
  1452. panel_mode = DSI_OP_CMD_MODE;
  1453. } else {
  1454. DSI_ERR("[%s] Unrecognized panel type-%s\n", panel->name, mode);
  1455. rc = -EINVAL;
  1456. goto error;
  1457. }
  1458. panel_mode_switch_enabled = utils->read_bool(utils->data,
  1459. "qcom,mdss-dsi-panel-mode-switch");
  1460. DSI_DEBUG("%s: panel operating mode switch feature %s\n", __func__,
  1461. (panel_mode_switch_enabled ? "enabled" : "disabled"));
  1462. if (panel_mode == DSI_OP_VIDEO_MODE || panel_mode_switch_enabled) {
  1463. rc = dsi_panel_parse_video_host_config(&panel->video_config,
  1464. utils,
  1465. panel->name);
  1466. if (rc) {
  1467. DSI_ERR("[%s] Failed to parse video host cfg, rc=%d\n",
  1468. panel->name, rc);
  1469. goto error;
  1470. }
  1471. }
  1472. if (panel_mode == DSI_OP_CMD_MODE || panel_mode_switch_enabled) {
  1473. rc = dsi_panel_parse_cmd_host_config(&panel->cmd_config,
  1474. utils,
  1475. panel->name);
  1476. if (rc) {
  1477. DSI_ERR("[%s] Failed to parse cmd host config, rc=%d\n",
  1478. panel->name, rc);
  1479. goto error;
  1480. }
  1481. }
  1482. panel->poms_align_vsync = utils->read_bool(utils->data,
  1483. "qcom,poms-align-panel-vsync");
  1484. panel->panel_mode = panel_mode;
  1485. panel->panel_mode_switch_enabled = panel_mode_switch_enabled;
  1486. error:
  1487. return rc;
  1488. }
  1489. static int dsi_panel_parse_phy_props(struct dsi_panel *panel)
  1490. {
  1491. int rc = 0;
  1492. u32 val = 0;
  1493. const char *str;
  1494. struct dsi_panel_phy_props *props = &panel->phy_props;
  1495. struct dsi_parser_utils *utils = &panel->utils;
  1496. const char *name = panel->name;
  1497. rc = utils->read_u32(utils->data,
  1498. "qcom,mdss-pan-physical-width-dimension", &val);
  1499. if (rc) {
  1500. DSI_DEBUG("[%s] Physical panel width is not defined\n", name);
  1501. props->panel_width_mm = 0;
  1502. rc = 0;
  1503. } else {
  1504. props->panel_width_mm = val;
  1505. }
  1506. rc = utils->read_u32(utils->data,
  1507. "qcom,mdss-pan-physical-height-dimension",
  1508. &val);
  1509. if (rc) {
  1510. DSI_DEBUG("[%s] Physical panel height is not defined\n", name);
  1511. props->panel_height_mm = 0;
  1512. rc = 0;
  1513. } else {
  1514. props->panel_height_mm = val;
  1515. }
  1516. str = utils->get_property(utils->data,
  1517. "qcom,mdss-dsi-panel-orientation", NULL);
  1518. if (!str) {
  1519. props->rotation = DSI_PANEL_ROTATE_NONE;
  1520. } else if (!strcmp(str, "180")) {
  1521. props->rotation = DSI_PANEL_ROTATE_HV_FLIP;
  1522. } else if (!strcmp(str, "hflip")) {
  1523. props->rotation = DSI_PANEL_ROTATE_H_FLIP;
  1524. } else if (!strcmp(str, "vflip")) {
  1525. props->rotation = DSI_PANEL_ROTATE_V_FLIP;
  1526. } else {
  1527. DSI_ERR("[%s] Unrecognized panel rotation-%s\n", name, str);
  1528. rc = -EINVAL;
  1529. goto error;
  1530. }
  1531. error:
  1532. return rc;
  1533. }
  1534. const char *cmd_set_prop_map[DSI_CMD_SET_MAX] = {
  1535. "qcom,mdss-dsi-pre-on-command",
  1536. "qcom,mdss-dsi-on-command",
  1537. "qcom,vid-on-commands",
  1538. "qcom,cmd-on-commands",
  1539. "qcom,mdss-dsi-post-panel-on-command",
  1540. "qcom,mdss-dsi-pre-off-command",
  1541. "qcom,mdss-dsi-off-command",
  1542. "qcom,mdss-dsi-post-off-command",
  1543. "qcom,mdss-dsi-pre-res-switch",
  1544. "qcom,mdss-dsi-res-switch",
  1545. "qcom,mdss-dsi-post-res-switch",
  1546. "qcom,video-mode-switch-in-commands",
  1547. "qcom,video-mode-switch-out-commands",
  1548. "qcom,cmd-mode-switch-in-commands",
  1549. "qcom,cmd-mode-switch-out-commands",
  1550. "qcom,mdss-dsi-panel-status-command",
  1551. "qcom,mdss-dsi-lp1-command",
  1552. "qcom,mdss-dsi-lp2-command",
  1553. "qcom,mdss-dsi-nolp-command",
  1554. "PPS not parsed from DTSI, generated dynamically",
  1555. "ROI not parsed from DTSI, generated dynamically",
  1556. "qcom,mdss-dsi-timing-switch-command",
  1557. "qcom,mdss-dsi-post-mode-switch-on-command",
  1558. "qcom,mdss-dsi-qsync-on-commands",
  1559. "qcom,mdss-dsi-qsync-off-commands",
  1560. };
  1561. const char *cmd_set_state_map[DSI_CMD_SET_MAX] = {
  1562. "qcom,mdss-dsi-pre-on-command-state",
  1563. "qcom,mdss-dsi-on-command-state",
  1564. "qcom,vid-on-commands-state",
  1565. "qcom,cmd-on-commands-state",
  1566. "qcom,mdss-dsi-post-on-command-state",
  1567. "qcom,mdss-dsi-pre-off-command-state",
  1568. "qcom,mdss-dsi-off-command-state",
  1569. "qcom,mdss-dsi-post-off-command-state",
  1570. "qcom,mdss-dsi-pre-res-switch-state",
  1571. "qcom,mdss-dsi-res-switch-state",
  1572. "qcom,mdss-dsi-post-res-switch-state",
  1573. "qcom,video-mode-switch-in-commands-state",
  1574. "qcom,video-mode-switch-out-commands-state",
  1575. "qcom,cmd-mode-switch-in-commands-state",
  1576. "qcom,cmd-mode-switch-out-commands-state",
  1577. "qcom,mdss-dsi-panel-status-command-state",
  1578. "qcom,mdss-dsi-lp1-command-state",
  1579. "qcom,mdss-dsi-lp2-command-state",
  1580. "qcom,mdss-dsi-nolp-command-state",
  1581. "PPS not parsed from DTSI, generated dynamically",
  1582. "ROI not parsed from DTSI, generated dynamically",
  1583. "qcom,mdss-dsi-timing-switch-command-state",
  1584. "qcom,mdss-dsi-post-mode-switch-on-command-state",
  1585. "qcom,mdss-dsi-qsync-on-commands-state",
  1586. "qcom,mdss-dsi-qsync-off-commands-state",
  1587. };
  1588. int dsi_panel_get_cmd_pkt_count(const char *data, u32 length, u32 *cnt)
  1589. {
  1590. const u32 cmd_set_min_size = 7;
  1591. u32 count = 0;
  1592. u32 packet_length;
  1593. u32 tmp;
  1594. while (length >= cmd_set_min_size) {
  1595. packet_length = cmd_set_min_size;
  1596. tmp = ((data[5] << 8) | (data[6]));
  1597. packet_length += tmp;
  1598. if (packet_length > length) {
  1599. DSI_ERR("format error\n");
  1600. return -EINVAL;
  1601. }
  1602. length -= packet_length;
  1603. data += packet_length;
  1604. count++;
  1605. }
  1606. *cnt = count;
  1607. return 0;
  1608. }
  1609. int dsi_panel_create_cmd_packets(const char *data,
  1610. u32 length,
  1611. u32 count,
  1612. struct dsi_cmd_desc *cmd)
  1613. {
  1614. int rc = 0;
  1615. int i, j;
  1616. u8 *payload;
  1617. for (i = 0; i < count; i++) {
  1618. u32 size;
  1619. cmd[i].msg.type = data[0];
  1620. cmd[i].msg.channel = data[2];
  1621. cmd[i].msg.flags |= data[3];
  1622. cmd[i].ctrl = 0;
  1623. cmd[i].post_wait_ms = data[4];
  1624. cmd[i].msg.tx_len = ((data[5] << 8) | (data[6]));
  1625. if (cmd[i].msg.flags & MIPI_DSI_MSG_BATCH_COMMAND)
  1626. cmd[i].last_command = false;
  1627. else
  1628. cmd[i].last_command = true;
  1629. size = cmd[i].msg.tx_len * sizeof(u8);
  1630. payload = kzalloc(size, GFP_KERNEL);
  1631. if (!payload) {
  1632. rc = -ENOMEM;
  1633. goto error_free_payloads;
  1634. }
  1635. for (j = 0; j < cmd[i].msg.tx_len; j++)
  1636. payload[j] = data[7 + j];
  1637. cmd[i].msg.tx_buf = payload;
  1638. data += (7 + cmd[i].msg.tx_len);
  1639. }
  1640. return rc;
  1641. error_free_payloads:
  1642. for (i = i - 1; i >= 0; i--) {
  1643. cmd--;
  1644. kfree(cmd->msg.tx_buf);
  1645. }
  1646. return rc;
  1647. }
  1648. void dsi_panel_destroy_cmd_packets(struct dsi_panel_cmd_set *set)
  1649. {
  1650. u32 i = 0;
  1651. struct dsi_cmd_desc *cmd;
  1652. for (i = 0; i < set->count; i++) {
  1653. cmd = &set->cmds[i];
  1654. kfree(cmd->msg.tx_buf);
  1655. }
  1656. }
  1657. void dsi_panel_dealloc_cmd_packets(struct dsi_panel_cmd_set *set)
  1658. {
  1659. kfree(set->cmds);
  1660. }
  1661. int dsi_panel_alloc_cmd_packets(struct dsi_panel_cmd_set *cmd,
  1662. u32 packet_count)
  1663. {
  1664. u32 size;
  1665. size = packet_count * sizeof(*cmd->cmds);
  1666. cmd->cmds = kzalloc(size, GFP_KERNEL);
  1667. if (!cmd->cmds)
  1668. return -ENOMEM;
  1669. cmd->count = packet_count;
  1670. return 0;
  1671. }
  1672. static int dsi_panel_parse_cmd_sets_sub(struct dsi_panel_cmd_set *cmd,
  1673. enum dsi_cmd_set_type type,
  1674. struct dsi_parser_utils *utils)
  1675. {
  1676. int rc = 0;
  1677. u32 length = 0;
  1678. const char *data;
  1679. const char *state;
  1680. u32 packet_count = 0;
  1681. data = utils->get_property(utils->data, cmd_set_prop_map[type],
  1682. &length);
  1683. if (!data) {
  1684. DSI_DEBUG("%s commands not defined\n", cmd_set_prop_map[type]);
  1685. rc = -ENOTSUPP;
  1686. goto error;
  1687. }
  1688. DSI_DEBUG("type=%d, name=%s, length=%d\n", type, cmd_set_prop_map[type], length);
  1689. print_hex_dump_debug("", DUMP_PREFIX_NONE, 8, 1, data, length, false);
  1690. rc = dsi_panel_get_cmd_pkt_count(data, length, &packet_count);
  1691. if (rc) {
  1692. DSI_ERR("commands failed, rc=%d\n", rc);
  1693. goto error;
  1694. }
  1695. DSI_DEBUG("[%s] packet-count=%d, %d\n", cmd_set_prop_map[type],
  1696. packet_count, length);
  1697. rc = dsi_panel_alloc_cmd_packets(cmd, packet_count);
  1698. if (rc) {
  1699. DSI_ERR("failed to allocate cmd packets, rc=%d\n", rc);
  1700. goto error;
  1701. }
  1702. rc = dsi_panel_create_cmd_packets(data, length, packet_count,
  1703. cmd->cmds);
  1704. if (rc) {
  1705. DSI_ERR("failed to create cmd packets, rc=%d\n", rc);
  1706. goto error_free_mem;
  1707. }
  1708. state = utils->get_property(utils->data, cmd_set_state_map[type], NULL);
  1709. if (!state || !strcmp(state, "dsi_lp_mode")) {
  1710. cmd->state = DSI_CMD_SET_STATE_LP;
  1711. } else if (!strcmp(state, "dsi_hs_mode")) {
  1712. cmd->state = DSI_CMD_SET_STATE_HS;
  1713. } else {
  1714. DSI_ERR("[%s] command state unrecognized-%s\n",
  1715. cmd_set_state_map[type], state);
  1716. goto error_free_mem;
  1717. }
  1718. return rc;
  1719. error_free_mem:
  1720. kfree(cmd->cmds);
  1721. cmd->cmds = NULL;
  1722. error:
  1723. return rc;
  1724. }
  1725. static int dsi_panel_parse_cmd_sets(
  1726. struct dsi_display_mode_priv_info *priv_info,
  1727. struct dsi_parser_utils *utils)
  1728. {
  1729. int rc = 0;
  1730. struct dsi_panel_cmd_set *set;
  1731. u32 i;
  1732. if (!priv_info) {
  1733. DSI_ERR("invalid mode priv info\n");
  1734. return -EINVAL;
  1735. }
  1736. for (i = DSI_CMD_SET_PRE_ON; i < DSI_CMD_SET_MAX; i++) {
  1737. set = &priv_info->cmd_sets[i];
  1738. set->type = i;
  1739. set->count = 0;
  1740. if (i == DSI_CMD_SET_PPS) {
  1741. rc = dsi_panel_alloc_cmd_packets(set, 1);
  1742. if (rc)
  1743. DSI_ERR("failed to allocate cmd set %d, rc = %d\n",
  1744. i, rc);
  1745. set->state = DSI_CMD_SET_STATE_LP;
  1746. } else {
  1747. rc = dsi_panel_parse_cmd_sets_sub(set, i, utils);
  1748. if (rc)
  1749. DSI_DEBUG("failed to parse set %d\n", i);
  1750. }
  1751. }
  1752. rc = 0;
  1753. return rc;
  1754. }
  1755. static int dsi_panel_parse_reset_sequence(struct dsi_panel *panel)
  1756. {
  1757. int rc = 0;
  1758. int i;
  1759. u32 length = 0;
  1760. u32 count = 0;
  1761. u32 size = 0;
  1762. u32 *arr_32 = NULL;
  1763. const u32 *arr;
  1764. struct dsi_parser_utils *utils = &panel->utils;
  1765. struct dsi_reset_seq *seq;
  1766. if (panel->host_config.ext_bridge_mode)
  1767. return 0;
  1768. arr = utils->get_property(utils->data,
  1769. "qcom,mdss-dsi-reset-sequence", &length);
  1770. if (!arr) {
  1771. DSI_ERR("[%s] dsi-reset-sequence not found\n", panel->name);
  1772. rc = -EINVAL;
  1773. goto error;
  1774. }
  1775. if (length & 0x1) {
  1776. DSI_ERR("[%s] syntax error for dsi-reset-sequence\n",
  1777. panel->name);
  1778. rc = -EINVAL;
  1779. goto error;
  1780. }
  1781. DSI_DEBUG("RESET SEQ LENGTH = %d\n", length);
  1782. length = length / sizeof(u32);
  1783. size = length * sizeof(u32);
  1784. arr_32 = kzalloc(size, GFP_KERNEL);
  1785. if (!arr_32) {
  1786. rc = -ENOMEM;
  1787. goto error;
  1788. }
  1789. rc = utils->read_u32_array(utils->data, "qcom,mdss-dsi-reset-sequence",
  1790. arr_32, length);
  1791. if (rc) {
  1792. DSI_ERR("[%s] cannot read dso-reset-seqience\n", panel->name);
  1793. goto error_free_arr_32;
  1794. }
  1795. count = length / 2;
  1796. size = count * sizeof(*seq);
  1797. seq = kzalloc(size, GFP_KERNEL);
  1798. if (!seq) {
  1799. rc = -ENOMEM;
  1800. goto error_free_arr_32;
  1801. }
  1802. panel->reset_config.sequence = seq;
  1803. panel->reset_config.count = count;
  1804. for (i = 0; i < length; i += 2) {
  1805. seq->level = arr_32[i];
  1806. seq->sleep_ms = arr_32[i + 1];
  1807. seq++;
  1808. }
  1809. error_free_arr_32:
  1810. kfree(arr_32);
  1811. error:
  1812. return rc;
  1813. }
  1814. static int dsi_panel_parse_misc_features(struct dsi_panel *panel)
  1815. {
  1816. struct dsi_parser_utils *utils = &panel->utils;
  1817. const char *string;
  1818. int i, rc = 0;
  1819. panel->ulps_feature_enabled =
  1820. utils->read_bool(utils->data, "qcom,ulps-enabled");
  1821. DSI_DEBUG("%s: ulps feature %s\n", __func__,
  1822. (panel->ulps_feature_enabled ? "enabled" : "disabled"));
  1823. panel->ulps_suspend_enabled =
  1824. utils->read_bool(utils->data, "qcom,suspend-ulps-enabled");
  1825. DSI_DEBUG("%s: ulps during suspend feature %s\n", __func__,
  1826. (panel->ulps_suspend_enabled ? "enabled" : "disabled"));
  1827. panel->te_using_watchdog_timer = utils->read_bool(utils->data,
  1828. "qcom,mdss-dsi-te-using-wd");
  1829. panel->sync_broadcast_en = utils->read_bool(utils->data,
  1830. "qcom,cmd-sync-wait-broadcast");
  1831. panel->lp11_init = utils->read_bool(utils->data,
  1832. "qcom,mdss-dsi-lp11-init");
  1833. panel->reset_gpio_always_on = utils->read_bool(utils->data,
  1834. "qcom,platform-reset-gpio-always-on");
  1835. panel->spr_info.enable = false;
  1836. panel->spr_info.pack_type = MSM_DISPLAY_SPR_TYPE_MAX;
  1837. rc = utils->read_string(utils->data, "qcom,spr-pack-type", &string);
  1838. if (!rc) {
  1839. // find match for pack-type string
  1840. for (i = 0; i < MSM_DISPLAY_SPR_TYPE_MAX; i++) {
  1841. if (msm_spr_pack_type_str[i] &&
  1842. (!strcmp(string, msm_spr_pack_type_str[i]))) {
  1843. panel->spr_info.enable = true;
  1844. panel->spr_info.pack_type = i;
  1845. break;
  1846. }
  1847. }
  1848. }
  1849. pr_debug("%s source side spr packing, pack-type %s\n",
  1850. panel->spr_info.enable ? "enable" : "disable",
  1851. panel->spr_info.enable ?
  1852. msm_spr_pack_type_str[panel->spr_info.pack_type] : "none");
  1853. return 0;
  1854. }
  1855. static int dsi_panel_parse_jitter_config(
  1856. struct dsi_display_mode *mode,
  1857. struct dsi_parser_utils *utils)
  1858. {
  1859. int rc;
  1860. struct dsi_display_mode_priv_info *priv_info;
  1861. u32 jitter[DEFAULT_PANEL_JITTER_ARRAY_SIZE] = {0, 0};
  1862. u64 jitter_val = 0;
  1863. priv_info = mode->priv_info;
  1864. rc = utils->read_u32_array(utils->data, "qcom,mdss-dsi-panel-jitter",
  1865. jitter, DEFAULT_PANEL_JITTER_ARRAY_SIZE);
  1866. if (rc) {
  1867. DSI_DEBUG("panel jitter not defined rc=%d\n", rc);
  1868. } else {
  1869. jitter_val = jitter[0];
  1870. jitter_val = div_u64(jitter_val, jitter[1]);
  1871. }
  1872. if (rc || !jitter_val || (jitter_val > MAX_PANEL_JITTER)) {
  1873. priv_info->panel_jitter_numer = DEFAULT_PANEL_JITTER_NUMERATOR;
  1874. priv_info->panel_jitter_denom =
  1875. DEFAULT_PANEL_JITTER_DENOMINATOR;
  1876. } else {
  1877. priv_info->panel_jitter_numer = jitter[0];
  1878. priv_info->panel_jitter_denom = jitter[1];
  1879. }
  1880. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-panel-prefill-lines",
  1881. &priv_info->panel_prefill_lines);
  1882. if (rc) {
  1883. DSI_DEBUG("panel prefill lines are not defined rc=%d\n", rc);
  1884. priv_info->panel_prefill_lines = mode->timing.v_back_porch +
  1885. mode->timing.v_sync_width + mode->timing.v_front_porch;
  1886. } else if (priv_info->panel_prefill_lines >=
  1887. DSI_V_TOTAL(&mode->timing)) {
  1888. DSI_DEBUG("invalid prefill lines config=%d setting to:%d\n",
  1889. priv_info->panel_prefill_lines, DEFAULT_PANEL_PREFILL_LINES);
  1890. priv_info->panel_prefill_lines = DEFAULT_PANEL_PREFILL_LINES;
  1891. }
  1892. return 0;
  1893. }
  1894. static int dsi_panel_parse_power_cfg(struct dsi_panel *panel)
  1895. {
  1896. int rc = 0;
  1897. char *supply_name;
  1898. if (panel->host_config.ext_bridge_mode)
  1899. return 0;
  1900. if (!strcmp(panel->type, "primary"))
  1901. supply_name = "qcom,panel-supply-entries";
  1902. else
  1903. supply_name = "qcom,panel-sec-supply-entries";
  1904. rc = dsi_pwr_of_get_vreg_data(&panel->utils,
  1905. &panel->power_info, supply_name);
  1906. if (rc) {
  1907. DSI_ERR("[%s] failed to parse vregs\n", panel->name);
  1908. goto error;
  1909. }
  1910. error:
  1911. return rc;
  1912. }
  1913. int dsi_panel_get_io_resources(struct dsi_panel *panel,
  1914. struct msm_io_res *io_res)
  1915. {
  1916. struct dsi_parser_utils *utils = &panel->utils;
  1917. struct list_head *mem_list = &io_res->mem;
  1918. int reset_gpio;
  1919. int rc = 0;
  1920. reset_gpio = utils->get_named_gpio(utils->data,
  1921. "qcom,platform-reset-gpio", 0);
  1922. if (gpio_is_valid(reset_gpio)) {
  1923. rc = msm_dss_get_gpio_io_mem(reset_gpio, mem_list);
  1924. if (rc) {
  1925. DSI_ERR("[%s] failed to retrieve the reset gpio address\n", panel->name);
  1926. goto end;
  1927. }
  1928. }
  1929. end:
  1930. return rc;
  1931. }
  1932. static int dsi_panel_parse_gpios(struct dsi_panel *panel)
  1933. {
  1934. int rc = 0;
  1935. const char *data;
  1936. struct dsi_parser_utils *utils = &panel->utils;
  1937. char *reset_gpio_name, *mode_set_gpio_name;
  1938. if (!strcmp(panel->type, "primary")) {
  1939. reset_gpio_name = "qcom,platform-reset-gpio";
  1940. mode_set_gpio_name = "qcom,panel-mode-gpio";
  1941. } else {
  1942. reset_gpio_name = "qcom,platform-sec-reset-gpio";
  1943. mode_set_gpio_name = "qcom,panel-sec-mode-gpio";
  1944. }
  1945. panel->reset_config.reset_gpio = utils->get_named_gpio(utils->data,
  1946. reset_gpio_name, 0);
  1947. if (!gpio_is_valid(panel->reset_config.reset_gpio) &&
  1948. !panel->host_config.ext_bridge_mode) {
  1949. DSI_DEBUG("[%s] reset gpio not set, rc=%d\n", panel->name,
  1950. panel->reset_config.reset_gpio);
  1951. }
  1952. panel->reset_config.disp_en_gpio = utils->get_named_gpio(utils->data,
  1953. "qcom,5v-boost-gpio",
  1954. 0);
  1955. if (!gpio_is_valid(panel->reset_config.disp_en_gpio)) {
  1956. DSI_DEBUG("[%s] 5v-boot-gpio is not set, rc=%d\n",
  1957. panel->name, rc);
  1958. panel->reset_config.disp_en_gpio =
  1959. utils->get_named_gpio(utils->data,
  1960. "qcom,platform-en-gpio", 0);
  1961. if (!gpio_is_valid(panel->reset_config.disp_en_gpio)) {
  1962. DSI_DEBUG("[%s] platform-en-gpio is not set, rc=%d\n",
  1963. panel->name, rc);
  1964. }
  1965. }
  1966. panel->reset_config.lcd_mode_sel_gpio = utils->get_named_gpio(
  1967. utils->data, mode_set_gpio_name, 0);
  1968. if (!gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio))
  1969. DSI_DEBUG("mode gpio not specified\n");
  1970. DSI_DEBUG("mode gpio=%d\n", panel->reset_config.lcd_mode_sel_gpio);
  1971. data = utils->get_property(utils->data,
  1972. "qcom,mdss-dsi-mode-sel-gpio-state", NULL);
  1973. if (data) {
  1974. if (!strcmp(data, "single_port"))
  1975. panel->reset_config.mode_sel_state =
  1976. MODE_SEL_SINGLE_PORT;
  1977. else if (!strcmp(data, "dual_port"))
  1978. panel->reset_config.mode_sel_state =
  1979. MODE_SEL_DUAL_PORT;
  1980. else if (!strcmp(data, "high"))
  1981. panel->reset_config.mode_sel_state =
  1982. MODE_GPIO_HIGH;
  1983. else if (!strcmp(data, "low"))
  1984. panel->reset_config.mode_sel_state =
  1985. MODE_GPIO_LOW;
  1986. } else {
  1987. /* Set default mode as SPLIT mode */
  1988. panel->reset_config.mode_sel_state = MODE_SEL_DUAL_PORT;
  1989. }
  1990. /* TODO: release memory */
  1991. rc = dsi_panel_parse_reset_sequence(panel);
  1992. if (rc) {
  1993. DSI_ERR("[%s] failed to parse reset sequence, rc=%d\n",
  1994. panel->name, rc);
  1995. goto error;
  1996. }
  1997. panel->panel_test_gpio = utils->get_named_gpio(utils->data,
  1998. "qcom,mdss-dsi-panel-test-pin",
  1999. 0);
  2000. if (!gpio_is_valid(panel->panel_test_gpio))
  2001. DSI_DEBUG("%s:%d panel test gpio not specified\n", __func__,
  2002. __LINE__);
  2003. error:
  2004. return rc;
  2005. }
  2006. static int dsi_panel_parse_bl_pwm_config(struct dsi_panel *panel)
  2007. {
  2008. int rc = 0;
  2009. u32 val;
  2010. struct dsi_backlight_config *config = &panel->bl_config;
  2011. struct dsi_parser_utils *utils = &panel->utils;
  2012. rc = utils->read_u32(utils->data, "qcom,bl-pmic-pwm-period-usecs",
  2013. &val);
  2014. if (rc) {
  2015. DSI_ERR("bl-pmic-pwm-period-usecs is not defined, rc=%d\n", rc);
  2016. goto error;
  2017. }
  2018. config->pwm_period_usecs = val;
  2019. error:
  2020. return rc;
  2021. }
  2022. static int dsi_panel_parse_bl_config(struct dsi_panel *panel)
  2023. {
  2024. int rc = 0;
  2025. u32 val = 0;
  2026. const char *bl_type = NULL;
  2027. const char *data = NULL;
  2028. const char *state = NULL;
  2029. struct dsi_parser_utils *utils = &panel->utils;
  2030. char *bl_name = NULL;
  2031. if (!strcmp(panel->type, "primary"))
  2032. bl_name = "qcom,mdss-dsi-bl-pmic-control-type";
  2033. else
  2034. bl_name = "qcom,mdss-dsi-sec-bl-pmic-control-type";
  2035. bl_type = utils->get_property(utils->data, bl_name, NULL);
  2036. if (!bl_type) {
  2037. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  2038. } else if (!strcmp(bl_type, "bl_ctrl_pwm")) {
  2039. panel->bl_config.type = DSI_BACKLIGHT_PWM;
  2040. } else if (!strcmp(bl_type, "bl_ctrl_wled")) {
  2041. panel->bl_config.type = DSI_BACKLIGHT_WLED;
  2042. } else if (!strcmp(bl_type, "bl_ctrl_dcs")) {
  2043. panel->bl_config.type = DSI_BACKLIGHT_DCS;
  2044. } else if (!strcmp(bl_type, "bl_ctrl_external")) {
  2045. panel->bl_config.type = DSI_BACKLIGHT_EXTERNAL;
  2046. } else {
  2047. DSI_DEBUG("[%s] bl-pmic-control-type unknown-%s\n",
  2048. panel->name, bl_type);
  2049. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  2050. }
  2051. data = utils->get_property(utils->data, "qcom,bl-update-flag", NULL);
  2052. if (!data) {
  2053. panel->bl_config.bl_update = BL_UPDATE_NONE;
  2054. } else if (!strcmp(data, "delay_until_first_frame")) {
  2055. panel->bl_config.bl_update = BL_UPDATE_DELAY_UNTIL_FIRST_FRAME;
  2056. } else {
  2057. DSI_DEBUG("[%s] No valid bl-update-flag: %s\n",
  2058. panel->name, data);
  2059. panel->bl_config.bl_update = BL_UPDATE_NONE;
  2060. }
  2061. panel->bl_config.bl_scale = MAX_BL_SCALE_LEVEL;
  2062. panel->bl_config.bl_scale_sv = MAX_SV_BL_SCALE_LEVEL;
  2063. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-bl-min-level", &val);
  2064. if (rc) {
  2065. DSI_DEBUG("[%s] bl-min-level unspecified, defaulting to zero\n",
  2066. panel->name);
  2067. panel->bl_config.bl_min_level = 0;
  2068. } else {
  2069. panel->bl_config.bl_min_level = val;
  2070. }
  2071. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-bl-max-level", &val);
  2072. if (rc) {
  2073. DSI_DEBUG("[%s] bl-max-level unspecified, defaulting to max level\n",
  2074. panel->name);
  2075. panel->bl_config.bl_max_level = MAX_BL_LEVEL;
  2076. } else {
  2077. panel->bl_config.bl_max_level = val;
  2078. }
  2079. rc = utils->read_u32(utils->data, "qcom,mdss-brightness-max-level",
  2080. &val);
  2081. if (rc) {
  2082. DSI_DEBUG("[%s] brigheness-max-level unspecified, defaulting to 255\n",
  2083. panel->name);
  2084. panel->bl_config.brightness_max_level = 255;
  2085. rc = 0;
  2086. } else {
  2087. panel->bl_config.brightness_max_level = val;
  2088. }
  2089. panel->bl_config.bl_inverted_dbv = utils->read_bool(utils->data,
  2090. "qcom,mdss-dsi-bl-inverted-dbv");
  2091. state = utils->get_property(utils->data, "qcom,bl-dsc-cmd-state", NULL);
  2092. if (!state || !strcmp(state, "dsi_hs_mode"))
  2093. panel->bl_config.lp_mode = false;
  2094. else if (!strcmp(state, "dsi_lp_mode"))
  2095. panel->bl_config.lp_mode = true;
  2096. else
  2097. DSI_ERR("bl-dsc-cmd-state command state unrecognized-%s\n",
  2098. state);
  2099. if (panel->bl_config.type == DSI_BACKLIGHT_PWM) {
  2100. rc = dsi_panel_parse_bl_pwm_config(panel);
  2101. if (rc) {
  2102. DSI_ERR("[%s] failed to parse pwm config, rc=%d\n",
  2103. panel->name, rc);
  2104. goto error;
  2105. }
  2106. }
  2107. panel->bl_config.en_gpio = utils->get_named_gpio(utils->data,
  2108. "qcom,platform-bklight-en-gpio",
  2109. 0);
  2110. if (!gpio_is_valid(panel->bl_config.en_gpio)) {
  2111. if (panel->bl_config.en_gpio == -EPROBE_DEFER) {
  2112. DSI_DEBUG("[%s] failed to get bklt gpio, rc=%d\n",
  2113. panel->name, rc);
  2114. rc = -EPROBE_DEFER;
  2115. goto error;
  2116. } else {
  2117. DSI_DEBUG("[%s] failed to get bklt gpio, rc=%d\n",
  2118. panel->name, rc);
  2119. rc = 0;
  2120. goto error;
  2121. }
  2122. }
  2123. error:
  2124. return rc;
  2125. }
  2126. static int dsi_panel_parse_phy_timing(struct dsi_display_mode *mode,
  2127. struct dsi_parser_utils *utils)
  2128. {
  2129. const char *data;
  2130. u32 len, i;
  2131. int rc = 0;
  2132. struct dsi_display_mode_priv_info *priv_info;
  2133. u64 pixel_clk_khz;
  2134. if (!mode || !mode->priv_info)
  2135. return -EINVAL;
  2136. priv_info = mode->priv_info;
  2137. data = utils->get_property(utils->data,
  2138. "qcom,mdss-dsi-panel-phy-timings", &len);
  2139. if (!data) {
  2140. DSI_DEBUG("Unable to read Phy timing settings\n");
  2141. } else {
  2142. priv_info->phy_timing_val =
  2143. kzalloc((sizeof(u32) * len), GFP_KERNEL);
  2144. if (!priv_info->phy_timing_val)
  2145. return -EINVAL;
  2146. for (i = 0; i < len; i++)
  2147. priv_info->phy_timing_val[i] = data[i];
  2148. priv_info->phy_timing_len = len;
  2149. }
  2150. if (mode->panel_mode_caps & DSI_OP_VIDEO_MODE) {
  2151. /*
  2152. * For command mode we update the pclk as part of
  2153. * function dsi_panel_calc_dsi_transfer_time( )
  2154. * as we set it based on dsi clock or mdp transfer time.
  2155. */
  2156. pixel_clk_khz = (dsi_h_total_dce(&mode->timing) *
  2157. DSI_V_TOTAL(&mode->timing) *
  2158. mode->timing.refresh_rate);
  2159. do_div(pixel_clk_khz, 1000);
  2160. mode->pixel_clk_khz = pixel_clk_khz;
  2161. }
  2162. return rc;
  2163. }
  2164. static int dsi_panel_parse_dsc_params(struct dsi_display_mode *mode,
  2165. struct dsi_parser_utils *utils)
  2166. {
  2167. u32 data;
  2168. int rc = -EINVAL;
  2169. int intf_width;
  2170. const char *compression;
  2171. struct dsi_display_mode_priv_info *priv_info;
  2172. if (!mode || !mode->priv_info)
  2173. return -EINVAL;
  2174. priv_info = mode->priv_info;
  2175. priv_info->dsc_enabled = false;
  2176. compression = utils->get_property(utils->data,
  2177. "qcom,compression-mode", NULL);
  2178. if (compression && !strcmp(compression, "dsc"))
  2179. priv_info->dsc_enabled = true;
  2180. if (!priv_info->dsc_enabled) {
  2181. DSI_DEBUG("dsc compression is not enabled for the mode\n");
  2182. return 0;
  2183. }
  2184. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-version", &data);
  2185. if (rc) {
  2186. priv_info->dsc.config.dsc_version_major = 0x1;
  2187. priv_info->dsc.config.dsc_version_minor = 0x1;
  2188. rc = 0;
  2189. } else {
  2190. /* BITS[0..3] provides minor version and BITS[4..7] provide
  2191. * major version information
  2192. */
  2193. priv_info->dsc.config.dsc_version_major = (data >> 4) & 0x0F;
  2194. priv_info->dsc.config.dsc_version_minor = data & 0x0F;
  2195. if ((priv_info->dsc.config.dsc_version_major != 0x1) ||
  2196. ((priv_info->dsc.config.dsc_version_minor
  2197. != 0x1) &&
  2198. (priv_info->dsc.config.dsc_version_minor
  2199. != 0x2))) {
  2200. DSI_ERR("%s:unsupported major:%d minor:%d version\n",
  2201. __func__,
  2202. priv_info->dsc.config.dsc_version_major,
  2203. priv_info->dsc.config.dsc_version_minor
  2204. );
  2205. rc = -EINVAL;
  2206. goto error;
  2207. }
  2208. }
  2209. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-scr-version", &data);
  2210. if (rc) {
  2211. priv_info->dsc.scr_rev = 0x0;
  2212. rc = 0;
  2213. } else {
  2214. priv_info->dsc.scr_rev = data & 0xff;
  2215. /* only one scr rev supported */
  2216. if (priv_info->dsc.scr_rev > 0x1) {
  2217. DSI_ERR("%s: DSC scr version:%d not supported\n",
  2218. __func__, priv_info->dsc.scr_rev);
  2219. rc = -EINVAL;
  2220. goto error;
  2221. }
  2222. }
  2223. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-slice-height", &data);
  2224. if (rc) {
  2225. DSI_ERR("failed to parse qcom,mdss-dsc-slice-height\n");
  2226. goto error;
  2227. }
  2228. priv_info->dsc.config.slice_height = data;
  2229. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-slice-width", &data);
  2230. if (rc) {
  2231. DSI_ERR("failed to parse qcom,mdss-dsc-slice-width\n");
  2232. goto error;
  2233. }
  2234. priv_info->dsc.config.slice_width = data;
  2235. intf_width = mode->timing.h_active;
  2236. if (intf_width % priv_info->dsc.config.slice_width) {
  2237. DSI_ERR("invalid slice width for the intf width:%d slice width:%d\n",
  2238. intf_width, priv_info->dsc.config.slice_width);
  2239. rc = -EINVAL;
  2240. goto error;
  2241. }
  2242. priv_info->dsc.config.pic_width = mode->timing.h_active;
  2243. priv_info->dsc.config.pic_height = mode->timing.v_active;
  2244. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-slice-per-pkt", &data);
  2245. if (rc) {
  2246. DSI_ERR("failed to parse qcom,mdss-dsc-slice-per-pkt\n");
  2247. goto error;
  2248. } else if (!data || (data > 2)) {
  2249. DSI_ERR("invalid dsc slice-per-pkt:%d\n", data);
  2250. goto error;
  2251. }
  2252. priv_info->dsc.slice_per_pkt = data;
  2253. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-bit-per-component",
  2254. &data);
  2255. if (rc) {
  2256. DSI_ERR("failed to parse qcom,mdss-dsc-bit-per-component\n");
  2257. goto error;
  2258. }
  2259. priv_info->dsc.config.bits_per_component = data;
  2260. rc = utils->read_u32(utils->data, "qcom,mdss-pps-delay-ms", &data);
  2261. if (rc) {
  2262. DSI_DEBUG("pps-delay-ms not specified, defaulting to 0\n");
  2263. data = 0;
  2264. }
  2265. priv_info->dsc.pps_delay_ms = data;
  2266. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-bit-per-pixel",
  2267. &data);
  2268. if (rc) {
  2269. DSI_ERR("failed to parse qcom,mdss-dsc-bit-per-pixel\n");
  2270. goto error;
  2271. }
  2272. priv_info->dsc.config.bits_per_pixel = data << 4;
  2273. rc = utils->read_u32(utils->data, "qcom,src-chroma-format",
  2274. &data);
  2275. if (rc) {
  2276. DSI_DEBUG("failed to parse qcom,src-chroma-format\n");
  2277. rc = 0;
  2278. data = MSM_CHROMA_444;
  2279. }
  2280. priv_info->dsc.chroma_format = data;
  2281. rc = utils->read_u32(utils->data, "qcom,src-color-space",
  2282. &data);
  2283. if (rc) {
  2284. DSI_DEBUG("failed to parse qcom,src-color-space\n");
  2285. rc = 0;
  2286. data = MSM_RGB;
  2287. }
  2288. priv_info->dsc.source_color_space = data;
  2289. priv_info->dsc.config.block_pred_enable = utils->read_bool(utils->data,
  2290. "qcom,mdss-dsc-block-prediction-enable");
  2291. priv_info->dsc.config.slice_count = DIV_ROUND_UP(intf_width,
  2292. priv_info->dsc.config.slice_width);
  2293. rc = sde_dsc_populate_dsc_config(&priv_info->dsc.config,
  2294. priv_info->dsc.scr_rev);
  2295. if (rc) {
  2296. DSI_DEBUG("failed populating dsc params\n");
  2297. rc = -EINVAL;
  2298. goto error;
  2299. }
  2300. rc = sde_dsc_populate_dsc_private_params(&priv_info->dsc, intf_width);
  2301. if (rc) {
  2302. DSI_DEBUG("failed populating other dsc params\n");
  2303. rc = -EINVAL;
  2304. goto error;
  2305. }
  2306. priv_info->pclk_scale.numer =
  2307. priv_info->dsc.config.bits_per_pixel >> 4;
  2308. priv_info->pclk_scale.denom = msm_get_src_bpc(
  2309. priv_info->dsc.chroma_format,
  2310. priv_info->dsc.config.bits_per_component);
  2311. mode->timing.dsc_enabled = true;
  2312. mode->timing.dsc = &priv_info->dsc;
  2313. mode->timing.pclk_scale = priv_info->pclk_scale;
  2314. error:
  2315. return rc;
  2316. }
  2317. static int dsi_panel_parse_vdc_params(struct dsi_display_mode *mode,
  2318. struct dsi_parser_utils *utils, int traffic_mode)
  2319. {
  2320. u32 data;
  2321. int rc = -EINVAL;
  2322. const char *compression;
  2323. struct dsi_display_mode_priv_info *priv_info;
  2324. int intf_width;
  2325. if (!mode || !mode->priv_info)
  2326. return -EINVAL;
  2327. priv_info = mode->priv_info;
  2328. priv_info->vdc_enabled = false;
  2329. compression = utils->get_property(utils->data,
  2330. "qcom,compression-mode", NULL);
  2331. if (compression && !strcmp(compression, "vdc"))
  2332. priv_info->vdc_enabled = true;
  2333. if (!priv_info->vdc_enabled) {
  2334. DSI_DEBUG("vdc compression is not enabled for the mode\n");
  2335. return 0;
  2336. }
  2337. priv_info->vdc.traffic_mode = traffic_mode;
  2338. rc = utils->read_u32(utils->data, "qcom,vdc-version", &data);
  2339. if (rc) {
  2340. priv_info->vdc.version_major = 0x1;
  2341. priv_info->vdc.version_minor = 0x2;
  2342. priv_info->vdc.version_release = 0x0;
  2343. rc = 0;
  2344. } else {
  2345. /* BITS[0..3] provides minor version and BITS[4..7] provide
  2346. * major version information
  2347. */
  2348. priv_info->vdc.version_major = (data >> 4) & 0x0F;
  2349. priv_info->vdc.version_minor = data & 0x0F;
  2350. if ((priv_info->vdc.version_major != 0x1) &&
  2351. ((priv_info->vdc.version_minor
  2352. != 0x2))) {
  2353. DSI_ERR("%s:unsupported major:%d minor:%d version\n",
  2354. __func__,
  2355. priv_info->vdc.version_major,
  2356. priv_info->vdc.version_minor
  2357. );
  2358. rc = -EINVAL;
  2359. goto error;
  2360. }
  2361. }
  2362. rc = utils->read_u32(utils->data, "qcom,vdc-version-release", &data);
  2363. if (rc) {
  2364. priv_info->vdc.version_release = 0x0;
  2365. rc = 0;
  2366. } else {
  2367. priv_info->vdc.version_release = data & 0xff;
  2368. /* only one release version is supported */
  2369. if (priv_info->vdc.version_release != 0x0) {
  2370. DSI_ERR("unsupported vdc release version %d\n",
  2371. priv_info->vdc.version_release);
  2372. rc = -EINVAL;
  2373. goto error;
  2374. }
  2375. }
  2376. DSI_INFO("vdc major: 0x%x minor : 0x%x release : 0x%x\n",
  2377. priv_info->vdc.version_major,
  2378. priv_info->vdc.version_minor,
  2379. priv_info->vdc.version_release);
  2380. rc = utils->read_u32(utils->data, "qcom,vdc-slice-height", &data);
  2381. if (rc) {
  2382. DSI_ERR("failed to parse qcom,vdc-slice-height\n");
  2383. goto error;
  2384. }
  2385. priv_info->vdc.slice_height = data;
  2386. /* slice height should be atleast 16 lines */
  2387. if (priv_info->vdc.slice_height < 16) {
  2388. DSI_ERR("invalid slice height %d\n",
  2389. priv_info->vdc.slice_height);
  2390. rc = -EINVAL;
  2391. goto error;
  2392. }
  2393. rc = utils->read_u32(utils->data, "qcom,vdc-slice-width", &data);
  2394. if (rc) {
  2395. DSI_ERR("failed to parse qcom,vdc-slice-width\n");
  2396. goto error;
  2397. }
  2398. priv_info->vdc.slice_width = data;
  2399. /*
  2400. * slide-width should be multiple of 8
  2401. * slice-width should be atlease 64 pixels
  2402. */
  2403. if ((priv_info->vdc.slice_width & 7) ||
  2404. (priv_info->vdc.slice_width < 64)) {
  2405. DSI_ERR("invalid slice width:%d\n", priv_info->vdc.slice_width);
  2406. rc = -EINVAL;
  2407. goto error;
  2408. }
  2409. rc = utils->read_u32(utils->data, "qcom,vdc-slice-per-pkt", &data);
  2410. if (rc) {
  2411. DSI_ERR("failed to parse qcom,vdc-slice-per-pkt\n");
  2412. goto error;
  2413. } else if (!data || (data > 2)) {
  2414. DSI_ERR("invalid vdc slice-per-pkt:%d\n", data);
  2415. rc = -EINVAL;
  2416. goto error;
  2417. }
  2418. intf_width = mode->timing.h_active;
  2419. priv_info->vdc.slice_per_pkt = data;
  2420. priv_info->vdc.frame_width = mode->timing.h_active;
  2421. priv_info->vdc.frame_height = mode->timing.v_active;
  2422. rc = utils->read_u32(utils->data, "qcom,vdc-bit-per-component",
  2423. &data);
  2424. if (rc) {
  2425. DSI_ERR("failed to parse qcom,vdc-bit-per-component\n");
  2426. goto error;
  2427. }
  2428. priv_info->vdc.bits_per_component = data;
  2429. rc = utils->read_u32(utils->data, "qcom,mdss-pps-delay-ms", &data);
  2430. if (rc) {
  2431. DSI_DEBUG("pps-delay-ms not specified, defaulting to 0\n");
  2432. data = 0;
  2433. }
  2434. priv_info->vdc.pps_delay_ms = data;
  2435. rc = utils->read_u32(utils->data, "qcom,vdc-bit-per-pixel",
  2436. &data);
  2437. if (rc) {
  2438. DSI_ERR("failed to parse qcom,vdc-bit-per-pixel\n");
  2439. goto error;
  2440. }
  2441. priv_info->vdc.bits_per_pixel = data << 4;
  2442. rc = utils->read_u32(utils->data, "qcom,src-chroma-format",
  2443. &data);
  2444. if (rc) {
  2445. DSI_DEBUG("failed to parse qcom,src-chroma-format\n");
  2446. rc = 0;
  2447. data = MSM_CHROMA_444;
  2448. }
  2449. priv_info->vdc.chroma_format = data;
  2450. rc = utils->read_u32(utils->data, "qcom,src-color-space",
  2451. &data);
  2452. if (rc) {
  2453. DSI_DEBUG("failed to parse qcom,src-color-space\n");
  2454. rc = 0;
  2455. data = MSM_RGB;
  2456. }
  2457. priv_info->vdc.source_color_space = data;
  2458. rc = sde_vdc_populate_config(&priv_info->vdc,
  2459. intf_width, traffic_mode);
  2460. if (rc) {
  2461. DSI_DEBUG("failed populating vdc config\n");
  2462. rc = -EINVAL;
  2463. goto error;
  2464. }
  2465. priv_info->pclk_scale.numer =
  2466. priv_info->vdc.bits_per_pixel >> 4;
  2467. priv_info->pclk_scale.denom = msm_get_src_bpc(
  2468. priv_info->vdc.chroma_format,
  2469. priv_info->vdc.bits_per_component);
  2470. mode->timing.vdc_enabled = true;
  2471. mode->timing.vdc = &priv_info->vdc;
  2472. mode->timing.pclk_scale = priv_info->pclk_scale;
  2473. error:
  2474. return rc;
  2475. }
  2476. static int dsi_panel_parse_hdr_config(struct dsi_panel *panel)
  2477. {
  2478. int rc = 0;
  2479. struct drm_panel_hdr_properties *hdr_prop;
  2480. struct dsi_parser_utils *utils = &panel->utils;
  2481. hdr_prop = &panel->hdr_props;
  2482. hdr_prop->hdr_enabled = utils->read_bool(utils->data,
  2483. "qcom,mdss-dsi-panel-hdr-enabled");
  2484. if (hdr_prop->hdr_enabled) {
  2485. rc = utils->read_u32_array(utils->data,
  2486. "qcom,mdss-dsi-panel-hdr-color-primaries",
  2487. hdr_prop->display_primaries,
  2488. DISPLAY_PRIMARIES_MAX);
  2489. if (rc) {
  2490. DSI_ERR("%s:%d, Unable to read color primaries,rc:%u\n",
  2491. __func__, __LINE__, rc);
  2492. hdr_prop->hdr_enabled = false;
  2493. return rc;
  2494. }
  2495. rc = utils->read_u32(utils->data,
  2496. "qcom,mdss-dsi-panel-peak-brightness",
  2497. &(hdr_prop->peak_brightness));
  2498. if (rc) {
  2499. DSI_ERR("%s:%d, Unable to read hdr brightness, rc:%u\n",
  2500. __func__, __LINE__, rc);
  2501. hdr_prop->hdr_enabled = false;
  2502. return rc;
  2503. }
  2504. rc = utils->read_u32(utils->data,
  2505. "qcom,mdss-dsi-panel-blackness-level",
  2506. &(hdr_prop->blackness_level));
  2507. if (rc) {
  2508. DSI_ERR("%s:%d, Unable to read hdr brightness, rc:%u\n",
  2509. __func__, __LINE__, rc);
  2510. hdr_prop->hdr_enabled = false;
  2511. return rc;
  2512. }
  2513. }
  2514. return 0;
  2515. }
  2516. static int dsi_panel_parse_topology(
  2517. struct dsi_display_mode_priv_info *priv_info,
  2518. struct dsi_parser_utils *utils,
  2519. int topology_override)
  2520. {
  2521. struct msm_display_topology *topology;
  2522. u32 top_count, top_sel, *array = NULL;
  2523. int i, len = 0;
  2524. int rc = -EINVAL;
  2525. len = utils->count_u32_elems(utils->data, "qcom,display-topology");
  2526. if (len <= 0 || len % TOPOLOGY_SET_LEN ||
  2527. len > (TOPOLOGY_SET_LEN * MAX_TOPOLOGY)) {
  2528. DSI_ERR("invalid topology list for the panel, rc = %d\n", rc);
  2529. return rc;
  2530. }
  2531. top_count = len / TOPOLOGY_SET_LEN;
  2532. array = kcalloc(len, sizeof(u32), GFP_KERNEL);
  2533. if (!array)
  2534. return -ENOMEM;
  2535. rc = utils->read_u32_array(utils->data,
  2536. "qcom,display-topology", array, len);
  2537. if (rc) {
  2538. DSI_ERR("unable to read the display topologies, rc = %d\n", rc);
  2539. goto read_fail;
  2540. }
  2541. topology = kcalloc(top_count, sizeof(*topology), GFP_KERNEL);
  2542. if (!topology) {
  2543. rc = -ENOMEM;
  2544. goto read_fail;
  2545. }
  2546. for (i = 0; i < top_count; i++) {
  2547. struct msm_display_topology *top = &topology[i];
  2548. top->num_lm = array[i * TOPOLOGY_SET_LEN];
  2549. top->num_enc = array[i * TOPOLOGY_SET_LEN + 1];
  2550. top->num_intf = array[i * TOPOLOGY_SET_LEN + 2];
  2551. }
  2552. if (topology_override >= 0 && topology_override < top_count) {
  2553. DSI_INFO("override topology: cfg:%d lm:%d comp_enc:%d intf:%d\n",
  2554. topology_override,
  2555. topology[topology_override].num_lm,
  2556. topology[topology_override].num_enc,
  2557. topology[topology_override].num_intf);
  2558. top_sel = topology_override;
  2559. goto parse_done;
  2560. }
  2561. rc = utils->read_u32(utils->data,
  2562. "qcom,default-topology-index", &top_sel);
  2563. if (rc) {
  2564. DSI_ERR("no default topology selected, rc = %d\n", rc);
  2565. goto parse_fail;
  2566. }
  2567. if (top_sel >= top_count) {
  2568. rc = -EINVAL;
  2569. DSI_ERR("default topology is specified is not valid, rc = %d\n",
  2570. rc);
  2571. goto parse_fail;
  2572. }
  2573. if (!(priv_info->dsc_enabled || priv_info->vdc_enabled) !=
  2574. !topology[top_sel].num_enc) {
  2575. DSI_ERR("topology and compression info mismatch dsc:%d vdc:%d num_enc:%d\n",
  2576. priv_info->dsc_enabled, priv_info->vdc_enabled,
  2577. topology[top_sel].num_enc);
  2578. goto parse_fail;
  2579. }
  2580. if (priv_info->dsc_enabled)
  2581. topology[top_sel].comp_type = MSM_DISPLAY_COMPRESSION_DSC;
  2582. else if (priv_info->vdc_enabled)
  2583. topology[top_sel].comp_type = MSM_DISPLAY_COMPRESSION_VDC;
  2584. DSI_INFO("default topology: lm: %d comp_enc:%d intf: %d\n",
  2585. topology[top_sel].num_lm,
  2586. topology[top_sel].num_enc,
  2587. topology[top_sel].num_intf);
  2588. parse_done:
  2589. memcpy(&priv_info->topology, &topology[top_sel],
  2590. sizeof(struct msm_display_topology));
  2591. parse_fail:
  2592. kfree(topology);
  2593. read_fail:
  2594. kfree(array);
  2595. return rc;
  2596. }
  2597. static int dsi_panel_parse_roi_alignment(struct dsi_parser_utils *utils,
  2598. struct msm_roi_alignment *align)
  2599. {
  2600. int len = 0, rc = 0;
  2601. u32 value[6];
  2602. struct property *data;
  2603. if (!align)
  2604. return -EINVAL;
  2605. memset(align, 0, sizeof(*align));
  2606. data = utils->find_property(utils->data,
  2607. "qcom,panel-roi-alignment", &len);
  2608. len /= sizeof(u32);
  2609. if (!data) {
  2610. DSI_ERR("panel roi alignment not found\n");
  2611. rc = -EINVAL;
  2612. } else if (len != 6) {
  2613. DSI_ERR("incorrect roi alignment len %d\n", len);
  2614. rc = -EINVAL;
  2615. } else {
  2616. rc = utils->read_u32_array(utils->data,
  2617. "qcom,panel-roi-alignment", value, len);
  2618. if (rc)
  2619. DSI_DEBUG("error reading panel roi alignment values\n");
  2620. else {
  2621. align->xstart_pix_align = value[0];
  2622. align->ystart_pix_align = value[1];
  2623. align->width_pix_align = value[2];
  2624. align->height_pix_align = value[3];
  2625. align->min_width = value[4];
  2626. align->min_height = value[5];
  2627. }
  2628. DSI_INFO("roi alignment: [%d, %d, %d, %d, %d, %d]\n",
  2629. align->xstart_pix_align,
  2630. align->width_pix_align,
  2631. align->ystart_pix_align,
  2632. align->height_pix_align,
  2633. align->min_width,
  2634. align->min_height);
  2635. }
  2636. return rc;
  2637. }
  2638. static int dsi_panel_parse_partial_update_caps(struct dsi_display_mode *mode,
  2639. struct dsi_parser_utils *utils)
  2640. {
  2641. struct msm_roi_caps *roi_caps = NULL;
  2642. const char *data;
  2643. int rc = 0;
  2644. if (!mode || !mode->priv_info) {
  2645. DSI_ERR("invalid arguments\n");
  2646. return -EINVAL;
  2647. }
  2648. roi_caps = &mode->priv_info->roi_caps;
  2649. memset(roi_caps, 0, sizeof(*roi_caps));
  2650. data = utils->get_property(utils->data,
  2651. "qcom,partial-update-enabled", NULL);
  2652. if (data) {
  2653. if (!strcmp(data, "dual_roi"))
  2654. roi_caps->num_roi = 2;
  2655. else if (!strcmp(data, "single_roi"))
  2656. roi_caps->num_roi = 1;
  2657. else {
  2658. DSI_INFO(
  2659. "invalid value for qcom,partial-update-enabled: %s\n",
  2660. data);
  2661. return 0;
  2662. }
  2663. } else {
  2664. DSI_DEBUG("partial update disabled as the property is not set\n");
  2665. return 0;
  2666. }
  2667. roi_caps->merge_rois = utils->read_bool(utils->data,
  2668. "qcom,partial-update-roi-merge");
  2669. roi_caps->enabled = roi_caps->num_roi > 0;
  2670. DSI_DEBUG("partial update num_rois=%d enabled=%d\n", roi_caps->num_roi,
  2671. roi_caps->enabled);
  2672. if (roi_caps->enabled)
  2673. rc = dsi_panel_parse_roi_alignment(utils,
  2674. &roi_caps->align);
  2675. if (rc)
  2676. memset(roi_caps, 0, sizeof(*roi_caps));
  2677. return rc;
  2678. }
  2679. static bool dsi_panel_parse_panel_mode_caps(struct dsi_display_mode *mode,
  2680. struct dsi_parser_utils *utils)
  2681. {
  2682. if (!mode || !mode->priv_info) {
  2683. DSI_ERR("invalid arguments\n");
  2684. return false;
  2685. }
  2686. if (utils->read_bool(utils->data, "qcom,mdss-dsi-video-mode"))
  2687. mode->panel_mode_caps |= DSI_OP_VIDEO_MODE;
  2688. if (utils->read_bool(utils->data, "qcom,mdss-dsi-cmd-mode"))
  2689. mode->panel_mode_caps |= DSI_OP_CMD_MODE;
  2690. if (!mode->panel_mode_caps)
  2691. return false;
  2692. return true;
  2693. };
  2694. static int dsi_panel_parse_dms_info(struct dsi_panel *panel)
  2695. {
  2696. int dms_enabled;
  2697. const char *data;
  2698. struct dsi_parser_utils *utils = &panel->utils;
  2699. panel->dms_mode = DSI_DMS_MODE_DISABLED;
  2700. dms_enabled = utils->read_bool(utils->data,
  2701. "qcom,dynamic-mode-switch-enabled");
  2702. if (!dms_enabled)
  2703. return 0;
  2704. data = utils->get_property(utils->data,
  2705. "qcom,dynamic-mode-switch-type", NULL);
  2706. if (data && !strcmp(data, "dynamic-resolution-switch-immediate")) {
  2707. panel->dms_mode = DSI_DMS_MODE_RES_SWITCH_IMMEDIATE;
  2708. } else {
  2709. DSI_ERR("[%s] unsupported dynamic switch mode: %s\n",
  2710. panel->name, data);
  2711. return -EINVAL;
  2712. }
  2713. return 0;
  2714. };
  2715. /*
  2716. * The length of all the valid values to be checked should not be greater
  2717. * than the length of returned data from read command.
  2718. */
  2719. static bool
  2720. dsi_panel_parse_esd_check_valid_params(struct dsi_panel *panel, u32 count)
  2721. {
  2722. int i;
  2723. struct drm_panel_esd_config *config = &panel->esd_config;
  2724. for (i = 0; i < count; ++i) {
  2725. if (config->status_valid_params[i] >
  2726. config->status_cmds_rlen[i]) {
  2727. DSI_DEBUG("ignore valid params\n");
  2728. return false;
  2729. }
  2730. }
  2731. return true;
  2732. }
  2733. static bool dsi_panel_parse_esd_status_len(struct dsi_parser_utils *utils,
  2734. char *prop_key, u32 **target, u32 cmd_cnt)
  2735. {
  2736. int tmp;
  2737. if (!utils->find_property(utils->data, prop_key, &tmp))
  2738. return false;
  2739. tmp /= sizeof(u32);
  2740. if (tmp != cmd_cnt) {
  2741. DSI_ERR("request property(%d) do not match cmd count(%d)\n",
  2742. tmp, cmd_cnt);
  2743. return false;
  2744. }
  2745. *target = kcalloc(tmp, sizeof(u32), GFP_KERNEL);
  2746. if (IS_ERR_OR_NULL(*target)) {
  2747. DSI_ERR("Error allocating memory for property\n");
  2748. return false;
  2749. }
  2750. if (utils->read_u32_array(utils->data, prop_key, *target, tmp)) {
  2751. DSI_ERR("cannot get values from dts\n");
  2752. kfree(*target);
  2753. *target = NULL;
  2754. return false;
  2755. }
  2756. return true;
  2757. }
  2758. static void dsi_panel_esd_config_deinit(struct drm_panel_esd_config *esd_config)
  2759. {
  2760. kfree(esd_config->status_buf);
  2761. kfree(esd_config->return_buf);
  2762. kfree(esd_config->status_value);
  2763. kfree(esd_config->status_valid_params);
  2764. kfree(esd_config->status_cmds_rlen);
  2765. kfree(esd_config->status_cmd.cmds);
  2766. }
  2767. int dsi_panel_parse_esd_reg_read_configs(struct dsi_panel *panel)
  2768. {
  2769. struct drm_panel_esd_config *esd_config;
  2770. int rc = 0;
  2771. u32 tmp;
  2772. u32 i, status_len, *lenp;
  2773. struct property *data;
  2774. struct dsi_parser_utils *utils = &panel->utils;
  2775. if (!panel) {
  2776. DSI_ERR("Invalid Params\n");
  2777. return -EINVAL;
  2778. }
  2779. esd_config = &panel->esd_config;
  2780. if (!esd_config)
  2781. return -EINVAL;
  2782. dsi_panel_parse_cmd_sets_sub(&esd_config->status_cmd,
  2783. DSI_CMD_SET_PANEL_STATUS, utils);
  2784. if (!esd_config->status_cmd.count) {
  2785. DSI_ERR("panel status command parsing failed\n");
  2786. rc = -EINVAL;
  2787. goto error;
  2788. }
  2789. if (!dsi_panel_parse_esd_status_len(utils,
  2790. "qcom,mdss-dsi-panel-status-read-length",
  2791. &panel->esd_config.status_cmds_rlen,
  2792. esd_config->status_cmd.count)) {
  2793. DSI_ERR("Invalid status read length\n");
  2794. rc = -EINVAL;
  2795. goto error1;
  2796. }
  2797. if (dsi_panel_parse_esd_status_len(utils,
  2798. "qcom,mdss-dsi-panel-status-valid-params",
  2799. &panel->esd_config.status_valid_params,
  2800. esd_config->status_cmd.count)) {
  2801. if (!dsi_panel_parse_esd_check_valid_params(panel,
  2802. esd_config->status_cmd.count)) {
  2803. rc = -EINVAL;
  2804. goto error2;
  2805. }
  2806. }
  2807. status_len = 0;
  2808. lenp = esd_config->status_valid_params ?: esd_config->status_cmds_rlen;
  2809. for (i = 0; i < esd_config->status_cmd.count; ++i)
  2810. status_len += lenp[i];
  2811. if (!status_len) {
  2812. rc = -EINVAL;
  2813. goto error2;
  2814. }
  2815. /*
  2816. * Some panel may need multiple read commands to properly
  2817. * check panel status. Do a sanity check for proper status
  2818. * value which will be compared with the value read by dsi
  2819. * controller during ESD check. Also check if multiple read
  2820. * commands are there then, there should be corresponding
  2821. * status check values for each read command.
  2822. */
  2823. data = utils->find_property(utils->data,
  2824. "qcom,mdss-dsi-panel-status-value", &tmp);
  2825. tmp /= sizeof(u32);
  2826. if (!IS_ERR_OR_NULL(data) && tmp != 0 && (tmp % status_len) == 0) {
  2827. esd_config->groups = tmp / status_len;
  2828. } else {
  2829. DSI_ERR("error parse panel-status-value\n");
  2830. rc = -EINVAL;
  2831. goto error2;
  2832. }
  2833. esd_config->status_value =
  2834. kzalloc(sizeof(u32) * status_len * esd_config->groups,
  2835. GFP_KERNEL);
  2836. if (!esd_config->status_value) {
  2837. rc = -ENOMEM;
  2838. goto error2;
  2839. }
  2840. esd_config->return_buf = kcalloc(status_len * esd_config->groups,
  2841. sizeof(unsigned char), GFP_KERNEL);
  2842. if (!esd_config->return_buf) {
  2843. rc = -ENOMEM;
  2844. goto error3;
  2845. }
  2846. esd_config->status_buf = kzalloc(SZ_4K, GFP_KERNEL);
  2847. if (!esd_config->status_buf) {
  2848. rc = -ENOMEM;
  2849. goto error4;
  2850. }
  2851. rc = utils->read_u32_array(utils->data,
  2852. "qcom,mdss-dsi-panel-status-value",
  2853. esd_config->status_value, esd_config->groups * status_len);
  2854. if (rc) {
  2855. DSI_DEBUG("error reading panel status values\n");
  2856. memset(esd_config->status_value, 0,
  2857. esd_config->groups * status_len);
  2858. }
  2859. return 0;
  2860. error4:
  2861. kfree(esd_config->return_buf);
  2862. error3:
  2863. kfree(esd_config->status_value);
  2864. error2:
  2865. kfree(esd_config->status_valid_params);
  2866. kfree(esd_config->status_cmds_rlen);
  2867. error1:
  2868. kfree(esd_config->status_cmd.cmds);
  2869. error:
  2870. return rc;
  2871. }
  2872. static int dsi_panel_parse_esd_config(struct dsi_panel *panel)
  2873. {
  2874. int rc = 0;
  2875. const char *string;
  2876. struct drm_panel_esd_config *esd_config;
  2877. struct dsi_parser_utils *utils = &panel->utils;
  2878. u8 *esd_mode = NULL;
  2879. esd_config = &panel->esd_config;
  2880. esd_config->status_mode = ESD_MODE_MAX;
  2881. esd_config->esd_enabled = utils->read_bool(utils->data,
  2882. "qcom,esd-check-enabled");
  2883. if (!esd_config->esd_enabled)
  2884. return 0;
  2885. rc = utils->read_string(utils->data,
  2886. "qcom,mdss-dsi-panel-status-check-mode", &string);
  2887. if (!rc) {
  2888. if (!strcmp(string, "bta_check")) {
  2889. esd_config->status_mode = ESD_MODE_SW_BTA;
  2890. } else if (!strcmp(string, "reg_read")) {
  2891. esd_config->status_mode = ESD_MODE_REG_READ;
  2892. } else if (!strcmp(string, "te_signal_check")) {
  2893. if (panel->panel_mode == DSI_OP_CMD_MODE) {
  2894. esd_config->status_mode = ESD_MODE_PANEL_TE;
  2895. } else {
  2896. DSI_ERR("TE-ESD not valid for video mode\n");
  2897. rc = -EINVAL;
  2898. goto error;
  2899. }
  2900. } else {
  2901. DSI_ERR("No valid panel-status-check-mode string\n");
  2902. rc = -EINVAL;
  2903. goto error;
  2904. }
  2905. } else {
  2906. DSI_DEBUG("status check method not defined!\n");
  2907. rc = -EINVAL;
  2908. goto error;
  2909. }
  2910. if (panel->esd_config.status_mode == ESD_MODE_REG_READ) {
  2911. rc = dsi_panel_parse_esd_reg_read_configs(panel);
  2912. if (rc) {
  2913. DSI_ERR("failed to parse esd reg read mode params, rc=%d\n",
  2914. rc);
  2915. goto error;
  2916. }
  2917. esd_mode = "register_read";
  2918. } else if (panel->esd_config.status_mode == ESD_MODE_SW_BTA) {
  2919. esd_mode = "bta_trigger";
  2920. } else if (panel->esd_config.status_mode == ESD_MODE_PANEL_TE) {
  2921. esd_mode = "te_check";
  2922. }
  2923. DSI_DEBUG("ESD enabled with mode: %s\n", esd_mode);
  2924. return 0;
  2925. error:
  2926. panel->esd_config.esd_enabled = false;
  2927. return rc;
  2928. }
  2929. static void dsi_panel_update_util(struct dsi_panel *panel,
  2930. struct device_node *parser_node)
  2931. {
  2932. struct dsi_parser_utils *utils = &panel->utils;
  2933. if (parser_node) {
  2934. *utils = *dsi_parser_get_parser_utils();
  2935. utils->data = parser_node;
  2936. DSI_DEBUG("switching to parser APIs\n");
  2937. goto end;
  2938. }
  2939. *utils = *dsi_parser_get_of_utils();
  2940. utils->data = panel->panel_of_node;
  2941. end:
  2942. utils->node = panel->panel_of_node;
  2943. }
  2944. static int dsi_panel_vm_stub(struct dsi_panel *panel)
  2945. {
  2946. return 0;
  2947. }
  2948. static void dsi_panel_setup_vm_ops(struct dsi_panel *panel, bool trusted_vm_env)
  2949. {
  2950. if (trusted_vm_env) {
  2951. panel->panel_ops.pinctrl_init = dsi_panel_vm_stub;
  2952. panel->panel_ops.gpio_request = dsi_panel_vm_stub;
  2953. panel->panel_ops.pinctrl_deinit = dsi_panel_vm_stub;
  2954. panel->panel_ops.gpio_release = dsi_panel_vm_stub;
  2955. panel->panel_ops.bl_register = dsi_panel_vm_stub;
  2956. panel->panel_ops.bl_unregister = dsi_panel_vm_stub;
  2957. panel->panel_ops.parse_gpios = dsi_panel_vm_stub;
  2958. panel->panel_ops.parse_power_cfg = dsi_panel_vm_stub;
  2959. panel->panel_ops.trigger_esd_attack = dsi_panel_vm_trigger_esd_attack;
  2960. } else {
  2961. panel->panel_ops.pinctrl_init = dsi_panel_pinctrl_init;
  2962. panel->panel_ops.gpio_request = dsi_panel_gpio_request;
  2963. panel->panel_ops.pinctrl_deinit = dsi_panel_pinctrl_deinit;
  2964. panel->panel_ops.gpio_release = dsi_panel_gpio_release;
  2965. panel->panel_ops.bl_register = dsi_panel_bl_register;
  2966. panel->panel_ops.bl_unregister = dsi_panel_bl_unregister;
  2967. panel->panel_ops.parse_gpios = dsi_panel_parse_gpios;
  2968. panel->panel_ops.parse_power_cfg = dsi_panel_parse_power_cfg;
  2969. panel->panel_ops.trigger_esd_attack = dsi_panel_trigger_esd_attack;
  2970. }
  2971. }
  2972. struct dsi_panel *dsi_panel_get(struct device *parent,
  2973. struct device_node *of_node,
  2974. struct device_node *parser_node,
  2975. const char *type,
  2976. int topology_override,
  2977. bool trusted_vm_env)
  2978. {
  2979. struct dsi_panel *panel;
  2980. struct dsi_parser_utils *utils;
  2981. const char *panel_physical_type;
  2982. int rc = 0;
  2983. panel = kzalloc(sizeof(*panel), GFP_KERNEL);
  2984. if (!panel)
  2985. return ERR_PTR(-ENOMEM);
  2986. dsi_panel_setup_vm_ops(panel, trusted_vm_env);
  2987. panel->panel_of_node = of_node;
  2988. panel->parent = parent;
  2989. panel->type = type;
  2990. dsi_panel_update_util(panel, parser_node);
  2991. utils = &panel->utils;
  2992. panel->name = utils->get_property(utils->data,
  2993. "qcom,mdss-dsi-panel-name", NULL);
  2994. if (!panel->name)
  2995. panel->name = DSI_PANEL_DEFAULT_LABEL;
  2996. /*
  2997. * Set panel type to LCD as default.
  2998. */
  2999. panel->panel_type = DSI_DISPLAY_PANEL_TYPE_LCD;
  3000. panel_physical_type = utils->get_property(utils->data,
  3001. "qcom,mdss-dsi-panel-physical-type", NULL);
  3002. if (panel_physical_type && !strcmp(panel_physical_type, "oled"))
  3003. panel->panel_type = DSI_DISPLAY_PANEL_TYPE_OLED;
  3004. rc = dsi_panel_parse_host_config(panel);
  3005. if (rc) {
  3006. DSI_ERR("failed to parse host configuration, rc=%d\n",
  3007. rc);
  3008. goto error;
  3009. }
  3010. rc = dsi_panel_parse_panel_mode(panel);
  3011. if (rc) {
  3012. DSI_ERR("failed to parse panel mode configuration, rc=%d\n",
  3013. rc);
  3014. goto error;
  3015. }
  3016. rc = dsi_panel_parse_dfps_caps(panel);
  3017. if (rc)
  3018. DSI_ERR("failed to parse dfps configuration, rc=%d\n", rc);
  3019. rc = dsi_panel_parse_qsync_caps(panel, of_node);
  3020. if (rc)
  3021. DSI_DEBUG("failed to parse qsync features, rc=%d\n", rc);
  3022. rc = dsi_panel_parse_avr_caps(panel, of_node);
  3023. if (rc)
  3024. DSI_ERR("failed to parse AVR features, rc=%d\n", rc);
  3025. rc = dsi_panel_parse_dyn_clk_caps(panel);
  3026. if (rc)
  3027. DSI_ERR("failed to parse dynamic clk config, rc=%d\n", rc);
  3028. rc = dsi_panel_parse_phy_props(panel);
  3029. if (rc) {
  3030. DSI_ERR("failed to parse panel physical dimension, rc=%d\n",
  3031. rc);
  3032. goto error;
  3033. }
  3034. rc = panel->panel_ops.parse_gpios(panel);
  3035. if (rc) {
  3036. DSI_ERR("failed to parse panel gpios, rc=%d\n", rc);
  3037. goto error;
  3038. }
  3039. rc = panel->panel_ops.parse_power_cfg(panel);
  3040. if (rc)
  3041. DSI_ERR("failed to parse power config, rc=%d\n", rc);
  3042. rc = dsi_panel_parse_bl_config(panel);
  3043. if (rc) {
  3044. DSI_ERR("failed to parse backlight config, rc=%d\n", rc);
  3045. if (rc == -EPROBE_DEFER)
  3046. goto error;
  3047. }
  3048. rc = dsi_panel_parse_misc_features(panel);
  3049. if (rc)
  3050. DSI_ERR("failed to parse misc features, rc=%d\n", rc);
  3051. rc = dsi_panel_parse_hdr_config(panel);
  3052. if (rc)
  3053. DSI_ERR("failed to parse hdr config, rc=%d\n", rc);
  3054. rc = dsi_panel_get_mode_count(panel);
  3055. if (rc) {
  3056. DSI_ERR("failed to get mode count, rc=%d\n", rc);
  3057. goto error;
  3058. }
  3059. rc = dsi_panel_parse_dms_info(panel);
  3060. if (rc)
  3061. DSI_DEBUG("failed to get dms info, rc=%d\n", rc);
  3062. rc = dsi_panel_parse_esd_config(panel);
  3063. if (rc)
  3064. DSI_DEBUG("failed to parse esd config, rc=%d\n", rc);
  3065. rc = dsi_panel_vreg_get(panel);
  3066. if (rc) {
  3067. DSI_ERR("[%s] failed to get panel regulators, rc=%d\n",
  3068. panel->name, rc);
  3069. goto error;
  3070. }
  3071. panel->power_mode = SDE_MODE_DPMS_OFF;
  3072. drm_panel_init(&panel->drm_panel, &panel->mipi_device.dev,
  3073. NULL, DRM_MODE_CONNECTOR_DSI);
  3074. panel->mipi_device.dev.of_node = of_node;
  3075. drm_panel_add(&panel->drm_panel);
  3076. mutex_init(&panel->panel_lock);
  3077. return panel;
  3078. error:
  3079. kfree(panel);
  3080. return ERR_PTR(rc);
  3081. }
  3082. void dsi_panel_put(struct dsi_panel *panel)
  3083. {
  3084. drm_panel_remove(&panel->drm_panel);
  3085. /* free resources allocated for ESD check */
  3086. dsi_panel_esd_config_deinit(&panel->esd_config);
  3087. kfree(panel->avr_caps.avr_step_fps_list);
  3088. kfree(panel);
  3089. }
  3090. int dsi_panel_drv_init(struct dsi_panel *panel,
  3091. struct mipi_dsi_host *host)
  3092. {
  3093. int rc = 0;
  3094. struct mipi_dsi_device *dev;
  3095. if (!panel || !host) {
  3096. DSI_ERR("invalid params\n");
  3097. return -EINVAL;
  3098. }
  3099. mutex_lock(&panel->panel_lock);
  3100. dev = &panel->mipi_device;
  3101. dev->host = host;
  3102. /*
  3103. * We dont have device structure since panel is not a device node.
  3104. * When using drm panel framework, the device is probed when the host is
  3105. * create.
  3106. */
  3107. dev->channel = 0;
  3108. dev->lanes = 4;
  3109. panel->host = host;
  3110. rc = panel->panel_ops.pinctrl_init(panel);
  3111. if (rc) {
  3112. DSI_ERR("[%s] failed to init pinctrl, rc=%d\n",
  3113. panel->name, rc);
  3114. goto exit;
  3115. }
  3116. rc = panel->panel_ops.gpio_request(panel);
  3117. if (rc) {
  3118. DSI_ERR("[%s] failed to request gpios, rc=%d\n", panel->name,
  3119. rc);
  3120. goto error_pinctrl_deinit;
  3121. }
  3122. rc = panel->panel_ops.bl_register(panel);
  3123. if (rc) {
  3124. if (rc != -EPROBE_DEFER)
  3125. DSI_ERR("[%s] failed to register backlight, rc=%d\n",
  3126. panel->name, rc);
  3127. goto error_gpio_release;
  3128. }
  3129. goto exit;
  3130. error_gpio_release:
  3131. (void)dsi_panel_gpio_release(panel);
  3132. error_pinctrl_deinit:
  3133. (void)dsi_panel_pinctrl_deinit(panel);
  3134. exit:
  3135. mutex_unlock(&panel->panel_lock);
  3136. return rc;
  3137. }
  3138. int dsi_panel_drv_deinit(struct dsi_panel *panel)
  3139. {
  3140. int rc = 0;
  3141. if (!panel) {
  3142. DSI_ERR("invalid params\n");
  3143. return -EINVAL;
  3144. }
  3145. mutex_lock(&panel->panel_lock);
  3146. rc = panel->panel_ops.bl_unregister(panel);
  3147. if (rc)
  3148. DSI_ERR("[%s] failed to unregister backlight, rc=%d\n",
  3149. panel->name, rc);
  3150. rc = panel->panel_ops.gpio_release(panel);
  3151. if (rc)
  3152. DSI_ERR("[%s] failed to release gpios, rc=%d\n", panel->name,
  3153. rc);
  3154. rc = panel->panel_ops.pinctrl_deinit(panel);
  3155. if (rc)
  3156. DSI_ERR("[%s] failed to deinit gpios, rc=%d\n", panel->name,
  3157. rc);
  3158. rc = dsi_panel_vreg_put(panel);
  3159. if (rc)
  3160. DSI_ERR("[%s] failed to put regs, rc=%d\n", panel->name, rc);
  3161. panel->host = NULL;
  3162. memset(&panel->mipi_device, 0x0, sizeof(panel->mipi_device));
  3163. mutex_unlock(&panel->panel_lock);
  3164. return rc;
  3165. }
  3166. int dsi_panel_validate_mode(struct dsi_panel *panel,
  3167. struct dsi_display_mode *mode)
  3168. {
  3169. return 0;
  3170. }
  3171. static int dsi_panel_get_max_res_count(struct dsi_parser_utils *utils,
  3172. struct device_node *node, u32 *dsc_count, u32 *lm_count)
  3173. {
  3174. const char *compression;
  3175. u32 *array = NULL, top_count, len, i;
  3176. int rc = -EINVAL;
  3177. bool dsc_enable = false;
  3178. *dsc_count = 0;
  3179. *lm_count = 0;
  3180. compression = utils->get_property(node, "qcom,compression-mode", NULL);
  3181. if (compression && !strcmp(compression, "dsc"))
  3182. dsc_enable = true;
  3183. len = utils->count_u32_elems(node, "qcom,display-topology");
  3184. if (len <= 0 || len % TOPOLOGY_SET_LEN ||
  3185. len > (TOPOLOGY_SET_LEN * MAX_TOPOLOGY))
  3186. return rc;
  3187. top_count = len / TOPOLOGY_SET_LEN;
  3188. array = kcalloc(len, sizeof(u32), GFP_KERNEL);
  3189. if (!array)
  3190. return -ENOMEM;
  3191. rc = utils->read_u32_array(node, "qcom,display-topology", array, len);
  3192. if (rc) {
  3193. DSI_ERR("unable to read the display topologies, rc = %d\n", rc);
  3194. goto read_fail;
  3195. }
  3196. for (i = 0; i < top_count; i++) {
  3197. *lm_count = max(*lm_count, array[i * TOPOLOGY_SET_LEN]);
  3198. if (dsc_enable)
  3199. *dsc_count = max(*dsc_count,
  3200. array[i * TOPOLOGY_SET_LEN + 1]);
  3201. }
  3202. read_fail:
  3203. kfree(array);
  3204. return 0;
  3205. }
  3206. int dsi_panel_get_mode_count(struct dsi_panel *panel)
  3207. {
  3208. const u32 SINGLE_MODE_SUPPORT = 1;
  3209. struct dsi_parser_utils *utils;
  3210. struct device_node *timings_np, *child_np;
  3211. int num_dfps_rates;
  3212. int num_video_modes = 0, num_cmd_modes = 0;
  3213. int count, rc = 0;
  3214. u32 dsc_count = 0, lm_count = 0;
  3215. if (!panel) {
  3216. DSI_ERR("invalid params\n");
  3217. return -EINVAL;
  3218. }
  3219. utils = &panel->utils;
  3220. panel->num_timing_nodes = 0;
  3221. timings_np = utils->get_child_by_name(utils->data,
  3222. "qcom,mdss-dsi-display-timings");
  3223. if (!timings_np && !panel->host_config.ext_bridge_mode) {
  3224. DSI_ERR("no display timing nodes defined\n");
  3225. rc = -EINVAL;
  3226. goto error;
  3227. }
  3228. count = utils->get_child_count(timings_np);
  3229. if ((!count && !panel->host_config.ext_bridge_mode) ||
  3230. count > DSI_MODE_MAX) {
  3231. DSI_ERR("invalid count of timing nodes: %d\n", count);
  3232. rc = -EINVAL;
  3233. goto error;
  3234. }
  3235. /* No multiresolution support is available for video mode panels.
  3236. * Multi-mode is supported for video mode during POMS is enabled.
  3237. */
  3238. if (panel->panel_mode != DSI_OP_CMD_MODE &&
  3239. !panel->host_config.ext_bridge_mode &&
  3240. !panel->panel_mode_switch_enabled)
  3241. count = SINGLE_MODE_SUPPORT;
  3242. panel->num_timing_nodes = count;
  3243. dsi_for_each_child_node(timings_np, child_np) {
  3244. if (utils->read_bool(child_np, "qcom,mdss-dsi-video-mode"))
  3245. num_video_modes++;
  3246. else if (utils->read_bool(child_np,
  3247. "qcom,mdss-dsi-cmd-mode"))
  3248. num_cmd_modes++;
  3249. else if (panel->panel_mode == DSI_OP_VIDEO_MODE)
  3250. num_video_modes++;
  3251. else if (panel->panel_mode == DSI_OP_CMD_MODE)
  3252. num_cmd_modes++;
  3253. dsi_panel_get_max_res_count(utils, child_np,
  3254. &dsc_count, &lm_count);
  3255. panel->dsc_count = max(dsc_count, panel->dsc_count);
  3256. panel->lm_count = max(lm_count, panel->lm_count);
  3257. }
  3258. num_dfps_rates = !panel->dfps_caps.dfps_support ? 1 :
  3259. panel->dfps_caps.dfps_list_len;
  3260. /*
  3261. * Inflate num_of_modes by fps in dfps.
  3262. * Single command mode for video mode panels supporting
  3263. * panel operating mode switch.
  3264. */
  3265. num_video_modes = num_video_modes * num_dfps_rates;
  3266. if ((panel->panel_mode == DSI_OP_VIDEO_MODE) &&
  3267. (panel->panel_mode_switch_enabled))
  3268. num_cmd_modes = 1;
  3269. panel->num_display_modes = num_video_modes + num_cmd_modes;
  3270. error:
  3271. return rc;
  3272. }
  3273. int dsi_panel_get_phy_props(struct dsi_panel *panel,
  3274. struct dsi_panel_phy_props *phy_props)
  3275. {
  3276. int rc = 0;
  3277. if (!panel || !phy_props) {
  3278. DSI_ERR("invalid params\n");
  3279. return -EINVAL;
  3280. }
  3281. memcpy(phy_props, &panel->phy_props, sizeof(*phy_props));
  3282. return rc;
  3283. }
  3284. int dsi_panel_get_dfps_caps(struct dsi_panel *panel,
  3285. struct dsi_dfps_capabilities *dfps_caps)
  3286. {
  3287. int rc = 0;
  3288. if (!panel || !dfps_caps) {
  3289. DSI_ERR("invalid params\n");
  3290. return -EINVAL;
  3291. }
  3292. memcpy(dfps_caps, &panel->dfps_caps, sizeof(*dfps_caps));
  3293. return rc;
  3294. }
  3295. void dsi_panel_put_mode(struct dsi_display_mode *mode)
  3296. {
  3297. int i;
  3298. if (!mode->priv_info)
  3299. return;
  3300. for (i = 0; i < DSI_CMD_SET_MAX; i++) {
  3301. dsi_panel_destroy_cmd_packets(&mode->priv_info->cmd_sets[i]);
  3302. dsi_panel_dealloc_cmd_packets(&mode->priv_info->cmd_sets[i]);
  3303. }
  3304. kfree(mode->priv_info);
  3305. }
  3306. void dsi_panel_calc_dsi_transfer_time(struct dsi_host_common_cfg *config,
  3307. struct dsi_display_mode *mode, u32 frame_threshold_us)
  3308. {
  3309. u32 frame_time_us, nslices;
  3310. u64 min_bitclk_hz, total_active_pixels, bits_per_line, pclk_rate_hz,
  3311. dsi_transfer_time_us, pixel_clk_khz;
  3312. struct msm_display_dsc_info *dsc = mode->timing.dsc;
  3313. struct dsi_mode_info *timing = &mode->timing;
  3314. struct dsi_display_mode *display_mode;
  3315. u32 jitter_numer, jitter_denom, prefill_lines;
  3316. u32 min_threshold_us, prefill_time_us, max_transfer_us, packet_overhead;
  3317. u16 bpp;
  3318. /* Packet overhead in bits,
  3319. * DPHY: 4 bytes header + 2 bytes checksum + 1 byte dcs data command.
  3320. * CPHY: 8 bytes header + 4 bytes checksum + 2 bytes SYNC +
  3321. * 1 byte dcs data command.
  3322. */
  3323. if (config->phy_type & DSI_PHY_TYPE_CPHY)
  3324. packet_overhead = 120;
  3325. else
  3326. packet_overhead = 56;
  3327. display_mode = container_of(timing, struct dsi_display_mode, timing);
  3328. jitter_numer = display_mode->priv_info->panel_jitter_numer;
  3329. jitter_denom = display_mode->priv_info->panel_jitter_denom;
  3330. frame_time_us = mult_frac(1000, 1000, (timing->refresh_rate));
  3331. if (timing->refresh_rate >= 120)
  3332. frame_threshold_us = HIGH_REFRESH_RATE_THRESHOLD_TIME_US;
  3333. if (timing->dsc_enabled) {
  3334. nslices = (timing->h_active)/(dsc->config.slice_width);
  3335. /* (slice width x bit-per-pixel + packet overhead) x
  3336. * number of slices x height x fps / lane
  3337. */
  3338. bpp = DSC_BPP(dsc->config);
  3339. bits_per_line = ((dsc->config.slice_width * bpp) +
  3340. packet_overhead) * nslices;
  3341. bits_per_line = bits_per_line / (config->num_data_lanes);
  3342. min_bitclk_hz = (bits_per_line * timing->v_active *
  3343. timing->refresh_rate);
  3344. } else {
  3345. total_active_pixels = ((dsi_h_active_dce(timing)
  3346. * timing->v_active));
  3347. /* calculate the actual bitclk needed to transfer the frame */
  3348. min_bitclk_hz = (total_active_pixels * (timing->refresh_rate) *
  3349. (config->bpp));
  3350. do_div(min_bitclk_hz, config->num_data_lanes);
  3351. }
  3352. timing->min_dsi_clk_hz = min_bitclk_hz;
  3353. /*
  3354. * Apart from prefill line time, we need to take into account RSCC mode threshold time. In
  3355. * cases where RSC is disabled, as jitter is no longer considered we need to make sure we
  3356. * have enough time for DCS command transfer. As of now, the RSC threshold time and DCS
  3357. * threshold time are configured to 40us.
  3358. */
  3359. if (mode->priv_info->disable_rsc_solver) {
  3360. min_threshold_us = DCS_COMMAND_THRESHOLD_TIME_US;
  3361. } else {
  3362. min_threshold_us = mult_frac(frame_time_us, jitter_numer, (jitter_denom * 100));
  3363. min_threshold_us += RSCC_MODE_THRESHOLD_TIME_US;
  3364. }
  3365. /*
  3366. * Increase the prefill_lines proportionately as recommended
  3367. * 40lines for 60fps, 60 for 90fps, 120lines for 120fps, and so on.
  3368. */
  3369. prefill_lines = mult_frac(MIN_PREFILL_LINES,
  3370. timing->refresh_rate, 60);
  3371. prefill_time_us = mult_frac(frame_time_us, prefill_lines,
  3372. (timing->v_active));
  3373. min_threshold_us = min_threshold_us + prefill_time_us;
  3374. DSI_DEBUG("min threshold time=%d\n", min_threshold_us);
  3375. if (timing->clk_rate_hz) {
  3376. /* adjust the transfer time proportionately for bit clk*/
  3377. dsi_transfer_time_us = frame_time_us * min_bitclk_hz;
  3378. do_div(dsi_transfer_time_us, timing->clk_rate_hz);
  3379. timing->dsi_transfer_time_us = dsi_transfer_time_us;
  3380. } else if (mode->priv_info->mdp_transfer_time_us) {
  3381. max_transfer_us = frame_time_us - min_threshold_us;
  3382. mode->priv_info->mdp_transfer_time_us = min(
  3383. mode->priv_info->mdp_transfer_time_us,
  3384. max_transfer_us);
  3385. timing->dsi_transfer_time_us =
  3386. mode->priv_info->mdp_transfer_time_us;
  3387. } else {
  3388. if ((min_threshold_us > frame_threshold_us) ||
  3389. (mode->priv_info->disable_rsc_solver))
  3390. frame_threshold_us = min_threshold_us;
  3391. timing->dsi_transfer_time_us = frame_time_us -
  3392. frame_threshold_us;
  3393. }
  3394. timing->mdp_transfer_time_us = timing->dsi_transfer_time_us;
  3395. /* Force update mdp xfer time to hal,if clk and mdp xfer time is set */
  3396. if (mode->priv_info->mdp_transfer_time_us && timing->clk_rate_hz) {
  3397. timing->mdp_transfer_time_us =
  3398. mode->priv_info->mdp_transfer_time_us;
  3399. }
  3400. /* Calculate pclk_khz to update modeinfo */
  3401. pclk_rate_hz = min_bitclk_hz * frame_time_us;
  3402. do_div(pclk_rate_hz, timing->dsi_transfer_time_us);
  3403. pixel_clk_khz = pclk_rate_hz * config->num_data_lanes;
  3404. do_div(pixel_clk_khz, config->bpp);
  3405. display_mode->pixel_clk_khz = pixel_clk_khz;
  3406. display_mode->pixel_clk_khz = display_mode->pixel_clk_khz / 1000;
  3407. }
  3408. int dsi_panel_get_mode(struct dsi_panel *panel,
  3409. u32 index, struct dsi_display_mode *mode,
  3410. int topology_override)
  3411. {
  3412. struct device_node *timings_np, *child_np;
  3413. struct dsi_parser_utils *utils;
  3414. struct dsi_display_mode_priv_info *prv_info;
  3415. u32 child_idx = 0;
  3416. int rc = 0, num_timings;
  3417. int traffic_mode;
  3418. void *utils_data = NULL;
  3419. if (!panel || !mode) {
  3420. DSI_ERR("invalid params\n");
  3421. return -EINVAL;
  3422. }
  3423. mutex_lock(&panel->panel_lock);
  3424. utils = &panel->utils;
  3425. mode->priv_info = kzalloc(sizeof(*mode->priv_info), GFP_KERNEL);
  3426. if (!mode->priv_info) {
  3427. rc = -ENOMEM;
  3428. goto done;
  3429. }
  3430. prv_info = mode->priv_info;
  3431. timings_np = utils->get_child_by_name(utils->data,
  3432. "qcom,mdss-dsi-display-timings");
  3433. if (!timings_np) {
  3434. DSI_ERR("no display timing nodes defined\n");
  3435. rc = -EINVAL;
  3436. goto parse_fail;
  3437. }
  3438. num_timings = utils->get_child_count(timings_np);
  3439. if (!num_timings || num_timings > DSI_MODE_MAX) {
  3440. DSI_ERR("invalid count of timing nodes: %d\n", num_timings);
  3441. rc = -EINVAL;
  3442. goto parse_fail;
  3443. }
  3444. utils_data = utils->data;
  3445. traffic_mode = panel->video_config.traffic_mode;
  3446. dsi_for_each_child_node(timings_np, child_np) {
  3447. if (index != child_idx++)
  3448. continue;
  3449. utils->data = child_np;
  3450. if (panel->panel_mode_switch_enabled) {
  3451. if (!dsi_panel_parse_panel_mode_caps(mode, utils)) {
  3452. mode->panel_mode_caps = panel->panel_mode;
  3453. DSI_INFO("panel mode isn't specified in timing[%d]\n",
  3454. child_idx);
  3455. }
  3456. } else {
  3457. mode->panel_mode_caps = panel->panel_mode;
  3458. }
  3459. rc = utils->read_u32(utils->data, "cell-index", &mode->mode_idx);
  3460. if (rc)
  3461. mode->mode_idx = index;
  3462. rc = dsi_panel_parse_timing(&mode->timing, utils);
  3463. if (rc) {
  3464. DSI_ERR("failed to parse panel timing, rc=%d\n", rc);
  3465. goto parse_fail;
  3466. }
  3467. if (panel->dyn_clk_caps.dyn_clk_support) {
  3468. rc = dsi_panel_parse_dyn_clk_list(mode, utils);
  3469. if (rc)
  3470. DSI_ERR("failed to parse dynamic clk rates, rc=%d\n", rc);
  3471. }
  3472. rc = dsi_panel_parse_dsc_params(mode, utils);
  3473. if (rc) {
  3474. DSI_ERR("failed to parse dsc params, rc=%d\n", rc);
  3475. goto parse_fail;
  3476. }
  3477. rc = dsi_panel_parse_vdc_params(mode, utils, traffic_mode);
  3478. if (rc) {
  3479. DSI_ERR("failed to parse vdc params, rc=%d\n", rc);
  3480. goto parse_fail;
  3481. }
  3482. rc = dsi_panel_parse_topology(prv_info, utils,
  3483. topology_override);
  3484. if (rc) {
  3485. DSI_ERR("failed to parse panel topology, rc=%d\n", rc);
  3486. goto parse_fail;
  3487. }
  3488. rc = dsi_panel_parse_cmd_sets(prv_info, utils);
  3489. if (rc) {
  3490. DSI_ERR("failed to parse command sets, rc=%d\n", rc);
  3491. goto parse_fail;
  3492. }
  3493. rc = dsi_panel_parse_jitter_config(mode, utils);
  3494. if (rc)
  3495. DSI_ERR(
  3496. "failed to parse panel jitter config, rc=%d\n", rc);
  3497. rc = dsi_panel_parse_phy_timing(mode, utils);
  3498. if (rc) {
  3499. DSI_ERR(
  3500. "failed to parse panel phy timings, rc=%d\n", rc);
  3501. goto parse_fail;
  3502. }
  3503. rc = dsi_panel_parse_partial_update_caps(mode, utils);
  3504. if (rc)
  3505. DSI_ERR("failed to partial update caps, rc=%d\n", rc);
  3506. }
  3507. goto done;
  3508. parse_fail:
  3509. kfree(mode->priv_info);
  3510. mode->priv_info = NULL;
  3511. done:
  3512. utils->data = utils_data;
  3513. mutex_unlock(&panel->panel_lock);
  3514. return rc;
  3515. }
  3516. int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel,
  3517. struct dsi_display_mode *mode,
  3518. struct dsi_host_config *config)
  3519. {
  3520. int rc = 0;
  3521. struct dsi_dyn_clk_caps *dyn_clk_caps = &panel->dyn_clk_caps;
  3522. if (!panel || !mode || !config) {
  3523. DSI_ERR("invalid params\n");
  3524. return -EINVAL;
  3525. }
  3526. mutex_lock(&panel->panel_lock);
  3527. config->panel_mode = panel->panel_mode;
  3528. memcpy(&config->common_config, &panel->host_config,
  3529. sizeof(config->common_config));
  3530. if (panel->panel_mode == DSI_OP_VIDEO_MODE) {
  3531. memcpy(&config->u.video_engine, &panel->video_config,
  3532. sizeof(config->u.video_engine));
  3533. } else {
  3534. memcpy(&config->u.cmd_engine, &panel->cmd_config,
  3535. sizeof(config->u.cmd_engine));
  3536. }
  3537. memcpy(&config->video_timing, &mode->timing,
  3538. sizeof(config->video_timing));
  3539. config->video_timing.mdp_transfer_time_us =
  3540. mode->priv_info->mdp_transfer_time_us;
  3541. config->video_timing.dsc_enabled = mode->priv_info->dsc_enabled;
  3542. config->video_timing.dsc = &mode->priv_info->dsc;
  3543. config->video_timing.vdc_enabled = mode->priv_info->vdc_enabled;
  3544. config->video_timing.vdc = &mode->priv_info->vdc;
  3545. if (dyn_clk_caps->dyn_clk_support)
  3546. config->bit_clk_rate_hz_override = mode->timing.clk_rate_hz;
  3547. else
  3548. config->bit_clk_rate_hz_override = mode->priv_info->clk_rate_hz;
  3549. config->esc_clk_rate_hz = 19200000;
  3550. mutex_unlock(&panel->panel_lock);
  3551. return rc;
  3552. }
  3553. int dsi_panel_pre_prepare(struct dsi_panel *panel)
  3554. {
  3555. int rc = 0;
  3556. if (!panel) {
  3557. DSI_ERR("invalid params\n");
  3558. return -EINVAL;
  3559. }
  3560. mutex_lock(&panel->panel_lock);
  3561. /* If LP11_INIT is set, panel will be powered up during prepare() */
  3562. if (panel->lp11_init)
  3563. goto error;
  3564. rc = dsi_panel_power_on(panel);
  3565. if (rc) {
  3566. DSI_ERR("[%s] panel power on failed, rc=%d\n", panel->name, rc);
  3567. goto error;
  3568. }
  3569. error:
  3570. mutex_unlock(&panel->panel_lock);
  3571. return rc;
  3572. }
  3573. int dsi_panel_update_pps(struct dsi_panel *panel)
  3574. {
  3575. int rc = 0;
  3576. struct dsi_panel_cmd_set *set = NULL;
  3577. struct dsi_display_mode_priv_info *priv_info = NULL;
  3578. if (!panel || !panel->cur_mode) {
  3579. DSI_ERR("invalid params\n");
  3580. return -EINVAL;
  3581. }
  3582. mutex_lock(&panel->panel_lock);
  3583. priv_info = panel->cur_mode->priv_info;
  3584. set = &priv_info->cmd_sets[DSI_CMD_SET_PPS];
  3585. if (priv_info->dsc_enabled)
  3586. dsi_dsc_create_pps_buf_cmd(&priv_info->dsc,
  3587. panel->dce_pps_cmd, 0,
  3588. DSI_CMD_PPS_SIZE - DSI_CMD_PPS_HDR_SIZE);
  3589. else if (priv_info->vdc_enabled)
  3590. dsi_vdc_create_pps_buf_cmd(&priv_info->vdc,
  3591. panel->dce_pps_cmd, 0,
  3592. DSI_CMD_PPS_SIZE - DSI_CMD_PPS_HDR_SIZE);
  3593. if (priv_info->dsc_enabled || priv_info->vdc_enabled) {
  3594. rc = dsi_panel_create_cmd_packets(panel->dce_pps_cmd,
  3595. DSI_CMD_PPS_SIZE, 1, set->cmds);
  3596. if (rc) {
  3597. DSI_ERR("failed to create cmd packets, rc=%d\n", rc);
  3598. goto error;
  3599. }
  3600. }
  3601. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PPS);
  3602. if (rc) {
  3603. DSI_ERR("[%s] failed to send DSI_CMD_SET_PPS cmds, rc=%d\n",
  3604. panel->name, rc);
  3605. }
  3606. dsi_panel_destroy_cmd_packets(set);
  3607. error:
  3608. mutex_unlock(&panel->panel_lock);
  3609. return rc;
  3610. }
  3611. int dsi_panel_set_lp1(struct dsi_panel *panel)
  3612. {
  3613. int rc = 0;
  3614. if (!panel) {
  3615. DSI_ERR("invalid params\n");
  3616. return -EINVAL;
  3617. }
  3618. mutex_lock(&panel->panel_lock);
  3619. if (!panel->panel_initialized)
  3620. goto exit;
  3621. /*
  3622. * Consider LP1->LP2->LP1.
  3623. * If the panel is already in LP mode, do not need to
  3624. * set the regulator.
  3625. * IBB and AB power mode would be set at the same time
  3626. * in PMIC driver, so we only call ibb setting that is enough.
  3627. */
  3628. if (dsi_panel_is_type_oled(panel) &&
  3629. panel->power_mode != SDE_MODE_DPMS_LP2)
  3630. dsi_pwr_panel_regulator_mode_set(&panel->power_info,
  3631. "ibb", REGULATOR_MODE_IDLE);
  3632. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_LP1);
  3633. if (rc)
  3634. DSI_ERR("[%s] failed to send DSI_CMD_SET_LP1 cmd, rc=%d\n",
  3635. panel->name, rc);
  3636. exit:
  3637. mutex_unlock(&panel->panel_lock);
  3638. return rc;
  3639. }
  3640. int dsi_panel_set_lp2(struct dsi_panel *panel)
  3641. {
  3642. int rc = 0;
  3643. if (!panel) {
  3644. DSI_ERR("invalid params\n");
  3645. return -EINVAL;
  3646. }
  3647. mutex_lock(&panel->panel_lock);
  3648. if (!panel->panel_initialized)
  3649. goto exit;
  3650. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_LP2);
  3651. if (rc)
  3652. DSI_ERR("[%s] failed to send DSI_CMD_SET_LP2 cmd, rc=%d\n",
  3653. panel->name, rc);
  3654. exit:
  3655. mutex_unlock(&panel->panel_lock);
  3656. return rc;
  3657. }
  3658. int dsi_panel_set_nolp(struct dsi_panel *panel)
  3659. {
  3660. int rc = 0;
  3661. if (!panel) {
  3662. DSI_ERR("invalid params\n");
  3663. return -EINVAL;
  3664. }
  3665. mutex_lock(&panel->panel_lock);
  3666. if (!panel->panel_initialized)
  3667. goto exit;
  3668. /*
  3669. * Consider about LP1->LP2->NOLP.
  3670. */
  3671. if (dsi_panel_is_type_oled(panel) &&
  3672. (panel->power_mode == SDE_MODE_DPMS_LP1 ||
  3673. panel->power_mode == SDE_MODE_DPMS_LP2))
  3674. dsi_pwr_panel_regulator_mode_set(&panel->power_info,
  3675. "ibb", REGULATOR_MODE_NORMAL);
  3676. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_NOLP);
  3677. if (rc)
  3678. DSI_ERR("[%s] failed to send DSI_CMD_SET_NOLP cmd, rc=%d\n",
  3679. panel->name, rc);
  3680. exit:
  3681. mutex_unlock(&panel->panel_lock);
  3682. return rc;
  3683. }
  3684. int dsi_panel_prepare(struct dsi_panel *panel)
  3685. {
  3686. int rc = 0;
  3687. if (!panel) {
  3688. DSI_ERR("invalid params\n");
  3689. return -EINVAL;
  3690. }
  3691. mutex_lock(&panel->panel_lock);
  3692. if (panel->lp11_init) {
  3693. rc = dsi_panel_power_on(panel);
  3694. if (rc) {
  3695. DSI_ERR("[%s] panel power on failed, rc=%d\n",
  3696. panel->name, rc);
  3697. goto error;
  3698. }
  3699. }
  3700. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PRE_ON);
  3701. if (rc) {
  3702. DSI_ERR("[%s] failed to send DSI_CMD_SET_PRE_ON cmds, rc=%d\n",
  3703. panel->name, rc);
  3704. goto error;
  3705. }
  3706. error:
  3707. mutex_unlock(&panel->panel_lock);
  3708. return rc;
  3709. }
  3710. static int dsi_panel_roi_prepare_dcs_cmds(struct dsi_panel_cmd_set *set,
  3711. struct dsi_rect *roi, int ctrl_idx, int unicast)
  3712. {
  3713. static const int ROI_CMD_LEN = 5;
  3714. int rc = 0;
  3715. /* DTYPE_DCS_LWRITE */
  3716. char *caset, *paset;
  3717. set->cmds = NULL;
  3718. caset = kzalloc(ROI_CMD_LEN, GFP_KERNEL);
  3719. if (!caset) {
  3720. rc = -ENOMEM;
  3721. goto exit;
  3722. }
  3723. caset[0] = 0x2a;
  3724. caset[1] = (roi->x & 0xFF00) >> 8;
  3725. caset[2] = roi->x & 0xFF;
  3726. caset[3] = ((roi->x - 1 + roi->w) & 0xFF00) >> 8;
  3727. caset[4] = (roi->x - 1 + roi->w) & 0xFF;
  3728. paset = kzalloc(ROI_CMD_LEN, GFP_KERNEL);
  3729. if (!paset) {
  3730. rc = -ENOMEM;
  3731. goto error_free_mem;
  3732. }
  3733. paset[0] = 0x2b;
  3734. paset[1] = (roi->y & 0xFF00) >> 8;
  3735. paset[2] = roi->y & 0xFF;
  3736. paset[3] = ((roi->y - 1 + roi->h) & 0xFF00) >> 8;
  3737. paset[4] = (roi->y - 1 + roi->h) & 0xFF;
  3738. set->type = DSI_CMD_SET_ROI;
  3739. set->state = DSI_CMD_SET_STATE_LP;
  3740. set->count = 2; /* send caset + paset together */
  3741. set->cmds = kcalloc(set->count, sizeof(*set->cmds), GFP_KERNEL);
  3742. if (!set->cmds) {
  3743. rc = -ENOMEM;
  3744. goto error_free_mem;
  3745. }
  3746. set->cmds[0].msg.channel = 0;
  3747. set->cmds[0].msg.type = MIPI_DSI_DCS_LONG_WRITE;
  3748. set->cmds[0].msg.flags = unicast ? MIPI_DSI_MSG_UNICAST_COMMAND : 0;
  3749. set->cmds[0].msg.flags |= MIPI_DSI_MSG_BATCH_COMMAND;
  3750. set->cmds[0].msg.tx_len = ROI_CMD_LEN;
  3751. set->cmds[0].msg.tx_buf = caset;
  3752. set->cmds[0].msg.rx_len = 0;
  3753. set->cmds[0].msg.rx_buf = 0;
  3754. set->cmds[0].last_command = 0;
  3755. set->cmds[0].post_wait_ms = 0;
  3756. set->cmds[0].ctrl = unicast ? ctrl_idx : 0;
  3757. set->cmds[1].msg.channel = 0;
  3758. set->cmds[1].msg.type = MIPI_DSI_DCS_LONG_WRITE;
  3759. set->cmds[1].msg.flags = unicast ? MIPI_DSI_MSG_UNICAST_COMMAND : 0;
  3760. set->cmds[1].msg.tx_len = ROI_CMD_LEN;
  3761. set->cmds[1].msg.tx_buf = paset;
  3762. set->cmds[1].msg.rx_len = 0;
  3763. set->cmds[1].msg.rx_buf = 0;
  3764. set->cmds[1].last_command = 1;
  3765. set->cmds[1].post_wait_ms = 0;
  3766. set->cmds[1].ctrl = unicast ? ctrl_idx : 0;
  3767. goto exit;
  3768. error_free_mem:
  3769. kfree(caset);
  3770. kfree(paset);
  3771. kfree(set->cmds);
  3772. exit:
  3773. return rc;
  3774. }
  3775. int dsi_panel_send_qsync_on_dcs(struct dsi_panel *panel,
  3776. int ctrl_idx)
  3777. {
  3778. int rc = 0;
  3779. if (!panel) {
  3780. DSI_ERR("invalid params\n");
  3781. return -EINVAL;
  3782. }
  3783. mutex_lock(&panel->panel_lock);
  3784. DSI_DEBUG("ctrl:%d qsync on\n", ctrl_idx);
  3785. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_QSYNC_ON);
  3786. if (rc)
  3787. DSI_ERR("[%s] failed to send DSI_CMD_SET_QSYNC_ON cmds rc=%d\n",
  3788. panel->name, rc);
  3789. mutex_unlock(&panel->panel_lock);
  3790. return rc;
  3791. }
  3792. int dsi_panel_send_qsync_off_dcs(struct dsi_panel *panel,
  3793. int ctrl_idx)
  3794. {
  3795. int rc = 0;
  3796. if (!panel) {
  3797. DSI_ERR("invalid params\n");
  3798. return -EINVAL;
  3799. }
  3800. mutex_lock(&panel->panel_lock);
  3801. DSI_DEBUG("ctrl:%d qsync off\n", ctrl_idx);
  3802. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_QSYNC_OFF);
  3803. if (rc)
  3804. DSI_ERR("[%s] failed to send DSI_CMD_SET_QSYNC_OFF cmds rc=%d\n",
  3805. panel->name, rc);
  3806. mutex_unlock(&panel->panel_lock);
  3807. return rc;
  3808. }
  3809. int dsi_panel_send_roi_dcs(struct dsi_panel *panel, int ctrl_idx,
  3810. struct dsi_rect *roi)
  3811. {
  3812. int rc = 0;
  3813. struct dsi_panel_cmd_set *set;
  3814. struct dsi_display_mode_priv_info *priv_info;
  3815. if (!panel || !panel->cur_mode) {
  3816. DSI_ERR("Invalid params\n");
  3817. return -EINVAL;
  3818. }
  3819. priv_info = panel->cur_mode->priv_info;
  3820. set = &priv_info->cmd_sets[DSI_CMD_SET_ROI];
  3821. rc = dsi_panel_roi_prepare_dcs_cmds(set, roi, ctrl_idx, true);
  3822. if (rc) {
  3823. DSI_ERR("[%s] failed to prepare DSI_CMD_SET_ROI cmds, rc=%d\n",
  3824. panel->name, rc);
  3825. return rc;
  3826. }
  3827. DSI_DEBUG("[%s] send roi x %d y %d w %d h %d\n", panel->name,
  3828. roi->x, roi->y, roi->w, roi->h);
  3829. SDE_EVT32(roi->x, roi->y, roi->w, roi->h);
  3830. mutex_lock(&panel->panel_lock);
  3831. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_ROI);
  3832. if (rc)
  3833. DSI_ERR("[%s] failed to send DSI_CMD_SET_ROI cmds, rc=%d\n",
  3834. panel->name, rc);
  3835. mutex_unlock(&panel->panel_lock);
  3836. dsi_panel_destroy_cmd_packets(set);
  3837. dsi_panel_dealloc_cmd_packets(set);
  3838. return rc;
  3839. }
  3840. int dsi_panel_switch_cmd_mode_out(struct dsi_panel *panel)
  3841. {
  3842. int rc = 0;
  3843. if (!panel) {
  3844. DSI_ERR("Invalid params\n");
  3845. return -EINVAL;
  3846. }
  3847. mutex_lock(&panel->panel_lock);
  3848. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_CMD_SWITCH_OUT);
  3849. if (rc)
  3850. DSI_ERR("[%s] failed to send DSI_CMD_SET_CMD_SWITCH_OUT cmds, rc=%d\n",
  3851. panel->name, rc);
  3852. mutex_unlock(&panel->panel_lock);
  3853. return rc;
  3854. }
  3855. int dsi_panel_switch_video_mode_out(struct dsi_panel *panel)
  3856. {
  3857. int rc = 0;
  3858. if (!panel) {
  3859. DSI_ERR("Invalid params\n");
  3860. return -EINVAL;
  3861. }
  3862. mutex_lock(&panel->panel_lock);
  3863. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_VID_SWITCH_OUT);
  3864. if (rc)
  3865. DSI_ERR("[%s] failed to send DSI_CMD_SET_VID_SWITCH_OUT cmds, rc=%d\n",
  3866. panel->name, rc);
  3867. mutex_unlock(&panel->panel_lock);
  3868. return rc;
  3869. }
  3870. int dsi_panel_switch_video_mode_in(struct dsi_panel *panel)
  3871. {
  3872. int rc = 0;
  3873. if (!panel) {
  3874. DSI_ERR("Invalid params\n");
  3875. return -EINVAL;
  3876. }
  3877. mutex_lock(&panel->panel_lock);
  3878. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_VID_SWITCH_IN);
  3879. if (rc)
  3880. DSI_ERR("[%s] failed to send DSI_CMD_SET_VID_SWITCH_IN cmds, rc=%d\n",
  3881. panel->name, rc);
  3882. mutex_unlock(&panel->panel_lock);
  3883. return rc;
  3884. }
  3885. int dsi_panel_switch_cmd_mode_in(struct dsi_panel *panel)
  3886. {
  3887. int rc = 0;
  3888. if (!panel) {
  3889. DSI_ERR("Invalid params\n");
  3890. return -EINVAL;
  3891. }
  3892. mutex_lock(&panel->panel_lock);
  3893. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_CMD_SWITCH_IN);
  3894. if (rc)
  3895. DSI_ERR("[%s] failed to send DSI_CMD_SET_CMD_SWITCH_IN cmds, rc=%d\n",
  3896. panel->name, rc);
  3897. mutex_unlock(&panel->panel_lock);
  3898. return rc;
  3899. }
  3900. int dsi_panel_switch(struct dsi_panel *panel)
  3901. {
  3902. int rc = 0;
  3903. if (!panel) {
  3904. DSI_ERR("Invalid params\n");
  3905. return -EINVAL;
  3906. }
  3907. mutex_lock(&panel->panel_lock);
  3908. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_TIMING_SWITCH);
  3909. if (rc)
  3910. DSI_ERR("[%s] failed to send DSI_CMD_SET_TIMING_SWITCH cmds, rc=%d\n",
  3911. panel->name, rc);
  3912. mutex_unlock(&panel->panel_lock);
  3913. return rc;
  3914. }
  3915. int dsi_panel_post_switch(struct dsi_panel *panel)
  3916. {
  3917. int rc = 0;
  3918. if (!panel) {
  3919. DSI_ERR("Invalid params\n");
  3920. return -EINVAL;
  3921. }
  3922. mutex_lock(&panel->panel_lock);
  3923. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_TIMING_SWITCH);
  3924. if (rc)
  3925. DSI_ERR("[%s] failed to send DSI_CMD_SET_POST_TIMING_SWITCH cmds, rc=%d\n",
  3926. panel->name, rc);
  3927. mutex_unlock(&panel->panel_lock);
  3928. return rc;
  3929. }
  3930. int dsi_panel_enable(struct dsi_panel *panel)
  3931. {
  3932. int rc = 0;
  3933. if (!panel) {
  3934. DSI_ERR("Invalid params\n");
  3935. return -EINVAL;
  3936. }
  3937. mutex_lock(&panel->panel_lock);
  3938. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_ON);
  3939. if (rc) {
  3940. DSI_ERR("[%s] failed to send DSI_CMD_SET_ON cmds, rc=%d\n",
  3941. panel->name, rc);
  3942. goto error;
  3943. }
  3944. if (panel->panel_mode == DSI_OP_CMD_MODE) {
  3945. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_CMD_ON);
  3946. if (rc) {
  3947. DSI_ERR("[%s] failed to send DSI_CMD_SET_CMD_ON cmds, rc=%d\n",
  3948. panel->name, rc);
  3949. goto error;
  3950. }
  3951. } else if (panel->panel_mode == DSI_OP_VIDEO_MODE) {
  3952. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_VID_ON);
  3953. if (rc) {
  3954. DSI_ERR("[%s] failed to send DSI_CMD_SET_VID_ON cmds, rc=%d\n",
  3955. panel->name, rc);
  3956. goto error;
  3957. }
  3958. }
  3959. panel->panel_initialized = true;
  3960. error:
  3961. mutex_unlock(&panel->panel_lock);
  3962. return rc;
  3963. }
  3964. int dsi_panel_post_enable(struct dsi_panel *panel)
  3965. {
  3966. int rc = 0;
  3967. if (!panel) {
  3968. DSI_ERR("invalid params\n");
  3969. return -EINVAL;
  3970. }
  3971. mutex_lock(&panel->panel_lock);
  3972. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_ON);
  3973. if (rc) {
  3974. DSI_ERR("[%s] failed to send DSI_CMD_SET_POST_ON cmds, rc=%d\n",
  3975. panel->name, rc);
  3976. goto error;
  3977. }
  3978. error:
  3979. mutex_unlock(&panel->panel_lock);
  3980. return rc;
  3981. }
  3982. int dsi_panel_pre_disable(struct dsi_panel *panel)
  3983. {
  3984. int rc = 0;
  3985. if (!panel) {
  3986. DSI_ERR("invalid params\n");
  3987. return -EINVAL;
  3988. }
  3989. mutex_lock(&panel->panel_lock);
  3990. if (gpio_is_valid(panel->bl_config.en_gpio))
  3991. gpio_set_value(panel->bl_config.en_gpio, 0);
  3992. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PRE_OFF);
  3993. if (rc) {
  3994. DSI_ERR("[%s] failed to send DSI_CMD_SET_PRE_OFF cmds, rc=%d\n",
  3995. panel->name, rc);
  3996. goto error;
  3997. }
  3998. error:
  3999. mutex_unlock(&panel->panel_lock);
  4000. return rc;
  4001. }
  4002. int dsi_panel_disable(struct dsi_panel *panel)
  4003. {
  4004. int rc = 0;
  4005. if (!panel) {
  4006. DSI_ERR("invalid params\n");
  4007. return -EINVAL;
  4008. }
  4009. mutex_lock(&panel->panel_lock);
  4010. /* Avoid sending panel off commands when ESD recovery is underway */
  4011. if (!atomic_read(&panel->esd_recovery_pending)) {
  4012. /*
  4013. * Need to set IBB/AB regulator mode to STANDBY,
  4014. * if panel is going off from AOD mode.
  4015. */
  4016. if (dsi_panel_is_type_oled(panel) &&
  4017. (panel->power_mode == SDE_MODE_DPMS_LP1 ||
  4018. panel->power_mode == SDE_MODE_DPMS_LP2))
  4019. dsi_pwr_panel_regulator_mode_set(&panel->power_info,
  4020. "ibb", REGULATOR_MODE_STANDBY);
  4021. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_OFF);
  4022. if (rc) {
  4023. /*
  4024. * Sending panel off commands may fail when DSI
  4025. * controller is in a bad state. These failures can be
  4026. * ignored since controller will go for full reset on
  4027. * subsequent display enable anyway.
  4028. */
  4029. pr_warn_ratelimited("[%s] failed to send DSI_CMD_SET_OFF cmds, rc=%d\n",
  4030. panel->name, rc);
  4031. rc = 0;
  4032. }
  4033. }
  4034. panel->panel_initialized = false;
  4035. panel->power_mode = SDE_MODE_DPMS_OFF;
  4036. mutex_unlock(&panel->panel_lock);
  4037. return rc;
  4038. }
  4039. int dsi_panel_unprepare(struct dsi_panel *panel)
  4040. {
  4041. int rc = 0;
  4042. if (!panel) {
  4043. DSI_ERR("invalid params\n");
  4044. return -EINVAL;
  4045. }
  4046. mutex_lock(&panel->panel_lock);
  4047. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_OFF);
  4048. if (rc) {
  4049. DSI_ERR("[%s] failed to send DSI_CMD_SET_POST_OFF cmds, rc=%d\n",
  4050. panel->name, rc);
  4051. goto error;
  4052. }
  4053. error:
  4054. mutex_unlock(&panel->panel_lock);
  4055. return rc;
  4056. }
  4057. int dsi_panel_post_unprepare(struct dsi_panel *panel)
  4058. {
  4059. int rc = 0;
  4060. if (!panel) {
  4061. DSI_ERR("invalid params\n");
  4062. return -EINVAL;
  4063. }
  4064. mutex_lock(&panel->panel_lock);
  4065. rc = dsi_panel_power_off(panel);
  4066. if (rc) {
  4067. DSI_ERR("[%s] panel power_Off failed, rc=%d\n",
  4068. panel->name, rc);
  4069. goto error;
  4070. }
  4071. error:
  4072. mutex_unlock(&panel->panel_lock);
  4073. return rc;
  4074. }