dsi_panel.c 121 KB

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