dsi_panel.c 108 KB

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