dsi_ctrl.c 111 KB

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