dsi_panel.c 117 KB

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