dsi_ctrl.c 111 KB

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