dsi_panel.c 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/delay.h>
  6. #include <linux/slab.h>
  7. #include <linux/gpio.h>
  8. #include <linux/of_gpio.h>
  9. #include <linux/pwm.h>
  10. #include <video/mipi_display.h>
  11. #include "dsi_panel.h"
  12. #include "dsi_ctrl_hw.h"
  13. #include "dsi_parser.h"
  14. #include "sde_dbg.h"
  15. #include "sde_dsc_helper.h"
  16. #include "sde_vdc_helper.h"
  17. /**
  18. * topology is currently defined by a set of following 3 values:
  19. * 1. num of layer mixers
  20. * 2. num of compression encoders
  21. * 3. num of interfaces
  22. */
  23. #define TOPOLOGY_SET_LEN 3
  24. #define MAX_TOPOLOGY 5
  25. #define DSI_PANEL_DEFAULT_LABEL "Default dsi panel"
  26. #define DEFAULT_PANEL_JITTER_NUMERATOR 2
  27. #define DEFAULT_PANEL_JITTER_DENOMINATOR 1
  28. #define DEFAULT_PANEL_JITTER_ARRAY_SIZE 2
  29. #define MAX_PANEL_JITTER 10
  30. #define DEFAULT_PANEL_PREFILL_LINES 25
  31. #define HIGH_REFRESH_RATE_THRESHOLD_TIME_US 500
  32. #define MIN_PREFILL_LINES 40
  33. static void dsi_dce_prepare_pps_header(char *buf, u32 pps_delay_ms)
  34. {
  35. char *bp;
  36. bp = buf;
  37. /* First 7 bytes are cmd header */
  38. *bp++ = 0x0A;
  39. *bp++ = 1;
  40. *bp++ = 0;
  41. *bp++ = 0;
  42. *bp++ = pps_delay_ms;
  43. *bp++ = 0;
  44. *bp++ = 128;
  45. }
  46. static int dsi_dsc_create_pps_buf_cmd(struct msm_display_dsc_info *dsc,
  47. char *buf, int pps_id, u32 size)
  48. {
  49. dsi_dce_prepare_pps_header(buf, dsc->pps_delay_ms);
  50. buf += DSI_CMD_PPS_HDR_SIZE;
  51. return sde_dsc_create_pps_buf_cmd(dsc, buf, pps_id,
  52. size);
  53. }
  54. static int dsi_vdc_create_pps_buf_cmd(struct msm_display_vdc_info *vdc,
  55. char *buf, int pps_id, u32 size)
  56. {
  57. dsi_dce_prepare_pps_header(buf, vdc->pps_delay_ms);
  58. buf += DSI_CMD_PPS_HDR_SIZE;
  59. return sde_vdc_create_pps_buf_cmd(vdc, buf, pps_id,
  60. size);
  61. }
  62. static int dsi_panel_vreg_get(struct dsi_panel *panel)
  63. {
  64. int rc = 0;
  65. int i;
  66. struct regulator *vreg = NULL;
  67. for (i = 0; i < panel->power_info.count; i++) {
  68. vreg = devm_regulator_get(panel->parent,
  69. panel->power_info.vregs[i].vreg_name);
  70. rc = PTR_ERR_OR_ZERO(vreg);
  71. if (rc) {
  72. DSI_ERR("failed to get %s regulator\n",
  73. panel->power_info.vregs[i].vreg_name);
  74. goto error_put;
  75. }
  76. panel->power_info.vregs[i].vreg = vreg;
  77. }
  78. return rc;
  79. error_put:
  80. for (i = i - 1; i >= 0; i--) {
  81. devm_regulator_put(panel->power_info.vregs[i].vreg);
  82. panel->power_info.vregs[i].vreg = NULL;
  83. }
  84. return rc;
  85. }
  86. static int dsi_panel_vreg_put(struct dsi_panel *panel)
  87. {
  88. int rc = 0;
  89. int i;
  90. for (i = panel->power_info.count - 1; i >= 0; i--)
  91. devm_regulator_put(panel->power_info.vregs[i].vreg);
  92. return rc;
  93. }
  94. static int dsi_panel_gpio_request(struct dsi_panel *panel)
  95. {
  96. int rc = 0;
  97. struct dsi_panel_reset_config *r_config = &panel->reset_config;
  98. if (gpio_is_valid(r_config->reset_gpio)) {
  99. rc = gpio_request(r_config->reset_gpio, "reset_gpio");
  100. if (rc) {
  101. DSI_ERR("request for reset_gpio failed, rc=%d\n", rc);
  102. goto error;
  103. }
  104. }
  105. if (gpio_is_valid(r_config->disp_en_gpio)) {
  106. rc = gpio_request(r_config->disp_en_gpio, "disp_en_gpio");
  107. if (rc) {
  108. DSI_ERR("request for disp_en_gpio failed, rc=%d\n", rc);
  109. goto error_release_reset;
  110. }
  111. }
  112. if (gpio_is_valid(panel->bl_config.en_gpio)) {
  113. rc = gpio_request(panel->bl_config.en_gpio, "bklt_en_gpio");
  114. if (rc) {
  115. DSI_ERR("request for bklt_en_gpio failed, rc=%d\n", rc);
  116. goto error_release_disp_en;
  117. }
  118. }
  119. if (gpio_is_valid(r_config->lcd_mode_sel_gpio)) {
  120. rc = gpio_request(r_config->lcd_mode_sel_gpio, "mode_gpio");
  121. if (rc) {
  122. DSI_ERR("request for mode_gpio failed, rc=%d\n", rc);
  123. goto error_release_mode_sel;
  124. }
  125. }
  126. if (gpio_is_valid(panel->panel_test_gpio)) {
  127. rc = gpio_request(panel->panel_test_gpio, "panel_test_gpio");
  128. if (rc) {
  129. DSI_WARN("request for panel_test_gpio failed, rc=%d\n",
  130. rc);
  131. panel->panel_test_gpio = -1;
  132. rc = 0;
  133. }
  134. }
  135. goto error;
  136. error_release_mode_sel:
  137. if (gpio_is_valid(panel->bl_config.en_gpio))
  138. gpio_free(panel->bl_config.en_gpio);
  139. error_release_disp_en:
  140. if (gpio_is_valid(r_config->disp_en_gpio))
  141. gpio_free(r_config->disp_en_gpio);
  142. error_release_reset:
  143. if (gpio_is_valid(r_config->reset_gpio))
  144. gpio_free(r_config->reset_gpio);
  145. error:
  146. return rc;
  147. }
  148. static int dsi_panel_gpio_release(struct dsi_panel *panel)
  149. {
  150. int rc = 0;
  151. struct dsi_panel_reset_config *r_config = &panel->reset_config;
  152. if (gpio_is_valid(r_config->reset_gpio))
  153. gpio_free(r_config->reset_gpio);
  154. if (gpio_is_valid(r_config->disp_en_gpio))
  155. gpio_free(r_config->disp_en_gpio);
  156. if (gpio_is_valid(panel->bl_config.en_gpio))
  157. gpio_free(panel->bl_config.en_gpio);
  158. if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio))
  159. gpio_free(panel->reset_config.lcd_mode_sel_gpio);
  160. if (gpio_is_valid(panel->panel_test_gpio))
  161. gpio_free(panel->panel_test_gpio);
  162. return rc;
  163. }
  164. int dsi_panel_trigger_esd_attack(struct dsi_panel *panel, bool trusted_vm_env)
  165. {
  166. if (!panel) {
  167. DSI_ERR("Invalid panel param\n");
  168. return -EINVAL;
  169. }
  170. /* toggle reset-gpio by writing directly to register in trusted-vm */
  171. if (trusted_vm_env) {
  172. struct dsi_tlmm_gpio *gpio = NULL;
  173. void __iomem *io;
  174. u32 offset = 0x4;
  175. int i;
  176. for (i = 0; i < panel->tlmm_gpio_count; i++)
  177. if (!strcmp(panel->tlmm_gpio[i].name, "reset-gpio"))
  178. gpio = &panel->tlmm_gpio[i];
  179. if (!gpio) {
  180. DSI_ERR("reset gpio not found\n");
  181. return -EINVAL;
  182. }
  183. io = ioremap(gpio->addr, gpio->size);
  184. writel_relaxed(0, io + offset);
  185. iounmap(io);
  186. } else {
  187. struct dsi_panel_reset_config *r_config = &panel->reset_config;
  188. if (!r_config) {
  189. DSI_ERR("Invalid panel reset configuration\n");
  190. return -EINVAL;
  191. }
  192. if (!gpio_is_valid(r_config->reset_gpio)) {
  193. DSI_ERR("failed to pull down gpio\n");
  194. return -EINVAL;
  195. }
  196. gpio_set_value(r_config->reset_gpio, 0);
  197. }
  198. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1);
  199. DSI_INFO("GPIO pulled low to simulate ESD\n");
  200. return 0;
  201. }
  202. static int dsi_panel_reset(struct dsi_panel *panel)
  203. {
  204. int rc = 0;
  205. struct dsi_panel_reset_config *r_config = &panel->reset_config;
  206. int i;
  207. if (gpio_is_valid(panel->reset_config.disp_en_gpio)) {
  208. rc = gpio_direction_output(panel->reset_config.disp_en_gpio, 1);
  209. if (rc) {
  210. DSI_ERR("unable to set dir for disp gpio rc=%d\n", rc);
  211. goto exit;
  212. }
  213. }
  214. if (r_config->count) {
  215. rc = gpio_direction_output(r_config->reset_gpio,
  216. r_config->sequence[0].level);
  217. if (rc) {
  218. DSI_ERR("unable to set dir for rst gpio rc=%d\n", rc);
  219. goto exit;
  220. }
  221. }
  222. for (i = 0; i < r_config->count; i++) {
  223. gpio_set_value(r_config->reset_gpio,
  224. r_config->sequence[i].level);
  225. if (r_config->sequence[i].sleep_ms)
  226. usleep_range(r_config->sequence[i].sleep_ms * 1000,
  227. (r_config->sequence[i].sleep_ms * 1000) + 100);
  228. }
  229. if (gpio_is_valid(panel->bl_config.en_gpio)) {
  230. rc = gpio_direction_output(panel->bl_config.en_gpio, 1);
  231. if (rc)
  232. DSI_ERR("unable to set dir for bklt gpio rc=%d\n", rc);
  233. }
  234. if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio)) {
  235. bool out = true;
  236. if ((panel->reset_config.mode_sel_state == MODE_SEL_DUAL_PORT)
  237. || (panel->reset_config.mode_sel_state
  238. == MODE_GPIO_LOW))
  239. out = false;
  240. else if ((panel->reset_config.mode_sel_state
  241. == MODE_SEL_SINGLE_PORT) ||
  242. (panel->reset_config.mode_sel_state
  243. == MODE_GPIO_HIGH))
  244. out = true;
  245. rc = gpio_direction_output(
  246. panel->reset_config.lcd_mode_sel_gpio, out);
  247. if (rc)
  248. DSI_ERR("unable to set dir for mode gpio rc=%d\n", rc);
  249. }
  250. if (gpio_is_valid(panel->panel_test_gpio)) {
  251. rc = gpio_direction_input(panel->panel_test_gpio);
  252. if (rc)
  253. DSI_WARN("unable to set dir for panel test gpio rc=%d\n",
  254. rc);
  255. }
  256. exit:
  257. return rc;
  258. }
  259. static int dsi_panel_set_pinctrl_state(struct dsi_panel *panel, bool enable)
  260. {
  261. int rc = 0;
  262. struct pinctrl_state *state;
  263. if (panel->host_config.ext_bridge_mode)
  264. return 0;
  265. if (!panel->pinctrl.pinctrl)
  266. return 0;
  267. if (enable)
  268. state = panel->pinctrl.active;
  269. else
  270. state = panel->pinctrl.suspend;
  271. rc = pinctrl_select_state(panel->pinctrl.pinctrl, state);
  272. if (rc)
  273. DSI_ERR("[%s] failed to set pin state, rc=%d\n",
  274. panel->name, rc);
  275. return rc;
  276. }
  277. static int dsi_panel_power_on(struct dsi_panel *panel)
  278. {
  279. int rc = 0;
  280. rc = dsi_pwr_enable_regulator(&panel->power_info, true);
  281. if (rc) {
  282. DSI_ERR("[%s] failed to enable vregs, rc=%d\n",
  283. panel->name, rc);
  284. goto exit;
  285. }
  286. rc = dsi_panel_set_pinctrl_state(panel, true);
  287. if (rc) {
  288. DSI_ERR("[%s] failed to set pinctrl, rc=%d\n", panel->name, rc);
  289. goto error_disable_vregs;
  290. }
  291. rc = dsi_panel_reset(panel);
  292. if (rc) {
  293. DSI_ERR("[%s] failed to reset panel, rc=%d\n", panel->name, rc);
  294. goto error_disable_gpio;
  295. }
  296. goto exit;
  297. error_disable_gpio:
  298. if (gpio_is_valid(panel->reset_config.disp_en_gpio))
  299. gpio_set_value(panel->reset_config.disp_en_gpio, 0);
  300. if (gpio_is_valid(panel->bl_config.en_gpio))
  301. gpio_set_value(panel->bl_config.en_gpio, 0);
  302. (void)dsi_panel_set_pinctrl_state(panel, false);
  303. error_disable_vregs:
  304. (void)dsi_pwr_enable_regulator(&panel->power_info, false);
  305. exit:
  306. return rc;
  307. }
  308. static int dsi_panel_power_off(struct dsi_panel *panel)
  309. {
  310. int rc = 0;
  311. if (gpio_is_valid(panel->reset_config.disp_en_gpio))
  312. gpio_set_value(panel->reset_config.disp_en_gpio, 0);
  313. if (gpio_is_valid(panel->reset_config.reset_gpio) &&
  314. !panel->reset_gpio_always_on)
  315. gpio_set_value(panel->reset_config.reset_gpio, 0);
  316. if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio))
  317. gpio_set_value(panel->reset_config.lcd_mode_sel_gpio, 0);
  318. if (gpio_is_valid(panel->panel_test_gpio)) {
  319. rc = gpio_direction_input(panel->panel_test_gpio);
  320. if (rc)
  321. DSI_WARN("set dir for panel test gpio failed rc=%d\n",
  322. rc);
  323. }
  324. rc = dsi_panel_set_pinctrl_state(panel, false);
  325. if (rc) {
  326. DSI_ERR("[%s] failed set pinctrl state, rc=%d\n", panel->name,
  327. rc);
  328. }
  329. rc = dsi_pwr_enable_regulator(&panel->power_info, false);
  330. if (rc)
  331. DSI_ERR("[%s] failed to enable vregs, rc=%d\n",
  332. panel->name, rc);
  333. return rc;
  334. }
  335. static int dsi_panel_tx_cmd_set(struct dsi_panel *panel,
  336. enum dsi_cmd_set_type type)
  337. {
  338. int rc = 0, i = 0;
  339. ssize_t len;
  340. struct dsi_cmd_desc *cmds;
  341. u32 count;
  342. enum dsi_cmd_set_state state;
  343. struct dsi_display_mode *mode;
  344. if (!panel || !panel->cur_mode)
  345. return -EINVAL;
  346. mode = panel->cur_mode;
  347. cmds = mode->priv_info->cmd_sets[type].cmds;
  348. count = mode->priv_info->cmd_sets[type].count;
  349. state = mode->priv_info->cmd_sets[type].state;
  350. SDE_EVT32(type, state, count);
  351. if (count == 0) {
  352. DSI_DEBUG("[%s] No commands to be sent for state(%d)\n",
  353. panel->name, type);
  354. goto error;
  355. }
  356. for (i = 0; i < count; i++) {
  357. if (state == DSI_CMD_SET_STATE_LP)
  358. cmds->msg.flags |= MIPI_DSI_MSG_USE_LPM;
  359. if (type == DSI_CMD_SET_VID_SWITCH_OUT)
  360. cmds->msg.flags |= MIPI_DSI_MSG_ASYNC_OVERRIDE;
  361. len = dsi_host_transfer_sub(panel->host, cmds);
  362. if (len < 0) {
  363. rc = len;
  364. DSI_ERR("failed to set cmds(%d), rc=%d\n", type, rc);
  365. goto error;
  366. }
  367. if (cmds->post_wait_ms)
  368. usleep_range(cmds->post_wait_ms*1000,
  369. ((cmds->post_wait_ms*1000)+10));
  370. cmds++;
  371. }
  372. error:
  373. return rc;
  374. }
  375. static int dsi_panel_pinctrl_deinit(struct dsi_panel *panel)
  376. {
  377. int rc = 0;
  378. if (panel->host_config.ext_bridge_mode)
  379. return 0;
  380. devm_pinctrl_put(panel->pinctrl.pinctrl);
  381. return rc;
  382. }
  383. static int dsi_panel_pinctrl_init(struct dsi_panel *panel)
  384. {
  385. int rc = 0;
  386. if (panel->host_config.ext_bridge_mode)
  387. return 0;
  388. /* TODO: pinctrl is defined in dsi dt node */
  389. panel->pinctrl.pinctrl = devm_pinctrl_get(panel->parent);
  390. if (IS_ERR_OR_NULL(panel->pinctrl.pinctrl)) {
  391. rc = PTR_ERR(panel->pinctrl.pinctrl);
  392. DSI_ERR("failed to get pinctrl, rc=%d\n", rc);
  393. goto error;
  394. }
  395. panel->pinctrl.active = pinctrl_lookup_state(panel->pinctrl.pinctrl,
  396. "panel_active");
  397. if (IS_ERR_OR_NULL(panel->pinctrl.active)) {
  398. rc = PTR_ERR(panel->pinctrl.active);
  399. DSI_ERR("failed to get pinctrl active state, rc=%d\n", rc);
  400. goto error;
  401. }
  402. panel->pinctrl.suspend =
  403. pinctrl_lookup_state(panel->pinctrl.pinctrl, "panel_suspend");
  404. if (IS_ERR_OR_NULL(panel->pinctrl.suspend)) {
  405. rc = PTR_ERR(panel->pinctrl.suspend);
  406. DSI_ERR("failed to get pinctrl suspend state, rc=%d\n", rc);
  407. goto error;
  408. }
  409. panel->pinctrl.pwm_pin =
  410. pinctrl_lookup_state(panel->pinctrl.pinctrl, "pwm_pin");
  411. if (IS_ERR_OR_NULL(panel->pinctrl.pwm_pin)) {
  412. panel->pinctrl.pwm_pin = NULL;
  413. DSI_DEBUG("failed to get pinctrl pwm_pin");
  414. }
  415. error:
  416. return rc;
  417. }
  418. static int dsi_panel_wled_register(struct dsi_panel *panel,
  419. struct dsi_backlight_config *bl)
  420. {
  421. struct backlight_device *bd;
  422. bd = backlight_device_get_by_type(BACKLIGHT_RAW);
  423. if (!bd) {
  424. DSI_ERR("[%s] fail raw backlight register rc=%d\n",
  425. panel->name, -EPROBE_DEFER);
  426. return -EPROBE_DEFER;
  427. }
  428. bl->raw_bd = bd;
  429. return 0;
  430. }
  431. static int dsi_panel_update_backlight(struct dsi_panel *panel,
  432. u32 bl_lvl)
  433. {
  434. int rc = 0;
  435. unsigned long mode_flags = 0;
  436. struct mipi_dsi_device *dsi = NULL;
  437. if (!panel || (bl_lvl > 0xffff)) {
  438. DSI_ERR("invalid params\n");
  439. return -EINVAL;
  440. }
  441. dsi = &panel->mipi_device;
  442. if (unlikely(panel->bl_config.lp_mode)) {
  443. mode_flags = dsi->mode_flags;
  444. dsi->mode_flags |= MIPI_DSI_MODE_LPM;
  445. }
  446. if (panel->bl_config.bl_inverted_dbv)
  447. bl_lvl = (((bl_lvl & 0xff) << 8) | (bl_lvl >> 8));
  448. rc = mipi_dsi_dcs_set_display_brightness(dsi, bl_lvl);
  449. if (rc < 0)
  450. DSI_ERR("failed to update dcs backlight:%d\n", bl_lvl);
  451. if (unlikely(panel->bl_config.lp_mode))
  452. dsi->mode_flags = mode_flags;
  453. return rc;
  454. }
  455. static int dsi_panel_update_pwm_backlight(struct dsi_panel *panel,
  456. u32 bl_lvl)
  457. {
  458. int rc = 0;
  459. u32 duty = 0;
  460. u32 period_ns = 0;
  461. struct dsi_backlight_config *bl;
  462. if (!panel) {
  463. DSI_ERR("Invalid Params\n");
  464. return -EINVAL;
  465. }
  466. bl = &panel->bl_config;
  467. if (!bl->pwm_bl) {
  468. DSI_ERR("pwm device not found\n");
  469. return -EINVAL;
  470. }
  471. period_ns = bl->pwm_period_usecs * NSEC_PER_USEC;
  472. duty = bl_lvl * period_ns;
  473. duty /= bl->bl_max_level;
  474. rc = pwm_config(bl->pwm_bl, duty, period_ns);
  475. if (rc) {
  476. DSI_ERR("[%s] failed to change pwm config, rc=\n", panel->name,
  477. rc);
  478. goto error;
  479. }
  480. if (bl_lvl == 0 && bl->pwm_enabled) {
  481. pwm_disable(bl->pwm_bl);
  482. bl->pwm_enabled = false;
  483. return 0;
  484. }
  485. if (bl_lvl != 0 && !bl->pwm_enabled) {
  486. rc = pwm_enable(bl->pwm_bl);
  487. if (rc) {
  488. DSI_ERR("[%s] failed to enable pwm, rc=\n", panel->name,
  489. rc);
  490. goto error;
  491. }
  492. bl->pwm_enabled = true;
  493. }
  494. error:
  495. return rc;
  496. }
  497. int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl)
  498. {
  499. int rc = 0;
  500. struct dsi_backlight_config *bl = &panel->bl_config;
  501. if (panel->host_config.ext_bridge_mode)
  502. return 0;
  503. DSI_DEBUG("backlight type:%d lvl:%d\n", bl->type, bl_lvl);
  504. switch (bl->type) {
  505. case DSI_BACKLIGHT_WLED:
  506. rc = backlight_device_set_brightness(bl->raw_bd, bl_lvl);
  507. break;
  508. case DSI_BACKLIGHT_DCS:
  509. rc = dsi_panel_update_backlight(panel, bl_lvl);
  510. break;
  511. case DSI_BACKLIGHT_EXTERNAL:
  512. break;
  513. case DSI_BACKLIGHT_PWM:
  514. rc = dsi_panel_update_pwm_backlight(panel, bl_lvl);
  515. break;
  516. default:
  517. DSI_ERR("Backlight type(%d) not supported\n", bl->type);
  518. rc = -ENOTSUPP;
  519. }
  520. return rc;
  521. }
  522. static u32 dsi_panel_get_brightness(struct dsi_backlight_config *bl)
  523. {
  524. u32 cur_bl_level;
  525. struct backlight_device *bd = bl->raw_bd;
  526. /* default the brightness level to 50% */
  527. cur_bl_level = bl->bl_max_level >> 1;
  528. switch (bl->type) {
  529. case DSI_BACKLIGHT_WLED:
  530. /* Try to query the backlight level from the backlight device */
  531. if (bd->ops && bd->ops->get_brightness)
  532. cur_bl_level = bd->ops->get_brightness(bd);
  533. break;
  534. case DSI_BACKLIGHT_DCS:
  535. case DSI_BACKLIGHT_EXTERNAL:
  536. case DSI_BACKLIGHT_PWM:
  537. default:
  538. /*
  539. * Ideally, we should read the backlight level from the
  540. * panel. For now, just set it default value.
  541. */
  542. break;
  543. }
  544. DSI_DEBUG("cur_bl_level=%d\n", cur_bl_level);
  545. return cur_bl_level;
  546. }
  547. void dsi_panel_bl_handoff(struct dsi_panel *panel)
  548. {
  549. struct dsi_backlight_config *bl = &panel->bl_config;
  550. bl->bl_level = dsi_panel_get_brightness(bl);
  551. }
  552. static int dsi_panel_pwm_register(struct dsi_panel *panel)
  553. {
  554. int rc = 0;
  555. struct dsi_backlight_config *bl = &panel->bl_config;
  556. bl->pwm_bl = devm_of_pwm_get(panel->parent, panel->panel_of_node, NULL);
  557. if (IS_ERR_OR_NULL(bl->pwm_bl)) {
  558. rc = PTR_ERR(bl->pwm_bl);
  559. DSI_ERR("[%s] failed to request pwm, rc=%d\n", panel->name,
  560. rc);
  561. return rc;
  562. }
  563. if (panel->pinctrl.pwm_pin) {
  564. rc = pinctrl_select_state(panel->pinctrl.pinctrl,
  565. panel->pinctrl.pwm_pin);
  566. if (rc)
  567. DSI_ERR("[%s] failed to set pwm pinctrl, rc=%d\n",
  568. panel->name, rc);
  569. }
  570. return 0;
  571. }
  572. static int dsi_panel_bl_register(struct dsi_panel *panel)
  573. {
  574. int rc = 0;
  575. struct dsi_backlight_config *bl = &panel->bl_config;
  576. if (panel->host_config.ext_bridge_mode)
  577. return 0;
  578. switch (bl->type) {
  579. case DSI_BACKLIGHT_WLED:
  580. rc = dsi_panel_wled_register(panel, bl);
  581. break;
  582. case DSI_BACKLIGHT_DCS:
  583. break;
  584. case DSI_BACKLIGHT_EXTERNAL:
  585. break;
  586. case DSI_BACKLIGHT_PWM:
  587. rc = dsi_panel_pwm_register(panel);
  588. break;
  589. default:
  590. DSI_ERR("Backlight type(%d) not supported\n", bl->type);
  591. rc = -ENOTSUPP;
  592. goto error;
  593. }
  594. error:
  595. return rc;
  596. }
  597. static void dsi_panel_pwm_unregister(struct dsi_panel *panel)
  598. {
  599. struct dsi_backlight_config *bl = &panel->bl_config;
  600. devm_pwm_put(panel->parent, bl->pwm_bl);
  601. }
  602. static int dsi_panel_bl_unregister(struct dsi_panel *panel)
  603. {
  604. int rc = 0;
  605. struct dsi_backlight_config *bl = &panel->bl_config;
  606. if (panel->host_config.ext_bridge_mode)
  607. return 0;
  608. switch (bl->type) {
  609. case DSI_BACKLIGHT_WLED:
  610. break;
  611. case DSI_BACKLIGHT_DCS:
  612. break;
  613. case DSI_BACKLIGHT_EXTERNAL:
  614. break;
  615. case DSI_BACKLIGHT_PWM:
  616. dsi_panel_pwm_unregister(panel);
  617. break;
  618. default:
  619. DSI_ERR("Backlight type(%d) not supported\n", bl->type);
  620. rc = -ENOTSUPP;
  621. goto error;
  622. }
  623. error:
  624. return rc;
  625. }
  626. static int dsi_panel_parse_timing(struct dsi_mode_info *mode,
  627. struct dsi_parser_utils *utils)
  628. {
  629. int rc = 0;
  630. u64 tmp64 = 0;
  631. struct dsi_display_mode *display_mode;
  632. struct dsi_display_mode_priv_info *priv_info;
  633. display_mode = container_of(mode, struct dsi_display_mode, timing);
  634. priv_info = display_mode->priv_info;
  635. rc = utils->read_u64(utils->data,
  636. "qcom,mdss-dsi-panel-clockrate", &tmp64);
  637. if (rc == -EOVERFLOW) {
  638. tmp64 = 0;
  639. rc = utils->read_u32(utils->data,
  640. "qcom,mdss-dsi-panel-clockrate", (u32 *)&tmp64);
  641. }
  642. mode->clk_rate_hz = !rc ? tmp64 : 0;
  643. display_mode->priv_info->clk_rate_hz = mode->clk_rate_hz;
  644. mode->pclk_scale.numer = 1;
  645. mode->pclk_scale.denom = 1;
  646. display_mode->priv_info->pclk_scale = mode->pclk_scale;
  647. rc = utils->read_u32(utils->data, "qcom,mdss-mdp-transfer-time-us",
  648. &mode->mdp_transfer_time_us);
  649. if (!rc)
  650. display_mode->priv_info->mdp_transfer_time_us =
  651. mode->mdp_transfer_time_us;
  652. else
  653. display_mode->priv_info->mdp_transfer_time_us = 0;
  654. rc = utils->read_u32(utils->data,
  655. "qcom,mdss-dsi-panel-framerate",
  656. &mode->refresh_rate);
  657. if (rc) {
  658. DSI_ERR("failed to read qcom,mdss-dsi-panel-framerate, rc=%d\n",
  659. rc);
  660. goto error;
  661. }
  662. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-panel-width",
  663. &mode->h_active);
  664. if (rc) {
  665. DSI_ERR("failed to read qcom,mdss-dsi-panel-width, rc=%d\n",
  666. rc);
  667. goto error;
  668. }
  669. rc = utils->read_u32(utils->data,
  670. "qcom,mdss-dsi-h-front-porch",
  671. &mode->h_front_porch);
  672. if (rc) {
  673. DSI_ERR("failed to read qcom,mdss-dsi-h-front-porch, rc=%d\n",
  674. rc);
  675. goto error;
  676. }
  677. rc = utils->read_u32(utils->data,
  678. "qcom,mdss-dsi-h-back-porch",
  679. &mode->h_back_porch);
  680. if (rc) {
  681. DSI_ERR("failed to read qcom,mdss-dsi-h-back-porch, rc=%d\n",
  682. rc);
  683. goto error;
  684. }
  685. rc = utils->read_u32(utils->data,
  686. "qcom,mdss-dsi-h-pulse-width",
  687. &mode->h_sync_width);
  688. if (rc) {
  689. DSI_ERR("failed to read qcom,mdss-dsi-h-pulse-width, rc=%d\n",
  690. rc);
  691. goto error;
  692. }
  693. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-h-sync-skew",
  694. &mode->h_skew);
  695. if (rc)
  696. DSI_DEBUG("qcom,mdss-dsi-h-sync-skew is not defined, rc=%d\n",
  697. rc);
  698. DSI_DEBUG("panel horz active:%d front_portch:%d back_porch:%d sync_skew:%d\n",
  699. mode->h_active, mode->h_front_porch, mode->h_back_porch,
  700. mode->h_sync_width);
  701. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-panel-height",
  702. &mode->v_active);
  703. if (rc) {
  704. DSI_ERR("failed to read qcom,mdss-dsi-panel-height, rc=%d\n",
  705. rc);
  706. goto error;
  707. }
  708. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-v-back-porch",
  709. &mode->v_back_porch);
  710. if (rc) {
  711. DSI_ERR("failed to read qcom,mdss-dsi-v-back-porch, rc=%d\n",
  712. rc);
  713. goto error;
  714. }
  715. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-v-front-porch",
  716. &mode->v_front_porch);
  717. if (rc) {
  718. DSI_ERR("failed to read qcom,mdss-dsi-v-back-porch, rc=%d\n",
  719. rc);
  720. goto error;
  721. }
  722. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-v-pulse-width",
  723. &mode->v_sync_width);
  724. if (rc) {
  725. DSI_ERR("failed to read qcom,mdss-dsi-v-pulse-width, rc=%d\n",
  726. rc);
  727. goto error;
  728. }
  729. DSI_DEBUG("panel vert active:%d front_portch:%d back_porch:%d pulse_width:%d\n",
  730. mode->v_active, mode->v_front_porch, mode->v_back_porch,
  731. mode->v_sync_width);
  732. error:
  733. return rc;
  734. }
  735. static int dsi_panel_parse_pixel_format(struct dsi_host_common_cfg *host,
  736. struct dsi_parser_utils *utils,
  737. const char *name)
  738. {
  739. int rc = 0;
  740. u32 bpp = 0;
  741. enum dsi_pixel_format fmt;
  742. const char *packing;
  743. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-bpp", &bpp);
  744. if (rc) {
  745. DSI_ERR("[%s] failed to read qcom,mdss-dsi-bpp, rc=%d\n",
  746. name, rc);
  747. return rc;
  748. }
  749. host->bpp = bpp;
  750. switch (bpp) {
  751. case 3:
  752. fmt = DSI_PIXEL_FORMAT_RGB111;
  753. break;
  754. case 8:
  755. fmt = DSI_PIXEL_FORMAT_RGB332;
  756. break;
  757. case 12:
  758. fmt = DSI_PIXEL_FORMAT_RGB444;
  759. break;
  760. case 16:
  761. fmt = DSI_PIXEL_FORMAT_RGB565;
  762. break;
  763. case 18:
  764. fmt = DSI_PIXEL_FORMAT_RGB666;
  765. break;
  766. case 24:
  767. default:
  768. fmt = DSI_PIXEL_FORMAT_RGB888;
  769. break;
  770. }
  771. if (fmt == DSI_PIXEL_FORMAT_RGB666) {
  772. packing = utils->get_property(utils->data,
  773. "qcom,mdss-dsi-pixel-packing",
  774. NULL);
  775. if (packing && !strcmp(packing, "loose"))
  776. fmt = DSI_PIXEL_FORMAT_RGB666_LOOSE;
  777. }
  778. host->dst_format = fmt;
  779. return rc;
  780. }
  781. static int dsi_panel_parse_lane_states(struct dsi_host_common_cfg *host,
  782. struct dsi_parser_utils *utils,
  783. const char *name)
  784. {
  785. int rc = 0;
  786. bool lane_enabled;
  787. u32 num_of_lanes = 0;
  788. lane_enabled = utils->read_bool(utils->data,
  789. "qcom,mdss-dsi-lane-0-state");
  790. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_0 : 0);
  791. lane_enabled = utils->read_bool(utils->data,
  792. "qcom,mdss-dsi-lane-1-state");
  793. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_1 : 0);
  794. lane_enabled = utils->read_bool(utils->data,
  795. "qcom,mdss-dsi-lane-2-state");
  796. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_2 : 0);
  797. lane_enabled = utils->read_bool(utils->data,
  798. "qcom,mdss-dsi-lane-3-state");
  799. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_3 : 0);
  800. if (host->data_lanes & DSI_DATA_LANE_0)
  801. num_of_lanes++;
  802. if (host->data_lanes & DSI_DATA_LANE_1)
  803. num_of_lanes++;
  804. if (host->data_lanes & DSI_DATA_LANE_2)
  805. num_of_lanes++;
  806. if (host->data_lanes & DSI_DATA_LANE_3)
  807. num_of_lanes++;
  808. host->num_data_lanes = num_of_lanes;
  809. if (host->data_lanes == 0) {
  810. DSI_ERR("[%s] No data lanes are enabled, rc=%d\n", name, rc);
  811. rc = -EINVAL;
  812. }
  813. return rc;
  814. }
  815. static int dsi_panel_parse_color_swap(struct dsi_host_common_cfg *host,
  816. struct dsi_parser_utils *utils,
  817. const char *name)
  818. {
  819. int rc = 0;
  820. const char *swap_mode;
  821. swap_mode = utils->get_property(utils->data,
  822. "qcom,mdss-dsi-color-order", NULL);
  823. if (swap_mode) {
  824. if (!strcmp(swap_mode, "rgb_swap_rgb")) {
  825. host->swap_mode = DSI_COLOR_SWAP_RGB;
  826. } else if (!strcmp(swap_mode, "rgb_swap_rbg")) {
  827. host->swap_mode = DSI_COLOR_SWAP_RBG;
  828. } else if (!strcmp(swap_mode, "rgb_swap_brg")) {
  829. host->swap_mode = DSI_COLOR_SWAP_BRG;
  830. } else if (!strcmp(swap_mode, "rgb_swap_grb")) {
  831. host->swap_mode = DSI_COLOR_SWAP_GRB;
  832. } else if (!strcmp(swap_mode, "rgb_swap_gbr")) {
  833. host->swap_mode = DSI_COLOR_SWAP_GBR;
  834. } else {
  835. DSI_ERR("[%s] Unrecognized color order-%s\n",
  836. name, swap_mode);
  837. rc = -EINVAL;
  838. }
  839. } else {
  840. DSI_DEBUG("[%s] Falling back to default color order\n", name);
  841. host->swap_mode = DSI_COLOR_SWAP_RGB;
  842. }
  843. /* bit swap on color channel is not defined in dt */
  844. host->bit_swap_red = false;
  845. host->bit_swap_green = false;
  846. host->bit_swap_blue = false;
  847. return rc;
  848. }
  849. static int dsi_panel_parse_triggers(struct dsi_host_common_cfg *host,
  850. struct dsi_parser_utils *utils,
  851. const char *name)
  852. {
  853. const char *trig;
  854. int rc = 0;
  855. trig = utils->get_property(utils->data,
  856. "qcom,mdss-dsi-mdp-trigger", NULL);
  857. if (trig) {
  858. if (!strcmp(trig, "none")) {
  859. host->mdp_cmd_trigger = DSI_TRIGGER_NONE;
  860. } else if (!strcmp(trig, "trigger_te")) {
  861. host->mdp_cmd_trigger = DSI_TRIGGER_TE;
  862. } else if (!strcmp(trig, "trigger_sw")) {
  863. host->mdp_cmd_trigger = DSI_TRIGGER_SW;
  864. } else if (!strcmp(trig, "trigger_sw_te")) {
  865. host->mdp_cmd_trigger = DSI_TRIGGER_SW_TE;
  866. } else {
  867. DSI_ERR("[%s] Unrecognized mdp trigger type (%s)\n",
  868. name, trig);
  869. rc = -EINVAL;
  870. }
  871. } else {
  872. DSI_DEBUG("[%s] Falling back to default MDP trigger\n",
  873. name);
  874. host->mdp_cmd_trigger = DSI_TRIGGER_SW;
  875. }
  876. trig = utils->get_property(utils->data,
  877. "qcom,mdss-dsi-dma-trigger", NULL);
  878. if (trig) {
  879. if (!strcmp(trig, "none")) {
  880. host->dma_cmd_trigger = DSI_TRIGGER_NONE;
  881. } else if (!strcmp(trig, "trigger_te")) {
  882. host->dma_cmd_trigger = DSI_TRIGGER_TE;
  883. } else if (!strcmp(trig, "trigger_sw")) {
  884. host->dma_cmd_trigger = DSI_TRIGGER_SW;
  885. } else if (!strcmp(trig, "trigger_sw_seof")) {
  886. host->dma_cmd_trigger = DSI_TRIGGER_SW_SEOF;
  887. } else if (!strcmp(trig, "trigger_sw_te")) {
  888. host->dma_cmd_trigger = DSI_TRIGGER_SW_TE;
  889. } else {
  890. DSI_ERR("[%s] Unrecognized mdp trigger type (%s)\n",
  891. name, trig);
  892. rc = -EINVAL;
  893. }
  894. } else {
  895. DSI_DEBUG("[%s] Falling back to default MDP trigger\n", name);
  896. host->dma_cmd_trigger = DSI_TRIGGER_SW;
  897. }
  898. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-te-pin-select",
  899. &host->te_mode);
  900. if (rc) {
  901. DSI_WARN("[%s] fallback to default te-pin-select\n", name);
  902. host->te_mode = 1;
  903. rc = 0;
  904. }
  905. return rc;
  906. }
  907. static int dsi_panel_parse_misc_host_config(struct dsi_host_common_cfg *host,
  908. struct dsi_parser_utils *utils,
  909. const char *name)
  910. {
  911. u32 val = 0, line_no = 0, window = 0;
  912. int rc = 0;
  913. bool panel_cphy_mode = false;
  914. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-t-clk-post", &val);
  915. if (!rc) {
  916. host->t_clk_post = val;
  917. DSI_DEBUG("[%s] t_clk_post = %d\n", name, val);
  918. }
  919. val = 0;
  920. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-t-clk-pre", &val);
  921. if (!rc) {
  922. host->t_clk_pre = val;
  923. DSI_DEBUG("[%s] t_clk_pre = %d\n", name, val);
  924. }
  925. host->ignore_rx_eot = utils->read_bool(utils->data,
  926. "qcom,mdss-dsi-rx-eot-ignore");
  927. host->append_tx_eot = utils->read_bool(utils->data,
  928. "qcom,mdss-dsi-tx-eot-append");
  929. host->ext_bridge_mode = utils->read_bool(utils->data,
  930. "qcom,mdss-dsi-ext-bridge-mode");
  931. host->force_hs_clk_lane = utils->read_bool(utils->data,
  932. "qcom,mdss-dsi-force-clock-lane-hs");
  933. panel_cphy_mode = utils->read_bool(utils->data,
  934. "qcom,panel-cphy-mode");
  935. host->phy_type = panel_cphy_mode ? DSI_PHY_TYPE_CPHY
  936. : DSI_PHY_TYPE_DPHY;
  937. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-dma-schedule-line",
  938. &line_no);
  939. if (rc)
  940. host->dma_sched_line = 0;
  941. else
  942. host->dma_sched_line = line_no;
  943. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-dma-schedule-window",
  944. &window);
  945. if (rc)
  946. host->dma_sched_window = 0;
  947. else
  948. host->dma_sched_window = window;
  949. DSI_DEBUG("[%s] DMA scheduling parameters Line: %d Window: %d\n", name,
  950. host->dma_sched_line, host->dma_sched_window);
  951. return 0;
  952. }
  953. static void dsi_panel_parse_split_link_config(struct dsi_host_common_cfg *host,
  954. struct dsi_parser_utils *utils,
  955. const char *name)
  956. {
  957. int rc = 0;
  958. u32 val = 0;
  959. bool supported = false;
  960. struct dsi_split_link_config *split_link = &host->split_link;
  961. supported = utils->read_bool(utils->data, "qcom,split-link-enabled");
  962. if (!supported) {
  963. DSI_DEBUG("[%s] Split link is not supported\n", name);
  964. split_link->enabled = false;
  965. return;
  966. }
  967. rc = utils->read_u32(utils->data, "qcom,sublinks-count", &val);
  968. if (rc || val < 1) {
  969. DSI_DEBUG("[%s] Using default sublinks count\n", name);
  970. split_link->num_sublinks = 2;
  971. } else {
  972. split_link->num_sublinks = val;
  973. }
  974. rc = utils->read_u32(utils->data, "qcom,lanes-per-sublink", &val);
  975. if (rc || val < 1) {
  976. DSI_DEBUG("[%s] Using default lanes per sublink\n", name);
  977. split_link->lanes_per_sublink = 2;
  978. } else {
  979. split_link->lanes_per_sublink = val;
  980. }
  981. supported = utils->read_bool(utils->data, "qcom,split-link-sublink-swap");
  982. if (!supported)
  983. split_link->sublink_swap = false;
  984. DSI_DEBUG("[%s] Split link is supported %d-%d\n", name,
  985. split_link->num_sublinks, split_link->lanes_per_sublink);
  986. split_link->enabled = true;
  987. }
  988. static int dsi_panel_parse_host_config(struct dsi_panel *panel)
  989. {
  990. int rc = 0;
  991. struct dsi_parser_utils *utils = &panel->utils;
  992. rc = dsi_panel_parse_pixel_format(&panel->host_config, utils,
  993. panel->name);
  994. if (rc) {
  995. DSI_ERR("[%s] failed to get pixel format, rc=%d\n",
  996. panel->name, rc);
  997. goto error;
  998. }
  999. rc = dsi_panel_parse_lane_states(&panel->host_config, utils,
  1000. panel->name);
  1001. if (rc) {
  1002. DSI_ERR("[%s] failed to parse lane states, rc=%d\n",
  1003. panel->name, rc);
  1004. goto error;
  1005. }
  1006. rc = dsi_panel_parse_color_swap(&panel->host_config, utils,
  1007. panel->name);
  1008. if (rc) {
  1009. DSI_ERR("[%s] failed to parse color swap config, rc=%d\n",
  1010. panel->name, rc);
  1011. goto error;
  1012. }
  1013. rc = dsi_panel_parse_triggers(&panel->host_config, utils,
  1014. panel->name);
  1015. if (rc) {
  1016. DSI_ERR("[%s] failed to parse triggers, rc=%d\n",
  1017. panel->name, rc);
  1018. goto error;
  1019. }
  1020. rc = dsi_panel_parse_misc_host_config(&panel->host_config, utils,
  1021. panel->name);
  1022. if (rc) {
  1023. DSI_ERR("[%s] failed to parse misc host config, rc=%d\n",
  1024. panel->name, rc);
  1025. goto error;
  1026. }
  1027. dsi_panel_parse_split_link_config(&panel->host_config, utils,
  1028. panel->name);
  1029. error:
  1030. return rc;
  1031. }
  1032. static int dsi_panel_parse_qsync_caps(struct dsi_panel *panel,
  1033. struct device_node *of_node)
  1034. {
  1035. int rc = 0;
  1036. u32 val = 0, i;
  1037. struct dsi_qsync_capabilities *qsync_caps = &panel->qsync_caps;
  1038. struct dsi_parser_utils *utils = &panel->utils;
  1039. const char *name = panel->name;
  1040. /**
  1041. * "mdss-dsi-qsync-min-refresh-rate" is defined in cmd mode and
  1042. * video mode when there is only one qsync min fps present.
  1043. */
  1044. rc = of_property_read_u32(of_node,
  1045. "qcom,mdss-dsi-qsync-min-refresh-rate",
  1046. &val);
  1047. if (rc)
  1048. DSI_DEBUG("[%s] qsync min fps not defined rc:%d\n",
  1049. panel->name, rc);
  1050. qsync_caps->qsync_min_fps = val;
  1051. /**
  1052. * "dsi-supported-qsync-min-fps-list" may be defined in video
  1053. * mode, only in dfps case when "qcom,dsi-supported-dfps-list"
  1054. * is defined.
  1055. */
  1056. qsync_caps->qsync_min_fps_list_len = utils->count_u32_elems(utils->data,
  1057. "qcom,dsi-supported-qsync-min-fps-list");
  1058. if (qsync_caps->qsync_min_fps_list_len < 1)
  1059. goto qsync_support;
  1060. /**
  1061. * qcom,dsi-supported-qsync-min-fps-list cannot be defined
  1062. * along with qcom,mdss-dsi-qsync-min-refresh-rate.
  1063. */
  1064. if (qsync_caps->qsync_min_fps_list_len >= 1 &&
  1065. qsync_caps->qsync_min_fps) {
  1066. DSI_ERR("[%s] Both qsync nodes are defined\n",
  1067. name);
  1068. rc = -EINVAL;
  1069. goto error;
  1070. }
  1071. if (panel->dfps_caps.dfps_list_len !=
  1072. qsync_caps->qsync_min_fps_list_len) {
  1073. DSI_ERR("[%s] Qsync min fps list mismatch with dfps\n", name);
  1074. rc = -EINVAL;
  1075. goto error;
  1076. }
  1077. qsync_caps->qsync_min_fps_list =
  1078. kcalloc(qsync_caps->qsync_min_fps_list_len, sizeof(u32),
  1079. GFP_KERNEL);
  1080. if (!qsync_caps->qsync_min_fps_list) {
  1081. rc = -ENOMEM;
  1082. goto error;
  1083. }
  1084. rc = utils->read_u32_array(utils->data,
  1085. "qcom,dsi-supported-qsync-min-fps-list",
  1086. qsync_caps->qsync_min_fps_list,
  1087. qsync_caps->qsync_min_fps_list_len);
  1088. if (rc) {
  1089. DSI_ERR("[%s] Qsync min fps list parse failed\n", name);
  1090. rc = -EINVAL;
  1091. goto error;
  1092. }
  1093. qsync_caps->qsync_min_fps = qsync_caps->qsync_min_fps_list[0];
  1094. for (i = 1; i < qsync_caps->qsync_min_fps_list_len; i++) {
  1095. if (qsync_caps->qsync_min_fps_list[i] <
  1096. qsync_caps->qsync_min_fps)
  1097. qsync_caps->qsync_min_fps =
  1098. qsync_caps->qsync_min_fps_list[i];
  1099. }
  1100. qsync_support:
  1101. /* allow qsync support only if DFPS is with VFP approach */
  1102. if ((panel->dfps_caps.dfps_support) &&
  1103. !(panel->dfps_caps.type == DSI_DFPS_IMMEDIATE_VFP))
  1104. panel->qsync_caps.qsync_min_fps = 0;
  1105. error:
  1106. if (rc < 0) {
  1107. qsync_caps->qsync_min_fps = 0;
  1108. qsync_caps->qsync_min_fps_list_len = 0;
  1109. }
  1110. return rc;
  1111. }
  1112. static int dsi_panel_parse_dyn_clk_caps(struct dsi_panel *panel)
  1113. {
  1114. int rc = 0;
  1115. bool supported = false;
  1116. struct dsi_dyn_clk_caps *dyn_clk_caps = &panel->dyn_clk_caps;
  1117. struct dsi_parser_utils *utils = &panel->utils;
  1118. const char *name = panel->name;
  1119. const char *type;
  1120. supported = utils->read_bool(utils->data, "qcom,dsi-dyn-clk-enable");
  1121. if (!supported) {
  1122. dyn_clk_caps->dyn_clk_support = false;
  1123. return rc;
  1124. }
  1125. dyn_clk_caps->bit_clk_list_len = utils->count_u32_elems(utils->data,
  1126. "qcom,dsi-dyn-clk-list");
  1127. if (dyn_clk_caps->bit_clk_list_len < 1) {
  1128. DSI_ERR("[%s] failed to get supported bit clk list\n", name);
  1129. return -EINVAL;
  1130. }
  1131. dyn_clk_caps->bit_clk_list = kcalloc(dyn_clk_caps->bit_clk_list_len,
  1132. sizeof(u32), GFP_KERNEL);
  1133. if (!dyn_clk_caps->bit_clk_list)
  1134. return -ENOMEM;
  1135. rc = utils->read_u32_array(utils->data, "qcom,dsi-dyn-clk-list",
  1136. dyn_clk_caps->bit_clk_list,
  1137. dyn_clk_caps->bit_clk_list_len);
  1138. if (rc) {
  1139. DSI_ERR("[%s] failed to parse supported bit clk list\n", name);
  1140. return -EINVAL;
  1141. }
  1142. dyn_clk_caps->dyn_clk_support = true;
  1143. type = utils->get_property(utils->data,
  1144. "qcom,dsi-dyn-clk-type", NULL);
  1145. if (!type) {
  1146. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_LEGACY;
  1147. dyn_clk_caps->maintain_const_fps = false;
  1148. return 0;
  1149. }
  1150. if (!strcmp(type, "constant-fps-adjust-hfp")) {
  1151. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_HFP;
  1152. dyn_clk_caps->maintain_const_fps = true;
  1153. } else if (!strcmp(type, "constant-fps-adjust-vfp")) {
  1154. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_VFP;
  1155. dyn_clk_caps->maintain_const_fps = true;
  1156. } else {
  1157. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_LEGACY;
  1158. dyn_clk_caps->maintain_const_fps = false;
  1159. }
  1160. DSI_DEBUG("Dynamic clock type is [%s]\n", type);
  1161. return 0;
  1162. }
  1163. static int dsi_panel_parse_dfps_caps(struct dsi_panel *panel)
  1164. {
  1165. int rc = 0;
  1166. bool supported = false;
  1167. struct dsi_dfps_capabilities *dfps_caps = &panel->dfps_caps;
  1168. struct dsi_parser_utils *utils = &panel->utils;
  1169. const char *name = panel->name;
  1170. const char *type;
  1171. u32 i;
  1172. supported = utils->read_bool(utils->data,
  1173. "qcom,mdss-dsi-pan-enable-dynamic-fps");
  1174. if (!supported) {
  1175. DSI_DEBUG("[%s] DFPS is not supported\n", name);
  1176. dfps_caps->dfps_support = false;
  1177. return rc;
  1178. }
  1179. type = utils->get_property(utils->data,
  1180. "qcom,mdss-dsi-pan-fps-update", NULL);
  1181. if (!type) {
  1182. DSI_ERR("[%s] dfps type not defined\n", name);
  1183. rc = -EINVAL;
  1184. goto error;
  1185. } else if (!strcmp(type, "dfps_suspend_resume_mode")) {
  1186. dfps_caps->type = DSI_DFPS_SUSPEND_RESUME;
  1187. } else if (!strcmp(type, "dfps_immediate_clk_mode")) {
  1188. dfps_caps->type = DSI_DFPS_IMMEDIATE_CLK;
  1189. } else if (!strcmp(type, "dfps_immediate_porch_mode_hfp")) {
  1190. dfps_caps->type = DSI_DFPS_IMMEDIATE_HFP;
  1191. } else if (!strcmp(type, "dfps_immediate_porch_mode_vfp")) {
  1192. dfps_caps->type = DSI_DFPS_IMMEDIATE_VFP;
  1193. } else {
  1194. DSI_ERR("[%s] dfps type is not recognized\n", name);
  1195. rc = -EINVAL;
  1196. goto error;
  1197. }
  1198. dfps_caps->dfps_list_len = utils->count_u32_elems(utils->data,
  1199. "qcom,dsi-supported-dfps-list");
  1200. if (dfps_caps->dfps_list_len < 1) {
  1201. DSI_ERR("[%s] dfps refresh list not present\n", name);
  1202. rc = -EINVAL;
  1203. goto error;
  1204. }
  1205. dfps_caps->dfps_list = kcalloc(dfps_caps->dfps_list_len, sizeof(u32),
  1206. GFP_KERNEL);
  1207. if (!dfps_caps->dfps_list) {
  1208. rc = -ENOMEM;
  1209. goto error;
  1210. }
  1211. rc = utils->read_u32_array(utils->data,
  1212. "qcom,dsi-supported-dfps-list",
  1213. dfps_caps->dfps_list,
  1214. dfps_caps->dfps_list_len);
  1215. if (rc) {
  1216. DSI_ERR("[%s] dfps refresh rate list parse failed\n", name);
  1217. rc = -EINVAL;
  1218. goto error;
  1219. }
  1220. dfps_caps->dfps_support = true;
  1221. /* calculate max and min fps */
  1222. dfps_caps->max_refresh_rate = dfps_caps->dfps_list[0];
  1223. dfps_caps->min_refresh_rate = dfps_caps->dfps_list[0];
  1224. for (i = 1; i < dfps_caps->dfps_list_len; i++) {
  1225. if (dfps_caps->dfps_list[i] < dfps_caps->min_refresh_rate)
  1226. dfps_caps->min_refresh_rate = dfps_caps->dfps_list[i];
  1227. else if (dfps_caps->dfps_list[i] > dfps_caps->max_refresh_rate)
  1228. dfps_caps->max_refresh_rate = dfps_caps->dfps_list[i];
  1229. }
  1230. error:
  1231. return rc;
  1232. }
  1233. static int dsi_panel_parse_video_host_config(struct dsi_video_engine_cfg *cfg,
  1234. struct dsi_parser_utils *utils,
  1235. const char *name)
  1236. {
  1237. int rc = 0;
  1238. const char *traffic_mode;
  1239. u32 vc_id = 0;
  1240. u32 val = 0;
  1241. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-h-sync-pulse", &val);
  1242. if (rc) {
  1243. DSI_DEBUG("[%s] fallback to default h-sync-pulse\n", name);
  1244. cfg->pulse_mode_hsa_he = false;
  1245. } else if (val == 1) {
  1246. cfg->pulse_mode_hsa_he = true;
  1247. } else if (val == 0) {
  1248. cfg->pulse_mode_hsa_he = false;
  1249. } else {
  1250. DSI_ERR("[%s] Unrecognized value for mdss-dsi-h-sync-pulse\n",
  1251. name);
  1252. rc = -EINVAL;
  1253. goto error;
  1254. }
  1255. cfg->hfp_lp11_en = utils->read_bool(utils->data,
  1256. "qcom,mdss-dsi-hfp-power-mode");
  1257. cfg->hbp_lp11_en = utils->read_bool(utils->data,
  1258. "qcom,mdss-dsi-hbp-power-mode");
  1259. cfg->hsa_lp11_en = utils->read_bool(utils->data,
  1260. "qcom,mdss-dsi-hsa-power-mode");
  1261. cfg->last_line_interleave_en = utils->read_bool(utils->data,
  1262. "qcom,mdss-dsi-last-line-interleave");
  1263. cfg->eof_bllp_lp11_en = utils->read_bool(utils->data,
  1264. "qcom,mdss-dsi-bllp-eof-power-mode");
  1265. cfg->bllp_lp11_en = utils->read_bool(utils->data,
  1266. "qcom,mdss-dsi-bllp-power-mode");
  1267. traffic_mode = utils->get_property(utils->data,
  1268. "qcom,mdss-dsi-traffic-mode",
  1269. NULL);
  1270. if (!traffic_mode) {
  1271. DSI_DEBUG("[%s] Falling back to default traffic mode\n", name);
  1272. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  1273. } else if (!strcmp(traffic_mode, "non_burst_sync_pulse")) {
  1274. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  1275. } else if (!strcmp(traffic_mode, "non_burst_sync_event")) {
  1276. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_START_EVENTS;
  1277. } else if (!strcmp(traffic_mode, "burst_mode")) {
  1278. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_BURST_MODE;
  1279. } else {
  1280. DSI_ERR("[%s] Unrecognized traffic mode-%s\n", name,
  1281. traffic_mode);
  1282. rc = -EINVAL;
  1283. goto error;
  1284. }
  1285. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-virtual-channel-id",
  1286. &vc_id);
  1287. if (rc) {
  1288. DSI_DEBUG("[%s] Fallback to default vc id\n", name);
  1289. cfg->vc_id = 0;
  1290. } else {
  1291. cfg->vc_id = vc_id;
  1292. }
  1293. error:
  1294. return rc;
  1295. }
  1296. static int dsi_panel_parse_cmd_host_config(struct dsi_cmd_engine_cfg *cfg,
  1297. struct dsi_parser_utils *utils,
  1298. const char *name)
  1299. {
  1300. u32 val = 0;
  1301. int rc = 0;
  1302. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-wr-mem-start", &val);
  1303. if (rc) {
  1304. DSI_DEBUG("[%s] Fallback to default wr-mem-start\n", name);
  1305. cfg->wr_mem_start = 0x2C;
  1306. } else {
  1307. cfg->wr_mem_start = val;
  1308. }
  1309. val = 0;
  1310. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-wr-mem-continue",
  1311. &val);
  1312. if (rc) {
  1313. DSI_DEBUG("[%s] Fallback to default wr-mem-continue\n", name);
  1314. cfg->wr_mem_continue = 0x3C;
  1315. } else {
  1316. cfg->wr_mem_continue = val;
  1317. }
  1318. /* TODO: fix following */
  1319. cfg->max_cmd_packets_interleave = 0;
  1320. val = 0;
  1321. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-te-dcs-command",
  1322. &val);
  1323. if (rc) {
  1324. DSI_DEBUG("[%s] fallback to default te-dcs-cmd\n", name);
  1325. cfg->insert_dcs_command = true;
  1326. } else if (val == 1) {
  1327. cfg->insert_dcs_command = true;
  1328. } else if (val == 0) {
  1329. cfg->insert_dcs_command = false;
  1330. } else {
  1331. DSI_ERR("[%s] Unrecognized value for mdss-dsi-te-dcs-command\n",
  1332. name);
  1333. rc = -EINVAL;
  1334. goto error;
  1335. }
  1336. error:
  1337. return rc;
  1338. }
  1339. static int dsi_panel_parse_panel_mode(struct dsi_panel *panel)
  1340. {
  1341. int rc = 0;
  1342. struct dsi_parser_utils *utils = &panel->utils;
  1343. bool panel_mode_switch_enabled;
  1344. enum dsi_op_mode panel_mode;
  1345. const char *mode;
  1346. mode = utils->get_property(utils->data,
  1347. "qcom,mdss-dsi-panel-type", NULL);
  1348. if (!mode) {
  1349. DSI_DEBUG("[%s] Fallback to default panel mode\n", panel->name);
  1350. panel_mode = DSI_OP_VIDEO_MODE;
  1351. } else if (!strcmp(mode, "dsi_video_mode")) {
  1352. panel_mode = DSI_OP_VIDEO_MODE;
  1353. } else if (!strcmp(mode, "dsi_cmd_mode")) {
  1354. panel_mode = DSI_OP_CMD_MODE;
  1355. } else {
  1356. DSI_ERR("[%s] Unrecognized panel type-%s\n", panel->name, mode);
  1357. rc = -EINVAL;
  1358. goto error;
  1359. }
  1360. panel_mode_switch_enabled = utils->read_bool(utils->data,
  1361. "qcom,mdss-dsi-panel-mode-switch");
  1362. DSI_DEBUG("%s: panel operating mode switch feature %s\n", __func__,
  1363. (panel_mode_switch_enabled ? "enabled" : "disabled"));
  1364. if (panel_mode == DSI_OP_VIDEO_MODE || panel_mode_switch_enabled) {
  1365. rc = dsi_panel_parse_video_host_config(&panel->video_config,
  1366. utils,
  1367. panel->name);
  1368. if (rc) {
  1369. DSI_ERR("[%s] Failed to parse video host cfg, rc=%d\n",
  1370. panel->name, rc);
  1371. goto error;
  1372. }
  1373. }
  1374. if (panel_mode == DSI_OP_CMD_MODE || panel_mode_switch_enabled) {
  1375. rc = dsi_panel_parse_cmd_host_config(&panel->cmd_config,
  1376. utils,
  1377. panel->name);
  1378. if (rc) {
  1379. DSI_ERR("[%s] Failed to parse cmd host config, rc=%d\n",
  1380. panel->name, rc);
  1381. goto error;
  1382. }
  1383. }
  1384. panel->poms_align_vsync = utils->read_bool(utils->data,
  1385. "qcom,poms-align-panel-vsync");
  1386. panel->panel_mode = panel_mode;
  1387. panel->panel_mode_switch_enabled = panel_mode_switch_enabled;
  1388. error:
  1389. return rc;
  1390. }
  1391. static int dsi_panel_parse_phy_props(struct dsi_panel *panel)
  1392. {
  1393. int rc = 0;
  1394. u32 val = 0;
  1395. const char *str;
  1396. struct dsi_panel_phy_props *props = &panel->phy_props;
  1397. struct dsi_parser_utils *utils = &panel->utils;
  1398. const char *name = panel->name;
  1399. rc = utils->read_u32(utils->data,
  1400. "qcom,mdss-pan-physical-width-dimension", &val);
  1401. if (rc) {
  1402. DSI_DEBUG("[%s] Physical panel width is not defined\n", name);
  1403. props->panel_width_mm = 0;
  1404. rc = 0;
  1405. } else {
  1406. props->panel_width_mm = val;
  1407. }
  1408. rc = utils->read_u32(utils->data,
  1409. "qcom,mdss-pan-physical-height-dimension",
  1410. &val);
  1411. if (rc) {
  1412. DSI_DEBUG("[%s] Physical panel height is not defined\n", name);
  1413. props->panel_height_mm = 0;
  1414. rc = 0;
  1415. } else {
  1416. props->panel_height_mm = val;
  1417. }
  1418. str = utils->get_property(utils->data,
  1419. "qcom,mdss-dsi-panel-orientation", NULL);
  1420. if (!str) {
  1421. props->rotation = DSI_PANEL_ROTATE_NONE;
  1422. } else if (!strcmp(str, "180")) {
  1423. props->rotation = DSI_PANEL_ROTATE_HV_FLIP;
  1424. } else if (!strcmp(str, "hflip")) {
  1425. props->rotation = DSI_PANEL_ROTATE_H_FLIP;
  1426. } else if (!strcmp(str, "vflip")) {
  1427. props->rotation = DSI_PANEL_ROTATE_V_FLIP;
  1428. } else {
  1429. DSI_ERR("[%s] Unrecognized panel rotation-%s\n", name, str);
  1430. rc = -EINVAL;
  1431. goto error;
  1432. }
  1433. error:
  1434. return rc;
  1435. }
  1436. const char *cmd_set_prop_map[DSI_CMD_SET_MAX] = {
  1437. "qcom,mdss-dsi-pre-on-command",
  1438. "qcom,mdss-dsi-on-command",
  1439. "qcom,vid-on-commands",
  1440. "qcom,cmd-on-commands",
  1441. "qcom,mdss-dsi-post-panel-on-command",
  1442. "qcom,mdss-dsi-pre-off-command",
  1443. "qcom,mdss-dsi-off-command",
  1444. "qcom,mdss-dsi-post-off-command",
  1445. "qcom,mdss-dsi-pre-res-switch",
  1446. "qcom,mdss-dsi-res-switch",
  1447. "qcom,mdss-dsi-post-res-switch",
  1448. "qcom,video-mode-switch-in-commands",
  1449. "qcom,video-mode-switch-out-commands",
  1450. "qcom,cmd-mode-switch-in-commands",
  1451. "qcom,cmd-mode-switch-out-commands",
  1452. "qcom,mdss-dsi-panel-status-command",
  1453. "qcom,mdss-dsi-lp1-command",
  1454. "qcom,mdss-dsi-lp2-command",
  1455. "qcom,mdss-dsi-nolp-command",
  1456. "PPS not parsed from DTSI, generated dynamically",
  1457. "ROI not parsed from DTSI, generated dynamically",
  1458. "qcom,mdss-dsi-timing-switch-command",
  1459. "qcom,mdss-dsi-post-mode-switch-on-command",
  1460. "qcom,mdss-dsi-qsync-on-commands",
  1461. "qcom,mdss-dsi-qsync-off-commands",
  1462. };
  1463. const char *cmd_set_state_map[DSI_CMD_SET_MAX] = {
  1464. "qcom,mdss-dsi-pre-on-command-state",
  1465. "qcom,mdss-dsi-on-command-state",
  1466. "qcom,vid-on-commands-state",
  1467. "qcom,cmd-on-commands-state",
  1468. "qcom,mdss-dsi-post-on-command-state",
  1469. "qcom,mdss-dsi-pre-off-command-state",
  1470. "qcom,mdss-dsi-off-command-state",
  1471. "qcom,mdss-dsi-post-off-command-state",
  1472. "qcom,mdss-dsi-pre-res-switch-state",
  1473. "qcom,mdss-dsi-res-switch-state",
  1474. "qcom,mdss-dsi-post-res-switch-state",
  1475. "qcom,video-mode-switch-in-commands-state",
  1476. "qcom,video-mode-switch-out-commands-state",
  1477. "qcom,cmd-mode-switch-in-commands-state",
  1478. "qcom,cmd-mode-switch-out-commands-state",
  1479. "qcom,mdss-dsi-panel-status-command-state",
  1480. "qcom,mdss-dsi-lp1-command-state",
  1481. "qcom,mdss-dsi-lp2-command-state",
  1482. "qcom,mdss-dsi-nolp-command-state",
  1483. "PPS not parsed from DTSI, generated dynamically",
  1484. "ROI not parsed from DTSI, generated dynamically",
  1485. "qcom,mdss-dsi-timing-switch-command-state",
  1486. "qcom,mdss-dsi-post-mode-switch-on-command-state",
  1487. "qcom,mdss-dsi-qsync-on-commands-state",
  1488. "qcom,mdss-dsi-qsync-off-commands-state",
  1489. };
  1490. int dsi_panel_get_cmd_pkt_count(const char *data, u32 length, u32 *cnt)
  1491. {
  1492. const u32 cmd_set_min_size = 7;
  1493. u32 count = 0;
  1494. u32 packet_length;
  1495. u32 tmp;
  1496. while (length >= cmd_set_min_size) {
  1497. packet_length = cmd_set_min_size;
  1498. tmp = ((data[5] << 8) | (data[6]));
  1499. packet_length += tmp;
  1500. if (packet_length > length) {
  1501. DSI_ERR("format error\n");
  1502. return -EINVAL;
  1503. }
  1504. length -= packet_length;
  1505. data += packet_length;
  1506. count++;
  1507. }
  1508. *cnt = count;
  1509. return 0;
  1510. }
  1511. int dsi_panel_create_cmd_packets(const char *data,
  1512. u32 length,
  1513. u32 count,
  1514. struct dsi_cmd_desc *cmd)
  1515. {
  1516. int rc = 0;
  1517. int i, j;
  1518. u8 *payload;
  1519. for (i = 0; i < count; i++) {
  1520. u32 size;
  1521. cmd[i].msg.type = data[0];
  1522. cmd[i].msg.channel = data[2];
  1523. cmd[i].msg.flags |= data[3];
  1524. cmd[i].ctrl = 0;
  1525. cmd[i].post_wait_ms = data[4];
  1526. cmd[i].msg.tx_len = ((data[5] << 8) | (data[6]));
  1527. if (cmd[i].msg.flags & MIPI_DSI_MSG_BATCH_COMMAND)
  1528. cmd[i].last_command = false;
  1529. else
  1530. cmd[i].last_command = true;
  1531. size = cmd[i].msg.tx_len * sizeof(u8);
  1532. payload = kzalloc(size, GFP_KERNEL);
  1533. if (!payload) {
  1534. rc = -ENOMEM;
  1535. goto error_free_payloads;
  1536. }
  1537. for (j = 0; j < cmd[i].msg.tx_len; j++)
  1538. payload[j] = data[7 + j];
  1539. cmd[i].msg.tx_buf = payload;
  1540. data += (7 + cmd[i].msg.tx_len);
  1541. }
  1542. return rc;
  1543. error_free_payloads:
  1544. for (i = i - 1; i >= 0; i--) {
  1545. cmd--;
  1546. kfree(cmd->msg.tx_buf);
  1547. }
  1548. return rc;
  1549. }
  1550. void dsi_panel_destroy_cmd_packets(struct dsi_panel_cmd_set *set)
  1551. {
  1552. u32 i = 0;
  1553. struct dsi_cmd_desc *cmd;
  1554. for (i = 0; i < set->count; i++) {
  1555. cmd = &set->cmds[i];
  1556. kfree(cmd->msg.tx_buf);
  1557. }
  1558. }
  1559. void dsi_panel_dealloc_cmd_packets(struct dsi_panel_cmd_set *set)
  1560. {
  1561. kfree(set->cmds);
  1562. }
  1563. int dsi_panel_alloc_cmd_packets(struct dsi_panel_cmd_set *cmd,
  1564. u32 packet_count)
  1565. {
  1566. u32 size;
  1567. size = packet_count * sizeof(*cmd->cmds);
  1568. cmd->cmds = kzalloc(size, GFP_KERNEL);
  1569. if (!cmd->cmds)
  1570. return -ENOMEM;
  1571. cmd->count = packet_count;
  1572. return 0;
  1573. }
  1574. static int dsi_panel_parse_cmd_sets_sub(struct dsi_panel_cmd_set *cmd,
  1575. enum dsi_cmd_set_type type,
  1576. struct dsi_parser_utils *utils)
  1577. {
  1578. int rc = 0;
  1579. u32 length = 0;
  1580. const char *data;
  1581. const char *state;
  1582. u32 packet_count = 0;
  1583. data = utils->get_property(utils->data, cmd_set_prop_map[type],
  1584. &length);
  1585. if (!data) {
  1586. DSI_DEBUG("%s commands not defined\n", cmd_set_prop_map[type]);
  1587. rc = -ENOTSUPP;
  1588. goto error;
  1589. }
  1590. DSI_DEBUG("type=%d, name=%s, length=%d\n", type, cmd_set_prop_map[type], length);
  1591. print_hex_dump_debug("", DUMP_PREFIX_NONE, 8, 1, data, length, false);
  1592. rc = dsi_panel_get_cmd_pkt_count(data, length, &packet_count);
  1593. if (rc) {
  1594. DSI_ERR("commands failed, rc=%d\n", rc);
  1595. goto error;
  1596. }
  1597. DSI_DEBUG("[%s] packet-count=%d, %d\n", cmd_set_prop_map[type],
  1598. packet_count, length);
  1599. rc = dsi_panel_alloc_cmd_packets(cmd, packet_count);
  1600. if (rc) {
  1601. DSI_ERR("failed to allocate cmd packets, rc=%d\n", rc);
  1602. goto error;
  1603. }
  1604. rc = dsi_panel_create_cmd_packets(data, length, packet_count,
  1605. cmd->cmds);
  1606. if (rc) {
  1607. DSI_ERR("failed to create cmd packets, rc=%d\n", rc);
  1608. goto error_free_mem;
  1609. }
  1610. state = utils->get_property(utils->data, cmd_set_state_map[type], NULL);
  1611. if (!state || !strcmp(state, "dsi_lp_mode")) {
  1612. cmd->state = DSI_CMD_SET_STATE_LP;
  1613. } else if (!strcmp(state, "dsi_hs_mode")) {
  1614. cmd->state = DSI_CMD_SET_STATE_HS;
  1615. } else {
  1616. DSI_ERR("[%s] command state unrecognized-%s\n",
  1617. cmd_set_state_map[type], state);
  1618. goto error_free_mem;
  1619. }
  1620. return rc;
  1621. error_free_mem:
  1622. kfree(cmd->cmds);
  1623. cmd->cmds = NULL;
  1624. error:
  1625. return rc;
  1626. }
  1627. static int dsi_panel_parse_cmd_sets(
  1628. struct dsi_display_mode_priv_info *priv_info,
  1629. struct dsi_parser_utils *utils)
  1630. {
  1631. int rc = 0;
  1632. struct dsi_panel_cmd_set *set;
  1633. u32 i;
  1634. if (!priv_info) {
  1635. DSI_ERR("invalid mode priv info\n");
  1636. return -EINVAL;
  1637. }
  1638. for (i = DSI_CMD_SET_PRE_ON; i < DSI_CMD_SET_MAX; i++) {
  1639. set = &priv_info->cmd_sets[i];
  1640. set->type = i;
  1641. set->count = 0;
  1642. if (i == DSI_CMD_SET_PPS) {
  1643. rc = dsi_panel_alloc_cmd_packets(set, 1);
  1644. if (rc)
  1645. DSI_ERR("failed to allocate cmd set %d, rc = %d\n",
  1646. i, rc);
  1647. set->state = DSI_CMD_SET_STATE_LP;
  1648. } else {
  1649. rc = dsi_panel_parse_cmd_sets_sub(set, i, utils);
  1650. if (rc)
  1651. DSI_DEBUG("failed to parse set %d\n", i);
  1652. }
  1653. }
  1654. rc = 0;
  1655. return rc;
  1656. }
  1657. static int dsi_panel_parse_reset_sequence(struct dsi_panel *panel)
  1658. {
  1659. int rc = 0;
  1660. int i;
  1661. u32 length = 0;
  1662. u32 count = 0;
  1663. u32 size = 0;
  1664. u32 *arr_32 = NULL;
  1665. const u32 *arr;
  1666. struct dsi_parser_utils *utils = &panel->utils;
  1667. struct dsi_reset_seq *seq;
  1668. if (panel->host_config.ext_bridge_mode)
  1669. return 0;
  1670. arr = utils->get_property(utils->data,
  1671. "qcom,mdss-dsi-reset-sequence", &length);
  1672. if (!arr) {
  1673. DSI_ERR("[%s] dsi-reset-sequence not found\n", panel->name);
  1674. rc = -EINVAL;
  1675. goto error;
  1676. }
  1677. if (length & 0x1) {
  1678. DSI_ERR("[%s] syntax error for dsi-reset-sequence\n",
  1679. panel->name);
  1680. rc = -EINVAL;
  1681. goto error;
  1682. }
  1683. DSI_DEBUG("RESET SEQ LENGTH = %d\n", length);
  1684. length = length / sizeof(u32);
  1685. size = length * sizeof(u32);
  1686. arr_32 = kzalloc(size, GFP_KERNEL);
  1687. if (!arr_32) {
  1688. rc = -ENOMEM;
  1689. goto error;
  1690. }
  1691. rc = utils->read_u32_array(utils->data, "qcom,mdss-dsi-reset-sequence",
  1692. arr_32, length);
  1693. if (rc) {
  1694. DSI_ERR("[%s] cannot read dso-reset-seqience\n", panel->name);
  1695. goto error_free_arr_32;
  1696. }
  1697. count = length / 2;
  1698. size = count * sizeof(*seq);
  1699. seq = kzalloc(size, GFP_KERNEL);
  1700. if (!seq) {
  1701. rc = -ENOMEM;
  1702. goto error_free_arr_32;
  1703. }
  1704. panel->reset_config.sequence = seq;
  1705. panel->reset_config.count = count;
  1706. for (i = 0; i < length; i += 2) {
  1707. seq->level = arr_32[i];
  1708. seq->sleep_ms = arr_32[i + 1];
  1709. seq++;
  1710. }
  1711. error_free_arr_32:
  1712. kfree(arr_32);
  1713. error:
  1714. return rc;
  1715. }
  1716. static int dsi_panel_parse_misc_features(struct dsi_panel *panel)
  1717. {
  1718. struct dsi_parser_utils *utils = &panel->utils;
  1719. const char *string;
  1720. int i, rc = 0;
  1721. panel->ulps_feature_enabled =
  1722. utils->read_bool(utils->data, "qcom,ulps-enabled");
  1723. DSI_DEBUG("%s: ulps feature %s\n", __func__,
  1724. (panel->ulps_feature_enabled ? "enabled" : "disabled"));
  1725. panel->ulps_suspend_enabled =
  1726. utils->read_bool(utils->data, "qcom,suspend-ulps-enabled");
  1727. DSI_DEBUG("%s: ulps during suspend feature %s\n", __func__,
  1728. (panel->ulps_suspend_enabled ? "enabled" : "disabled"));
  1729. panel->te_using_watchdog_timer = utils->read_bool(utils->data,
  1730. "qcom,mdss-dsi-te-using-wd");
  1731. panel->sync_broadcast_en = utils->read_bool(utils->data,
  1732. "qcom,cmd-sync-wait-broadcast");
  1733. panel->lp11_init = utils->read_bool(utils->data,
  1734. "qcom,mdss-dsi-lp11-init");
  1735. panel->reset_gpio_always_on = utils->read_bool(utils->data,
  1736. "qcom,platform-reset-gpio-always-on");
  1737. panel->spr_info.enable = false;
  1738. panel->spr_info.pack_type = MSM_DISPLAY_SPR_TYPE_MAX;
  1739. rc = utils->read_string(utils->data, "qcom,spr-pack-type", &string);
  1740. if (!rc) {
  1741. // find match for pack-type string
  1742. for (i = 0; i < MSM_DISPLAY_SPR_TYPE_MAX; i++) {
  1743. if (msm_spr_pack_type_str[i] &&
  1744. (!strcmp(string, msm_spr_pack_type_str[i]))) {
  1745. panel->spr_info.enable = true;
  1746. panel->spr_info.pack_type = i;
  1747. break;
  1748. }
  1749. }
  1750. }
  1751. pr_debug("%s source side spr packing, pack-type %s\n",
  1752. panel->spr_info.enable ? "enable" : "disable",
  1753. panel->spr_info.enable ?
  1754. msm_spr_pack_type_str[panel->spr_info.pack_type] : "none");
  1755. return 0;
  1756. }
  1757. static int dsi_panel_parse_jitter_config(
  1758. struct dsi_display_mode *mode,
  1759. struct dsi_parser_utils *utils)
  1760. {
  1761. int rc;
  1762. struct dsi_display_mode_priv_info *priv_info;
  1763. u32 jitter[DEFAULT_PANEL_JITTER_ARRAY_SIZE] = {0, 0};
  1764. u64 jitter_val = 0;
  1765. priv_info = mode->priv_info;
  1766. rc = utils->read_u32_array(utils->data, "qcom,mdss-dsi-panel-jitter",
  1767. jitter, DEFAULT_PANEL_JITTER_ARRAY_SIZE);
  1768. if (rc) {
  1769. DSI_DEBUG("panel jitter not defined rc=%d\n", rc);
  1770. } else {
  1771. jitter_val = jitter[0];
  1772. jitter_val = div_u64(jitter_val, jitter[1]);
  1773. }
  1774. if (rc || !jitter_val || (jitter_val > MAX_PANEL_JITTER)) {
  1775. priv_info->panel_jitter_numer = DEFAULT_PANEL_JITTER_NUMERATOR;
  1776. priv_info->panel_jitter_denom =
  1777. DEFAULT_PANEL_JITTER_DENOMINATOR;
  1778. } else {
  1779. priv_info->panel_jitter_numer = jitter[0];
  1780. priv_info->panel_jitter_denom = jitter[1];
  1781. }
  1782. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-panel-prefill-lines",
  1783. &priv_info->panel_prefill_lines);
  1784. if (rc) {
  1785. DSI_DEBUG("panel prefill lines are not defined rc=%d\n", rc);
  1786. priv_info->panel_prefill_lines = mode->timing.v_back_porch +
  1787. mode->timing.v_sync_width + mode->timing.v_front_porch;
  1788. } else if (priv_info->panel_prefill_lines >=
  1789. DSI_V_TOTAL(&mode->timing)) {
  1790. DSI_DEBUG("invalid prefill lines config=%d setting to:%d\n",
  1791. priv_info->panel_prefill_lines, DEFAULT_PANEL_PREFILL_LINES);
  1792. priv_info->panel_prefill_lines = DEFAULT_PANEL_PREFILL_LINES;
  1793. }
  1794. return 0;
  1795. }
  1796. static int dsi_panel_parse_power_cfg(struct dsi_panel *panel)
  1797. {
  1798. int rc = 0;
  1799. char *supply_name;
  1800. if (panel->host_config.ext_bridge_mode)
  1801. return 0;
  1802. if (!strcmp(panel->type, "primary"))
  1803. supply_name = "qcom,panel-supply-entries";
  1804. else
  1805. supply_name = "qcom,panel-sec-supply-entries";
  1806. rc = dsi_pwr_of_get_vreg_data(&panel->utils,
  1807. &panel->power_info, supply_name);
  1808. if (rc) {
  1809. DSI_ERR("[%s] failed to parse vregs\n", panel->name);
  1810. goto error;
  1811. }
  1812. error:
  1813. return rc;
  1814. }
  1815. int dsi_panel_get_io_resources(struct dsi_panel *panel,
  1816. struct msm_io_res *io_res)
  1817. {
  1818. struct list_head temp_head;
  1819. struct msm_io_mem_entry *io_mem, *pos, *tmp;
  1820. struct list_head *mem_list = &io_res->mem;
  1821. int i, rc = 0;
  1822. INIT_LIST_HEAD(&temp_head);
  1823. for (i = 0; i < panel->tlmm_gpio_count; i++) {
  1824. io_mem = kzalloc(sizeof(*io_mem), GFP_KERNEL);
  1825. if (!io_mem) {
  1826. rc = -ENOMEM;
  1827. goto parse_fail;
  1828. }
  1829. io_mem->base = panel->tlmm_gpio[i].addr;
  1830. io_mem->size = panel->tlmm_gpio[i].size;
  1831. list_add(&io_mem->list, &temp_head);
  1832. }
  1833. list_splice(&temp_head, mem_list);
  1834. goto end;
  1835. parse_fail:
  1836. list_for_each_entry_safe(pos, tmp, &temp_head, list) {
  1837. list_del(&pos->list);
  1838. kfree(pos);
  1839. }
  1840. end:
  1841. return rc;
  1842. }
  1843. static int dsi_panel_parse_gpios(struct dsi_panel *panel)
  1844. {
  1845. int rc = 0;
  1846. const char *data;
  1847. struct dsi_parser_utils *utils = &panel->utils;
  1848. char *reset_gpio_name, *mode_set_gpio_name;
  1849. if (!strcmp(panel->type, "primary")) {
  1850. reset_gpio_name = "qcom,platform-reset-gpio";
  1851. mode_set_gpio_name = "qcom,panel-mode-gpio";
  1852. } else {
  1853. reset_gpio_name = "qcom,platform-sec-reset-gpio";
  1854. mode_set_gpio_name = "qcom,panel-sec-mode-gpio";
  1855. }
  1856. panel->reset_config.reset_gpio = utils->get_named_gpio(utils->data,
  1857. reset_gpio_name, 0);
  1858. if (!gpio_is_valid(panel->reset_config.reset_gpio) &&
  1859. !panel->host_config.ext_bridge_mode) {
  1860. rc = panel->reset_config.reset_gpio;
  1861. DSI_ERR("[%s] failed get reset gpio, rc=%d\n", panel->name, rc);
  1862. goto error;
  1863. }
  1864. panel->reset_config.disp_en_gpio = utils->get_named_gpio(utils->data,
  1865. "qcom,5v-boost-gpio",
  1866. 0);
  1867. if (!gpio_is_valid(panel->reset_config.disp_en_gpio)) {
  1868. DSI_DEBUG("[%s] 5v-boot-gpio is not set, rc=%d\n",
  1869. panel->name, rc);
  1870. panel->reset_config.disp_en_gpio =
  1871. utils->get_named_gpio(utils->data,
  1872. "qcom,platform-en-gpio", 0);
  1873. if (!gpio_is_valid(panel->reset_config.disp_en_gpio)) {
  1874. DSI_DEBUG("[%s] platform-en-gpio is not set, rc=%d\n",
  1875. panel->name, rc);
  1876. }
  1877. }
  1878. panel->reset_config.lcd_mode_sel_gpio = utils->get_named_gpio(
  1879. utils->data, mode_set_gpio_name, 0);
  1880. if (!gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio))
  1881. DSI_DEBUG("mode gpio not specified\n");
  1882. DSI_DEBUG("mode gpio=%d\n", panel->reset_config.lcd_mode_sel_gpio);
  1883. data = utils->get_property(utils->data,
  1884. "qcom,mdss-dsi-mode-sel-gpio-state", NULL);
  1885. if (data) {
  1886. if (!strcmp(data, "single_port"))
  1887. panel->reset_config.mode_sel_state =
  1888. MODE_SEL_SINGLE_PORT;
  1889. else if (!strcmp(data, "dual_port"))
  1890. panel->reset_config.mode_sel_state =
  1891. MODE_SEL_DUAL_PORT;
  1892. else if (!strcmp(data, "high"))
  1893. panel->reset_config.mode_sel_state =
  1894. MODE_GPIO_HIGH;
  1895. else if (!strcmp(data, "low"))
  1896. panel->reset_config.mode_sel_state =
  1897. MODE_GPIO_LOW;
  1898. } else {
  1899. /* Set default mode as SPLIT mode */
  1900. panel->reset_config.mode_sel_state = MODE_SEL_DUAL_PORT;
  1901. }
  1902. /* TODO: release memory */
  1903. rc = dsi_panel_parse_reset_sequence(panel);
  1904. if (rc) {
  1905. DSI_ERR("[%s] failed to parse reset sequence, rc=%d\n",
  1906. panel->name, rc);
  1907. goto error;
  1908. }
  1909. panel->panel_test_gpio = utils->get_named_gpio(utils->data,
  1910. "qcom,mdss-dsi-panel-test-pin",
  1911. 0);
  1912. if (!gpio_is_valid(panel->panel_test_gpio))
  1913. DSI_DEBUG("%s:%d panel test gpio not specified\n", __func__,
  1914. __LINE__);
  1915. error:
  1916. return rc;
  1917. }
  1918. static int dsi_panel_parse_tlmm_gpio(struct dsi_panel *panel)
  1919. {
  1920. struct dsi_parser_utils *utils = &panel->utils;
  1921. u32 base, size, pin;
  1922. int pin_count, address_count, name_count, i;
  1923. address_count = of_property_count_u32_elems(utils->data,
  1924. "qcom,dsi-panel-gpio-address");
  1925. if (address_count != 2) {
  1926. DSI_DEBUG("panel gpio address not defined\n");
  1927. return 0;
  1928. }
  1929. of_property_read_u32_index(utils->data,
  1930. "qcom,dsi-panel-gpio-address", 0, &base);
  1931. of_property_read_u32_index(utils->data,
  1932. "qcom,dsi-panel-gpio-address", 1, &size);
  1933. pin_count = of_property_count_u32_elems(utils->data,
  1934. "qcom,dsi-panel-gpio-pins");
  1935. name_count = of_property_count_strings(utils->data,
  1936. "qcom,dsi-panel-gpio-names");
  1937. if ((pin_count < 0) || (name_count < 0) || (pin_count != name_count)) {
  1938. DSI_ERR("invalid gpio pins/names\n");
  1939. return -EINVAL;
  1940. }
  1941. panel->tlmm_gpio = kcalloc(pin_count,
  1942. sizeof(struct dsi_tlmm_gpio), GFP_KERNEL);
  1943. if (!panel->tlmm_gpio)
  1944. return -ENOMEM;
  1945. panel->tlmm_gpio_count = pin_count;
  1946. for (i = 0; i < pin_count; i++) {
  1947. of_property_read_u32_index(utils->data,
  1948. "qcom,dsi-panel-gpio-pins", i, &pin);
  1949. panel->tlmm_gpio[i].num = pin;
  1950. panel->tlmm_gpio[i].addr = base + (pin * size);
  1951. panel->tlmm_gpio[i].size = size;
  1952. of_property_read_string_index(utils->data,
  1953. "qcom,dsi-panel-gpio-names", i,
  1954. &(panel->tlmm_gpio[i].name));
  1955. }
  1956. return 0;
  1957. }
  1958. static int dsi_panel_parse_bl_pwm_config(struct dsi_panel *panel)
  1959. {
  1960. int rc = 0;
  1961. u32 val;
  1962. struct dsi_backlight_config *config = &panel->bl_config;
  1963. struct dsi_parser_utils *utils = &panel->utils;
  1964. rc = utils->read_u32(utils->data, "qcom,bl-pmic-pwm-period-usecs",
  1965. &val);
  1966. if (rc) {
  1967. DSI_ERR("bl-pmic-pwm-period-usecs is not defined, rc=%d\n", rc);
  1968. goto error;
  1969. }
  1970. config->pwm_period_usecs = val;
  1971. error:
  1972. return rc;
  1973. }
  1974. static int dsi_panel_parse_bl_config(struct dsi_panel *panel)
  1975. {
  1976. int rc = 0;
  1977. u32 val = 0;
  1978. const char *bl_type = NULL;
  1979. const char *data = NULL;
  1980. const char *state = NULL;
  1981. struct dsi_parser_utils *utils = &panel->utils;
  1982. char *bl_name = NULL;
  1983. if (!strcmp(panel->type, "primary"))
  1984. bl_name = "qcom,mdss-dsi-bl-pmic-control-type";
  1985. else
  1986. bl_name = "qcom,mdss-dsi-sec-bl-pmic-control-type";
  1987. bl_type = utils->get_property(utils->data, bl_name, NULL);
  1988. if (!bl_type) {
  1989. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  1990. } else if (!strcmp(bl_type, "bl_ctrl_pwm")) {
  1991. panel->bl_config.type = DSI_BACKLIGHT_PWM;
  1992. } else if (!strcmp(bl_type, "bl_ctrl_wled")) {
  1993. panel->bl_config.type = DSI_BACKLIGHT_WLED;
  1994. } else if (!strcmp(bl_type, "bl_ctrl_dcs")) {
  1995. panel->bl_config.type = DSI_BACKLIGHT_DCS;
  1996. } else if (!strcmp(bl_type, "bl_ctrl_external")) {
  1997. panel->bl_config.type = DSI_BACKLIGHT_EXTERNAL;
  1998. } else {
  1999. DSI_DEBUG("[%s] bl-pmic-control-type unknown-%s\n",
  2000. panel->name, bl_type);
  2001. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  2002. }
  2003. data = utils->get_property(utils->data, "qcom,bl-update-flag", NULL);
  2004. if (!data) {
  2005. panel->bl_config.bl_update = BL_UPDATE_NONE;
  2006. } else if (!strcmp(data, "delay_until_first_frame")) {
  2007. panel->bl_config.bl_update = BL_UPDATE_DELAY_UNTIL_FIRST_FRAME;
  2008. } else {
  2009. DSI_DEBUG("[%s] No valid bl-update-flag: %s\n",
  2010. panel->name, data);
  2011. panel->bl_config.bl_update = BL_UPDATE_NONE;
  2012. }
  2013. panel->bl_config.bl_scale = MAX_BL_SCALE_LEVEL;
  2014. panel->bl_config.bl_scale_sv = MAX_SV_BL_SCALE_LEVEL;
  2015. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-bl-min-level", &val);
  2016. if (rc) {
  2017. DSI_DEBUG("[%s] bl-min-level unspecified, defaulting to zero\n",
  2018. panel->name);
  2019. panel->bl_config.bl_min_level = 0;
  2020. } else {
  2021. panel->bl_config.bl_min_level = val;
  2022. }
  2023. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-bl-max-level", &val);
  2024. if (rc) {
  2025. DSI_DEBUG("[%s] bl-max-level unspecified, defaulting to max level\n",
  2026. panel->name);
  2027. panel->bl_config.bl_max_level = MAX_BL_LEVEL;
  2028. } else {
  2029. panel->bl_config.bl_max_level = val;
  2030. }
  2031. rc = utils->read_u32(utils->data, "qcom,mdss-brightness-max-level",
  2032. &val);
  2033. if (rc) {
  2034. DSI_DEBUG("[%s] brigheness-max-level unspecified, defaulting to 255\n",
  2035. panel->name);
  2036. panel->bl_config.brightness_max_level = 255;
  2037. rc = 0;
  2038. } else {
  2039. panel->bl_config.brightness_max_level = val;
  2040. }
  2041. panel->bl_config.bl_inverted_dbv = utils->read_bool(utils->data,
  2042. "qcom,mdss-dsi-bl-inverted-dbv");
  2043. state = utils->get_property(utils->data, "qcom,bl-dsc-cmd-state", NULL);
  2044. if (!state || !strcmp(state, "dsi_hs_mode"))
  2045. panel->bl_config.lp_mode = false;
  2046. else if (!strcmp(state, "dsi_lp_mode"))
  2047. panel->bl_config.lp_mode = true;
  2048. else
  2049. DSI_ERR("bl-dsc-cmd-state command state unrecognized-%s\n",
  2050. state);
  2051. if (panel->bl_config.type == DSI_BACKLIGHT_PWM) {
  2052. rc = dsi_panel_parse_bl_pwm_config(panel);
  2053. if (rc) {
  2054. DSI_ERR("[%s] failed to parse pwm config, rc=%d\n",
  2055. panel->name, rc);
  2056. goto error;
  2057. }
  2058. }
  2059. panel->bl_config.en_gpio = utils->get_named_gpio(utils->data,
  2060. "qcom,platform-bklight-en-gpio",
  2061. 0);
  2062. if (!gpio_is_valid(panel->bl_config.en_gpio)) {
  2063. if (panel->bl_config.en_gpio == -EPROBE_DEFER) {
  2064. DSI_DEBUG("[%s] failed to get bklt gpio, rc=%d\n",
  2065. panel->name, rc);
  2066. rc = -EPROBE_DEFER;
  2067. goto error;
  2068. } else {
  2069. DSI_DEBUG("[%s] failed to get bklt gpio, rc=%d\n",
  2070. panel->name, rc);
  2071. rc = 0;
  2072. goto error;
  2073. }
  2074. }
  2075. error:
  2076. return rc;
  2077. }
  2078. static int dsi_panel_parse_phy_timing(struct dsi_display_mode *mode,
  2079. struct dsi_parser_utils *utils)
  2080. {
  2081. const char *data;
  2082. u32 len, i;
  2083. int rc = 0;
  2084. struct dsi_display_mode_priv_info *priv_info;
  2085. u64 pixel_clk_khz;
  2086. if (!mode || !mode->priv_info)
  2087. return -EINVAL;
  2088. priv_info = mode->priv_info;
  2089. data = utils->get_property(utils->data,
  2090. "qcom,mdss-dsi-panel-phy-timings", &len);
  2091. if (!data) {
  2092. DSI_DEBUG("Unable to read Phy timing settings\n");
  2093. } else {
  2094. priv_info->phy_timing_val =
  2095. kzalloc((sizeof(u32) * len), GFP_KERNEL);
  2096. if (!priv_info->phy_timing_val)
  2097. return -EINVAL;
  2098. for (i = 0; i < len; i++)
  2099. priv_info->phy_timing_val[i] = data[i];
  2100. priv_info->phy_timing_len = len;
  2101. }
  2102. if (mode->panel_mode_caps & DSI_OP_VIDEO_MODE) {
  2103. /*
  2104. * For command mode we update the pclk as part of
  2105. * function dsi_panel_calc_dsi_transfer_time( )
  2106. * as we set it based on dsi clock or mdp transfer time.
  2107. */
  2108. pixel_clk_khz = (dsi_h_total_dce(&mode->timing) *
  2109. DSI_V_TOTAL(&mode->timing) *
  2110. mode->timing.refresh_rate);
  2111. do_div(pixel_clk_khz, 1000);
  2112. mode->pixel_clk_khz = pixel_clk_khz;
  2113. }
  2114. return rc;
  2115. }
  2116. static int dsi_panel_parse_dsc_params(struct dsi_display_mode *mode,
  2117. struct dsi_parser_utils *utils)
  2118. {
  2119. u32 data;
  2120. int rc = -EINVAL;
  2121. int intf_width;
  2122. const char *compression;
  2123. struct dsi_display_mode_priv_info *priv_info;
  2124. if (!mode || !mode->priv_info)
  2125. return -EINVAL;
  2126. priv_info = mode->priv_info;
  2127. priv_info->dsc_enabled = false;
  2128. compression = utils->get_property(utils->data,
  2129. "qcom,compression-mode", NULL);
  2130. if (compression && !strcmp(compression, "dsc"))
  2131. priv_info->dsc_enabled = true;
  2132. if (!priv_info->dsc_enabled) {
  2133. DSI_DEBUG("dsc compression is not enabled for the mode\n");
  2134. return 0;
  2135. }
  2136. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-version", &data);
  2137. if (rc) {
  2138. priv_info->dsc.config.dsc_version_major = 0x1;
  2139. priv_info->dsc.config.dsc_version_minor = 0x1;
  2140. rc = 0;
  2141. } else {
  2142. /* BITS[0..3] provides minor version and BITS[4..7] provide
  2143. * major version information
  2144. */
  2145. priv_info->dsc.config.dsc_version_major = (data >> 4) & 0x0F;
  2146. priv_info->dsc.config.dsc_version_minor = data & 0x0F;
  2147. if ((priv_info->dsc.config.dsc_version_major != 0x1) ||
  2148. ((priv_info->dsc.config.dsc_version_minor
  2149. != 0x1) &&
  2150. (priv_info->dsc.config.dsc_version_minor
  2151. != 0x2))) {
  2152. DSI_ERR("%s:unsupported major:%d minor:%d version\n",
  2153. __func__,
  2154. priv_info->dsc.config.dsc_version_major,
  2155. priv_info->dsc.config.dsc_version_minor
  2156. );
  2157. rc = -EINVAL;
  2158. goto error;
  2159. }
  2160. }
  2161. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-scr-version", &data);
  2162. if (rc) {
  2163. priv_info->dsc.scr_rev = 0x0;
  2164. rc = 0;
  2165. } else {
  2166. priv_info->dsc.scr_rev = data & 0xff;
  2167. /* only one scr rev supported */
  2168. if (priv_info->dsc.scr_rev > 0x1) {
  2169. DSI_ERR("%s: DSC scr version:%d not supported\n",
  2170. __func__, priv_info->dsc.scr_rev);
  2171. rc = -EINVAL;
  2172. goto error;
  2173. }
  2174. }
  2175. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-slice-height", &data);
  2176. if (rc) {
  2177. DSI_ERR("failed to parse qcom,mdss-dsc-slice-height\n");
  2178. goto error;
  2179. }
  2180. priv_info->dsc.config.slice_height = data;
  2181. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-slice-width", &data);
  2182. if (rc) {
  2183. DSI_ERR("failed to parse qcom,mdss-dsc-slice-width\n");
  2184. goto error;
  2185. }
  2186. priv_info->dsc.config.slice_width = data;
  2187. intf_width = mode->timing.h_active;
  2188. if (intf_width % priv_info->dsc.config.slice_width) {
  2189. DSI_ERR("invalid slice width for the intf width:%d slice width:%d\n",
  2190. intf_width, priv_info->dsc.config.slice_width);
  2191. rc = -EINVAL;
  2192. goto error;
  2193. }
  2194. priv_info->dsc.config.pic_width = mode->timing.h_active;
  2195. priv_info->dsc.config.pic_height = mode->timing.v_active;
  2196. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-slice-per-pkt", &data);
  2197. if (rc) {
  2198. DSI_ERR("failed to parse qcom,mdss-dsc-slice-per-pkt\n");
  2199. goto error;
  2200. } else if (!data || (data > 2)) {
  2201. DSI_ERR("invalid dsc slice-per-pkt:%d\n", data);
  2202. goto error;
  2203. }
  2204. priv_info->dsc.slice_per_pkt = data;
  2205. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-bit-per-component",
  2206. &data);
  2207. if (rc) {
  2208. DSI_ERR("failed to parse qcom,mdss-dsc-bit-per-component\n");
  2209. goto error;
  2210. }
  2211. priv_info->dsc.config.bits_per_component = data;
  2212. rc = utils->read_u32(utils->data, "qcom,mdss-pps-delay-ms", &data);
  2213. if (rc) {
  2214. DSI_DEBUG("pps-delay-ms not specified, defaulting to 0\n");
  2215. data = 0;
  2216. }
  2217. priv_info->dsc.pps_delay_ms = data;
  2218. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-bit-per-pixel",
  2219. &data);
  2220. if (rc) {
  2221. DSI_ERR("failed to parse qcom,mdss-dsc-bit-per-pixel\n");
  2222. goto error;
  2223. }
  2224. priv_info->dsc.config.bits_per_pixel = data << 4;
  2225. rc = utils->read_u32(utils->data, "qcom,src-chroma-format",
  2226. &data);
  2227. if (rc) {
  2228. DSI_DEBUG("failed to parse qcom,src-chroma-format\n");
  2229. rc = 0;
  2230. data = MSM_CHROMA_444;
  2231. }
  2232. priv_info->dsc.chroma_format = data;
  2233. rc = utils->read_u32(utils->data, "qcom,src-color-space",
  2234. &data);
  2235. if (rc) {
  2236. DSI_DEBUG("failed to parse qcom,src-color-space\n");
  2237. rc = 0;
  2238. data = MSM_RGB;
  2239. }
  2240. priv_info->dsc.source_color_space = data;
  2241. priv_info->dsc.config.block_pred_enable = utils->read_bool(utils->data,
  2242. "qcom,mdss-dsc-block-prediction-enable");
  2243. priv_info->dsc.config.slice_count = DIV_ROUND_UP(intf_width,
  2244. priv_info->dsc.config.slice_width);
  2245. rc = sde_dsc_populate_dsc_config(&priv_info->dsc.config,
  2246. priv_info->dsc.scr_rev);
  2247. if (rc) {
  2248. DSI_DEBUG("failed populating dsc params\n");
  2249. rc = -EINVAL;
  2250. goto error;
  2251. }
  2252. rc = sde_dsc_populate_dsc_private_params(&priv_info->dsc, intf_width);
  2253. if (rc) {
  2254. DSI_DEBUG("failed populating other dsc params\n");
  2255. rc = -EINVAL;
  2256. goto error;
  2257. }
  2258. priv_info->pclk_scale.numer =
  2259. priv_info->dsc.config.bits_per_pixel >> 4;
  2260. priv_info->pclk_scale.denom = msm_get_src_bpc(
  2261. priv_info->dsc.chroma_format,
  2262. priv_info->dsc.config.bits_per_component);
  2263. mode->timing.dsc_enabled = true;
  2264. mode->timing.dsc = &priv_info->dsc;
  2265. mode->timing.pclk_scale = priv_info->pclk_scale;
  2266. error:
  2267. return rc;
  2268. }
  2269. static int dsi_panel_parse_vdc_params(struct dsi_display_mode *mode,
  2270. struct dsi_parser_utils *utils, int traffic_mode)
  2271. {
  2272. u32 data;
  2273. int rc = -EINVAL;
  2274. const char *compression;
  2275. struct dsi_display_mode_priv_info *priv_info;
  2276. int intf_width;
  2277. if (!mode || !mode->priv_info)
  2278. return -EINVAL;
  2279. priv_info = mode->priv_info;
  2280. priv_info->vdc_enabled = false;
  2281. compression = utils->get_property(utils->data,
  2282. "qcom,compression-mode", NULL);
  2283. if (compression && !strcmp(compression, "vdc"))
  2284. priv_info->vdc_enabled = true;
  2285. if (!priv_info->vdc_enabled) {
  2286. DSI_DEBUG("vdc compression is not enabled for the mode\n");
  2287. return 0;
  2288. }
  2289. priv_info->vdc.traffic_mode = traffic_mode;
  2290. rc = utils->read_u32(utils->data, "qcom,vdc-version", &data);
  2291. if (rc) {
  2292. priv_info->vdc.version_major = 0x1;
  2293. priv_info->vdc.version_minor = 0x2;
  2294. priv_info->vdc.version_release = 0x0;
  2295. rc = 0;
  2296. } else {
  2297. /* BITS[0..3] provides minor version and BITS[4..7] provide
  2298. * major version information
  2299. */
  2300. priv_info->vdc.version_major = (data >> 4) & 0x0F;
  2301. priv_info->vdc.version_minor = data & 0x0F;
  2302. if ((priv_info->vdc.version_major != 0x1) &&
  2303. ((priv_info->vdc.version_minor
  2304. != 0x2))) {
  2305. DSI_ERR("%s:unsupported major:%d minor:%d version\n",
  2306. __func__,
  2307. priv_info->vdc.version_major,
  2308. priv_info->vdc.version_minor
  2309. );
  2310. rc = -EINVAL;
  2311. goto error;
  2312. }
  2313. }
  2314. rc = utils->read_u32(utils->data, "qcom,vdc-version-release", &data);
  2315. if (rc) {
  2316. priv_info->vdc.version_release = 0x0;
  2317. rc = 0;
  2318. } else {
  2319. priv_info->vdc.version_release = data & 0xff;
  2320. /* only one release version is supported */
  2321. if (priv_info->vdc.version_release != 0x0) {
  2322. DSI_ERR("unsupported vdc release version %d\n",
  2323. priv_info->vdc.version_release);
  2324. rc = -EINVAL;
  2325. goto error;
  2326. }
  2327. }
  2328. DSI_INFO("vdc major: 0x%x minor : 0x%x release : 0x%x\n",
  2329. priv_info->vdc.version_major,
  2330. priv_info->vdc.version_minor,
  2331. priv_info->vdc.version_release);
  2332. rc = utils->read_u32(utils->data, "qcom,vdc-slice-height", &data);
  2333. if (rc) {
  2334. DSI_ERR("failed to parse qcom,vdc-slice-height\n");
  2335. goto error;
  2336. }
  2337. priv_info->vdc.slice_height = data;
  2338. /* slice height should be atleast 16 lines */
  2339. if (priv_info->vdc.slice_height < 16) {
  2340. DSI_ERR("invalid slice height %d\n",
  2341. priv_info->vdc.slice_height);
  2342. rc = -EINVAL;
  2343. goto error;
  2344. }
  2345. rc = utils->read_u32(utils->data, "qcom,vdc-slice-width", &data);
  2346. if (rc) {
  2347. DSI_ERR("failed to parse qcom,vdc-slice-width\n");
  2348. goto error;
  2349. }
  2350. priv_info->vdc.slice_width = data;
  2351. /*
  2352. * slide-width should be multiple of 8
  2353. * slice-width should be atlease 64 pixels
  2354. */
  2355. if ((priv_info->vdc.slice_width & 7) ||
  2356. (priv_info->vdc.slice_width < 64)) {
  2357. DSI_ERR("invalid slice width:%d\n", priv_info->vdc.slice_width);
  2358. rc = -EINVAL;
  2359. goto error;
  2360. }
  2361. rc = utils->read_u32(utils->data, "qcom,vdc-slice-per-pkt", &data);
  2362. if (rc) {
  2363. DSI_ERR("failed to parse qcom,vdc-slice-per-pkt\n");
  2364. goto error;
  2365. } else if (!data || (data > 2)) {
  2366. DSI_ERR("invalid vdc slice-per-pkt:%d\n", data);
  2367. rc = -EINVAL;
  2368. goto error;
  2369. }
  2370. intf_width = mode->timing.h_active;
  2371. priv_info->vdc.slice_per_pkt = data;
  2372. priv_info->vdc.frame_width = mode->timing.h_active;
  2373. priv_info->vdc.frame_height = mode->timing.v_active;
  2374. rc = utils->read_u32(utils->data, "qcom,vdc-bit-per-component",
  2375. &data);
  2376. if (rc) {
  2377. DSI_ERR("failed to parse qcom,vdc-bit-per-component\n");
  2378. goto error;
  2379. }
  2380. priv_info->vdc.bits_per_component = data;
  2381. rc = utils->read_u32(utils->data, "qcom,mdss-pps-delay-ms", &data);
  2382. if (rc) {
  2383. DSI_DEBUG("pps-delay-ms not specified, defaulting to 0\n");
  2384. data = 0;
  2385. }
  2386. priv_info->vdc.pps_delay_ms = data;
  2387. rc = utils->read_u32(utils->data, "qcom,vdc-bit-per-pixel",
  2388. &data);
  2389. if (rc) {
  2390. DSI_ERR("failed to parse qcom,vdc-bit-per-pixel\n");
  2391. goto error;
  2392. }
  2393. priv_info->vdc.bits_per_pixel = data << 4;
  2394. rc = utils->read_u32(utils->data, "qcom,src-chroma-format",
  2395. &data);
  2396. if (rc) {
  2397. DSI_DEBUG("failed to parse qcom,src-chroma-format\n");
  2398. rc = 0;
  2399. data = MSM_CHROMA_444;
  2400. }
  2401. priv_info->vdc.chroma_format = data;
  2402. rc = utils->read_u32(utils->data, "qcom,src-color-space",
  2403. &data);
  2404. if (rc) {
  2405. DSI_DEBUG("failed to parse qcom,src-color-space\n");
  2406. rc = 0;
  2407. data = MSM_RGB;
  2408. }
  2409. priv_info->vdc.source_color_space = data;
  2410. rc = sde_vdc_populate_config(&priv_info->vdc,
  2411. intf_width, traffic_mode);
  2412. if (rc) {
  2413. DSI_DEBUG("failed populating vdc config\n");
  2414. rc = -EINVAL;
  2415. goto error;
  2416. }
  2417. priv_info->pclk_scale.numer =
  2418. priv_info->vdc.bits_per_pixel >> 4;
  2419. priv_info->pclk_scale.denom = msm_get_src_bpc(
  2420. priv_info->vdc.chroma_format,
  2421. priv_info->vdc.bits_per_component);
  2422. mode->timing.vdc_enabled = true;
  2423. mode->timing.vdc = &priv_info->vdc;
  2424. mode->timing.pclk_scale = priv_info->pclk_scale;
  2425. error:
  2426. return rc;
  2427. }
  2428. static int dsi_panel_parse_hdr_config(struct dsi_panel *panel)
  2429. {
  2430. int rc = 0;
  2431. struct drm_panel_hdr_properties *hdr_prop;
  2432. struct dsi_parser_utils *utils = &panel->utils;
  2433. hdr_prop = &panel->hdr_props;
  2434. hdr_prop->hdr_enabled = utils->read_bool(utils->data,
  2435. "qcom,mdss-dsi-panel-hdr-enabled");
  2436. if (hdr_prop->hdr_enabled) {
  2437. rc = utils->read_u32_array(utils->data,
  2438. "qcom,mdss-dsi-panel-hdr-color-primaries",
  2439. hdr_prop->display_primaries,
  2440. DISPLAY_PRIMARIES_MAX);
  2441. if (rc) {
  2442. DSI_ERR("%s:%d, Unable to read color primaries,rc:%u\n",
  2443. __func__, __LINE__, rc);
  2444. hdr_prop->hdr_enabled = false;
  2445. return rc;
  2446. }
  2447. rc = utils->read_u32(utils->data,
  2448. "qcom,mdss-dsi-panel-peak-brightness",
  2449. &(hdr_prop->peak_brightness));
  2450. if (rc) {
  2451. DSI_ERR("%s:%d, Unable to read hdr brightness, rc:%u\n",
  2452. __func__, __LINE__, rc);
  2453. hdr_prop->hdr_enabled = false;
  2454. return rc;
  2455. }
  2456. rc = utils->read_u32(utils->data,
  2457. "qcom,mdss-dsi-panel-blackness-level",
  2458. &(hdr_prop->blackness_level));
  2459. if (rc) {
  2460. DSI_ERR("%s:%d, Unable to read hdr brightness, rc:%u\n",
  2461. __func__, __LINE__, rc);
  2462. hdr_prop->hdr_enabled = false;
  2463. return rc;
  2464. }
  2465. }
  2466. return 0;
  2467. }
  2468. static int dsi_panel_parse_topology(
  2469. struct dsi_display_mode_priv_info *priv_info,
  2470. struct dsi_parser_utils *utils,
  2471. int topology_override)
  2472. {
  2473. struct msm_display_topology *topology;
  2474. u32 top_count, top_sel, *array = NULL;
  2475. int i, len = 0;
  2476. int rc = -EINVAL;
  2477. len = utils->count_u32_elems(utils->data, "qcom,display-topology");
  2478. if (len <= 0 || len % TOPOLOGY_SET_LEN ||
  2479. len > (TOPOLOGY_SET_LEN * MAX_TOPOLOGY)) {
  2480. DSI_ERR("invalid topology list for the panel, rc = %d\n", rc);
  2481. return rc;
  2482. }
  2483. top_count = len / TOPOLOGY_SET_LEN;
  2484. array = kcalloc(len, sizeof(u32), GFP_KERNEL);
  2485. if (!array)
  2486. return -ENOMEM;
  2487. rc = utils->read_u32_array(utils->data,
  2488. "qcom,display-topology", array, len);
  2489. if (rc) {
  2490. DSI_ERR("unable to read the display topologies, rc = %d\n", rc);
  2491. goto read_fail;
  2492. }
  2493. topology = kcalloc(top_count, sizeof(*topology), GFP_KERNEL);
  2494. if (!topology) {
  2495. rc = -ENOMEM;
  2496. goto read_fail;
  2497. }
  2498. for (i = 0; i < top_count; i++) {
  2499. struct msm_display_topology *top = &topology[i];
  2500. top->num_lm = array[i * TOPOLOGY_SET_LEN];
  2501. top->num_enc = array[i * TOPOLOGY_SET_LEN + 1];
  2502. top->num_intf = array[i * TOPOLOGY_SET_LEN + 2];
  2503. }
  2504. if (topology_override >= 0 && topology_override < top_count) {
  2505. DSI_INFO("override topology: cfg:%d lm:%d comp_enc:%d intf:%d\n",
  2506. topology_override,
  2507. topology[topology_override].num_lm,
  2508. topology[topology_override].num_enc,
  2509. topology[topology_override].num_intf);
  2510. top_sel = topology_override;
  2511. goto parse_done;
  2512. }
  2513. rc = utils->read_u32(utils->data,
  2514. "qcom,default-topology-index", &top_sel);
  2515. if (rc) {
  2516. DSI_ERR("no default topology selected, rc = %d\n", rc);
  2517. goto parse_fail;
  2518. }
  2519. if (top_sel >= top_count) {
  2520. rc = -EINVAL;
  2521. DSI_ERR("default topology is specified is not valid, rc = %d\n",
  2522. rc);
  2523. goto parse_fail;
  2524. }
  2525. DSI_INFO("default topology: lm: %d comp_enc:%d intf: %d\n",
  2526. topology[top_sel].num_lm,
  2527. topology[top_sel].num_enc,
  2528. topology[top_sel].num_intf);
  2529. parse_done:
  2530. memcpy(&priv_info->topology, &topology[top_sel],
  2531. sizeof(struct msm_display_topology));
  2532. parse_fail:
  2533. kfree(topology);
  2534. read_fail:
  2535. kfree(array);
  2536. return rc;
  2537. }
  2538. static int dsi_panel_parse_roi_alignment(struct dsi_parser_utils *utils,
  2539. struct msm_roi_alignment *align)
  2540. {
  2541. int len = 0, rc = 0;
  2542. u32 value[6];
  2543. struct property *data;
  2544. if (!align)
  2545. return -EINVAL;
  2546. memset(align, 0, sizeof(*align));
  2547. data = utils->find_property(utils->data,
  2548. "qcom,panel-roi-alignment", &len);
  2549. len /= sizeof(u32);
  2550. if (!data) {
  2551. DSI_ERR("panel roi alignment not found\n");
  2552. rc = -EINVAL;
  2553. } else if (len != 6) {
  2554. DSI_ERR("incorrect roi alignment len %d\n", len);
  2555. rc = -EINVAL;
  2556. } else {
  2557. rc = utils->read_u32_array(utils->data,
  2558. "qcom,panel-roi-alignment", value, len);
  2559. if (rc)
  2560. DSI_DEBUG("error reading panel roi alignment values\n");
  2561. else {
  2562. align->xstart_pix_align = value[0];
  2563. align->ystart_pix_align = value[1];
  2564. align->width_pix_align = value[2];
  2565. align->height_pix_align = value[3];
  2566. align->min_width = value[4];
  2567. align->min_height = value[5];
  2568. }
  2569. DSI_INFO("roi alignment: [%d, %d, %d, %d, %d, %d]\n",
  2570. align->xstart_pix_align,
  2571. align->width_pix_align,
  2572. align->ystart_pix_align,
  2573. align->height_pix_align,
  2574. align->min_width,
  2575. align->min_height);
  2576. }
  2577. return rc;
  2578. }
  2579. static int dsi_panel_parse_partial_update_caps(struct dsi_display_mode *mode,
  2580. struct dsi_parser_utils *utils)
  2581. {
  2582. struct msm_roi_caps *roi_caps = NULL;
  2583. const char *data;
  2584. int rc = 0;
  2585. if (!mode || !mode->priv_info) {
  2586. DSI_ERR("invalid arguments\n");
  2587. return -EINVAL;
  2588. }
  2589. roi_caps = &mode->priv_info->roi_caps;
  2590. memset(roi_caps, 0, sizeof(*roi_caps));
  2591. data = utils->get_property(utils->data,
  2592. "qcom,partial-update-enabled", NULL);
  2593. if (data) {
  2594. if (!strcmp(data, "dual_roi"))
  2595. roi_caps->num_roi = 2;
  2596. else if (!strcmp(data, "single_roi"))
  2597. roi_caps->num_roi = 1;
  2598. else {
  2599. DSI_INFO(
  2600. "invalid value for qcom,partial-update-enabled: %s\n",
  2601. data);
  2602. return 0;
  2603. }
  2604. } else {
  2605. DSI_DEBUG("partial update disabled as the property is not set\n");
  2606. return 0;
  2607. }
  2608. roi_caps->merge_rois = utils->read_bool(utils->data,
  2609. "qcom,partial-update-roi-merge");
  2610. roi_caps->enabled = roi_caps->num_roi > 0;
  2611. DSI_DEBUG("partial update num_rois=%d enabled=%d\n", roi_caps->num_roi,
  2612. roi_caps->enabled);
  2613. if (roi_caps->enabled)
  2614. rc = dsi_panel_parse_roi_alignment(utils,
  2615. &roi_caps->align);
  2616. if (rc)
  2617. memset(roi_caps, 0, sizeof(*roi_caps));
  2618. return rc;
  2619. }
  2620. static bool dsi_panel_parse_panel_mode_caps(struct dsi_display_mode *mode,
  2621. struct dsi_parser_utils *utils)
  2622. {
  2623. if (!mode || !mode->priv_info) {
  2624. DSI_ERR("invalid arguments\n");
  2625. return false;
  2626. }
  2627. if (utils->read_bool(utils->data, "qcom,mdss-dsi-video-mode"))
  2628. mode->panel_mode_caps |= DSI_OP_VIDEO_MODE;
  2629. if (utils->read_bool(utils->data, "qcom,mdss-dsi-cmd-mode"))
  2630. mode->panel_mode_caps |= DSI_OP_CMD_MODE;
  2631. if (!mode->panel_mode_caps)
  2632. return false;
  2633. return true;
  2634. };
  2635. static int dsi_panel_parse_dms_info(struct dsi_panel *panel)
  2636. {
  2637. int dms_enabled;
  2638. const char *data;
  2639. struct dsi_parser_utils *utils = &panel->utils;
  2640. panel->dms_mode = DSI_DMS_MODE_DISABLED;
  2641. dms_enabled = utils->read_bool(utils->data,
  2642. "qcom,dynamic-mode-switch-enabled");
  2643. if (!dms_enabled)
  2644. return 0;
  2645. data = utils->get_property(utils->data,
  2646. "qcom,dynamic-mode-switch-type", NULL);
  2647. if (data && !strcmp(data, "dynamic-resolution-switch-immediate")) {
  2648. panel->dms_mode = DSI_DMS_MODE_RES_SWITCH_IMMEDIATE;
  2649. } else {
  2650. DSI_ERR("[%s] unsupported dynamic switch mode: %s\n",
  2651. panel->name, data);
  2652. return -EINVAL;
  2653. }
  2654. return 0;
  2655. };
  2656. /*
  2657. * The length of all the valid values to be checked should not be greater
  2658. * than the length of returned data from read command.
  2659. */
  2660. static bool
  2661. dsi_panel_parse_esd_check_valid_params(struct dsi_panel *panel, u32 count)
  2662. {
  2663. int i;
  2664. struct drm_panel_esd_config *config = &panel->esd_config;
  2665. for (i = 0; i < count; ++i) {
  2666. if (config->status_valid_params[i] >
  2667. config->status_cmds_rlen[i]) {
  2668. DSI_DEBUG("ignore valid params\n");
  2669. return false;
  2670. }
  2671. }
  2672. return true;
  2673. }
  2674. static bool dsi_panel_parse_esd_status_len(struct dsi_parser_utils *utils,
  2675. char *prop_key, u32 **target, u32 cmd_cnt)
  2676. {
  2677. int tmp;
  2678. if (!utils->find_property(utils->data, prop_key, &tmp))
  2679. return false;
  2680. tmp /= sizeof(u32);
  2681. if (tmp != cmd_cnt) {
  2682. DSI_ERR("request property(%d) do not match cmd count(%d)\n",
  2683. tmp, cmd_cnt);
  2684. return false;
  2685. }
  2686. *target = kcalloc(tmp, sizeof(u32), GFP_KERNEL);
  2687. if (IS_ERR_OR_NULL(*target)) {
  2688. DSI_ERR("Error allocating memory for property\n");
  2689. return false;
  2690. }
  2691. if (utils->read_u32_array(utils->data, prop_key, *target, tmp)) {
  2692. DSI_ERR("cannot get values from dts\n");
  2693. kfree(*target);
  2694. *target = NULL;
  2695. return false;
  2696. }
  2697. return true;
  2698. }
  2699. static void dsi_panel_esd_config_deinit(struct drm_panel_esd_config *esd_config)
  2700. {
  2701. kfree(esd_config->status_buf);
  2702. kfree(esd_config->return_buf);
  2703. kfree(esd_config->status_value);
  2704. kfree(esd_config->status_valid_params);
  2705. kfree(esd_config->status_cmds_rlen);
  2706. kfree(esd_config->status_cmd.cmds);
  2707. }
  2708. int dsi_panel_parse_esd_reg_read_configs(struct dsi_panel *panel)
  2709. {
  2710. struct drm_panel_esd_config *esd_config;
  2711. int rc = 0;
  2712. u32 tmp;
  2713. u32 i, status_len, *lenp;
  2714. struct property *data;
  2715. struct dsi_parser_utils *utils = &panel->utils;
  2716. if (!panel) {
  2717. DSI_ERR("Invalid Params\n");
  2718. return -EINVAL;
  2719. }
  2720. esd_config = &panel->esd_config;
  2721. if (!esd_config)
  2722. return -EINVAL;
  2723. dsi_panel_parse_cmd_sets_sub(&esd_config->status_cmd,
  2724. DSI_CMD_SET_PANEL_STATUS, utils);
  2725. if (!esd_config->status_cmd.count) {
  2726. DSI_ERR("panel status command parsing failed\n");
  2727. rc = -EINVAL;
  2728. goto error;
  2729. }
  2730. if (!dsi_panel_parse_esd_status_len(utils,
  2731. "qcom,mdss-dsi-panel-status-read-length",
  2732. &panel->esd_config.status_cmds_rlen,
  2733. esd_config->status_cmd.count)) {
  2734. DSI_ERR("Invalid status read length\n");
  2735. rc = -EINVAL;
  2736. goto error1;
  2737. }
  2738. if (dsi_panel_parse_esd_status_len(utils,
  2739. "qcom,mdss-dsi-panel-status-valid-params",
  2740. &panel->esd_config.status_valid_params,
  2741. esd_config->status_cmd.count)) {
  2742. if (!dsi_panel_parse_esd_check_valid_params(panel,
  2743. esd_config->status_cmd.count)) {
  2744. rc = -EINVAL;
  2745. goto error2;
  2746. }
  2747. }
  2748. status_len = 0;
  2749. lenp = esd_config->status_valid_params ?: esd_config->status_cmds_rlen;
  2750. for (i = 0; i < esd_config->status_cmd.count; ++i)
  2751. status_len += lenp[i];
  2752. if (!status_len) {
  2753. rc = -EINVAL;
  2754. goto error2;
  2755. }
  2756. /*
  2757. * Some panel may need multiple read commands to properly
  2758. * check panel status. Do a sanity check for proper status
  2759. * value which will be compared with the value read by dsi
  2760. * controller during ESD check. Also check if multiple read
  2761. * commands are there then, there should be corresponding
  2762. * status check values for each read command.
  2763. */
  2764. data = utils->find_property(utils->data,
  2765. "qcom,mdss-dsi-panel-status-value", &tmp);
  2766. tmp /= sizeof(u32);
  2767. if (!IS_ERR_OR_NULL(data) && tmp != 0 && (tmp % status_len) == 0) {
  2768. esd_config->groups = tmp / status_len;
  2769. } else {
  2770. DSI_ERR("error parse panel-status-value\n");
  2771. rc = -EINVAL;
  2772. goto error2;
  2773. }
  2774. esd_config->status_value =
  2775. kzalloc(sizeof(u32) * status_len * esd_config->groups,
  2776. GFP_KERNEL);
  2777. if (!esd_config->status_value) {
  2778. rc = -ENOMEM;
  2779. goto error2;
  2780. }
  2781. esd_config->return_buf = kcalloc(status_len * esd_config->groups,
  2782. sizeof(unsigned char), GFP_KERNEL);
  2783. if (!esd_config->return_buf) {
  2784. rc = -ENOMEM;
  2785. goto error3;
  2786. }
  2787. esd_config->status_buf = kzalloc(SZ_4K, GFP_KERNEL);
  2788. if (!esd_config->status_buf) {
  2789. rc = -ENOMEM;
  2790. goto error4;
  2791. }
  2792. rc = utils->read_u32_array(utils->data,
  2793. "qcom,mdss-dsi-panel-status-value",
  2794. esd_config->status_value, esd_config->groups * status_len);
  2795. if (rc) {
  2796. DSI_DEBUG("error reading panel status values\n");
  2797. memset(esd_config->status_value, 0,
  2798. esd_config->groups * status_len);
  2799. }
  2800. return 0;
  2801. error4:
  2802. kfree(esd_config->return_buf);
  2803. error3:
  2804. kfree(esd_config->status_value);
  2805. error2:
  2806. kfree(esd_config->status_valid_params);
  2807. kfree(esd_config->status_cmds_rlen);
  2808. error1:
  2809. kfree(esd_config->status_cmd.cmds);
  2810. error:
  2811. return rc;
  2812. }
  2813. static int dsi_panel_parse_esd_config(struct dsi_panel *panel)
  2814. {
  2815. int rc = 0;
  2816. const char *string;
  2817. struct drm_panel_esd_config *esd_config;
  2818. struct dsi_parser_utils *utils = &panel->utils;
  2819. u8 *esd_mode = NULL;
  2820. esd_config = &panel->esd_config;
  2821. esd_config->status_mode = ESD_MODE_MAX;
  2822. esd_config->esd_enabled = utils->read_bool(utils->data,
  2823. "qcom,esd-check-enabled");
  2824. if (!esd_config->esd_enabled)
  2825. return 0;
  2826. rc = utils->read_string(utils->data,
  2827. "qcom,mdss-dsi-panel-status-check-mode", &string);
  2828. if (!rc) {
  2829. if (!strcmp(string, "bta_check")) {
  2830. esd_config->status_mode = ESD_MODE_SW_BTA;
  2831. } else if (!strcmp(string, "reg_read")) {
  2832. esd_config->status_mode = ESD_MODE_REG_READ;
  2833. } else if (!strcmp(string, "te_signal_check")) {
  2834. if (panel->panel_mode == DSI_OP_CMD_MODE) {
  2835. esd_config->status_mode = ESD_MODE_PANEL_TE;
  2836. } else {
  2837. DSI_ERR("TE-ESD not valid for video mode\n");
  2838. rc = -EINVAL;
  2839. goto error;
  2840. }
  2841. } else {
  2842. DSI_ERR("No valid panel-status-check-mode string\n");
  2843. rc = -EINVAL;
  2844. goto error;
  2845. }
  2846. } else {
  2847. DSI_DEBUG("status check method not defined!\n");
  2848. rc = -EINVAL;
  2849. goto error;
  2850. }
  2851. if (panel->esd_config.status_mode == ESD_MODE_REG_READ) {
  2852. rc = dsi_panel_parse_esd_reg_read_configs(panel);
  2853. if (rc) {
  2854. DSI_ERR("failed to parse esd reg read mode params, rc=%d\n",
  2855. rc);
  2856. goto error;
  2857. }
  2858. esd_mode = "register_read";
  2859. } else if (panel->esd_config.status_mode == ESD_MODE_SW_BTA) {
  2860. esd_mode = "bta_trigger";
  2861. } else if (panel->esd_config.status_mode == ESD_MODE_PANEL_TE) {
  2862. esd_mode = "te_check";
  2863. }
  2864. DSI_DEBUG("ESD enabled with mode: %s\n", esd_mode);
  2865. return 0;
  2866. error:
  2867. panel->esd_config.esd_enabled = false;
  2868. return rc;
  2869. }
  2870. static void dsi_panel_update_util(struct dsi_panel *panel,
  2871. struct device_node *parser_node)
  2872. {
  2873. struct dsi_parser_utils *utils = &panel->utils;
  2874. if (parser_node) {
  2875. *utils = *dsi_parser_get_parser_utils();
  2876. utils->data = parser_node;
  2877. DSI_DEBUG("switching to parser APIs\n");
  2878. goto end;
  2879. }
  2880. *utils = *dsi_parser_get_of_utils();
  2881. utils->data = panel->panel_of_node;
  2882. end:
  2883. utils->node = panel->panel_of_node;
  2884. }
  2885. static int dsi_panel_vm_stub(struct dsi_panel *panel)
  2886. {
  2887. return 0;
  2888. }
  2889. static void dsi_panel_setup_vm_ops(struct dsi_panel *panel, bool trusted_vm_env)
  2890. {
  2891. if (trusted_vm_env) {
  2892. panel->panel_ops.pinctrl_init = dsi_panel_vm_stub;
  2893. panel->panel_ops.gpio_request = dsi_panel_vm_stub;
  2894. panel->panel_ops.pinctrl_deinit = dsi_panel_vm_stub;
  2895. panel->panel_ops.gpio_release = dsi_panel_vm_stub;
  2896. panel->panel_ops.bl_register = dsi_panel_vm_stub;
  2897. panel->panel_ops.bl_unregister = dsi_panel_vm_stub;
  2898. panel->panel_ops.parse_gpios = dsi_panel_vm_stub;
  2899. } else {
  2900. panel->panel_ops.pinctrl_init = dsi_panel_pinctrl_init;
  2901. panel->panel_ops.gpio_request = dsi_panel_gpio_request;
  2902. panel->panel_ops.pinctrl_deinit = dsi_panel_pinctrl_deinit;
  2903. panel->panel_ops.gpio_release = dsi_panel_gpio_release;
  2904. panel->panel_ops.bl_register = dsi_panel_bl_register;
  2905. panel->panel_ops.bl_unregister = dsi_panel_bl_unregister;
  2906. panel->panel_ops.parse_gpios = dsi_panel_parse_gpios;
  2907. }
  2908. }
  2909. struct dsi_panel *dsi_panel_get(struct device *parent,
  2910. struct device_node *of_node,
  2911. struct device_node *parser_node,
  2912. const char *type,
  2913. int topology_override,
  2914. bool trusted_vm_env)
  2915. {
  2916. struct dsi_panel *panel;
  2917. struct dsi_parser_utils *utils;
  2918. const char *panel_physical_type;
  2919. int rc = 0;
  2920. panel = kzalloc(sizeof(*panel), GFP_KERNEL);
  2921. if (!panel)
  2922. return ERR_PTR(-ENOMEM);
  2923. dsi_panel_setup_vm_ops(panel, trusted_vm_env);
  2924. panel->panel_of_node = of_node;
  2925. panel->parent = parent;
  2926. panel->type = type;
  2927. dsi_panel_update_util(panel, parser_node);
  2928. utils = &panel->utils;
  2929. panel->name = utils->get_property(utils->data,
  2930. "qcom,mdss-dsi-panel-name", NULL);
  2931. if (!panel->name)
  2932. panel->name = DSI_PANEL_DEFAULT_LABEL;
  2933. /*
  2934. * Set panel type to LCD as default.
  2935. */
  2936. panel->panel_type = DSI_DISPLAY_PANEL_TYPE_LCD;
  2937. panel_physical_type = utils->get_property(utils->data,
  2938. "qcom,mdss-dsi-panel-physical-type", NULL);
  2939. if (panel_physical_type && !strcmp(panel_physical_type, "oled"))
  2940. panel->panel_type = DSI_DISPLAY_PANEL_TYPE_OLED;
  2941. rc = dsi_panel_parse_host_config(panel);
  2942. if (rc) {
  2943. DSI_ERR("failed to parse host configuration, rc=%d\n",
  2944. rc);
  2945. goto error;
  2946. }
  2947. rc = dsi_panel_parse_panel_mode(panel);
  2948. if (rc) {
  2949. DSI_ERR("failed to parse panel mode configuration, rc=%d\n",
  2950. rc);
  2951. goto error;
  2952. }
  2953. rc = dsi_panel_parse_dfps_caps(panel);
  2954. if (rc)
  2955. DSI_ERR("failed to parse dfps configuration, rc=%d\n", rc);
  2956. rc = dsi_panel_parse_qsync_caps(panel, of_node);
  2957. if (rc)
  2958. DSI_DEBUG("failed to parse qsync features, rc=%d\n", rc);
  2959. rc = dsi_panel_parse_dyn_clk_caps(panel);
  2960. if (rc)
  2961. DSI_ERR("failed to parse dynamic clk config, rc=%d\n", rc);
  2962. rc = dsi_panel_parse_phy_props(panel);
  2963. if (rc) {
  2964. DSI_ERR("failed to parse panel physical dimension, rc=%d\n",
  2965. rc);
  2966. goto error;
  2967. }
  2968. rc = panel->panel_ops.parse_gpios(panel);
  2969. if (rc) {
  2970. DSI_ERR("failed to parse panel gpios, rc=%d\n", rc);
  2971. goto error;
  2972. }
  2973. rc = dsi_panel_parse_tlmm_gpio(panel);
  2974. if (rc) {
  2975. DSI_ERR("failed to parse panel tlmm gpios, rc=%d\n", rc);
  2976. goto error;
  2977. }
  2978. rc = dsi_panel_parse_power_cfg(panel);
  2979. if (rc)
  2980. DSI_ERR("failed to parse power config, rc=%d\n", rc);
  2981. rc = dsi_panel_parse_bl_config(panel);
  2982. if (rc) {
  2983. DSI_ERR("failed to parse backlight config, rc=%d\n", rc);
  2984. if (rc == -EPROBE_DEFER)
  2985. goto error;
  2986. }
  2987. rc = dsi_panel_parse_misc_features(panel);
  2988. if (rc)
  2989. DSI_ERR("failed to parse misc features, rc=%d\n", rc);
  2990. rc = dsi_panel_parse_hdr_config(panel);
  2991. if (rc)
  2992. DSI_ERR("failed to parse hdr config, rc=%d\n", rc);
  2993. rc = dsi_panel_get_mode_count(panel);
  2994. if (rc) {
  2995. DSI_ERR("failed to get mode count, rc=%d\n", rc);
  2996. goto error;
  2997. }
  2998. rc = dsi_panel_parse_dms_info(panel);
  2999. if (rc)
  3000. DSI_DEBUG("failed to get dms info, rc=%d\n", rc);
  3001. rc = dsi_panel_parse_esd_config(panel);
  3002. if (rc)
  3003. DSI_DEBUG("failed to parse esd config, rc=%d\n", rc);
  3004. rc = dsi_panel_vreg_get(panel);
  3005. if (rc) {
  3006. DSI_ERR("[%s] failed to get panel regulators, rc=%d\n",
  3007. panel->name, rc);
  3008. goto error;
  3009. }
  3010. panel->power_mode = SDE_MODE_DPMS_OFF;
  3011. drm_panel_init(&panel->drm_panel, &panel->mipi_device.dev,
  3012. NULL, DRM_MODE_CONNECTOR_DSI);
  3013. panel->mipi_device.dev.of_node = of_node;
  3014. drm_panel_add(&panel->drm_panel);
  3015. mutex_init(&panel->panel_lock);
  3016. return panel;
  3017. error:
  3018. kfree(panel);
  3019. return ERR_PTR(rc);
  3020. }
  3021. void dsi_panel_put(struct dsi_panel *panel)
  3022. {
  3023. drm_panel_remove(&panel->drm_panel);
  3024. /* free resources allocated for ESD check */
  3025. dsi_panel_esd_config_deinit(&panel->esd_config);
  3026. kfree(panel);
  3027. }
  3028. int dsi_panel_drv_init(struct dsi_panel *panel,
  3029. struct mipi_dsi_host *host)
  3030. {
  3031. int rc = 0;
  3032. struct mipi_dsi_device *dev;
  3033. if (!panel || !host) {
  3034. DSI_ERR("invalid params\n");
  3035. return -EINVAL;
  3036. }
  3037. mutex_lock(&panel->panel_lock);
  3038. dev = &panel->mipi_device;
  3039. dev->host = host;
  3040. /*
  3041. * We dont have device structure since panel is not a device node.
  3042. * When using drm panel framework, the device is probed when the host is
  3043. * create.
  3044. */
  3045. dev->channel = 0;
  3046. dev->lanes = 4;
  3047. panel->host = host;
  3048. rc = panel->panel_ops.pinctrl_init(panel);
  3049. if (rc) {
  3050. DSI_ERR("[%s] failed to init pinctrl, rc=%d\n",
  3051. panel->name, rc);
  3052. goto exit;
  3053. }
  3054. rc = panel->panel_ops.gpio_request(panel);
  3055. if (rc) {
  3056. DSI_ERR("[%s] failed to request gpios, rc=%d\n", panel->name,
  3057. rc);
  3058. goto error_pinctrl_deinit;
  3059. }
  3060. rc = panel->panel_ops.bl_register(panel);
  3061. if (rc) {
  3062. if (rc != -EPROBE_DEFER)
  3063. DSI_ERR("[%s] failed to register backlight, rc=%d\n",
  3064. panel->name, rc);
  3065. goto error_gpio_release;
  3066. }
  3067. goto exit;
  3068. error_gpio_release:
  3069. (void)dsi_panel_gpio_release(panel);
  3070. error_pinctrl_deinit:
  3071. (void)dsi_panel_pinctrl_deinit(panel);
  3072. exit:
  3073. mutex_unlock(&panel->panel_lock);
  3074. return rc;
  3075. }
  3076. int dsi_panel_drv_deinit(struct dsi_panel *panel)
  3077. {
  3078. int rc = 0;
  3079. if (!panel) {
  3080. DSI_ERR("invalid params\n");
  3081. return -EINVAL;
  3082. }
  3083. mutex_lock(&panel->panel_lock);
  3084. rc = panel->panel_ops.bl_unregister(panel);
  3085. if (rc)
  3086. DSI_ERR("[%s] failed to unregister backlight, rc=%d\n",
  3087. panel->name, rc);
  3088. rc = panel->panel_ops.gpio_release(panel);
  3089. if (rc)
  3090. DSI_ERR("[%s] failed to release gpios, rc=%d\n", panel->name,
  3091. rc);
  3092. rc = panel->panel_ops.pinctrl_deinit(panel);
  3093. if (rc)
  3094. DSI_ERR("[%s] failed to deinit gpios, rc=%d\n", panel->name,
  3095. rc);
  3096. rc = dsi_panel_vreg_put(panel);
  3097. if (rc)
  3098. DSI_ERR("[%s] failed to put regs, rc=%d\n", panel->name, rc);
  3099. kfree(panel->tlmm_gpio);
  3100. panel->host = NULL;
  3101. memset(&panel->mipi_device, 0x0, sizeof(panel->mipi_device));
  3102. mutex_unlock(&panel->panel_lock);
  3103. return rc;
  3104. }
  3105. int dsi_panel_validate_mode(struct dsi_panel *panel,
  3106. struct dsi_display_mode *mode)
  3107. {
  3108. return 0;
  3109. }
  3110. static int dsi_panel_get_max_res_count(struct dsi_parser_utils *utils,
  3111. struct device_node *node, u32 *dsc_count, u32 *lm_count)
  3112. {
  3113. const char *compression;
  3114. u32 *array = NULL, top_count, len, i;
  3115. int rc = -EINVAL;
  3116. bool dsc_enable = false;
  3117. *dsc_count = 0;
  3118. *lm_count = 0;
  3119. compression = utils->get_property(node, "qcom,compression-mode", NULL);
  3120. if (compression && !strcmp(compression, "dsc"))
  3121. dsc_enable = true;
  3122. len = utils->count_u32_elems(node, "qcom,display-topology");
  3123. if (len <= 0 || len % TOPOLOGY_SET_LEN ||
  3124. len > (TOPOLOGY_SET_LEN * MAX_TOPOLOGY))
  3125. return rc;
  3126. top_count = len / TOPOLOGY_SET_LEN;
  3127. array = kcalloc(len, sizeof(u32), GFP_KERNEL);
  3128. if (!array)
  3129. return -ENOMEM;
  3130. rc = utils->read_u32_array(node, "qcom,display-topology", array, len);
  3131. if (rc) {
  3132. DSI_ERR("unable to read the display topologies, rc = %d\n", rc);
  3133. goto read_fail;
  3134. }
  3135. for (i = 0; i < top_count; i++) {
  3136. *lm_count = max(*lm_count, array[i * TOPOLOGY_SET_LEN]);
  3137. if (dsc_enable)
  3138. *dsc_count = max(*dsc_count,
  3139. array[i * TOPOLOGY_SET_LEN + 1]);
  3140. }
  3141. read_fail:
  3142. kfree(array);
  3143. return 0;
  3144. }
  3145. int dsi_panel_get_mode_count(struct dsi_panel *panel)
  3146. {
  3147. const u32 SINGLE_MODE_SUPPORT = 1;
  3148. struct dsi_parser_utils *utils;
  3149. struct device_node *timings_np, *child_np;
  3150. int num_dfps_rates, num_bit_clks;
  3151. int num_video_modes = 0, num_cmd_modes = 0;
  3152. int count, rc = 0;
  3153. u32 dsc_count = 0, lm_count = 0;
  3154. if (!panel) {
  3155. DSI_ERR("invalid params\n");
  3156. return -EINVAL;
  3157. }
  3158. utils = &panel->utils;
  3159. panel->num_timing_nodes = 0;
  3160. timings_np = utils->get_child_by_name(utils->data,
  3161. "qcom,mdss-dsi-display-timings");
  3162. if (!timings_np && !panel->host_config.ext_bridge_mode) {
  3163. DSI_ERR("no display timing nodes defined\n");
  3164. rc = -EINVAL;
  3165. goto error;
  3166. }
  3167. count = utils->get_child_count(timings_np);
  3168. if ((!count && !panel->host_config.ext_bridge_mode) ||
  3169. count > DSI_MODE_MAX) {
  3170. DSI_ERR("invalid count of timing nodes: %d\n", count);
  3171. rc = -EINVAL;
  3172. goto error;
  3173. }
  3174. /* No multiresolution support is available for video mode panels.
  3175. * Multi-mode is supported for video mode during POMS is enabled.
  3176. */
  3177. if (panel->panel_mode != DSI_OP_CMD_MODE &&
  3178. !panel->host_config.ext_bridge_mode &&
  3179. !panel->panel_mode_switch_enabled)
  3180. count = SINGLE_MODE_SUPPORT;
  3181. panel->num_timing_nodes = count;
  3182. dsi_for_each_child_node(timings_np, child_np) {
  3183. if (utils->read_bool(child_np, "qcom,mdss-dsi-video-mode"))
  3184. num_video_modes++;
  3185. else if (utils->read_bool(child_np,
  3186. "qcom,mdss-dsi-cmd-mode"))
  3187. num_cmd_modes++;
  3188. else if (panel->panel_mode == DSI_OP_VIDEO_MODE)
  3189. num_video_modes++;
  3190. else if (panel->panel_mode == DSI_OP_CMD_MODE)
  3191. num_cmd_modes++;
  3192. dsi_panel_get_max_res_count(utils, child_np,
  3193. &dsc_count, &lm_count);
  3194. panel->dsc_count = max(dsc_count, panel->dsc_count);
  3195. panel->lm_count = max(lm_count, panel->lm_count);
  3196. }
  3197. num_dfps_rates = !panel->dfps_caps.dfps_support ? 1 :
  3198. panel->dfps_caps.dfps_list_len;
  3199. num_bit_clks = !panel->dyn_clk_caps.dyn_clk_support ? 1 :
  3200. panel->dyn_clk_caps.bit_clk_list_len;
  3201. /*
  3202. * Inflate num_of_modes by fps and bit clks in dfps.
  3203. * Single command mode for video mode panels supporting
  3204. * panel operating mode switch.
  3205. */
  3206. num_video_modes = num_video_modes * num_bit_clks * num_dfps_rates;
  3207. if ((panel->panel_mode == DSI_OP_VIDEO_MODE) &&
  3208. (panel->panel_mode_switch_enabled))
  3209. num_cmd_modes = 1;
  3210. else
  3211. num_cmd_modes = num_cmd_modes * num_bit_clks;
  3212. panel->num_display_modes = num_video_modes + num_cmd_modes;
  3213. error:
  3214. return rc;
  3215. }
  3216. int dsi_panel_get_phy_props(struct dsi_panel *panel,
  3217. struct dsi_panel_phy_props *phy_props)
  3218. {
  3219. int rc = 0;
  3220. if (!panel || !phy_props) {
  3221. DSI_ERR("invalid params\n");
  3222. return -EINVAL;
  3223. }
  3224. memcpy(phy_props, &panel->phy_props, sizeof(*phy_props));
  3225. return rc;
  3226. }
  3227. int dsi_panel_get_dfps_caps(struct dsi_panel *panel,
  3228. struct dsi_dfps_capabilities *dfps_caps)
  3229. {
  3230. int rc = 0;
  3231. if (!panel || !dfps_caps) {
  3232. DSI_ERR("invalid params\n");
  3233. return -EINVAL;
  3234. }
  3235. memcpy(dfps_caps, &panel->dfps_caps, sizeof(*dfps_caps));
  3236. return rc;
  3237. }
  3238. void dsi_panel_put_mode(struct dsi_display_mode *mode)
  3239. {
  3240. int i;
  3241. if (!mode->priv_info)
  3242. return;
  3243. for (i = 0; i < DSI_CMD_SET_MAX; i++) {
  3244. dsi_panel_destroy_cmd_packets(&mode->priv_info->cmd_sets[i]);
  3245. dsi_panel_dealloc_cmd_packets(&mode->priv_info->cmd_sets[i]);
  3246. }
  3247. kfree(mode->priv_info);
  3248. }
  3249. void dsi_panel_calc_dsi_transfer_time(struct dsi_host_common_cfg *config,
  3250. struct dsi_display_mode *mode, u32 frame_threshold_us)
  3251. {
  3252. u32 frame_time_us, nslices;
  3253. u64 min_bitclk_hz, total_active_pixels, bits_per_line, pclk_rate_hz,
  3254. dsi_transfer_time_us, pixel_clk_khz;
  3255. struct msm_display_dsc_info *dsc = mode->timing.dsc;
  3256. struct dsi_mode_info *timing = &mode->timing;
  3257. struct dsi_display_mode *display_mode;
  3258. u32 jitter_numer, jitter_denom, prefill_lines;
  3259. u32 min_threshold_us, prefill_time_us, max_transfer_us;
  3260. u16 bpp;
  3261. /* Packet overlead in bits,2 bytes header + 2 bytes checksum
  3262. * + 1 byte dcs data command.
  3263. */
  3264. const u32 packet_overhead = 56;
  3265. display_mode = container_of(timing, struct dsi_display_mode, timing);
  3266. jitter_numer = display_mode->priv_info->panel_jitter_numer;
  3267. jitter_denom = display_mode->priv_info->panel_jitter_denom;
  3268. frame_time_us = mult_frac(1000, 1000, (timing->refresh_rate));
  3269. if (timing->refresh_rate >= 120)
  3270. frame_threshold_us = HIGH_REFRESH_RATE_THRESHOLD_TIME_US;
  3271. if (timing->dsc_enabled) {
  3272. nslices = (timing->h_active)/(dsc->config.slice_width);
  3273. /* (slice width x bit-per-pixel + packet overhead) x
  3274. * number of slices x height x fps / lane
  3275. */
  3276. bpp = DSC_BPP(dsc->config);
  3277. bits_per_line = ((dsc->config.slice_width * bpp) +
  3278. packet_overhead) * nslices;
  3279. bits_per_line = bits_per_line / (config->num_data_lanes);
  3280. min_bitclk_hz = (bits_per_line * timing->v_active *
  3281. timing->refresh_rate);
  3282. } else {
  3283. total_active_pixels = ((dsi_h_active_dce(timing)
  3284. * timing->v_active));
  3285. /* calculate the actual bitclk needed to transfer the frame */
  3286. min_bitclk_hz = (total_active_pixels * (timing->refresh_rate) *
  3287. (config->bpp));
  3288. do_div(min_bitclk_hz, config->num_data_lanes);
  3289. }
  3290. timing->min_dsi_clk_hz = min_bitclk_hz;
  3291. min_threshold_us = mult_frac(frame_time_us,
  3292. jitter_numer, (jitter_denom * 100));
  3293. /*
  3294. * Increase the prefill_lines proportionately as recommended
  3295. * 35lines for 60fps, 52 for 90fps, 70lines for 120fps.
  3296. */
  3297. prefill_lines = mult_frac(MIN_PREFILL_LINES,
  3298. timing->refresh_rate, 60);
  3299. prefill_time_us = mult_frac(frame_time_us, prefill_lines,
  3300. (timing->v_active));
  3301. /*
  3302. * Threshold is sum of panel jitter time, prefill line time
  3303. * plus 64usec buffer time.
  3304. */
  3305. min_threshold_us = min_threshold_us + 64 + prefill_time_us;
  3306. DSI_DEBUG("min threshold time=%d\n", min_threshold_us);
  3307. if (timing->clk_rate_hz) {
  3308. /* adjust the transfer time proportionately for bit clk*/
  3309. dsi_transfer_time_us = frame_time_us * min_bitclk_hz;
  3310. do_div(dsi_transfer_time_us, timing->clk_rate_hz);
  3311. timing->dsi_transfer_time_us = dsi_transfer_time_us;
  3312. } else if (mode->priv_info->mdp_transfer_time_us) {
  3313. max_transfer_us = frame_time_us - min_threshold_us;
  3314. mode->priv_info->mdp_transfer_time_us = min(
  3315. mode->priv_info->mdp_transfer_time_us,
  3316. max_transfer_us);
  3317. timing->dsi_transfer_time_us =
  3318. mode->priv_info->mdp_transfer_time_us;
  3319. } else {
  3320. if (min_threshold_us > frame_threshold_us)
  3321. frame_threshold_us = min_threshold_us;
  3322. timing->dsi_transfer_time_us = frame_time_us -
  3323. frame_threshold_us;
  3324. }
  3325. timing->mdp_transfer_time_us = timing->dsi_transfer_time_us;
  3326. /* Force update mdp xfer time to hal,if clk and mdp xfer time is set */
  3327. if (mode->priv_info->mdp_transfer_time_us && timing->clk_rate_hz) {
  3328. timing->mdp_transfer_time_us =
  3329. mode->priv_info->mdp_transfer_time_us;
  3330. }
  3331. /* Calculate pclk_khz to update modeinfo */
  3332. pclk_rate_hz = min_bitclk_hz * frame_time_us;
  3333. do_div(pclk_rate_hz, timing->dsi_transfer_time_us);
  3334. pixel_clk_khz = pclk_rate_hz * config->num_data_lanes;
  3335. do_div(pixel_clk_khz, config->bpp);
  3336. display_mode->pixel_clk_khz = pixel_clk_khz;
  3337. display_mode->pixel_clk_khz = display_mode->pixel_clk_khz / 1000;
  3338. }
  3339. int dsi_panel_get_mode(struct dsi_panel *panel,
  3340. u32 index, struct dsi_display_mode *mode,
  3341. int topology_override)
  3342. {
  3343. struct device_node *timings_np, *child_np;
  3344. struct dsi_parser_utils *utils;
  3345. struct dsi_display_mode_priv_info *prv_info;
  3346. u32 child_idx = 0;
  3347. int rc = 0, num_timings;
  3348. int traffic_mode;
  3349. void *utils_data = NULL;
  3350. if (!panel || !mode) {
  3351. DSI_ERR("invalid params\n");
  3352. return -EINVAL;
  3353. }
  3354. mutex_lock(&panel->panel_lock);
  3355. utils = &panel->utils;
  3356. mode->priv_info = kzalloc(sizeof(*mode->priv_info), GFP_KERNEL);
  3357. if (!mode->priv_info) {
  3358. rc = -ENOMEM;
  3359. goto done;
  3360. }
  3361. prv_info = mode->priv_info;
  3362. timings_np = utils->get_child_by_name(utils->data,
  3363. "qcom,mdss-dsi-display-timings");
  3364. if (!timings_np) {
  3365. DSI_ERR("no display timing nodes defined\n");
  3366. rc = -EINVAL;
  3367. goto parse_fail;
  3368. }
  3369. num_timings = utils->get_child_count(timings_np);
  3370. if (!num_timings || num_timings > DSI_MODE_MAX) {
  3371. DSI_ERR("invalid count of timing nodes: %d\n", num_timings);
  3372. rc = -EINVAL;
  3373. goto parse_fail;
  3374. }
  3375. utils_data = utils->data;
  3376. traffic_mode = panel->video_config.traffic_mode;
  3377. dsi_for_each_child_node(timings_np, child_np) {
  3378. if (index != child_idx++)
  3379. continue;
  3380. utils->data = child_np;
  3381. if (panel->panel_mode_switch_enabled) {
  3382. if (!dsi_panel_parse_panel_mode_caps(mode, utils)) {
  3383. mode->panel_mode_caps = panel->panel_mode;
  3384. DSI_INFO("panel mode isn't specified in timing[%d]\n",
  3385. child_idx);
  3386. }
  3387. } else {
  3388. mode->panel_mode_caps = panel->panel_mode;
  3389. }
  3390. rc = dsi_panel_parse_timing(&mode->timing, utils);
  3391. if (rc) {
  3392. DSI_ERR("failed to parse panel timing, rc=%d\n", rc);
  3393. goto parse_fail;
  3394. }
  3395. rc = dsi_panel_parse_dsc_params(mode, utils);
  3396. if (rc) {
  3397. DSI_ERR("failed to parse dsc params, rc=%d\n", rc);
  3398. goto parse_fail;
  3399. }
  3400. rc = dsi_panel_parse_vdc_params(mode, utils, traffic_mode);
  3401. if (rc) {
  3402. DSI_ERR("failed to parse vdc params, rc=%d\n", rc);
  3403. goto parse_fail;
  3404. }
  3405. rc = dsi_panel_parse_topology(prv_info, utils,
  3406. topology_override);
  3407. if (rc) {
  3408. DSI_ERR("failed to parse panel topology, rc=%d\n", rc);
  3409. goto parse_fail;
  3410. }
  3411. rc = dsi_panel_parse_cmd_sets(prv_info, utils);
  3412. if (rc) {
  3413. DSI_ERR("failed to parse command sets, rc=%d\n", rc);
  3414. goto parse_fail;
  3415. }
  3416. rc = dsi_panel_parse_jitter_config(mode, utils);
  3417. if (rc)
  3418. DSI_ERR(
  3419. "failed to parse panel jitter config, rc=%d\n", rc);
  3420. rc = dsi_panel_parse_phy_timing(mode, utils);
  3421. if (rc) {
  3422. DSI_ERR(
  3423. "failed to parse panel phy timings, rc=%d\n", rc);
  3424. goto parse_fail;
  3425. }
  3426. rc = dsi_panel_parse_partial_update_caps(mode, utils);
  3427. if (rc)
  3428. DSI_ERR("failed to partial update caps, rc=%d\n", rc);
  3429. }
  3430. goto done;
  3431. parse_fail:
  3432. kfree(mode->priv_info);
  3433. mode->priv_info = NULL;
  3434. done:
  3435. utils->data = utils_data;
  3436. mutex_unlock(&panel->panel_lock);
  3437. return rc;
  3438. }
  3439. int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel,
  3440. struct dsi_display_mode *mode,
  3441. struct dsi_host_config *config)
  3442. {
  3443. int rc = 0;
  3444. struct dsi_dyn_clk_caps *dyn_clk_caps = &panel->dyn_clk_caps;
  3445. if (!panel || !mode || !config) {
  3446. DSI_ERR("invalid params\n");
  3447. return -EINVAL;
  3448. }
  3449. mutex_lock(&panel->panel_lock);
  3450. config->panel_mode = panel->panel_mode;
  3451. memcpy(&config->common_config, &panel->host_config,
  3452. sizeof(config->common_config));
  3453. if (panel->panel_mode == DSI_OP_VIDEO_MODE) {
  3454. memcpy(&config->u.video_engine, &panel->video_config,
  3455. sizeof(config->u.video_engine));
  3456. } else {
  3457. memcpy(&config->u.cmd_engine, &panel->cmd_config,
  3458. sizeof(config->u.cmd_engine));
  3459. }
  3460. memcpy(&config->video_timing, &mode->timing,
  3461. sizeof(config->video_timing));
  3462. config->video_timing.mdp_transfer_time_us =
  3463. mode->priv_info->mdp_transfer_time_us;
  3464. config->video_timing.dsc_enabled = mode->priv_info->dsc_enabled;
  3465. config->video_timing.dsc = &mode->priv_info->dsc;
  3466. config->video_timing.vdc_enabled = mode->priv_info->vdc_enabled;
  3467. config->video_timing.vdc = &mode->priv_info->vdc;
  3468. if (dyn_clk_caps->dyn_clk_support)
  3469. config->bit_clk_rate_hz_override = mode->timing.clk_rate_hz;
  3470. else
  3471. config->bit_clk_rate_hz_override = mode->priv_info->clk_rate_hz;
  3472. config->esc_clk_rate_hz = 19200000;
  3473. mutex_unlock(&panel->panel_lock);
  3474. return rc;
  3475. }
  3476. int dsi_panel_pre_prepare(struct dsi_panel *panel)
  3477. {
  3478. int rc = 0;
  3479. if (!panel) {
  3480. DSI_ERR("invalid params\n");
  3481. return -EINVAL;
  3482. }
  3483. mutex_lock(&panel->panel_lock);
  3484. /* If LP11_INIT is set, panel will be powered up during prepare() */
  3485. if (panel->lp11_init)
  3486. goto error;
  3487. rc = dsi_panel_power_on(panel);
  3488. if (rc) {
  3489. DSI_ERR("[%s] panel power on failed, rc=%d\n", panel->name, rc);
  3490. goto error;
  3491. }
  3492. error:
  3493. mutex_unlock(&panel->panel_lock);
  3494. return rc;
  3495. }
  3496. int dsi_panel_update_pps(struct dsi_panel *panel)
  3497. {
  3498. int rc = 0;
  3499. struct dsi_panel_cmd_set *set = NULL;
  3500. struct dsi_display_mode_priv_info *priv_info = NULL;
  3501. if (!panel || !panel->cur_mode) {
  3502. DSI_ERR("invalid params\n");
  3503. return -EINVAL;
  3504. }
  3505. mutex_lock(&panel->panel_lock);
  3506. priv_info = panel->cur_mode->priv_info;
  3507. set = &priv_info->cmd_sets[DSI_CMD_SET_PPS];
  3508. if (priv_info->dsc_enabled)
  3509. dsi_dsc_create_pps_buf_cmd(&priv_info->dsc,
  3510. panel->dce_pps_cmd, 0,
  3511. DSI_CMD_PPS_SIZE - DSI_CMD_PPS_HDR_SIZE);
  3512. else if (priv_info->vdc_enabled)
  3513. dsi_vdc_create_pps_buf_cmd(&priv_info->vdc,
  3514. panel->dce_pps_cmd, 0,
  3515. DSI_CMD_PPS_SIZE - DSI_CMD_PPS_HDR_SIZE);
  3516. if (priv_info->dsc_enabled || priv_info->vdc_enabled) {
  3517. rc = dsi_panel_create_cmd_packets(panel->dce_pps_cmd,
  3518. DSI_CMD_PPS_SIZE, 1, set->cmds);
  3519. if (rc) {
  3520. DSI_ERR("failed to create cmd packets, rc=%d\n", rc);
  3521. goto error;
  3522. }
  3523. }
  3524. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PPS);
  3525. if (rc) {
  3526. DSI_ERR("[%s] failed to send DSI_CMD_SET_PPS cmds, rc=%d\n",
  3527. panel->name, rc);
  3528. }
  3529. dsi_panel_destroy_cmd_packets(set);
  3530. error:
  3531. mutex_unlock(&panel->panel_lock);
  3532. return rc;
  3533. }
  3534. int dsi_panel_set_lp1(struct dsi_panel *panel)
  3535. {
  3536. int rc = 0;
  3537. if (!panel) {
  3538. DSI_ERR("invalid params\n");
  3539. return -EINVAL;
  3540. }
  3541. mutex_lock(&panel->panel_lock);
  3542. if (!panel->panel_initialized)
  3543. goto exit;
  3544. /*
  3545. * Consider LP1->LP2->LP1.
  3546. * If the panel is already in LP mode, do not need to
  3547. * set the regulator.
  3548. * IBB and AB power mode would be set at the same time
  3549. * in PMIC driver, so we only call ibb setting that is enough.
  3550. */
  3551. if (dsi_panel_is_type_oled(panel) &&
  3552. panel->power_mode != SDE_MODE_DPMS_LP2)
  3553. dsi_pwr_panel_regulator_mode_set(&panel->power_info,
  3554. "ibb", REGULATOR_MODE_IDLE);
  3555. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_LP1);
  3556. if (rc)
  3557. DSI_ERR("[%s] failed to send DSI_CMD_SET_LP1 cmd, rc=%d\n",
  3558. panel->name, rc);
  3559. exit:
  3560. mutex_unlock(&panel->panel_lock);
  3561. return rc;
  3562. }
  3563. int dsi_panel_set_lp2(struct dsi_panel *panel)
  3564. {
  3565. int rc = 0;
  3566. if (!panel) {
  3567. DSI_ERR("invalid params\n");
  3568. return -EINVAL;
  3569. }
  3570. mutex_lock(&panel->panel_lock);
  3571. if (!panel->panel_initialized)
  3572. goto exit;
  3573. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_LP2);
  3574. if (rc)
  3575. DSI_ERR("[%s] failed to send DSI_CMD_SET_LP2 cmd, rc=%d\n",
  3576. panel->name, rc);
  3577. exit:
  3578. mutex_unlock(&panel->panel_lock);
  3579. return rc;
  3580. }
  3581. int dsi_panel_set_nolp(struct dsi_panel *panel)
  3582. {
  3583. int rc = 0;
  3584. if (!panel) {
  3585. DSI_ERR("invalid params\n");
  3586. return -EINVAL;
  3587. }
  3588. mutex_lock(&panel->panel_lock);
  3589. if (!panel->panel_initialized)
  3590. goto exit;
  3591. /*
  3592. * Consider about LP1->LP2->NOLP.
  3593. */
  3594. if (dsi_panel_is_type_oled(panel) &&
  3595. (panel->power_mode == SDE_MODE_DPMS_LP1 ||
  3596. panel->power_mode == SDE_MODE_DPMS_LP2))
  3597. dsi_pwr_panel_regulator_mode_set(&panel->power_info,
  3598. "ibb", REGULATOR_MODE_NORMAL);
  3599. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_NOLP);
  3600. if (rc)
  3601. DSI_ERR("[%s] failed to send DSI_CMD_SET_NOLP cmd, rc=%d\n",
  3602. panel->name, rc);
  3603. exit:
  3604. mutex_unlock(&panel->panel_lock);
  3605. return rc;
  3606. }
  3607. int dsi_panel_prepare(struct dsi_panel *panel)
  3608. {
  3609. int rc = 0;
  3610. if (!panel) {
  3611. DSI_ERR("invalid params\n");
  3612. return -EINVAL;
  3613. }
  3614. mutex_lock(&panel->panel_lock);
  3615. if (panel->lp11_init) {
  3616. rc = dsi_panel_power_on(panel);
  3617. if (rc) {
  3618. DSI_ERR("[%s] panel power on failed, rc=%d\n",
  3619. panel->name, rc);
  3620. goto error;
  3621. }
  3622. }
  3623. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PRE_ON);
  3624. if (rc) {
  3625. DSI_ERR("[%s] failed to send DSI_CMD_SET_PRE_ON cmds, rc=%d\n",
  3626. panel->name, rc);
  3627. goto error;
  3628. }
  3629. error:
  3630. mutex_unlock(&panel->panel_lock);
  3631. return rc;
  3632. }
  3633. static int dsi_panel_roi_prepare_dcs_cmds(struct dsi_panel_cmd_set *set,
  3634. struct dsi_rect *roi, int ctrl_idx, int unicast)
  3635. {
  3636. static const int ROI_CMD_LEN = 5;
  3637. int rc = 0;
  3638. /* DTYPE_DCS_LWRITE */
  3639. char *caset, *paset;
  3640. set->cmds = NULL;
  3641. caset = kzalloc(ROI_CMD_LEN, GFP_KERNEL);
  3642. if (!caset) {
  3643. rc = -ENOMEM;
  3644. goto exit;
  3645. }
  3646. caset[0] = 0x2a;
  3647. caset[1] = (roi->x & 0xFF00) >> 8;
  3648. caset[2] = roi->x & 0xFF;
  3649. caset[3] = ((roi->x - 1 + roi->w) & 0xFF00) >> 8;
  3650. caset[4] = (roi->x - 1 + roi->w) & 0xFF;
  3651. paset = kzalloc(ROI_CMD_LEN, GFP_KERNEL);
  3652. if (!paset) {
  3653. rc = -ENOMEM;
  3654. goto error_free_mem;
  3655. }
  3656. paset[0] = 0x2b;
  3657. paset[1] = (roi->y & 0xFF00) >> 8;
  3658. paset[2] = roi->y & 0xFF;
  3659. paset[3] = ((roi->y - 1 + roi->h) & 0xFF00) >> 8;
  3660. paset[4] = (roi->y - 1 + roi->h) & 0xFF;
  3661. set->type = DSI_CMD_SET_ROI;
  3662. set->state = DSI_CMD_SET_STATE_LP;
  3663. set->count = 2; /* send caset + paset together */
  3664. set->cmds = kcalloc(set->count, sizeof(*set->cmds), GFP_KERNEL);
  3665. if (!set->cmds) {
  3666. rc = -ENOMEM;
  3667. goto error_free_mem;
  3668. }
  3669. set->cmds[0].msg.channel = 0;
  3670. set->cmds[0].msg.type = MIPI_DSI_DCS_LONG_WRITE;
  3671. set->cmds[0].msg.flags = unicast ? MIPI_DSI_MSG_UNICAST_COMMAND : 0;
  3672. set->cmds[0].msg.tx_len = ROI_CMD_LEN;
  3673. set->cmds[0].msg.tx_buf = caset;
  3674. set->cmds[0].msg.rx_len = 0;
  3675. set->cmds[0].msg.rx_buf = 0;
  3676. set->cmds[0].last_command = 0;
  3677. set->cmds[0].post_wait_ms = 0;
  3678. set->cmds[0].ctrl = unicast ? ctrl_idx : 0;
  3679. set->cmds[1].msg.channel = 0;
  3680. set->cmds[1].msg.type = MIPI_DSI_DCS_LONG_WRITE;
  3681. set->cmds[1].msg.flags = unicast ? MIPI_DSI_MSG_UNICAST_COMMAND : 0;
  3682. set->cmds[1].msg.tx_len = ROI_CMD_LEN;
  3683. set->cmds[1].msg.tx_buf = paset;
  3684. set->cmds[1].msg.rx_len = 0;
  3685. set->cmds[1].msg.rx_buf = 0;
  3686. set->cmds[1].last_command = 1;
  3687. set->cmds[1].post_wait_ms = 0;
  3688. set->cmds[1].ctrl = unicast ? ctrl_idx : 0;
  3689. goto exit;
  3690. error_free_mem:
  3691. kfree(caset);
  3692. kfree(paset);
  3693. kfree(set->cmds);
  3694. exit:
  3695. return rc;
  3696. }
  3697. int dsi_panel_send_qsync_on_dcs(struct dsi_panel *panel,
  3698. int ctrl_idx)
  3699. {
  3700. int rc = 0;
  3701. if (!panel) {
  3702. DSI_ERR("invalid params\n");
  3703. return -EINVAL;
  3704. }
  3705. mutex_lock(&panel->panel_lock);
  3706. DSI_DEBUG("ctrl:%d qsync on\n", ctrl_idx);
  3707. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_QSYNC_ON);
  3708. if (rc)
  3709. DSI_ERR("[%s] failed to send DSI_CMD_SET_QSYNC_ON cmds rc=%d\n",
  3710. panel->name, rc);
  3711. mutex_unlock(&panel->panel_lock);
  3712. return rc;
  3713. }
  3714. int dsi_panel_send_qsync_off_dcs(struct dsi_panel *panel,
  3715. int ctrl_idx)
  3716. {
  3717. int rc = 0;
  3718. if (!panel) {
  3719. DSI_ERR("invalid params\n");
  3720. return -EINVAL;
  3721. }
  3722. mutex_lock(&panel->panel_lock);
  3723. DSI_DEBUG("ctrl:%d qsync off\n", ctrl_idx);
  3724. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_QSYNC_OFF);
  3725. if (rc)
  3726. DSI_ERR("[%s] failed to send DSI_CMD_SET_QSYNC_OFF cmds rc=%d\n",
  3727. panel->name, rc);
  3728. mutex_unlock(&panel->panel_lock);
  3729. return rc;
  3730. }
  3731. int dsi_panel_send_roi_dcs(struct dsi_panel *panel, int ctrl_idx,
  3732. struct dsi_rect *roi)
  3733. {
  3734. int rc = 0;
  3735. struct dsi_panel_cmd_set *set;
  3736. struct dsi_display_mode_priv_info *priv_info;
  3737. if (!panel || !panel->cur_mode) {
  3738. DSI_ERR("Invalid params\n");
  3739. return -EINVAL;
  3740. }
  3741. priv_info = panel->cur_mode->priv_info;
  3742. set = &priv_info->cmd_sets[DSI_CMD_SET_ROI];
  3743. rc = dsi_panel_roi_prepare_dcs_cmds(set, roi, ctrl_idx, true);
  3744. if (rc) {
  3745. DSI_ERR("[%s] failed to prepare DSI_CMD_SET_ROI cmds, rc=%d\n",
  3746. panel->name, rc);
  3747. return rc;
  3748. }
  3749. DSI_DEBUG("[%s] send roi x %d y %d w %d h %d\n", panel->name,
  3750. roi->x, roi->y, roi->w, roi->h);
  3751. SDE_EVT32(roi->x, roi->y, roi->w, roi->h);
  3752. mutex_lock(&panel->panel_lock);
  3753. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_ROI);
  3754. if (rc)
  3755. DSI_ERR("[%s] failed to send DSI_CMD_SET_ROI cmds, rc=%d\n",
  3756. panel->name, rc);
  3757. mutex_unlock(&panel->panel_lock);
  3758. dsi_panel_destroy_cmd_packets(set);
  3759. dsi_panel_dealloc_cmd_packets(set);
  3760. return rc;
  3761. }
  3762. int dsi_panel_switch_cmd_mode_out(struct dsi_panel *panel)
  3763. {
  3764. int rc = 0;
  3765. if (!panel) {
  3766. DSI_ERR("Invalid params\n");
  3767. return -EINVAL;
  3768. }
  3769. mutex_lock(&panel->panel_lock);
  3770. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_CMD_SWITCH_OUT);
  3771. if (rc)
  3772. DSI_ERR("[%s] failed to send DSI_CMD_SET_CMD_SWITCH_OUT cmds, rc=%d\n",
  3773. panel->name, rc);
  3774. mutex_unlock(&panel->panel_lock);
  3775. return rc;
  3776. }
  3777. int dsi_panel_switch_video_mode_out(struct dsi_panel *panel)
  3778. {
  3779. int rc = 0;
  3780. if (!panel) {
  3781. DSI_ERR("Invalid params\n");
  3782. return -EINVAL;
  3783. }
  3784. mutex_lock(&panel->panel_lock);
  3785. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_VID_SWITCH_OUT);
  3786. if (rc)
  3787. DSI_ERR("[%s] failed to send DSI_CMD_SET_VID_SWITCH_OUT cmds, rc=%d\n",
  3788. panel->name, rc);
  3789. mutex_unlock(&panel->panel_lock);
  3790. return rc;
  3791. }
  3792. int dsi_panel_switch_video_mode_in(struct dsi_panel *panel)
  3793. {
  3794. int rc = 0;
  3795. if (!panel) {
  3796. DSI_ERR("Invalid params\n");
  3797. return -EINVAL;
  3798. }
  3799. mutex_lock(&panel->panel_lock);
  3800. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_VID_SWITCH_IN);
  3801. if (rc)
  3802. DSI_ERR("[%s] failed to send DSI_CMD_SET_VID_SWITCH_IN cmds, rc=%d\n",
  3803. panel->name, rc);
  3804. mutex_unlock(&panel->panel_lock);
  3805. return rc;
  3806. }
  3807. int dsi_panel_switch_cmd_mode_in(struct dsi_panel *panel)
  3808. {
  3809. int rc = 0;
  3810. if (!panel) {
  3811. DSI_ERR("Invalid params\n");
  3812. return -EINVAL;
  3813. }
  3814. mutex_lock(&panel->panel_lock);
  3815. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_CMD_SWITCH_IN);
  3816. if (rc)
  3817. DSI_ERR("[%s] failed to send DSI_CMD_SET_CMD_SWITCH_IN cmds, rc=%d\n",
  3818. panel->name, rc);
  3819. mutex_unlock(&panel->panel_lock);
  3820. return rc;
  3821. }
  3822. int dsi_panel_switch(struct dsi_panel *panel)
  3823. {
  3824. int rc = 0;
  3825. if (!panel) {
  3826. DSI_ERR("Invalid params\n");
  3827. return -EINVAL;
  3828. }
  3829. mutex_lock(&panel->panel_lock);
  3830. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_TIMING_SWITCH);
  3831. if (rc)
  3832. DSI_ERR("[%s] failed to send DSI_CMD_SET_TIMING_SWITCH cmds, rc=%d\n",
  3833. panel->name, rc);
  3834. mutex_unlock(&panel->panel_lock);
  3835. return rc;
  3836. }
  3837. int dsi_panel_post_switch(struct dsi_panel *panel)
  3838. {
  3839. int rc = 0;
  3840. if (!panel) {
  3841. DSI_ERR("Invalid params\n");
  3842. return -EINVAL;
  3843. }
  3844. mutex_lock(&panel->panel_lock);
  3845. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_TIMING_SWITCH);
  3846. if (rc)
  3847. DSI_ERR("[%s] failed to send DSI_CMD_SET_POST_TIMING_SWITCH cmds, rc=%d\n",
  3848. panel->name, rc);
  3849. mutex_unlock(&panel->panel_lock);
  3850. return rc;
  3851. }
  3852. int dsi_panel_enable(struct dsi_panel *panel)
  3853. {
  3854. int rc = 0;
  3855. if (!panel) {
  3856. DSI_ERR("Invalid params\n");
  3857. return -EINVAL;
  3858. }
  3859. mutex_lock(&panel->panel_lock);
  3860. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_ON);
  3861. if (rc) {
  3862. DSI_ERR("[%s] failed to send DSI_CMD_SET_ON cmds, rc=%d\n",
  3863. panel->name, rc);
  3864. goto error;
  3865. }
  3866. if (panel->panel_mode == DSI_OP_CMD_MODE) {
  3867. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_CMD_ON);
  3868. if (rc) {
  3869. DSI_ERR("[%s] failed to send DSI_CMD_SET_CMD_ON cmds, rc=%d\n",
  3870. panel->name, rc);
  3871. goto error;
  3872. }
  3873. } else if (panel->panel_mode == DSI_OP_VIDEO_MODE) {
  3874. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_VID_ON);
  3875. if (rc) {
  3876. DSI_ERR("[%s] failed to send DSI_CMD_SET_VID_ON cmds, rc=%d\n",
  3877. panel->name, rc);
  3878. goto error;
  3879. }
  3880. }
  3881. panel->panel_initialized = true;
  3882. error:
  3883. mutex_unlock(&panel->panel_lock);
  3884. return rc;
  3885. }
  3886. int dsi_panel_post_enable(struct dsi_panel *panel)
  3887. {
  3888. int rc = 0;
  3889. if (!panel) {
  3890. DSI_ERR("invalid params\n");
  3891. return -EINVAL;
  3892. }
  3893. mutex_lock(&panel->panel_lock);
  3894. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_ON);
  3895. if (rc) {
  3896. DSI_ERR("[%s] failed to send DSI_CMD_SET_POST_ON cmds, rc=%d\n",
  3897. panel->name, rc);
  3898. goto error;
  3899. }
  3900. error:
  3901. mutex_unlock(&panel->panel_lock);
  3902. return rc;
  3903. }
  3904. int dsi_panel_pre_disable(struct dsi_panel *panel)
  3905. {
  3906. int rc = 0;
  3907. if (!panel) {
  3908. DSI_ERR("invalid params\n");
  3909. return -EINVAL;
  3910. }
  3911. mutex_lock(&panel->panel_lock);
  3912. if (gpio_is_valid(panel->bl_config.en_gpio))
  3913. gpio_set_value(panel->bl_config.en_gpio, 0);
  3914. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PRE_OFF);
  3915. if (rc) {
  3916. DSI_ERR("[%s] failed to send DSI_CMD_SET_PRE_OFF cmds, rc=%d\n",
  3917. panel->name, rc);
  3918. goto error;
  3919. }
  3920. error:
  3921. mutex_unlock(&panel->panel_lock);
  3922. return rc;
  3923. }
  3924. int dsi_panel_disable(struct dsi_panel *panel)
  3925. {
  3926. int rc = 0;
  3927. if (!panel) {
  3928. DSI_ERR("invalid params\n");
  3929. return -EINVAL;
  3930. }
  3931. mutex_lock(&panel->panel_lock);
  3932. /* Avoid sending panel off commands when ESD recovery is underway */
  3933. if (!atomic_read(&panel->esd_recovery_pending)) {
  3934. /*
  3935. * Need to set IBB/AB regulator mode to STANDBY,
  3936. * if panel is going off from AOD mode.
  3937. */
  3938. if (dsi_panel_is_type_oled(panel) &&
  3939. (panel->power_mode == SDE_MODE_DPMS_LP1 ||
  3940. panel->power_mode == SDE_MODE_DPMS_LP2))
  3941. dsi_pwr_panel_regulator_mode_set(&panel->power_info,
  3942. "ibb", REGULATOR_MODE_STANDBY);
  3943. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_OFF);
  3944. if (rc) {
  3945. /*
  3946. * Sending panel off commands may fail when DSI
  3947. * controller is in a bad state. These failures can be
  3948. * ignored since controller will go for full reset on
  3949. * subsequent display enable anyway.
  3950. */
  3951. pr_warn_ratelimited("[%s] failed to send DSI_CMD_SET_OFF cmds, rc=%d\n",
  3952. panel->name, rc);
  3953. rc = 0;
  3954. }
  3955. }
  3956. panel->panel_initialized = false;
  3957. panel->power_mode = SDE_MODE_DPMS_OFF;
  3958. mutex_unlock(&panel->panel_lock);
  3959. return rc;
  3960. }
  3961. int dsi_panel_unprepare(struct dsi_panel *panel)
  3962. {
  3963. int rc = 0;
  3964. if (!panel) {
  3965. DSI_ERR("invalid params\n");
  3966. return -EINVAL;
  3967. }
  3968. mutex_lock(&panel->panel_lock);
  3969. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_OFF);
  3970. if (rc) {
  3971. DSI_ERR("[%s] failed to send DSI_CMD_SET_POST_OFF cmds, rc=%d\n",
  3972. panel->name, rc);
  3973. goto error;
  3974. }
  3975. error:
  3976. mutex_unlock(&panel->panel_lock);
  3977. return rc;
  3978. }
  3979. int dsi_panel_post_unprepare(struct dsi_panel *panel)
  3980. {
  3981. int rc = 0;
  3982. if (!panel) {
  3983. DSI_ERR("invalid params\n");
  3984. return -EINVAL;
  3985. }
  3986. mutex_lock(&panel->panel_lock);
  3987. rc = dsi_panel_power_off(panel);
  3988. if (rc) {
  3989. DSI_ERR("[%s] panel power_Off failed, rc=%d\n",
  3990. panel->name, rc);
  3991. goto error;
  3992. }
  3993. error:
  3994. mutex_unlock(&panel->panel_lock);
  3995. return rc;
  3996. }