dsi_ctrl.c 96 KB

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