dsi_panel.c 124 KB

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