dsi_panel.c 120 KB

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