dsi_ctrl.c 95 KB

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