dsi_ctrl.c 109 KB

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