dsi_ctrl.c 110 KB

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