dsi_panel.c 119 KB

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