dsi_panel.c 125 KB

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