dsi_ctrl.c 95 KB

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