dsi_panel.c 117 KB

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