dsi_panel.c 106 KB

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