dsi_ctrl.c 95 KB

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