dsi_ctrl.c 111 KB

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