dsi_ctrl.c 109 KB

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