dsi_ctrl.c 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021-2024, Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #include <linux/of_device.h>
  7. #include <linux/err.h>
  8. #include <linux/regulator/consumer.h>
  9. #include <linux/clk.h>
  10. #include <linux/of_irq.h>
  11. #include <video/mipi_display.h>
  12. #include "msm_drv.h"
  13. #include "msm_kms.h"
  14. #include "msm_mmu.h"
  15. #include "dsi_ctrl.h"
  16. #include "dsi_ctrl_hw.h"
  17. #include "dsi_clk.h"
  18. #include "dsi_display.h"
  19. #include "dsi_pwr.h"
  20. #include "dsi_catalog.h"
  21. #include "dsi_panel.h"
  22. #include "sde_dbg.h"
  23. #define DSI_CTRL_DEFAULT_LABEL "MDSS DSI CTRL"
  24. #define DSI_CTRL_TX_TO_MS 1200
  25. #define TO_ON_OFF(x) ((x) ? "ON" : "OFF")
  26. #define CEIL(x, y) (((x) + ((y)-1)) / (y))
  27. #define TICKS_IN_MICRO_SECOND 1000000
  28. #define DSI_CTRL_DEBUG(c, fmt, ...) DRM_DEV_DEBUG(NULL, "[msm-dsi-debug]: %s: "\
  29. fmt, c ? c->name : "inv", ##__VA_ARGS__)
  30. #define DSI_CTRL_ERR(c, fmt, ...) DRM_DEV_ERROR(NULL, "[msm-dsi-error]: %s: "\
  31. fmt, c ? c->name : "inv", ##__VA_ARGS__)
  32. #define DSI_CTRL_INFO(c, fmt, ...) DRM_DEV_INFO(NULL, "[msm-dsi-info]: %s: "\
  33. fmt, c->name, ##__VA_ARGS__)
  34. #define DSI_CTRL_WARN(c, fmt, ...) DRM_WARN("[msm-dsi-warn]: %s: " fmt,\
  35. c ? c->name : "inv", ##__VA_ARGS__)
  36. struct dsi_ctrl_list_item {
  37. struct dsi_ctrl *ctrl;
  38. struct list_head list;
  39. };
  40. static LIST_HEAD(dsi_ctrl_list);
  41. static DEFINE_MUTEX(dsi_ctrl_list_lock);
  42. static const enum dsi_ctrl_version dsi_ctrl_v2_2 = DSI_CTRL_VERSION_2_2;
  43. static const enum dsi_ctrl_version dsi_ctrl_v2_3 = DSI_CTRL_VERSION_2_3;
  44. static const enum dsi_ctrl_version dsi_ctrl_v2_4 = DSI_CTRL_VERSION_2_4;
  45. static const enum dsi_ctrl_version dsi_ctrl_v2_5 = DSI_CTRL_VERSION_2_5;
  46. static const enum dsi_ctrl_version dsi_ctrl_v2_6 = DSI_CTRL_VERSION_2_6;
  47. static const enum dsi_ctrl_version dsi_ctrl_v2_7 = DSI_CTRL_VERSION_2_7;
  48. static const enum dsi_ctrl_version dsi_ctrl_v2_8 = DSI_CTRL_VERSION_2_8;
  49. static const struct of_device_id msm_dsi_of_match[] = {
  50. {
  51. .compatible = "qcom,dsi-ctrl-hw-v2.2",
  52. .data = &dsi_ctrl_v2_2,
  53. },
  54. {
  55. .compatible = "qcom,dsi-ctrl-hw-v2.3",
  56. .data = &dsi_ctrl_v2_3,
  57. },
  58. {
  59. .compatible = "qcom,dsi-ctrl-hw-v2.4",
  60. .data = &dsi_ctrl_v2_4,
  61. },
  62. {
  63. .compatible = "qcom,dsi-ctrl-hw-v2.5",
  64. .data = &dsi_ctrl_v2_5,
  65. },
  66. {
  67. .compatible = "qcom,dsi-ctrl-hw-v2.6",
  68. .data = &dsi_ctrl_v2_6,
  69. },
  70. {
  71. .compatible = "qcom,dsi-ctrl-hw-v2.7",
  72. .data = &dsi_ctrl_v2_7,
  73. },
  74. {
  75. .compatible = "qcom,dsi-ctrl-hw-v2.8",
  76. .data = &dsi_ctrl_v2_8,
  77. },
  78. {}
  79. };
  80. #if IS_ENABLED(CONFIG_DEBUG_FS)
  81. static ssize_t debugfs_state_info_read(struct file *file,
  82. char __user *buff,
  83. size_t count,
  84. loff_t *ppos)
  85. {
  86. struct dsi_ctrl *dsi_ctrl = file->private_data;
  87. char *buf;
  88. u32 len = 0;
  89. if (!dsi_ctrl)
  90. return -ENODEV;
  91. if (*ppos)
  92. return 0;
  93. buf = kzalloc(SZ_4K, GFP_KERNEL);
  94. if (!buf)
  95. return -ENOMEM;
  96. /* Dump current state */
  97. len += snprintf((buf + len), (SZ_4K - len), "Current State:\n");
  98. len += snprintf((buf + len), (SZ_4K - len),
  99. "\tCTRL_ENGINE = %s\n",
  100. TO_ON_OFF(dsi_ctrl->current_state.controller_state));
  101. len += snprintf((buf + len), (SZ_4K - len),
  102. "\tVIDEO_ENGINE = %s\n\tCOMMAND_ENGINE = %s\n",
  103. TO_ON_OFF(dsi_ctrl->current_state.vid_engine_state),
  104. TO_ON_OFF(dsi_ctrl->current_state.cmd_engine_state));
  105. /* Dump clock information */
  106. len += snprintf((buf + len), (SZ_4K - len), "\nClock Info:\n");
  107. len += snprintf((buf + len), (SZ_4K - len),
  108. "\tBYTE_CLK = %u, PIXEL_CLK = %u, ESC_CLK = %u\n",
  109. dsi_ctrl->clk_freq.byte_clk_rate,
  110. dsi_ctrl->clk_freq.pix_clk_rate,
  111. dsi_ctrl->clk_freq.esc_clk_rate);
  112. if (len > count)
  113. len = count;
  114. len = min_t(size_t, len, SZ_4K);
  115. if (copy_to_user(buff, buf, len)) {
  116. kfree(buf);
  117. return -EFAULT;
  118. }
  119. *ppos += len;
  120. kfree(buf);
  121. return len;
  122. }
  123. static ssize_t debugfs_reg_dump_read(struct file *file,
  124. char __user *buff,
  125. size_t count,
  126. loff_t *ppos)
  127. {
  128. struct dsi_ctrl *dsi_ctrl = file->private_data;
  129. char *buf;
  130. u32 len = 0;
  131. struct dsi_clk_ctrl_info clk_info;
  132. int rc = 0;
  133. if (!dsi_ctrl)
  134. return -ENODEV;
  135. if (*ppos)
  136. return 0;
  137. buf = kzalloc(SZ_4K, GFP_KERNEL);
  138. if (!buf)
  139. return -ENOMEM;
  140. clk_info.client = DSI_CLK_REQ_DSI_CLIENT;
  141. clk_info.clk_type = DSI_CORE_CLK;
  142. clk_info.clk_state = DSI_CLK_ON;
  143. rc = dsi_ctrl->clk_cb.dsi_clk_cb(dsi_ctrl->clk_cb.priv, clk_info);
  144. if (rc) {
  145. DSI_CTRL_ERR(dsi_ctrl, "failed to enable DSI core clocks\n");
  146. kfree(buf);
  147. return rc;
  148. }
  149. if (dsi_ctrl->hw.ops.reg_dump_to_buffer)
  150. len = dsi_ctrl->hw.ops.reg_dump_to_buffer(&dsi_ctrl->hw,
  151. buf, SZ_4K);
  152. clk_info.clk_state = DSI_CLK_OFF;
  153. rc = dsi_ctrl->clk_cb.dsi_clk_cb(dsi_ctrl->clk_cb.priv, clk_info);
  154. if (rc) {
  155. DSI_CTRL_ERR(dsi_ctrl, "failed to disable DSI core clocks\n");
  156. kfree(buf);
  157. return rc;
  158. }
  159. if (len > count)
  160. len = count;
  161. len = min_t(size_t, len, SZ_4K);
  162. if (copy_to_user(buff, buf, len)) {
  163. kfree(buf);
  164. return -EFAULT;
  165. }
  166. *ppos += len;
  167. kfree(buf);
  168. return len;
  169. }
  170. static ssize_t debugfs_line_count_read(struct file *file,
  171. char __user *user_buf,
  172. size_t user_len,
  173. loff_t *ppos)
  174. {
  175. struct dsi_ctrl *dsi_ctrl = file->private_data;
  176. char *buf;
  177. int rc = 0;
  178. u32 len = 0;
  179. size_t max_len = min_t(size_t, user_len, SZ_4K);
  180. if (!dsi_ctrl)
  181. return -ENODEV;
  182. if (*ppos)
  183. return 0;
  184. buf = kzalloc(max_len, GFP_KERNEL);
  185. if (ZERO_OR_NULL_PTR(buf))
  186. return -ENOMEM;
  187. mutex_lock(&dsi_ctrl->ctrl_lock);
  188. len += scnprintf(buf, max_len, "Command triggered at line: %04x\n",
  189. dsi_ctrl->cmd_trigger_line);
  190. len += scnprintf((buf + len), max_len - len,
  191. "Command triggered at frame: %04x\n",
  192. dsi_ctrl->cmd_trigger_frame);
  193. len += scnprintf((buf + len), max_len - len,
  194. "Command successful at line: %04x\n",
  195. dsi_ctrl->cmd_success_line);
  196. len += scnprintf((buf + len), max_len - len,
  197. "Command successful at frame: %04x\n",
  198. dsi_ctrl->cmd_success_frame);
  199. mutex_unlock(&dsi_ctrl->ctrl_lock);
  200. if (len > max_len)
  201. len = max_len;
  202. if (copy_to_user(user_buf, buf, len)) {
  203. rc = -EFAULT;
  204. goto error;
  205. }
  206. *ppos += len;
  207. error:
  208. kfree(buf);
  209. return len;
  210. }
  211. static const struct file_operations state_info_fops = {
  212. .open = simple_open,
  213. .read = debugfs_state_info_read,
  214. };
  215. static const struct file_operations reg_dump_fops = {
  216. .open = simple_open,
  217. .read = debugfs_reg_dump_read,
  218. };
  219. static const struct file_operations cmd_dma_stats_fops = {
  220. .open = simple_open,
  221. .read = debugfs_line_count_read,
  222. };
  223. static int dsi_ctrl_debugfs_init(struct dsi_ctrl *dsi_ctrl,
  224. struct dentry *parent)
  225. {
  226. int rc = 0;
  227. struct dentry *dir, *state_file, *reg_dump, *cmd_dma_logs;
  228. if (!dsi_ctrl || !parent) {
  229. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  230. return -EINVAL;
  231. }
  232. dir = debugfs_create_dir(dsi_ctrl->name, parent);
  233. if (IS_ERR_OR_NULL(dir)) {
  234. rc = PTR_ERR(dir);
  235. DSI_CTRL_ERR(dsi_ctrl, "debugfs create dir failed, rc=%d\n",
  236. rc);
  237. goto error;
  238. }
  239. state_file = debugfs_create_file("state_info",
  240. 0444,
  241. dir,
  242. dsi_ctrl,
  243. &state_info_fops);
  244. if (IS_ERR_OR_NULL(state_file)) {
  245. rc = PTR_ERR(state_file);
  246. DSI_CTRL_ERR(dsi_ctrl, "state file failed, rc=%d\n", rc);
  247. goto error_remove_dir;
  248. }
  249. reg_dump = debugfs_create_file("reg_dump",
  250. 0444,
  251. dir,
  252. dsi_ctrl,
  253. &reg_dump_fops);
  254. if (IS_ERR_OR_NULL(reg_dump)) {
  255. rc = PTR_ERR(reg_dump);
  256. DSI_CTRL_ERR(dsi_ctrl, "reg dump file failed, rc=%d\n", rc);
  257. goto error_remove_dir;
  258. }
  259. debugfs_create_bool("enable_cmd_dma_stats", 0600, dir, &dsi_ctrl->enable_cmd_dma_stats);
  260. cmd_dma_logs = debugfs_create_file("cmd_dma_stats",
  261. 0444,
  262. dir,
  263. dsi_ctrl,
  264. &cmd_dma_stats_fops);
  265. if (IS_ERR_OR_NULL(cmd_dma_logs)) {
  266. rc = PTR_ERR(cmd_dma_logs);
  267. DSI_CTRL_ERR(dsi_ctrl, "Line count file failed, rc=%d\n",
  268. rc);
  269. goto error_remove_dir;
  270. }
  271. dsi_ctrl->debugfs_root = dir;
  272. return rc;
  273. error_remove_dir:
  274. debugfs_remove(dir);
  275. error:
  276. return rc;
  277. }
  278. static int dsi_ctrl_debugfs_deinit(struct dsi_ctrl *dsi_ctrl)
  279. {
  280. if (dsi_ctrl->debugfs_root) {
  281. debugfs_remove(dsi_ctrl->debugfs_root);
  282. dsi_ctrl->debugfs_root = NULL;
  283. }
  284. return 0;
  285. }
  286. #else
  287. static int dsi_ctrl_debugfs_init(struct dsi_ctrl *dsi_ctrl, struct dentry *parent)
  288. {
  289. char dbg_name[DSI_DEBUG_NAME_LEN];
  290. snprintf(dbg_name, DSI_DEBUG_NAME_LEN, "dsi%d_ctrl",
  291. dsi_ctrl->cell_index);
  292. sde_dbg_reg_register_base(dbg_name,
  293. dsi_ctrl->hw.base,
  294. msm_iomap_size(dsi_ctrl->pdev, "dsi_ctrl"));
  295. return 0;
  296. }
  297. static int dsi_ctrl_debugfs_deinit(struct dsi_ctrl *dsi_ctrl)
  298. {
  299. return 0;
  300. }
  301. #endif /* CONFIG_DEBUG_FS */
  302. static inline struct msm_gem_address_space*
  303. dsi_ctrl_get_aspace(struct dsi_ctrl *dsi_ctrl,
  304. int domain)
  305. {
  306. if (!dsi_ctrl || !dsi_ctrl->drm_dev)
  307. return NULL;
  308. return msm_gem_smmu_address_space_get(dsi_ctrl->drm_dev, domain);
  309. }
  310. static void dsi_ctrl_dma_cmd_wait_for_done(struct dsi_ctrl *dsi_ctrl)
  311. {
  312. int ret = 0;
  313. u32 status;
  314. u32 mask = DSI_CMD_MODE_DMA_DONE;
  315. struct dsi_ctrl_hw_ops dsi_hw_ops;
  316. dsi_hw_ops = dsi_ctrl->hw.ops;
  317. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_ENTRY);
  318. ret = wait_for_completion_timeout(
  319. &dsi_ctrl->irq_info.cmd_dma_done,
  320. msecs_to_jiffies(DSI_CTRL_TX_TO_MS));
  321. if (ret == 0 && !atomic_read(&dsi_ctrl->dma_irq_trig)) {
  322. status = dsi_hw_ops.get_interrupt_status(&dsi_ctrl->hw);
  323. if (status & mask) {
  324. status |= (DSI_CMD_MODE_DMA_DONE | DSI_BTA_DONE);
  325. dsi_hw_ops.clear_interrupt_status(&dsi_ctrl->hw,
  326. status);
  327. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_CASE1);
  328. DSI_CTRL_WARN(dsi_ctrl,
  329. "dma_tx done but irq not triggered\n");
  330. } else {
  331. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_ERROR);
  332. DSI_CTRL_ERR(dsi_ctrl,
  333. "Command transfer failed\n");
  334. }
  335. dsi_ctrl_disable_status_interrupt(dsi_ctrl,
  336. DSI_SINT_CMD_MODE_DMA_DONE);
  337. }
  338. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_EXIT);
  339. }
  340. /**
  341. * dsi_ctrl_clear_dma_status - API to clear DMA status
  342. * @dsi_ctrl: DSI controller handle.
  343. */
  344. static void dsi_ctrl_clear_dma_status(struct dsi_ctrl *dsi_ctrl)
  345. {
  346. struct dsi_ctrl_hw_ops dsi_hw_ops;
  347. u32 status = 0;
  348. if (!dsi_ctrl) {
  349. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  350. return;
  351. }
  352. dsi_hw_ops = dsi_ctrl->hw.ops;
  353. mutex_lock(&dsi_ctrl->ctrl_lock);
  354. status = dsi_hw_ops.poll_dma_status(&dsi_ctrl->hw);
  355. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_ENTRY, status);
  356. status |= (DSI_CMD_MODE_DMA_DONE | DSI_BTA_DONE);
  357. dsi_hw_ops.clear_interrupt_status(&dsi_ctrl->hw, status);
  358. mutex_unlock(&dsi_ctrl->ctrl_lock);
  359. }
  360. static void dsi_ctrl_post_cmd_transfer(struct dsi_ctrl *dsi_ctrl)
  361. {
  362. struct dsi_ctrl_hw_ops dsi_hw_ops = dsi_ctrl->hw.ops;
  363. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, dsi_ctrl->cell_index, dsi_ctrl->pending_cmd_flags);
  364. /* In case of broadcast messages, we poll on the slave controller. */
  365. if ((dsi_ctrl->pending_cmd_flags & DSI_CTRL_CMD_BROADCAST) &&
  366. !(dsi_ctrl->pending_cmd_flags & DSI_CTRL_CMD_BROADCAST_MASTER)) {
  367. dsi_ctrl_clear_dma_status(dsi_ctrl);
  368. } else if (!(dsi_ctrl->pending_cmd_flags & DSI_CTRL_CMD_READ)) {
  369. /* Wait for read command transfer to complete is done in dsi_message_rx. */
  370. dsi_ctrl_dma_cmd_wait_for_done(dsi_ctrl);
  371. }
  372. mutex_lock(&dsi_ctrl->ctrl_lock);
  373. if (dsi_ctrl->hw.reset_trig_ctrl)
  374. dsi_hw_ops.reset_trig_ctrl(&dsi_ctrl->hw,
  375. &dsi_ctrl->host_config.common_config);
  376. mutex_unlock(&dsi_ctrl->ctrl_lock);
  377. dsi_ctrl_transfer_cleanup(dsi_ctrl);
  378. }
  379. static void dsi_ctrl_post_cmd_transfer_work(struct work_struct *work)
  380. {
  381. struct dsi_ctrl *dsi_ctrl = NULL;
  382. dsi_ctrl = container_of(work, struct dsi_ctrl, post_cmd_tx_work);
  383. dsi_ctrl_post_cmd_transfer(dsi_ctrl);
  384. dsi_ctrl->post_tx_queued = false;
  385. }
  386. void dsi_ctrl_flush_cmd_dma_queue(struct dsi_ctrl *dsi_ctrl)
  387. {
  388. /*
  389. * If a command is triggered right after another command,
  390. * check if the previous command transfer is completed. If
  391. * transfer is done, cancel any work that has been
  392. * queued. Otherwise wait till the work is scheduled and
  393. * completed before triggering the next command by
  394. * flushing the workqueue.
  395. *
  396. * cancel_work_sync returns true if the work has not yet been scheduled, in that case as
  397. * we are cancelling the work we need to explicitly call the post_cmd_transfer API to
  398. * clean up the states.
  399. */
  400. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  401. if (atomic_read(&dsi_ctrl->dma_irq_trig)) {
  402. if (cancel_work_sync(&dsi_ctrl->post_cmd_tx_work)) {
  403. dsi_ctrl_post_cmd_transfer(dsi_ctrl);
  404. dsi_ctrl->post_tx_queued = false;
  405. }
  406. } else {
  407. flush_workqueue(dsi_ctrl->post_cmd_tx_workq);
  408. SDE_EVT32(SDE_EVTLOG_FUNC_CASE2);
  409. }
  410. }
  411. static int dsi_ctrl_check_state(struct dsi_ctrl *dsi_ctrl,
  412. enum dsi_ctrl_driver_ops op,
  413. u32 op_state)
  414. {
  415. int rc = 0;
  416. struct dsi_ctrl_state_info *state = &dsi_ctrl->current_state;
  417. SDE_EVT32_VERBOSE(dsi_ctrl->cell_index, op, op_state);
  418. switch (op) {
  419. case DSI_CTRL_OP_POWER_STATE_CHANGE:
  420. if (state->power_state == op_state) {
  421. DSI_CTRL_ERR(dsi_ctrl, "No change in state, pwr_state=%d\n",
  422. op_state);
  423. rc = -EINVAL;
  424. } else if (state->power_state == DSI_CTRL_POWER_VREG_ON) {
  425. if (state->vid_engine_state == DSI_CTRL_ENGINE_ON) {
  426. DSI_CTRL_ERR(dsi_ctrl, "State error: op=%d: %d\n",
  427. op_state,
  428. state->vid_engine_state);
  429. rc = -EINVAL;
  430. }
  431. }
  432. break;
  433. case DSI_CTRL_OP_CMD_ENGINE:
  434. if (state->cmd_engine_state == op_state) {
  435. DSI_CTRL_ERR(dsi_ctrl, "No change in state, cmd_state=%d\n",
  436. op_state);
  437. rc = -EINVAL;
  438. } else if ((state->power_state != DSI_CTRL_POWER_VREG_ON) ||
  439. (state->controller_state != DSI_CTRL_ENGINE_ON)) {
  440. DSI_CTRL_ERR(dsi_ctrl, "State error: op=%d: %d, %d\n",
  441. op,
  442. state->power_state,
  443. state->controller_state);
  444. rc = -EINVAL;
  445. }
  446. break;
  447. case DSI_CTRL_OP_VID_ENGINE:
  448. if (state->vid_engine_state == op_state) {
  449. DSI_CTRL_ERR(dsi_ctrl, "No change in state, cmd_state=%d\n",
  450. op_state);
  451. rc = -EINVAL;
  452. } else if ((state->power_state != DSI_CTRL_POWER_VREG_ON) ||
  453. (state->controller_state != DSI_CTRL_ENGINE_ON)) {
  454. DSI_CTRL_ERR(dsi_ctrl, "State error: op=%d: %d, %d\n",
  455. op,
  456. state->power_state,
  457. state->controller_state);
  458. rc = -EINVAL;
  459. }
  460. break;
  461. case DSI_CTRL_OP_HOST_ENGINE:
  462. if (state->controller_state == op_state) {
  463. DSI_CTRL_ERR(dsi_ctrl, "No change in state, ctrl_state=%d\n",
  464. op_state);
  465. rc = -EINVAL;
  466. } else if (state->power_state != DSI_CTRL_POWER_VREG_ON) {
  467. DSI_CTRL_ERR(dsi_ctrl, "State error (link is off): op=%d:, %d\n",
  468. op_state,
  469. state->power_state);
  470. rc = -EINVAL;
  471. } else if ((op_state == DSI_CTRL_ENGINE_OFF) &&
  472. ((state->cmd_engine_state != DSI_CTRL_ENGINE_OFF) ||
  473. (state->vid_engine_state != DSI_CTRL_ENGINE_OFF))) {
  474. DSI_CTRL_ERR(dsi_ctrl, "State error (eng on): op=%d: %d, %d\n",
  475. op_state,
  476. state->cmd_engine_state,
  477. state->vid_engine_state);
  478. rc = -EINVAL;
  479. }
  480. break;
  481. case DSI_CTRL_OP_CMD_TX:
  482. if ((state->power_state != DSI_CTRL_POWER_VREG_ON) ||
  483. (!state->host_initialized) ||
  484. (state->cmd_engine_state != DSI_CTRL_ENGINE_ON)) {
  485. DSI_CTRL_ERR(dsi_ctrl, "State error: op=%d: %d, %d, %d\n",
  486. op,
  487. state->power_state,
  488. state->host_initialized,
  489. state->cmd_engine_state);
  490. rc = -EINVAL;
  491. }
  492. break;
  493. case DSI_CTRL_OP_HOST_INIT:
  494. if (state->host_initialized == op_state) {
  495. DSI_CTRL_ERR(dsi_ctrl, "No change in state, host_init=%d\n",
  496. op_state);
  497. rc = -EINVAL;
  498. } else if (state->power_state != DSI_CTRL_POWER_VREG_ON) {
  499. DSI_CTRL_ERR(dsi_ctrl, "State error: op=%d: %d\n",
  500. op, state->power_state);
  501. rc = -EINVAL;
  502. }
  503. break;
  504. case DSI_CTRL_OP_TPG:
  505. if (state->tpg_enabled == op_state) {
  506. DSI_CTRL_ERR(dsi_ctrl, "No change in state, tpg_enabled=%d\n",
  507. op_state);
  508. rc = -EINVAL;
  509. } else if ((state->power_state != DSI_CTRL_POWER_VREG_ON) ||
  510. (state->controller_state != DSI_CTRL_ENGINE_ON)) {
  511. DSI_CTRL_ERR(dsi_ctrl, "State error: op=%d: %d, %d\n",
  512. op,
  513. state->power_state,
  514. state->controller_state);
  515. rc = -EINVAL;
  516. }
  517. break;
  518. case DSI_CTRL_OP_PHY_SW_RESET:
  519. if (state->power_state != DSI_CTRL_POWER_VREG_ON) {
  520. DSI_CTRL_ERR(dsi_ctrl, "State error: op=%d: %d\n",
  521. op, state->power_state);
  522. rc = -EINVAL;
  523. }
  524. break;
  525. case DSI_CTRL_OP_ASYNC_TIMING:
  526. if (state->vid_engine_state != op_state) {
  527. DSI_CTRL_ERR(dsi_ctrl, "Unexpected engine state vid_state=%d\n",
  528. op_state);
  529. rc = -EINVAL;
  530. }
  531. break;
  532. default:
  533. rc = -ENOTSUPP;
  534. break;
  535. }
  536. return rc;
  537. }
  538. bool dsi_ctrl_validate_host_state(struct dsi_ctrl *dsi_ctrl)
  539. {
  540. struct dsi_ctrl_state_info *state = &dsi_ctrl->current_state;
  541. if (!state) {
  542. DSI_CTRL_ERR(dsi_ctrl, "Invalid host state for DSI controller\n");
  543. return -EINVAL;
  544. }
  545. if (!state->host_initialized)
  546. return false;
  547. return true;
  548. }
  549. static void dsi_ctrl_update_state(struct dsi_ctrl *dsi_ctrl,
  550. enum dsi_ctrl_driver_ops op,
  551. u32 op_state)
  552. {
  553. struct dsi_ctrl_state_info *state = &dsi_ctrl->current_state;
  554. switch (op) {
  555. case DSI_CTRL_OP_POWER_STATE_CHANGE:
  556. state->power_state = op_state;
  557. break;
  558. case DSI_CTRL_OP_CMD_ENGINE:
  559. state->cmd_engine_state = op_state;
  560. break;
  561. case DSI_CTRL_OP_VID_ENGINE:
  562. state->vid_engine_state = op_state;
  563. break;
  564. case DSI_CTRL_OP_HOST_ENGINE:
  565. state->controller_state = op_state;
  566. break;
  567. case DSI_CTRL_OP_HOST_INIT:
  568. state->host_initialized = (op_state == 1) ? true : false;
  569. break;
  570. case DSI_CTRL_OP_TPG:
  571. state->tpg_enabled = (op_state == 1) ? true : false;
  572. break;
  573. case DSI_CTRL_OP_CMD_TX:
  574. case DSI_CTRL_OP_PHY_SW_RESET:
  575. default:
  576. break;
  577. }
  578. }
  579. static int dsi_ctrl_init_regmap(struct platform_device *pdev,
  580. struct dsi_ctrl *ctrl)
  581. {
  582. int rc = 0;
  583. void __iomem *ptr;
  584. ptr = msm_ioremap(pdev, "dsi_ctrl", ctrl->name);
  585. if (IS_ERR(ptr)) {
  586. rc = PTR_ERR(ptr);
  587. return rc;
  588. }
  589. ctrl->hw.base = ptr;
  590. DSI_CTRL_DEBUG(ctrl, "map dsi_ctrl registers to %pK\n", ctrl->hw.base);
  591. switch (ctrl->version) {
  592. case DSI_CTRL_VERSION_2_2:
  593. case DSI_CTRL_VERSION_2_3:
  594. case DSI_CTRL_VERSION_2_4:
  595. case DSI_CTRL_VERSION_2_5:
  596. case DSI_CTRL_VERSION_2_6:
  597. case DSI_CTRL_VERSION_2_7:
  598. case DSI_CTRL_VERSION_2_8:
  599. ptr = msm_ioremap(pdev, "disp_cc_base", ctrl->name);
  600. if (IS_ERR(ptr)) {
  601. DSI_CTRL_ERR(ctrl, "disp_cc base address not found for\n");
  602. rc = PTR_ERR(ptr);
  603. return rc;
  604. }
  605. ctrl->hw.disp_cc_base = ptr;
  606. ctrl->hw.mmss_misc_base = NULL;
  607. ptr = msm_ioremap(pdev, "mdp_intf_base", ctrl->name);
  608. if (!IS_ERR(ptr))
  609. ctrl->hw.mdp_intf_base = ptr;
  610. break;
  611. default:
  612. break;
  613. }
  614. return rc;
  615. }
  616. static int dsi_ctrl_clocks_deinit(struct dsi_ctrl *ctrl)
  617. {
  618. struct dsi_core_clk_info *core = &ctrl->clk_info.core_clks;
  619. struct dsi_link_lp_clk_info *lp_link = &ctrl->clk_info.lp_link_clks;
  620. struct dsi_link_hs_clk_info *hs_link = &ctrl->clk_info.hs_link_clks;
  621. struct dsi_clk_link_set *rcg = &ctrl->clk_info.rcg_clks;
  622. if (core->mdp_core_clk)
  623. devm_clk_put(&ctrl->pdev->dev, core->mdp_core_clk);
  624. if (core->iface_clk)
  625. devm_clk_put(&ctrl->pdev->dev, core->iface_clk);
  626. if (core->core_mmss_clk)
  627. devm_clk_put(&ctrl->pdev->dev, core->core_mmss_clk);
  628. if (core->bus_clk)
  629. devm_clk_put(&ctrl->pdev->dev, core->bus_clk);
  630. if (core->mnoc_clk)
  631. devm_clk_put(&ctrl->pdev->dev, core->mnoc_clk);
  632. memset(core, 0x0, sizeof(*core));
  633. if (hs_link->byte_clk)
  634. devm_clk_put(&ctrl->pdev->dev, hs_link->byte_clk);
  635. if (hs_link->pixel_clk)
  636. devm_clk_put(&ctrl->pdev->dev, hs_link->pixel_clk);
  637. if (lp_link->esc_clk)
  638. devm_clk_put(&ctrl->pdev->dev, lp_link->esc_clk);
  639. if (hs_link->byte_intf_clk)
  640. devm_clk_put(&ctrl->pdev->dev, hs_link->byte_intf_clk);
  641. memset(hs_link, 0x0, sizeof(*hs_link));
  642. memset(lp_link, 0x0, sizeof(*lp_link));
  643. if (rcg->byte_clk)
  644. devm_clk_put(&ctrl->pdev->dev, rcg->byte_clk);
  645. if (rcg->pixel_clk)
  646. devm_clk_put(&ctrl->pdev->dev, rcg->pixel_clk);
  647. memset(rcg, 0x0, sizeof(*rcg));
  648. return 0;
  649. }
  650. static int dsi_ctrl_clocks_init(struct platform_device *pdev,
  651. struct dsi_ctrl *ctrl)
  652. {
  653. int rc = 0;
  654. struct dsi_core_clk_info *core = &ctrl->clk_info.core_clks;
  655. struct dsi_link_lp_clk_info *lp_link = &ctrl->clk_info.lp_link_clks;
  656. struct dsi_link_hs_clk_info *hs_link = &ctrl->clk_info.hs_link_clks;
  657. struct dsi_clk_link_set *rcg = &ctrl->clk_info.rcg_clks;
  658. struct dsi_clk_link_set *xo = &ctrl->clk_info.xo_clk;
  659. core->mdp_core_clk = devm_clk_get(&pdev->dev, "mdp_core_clk");
  660. if (IS_ERR(core->mdp_core_clk)) {
  661. core->mdp_core_clk = NULL;
  662. DSI_CTRL_DEBUG(ctrl, "failed to get mdp_core_clk, rc=%d\n", rc);
  663. }
  664. core->iface_clk = devm_clk_get(&pdev->dev, "iface_clk");
  665. if (IS_ERR(core->iface_clk)) {
  666. core->iface_clk = NULL;
  667. DSI_CTRL_DEBUG(ctrl, "failed to get iface_clk, rc=%d\n", rc);
  668. }
  669. core->core_mmss_clk = devm_clk_get(&pdev->dev, "core_mmss_clk");
  670. if (IS_ERR(core->core_mmss_clk)) {
  671. core->core_mmss_clk = NULL;
  672. DSI_CTRL_DEBUG(ctrl, "failed to get core_mmss_clk, rc=%d\n",
  673. rc);
  674. }
  675. core->bus_clk = devm_clk_get(&pdev->dev, "bus_clk");
  676. if (IS_ERR(core->bus_clk)) {
  677. core->bus_clk = NULL;
  678. DSI_CTRL_DEBUG(ctrl, "failed to get bus_clk, rc=%d\n", rc);
  679. }
  680. core->mnoc_clk = devm_clk_get(&pdev->dev, "mnoc_clk");
  681. if (IS_ERR(core->mnoc_clk)) {
  682. core->mnoc_clk = NULL;
  683. DSI_CTRL_DEBUG(ctrl, "can't get mnoc clock, rc=%d\n", rc);
  684. }
  685. hs_link->byte_clk = devm_clk_get(&pdev->dev, "byte_clk");
  686. if (IS_ERR(hs_link->byte_clk)) {
  687. rc = PTR_ERR(hs_link->byte_clk);
  688. DSI_CTRL_ERR(ctrl, "failed to get byte_clk, rc=%d\n", rc);
  689. goto fail;
  690. }
  691. hs_link->pixel_clk = devm_clk_get(&pdev->dev, "pixel_clk");
  692. if (IS_ERR(hs_link->pixel_clk)) {
  693. rc = PTR_ERR(hs_link->pixel_clk);
  694. DSI_CTRL_ERR(ctrl, "failed to get pixel_clk, rc=%d\n", rc);
  695. goto fail;
  696. }
  697. lp_link->esc_clk = devm_clk_get(&pdev->dev, "esc_clk");
  698. if (IS_ERR(lp_link->esc_clk)) {
  699. rc = PTR_ERR(lp_link->esc_clk);
  700. DSI_CTRL_ERR(ctrl, "failed to get esc_clk, rc=%d\n", rc);
  701. goto fail;
  702. }
  703. hs_link->byte_intf_clk = devm_clk_get(&pdev->dev, "byte_intf_clk");
  704. if (IS_ERR(hs_link->byte_intf_clk)) {
  705. hs_link->byte_intf_clk = NULL;
  706. DSI_CTRL_DEBUG(ctrl, "can't find byte intf clk, rc=%d\n", rc);
  707. }
  708. rcg->byte_clk = devm_clk_get(&pdev->dev, "byte_clk_rcg");
  709. if (IS_ERR(rcg->byte_clk)) {
  710. rc = PTR_ERR(rcg->byte_clk);
  711. DSI_CTRL_ERR(ctrl, "failed to get byte_clk_rcg, rc=%d\n", rc);
  712. goto fail;
  713. }
  714. rcg->pixel_clk = devm_clk_get(&pdev->dev, "pixel_clk_rcg");
  715. if (IS_ERR(rcg->pixel_clk)) {
  716. rc = PTR_ERR(rcg->pixel_clk);
  717. DSI_CTRL_ERR(ctrl, "failed to get pixel_clk_rcg, rc=%d\n", rc);
  718. goto fail;
  719. }
  720. xo->byte_clk = devm_clk_get(&pdev->dev, "xo");
  721. if (IS_ERR(xo->byte_clk)) {
  722. xo->byte_clk = NULL;
  723. DSI_CTRL_DEBUG(ctrl, "failed to get xo clk, rc=%d\n", rc);
  724. }
  725. xo->pixel_clk = xo->byte_clk;
  726. return 0;
  727. fail:
  728. dsi_ctrl_clocks_deinit(ctrl);
  729. return rc;
  730. }
  731. static int dsi_ctrl_supplies_deinit(struct dsi_ctrl *ctrl)
  732. {
  733. int i = 0;
  734. int rc = 0;
  735. struct dsi_regulator_info *regs;
  736. regs = &ctrl->pwr_info.digital;
  737. for (i = 0; i < regs->count; i++) {
  738. if (!regs->vregs[i].vreg)
  739. DSI_CTRL_ERR(ctrl,
  740. "vreg is NULL, should not reach here\n");
  741. else
  742. devm_regulator_put(regs->vregs[i].vreg);
  743. }
  744. regs = &ctrl->pwr_info.host_pwr;
  745. for (i = 0; i < regs->count; i++) {
  746. if (!regs->vregs[i].vreg)
  747. DSI_CTRL_ERR(ctrl,
  748. "vreg is NULL, should not reach here\n");
  749. else
  750. devm_regulator_put(regs->vregs[i].vreg);
  751. }
  752. if (!ctrl->pwr_info.host_pwr.vregs) {
  753. devm_kfree(&ctrl->pdev->dev, ctrl->pwr_info.host_pwr.vregs);
  754. ctrl->pwr_info.host_pwr.vregs = NULL;
  755. ctrl->pwr_info.host_pwr.count = 0;
  756. }
  757. if (!ctrl->pwr_info.digital.vregs) {
  758. devm_kfree(&ctrl->pdev->dev, ctrl->pwr_info.digital.vregs);
  759. ctrl->pwr_info.digital.vregs = NULL;
  760. ctrl->pwr_info.digital.count = 0;
  761. }
  762. return rc;
  763. }
  764. static int dsi_ctrl_supplies_init(struct platform_device *pdev,
  765. struct dsi_ctrl *ctrl)
  766. {
  767. int rc = 0;
  768. int i = 0;
  769. struct dsi_regulator_info *regs;
  770. struct regulator *vreg = NULL;
  771. rc = dsi_pwr_get_dt_vreg_data(&pdev->dev,
  772. &ctrl->pwr_info.digital,
  773. "qcom,core-supply-entries");
  774. if (rc)
  775. DSI_CTRL_DEBUG(ctrl,
  776. "failed to get digital supply, rc = %d\n", rc);
  777. rc = dsi_pwr_get_dt_vreg_data(&pdev->dev,
  778. &ctrl->pwr_info.host_pwr,
  779. "qcom,ctrl-supply-entries");
  780. if (rc) {
  781. DSI_CTRL_ERR(ctrl,
  782. "failed to get host power supplies, rc = %d\n", rc);
  783. goto error_digital;
  784. }
  785. regs = &ctrl->pwr_info.digital;
  786. for (i = 0; i < regs->count; i++) {
  787. vreg = devm_regulator_get(&pdev->dev, regs->vregs[i].vreg_name);
  788. if (IS_ERR(vreg)) {
  789. DSI_CTRL_ERR(ctrl, "failed to get %s regulator\n",
  790. regs->vregs[i].vreg_name);
  791. rc = PTR_ERR(vreg);
  792. goto error_host_pwr;
  793. }
  794. regs->vregs[i].vreg = vreg;
  795. }
  796. regs = &ctrl->pwr_info.host_pwr;
  797. for (i = 0; i < regs->count; i++) {
  798. vreg = devm_regulator_get(&pdev->dev, regs->vregs[i].vreg_name);
  799. if (IS_ERR(vreg)) {
  800. DSI_CTRL_ERR(ctrl, "failed to get %s regulator\n",
  801. regs->vregs[i].vreg_name);
  802. for (--i; i >= 0; i--)
  803. devm_regulator_put(regs->vregs[i].vreg);
  804. rc = PTR_ERR(vreg);
  805. goto error_digital_put;
  806. }
  807. regs->vregs[i].vreg = vreg;
  808. }
  809. return rc;
  810. error_digital_put:
  811. regs = &ctrl->pwr_info.digital;
  812. for (i = 0; i < regs->count; i++)
  813. devm_regulator_put(regs->vregs[i].vreg);
  814. error_host_pwr:
  815. devm_kfree(&pdev->dev, ctrl->pwr_info.host_pwr.vregs);
  816. ctrl->pwr_info.host_pwr.vregs = NULL;
  817. ctrl->pwr_info.host_pwr.count = 0;
  818. error_digital:
  819. if (ctrl->pwr_info.digital.vregs)
  820. devm_kfree(&pdev->dev, ctrl->pwr_info.digital.vregs);
  821. ctrl->pwr_info.digital.vregs = NULL;
  822. ctrl->pwr_info.digital.count = 0;
  823. return rc;
  824. }
  825. static int dsi_ctrl_validate_panel_info(struct dsi_ctrl *dsi_ctrl,
  826. struct dsi_host_config *config)
  827. {
  828. int rc = 0;
  829. struct dsi_host_common_cfg *host_cfg = &config->common_config;
  830. if (config->panel_mode >= DSI_OP_MODE_MAX) {
  831. DSI_CTRL_ERR(dsi_ctrl, "Invalid dsi operation mode (%d)\n",
  832. config->panel_mode);
  833. rc = -EINVAL;
  834. goto err;
  835. }
  836. if ((host_cfg->data_lanes & (DSI_CLOCK_LANE - 1)) == 0) {
  837. DSI_CTRL_ERR(dsi_ctrl, "No data lanes are enabled\n");
  838. rc = -EINVAL;
  839. goto err;
  840. }
  841. err:
  842. return rc;
  843. }
  844. /* Function returns number of bits per pxl */
  845. int dsi_ctrl_pixel_format_to_bpp(enum dsi_pixel_format dst_format)
  846. {
  847. u32 bpp = 0;
  848. switch (dst_format) {
  849. case DSI_PIXEL_FORMAT_RGB111:
  850. bpp = 3;
  851. break;
  852. case DSI_PIXEL_FORMAT_RGB332:
  853. bpp = 8;
  854. break;
  855. case DSI_PIXEL_FORMAT_RGB444:
  856. bpp = 12;
  857. break;
  858. case DSI_PIXEL_FORMAT_RGB565:
  859. bpp = 16;
  860. break;
  861. case DSI_PIXEL_FORMAT_RGB666:
  862. case DSI_PIXEL_FORMAT_RGB666_LOOSE:
  863. bpp = 18;
  864. break;
  865. case DSI_PIXEL_FORMAT_RGB888:
  866. bpp = 24;
  867. break;
  868. case DSI_PIXEL_FORMAT_RGB101010:
  869. bpp = 30;
  870. break;
  871. default:
  872. bpp = 24;
  873. break;
  874. }
  875. return bpp;
  876. }
  877. static int dsi_ctrl_update_link_freqs(struct dsi_ctrl *dsi_ctrl,
  878. struct dsi_host_config *config, void *clk_handle,
  879. struct dsi_display_mode *mode)
  880. {
  881. int rc = 0;
  882. u32 num_of_lanes = 0;
  883. u32 bits_per_symbol = 16, num_of_symbols = 7; /* For Cphy */
  884. u32 bpp, frame_time_us, byte_intf_clk_div;
  885. u64 h_period, v_period, bit_rate, pclk_rate, bit_rate_per_lane,
  886. byte_clk_rate, byte_intf_clk_rate;
  887. struct dsi_host_common_cfg *host_cfg = &config->common_config;
  888. struct dsi_split_link_config *split_link = &host_cfg->split_link;
  889. struct dsi_mode_info *timing = &config->video_timing;
  890. u64 dsi_transfer_time_us = mode->priv_info->dsi_transfer_time_us;
  891. u64 min_dsi_clk_hz = mode->priv_info->min_dsi_clk_hz;
  892. /* Get bits per pxl in destination format */
  893. bpp = dsi_ctrl_pixel_format_to_bpp(host_cfg->dst_format);
  894. frame_time_us = mult_frac(1000, 1000, (timing->refresh_rate));
  895. if (host_cfg->data_lanes & DSI_DATA_LANE_0)
  896. num_of_lanes++;
  897. if (host_cfg->data_lanes & DSI_DATA_LANE_1)
  898. num_of_lanes++;
  899. if (host_cfg->data_lanes & DSI_DATA_LANE_2)
  900. num_of_lanes++;
  901. if (host_cfg->data_lanes & DSI_DATA_LANE_3)
  902. num_of_lanes++;
  903. if (split_link->enabled)
  904. num_of_lanes = split_link->lanes_per_sublink;
  905. config->common_config.num_data_lanes = num_of_lanes;
  906. config->common_config.bpp = bpp;
  907. if (config->bit_clk_rate_hz_override != 0) {
  908. bit_rate = config->bit_clk_rate_hz_override * num_of_lanes;
  909. if (host_cfg->phy_type == DSI_PHY_TYPE_CPHY) {
  910. bit_rate *= bits_per_symbol;
  911. do_div(bit_rate, num_of_symbols);
  912. }
  913. } else if (config->panel_mode == DSI_OP_CMD_MODE) {
  914. /* Calculate the bit rate needed to match dsi transfer time */
  915. if (host_cfg->phy_type == DSI_PHY_TYPE_CPHY) {
  916. min_dsi_clk_hz *= bits_per_symbol;
  917. do_div(min_dsi_clk_hz, num_of_symbols);
  918. }
  919. bit_rate = min_dsi_clk_hz * frame_time_us;
  920. do_div(bit_rate, dsi_transfer_time_us);
  921. bit_rate = bit_rate * num_of_lanes;
  922. } else {
  923. h_period = dsi_h_total_dce(timing);
  924. v_period = DSI_V_TOTAL(timing);
  925. bit_rate = h_period * v_period * timing->refresh_rate * bpp;
  926. }
  927. pclk_rate = bit_rate;
  928. do_div(pclk_rate, bpp);
  929. if (host_cfg->phy_type == DSI_PHY_TYPE_DPHY) {
  930. bit_rate_per_lane = bit_rate;
  931. do_div(bit_rate_per_lane, num_of_lanes);
  932. byte_clk_rate = bit_rate_per_lane;
  933. /**
  934. * Ensure that the byte clock rate is even to avoid failures
  935. * during set rate for byte intf clock. Round up to the nearest
  936. * even number for byte clk.
  937. */
  938. byte_clk_rate = DIV_ROUND_CLOSEST(byte_clk_rate, 8);
  939. byte_clk_rate = ((byte_clk_rate + 1) & ~BIT(0));
  940. byte_intf_clk_rate = byte_clk_rate;
  941. byte_intf_clk_div = host_cfg->byte_intf_clk_div;
  942. do_div(byte_intf_clk_rate, byte_intf_clk_div);
  943. config->bit_clk_rate_hz = byte_clk_rate * 8;
  944. } else {
  945. do_div(bit_rate, bits_per_symbol);
  946. bit_rate *= num_of_symbols;
  947. bit_rate_per_lane = bit_rate;
  948. do_div(bit_rate_per_lane, num_of_lanes);
  949. byte_clk_rate = bit_rate_per_lane;
  950. do_div(byte_clk_rate, 7);
  951. /* For CPHY, byte_intf_clk is same as byte_clk */
  952. byte_intf_clk_rate = byte_clk_rate;
  953. config->bit_clk_rate_hz = byte_clk_rate * 7;
  954. }
  955. DSI_CTRL_DEBUG(dsi_ctrl, "bit_clk_rate = %llu, bit_clk_rate_per_lane = %llu\n",
  956. bit_rate, bit_rate_per_lane);
  957. DSI_CTRL_DEBUG(dsi_ctrl, "byte_clk_rate = %llu, byte_intf_clk = %llu\n",
  958. byte_clk_rate, byte_intf_clk_rate);
  959. DSI_CTRL_DEBUG(dsi_ctrl, "pclk_rate = %llu\n", pclk_rate);
  960. SDE_EVT32(dsi_ctrl->cell_index, bit_rate, byte_clk_rate, pclk_rate);
  961. dsi_ctrl->clk_freq.byte_clk_rate = byte_clk_rate;
  962. dsi_ctrl->clk_freq.byte_intf_clk_rate = byte_intf_clk_rate;
  963. dsi_ctrl->clk_freq.pix_clk_rate = pclk_rate;
  964. dsi_ctrl->clk_freq.esc_clk_rate = config->esc_clk_rate_hz;
  965. return rc;
  966. }
  967. static int dsi_ctrl_enable_supplies(struct dsi_ctrl *dsi_ctrl, bool enable)
  968. {
  969. int rc = 0;
  970. if (enable) {
  971. rc = pm_runtime_resume_and_get(dsi_ctrl->drm_dev->dev);
  972. if (rc < 0) {
  973. DSI_CTRL_ERR(dsi_ctrl, "failed to enable power resource %d\n", rc);
  974. SDE_EVT32(rc, SDE_EVTLOG_ERROR);
  975. goto error;
  976. }
  977. if (!dsi_ctrl->current_state.host_initialized) {
  978. rc = dsi_pwr_enable_regulator(
  979. &dsi_ctrl->pwr_info.host_pwr, true);
  980. if (rc) {
  981. DSI_CTRL_ERR(dsi_ctrl, "failed to enable host power regs\n");
  982. goto error_get_sync;
  983. }
  984. }
  985. rc = dsi_pwr_enable_regulator(&dsi_ctrl->pwr_info.digital,
  986. true);
  987. if (rc) {
  988. DSI_CTRL_ERR(dsi_ctrl, "failed to enable gdsc, rc=%d\n",
  989. rc);
  990. (void)dsi_pwr_enable_regulator(
  991. &dsi_ctrl->pwr_info.host_pwr,
  992. false
  993. );
  994. goto error_get_sync;
  995. }
  996. return rc;
  997. } else {
  998. rc = dsi_pwr_enable_regulator(&dsi_ctrl->pwr_info.digital,
  999. false);
  1000. if (rc) {
  1001. DSI_CTRL_ERR(dsi_ctrl, "failed to disable gdsc, rc=%d\n",
  1002. rc);
  1003. goto error;
  1004. }
  1005. if (!dsi_ctrl->current_state.host_initialized) {
  1006. rc = dsi_pwr_enable_regulator(
  1007. &dsi_ctrl->pwr_info.host_pwr, false);
  1008. if (rc) {
  1009. DSI_CTRL_ERR(dsi_ctrl, "failed to disable host power regs\n");
  1010. goto error;
  1011. }
  1012. }
  1013. pm_runtime_put_sync(dsi_ctrl->drm_dev->dev);
  1014. return rc;
  1015. }
  1016. error_get_sync:
  1017. pm_runtime_put_sync(dsi_ctrl->drm_dev->dev);
  1018. error:
  1019. return rc;
  1020. }
  1021. static int dsi_ctrl_copy_and_pad_cmd(struct dsi_ctrl *dsi_ctrl,
  1022. const struct mipi_dsi_packet *packet,
  1023. u8 **buffer,
  1024. u32 *size)
  1025. {
  1026. int rc = 0;
  1027. u8 *buf = NULL;
  1028. u32 len, i;
  1029. u8 cmd_type = 0;
  1030. len = packet->size;
  1031. len += 0x3; len &= ~0x03; /* Align to 32 bits */
  1032. buf = devm_kzalloc(&dsi_ctrl->pdev->dev, len * sizeof(u8), GFP_KERNEL);
  1033. if (!buf)
  1034. return -ENOMEM;
  1035. for (i = 0; i < len; i++) {
  1036. if (i >= packet->size)
  1037. buf[i] = 0xFF;
  1038. else if (i < sizeof(packet->header))
  1039. buf[i] = packet->header[i];
  1040. else
  1041. buf[i] = packet->payload[i - sizeof(packet->header)];
  1042. }
  1043. if (packet->payload_length > 0)
  1044. buf[3] |= BIT(6);
  1045. /* Swap BYTE order in the command buffer for MSM */
  1046. buf[0] = packet->header[1];
  1047. buf[1] = packet->header[2];
  1048. buf[2] = packet->header[0];
  1049. /* send embedded BTA for read commands */
  1050. cmd_type = buf[2] & 0x3f;
  1051. if ((cmd_type == MIPI_DSI_DCS_READ) ||
  1052. (cmd_type == MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM) ||
  1053. (cmd_type == MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM) ||
  1054. (cmd_type == MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM))
  1055. buf[3] |= BIT(5);
  1056. *buffer = buf;
  1057. *size = len;
  1058. return rc;
  1059. }
  1060. int dsi_ctrl_wait_for_cmd_mode_mdp_idle(struct dsi_ctrl *dsi_ctrl)
  1061. {
  1062. int rc = 0;
  1063. if (!dsi_ctrl) {
  1064. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  1065. return -EINVAL;
  1066. }
  1067. if (dsi_ctrl->host_config.panel_mode != DSI_OP_CMD_MODE)
  1068. return -EINVAL;
  1069. mutex_lock(&dsi_ctrl->ctrl_lock);
  1070. rc = dsi_ctrl->hw.ops.wait_for_cmd_mode_mdp_idle(&dsi_ctrl->hw);
  1071. mutex_unlock(&dsi_ctrl->ctrl_lock);
  1072. return rc;
  1073. }
  1074. int dsi_message_validate_tx_mode(struct dsi_ctrl *dsi_ctrl,
  1075. u32 cmd_len,
  1076. u32 *flags)
  1077. {
  1078. int rc = 0;
  1079. if (*flags & DSI_CTRL_CMD_FIFO_STORE) {
  1080. /* if command size plus header is greater than fifo size */
  1081. if ((cmd_len + 4) > DSI_CTRL_MAX_CMD_FIFO_STORE_SIZE) {
  1082. DSI_CTRL_ERR(dsi_ctrl, "Cannot transfer Cmd in FIFO config\n");
  1083. return -ENOTSUPP;
  1084. }
  1085. if (!dsi_ctrl->hw.ops.kickoff_fifo_command) {
  1086. DSI_CTRL_ERR(dsi_ctrl, "Cannot transfer command,ops not defined\n");
  1087. return -ENOTSUPP;
  1088. }
  1089. }
  1090. if (*flags & DSI_CTRL_CMD_NON_EMBEDDED_MODE) {
  1091. if (*flags & DSI_CTRL_CMD_BROADCAST) {
  1092. DSI_CTRL_ERR(dsi_ctrl, "Non embedded not supported with broadcast\n");
  1093. return -ENOTSUPP;
  1094. }
  1095. if (!dsi_ctrl->hw.ops.kickoff_command_non_embedded_mode) {
  1096. DSI_CTRL_ERR(dsi_ctrl, " Cannot transfer command,ops not defined\n");
  1097. return -ENOTSUPP;
  1098. }
  1099. if ((cmd_len + 4) > SZ_4K) {
  1100. DSI_CTRL_ERR(dsi_ctrl, "Cannot transfer,size is greater than 4096\n");
  1101. return -ENOTSUPP;
  1102. }
  1103. }
  1104. if (*flags & DSI_CTRL_CMD_FETCH_MEMORY) {
  1105. if ((dsi_ctrl->cmd_len + cmd_len + 4) > SZ_4K) {
  1106. DSI_CTRL_ERR(dsi_ctrl, "Cannot transfer,size is greater than 4096\n");
  1107. return -ENOTSUPP;
  1108. }
  1109. }
  1110. return rc;
  1111. }
  1112. static void dsi_configure_command_scheduling(struct dsi_ctrl *dsi_ctrl,
  1113. struct dsi_ctrl_cmd_dma_info *cmd_mem)
  1114. {
  1115. u32 line_no = 0, window = 0, sched_line_no = 0;
  1116. struct dsi_ctrl_hw_ops dsi_hw_ops = dsi_ctrl->hw.ops;
  1117. struct dsi_mode_info *timing = &(dsi_ctrl->host_config.video_timing);
  1118. line_no = dsi_ctrl->host_config.common_config.dma_sched_line;
  1119. window = dsi_ctrl->host_config.common_config.dma_sched_window;
  1120. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_ENTRY, line_no, window);
  1121. /*
  1122. * In case of command scheduling in video mode, the line at which
  1123. * the command is scheduled can revert to the default value i.e. 1
  1124. * for the following cases:
  1125. * 1) No schedule line defined by the panel.
  1126. * 2) schedule line defined is greater than VFP.
  1127. */
  1128. if ((dsi_ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE) &&
  1129. dsi_hw_ops.schedule_dma_cmd &&
  1130. (dsi_ctrl->current_state.vid_engine_state ==
  1131. DSI_CTRL_ENGINE_ON)) {
  1132. sched_line_no = (line_no == 0) ? 1 : line_no;
  1133. if (timing) {
  1134. if (sched_line_no >= timing->v_front_porch)
  1135. sched_line_no = 1;
  1136. sched_line_no += timing->v_back_porch +
  1137. timing->v_sync_width + timing->v_active;
  1138. }
  1139. dsi_hw_ops.schedule_dma_cmd(&dsi_ctrl->hw, sched_line_no);
  1140. }
  1141. /*
  1142. * In case of command scheduling in command mode, set the maximum
  1143. * possible size of the DMA start window in case no schedule line and
  1144. * window size properties are defined by the panel.
  1145. */
  1146. if ((dsi_ctrl->host_config.panel_mode == DSI_OP_CMD_MODE) &&
  1147. dsi_hw_ops.configure_cmddma_window) {
  1148. sched_line_no = (line_no == 0) ? TEARCHECK_WINDOW_SIZE :
  1149. line_no;
  1150. window = (window == 0) ? timing->v_active : window;
  1151. sched_line_no += timing->v_active;
  1152. dsi_hw_ops.configure_cmddma_window(&dsi_ctrl->hw, cmd_mem,
  1153. sched_line_no, window);
  1154. }
  1155. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_EXIT,
  1156. sched_line_no, window);
  1157. }
  1158. static u32 calculate_schedule_line(struct dsi_ctrl *dsi_ctrl, u32 flags)
  1159. {
  1160. u32 line_no = 0x1;
  1161. struct dsi_mode_info *timing;
  1162. /* check if custom dma scheduling line needed */
  1163. if ((dsi_ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE) &&
  1164. (flags & DSI_CTRL_CMD_CUSTOM_DMA_SCHED))
  1165. line_no = dsi_ctrl->host_config.common_config.dma_sched_line;
  1166. timing = &(dsi_ctrl->host_config.video_timing);
  1167. if (timing)
  1168. line_no += timing->v_back_porch + timing->v_sync_width +
  1169. timing->v_active;
  1170. return line_no;
  1171. }
  1172. static void dsi_kickoff_msg_tx(struct dsi_ctrl *dsi_ctrl,
  1173. const struct mipi_dsi_msg *msg,
  1174. struct dsi_ctrl_cmd_dma_fifo_info *cmd,
  1175. struct dsi_ctrl_cmd_dma_info *cmd_mem,
  1176. u32 flags)
  1177. {
  1178. u32 hw_flags = 0;
  1179. struct dsi_ctrl_hw_ops dsi_hw_ops = dsi_ctrl->hw.ops;
  1180. struct dsi_split_link_config *split_link;
  1181. split_link = &(dsi_ctrl->host_config.common_config.split_link);
  1182. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_ENTRY, flags,
  1183. msg->flags);
  1184. if (dsi_hw_ops.splitlink_cmd_setup && split_link->enabled)
  1185. dsi_hw_ops.splitlink_cmd_setup(&dsi_ctrl->hw,
  1186. &dsi_ctrl->host_config.common_config, flags);
  1187. if (dsi_hw_ops.init_cmddma_trig_ctrl)
  1188. dsi_hw_ops.init_cmddma_trig_ctrl(&dsi_ctrl->hw,
  1189. &dsi_ctrl->host_config.common_config);
  1190. /*
  1191. * Always enable DMA scheduling for video mode panel.
  1192. *
  1193. * In video mode panel, if the DMA is triggered very close to
  1194. * the beginning of the active window and the DMA transfer
  1195. * happens in the last line of VBP, then the HW state will
  1196. * stay in ‘wait’ and return to ‘idle’ in the first line of VFP.
  1197. * But somewhere in the middle of the active window, if SW
  1198. * disables DSI command mode engine while the HW is still
  1199. * waiting and re-enable after timing engine is OFF. So the
  1200. * HW never ‘sees’ another vblank line and hence it gets
  1201. * stuck in the ‘wait’ state.
  1202. */
  1203. if ((flags & DSI_CTRL_CMD_CUSTOM_DMA_SCHED) ||
  1204. (dsi_ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE))
  1205. dsi_configure_command_scheduling(dsi_ctrl, cmd_mem);
  1206. dsi_ctrl->cmd_mode = (dsi_ctrl->host_config.panel_mode ==
  1207. DSI_OP_CMD_MODE);
  1208. hw_flags |= (flags & DSI_CTRL_CMD_DEFER_TRIGGER) ?
  1209. DSI_CTRL_HW_CMD_WAIT_FOR_TRIGGER : 0;
  1210. if (flags & DSI_CTRL_CMD_LAST_COMMAND)
  1211. hw_flags |= DSI_CTRL_CMD_LAST_COMMAND;
  1212. if (flags & DSI_CTRL_CMD_DEFER_TRIGGER) {
  1213. if (flags & DSI_CTRL_CMD_FETCH_MEMORY) {
  1214. if (flags & DSI_CTRL_CMD_NON_EMBEDDED_MODE) {
  1215. dsi_hw_ops.kickoff_command_non_embedded_mode(
  1216. &dsi_ctrl->hw,
  1217. cmd_mem,
  1218. hw_flags);
  1219. } else {
  1220. dsi_hw_ops.kickoff_command(
  1221. &dsi_ctrl->hw,
  1222. cmd_mem,
  1223. hw_flags);
  1224. }
  1225. } else if (flags & DSI_CTRL_CMD_FIFO_STORE) {
  1226. dsi_hw_ops.kickoff_fifo_command(&dsi_ctrl->hw,
  1227. cmd,
  1228. hw_flags);
  1229. }
  1230. }
  1231. if (!(flags & DSI_CTRL_CMD_DEFER_TRIGGER)) {
  1232. atomic_set(&dsi_ctrl->dma_irq_trig, 0);
  1233. dsi_ctrl_enable_status_interrupt(dsi_ctrl,
  1234. DSI_SINT_CMD_MODE_DMA_DONE, NULL);
  1235. reinit_completion(&dsi_ctrl->irq_info.cmd_dma_done);
  1236. if (flags & DSI_CTRL_CMD_FETCH_MEMORY) {
  1237. if (flags & DSI_CTRL_CMD_NON_EMBEDDED_MODE) {
  1238. dsi_hw_ops.kickoff_command_non_embedded_mode(
  1239. &dsi_ctrl->hw,
  1240. cmd_mem,
  1241. hw_flags);
  1242. } else {
  1243. dsi_hw_ops.kickoff_command(
  1244. &dsi_ctrl->hw,
  1245. cmd_mem,
  1246. hw_flags);
  1247. }
  1248. } else if (flags & DSI_CTRL_CMD_FIFO_STORE) {
  1249. dsi_hw_ops.kickoff_fifo_command(&dsi_ctrl->hw,
  1250. cmd,
  1251. hw_flags);
  1252. }
  1253. if (dsi_ctrl->enable_cmd_dma_stats) {
  1254. u32 reg = dsi_hw_ops.log_line_count(&dsi_ctrl->hw,
  1255. dsi_ctrl->cmd_mode);
  1256. dsi_ctrl->cmd_trigger_line = (reg & 0xFFFF);
  1257. dsi_ctrl->cmd_trigger_frame = ((reg >> 16) & 0xFFFF);
  1258. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_CASE1,
  1259. dsi_ctrl->cmd_trigger_line,
  1260. dsi_ctrl->cmd_trigger_frame);
  1261. }
  1262. dsi_hw_ops.reset_cmd_fifo(&dsi_ctrl->hw);
  1263. /*
  1264. * DSI 2.2 needs a soft reset whenever we send non-embedded
  1265. * mode command followed by embedded mode. Otherwise it will
  1266. * result in smmu write faults with DSI as client.
  1267. */
  1268. if (flags & DSI_CTRL_CMD_NON_EMBEDDED_MODE) {
  1269. if (dsi_ctrl->version < DSI_CTRL_VERSION_2_4)
  1270. dsi_hw_ops.soft_reset(&dsi_ctrl->hw);
  1271. dsi_ctrl->cmd_len = 0;
  1272. }
  1273. }
  1274. }
  1275. static int dsi_message_tx(struct dsi_ctrl *dsi_ctrl, struct dsi_cmd_desc *cmd_desc)
  1276. {
  1277. int rc = 0;
  1278. struct mipi_dsi_packet packet;
  1279. struct dsi_ctrl_cmd_dma_fifo_info cmd;
  1280. struct dsi_ctrl_cmd_dma_info cmd_mem;
  1281. const struct mipi_dsi_msg *msg;
  1282. u32 length = 0;
  1283. u8 *buffer = NULL;
  1284. u32 cnt = 0;
  1285. u8 *cmdbuf;
  1286. u32 *flags;
  1287. msg = &cmd_desc->msg;
  1288. flags = &cmd_desc->ctrl_flags;
  1289. /* Validate the mode before sending the command */
  1290. rc = dsi_message_validate_tx_mode(dsi_ctrl, msg->tx_len, flags);
  1291. if (rc) {
  1292. DSI_CTRL_ERR(dsi_ctrl,
  1293. "Cmd tx validation failed, cannot transfer cmd\n");
  1294. rc = -ENOTSUPP;
  1295. goto error;
  1296. }
  1297. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_ENTRY, *flags, dsi_ctrl->cmd_len);
  1298. if (*flags & DSI_CTRL_CMD_NON_EMBEDDED_MODE) {
  1299. cmd_mem.offset = dsi_ctrl->cmd_buffer_iova;
  1300. cmd_mem.en_broadcast = (*flags & DSI_CTRL_CMD_BROADCAST) ?
  1301. true : false;
  1302. cmd_mem.is_master = (*flags & DSI_CTRL_CMD_BROADCAST_MASTER) ?
  1303. true : false;
  1304. cmd_mem.use_lpm = (msg->flags & MIPI_DSI_MSG_USE_LPM) ?
  1305. true : false;
  1306. cmd_mem.datatype = msg->type;
  1307. cmd_mem.length = msg->tx_len;
  1308. dsi_ctrl->cmd_len = msg->tx_len;
  1309. memcpy(dsi_ctrl->vaddr, msg->tx_buf, msg->tx_len);
  1310. DSI_CTRL_DEBUG(dsi_ctrl,
  1311. "non-embedded mode , size of command =%zd\n",
  1312. msg->tx_len);
  1313. goto kickoff;
  1314. }
  1315. rc = mipi_dsi_create_packet(&packet, msg);
  1316. if (rc) {
  1317. DSI_CTRL_ERR(dsi_ctrl, "Failed to create message packet, rc=%d\n",
  1318. rc);
  1319. goto error;
  1320. }
  1321. rc = dsi_ctrl_copy_and_pad_cmd(dsi_ctrl,
  1322. &packet,
  1323. &buffer,
  1324. &length);
  1325. if (rc) {
  1326. DSI_CTRL_ERR(dsi_ctrl, "failed to copy message, rc=%d\n", rc);
  1327. goto error;
  1328. }
  1329. /*
  1330. * In case of broadcast CMD length cannot be greater than 512 bytes
  1331. * as specified by HW limitations. Need to overwrite the flags to
  1332. * set the LAST_COMMAND flag to ensure no command transfer failures.
  1333. */
  1334. if ((*flags & DSI_CTRL_CMD_FETCH_MEMORY) && (*flags & DSI_CTRL_CMD_BROADCAST)) {
  1335. if (((dsi_ctrl->cmd_len + length) > 240) && !(*flags & DSI_CTRL_CMD_LAST_COMMAND)) {
  1336. *flags |= DSI_CTRL_CMD_LAST_COMMAND;
  1337. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_CASE1, *flags);
  1338. }
  1339. }
  1340. if (*flags & DSI_CTRL_CMD_LAST_COMMAND)
  1341. buffer[3] |= BIT(7);//set the last cmd bit in header.
  1342. if (*flags & DSI_CTRL_CMD_FETCH_MEMORY) {
  1343. /* Embedded mode config is selected */
  1344. cmd_mem.offset = dsi_ctrl->cmd_buffer_iova;
  1345. cmd_mem.en_broadcast = (*flags & DSI_CTRL_CMD_BROADCAST) ?
  1346. true : false;
  1347. cmd_mem.is_master = (*flags & DSI_CTRL_CMD_BROADCAST_MASTER) ?
  1348. true : false;
  1349. cmd_mem.use_lpm = (msg->flags & MIPI_DSI_MSG_USE_LPM) ?
  1350. true : false;
  1351. cmdbuf = (u8 *)(dsi_ctrl->vaddr);
  1352. for (cnt = 0; cnt < length; cnt++)
  1353. cmdbuf[dsi_ctrl->cmd_len + cnt] = buffer[cnt];
  1354. dsi_ctrl->cmd_len += length;
  1355. msm_gem_sync(dsi_ctrl->tx_cmd_buf);
  1356. if (*flags & DSI_CTRL_CMD_LAST_COMMAND) {
  1357. cmd_mem.length = dsi_ctrl->cmd_len;
  1358. dsi_ctrl->cmd_len = 0;
  1359. } else {
  1360. goto error;
  1361. }
  1362. } else if (*flags & DSI_CTRL_CMD_FIFO_STORE) {
  1363. cmd.command = (u32 *)buffer;
  1364. cmd.size = length;
  1365. cmd.en_broadcast = (*flags & DSI_CTRL_CMD_BROADCAST) ?
  1366. true : false;
  1367. cmd.is_master = (*flags & DSI_CTRL_CMD_BROADCAST_MASTER) ?
  1368. true : false;
  1369. cmd.use_lpm = (msg->flags & MIPI_DSI_MSG_USE_LPM) ?
  1370. true : false;
  1371. }
  1372. kickoff:
  1373. dsi_kickoff_msg_tx(dsi_ctrl, msg, &cmd, &cmd_mem, *flags);
  1374. error:
  1375. if (buffer)
  1376. devm_kfree(&dsi_ctrl->pdev->dev, buffer);
  1377. return rc;
  1378. }
  1379. static int dsi_set_max_return_size(struct dsi_ctrl *dsi_ctrl, struct dsi_cmd_desc *rx_cmd, u32 size)
  1380. {
  1381. int rc = 0;
  1382. const struct mipi_dsi_msg *rx_msg = &rx_cmd->msg;
  1383. u8 tx[2] = { (u8)(size & 0xFF), (u8)(size >> 8) };
  1384. u16 dflags = rx_msg->flags;
  1385. struct dsi_cmd_desc cmd= {
  1386. .msg.channel = rx_msg->channel,
  1387. .msg.type = MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE,
  1388. .msg.tx_len = 2,
  1389. .msg.tx_buf = tx,
  1390. .msg.flags = rx_msg->flags,
  1391. };
  1392. /* remove last message flag to batch max packet cmd to read command */
  1393. dflags &= ~BIT(3);
  1394. cmd.msg.flags = dflags;
  1395. cmd.ctrl_flags = DSI_CTRL_CMD_FETCH_MEMORY;
  1396. rc = dsi_message_tx(dsi_ctrl, &cmd);
  1397. if (rc)
  1398. DSI_CTRL_ERR(dsi_ctrl, "failed to send max return size packet, rc=%d\n",
  1399. rc);
  1400. return rc;
  1401. }
  1402. /* Helper functions to support DCS read operation */
  1403. static int dsi_parse_short_read1_resp(const struct mipi_dsi_msg *msg,
  1404. unsigned char *buff)
  1405. {
  1406. u8 *data = msg->rx_buf;
  1407. int read_len = 1;
  1408. if (!data)
  1409. return 0;
  1410. /* remove dcs type */
  1411. if (msg->rx_len >= 1)
  1412. data[0] = buff[1];
  1413. else
  1414. read_len = 0;
  1415. return read_len;
  1416. }
  1417. static int dsi_parse_short_read2_resp(const struct mipi_dsi_msg *msg,
  1418. unsigned char *buff)
  1419. {
  1420. u8 *data = msg->rx_buf;
  1421. int read_len = 2;
  1422. if (!data)
  1423. return 0;
  1424. /* remove dcs type */
  1425. if (msg->rx_len >= 2) {
  1426. data[0] = buff[1];
  1427. data[1] = buff[2];
  1428. } else {
  1429. read_len = 0;
  1430. }
  1431. return read_len;
  1432. }
  1433. static int dsi_parse_long_read_resp(const struct mipi_dsi_msg *msg,
  1434. unsigned char *buff)
  1435. {
  1436. if (!msg->rx_buf)
  1437. return 0;
  1438. /* remove dcs type */
  1439. if (msg->rx_buf && msg->rx_len)
  1440. memcpy(msg->rx_buf, buff + 4, msg->rx_len);
  1441. return msg->rx_len;
  1442. }
  1443. static int dsi_message_rx(struct dsi_ctrl *dsi_ctrl, struct dsi_cmd_desc *cmd_desc)
  1444. {
  1445. int rc = 0;
  1446. u32 rd_pkt_size, total_read_len, hw_read_cnt;
  1447. u32 current_read_len = 0, total_bytes_read = 0;
  1448. bool short_resp = false;
  1449. bool read_done = false;
  1450. u32 dlen, diff, rlen;
  1451. unsigned char *buff = NULL;
  1452. char cmd;
  1453. const struct mipi_dsi_msg *msg;
  1454. u32 buffer_sz = 0, header_offset = 0;
  1455. u8 *head = NULL;
  1456. if (!cmd_desc) {
  1457. DSI_CTRL_ERR(dsi_ctrl, "Invalid command\n");
  1458. rc = -EINVAL;
  1459. goto error;
  1460. }
  1461. msg = &cmd_desc->msg;
  1462. rlen = msg->rx_len;
  1463. if (msg->rx_len <= 2) {
  1464. short_resp = true;
  1465. rd_pkt_size = msg->rx_len;
  1466. total_read_len = 4;
  1467. /*
  1468. * buffer size: header + data
  1469. * No 32 bits alignment issue, thus offset is 0
  1470. */
  1471. buffer_sz = 4;
  1472. } else {
  1473. short_resp = false;
  1474. current_read_len = 10;
  1475. if (msg->rx_len < current_read_len)
  1476. rd_pkt_size = msg->rx_len;
  1477. else
  1478. rd_pkt_size = current_read_len;
  1479. total_read_len = current_read_len + 6;
  1480. /*
  1481. * buffer size: header + data + footer, rounded up to 4 bytes.
  1482. * Out of bound can occur if rx_len is not aligned to size 4.
  1483. */
  1484. buffer_sz = 4 + msg->rx_len + 2;
  1485. buffer_sz = ALIGN(buffer_sz, 4);
  1486. if (buffer_sz < 16)
  1487. buffer_sz = 16;
  1488. }
  1489. buff = kzalloc(buffer_sz, GFP_KERNEL);
  1490. if (!buff) {
  1491. rc = -ENOMEM;
  1492. goto error;
  1493. }
  1494. head = buff;
  1495. while (!read_done) {
  1496. rc = dsi_set_max_return_size(dsi_ctrl, cmd_desc, rd_pkt_size);
  1497. if (rc) {
  1498. DSI_CTRL_ERR(dsi_ctrl, "Failed to set max return packet size, rc=%d\n",
  1499. rc);
  1500. goto error;
  1501. }
  1502. /* clear RDBK_DATA registers before proceeding */
  1503. dsi_ctrl->hw.ops.clear_rdbk_register(&dsi_ctrl->hw);
  1504. rc = dsi_message_tx(dsi_ctrl, cmd_desc);
  1505. if (rc) {
  1506. DSI_CTRL_ERR(dsi_ctrl, "Message transmission failed, rc=%d\n",
  1507. rc);
  1508. goto error;
  1509. }
  1510. /* Wait for read command transfer success */
  1511. dsi_ctrl_dma_cmd_wait_for_done(dsi_ctrl);
  1512. /*
  1513. * wait before reading rdbk_data register, if any delay is
  1514. * required after sending the read command.
  1515. */
  1516. if (cmd_desc->post_wait_ms)
  1517. usleep_range(cmd_desc->post_wait_ms * 1000,
  1518. ((cmd_desc->post_wait_ms * 1000) + 10));
  1519. dlen = dsi_ctrl->hw.ops.get_cmd_read_data(&dsi_ctrl->hw,
  1520. buff, total_bytes_read,
  1521. total_read_len, rd_pkt_size,
  1522. &hw_read_cnt);
  1523. if (!dlen)
  1524. goto error;
  1525. if (short_resp)
  1526. break;
  1527. if (rlen <= current_read_len) {
  1528. diff = current_read_len - rlen;
  1529. read_done = true;
  1530. } else {
  1531. diff = 0;
  1532. rlen -= current_read_len;
  1533. }
  1534. dlen -= 2; /* 2 bytes of CRC */
  1535. dlen -= diff;
  1536. buff += dlen;
  1537. total_bytes_read += dlen;
  1538. if (!read_done) {
  1539. current_read_len = 14; /* Not first read */
  1540. if (rlen < current_read_len)
  1541. rd_pkt_size += rlen;
  1542. else
  1543. rd_pkt_size += current_read_len;
  1544. }
  1545. }
  1546. buff = head;
  1547. if (hw_read_cnt < 16 && !short_resp)
  1548. header_offset = (16 - hw_read_cnt);
  1549. else
  1550. header_offset = 0;
  1551. /* parse the data read from panel */
  1552. cmd = buff[header_offset];
  1553. switch (cmd) {
  1554. case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
  1555. DSI_CTRL_ERR(dsi_ctrl, "Rx ACK_ERROR 0x%x\n", cmd);
  1556. rc = 0;
  1557. break;
  1558. case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE:
  1559. case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
  1560. rc = dsi_parse_short_read1_resp(msg, &buff[header_offset]);
  1561. break;
  1562. case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE:
  1563. case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
  1564. rc = dsi_parse_short_read2_resp(msg, &buff[header_offset]);
  1565. break;
  1566. case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE:
  1567. case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE:
  1568. rc = dsi_parse_long_read_resp(msg, &buff[header_offset]);
  1569. break;
  1570. default:
  1571. DSI_CTRL_WARN(dsi_ctrl, "Invalid response: 0x%x\n", cmd);
  1572. rc = 0;
  1573. }
  1574. error:
  1575. kfree(buff);
  1576. return rc;
  1577. }
  1578. static int dsi_enable_ulps(struct dsi_ctrl *dsi_ctrl)
  1579. {
  1580. int rc = 0;
  1581. u32 lanes = 0;
  1582. u32 ulps_lanes;
  1583. lanes = dsi_ctrl->host_config.common_config.data_lanes;
  1584. rc = dsi_ctrl->hw.ops.wait_for_lane_idle(&dsi_ctrl->hw, lanes);
  1585. if (rc) {
  1586. DSI_CTRL_ERR(dsi_ctrl, "lanes not entering idle, skip ULPS\n");
  1587. return rc;
  1588. }
  1589. if (!dsi_ctrl->hw.ops.ulps_ops.ulps_request ||
  1590. !dsi_ctrl->hw.ops.ulps_ops.ulps_exit) {
  1591. DSI_CTRL_DEBUG(dsi_ctrl, "DSI controller ULPS ops not present\n");
  1592. return 0;
  1593. }
  1594. if (!dsi_is_type_cphy(&dsi_ctrl->host_config.common_config))
  1595. lanes |= DSI_CLOCK_LANE;
  1596. dsi_ctrl->hw.ops.ulps_ops.ulps_request(&dsi_ctrl->hw, lanes);
  1597. ulps_lanes = dsi_ctrl->hw.ops.ulps_ops.get_lanes_in_ulps(&dsi_ctrl->hw);
  1598. if ((lanes & ulps_lanes) != lanes) {
  1599. DSI_CTRL_ERR(dsi_ctrl, "Failed to enter ULPS, request=0x%x, actual=0x%x\n",
  1600. lanes, ulps_lanes);
  1601. rc = -EIO;
  1602. }
  1603. return rc;
  1604. }
  1605. static int dsi_disable_ulps(struct dsi_ctrl *dsi_ctrl)
  1606. {
  1607. int rc = 0;
  1608. u32 ulps_lanes, lanes = 0;
  1609. dsi_ctrl->hw.ops.clear_phy0_ln_err(&dsi_ctrl->hw);
  1610. if (!dsi_ctrl->hw.ops.ulps_ops.ulps_request ||
  1611. !dsi_ctrl->hw.ops.ulps_ops.ulps_exit) {
  1612. DSI_CTRL_DEBUG(dsi_ctrl, "DSI controller ULPS ops not present\n");
  1613. return 0;
  1614. }
  1615. lanes = dsi_ctrl->host_config.common_config.data_lanes;
  1616. if (!dsi_is_type_cphy(&dsi_ctrl->host_config.common_config))
  1617. lanes |= DSI_CLOCK_LANE;
  1618. ulps_lanes = dsi_ctrl->hw.ops.ulps_ops.get_lanes_in_ulps(&dsi_ctrl->hw);
  1619. if ((lanes & ulps_lanes) != lanes)
  1620. DSI_CTRL_ERR(dsi_ctrl, "Mismatch between lanes in ULPS\n");
  1621. lanes &= ulps_lanes;
  1622. dsi_ctrl->hw.ops.ulps_ops.ulps_exit(&dsi_ctrl->hw, lanes);
  1623. ulps_lanes = dsi_ctrl->hw.ops.ulps_ops.get_lanes_in_ulps(&dsi_ctrl->hw);
  1624. if (ulps_lanes & lanes) {
  1625. DSI_CTRL_ERR(dsi_ctrl, "Lanes (0x%x) stuck in ULPS\n",
  1626. ulps_lanes);
  1627. rc = -EIO;
  1628. }
  1629. return rc;
  1630. }
  1631. void dsi_ctrl_toggle_error_interrupt_status(struct dsi_ctrl *dsi_ctrl, bool enable)
  1632. {
  1633. if (!enable) {
  1634. dsi_ctrl->hw.ops.enable_error_interrupts(&dsi_ctrl->hw, 0);
  1635. } else {
  1636. if (dsi_ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE &&
  1637. !dsi_ctrl->host_config.u.video_engine.bllp_lp11_en &&
  1638. !dsi_ctrl->host_config.u.video_engine.eof_bllp_lp11_en)
  1639. dsi_ctrl->hw.ops.enable_error_interrupts(&dsi_ctrl->hw, 0xFF00A0);
  1640. else
  1641. dsi_ctrl->hw.ops.enable_error_interrupts(&dsi_ctrl->hw, 0xFF00E0);
  1642. }
  1643. }
  1644. static int dsi_ctrl_drv_state_init(struct dsi_ctrl *dsi_ctrl)
  1645. {
  1646. int rc = 0;
  1647. bool splash_enabled = false;
  1648. struct dsi_ctrl_state_info *state = &dsi_ctrl->current_state;
  1649. if (!splash_enabled) {
  1650. state->power_state = DSI_CTRL_POWER_VREG_OFF;
  1651. state->cmd_engine_state = DSI_CTRL_ENGINE_OFF;
  1652. state->vid_engine_state = DSI_CTRL_ENGINE_OFF;
  1653. }
  1654. return rc;
  1655. }
  1656. static int dsi_ctrl_buffer_deinit(struct dsi_ctrl *dsi_ctrl)
  1657. {
  1658. struct msm_gem_address_space *aspace = NULL;
  1659. if (dsi_ctrl->tx_cmd_buf) {
  1660. aspace = dsi_ctrl_get_aspace(dsi_ctrl,
  1661. MSM_SMMU_DOMAIN_UNSECURE);
  1662. if (!aspace) {
  1663. DSI_CTRL_ERR(dsi_ctrl, "failed to get address space\n");
  1664. return -ENOMEM;
  1665. }
  1666. msm_gem_put_iova(dsi_ctrl->tx_cmd_buf, aspace);
  1667. mutex_lock(&dsi_ctrl->drm_dev->struct_mutex);
  1668. msm_gem_free_object(dsi_ctrl->tx_cmd_buf);
  1669. mutex_unlock(&dsi_ctrl->drm_dev->struct_mutex);
  1670. dsi_ctrl->tx_cmd_buf = NULL;
  1671. }
  1672. return 0;
  1673. }
  1674. int dsi_ctrl_buffer_init(struct dsi_ctrl *dsi_ctrl)
  1675. {
  1676. int rc = 0;
  1677. u64 iova = 0;
  1678. struct msm_gem_address_space *aspace = NULL;
  1679. aspace = dsi_ctrl_get_aspace(dsi_ctrl, MSM_SMMU_DOMAIN_UNSECURE);
  1680. if (!aspace) {
  1681. DSI_CTRL_ERR(dsi_ctrl, "failed to get address space\n");
  1682. return -ENOMEM;
  1683. }
  1684. dsi_ctrl->tx_cmd_buf = msm_gem_new(dsi_ctrl->drm_dev,
  1685. SZ_4K,
  1686. MSM_BO_UNCACHED);
  1687. if (IS_ERR(dsi_ctrl->tx_cmd_buf)) {
  1688. rc = PTR_ERR(dsi_ctrl->tx_cmd_buf);
  1689. DSI_CTRL_ERR(dsi_ctrl, "failed to allocate gem, rc=%d\n", rc);
  1690. dsi_ctrl->tx_cmd_buf = NULL;
  1691. goto error;
  1692. }
  1693. dsi_ctrl->cmd_buffer_size = SZ_4K;
  1694. rc = msm_gem_get_iova(dsi_ctrl->tx_cmd_buf, aspace, &iova);
  1695. if (rc) {
  1696. DSI_CTRL_ERR(dsi_ctrl, "failed to get iova, rc=%d\n", rc);
  1697. (void)dsi_ctrl_buffer_deinit(dsi_ctrl);
  1698. goto error;
  1699. }
  1700. if (iova & 0x07) {
  1701. DSI_CTRL_ERR(dsi_ctrl, "Tx command buffer is not 8 byte aligned\n");
  1702. rc = -ENOTSUPP;
  1703. (void)dsi_ctrl_buffer_deinit(dsi_ctrl);
  1704. goto error;
  1705. }
  1706. error:
  1707. return rc;
  1708. }
  1709. static int dsi_enable_io_clamp(struct dsi_ctrl *dsi_ctrl,
  1710. bool enable, bool ulps_enabled)
  1711. {
  1712. u32 lanes = 0;
  1713. if (dsi_ctrl->host_config.panel_mode == DSI_OP_CMD_MODE)
  1714. lanes = dsi_ctrl->host_config.common_config.data_lanes;
  1715. lanes |= DSI_CLOCK_LANE;
  1716. if (enable)
  1717. dsi_ctrl->hw.ops.clamp_enable(&dsi_ctrl->hw,
  1718. lanes, ulps_enabled);
  1719. else
  1720. dsi_ctrl->hw.ops.clamp_disable(&dsi_ctrl->hw,
  1721. lanes, ulps_enabled);
  1722. return 0;
  1723. }
  1724. static int dsi_ctrl_dts_parse(struct dsi_ctrl *dsi_ctrl,
  1725. struct device_node *of_node)
  1726. {
  1727. u32 index = 0, frame_threshold_time_us = 0;
  1728. int rc = 0;
  1729. if (!dsi_ctrl || !of_node) {
  1730. DSI_CTRL_ERR(dsi_ctrl, "invalid dsi_ctrl:%d or of_node:%d\n",
  1731. dsi_ctrl != NULL, of_node != NULL);
  1732. return -EINVAL;
  1733. }
  1734. rc = of_property_read_u32(of_node, "cell-index", &index);
  1735. if (rc) {
  1736. DSI_CTRL_DEBUG(dsi_ctrl, "cell index not set, default to 0\n");
  1737. index = 0;
  1738. }
  1739. dsi_ctrl->cell_index = index;
  1740. dsi_ctrl->name = of_get_property(of_node, "label", NULL);
  1741. if (!dsi_ctrl->name)
  1742. dsi_ctrl->name = DSI_CTRL_DEFAULT_LABEL;
  1743. dsi_ctrl->null_insertion_enabled = of_property_read_bool(of_node,
  1744. "qcom,null-insertion-enabled");
  1745. dsi_ctrl->split_link_supported = of_property_read_bool(of_node,
  1746. "qcom,split-link-supported");
  1747. dsi_ctrl->phy_pll_bypass = of_property_read_bool(of_node,
  1748. "qcom,dsi-phy-pll-bypass");
  1749. rc = of_property_read_u32(of_node, "frame-threshold-time-us",
  1750. &frame_threshold_time_us);
  1751. if (rc) {
  1752. DSI_CTRL_DEBUG(dsi_ctrl,
  1753. "frame-threshold-time not specified, defaulting\n");
  1754. frame_threshold_time_us = 2666;
  1755. }
  1756. dsi_ctrl->frame_threshold_time_us = frame_threshold_time_us;
  1757. dsi_ctrl->dsi_ctrl_shared = of_property_read_bool(of_node, "qcom,dsi-ctrl-shared");
  1758. return 0;
  1759. }
  1760. static int dsi_ctrl_dev_probe(struct platform_device *pdev)
  1761. {
  1762. struct dsi_ctrl *dsi_ctrl;
  1763. struct dsi_ctrl_list_item *item;
  1764. const struct of_device_id *id;
  1765. enum dsi_ctrl_version version;
  1766. int rc = 0;
  1767. id = of_match_node(msm_dsi_of_match, pdev->dev.of_node);
  1768. if (!id)
  1769. return -ENODEV;
  1770. version = *(enum dsi_ctrl_version *)id->data;
  1771. item = devm_kzalloc(&pdev->dev, sizeof(*item), GFP_KERNEL);
  1772. if (!item)
  1773. return -ENOMEM;
  1774. dsi_ctrl = devm_kzalloc(&pdev->dev, sizeof(*dsi_ctrl), GFP_KERNEL);
  1775. if (!dsi_ctrl)
  1776. return -ENOMEM;
  1777. dsi_ctrl->version = version;
  1778. dsi_ctrl->irq_info.irq_num = -1;
  1779. dsi_ctrl->irq_info.irq_stat_mask = 0x0;
  1780. INIT_WORK(&dsi_ctrl->post_cmd_tx_work, dsi_ctrl_post_cmd_transfer_work);
  1781. atomic_set(&dsi_ctrl->dma_irq_trig, 0);
  1782. spin_lock_init(&dsi_ctrl->irq_info.irq_lock);
  1783. rc = dsi_ctrl_dts_parse(dsi_ctrl, pdev->dev.of_node);
  1784. if (rc) {
  1785. DSI_CTRL_ERR(dsi_ctrl, "dts parse failed, rc = %d\n", rc);
  1786. goto fail;
  1787. }
  1788. rc = dsi_ctrl_init_regmap(pdev, dsi_ctrl);
  1789. if (rc) {
  1790. DSI_CTRL_ERR(dsi_ctrl, "Failed to parse register information, rc = %d\n",
  1791. rc);
  1792. goto fail;
  1793. }
  1794. rc = dsi_ctrl_supplies_init(pdev, dsi_ctrl);
  1795. if (rc) {
  1796. DSI_CTRL_ERR(dsi_ctrl, "Failed to parse voltage supplies, rc = %d\n",
  1797. rc);
  1798. goto fail;
  1799. }
  1800. rc = dsi_ctrl_clocks_init(pdev, dsi_ctrl);
  1801. if (rc) {
  1802. DSI_CTRL_ERR(dsi_ctrl, "Failed to parse clock information, rc = %d\n",
  1803. rc);
  1804. goto fail_supplies;
  1805. }
  1806. rc = dsi_catalog_ctrl_setup(&dsi_ctrl->hw, dsi_ctrl->version,
  1807. dsi_ctrl->cell_index, dsi_ctrl->phy_pll_bypass,
  1808. dsi_ctrl->null_insertion_enabled);
  1809. if (rc) {
  1810. DSI_CTRL_ERR(dsi_ctrl, "Catalog does not support version (%d)\n",
  1811. dsi_ctrl->version);
  1812. goto fail_clks;
  1813. }
  1814. item->ctrl = dsi_ctrl;
  1815. sde_dbg_dsi_ctrl_register(dsi_ctrl->hw.base, dsi_ctrl->name);
  1816. mutex_lock(&dsi_ctrl_list_lock);
  1817. list_add(&item->list, &dsi_ctrl_list);
  1818. mutex_unlock(&dsi_ctrl_list_lock);
  1819. mutex_init(&dsi_ctrl->ctrl_lock);
  1820. dsi_ctrl->secure_mode = false;
  1821. dsi_ctrl->pdev = pdev;
  1822. platform_set_drvdata(pdev, dsi_ctrl);
  1823. DSI_CTRL_INFO(dsi_ctrl, "Probe successful\n");
  1824. return 0;
  1825. fail_clks:
  1826. (void)dsi_ctrl_clocks_deinit(dsi_ctrl);
  1827. fail_supplies:
  1828. (void)dsi_ctrl_supplies_deinit(dsi_ctrl);
  1829. fail:
  1830. return rc;
  1831. }
  1832. static int dsi_ctrl_dev_remove(struct platform_device *pdev)
  1833. {
  1834. int rc = 0;
  1835. struct dsi_ctrl *dsi_ctrl;
  1836. struct list_head *pos, *tmp;
  1837. dsi_ctrl = platform_get_drvdata(pdev);
  1838. mutex_lock(&dsi_ctrl_list_lock);
  1839. list_for_each_safe(pos, tmp, &dsi_ctrl_list) {
  1840. struct dsi_ctrl_list_item *n = list_entry(pos,
  1841. struct dsi_ctrl_list_item,
  1842. list);
  1843. if (n->ctrl == dsi_ctrl) {
  1844. list_del(&n->list);
  1845. break;
  1846. }
  1847. }
  1848. mutex_unlock(&dsi_ctrl_list_lock);
  1849. mutex_lock(&dsi_ctrl->ctrl_lock);
  1850. dsi_ctrl_isr_configure(dsi_ctrl, false);
  1851. rc = dsi_ctrl_supplies_deinit(dsi_ctrl);
  1852. if (rc)
  1853. DSI_CTRL_ERR(dsi_ctrl,
  1854. "failed to deinitialize voltage supplies, rc=%d\n",
  1855. rc);
  1856. rc = dsi_ctrl_clocks_deinit(dsi_ctrl);
  1857. if (rc)
  1858. DSI_CTRL_ERR(dsi_ctrl,
  1859. "failed to deinitialize clocks, rc=%d\n", rc);
  1860. atomic_set(&dsi_ctrl->dma_irq_trig, 0);
  1861. mutex_unlock(&dsi_ctrl->ctrl_lock);
  1862. mutex_destroy(&dsi_ctrl->ctrl_lock);
  1863. devm_kfree(&pdev->dev, dsi_ctrl);
  1864. platform_set_drvdata(pdev, NULL);
  1865. return 0;
  1866. }
  1867. static struct platform_driver dsi_ctrl_driver = {
  1868. .probe = dsi_ctrl_dev_probe,
  1869. .remove = dsi_ctrl_dev_remove,
  1870. .driver = {
  1871. .name = "drm_dsi_ctrl",
  1872. .of_match_table = msm_dsi_of_match,
  1873. .suppress_bind_attrs = true,
  1874. },
  1875. };
  1876. int dsi_ctrl_get_io_resources(struct msm_io_res *io_res)
  1877. {
  1878. int rc = 0;
  1879. struct dsi_ctrl_list_item *dsi_ctrl;
  1880. mutex_lock(&dsi_ctrl_list_lock);
  1881. list_for_each_entry(dsi_ctrl, &dsi_ctrl_list, list) {
  1882. rc = msm_dss_get_io_mem(dsi_ctrl->ctrl->pdev, &io_res->mem);
  1883. if (rc) {
  1884. DSI_CTRL_ERR(dsi_ctrl->ctrl,
  1885. "failed to get io mem, rc = %d\n", rc);
  1886. return rc;
  1887. }
  1888. }
  1889. mutex_unlock(&dsi_ctrl_list_lock);
  1890. return rc;
  1891. }
  1892. /**
  1893. * dsi_ctrl_check_resource() - check if DSI controller is probed
  1894. * @of_node: of_node of the DSI controller.
  1895. *
  1896. * Checks if the DSI controller has been probed and is available.
  1897. *
  1898. * Return: status of DSI controller
  1899. */
  1900. bool dsi_ctrl_check_resource(struct device_node *of_node)
  1901. {
  1902. struct list_head *pos, *tmp;
  1903. struct dsi_ctrl *ctrl = NULL;
  1904. mutex_lock(&dsi_ctrl_list_lock);
  1905. list_for_each_safe(pos, tmp, &dsi_ctrl_list) {
  1906. struct dsi_ctrl_list_item *n;
  1907. n = list_entry(pos, struct dsi_ctrl_list_item, list);
  1908. if (!n->ctrl || !n->ctrl->pdev)
  1909. break;
  1910. if (n->ctrl->pdev->dev.of_node == of_node) {
  1911. ctrl = n->ctrl;
  1912. break;
  1913. }
  1914. }
  1915. mutex_unlock(&dsi_ctrl_list_lock);
  1916. return ctrl ? true : false;
  1917. }
  1918. /**
  1919. * dsi_ctrl_get() - get a dsi_ctrl handle from an of_node
  1920. * @of_node: of_node of the DSI controller.
  1921. *
  1922. * Gets the DSI controller handle for the corresponding of_node. The ref count
  1923. * is incremented to one and all subsequent gets will fail until the original
  1924. * clients calls a put.
  1925. *
  1926. * Return: DSI Controller handle.
  1927. */
  1928. struct dsi_ctrl *dsi_ctrl_get(struct device_node *of_node)
  1929. {
  1930. struct list_head *pos, *tmp;
  1931. struct dsi_ctrl *ctrl = NULL;
  1932. mutex_lock(&dsi_ctrl_list_lock);
  1933. list_for_each_safe(pos, tmp, &dsi_ctrl_list) {
  1934. struct dsi_ctrl_list_item *n;
  1935. n = list_entry(pos, struct dsi_ctrl_list_item, list);
  1936. if (n->ctrl->pdev->dev.of_node == of_node) {
  1937. ctrl = n->ctrl;
  1938. break;
  1939. }
  1940. }
  1941. mutex_unlock(&dsi_ctrl_list_lock);
  1942. if (!ctrl) {
  1943. DSI_CTRL_ERR(ctrl, "Device with of node not found rc=%d\n",
  1944. -EPROBE_DEFER);
  1945. ctrl = ERR_PTR(-EPROBE_DEFER);
  1946. return ctrl;
  1947. }
  1948. mutex_lock(&ctrl->ctrl_lock);
  1949. if ((ctrl->dsi_ctrl_shared && ctrl->refcount == 2) ||
  1950. (!ctrl->dsi_ctrl_shared && ctrl->refcount == 1)) {
  1951. DSI_CTRL_ERR(ctrl, "Device in use\n");
  1952. mutex_unlock(&ctrl->ctrl_lock);
  1953. ctrl = ERR_PTR(-EBUSY);
  1954. return ctrl;
  1955. }
  1956. ctrl->refcount++;
  1957. mutex_unlock(&ctrl->ctrl_lock);
  1958. return ctrl;
  1959. }
  1960. /**
  1961. * dsi_ctrl_put() - releases a dsi controller handle.
  1962. * @dsi_ctrl: DSI controller handle.
  1963. *
  1964. * Releases the DSI controller. Driver will clean up all resources and puts back
  1965. * the DSI controller into reset state.
  1966. */
  1967. void dsi_ctrl_put(struct dsi_ctrl *dsi_ctrl)
  1968. {
  1969. mutex_lock(&dsi_ctrl->ctrl_lock);
  1970. if (dsi_ctrl->refcount == 0)
  1971. DSI_CTRL_ERR(dsi_ctrl, "Unbalanced %s call\n", __func__);
  1972. else
  1973. dsi_ctrl->refcount--;
  1974. mutex_unlock(&dsi_ctrl->ctrl_lock);
  1975. }
  1976. /**
  1977. * dsi_ctrl_drv_init() - initialize dsi controller driver.
  1978. * @dsi_ctrl: DSI controller handle.
  1979. * @parent: Parent directory for debug fs.
  1980. *
  1981. * Initializes DSI controller driver. Driver should be initialized after
  1982. * dsi_ctrl_get() succeeds.
  1983. *
  1984. * Return: error code.
  1985. */
  1986. int dsi_ctrl_drv_init(struct dsi_ctrl *dsi_ctrl, struct dentry *parent)
  1987. {
  1988. char dbg_name[DSI_DEBUG_NAME_LEN];
  1989. int rc = 0;
  1990. if (!dsi_ctrl) {
  1991. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  1992. return -EINVAL;
  1993. }
  1994. mutex_lock(&dsi_ctrl->ctrl_lock);
  1995. rc = dsi_ctrl_drv_state_init(dsi_ctrl);
  1996. if (rc) {
  1997. DSI_CTRL_ERR(dsi_ctrl, "Failed to initialize driver state, rc=%d\n",
  1998. rc);
  1999. goto error;
  2000. }
  2001. rc = dsi_ctrl_debugfs_init(dsi_ctrl, parent);
  2002. if (rc) {
  2003. DSI_CTRL_ERR(dsi_ctrl, "failed to init debug fs, rc=%d\n", rc);
  2004. goto error;
  2005. }
  2006. snprintf(dbg_name, DSI_DEBUG_NAME_LEN, "dsi%d_ctrl", dsi_ctrl->cell_index);
  2007. sde_dbg_reg_register_base(dbg_name, dsi_ctrl->hw.base,
  2008. msm_iomap_size(dsi_ctrl->pdev, "dsi_ctrl"),
  2009. msm_get_phys_addr(dsi_ctrl->pdev, "dsi_ctrl"), SDE_DBG_DSI);
  2010. error:
  2011. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2012. return rc;
  2013. }
  2014. /**
  2015. * dsi_ctrl_drv_deinit() - de-initializes dsi controller driver
  2016. * @dsi_ctrl: DSI controller handle.
  2017. *
  2018. * Releases all resources acquired by dsi_ctrl_drv_init().
  2019. *
  2020. * Return: error code.
  2021. */
  2022. int dsi_ctrl_drv_deinit(struct dsi_ctrl *dsi_ctrl)
  2023. {
  2024. int rc = 0;
  2025. if (!dsi_ctrl) {
  2026. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2027. return -EINVAL;
  2028. }
  2029. mutex_lock(&dsi_ctrl->ctrl_lock);
  2030. rc = dsi_ctrl_debugfs_deinit(dsi_ctrl);
  2031. if (rc)
  2032. DSI_CTRL_ERR(dsi_ctrl, "failed to release debugfs root, rc=%d\n",
  2033. rc);
  2034. rc = dsi_ctrl_buffer_deinit(dsi_ctrl);
  2035. if (rc)
  2036. DSI_CTRL_ERR(dsi_ctrl, "Failed to free cmd buffers, rc=%d\n",
  2037. rc);
  2038. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2039. return rc;
  2040. }
  2041. int dsi_ctrl_clk_cb_register(struct dsi_ctrl *dsi_ctrl,
  2042. struct clk_ctrl_cb *clk_cb)
  2043. {
  2044. if (!dsi_ctrl || !clk_cb) {
  2045. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2046. return -EINVAL;
  2047. }
  2048. dsi_ctrl->clk_cb.priv = clk_cb->priv;
  2049. dsi_ctrl->clk_cb.dsi_clk_cb = clk_cb->dsi_clk_cb;
  2050. return 0;
  2051. }
  2052. /**
  2053. * dsi_ctrl_phy_sw_reset() - perform a PHY software reset
  2054. * @dsi_ctrl: DSI controller handle.
  2055. *
  2056. * Performs a PHY software reset on the DSI controller. Reset should be done
  2057. * when the controller power state is DSI_CTRL_POWER_CORE_CLK_ON and the PHY is
  2058. * not enabled.
  2059. *
  2060. * This function will fail if driver is in any other state.
  2061. *
  2062. * Return: error code.
  2063. */
  2064. int dsi_ctrl_phy_sw_reset(struct dsi_ctrl *dsi_ctrl)
  2065. {
  2066. int rc = 0;
  2067. if (!dsi_ctrl) {
  2068. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2069. return -EINVAL;
  2070. }
  2071. mutex_lock(&dsi_ctrl->ctrl_lock);
  2072. rc = dsi_ctrl_check_state(dsi_ctrl, DSI_CTRL_OP_PHY_SW_RESET, 0x0);
  2073. if (rc) {
  2074. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n",
  2075. rc);
  2076. goto error;
  2077. }
  2078. dsi_ctrl->hw.ops.phy_sw_reset(&dsi_ctrl->hw);
  2079. DSI_CTRL_DEBUG(dsi_ctrl, "PHY soft reset done\n");
  2080. dsi_ctrl_update_state(dsi_ctrl, DSI_CTRL_OP_PHY_SW_RESET, 0x0);
  2081. error:
  2082. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2083. return rc;
  2084. }
  2085. /**
  2086. * dsi_ctrl_seamless_timing_update() - update only controller timing
  2087. * @dsi_ctrl: DSI controller handle.
  2088. * @timing: New DSI timing info
  2089. *
  2090. * Updates host timing values to conduct a seamless transition to new timing
  2091. * For example, to update the porch values in a dynamic fps switch.
  2092. *
  2093. * Return: error code.
  2094. */
  2095. int dsi_ctrl_async_timing_update(struct dsi_ctrl *dsi_ctrl,
  2096. struct dsi_mode_info *timing)
  2097. {
  2098. struct dsi_mode_info *host_mode;
  2099. int rc = 0;
  2100. if (!dsi_ctrl || !timing) {
  2101. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2102. return -EINVAL;
  2103. }
  2104. mutex_lock(&dsi_ctrl->ctrl_lock);
  2105. rc = dsi_ctrl_check_state(dsi_ctrl, DSI_CTRL_OP_ASYNC_TIMING,
  2106. DSI_CTRL_ENGINE_ON);
  2107. if (rc) {
  2108. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n",
  2109. rc);
  2110. goto exit;
  2111. }
  2112. host_mode = &dsi_ctrl->host_config.video_timing;
  2113. memcpy(host_mode, timing, sizeof(*host_mode));
  2114. dsi_ctrl->hw.ops.set_timing_db(&dsi_ctrl->hw, true);
  2115. dsi_ctrl->hw.ops.set_video_timing(&dsi_ctrl->hw, host_mode);
  2116. exit:
  2117. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2118. return rc;
  2119. }
  2120. /**
  2121. * dsi_ctrl_timing_db_update() - update only controller Timing DB
  2122. * @dsi_ctrl: DSI controller handle.
  2123. * @enable: Enable/disable Timing DB register
  2124. * @pf_time_in_us: Programmable fetch time in micro-seconds
  2125. *
  2126. * Update timing db register value during dfps usecases
  2127. *
  2128. * Return: error code.
  2129. */
  2130. int dsi_ctrl_timing_db_update(struct dsi_ctrl *dsi_ctrl,
  2131. bool enable, u32 pf_time_in_us)
  2132. {
  2133. int rc = 0;
  2134. if (!dsi_ctrl) {
  2135. DSI_CTRL_ERR(dsi_ctrl, "Invalid dsi_ctrl\n");
  2136. return -EINVAL;
  2137. }
  2138. mutex_lock(&dsi_ctrl->ctrl_lock);
  2139. rc = dsi_ctrl_check_state(dsi_ctrl, DSI_CTRL_OP_ASYNC_TIMING,
  2140. DSI_CTRL_ENGINE_ON);
  2141. if (rc) {
  2142. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n",
  2143. rc);
  2144. goto exit;
  2145. }
  2146. /*
  2147. * Add HW recommended delay for dfps feature.
  2148. * When prefetch is enabled, MDSS HW works on 2 vsync
  2149. * boundaries i.e. mdp_vsync and panel_vsync.
  2150. * In the current implementation we are only waiting
  2151. * for mdp_vsync. We need to make sure that interface
  2152. * flush is after panel_vsync. So, added the recommended
  2153. * delays after dfps update.
  2154. */
  2155. if (pf_time_in_us > 2000) {
  2156. DSI_CTRL_ERR(dsi_ctrl, "Programmable fetch time check failed, pf_time_in_us=%u\n",
  2157. pf_time_in_us);
  2158. pf_time_in_us = 2000;
  2159. }
  2160. usleep_range(pf_time_in_us, pf_time_in_us + 10);
  2161. dsi_ctrl->hw.ops.set_timing_db(&dsi_ctrl->hw, enable);
  2162. exit:
  2163. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2164. return rc;
  2165. }
  2166. int dsi_ctrl_timing_setup(struct dsi_ctrl *dsi_ctrl)
  2167. {
  2168. int rc = 0;
  2169. if (!dsi_ctrl) {
  2170. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2171. return -EINVAL;
  2172. }
  2173. mutex_lock(&dsi_ctrl->ctrl_lock);
  2174. if (dsi_ctrl->host_config.panel_mode == DSI_OP_CMD_MODE) {
  2175. dsi_ctrl->hw.ops.cmd_engine_setup(&dsi_ctrl->hw,
  2176. &dsi_ctrl->host_config.common_config,
  2177. &dsi_ctrl->host_config.u.cmd_engine);
  2178. dsi_ctrl->hw.ops.setup_cmd_stream(&dsi_ctrl->hw,
  2179. &dsi_ctrl->host_config.video_timing,
  2180. &dsi_ctrl->host_config.common_config,
  2181. 0x0,
  2182. &dsi_ctrl->roi);
  2183. dsi_ctrl->hw.ops.cmd_engine_en(&dsi_ctrl->hw, true);
  2184. } else {
  2185. dsi_ctrl->hw.ops.video_engine_setup(&dsi_ctrl->hw,
  2186. &dsi_ctrl->host_config.common_config,
  2187. &dsi_ctrl->host_config.u.video_engine);
  2188. dsi_ctrl->hw.ops.set_video_timing(&dsi_ctrl->hw,
  2189. &dsi_ctrl->host_config.video_timing);
  2190. dsi_ctrl->hw.ops.video_engine_en(&dsi_ctrl->hw, true);
  2191. }
  2192. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2193. return rc;
  2194. }
  2195. int dsi_ctrl_setup(struct dsi_ctrl *dsi_ctrl)
  2196. {
  2197. int rc = 0;
  2198. rc = dsi_ctrl_timing_setup(dsi_ctrl);
  2199. if (rc)
  2200. return -EINVAL;
  2201. mutex_lock(&dsi_ctrl->ctrl_lock);
  2202. dsi_ctrl->hw.ops.setup_lane_map(&dsi_ctrl->hw,
  2203. &dsi_ctrl->host_config.lane_map);
  2204. dsi_ctrl->hw.ops.host_setup(&dsi_ctrl->hw,
  2205. &dsi_ctrl->host_config.common_config);
  2206. dsi_ctrl->hw.ops.enable_status_interrupts(&dsi_ctrl->hw, 0x0);
  2207. dsi_ctrl_toggle_error_interrupt_status(dsi_ctrl, true);
  2208. dsi_ctrl->hw.ops.ctrl_en(&dsi_ctrl->hw, true);
  2209. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2210. return rc;
  2211. }
  2212. int dsi_ctrl_set_roi(struct dsi_ctrl *dsi_ctrl, struct dsi_rect *roi,
  2213. bool *changed)
  2214. {
  2215. int rc = 0;
  2216. if (!dsi_ctrl || !roi || !changed) {
  2217. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2218. return -EINVAL;
  2219. }
  2220. mutex_lock(&dsi_ctrl->ctrl_lock);
  2221. if ((!dsi_rect_is_equal(&dsi_ctrl->roi, roi)) ||
  2222. dsi_ctrl->modeupdated) {
  2223. *changed = true;
  2224. memcpy(&dsi_ctrl->roi, roi, sizeof(dsi_ctrl->roi));
  2225. dsi_ctrl->modeupdated = false;
  2226. } else
  2227. *changed = false;
  2228. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2229. return rc;
  2230. }
  2231. /**
  2232. * dsi_ctrl_config_clk_gating() - Enable/disable DSI PHY clk gating.
  2233. * @dsi_ctrl: DSI controller handle.
  2234. * @enable: Enable/disable DSI PHY clk gating
  2235. * @clk_selection: clock to enable/disable clock gating
  2236. *
  2237. * Return: error code.
  2238. */
  2239. int dsi_ctrl_config_clk_gating(struct dsi_ctrl *dsi_ctrl, bool enable,
  2240. enum dsi_clk_gate_type clk_selection)
  2241. {
  2242. if (!dsi_ctrl) {
  2243. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2244. return -EINVAL;
  2245. }
  2246. if (dsi_ctrl->hw.ops.config_clk_gating)
  2247. dsi_ctrl->hw.ops.config_clk_gating(&dsi_ctrl->hw, enable,
  2248. clk_selection);
  2249. return 0;
  2250. }
  2251. /**
  2252. * dsi_ctrl_phy_reset_config() - Mask/unmask propagation of ahb reset signal
  2253. * to DSI PHY hardware.
  2254. * @dsi_ctrl: DSI controller handle.
  2255. * @enable: Mask/unmask the PHY reset signal.
  2256. *
  2257. * Return: error code.
  2258. */
  2259. int dsi_ctrl_phy_reset_config(struct dsi_ctrl *dsi_ctrl, bool enable)
  2260. {
  2261. if (!dsi_ctrl) {
  2262. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2263. return -EINVAL;
  2264. }
  2265. if (dsi_ctrl->hw.ops.phy_reset_config)
  2266. dsi_ctrl->hw.ops.phy_reset_config(&dsi_ctrl->hw, enable);
  2267. return 0;
  2268. }
  2269. static bool dsi_ctrl_check_for_spurious_error_interrupts(
  2270. struct dsi_ctrl *dsi_ctrl)
  2271. {
  2272. const unsigned long intr_check_interval = msecs_to_jiffies(1000);
  2273. const unsigned int interrupt_threshold = 15;
  2274. unsigned long jiffies_now = jiffies;
  2275. if (!dsi_ctrl) {
  2276. DSI_CTRL_ERR(dsi_ctrl, "Invalid DSI controller structure\n");
  2277. return false;
  2278. }
  2279. if (dsi_ctrl->jiffies_start == 0)
  2280. dsi_ctrl->jiffies_start = jiffies;
  2281. dsi_ctrl->error_interrupt_count++;
  2282. if ((jiffies_now - dsi_ctrl->jiffies_start) < intr_check_interval) {
  2283. if (dsi_ctrl->error_interrupt_count > interrupt_threshold) {
  2284. SDE_EVT32_IRQ(dsi_ctrl->cell_index,
  2285. dsi_ctrl->error_interrupt_count,
  2286. interrupt_threshold);
  2287. return true;
  2288. }
  2289. } else {
  2290. dsi_ctrl->jiffies_start = jiffies;
  2291. dsi_ctrl->error_interrupt_count = 1;
  2292. }
  2293. return false;
  2294. }
  2295. static void dsi_ctrl_handle_error_status(struct dsi_ctrl *dsi_ctrl,
  2296. unsigned long error)
  2297. {
  2298. struct dsi_event_cb_info cb_info;
  2299. struct dsi_display *display;
  2300. bool skip_irq_enable = false;
  2301. bool is_spurious_interrupt = false;
  2302. cb_info = dsi_ctrl->irq_info.irq_err_cb;
  2303. /* disable error interrupts */
  2304. if (dsi_ctrl->hw.ops.error_intr_ctrl)
  2305. dsi_ctrl->hw.ops.error_intr_ctrl(&dsi_ctrl->hw, false);
  2306. /* clear error interrupts first */
  2307. if (dsi_ctrl->hw.ops.clear_error_status)
  2308. dsi_ctrl->hw.ops.clear_error_status(&dsi_ctrl->hw,
  2309. error);
  2310. /* check for spurious interrupts */
  2311. if (dsi_ctrl_check_for_spurious_error_interrupts(dsi_ctrl))
  2312. is_spurious_interrupt = true;
  2313. /* DTLN PHY error */
  2314. if (error & 0x3000E00)
  2315. pr_err_ratelimited("[%s] dsi PHY contention error: 0x%lx\n",
  2316. dsi_ctrl->name, error);
  2317. /* ignore TX timeout if blpp_lp11 is disabled */
  2318. if (dsi_ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE &&
  2319. !dsi_ctrl->host_config.u.video_engine.bllp_lp11_en &&
  2320. !dsi_ctrl->host_config.u.video_engine.eof_bllp_lp11_en)
  2321. error &= ~DSI_HS_TX_TIMEOUT;
  2322. /* TX timeout error */
  2323. if (error & 0xE0) {
  2324. if (error & 0xA0) {
  2325. if (cb_info.event_cb) {
  2326. cb_info.event_idx = DSI_LP_Rx_TIMEOUT;
  2327. (void)cb_info.event_cb(cb_info.event_usr_ptr,
  2328. cb_info.event_idx,
  2329. dsi_ctrl->cell_index,
  2330. 0, 0, 0, 0);
  2331. }
  2332. }
  2333. }
  2334. /* DSI FIFO OVERFLOW error */
  2335. if (error & 0xF0000) {
  2336. u32 mask = 0;
  2337. if (dsi_ctrl->hw.ops.get_error_mask)
  2338. mask = dsi_ctrl->hw.ops.get_error_mask(&dsi_ctrl->hw);
  2339. /* no need to report FIFO overflow if already masked */
  2340. if (cb_info.event_cb && !(mask & 0xf0000)) {
  2341. cb_info.event_idx = DSI_FIFO_OVERFLOW;
  2342. display = cb_info.event_usr_ptr;
  2343. display->is_spurious_interrupt = is_spurious_interrupt;
  2344. (void)cb_info.event_cb(cb_info.event_usr_ptr,
  2345. cb_info.event_idx,
  2346. dsi_ctrl->cell_index,
  2347. 0, 0, 0, 0);
  2348. skip_irq_enable = true;
  2349. }
  2350. }
  2351. /* DSI FIFO UNDERFLOW error */
  2352. if (error & 0xF00000) {
  2353. if (cb_info.event_cb) {
  2354. cb_info.event_idx = DSI_FIFO_UNDERFLOW;
  2355. display = cb_info.event_usr_ptr;
  2356. display->is_spurious_interrupt = is_spurious_interrupt;
  2357. (void)cb_info.event_cb(cb_info.event_usr_ptr,
  2358. cb_info.event_idx,
  2359. dsi_ctrl->cell_index,
  2360. 0, 0, 0, 0);
  2361. skip_irq_enable = true;
  2362. }
  2363. }
  2364. /* DSI PLL UNLOCK error */
  2365. if (error & BIT(8))
  2366. DSI_CTRL_ERR(dsi_ctrl, "dsi PLL unlock error: 0x%lx\n", error);
  2367. /* ACK error */
  2368. if (error & 0xF)
  2369. DSI_CTRL_ERR(dsi_ctrl, "ack error: 0x%lx\n", error);
  2370. /*
  2371. * DSI Phy can go into bad state during ESD influence. This can
  2372. * manifest as various types of spurious error interrupts on
  2373. * DSI controller. This check will allow us to handle afore mentioned
  2374. * case and prevent us from re enabling interrupts until a full ESD
  2375. * recovery is completed.
  2376. */
  2377. if (is_spurious_interrupt && dsi_ctrl->esd_check_underway) {
  2378. dsi_ctrl->hw.ops.soft_reset(&dsi_ctrl->hw);
  2379. return;
  2380. }
  2381. /* enable back DSI interrupts */
  2382. if (dsi_ctrl->hw.ops.error_intr_ctrl && !skip_irq_enable)
  2383. dsi_ctrl->hw.ops.error_intr_ctrl(&dsi_ctrl->hw, true);
  2384. }
  2385. /**
  2386. * dsi_ctrl_isr - interrupt service routine for DSI CTRL component
  2387. * @irq: Incoming IRQ number
  2388. * @ptr: Pointer to user data structure (struct dsi_ctrl)
  2389. * Returns: IRQ_HANDLED if no further action required
  2390. */
  2391. static irqreturn_t dsi_ctrl_isr(int irq, void *ptr)
  2392. {
  2393. struct dsi_ctrl *dsi_ctrl;
  2394. struct dsi_event_cb_info cb_info;
  2395. unsigned long flags;
  2396. uint32_t status = 0x0, i;
  2397. uint64_t errors = 0x0;
  2398. if (!ptr)
  2399. return IRQ_NONE;
  2400. dsi_ctrl = ptr;
  2401. /* check status interrupts */
  2402. if (dsi_ctrl->hw.ops.get_interrupt_status)
  2403. status = dsi_ctrl->hw.ops.get_interrupt_status(&dsi_ctrl->hw);
  2404. /* check error interrupts */
  2405. if (dsi_ctrl->hw.ops.get_error_status)
  2406. errors = dsi_ctrl->hw.ops.get_error_status(&dsi_ctrl->hw);
  2407. /* clear interrupts */
  2408. if (dsi_ctrl->hw.ops.clear_interrupt_status)
  2409. dsi_ctrl->hw.ops.clear_interrupt_status(&dsi_ctrl->hw, 0x0);
  2410. SDE_EVT32_IRQ(dsi_ctrl->cell_index, status, errors);
  2411. /* handle DSI error recovery */
  2412. if (status & DSI_ERROR)
  2413. dsi_ctrl_handle_error_status(dsi_ctrl, errors);
  2414. if (status & DSI_CMD_MODE_DMA_DONE) {
  2415. if (dsi_ctrl->enable_cmd_dma_stats) {
  2416. u32 reg = dsi_ctrl->hw.ops.log_line_count(&dsi_ctrl->hw,
  2417. dsi_ctrl->cmd_mode);
  2418. dsi_ctrl->cmd_success_line = (reg & 0xFFFF);
  2419. dsi_ctrl->cmd_success_frame = ((reg >> 16) & 0xFFFF);
  2420. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_CASE1,
  2421. dsi_ctrl->cmd_success_line,
  2422. dsi_ctrl->cmd_success_frame);
  2423. }
  2424. dsi_ctrl->cmd_success_ts = ktime_get();
  2425. atomic_set(&dsi_ctrl->dma_irq_trig, 1);
  2426. dsi_ctrl_disable_status_interrupt(dsi_ctrl,
  2427. DSI_SINT_CMD_MODE_DMA_DONE);
  2428. complete_all(&dsi_ctrl->irq_info.cmd_dma_done);
  2429. }
  2430. if (status & DSI_CMD_FRAME_DONE) {
  2431. dsi_ctrl_disable_status_interrupt(dsi_ctrl,
  2432. DSI_SINT_CMD_FRAME_DONE);
  2433. complete_all(&dsi_ctrl->irq_info.cmd_frame_done);
  2434. }
  2435. if (status & DSI_VIDEO_MODE_FRAME_DONE) {
  2436. dsi_ctrl_disable_status_interrupt(dsi_ctrl,
  2437. DSI_SINT_VIDEO_MODE_FRAME_DONE);
  2438. complete_all(&dsi_ctrl->irq_info.vid_frame_done);
  2439. }
  2440. if (status & DSI_BTA_DONE) {
  2441. u32 fifo_overflow_mask = (DSI_DLN0_HS_FIFO_OVERFLOW |
  2442. DSI_DLN1_HS_FIFO_OVERFLOW |
  2443. DSI_DLN2_HS_FIFO_OVERFLOW |
  2444. DSI_DLN3_HS_FIFO_OVERFLOW);
  2445. dsi_ctrl_disable_status_interrupt(dsi_ctrl,
  2446. DSI_SINT_BTA_DONE);
  2447. complete_all(&dsi_ctrl->irq_info.bta_done);
  2448. if (dsi_ctrl->hw.ops.clear_error_status)
  2449. dsi_ctrl->hw.ops.clear_error_status(&dsi_ctrl->hw,
  2450. fifo_overflow_mask);
  2451. }
  2452. for (i = 0; status && i < DSI_STATUS_INTERRUPT_COUNT; ++i) {
  2453. if (status & 0x1) {
  2454. spin_lock_irqsave(&dsi_ctrl->irq_info.irq_lock, flags);
  2455. cb_info = dsi_ctrl->irq_info.irq_stat_cb[i];
  2456. spin_unlock_irqrestore(
  2457. &dsi_ctrl->irq_info.irq_lock, flags);
  2458. if (cb_info.event_cb)
  2459. (void)cb_info.event_cb(cb_info.event_usr_ptr,
  2460. cb_info.event_idx,
  2461. dsi_ctrl->cell_index,
  2462. irq, 0, 0, 0);
  2463. }
  2464. status >>= 1;
  2465. }
  2466. return IRQ_HANDLED;
  2467. }
  2468. /**
  2469. * _dsi_ctrl_setup_isr - register ISR handler
  2470. * @dsi_ctrl: Pointer to associated dsi_ctrl structure
  2471. * Returns: Zero on success
  2472. */
  2473. static int _dsi_ctrl_setup_isr(struct dsi_ctrl *dsi_ctrl)
  2474. {
  2475. int irq_num, rc;
  2476. if (!dsi_ctrl)
  2477. return -EINVAL;
  2478. if (dsi_ctrl->irq_info.irq_num != -1)
  2479. return 0;
  2480. init_completion(&dsi_ctrl->irq_info.cmd_dma_done);
  2481. init_completion(&dsi_ctrl->irq_info.vid_frame_done);
  2482. init_completion(&dsi_ctrl->irq_info.cmd_frame_done);
  2483. init_completion(&dsi_ctrl->irq_info.bta_done);
  2484. irq_num = platform_get_irq(dsi_ctrl->pdev, 0);
  2485. if (irq_num < 0) {
  2486. DSI_CTRL_ERR(dsi_ctrl, "Failed to get IRQ number, %d\n",
  2487. irq_num);
  2488. rc = irq_num;
  2489. } else {
  2490. rc = devm_request_threaded_irq(&dsi_ctrl->pdev->dev, irq_num,
  2491. dsi_ctrl_isr, NULL, 0, "dsi_ctrl", dsi_ctrl);
  2492. if (rc) {
  2493. DSI_CTRL_ERR(dsi_ctrl, "Failed to request IRQ, %d\n",
  2494. rc);
  2495. } else {
  2496. dsi_ctrl->irq_info.irq_num = irq_num;
  2497. disable_irq_nosync(irq_num);
  2498. DSI_CTRL_INFO(dsi_ctrl, "IRQ %d registered\n", irq_num);
  2499. }
  2500. }
  2501. return rc;
  2502. }
  2503. /**
  2504. * _dsi_ctrl_destroy_isr - unregister ISR handler
  2505. * @dsi_ctrl: Pointer to associated dsi_ctrl structure
  2506. */
  2507. static void _dsi_ctrl_destroy_isr(struct dsi_ctrl *dsi_ctrl)
  2508. {
  2509. if (!dsi_ctrl || !dsi_ctrl->pdev || dsi_ctrl->irq_info.irq_num < 0)
  2510. return;
  2511. if (dsi_ctrl->irq_info.irq_num != -1) {
  2512. devm_free_irq(&dsi_ctrl->pdev->dev,
  2513. dsi_ctrl->irq_info.irq_num, dsi_ctrl);
  2514. dsi_ctrl->irq_info.irq_num = -1;
  2515. }
  2516. }
  2517. void dsi_ctrl_enable_status_interrupt(struct dsi_ctrl *dsi_ctrl,
  2518. uint32_t intr_idx, struct dsi_event_cb_info *event_info)
  2519. {
  2520. unsigned long flags;
  2521. if (!dsi_ctrl || dsi_ctrl->irq_info.irq_num == -1 ||
  2522. intr_idx >= DSI_STATUS_INTERRUPT_COUNT)
  2523. return;
  2524. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_ENTRY, intr_idx,
  2525. dsi_ctrl->irq_info.irq_num, dsi_ctrl->irq_info.irq_stat_mask,
  2526. dsi_ctrl->irq_info.irq_stat_refcount[intr_idx]);
  2527. spin_lock_irqsave(&dsi_ctrl->irq_info.irq_lock, flags);
  2528. if (dsi_ctrl->irq_info.irq_stat_refcount[intr_idx] == 0) {
  2529. /* enable irq on first request */
  2530. if (dsi_ctrl->irq_info.irq_stat_mask == 0)
  2531. enable_irq(dsi_ctrl->irq_info.irq_num);
  2532. /* update hardware mask */
  2533. dsi_ctrl->irq_info.irq_stat_mask |= BIT(intr_idx);
  2534. dsi_ctrl->hw.ops.enable_status_interrupts(&dsi_ctrl->hw,
  2535. dsi_ctrl->irq_info.irq_stat_mask);
  2536. }
  2537. if (intr_idx == DSI_SINT_CMD_MODE_DMA_DONE)
  2538. dsi_ctrl->hw.ops.enable_status_interrupts(&dsi_ctrl->hw,
  2539. dsi_ctrl->irq_info.irq_stat_mask);
  2540. ++(dsi_ctrl->irq_info.irq_stat_refcount[intr_idx]);
  2541. if (event_info)
  2542. dsi_ctrl->irq_info.irq_stat_cb[intr_idx] = *event_info;
  2543. spin_unlock_irqrestore(&dsi_ctrl->irq_info.irq_lock, flags);
  2544. }
  2545. void dsi_ctrl_disable_status_interrupt(struct dsi_ctrl *dsi_ctrl,
  2546. uint32_t intr_idx)
  2547. {
  2548. unsigned long flags;
  2549. if (!dsi_ctrl || intr_idx >= DSI_STATUS_INTERRUPT_COUNT)
  2550. return;
  2551. SDE_EVT32_IRQ(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_ENTRY, intr_idx,
  2552. dsi_ctrl->irq_info.irq_num, dsi_ctrl->irq_info.irq_stat_mask,
  2553. dsi_ctrl->irq_info.irq_stat_refcount[intr_idx]);
  2554. spin_lock_irqsave(&dsi_ctrl->irq_info.irq_lock, flags);
  2555. if (dsi_ctrl->irq_info.irq_stat_refcount[intr_idx])
  2556. if (--(dsi_ctrl->irq_info.irq_stat_refcount[intr_idx]) == 0) {
  2557. dsi_ctrl->irq_info.irq_stat_mask &= ~BIT(intr_idx);
  2558. dsi_ctrl->hw.ops.enable_status_interrupts(&dsi_ctrl->hw,
  2559. dsi_ctrl->irq_info.irq_stat_mask);
  2560. /* don't need irq if no lines are enabled */
  2561. if (dsi_ctrl->irq_info.irq_stat_mask == 0 &&
  2562. dsi_ctrl->irq_info.irq_num != -1)
  2563. disable_irq_nosync(dsi_ctrl->irq_info.irq_num);
  2564. }
  2565. spin_unlock_irqrestore(&dsi_ctrl->irq_info.irq_lock, flags);
  2566. }
  2567. int dsi_ctrl_host_timing_update(struct dsi_ctrl *dsi_ctrl)
  2568. {
  2569. if (!dsi_ctrl) {
  2570. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2571. return -EINVAL;
  2572. }
  2573. mutex_lock(&dsi_ctrl->ctrl_lock);
  2574. if (dsi_ctrl->hw.ops.host_setup)
  2575. dsi_ctrl->hw.ops.host_setup(&dsi_ctrl->hw,
  2576. &dsi_ctrl->host_config.common_config);
  2577. if (dsi_ctrl->host_config.panel_mode == DSI_OP_CMD_MODE) {
  2578. if (dsi_ctrl->hw.ops.cmd_engine_setup)
  2579. dsi_ctrl->hw.ops.cmd_engine_setup(&dsi_ctrl->hw,
  2580. &dsi_ctrl->host_config.common_config,
  2581. &dsi_ctrl->host_config.u.cmd_engine);
  2582. if (dsi_ctrl->hw.ops.setup_cmd_stream)
  2583. dsi_ctrl->hw.ops.setup_cmd_stream(&dsi_ctrl->hw,
  2584. &dsi_ctrl->host_config.video_timing,
  2585. &dsi_ctrl->host_config.common_config,
  2586. 0x0, NULL);
  2587. } else {
  2588. DSI_CTRL_ERR(dsi_ctrl, "invalid panel mode for resolution switch\n");
  2589. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2590. return -EINVAL;
  2591. }
  2592. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2593. return 0;
  2594. }
  2595. /**
  2596. * dsi_ctrl_update_host_state() - Update the host initialization state.
  2597. * @dsi_ctrl: DSI controller handle.
  2598. * @op: ctrl driver ops
  2599. * @enable: boolean signifying host state.
  2600. *
  2601. * Update the host status only while exiting from ulps during suspend state.
  2602. *
  2603. * Return: error code.
  2604. */
  2605. int dsi_ctrl_update_host_state(struct dsi_ctrl *dsi_ctrl,
  2606. enum dsi_ctrl_driver_ops op, bool enable)
  2607. {
  2608. int rc = 0;
  2609. u32 state = enable ? 0x1 : 0x0;
  2610. if (!dsi_ctrl)
  2611. return rc;
  2612. mutex_lock(&dsi_ctrl->ctrl_lock);
  2613. rc = dsi_ctrl_check_state(dsi_ctrl, op, state);
  2614. if (rc) {
  2615. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n",
  2616. rc);
  2617. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2618. return rc;
  2619. }
  2620. dsi_ctrl_update_state(dsi_ctrl, op, state);
  2621. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2622. return rc;
  2623. }
  2624. /**
  2625. * dsi_ctrl_host_init() - Initialize DSI host hardware.
  2626. * @dsi_ctrl: DSI controller handle.
  2627. * @skip_op: Boolean to indicate few operations can be skipped.
  2628. * Set during the cont-splash or trusted-vm enable case.
  2629. *
  2630. * Initializes DSI controller hardware with host configuration provided by
  2631. * dsi_ctrl_update_host_config(). Initialization can be performed only during
  2632. * DSI_CTRL_POWER_CORE_CLK_ON state and after the PHY SW reset has been
  2633. * performed.
  2634. *
  2635. * Return: error code.
  2636. */
  2637. int dsi_ctrl_host_init(struct dsi_ctrl *dsi_ctrl, bool skip_op)
  2638. {
  2639. int rc = 0;
  2640. if (!dsi_ctrl) {
  2641. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2642. return -EINVAL;
  2643. }
  2644. mutex_lock(&dsi_ctrl->ctrl_lock);
  2645. rc = dsi_ctrl_check_state(dsi_ctrl, DSI_CTRL_OP_HOST_INIT, 0x1);
  2646. if (rc) {
  2647. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n",
  2648. rc);
  2649. goto error;
  2650. }
  2651. /*
  2652. * For continuous splash/trusted vm usecases we omit hw operations
  2653. * as bootloader/primary vm takes care of them respectively
  2654. */
  2655. if (!skip_op) {
  2656. dsi_ctrl->hw.ops.setup_lane_map(&dsi_ctrl->hw,
  2657. &dsi_ctrl->host_config.lane_map);
  2658. dsi_ctrl->hw.ops.host_setup(&dsi_ctrl->hw,
  2659. &dsi_ctrl->host_config.common_config);
  2660. if (dsi_ctrl->host_config.panel_mode == DSI_OP_CMD_MODE) {
  2661. dsi_ctrl->hw.ops.cmd_engine_setup(&dsi_ctrl->hw,
  2662. &dsi_ctrl->host_config.common_config,
  2663. &dsi_ctrl->host_config.u.cmd_engine);
  2664. dsi_ctrl->hw.ops.setup_cmd_stream(&dsi_ctrl->hw,
  2665. &dsi_ctrl->host_config.video_timing,
  2666. &dsi_ctrl->host_config.common_config,
  2667. 0x0,
  2668. NULL);
  2669. } else {
  2670. dsi_ctrl->hw.ops.video_engine_setup(&dsi_ctrl->hw,
  2671. &dsi_ctrl->host_config.common_config,
  2672. &dsi_ctrl->host_config.u.video_engine);
  2673. dsi_ctrl->hw.ops.set_video_timing(&dsi_ctrl->hw,
  2674. &dsi_ctrl->host_config.video_timing);
  2675. }
  2676. }
  2677. dsi_ctrl->hw.ops.enable_status_interrupts(&dsi_ctrl->hw, 0x0);
  2678. dsi_ctrl_toggle_error_interrupt_status(dsi_ctrl, true);
  2679. DSI_CTRL_DEBUG(dsi_ctrl, "Host initialization complete, skip op: %d\n",
  2680. skip_op);
  2681. dsi_ctrl_update_state(dsi_ctrl, DSI_CTRL_OP_HOST_INIT, 0x1);
  2682. error:
  2683. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2684. return rc;
  2685. }
  2686. /**
  2687. * dsi_ctrl_isr_configure() - API to register/deregister dsi isr
  2688. * @dsi_ctrl: DSI controller handle.
  2689. * @enable: variable to control register/deregister isr
  2690. */
  2691. void dsi_ctrl_isr_configure(struct dsi_ctrl *dsi_ctrl, bool enable)
  2692. {
  2693. if (!dsi_ctrl)
  2694. return;
  2695. mutex_lock(&dsi_ctrl->ctrl_lock);
  2696. if (enable)
  2697. _dsi_ctrl_setup_isr(dsi_ctrl);
  2698. else
  2699. _dsi_ctrl_destroy_isr(dsi_ctrl);
  2700. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2701. }
  2702. void dsi_ctrl_hs_req_sel(struct dsi_ctrl *dsi_ctrl, bool sel_phy)
  2703. {
  2704. if (!dsi_ctrl)
  2705. return;
  2706. mutex_lock(&dsi_ctrl->ctrl_lock);
  2707. dsi_ctrl->hw.ops.hs_req_sel(&dsi_ctrl->hw, sel_phy);
  2708. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2709. }
  2710. void dsi_ctrl_set_continuous_clk(struct dsi_ctrl *dsi_ctrl, bool enable)
  2711. {
  2712. if (!dsi_ctrl)
  2713. return;
  2714. mutex_lock(&dsi_ctrl->ctrl_lock);
  2715. dsi_ctrl->hw.ops.set_continuous_clk(&dsi_ctrl->hw, enable);
  2716. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2717. }
  2718. int dsi_ctrl_soft_reset(struct dsi_ctrl *dsi_ctrl)
  2719. {
  2720. if (!dsi_ctrl)
  2721. return -EINVAL;
  2722. mutex_lock(&dsi_ctrl->ctrl_lock);
  2723. dsi_ctrl->hw.ops.soft_reset(&dsi_ctrl->hw);
  2724. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2725. DSI_CTRL_DEBUG(dsi_ctrl, "Soft reset complete\n");
  2726. return 0;
  2727. }
  2728. int dsi_ctrl_reset(struct dsi_ctrl *dsi_ctrl, int mask)
  2729. {
  2730. int rc = 0;
  2731. if (!dsi_ctrl)
  2732. return -EINVAL;
  2733. mutex_lock(&dsi_ctrl->ctrl_lock);
  2734. rc = dsi_ctrl->hw.ops.ctrl_reset(&dsi_ctrl->hw, mask);
  2735. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2736. return rc;
  2737. }
  2738. int dsi_ctrl_get_hw_version(struct dsi_ctrl *dsi_ctrl)
  2739. {
  2740. int rc = 0;
  2741. if (!dsi_ctrl)
  2742. return -EINVAL;
  2743. mutex_lock(&dsi_ctrl->ctrl_lock);
  2744. rc = dsi_ctrl->hw.ops.get_hw_version(&dsi_ctrl->hw);
  2745. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2746. return rc;
  2747. }
  2748. int dsi_ctrl_vid_engine_en(struct dsi_ctrl *dsi_ctrl, bool on)
  2749. {
  2750. int rc = 0;
  2751. if (!dsi_ctrl)
  2752. return -EINVAL;
  2753. mutex_lock(&dsi_ctrl->ctrl_lock);
  2754. dsi_ctrl->hw.ops.video_engine_en(&dsi_ctrl->hw, on);
  2755. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2756. return rc;
  2757. }
  2758. int dsi_ctrl_setup_avr(struct dsi_ctrl *dsi_ctrl, bool enable)
  2759. {
  2760. if (!dsi_ctrl)
  2761. return -EINVAL;
  2762. if (dsi_ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE) {
  2763. mutex_lock(&dsi_ctrl->ctrl_lock);
  2764. dsi_ctrl->hw.ops.setup_avr(&dsi_ctrl->hw, enable);
  2765. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2766. }
  2767. return 0;
  2768. }
  2769. /**
  2770. * dsi_ctrl_host_deinit() - De-Initialize DSI host hardware.
  2771. * @dsi_ctrl: DSI controller handle.
  2772. *
  2773. * De-initializes DSI controller hardware. It can be performed only during
  2774. * DSI_CTRL_POWER_CORE_CLK_ON state after LINK clocks have been turned off.
  2775. *
  2776. * Return: error code.
  2777. */
  2778. int dsi_ctrl_host_deinit(struct dsi_ctrl *dsi_ctrl)
  2779. {
  2780. int rc = 0;
  2781. if (!dsi_ctrl) {
  2782. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2783. return -EINVAL;
  2784. }
  2785. mutex_lock(&dsi_ctrl->ctrl_lock);
  2786. rc = dsi_ctrl_check_state(dsi_ctrl, DSI_CTRL_OP_HOST_INIT, 0x0);
  2787. if (rc) {
  2788. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n",
  2789. rc);
  2790. DSI_CTRL_ERR(dsi_ctrl, "driver state check failed, rc=%d\n",
  2791. rc);
  2792. goto error;
  2793. }
  2794. DSI_CTRL_DEBUG(dsi_ctrl, "Host deinitization complete\n");
  2795. dsi_ctrl_update_state(dsi_ctrl, DSI_CTRL_OP_HOST_INIT, 0x0);
  2796. error:
  2797. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2798. return rc;
  2799. }
  2800. /**
  2801. * dsi_ctrl_update_host_config() - update dsi host configuration
  2802. * @dsi_ctrl: DSI controller handle.
  2803. * @config: DSI host configuration.
  2804. * @flags: dsi_mode_flags modifying the behavior
  2805. *
  2806. * Updates driver with new Host configuration to use for host initialization.
  2807. * This function call will only update the software context. The stored
  2808. * configuration information will be used when the host is initialized.
  2809. *
  2810. * Return: error code.
  2811. */
  2812. int dsi_ctrl_update_host_config(struct dsi_ctrl *ctrl,
  2813. struct dsi_host_config *config,
  2814. struct dsi_display_mode *mode, int flags,
  2815. void *clk_handle)
  2816. {
  2817. int rc = 0;
  2818. if (!ctrl || !config) {
  2819. DSI_CTRL_ERR(ctrl, "Invalid params\n");
  2820. return -EINVAL;
  2821. }
  2822. mutex_lock(&ctrl->ctrl_lock);
  2823. rc = dsi_ctrl_validate_panel_info(ctrl, config);
  2824. if (rc) {
  2825. DSI_CTRL_ERR(ctrl, "panel validation failed, rc=%d\n", rc);
  2826. goto error;
  2827. }
  2828. if (!(flags & (DSI_MODE_FLAG_SEAMLESS | DSI_MODE_FLAG_VRR |
  2829. DSI_MODE_FLAG_DYN_CLK))) {
  2830. /*
  2831. * for dynamic clk switch case link frequence would
  2832. * be updated dsi_display_dynamic_clk_switch().
  2833. */
  2834. rc = dsi_ctrl_update_link_freqs(ctrl, config, clk_handle,
  2835. mode);
  2836. if (rc) {
  2837. DSI_CTRL_ERR(ctrl, "failed to update link frequency, rc=%d\n",
  2838. rc);
  2839. goto error;
  2840. }
  2841. }
  2842. DSI_CTRL_DEBUG(ctrl, "Host config updated\n");
  2843. memcpy(&ctrl->host_config, config, sizeof(ctrl->host_config));
  2844. ctrl->mode_bounds.x = ctrl->host_config.video_timing.h_active *
  2845. ctrl->horiz_index;
  2846. ctrl->mode_bounds.y = 0;
  2847. ctrl->mode_bounds.w = ctrl->host_config.video_timing.h_active;
  2848. ctrl->mode_bounds.h = ctrl->host_config.video_timing.v_active;
  2849. memcpy(&ctrl->roi, &ctrl->mode_bounds, sizeof(ctrl->mode_bounds));
  2850. ctrl->modeupdated = true;
  2851. ctrl->roi.x = 0;
  2852. error:
  2853. mutex_unlock(&ctrl->ctrl_lock);
  2854. return rc;
  2855. }
  2856. /**
  2857. * dsi_ctrl_validate_timing() - validate a video timing configuration
  2858. * @dsi_ctrl: DSI controller handle.
  2859. * @timing: Pointer to timing data.
  2860. *
  2861. * Driver will validate if the timing configuration is supported on the
  2862. * controller hardware.
  2863. *
  2864. * Return: error code if timing is not supported.
  2865. */
  2866. int dsi_ctrl_validate_timing(struct dsi_ctrl *dsi_ctrl,
  2867. struct dsi_mode_info *mode)
  2868. {
  2869. int rc = 0;
  2870. if (!dsi_ctrl || !mode) {
  2871. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2872. return -EINVAL;
  2873. }
  2874. return rc;
  2875. }
  2876. /**
  2877. * dsi_ctrl_transfer_prepare() - Set up a command transfer
  2878. * @dsi_ctrl: DSI controller handle.
  2879. * @flags: Controller flags of the command.
  2880. *
  2881. * Command transfer requires command engine to be enabled, along with
  2882. * clock votes and masking the overflow bits.
  2883. *
  2884. * Return: error code.
  2885. */
  2886. int dsi_ctrl_transfer_prepare(struct dsi_ctrl *dsi_ctrl, u32 flags)
  2887. {
  2888. int rc = 0;
  2889. struct dsi_clk_ctrl_info clk_info;
  2890. u32 mask = BIT(DSI_FIFO_OVERFLOW);
  2891. if (!dsi_ctrl)
  2892. return -EINVAL;
  2893. if ((flags & DSI_CTRL_CMD_FETCH_MEMORY) && (dsi_ctrl->cmd_len != 0))
  2894. return rc;
  2895. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, dsi_ctrl->cell_index, flags);
  2896. /* Vote for clocks, gdsc, enable command engine, mask overflow */
  2897. rc = pm_runtime_resume_and_get(dsi_ctrl->drm_dev->dev);
  2898. if (rc < 0) {
  2899. DSI_CTRL_ERR(dsi_ctrl, "failed to enable power resource %d\n", rc);
  2900. SDE_EVT32(rc, SDE_EVTLOG_ERROR);
  2901. return rc;
  2902. }
  2903. clk_info.client = DSI_CLK_REQ_DSI_CLIENT;
  2904. clk_info.clk_type = DSI_ALL_CLKS;
  2905. clk_info.clk_state = DSI_CLK_ON;
  2906. rc = dsi_ctrl->clk_cb.dsi_clk_cb(dsi_ctrl->clk_cb.priv, clk_info);
  2907. if (rc) {
  2908. DSI_CTRL_ERR(dsi_ctrl, "failed to enable clocks\n");
  2909. goto error_disable_gdsc;
  2910. }
  2911. /* Wait till any previous ASYNC waits are scheduled and completed */
  2912. if (dsi_ctrl->post_tx_queued)
  2913. dsi_ctrl_flush_cmd_dma_queue(dsi_ctrl);
  2914. mutex_lock(&dsi_ctrl->ctrl_lock);
  2915. if (!(flags & DSI_CTRL_CMD_READ))
  2916. dsi_ctrl_mask_error_status_interrupts(dsi_ctrl, mask, true);
  2917. rc = dsi_ctrl_set_cmd_engine_state(dsi_ctrl, DSI_CTRL_ENGINE_ON, false);
  2918. if (rc) {
  2919. DSI_CTRL_ERR(dsi_ctrl, "failed to enable command engine: %d\n", rc);
  2920. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2921. goto error_disable_clks;
  2922. }
  2923. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2924. return rc;
  2925. error_disable_clks:
  2926. clk_info.clk_state = DSI_CLK_OFF;
  2927. (void)dsi_ctrl->clk_cb.dsi_clk_cb(dsi_ctrl->clk_cb.priv, clk_info);
  2928. error_disable_gdsc:
  2929. (void)pm_runtime_put_sync(dsi_ctrl->drm_dev->dev);
  2930. return rc;
  2931. }
  2932. /**
  2933. * dsi_ctrl_cmd_transfer() - Transfer commands on DSI link
  2934. * @dsi_ctrl: DSI controller handle.
  2935. * @cmd: Command description to transfer on DSI link.
  2936. *
  2937. * Command transfer can be done only when command engine is enabled. The
  2938. * transfer API will block until either the command transfer finishes or
  2939. * the timeout value is reached. If the trigger is deferred, it will return
  2940. * without triggering the transfer. Command parameters are programmed to
  2941. * hardware.
  2942. *
  2943. * Return: error code.
  2944. */
  2945. int dsi_ctrl_cmd_transfer(struct dsi_ctrl *dsi_ctrl, struct dsi_cmd_desc *cmd)
  2946. {
  2947. int rc = 0;
  2948. if (!dsi_ctrl || !cmd) {
  2949. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  2950. return -EINVAL;
  2951. }
  2952. mutex_lock(&dsi_ctrl->ctrl_lock);
  2953. if (cmd->ctrl_flags & DSI_CTRL_CMD_READ) {
  2954. rc = dsi_message_rx(dsi_ctrl, cmd);
  2955. if (rc <= 0)
  2956. DSI_CTRL_ERR(dsi_ctrl, "read message failed read length, rc=%d\n",
  2957. rc);
  2958. } else {
  2959. rc = dsi_message_tx(dsi_ctrl, cmd);
  2960. if (rc)
  2961. DSI_CTRL_ERR(dsi_ctrl, "command msg transfer failed, rc = %d\n",
  2962. rc);
  2963. }
  2964. cmd->ts = dsi_ctrl->cmd_success_ts;
  2965. dsi_ctrl_update_state(dsi_ctrl, DSI_CTRL_OP_CMD_TX, 0x0);
  2966. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2967. return rc;
  2968. }
  2969. void dsi_ctrl_transfer_cleanup(struct dsi_ctrl *dsi_ctrl)
  2970. {
  2971. int rc = 0;
  2972. struct dsi_clk_ctrl_info clk_info;
  2973. u32 mask = BIT(DSI_FIFO_OVERFLOW);
  2974. mutex_lock(&dsi_ctrl->ctrl_lock);
  2975. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, dsi_ctrl->cell_index, dsi_ctrl->pending_cmd_flags);
  2976. /* Command engine disable, unmask overflow, remove vote on clocks and gdsc */
  2977. rc = dsi_ctrl_set_cmd_engine_state(dsi_ctrl, DSI_CTRL_ENGINE_OFF, false);
  2978. if (rc)
  2979. DSI_CTRL_ERR(dsi_ctrl, "failed to disable command engine\n");
  2980. if (!(dsi_ctrl->pending_cmd_flags & DSI_CTRL_CMD_READ))
  2981. dsi_ctrl_mask_error_status_interrupts(dsi_ctrl, mask, false);
  2982. mutex_unlock(&dsi_ctrl->ctrl_lock);
  2983. clk_info.client = DSI_CLK_REQ_DSI_CLIENT;
  2984. clk_info.clk_type = DSI_ALL_CLKS;
  2985. clk_info.clk_state = DSI_CLK_OFF;
  2986. rc = dsi_ctrl->clk_cb.dsi_clk_cb(dsi_ctrl->clk_cb.priv, clk_info);
  2987. if (rc)
  2988. DSI_CTRL_ERR(dsi_ctrl, "failed to disable clocks\n");
  2989. (void)pm_runtime_put_sync(dsi_ctrl->drm_dev->dev);
  2990. }
  2991. /**
  2992. * dsi_ctrl_transfer_unprepare() - Clean up post a command transfer
  2993. * @dsi_ctrl: DSI controller handle.
  2994. * @flags: Controller flags of the command
  2995. *
  2996. * After the DSI controller has been programmed to trigger a DCS command
  2997. * the post transfer API is used to check for success and clean up the
  2998. * resources. Depending on the controller flags, this check is either
  2999. * scheduled on the same thread or queued.
  3000. *
  3001. */
  3002. void dsi_ctrl_transfer_unprepare(struct dsi_ctrl *dsi_ctrl, u32 flags)
  3003. {
  3004. if (!dsi_ctrl)
  3005. return;
  3006. dsi_ctrl->pending_cmd_flags = flags;
  3007. if (!(flags & DSI_CTRL_CMD_LAST_COMMAND))
  3008. return;
  3009. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, dsi_ctrl->cell_index, flags);
  3010. if (flags & DSI_CTRL_CMD_ASYNC_WAIT) {
  3011. dsi_ctrl->post_tx_queued = true;
  3012. queue_work(dsi_ctrl->post_cmd_tx_workq, &dsi_ctrl->post_cmd_tx_work);
  3013. } else {
  3014. dsi_ctrl->post_tx_queued = false;
  3015. dsi_ctrl_post_cmd_transfer(dsi_ctrl);
  3016. }
  3017. }
  3018. /**
  3019. * dsi_ctrl_cmd_tx_trigger() - Trigger a deferred command.
  3020. * @dsi_ctrl: DSI controller handle.
  3021. * @flags: Modifiers.
  3022. *
  3023. * Return: error code.
  3024. */
  3025. int dsi_ctrl_cmd_tx_trigger(struct dsi_ctrl *dsi_ctrl, u32 flags)
  3026. {
  3027. int rc = 0;
  3028. struct dsi_ctrl_hw_ops dsi_hw_ops;
  3029. u32 v_total = 0, fps = 0, cur_line = 0, mem_latency_us = 100;
  3030. u32 line_time = 0, schedule_line = 0x1, latency_by_line = 0;
  3031. struct dsi_mode_info *timing;
  3032. unsigned long flag;
  3033. if (!dsi_ctrl) {
  3034. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3035. return -EINVAL;
  3036. }
  3037. dsi_hw_ops = dsi_ctrl->hw.ops;
  3038. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_ENTRY, flags);
  3039. /* Dont trigger the command if this is not the last ocmmand */
  3040. if (!(flags & DSI_CTRL_CMD_LAST_COMMAND))
  3041. return rc;
  3042. mutex_lock(&dsi_ctrl->ctrl_lock);
  3043. timing = &(dsi_ctrl->host_config.video_timing);
  3044. if (timing &&
  3045. (dsi_ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE)) {
  3046. v_total = timing->v_sync_width + timing->v_back_porch +
  3047. timing->v_front_porch + timing->v_active;
  3048. fps = timing->refresh_rate;
  3049. schedule_line = calculate_schedule_line(dsi_ctrl, flags);
  3050. line_time = (1000000 / fps) / v_total;
  3051. latency_by_line = CEIL(mem_latency_us, line_time);
  3052. }
  3053. if (!(flags & DSI_CTRL_CMD_BROADCAST_MASTER)) {
  3054. dsi_hw_ops.trigger_command_dma(&dsi_ctrl->hw);
  3055. if (dsi_ctrl->enable_cmd_dma_stats) {
  3056. u32 reg = dsi_hw_ops.log_line_count(&dsi_ctrl->hw,
  3057. dsi_ctrl->cmd_mode);
  3058. dsi_ctrl->cmd_trigger_line = (reg & 0xFFFF);
  3059. dsi_ctrl->cmd_trigger_frame = ((reg >> 16) & 0xFFFF);
  3060. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_CASE1,
  3061. dsi_ctrl->cmd_trigger_line,
  3062. dsi_ctrl->cmd_trigger_frame);
  3063. }
  3064. }
  3065. if ((flags & DSI_CTRL_CMD_BROADCAST) &&
  3066. (flags & DSI_CTRL_CMD_BROADCAST_MASTER)) {
  3067. atomic_set(&dsi_ctrl->dma_irq_trig, 0);
  3068. dsi_ctrl_enable_status_interrupt(dsi_ctrl,
  3069. DSI_SINT_CMD_MODE_DMA_DONE, NULL);
  3070. reinit_completion(&dsi_ctrl->irq_info.cmd_dma_done);
  3071. /* trigger command */
  3072. if ((dsi_ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE) &&
  3073. dsi_hw_ops.schedule_dma_cmd &&
  3074. (dsi_ctrl->current_state.vid_engine_state ==
  3075. DSI_CTRL_ENGINE_ON)) {
  3076. /*
  3077. * This change reads the video line count from
  3078. * MDP_INTF_LINE_COUNT register and checks whether
  3079. * DMA trigger happens close to the schedule line.
  3080. * If it is not close to the schedule line, then DMA
  3081. * command transfer is triggered.
  3082. */
  3083. while (1) {
  3084. local_irq_save(flag);
  3085. cur_line =
  3086. dsi_hw_ops.log_line_count(&dsi_ctrl->hw,
  3087. dsi_ctrl->cmd_mode);
  3088. if (cur_line <
  3089. (schedule_line - latency_by_line) ||
  3090. cur_line > (schedule_line + 1)) {
  3091. dsi_hw_ops.trigger_command_dma(
  3092. &dsi_ctrl->hw);
  3093. local_irq_restore(flag);
  3094. break;
  3095. }
  3096. local_irq_restore(flag);
  3097. udelay(1000);
  3098. }
  3099. } else
  3100. dsi_hw_ops.trigger_command_dma(&dsi_ctrl->hw);
  3101. if (dsi_ctrl->enable_cmd_dma_stats) {
  3102. u32 reg = dsi_hw_ops.log_line_count(&dsi_ctrl->hw,
  3103. dsi_ctrl->cmd_mode);
  3104. dsi_ctrl->cmd_trigger_line = (reg & 0xFFFF);
  3105. dsi_ctrl->cmd_trigger_frame = ((reg >> 16) & 0xFFFF);
  3106. SDE_EVT32(dsi_ctrl->cell_index, SDE_EVTLOG_FUNC_CASE1,
  3107. dsi_ctrl->cmd_trigger_line,
  3108. dsi_ctrl->cmd_trigger_frame);
  3109. }
  3110. if (flags & DSI_CTRL_CMD_NON_EMBEDDED_MODE) {
  3111. if (dsi_ctrl->version < DSI_CTRL_VERSION_2_4)
  3112. dsi_hw_ops.soft_reset(&dsi_ctrl->hw);
  3113. dsi_ctrl->cmd_len = 0;
  3114. }
  3115. }
  3116. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3117. return rc;
  3118. }
  3119. /**
  3120. * dsi_ctrl_cache_misr - Cache frame MISR value
  3121. * @dsi_ctrl: Pointer to associated dsi_ctrl structure
  3122. */
  3123. void dsi_ctrl_cache_misr(struct dsi_ctrl *dsi_ctrl)
  3124. {
  3125. u32 misr;
  3126. if (!dsi_ctrl || !dsi_ctrl->hw.ops.collect_misr)
  3127. return;
  3128. misr = dsi_ctrl->hw.ops.collect_misr(&dsi_ctrl->hw,
  3129. dsi_ctrl->host_config.panel_mode);
  3130. if (misr)
  3131. dsi_ctrl->misr_cache = misr;
  3132. DSI_CTRL_DEBUG(dsi_ctrl, "misr_cache = %x\n", dsi_ctrl->misr_cache);
  3133. }
  3134. /**
  3135. * dsi_ctrl_get_host_engine_init_state() - Return host init state
  3136. * @dsi_ctrl: DSI controller handle.
  3137. * @state: Controller initialization state
  3138. *
  3139. * Return: error code.
  3140. */
  3141. int dsi_ctrl_get_host_engine_init_state(struct dsi_ctrl *dsi_ctrl,
  3142. bool *state)
  3143. {
  3144. if (!dsi_ctrl || !state) {
  3145. DSI_CTRL_ERR(dsi_ctrl, "Invalid Params\n");
  3146. return -EINVAL;
  3147. }
  3148. mutex_lock(&dsi_ctrl->ctrl_lock);
  3149. *state = dsi_ctrl->current_state.host_initialized;
  3150. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3151. return 0;
  3152. }
  3153. /**
  3154. * dsi_ctrl_set_power_state() - set power state for dsi controller
  3155. * @dsi_ctrl: DSI controller handle.
  3156. * @state: Power state.
  3157. *
  3158. * Set power state for DSI controller. Power state can be changed only when
  3159. * Controller, Video and Command engines are turned off.
  3160. *
  3161. * Return: error code.
  3162. */
  3163. int dsi_ctrl_set_power_state(struct dsi_ctrl *dsi_ctrl,
  3164. enum dsi_power_state state)
  3165. {
  3166. int rc = 0;
  3167. if (!dsi_ctrl || (state >= DSI_CTRL_POWER_MAX)) {
  3168. DSI_CTRL_ERR(dsi_ctrl, "Invalid Params\n");
  3169. return -EINVAL;
  3170. }
  3171. mutex_lock(&dsi_ctrl->ctrl_lock);
  3172. rc = dsi_ctrl_check_state(dsi_ctrl, DSI_CTRL_OP_POWER_STATE_CHANGE,
  3173. state);
  3174. if (rc) {
  3175. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n",
  3176. rc);
  3177. goto error;
  3178. }
  3179. if (state == DSI_CTRL_POWER_VREG_ON) {
  3180. rc = dsi_ctrl_enable_supplies(dsi_ctrl, true);
  3181. if (rc) {
  3182. DSI_CTRL_ERR(dsi_ctrl, "failed to enable voltage supplies, rc=%d\n",
  3183. rc);
  3184. goto error;
  3185. }
  3186. } else if (state == DSI_CTRL_POWER_VREG_OFF) {
  3187. rc = dsi_ctrl_enable_supplies(dsi_ctrl, false);
  3188. if (rc) {
  3189. DSI_CTRL_ERR(dsi_ctrl, "failed to disable vreg supplies, rc=%d\n",
  3190. rc);
  3191. goto error;
  3192. }
  3193. }
  3194. DSI_CTRL_DEBUG(dsi_ctrl, "Power state updated to %d\n", state);
  3195. dsi_ctrl_update_state(dsi_ctrl, DSI_CTRL_OP_POWER_STATE_CHANGE, state);
  3196. error:
  3197. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3198. return rc;
  3199. }
  3200. /**
  3201. * dsi_ctrl_set_tpg_state() - enable/disable test pattern on the controller
  3202. * @dsi_ctrl: DSI controller handle.
  3203. * @on: enable/disable test pattern.
  3204. *
  3205. * Test pattern can be enabled only after Video engine (for video mode panels)
  3206. * or command engine (for cmd mode panels) is enabled.
  3207. *
  3208. * Return: error code.
  3209. */
  3210. int dsi_ctrl_set_tpg_state(struct dsi_ctrl *dsi_ctrl, bool on,
  3211. enum dsi_test_pattern type, u32 init_val,
  3212. enum dsi_ctrl_tpg_pattern pattern)
  3213. {
  3214. int rc = 0;
  3215. if (!dsi_ctrl) {
  3216. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3217. return -EINVAL;
  3218. }
  3219. mutex_lock(&dsi_ctrl->ctrl_lock);
  3220. rc = dsi_ctrl_check_state(dsi_ctrl, DSI_CTRL_OP_TPG, on);
  3221. if (rc) {
  3222. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n",
  3223. rc);
  3224. goto error;
  3225. }
  3226. if (on) {
  3227. if (dsi_ctrl->host_config.panel_mode == DSI_OP_VIDEO_MODE)
  3228. dsi_ctrl->hw.ops.video_test_pattern_setup(&dsi_ctrl->hw, type, init_val);
  3229. else
  3230. dsi_ctrl->hw.ops.cmd_test_pattern_setup(&dsi_ctrl->hw, type, init_val, 0x0);
  3231. }
  3232. dsi_ctrl->hw.ops.test_pattern_enable(&dsi_ctrl->hw, on, pattern,
  3233. dsi_ctrl->host_config.panel_mode);
  3234. DSI_CTRL_DEBUG(dsi_ctrl, "Set test pattern state=%d\n", on);
  3235. dsi_ctrl_update_state(dsi_ctrl, DSI_CTRL_OP_TPG, on);
  3236. error:
  3237. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3238. return rc;
  3239. }
  3240. /**
  3241. * dsi_ctrl_trigger_test_pattern() - trigger a command mode frame update with test pattern
  3242. * @dsi_ctrl: DSI controller handle.
  3243. *
  3244. * Trigger a command mode frame update with chosen test pattern.
  3245. *
  3246. * Return: error code.
  3247. */
  3248. int dsi_ctrl_trigger_test_pattern(struct dsi_ctrl *dsi_ctrl)
  3249. {
  3250. int ret = 0;
  3251. if (!dsi_ctrl) {
  3252. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3253. return -EINVAL;
  3254. }
  3255. mutex_lock(&dsi_ctrl->ctrl_lock);
  3256. dsi_ctrl->hw.ops.trigger_cmd_test_pattern(&dsi_ctrl->hw, 0);
  3257. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3258. return ret;
  3259. }
  3260. /**
  3261. * dsi_ctrl_set_host_engine_state() - set host engine state
  3262. * @dsi_ctrl: DSI Controller handle.
  3263. * @state: Engine state.
  3264. * @skip_op: Boolean to indicate few operations can be skipped.
  3265. * Set during the cont-splash or trusted-vm enable case.
  3266. *
  3267. * Host engine state can be modified only when DSI controller power state is
  3268. * set to DSI_CTRL_POWER_LINK_CLK_ON and cmd, video engines are disabled.
  3269. *
  3270. * Return: error code.
  3271. */
  3272. int dsi_ctrl_set_host_engine_state(struct dsi_ctrl *dsi_ctrl,
  3273. enum dsi_engine_state state, bool skip_op)
  3274. {
  3275. int rc = 0;
  3276. if (!dsi_ctrl || (state >= DSI_CTRL_ENGINE_MAX)) {
  3277. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3278. return -EINVAL;
  3279. }
  3280. mutex_lock(&dsi_ctrl->ctrl_lock);
  3281. rc = dsi_ctrl_check_state(dsi_ctrl, DSI_CTRL_OP_HOST_ENGINE, state);
  3282. if (rc) {
  3283. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n",
  3284. rc);
  3285. goto error;
  3286. }
  3287. if (!skip_op) {
  3288. if (state == DSI_CTRL_ENGINE_ON)
  3289. dsi_ctrl->hw.ops.ctrl_en(&dsi_ctrl->hw, true);
  3290. else
  3291. dsi_ctrl->hw.ops.ctrl_en(&dsi_ctrl->hw, false);
  3292. }
  3293. SDE_EVT32(dsi_ctrl->cell_index, state, skip_op);
  3294. DSI_CTRL_DEBUG(dsi_ctrl, "Set host engine state = %d\n", state);
  3295. dsi_ctrl_update_state(dsi_ctrl, DSI_CTRL_OP_HOST_ENGINE, state);
  3296. error:
  3297. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3298. return rc;
  3299. }
  3300. /**
  3301. * dsi_ctrl_set_cmd_engine_state() - set command engine state
  3302. * @dsi_ctrl: DSI Controller handle.
  3303. * @state: Engine state.
  3304. * @skip_op: Boolean to indicate few operations can be skipped.
  3305. * Set during the cont-splash or trusted-vm enable case.
  3306. *
  3307. * Command engine state can be modified only when DSI controller power state is
  3308. * set to DSI_CTRL_POWER_LINK_CLK_ON.
  3309. *
  3310. * Return: error code.
  3311. */
  3312. int dsi_ctrl_set_cmd_engine_state(struct dsi_ctrl *dsi_ctrl,
  3313. enum dsi_engine_state state, bool skip_op)
  3314. {
  3315. int rc = 0;
  3316. if (!dsi_ctrl || (state >= DSI_CTRL_ENGINE_MAX)) {
  3317. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3318. return -EINVAL;
  3319. }
  3320. if (state == DSI_CTRL_ENGINE_ON) {
  3321. if (dsi_ctrl->cmd_engine_refcount > 0) {
  3322. dsi_ctrl->cmd_engine_refcount++;
  3323. goto error;
  3324. }
  3325. } else {
  3326. if (dsi_ctrl->cmd_engine_refcount > 1) {
  3327. dsi_ctrl->cmd_engine_refcount--;
  3328. goto error;
  3329. }
  3330. }
  3331. rc = dsi_ctrl_check_state(dsi_ctrl, DSI_CTRL_OP_CMD_ENGINE, state);
  3332. if (rc) {
  3333. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n", rc);
  3334. goto error;
  3335. }
  3336. if (!skip_op) {
  3337. if (state == DSI_CTRL_ENGINE_ON)
  3338. dsi_ctrl->hw.ops.cmd_engine_en(&dsi_ctrl->hw, true);
  3339. else
  3340. dsi_ctrl->hw.ops.cmd_engine_en(&dsi_ctrl->hw, false);
  3341. }
  3342. if (state == DSI_CTRL_ENGINE_ON)
  3343. dsi_ctrl->cmd_engine_refcount++;
  3344. else
  3345. dsi_ctrl->cmd_engine_refcount = 0;
  3346. SDE_EVT32(dsi_ctrl->cell_index, state, skip_op);
  3347. dsi_ctrl_update_state(dsi_ctrl, DSI_CTRL_OP_CMD_ENGINE, state);
  3348. error:
  3349. DSI_CTRL_DEBUG(dsi_ctrl, "Set cmd engine state:%d, skip_op:%d, enable count: %d\n",
  3350. state, skip_op, dsi_ctrl->cmd_engine_refcount);
  3351. return rc;
  3352. }
  3353. /**
  3354. * dsi_ctrl_set_vid_engine_state() - set video engine state
  3355. * @dsi_ctrl: DSI Controller handle.
  3356. * @state: Engine state.
  3357. * @skip_op: Boolean to indicate few operations can be skipped.
  3358. * Set during the cont-splash or trusted-vm enable case.
  3359. *
  3360. * Video engine state can be modified only when DSI controller power state is
  3361. * set to DSI_CTRL_POWER_LINK_CLK_ON.
  3362. *
  3363. * Return: error code.
  3364. */
  3365. int dsi_ctrl_set_vid_engine_state(struct dsi_ctrl *dsi_ctrl,
  3366. enum dsi_engine_state state, bool skip_op)
  3367. {
  3368. int rc = 0;
  3369. bool on;
  3370. bool vid_eng_busy;
  3371. if (!dsi_ctrl || (state >= DSI_CTRL_ENGINE_MAX)) {
  3372. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3373. return -EINVAL;
  3374. }
  3375. mutex_lock(&dsi_ctrl->ctrl_lock);
  3376. rc = dsi_ctrl_check_state(dsi_ctrl, DSI_CTRL_OP_VID_ENGINE, state);
  3377. if (rc) {
  3378. DSI_CTRL_ERR(dsi_ctrl, "Controller state check failed, rc=%d\n",
  3379. rc);
  3380. goto error;
  3381. }
  3382. if (!skip_op) {
  3383. on = (state == DSI_CTRL_ENGINE_ON) ? true : false;
  3384. dsi_ctrl->hw.ops.video_engine_en(&dsi_ctrl->hw, on);
  3385. vid_eng_busy = dsi_ctrl->hw.ops.vid_engine_busy(&dsi_ctrl->hw);
  3386. /*
  3387. * During ESD check failure, DSI video engine can get stuck
  3388. * sending data from display engine. In use cases where GDSC
  3389. * toggle does not happen like DP MST connected or secure video
  3390. * playback, display does not recover back after ESD failure.
  3391. * Perform a reset if video engine is stuck.
  3392. */
  3393. if (!on && vid_eng_busy)
  3394. dsi_ctrl->hw.ops.soft_reset(&dsi_ctrl->hw);
  3395. }
  3396. SDE_EVT32(dsi_ctrl->cell_index, state, skip_op);
  3397. DSI_CTRL_DEBUG(dsi_ctrl, "Set video engine state:%d, skip_op:%d\n",
  3398. state, skip_op);
  3399. dsi_ctrl_update_state(dsi_ctrl, DSI_CTRL_OP_VID_ENGINE, state);
  3400. error:
  3401. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3402. return rc;
  3403. }
  3404. /**
  3405. * dsi_ctrl_set_ulps() - set ULPS state for DSI lanes.
  3406. * @dsi_ctrl: DSI controller handle.
  3407. * @enable: enable/disable ULPS.
  3408. *
  3409. * ULPS can be enabled/disabled after DSI host engine is turned on.
  3410. *
  3411. * Return: error code.
  3412. */
  3413. int dsi_ctrl_set_ulps(struct dsi_ctrl *dsi_ctrl, bool enable)
  3414. {
  3415. int rc = 0;
  3416. if (!dsi_ctrl) {
  3417. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3418. return -EINVAL;
  3419. }
  3420. mutex_lock(&dsi_ctrl->ctrl_lock);
  3421. if (enable)
  3422. rc = dsi_enable_ulps(dsi_ctrl);
  3423. else
  3424. rc = dsi_disable_ulps(dsi_ctrl);
  3425. if (rc) {
  3426. DSI_CTRL_ERR(dsi_ctrl, "Ulps state change(%d) failed, rc=%d\n",
  3427. enable, rc);
  3428. goto error;
  3429. }
  3430. DSI_CTRL_DEBUG(dsi_ctrl, "ULPS state = %d\n", enable);
  3431. error:
  3432. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3433. return rc;
  3434. }
  3435. /**
  3436. * dsi_ctrl_set_clamp_state() - set clamp state for DSI phy
  3437. * @dsi_ctrl: DSI controller handle.
  3438. * @enable: enable/disable clamping.
  3439. *
  3440. * Clamps can be enabled/disabled while DSI controller is still turned on.
  3441. *
  3442. * Return: error code.
  3443. */
  3444. int dsi_ctrl_set_clamp_state(struct dsi_ctrl *dsi_ctrl,
  3445. bool enable, bool ulps_enabled)
  3446. {
  3447. int rc = 0;
  3448. if (!dsi_ctrl) {
  3449. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3450. return -EINVAL;
  3451. }
  3452. if (!dsi_ctrl->hw.ops.clamp_enable ||
  3453. !dsi_ctrl->hw.ops.clamp_disable) {
  3454. DSI_CTRL_DEBUG(dsi_ctrl, "No clamp control for DSI controller\n");
  3455. return 0;
  3456. }
  3457. mutex_lock(&dsi_ctrl->ctrl_lock);
  3458. rc = dsi_enable_io_clamp(dsi_ctrl, enable, ulps_enabled);
  3459. if (rc) {
  3460. DSI_CTRL_ERR(dsi_ctrl, "Failed to enable IO clamp\n");
  3461. goto error;
  3462. }
  3463. DSI_CTRL_DEBUG(dsi_ctrl, "Clamp state = %d\n", enable);
  3464. error:
  3465. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3466. return rc;
  3467. }
  3468. /**
  3469. * dsi_ctrl_set_clock_source() - set clock source fpr dsi link clocks
  3470. * @dsi_ctrl: DSI controller handle.
  3471. * @source_clks: Source clocks for DSI link clocks.
  3472. *
  3473. * Clock source should be changed while link clocks are disabled.
  3474. *
  3475. * Return: error code.
  3476. */
  3477. int dsi_ctrl_set_clock_source(struct dsi_ctrl *dsi_ctrl,
  3478. struct dsi_clk_link_set *source_clks)
  3479. {
  3480. int rc = 0;
  3481. if (!dsi_ctrl || !source_clks) {
  3482. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3483. return -EINVAL;
  3484. }
  3485. mutex_lock(&dsi_ctrl->ctrl_lock);
  3486. rc = dsi_clk_update_parent(source_clks, &dsi_ctrl->clk_info.rcg_clks);
  3487. if (rc) {
  3488. DSI_CTRL_ERR(dsi_ctrl, "Failed to update link clk parent, rc=%d\n",
  3489. rc);
  3490. (void)dsi_clk_update_parent(&dsi_ctrl->clk_info.pll_op_clks,
  3491. &dsi_ctrl->clk_info.rcg_clks);
  3492. goto error;
  3493. }
  3494. dsi_ctrl->clk_info.pll_op_clks.byte_clk = source_clks->byte_clk;
  3495. dsi_ctrl->clk_info.pll_op_clks.pixel_clk = source_clks->pixel_clk;
  3496. DSI_CTRL_DEBUG(dsi_ctrl, "Source clocks are updated\n");
  3497. error:
  3498. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3499. return rc;
  3500. }
  3501. /**
  3502. * dsi_ctrl_setup_misr() - Setup frame MISR
  3503. * @dsi_ctrl: DSI controller handle.
  3504. * @enable: enable/disable MISR.
  3505. * @frame_count: Number of frames to accumulate MISR.
  3506. *
  3507. * Return: error code.
  3508. */
  3509. int dsi_ctrl_setup_misr(struct dsi_ctrl *dsi_ctrl,
  3510. bool enable,
  3511. u32 frame_count)
  3512. {
  3513. if (!dsi_ctrl) {
  3514. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3515. return -EINVAL;
  3516. }
  3517. if (!dsi_ctrl->hw.ops.setup_misr)
  3518. return 0;
  3519. mutex_lock(&dsi_ctrl->ctrl_lock);
  3520. dsi_ctrl->misr_enable = enable;
  3521. dsi_ctrl->hw.ops.setup_misr(&dsi_ctrl->hw,
  3522. dsi_ctrl->host_config.panel_mode,
  3523. enable, frame_count);
  3524. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3525. return 0;
  3526. }
  3527. /**
  3528. * dsi_ctrl_collect_misr() - Read frame MISR
  3529. * @dsi_ctrl: DSI controller handle.
  3530. *
  3531. * Return: MISR value.
  3532. */
  3533. u32 dsi_ctrl_collect_misr(struct dsi_ctrl *dsi_ctrl)
  3534. {
  3535. u32 misr;
  3536. if (!dsi_ctrl || !dsi_ctrl->hw.ops.collect_misr)
  3537. return 0;
  3538. misr = dsi_ctrl->hw.ops.collect_misr(&dsi_ctrl->hw,
  3539. dsi_ctrl->host_config.panel_mode);
  3540. if (!misr)
  3541. misr = dsi_ctrl->misr_cache;
  3542. DSI_CTRL_DEBUG(dsi_ctrl, "cached misr = %x, final = %x\n",
  3543. dsi_ctrl->misr_cache, misr);
  3544. return misr;
  3545. }
  3546. void dsi_ctrl_mask_error_status_interrupts(struct dsi_ctrl *dsi_ctrl, u32 idx,
  3547. bool mask_enable)
  3548. {
  3549. if (!dsi_ctrl || !dsi_ctrl->hw.ops.error_intr_ctrl
  3550. || !dsi_ctrl->hw.ops.clear_error_status) {
  3551. DSI_CTRL_ERR(dsi_ctrl, "Invalid params\n");
  3552. return;
  3553. }
  3554. /*
  3555. * Mask DSI error status interrupts and clear error status
  3556. * register
  3557. */
  3558. if (idx & BIT(DSI_ERR_INTR_ALL)) {
  3559. /*
  3560. * The behavior of mask_enable is different in ctrl register
  3561. * and mask register and hence mask_enable is manipulated for
  3562. * selective error interrupt masking vs total error interrupt
  3563. * masking.
  3564. */
  3565. dsi_ctrl->hw.ops.error_intr_ctrl(&dsi_ctrl->hw, !mask_enable);
  3566. dsi_ctrl->hw.ops.clear_error_status(&dsi_ctrl->hw,
  3567. DSI_ERROR_INTERRUPT_COUNT);
  3568. } else {
  3569. dsi_ctrl->hw.ops.mask_error_intr(&dsi_ctrl->hw, idx,
  3570. mask_enable);
  3571. dsi_ctrl->hw.ops.clear_error_status(&dsi_ctrl->hw,
  3572. DSI_ERROR_INTERRUPT_COUNT);
  3573. }
  3574. }
  3575. /**
  3576. * dsi_ctrl_irq_update() - Put a irq vote to process DSI error
  3577. * interrupts at any time.
  3578. * @dsi_ctrl: DSI controller handle.
  3579. * @enable: variable to enable/disable irq
  3580. */
  3581. void dsi_ctrl_irq_update(struct dsi_ctrl *dsi_ctrl, bool enable)
  3582. {
  3583. if (!dsi_ctrl)
  3584. return;
  3585. mutex_lock(&dsi_ctrl->ctrl_lock);
  3586. if (enable)
  3587. dsi_ctrl_enable_status_interrupt(dsi_ctrl,
  3588. DSI_SINT_ERROR, NULL);
  3589. else
  3590. dsi_ctrl_disable_status_interrupt(dsi_ctrl,
  3591. DSI_SINT_ERROR);
  3592. mutex_unlock(&dsi_ctrl->ctrl_lock);
  3593. }
  3594. /**
  3595. * dsi_ctrl_wait4dynamic_refresh_done() - Poll for dynamci refresh
  3596. * done interrupt.
  3597. * @dsi_ctrl: DSI controller handle.
  3598. */
  3599. int dsi_ctrl_wait4dynamic_refresh_done(struct dsi_ctrl *ctrl)
  3600. {
  3601. int rc = 0;
  3602. if (!ctrl)
  3603. return 0;
  3604. mutex_lock(&ctrl->ctrl_lock);
  3605. if (ctrl->hw.ops.wait4dynamic_refresh_done)
  3606. rc = ctrl->hw.ops.wait4dynamic_refresh_done(&ctrl->hw);
  3607. mutex_unlock(&ctrl->ctrl_lock);
  3608. return rc;
  3609. }
  3610. /**
  3611. * dsi_ctrl_drv_register() - register platform driver for dsi controller
  3612. */
  3613. void dsi_ctrl_drv_register(void)
  3614. {
  3615. platform_driver_register(&dsi_ctrl_driver);
  3616. }
  3617. /**
  3618. * dsi_ctrl_drv_unregister() - unregister platform driver
  3619. */
  3620. void dsi_ctrl_drv_unregister(void)
  3621. {
  3622. platform_driver_unregister(&dsi_ctrl_driver);
  3623. }