dsi_ctrl.c 109 KB

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