dsi_display.c 210 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/list.h>
  6. #include <linux/of.h>
  7. #include <linux/of_gpio.h>
  8. #include <linux/err.h>
  9. #include "msm_drv.h"
  10. #include "sde_connector.h"
  11. #include "msm_mmu.h"
  12. #include "dsi_display.h"
  13. #include "dsi_panel.h"
  14. #include "dsi_ctrl.h"
  15. #include "dsi_ctrl_hw.h"
  16. #include "dsi_drm.h"
  17. #include "dsi_clk.h"
  18. #include "dsi_pwr.h"
  19. #include "sde_dbg.h"
  20. #include "dsi_parser.h"
  21. #define to_dsi_display(x) container_of(x, struct dsi_display, host)
  22. #define INT_BASE_10 10
  23. #define MISR_BUFF_SIZE 256
  24. #define ESD_MODE_STRING_MAX_LEN 256
  25. #define ESD_TRIGGER_STRING_MAX_LEN 10
  26. #define MAX_NAME_SIZE 64
  27. #define MAX_TE_RECHECKS 5
  28. #define DSI_CLOCK_BITRATE_RADIX 10
  29. #define MAX_TE_SOURCE_ID 2
  30. #define SEC_PANEL_NAME_MAX_LEN 256
  31. u8 dbgfs_tx_cmd_buf[SZ_4K];
  32. static char dsi_display_primary[MAX_CMDLINE_PARAM_LEN];
  33. static char dsi_display_secondary[MAX_CMDLINE_PARAM_LEN];
  34. static struct dsi_display_boot_param boot_displays[MAX_DSI_ACTIVE_DISPLAY] = {
  35. {.boot_param = dsi_display_primary},
  36. {.boot_param = dsi_display_secondary},
  37. };
  38. static const struct of_device_id dsi_display_dt_match[] = {
  39. {.compatible = "qcom,dsi-display"},
  40. {}
  41. };
  42. bool is_skip_op_required(struct dsi_display *display)
  43. {
  44. if (!display)
  45. return false;
  46. return (display->is_cont_splash_enabled || display->trusted_vm_env);
  47. }
  48. static void dsi_display_mask_ctrl_error_interrupts(struct dsi_display *display,
  49. u32 mask, bool enable)
  50. {
  51. int i;
  52. struct dsi_display_ctrl *ctrl;
  53. if (!display)
  54. return;
  55. display_for_each_ctrl(i, display) {
  56. ctrl = &display->ctrl[i];
  57. if (!ctrl)
  58. continue;
  59. dsi_ctrl_mask_error_status_interrupts(ctrl->ctrl, mask, enable);
  60. }
  61. }
  62. static int dsi_display_config_clk_gating(struct dsi_display *display,
  63. bool enable)
  64. {
  65. int rc = 0, i = 0;
  66. struct dsi_display_ctrl *mctrl, *ctrl;
  67. enum dsi_clk_gate_type clk_selection;
  68. enum dsi_clk_gate_type const default_clk_select = PIXEL_CLK | DSI_PHY;
  69. if (!display) {
  70. DSI_ERR("Invalid params\n");
  71. return -EINVAL;
  72. }
  73. if (display->panel->host_config.force_hs_clk_lane) {
  74. DSI_DEBUG("no dsi clock gating for continuous clock mode\n");
  75. return 0;
  76. }
  77. mctrl = &display->ctrl[display->clk_master_idx];
  78. if (!mctrl) {
  79. DSI_ERR("Invalid controller\n");
  80. return -EINVAL;
  81. }
  82. clk_selection = display->clk_gating_config;
  83. if (!enable) {
  84. /* for disable path, make sure to disable all clk gating */
  85. clk_selection = DSI_CLK_ALL;
  86. } else if (!clk_selection || clk_selection > DSI_CLK_NONE) {
  87. /* Default selection, no overrides */
  88. clk_selection = default_clk_select;
  89. } else if (clk_selection == DSI_CLK_NONE) {
  90. clk_selection = 0;
  91. }
  92. DSI_DEBUG("%s clock gating Byte:%s Pixel:%s PHY:%s\n",
  93. enable ? "Enabling" : "Disabling",
  94. clk_selection & BYTE_CLK ? "yes" : "no",
  95. clk_selection & PIXEL_CLK ? "yes" : "no",
  96. clk_selection & DSI_PHY ? "yes" : "no");
  97. rc = dsi_ctrl_config_clk_gating(mctrl->ctrl, enable, clk_selection);
  98. if (rc) {
  99. DSI_ERR("[%s] failed to %s clk gating for clocks %d, rc=%d\n",
  100. display->name, enable ? "enable" : "disable",
  101. clk_selection, rc);
  102. return rc;
  103. }
  104. display_for_each_ctrl(i, display) {
  105. ctrl = &display->ctrl[i];
  106. if (!ctrl->ctrl || (ctrl == mctrl))
  107. continue;
  108. /**
  109. * In Split DSI usecase we should not enable clock gating on
  110. * DSI PHY1 to ensure no display atrifacts are seen.
  111. */
  112. clk_selection &= ~DSI_PHY;
  113. rc = dsi_ctrl_config_clk_gating(ctrl->ctrl, enable,
  114. clk_selection);
  115. if (rc) {
  116. DSI_ERR("[%s] failed to %s clk gating for clocks %d, rc=%d\n",
  117. display->name, enable ? "enable" : "disable",
  118. clk_selection, rc);
  119. return rc;
  120. }
  121. }
  122. return 0;
  123. }
  124. static void dsi_display_set_ctrl_esd_check_flag(struct dsi_display *display,
  125. bool enable)
  126. {
  127. int i;
  128. struct dsi_display_ctrl *ctrl;
  129. if (!display)
  130. return;
  131. display_for_each_ctrl(i, display) {
  132. ctrl = &display->ctrl[i];
  133. if (!ctrl)
  134. continue;
  135. ctrl->ctrl->esd_check_underway = enable;
  136. }
  137. }
  138. static void dsi_display_ctrl_irq_update(struct dsi_display *display, bool en)
  139. {
  140. int i;
  141. struct dsi_display_ctrl *ctrl;
  142. if (!display)
  143. return;
  144. display_for_each_ctrl(i, display) {
  145. ctrl = &display->ctrl[i];
  146. if (!ctrl)
  147. continue;
  148. dsi_ctrl_irq_update(ctrl->ctrl, en);
  149. }
  150. }
  151. void dsi_rect_intersect(const struct dsi_rect *r1,
  152. const struct dsi_rect *r2,
  153. struct dsi_rect *result)
  154. {
  155. int l, t, r, b;
  156. if (!r1 || !r2 || !result)
  157. return;
  158. l = max(r1->x, r2->x);
  159. t = max(r1->y, r2->y);
  160. r = min((r1->x + r1->w), (r2->x + r2->w));
  161. b = min((r1->y + r1->h), (r2->y + r2->h));
  162. if (r <= l || b <= t) {
  163. memset(result, 0, sizeof(*result));
  164. } else {
  165. result->x = l;
  166. result->y = t;
  167. result->w = r - l;
  168. result->h = b - t;
  169. }
  170. }
  171. int dsi_display_set_backlight(struct drm_connector *connector,
  172. void *display, u32 bl_lvl)
  173. {
  174. struct dsi_display *dsi_display = display;
  175. struct dsi_panel *panel;
  176. u32 bl_scale, bl_scale_sv;
  177. u64 bl_temp;
  178. int rc = 0;
  179. if (dsi_display == NULL || dsi_display->panel == NULL)
  180. return -EINVAL;
  181. panel = dsi_display->panel;
  182. mutex_lock(&panel->panel_lock);
  183. if (!dsi_panel_initialized(panel)) {
  184. rc = -EINVAL;
  185. goto error;
  186. }
  187. panel->bl_config.bl_level = bl_lvl;
  188. /* scale backlight */
  189. bl_scale = panel->bl_config.bl_scale;
  190. bl_temp = bl_lvl * bl_scale / MAX_BL_SCALE_LEVEL;
  191. bl_scale_sv = panel->bl_config.bl_scale_sv;
  192. bl_temp = (u32)bl_temp * bl_scale_sv / MAX_SV_BL_SCALE_LEVEL;
  193. DSI_DEBUG("bl_scale = %u, bl_scale_sv = %u, bl_lvl = %u\n",
  194. bl_scale, bl_scale_sv, (u32)bl_temp);
  195. rc = dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  196. DSI_CORE_CLK, DSI_CLK_ON);
  197. if (rc) {
  198. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  199. dsi_display->name, rc);
  200. goto error;
  201. }
  202. rc = dsi_panel_set_backlight(panel, (u32)bl_temp);
  203. if (rc)
  204. DSI_ERR("unable to set backlight\n");
  205. rc = dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  206. DSI_CORE_CLK, DSI_CLK_OFF);
  207. if (rc) {
  208. DSI_ERR("[%s] failed to disable DSI core clocks, rc=%d\n",
  209. dsi_display->name, rc);
  210. goto error;
  211. }
  212. error:
  213. mutex_unlock(&panel->panel_lock);
  214. return rc;
  215. }
  216. static int dsi_display_cmd_engine_enable(struct dsi_display *display)
  217. {
  218. int rc = 0;
  219. int i;
  220. struct dsi_display_ctrl *m_ctrl, *ctrl;
  221. bool skip_op = is_skip_op_required(display);
  222. m_ctrl = &display->ctrl[display->cmd_master_idx];
  223. mutex_lock(&m_ctrl->ctrl->ctrl_lock);
  224. if (display->cmd_engine_refcount > 0) {
  225. display->cmd_engine_refcount++;
  226. goto done;
  227. }
  228. rc = dsi_ctrl_set_cmd_engine_state(m_ctrl->ctrl,
  229. DSI_CTRL_ENGINE_ON, skip_op);
  230. if (rc) {
  231. DSI_ERR("[%s] enable mcmd engine failed, skip_op:%d rc:%d\n",
  232. display->name, skip_op, rc);
  233. goto done;
  234. }
  235. display_for_each_ctrl(i, display) {
  236. ctrl = &display->ctrl[i];
  237. if (!ctrl->ctrl || (ctrl == m_ctrl))
  238. continue;
  239. rc = dsi_ctrl_set_cmd_engine_state(ctrl->ctrl,
  240. DSI_CTRL_ENGINE_ON, skip_op);
  241. if (rc) {
  242. DSI_ERR(
  243. "[%s] enable cmd engine failed, skip_op:%d rc:%d\n",
  244. display->name, skip_op, rc);
  245. goto error_disable_master;
  246. }
  247. }
  248. display->cmd_engine_refcount++;
  249. goto done;
  250. error_disable_master:
  251. (void)dsi_ctrl_set_cmd_engine_state(m_ctrl->ctrl,
  252. DSI_CTRL_ENGINE_OFF, skip_op);
  253. done:
  254. mutex_unlock(&m_ctrl->ctrl->ctrl_lock);
  255. return rc;
  256. }
  257. static int dsi_display_cmd_engine_disable(struct dsi_display *display)
  258. {
  259. int rc = 0;
  260. int i;
  261. struct dsi_display_ctrl *m_ctrl, *ctrl;
  262. bool skip_op = is_skip_op_required(display);
  263. m_ctrl = &display->ctrl[display->cmd_master_idx];
  264. mutex_lock(&m_ctrl->ctrl->ctrl_lock);
  265. if (display->cmd_engine_refcount == 0) {
  266. DSI_ERR("[%s] Invalid refcount\n", display->name);
  267. goto done;
  268. } else if (display->cmd_engine_refcount > 1) {
  269. display->cmd_engine_refcount--;
  270. goto done;
  271. }
  272. display_for_each_ctrl(i, display) {
  273. ctrl = &display->ctrl[i];
  274. if (!ctrl->ctrl || (ctrl == m_ctrl))
  275. continue;
  276. rc = dsi_ctrl_set_cmd_engine_state(ctrl->ctrl,
  277. DSI_CTRL_ENGINE_OFF, skip_op);
  278. if (rc)
  279. DSI_ERR(
  280. "[%s] disable cmd engine failed, skip_op:%d rc:%d\n",
  281. display->name, skip_op, rc);
  282. }
  283. rc = dsi_ctrl_set_cmd_engine_state(m_ctrl->ctrl,
  284. DSI_CTRL_ENGINE_OFF, skip_op);
  285. if (rc) {
  286. DSI_ERR("[%s] disable mcmd engine failed, skip_op:%d rc:%d\n",
  287. display->name, skip_op, rc);
  288. goto error;
  289. }
  290. error:
  291. display->cmd_engine_refcount = 0;
  292. done:
  293. mutex_unlock(&m_ctrl->ctrl->ctrl_lock);
  294. return rc;
  295. }
  296. static void dsi_display_aspace_cb_locked(void *cb_data, bool is_detach)
  297. {
  298. struct dsi_display *display;
  299. struct dsi_display_ctrl *display_ctrl;
  300. int rc, cnt;
  301. if (!cb_data) {
  302. DSI_ERR("aspace cb called with invalid cb_data\n");
  303. return;
  304. }
  305. display = (struct dsi_display *)cb_data;
  306. /*
  307. * acquire panel_lock to make sure no commands are in-progress
  308. * while detaching the non-secure context banks
  309. */
  310. dsi_panel_acquire_panel_lock(display->panel);
  311. if (is_detach) {
  312. /* invalidate the stored iova */
  313. display->cmd_buffer_iova = 0;
  314. /* return the virtual address mapping */
  315. msm_gem_put_vaddr(display->tx_cmd_buf);
  316. msm_gem_vunmap(display->tx_cmd_buf, OBJ_LOCK_NORMAL);
  317. } else {
  318. rc = msm_gem_get_iova(display->tx_cmd_buf,
  319. display->aspace, &(display->cmd_buffer_iova));
  320. if (rc) {
  321. DSI_ERR("failed to get the iova rc %d\n", rc);
  322. goto end;
  323. }
  324. display->vaddr =
  325. (void *) msm_gem_get_vaddr(display->tx_cmd_buf);
  326. if (IS_ERR_OR_NULL(display->vaddr)) {
  327. DSI_ERR("failed to get va rc %d\n", rc);
  328. goto end;
  329. }
  330. }
  331. display_for_each_ctrl(cnt, display) {
  332. display_ctrl = &display->ctrl[cnt];
  333. display_ctrl->ctrl->cmd_buffer_size = display->cmd_buffer_size;
  334. display_ctrl->ctrl->cmd_buffer_iova = display->cmd_buffer_iova;
  335. display_ctrl->ctrl->vaddr = display->vaddr;
  336. display_ctrl->ctrl->secure_mode = is_detach;
  337. }
  338. end:
  339. /* release panel_lock */
  340. dsi_panel_release_panel_lock(display->panel);
  341. }
  342. static irqreturn_t dsi_display_panel_te_irq_handler(int irq, void *data)
  343. {
  344. struct dsi_display *display = (struct dsi_display *)data;
  345. /*
  346. * This irq handler is used for sole purpose of identifying
  347. * ESD attacks on panel and we can safely assume IRQ_HANDLED
  348. * in case of display not being initialized yet
  349. */
  350. if (!display)
  351. return IRQ_HANDLED;
  352. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1);
  353. complete_all(&display->esd_te_gate);
  354. return IRQ_HANDLED;
  355. }
  356. static void dsi_display_change_te_irq_status(struct dsi_display *display,
  357. bool enable)
  358. {
  359. if (!display) {
  360. DSI_ERR("Invalid params\n");
  361. return;
  362. }
  363. /* Handle unbalanced irq enable/disable calls */
  364. if (enable && !display->is_te_irq_enabled) {
  365. enable_irq(gpio_to_irq(display->disp_te_gpio));
  366. display->is_te_irq_enabled = true;
  367. } else if (!enable && display->is_te_irq_enabled) {
  368. disable_irq(gpio_to_irq(display->disp_te_gpio));
  369. display->is_te_irq_enabled = false;
  370. }
  371. }
  372. static void dsi_display_register_te_irq(struct dsi_display *display)
  373. {
  374. int rc = 0;
  375. struct platform_device *pdev;
  376. struct device *dev;
  377. unsigned int te_irq;
  378. pdev = display->pdev;
  379. if (!pdev) {
  380. DSI_ERR("invalid platform device\n");
  381. return;
  382. }
  383. dev = &pdev->dev;
  384. if (!dev) {
  385. DSI_ERR("invalid device\n");
  386. return;
  387. }
  388. if (display->trusted_vm_env) {
  389. DSI_INFO("GPIO's are not enabled in trusted VM\n");
  390. return;
  391. }
  392. if (!gpio_is_valid(display->disp_te_gpio)) {
  393. rc = -EINVAL;
  394. goto error;
  395. }
  396. init_completion(&display->esd_te_gate);
  397. te_irq = gpio_to_irq(display->disp_te_gpio);
  398. /* Avoid deferred spurious irqs with disable_irq() */
  399. irq_set_status_flags(te_irq, IRQ_DISABLE_UNLAZY);
  400. rc = devm_request_irq(dev, te_irq, dsi_display_panel_te_irq_handler,
  401. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  402. "TE_GPIO", display);
  403. if (rc) {
  404. DSI_ERR("TE request_irq failed for ESD rc:%d\n", rc);
  405. irq_clear_status_flags(te_irq, IRQ_DISABLE_UNLAZY);
  406. goto error;
  407. }
  408. disable_irq(te_irq);
  409. display->is_te_irq_enabled = false;
  410. return;
  411. error:
  412. /* disable the TE based ESD check */
  413. DSI_WARN("Unable to register for TE IRQ\n");
  414. if (display->panel->esd_config.status_mode == ESD_MODE_PANEL_TE)
  415. display->panel->esd_config.esd_enabled = false;
  416. }
  417. /* Allocate memory for cmd dma tx buffer */
  418. static int dsi_host_alloc_cmd_tx_buffer(struct dsi_display *display)
  419. {
  420. int rc = 0, cnt = 0;
  421. struct dsi_display_ctrl *display_ctrl;
  422. display->tx_cmd_buf = msm_gem_new(display->drm_dev,
  423. SZ_4K,
  424. MSM_BO_UNCACHED);
  425. if ((display->tx_cmd_buf) == NULL) {
  426. DSI_ERR("Failed to allocate cmd tx buf memory\n");
  427. rc = -ENOMEM;
  428. goto error;
  429. }
  430. display->cmd_buffer_size = SZ_4K;
  431. display->aspace = msm_gem_smmu_address_space_get(
  432. display->drm_dev, MSM_SMMU_DOMAIN_UNSECURE);
  433. if (PTR_ERR(display->aspace) == -ENODEV) {
  434. display->aspace = NULL;
  435. DSI_DEBUG("IOMMU not present, relying on VRAM\n");
  436. } else if (IS_ERR_OR_NULL(display->aspace)) {
  437. rc = PTR_ERR(display->aspace);
  438. display->aspace = NULL;
  439. DSI_ERR("failed to get aspace %d\n", rc);
  440. goto free_gem;
  441. } else if (display->aspace) {
  442. /* register to aspace */
  443. rc = msm_gem_address_space_register_cb(display->aspace,
  444. dsi_display_aspace_cb_locked, (void *)display);
  445. if (rc) {
  446. DSI_ERR("failed to register callback %d\n", rc);
  447. goto free_gem;
  448. }
  449. }
  450. rc = msm_gem_get_iova(display->tx_cmd_buf, display->aspace,
  451. &(display->cmd_buffer_iova));
  452. if (rc) {
  453. DSI_ERR("failed to get the iova rc %d\n", rc);
  454. goto free_aspace_cb;
  455. }
  456. display->vaddr =
  457. (void *) msm_gem_get_vaddr(display->tx_cmd_buf);
  458. if (IS_ERR_OR_NULL(display->vaddr)) {
  459. DSI_ERR("failed to get va rc %d\n", rc);
  460. rc = -EINVAL;
  461. goto put_iova;
  462. }
  463. display_for_each_ctrl(cnt, display) {
  464. display_ctrl = &display->ctrl[cnt];
  465. display_ctrl->ctrl->cmd_buffer_size = SZ_4K;
  466. display_ctrl->ctrl->cmd_buffer_iova =
  467. display->cmd_buffer_iova;
  468. display_ctrl->ctrl->vaddr = display->vaddr;
  469. display_ctrl->ctrl->tx_cmd_buf = display->tx_cmd_buf;
  470. }
  471. return rc;
  472. put_iova:
  473. msm_gem_put_iova(display->tx_cmd_buf, display->aspace);
  474. free_aspace_cb:
  475. msm_gem_address_space_unregister_cb(display->aspace,
  476. dsi_display_aspace_cb_locked, display);
  477. free_gem:
  478. mutex_lock(&display->drm_dev->struct_mutex);
  479. msm_gem_free_object(display->tx_cmd_buf);
  480. mutex_unlock(&display->drm_dev->struct_mutex);
  481. error:
  482. return rc;
  483. }
  484. static bool dsi_display_validate_reg_read(struct dsi_panel *panel)
  485. {
  486. int i, j = 0;
  487. int len = 0, *lenp;
  488. int group = 0, count = 0;
  489. struct drm_panel_esd_config *config;
  490. if (!panel)
  491. return false;
  492. config = &(panel->esd_config);
  493. lenp = config->status_valid_params ?: config->status_cmds_rlen;
  494. count = config->status_cmd.count;
  495. for (i = 0; i < count; i++)
  496. len += lenp[i];
  497. for (i = 0; i < len; i++)
  498. j += len;
  499. for (j = 0; j < config->groups; ++j) {
  500. for (i = 0; i < len; ++i) {
  501. if (config->return_buf[i] !=
  502. config->status_value[group + i]) {
  503. DRM_ERROR("mismatch: 0x%x\n",
  504. config->return_buf[i]);
  505. break;
  506. }
  507. }
  508. if (i == len)
  509. return true;
  510. group += len;
  511. }
  512. return false;
  513. }
  514. static void dsi_display_parse_te_data(struct dsi_display *display)
  515. {
  516. struct platform_device *pdev;
  517. struct device *dev;
  518. int rc = 0;
  519. u32 val = 0;
  520. pdev = display->pdev;
  521. if (!pdev) {
  522. DSI_ERR("Invalid platform device\n");
  523. return;
  524. }
  525. dev = &pdev->dev;
  526. if (!dev) {
  527. DSI_ERR("Invalid platform device\n");
  528. return;
  529. }
  530. display->disp_te_gpio = of_get_named_gpio(dev->of_node,
  531. "qcom,platform-te-gpio", 0);
  532. if (display->fw)
  533. rc = dsi_parser_read_u32(display->parser_node,
  534. "qcom,panel-te-source", &val);
  535. else
  536. rc = of_property_read_u32(dev->of_node,
  537. "qcom,panel-te-source", &val);
  538. if (rc || (val > MAX_TE_SOURCE_ID)) {
  539. DSI_ERR("invalid vsync source selection\n");
  540. val = 0;
  541. }
  542. display->te_source = val;
  543. }
  544. static void dsi_display_set_cmd_tx_ctrl_flags(struct dsi_display *display,
  545. struct dsi_cmd_desc *cmd)
  546. {
  547. struct dsi_display_ctrl *ctrl, *m_ctrl;
  548. struct mipi_dsi_msg *msg = &cmd->msg;
  549. u32 flags = 0;
  550. int i = 0;
  551. m_ctrl = &display->ctrl[display->clk_master_idx];
  552. display_for_each_ctrl(i, display) {
  553. ctrl = &display->ctrl[i];
  554. if (!ctrl->ctrl)
  555. continue;
  556. /*
  557. * Set cmd transfer mode flags.
  558. * 1) Default selection is CMD fetch from memory.
  559. * 2) In secure session override and use FIFO rather than
  560. * memory.
  561. * 3) If cmd_len is greater than FIFO size non embedded mode of
  562. * tx is used.
  563. */
  564. flags = DSI_CTRL_CMD_FETCH_MEMORY;
  565. if (ctrl->ctrl->secure_mode) {
  566. flags &= ~DSI_CTRL_CMD_FETCH_MEMORY;
  567. flags |= DSI_CTRL_CMD_FIFO_STORE;
  568. } else if (msg->tx_len > DSI_EMBEDDED_MODE_DMA_MAX_SIZE_BYTES) {
  569. flags |= DSI_CTRL_CMD_NON_EMBEDDED_MODE;
  570. }
  571. /* Set flags needed for broadcast. Read commands are always unicast */
  572. if (!(msg->flags & MIPI_DSI_MSG_UNICAST_COMMAND) && (display->ctrl_count > 1))
  573. flags |= DSI_CTRL_CMD_BROADCAST | DSI_CTRL_CMD_DEFER_TRIGGER;
  574. /*
  575. * Set flags for command scheduling.
  576. * 1) In video mode command DMA scheduling is default.
  577. * 2) In command mode command DMA scheduling depends on message
  578. * flag and TE needs to be running.
  579. */
  580. if (display->panel->panel_mode == DSI_OP_VIDEO_MODE) {
  581. flags |= DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  582. } else {
  583. if (msg->flags & MIPI_DSI_MSG_CMD_DMA_SCHED)
  584. flags |= DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  585. if (!display->enabled)
  586. flags &= ~DSI_CTRL_CMD_CUSTOM_DMA_SCHED;
  587. }
  588. /* Set flags for last command */
  589. if (!(msg->flags & MIPI_DSI_MSG_BATCH_COMMAND))
  590. flags |= DSI_CTRL_CMD_LAST_COMMAND;
  591. /*
  592. * Set flags for asynchronous wait.
  593. * Asynchronous wait is supported in the following scenarios
  594. * 1) queue_cmd_waits is set by connector and
  595. * - commands are not sent using DSI FIFO memory
  596. * - commands are not sent in non-embedded mode
  597. * - not a video mode panel
  598. * - no explicit msg post_wait_ms is specified
  599. * - not a read command
  600. * 2) if async override msg flag is present
  601. */
  602. if (display->queue_cmd_waits)
  603. if (!(flags & DSI_CTRL_CMD_FIFO_STORE) &&
  604. !(flags & DSI_CTRL_CMD_NON_EMBEDDED_MODE) &&
  605. !(display->panel->panel_mode == DSI_OP_VIDEO_MODE) &&
  606. (cmd->post_wait_ms == 0) &&
  607. !(cmd->ctrl_flags & DSI_CTRL_CMD_READ))
  608. flags |= DSI_CTRL_CMD_ASYNC_WAIT;
  609. if (msg->flags & MIPI_DSI_MSG_ASYNC_OVERRIDE)
  610. flags |= DSI_CTRL_CMD_ASYNC_WAIT;
  611. }
  612. cmd->ctrl_flags |= flags;
  613. }
  614. static int dsi_display_read_status(struct dsi_display_ctrl *ctrl,
  615. struct dsi_display *display)
  616. {
  617. int i, rc = 0, count = 0, start = 0, *lenp;
  618. struct drm_panel_esd_config *config;
  619. struct dsi_cmd_desc *cmds;
  620. struct dsi_panel *panel;
  621. u32 flags = 0;
  622. if (!display->panel || !ctrl || !ctrl->ctrl)
  623. return -EINVAL;
  624. panel = display->panel;
  625. /*
  626. * When DSI controller is not in initialized state, we do not want to
  627. * report a false ESD failure and hence we defer until next read
  628. * happen.
  629. */
  630. if (!dsi_ctrl_validate_host_state(ctrl->ctrl))
  631. return 1;
  632. config = &(panel->esd_config);
  633. lenp = config->status_valid_params ?: config->status_cmds_rlen;
  634. count = config->status_cmd.count;
  635. cmds = config->status_cmd.cmds;
  636. flags = DSI_CTRL_CMD_READ;
  637. for (i = 0; i < count; ++i) {
  638. memset(config->status_buf, 0x0, SZ_4K);
  639. if (config->status_cmd.state == DSI_CMD_SET_STATE_LP)
  640. cmds[i].msg.flags |= MIPI_DSI_MSG_USE_LPM;
  641. cmds[i].msg.flags |= MIPI_DSI_MSG_UNICAST_COMMAND;
  642. cmds[i].msg.rx_buf = config->status_buf;
  643. cmds[i].msg.rx_len = config->status_cmds_rlen[i];
  644. cmds[i].ctrl_flags = flags;
  645. dsi_display_set_cmd_tx_ctrl_flags(display,&cmds[i]);
  646. rc = dsi_ctrl_cmd_transfer(ctrl->ctrl, &cmds[i]);
  647. if (rc <= 0) {
  648. DSI_ERR("rx cmd transfer failed rc=%d\n", rc);
  649. return rc;
  650. }
  651. memcpy(config->return_buf + start,
  652. config->status_buf, lenp[i]);
  653. start += lenp[i];
  654. }
  655. return rc;
  656. }
  657. static int dsi_display_validate_status(struct dsi_display_ctrl *ctrl,
  658. struct dsi_display *display)
  659. {
  660. int rc = 0;
  661. rc = dsi_display_read_status(ctrl, display);
  662. if (rc <= 0) {
  663. goto exit;
  664. } else {
  665. /*
  666. * panel status read successfully.
  667. * check for validity of the data read back.
  668. */
  669. rc = dsi_display_validate_reg_read(display->panel);
  670. if (!rc) {
  671. rc = -EINVAL;
  672. goto exit;
  673. }
  674. }
  675. exit:
  676. return rc;
  677. }
  678. static int dsi_display_status_reg_read(struct dsi_display *display)
  679. {
  680. int rc = 0, i;
  681. struct dsi_display_ctrl *m_ctrl, *ctrl;
  682. DSI_DEBUG(" ++\n");
  683. m_ctrl = &display->ctrl[display->cmd_master_idx];
  684. if (display->tx_cmd_buf == NULL) {
  685. rc = dsi_host_alloc_cmd_tx_buffer(display);
  686. if (rc) {
  687. DSI_ERR("failed to allocate cmd tx buffer memory\n");
  688. goto done;
  689. }
  690. }
  691. rc = dsi_display_cmd_engine_enable(display);
  692. if (rc) {
  693. DSI_ERR("cmd engine enable failed\n");
  694. return -EPERM;
  695. }
  696. rc = dsi_display_validate_status(m_ctrl, display);
  697. if (rc <= 0) {
  698. DSI_ERR("[%s] read status failed on master,rc=%d\n",
  699. display->name, rc);
  700. goto exit;
  701. }
  702. if (!display->panel->sync_broadcast_en)
  703. goto exit;
  704. display_for_each_ctrl(i, display) {
  705. ctrl = &display->ctrl[i];
  706. if (ctrl == m_ctrl)
  707. continue;
  708. rc = dsi_display_validate_status(ctrl, display);
  709. if (rc <= 0) {
  710. DSI_ERR("[%s] read status failed on slave,rc=%d\n",
  711. display->name, rc);
  712. goto exit;
  713. }
  714. }
  715. exit:
  716. dsi_display_cmd_engine_disable(display);
  717. done:
  718. return rc;
  719. }
  720. static int dsi_display_status_bta_request(struct dsi_display *display)
  721. {
  722. int rc = 0;
  723. DSI_DEBUG(" ++\n");
  724. /* TODO: trigger SW BTA and wait for acknowledgment */
  725. return rc;
  726. }
  727. static void dsi_display_release_te_irq(struct dsi_display *display)
  728. {
  729. int te_irq = 0;
  730. te_irq = gpio_to_irq(display->disp_te_gpio);
  731. if (te_irq)
  732. free_irq(te_irq, display);
  733. }
  734. static int dsi_display_status_check_te(struct dsi_display *display,
  735. int rechecks)
  736. {
  737. int rc = 1, i = 0;
  738. int const esd_te_timeout = msecs_to_jiffies(3*20);
  739. if (!rechecks)
  740. return rc;
  741. /* register te irq handler */
  742. dsi_display_register_te_irq(display);
  743. dsi_display_change_te_irq_status(display, true);
  744. for (i = 0; i < rechecks; i++) {
  745. reinit_completion(&display->esd_te_gate);
  746. if (!wait_for_completion_timeout(&display->esd_te_gate,
  747. esd_te_timeout)) {
  748. DSI_ERR("TE check failed\n");
  749. dsi_display_change_te_irq_status(display, false);
  750. return -EINVAL;
  751. }
  752. }
  753. dsi_display_change_te_irq_status(display, false);
  754. dsi_display_release_te_irq(display);
  755. return rc;
  756. }
  757. int dsi_display_check_status(struct drm_connector *connector, void *display,
  758. bool te_check_override)
  759. {
  760. struct dsi_display *dsi_display = display;
  761. struct dsi_panel *panel;
  762. u32 status_mode;
  763. int rc = 0x1, ret;
  764. u32 mask;
  765. int te_rechecks = 1;
  766. if (!dsi_display || !dsi_display->panel)
  767. return -EINVAL;
  768. panel = dsi_display->panel;
  769. dsi_panel_acquire_panel_lock(panel);
  770. if (!panel->panel_initialized) {
  771. DSI_DEBUG("Panel not initialized\n");
  772. goto release_panel_lock;
  773. }
  774. /* Prevent another ESD check,when ESD recovery is underway */
  775. if (atomic_read(&panel->esd_recovery_pending))
  776. goto release_panel_lock;
  777. status_mode = panel->esd_config.status_mode;
  778. if ((status_mode == ESD_MODE_SW_SIM_SUCCESS) ||
  779. (dsi_display->sw_te_using_wd))
  780. goto release_panel_lock;
  781. if (status_mode == ESD_MODE_SW_SIM_FAILURE) {
  782. rc = -EINVAL;
  783. goto release_panel_lock;
  784. }
  785. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, status_mode, te_check_override);
  786. if (te_check_override)
  787. te_rechecks = MAX_TE_RECHECKS;
  788. if ((dsi_display->trusted_vm_env) ||
  789. (panel->panel_mode == DSI_OP_VIDEO_MODE))
  790. te_rechecks = 0;
  791. ret = dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  792. DSI_ALL_CLKS, DSI_CLK_ON);
  793. if (ret)
  794. goto release_panel_lock;
  795. /* Mask error interrupts before attempting ESD read */
  796. mask = BIT(DSI_FIFO_OVERFLOW) | BIT(DSI_FIFO_UNDERFLOW);
  797. dsi_display_set_ctrl_esd_check_flag(dsi_display, true);
  798. dsi_display_mask_ctrl_error_interrupts(dsi_display, mask, true);
  799. if (status_mode == ESD_MODE_REG_READ) {
  800. rc = dsi_display_status_reg_read(dsi_display);
  801. } else if (status_mode == ESD_MODE_SW_BTA) {
  802. rc = dsi_display_status_bta_request(dsi_display);
  803. } else if (status_mode == ESD_MODE_PANEL_TE) {
  804. rc = dsi_display_status_check_te(dsi_display, te_rechecks);
  805. te_check_override = false;
  806. } else {
  807. DSI_WARN("Unsupported check status mode: %d\n", status_mode);
  808. panel->esd_config.esd_enabled = false;
  809. }
  810. if (rc <= 0 && te_check_override)
  811. rc = dsi_display_status_check_te(dsi_display, te_rechecks);
  812. /* Unmask error interrupts if check passed*/
  813. if (rc > 0) {
  814. dsi_display_set_ctrl_esd_check_flag(dsi_display, false);
  815. dsi_display_mask_ctrl_error_interrupts(dsi_display, mask,
  816. false);
  817. if (te_check_override && panel->esd_config.esd_enabled == false)
  818. rc = dsi_display_status_check_te(dsi_display,
  819. te_rechecks);
  820. }
  821. dsi_display_clk_ctrl(dsi_display->dsi_clk_handle,
  822. DSI_ALL_CLKS, DSI_CLK_OFF);
  823. /* Handle Panel failures during display disable sequence */
  824. if (rc <=0)
  825. atomic_set(&panel->esd_recovery_pending, 1);
  826. release_panel_lock:
  827. dsi_panel_release_panel_lock(panel);
  828. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT, rc);
  829. return rc;
  830. }
  831. static int dsi_display_ctrl_get_host_init_state(struct dsi_display *dsi_display,
  832. bool *state)
  833. {
  834. struct dsi_display_ctrl *ctrl;
  835. int i, rc = -EINVAL;
  836. display_for_each_ctrl(i, dsi_display) {
  837. ctrl = &dsi_display->ctrl[i];
  838. rc = dsi_ctrl_get_host_engine_init_state(ctrl->ctrl, state);
  839. if (rc)
  840. break;
  841. }
  842. return rc;
  843. }
  844. static int dsi_display_cmd_rx(struct dsi_display *display,
  845. struct dsi_cmd_desc *cmd)
  846. {
  847. struct dsi_display_ctrl *m_ctrl = NULL;
  848. u32 mask = 0, flags = 0;
  849. int rc = 0;
  850. if (!display || !display->panel)
  851. return -EINVAL;
  852. m_ctrl = &display->ctrl[display->cmd_master_idx];
  853. if (!m_ctrl || !m_ctrl->ctrl)
  854. return -EINVAL;
  855. /* acquire panel_lock to make sure no commands are in progress */
  856. dsi_panel_acquire_panel_lock(display->panel);
  857. if (!display->panel->panel_initialized) {
  858. DSI_DEBUG("panel not initialized\n");
  859. goto release_panel_lock;
  860. }
  861. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  862. DSI_ALL_CLKS, DSI_CLK_ON);
  863. if (rc)
  864. goto release_panel_lock;
  865. mask = BIT(DSI_FIFO_OVERFLOW) | BIT(DSI_FIFO_UNDERFLOW);
  866. dsi_display_mask_ctrl_error_interrupts(display, mask, true);
  867. rc = dsi_display_cmd_engine_enable(display);
  868. if (rc) {
  869. DSI_ERR("cmd engine enable failed rc = %d\n", rc);
  870. goto error;
  871. }
  872. flags = DSI_CTRL_CMD_READ;
  873. cmd->ctrl_flags = flags;
  874. dsi_display_set_cmd_tx_ctrl_flags(display, cmd);
  875. rc = dsi_ctrl_cmd_transfer(m_ctrl->ctrl, cmd);
  876. if (rc <= 0)
  877. DSI_ERR("rx cmd transfer failed rc = %d\n", rc);
  878. dsi_display_cmd_engine_disable(display);
  879. error:
  880. dsi_display_mask_ctrl_error_interrupts(display, mask, false);
  881. dsi_display_clk_ctrl(display->dsi_clk_handle,
  882. DSI_ALL_CLKS, DSI_CLK_OFF);
  883. release_panel_lock:
  884. dsi_panel_release_panel_lock(display->panel);
  885. return rc;
  886. }
  887. int dsi_display_cmd_transfer(struct drm_connector *connector,
  888. void *display, const char *cmd_buf,
  889. u32 cmd_buf_len)
  890. {
  891. struct dsi_display *dsi_display = display;
  892. int rc = 0, cnt = 0, i = 0;
  893. bool state = false, transfer = false;
  894. struct dsi_panel_cmd_set *set;
  895. if (!dsi_display || !cmd_buf) {
  896. DSI_ERR("[DSI] invalid params\n");
  897. return -EINVAL;
  898. }
  899. DSI_DEBUG("[DSI] Display command transfer\n");
  900. if (!(cmd_buf[3] & MIPI_DSI_MSG_BATCH_COMMAND))
  901. transfer = true;
  902. mutex_lock(&dsi_display->display_lock);
  903. rc = dsi_display_ctrl_get_host_init_state(dsi_display, &state);
  904. /**
  905. * Handle scenario where a command transfer is initiated through
  906. * sysfs interface when device is in suepnd state.
  907. */
  908. if (!rc && !state) {
  909. pr_warn_ratelimited("Command xfer attempted while device is in suspend state\n"
  910. );
  911. rc = -EPERM;
  912. goto end;
  913. }
  914. if (rc || !state) {
  915. DSI_ERR("[DSI] Invalid host state %d rc %d\n",
  916. state, rc);
  917. rc = -EPERM;
  918. goto end;
  919. }
  920. /*
  921. * Reset the dbgfs buffer if the commands sent exceed the available
  922. * buffer size. For video mode, limiting the buffer size to 2K to
  923. * ensure no performance issues.
  924. */
  925. if (dsi_display->panel->panel_mode == DSI_OP_CMD_MODE) {
  926. if ((dsi_display->tx_cmd_buf_ndx + cmd_buf_len) > SZ_4K) {
  927. memset(dbgfs_tx_cmd_buf, 0, SZ_4K);
  928. dsi_display->tx_cmd_buf_ndx = 0;
  929. }
  930. } else {
  931. if ((dsi_display->tx_cmd_buf_ndx + cmd_buf_len) > SZ_2K) {
  932. memset(dbgfs_tx_cmd_buf, 0, SZ_4K);
  933. dsi_display->tx_cmd_buf_ndx = 0;
  934. }
  935. }
  936. memcpy(&dbgfs_tx_cmd_buf[dsi_display->tx_cmd_buf_ndx], cmd_buf,
  937. cmd_buf_len);
  938. dsi_display->tx_cmd_buf_ndx += cmd_buf_len;
  939. if (transfer) {
  940. struct dsi_cmd_desc *cmds;
  941. set = &dsi_display->cmd_set;
  942. set->count = 0;
  943. dsi_panel_get_cmd_pkt_count(dbgfs_tx_cmd_buf,
  944. dsi_display->tx_cmd_buf_ndx, &cnt);
  945. dsi_panel_alloc_cmd_packets(set, cnt);
  946. dsi_panel_create_cmd_packets(dbgfs_tx_cmd_buf,
  947. dsi_display->tx_cmd_buf_ndx, cnt, set->cmds);
  948. cmds = set->cmds;
  949. dsi_display->tx_cmd_buf_ndx = 0;
  950. for (i = 0; i < cnt; i++) {
  951. rc = dsi_host_transfer_sub(&dsi_display->host, cmds);
  952. if (rc < 0) {
  953. DSI_ERR("failed to send command, rc=%d\n", rc);
  954. break;
  955. }
  956. if (cmds->post_wait_ms)
  957. usleep_range(cmds->post_wait_ms*1000,
  958. ((cmds->post_wait_ms*1000)+10));
  959. cmds++;
  960. }
  961. memset(dbgfs_tx_cmd_buf, 0, SZ_4K);
  962. dsi_panel_destroy_cmd_packets(set);
  963. dsi_panel_dealloc_cmd_packets(set);
  964. }
  965. end:
  966. mutex_unlock(&dsi_display->display_lock);
  967. return rc;
  968. }
  969. static void _dsi_display_continuous_clk_ctrl(struct dsi_display *display,
  970. bool enable)
  971. {
  972. int i;
  973. struct dsi_display_ctrl *ctrl;
  974. if (!display || !display->panel->host_config.force_hs_clk_lane)
  975. return;
  976. display_for_each_ctrl(i, display) {
  977. ctrl = &display->ctrl[i];
  978. /*
  979. * For phy ver 4.0 chipsets, configure DSI controller and
  980. * DSI PHY to force clk lane to HS mode always whereas
  981. * for other phy ver chipsets, configure DSI controller only.
  982. */
  983. if (ctrl->phy->hw.ops.set_continuous_clk) {
  984. dsi_ctrl_hs_req_sel(ctrl->ctrl, true);
  985. dsi_ctrl_set_continuous_clk(ctrl->ctrl, enable);
  986. dsi_phy_set_continuous_clk(ctrl->phy, enable);
  987. } else {
  988. dsi_ctrl_set_continuous_clk(ctrl->ctrl, enable);
  989. }
  990. }
  991. }
  992. int dsi_display_cmd_receive(void *display, const char *cmd_buf,
  993. u32 cmd_buf_len, u8 *recv_buf, u32 recv_buf_len)
  994. {
  995. struct dsi_display *dsi_display = display;
  996. struct dsi_cmd_desc cmd = {};
  997. bool state = false;
  998. int rc = -1;
  999. if (!dsi_display || !cmd_buf || !recv_buf) {
  1000. DSI_ERR("[DSI] invalid params\n");
  1001. return -EINVAL;
  1002. }
  1003. rc = dsi_panel_create_cmd_packets(cmd_buf, cmd_buf_len, 1, &cmd);
  1004. if (rc) {
  1005. DSI_ERR("[DSI] command packet create failed, rc = %d\n", rc);
  1006. return rc;
  1007. }
  1008. cmd.msg.rx_buf = recv_buf;
  1009. cmd.msg.rx_len = recv_buf_len;
  1010. cmd.msg.flags |= MIPI_DSI_MSG_UNICAST_COMMAND;
  1011. mutex_lock(&dsi_display->display_lock);
  1012. rc = dsi_display_ctrl_get_host_init_state(dsi_display, &state);
  1013. if (rc || !state) {
  1014. DSI_ERR("[DSI] Invalid host state = %d rc = %d\n",
  1015. state, rc);
  1016. rc = -EPERM;
  1017. goto end;
  1018. }
  1019. rc = dsi_display_cmd_rx(dsi_display, &cmd);
  1020. if (rc <= 0)
  1021. DSI_ERR("[DSI] Display command receive failed, rc=%d\n", rc);
  1022. end:
  1023. mutex_unlock(&dsi_display->display_lock);
  1024. return rc;
  1025. }
  1026. int dsi_display_soft_reset(void *display)
  1027. {
  1028. struct dsi_display *dsi_display;
  1029. struct dsi_display_ctrl *ctrl;
  1030. int rc = 0;
  1031. int i;
  1032. if (!display)
  1033. return -EINVAL;
  1034. dsi_display = display;
  1035. display_for_each_ctrl(i, dsi_display) {
  1036. ctrl = &dsi_display->ctrl[i];
  1037. rc = dsi_ctrl_soft_reset(ctrl->ctrl);
  1038. if (rc) {
  1039. DSI_ERR("[%s] failed to soft reset host_%d, rc=%d\n",
  1040. dsi_display->name, i, rc);
  1041. break;
  1042. }
  1043. }
  1044. return rc;
  1045. }
  1046. enum dsi_pixel_format dsi_display_get_dst_format(
  1047. struct drm_connector *connector,
  1048. void *display)
  1049. {
  1050. enum dsi_pixel_format format = DSI_PIXEL_FORMAT_MAX;
  1051. struct dsi_display *dsi_display = (struct dsi_display *)display;
  1052. if (!dsi_display || !dsi_display->panel) {
  1053. DSI_ERR("Invalid params(s) dsi_display %pK, panel %pK\n",
  1054. dsi_display,
  1055. ((dsi_display) ? dsi_display->panel : NULL));
  1056. return format;
  1057. }
  1058. format = dsi_display->panel->host_config.dst_format;
  1059. return format;
  1060. }
  1061. static void _dsi_display_setup_misr(struct dsi_display *display)
  1062. {
  1063. int i;
  1064. display_for_each_ctrl(i, display) {
  1065. dsi_ctrl_setup_misr(display->ctrl[i].ctrl,
  1066. display->misr_enable,
  1067. display->misr_frame_count);
  1068. }
  1069. }
  1070. int dsi_display_set_power(struct drm_connector *connector,
  1071. int power_mode, void *disp)
  1072. {
  1073. struct dsi_display *display = disp;
  1074. int rc = 0;
  1075. if (!display || !display->panel) {
  1076. DSI_ERR("invalid display/panel\n");
  1077. return -EINVAL;
  1078. }
  1079. switch (power_mode) {
  1080. case SDE_MODE_DPMS_LP1:
  1081. rc = dsi_panel_set_lp1(display->panel);
  1082. break;
  1083. case SDE_MODE_DPMS_LP2:
  1084. rc = dsi_panel_set_lp2(display->panel);
  1085. break;
  1086. case SDE_MODE_DPMS_ON:
  1087. if ((display->panel->power_mode == SDE_MODE_DPMS_LP1) ||
  1088. (display->panel->power_mode == SDE_MODE_DPMS_LP2))
  1089. rc = dsi_panel_set_nolp(display->panel);
  1090. break;
  1091. case SDE_MODE_DPMS_OFF:
  1092. default:
  1093. return rc;
  1094. }
  1095. SDE_EVT32(display->panel->power_mode, power_mode, rc);
  1096. DSI_DEBUG("Power mode transition from %d to %d %s",
  1097. display->panel->power_mode, power_mode,
  1098. rc ? "failed" : "successful");
  1099. if (!rc)
  1100. display->panel->power_mode = power_mode;
  1101. return rc;
  1102. }
  1103. #ifdef CONFIG_DEBUG_FS
  1104. static bool dsi_display_is_te_based_esd(struct dsi_display *display)
  1105. {
  1106. u32 status_mode = 0;
  1107. if (!display->panel) {
  1108. DSI_ERR("Invalid panel data\n");
  1109. return false;
  1110. }
  1111. status_mode = display->panel->esd_config.status_mode;
  1112. if (status_mode == ESD_MODE_PANEL_TE &&
  1113. gpio_is_valid(display->disp_te_gpio))
  1114. return true;
  1115. return false;
  1116. }
  1117. static ssize_t debugfs_dump_info_read(struct file *file,
  1118. char __user *user_buf,
  1119. size_t user_len,
  1120. loff_t *ppos)
  1121. {
  1122. struct dsi_display *display = file->private_data;
  1123. char *buf;
  1124. u32 len = 0;
  1125. int i;
  1126. if (!display)
  1127. return -ENODEV;
  1128. if (*ppos)
  1129. return 0;
  1130. buf = kzalloc(SZ_4K, GFP_KERNEL);
  1131. if (!buf)
  1132. return -ENOMEM;
  1133. len += snprintf(buf + len, (SZ_4K - len), "name = %s\n", display->name);
  1134. len += snprintf(buf + len, (SZ_4K - len),
  1135. "\tResolution = %dx%d\n",
  1136. display->config.video_timing.h_active,
  1137. display->config.video_timing.v_active);
  1138. display_for_each_ctrl(i, display) {
  1139. len += snprintf(buf + len, (SZ_4K - len),
  1140. "\tCTRL_%d:\n\t\tctrl = %s\n\t\tphy = %s\n",
  1141. i, display->ctrl[i].ctrl->name,
  1142. display->ctrl[i].phy->name);
  1143. }
  1144. len += snprintf(buf + len, (SZ_4K - len),
  1145. "\tPanel = %s\n", display->panel->name);
  1146. len += snprintf(buf + len, (SZ_4K - len),
  1147. "\tClock master = %s\n",
  1148. display->ctrl[display->clk_master_idx].ctrl->name);
  1149. if (len > user_len)
  1150. len = user_len;
  1151. if (copy_to_user(user_buf, buf, len)) {
  1152. kfree(buf);
  1153. return -EFAULT;
  1154. }
  1155. *ppos += len;
  1156. kfree(buf);
  1157. return len;
  1158. }
  1159. static ssize_t debugfs_misr_setup(struct file *file,
  1160. const char __user *user_buf,
  1161. size_t user_len,
  1162. loff_t *ppos)
  1163. {
  1164. struct dsi_display *display = file->private_data;
  1165. char *buf;
  1166. int rc = 0;
  1167. size_t len;
  1168. u32 enable, frame_count;
  1169. if (!display)
  1170. return -ENODEV;
  1171. if (*ppos)
  1172. return 0;
  1173. buf = kzalloc(MISR_BUFF_SIZE, GFP_KERNEL);
  1174. if (!buf)
  1175. return -ENOMEM;
  1176. /* leave room for termination char */
  1177. len = min_t(size_t, user_len, MISR_BUFF_SIZE - 1);
  1178. if (copy_from_user(buf, user_buf, len)) {
  1179. rc = -EINVAL;
  1180. goto error;
  1181. }
  1182. buf[len] = '\0'; /* terminate the string */
  1183. if (sscanf(buf, "%u %u", &enable, &frame_count) != 2) {
  1184. rc = -EINVAL;
  1185. goto error;
  1186. }
  1187. display->misr_enable = enable;
  1188. display->misr_frame_count = frame_count;
  1189. mutex_lock(&display->display_lock);
  1190. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1191. DSI_CORE_CLK, DSI_CLK_ON);
  1192. if (rc) {
  1193. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  1194. display->name, rc);
  1195. goto unlock;
  1196. }
  1197. _dsi_display_setup_misr(display);
  1198. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1199. DSI_CORE_CLK, DSI_CLK_OFF);
  1200. if (rc) {
  1201. DSI_ERR("[%s] failed to disable DSI core clocks, rc=%d\n",
  1202. display->name, rc);
  1203. goto unlock;
  1204. }
  1205. rc = user_len;
  1206. unlock:
  1207. mutex_unlock(&display->display_lock);
  1208. error:
  1209. kfree(buf);
  1210. return rc;
  1211. }
  1212. static ssize_t debugfs_misr_read(struct file *file,
  1213. char __user *user_buf,
  1214. size_t user_len,
  1215. loff_t *ppos)
  1216. {
  1217. struct dsi_display *display = file->private_data;
  1218. char *buf;
  1219. u32 len = 0;
  1220. int rc = 0;
  1221. struct dsi_ctrl *dsi_ctrl;
  1222. int i;
  1223. u32 misr;
  1224. size_t max_len = min_t(size_t, user_len, MISR_BUFF_SIZE);
  1225. if (!display)
  1226. return -ENODEV;
  1227. if (*ppos)
  1228. return 0;
  1229. buf = kzalloc(max_len, GFP_KERNEL);
  1230. if (ZERO_OR_NULL_PTR(buf))
  1231. return -ENOMEM;
  1232. mutex_lock(&display->display_lock);
  1233. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1234. DSI_CORE_CLK, DSI_CLK_ON);
  1235. if (rc) {
  1236. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  1237. display->name, rc);
  1238. goto error;
  1239. }
  1240. display_for_each_ctrl(i, display) {
  1241. dsi_ctrl = display->ctrl[i].ctrl;
  1242. misr = dsi_ctrl_collect_misr(display->ctrl[i].ctrl);
  1243. len += snprintf((buf + len), max_len - len,
  1244. "DSI_%d MISR: 0x%x\n", dsi_ctrl->cell_index, misr);
  1245. if (len >= max_len)
  1246. break;
  1247. }
  1248. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  1249. DSI_CORE_CLK, DSI_CLK_OFF);
  1250. if (rc) {
  1251. DSI_ERR("[%s] failed to disable DSI core clocks, rc=%d\n",
  1252. display->name, rc);
  1253. goto error;
  1254. }
  1255. if (copy_to_user(user_buf, buf, max_len)) {
  1256. rc = -EFAULT;
  1257. goto error;
  1258. }
  1259. *ppos += len;
  1260. error:
  1261. mutex_unlock(&display->display_lock);
  1262. kfree(buf);
  1263. return len;
  1264. }
  1265. static ssize_t debugfs_esd_trigger_check(struct file *file,
  1266. const char __user *user_buf,
  1267. size_t user_len,
  1268. loff_t *ppos)
  1269. {
  1270. struct dsi_display *display = file->private_data;
  1271. char *buf;
  1272. int rc = 0;
  1273. struct drm_panel_esd_config *esd_config = &display->panel->esd_config;
  1274. u32 esd_trigger;
  1275. size_t len;
  1276. if (!display)
  1277. return -ENODEV;
  1278. if (*ppos)
  1279. return 0;
  1280. if (user_len > sizeof(u32))
  1281. return -EINVAL;
  1282. if (!user_len || !user_buf)
  1283. return -EINVAL;
  1284. if (!display->panel ||
  1285. atomic_read(&display->panel->esd_recovery_pending))
  1286. return user_len;
  1287. if (!esd_config->esd_enabled) {
  1288. DSI_ERR("ESD feature is not enabled\n");
  1289. return -EINVAL;
  1290. }
  1291. buf = kzalloc(ESD_TRIGGER_STRING_MAX_LEN, GFP_KERNEL);
  1292. if (!buf)
  1293. return -ENOMEM;
  1294. len = min_t(size_t, user_len, ESD_TRIGGER_STRING_MAX_LEN - 1);
  1295. if (copy_from_user(buf, user_buf, len)) {
  1296. rc = -EINVAL;
  1297. goto error;
  1298. }
  1299. buf[len] = '\0'; /* terminate the string */
  1300. if (kstrtouint(buf, 10, &esd_trigger)) {
  1301. rc = -EINVAL;
  1302. goto error;
  1303. }
  1304. if (esd_trigger != 1) {
  1305. rc = -EINVAL;
  1306. goto error;
  1307. }
  1308. display->esd_trigger = esd_trigger;
  1309. if (display->esd_trigger) {
  1310. DSI_INFO("ESD attack triggered by user\n");
  1311. rc = dsi_panel_trigger_esd_attack(display->panel,
  1312. display->trusted_vm_env);
  1313. if (rc) {
  1314. DSI_ERR("Failed to trigger ESD attack\n");
  1315. goto error;
  1316. }
  1317. }
  1318. rc = len;
  1319. error:
  1320. kfree(buf);
  1321. return rc;
  1322. }
  1323. static ssize_t debugfs_alter_esd_check_mode(struct file *file,
  1324. const char __user *user_buf,
  1325. size_t user_len,
  1326. loff_t *ppos)
  1327. {
  1328. struct dsi_display *display = file->private_data;
  1329. struct drm_panel_esd_config *esd_config;
  1330. char *buf;
  1331. int rc = 0;
  1332. size_t len;
  1333. if (!display)
  1334. return -ENODEV;
  1335. if (*ppos)
  1336. return 0;
  1337. buf = kzalloc(ESD_MODE_STRING_MAX_LEN, GFP_KERNEL);
  1338. if (ZERO_OR_NULL_PTR(buf))
  1339. return -ENOMEM;
  1340. len = min_t(size_t, user_len, ESD_MODE_STRING_MAX_LEN - 1);
  1341. if (copy_from_user(buf, user_buf, len)) {
  1342. rc = -EINVAL;
  1343. goto error;
  1344. }
  1345. buf[len] = '\0'; /* terminate the string */
  1346. if (!display->panel) {
  1347. rc = -EINVAL;
  1348. goto error;
  1349. }
  1350. esd_config = &display->panel->esd_config;
  1351. if (!esd_config) {
  1352. DSI_ERR("Invalid panel esd config\n");
  1353. rc = -EINVAL;
  1354. goto error;
  1355. }
  1356. if (!esd_config->esd_enabled) {
  1357. rc = -EINVAL;
  1358. goto error;
  1359. }
  1360. if (!strcmp(buf, "te_signal_check\n")) {
  1361. if (display->panel->panel_mode == DSI_OP_VIDEO_MODE) {
  1362. DSI_INFO("TE based ESD check for Video Mode panels is not allowed\n");
  1363. rc = -EINVAL;
  1364. goto error;
  1365. }
  1366. DSI_INFO("ESD check is switched to TE mode by user\n");
  1367. esd_config->status_mode = ESD_MODE_PANEL_TE;
  1368. dsi_display_change_te_irq_status(display, true);
  1369. }
  1370. if (!strcmp(buf, "reg_read\n")) {
  1371. DSI_INFO("ESD check is switched to reg read by user\n");
  1372. rc = dsi_panel_parse_esd_reg_read_configs(display->panel);
  1373. if (rc) {
  1374. DSI_ERR("failed to alter esd check mode,rc=%d\n",
  1375. rc);
  1376. rc = user_len;
  1377. goto error;
  1378. }
  1379. esd_config->status_mode = ESD_MODE_REG_READ;
  1380. if (dsi_display_is_te_based_esd(display))
  1381. dsi_display_change_te_irq_status(display, false);
  1382. }
  1383. if (!strcmp(buf, "esd_sw_sim_success\n"))
  1384. esd_config->status_mode = ESD_MODE_SW_SIM_SUCCESS;
  1385. if (!strcmp(buf, "esd_sw_sim_failure\n"))
  1386. esd_config->status_mode = ESD_MODE_SW_SIM_FAILURE;
  1387. rc = len;
  1388. error:
  1389. kfree(buf);
  1390. return rc;
  1391. }
  1392. static ssize_t debugfs_read_esd_check_mode(struct file *file,
  1393. char __user *user_buf,
  1394. size_t user_len,
  1395. loff_t *ppos)
  1396. {
  1397. struct dsi_display *display = file->private_data;
  1398. struct drm_panel_esd_config *esd_config;
  1399. char *buf;
  1400. int rc = 0;
  1401. size_t len = 0;
  1402. if (!display)
  1403. return -ENODEV;
  1404. if (*ppos)
  1405. return 0;
  1406. if (!display->panel) {
  1407. DSI_ERR("invalid panel data\n");
  1408. return -EINVAL;
  1409. }
  1410. buf = kzalloc(ESD_MODE_STRING_MAX_LEN, GFP_KERNEL);
  1411. if (ZERO_OR_NULL_PTR(buf))
  1412. return -ENOMEM;
  1413. esd_config = &display->panel->esd_config;
  1414. if (!esd_config) {
  1415. DSI_ERR("Invalid panel esd config\n");
  1416. rc = -EINVAL;
  1417. goto error;
  1418. }
  1419. len = min_t(size_t, user_len, ESD_MODE_STRING_MAX_LEN - 1);
  1420. if (!esd_config->esd_enabled) {
  1421. rc = snprintf(buf, len, "ESD feature not enabled");
  1422. goto output_mode;
  1423. }
  1424. switch (esd_config->status_mode) {
  1425. case ESD_MODE_REG_READ:
  1426. rc = snprintf(buf, len, "reg_read");
  1427. break;
  1428. case ESD_MODE_PANEL_TE:
  1429. rc = snprintf(buf, len, "te_signal_check");
  1430. break;
  1431. case ESD_MODE_SW_SIM_FAILURE:
  1432. rc = snprintf(buf, len, "esd_sw_sim_failure");
  1433. break;
  1434. case ESD_MODE_SW_SIM_SUCCESS:
  1435. rc = snprintf(buf, len, "esd_sw_sim_success");
  1436. break;
  1437. default:
  1438. rc = snprintf(buf, len, "invalid");
  1439. break;
  1440. }
  1441. output_mode:
  1442. if (!rc) {
  1443. rc = -EINVAL;
  1444. goto error;
  1445. }
  1446. if (copy_to_user(user_buf, buf, len)) {
  1447. rc = -EFAULT;
  1448. goto error;
  1449. }
  1450. *ppos += len;
  1451. error:
  1452. kfree(buf);
  1453. return len;
  1454. }
  1455. static ssize_t debugfs_update_cmd_scheduling_params(struct file *file,
  1456. const char __user *user_buf,
  1457. size_t user_len,
  1458. loff_t *ppos)
  1459. {
  1460. struct dsi_display *display = file->private_data;
  1461. struct dsi_display_ctrl *display_ctrl;
  1462. char *buf;
  1463. int rc = 0;
  1464. u32 line = 0, window = 0;
  1465. size_t len;
  1466. int i;
  1467. if (!display)
  1468. return -ENODEV;
  1469. if (*ppos)
  1470. return 0;
  1471. buf = kzalloc(256, GFP_KERNEL);
  1472. if (ZERO_OR_NULL_PTR(buf))
  1473. return -ENOMEM;
  1474. len = min_t(size_t, user_len, 255);
  1475. if (copy_from_user(buf, user_buf, len)) {
  1476. rc = -EINVAL;
  1477. goto error;
  1478. }
  1479. buf[len] = '\0'; /* terminate the string */
  1480. if (sscanf(buf, "%d %d", &line, &window) != 2)
  1481. return -EFAULT;
  1482. display_for_each_ctrl(i, display) {
  1483. struct dsi_ctrl *ctrl;
  1484. display_ctrl = &display->ctrl[i];
  1485. if (!display_ctrl->ctrl)
  1486. continue;
  1487. ctrl = display_ctrl->ctrl;
  1488. ctrl->host_config.common_config.dma_sched_line = line;
  1489. ctrl->host_config.common_config.dma_sched_window = window;
  1490. }
  1491. rc = len;
  1492. error:
  1493. kfree(buf);
  1494. return rc;
  1495. }
  1496. static ssize_t debugfs_read_cmd_scheduling_params(struct file *file,
  1497. char __user *user_buf,
  1498. size_t user_len,
  1499. loff_t *ppos)
  1500. {
  1501. struct dsi_display *display = file->private_data;
  1502. struct dsi_display_ctrl *m_ctrl;
  1503. struct dsi_ctrl *ctrl;
  1504. char *buf;
  1505. u32 len = 0;
  1506. int rc = 0;
  1507. size_t max_len = min_t(size_t, user_len, SZ_4K);
  1508. if (!display)
  1509. return -ENODEV;
  1510. if (*ppos)
  1511. return 0;
  1512. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1513. ctrl = m_ctrl->ctrl;
  1514. buf = kzalloc(max_len, GFP_KERNEL);
  1515. if (ZERO_OR_NULL_PTR(buf))
  1516. return -ENOMEM;
  1517. len += scnprintf(buf, max_len, "Schedule command window start: %d\n",
  1518. ctrl->host_config.common_config.dma_sched_line);
  1519. len += scnprintf((buf + len), max_len - len,
  1520. "Schedule command window width: %d\n",
  1521. ctrl->host_config.common_config.dma_sched_window);
  1522. if (len > max_len)
  1523. len = max_len;
  1524. if (copy_to_user(user_buf, buf, len)) {
  1525. rc = -EFAULT;
  1526. goto error;
  1527. }
  1528. *ppos += len;
  1529. error:
  1530. kfree(buf);
  1531. return len;
  1532. }
  1533. static const struct file_operations dump_info_fops = {
  1534. .open = simple_open,
  1535. .read = debugfs_dump_info_read,
  1536. };
  1537. static const struct file_operations misr_data_fops = {
  1538. .open = simple_open,
  1539. .read = debugfs_misr_read,
  1540. .write = debugfs_misr_setup,
  1541. };
  1542. static const struct file_operations esd_trigger_fops = {
  1543. .open = simple_open,
  1544. .write = debugfs_esd_trigger_check,
  1545. };
  1546. static const struct file_operations esd_check_mode_fops = {
  1547. .open = simple_open,
  1548. .write = debugfs_alter_esd_check_mode,
  1549. .read = debugfs_read_esd_check_mode,
  1550. };
  1551. static const struct file_operations dsi_command_scheduling_fops = {
  1552. .open = simple_open,
  1553. .write = debugfs_update_cmd_scheduling_params,
  1554. .read = debugfs_read_cmd_scheduling_params,
  1555. };
  1556. static int dsi_display_debugfs_init(struct dsi_display *display)
  1557. {
  1558. int rc = 0;
  1559. struct dentry *dir, *dump_file, *misr_data;
  1560. char name[MAX_NAME_SIZE];
  1561. char panel_name[SEC_PANEL_NAME_MAX_LEN];
  1562. char secondary_panel_str[] = "_secondary";
  1563. int i;
  1564. strlcpy(panel_name, display->name, SEC_PANEL_NAME_MAX_LEN);
  1565. if (strcmp(display->display_type, "secondary") == 0)
  1566. strlcat(panel_name, secondary_panel_str, SEC_PANEL_NAME_MAX_LEN);
  1567. dir = debugfs_create_dir(panel_name, NULL);
  1568. if (IS_ERR_OR_NULL(dir)) {
  1569. rc = PTR_ERR(dir);
  1570. DSI_ERR("[%s] debugfs create dir failed, rc = %d\n",
  1571. display->name, rc);
  1572. goto error;
  1573. }
  1574. dump_file = debugfs_create_file("dump_info",
  1575. 0400,
  1576. dir,
  1577. display,
  1578. &dump_info_fops);
  1579. if (IS_ERR_OR_NULL(dump_file)) {
  1580. rc = PTR_ERR(dump_file);
  1581. DSI_ERR("[%s] debugfs create dump info file failed, rc=%d\n",
  1582. display->name, rc);
  1583. goto error_remove_dir;
  1584. }
  1585. dump_file = debugfs_create_file("esd_trigger",
  1586. 0644,
  1587. dir,
  1588. display,
  1589. &esd_trigger_fops);
  1590. if (IS_ERR_OR_NULL(dump_file)) {
  1591. rc = PTR_ERR(dump_file);
  1592. DSI_ERR("[%s] debugfs for esd trigger file failed, rc=%d\n",
  1593. display->name, rc);
  1594. goto error_remove_dir;
  1595. }
  1596. dump_file = debugfs_create_file("esd_check_mode",
  1597. 0644,
  1598. dir,
  1599. display,
  1600. &esd_check_mode_fops);
  1601. if (IS_ERR_OR_NULL(dump_file)) {
  1602. rc = PTR_ERR(dump_file);
  1603. DSI_ERR("[%s] debugfs for esd check mode failed, rc=%d\n",
  1604. display->name, rc);
  1605. goto error_remove_dir;
  1606. }
  1607. dump_file = debugfs_create_file("cmd_sched_params",
  1608. 0644,
  1609. dir,
  1610. display,
  1611. &dsi_command_scheduling_fops);
  1612. if (IS_ERR_OR_NULL(dump_file)) {
  1613. rc = PTR_ERR(dump_file);
  1614. DSI_ERR("[%s] debugfs for cmd scheduling file failed, rc=%d\n",
  1615. display->name, rc);
  1616. goto error_remove_dir;
  1617. }
  1618. misr_data = debugfs_create_file("misr_data",
  1619. 0600,
  1620. dir,
  1621. display,
  1622. &misr_data_fops);
  1623. if (IS_ERR_OR_NULL(misr_data)) {
  1624. rc = PTR_ERR(misr_data);
  1625. DSI_ERR("[%s] debugfs create misr datafile failed, rc=%d\n",
  1626. display->name, rc);
  1627. goto error_remove_dir;
  1628. }
  1629. display_for_each_ctrl(i, display) {
  1630. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  1631. if (!phy || !phy->name)
  1632. continue;
  1633. snprintf(name, ARRAY_SIZE(name),
  1634. "%s_allow_phy_power_off", phy->name);
  1635. dump_file = debugfs_create_bool(name, 0600, dir,
  1636. &phy->allow_phy_power_off);
  1637. if (IS_ERR_OR_NULL(dump_file)) {
  1638. rc = PTR_ERR(dump_file);
  1639. DSI_ERR("[%s] debugfs create %s failed, rc=%d\n",
  1640. display->name, name, rc);
  1641. goto error_remove_dir;
  1642. }
  1643. snprintf(name, ARRAY_SIZE(name),
  1644. "%s_regulator_min_datarate_bps", phy->name);
  1645. debugfs_create_u32(name, 0600, dir, &phy->regulator_min_datarate_bps);
  1646. }
  1647. if (!debugfs_create_bool("ulps_feature_enable", 0600, dir,
  1648. &display->panel->ulps_feature_enabled)) {
  1649. DSI_ERR("[%s] debugfs create ulps feature enable file failed\n",
  1650. display->name);
  1651. goto error_remove_dir;
  1652. }
  1653. if (!debugfs_create_bool("ulps_suspend_feature_enable", 0600, dir,
  1654. &display->panel->ulps_suspend_enabled)) {
  1655. DSI_ERR("[%s] debugfs create ulps-suspend feature enable file failed\n",
  1656. display->name);
  1657. goto error_remove_dir;
  1658. }
  1659. if (!debugfs_create_bool("ulps_status", 0400, dir,
  1660. &display->ulps_enabled)) {
  1661. DSI_ERR("[%s] debugfs create ulps status file failed\n",
  1662. display->name);
  1663. goto error_remove_dir;
  1664. }
  1665. debugfs_create_u32("clk_gating_config", 0600, dir, &display->clk_gating_config);
  1666. display->root = dir;
  1667. dsi_parser_dbg_init(display->parser, dir);
  1668. return rc;
  1669. error_remove_dir:
  1670. debugfs_remove(dir);
  1671. error:
  1672. return rc;
  1673. }
  1674. static int dsi_display_debugfs_deinit(struct dsi_display *display)
  1675. {
  1676. debugfs_remove_recursive(display->root);
  1677. return 0;
  1678. }
  1679. #else
  1680. static int dsi_display_debugfs_init(struct dsi_display *display)
  1681. {
  1682. return 0;
  1683. }
  1684. static int dsi_display_debugfs_deinit(struct dsi_display *display)
  1685. {
  1686. return 0;
  1687. }
  1688. #endif /* CONFIG_DEBUG_FS */
  1689. static void adjust_timing_by_ctrl_count(const struct dsi_display *display,
  1690. struct dsi_display_mode *mode)
  1691. {
  1692. struct dsi_host_common_cfg *host = &display->panel->host_config;
  1693. bool is_split_link = host->split_link.split_link_enabled;
  1694. u32 sublinks_count = host->split_link.num_sublinks;
  1695. if (is_split_link && sublinks_count > 1) {
  1696. mode->timing.h_active /= sublinks_count;
  1697. mode->timing.h_front_porch /= sublinks_count;
  1698. mode->timing.h_sync_width /= sublinks_count;
  1699. mode->timing.h_back_porch /= sublinks_count;
  1700. mode->timing.h_skew /= sublinks_count;
  1701. mode->pixel_clk_khz /= sublinks_count;
  1702. } else {
  1703. if (mode->priv_info->dsc_enabled)
  1704. mode->priv_info->dsc.config.pic_width =
  1705. mode->timing.h_active;
  1706. mode->timing.h_active /= display->ctrl_count;
  1707. mode->timing.h_front_porch /= display->ctrl_count;
  1708. mode->timing.h_sync_width /= display->ctrl_count;
  1709. mode->timing.h_back_porch /= display->ctrl_count;
  1710. mode->timing.h_skew /= display->ctrl_count;
  1711. mode->pixel_clk_khz /= display->ctrl_count;
  1712. }
  1713. }
  1714. static int dsi_display_is_ulps_req_valid(struct dsi_display *display,
  1715. bool enable)
  1716. {
  1717. /* TODO: make checks based on cont. splash */
  1718. DSI_DEBUG("checking ulps req validity\n");
  1719. if (atomic_read(&display->panel->esd_recovery_pending)) {
  1720. DSI_DEBUG("%s: ESD recovery sequence underway\n", __func__);
  1721. return false;
  1722. }
  1723. if (!dsi_panel_ulps_feature_enabled(display->panel) &&
  1724. !display->panel->ulps_suspend_enabled) {
  1725. DSI_DEBUG("%s: ULPS feature is not enabled\n", __func__);
  1726. return false;
  1727. }
  1728. if (!dsi_panel_initialized(display->panel) &&
  1729. !display->panel->ulps_suspend_enabled) {
  1730. DSI_DEBUG("%s: panel not yet initialized\n", __func__);
  1731. return false;
  1732. }
  1733. if (enable && display->ulps_enabled) {
  1734. DSI_DEBUG("ULPS already enabled\n");
  1735. return false;
  1736. } else if (!enable && !display->ulps_enabled) {
  1737. DSI_DEBUG("ULPS already disabled\n");
  1738. return false;
  1739. }
  1740. /*
  1741. * No need to enter ULPS when transitioning from splash screen to
  1742. * boot animation or trusted vm environments since it is expected
  1743. * that the clocks would be turned right back on.
  1744. */
  1745. if (enable && is_skip_op_required(display))
  1746. return false;
  1747. return true;
  1748. }
  1749. /**
  1750. * dsi_display_set_ulps() - set ULPS state for DSI lanes.
  1751. * @dsi_display: DSI display handle.
  1752. * @enable: enable/disable ULPS.
  1753. *
  1754. * ULPS can be enabled/disabled after DSI host engine is turned on.
  1755. *
  1756. * Return: error code.
  1757. */
  1758. static int dsi_display_set_ulps(struct dsi_display *display, bool enable)
  1759. {
  1760. int rc = 0;
  1761. int i = 0;
  1762. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1763. if (!display) {
  1764. DSI_ERR("Invalid params\n");
  1765. return -EINVAL;
  1766. }
  1767. if (!dsi_display_is_ulps_req_valid(display, enable)) {
  1768. DSI_DEBUG("%s: skipping ULPS config, enable=%d\n",
  1769. __func__, enable);
  1770. return 0;
  1771. }
  1772. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1773. /*
  1774. * ULPS entry-exit can be either through the DSI controller or
  1775. * the DSI PHY depending on hardware variation. For some chipsets,
  1776. * both controller version and phy version ulps entry-exit ops can
  1777. * be present. To handle such cases, send ulps request through PHY,
  1778. * if ulps request is handled in PHY, then no need to send request
  1779. * through controller.
  1780. */
  1781. rc = dsi_phy_set_ulps(m_ctrl->phy, &display->config, enable,
  1782. display->clamp_enabled);
  1783. if (rc == DSI_PHY_ULPS_ERROR) {
  1784. DSI_ERR("Ulps PHY state change(%d) failed\n", enable);
  1785. return -EINVAL;
  1786. }
  1787. else if (rc == DSI_PHY_ULPS_HANDLED) {
  1788. display_for_each_ctrl(i, display) {
  1789. ctrl = &display->ctrl[i];
  1790. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1791. continue;
  1792. rc = dsi_phy_set_ulps(ctrl->phy, &display->config,
  1793. enable, display->clamp_enabled);
  1794. if (rc == DSI_PHY_ULPS_ERROR) {
  1795. DSI_ERR("Ulps PHY state change(%d) failed\n",
  1796. enable);
  1797. return -EINVAL;
  1798. }
  1799. }
  1800. }
  1801. else if (rc == DSI_PHY_ULPS_NOT_HANDLED) {
  1802. rc = dsi_ctrl_set_ulps(m_ctrl->ctrl, enable);
  1803. if (rc) {
  1804. DSI_ERR("Ulps controller state change(%d) failed\n",
  1805. enable);
  1806. return rc;
  1807. }
  1808. display_for_each_ctrl(i, display) {
  1809. ctrl = &display->ctrl[i];
  1810. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1811. continue;
  1812. rc = dsi_ctrl_set_ulps(ctrl->ctrl, enable);
  1813. if (rc) {
  1814. DSI_ERR("Ulps controller state change(%d) failed\n",
  1815. enable);
  1816. return rc;
  1817. }
  1818. }
  1819. }
  1820. display->ulps_enabled = enable;
  1821. return 0;
  1822. }
  1823. /**
  1824. * dsi_display_set_clamp() - set clamp state for DSI IO.
  1825. * @dsi_display: DSI display handle.
  1826. * @enable: enable/disable clamping.
  1827. *
  1828. * Return: error code.
  1829. */
  1830. static int dsi_display_set_clamp(struct dsi_display *display, bool enable)
  1831. {
  1832. int rc = 0;
  1833. int i = 0;
  1834. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1835. bool ulps_enabled = false;
  1836. if (!display) {
  1837. DSI_ERR("Invalid params\n");
  1838. return -EINVAL;
  1839. }
  1840. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1841. ulps_enabled = display->ulps_enabled;
  1842. /*
  1843. * Clamp control can be either through the DSI controller or
  1844. * the DSI PHY depending on hardware variation
  1845. */
  1846. rc = dsi_ctrl_set_clamp_state(m_ctrl->ctrl, enable, ulps_enabled);
  1847. if (rc) {
  1848. DSI_ERR("DSI ctrl clamp state change(%d) failed\n", enable);
  1849. return rc;
  1850. }
  1851. rc = dsi_phy_set_clamp_state(m_ctrl->phy, enable);
  1852. if (rc) {
  1853. DSI_ERR("DSI phy clamp state change(%d) failed\n", enable);
  1854. return rc;
  1855. }
  1856. display_for_each_ctrl(i, display) {
  1857. ctrl = &display->ctrl[i];
  1858. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1859. continue;
  1860. rc = dsi_ctrl_set_clamp_state(ctrl->ctrl, enable, ulps_enabled);
  1861. if (rc) {
  1862. DSI_ERR("DSI Clamp state change(%d) failed\n", enable);
  1863. return rc;
  1864. }
  1865. rc = dsi_phy_set_clamp_state(ctrl->phy, enable);
  1866. if (rc) {
  1867. DSI_ERR("DSI phy clamp state change(%d) failed\n",
  1868. enable);
  1869. return rc;
  1870. }
  1871. DSI_DEBUG("Clamps %s for ctrl%d\n",
  1872. enable ? "enabled" : "disabled", i);
  1873. }
  1874. display->clamp_enabled = enable;
  1875. return 0;
  1876. }
  1877. /**
  1878. * dsi_display_setup_ctrl() - setup DSI controller.
  1879. * @dsi_display: DSI display handle.
  1880. *
  1881. * Return: error code.
  1882. */
  1883. static int dsi_display_ctrl_setup(struct dsi_display *display)
  1884. {
  1885. int rc = 0;
  1886. int i = 0;
  1887. struct dsi_display_ctrl *ctrl, *m_ctrl;
  1888. if (!display) {
  1889. DSI_ERR("Invalid params\n");
  1890. return -EINVAL;
  1891. }
  1892. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1893. rc = dsi_ctrl_setup(m_ctrl->ctrl);
  1894. if (rc) {
  1895. DSI_ERR("DSI controller setup failed\n");
  1896. return rc;
  1897. }
  1898. display_for_each_ctrl(i, display) {
  1899. ctrl = &display->ctrl[i];
  1900. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1901. continue;
  1902. rc = dsi_ctrl_setup(ctrl->ctrl);
  1903. if (rc) {
  1904. DSI_ERR("DSI controller setup failed\n");
  1905. return rc;
  1906. }
  1907. }
  1908. return 0;
  1909. }
  1910. static int dsi_display_phy_enable(struct dsi_display *display);
  1911. /**
  1912. * dsi_display_phy_idle_on() - enable DSI PHY while coming out of idle screen.
  1913. * @dsi_display: DSI display handle.
  1914. * @mmss_clamp: True if clamp is enabled.
  1915. *
  1916. * Return: error code.
  1917. */
  1918. static int dsi_display_phy_idle_on(struct dsi_display *display,
  1919. bool mmss_clamp)
  1920. {
  1921. int rc = 0;
  1922. int i = 0;
  1923. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1924. if (!display) {
  1925. DSI_ERR("Invalid params\n");
  1926. return -EINVAL;
  1927. }
  1928. if (mmss_clamp && !display->phy_idle_power_off) {
  1929. dsi_display_phy_enable(display);
  1930. return 0;
  1931. }
  1932. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1933. rc = dsi_phy_idle_ctrl(m_ctrl->phy, true);
  1934. if (rc) {
  1935. DSI_ERR("DSI controller setup failed\n");
  1936. return rc;
  1937. }
  1938. display_for_each_ctrl(i, display) {
  1939. ctrl = &display->ctrl[i];
  1940. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1941. continue;
  1942. rc = dsi_phy_idle_ctrl(ctrl->phy, true);
  1943. if (rc) {
  1944. DSI_ERR("DSI controller setup failed\n");
  1945. return rc;
  1946. }
  1947. }
  1948. display->phy_idle_power_off = false;
  1949. return 0;
  1950. }
  1951. /**
  1952. * dsi_display_phy_idle_off() - disable DSI PHY while going to idle screen.
  1953. * @dsi_display: DSI display handle.
  1954. *
  1955. * Return: error code.
  1956. */
  1957. static int dsi_display_phy_idle_off(struct dsi_display *display)
  1958. {
  1959. int rc = 0;
  1960. int i = 0;
  1961. struct dsi_display_ctrl *m_ctrl, *ctrl;
  1962. if (!display) {
  1963. DSI_ERR("Invalid params\n");
  1964. return -EINVAL;
  1965. }
  1966. display_for_each_ctrl(i, display) {
  1967. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  1968. if (!phy)
  1969. continue;
  1970. if (!phy->allow_phy_power_off) {
  1971. DSI_DEBUG("phy doesn't support this feature\n");
  1972. return 0;
  1973. }
  1974. }
  1975. m_ctrl = &display->ctrl[display->cmd_master_idx];
  1976. rc = dsi_phy_idle_ctrl(m_ctrl->phy, false);
  1977. if (rc) {
  1978. DSI_ERR("[%s] failed to enable cmd engine, rc=%d\n",
  1979. display->name, rc);
  1980. return rc;
  1981. }
  1982. display_for_each_ctrl(i, display) {
  1983. ctrl = &display->ctrl[i];
  1984. if (!ctrl->ctrl || (ctrl == m_ctrl))
  1985. continue;
  1986. rc = dsi_phy_idle_ctrl(ctrl->phy, false);
  1987. if (rc) {
  1988. DSI_ERR("DSI controller setup failed\n");
  1989. return rc;
  1990. }
  1991. }
  1992. display->phy_idle_power_off = true;
  1993. return 0;
  1994. }
  1995. void dsi_display_enable_event(struct drm_connector *connector,
  1996. struct dsi_display *display,
  1997. uint32_t event_idx, struct dsi_event_cb_info *event_info,
  1998. bool enable)
  1999. {
  2000. uint32_t irq_status_idx = DSI_STATUS_INTERRUPT_COUNT;
  2001. int i;
  2002. if (!display) {
  2003. DSI_ERR("invalid display\n");
  2004. return;
  2005. }
  2006. if (event_info)
  2007. event_info->event_idx = event_idx;
  2008. switch (event_idx) {
  2009. case SDE_CONN_EVENT_VID_DONE:
  2010. irq_status_idx = DSI_SINT_VIDEO_MODE_FRAME_DONE;
  2011. break;
  2012. case SDE_CONN_EVENT_CMD_DONE:
  2013. irq_status_idx = DSI_SINT_CMD_FRAME_DONE;
  2014. break;
  2015. case SDE_CONN_EVENT_VID_FIFO_OVERFLOW:
  2016. case SDE_CONN_EVENT_CMD_FIFO_UNDERFLOW:
  2017. if (event_info) {
  2018. display_for_each_ctrl(i, display)
  2019. display->ctrl[i].ctrl->recovery_cb =
  2020. *event_info;
  2021. }
  2022. break;
  2023. case SDE_CONN_EVENT_PANEL_ID:
  2024. if (event_info)
  2025. display_for_each_ctrl(i, display)
  2026. display->ctrl[i].ctrl->panel_id_cb
  2027. = *event_info;
  2028. break;
  2029. default:
  2030. /* nothing to do */
  2031. DSI_DEBUG("[%s] unhandled event %d\n", display->name, event_idx);
  2032. return;
  2033. }
  2034. if (enable) {
  2035. display_for_each_ctrl(i, display)
  2036. dsi_ctrl_enable_status_interrupt(
  2037. display->ctrl[i].ctrl, irq_status_idx,
  2038. event_info);
  2039. } else {
  2040. display_for_each_ctrl(i, display)
  2041. dsi_ctrl_disable_status_interrupt(
  2042. display->ctrl[i].ctrl, irq_status_idx);
  2043. }
  2044. }
  2045. static int dsi_display_ctrl_power_on(struct dsi_display *display)
  2046. {
  2047. int rc = 0;
  2048. int i;
  2049. struct dsi_display_ctrl *ctrl;
  2050. /* Sequence does not matter for split dsi usecases */
  2051. display_for_each_ctrl(i, display) {
  2052. ctrl = &display->ctrl[i];
  2053. if (!ctrl->ctrl)
  2054. continue;
  2055. rc = dsi_ctrl_set_power_state(ctrl->ctrl,
  2056. DSI_CTRL_POWER_VREG_ON);
  2057. if (rc) {
  2058. DSI_ERR("[%s] Failed to set power state, rc=%d\n",
  2059. ctrl->ctrl->name, rc);
  2060. goto error;
  2061. }
  2062. }
  2063. return rc;
  2064. error:
  2065. for (i = i - 1; i >= 0; i--) {
  2066. ctrl = &display->ctrl[i];
  2067. if (!ctrl->ctrl)
  2068. continue;
  2069. (void)dsi_ctrl_set_power_state(ctrl->ctrl,
  2070. DSI_CTRL_POWER_VREG_OFF);
  2071. }
  2072. return rc;
  2073. }
  2074. static int dsi_display_ctrl_power_off(struct dsi_display *display)
  2075. {
  2076. int rc = 0;
  2077. int i;
  2078. struct dsi_display_ctrl *ctrl;
  2079. /* Sequence does not matter for split dsi usecases */
  2080. display_for_each_ctrl(i, display) {
  2081. ctrl = &display->ctrl[i];
  2082. if (!ctrl->ctrl)
  2083. continue;
  2084. rc = dsi_ctrl_set_power_state(ctrl->ctrl,
  2085. DSI_CTRL_POWER_VREG_OFF);
  2086. if (rc) {
  2087. DSI_ERR("[%s] Failed to power off, rc=%d\n",
  2088. ctrl->ctrl->name, rc);
  2089. goto error;
  2090. }
  2091. }
  2092. error:
  2093. return rc;
  2094. }
  2095. static void dsi_display_parse_cmdline_topology(struct dsi_display *display,
  2096. unsigned int display_type)
  2097. {
  2098. char *boot_str = NULL;
  2099. char *str = NULL;
  2100. char *sw_te = NULL;
  2101. unsigned long cmdline_topology = NO_OVERRIDE;
  2102. unsigned long cmdline_timing = NO_OVERRIDE;
  2103. unsigned long panel_id = NO_OVERRIDE;
  2104. if (display_type >= MAX_DSI_ACTIVE_DISPLAY) {
  2105. DSI_ERR("display_type=%d not supported\n", display_type);
  2106. goto end;
  2107. }
  2108. if (display_type == DSI_PRIMARY)
  2109. boot_str = dsi_display_primary;
  2110. else
  2111. boot_str = dsi_display_secondary;
  2112. sw_te = strnstr(boot_str, ":sim-swte", strlen(boot_str));
  2113. if (sw_te)
  2114. display->sw_te_using_wd = true;
  2115. str = strnstr(boot_str, ":panelid", strlen(boot_str));
  2116. if (str) {
  2117. if (kstrtol(str + strlen(":panelid"), INT_BASE_10,
  2118. (unsigned long *)&panel_id)) {
  2119. DSI_INFO("panel id not found: %s\n", boot_str);
  2120. } else {
  2121. DSI_INFO("panel id found: %lx\n", panel_id);
  2122. display->panel_id = panel_id;
  2123. }
  2124. }
  2125. str = strnstr(boot_str, ":config", strlen(boot_str));
  2126. if (str) {
  2127. if (sscanf(str, ":config%lu", &cmdline_topology) != 1) {
  2128. DSI_ERR("invalid config index override: %s\n",
  2129. boot_str);
  2130. goto end;
  2131. }
  2132. }
  2133. str = strnstr(boot_str, ":timing", strlen(boot_str));
  2134. if (str) {
  2135. if (sscanf(str, ":timing%lu", &cmdline_timing) != 1) {
  2136. DSI_ERR("invalid timing index override: %s\n",
  2137. boot_str);
  2138. cmdline_topology = NO_OVERRIDE;
  2139. goto end;
  2140. }
  2141. }
  2142. DSI_DEBUG("successfully parsed command line topology and timing\n");
  2143. end:
  2144. display->cmdline_topology = cmdline_topology;
  2145. display->cmdline_timing = cmdline_timing;
  2146. }
  2147. /**
  2148. * dsi_display_parse_boot_display_selection()- Parse DSI boot display name
  2149. *
  2150. * Return: returns error status
  2151. */
  2152. static int dsi_display_parse_boot_display_selection(void)
  2153. {
  2154. char *pos = NULL;
  2155. char disp_buf[MAX_CMDLINE_PARAM_LEN] = {'\0'};
  2156. int i, j;
  2157. for (i = 0; i < MAX_DSI_ACTIVE_DISPLAY; i++) {
  2158. strlcpy(disp_buf, boot_displays[i].boot_param,
  2159. MAX_CMDLINE_PARAM_LEN);
  2160. pos = strnstr(disp_buf, ":", MAX_CMDLINE_PARAM_LEN);
  2161. /* Use ':' as a delimiter to retrieve the display name */
  2162. if (!pos) {
  2163. DSI_DEBUG("display name[%s]is not valid\n", disp_buf);
  2164. continue;
  2165. }
  2166. for (j = 0; (disp_buf + j) < pos; j++)
  2167. boot_displays[i].name[j] = *(disp_buf + j);
  2168. boot_displays[i].name[j] = '\0';
  2169. boot_displays[i].boot_disp_en = true;
  2170. }
  2171. return 0;
  2172. }
  2173. static int dsi_display_phy_power_on(struct dsi_display *display)
  2174. {
  2175. int rc = 0;
  2176. int i;
  2177. struct dsi_display_ctrl *ctrl;
  2178. /* Sequence does not matter for split dsi usecases */
  2179. display_for_each_ctrl(i, display) {
  2180. ctrl = &display->ctrl[i];
  2181. if (!ctrl->ctrl)
  2182. continue;
  2183. rc = dsi_phy_set_power_state(ctrl->phy, true);
  2184. if (rc) {
  2185. DSI_ERR("[%s] Failed to set power state, rc=%d\n",
  2186. ctrl->phy->name, rc);
  2187. goto error;
  2188. }
  2189. }
  2190. return rc;
  2191. error:
  2192. for (i = i - 1; i >= 0; i--) {
  2193. ctrl = &display->ctrl[i];
  2194. if (!ctrl->phy)
  2195. continue;
  2196. (void)dsi_phy_set_power_state(ctrl->phy, false);
  2197. }
  2198. return rc;
  2199. }
  2200. static int dsi_display_phy_power_off(struct dsi_display *display)
  2201. {
  2202. int rc = 0;
  2203. int i;
  2204. struct dsi_display_ctrl *ctrl;
  2205. /* Sequence does not matter for split dsi usecases */
  2206. display_for_each_ctrl(i, display) {
  2207. ctrl = &display->ctrl[i];
  2208. if (!ctrl->phy)
  2209. continue;
  2210. rc = dsi_phy_set_power_state(ctrl->phy, false);
  2211. if (rc) {
  2212. DSI_ERR("[%s] Failed to power off, rc=%d\n",
  2213. ctrl->ctrl->name, rc);
  2214. goto error;
  2215. }
  2216. }
  2217. error:
  2218. return rc;
  2219. }
  2220. static int dsi_display_set_clk_src(struct dsi_display *display, bool set_xo)
  2221. {
  2222. int rc = 0;
  2223. int i;
  2224. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2225. struct dsi_ctrl_clk_info *info;
  2226. if (display->trusted_vm_env)
  2227. return 0;
  2228. /*
  2229. * In case of split DSI usecases, the clock for master controller should
  2230. * be enabled before the other controller. Master controller in the
  2231. * clock context refers to the controller that sources the clock. While turning off the
  2232. * clocks, the source is set to xo.
  2233. */
  2234. m_ctrl = &display->ctrl[display->clk_master_idx];
  2235. info = &m_ctrl->ctrl->clk_info;
  2236. if (!set_xo)
  2237. rc = dsi_ctrl_set_clock_source(m_ctrl->ctrl, &display->clock_info.pll_clks);
  2238. else if ((info->xo_clk.byte_clk) && (info->xo_clk.pixel_clk))
  2239. rc = dsi_ctrl_set_clock_source(m_ctrl->ctrl, &info->xo_clk);
  2240. if (rc) {
  2241. DSI_ERR("[%s] failed to set source clocks for master, rc=%d\n", display->name, rc);
  2242. return rc;
  2243. }
  2244. /* Set source for the rest of the controllers */
  2245. display_for_each_ctrl(i, display) {
  2246. ctrl = &display->ctrl[i];
  2247. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2248. continue;
  2249. info = &ctrl->ctrl->clk_info;
  2250. if (!set_xo)
  2251. rc = dsi_ctrl_set_clock_source(ctrl->ctrl, &display->clock_info.pll_clks);
  2252. else if ((info->xo_clk.byte_clk) && (info->xo_clk.pixel_clk))
  2253. rc = dsi_ctrl_set_clock_source(ctrl->ctrl, &info->xo_clk);
  2254. if (rc) {
  2255. DSI_ERR("[%s] failed to set source clocks, rc=%d\n", display->name, rc);
  2256. return rc;
  2257. }
  2258. }
  2259. return 0;
  2260. }
  2261. int dsi_display_phy_pll_toggle(void *priv, bool prepare)
  2262. {
  2263. int rc = 0;
  2264. struct dsi_display *display = priv;
  2265. struct dsi_display_ctrl *m_ctrl;
  2266. if (!display) {
  2267. DSI_ERR("invalid arguments\n");
  2268. return -EINVAL;
  2269. }
  2270. rc = dsi_display_set_clk_src(display, !prepare);
  2271. m_ctrl = &display->ctrl[display->clk_master_idx];
  2272. if (!m_ctrl->phy) {
  2273. DSI_ERR("[%s] PHY not found\n", display->name);
  2274. return -EINVAL;
  2275. }
  2276. rc = dsi_phy_pll_toggle(m_ctrl->phy, prepare);
  2277. return rc;
  2278. }
  2279. int dsi_display_phy_configure(void *priv, bool commit)
  2280. {
  2281. int rc = 0;
  2282. struct dsi_display *display = priv;
  2283. struct dsi_display_ctrl *m_ctrl;
  2284. struct dsi_pll_resource *pll_res;
  2285. struct dsi_ctrl *ctrl;
  2286. if (!display) {
  2287. DSI_ERR("invalid arguments\n");
  2288. return -EINVAL;
  2289. }
  2290. m_ctrl = &display->ctrl[display->clk_master_idx];
  2291. if ((!m_ctrl->phy) || (!m_ctrl->ctrl)) {
  2292. DSI_ERR("[%s] PHY not found\n", display->name);
  2293. return -EINVAL;
  2294. }
  2295. pll_res = m_ctrl->phy->pll;
  2296. if (!pll_res) {
  2297. DSI_ERR("[%s] PLL res not found\n", display->name);
  2298. return -EINVAL;
  2299. }
  2300. ctrl = m_ctrl->ctrl;
  2301. pll_res->byteclk_rate = ctrl->clk_freq.byte_clk_rate;
  2302. pll_res->pclk_rate = ctrl->clk_freq.pix_clk_rate;
  2303. rc = dsi_phy_configure(m_ctrl->phy, commit);
  2304. return rc;
  2305. }
  2306. static int dsi_display_phy_reset_config(struct dsi_display *display,
  2307. bool enable)
  2308. {
  2309. int rc = 0;
  2310. int i;
  2311. struct dsi_display_ctrl *ctrl;
  2312. display_for_each_ctrl(i, display) {
  2313. ctrl = &display->ctrl[i];
  2314. rc = dsi_ctrl_phy_reset_config(ctrl->ctrl, enable);
  2315. if (rc) {
  2316. DSI_ERR("[%s] failed to %s phy reset, rc=%d\n",
  2317. display->name, enable ? "mask" : "unmask", rc);
  2318. return rc;
  2319. }
  2320. }
  2321. return 0;
  2322. }
  2323. static void dsi_display_toggle_resync_fifo(struct dsi_display *display)
  2324. {
  2325. struct dsi_display_ctrl *ctrl;
  2326. int i;
  2327. if (!display)
  2328. return;
  2329. display_for_each_ctrl(i, display) {
  2330. ctrl = &display->ctrl[i];
  2331. dsi_phy_toggle_resync_fifo(ctrl->phy);
  2332. }
  2333. /*
  2334. * After retime buffer synchronization we need to turn of clk_en_sel
  2335. * bit on each phy. Avoid this for Cphy.
  2336. */
  2337. if (display->panel->host_config.phy_type == DSI_PHY_TYPE_CPHY)
  2338. return;
  2339. display_for_each_ctrl(i, display) {
  2340. ctrl = &display->ctrl[i];
  2341. dsi_phy_reset_clk_en_sel(ctrl->phy);
  2342. }
  2343. }
  2344. static int dsi_display_ctrl_update(struct dsi_display *display)
  2345. {
  2346. int rc = 0;
  2347. int i;
  2348. struct dsi_display_ctrl *ctrl;
  2349. display_for_each_ctrl(i, display) {
  2350. ctrl = &display->ctrl[i];
  2351. rc = dsi_ctrl_host_timing_update(ctrl->ctrl);
  2352. if (rc) {
  2353. DSI_ERR("[%s] failed to update host_%d, rc=%d\n",
  2354. display->name, i, rc);
  2355. goto error_host_deinit;
  2356. }
  2357. }
  2358. return 0;
  2359. error_host_deinit:
  2360. for (i = i - 1; i >= 0; i--) {
  2361. ctrl = &display->ctrl[i];
  2362. (void)dsi_ctrl_host_deinit(ctrl->ctrl);
  2363. }
  2364. return rc;
  2365. }
  2366. static int dsi_display_ctrl_init(struct dsi_display *display)
  2367. {
  2368. int rc = 0;
  2369. int i;
  2370. struct dsi_display_ctrl *ctrl;
  2371. bool skip_op = is_skip_op_required(display);
  2372. /* when ULPS suspend feature is enabled, we will keep the lanes in
  2373. * ULPS during suspend state and clamp DSI phy. Hence while resuming
  2374. * we will programe DSI controller as part of core clock enable.
  2375. * After that we should not re-configure DSI controller again here for
  2376. * usecases where we are resuming from ulps suspend as it might put
  2377. * the HW in bad state.
  2378. */
  2379. if (!display->panel->ulps_suspend_enabled || !display->ulps_enabled) {
  2380. display_for_each_ctrl(i, display) {
  2381. ctrl = &display->ctrl[i];
  2382. rc = dsi_ctrl_host_init(ctrl->ctrl, skip_op);
  2383. if (rc) {
  2384. DSI_ERR(
  2385. "[%s] failed to init host_%d, skip_op=%d, rc=%d\n",
  2386. display->name, i, skip_op, rc);
  2387. goto error_host_deinit;
  2388. }
  2389. }
  2390. } else {
  2391. display_for_each_ctrl(i, display) {
  2392. ctrl = &display->ctrl[i];
  2393. rc = dsi_ctrl_update_host_state(ctrl->ctrl,
  2394. DSI_CTRL_OP_HOST_INIT,
  2395. true);
  2396. if (rc)
  2397. DSI_DEBUG("host init update failed rc=%d\n",
  2398. rc);
  2399. }
  2400. }
  2401. return rc;
  2402. error_host_deinit:
  2403. for (i = i - 1; i >= 0; i--) {
  2404. ctrl = &display->ctrl[i];
  2405. (void)dsi_ctrl_host_deinit(ctrl->ctrl);
  2406. }
  2407. return rc;
  2408. }
  2409. static int dsi_display_ctrl_deinit(struct dsi_display *display)
  2410. {
  2411. int rc = 0;
  2412. int i;
  2413. struct dsi_display_ctrl *ctrl;
  2414. display_for_each_ctrl(i, display) {
  2415. ctrl = &display->ctrl[i];
  2416. rc = dsi_ctrl_host_deinit(ctrl->ctrl);
  2417. if (rc) {
  2418. DSI_ERR("[%s] failed to deinit host_%d, rc=%d\n",
  2419. display->name, i, rc);
  2420. }
  2421. }
  2422. return rc;
  2423. }
  2424. static int dsi_display_ctrl_host_enable(struct dsi_display *display)
  2425. {
  2426. int rc = 0;
  2427. int i;
  2428. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2429. bool skip_op = is_skip_op_required(display);
  2430. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2431. rc = dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2432. DSI_CTRL_ENGINE_ON, skip_op);
  2433. if (rc) {
  2434. DSI_ERR("[%s]enable host engine failed, skip_op:%d rc:%d\n",
  2435. display->name, skip_op, rc);
  2436. goto error;
  2437. }
  2438. display_for_each_ctrl(i, display) {
  2439. ctrl = &display->ctrl[i];
  2440. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2441. continue;
  2442. rc = dsi_ctrl_set_host_engine_state(ctrl->ctrl,
  2443. DSI_CTRL_ENGINE_ON, skip_op);
  2444. if (rc) {
  2445. DSI_ERR(
  2446. "[%s] enable host engine failed, skip_op:%d rc:%d\n",
  2447. display->name, skip_op, rc);
  2448. goto error_disable_master;
  2449. }
  2450. }
  2451. return rc;
  2452. error_disable_master:
  2453. (void)dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2454. DSI_CTRL_ENGINE_OFF, skip_op);
  2455. error:
  2456. return rc;
  2457. }
  2458. static int dsi_display_ctrl_host_disable(struct dsi_display *display)
  2459. {
  2460. int rc = 0;
  2461. int i;
  2462. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2463. bool skip_op = is_skip_op_required(display);
  2464. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2465. /*
  2466. * For platforms where ULPS is controlled by DSI controller block,
  2467. * do not disable dsi controller block if lanes are to be
  2468. * kept in ULPS during suspend. So just update the SW state
  2469. * and return early.
  2470. */
  2471. if (display->panel->ulps_suspend_enabled &&
  2472. !m_ctrl->phy->hw.ops.ulps_ops.ulps_request) {
  2473. display_for_each_ctrl(i, display) {
  2474. ctrl = &display->ctrl[i];
  2475. rc = dsi_ctrl_update_host_state(ctrl->ctrl,
  2476. DSI_CTRL_OP_HOST_ENGINE,
  2477. false);
  2478. if (rc)
  2479. DSI_DEBUG("host state update failed %d\n", rc);
  2480. }
  2481. return rc;
  2482. }
  2483. display_for_each_ctrl(i, display) {
  2484. ctrl = &display->ctrl[i];
  2485. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2486. continue;
  2487. rc = dsi_ctrl_set_host_engine_state(ctrl->ctrl,
  2488. DSI_CTRL_ENGINE_OFF, skip_op);
  2489. if (rc)
  2490. DSI_ERR(
  2491. "[%s] disable host engine failed, skip_op:%d rc:%d\n",
  2492. display->name, skip_op, rc);
  2493. }
  2494. rc = dsi_ctrl_set_host_engine_state(m_ctrl->ctrl,
  2495. DSI_CTRL_ENGINE_OFF, skip_op);
  2496. if (rc) {
  2497. DSI_ERR("[%s] disable mhost engine failed, skip_op:%d rc:%d\n",
  2498. display->name, skip_op, rc);
  2499. goto error;
  2500. }
  2501. error:
  2502. return rc;
  2503. }
  2504. static int dsi_display_vid_engine_enable(struct dsi_display *display)
  2505. {
  2506. int rc = 0;
  2507. int i;
  2508. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2509. bool skip_op = is_skip_op_required(display);
  2510. m_ctrl = &display->ctrl[display->video_master_idx];
  2511. rc = dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2512. DSI_CTRL_ENGINE_ON, skip_op);
  2513. if (rc) {
  2514. DSI_ERR("[%s] enable mvid engine failed, skip_op:%d rc:%d\n",
  2515. display->name, skip_op, rc);
  2516. goto error;
  2517. }
  2518. display_for_each_ctrl(i, display) {
  2519. ctrl = &display->ctrl[i];
  2520. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2521. continue;
  2522. rc = dsi_ctrl_set_vid_engine_state(ctrl->ctrl,
  2523. DSI_CTRL_ENGINE_ON, skip_op);
  2524. if (rc) {
  2525. DSI_ERR(
  2526. "[%s] enable vid engine failed, skip_op:%d rc:%d\n",
  2527. display->name, skip_op, rc);
  2528. goto error_disable_master;
  2529. }
  2530. }
  2531. return rc;
  2532. error_disable_master:
  2533. (void)dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2534. DSI_CTRL_ENGINE_OFF, skip_op);
  2535. error:
  2536. return rc;
  2537. }
  2538. static int dsi_display_vid_engine_disable(struct dsi_display *display)
  2539. {
  2540. int rc = 0;
  2541. int i;
  2542. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2543. bool skip_op = is_skip_op_required(display);
  2544. m_ctrl = &display->ctrl[display->video_master_idx];
  2545. display_for_each_ctrl(i, display) {
  2546. ctrl = &display->ctrl[i];
  2547. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2548. continue;
  2549. rc = dsi_ctrl_set_vid_engine_state(ctrl->ctrl,
  2550. DSI_CTRL_ENGINE_OFF, skip_op);
  2551. if (rc)
  2552. DSI_ERR(
  2553. "[%s] disable vid engine failed, skip_op:%d rc:%d\n",
  2554. display->name, skip_op, rc);
  2555. }
  2556. rc = dsi_ctrl_set_vid_engine_state(m_ctrl->ctrl,
  2557. DSI_CTRL_ENGINE_OFF, skip_op);
  2558. if (rc)
  2559. DSI_ERR("[%s] disable mvid engine failed, skip_op:%d rc:%d\n",
  2560. display->name, skip_op, rc);
  2561. return rc;
  2562. }
  2563. static int dsi_display_phy_enable(struct dsi_display *display)
  2564. {
  2565. int rc = 0;
  2566. int i;
  2567. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2568. enum dsi_phy_pll_source m_src = DSI_PLL_SOURCE_STANDALONE;
  2569. bool skip_op = is_skip_op_required(display);
  2570. m_ctrl = &display->ctrl[display->clk_master_idx];
  2571. if (display->ctrl_count > 1)
  2572. m_src = DSI_PLL_SOURCE_NATIVE;
  2573. rc = dsi_phy_enable(m_ctrl->phy, &display->config,
  2574. m_src, true, skip_op);
  2575. if (rc) {
  2576. DSI_ERR("[%s] failed to enable DSI PHY, skip_op=%d rc=%d\n",
  2577. display->name, skip_op, rc);
  2578. goto error;
  2579. }
  2580. display_for_each_ctrl(i, display) {
  2581. ctrl = &display->ctrl[i];
  2582. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2583. continue;
  2584. rc = dsi_phy_enable(ctrl->phy, &display->config,
  2585. DSI_PLL_SOURCE_NON_NATIVE, true, skip_op);
  2586. if (rc) {
  2587. DSI_ERR(
  2588. "[%s] failed to enable DSI PHY, skip_op: %d rc=%d\n",
  2589. display->name, skip_op, rc);
  2590. goto error_disable_master;
  2591. }
  2592. }
  2593. return rc;
  2594. error_disable_master:
  2595. (void)dsi_phy_disable(m_ctrl->phy, skip_op);
  2596. error:
  2597. return rc;
  2598. }
  2599. static int dsi_display_phy_disable(struct dsi_display *display)
  2600. {
  2601. int rc = 0;
  2602. int i;
  2603. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2604. bool skip_op = is_skip_op_required(display);
  2605. m_ctrl = &display->ctrl[display->clk_master_idx];
  2606. display_for_each_ctrl(i, display) {
  2607. ctrl = &display->ctrl[i];
  2608. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2609. continue;
  2610. rc = dsi_phy_disable(ctrl->phy, skip_op);
  2611. if (rc)
  2612. DSI_ERR(
  2613. "[%s] failed to disable DSI PHY, skip_op=%d rc=%d\n",
  2614. display->name, skip_op, rc);
  2615. }
  2616. rc = dsi_phy_disable(m_ctrl->phy, skip_op);
  2617. if (rc)
  2618. DSI_ERR("[%s] failed to disable DSI PHY, skip_op=%d rc=%d\n",
  2619. display->name, skip_op, rc);
  2620. return rc;
  2621. }
  2622. static int dsi_display_wake_up(struct dsi_display *display)
  2623. {
  2624. return 0;
  2625. }
  2626. static void dsi_display_mask_overflow(struct dsi_display *display, u32 flags,
  2627. bool enable)
  2628. {
  2629. struct dsi_display_ctrl *ctrl;
  2630. int i;
  2631. if (!(flags & DSI_CTRL_CMD_LAST_COMMAND))
  2632. return;
  2633. display_for_each_ctrl(i, display) {
  2634. ctrl = &display->ctrl[i];
  2635. if (!ctrl)
  2636. continue;
  2637. dsi_ctrl_mask_overflow(ctrl->ctrl, enable);
  2638. }
  2639. }
  2640. static int dsi_display_broadcast_cmd(struct dsi_display *display, struct dsi_cmd_desc *cmd)
  2641. {
  2642. int rc = 0;
  2643. struct dsi_display_ctrl *ctrl, *m_ctrl;
  2644. int i;
  2645. /*
  2646. * 1. Setup commands in FIFO
  2647. * 2. Trigger commands
  2648. */
  2649. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2650. dsi_display_mask_overflow(display, cmd->ctrl_flags, true);
  2651. cmd->ctrl_flags |= DSI_CTRL_CMD_BROADCAST_MASTER;
  2652. rc = dsi_ctrl_cmd_transfer(m_ctrl->ctrl, cmd);
  2653. if (rc) {
  2654. DSI_ERR("[%s] cmd transfer failed on master,rc=%d\n",
  2655. display->name, rc);
  2656. goto error;
  2657. }
  2658. cmd->ctrl_flags &= ~DSI_CTRL_CMD_BROADCAST_MASTER;
  2659. display_for_each_ctrl(i, display) {
  2660. ctrl = &display->ctrl[i];
  2661. if (ctrl == m_ctrl)
  2662. continue;
  2663. rc = dsi_ctrl_cmd_transfer(ctrl->ctrl, cmd);
  2664. if (rc) {
  2665. DSI_ERR("[%s] cmd transfer failed, rc=%d\n",
  2666. display->name, rc);
  2667. goto error;
  2668. }
  2669. rc = dsi_ctrl_cmd_tx_trigger(ctrl->ctrl, cmd->ctrl_flags);
  2670. if (rc) {
  2671. DSI_ERR("[%s] cmd trigger failed, rc=%d\n",
  2672. display->name, rc);
  2673. goto error;
  2674. }
  2675. }
  2676. rc = dsi_ctrl_cmd_tx_trigger(m_ctrl->ctrl, cmd->ctrl_flags | DSI_CTRL_CMD_BROADCAST_MASTER);
  2677. if (rc) {
  2678. DSI_ERR("[%s] cmd trigger failed for master, rc=%d\n",
  2679. display->name, rc);
  2680. goto error;
  2681. }
  2682. error:
  2683. dsi_display_mask_overflow(display, cmd->ctrl_flags, false);
  2684. return rc;
  2685. }
  2686. static int dsi_display_phy_sw_reset(struct dsi_display *display)
  2687. {
  2688. int rc = 0;
  2689. int i;
  2690. struct dsi_display_ctrl *m_ctrl, *ctrl;
  2691. /*
  2692. * For continuous splash and trusted vm environment,
  2693. * ctrl states are updated separately and hence we do
  2694. * an early return
  2695. */
  2696. if (is_skip_op_required(display)) {
  2697. DSI_DEBUG(
  2698. "cont splash/trusted vm use case, phy sw reset not required\n");
  2699. return 0;
  2700. }
  2701. m_ctrl = &display->ctrl[display->cmd_master_idx];
  2702. rc = dsi_ctrl_phy_sw_reset(m_ctrl->ctrl);
  2703. if (rc) {
  2704. DSI_ERR("[%s] failed to reset phy, rc=%d\n", display->name, rc);
  2705. goto error;
  2706. }
  2707. display_for_each_ctrl(i, display) {
  2708. ctrl = &display->ctrl[i];
  2709. if (!ctrl->ctrl || (ctrl == m_ctrl))
  2710. continue;
  2711. rc = dsi_ctrl_phy_sw_reset(ctrl->ctrl);
  2712. if (rc) {
  2713. DSI_ERR("[%s] failed to reset phy, rc=%d\n",
  2714. display->name, rc);
  2715. goto error;
  2716. }
  2717. }
  2718. error:
  2719. return rc;
  2720. }
  2721. static int dsi_host_attach(struct mipi_dsi_host *host,
  2722. struct mipi_dsi_device *dsi)
  2723. {
  2724. return 0;
  2725. }
  2726. static int dsi_host_detach(struct mipi_dsi_host *host,
  2727. struct mipi_dsi_device *dsi)
  2728. {
  2729. return 0;
  2730. }
  2731. int dsi_host_transfer_sub(struct mipi_dsi_host *host, struct dsi_cmd_desc *cmd)
  2732. {
  2733. struct dsi_display *display;
  2734. int rc = 0, ret = 0;
  2735. if (!host || !cmd) {
  2736. DSI_ERR("Invalid params\n");
  2737. return 0;
  2738. }
  2739. display = to_dsi_display(host);
  2740. /* Avoid sending DCS commands when ESD recovery is pending */
  2741. if (atomic_read(&display->panel->esd_recovery_pending)) {
  2742. DSI_DEBUG("ESD recovery pending\n");
  2743. return 0;
  2744. }
  2745. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  2746. DSI_ALL_CLKS, DSI_CLK_ON);
  2747. if (rc) {
  2748. DSI_ERR("[%s] failed to enable all DSI clocks, rc=%d\n",
  2749. display->name, rc);
  2750. goto error;
  2751. }
  2752. rc = dsi_display_wake_up(display);
  2753. if (rc) {
  2754. DSI_ERR("[%s] failed to wake up display, rc=%d\n",
  2755. display->name, rc);
  2756. goto error_disable_clks;
  2757. }
  2758. rc = dsi_display_cmd_engine_enable(display);
  2759. if (rc) {
  2760. DSI_ERR("[%s] failed to enable cmd engine, rc=%d\n",
  2761. display->name, rc);
  2762. goto error_disable_clks;
  2763. }
  2764. if (display->tx_cmd_buf == NULL) {
  2765. rc = dsi_host_alloc_cmd_tx_buffer(display);
  2766. if (rc) {
  2767. DSI_ERR("failed to allocate cmd tx buffer memory\n");
  2768. goto error_disable_cmd_engine;
  2769. }
  2770. }
  2771. dsi_display_set_cmd_tx_ctrl_flags(display, cmd);
  2772. if (cmd->ctrl_flags & DSI_CTRL_CMD_BROADCAST) {
  2773. rc = dsi_display_broadcast_cmd(display, cmd);
  2774. if (rc) {
  2775. DSI_ERR("[%s] cmd broadcast failed, rc=%d\n", display->name, rc);
  2776. goto error_disable_cmd_engine;
  2777. }
  2778. } else {
  2779. int idx = cmd->ctrl;
  2780. rc = dsi_ctrl_cmd_transfer(display->ctrl[idx].ctrl, cmd);
  2781. if (rc) {
  2782. DSI_ERR("[%s] cmd transfer failed, rc=%d\n",
  2783. display->name, rc);
  2784. goto error_disable_cmd_engine;
  2785. }
  2786. }
  2787. error_disable_cmd_engine:
  2788. ret = dsi_display_cmd_engine_disable(display);
  2789. if (ret) {
  2790. DSI_ERR("[%s]failed to disable DSI cmd engine, rc=%d\n",
  2791. display->name, ret);
  2792. }
  2793. error_disable_clks:
  2794. ret = dsi_display_clk_ctrl(display->dsi_clk_handle,
  2795. DSI_ALL_CLKS, DSI_CLK_OFF);
  2796. if (ret) {
  2797. DSI_ERR("[%s] failed to disable all DSI clocks, rc=%d\n",
  2798. display->name, ret);
  2799. }
  2800. error:
  2801. return rc;
  2802. }
  2803. static ssize_t dsi_host_transfer(struct mipi_dsi_host *host, const struct mipi_dsi_msg *msg)
  2804. {
  2805. int rc = 0;
  2806. struct dsi_cmd_desc cmd;
  2807. if (!msg) {
  2808. DSI_ERR("Invalid params\n");
  2809. return 0;
  2810. }
  2811. memcpy(&cmd.msg, msg, sizeof(*msg));
  2812. cmd.ctrl = 0;
  2813. cmd.post_wait_ms = 0;
  2814. cmd.ctrl_flags = 0;
  2815. rc = dsi_host_transfer_sub(host, &cmd);
  2816. return rc;
  2817. }
  2818. static struct mipi_dsi_host_ops dsi_host_ops = {
  2819. .attach = dsi_host_attach,
  2820. .detach = dsi_host_detach,
  2821. .transfer = dsi_host_transfer,
  2822. };
  2823. static int dsi_display_mipi_host_init(struct dsi_display *display)
  2824. {
  2825. int rc = 0;
  2826. struct mipi_dsi_host *host = &display->host;
  2827. host->dev = &display->pdev->dev;
  2828. host->ops = &dsi_host_ops;
  2829. rc = mipi_dsi_host_register(host);
  2830. if (rc) {
  2831. DSI_ERR("[%s] failed to register mipi dsi host, rc=%d\n",
  2832. display->name, rc);
  2833. goto error;
  2834. }
  2835. error:
  2836. return rc;
  2837. }
  2838. static int dsi_display_mipi_host_deinit(struct dsi_display *display)
  2839. {
  2840. int rc = 0;
  2841. struct mipi_dsi_host *host = &display->host;
  2842. mipi_dsi_host_unregister(host);
  2843. host->dev = NULL;
  2844. host->ops = NULL;
  2845. return rc;
  2846. }
  2847. static bool dsi_display_check_prefix(const char *clk_prefix,
  2848. const char *clk_name)
  2849. {
  2850. return !!strnstr(clk_name, clk_prefix, strlen(clk_name));
  2851. }
  2852. static int dsi_display_get_clocks_count(struct dsi_display *display,
  2853. char *dsi_clk_name)
  2854. {
  2855. if (display->fw)
  2856. return dsi_parser_count_strings(display->parser_node,
  2857. dsi_clk_name);
  2858. else
  2859. return of_property_count_strings(display->panel_node,
  2860. dsi_clk_name);
  2861. }
  2862. static void dsi_display_get_clock_name(struct dsi_display *display,
  2863. char *dsi_clk_name, int index,
  2864. const char **clk_name)
  2865. {
  2866. if (display->fw)
  2867. dsi_parser_read_string_index(display->parser_node,
  2868. dsi_clk_name, index, clk_name);
  2869. else
  2870. of_property_read_string_index(display->panel_node,
  2871. dsi_clk_name, index, clk_name);
  2872. }
  2873. static int dsi_display_clocks_init(struct dsi_display *display)
  2874. {
  2875. int i, rc = 0, num_clk = 0;
  2876. const char *clk_name;
  2877. const char *pll_byte = "pll_byte", *pll_dsi = "pll_dsi";
  2878. struct clk *dsi_clk;
  2879. struct dsi_clk_link_set *pll = &display->clock_info.pll_clks;
  2880. char *dsi_clock_name;
  2881. if (!strcmp(display->display_type, "primary"))
  2882. dsi_clock_name = "qcom,dsi-select-clocks";
  2883. else
  2884. dsi_clock_name = "qcom,dsi-select-sec-clocks";
  2885. num_clk = dsi_display_get_clocks_count(display, dsi_clock_name);
  2886. for (i = 0; i < num_clk; i++) {
  2887. dsi_display_get_clock_name(display, dsi_clock_name, i,
  2888. &clk_name);
  2889. DSI_DEBUG("clock name:%s\n", clk_name);
  2890. dsi_clk = devm_clk_get(&display->pdev->dev, clk_name);
  2891. if (IS_ERR_OR_NULL(dsi_clk)) {
  2892. rc = PTR_ERR(dsi_clk);
  2893. DSI_ERR("failed to get %s, rc=%d\n", clk_name, rc);
  2894. if (dsi_display_check_prefix(pll_byte, clk_name)) {
  2895. pll->byte_clk = NULL;
  2896. goto error;
  2897. }
  2898. if (dsi_display_check_prefix(pll_dsi, clk_name)) {
  2899. pll->pixel_clk = NULL;
  2900. goto error;
  2901. }
  2902. }
  2903. if (dsi_display_check_prefix(pll_byte, clk_name)) {
  2904. pll->byte_clk = dsi_clk;
  2905. continue;
  2906. }
  2907. if (dsi_display_check_prefix(pll_dsi, clk_name)) {
  2908. pll->pixel_clk = dsi_clk;
  2909. continue;
  2910. }
  2911. }
  2912. return 0;
  2913. error:
  2914. return rc;
  2915. }
  2916. static int dsi_display_clk_ctrl_cb(void *priv,
  2917. struct dsi_clk_ctrl_info clk_state_info)
  2918. {
  2919. int rc = 0;
  2920. struct dsi_display *display = NULL;
  2921. void *clk_handle = NULL;
  2922. if (!priv) {
  2923. DSI_ERR("Invalid params\n");
  2924. return -EINVAL;
  2925. }
  2926. display = priv;
  2927. if (clk_state_info.client == DSI_CLK_REQ_MDP_CLIENT) {
  2928. clk_handle = display->mdp_clk_handle;
  2929. } else if (clk_state_info.client == DSI_CLK_REQ_DSI_CLIENT) {
  2930. clk_handle = display->dsi_clk_handle;
  2931. } else {
  2932. DSI_ERR("invalid clk handle, return error\n");
  2933. return -EINVAL;
  2934. }
  2935. /*
  2936. * TODO: Wait for CMD_MDP_DONE interrupt if MDP client tries
  2937. * to turn off DSI clocks.
  2938. */
  2939. rc = dsi_display_clk_ctrl(clk_handle,
  2940. clk_state_info.clk_type, clk_state_info.clk_state);
  2941. if (rc) {
  2942. DSI_ERR("[%s] failed to %d DSI %d clocks, rc=%d\n",
  2943. display->name, clk_state_info.clk_state,
  2944. clk_state_info.clk_type, rc);
  2945. return rc;
  2946. }
  2947. return 0;
  2948. }
  2949. static void dsi_display_ctrl_isr_configure(struct dsi_display *display, bool en)
  2950. {
  2951. int i;
  2952. struct dsi_display_ctrl *ctrl;
  2953. if (!display)
  2954. return;
  2955. display_for_each_ctrl(i, display) {
  2956. ctrl = &display->ctrl[i];
  2957. if (!ctrl)
  2958. continue;
  2959. dsi_ctrl_isr_configure(ctrl->ctrl, en);
  2960. }
  2961. }
  2962. int dsi_pre_clkoff_cb(void *priv,
  2963. enum dsi_clk_type clk,
  2964. enum dsi_lclk_type l_type,
  2965. enum dsi_clk_state new_state)
  2966. {
  2967. int rc = 0, i;
  2968. struct dsi_display *display = priv;
  2969. struct dsi_display_ctrl *ctrl;
  2970. /*
  2971. * If Idle Power Collapse occurs immediately after a CMD
  2972. * transfer with an asynchronous wait for DMA done, ensure
  2973. * that the work queued is scheduled and completed before turning
  2974. * off the clocks and disabling interrupts to validate the command
  2975. * transfer.
  2976. */
  2977. display_for_each_ctrl(i, display) {
  2978. ctrl = &display->ctrl[i];
  2979. if (!ctrl->ctrl || !ctrl->ctrl->dma_wait_queued)
  2980. continue;
  2981. flush_workqueue(display->dma_cmd_workq);
  2982. cancel_work_sync(&ctrl->ctrl->dma_cmd_wait);
  2983. ctrl->ctrl->dma_wait_queued = false;
  2984. }
  2985. if ((clk & DSI_LINK_CLK) && (new_state == DSI_CLK_OFF) &&
  2986. (l_type & DSI_LINK_LP_CLK)) {
  2987. /*
  2988. * If continuous clock is enabled then disable it
  2989. * before entering into ULPS Mode.
  2990. */
  2991. if (display->panel->host_config.force_hs_clk_lane)
  2992. _dsi_display_continuous_clk_ctrl(display, false);
  2993. /*
  2994. * If ULPS feature is enabled, enter ULPS first.
  2995. * However, when blanking the panel, we should enter ULPS
  2996. * only if ULPS during suspend feature is enabled.
  2997. */
  2998. if (!dsi_panel_initialized(display->panel)) {
  2999. if (display->panel->ulps_suspend_enabled)
  3000. rc = dsi_display_set_ulps(display, true);
  3001. } else if (dsi_panel_ulps_feature_enabled(display->panel)) {
  3002. rc = dsi_display_set_ulps(display, true);
  3003. }
  3004. if (rc)
  3005. DSI_ERR("%s: failed enable ulps, rc = %d\n",
  3006. __func__, rc);
  3007. }
  3008. if ((clk & DSI_LINK_CLK) && (new_state == DSI_CLK_OFF) &&
  3009. (l_type & DSI_LINK_HS_CLK)) {
  3010. /*
  3011. * PHY clock gating should be disabled before the PLL and the
  3012. * branch clocks are turned off. Otherwise, it is possible that
  3013. * the clock RCGs may not be turned off correctly resulting
  3014. * in clock warnings.
  3015. */
  3016. rc = dsi_display_config_clk_gating(display, false);
  3017. if (rc)
  3018. DSI_ERR("[%s] failed to disable clk gating, rc=%d\n",
  3019. display->name, rc);
  3020. }
  3021. if ((clk & DSI_CORE_CLK) && (new_state == DSI_CLK_OFF)) {
  3022. /*
  3023. * Enable DSI clamps only if entering idle power collapse or
  3024. * when ULPS during suspend is enabled..
  3025. */
  3026. if (dsi_panel_initialized(display->panel) ||
  3027. display->panel->ulps_suspend_enabled) {
  3028. dsi_display_phy_idle_off(display);
  3029. rc = dsi_display_set_clamp(display, true);
  3030. if (rc)
  3031. DSI_ERR("%s: Failed to enable dsi clamps. rc=%d\n",
  3032. __func__, rc);
  3033. rc = dsi_display_phy_reset_config(display, false);
  3034. if (rc)
  3035. DSI_ERR("%s: Failed to reset phy, rc=%d\n",
  3036. __func__, rc);
  3037. } else {
  3038. /* Make sure that controller is not in ULPS state when
  3039. * the DSI link is not active.
  3040. */
  3041. rc = dsi_display_set_ulps(display, false);
  3042. if (rc)
  3043. DSI_ERR("%s: failed to disable ulps. rc=%d\n",
  3044. __func__, rc);
  3045. }
  3046. /* dsi will not be able to serve irqs from here on */
  3047. dsi_display_ctrl_irq_update(display, false);
  3048. /* cache the MISR values */
  3049. display_for_each_ctrl(i, display) {
  3050. ctrl = &display->ctrl[i];
  3051. if (!ctrl->ctrl)
  3052. continue;
  3053. dsi_ctrl_cache_misr(ctrl->ctrl);
  3054. }
  3055. }
  3056. return rc;
  3057. }
  3058. int dsi_post_clkon_cb(void *priv,
  3059. enum dsi_clk_type clk,
  3060. enum dsi_lclk_type l_type,
  3061. enum dsi_clk_state curr_state)
  3062. {
  3063. int rc = 0;
  3064. struct dsi_display *display = priv;
  3065. bool mmss_clamp = false;
  3066. if ((clk & DSI_LINK_CLK) && (l_type & DSI_LINK_LP_CLK)) {
  3067. mmss_clamp = display->clamp_enabled;
  3068. /*
  3069. * controller setup is needed if coming out of idle
  3070. * power collapse with clamps enabled.
  3071. */
  3072. if (mmss_clamp)
  3073. dsi_display_ctrl_setup(display);
  3074. /*
  3075. * Phy setup is needed if coming out of idle
  3076. * power collapse with clamps enabled.
  3077. */
  3078. if (display->phy_idle_power_off || mmss_clamp)
  3079. dsi_display_phy_idle_on(display, mmss_clamp);
  3080. if (display->ulps_enabled && mmss_clamp) {
  3081. /*
  3082. * ULPS Entry Request. This is needed if the lanes were
  3083. * in ULPS prior to power collapse, since after
  3084. * power collapse and reset, the DSI controller resets
  3085. * back to idle state and not ULPS. This ulps entry
  3086. * request will transition the state of the DSI
  3087. * controller to ULPS which will match the state of the
  3088. * DSI phy. This needs to be done prior to disabling
  3089. * the DSI clamps.
  3090. *
  3091. * Also, reset the ulps flag so that ulps_config
  3092. * function would reconfigure the controller state to
  3093. * ULPS.
  3094. */
  3095. display->ulps_enabled = false;
  3096. rc = dsi_display_set_ulps(display, true);
  3097. if (rc) {
  3098. DSI_ERR("%s: Failed to enter ULPS. rc=%d\n",
  3099. __func__, rc);
  3100. goto error;
  3101. }
  3102. }
  3103. rc = dsi_display_phy_reset_config(display, true);
  3104. if (rc) {
  3105. DSI_ERR("%s: Failed to reset phy, rc=%d\n",
  3106. __func__, rc);
  3107. goto error;
  3108. }
  3109. rc = dsi_display_set_clamp(display, false);
  3110. if (rc) {
  3111. DSI_ERR("%s: Failed to disable dsi clamps. rc=%d\n",
  3112. __func__, rc);
  3113. goto error;
  3114. }
  3115. }
  3116. if ((clk & DSI_LINK_CLK) && (l_type & DSI_LINK_HS_CLK)) {
  3117. /*
  3118. * Toggle the resync FIFO everytime clock changes, except
  3119. * when cont-splash screen transition is going on.
  3120. * Toggling resync FIFO during cont splash transition
  3121. * can lead to blinks on the display.
  3122. */
  3123. if (!display->is_cont_splash_enabled)
  3124. dsi_display_toggle_resync_fifo(display);
  3125. if (display->ulps_enabled) {
  3126. rc = dsi_display_set_ulps(display, false);
  3127. if (rc) {
  3128. DSI_ERR("%s: failed to disable ulps, rc= %d\n",
  3129. __func__, rc);
  3130. goto error;
  3131. }
  3132. }
  3133. if (display->panel->host_config.force_hs_clk_lane)
  3134. _dsi_display_continuous_clk_ctrl(display, true);
  3135. rc = dsi_display_config_clk_gating(display, true);
  3136. if (rc) {
  3137. DSI_ERR("[%s] failed to enable clk gating %d\n",
  3138. display->name, rc);
  3139. goto error;
  3140. }
  3141. }
  3142. /* enable dsi to serve irqs */
  3143. if (clk & DSI_CORE_CLK)
  3144. dsi_display_ctrl_irq_update(display, true);
  3145. error:
  3146. return rc;
  3147. }
  3148. int dsi_post_clkoff_cb(void *priv,
  3149. enum dsi_clk_type clk_type,
  3150. enum dsi_lclk_type l_type,
  3151. enum dsi_clk_state curr_state)
  3152. {
  3153. int rc = 0;
  3154. struct dsi_display *display = priv;
  3155. if (!display) {
  3156. DSI_ERR("%s: Invalid arg\n", __func__);
  3157. return -EINVAL;
  3158. }
  3159. if ((clk_type & DSI_CORE_CLK) &&
  3160. (curr_state == DSI_CLK_OFF)) {
  3161. rc = dsi_display_phy_power_off(display);
  3162. if (rc)
  3163. DSI_ERR("[%s] failed to power off PHY, rc=%d\n",
  3164. display->name, rc);
  3165. rc = dsi_display_ctrl_power_off(display);
  3166. if (rc)
  3167. DSI_ERR("[%s] failed to power DSI vregs, rc=%d\n",
  3168. display->name, rc);
  3169. }
  3170. return rc;
  3171. }
  3172. int dsi_pre_clkon_cb(void *priv,
  3173. enum dsi_clk_type clk_type,
  3174. enum dsi_lclk_type l_type,
  3175. enum dsi_clk_state new_state)
  3176. {
  3177. int rc = 0;
  3178. struct dsi_display *display = priv;
  3179. if (!display) {
  3180. DSI_ERR("%s: invalid input\n", __func__);
  3181. return -EINVAL;
  3182. }
  3183. if ((clk_type & DSI_CORE_CLK) && (new_state == DSI_CLK_ON)) {
  3184. /*
  3185. * Enable DSI core power
  3186. * 1.> PANEL_PM are controlled as part of
  3187. * panel_power_ctrl. Needed not be handled here.
  3188. * 2.> CTRL_PM need to be enabled/disabled
  3189. * only during unblank/blank. Their state should
  3190. * not be changed during static screen.
  3191. */
  3192. DSI_DEBUG("updating power states for ctrl and phy\n");
  3193. rc = dsi_display_ctrl_power_on(display);
  3194. if (rc) {
  3195. DSI_ERR("[%s] failed to power on dsi controllers, rc=%d\n",
  3196. display->name, rc);
  3197. return rc;
  3198. }
  3199. rc = dsi_display_phy_power_on(display);
  3200. if (rc) {
  3201. DSI_ERR("[%s] failed to power on dsi phy, rc = %d\n",
  3202. display->name, rc);
  3203. return rc;
  3204. }
  3205. DSI_DEBUG("%s: Enable DSI core power\n", __func__);
  3206. }
  3207. return rc;
  3208. }
  3209. static void __set_lane_map_v2(u8 *lane_map_v2,
  3210. enum dsi_phy_data_lanes lane0,
  3211. enum dsi_phy_data_lanes lane1,
  3212. enum dsi_phy_data_lanes lane2,
  3213. enum dsi_phy_data_lanes lane3)
  3214. {
  3215. lane_map_v2[DSI_LOGICAL_LANE_0] = lane0;
  3216. lane_map_v2[DSI_LOGICAL_LANE_1] = lane1;
  3217. lane_map_v2[DSI_LOGICAL_LANE_2] = lane2;
  3218. lane_map_v2[DSI_LOGICAL_LANE_3] = lane3;
  3219. }
  3220. static int dsi_display_parse_lane_map(struct dsi_display *display)
  3221. {
  3222. int rc = 0, i = 0;
  3223. const char *data;
  3224. u8 temp[DSI_LANE_MAX - 1];
  3225. if (!display) {
  3226. DSI_ERR("invalid params\n");
  3227. return -EINVAL;
  3228. }
  3229. /* lane-map-v2 supersedes lane-map-v1 setting */
  3230. rc = of_property_read_u8_array(display->pdev->dev.of_node,
  3231. "qcom,lane-map-v2", temp, (DSI_LANE_MAX - 1));
  3232. if (!rc) {
  3233. for (i = DSI_LOGICAL_LANE_0; i < (DSI_LANE_MAX - 1); i++)
  3234. display->lane_map.lane_map_v2[i] = BIT(temp[i]);
  3235. return 0;
  3236. } else if (rc != EINVAL) {
  3237. DSI_DEBUG("Incorrect mapping, configure default\n");
  3238. goto set_default;
  3239. }
  3240. /* lane-map older version, for DSI controller version < 2.0 */
  3241. data = of_get_property(display->pdev->dev.of_node,
  3242. "qcom,lane-map", NULL);
  3243. if (!data)
  3244. goto set_default;
  3245. if (!strcmp(data, "lane_map_3012")) {
  3246. display->lane_map.lane_map_v1 = DSI_LANE_MAP_3012;
  3247. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3248. DSI_PHYSICAL_LANE_1,
  3249. DSI_PHYSICAL_LANE_2,
  3250. DSI_PHYSICAL_LANE_3,
  3251. DSI_PHYSICAL_LANE_0);
  3252. } else if (!strcmp(data, "lane_map_2301")) {
  3253. display->lane_map.lane_map_v1 = DSI_LANE_MAP_2301;
  3254. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3255. DSI_PHYSICAL_LANE_2,
  3256. DSI_PHYSICAL_LANE_3,
  3257. DSI_PHYSICAL_LANE_0,
  3258. DSI_PHYSICAL_LANE_1);
  3259. } else if (!strcmp(data, "lane_map_1230")) {
  3260. display->lane_map.lane_map_v1 = DSI_LANE_MAP_1230;
  3261. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3262. DSI_PHYSICAL_LANE_3,
  3263. DSI_PHYSICAL_LANE_0,
  3264. DSI_PHYSICAL_LANE_1,
  3265. DSI_PHYSICAL_LANE_2);
  3266. } else if (!strcmp(data, "lane_map_0321")) {
  3267. display->lane_map.lane_map_v1 = DSI_LANE_MAP_0321;
  3268. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3269. DSI_PHYSICAL_LANE_0,
  3270. DSI_PHYSICAL_LANE_3,
  3271. DSI_PHYSICAL_LANE_2,
  3272. DSI_PHYSICAL_LANE_1);
  3273. } else if (!strcmp(data, "lane_map_1032")) {
  3274. display->lane_map.lane_map_v1 = DSI_LANE_MAP_1032;
  3275. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3276. DSI_PHYSICAL_LANE_1,
  3277. DSI_PHYSICAL_LANE_0,
  3278. DSI_PHYSICAL_LANE_3,
  3279. DSI_PHYSICAL_LANE_2);
  3280. } else if (!strcmp(data, "lane_map_2103")) {
  3281. display->lane_map.lane_map_v1 = DSI_LANE_MAP_2103;
  3282. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3283. DSI_PHYSICAL_LANE_2,
  3284. DSI_PHYSICAL_LANE_1,
  3285. DSI_PHYSICAL_LANE_0,
  3286. DSI_PHYSICAL_LANE_3);
  3287. } else if (!strcmp(data, "lane_map_3210")) {
  3288. display->lane_map.lane_map_v1 = DSI_LANE_MAP_3210;
  3289. __set_lane_map_v2(display->lane_map.lane_map_v2,
  3290. DSI_PHYSICAL_LANE_3,
  3291. DSI_PHYSICAL_LANE_2,
  3292. DSI_PHYSICAL_LANE_1,
  3293. DSI_PHYSICAL_LANE_0);
  3294. } else {
  3295. DSI_WARN("%s: invalid lane map %s specified. defaulting to lane_map0123\n",
  3296. __func__, data);
  3297. goto set_default;
  3298. }
  3299. return 0;
  3300. set_default:
  3301. /* default lane mapping */
  3302. __set_lane_map_v2(display->lane_map.lane_map_v2, DSI_PHYSICAL_LANE_0,
  3303. DSI_PHYSICAL_LANE_1, DSI_PHYSICAL_LANE_2, DSI_PHYSICAL_LANE_3);
  3304. display->lane_map.lane_map_v1 = DSI_LANE_MAP_0123;
  3305. return 0;
  3306. }
  3307. static int dsi_display_get_phandle_index(
  3308. struct dsi_display *display,
  3309. const char *propname, int count, int index)
  3310. {
  3311. struct device_node *disp_node = display->panel_node;
  3312. u32 *val = NULL;
  3313. int rc = 0;
  3314. val = kcalloc(count, sizeof(*val), GFP_KERNEL);
  3315. if (ZERO_OR_NULL_PTR(val)) {
  3316. rc = -ENOMEM;
  3317. goto end;
  3318. }
  3319. if (index >= count)
  3320. goto end;
  3321. if (display->fw)
  3322. rc = dsi_parser_read_u32_array(display->parser_node,
  3323. propname, val, count);
  3324. else
  3325. rc = of_property_read_u32_array(disp_node, propname,
  3326. val, count);
  3327. if (rc)
  3328. goto end;
  3329. rc = val[index];
  3330. DSI_DEBUG("%s index=%d\n", propname, rc);
  3331. end:
  3332. kfree(val);
  3333. return rc;
  3334. }
  3335. static int dsi_display_get_phandle_count(struct dsi_display *display,
  3336. const char *propname)
  3337. {
  3338. if (display->fw)
  3339. return dsi_parser_count_u32_elems(display->parser_node,
  3340. propname);
  3341. else
  3342. return of_property_count_u32_elems(display->panel_node,
  3343. propname);
  3344. }
  3345. static int dsi_display_parse_dt(struct dsi_display *display)
  3346. {
  3347. int i, rc = 0;
  3348. u32 phy_count = 0;
  3349. struct device_node *of_node = display->pdev->dev.of_node;
  3350. char *dsi_ctrl_name, *dsi_phy_name;
  3351. if (!strcmp(display->display_type, "primary")) {
  3352. dsi_ctrl_name = "qcom,dsi-ctrl-num";
  3353. dsi_phy_name = "qcom,dsi-phy-num";
  3354. } else {
  3355. dsi_ctrl_name = "qcom,dsi-sec-ctrl-num";
  3356. dsi_phy_name = "qcom,dsi-sec-phy-num";
  3357. }
  3358. display->ctrl_count = dsi_display_get_phandle_count(display,
  3359. dsi_ctrl_name);
  3360. phy_count = dsi_display_get_phandle_count(display, dsi_phy_name);
  3361. DSI_DEBUG("ctrl count=%d, phy count=%d\n",
  3362. display->ctrl_count, phy_count);
  3363. if (!phy_count || !display->ctrl_count) {
  3364. DSI_ERR("no ctrl/phys found\n");
  3365. rc = -ENODEV;
  3366. goto error;
  3367. }
  3368. if (phy_count != display->ctrl_count) {
  3369. DSI_ERR("different ctrl and phy counts\n");
  3370. rc = -ENODEV;
  3371. goto error;
  3372. }
  3373. display_for_each_ctrl(i, display) {
  3374. struct dsi_display_ctrl *ctrl = &display->ctrl[i];
  3375. int index;
  3376. index = dsi_display_get_phandle_index(display, dsi_ctrl_name,
  3377. display->ctrl_count, i);
  3378. ctrl->ctrl_of_node = of_parse_phandle(of_node,
  3379. "qcom,dsi-ctrl", index);
  3380. of_node_put(ctrl->ctrl_of_node);
  3381. index = dsi_display_get_phandle_index(display, dsi_phy_name,
  3382. display->ctrl_count, i);
  3383. ctrl->phy_of_node = of_parse_phandle(of_node,
  3384. "qcom,dsi-phy", index);
  3385. of_node_put(ctrl->phy_of_node);
  3386. }
  3387. /* Parse TE data */
  3388. dsi_display_parse_te_data(display);
  3389. /* Parse all external bridges from port 0 */
  3390. display_for_each_ctrl(i, display) {
  3391. display->ext_bridge[i].node_of =
  3392. of_graph_get_remote_node(of_node, 0, i);
  3393. if (display->ext_bridge[i].node_of)
  3394. display->ext_bridge_cnt++;
  3395. else
  3396. break;
  3397. }
  3398. DSI_DEBUG("success\n");
  3399. error:
  3400. return rc;
  3401. }
  3402. static int dsi_display_validate_resources(struct dsi_display *display)
  3403. {
  3404. int rc = 0;
  3405. int i;
  3406. struct dsi_display_ctrl *ctrl;
  3407. display_for_each_ctrl(i, display) {
  3408. ctrl = &display->ctrl[i];
  3409. ctrl->ctrl = dsi_ctrl_get(ctrl->ctrl_of_node);
  3410. if (IS_ERR_OR_NULL(ctrl->ctrl)) {
  3411. rc = PTR_ERR(ctrl->ctrl);
  3412. DSI_ERR("failed to get dsi controller, rc=%d\n", rc);
  3413. ctrl->ctrl = NULL;
  3414. goto error;
  3415. }
  3416. ctrl->phy = dsi_phy_get(ctrl->phy_of_node);
  3417. if (IS_ERR_OR_NULL(ctrl->phy)) {
  3418. rc = PTR_ERR(ctrl->phy);
  3419. DSI_ERR("failed to get phy controller, rc=%d\n", rc);
  3420. dsi_ctrl_put(ctrl->ctrl);
  3421. ctrl->phy = NULL;
  3422. goto error;
  3423. }
  3424. }
  3425. return rc;
  3426. error:
  3427. for (i = i - 1; i >= 0; i--) {
  3428. ctrl = &display->ctrl[i];
  3429. dsi_ctrl_put(ctrl->ctrl);
  3430. dsi_phy_put(ctrl->phy);
  3431. }
  3432. return -EPROBE_DEFER;
  3433. }
  3434. static int dsi_display_res_init(struct dsi_display *display)
  3435. {
  3436. int rc = 0;
  3437. int i;
  3438. display->panel = dsi_panel_get(&display->pdev->dev,
  3439. display->panel_node,
  3440. display->parser_node,
  3441. display->display_type,
  3442. display->cmdline_topology,
  3443. display->trusted_vm_env);
  3444. if (IS_ERR_OR_NULL(display->panel)) {
  3445. rc = PTR_ERR(display->panel);
  3446. DSI_ERR("failed to get panel, rc=%d\n", rc);
  3447. display->panel = NULL;
  3448. goto error;
  3449. }
  3450. display_for_each_ctrl(i, display) {
  3451. struct msm_dsi_phy *phy = display->ctrl[i].phy;
  3452. phy->cfg.force_clk_lane_hs =
  3453. display->panel->host_config.force_hs_clk_lane;
  3454. phy->cfg.phy_type =
  3455. display->panel->host_config.phy_type;
  3456. /*
  3457. * Parse the dynamic clock trim codes for PLL, for video mode panels that have
  3458. * dynamic clock property set.
  3459. */
  3460. if ((display->panel->dyn_clk_caps.dyn_clk_support) &&
  3461. (display->panel->panel_mode == DSI_OP_VIDEO_MODE))
  3462. dsi_phy_pll_parse_dfps_data(phy);
  3463. }
  3464. rc = dsi_display_parse_lane_map(display);
  3465. if (rc) {
  3466. DSI_ERR("Lane map not found, rc=%d\n", rc);
  3467. goto error;
  3468. }
  3469. rc = dsi_display_clocks_init(display);
  3470. if (rc) {
  3471. DSI_ERR("Failed to parse clock data, rc=%d\n", rc);
  3472. goto error;
  3473. }
  3474. /**
  3475. * In trusted vm, the connectors will not be enabled
  3476. * until the HW resources are assigned and accepted.
  3477. */
  3478. if (display->trusted_vm_env)
  3479. display->is_active = false;
  3480. else
  3481. display->is_active = true;
  3482. error:
  3483. return rc;
  3484. }
  3485. static int dsi_display_res_deinit(struct dsi_display *display)
  3486. {
  3487. int rc = 0;
  3488. int i;
  3489. struct dsi_display_ctrl *ctrl;
  3490. display_for_each_ctrl(i, display) {
  3491. ctrl = &display->ctrl[i];
  3492. dsi_phy_put(ctrl->phy);
  3493. dsi_ctrl_put(ctrl->ctrl);
  3494. }
  3495. if (display->panel)
  3496. dsi_panel_put(display->panel);
  3497. return rc;
  3498. }
  3499. static int dsi_display_validate_mode_set(struct dsi_display *display,
  3500. struct dsi_display_mode *mode,
  3501. u32 flags)
  3502. {
  3503. int rc = 0;
  3504. int i;
  3505. struct dsi_display_ctrl *ctrl;
  3506. /*
  3507. * To set a mode:
  3508. * 1. Controllers should be turned off.
  3509. * 2. Link clocks should be off.
  3510. * 3. Phy should be disabled.
  3511. */
  3512. display_for_each_ctrl(i, display) {
  3513. ctrl = &display->ctrl[i];
  3514. if ((ctrl->power_state > DSI_CTRL_POWER_VREG_ON) ||
  3515. (ctrl->phy_enabled)) {
  3516. rc = -EINVAL;
  3517. goto error;
  3518. }
  3519. }
  3520. error:
  3521. return rc;
  3522. }
  3523. static bool dsi_display_is_seamless_dfps_possible(
  3524. const struct dsi_display *display,
  3525. const struct dsi_display_mode *tgt,
  3526. const enum dsi_dfps_type dfps_type)
  3527. {
  3528. struct dsi_display_mode *cur;
  3529. if (!display || !tgt || !display->panel) {
  3530. DSI_ERR("Invalid params\n");
  3531. return false;
  3532. }
  3533. cur = display->panel->cur_mode;
  3534. if (cur->timing.h_active != tgt->timing.h_active) {
  3535. DSI_DEBUG("timing.h_active differs %d %d\n",
  3536. cur->timing.h_active, tgt->timing.h_active);
  3537. return false;
  3538. }
  3539. if (cur->timing.h_back_porch != tgt->timing.h_back_porch) {
  3540. DSI_DEBUG("timing.h_back_porch differs %d %d\n",
  3541. cur->timing.h_back_porch,
  3542. tgt->timing.h_back_porch);
  3543. return false;
  3544. }
  3545. if (cur->timing.h_sync_width != tgt->timing.h_sync_width) {
  3546. DSI_DEBUG("timing.h_sync_width differs %d %d\n",
  3547. cur->timing.h_sync_width,
  3548. tgt->timing.h_sync_width);
  3549. return false;
  3550. }
  3551. if (cur->timing.h_front_porch != tgt->timing.h_front_porch) {
  3552. DSI_DEBUG("timing.h_front_porch differs %d %d\n",
  3553. cur->timing.h_front_porch,
  3554. tgt->timing.h_front_porch);
  3555. if (dfps_type != DSI_DFPS_IMMEDIATE_HFP)
  3556. return false;
  3557. }
  3558. if (cur->timing.h_skew != tgt->timing.h_skew) {
  3559. DSI_DEBUG("timing.h_skew differs %d %d\n",
  3560. cur->timing.h_skew,
  3561. tgt->timing.h_skew);
  3562. return false;
  3563. }
  3564. /* skip polarity comparison */
  3565. if (cur->timing.v_active != tgt->timing.v_active) {
  3566. DSI_DEBUG("timing.v_active differs %d %d\n",
  3567. cur->timing.v_active,
  3568. tgt->timing.v_active);
  3569. return false;
  3570. }
  3571. if (cur->timing.v_back_porch != tgt->timing.v_back_porch) {
  3572. DSI_DEBUG("timing.v_back_porch differs %d %d\n",
  3573. cur->timing.v_back_porch,
  3574. tgt->timing.v_back_porch);
  3575. return false;
  3576. }
  3577. if (cur->timing.v_sync_width != tgt->timing.v_sync_width) {
  3578. DSI_DEBUG("timing.v_sync_width differs %d %d\n",
  3579. cur->timing.v_sync_width,
  3580. tgt->timing.v_sync_width);
  3581. return false;
  3582. }
  3583. if (cur->timing.v_front_porch != tgt->timing.v_front_porch) {
  3584. DSI_DEBUG("timing.v_front_porch differs %d %d\n",
  3585. cur->timing.v_front_porch,
  3586. tgt->timing.v_front_porch);
  3587. if (dfps_type != DSI_DFPS_IMMEDIATE_VFP)
  3588. return false;
  3589. }
  3590. /* skip polarity comparison */
  3591. if (cur->timing.refresh_rate == tgt->timing.refresh_rate)
  3592. DSI_DEBUG("timing.refresh_rate identical %d %d\n",
  3593. cur->timing.refresh_rate,
  3594. tgt->timing.refresh_rate);
  3595. if (cur->pixel_clk_khz != tgt->pixel_clk_khz)
  3596. DSI_DEBUG("pixel_clk_khz differs %d %d\n",
  3597. cur->pixel_clk_khz, tgt->pixel_clk_khz);
  3598. if (cur->dsi_mode_flags != tgt->dsi_mode_flags)
  3599. DSI_DEBUG("flags differs %d %d\n",
  3600. cur->dsi_mode_flags, tgt->dsi_mode_flags);
  3601. return true;
  3602. }
  3603. void dsi_display_update_byte_intf_div(struct dsi_display *display)
  3604. {
  3605. struct dsi_host_common_cfg *config;
  3606. struct dsi_display_ctrl *m_ctrl;
  3607. int phy_ver;
  3608. m_ctrl = &display->ctrl[display->cmd_master_idx];
  3609. config = &display->panel->host_config;
  3610. phy_ver = dsi_phy_get_version(m_ctrl->phy);
  3611. if (phy_ver <= DSI_PHY_VERSION_2_0)
  3612. config->byte_intf_clk_div = 1;
  3613. else
  3614. config->byte_intf_clk_div = 2;
  3615. }
  3616. static int dsi_display_update_dsi_bitrate(struct dsi_display *display,
  3617. u32 bit_clk_rate)
  3618. {
  3619. int rc = 0;
  3620. int i;
  3621. DSI_DEBUG("%s:bit rate:%d\n", __func__, bit_clk_rate);
  3622. if (!display->panel) {
  3623. DSI_ERR("Invalid params\n");
  3624. return -EINVAL;
  3625. }
  3626. if (bit_clk_rate == 0) {
  3627. DSI_ERR("Invalid bit clock rate\n");
  3628. return -EINVAL;
  3629. }
  3630. display->config.bit_clk_rate_hz = bit_clk_rate;
  3631. display_for_each_ctrl(i, display) {
  3632. struct dsi_display_ctrl *dsi_disp_ctrl = &display->ctrl[i];
  3633. struct dsi_ctrl *ctrl = dsi_disp_ctrl->ctrl;
  3634. u32 num_of_lanes = 0, bpp, byte_intf_clk_div;
  3635. u64 bit_rate, pclk_rate, bit_rate_per_lane, byte_clk_rate,
  3636. byte_intf_clk_rate;
  3637. u32 bits_per_symbol = 16, num_of_symbols = 7; /* For Cphy */
  3638. struct dsi_host_common_cfg *host_cfg;
  3639. mutex_lock(&ctrl->ctrl_lock);
  3640. host_cfg = &display->panel->host_config;
  3641. if (host_cfg->data_lanes & DSI_DATA_LANE_0)
  3642. num_of_lanes++;
  3643. if (host_cfg->data_lanes & DSI_DATA_LANE_1)
  3644. num_of_lanes++;
  3645. if (host_cfg->data_lanes & DSI_DATA_LANE_2)
  3646. num_of_lanes++;
  3647. if (host_cfg->data_lanes & DSI_DATA_LANE_3)
  3648. num_of_lanes++;
  3649. if (num_of_lanes == 0) {
  3650. DSI_ERR("Invalid lane count\n");
  3651. rc = -EINVAL;
  3652. goto error;
  3653. }
  3654. bpp = dsi_pixel_format_to_bpp(host_cfg->dst_format);
  3655. bit_rate = display->config.bit_clk_rate_hz * num_of_lanes;
  3656. bit_rate_per_lane = bit_rate;
  3657. do_div(bit_rate_per_lane, num_of_lanes);
  3658. pclk_rate = bit_rate;
  3659. do_div(pclk_rate, bpp);
  3660. if (host_cfg->phy_type == DSI_PHY_TYPE_DPHY) {
  3661. bit_rate_per_lane = bit_rate;
  3662. do_div(bit_rate_per_lane, num_of_lanes);
  3663. byte_clk_rate = bit_rate_per_lane;
  3664. do_div(byte_clk_rate, 8);
  3665. byte_intf_clk_rate = byte_clk_rate;
  3666. byte_intf_clk_div = host_cfg->byte_intf_clk_div;
  3667. do_div(byte_intf_clk_rate, byte_intf_clk_div);
  3668. } else {
  3669. bit_rate_per_lane = bit_clk_rate;
  3670. pclk_rate *= bits_per_symbol;
  3671. do_div(pclk_rate, num_of_symbols);
  3672. byte_clk_rate = bit_clk_rate;
  3673. do_div(byte_clk_rate, num_of_symbols);
  3674. /* For CPHY, byte_intf_clk is same as byte_clk */
  3675. byte_intf_clk_rate = byte_clk_rate;
  3676. }
  3677. DSI_DEBUG("bit_clk_rate = %llu, bit_clk_rate_per_lane = %llu\n",
  3678. bit_rate, bit_rate_per_lane);
  3679. DSI_DEBUG("byte_clk_rate = %llu, byte_intf_clk_rate = %llu\n",
  3680. byte_clk_rate, byte_intf_clk_rate);
  3681. DSI_DEBUG("pclk_rate = %llu\n", pclk_rate);
  3682. SDE_EVT32(i, bit_rate, byte_clk_rate, pclk_rate);
  3683. ctrl->clk_freq.byte_clk_rate = byte_clk_rate;
  3684. ctrl->clk_freq.byte_intf_clk_rate = byte_intf_clk_rate;
  3685. ctrl->clk_freq.pix_clk_rate = pclk_rate;
  3686. rc = dsi_clk_set_link_frequencies(display->dsi_clk_handle,
  3687. ctrl->clk_freq, ctrl->cell_index);
  3688. if (rc) {
  3689. DSI_ERR("Failed to update link frequencies\n");
  3690. goto error;
  3691. }
  3692. ctrl->host_config.bit_clk_rate_hz = bit_clk_rate;
  3693. error:
  3694. mutex_unlock(&ctrl->ctrl_lock);
  3695. /* TODO: recover ctrl->clk_freq in case of failure */
  3696. if (rc)
  3697. return rc;
  3698. }
  3699. return 0;
  3700. }
  3701. static void _dsi_display_calc_pipe_delay(struct dsi_display *display,
  3702. struct dsi_dyn_clk_delay *delay,
  3703. struct dsi_display_mode *mode)
  3704. {
  3705. u32 esc_clk_rate_hz;
  3706. u32 pclk_to_esc_ratio, byte_to_esc_ratio, hr_bit_to_esc_ratio;
  3707. u32 hsync_period = 0;
  3708. struct dsi_display_ctrl *m_ctrl;
  3709. struct dsi_ctrl *dsi_ctrl;
  3710. struct dsi_phy_cfg *cfg;
  3711. int phy_ver;
  3712. m_ctrl = &display->ctrl[display->clk_master_idx];
  3713. dsi_ctrl = m_ctrl->ctrl;
  3714. cfg = &(m_ctrl->phy->cfg);
  3715. esc_clk_rate_hz = dsi_ctrl->clk_freq.esc_clk_rate;
  3716. pclk_to_esc_ratio = (dsi_ctrl->clk_freq.pix_clk_rate /
  3717. esc_clk_rate_hz);
  3718. byte_to_esc_ratio = (dsi_ctrl->clk_freq.byte_clk_rate /
  3719. esc_clk_rate_hz);
  3720. hr_bit_to_esc_ratio = ((dsi_ctrl->clk_freq.byte_clk_rate * 4) /
  3721. esc_clk_rate_hz);
  3722. hsync_period = dsi_h_total_dce(&mode->timing);
  3723. delay->pipe_delay = (hsync_period + 1) / pclk_to_esc_ratio;
  3724. if (!display->panel->video_config.eof_bllp_lp11_en)
  3725. delay->pipe_delay += (17 / pclk_to_esc_ratio) +
  3726. ((21 + (display->config.common_config.t_clk_pre + 1) +
  3727. (display->config.common_config.t_clk_post + 1)) /
  3728. byte_to_esc_ratio) +
  3729. ((((cfg->timing.lane_v3[8] >> 1) + 1) +
  3730. ((cfg->timing.lane_v3[6] >> 1) + 1) +
  3731. ((cfg->timing.lane_v3[3] * 4) +
  3732. (cfg->timing.lane_v3[5] >> 1) + 1) +
  3733. ((cfg->timing.lane_v3[7] >> 1) + 1) +
  3734. ((cfg->timing.lane_v3[1] >> 1) + 1) +
  3735. ((cfg->timing.lane_v3[4] >> 1) + 1)) /
  3736. hr_bit_to_esc_ratio);
  3737. delay->pipe_delay2 = 0;
  3738. if (display->panel->host_config.force_hs_clk_lane)
  3739. delay->pipe_delay2 = (6 / byte_to_esc_ratio) +
  3740. ((((cfg->timing.lane_v3[1] >> 1) + 1) +
  3741. ((cfg->timing.lane_v3[4] >> 1) + 1)) /
  3742. hr_bit_to_esc_ratio);
  3743. /*
  3744. * 100us pll delay recommended for phy ver 2.0 and 3.0
  3745. * 25us pll delay recommended for phy ver 4.0
  3746. */
  3747. phy_ver = dsi_phy_get_version(m_ctrl->phy);
  3748. if (phy_ver <= DSI_PHY_VERSION_3_0)
  3749. delay->pll_delay = 100;
  3750. else
  3751. delay->pll_delay = 25;
  3752. delay->pll_delay = ((delay->pll_delay * esc_clk_rate_hz) / 1000000);
  3753. }
  3754. /*
  3755. * dsi_display_is_type_cphy - check if panel type is cphy
  3756. * @display: Pointer to private display structure
  3757. * Returns: True if panel type is cphy
  3758. */
  3759. static inline bool dsi_display_is_type_cphy(struct dsi_display *display)
  3760. {
  3761. return (display->panel->host_config.phy_type ==
  3762. DSI_PHY_TYPE_CPHY) ? true : false;
  3763. }
  3764. static int _dsi_display_dyn_update_clks(struct dsi_display *display,
  3765. struct link_clk_freq *bkp_freq)
  3766. {
  3767. int rc = 0, i;
  3768. u8 ctrl_version;
  3769. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3770. struct dsi_dyn_clk_caps *dyn_clk_caps;
  3771. struct dsi_clk_link_set *enable_clk;
  3772. m_ctrl = &display->ctrl[display->clk_master_idx];
  3773. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  3774. ctrl_version = m_ctrl->ctrl->version;
  3775. enable_clk = &display->clock_info.pll_clks;
  3776. dsi_clk_prepare_enable(enable_clk);
  3777. dsi_display_phy_configure(display, false);
  3778. display_for_each_ctrl(i, display) {
  3779. ctrl = &display->ctrl[i];
  3780. if (!ctrl->ctrl)
  3781. continue;
  3782. rc = dsi_clk_set_byte_clk_rate(display->dsi_clk_handle,
  3783. ctrl->ctrl->clk_freq.byte_clk_rate,
  3784. ctrl->ctrl->clk_freq.byte_intf_clk_rate, i);
  3785. if (rc) {
  3786. DSI_ERR("failed to set byte rate for index:%d\n", i);
  3787. goto recover_byte_clk;
  3788. }
  3789. rc = dsi_clk_set_pixel_clk_rate(display->dsi_clk_handle,
  3790. ctrl->ctrl->clk_freq.pix_clk_rate, i);
  3791. if (rc) {
  3792. DSI_ERR("failed to set pix rate for index:%d\n", i);
  3793. goto recover_pix_clk;
  3794. }
  3795. }
  3796. display_for_each_ctrl(i, display) {
  3797. ctrl = &display->ctrl[i];
  3798. if (ctrl == m_ctrl)
  3799. continue;
  3800. dsi_phy_dynamic_refresh_trigger(ctrl->phy, false);
  3801. }
  3802. dsi_phy_dynamic_refresh_trigger(m_ctrl->phy, true);
  3803. /*
  3804. * Don't wait for dynamic refresh done for dsi ctrl greater than 2.5
  3805. * and with constant fps, as dynamic refresh will applied with
  3806. * next mdp intf ctrl flush.
  3807. */
  3808. if ((ctrl_version >= DSI_CTRL_VERSION_2_5) &&
  3809. (dyn_clk_caps->maintain_const_fps))
  3810. goto defer_dfps_wait;
  3811. /* wait for dynamic refresh done */
  3812. display_for_each_ctrl(i, display) {
  3813. ctrl = &display->ctrl[i];
  3814. rc = dsi_ctrl_wait4dynamic_refresh_done(ctrl->ctrl);
  3815. if (rc) {
  3816. DSI_ERR("wait4dynamic refresh failed for dsi:%d\n", i);
  3817. goto recover_pix_clk;
  3818. } else {
  3819. DSI_INFO("dynamic refresh done on dsi: %s\n",
  3820. i ? "slave" : "master");
  3821. }
  3822. }
  3823. display_for_each_ctrl(i, display) {
  3824. ctrl = &display->ctrl[i];
  3825. dsi_phy_dynamic_refresh_clear(ctrl->phy);
  3826. }
  3827. defer_dfps_wait:
  3828. if (rc)
  3829. DSI_ERR("could not switch back to src clks %d\n", rc);
  3830. dsi_clk_disable_unprepare(enable_clk);
  3831. return rc;
  3832. recover_pix_clk:
  3833. display_for_each_ctrl(i, display) {
  3834. ctrl = &display->ctrl[i];
  3835. if (!ctrl->ctrl)
  3836. continue;
  3837. dsi_clk_set_pixel_clk_rate(display->dsi_clk_handle,
  3838. bkp_freq->pix_clk_rate, i);
  3839. }
  3840. recover_byte_clk:
  3841. display_for_each_ctrl(i, display) {
  3842. ctrl = &display->ctrl[i];
  3843. if (!ctrl->ctrl)
  3844. continue;
  3845. dsi_clk_set_byte_clk_rate(display->dsi_clk_handle,
  3846. bkp_freq->byte_clk_rate,
  3847. bkp_freq->byte_intf_clk_rate, i);
  3848. }
  3849. return rc;
  3850. }
  3851. static int dsi_display_dynamic_clk_switch_vid(struct dsi_display *display,
  3852. struct dsi_display_mode *mode)
  3853. {
  3854. int rc = 0, mask, i;
  3855. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3856. struct dsi_dyn_clk_delay delay;
  3857. struct link_clk_freq bkp_freq;
  3858. dsi_panel_acquire_panel_lock(display->panel);
  3859. m_ctrl = &display->ctrl[display->clk_master_idx];
  3860. dsi_display_clk_ctrl(display->dsi_clk_handle, DSI_ALL_CLKS, DSI_CLK_ON);
  3861. /* mask PLL unlock, FIFO overflow and underflow errors */
  3862. mask = BIT(DSI_PLL_UNLOCK_ERR) | BIT(DSI_FIFO_UNDERFLOW) |
  3863. BIT(DSI_FIFO_OVERFLOW);
  3864. dsi_display_mask_ctrl_error_interrupts(display, mask, true);
  3865. /* update the phy timings based on new mode */
  3866. display_for_each_ctrl(i, display) {
  3867. ctrl = &display->ctrl[i];
  3868. dsi_phy_update_phy_timings(ctrl->phy, &display->config);
  3869. }
  3870. /* back up existing rates to handle failure case */
  3871. bkp_freq.byte_clk_rate = m_ctrl->ctrl->clk_freq.byte_clk_rate;
  3872. bkp_freq.byte_intf_clk_rate = m_ctrl->ctrl->clk_freq.byte_intf_clk_rate;
  3873. bkp_freq.pix_clk_rate = m_ctrl->ctrl->clk_freq.pix_clk_rate;
  3874. bkp_freq.esc_clk_rate = m_ctrl->ctrl->clk_freq.esc_clk_rate;
  3875. rc = dsi_display_update_dsi_bitrate(display, mode->timing.clk_rate_hz);
  3876. if (rc) {
  3877. DSI_ERR("failed set link frequencies %d\n", rc);
  3878. goto exit;
  3879. }
  3880. /* calculate pipe delays */
  3881. _dsi_display_calc_pipe_delay(display, &delay, mode);
  3882. /* configure dynamic refresh ctrl registers */
  3883. display_for_each_ctrl(i, display) {
  3884. ctrl = &display->ctrl[i];
  3885. if (!ctrl->phy)
  3886. continue;
  3887. if (ctrl == m_ctrl)
  3888. dsi_phy_config_dynamic_refresh(ctrl->phy, &delay, true);
  3889. else
  3890. dsi_phy_config_dynamic_refresh(ctrl->phy, &delay,
  3891. false);
  3892. }
  3893. rc = _dsi_display_dyn_update_clks(display, &bkp_freq);
  3894. exit:
  3895. dsi_display_mask_ctrl_error_interrupts(display, mask, false);
  3896. dsi_display_clk_ctrl(display->dsi_clk_handle, DSI_ALL_CLKS,
  3897. DSI_CLK_OFF);
  3898. /* store newly calculated phy timings in mode private info */
  3899. dsi_phy_dyn_refresh_cache_phy_timings(m_ctrl->phy,
  3900. mode->priv_info->phy_timing_val,
  3901. mode->priv_info->phy_timing_len);
  3902. dsi_panel_release_panel_lock(display->panel);
  3903. return rc;
  3904. }
  3905. static int dsi_display_dynamic_clk_configure_cmd(struct dsi_display *display,
  3906. int clk_rate)
  3907. {
  3908. int rc = 0;
  3909. if (clk_rate <= 0) {
  3910. DSI_ERR("%s: bitrate should be greater than 0\n", __func__);
  3911. return -EINVAL;
  3912. }
  3913. if (clk_rate == display->cached_clk_rate) {
  3914. DSI_INFO("%s: ignore duplicated DSI clk setting\n", __func__);
  3915. return rc;
  3916. }
  3917. display->cached_clk_rate = clk_rate;
  3918. rc = dsi_display_update_dsi_bitrate(display, clk_rate);
  3919. if (!rc) {
  3920. DSI_DEBUG("%s: bit clk is ready to be configured to '%d'\n",
  3921. __func__, clk_rate);
  3922. atomic_set(&display->clkrate_change_pending, 1);
  3923. } else {
  3924. DSI_ERR("%s: Failed to prepare to configure '%d'. rc = %d\n",
  3925. __func__, clk_rate, rc);
  3926. /* Caching clock failed, so don't go on doing so. */
  3927. atomic_set(&display->clkrate_change_pending, 0);
  3928. display->cached_clk_rate = 0;
  3929. }
  3930. return rc;
  3931. }
  3932. static int dsi_display_dfps_update(struct dsi_display *display,
  3933. struct dsi_display_mode *dsi_mode)
  3934. {
  3935. struct dsi_mode_info *timing;
  3936. struct dsi_display_ctrl *m_ctrl, *ctrl;
  3937. struct dsi_display_mode *panel_mode;
  3938. struct dsi_dfps_capabilities dfps_caps;
  3939. int rc = 0;
  3940. int i = 0;
  3941. struct dsi_dyn_clk_caps *dyn_clk_caps;
  3942. if (!display || !dsi_mode || !display->panel) {
  3943. DSI_ERR("Invalid params\n");
  3944. return -EINVAL;
  3945. }
  3946. timing = &dsi_mode->timing;
  3947. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  3948. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  3949. if (!dfps_caps.dfps_support && !dyn_clk_caps->maintain_const_fps) {
  3950. DSI_ERR("dfps or constant fps not supported\n");
  3951. return -ENOTSUPP;
  3952. }
  3953. if (dfps_caps.type == DSI_DFPS_IMMEDIATE_CLK) {
  3954. DSI_ERR("dfps clock method not supported\n");
  3955. return -ENOTSUPP;
  3956. }
  3957. /* For split DSI, update the clock master first */
  3958. DSI_DEBUG("configuring seamless dynamic fps\n\n");
  3959. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  3960. m_ctrl = &display->ctrl[display->clk_master_idx];
  3961. rc = dsi_ctrl_async_timing_update(m_ctrl->ctrl, timing);
  3962. if (rc) {
  3963. DSI_ERR("[%s] failed to dfps update host_%d, rc=%d\n",
  3964. display->name, i, rc);
  3965. goto error;
  3966. }
  3967. /* Update the rest of the controllers */
  3968. display_for_each_ctrl(i, display) {
  3969. ctrl = &display->ctrl[i];
  3970. if (!ctrl->ctrl || (ctrl == m_ctrl))
  3971. continue;
  3972. rc = dsi_ctrl_async_timing_update(ctrl->ctrl, timing);
  3973. if (rc) {
  3974. DSI_ERR("[%s] failed to dfps update host_%d, rc=%d\n",
  3975. display->name, i, rc);
  3976. goto error;
  3977. }
  3978. }
  3979. panel_mode = display->panel->cur_mode;
  3980. memcpy(panel_mode, dsi_mode, sizeof(*panel_mode));
  3981. /*
  3982. * dsi_mode_flags flags are used to communicate with other drm driver
  3983. * components, and are transient. They aren't inherently part of the
  3984. * display panel's mode and shouldn't be saved into the cached currently
  3985. * active mode.
  3986. */
  3987. panel_mode->dsi_mode_flags = 0;
  3988. error:
  3989. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  3990. return rc;
  3991. }
  3992. static int dsi_display_dfps_calc_front_porch(
  3993. u32 old_fps,
  3994. u32 new_fps,
  3995. u32 a_total,
  3996. u32 b_total,
  3997. u32 b_fp,
  3998. u32 *b_fp_out)
  3999. {
  4000. s32 b_fp_new;
  4001. int add_porches, diff;
  4002. if (!b_fp_out) {
  4003. DSI_ERR("Invalid params\n");
  4004. return -EINVAL;
  4005. }
  4006. if (!a_total || !new_fps) {
  4007. DSI_ERR("Invalid pixel total or new fps in mode request\n");
  4008. return -EINVAL;
  4009. }
  4010. /*
  4011. * Keep clock, other porches constant, use new fps, calc front porch
  4012. * new_vtotal = old_vtotal * (old_fps / new_fps )
  4013. * new_vfp - old_vfp = new_vtotal - old_vtotal
  4014. * new_vfp = old_vfp + old_vtotal * ((old_fps - new_fps)/ new_fps)
  4015. */
  4016. diff = abs(old_fps - new_fps);
  4017. add_porches = mult_frac(b_total, diff, new_fps);
  4018. if (old_fps > new_fps)
  4019. b_fp_new = b_fp + add_porches;
  4020. else
  4021. b_fp_new = b_fp - add_porches;
  4022. DSI_DEBUG("fps %u a %u b %u b_fp %u new_fp %d\n",
  4023. new_fps, a_total, b_total, b_fp, b_fp_new);
  4024. if (b_fp_new < 0) {
  4025. DSI_ERR("Invalid new_hfp calcluated%d\n", b_fp_new);
  4026. return -EINVAL;
  4027. }
  4028. /**
  4029. * TODO: To differentiate from clock method when communicating to the
  4030. * other components, perhaps we should set clk here to original value
  4031. */
  4032. *b_fp_out = b_fp_new;
  4033. return 0;
  4034. }
  4035. /**
  4036. * dsi_display_get_dfps_timing() - Get the new dfps values.
  4037. * @display: DSI display handle.
  4038. * @adj_mode: Mode value structure to be changed.
  4039. * It contains old timing values and latest fps value.
  4040. * New timing values are updated based on new fps.
  4041. * @curr_refresh_rate: Current fps rate.
  4042. * If zero , current fps rate is taken from
  4043. * display->panel->cur_mode.
  4044. * Return: error code.
  4045. */
  4046. static int dsi_display_get_dfps_timing(struct dsi_display *display,
  4047. struct dsi_display_mode *adj_mode,
  4048. u32 curr_refresh_rate)
  4049. {
  4050. struct dsi_dfps_capabilities dfps_caps;
  4051. struct dsi_display_mode per_ctrl_mode;
  4052. struct dsi_mode_info *timing;
  4053. struct dsi_ctrl *m_ctrl;
  4054. int rc = 0;
  4055. if (!display || !adj_mode) {
  4056. DSI_ERR("Invalid params\n");
  4057. return -EINVAL;
  4058. }
  4059. m_ctrl = display->ctrl[display->clk_master_idx].ctrl;
  4060. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  4061. if (!dfps_caps.dfps_support) {
  4062. DSI_ERR("dfps not supported by panel\n");
  4063. return -EINVAL;
  4064. }
  4065. per_ctrl_mode = *adj_mode;
  4066. adjust_timing_by_ctrl_count(display, &per_ctrl_mode);
  4067. if (!curr_refresh_rate) {
  4068. if (!dsi_display_is_seamless_dfps_possible(display,
  4069. &per_ctrl_mode, dfps_caps.type)) {
  4070. DSI_ERR("seamless dynamic fps not supported for mode\n");
  4071. return -EINVAL;
  4072. }
  4073. if (display->panel->cur_mode) {
  4074. curr_refresh_rate =
  4075. display->panel->cur_mode->timing.refresh_rate;
  4076. } else {
  4077. DSI_ERR("cur_mode is not initialized\n");
  4078. return -EINVAL;
  4079. }
  4080. }
  4081. /* TODO: Remove this direct reference to the dsi_ctrl */
  4082. timing = &per_ctrl_mode.timing;
  4083. switch (dfps_caps.type) {
  4084. case DSI_DFPS_IMMEDIATE_VFP:
  4085. rc = dsi_display_dfps_calc_front_porch(
  4086. curr_refresh_rate,
  4087. timing->refresh_rate,
  4088. dsi_h_total_dce(timing),
  4089. DSI_V_TOTAL(timing),
  4090. timing->v_front_porch,
  4091. &adj_mode->timing.v_front_porch);
  4092. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1, DSI_DFPS_IMMEDIATE_VFP,
  4093. curr_refresh_rate, timing->refresh_rate,
  4094. timing->v_front_porch, adj_mode->timing.v_front_porch);
  4095. break;
  4096. case DSI_DFPS_IMMEDIATE_HFP:
  4097. rc = dsi_display_dfps_calc_front_porch(
  4098. curr_refresh_rate,
  4099. timing->refresh_rate,
  4100. DSI_V_TOTAL(timing),
  4101. dsi_h_total_dce(timing),
  4102. timing->h_front_porch,
  4103. &adj_mode->timing.h_front_porch);
  4104. SDE_EVT32(SDE_EVTLOG_FUNC_CASE2, DSI_DFPS_IMMEDIATE_HFP,
  4105. curr_refresh_rate, timing->refresh_rate,
  4106. timing->h_front_porch, adj_mode->timing.h_front_porch);
  4107. if (!rc)
  4108. adj_mode->timing.h_front_porch *= display->ctrl_count;
  4109. break;
  4110. default:
  4111. DSI_ERR("Unsupported DFPS mode %d\n", dfps_caps.type);
  4112. rc = -ENOTSUPP;
  4113. }
  4114. return rc;
  4115. }
  4116. static bool dsi_display_validate_mode_seamless(struct dsi_display *display,
  4117. struct dsi_display_mode *adj_mode)
  4118. {
  4119. int rc = 0;
  4120. if (!display || !adj_mode) {
  4121. DSI_ERR("Invalid params\n");
  4122. return false;
  4123. }
  4124. /* Currently the only seamless transition is dynamic fps */
  4125. rc = dsi_display_get_dfps_timing(display, adj_mode, 0);
  4126. if (rc) {
  4127. DSI_DEBUG("Dynamic FPS not supported for seamless\n");
  4128. } else {
  4129. DSI_DEBUG("Mode switch is seamless Dynamic FPS\n");
  4130. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_DFPS |
  4131. DSI_MODE_FLAG_VBLANK_PRE_MODESET;
  4132. }
  4133. return rc;
  4134. }
  4135. static void dsi_display_validate_dms_fps(struct dsi_display_mode *cur_mode,
  4136. struct dsi_display_mode *to_mode)
  4137. {
  4138. u32 cur_fps, to_fps;
  4139. u32 cur_h_active, to_h_active;
  4140. u32 cur_v_active, to_v_active;
  4141. cur_fps = cur_mode->timing.refresh_rate;
  4142. to_fps = to_mode->timing.refresh_rate;
  4143. cur_h_active = cur_mode->timing.h_active;
  4144. cur_v_active = cur_mode->timing.v_active;
  4145. to_h_active = to_mode->timing.h_active;
  4146. to_v_active = to_mode->timing.v_active;
  4147. if ((cur_h_active == to_h_active) && (cur_v_active == to_v_active) &&
  4148. (cur_fps != to_fps)) {
  4149. to_mode->dsi_mode_flags |= DSI_MODE_FLAG_DMS_FPS;
  4150. DSI_DEBUG("DMS Modeset with FPS change\n");
  4151. } else {
  4152. to_mode->dsi_mode_flags &= ~DSI_MODE_FLAG_DMS_FPS;
  4153. }
  4154. }
  4155. static int dsi_display_set_mode_sub(struct dsi_display *display,
  4156. struct dsi_display_mode *mode,
  4157. u32 flags)
  4158. {
  4159. int rc = 0, clk_rate = 0;
  4160. int i;
  4161. struct dsi_display_ctrl *ctrl;
  4162. struct dsi_display_ctrl *mctrl;
  4163. struct dsi_display_mode_priv_info *priv_info;
  4164. bool commit_phy_timing = false;
  4165. struct dsi_dyn_clk_caps *dyn_clk_caps;
  4166. priv_info = mode->priv_info;
  4167. if (!priv_info) {
  4168. DSI_ERR("[%s] failed to get private info of the display mode\n",
  4169. display->name);
  4170. return -EINVAL;
  4171. }
  4172. SDE_EVT32(mode->dsi_mode_flags, display->panel->panel_mode);
  4173. if (mode->dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_VID)
  4174. display->panel->panel_mode = DSI_OP_VIDEO_MODE;
  4175. else if (mode->dsi_mode_flags & DSI_MODE_FLAG_POMS_TO_CMD)
  4176. display->panel->panel_mode = DSI_OP_CMD_MODE;
  4177. rc = dsi_panel_get_host_cfg_for_mode(display->panel,
  4178. mode,
  4179. &display->config);
  4180. if (rc) {
  4181. DSI_ERR("[%s] failed to get host config for mode, rc=%d\n",
  4182. display->name, rc);
  4183. goto error;
  4184. }
  4185. memcpy(&display->config.lane_map, &display->lane_map,
  4186. sizeof(display->lane_map));
  4187. mctrl = &display->ctrl[display->clk_master_idx];
  4188. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  4189. if (mode->dsi_mode_flags &
  4190. (DSI_MODE_FLAG_DFPS | DSI_MODE_FLAG_VRR)) {
  4191. display_for_each_ctrl(i, display) {
  4192. ctrl = &display->ctrl[i];
  4193. if (!ctrl->ctrl || (ctrl != mctrl))
  4194. continue;
  4195. ctrl->ctrl->hw.ops.set_timing_db(&ctrl->ctrl->hw,
  4196. true);
  4197. dsi_phy_dynamic_refresh_clear(ctrl->phy);
  4198. if ((ctrl->ctrl->version >= DSI_CTRL_VERSION_2_5) &&
  4199. (dyn_clk_caps->maintain_const_fps)) {
  4200. dsi_phy_dynamic_refresh_trigger_sel(ctrl->phy,
  4201. true);
  4202. }
  4203. }
  4204. rc = dsi_display_dfps_update(display, mode);
  4205. if (rc) {
  4206. DSI_ERR("[%s]DSI dfps update failed, rc=%d\n",
  4207. display->name, rc);
  4208. goto error;
  4209. }
  4210. display_for_each_ctrl(i, display) {
  4211. ctrl = &display->ctrl[i];
  4212. rc = dsi_ctrl_update_host_config(ctrl->ctrl,
  4213. &display->config, mode, mode->dsi_mode_flags,
  4214. display->dsi_clk_handle);
  4215. if (rc) {
  4216. DSI_ERR("failed to update ctrl config\n");
  4217. goto error;
  4218. }
  4219. }
  4220. if (priv_info->phy_timing_len) {
  4221. display_for_each_ctrl(i, display) {
  4222. ctrl = &display->ctrl[i];
  4223. rc = dsi_phy_set_timing_params(ctrl->phy,
  4224. priv_info->phy_timing_val,
  4225. priv_info->phy_timing_len,
  4226. commit_phy_timing);
  4227. if (rc)
  4228. DSI_ERR("Fail to add timing params\n");
  4229. }
  4230. }
  4231. if (!(mode->dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK))
  4232. return rc;
  4233. }
  4234. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK) {
  4235. if (display->panel->panel_mode == DSI_OP_VIDEO_MODE) {
  4236. rc = dsi_display_dynamic_clk_switch_vid(display, mode);
  4237. if (rc)
  4238. DSI_ERR("dynamic clk change failed %d\n", rc);
  4239. /*
  4240. * skip rest of the opearations since
  4241. * dsi_display_dynamic_clk_switch_vid() already takes
  4242. * care of them.
  4243. */
  4244. return rc;
  4245. } else if (display->panel->panel_mode == DSI_OP_CMD_MODE) {
  4246. clk_rate = mode->timing.clk_rate_hz;
  4247. rc = dsi_display_dynamic_clk_configure_cmd(display,
  4248. clk_rate);
  4249. if (rc) {
  4250. DSI_ERR("Failed to configure dynamic clk\n");
  4251. return rc;
  4252. }
  4253. }
  4254. }
  4255. display_for_each_ctrl(i, display) {
  4256. ctrl = &display->ctrl[i];
  4257. rc = dsi_ctrl_update_host_config(ctrl->ctrl, &display->config,
  4258. mode, mode->dsi_mode_flags,
  4259. display->dsi_clk_handle);
  4260. if (rc) {
  4261. DSI_ERR("[%s] failed to update ctrl config, rc=%d\n",
  4262. display->name, rc);
  4263. goto error;
  4264. }
  4265. }
  4266. if ((mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) &&
  4267. (display->panel->panel_mode == DSI_OP_CMD_MODE)) {
  4268. u64 cur_bitclk = display->panel->cur_mode->timing.clk_rate_hz;
  4269. u64 to_bitclk = mode->timing.clk_rate_hz;
  4270. commit_phy_timing = true;
  4271. /* No need to set clkrate pending flag if clocks are same */
  4272. if ((!cur_bitclk && !to_bitclk) || (cur_bitclk != to_bitclk))
  4273. atomic_set(&display->clkrate_change_pending, 1);
  4274. dsi_display_validate_dms_fps(display->panel->cur_mode, mode);
  4275. }
  4276. if (priv_info->phy_timing_len) {
  4277. display_for_each_ctrl(i, display) {
  4278. ctrl = &display->ctrl[i];
  4279. rc = dsi_phy_set_timing_params(ctrl->phy,
  4280. priv_info->phy_timing_val,
  4281. priv_info->phy_timing_len,
  4282. commit_phy_timing);
  4283. if (rc)
  4284. DSI_ERR("failed to add DSI PHY timing params\n");
  4285. }
  4286. }
  4287. error:
  4288. return rc;
  4289. }
  4290. /**
  4291. * _dsi_display_dev_init - initializes the display device
  4292. * Initialization will acquire references to the resources required for the
  4293. * display hardware to function.
  4294. * @display: Handle to the display
  4295. * Returns: Zero on success
  4296. */
  4297. static int _dsi_display_dev_init(struct dsi_display *display)
  4298. {
  4299. int rc = 0;
  4300. if (!display) {
  4301. DSI_ERR("invalid display\n");
  4302. return -EINVAL;
  4303. }
  4304. if (!display->panel_node && !display->fw)
  4305. return 0;
  4306. mutex_lock(&display->display_lock);
  4307. display->parser = dsi_parser_get(&display->pdev->dev);
  4308. if (display->fw && display->parser)
  4309. display->parser_node = dsi_parser_get_head_node(
  4310. display->parser, display->fw->data,
  4311. display->fw->size);
  4312. rc = dsi_display_res_init(display);
  4313. if (rc) {
  4314. DSI_ERR("[%s] failed to initialize resources, rc=%d\n",
  4315. display->name, rc);
  4316. goto error;
  4317. }
  4318. error:
  4319. mutex_unlock(&display->display_lock);
  4320. return rc;
  4321. }
  4322. /**
  4323. * _dsi_display_dev_deinit - deinitializes the display device
  4324. * All the resources acquired during device init will be released.
  4325. * @display: Handle to the display
  4326. * Returns: Zero on success
  4327. */
  4328. static int _dsi_display_dev_deinit(struct dsi_display *display)
  4329. {
  4330. int rc = 0;
  4331. if (!display) {
  4332. DSI_ERR("invalid display\n");
  4333. return -EINVAL;
  4334. }
  4335. mutex_lock(&display->display_lock);
  4336. rc = dsi_display_res_deinit(display);
  4337. if (rc)
  4338. DSI_ERR("[%s] failed to deinitialize resource, rc=%d\n",
  4339. display->name, rc);
  4340. mutex_unlock(&display->display_lock);
  4341. return rc;
  4342. }
  4343. /**
  4344. * dsi_display_cont_splash_res_disable() - Disable resource votes added in probe
  4345. * @dsi_display: Pointer to dsi display
  4346. * Returns: Zero on success
  4347. */
  4348. int dsi_display_cont_splash_res_disable(void *dsi_display)
  4349. {
  4350. struct dsi_display *display = dsi_display;
  4351. int rc = 0;
  4352. /* Remove the panel vote that was added during dsi display probe */
  4353. rc = dsi_pwr_enable_regulator(&display->panel->power_info, false);
  4354. if (rc)
  4355. DSI_ERR("[%s] failed to disable vregs, rc=%d\n",
  4356. display->panel->name, rc);
  4357. return rc;
  4358. }
  4359. /**
  4360. * dsi_display_cont_splash_config() - Initialize resources for continuous splash
  4361. * @dsi_display: Pointer to dsi display
  4362. * Returns: Zero on success
  4363. */
  4364. int dsi_display_cont_splash_config(void *dsi_display)
  4365. {
  4366. struct dsi_display *display = dsi_display;
  4367. int rc = 0;
  4368. /* Vote for gdsc required to read register address space */
  4369. if (!display) {
  4370. DSI_ERR("invalid input display param\n");
  4371. return -EINVAL;
  4372. }
  4373. rc = pm_runtime_get_sync(display->drm_dev->dev);
  4374. if (rc < 0) {
  4375. DSI_ERR("failed to vote gdsc for continuous splash, rc=%d\n",
  4376. rc);
  4377. return rc;
  4378. }
  4379. mutex_lock(&display->display_lock);
  4380. display->is_cont_splash_enabled = true;
  4381. /* Update splash status for clock manager */
  4382. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4383. display->is_cont_splash_enabled);
  4384. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY, display->is_cont_splash_enabled);
  4385. /* Set up ctrl isr before enabling core clk */
  4386. dsi_display_ctrl_isr_configure(display, true);
  4387. /* Vote for Core clk and link clk. Votes on ctrl and phy
  4388. * regulator are inplicit from pre clk on callback
  4389. */
  4390. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  4391. DSI_ALL_CLKS, DSI_CLK_ON);
  4392. if (rc) {
  4393. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  4394. display->name, rc);
  4395. goto clk_manager_update;
  4396. }
  4397. mutex_unlock(&display->display_lock);
  4398. /* Set the current brightness level */
  4399. dsi_panel_bl_handoff(display->panel);
  4400. return rc;
  4401. clk_manager_update:
  4402. dsi_display_ctrl_isr_configure(display, false);
  4403. /* Update splash status for clock manager */
  4404. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4405. false);
  4406. pm_runtime_put_sync(display->drm_dev->dev);
  4407. display->is_cont_splash_enabled = false;
  4408. mutex_unlock(&display->display_lock);
  4409. return rc;
  4410. }
  4411. /**
  4412. * dsi_display_splash_res_cleanup() - cleanup for continuous splash
  4413. * @display: Pointer to dsi display
  4414. * Returns: Zero on success
  4415. */
  4416. int dsi_display_splash_res_cleanup(struct dsi_display *display)
  4417. {
  4418. int rc = 0;
  4419. if (!display->is_cont_splash_enabled)
  4420. return 0;
  4421. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  4422. DSI_ALL_CLKS, DSI_CLK_OFF);
  4423. if (rc)
  4424. DSI_ERR("[%s] failed to disable DSI link clocks, rc=%d\n",
  4425. display->name, rc);
  4426. pm_runtime_put_sync(display->drm_dev->dev);
  4427. display->is_cont_splash_enabled = false;
  4428. /* Update splash status for clock manager */
  4429. dsi_display_clk_mngr_update_splash_status(display->clk_mngr,
  4430. display->is_cont_splash_enabled);
  4431. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT, display->is_cont_splash_enabled);
  4432. return rc;
  4433. }
  4434. static int dsi_display_force_update_dsi_clk(struct dsi_display *display)
  4435. {
  4436. int rc = 0;
  4437. rc = dsi_display_link_clk_force_update_ctrl(display->dsi_clk_handle);
  4438. if (!rc) {
  4439. DSI_DEBUG("dsi bit clk has been configured to %d\n",
  4440. display->cached_clk_rate);
  4441. atomic_set(&display->clkrate_change_pending, 0);
  4442. } else {
  4443. DSI_ERR("Failed to configure dsi bit clock '%d'. rc = %d\n",
  4444. display->cached_clk_rate, rc);
  4445. }
  4446. return rc;
  4447. }
  4448. static int dsi_display_validate_split_link(struct dsi_display *display)
  4449. {
  4450. int i, rc = 0;
  4451. struct dsi_display_ctrl *ctrl;
  4452. struct dsi_host_common_cfg *host = &display->panel->host_config;
  4453. if (!host->split_link.split_link_enabled)
  4454. return 0;
  4455. if (display->panel->panel_mode == DSI_OP_CMD_MODE) {
  4456. DSI_ERR("[%s] split link is not supported in command mode\n",
  4457. display->name);
  4458. rc = -ENOTSUPP;
  4459. goto error;
  4460. }
  4461. display_for_each_ctrl(i, display) {
  4462. ctrl = &display->ctrl[i];
  4463. if (!ctrl->ctrl->split_link_supported) {
  4464. DSI_ERR("[%s] split link is not supported by hw\n",
  4465. display->name);
  4466. rc = -ENOTSUPP;
  4467. goto error;
  4468. }
  4469. set_bit(DSI_PHY_SPLIT_LINK, ctrl->phy->hw.feature_map);
  4470. }
  4471. DSI_DEBUG("Split link is enabled\n");
  4472. return 0;
  4473. error:
  4474. host->split_link.split_link_enabled = false;
  4475. return rc;
  4476. }
  4477. static int dsi_display_get_io_resources(struct msm_io_res *io_res, void *data)
  4478. {
  4479. int rc = 0;
  4480. struct dsi_display *display;
  4481. if (!data)
  4482. return -EINVAL;
  4483. rc = dsi_ctrl_get_io_resources(io_res);
  4484. if (rc)
  4485. goto end;
  4486. rc = dsi_phy_get_io_resources(io_res);
  4487. if (rc)
  4488. goto end;
  4489. display = (struct dsi_display *)data;
  4490. rc = dsi_panel_get_io_resources(display->panel, io_res);
  4491. end:
  4492. return rc;
  4493. }
  4494. static int dsi_display_pre_release(void *data)
  4495. {
  4496. if (!data)
  4497. return -EINVAL;
  4498. dsi_display_ctrl_irq_update((struct dsi_display *)data, false);
  4499. return 0;
  4500. }
  4501. static int dsi_display_pre_acquire(void *data)
  4502. {
  4503. if (!data)
  4504. return -EINVAL;
  4505. dsi_display_ctrl_irq_update((struct dsi_display *)data, true);
  4506. return 0;
  4507. }
  4508. /**
  4509. * dsi_display_bind - bind dsi device with controlling device
  4510. * @dev: Pointer to base of platform device
  4511. * @master: Pointer to container of drm device
  4512. * @data: Pointer to private data
  4513. * Returns: Zero on success
  4514. */
  4515. static int dsi_display_bind(struct device *dev,
  4516. struct device *master,
  4517. void *data)
  4518. {
  4519. struct dsi_display_ctrl *display_ctrl;
  4520. struct drm_device *drm;
  4521. struct dsi_display *display;
  4522. struct dsi_clk_info info;
  4523. struct clk_ctrl_cb clk_cb;
  4524. void *handle = NULL;
  4525. struct platform_device *pdev = to_platform_device(dev);
  4526. char *client1 = "dsi_clk_client";
  4527. char *client2 = "mdp_event_client";
  4528. struct msm_vm_ops vm_event_ops = {
  4529. .vm_get_io_resources = dsi_display_get_io_resources,
  4530. .vm_pre_hw_release = dsi_display_pre_release,
  4531. .vm_post_hw_acquire = dsi_display_pre_acquire,
  4532. };
  4533. int i, rc = 0;
  4534. if (!dev || !pdev || !master) {
  4535. DSI_ERR("invalid param(s), dev %pK, pdev %pK, master %pK\n",
  4536. dev, pdev, master);
  4537. return -EINVAL;
  4538. }
  4539. drm = dev_get_drvdata(master);
  4540. display = platform_get_drvdata(pdev);
  4541. if (!drm || !display) {
  4542. DSI_ERR("invalid param(s), drm %pK, display %pK\n",
  4543. drm, display);
  4544. return -EINVAL;
  4545. }
  4546. if (!display->panel_node && !display->fw)
  4547. return 0;
  4548. if (!display->fw)
  4549. display->name = display->panel_node->name;
  4550. /* defer bind if ext bridge driver is not loaded */
  4551. if (display->panel && display->panel->host_config.ext_bridge_mode) {
  4552. for (i = 0; i < display->ext_bridge_cnt; i++) {
  4553. if (!of_drm_find_bridge(
  4554. display->ext_bridge[i].node_of)) {
  4555. DSI_DEBUG("defer for bridge[%d] %s\n", i,
  4556. display->ext_bridge[i].node_of->full_name);
  4557. return -EPROBE_DEFER;
  4558. }
  4559. }
  4560. }
  4561. mutex_lock(&display->display_lock);
  4562. rc = dsi_display_validate_split_link(display);
  4563. if (rc) {
  4564. DSI_ERR("[%s] split link validation failed, rc=%d\n",
  4565. display->name, rc);
  4566. goto error;
  4567. }
  4568. rc = dsi_display_debugfs_init(display);
  4569. if (rc) {
  4570. DSI_ERR("[%s] debugfs init failed, rc=%d\n", display->name, rc);
  4571. goto error;
  4572. }
  4573. atomic_set(&display->clkrate_change_pending, 0);
  4574. display->cached_clk_rate = 0;
  4575. memset(&info, 0x0, sizeof(info));
  4576. display_for_each_ctrl(i, display) {
  4577. display_ctrl = &display->ctrl[i];
  4578. rc = dsi_ctrl_drv_init(display_ctrl->ctrl, display->root);
  4579. if (rc) {
  4580. DSI_ERR("[%s] failed to initialize ctrl[%d], rc=%d\n",
  4581. display->name, i, rc);
  4582. goto error_ctrl_deinit;
  4583. }
  4584. display_ctrl->ctrl->horiz_index = i;
  4585. rc = dsi_phy_drv_init(display_ctrl->phy);
  4586. if (rc) {
  4587. DSI_ERR("[%s] Failed to initialize phy[%d], rc=%d\n",
  4588. display->name, i, rc);
  4589. (void)dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4590. goto error_ctrl_deinit;
  4591. }
  4592. display_ctrl->ctrl->dma_cmd_workq = display->dma_cmd_workq;
  4593. memcpy(&info.c_clks[i],
  4594. (&display_ctrl->ctrl->clk_info.core_clks),
  4595. sizeof(struct dsi_core_clk_info));
  4596. memcpy(&info.l_hs_clks[i],
  4597. (&display_ctrl->ctrl->clk_info.hs_link_clks),
  4598. sizeof(struct dsi_link_hs_clk_info));
  4599. memcpy(&info.l_lp_clks[i],
  4600. (&display_ctrl->ctrl->clk_info.lp_link_clks),
  4601. sizeof(struct dsi_link_lp_clk_info));
  4602. info.c_clks[i].drm = drm;
  4603. info.ctrl_index[i] = display_ctrl->ctrl->cell_index;
  4604. }
  4605. info.pre_clkoff_cb = dsi_pre_clkoff_cb;
  4606. info.pre_clkon_cb = dsi_pre_clkon_cb;
  4607. info.post_clkoff_cb = dsi_post_clkoff_cb;
  4608. info.post_clkon_cb = dsi_post_clkon_cb;
  4609. info.phy_config_cb = dsi_display_phy_configure;
  4610. info.phy_pll_toggle_cb = dsi_display_phy_pll_toggle;
  4611. info.priv_data = display;
  4612. info.master_ndx = display->clk_master_idx;
  4613. info.dsi_ctrl_count = display->ctrl_count;
  4614. snprintf(info.name, MAX_STRING_LEN,
  4615. "DSI_MNGR-%s", display->name);
  4616. display->clk_mngr = dsi_display_clk_mngr_register(&info);
  4617. if (IS_ERR_OR_NULL(display->clk_mngr)) {
  4618. rc = PTR_ERR(display->clk_mngr);
  4619. display->clk_mngr = NULL;
  4620. DSI_ERR("dsi clock registration failed, rc = %d\n", rc);
  4621. goto error_ctrl_deinit;
  4622. }
  4623. handle = dsi_register_clk_handle(display->clk_mngr, client1);
  4624. if (IS_ERR_OR_NULL(handle)) {
  4625. rc = PTR_ERR(handle);
  4626. DSI_ERR("failed to register %s client, rc = %d\n",
  4627. client1, rc);
  4628. goto error_clk_deinit;
  4629. } else {
  4630. display->dsi_clk_handle = handle;
  4631. }
  4632. handle = dsi_register_clk_handle(display->clk_mngr, client2);
  4633. if (IS_ERR_OR_NULL(handle)) {
  4634. rc = PTR_ERR(handle);
  4635. DSI_ERR("failed to register %s client, rc = %d\n",
  4636. client2, rc);
  4637. goto error_clk_client_deinit;
  4638. } else {
  4639. display->mdp_clk_handle = handle;
  4640. }
  4641. clk_cb.priv = display;
  4642. clk_cb.dsi_clk_cb = dsi_display_clk_ctrl_cb;
  4643. display_for_each_ctrl(i, display) {
  4644. display_ctrl = &display->ctrl[i];
  4645. rc = dsi_ctrl_clk_cb_register(display_ctrl->ctrl, &clk_cb);
  4646. if (rc) {
  4647. DSI_ERR("[%s] failed to register ctrl clk_cb[%d], rc=%d\n",
  4648. display->name, i, rc);
  4649. goto error_ctrl_deinit;
  4650. }
  4651. rc = dsi_phy_clk_cb_register(display_ctrl->phy, &clk_cb);
  4652. if (rc) {
  4653. DSI_ERR("[%s] failed to register phy clk_cb[%d], rc=%d\n",
  4654. display->name, i, rc);
  4655. goto error_ctrl_deinit;
  4656. }
  4657. }
  4658. dsi_display_update_byte_intf_div(display);
  4659. rc = dsi_display_mipi_host_init(display);
  4660. if (rc) {
  4661. DSI_ERR("[%s] failed to initialize mipi host, rc=%d\n",
  4662. display->name, rc);
  4663. goto error_ctrl_deinit;
  4664. }
  4665. rc = dsi_panel_drv_init(display->panel, &display->host);
  4666. if (rc) {
  4667. if (rc != -EPROBE_DEFER)
  4668. DSI_ERR("[%s] failed to initialize panel driver, rc=%d\n",
  4669. display->name, rc);
  4670. goto error_host_deinit;
  4671. }
  4672. DSI_INFO("Successfully bind display panel '%s'\n", display->name);
  4673. display->drm_dev = drm;
  4674. display_for_each_ctrl(i, display) {
  4675. display_ctrl = &display->ctrl[i];
  4676. if (!display_ctrl->phy || !display_ctrl->ctrl)
  4677. continue;
  4678. display_ctrl->ctrl->drm_dev = drm;
  4679. rc = dsi_phy_set_clk_freq(display_ctrl->phy,
  4680. &display_ctrl->ctrl->clk_freq);
  4681. if (rc) {
  4682. DSI_ERR("[%s] failed to set phy clk freq, rc=%d\n",
  4683. display->name, rc);
  4684. goto error;
  4685. }
  4686. }
  4687. msm_register_vm_event(master, dev, &vm_event_ops, (void *)display);
  4688. goto error;
  4689. error_host_deinit:
  4690. (void)dsi_display_mipi_host_deinit(display);
  4691. error_clk_client_deinit:
  4692. (void)dsi_deregister_clk_handle(display->dsi_clk_handle);
  4693. error_clk_deinit:
  4694. (void)dsi_display_clk_mngr_deregister(display->clk_mngr);
  4695. error_ctrl_deinit:
  4696. for (i = i - 1; i >= 0; i--) {
  4697. display_ctrl = &display->ctrl[i];
  4698. (void)dsi_phy_drv_deinit(display_ctrl->phy);
  4699. (void)dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4700. }
  4701. (void)dsi_display_debugfs_deinit(display);
  4702. error:
  4703. mutex_unlock(&display->display_lock);
  4704. return rc;
  4705. }
  4706. /**
  4707. * dsi_display_unbind - unbind dsi from controlling device
  4708. * @dev: Pointer to base of platform device
  4709. * @master: Pointer to container of drm device
  4710. * @data: Pointer to private data
  4711. */
  4712. static void dsi_display_unbind(struct device *dev,
  4713. struct device *master, void *data)
  4714. {
  4715. struct dsi_display_ctrl *display_ctrl;
  4716. struct dsi_display *display;
  4717. struct platform_device *pdev = to_platform_device(dev);
  4718. int i, rc = 0;
  4719. if (!dev || !pdev || !master) {
  4720. DSI_ERR("invalid param(s)\n");
  4721. return;
  4722. }
  4723. display = platform_get_drvdata(pdev);
  4724. if (!display || !display->panel_node) {
  4725. DSI_ERR("invalid display\n");
  4726. return;
  4727. }
  4728. mutex_lock(&display->display_lock);
  4729. rc = dsi_display_mipi_host_deinit(display);
  4730. if (rc)
  4731. DSI_ERR("[%s] failed to deinit mipi hosts, rc=%d\n",
  4732. display->name,
  4733. rc);
  4734. display_for_each_ctrl(i, display) {
  4735. display_ctrl = &display->ctrl[i];
  4736. rc = dsi_phy_drv_deinit(display_ctrl->phy);
  4737. if (rc)
  4738. DSI_ERR("[%s] failed to deinit phy%d driver, rc=%d\n",
  4739. display->name, i, rc);
  4740. display->ctrl->ctrl->dma_cmd_workq = NULL;
  4741. rc = dsi_ctrl_drv_deinit(display_ctrl->ctrl);
  4742. if (rc)
  4743. DSI_ERR("[%s] failed to deinit ctrl%d driver, rc=%d\n",
  4744. display->name, i, rc);
  4745. }
  4746. atomic_set(&display->clkrate_change_pending, 0);
  4747. (void)dsi_display_debugfs_deinit(display);
  4748. mutex_unlock(&display->display_lock);
  4749. }
  4750. static const struct component_ops dsi_display_comp_ops = {
  4751. .bind = dsi_display_bind,
  4752. .unbind = dsi_display_unbind,
  4753. };
  4754. static struct platform_driver dsi_display_driver = {
  4755. .probe = dsi_display_dev_probe,
  4756. .remove = dsi_display_dev_remove,
  4757. .driver = {
  4758. .name = "msm-dsi-display",
  4759. .of_match_table = dsi_display_dt_match,
  4760. .suppress_bind_attrs = true,
  4761. },
  4762. };
  4763. static int dsi_display_init(struct dsi_display *display)
  4764. {
  4765. int rc = 0;
  4766. struct platform_device *pdev = display->pdev;
  4767. rc = _dsi_display_dev_init(display);
  4768. if (rc) {
  4769. DSI_ERR("device init failed, rc=%d\n", rc);
  4770. goto end;
  4771. }
  4772. /*
  4773. * Vote on panel regulator is added to make sure panel regulators
  4774. * are ON for cont-splash enabled usecase.
  4775. * This panel regulator vote will be removed only in:
  4776. * 1) device suspend when cont-splash is enabled.
  4777. * 2) cont_splash_res_disable() when cont-splash is disabled.
  4778. * For GKI, adding this vote will make sure that sync_state
  4779. * kernel driver doesn't disable the panel regulators after
  4780. * dsi probe is complete.
  4781. */
  4782. if (display->panel) {
  4783. rc = dsi_pwr_enable_regulator(&display->panel->power_info,
  4784. true);
  4785. if (rc) {
  4786. DSI_ERR("[%s] failed to enable vregs, rc=%d\n",
  4787. display->panel->name, rc);
  4788. return rc;
  4789. }
  4790. }
  4791. rc = component_add(&pdev->dev, &dsi_display_comp_ops);
  4792. if (rc)
  4793. DSI_ERR("component add failed, rc=%d\n", rc);
  4794. DSI_DEBUG("component add success: %s\n", display->name);
  4795. end:
  4796. return rc;
  4797. }
  4798. static void dsi_display_firmware_display(const struct firmware *fw,
  4799. void *context)
  4800. {
  4801. struct dsi_display *display = context;
  4802. if (fw) {
  4803. DSI_INFO("reading data from firmware, size=%zd\n",
  4804. fw->size);
  4805. display->fw = fw;
  4806. if (!strcmp(display->display_type, "primary"))
  4807. display->name = "dsi_firmware_display";
  4808. else if (!strcmp(display->display_type, "secondary"))
  4809. display->name = "dsi_firmware_display_secondary";
  4810. } else {
  4811. DSI_INFO("no firmware available, fallback to device node\n");
  4812. }
  4813. if (dsi_display_init(display))
  4814. return;
  4815. DSI_DEBUG("success\n");
  4816. }
  4817. int dsi_display_dev_probe(struct platform_device *pdev)
  4818. {
  4819. struct dsi_display *display = NULL;
  4820. struct device_node *node = NULL, *panel_node = NULL, *mdp_node = NULL;
  4821. int rc = 0, index = DSI_PRIMARY;
  4822. bool firm_req = false;
  4823. struct dsi_display_boot_param *boot_disp;
  4824. if (!pdev || !pdev->dev.of_node) {
  4825. DSI_ERR("pdev not found\n");
  4826. rc = -ENODEV;
  4827. goto end;
  4828. }
  4829. display = devm_kzalloc(&pdev->dev, sizeof(*display), GFP_KERNEL);
  4830. if (!display) {
  4831. rc = -ENOMEM;
  4832. goto end;
  4833. }
  4834. mutex_init(&display->display_lock);
  4835. display->dma_cmd_workq = create_singlethread_workqueue(
  4836. "dsi_dma_cmd_workq");
  4837. if (!display->dma_cmd_workq) {
  4838. DSI_ERR("failed to create work queue\n");
  4839. rc = -EINVAL;
  4840. goto end;
  4841. }
  4842. mdp_node = of_parse_phandle(pdev->dev.of_node, "qcom,mdp", 0);
  4843. if (!mdp_node) {
  4844. DSI_ERR("mdp_node not found\n");
  4845. rc = -ENODEV;
  4846. goto end;
  4847. }
  4848. display->trusted_vm_env = of_property_read_bool(mdp_node,
  4849. "qcom,sde-trusted-vm-env");
  4850. if (display->trusted_vm_env)
  4851. DSI_INFO("Display enabled with trusted vm path\n");
  4852. /* initialize panel id to UINT64_MAX */
  4853. display->panel_id = ~0x0;
  4854. display->display_type = of_get_property(pdev->dev.of_node,
  4855. "label", NULL);
  4856. if (!display->display_type)
  4857. display->display_type = "primary";
  4858. if (!strcmp(display->display_type, "secondary"))
  4859. index = DSI_SECONDARY;
  4860. boot_disp = &boot_displays[index];
  4861. node = pdev->dev.of_node;
  4862. if (boot_disp->boot_disp_en) {
  4863. /* The panel name should be same as UEFI name index */
  4864. panel_node = of_find_node_by_name(mdp_node, boot_disp->name);
  4865. if (!panel_node)
  4866. DSI_WARN("panel_node %s not found\n", boot_disp->name);
  4867. } else {
  4868. panel_node = of_parse_phandle(node,
  4869. "qcom,dsi-default-panel", 0);
  4870. if (!panel_node)
  4871. DSI_WARN("default panel not found\n");
  4872. }
  4873. boot_disp->node = pdev->dev.of_node;
  4874. boot_disp->disp = display;
  4875. display->panel_node = panel_node;
  4876. display->pdev = pdev;
  4877. display->boot_disp = boot_disp;
  4878. dsi_display_parse_cmdline_topology(display, index);
  4879. platform_set_drvdata(pdev, display);
  4880. rc = dsi_display_parse_dt(display);
  4881. if (rc) {
  4882. DSI_ERR("[%s] failed to parse dt, rc=%d\n", display->name, rc);
  4883. goto end;
  4884. }
  4885. rc = dsi_display_validate_resources(display);
  4886. if (rc) {
  4887. DSI_ERR("[%s] needed resources not probed yet, rc=%d\n",
  4888. display->name, rc);
  4889. goto end;
  4890. }
  4891. /* initialize display in firmware callback */
  4892. if (!boot_disp->boot_disp_en &&
  4893. IS_ENABLED(CONFIG_DSI_PARSER) &&
  4894. !display->trusted_vm_env) {
  4895. if (!strcmp(display->display_type, "primary"))
  4896. firm_req = !request_firmware_nowait(
  4897. THIS_MODULE, 1, "dsi_prop",
  4898. &pdev->dev, GFP_KERNEL, display,
  4899. dsi_display_firmware_display);
  4900. else if (!strcmp(display->display_type, "secondary"))
  4901. firm_req = !request_firmware_nowait(
  4902. THIS_MODULE, 1, "dsi_prop_sec",
  4903. &pdev->dev, GFP_KERNEL, display,
  4904. dsi_display_firmware_display);
  4905. }
  4906. if (!firm_req) {
  4907. rc = dsi_display_init(display);
  4908. if (rc)
  4909. goto end;
  4910. }
  4911. return 0;
  4912. end:
  4913. if (display) {
  4914. mutex_destroy(&display->display_lock);
  4915. devm_kfree(&pdev->dev, display);
  4916. }
  4917. return rc;
  4918. }
  4919. int dsi_display_dev_remove(struct platform_device *pdev)
  4920. {
  4921. int rc = 0, i = 0;
  4922. struct dsi_display *display;
  4923. struct dsi_display_ctrl *ctrl;
  4924. if (!pdev) {
  4925. DSI_ERR("Invalid device\n");
  4926. return -EINVAL;
  4927. }
  4928. display = platform_get_drvdata(pdev);
  4929. /* decrement ref count */
  4930. of_node_put(display->panel_node);
  4931. if (display->dma_cmd_workq) {
  4932. flush_workqueue(display->dma_cmd_workq);
  4933. destroy_workqueue(display->dma_cmd_workq);
  4934. display->dma_cmd_workq = NULL;
  4935. display_for_each_ctrl(i, display) {
  4936. ctrl = &display->ctrl[i];
  4937. if (!ctrl->ctrl)
  4938. continue;
  4939. ctrl->ctrl->dma_cmd_workq = NULL;
  4940. }
  4941. }
  4942. (void)_dsi_display_dev_deinit(display);
  4943. platform_set_drvdata(pdev, NULL);
  4944. devm_kfree(&pdev->dev, display);
  4945. return rc;
  4946. }
  4947. int dsi_display_get_num_of_displays(void)
  4948. {
  4949. int i, count = 0;
  4950. for (i = 0; i < MAX_DSI_ACTIVE_DISPLAY; i++) {
  4951. struct dsi_display *display = boot_displays[i].disp;
  4952. if ((display && display->panel_node) ||
  4953. (display && display->fw))
  4954. count++;
  4955. }
  4956. return count;
  4957. }
  4958. int dsi_display_get_active_displays(void **display_array, u32 max_display_count)
  4959. {
  4960. int index = 0, count = 0;
  4961. if (!display_array || !max_display_count) {
  4962. DSI_ERR("invalid params\n");
  4963. return 0;
  4964. }
  4965. for (index = 0; index < MAX_DSI_ACTIVE_DISPLAY; index++) {
  4966. struct dsi_display *display = boot_displays[index].disp;
  4967. if ((display && display->panel_node) ||
  4968. (display && display->fw))
  4969. display_array[count++] = display;
  4970. }
  4971. return count;
  4972. }
  4973. void dsi_display_set_active_state(struct dsi_display *display, bool is_active)
  4974. {
  4975. if (!display)
  4976. return;
  4977. mutex_lock(&display->display_lock);
  4978. display->is_active = is_active;
  4979. mutex_unlock(&display->display_lock);
  4980. }
  4981. int dsi_display_drm_bridge_init(struct dsi_display *display,
  4982. struct drm_encoder *enc)
  4983. {
  4984. int rc = 0;
  4985. struct dsi_bridge *bridge;
  4986. struct msm_drm_private *priv = NULL;
  4987. if (!display || !display->drm_dev || !enc) {
  4988. DSI_ERR("invalid param(s)\n");
  4989. return -EINVAL;
  4990. }
  4991. mutex_lock(&display->display_lock);
  4992. priv = display->drm_dev->dev_private;
  4993. if (!priv) {
  4994. DSI_ERR("Private data is not present\n");
  4995. rc = -EINVAL;
  4996. goto error;
  4997. }
  4998. if (display->bridge) {
  4999. DSI_ERR("display is already initialize\n");
  5000. goto error;
  5001. }
  5002. bridge = dsi_drm_bridge_init(display, display->drm_dev, enc);
  5003. if (IS_ERR_OR_NULL(bridge)) {
  5004. rc = PTR_ERR(bridge);
  5005. DSI_ERR("[%s] brige init failed, %d\n", display->name, rc);
  5006. goto error;
  5007. }
  5008. display->bridge = bridge;
  5009. priv->bridges[priv->num_bridges++] = &bridge->base;
  5010. if (display->tx_cmd_buf == NULL) {
  5011. rc = dsi_host_alloc_cmd_tx_buffer(display);
  5012. if (rc)
  5013. DSI_ERR("failed to allocate cmd tx buffer memory\n");
  5014. }
  5015. error:
  5016. mutex_unlock(&display->display_lock);
  5017. return rc;
  5018. }
  5019. int dsi_display_drm_bridge_deinit(struct dsi_display *display)
  5020. {
  5021. int rc = 0;
  5022. if (!display) {
  5023. DSI_ERR("Invalid params\n");
  5024. return -EINVAL;
  5025. }
  5026. mutex_lock(&display->display_lock);
  5027. dsi_drm_bridge_cleanup(display->bridge);
  5028. display->bridge = NULL;
  5029. mutex_unlock(&display->display_lock);
  5030. return rc;
  5031. }
  5032. /* Hook functions to call external connector, pointer validation is
  5033. * done in dsi_display_drm_ext_bridge_init.
  5034. */
  5035. static enum drm_connector_status dsi_display_drm_ext_detect(
  5036. struct drm_connector *connector,
  5037. bool force,
  5038. void *disp)
  5039. {
  5040. struct dsi_display *display = disp;
  5041. return display->ext_conn->funcs->detect(display->ext_conn, force);
  5042. }
  5043. static int dsi_display_drm_ext_get_modes(
  5044. struct drm_connector *connector, void *disp,
  5045. const struct msm_resource_caps_info *avail_res)
  5046. {
  5047. struct dsi_display *display = disp;
  5048. struct drm_display_mode *pmode, *pt;
  5049. int count;
  5050. /* if there are modes defined in panel, ignore external modes */
  5051. if (display->panel->num_timing_nodes)
  5052. return dsi_connector_get_modes(connector, disp, avail_res);
  5053. count = display->ext_conn->helper_private->get_modes(
  5054. display->ext_conn);
  5055. list_for_each_entry_safe(pmode, pt,
  5056. &display->ext_conn->probed_modes, head) {
  5057. list_move_tail(&pmode->head, &connector->probed_modes);
  5058. }
  5059. connector->display_info = display->ext_conn->display_info;
  5060. return count;
  5061. }
  5062. static enum drm_mode_status dsi_display_drm_ext_mode_valid(
  5063. struct drm_connector *connector,
  5064. struct drm_display_mode *mode,
  5065. void *disp, const struct msm_resource_caps_info *avail_res)
  5066. {
  5067. struct dsi_display *display = disp;
  5068. enum drm_mode_status status;
  5069. /* always do internal mode_valid check */
  5070. status = dsi_conn_mode_valid(connector, mode, disp, avail_res);
  5071. if (status != MODE_OK)
  5072. return status;
  5073. return display->ext_conn->helper_private->mode_valid(
  5074. display->ext_conn, mode);
  5075. }
  5076. static int dsi_display_drm_ext_atomic_check(struct drm_connector *connector,
  5077. void *disp,
  5078. struct drm_atomic_state *state)
  5079. {
  5080. struct dsi_display *display = disp;
  5081. struct drm_connector_state *c_state;
  5082. c_state = drm_atomic_get_new_connector_state(state, connector);
  5083. return display->ext_conn->helper_private->atomic_check(
  5084. display->ext_conn, state);
  5085. }
  5086. static int dsi_display_ext_get_info(struct drm_connector *connector,
  5087. struct msm_display_info *info, void *disp)
  5088. {
  5089. struct dsi_display *display;
  5090. int i;
  5091. if (!info || !disp) {
  5092. DSI_ERR("invalid params\n");
  5093. return -EINVAL;
  5094. }
  5095. display = disp;
  5096. if (!display->panel) {
  5097. DSI_ERR("invalid display panel\n");
  5098. return -EINVAL;
  5099. }
  5100. mutex_lock(&display->display_lock);
  5101. memset(info, 0, sizeof(struct msm_display_info));
  5102. info->intf_type = DRM_MODE_CONNECTOR_DSI;
  5103. info->num_of_h_tiles = display->ctrl_count;
  5104. for (i = 0; i < info->num_of_h_tiles; i++)
  5105. info->h_tile_instance[i] = display->ctrl[i].ctrl->cell_index;
  5106. info->is_connected = connector->status != connector_status_disconnected;
  5107. if (!strcmp(display->display_type, "primary"))
  5108. info->display_type = SDE_CONNECTOR_PRIMARY;
  5109. else if (!strcmp(display->display_type, "secondary"))
  5110. info->display_type = SDE_CONNECTOR_SECONDARY;
  5111. info->capabilities |= (MSM_DISPLAY_CAP_VID_MODE |
  5112. MSM_DISPLAY_CAP_EDID | MSM_DISPLAY_CAP_HOT_PLUG);
  5113. info->curr_panel_mode = MSM_DISPLAY_VIDEO_MODE;
  5114. mutex_unlock(&display->display_lock);
  5115. return 0;
  5116. }
  5117. static int dsi_display_ext_get_mode_info(struct drm_connector *connector,
  5118. const struct drm_display_mode *drm_mode,
  5119. struct msm_mode_info *mode_info,
  5120. void *display, const struct msm_resource_caps_info *avail_res)
  5121. {
  5122. struct msm_display_topology *topology;
  5123. if (!drm_mode || !mode_info ||
  5124. !avail_res || !avail_res->max_mixer_width)
  5125. return -EINVAL;
  5126. memset(mode_info, 0, sizeof(*mode_info));
  5127. mode_info->frame_rate = drm_mode_vrefresh(drm_mode);
  5128. mode_info->vtotal = drm_mode->vtotal;
  5129. topology = &mode_info->topology;
  5130. topology->num_lm = (avail_res->max_mixer_width
  5131. <= drm_mode->hdisplay) ? 2 : 1;
  5132. topology->num_enc = 0;
  5133. topology->num_intf = topology->num_lm;
  5134. mode_info->comp_info.comp_type = MSM_DISPLAY_COMPRESSION_NONE;
  5135. return 0;
  5136. }
  5137. static struct dsi_display_ext_bridge *dsi_display_ext_get_bridge(
  5138. struct drm_bridge *bridge)
  5139. {
  5140. struct msm_drm_private *priv;
  5141. struct sde_kms *sde_kms;
  5142. struct drm_connector *conn;
  5143. struct drm_connector_list_iter conn_iter;
  5144. struct sde_connector *sde_conn;
  5145. struct dsi_display *display;
  5146. struct dsi_display_ext_bridge *dsi_bridge = NULL;
  5147. int i;
  5148. if (!bridge || !bridge->encoder) {
  5149. SDE_ERROR("invalid argument\n");
  5150. return NULL;
  5151. }
  5152. priv = bridge->dev->dev_private;
  5153. sde_kms = to_sde_kms(priv->kms);
  5154. drm_connector_list_iter_begin(sde_kms->dev, &conn_iter);
  5155. drm_for_each_connector_iter(conn, &conn_iter) {
  5156. sde_conn = to_sde_connector(conn);
  5157. if (sde_conn->encoder == bridge->encoder) {
  5158. display = sde_conn->display;
  5159. display_for_each_ctrl(i, display) {
  5160. if (display->ext_bridge[i].bridge == bridge) {
  5161. dsi_bridge = &display->ext_bridge[i];
  5162. break;
  5163. }
  5164. }
  5165. }
  5166. }
  5167. drm_connector_list_iter_end(&conn_iter);
  5168. return dsi_bridge;
  5169. }
  5170. static void dsi_display_drm_ext_adjust_timing(
  5171. const struct dsi_display *display,
  5172. struct drm_display_mode *mode)
  5173. {
  5174. mode->hdisplay /= display->ctrl_count;
  5175. mode->hsync_start /= display->ctrl_count;
  5176. mode->hsync_end /= display->ctrl_count;
  5177. mode->htotal /= display->ctrl_count;
  5178. mode->hskew /= display->ctrl_count;
  5179. mode->clock /= display->ctrl_count;
  5180. }
  5181. static enum drm_mode_status dsi_display_drm_ext_bridge_mode_valid(
  5182. struct drm_bridge *bridge,
  5183. const struct drm_display_info *info,
  5184. const struct drm_display_mode *mode)
  5185. {
  5186. struct dsi_display_ext_bridge *ext_bridge;
  5187. struct drm_display_mode tmp;
  5188. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5189. if (!ext_bridge)
  5190. return MODE_ERROR;
  5191. tmp = *mode;
  5192. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5193. return ext_bridge->orig_funcs->mode_valid(bridge, info, &tmp);
  5194. }
  5195. static bool dsi_display_drm_ext_bridge_mode_fixup(
  5196. struct drm_bridge *bridge,
  5197. const struct drm_display_mode *mode,
  5198. struct drm_display_mode *adjusted_mode)
  5199. {
  5200. struct dsi_display_ext_bridge *ext_bridge;
  5201. struct drm_display_mode tmp;
  5202. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5203. if (!ext_bridge)
  5204. return false;
  5205. tmp = *mode;
  5206. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5207. return ext_bridge->orig_funcs->mode_fixup(bridge, &tmp, &tmp);
  5208. }
  5209. static void dsi_display_drm_ext_bridge_mode_set(
  5210. struct drm_bridge *bridge,
  5211. const struct drm_display_mode *mode,
  5212. const struct drm_display_mode *adjusted_mode)
  5213. {
  5214. struct dsi_display_ext_bridge *ext_bridge;
  5215. struct drm_display_mode tmp;
  5216. ext_bridge = dsi_display_ext_get_bridge(bridge);
  5217. if (!ext_bridge)
  5218. return;
  5219. tmp = *mode;
  5220. dsi_display_drm_ext_adjust_timing(ext_bridge->display, &tmp);
  5221. ext_bridge->orig_funcs->mode_set(bridge, &tmp, &tmp);
  5222. }
  5223. static int dsi_host_ext_attach(struct mipi_dsi_host *host,
  5224. struct mipi_dsi_device *dsi)
  5225. {
  5226. struct dsi_display *display = to_dsi_display(host);
  5227. struct dsi_panel *panel;
  5228. if (!host || !dsi || !display->panel) {
  5229. DSI_ERR("Invalid param\n");
  5230. return -EINVAL;
  5231. }
  5232. DSI_DEBUG("DSI[%s]: channel=%d, lanes=%d, format=%d, mode_flags=%lx\n",
  5233. dsi->name, dsi->channel, dsi->lanes,
  5234. dsi->format, dsi->mode_flags);
  5235. panel = display->panel;
  5236. panel->host_config.data_lanes = 0;
  5237. if (dsi->lanes > 0)
  5238. panel->host_config.data_lanes |= DSI_DATA_LANE_0;
  5239. if (dsi->lanes > 1)
  5240. panel->host_config.data_lanes |= DSI_DATA_LANE_1;
  5241. if (dsi->lanes > 2)
  5242. panel->host_config.data_lanes |= DSI_DATA_LANE_2;
  5243. if (dsi->lanes > 3)
  5244. panel->host_config.data_lanes |= DSI_DATA_LANE_3;
  5245. switch (dsi->format) {
  5246. case MIPI_DSI_FMT_RGB888:
  5247. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB888;
  5248. break;
  5249. case MIPI_DSI_FMT_RGB666:
  5250. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB666_LOOSE;
  5251. break;
  5252. case MIPI_DSI_FMT_RGB666_PACKED:
  5253. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB666;
  5254. break;
  5255. case MIPI_DSI_FMT_RGB565:
  5256. default:
  5257. panel->host_config.dst_format = DSI_PIXEL_FORMAT_RGB565;
  5258. break;
  5259. }
  5260. if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) {
  5261. panel->panel_mode = DSI_OP_VIDEO_MODE;
  5262. if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
  5263. panel->video_config.traffic_mode =
  5264. DSI_VIDEO_TRAFFIC_BURST_MODE;
  5265. else if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
  5266. panel->video_config.traffic_mode =
  5267. DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  5268. else
  5269. panel->video_config.traffic_mode =
  5270. DSI_VIDEO_TRAFFIC_SYNC_START_EVENTS;
  5271. panel->video_config.hsa_lp11_en =
  5272. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSA;
  5273. panel->video_config.hbp_lp11_en =
  5274. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HBP;
  5275. panel->video_config.hfp_lp11_en =
  5276. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HFP;
  5277. panel->video_config.pulse_mode_hsa_he =
  5278. dsi->mode_flags & MIPI_DSI_MODE_VIDEO_HSE;
  5279. } else {
  5280. panel->panel_mode = DSI_OP_CMD_MODE;
  5281. DSI_ERR("command mode not supported by ext bridge\n");
  5282. return -ENOTSUPP;
  5283. }
  5284. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  5285. return 0;
  5286. }
  5287. static struct mipi_dsi_host_ops dsi_host_ext_ops = {
  5288. .attach = dsi_host_ext_attach,
  5289. .detach = dsi_host_detach,
  5290. .transfer = dsi_host_transfer,
  5291. };
  5292. struct drm_panel *dsi_display_get_drm_panel(struct dsi_display *display)
  5293. {
  5294. if (!display || !display->panel) {
  5295. pr_err("invalid param(s)\n");
  5296. return NULL;
  5297. }
  5298. return &display->panel->drm_panel;
  5299. }
  5300. int dsi_display_drm_ext_bridge_init(struct dsi_display *display,
  5301. struct drm_encoder *encoder, struct drm_connector *connector)
  5302. {
  5303. struct drm_device *drm;
  5304. struct drm_bridge *bridge;
  5305. struct drm_bridge *ext_bridge;
  5306. struct drm_connector *ext_conn;
  5307. struct sde_connector *sde_conn;
  5308. struct drm_bridge *prev_bridge;
  5309. int rc = 0, i;
  5310. if (!display || !encoder || !connector)
  5311. return -EINVAL;
  5312. drm = encoder->dev;
  5313. bridge = drm_bridge_chain_get_first_bridge(encoder);
  5314. sde_conn = to_sde_connector(connector);
  5315. prev_bridge = bridge;
  5316. if (display->panel && !display->panel->host_config.ext_bridge_mode)
  5317. return 0;
  5318. if (!bridge)
  5319. return -EINVAL;
  5320. for (i = 0; i < display->ext_bridge_cnt; i++) {
  5321. struct dsi_display_ext_bridge *ext_bridge_info =
  5322. &display->ext_bridge[i];
  5323. struct drm_encoder *c_encoder;
  5324. /* return if ext bridge is already initialized */
  5325. if (ext_bridge_info->bridge)
  5326. return 0;
  5327. ext_bridge = of_drm_find_bridge(ext_bridge_info->node_of);
  5328. if (IS_ERR_OR_NULL(ext_bridge)) {
  5329. rc = PTR_ERR(ext_bridge);
  5330. DSI_ERR("failed to find ext bridge\n");
  5331. goto error;
  5332. }
  5333. /* override functions for mode adjustment */
  5334. if (display->ext_bridge_cnt > 1) {
  5335. ext_bridge_info->bridge_funcs = *ext_bridge->funcs;
  5336. if (ext_bridge->funcs->mode_fixup)
  5337. ext_bridge_info->bridge_funcs.mode_fixup =
  5338. dsi_display_drm_ext_bridge_mode_fixup;
  5339. if (ext_bridge->funcs->mode_valid)
  5340. ext_bridge_info->bridge_funcs.mode_valid =
  5341. dsi_display_drm_ext_bridge_mode_valid;
  5342. if (ext_bridge->funcs->mode_set)
  5343. ext_bridge_info->bridge_funcs.mode_set =
  5344. dsi_display_drm_ext_bridge_mode_set;
  5345. ext_bridge_info->orig_funcs = ext_bridge->funcs;
  5346. ext_bridge->funcs = &ext_bridge_info->bridge_funcs;
  5347. }
  5348. rc = drm_bridge_attach(encoder, ext_bridge, prev_bridge, 0);
  5349. if (rc) {
  5350. DSI_ERR("[%s] ext brige attach failed, %d\n",
  5351. display->name, rc);
  5352. goto error;
  5353. }
  5354. ext_bridge_info->display = display;
  5355. ext_bridge_info->bridge = ext_bridge;
  5356. prev_bridge = ext_bridge;
  5357. /* ext bridge will init its own connector during attach,
  5358. * we need to extract it out of the connector list
  5359. */
  5360. spin_lock_irq(&drm->mode_config.connector_list_lock);
  5361. ext_conn = list_last_entry(&drm->mode_config.connector_list,
  5362. struct drm_connector, head);
  5363. if (!ext_conn) {
  5364. DSI_ERR("failed to get external connector\n");
  5365. rc = PTR_ERR(ext_conn);
  5366. spin_unlock_irq(&drm->mode_config.connector_list_lock);
  5367. goto error;
  5368. }
  5369. drm_connector_for_each_possible_encoder(ext_conn, c_encoder)
  5370. break;
  5371. if (!c_encoder) {
  5372. DSI_ERR("failed to get encoder\n");
  5373. rc = PTR_ERR(c_encoder);
  5374. spin_unlock_irq(&drm->mode_config.connector_list_lock);
  5375. goto error;
  5376. }
  5377. if (ext_conn && ext_conn != connector &&
  5378. c_encoder->base.id == bridge->encoder->base.id) {
  5379. list_del_init(&ext_conn->head);
  5380. display->ext_conn = ext_conn;
  5381. }
  5382. spin_unlock_irq(&drm->mode_config.connector_list_lock);
  5383. /* if there is no valid external connector created, or in split
  5384. * mode, default setting is used from panel defined in DT file.
  5385. */
  5386. if (!display->ext_conn ||
  5387. !display->ext_conn->funcs ||
  5388. !display->ext_conn->helper_private ||
  5389. display->ext_bridge_cnt > 1) {
  5390. display->ext_conn = NULL;
  5391. continue;
  5392. }
  5393. /* otherwise, hook up the functions to use external connector */
  5394. if (display->ext_conn->funcs->detect)
  5395. sde_conn->ops.detect = dsi_display_drm_ext_detect;
  5396. if (display->ext_conn->helper_private->get_modes)
  5397. sde_conn->ops.get_modes =
  5398. dsi_display_drm_ext_get_modes;
  5399. if (display->ext_conn->helper_private->mode_valid)
  5400. sde_conn->ops.mode_valid =
  5401. dsi_display_drm_ext_mode_valid;
  5402. if (display->ext_conn->helper_private->atomic_check)
  5403. sde_conn->ops.atomic_check =
  5404. dsi_display_drm_ext_atomic_check;
  5405. sde_conn->ops.get_info =
  5406. dsi_display_ext_get_info;
  5407. sde_conn->ops.get_mode_info =
  5408. dsi_display_ext_get_mode_info;
  5409. /* add support to attach/detach */
  5410. display->host.ops = &dsi_host_ext_ops;
  5411. }
  5412. return 0;
  5413. error:
  5414. return rc;
  5415. }
  5416. int dsi_display_get_info(struct drm_connector *connector,
  5417. struct msm_display_info *info, void *disp)
  5418. {
  5419. struct dsi_display *display;
  5420. struct dsi_panel_phy_props phy_props;
  5421. struct dsi_host_common_cfg *host;
  5422. int i, rc;
  5423. if (!info || !disp) {
  5424. DSI_ERR("invalid params\n");
  5425. return -EINVAL;
  5426. }
  5427. display = disp;
  5428. if (!display->panel) {
  5429. DSI_ERR("invalid display panel\n");
  5430. return -EINVAL;
  5431. }
  5432. mutex_lock(&display->display_lock);
  5433. rc = dsi_panel_get_phy_props(display->panel, &phy_props);
  5434. if (rc) {
  5435. DSI_ERR("[%s] failed to get panel phy props, rc=%d\n",
  5436. display->name, rc);
  5437. goto error;
  5438. }
  5439. memset(info, 0, sizeof(struct msm_display_info));
  5440. info->intf_type = DRM_MODE_CONNECTOR_DSI;
  5441. info->num_of_h_tiles = display->ctrl_count;
  5442. for (i = 0; i < info->num_of_h_tiles; i++)
  5443. info->h_tile_instance[i] = display->ctrl[i].ctrl->cell_index;
  5444. info->is_connected = display->is_active;
  5445. if (!strcmp(display->display_type, "primary"))
  5446. info->display_type = SDE_CONNECTOR_PRIMARY;
  5447. else if (!strcmp(display->display_type, "secondary"))
  5448. info->display_type = SDE_CONNECTOR_SECONDARY;
  5449. info->width_mm = phy_props.panel_width_mm;
  5450. info->height_mm = phy_props.panel_height_mm;
  5451. info->max_width = 1920;
  5452. info->max_height = 1080;
  5453. info->qsync_min_fps =
  5454. display->panel->qsync_caps.qsync_min_fps;
  5455. info->has_qsync_min_fps_list =
  5456. (display->panel->qsync_caps.qsync_min_fps_list_len > 0) ?
  5457. true : false;
  5458. info->poms_align_vsync = display->panel->poms_align_vsync;
  5459. switch (display->panel->panel_mode) {
  5460. case DSI_OP_VIDEO_MODE:
  5461. info->curr_panel_mode = MSM_DISPLAY_VIDEO_MODE;
  5462. info->capabilities |= MSM_DISPLAY_CAP_VID_MODE;
  5463. if (display->panel->panel_mode_switch_enabled)
  5464. info->capabilities |= MSM_DISPLAY_CAP_CMD_MODE;
  5465. break;
  5466. case DSI_OP_CMD_MODE:
  5467. info->curr_panel_mode = MSM_DISPLAY_CMD_MODE;
  5468. info->capabilities |= MSM_DISPLAY_CAP_CMD_MODE;
  5469. if (display->panel->panel_mode_switch_enabled)
  5470. info->capabilities |= MSM_DISPLAY_CAP_VID_MODE;
  5471. info->is_te_using_watchdog_timer =
  5472. display->panel->te_using_watchdog_timer |
  5473. display->sw_te_using_wd;
  5474. break;
  5475. default:
  5476. DSI_ERR("unknwown dsi panel mode %d\n",
  5477. display->panel->panel_mode);
  5478. break;
  5479. }
  5480. if (display->panel->esd_config.esd_enabled &&
  5481. !display->sw_te_using_wd)
  5482. info->capabilities |= MSM_DISPLAY_ESD_ENABLED;
  5483. info->te_source = display->te_source;
  5484. host = &display->panel->host_config;
  5485. if (host->split_link.split_link_enabled)
  5486. info->capabilities |= MSM_DISPLAY_SPLIT_LINK;
  5487. info->dsc_count = display->panel->dsc_count;
  5488. info->lm_count = display->panel->lm_count;
  5489. error:
  5490. mutex_unlock(&display->display_lock);
  5491. return rc;
  5492. }
  5493. int dsi_display_get_mode_count(struct dsi_display *display,
  5494. u32 *count)
  5495. {
  5496. if (!display || !display->panel) {
  5497. DSI_ERR("invalid display:%d panel:%d\n", display != NULL,
  5498. display ? display->panel != NULL : 0);
  5499. return -EINVAL;
  5500. }
  5501. mutex_lock(&display->display_lock);
  5502. *count = display->panel->num_display_modes;
  5503. mutex_unlock(&display->display_lock);
  5504. return 0;
  5505. }
  5506. void dsi_display_adjust_mode_timing(struct dsi_display *display,
  5507. struct dsi_display_mode *dsi_mode,
  5508. int lanes, int bpp)
  5509. {
  5510. u64 new_htotal, new_vtotal, htotal, vtotal, old_htotal, div;
  5511. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5512. u32 bits_per_symbol = 16, num_of_symbols = 7; /* For Cphy */
  5513. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5514. /* Constant FPS is not supported on command mode */
  5515. if (!(dsi_mode->panel_mode_caps & DSI_OP_VIDEO_MODE))
  5516. return;
  5517. if (!dyn_clk_caps->maintain_const_fps)
  5518. return;
  5519. /*
  5520. * When there is a dynamic clock switch, there is small change
  5521. * in FPS. To compensate for this difference in FPS, hfp or vfp
  5522. * is adjusted. It has been assumed that the refined porch values
  5523. * are supported by the panel. This logic can be enhanced further
  5524. * in future by taking min/max porches supported by the panel.
  5525. */
  5526. switch (dyn_clk_caps->type) {
  5527. case DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_HFP:
  5528. vtotal = DSI_V_TOTAL(&dsi_mode->timing);
  5529. old_htotal = dsi_h_total_dce(&dsi_mode->timing);
  5530. do_div(old_htotal, display->ctrl_count);
  5531. new_htotal = dsi_mode->timing.clk_rate_hz * lanes;
  5532. div = bpp * vtotal * dsi_mode->timing.refresh_rate;
  5533. if (dsi_display_is_type_cphy(display)) {
  5534. new_htotal = new_htotal * bits_per_symbol;
  5535. div = div * num_of_symbols;
  5536. }
  5537. do_div(new_htotal, div);
  5538. if (old_htotal > new_htotal)
  5539. dsi_mode->timing.h_front_porch -=
  5540. ((old_htotal - new_htotal) * display->ctrl_count);
  5541. else
  5542. dsi_mode->timing.h_front_porch +=
  5543. ((new_htotal - old_htotal) * display->ctrl_count);
  5544. break;
  5545. case DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_VFP:
  5546. htotal = dsi_h_total_dce(&dsi_mode->timing);
  5547. do_div(htotal, display->ctrl_count);
  5548. new_vtotal = dsi_mode->timing.clk_rate_hz * lanes;
  5549. div = bpp * htotal * dsi_mode->timing.refresh_rate;
  5550. if (dsi_display_is_type_cphy(display)) {
  5551. new_vtotal = new_vtotal * bits_per_symbol;
  5552. div = div * num_of_symbols;
  5553. }
  5554. do_div(new_vtotal, div);
  5555. dsi_mode->timing.v_front_porch = new_vtotal -
  5556. dsi_mode->timing.v_back_porch -
  5557. dsi_mode->timing.v_sync_width -
  5558. dsi_mode->timing.v_active;
  5559. break;
  5560. default:
  5561. break;
  5562. }
  5563. }
  5564. static void _dsi_display_populate_bit_clks(struct dsi_display *display,
  5565. int start, int end, u32 *mode_idx)
  5566. {
  5567. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5568. struct dsi_display_mode *src, *dst;
  5569. struct dsi_host_common_cfg *cfg;
  5570. struct dsi_display_mode_priv_info *priv_info;
  5571. int i, j, total_modes, bpp, lanes = 0;
  5572. size_t size = 0;
  5573. if (!display || !mode_idx)
  5574. return;
  5575. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5576. if (!dyn_clk_caps->dyn_clk_support)
  5577. return;
  5578. cfg = &(display->panel->host_config);
  5579. bpp = dsi_pixel_format_to_bpp(cfg->dst_format);
  5580. if (cfg->data_lanes & DSI_DATA_LANE_0)
  5581. lanes++;
  5582. if (cfg->data_lanes & DSI_DATA_LANE_1)
  5583. lanes++;
  5584. if (cfg->data_lanes & DSI_DATA_LANE_2)
  5585. lanes++;
  5586. if (cfg->data_lanes & DSI_DATA_LANE_3)
  5587. lanes++;
  5588. total_modes = display->panel->num_display_modes;
  5589. for (i = start; i < end; i++) {
  5590. src = &display->modes[i];
  5591. if (!src)
  5592. return;
  5593. /*
  5594. * TODO: currently setting the first bit rate in
  5595. * the list as preferred rate. But ideally should
  5596. * be based on user or device tree preferrence.
  5597. */
  5598. src->timing.clk_rate_hz = dyn_clk_caps->bit_clk_list[0];
  5599. dsi_display_adjust_mode_timing(display, src, lanes, bpp);
  5600. src->pixel_clk_khz =
  5601. div_u64(src->timing.clk_rate_hz * lanes, bpp);
  5602. src->pixel_clk_khz /= 1000;
  5603. src->pixel_clk_khz *= display->ctrl_count;
  5604. }
  5605. for (i = 1; i < dyn_clk_caps->bit_clk_list_len; i++) {
  5606. if (*mode_idx >= total_modes)
  5607. return;
  5608. for (j = start; j < end; j++) {
  5609. src = &display->modes[j];
  5610. dst = &display->modes[*mode_idx];
  5611. if (!src || !dst) {
  5612. DSI_ERR("invalid mode index\n");
  5613. return;
  5614. }
  5615. memcpy(dst, src, sizeof(struct dsi_display_mode));
  5616. size = sizeof(struct dsi_display_mode_priv_info);
  5617. priv_info = kzalloc(size, GFP_KERNEL);
  5618. dst->priv_info = priv_info;
  5619. if (dst->priv_info)
  5620. memcpy(dst->priv_info, src->priv_info, size);
  5621. dst->timing.clk_rate_hz = dyn_clk_caps->bit_clk_list[i];
  5622. dsi_display_adjust_mode_timing(display, dst, lanes,
  5623. bpp);
  5624. dst->panel_mode_caps = DSI_OP_VIDEO_MODE;
  5625. dst->pixel_clk_khz =
  5626. div_u64(dst->timing.clk_rate_hz * lanes, bpp);
  5627. dst->pixel_clk_khz /= 1000;
  5628. dst->pixel_clk_khz *= display->ctrl_count;
  5629. (*mode_idx)++;
  5630. }
  5631. }
  5632. }
  5633. void dsi_display_put_mode(struct dsi_display *display,
  5634. struct dsi_display_mode *mode)
  5635. {
  5636. dsi_panel_put_mode(mode);
  5637. }
  5638. int dsi_display_get_modes(struct dsi_display *display,
  5639. struct dsi_display_mode **out_modes)
  5640. {
  5641. struct dsi_dfps_capabilities dfps_caps;
  5642. struct dsi_display_ctrl *ctrl;
  5643. struct dsi_host_common_cfg *host = &display->panel->host_config;
  5644. bool is_split_link, support_cmd_mode, support_video_mode;
  5645. u32 num_dfps_rates, timing_mode_count, display_mode_count;
  5646. u32 sublinks_count, mode_idx, array_idx = 0;
  5647. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5648. int i, start, end, rc = -EINVAL;
  5649. if (!display || !out_modes) {
  5650. DSI_ERR("Invalid params\n");
  5651. return -EINVAL;
  5652. }
  5653. *out_modes = NULL;
  5654. ctrl = &display->ctrl[0];
  5655. mutex_lock(&display->display_lock);
  5656. if (display->modes)
  5657. goto exit;
  5658. display_mode_count = display->panel->num_display_modes;
  5659. display->modes = kcalloc(display_mode_count, sizeof(*display->modes),
  5660. GFP_KERNEL);
  5661. if (!display->modes) {
  5662. rc = -ENOMEM;
  5663. goto error;
  5664. }
  5665. rc = dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5666. if (rc) {
  5667. DSI_ERR("[%s] failed to get dfps caps from panel\n",
  5668. display->name);
  5669. goto error;
  5670. }
  5671. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5672. timing_mode_count = display->panel->num_timing_nodes;
  5673. /* Validate command line timing */
  5674. if ((display->cmdline_timing != NO_OVERRIDE) &&
  5675. (display->cmdline_timing >= timing_mode_count))
  5676. display->cmdline_timing = NO_OVERRIDE;
  5677. for (mode_idx = 0; mode_idx < timing_mode_count; mode_idx++) {
  5678. struct dsi_display_mode display_mode;
  5679. int topology_override = NO_OVERRIDE;
  5680. bool is_preferred = false;
  5681. u32 frame_threshold_us = ctrl->ctrl->frame_threshold_time_us;
  5682. if (display->cmdline_timing == mode_idx) {
  5683. topology_override = display->cmdline_topology;
  5684. is_preferred = true;
  5685. }
  5686. memset(&display_mode, 0, sizeof(display_mode));
  5687. rc = dsi_panel_get_mode(display->panel, mode_idx,
  5688. &display_mode,
  5689. topology_override);
  5690. if (rc) {
  5691. DSI_ERR("[%s] failed to get mode idx %d from panel\n",
  5692. display->name, mode_idx);
  5693. goto error;
  5694. }
  5695. support_cmd_mode = display_mode.panel_mode_caps & DSI_OP_CMD_MODE;
  5696. support_video_mode = display_mode.panel_mode_caps & DSI_OP_VIDEO_MODE;
  5697. /* Setup widebus support */
  5698. display_mode.priv_info->widebus_support =
  5699. ctrl->ctrl->hw.widebus_support;
  5700. num_dfps_rates = ((!dfps_caps.dfps_support ||
  5701. !support_video_mode) ? 1 : dfps_caps.dfps_list_len);
  5702. /* Calculate dsi frame transfer time */
  5703. if (support_cmd_mode) {
  5704. dsi_panel_calc_dsi_transfer_time(
  5705. &display->panel->host_config,
  5706. &display_mode, frame_threshold_us);
  5707. display_mode.priv_info->dsi_transfer_time_us =
  5708. display_mode.timing.dsi_transfer_time_us;
  5709. display_mode.priv_info->min_dsi_clk_hz =
  5710. display_mode.timing.min_dsi_clk_hz;
  5711. display_mode.priv_info->mdp_transfer_time_us =
  5712. display_mode.timing.mdp_transfer_time_us;
  5713. }
  5714. is_split_link = host->split_link.split_link_enabled;
  5715. sublinks_count = host->split_link.num_sublinks;
  5716. if (is_split_link && sublinks_count > 1) {
  5717. display_mode.timing.h_active *= sublinks_count;
  5718. display_mode.timing.h_front_porch *= sublinks_count;
  5719. display_mode.timing.h_sync_width *= sublinks_count;
  5720. display_mode.timing.h_back_porch *= sublinks_count;
  5721. display_mode.timing.h_skew *= sublinks_count;
  5722. display_mode.pixel_clk_khz *= sublinks_count;
  5723. } else {
  5724. display_mode.timing.h_active *= display->ctrl_count;
  5725. display_mode.timing.h_front_porch *=
  5726. display->ctrl_count;
  5727. display_mode.timing.h_sync_width *=
  5728. display->ctrl_count;
  5729. display_mode.timing.h_back_porch *=
  5730. display->ctrl_count;
  5731. display_mode.timing.h_skew *= display->ctrl_count;
  5732. display_mode.pixel_clk_khz *= display->ctrl_count;
  5733. }
  5734. start = array_idx;
  5735. for (i = 0; i < num_dfps_rates; i++) {
  5736. struct dsi_display_mode *sub_mode =
  5737. &display->modes[array_idx];
  5738. u32 curr_refresh_rate;
  5739. if (!sub_mode) {
  5740. DSI_ERR("invalid mode data\n");
  5741. rc = -EFAULT;
  5742. goto error;
  5743. }
  5744. memcpy(sub_mode, &display_mode, sizeof(display_mode));
  5745. array_idx++;
  5746. if (!dfps_caps.dfps_support || !support_video_mode)
  5747. continue;
  5748. curr_refresh_rate = sub_mode->timing.refresh_rate;
  5749. sub_mode->timing.refresh_rate = dfps_caps.dfps_list[i];
  5750. dsi_display_get_dfps_timing(display, sub_mode,
  5751. curr_refresh_rate);
  5752. sub_mode->panel_mode_caps = DSI_OP_VIDEO_MODE;
  5753. }
  5754. end = array_idx;
  5755. _dsi_display_populate_bit_clks(display, start, end, &array_idx);
  5756. if (is_preferred) {
  5757. /* Set first timing sub mode as preferred mode */
  5758. display->modes[start].is_preferred = true;
  5759. }
  5760. }
  5761. exit:
  5762. *out_modes = display->modes;
  5763. rc = 0;
  5764. error:
  5765. if (rc)
  5766. kfree(display->modes);
  5767. mutex_unlock(&display->display_lock);
  5768. return rc;
  5769. }
  5770. int dsi_display_get_panel_vfp(void *dsi_display,
  5771. int h_active, int v_active)
  5772. {
  5773. int i, rc = 0;
  5774. u32 count, refresh_rate = 0;
  5775. struct dsi_dfps_capabilities dfps_caps;
  5776. struct dsi_display *display = (struct dsi_display *)dsi_display;
  5777. struct dsi_host_common_cfg *host;
  5778. if (!display || !display->panel)
  5779. return -EINVAL;
  5780. mutex_lock(&display->display_lock);
  5781. count = display->panel->num_display_modes;
  5782. if (display->panel->cur_mode)
  5783. refresh_rate = display->panel->cur_mode->timing.refresh_rate;
  5784. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5785. if (dfps_caps.dfps_support)
  5786. refresh_rate = dfps_caps.max_refresh_rate;
  5787. if (!refresh_rate) {
  5788. mutex_unlock(&display->display_lock);
  5789. DSI_ERR("Null Refresh Rate\n");
  5790. return -EINVAL;
  5791. }
  5792. host = &display->panel->host_config;
  5793. if (host->split_link.split_link_enabled)
  5794. h_active *= host->split_link.num_sublinks;
  5795. else
  5796. h_active *= display->ctrl_count;
  5797. for (i = 0; i < count; i++) {
  5798. struct dsi_display_mode *m = &display->modes[i];
  5799. if (m && v_active == m->timing.v_active &&
  5800. h_active == m->timing.h_active &&
  5801. refresh_rate == m->timing.refresh_rate) {
  5802. rc = m->timing.v_front_porch;
  5803. break;
  5804. }
  5805. }
  5806. mutex_unlock(&display->display_lock);
  5807. return rc;
  5808. }
  5809. int dsi_display_get_default_lms(void *dsi_display, u32 *num_lm)
  5810. {
  5811. struct dsi_display *display = (struct dsi_display *)dsi_display;
  5812. u32 count, i;
  5813. int rc = 0;
  5814. *num_lm = 0;
  5815. mutex_lock(&display->display_lock);
  5816. count = display->panel->num_display_modes;
  5817. mutex_unlock(&display->display_lock);
  5818. if (!display->modes) {
  5819. struct dsi_display_mode *m;
  5820. rc = dsi_display_get_modes(display, &m);
  5821. if (rc)
  5822. return rc;
  5823. }
  5824. mutex_lock(&display->display_lock);
  5825. for (i = 0; i < count; i++) {
  5826. struct dsi_display_mode *m = &display->modes[i];
  5827. *num_lm = max(m->priv_info->topology.num_lm, *num_lm);
  5828. }
  5829. mutex_unlock(&display->display_lock);
  5830. return rc;
  5831. }
  5832. int dsi_display_get_qsync_min_fps(void *display_dsi, u32 mode_fps)
  5833. {
  5834. struct dsi_display *display = (struct dsi_display *)display_dsi;
  5835. struct dsi_panel *panel;
  5836. u32 i;
  5837. if (display == NULL || display->panel == NULL)
  5838. return -EINVAL;
  5839. panel = display->panel;
  5840. for (i = 0; i < panel->dfps_caps.dfps_list_len; i++) {
  5841. if (panel->dfps_caps.dfps_list[i] == mode_fps)
  5842. return panel->qsync_caps.qsync_min_fps_list[i];
  5843. }
  5844. SDE_EVT32(mode_fps);
  5845. DSI_DEBUG("Invalid mode_fps %d\n", mode_fps);
  5846. return -EINVAL;
  5847. }
  5848. int dsi_display_find_mode(struct dsi_display *display,
  5849. const struct dsi_display_mode *cmp,
  5850. struct dsi_display_mode **out_mode)
  5851. {
  5852. u32 count, i;
  5853. int rc;
  5854. if (!display || !out_mode)
  5855. return -EINVAL;
  5856. *out_mode = NULL;
  5857. mutex_lock(&display->display_lock);
  5858. count = display->panel->num_display_modes;
  5859. mutex_unlock(&display->display_lock);
  5860. if (!display->modes) {
  5861. struct dsi_display_mode *m;
  5862. rc = dsi_display_get_modes(display, &m);
  5863. if (rc)
  5864. return rc;
  5865. }
  5866. mutex_lock(&display->display_lock);
  5867. for (i = 0; i < count; i++) {
  5868. struct dsi_display_mode *m = &display->modes[i];
  5869. if (cmp->timing.v_active == m->timing.v_active &&
  5870. cmp->timing.h_active == m->timing.h_active &&
  5871. cmp->timing.refresh_rate == m->timing.refresh_rate) {
  5872. *out_mode = m;
  5873. rc = 0;
  5874. break;
  5875. }
  5876. }
  5877. mutex_unlock(&display->display_lock);
  5878. if (!*out_mode) {
  5879. DSI_ERR("[%s] failed to find mode for v_active %u h_active %u fps %u pclk %u\n",
  5880. display->name, cmp->timing.v_active,
  5881. cmp->timing.h_active, cmp->timing.refresh_rate,
  5882. cmp->pixel_clk_khz);
  5883. rc = -ENOENT;
  5884. }
  5885. return rc;
  5886. }
  5887. static inline bool dsi_display_mode_switch_dfps(struct dsi_display_mode *cur,
  5888. struct dsi_display_mode *adj)
  5889. {
  5890. /*
  5891. * If there is a change in the hfp or vfp of the current and adjoining
  5892. * mode,then either it is a dfps mode switch or dynamic clk change with
  5893. * constant fps.
  5894. */
  5895. if ((cur->timing.h_front_porch != adj->timing.h_front_porch) ||
  5896. (cur->timing.v_front_porch != adj->timing.v_front_porch))
  5897. return true;
  5898. else
  5899. return false;
  5900. }
  5901. /**
  5902. * dsi_display_validate_mode_change() - Validate mode change case.
  5903. * @display: DSI display handle.
  5904. * @cur_mode: Current mode.
  5905. * @adj_mode: Mode to be set.
  5906. * MSM_MODE_FLAG_SEAMLESS_VRR flag is set if there
  5907. * is change in hfp or vfp but vactive and hactive are same.
  5908. * DSI_MODE_FLAG_DYN_CLK flag is set if there
  5909. * is change in clk but vactive and hactive are same.
  5910. * Return: error code.
  5911. */
  5912. int dsi_display_validate_mode_change(struct dsi_display *display,
  5913. struct dsi_display_mode *cur_mode,
  5914. struct dsi_display_mode *adj_mode)
  5915. {
  5916. int rc = 0;
  5917. struct dsi_dfps_capabilities dfps_caps;
  5918. struct dsi_dyn_clk_caps *dyn_clk_caps;
  5919. struct sde_connector *sde_conn;
  5920. if (!display || !adj_mode || !display->drm_conn) {
  5921. DSI_ERR("Invalid params\n");
  5922. return -EINVAL;
  5923. }
  5924. if (!display->panel || !display->panel->cur_mode) {
  5925. DSI_DEBUG("Current panel mode not set\n");
  5926. return rc;
  5927. }
  5928. if ((cur_mode->timing.v_active != adj_mode->timing.v_active) ||
  5929. (cur_mode->timing.h_active != adj_mode->timing.h_active)) {
  5930. DSI_DEBUG("Avoid VRR and POMS when resolution is changed\n");
  5931. return rc;
  5932. }
  5933. sde_conn = to_sde_connector(display->drm_conn);
  5934. mutex_lock(&display->display_lock);
  5935. if (sde_conn->expected_panel_mode == MSM_DISPLAY_VIDEO_MODE &&
  5936. display->config.panel_mode == DSI_OP_CMD_MODE) {
  5937. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_POMS_TO_VID;
  5938. DSI_DEBUG("Panel operating mode change to video detected\n");
  5939. } else if (sde_conn->expected_panel_mode == MSM_DISPLAY_CMD_MODE &&
  5940. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  5941. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_POMS_TO_CMD;
  5942. DSI_DEBUG("Panel operating mode change to command detected\n");
  5943. } else {
  5944. dyn_clk_caps = &(display->panel->dyn_clk_caps);
  5945. /* dfps and dynamic clock with const fps use case */
  5946. if (dsi_display_mode_switch_dfps(cur_mode, adj_mode)) {
  5947. dsi_panel_get_dfps_caps(display->panel, &dfps_caps);
  5948. if (dfps_caps.dfps_support ||
  5949. dyn_clk_caps->maintain_const_fps) {
  5950. DSI_DEBUG("Mode switch is seamless variable refresh\n");
  5951. adj_mode->dsi_mode_flags |= DSI_MODE_FLAG_VRR;
  5952. SDE_EVT32(SDE_EVTLOG_FUNC_CASE1,
  5953. cur_mode->timing.refresh_rate,
  5954. adj_mode->timing.refresh_rate,
  5955. cur_mode->timing.h_front_porch,
  5956. adj_mode->timing.h_front_porch,
  5957. cur_mode->timing.v_front_porch,
  5958. adj_mode->timing.v_front_porch);
  5959. }
  5960. }
  5961. /* dynamic clk change use case */
  5962. if (cur_mode->pixel_clk_khz != adj_mode->pixel_clk_khz) {
  5963. if (dyn_clk_caps->dyn_clk_support) {
  5964. DSI_DEBUG("dynamic clk change detected\n");
  5965. if ((adj_mode->dsi_mode_flags &
  5966. DSI_MODE_FLAG_VRR) &&
  5967. (!dyn_clk_caps->maintain_const_fps)) {
  5968. DSI_ERR("dfps and dyn clk not supported in same commit\n");
  5969. rc = -ENOTSUPP;
  5970. goto error;
  5971. }
  5972. adj_mode->dsi_mode_flags |=
  5973. DSI_MODE_FLAG_DYN_CLK;
  5974. SDE_EVT32(SDE_EVTLOG_FUNC_CASE2,
  5975. cur_mode->pixel_clk_khz,
  5976. adj_mode->pixel_clk_khz);
  5977. }
  5978. }
  5979. }
  5980. error:
  5981. mutex_unlock(&display->display_lock);
  5982. return rc;
  5983. }
  5984. int dsi_display_validate_mode(struct dsi_display *display,
  5985. struct dsi_display_mode *mode,
  5986. u32 flags)
  5987. {
  5988. int rc = 0;
  5989. int i;
  5990. struct dsi_display_ctrl *ctrl;
  5991. struct dsi_display_mode adj_mode;
  5992. if (!display || !mode) {
  5993. DSI_ERR("Invalid params\n");
  5994. return -EINVAL;
  5995. }
  5996. mutex_lock(&display->display_lock);
  5997. adj_mode = *mode;
  5998. adjust_timing_by_ctrl_count(display, &adj_mode);
  5999. rc = dsi_panel_validate_mode(display->panel, &adj_mode);
  6000. if (rc) {
  6001. DSI_ERR("[%s] panel mode validation failed, rc=%d\n",
  6002. display->name, rc);
  6003. goto error;
  6004. }
  6005. display_for_each_ctrl(i, display) {
  6006. ctrl = &display->ctrl[i];
  6007. rc = dsi_ctrl_validate_timing(ctrl->ctrl, &adj_mode.timing);
  6008. if (rc) {
  6009. DSI_ERR("[%s] ctrl mode validation failed, rc=%d\n",
  6010. display->name, rc);
  6011. goto error;
  6012. }
  6013. rc = dsi_phy_validate_mode(ctrl->phy, &adj_mode.timing);
  6014. if (rc) {
  6015. DSI_ERR("[%s] phy mode validation failed, rc=%d\n",
  6016. display->name, rc);
  6017. goto error;
  6018. }
  6019. }
  6020. if ((flags & DSI_VALIDATE_FLAG_ALLOW_ADJUST) &&
  6021. (mode->dsi_mode_flags & DSI_MODE_FLAG_SEAMLESS)) {
  6022. rc = dsi_display_validate_mode_seamless(display, mode);
  6023. if (rc) {
  6024. DSI_ERR("[%s] seamless not possible rc=%d\n",
  6025. display->name, rc);
  6026. goto error;
  6027. }
  6028. }
  6029. error:
  6030. mutex_unlock(&display->display_lock);
  6031. return rc;
  6032. }
  6033. int dsi_display_set_mode(struct dsi_display *display,
  6034. struct dsi_display_mode *mode,
  6035. u32 flags)
  6036. {
  6037. int rc = 0;
  6038. struct dsi_display_mode adj_mode;
  6039. struct dsi_mode_info timing;
  6040. if (!display || !mode || !display->panel) {
  6041. DSI_ERR("Invalid params\n");
  6042. return -EINVAL;
  6043. }
  6044. mutex_lock(&display->display_lock);
  6045. adj_mode = *mode;
  6046. timing = adj_mode.timing;
  6047. adjust_timing_by_ctrl_count(display, &adj_mode);
  6048. if (!display->panel->cur_mode) {
  6049. display->panel->cur_mode =
  6050. kzalloc(sizeof(struct dsi_display_mode), GFP_KERNEL);
  6051. if (!display->panel->cur_mode) {
  6052. rc = -ENOMEM;
  6053. goto error;
  6054. }
  6055. }
  6056. /*For dynamic DSI setting, use specified clock rate */
  6057. if (display->cached_clk_rate > 0)
  6058. adj_mode.priv_info->clk_rate_hz = display->cached_clk_rate;
  6059. rc = dsi_display_validate_mode_set(display, &adj_mode, flags);
  6060. if (rc) {
  6061. DSI_ERR("[%s] mode cannot be set\n", display->name);
  6062. goto error;
  6063. }
  6064. rc = dsi_display_set_mode_sub(display, &adj_mode, flags);
  6065. if (rc) {
  6066. DSI_ERR("[%s] failed to set mode\n", display->name);
  6067. goto error;
  6068. }
  6069. DSI_INFO("mdp_transfer_time=%d, hactive=%d, vactive=%d, fps=%d\n",
  6070. adj_mode.priv_info->mdp_transfer_time_us,
  6071. timing.h_active, timing.v_active, timing.refresh_rate);
  6072. SDE_EVT32(adj_mode.priv_info->mdp_transfer_time_us,
  6073. timing.h_active, timing.v_active, timing.refresh_rate);
  6074. memcpy(display->panel->cur_mode, &adj_mode, sizeof(adj_mode));
  6075. error:
  6076. mutex_unlock(&display->display_lock);
  6077. return rc;
  6078. }
  6079. int dsi_display_set_tpg_state(struct dsi_display *display, bool enable)
  6080. {
  6081. int rc = 0;
  6082. int i;
  6083. struct dsi_display_ctrl *ctrl;
  6084. if (!display) {
  6085. DSI_ERR("Invalid params\n");
  6086. return -EINVAL;
  6087. }
  6088. display_for_each_ctrl(i, display) {
  6089. ctrl = &display->ctrl[i];
  6090. rc = dsi_ctrl_set_tpg_state(ctrl->ctrl, enable);
  6091. if (rc) {
  6092. DSI_ERR("[%s] failed to set tpg state for host_%d\n",
  6093. display->name, i);
  6094. goto error;
  6095. }
  6096. }
  6097. display->is_tpg_enabled = enable;
  6098. error:
  6099. return rc;
  6100. }
  6101. static int dsi_display_pre_switch(struct dsi_display *display)
  6102. {
  6103. int rc = 0;
  6104. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6105. DSI_CORE_CLK, DSI_CLK_ON);
  6106. if (rc) {
  6107. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  6108. display->name, rc);
  6109. goto error;
  6110. }
  6111. rc = dsi_display_ctrl_update(display);
  6112. if (rc) {
  6113. DSI_ERR("[%s] failed to update DSI controller, rc=%d\n",
  6114. display->name, rc);
  6115. goto error_ctrl_clk_off;
  6116. }
  6117. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6118. DSI_LINK_CLK, DSI_CLK_ON);
  6119. if (rc) {
  6120. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  6121. display->name, rc);
  6122. goto error_ctrl_deinit;
  6123. }
  6124. goto error;
  6125. error_ctrl_deinit:
  6126. (void)dsi_display_ctrl_deinit(display);
  6127. error_ctrl_clk_off:
  6128. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6129. DSI_CORE_CLK, DSI_CLK_OFF);
  6130. error:
  6131. return rc;
  6132. }
  6133. static bool _dsi_display_validate_host_state(struct dsi_display *display)
  6134. {
  6135. int i;
  6136. struct dsi_display_ctrl *ctrl;
  6137. display_for_each_ctrl(i, display) {
  6138. ctrl = &display->ctrl[i];
  6139. if (!ctrl->ctrl)
  6140. continue;
  6141. if (!dsi_ctrl_validate_host_state(ctrl->ctrl))
  6142. return false;
  6143. }
  6144. return true;
  6145. }
  6146. static void dsi_display_handle_fifo_underflow(struct work_struct *work)
  6147. {
  6148. struct dsi_display *display = NULL;
  6149. display = container_of(work, struct dsi_display, fifo_underflow_work);
  6150. if (!display || !display->panel ||
  6151. atomic_read(&display->panel->esd_recovery_pending)) {
  6152. DSI_DEBUG("Invalid recovery use case\n");
  6153. return;
  6154. }
  6155. mutex_lock(&display->display_lock);
  6156. if (!_dsi_display_validate_host_state(display)) {
  6157. mutex_unlock(&display->display_lock);
  6158. return;
  6159. }
  6160. DSI_INFO("handle DSI FIFO underflow error\n");
  6161. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6162. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6163. DSI_ALL_CLKS, DSI_CLK_ON);
  6164. dsi_display_soft_reset(display);
  6165. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6166. DSI_ALL_CLKS, DSI_CLK_OFF);
  6167. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6168. mutex_unlock(&display->display_lock);
  6169. }
  6170. static void dsi_display_handle_fifo_overflow(struct work_struct *work)
  6171. {
  6172. struct dsi_display *display = NULL;
  6173. struct dsi_display_ctrl *ctrl;
  6174. int i, rc;
  6175. int mask = BIT(20); /* clock lane */
  6176. int (*cb_func)(void *event_usr_ptr,
  6177. uint32_t event_idx, uint32_t instance_idx,
  6178. uint32_t data0, uint32_t data1,
  6179. uint32_t data2, uint32_t data3);
  6180. void *data;
  6181. u32 version = 0;
  6182. display = container_of(work, struct dsi_display, fifo_overflow_work);
  6183. if (!display || !display->panel ||
  6184. (display->panel->panel_mode != DSI_OP_VIDEO_MODE) ||
  6185. atomic_read(&display->panel->esd_recovery_pending)) {
  6186. DSI_DEBUG("Invalid recovery use case\n");
  6187. return;
  6188. }
  6189. mutex_lock(&display->display_lock);
  6190. if (!_dsi_display_validate_host_state(display)) {
  6191. mutex_unlock(&display->display_lock);
  6192. return;
  6193. }
  6194. DSI_INFO("handle DSI FIFO overflow error\n");
  6195. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6196. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6197. DSI_ALL_CLKS, DSI_CLK_ON);
  6198. /*
  6199. * below recovery sequence is not applicable to
  6200. * hw version 2.0.0, 2.1.0 and 2.2.0, so return early.
  6201. */
  6202. ctrl = &display->ctrl[display->clk_master_idx];
  6203. version = dsi_ctrl_get_hw_version(ctrl->ctrl);
  6204. if (!version || (version < 0x20020001))
  6205. goto end;
  6206. /* reset ctrl and lanes */
  6207. display_for_each_ctrl(i, display) {
  6208. ctrl = &display->ctrl[i];
  6209. rc = dsi_ctrl_reset(ctrl->ctrl, mask);
  6210. rc = dsi_phy_lane_reset(ctrl->phy);
  6211. }
  6212. /* wait for display line count to be in active area */
  6213. ctrl = &display->ctrl[display->clk_master_idx];
  6214. if (ctrl->ctrl->recovery_cb.event_cb) {
  6215. cb_func = ctrl->ctrl->recovery_cb.event_cb;
  6216. data = ctrl->ctrl->recovery_cb.event_usr_ptr;
  6217. rc = cb_func(data, SDE_CONN_EVENT_VID_FIFO_OVERFLOW,
  6218. display->clk_master_idx, 0, 0, 0, 0);
  6219. if (rc < 0) {
  6220. DSI_DEBUG("sde callback failed\n");
  6221. goto end;
  6222. }
  6223. }
  6224. /* Enable Video mode for DSI controller */
  6225. display_for_each_ctrl(i, display) {
  6226. ctrl = &display->ctrl[i];
  6227. dsi_ctrl_vid_engine_en(ctrl->ctrl, true);
  6228. }
  6229. /*
  6230. * Add sufficient delay to make sure
  6231. * pixel transmission has started
  6232. */
  6233. udelay(200);
  6234. end:
  6235. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6236. DSI_ALL_CLKS, DSI_CLK_OFF);
  6237. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6238. mutex_unlock(&display->display_lock);
  6239. }
  6240. static void dsi_display_handle_lp_rx_timeout(struct work_struct *work)
  6241. {
  6242. struct dsi_display *display = NULL;
  6243. struct dsi_display_ctrl *ctrl;
  6244. int i, rc;
  6245. int mask = (BIT(20) | (0xF << 16)); /* clock lane and 4 data lane */
  6246. int (*cb_func)(void *event_usr_ptr,
  6247. uint32_t event_idx, uint32_t instance_idx,
  6248. uint32_t data0, uint32_t data1,
  6249. uint32_t data2, uint32_t data3);
  6250. void *data;
  6251. u32 version = 0;
  6252. display = container_of(work, struct dsi_display, lp_rx_timeout_work);
  6253. if (!display || !display->panel ||
  6254. (display->panel->panel_mode != DSI_OP_VIDEO_MODE) ||
  6255. atomic_read(&display->panel->esd_recovery_pending)) {
  6256. DSI_DEBUG("Invalid recovery use case\n");
  6257. return;
  6258. }
  6259. mutex_lock(&display->display_lock);
  6260. if (!_dsi_display_validate_host_state(display)) {
  6261. mutex_unlock(&display->display_lock);
  6262. return;
  6263. }
  6264. DSI_INFO("handle DSI LP RX Timeout error\n");
  6265. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6266. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6267. DSI_ALL_CLKS, DSI_CLK_ON);
  6268. /*
  6269. * below recovery sequence is not applicable to
  6270. * hw version 2.0.0, 2.1.0 and 2.2.0, so return early.
  6271. */
  6272. ctrl = &display->ctrl[display->clk_master_idx];
  6273. version = dsi_ctrl_get_hw_version(ctrl->ctrl);
  6274. if (!version || (version < 0x20020001))
  6275. goto end;
  6276. /* reset ctrl and lanes */
  6277. display_for_each_ctrl(i, display) {
  6278. ctrl = &display->ctrl[i];
  6279. rc = dsi_ctrl_reset(ctrl->ctrl, mask);
  6280. rc = dsi_phy_lane_reset(ctrl->phy);
  6281. }
  6282. ctrl = &display->ctrl[display->clk_master_idx];
  6283. if (ctrl->ctrl->recovery_cb.event_cb) {
  6284. cb_func = ctrl->ctrl->recovery_cb.event_cb;
  6285. data = ctrl->ctrl->recovery_cb.event_usr_ptr;
  6286. rc = cb_func(data, SDE_CONN_EVENT_VID_FIFO_OVERFLOW,
  6287. display->clk_master_idx, 0, 0, 0, 0);
  6288. if (rc < 0) {
  6289. DSI_DEBUG("Target is in suspend/shutdown\n");
  6290. goto end;
  6291. }
  6292. }
  6293. /* Enable Video mode for DSI controller */
  6294. display_for_each_ctrl(i, display) {
  6295. ctrl = &display->ctrl[i];
  6296. dsi_ctrl_vid_engine_en(ctrl->ctrl, true);
  6297. }
  6298. /*
  6299. * Add sufficient delay to make sure
  6300. * pixel transmission as started
  6301. */
  6302. udelay(200);
  6303. end:
  6304. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6305. DSI_ALL_CLKS, DSI_CLK_OFF);
  6306. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6307. mutex_unlock(&display->display_lock);
  6308. }
  6309. static int dsi_display_cb_error_handler(void *data,
  6310. uint32_t event_idx, uint32_t instance_idx,
  6311. uint32_t data0, uint32_t data1,
  6312. uint32_t data2, uint32_t data3)
  6313. {
  6314. struct dsi_display *display = data;
  6315. if (!display || !(display->err_workq))
  6316. return -EINVAL;
  6317. switch (event_idx) {
  6318. case DSI_FIFO_UNDERFLOW:
  6319. queue_work(display->err_workq, &display->fifo_underflow_work);
  6320. break;
  6321. case DSI_FIFO_OVERFLOW:
  6322. queue_work(display->err_workq, &display->fifo_overflow_work);
  6323. break;
  6324. case DSI_LP_Rx_TIMEOUT:
  6325. queue_work(display->err_workq, &display->lp_rx_timeout_work);
  6326. break;
  6327. default:
  6328. DSI_WARN("unhandled error interrupt: %d\n", event_idx);
  6329. break;
  6330. }
  6331. return 0;
  6332. }
  6333. static void dsi_display_register_error_handler(struct dsi_display *display)
  6334. {
  6335. int i = 0;
  6336. struct dsi_display_ctrl *ctrl;
  6337. struct dsi_event_cb_info event_info;
  6338. if (!display)
  6339. return;
  6340. display->err_workq = create_singlethread_workqueue("dsi_err_workq");
  6341. if (!display->err_workq) {
  6342. DSI_ERR("failed to create dsi workq!\n");
  6343. return;
  6344. }
  6345. INIT_WORK(&display->fifo_underflow_work,
  6346. dsi_display_handle_fifo_underflow);
  6347. INIT_WORK(&display->fifo_overflow_work,
  6348. dsi_display_handle_fifo_overflow);
  6349. INIT_WORK(&display->lp_rx_timeout_work,
  6350. dsi_display_handle_lp_rx_timeout);
  6351. memset(&event_info, 0, sizeof(event_info));
  6352. event_info.event_cb = dsi_display_cb_error_handler;
  6353. event_info.event_usr_ptr = display;
  6354. display_for_each_ctrl(i, display) {
  6355. ctrl = &display->ctrl[i];
  6356. ctrl->ctrl->irq_info.irq_err_cb = event_info;
  6357. }
  6358. }
  6359. static void dsi_display_unregister_error_handler(struct dsi_display *display)
  6360. {
  6361. int i = 0;
  6362. struct dsi_display_ctrl *ctrl;
  6363. if (!display)
  6364. return;
  6365. display_for_each_ctrl(i, display) {
  6366. ctrl = &display->ctrl[i];
  6367. memset(&ctrl->ctrl->irq_info.irq_err_cb,
  6368. 0, sizeof(struct dsi_event_cb_info));
  6369. }
  6370. if (display->err_workq) {
  6371. destroy_workqueue(display->err_workq);
  6372. display->err_workq = NULL;
  6373. }
  6374. }
  6375. int dsi_display_prepare(struct dsi_display *display)
  6376. {
  6377. int rc = 0;
  6378. struct dsi_display_mode *mode;
  6379. if (!display) {
  6380. DSI_ERR("Invalid params\n");
  6381. return -EINVAL;
  6382. }
  6383. if (!display->panel->cur_mode) {
  6384. DSI_ERR("no valid mode set for the display\n");
  6385. return -EINVAL;
  6386. }
  6387. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6388. mutex_lock(&display->display_lock);
  6389. mode = display->panel->cur_mode;
  6390. dsi_display_set_ctrl_esd_check_flag(display, false);
  6391. /* Set up ctrl isr before enabling core clk */
  6392. if (!display->trusted_vm_env)
  6393. dsi_display_ctrl_isr_configure(display, true);
  6394. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6395. if (display->is_cont_splash_enabled &&
  6396. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6397. DSI_ERR("DMS not supported on first frame\n");
  6398. rc = -EINVAL;
  6399. goto error;
  6400. }
  6401. if (!is_skip_op_required(display)) {
  6402. /* update dsi ctrl for new mode */
  6403. rc = dsi_display_pre_switch(display);
  6404. if (rc)
  6405. DSI_ERR("[%s] panel pre-switch failed, rc=%d\n",
  6406. display->name, rc);
  6407. goto error;
  6408. }
  6409. }
  6410. if (!display->poms_pending &&
  6411. (!is_skip_op_required(display))) {
  6412. /*
  6413. * For continuous splash/trusted vm, we skip panel
  6414. * pre prepare since the regulator vote is already
  6415. * taken care in splash resource init
  6416. */
  6417. rc = dsi_panel_pre_prepare(display->panel);
  6418. if (rc) {
  6419. DSI_ERR("[%s] panel pre-prepare failed, rc=%d\n",
  6420. display->name, rc);
  6421. goto error;
  6422. }
  6423. }
  6424. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6425. DSI_CORE_CLK, DSI_CLK_ON);
  6426. if (rc) {
  6427. DSI_ERR("[%s] failed to enable DSI core clocks, rc=%d\n",
  6428. display->name, rc);
  6429. goto error_panel_post_unprep;
  6430. }
  6431. /*
  6432. * If ULPS during suspend feature is enabled, then DSI PHY was
  6433. * left on during suspend. In this case, we do not need to reset/init
  6434. * PHY. This would have already been done when the CORE clocks are
  6435. * turned on. However, if cont splash is disabled, the first time DSI
  6436. * is powered on, phy init needs to be done unconditionally.
  6437. */
  6438. if (!display->panel->ulps_suspend_enabled || !display->ulps_enabled) {
  6439. rc = dsi_display_phy_sw_reset(display);
  6440. if (rc) {
  6441. DSI_ERR("[%s] failed to reset phy, rc=%d\n",
  6442. display->name, rc);
  6443. goto error_ctrl_clk_off;
  6444. }
  6445. rc = dsi_display_phy_enable(display);
  6446. if (rc) {
  6447. DSI_ERR("[%s] failed to enable DSI PHY, rc=%d\n",
  6448. display->name, rc);
  6449. goto error_ctrl_clk_off;
  6450. }
  6451. }
  6452. rc = dsi_display_ctrl_init(display);
  6453. if (rc) {
  6454. DSI_ERR("[%s] failed to setup DSI controller, rc=%d\n",
  6455. display->name, rc);
  6456. goto error_phy_disable;
  6457. }
  6458. /* Set up DSI ERROR event callback */
  6459. dsi_display_register_error_handler(display);
  6460. rc = dsi_display_ctrl_host_enable(display);
  6461. if (rc) {
  6462. DSI_ERR("[%s] failed to enable DSI host, rc=%d\n",
  6463. display->name, rc);
  6464. goto error_ctrl_deinit;
  6465. }
  6466. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6467. DSI_LINK_CLK, DSI_CLK_ON);
  6468. if (rc) {
  6469. DSI_ERR("[%s] failed to enable DSI link clocks, rc=%d\n",
  6470. display->name, rc);
  6471. goto error_host_engine_off;
  6472. }
  6473. if (!is_skip_op_required(display)) {
  6474. /*
  6475. * For continuous splash/trusted vm, skip panel prepare and
  6476. * ctl reset since the pnael and ctrl is already in active
  6477. * state and panel on commands are not needed
  6478. */
  6479. rc = dsi_display_soft_reset(display);
  6480. if (rc) {
  6481. DSI_ERR("[%s] failed soft reset, rc=%d\n",
  6482. display->name, rc);
  6483. goto error_ctrl_link_off;
  6484. }
  6485. if (!display->poms_pending) {
  6486. rc = dsi_panel_prepare(display->panel);
  6487. if (rc) {
  6488. DSI_ERR("[%s] panel prepare failed, rc=%d\n",
  6489. display->name, rc);
  6490. goto error_ctrl_link_off;
  6491. }
  6492. }
  6493. }
  6494. goto error;
  6495. error_ctrl_link_off:
  6496. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6497. DSI_LINK_CLK, DSI_CLK_OFF);
  6498. error_host_engine_off:
  6499. (void)dsi_display_ctrl_host_disable(display);
  6500. error_ctrl_deinit:
  6501. (void)dsi_display_ctrl_deinit(display);
  6502. error_phy_disable:
  6503. (void)dsi_display_phy_disable(display);
  6504. error_ctrl_clk_off:
  6505. (void)dsi_display_clk_ctrl(display->dsi_clk_handle,
  6506. DSI_CORE_CLK, DSI_CLK_OFF);
  6507. error_panel_post_unprep:
  6508. (void)dsi_panel_post_unprepare(display->panel);
  6509. error:
  6510. mutex_unlock(&display->display_lock);
  6511. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6512. return rc;
  6513. }
  6514. static int dsi_display_calc_ctrl_roi(const struct dsi_display *display,
  6515. const struct dsi_display_ctrl *ctrl,
  6516. const struct msm_roi_list *req_rois,
  6517. struct dsi_rect *out_roi)
  6518. {
  6519. const struct dsi_rect *bounds = &ctrl->ctrl->mode_bounds;
  6520. struct dsi_display_mode *cur_mode;
  6521. struct msm_roi_caps *roi_caps;
  6522. struct dsi_rect req_roi = { 0 };
  6523. int rc = 0;
  6524. cur_mode = display->panel->cur_mode;
  6525. if (!cur_mode)
  6526. return 0;
  6527. roi_caps = &cur_mode->priv_info->roi_caps;
  6528. if (req_rois->num_rects > roi_caps->num_roi) {
  6529. DSI_ERR("request for %d rois greater than max %d\n",
  6530. req_rois->num_rects,
  6531. roi_caps->num_roi);
  6532. rc = -EINVAL;
  6533. goto exit;
  6534. }
  6535. /**
  6536. * if no rois, user wants to reset back to full resolution
  6537. * note: h_active is already divided by ctrl_count
  6538. */
  6539. if (!req_rois->num_rects) {
  6540. *out_roi = *bounds;
  6541. goto exit;
  6542. }
  6543. /* intersect with the bounds */
  6544. req_roi.x = req_rois->roi[0].x1;
  6545. req_roi.y = req_rois->roi[0].y1;
  6546. req_roi.w = req_rois->roi[0].x2 - req_rois->roi[0].x1;
  6547. req_roi.h = req_rois->roi[0].y2 - req_rois->roi[0].y1;
  6548. dsi_rect_intersect(&req_roi, bounds, out_roi);
  6549. exit:
  6550. /* adjust the ctrl origin to be top left within the ctrl */
  6551. out_roi->x = out_roi->x - bounds->x;
  6552. DSI_DEBUG("ctrl%d:%d: req (%d,%d,%d,%d) bnd (%d,%d,%d,%d) out (%d,%d,%d,%d)\n",
  6553. ctrl->dsi_ctrl_idx, ctrl->ctrl->cell_index,
  6554. req_roi.x, req_roi.y, req_roi.w, req_roi.h,
  6555. bounds->x, bounds->y, bounds->w, bounds->h,
  6556. out_roi->x, out_roi->y, out_roi->w, out_roi->h);
  6557. return rc;
  6558. }
  6559. static int dsi_display_qsync(struct dsi_display *display, bool enable)
  6560. {
  6561. int i;
  6562. int rc = 0;
  6563. if (!display->panel->qsync_caps.qsync_min_fps) {
  6564. DSI_ERR("%s:ERROR: qsync set, but no fps\n", __func__);
  6565. return 0;
  6566. }
  6567. mutex_lock(&display->display_lock);
  6568. display_for_each_ctrl(i, display) {
  6569. if (enable) {
  6570. /* send the commands to enable qsync */
  6571. rc = dsi_panel_send_qsync_on_dcs(display->panel, i);
  6572. if (rc) {
  6573. DSI_ERR("fail qsync ON cmds rc:%d\n", rc);
  6574. goto exit;
  6575. }
  6576. } else {
  6577. /* send the commands to enable qsync */
  6578. rc = dsi_panel_send_qsync_off_dcs(display->panel, i);
  6579. if (rc) {
  6580. DSI_ERR("fail qsync OFF cmds rc:%d\n", rc);
  6581. goto exit;
  6582. }
  6583. }
  6584. dsi_ctrl_setup_avr(display->ctrl[i].ctrl, enable);
  6585. }
  6586. exit:
  6587. SDE_EVT32(enable, display->panel->qsync_caps.qsync_min_fps, rc);
  6588. mutex_unlock(&display->display_lock);
  6589. return rc;
  6590. }
  6591. static int dsi_display_set_roi(struct dsi_display *display,
  6592. struct msm_roi_list *rois)
  6593. {
  6594. struct dsi_display_mode *cur_mode;
  6595. struct msm_roi_caps *roi_caps;
  6596. int rc = 0;
  6597. int i;
  6598. if (!display || !rois || !display->panel)
  6599. return -EINVAL;
  6600. cur_mode = display->panel->cur_mode;
  6601. if (!cur_mode)
  6602. return 0;
  6603. roi_caps = &cur_mode->priv_info->roi_caps;
  6604. if (!roi_caps->enabled)
  6605. return 0;
  6606. display_for_each_ctrl(i, display) {
  6607. struct dsi_display_ctrl *ctrl = &display->ctrl[i];
  6608. struct dsi_rect ctrl_roi;
  6609. bool changed = false;
  6610. rc = dsi_display_calc_ctrl_roi(display, ctrl, rois, &ctrl_roi);
  6611. if (rc) {
  6612. DSI_ERR("dsi_display_calc_ctrl_roi failed rc %d\n", rc);
  6613. return rc;
  6614. }
  6615. rc = dsi_ctrl_set_roi(ctrl->ctrl, &ctrl_roi, &changed);
  6616. if (rc) {
  6617. DSI_ERR("dsi_ctrl_set_roi failed rc %d\n", rc);
  6618. return rc;
  6619. }
  6620. if (!changed)
  6621. continue;
  6622. /* send the new roi to the panel via dcs commands */
  6623. rc = dsi_panel_send_roi_dcs(display->panel, i, &ctrl_roi);
  6624. if (rc) {
  6625. DSI_ERR("dsi_panel_set_roi failed rc %d\n", rc);
  6626. return rc;
  6627. }
  6628. /* re-program the ctrl with the timing based on the new roi */
  6629. rc = dsi_ctrl_timing_setup(ctrl->ctrl);
  6630. if (rc) {
  6631. DSI_ERR("dsi_ctrl_setup failed rc %d\n", rc);
  6632. return rc;
  6633. }
  6634. }
  6635. return rc;
  6636. }
  6637. int dsi_display_pre_kickoff(struct drm_connector *connector,
  6638. struct dsi_display *display,
  6639. struct msm_display_kickoff_params *params)
  6640. {
  6641. int rc = 0, ret = 0;
  6642. int i;
  6643. /* check and setup MISR */
  6644. if (display->misr_enable)
  6645. _dsi_display_setup_misr(display);
  6646. /* dynamic DSI clock setting */
  6647. if (atomic_read(&display->clkrate_change_pending)) {
  6648. mutex_lock(&display->display_lock);
  6649. /*
  6650. * acquire panel_lock to make sure no commands are in progress
  6651. */
  6652. dsi_panel_acquire_panel_lock(display->panel);
  6653. /*
  6654. * Wait for DSI command engine not to be busy sending data
  6655. * from display engine.
  6656. * If waiting fails, return "rc" instead of below "ret" so as
  6657. * not to impact DRM commit. The clock updating would be
  6658. * deferred to the next DRM commit.
  6659. */
  6660. display_for_each_ctrl(i, display) {
  6661. struct dsi_ctrl *ctrl = display->ctrl[i].ctrl;
  6662. ret = dsi_ctrl_wait_for_cmd_mode_mdp_idle(ctrl);
  6663. if (ret)
  6664. goto wait_failure;
  6665. }
  6666. /*
  6667. * Don't check the return value so as not to impact DRM commit
  6668. * when error occurs.
  6669. */
  6670. (void)dsi_display_force_update_dsi_clk(display);
  6671. wait_failure:
  6672. /* release panel_lock */
  6673. dsi_panel_release_panel_lock(display->panel);
  6674. mutex_unlock(&display->display_lock);
  6675. }
  6676. if (!ret)
  6677. rc = dsi_display_set_roi(display, params->rois);
  6678. return rc;
  6679. }
  6680. int dsi_display_config_ctrl_for_cont_splash(struct dsi_display *display)
  6681. {
  6682. int rc = 0;
  6683. if (!display || !display->panel) {
  6684. DSI_ERR("Invalid params\n");
  6685. return -EINVAL;
  6686. }
  6687. if (!display->panel->cur_mode) {
  6688. DSI_ERR("no valid mode set for the display\n");
  6689. return -EINVAL;
  6690. }
  6691. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6692. rc = dsi_display_vid_engine_enable(display);
  6693. if (rc) {
  6694. DSI_ERR("[%s]failed to enable DSI video engine, rc=%d\n",
  6695. display->name, rc);
  6696. goto error_out;
  6697. }
  6698. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6699. rc = dsi_display_cmd_engine_enable(display);
  6700. if (rc) {
  6701. DSI_ERR("[%s]failed to enable DSI cmd engine, rc=%d\n",
  6702. display->name, rc);
  6703. goto error_out;
  6704. }
  6705. } else {
  6706. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6707. rc = -EINVAL;
  6708. }
  6709. error_out:
  6710. return rc;
  6711. }
  6712. int dsi_display_pre_commit(void *display,
  6713. struct msm_display_conn_params *params)
  6714. {
  6715. bool enable = false;
  6716. int rc = 0;
  6717. if (!display || !params) {
  6718. pr_err("Invalid params\n");
  6719. return -EINVAL;
  6720. }
  6721. if (params->qsync_update) {
  6722. enable = (params->qsync_mode > 0) ? true : false;
  6723. rc = dsi_display_qsync(display, enable);
  6724. if (rc)
  6725. pr_err("%s failed to send qsync commands\n",
  6726. __func__);
  6727. SDE_EVT32(params->qsync_mode, rc);
  6728. }
  6729. return rc;
  6730. }
  6731. static void dsi_display_panel_id_notification(struct dsi_display *display)
  6732. {
  6733. if (display->panel_id != ~0x0 &&
  6734. display->ctrl[0].ctrl->panel_id_cb.event_cb) {
  6735. display->ctrl[0].ctrl->panel_id_cb.event_cb(
  6736. display->ctrl[0].ctrl->panel_id_cb.event_usr_ptr,
  6737. display->ctrl[0].ctrl->panel_id_cb.event_idx,
  6738. 0, ((display->panel_id & 0xffffffff00000000) >> 31),
  6739. (display->panel_id & 0xffffffff), 0, 0);
  6740. }
  6741. }
  6742. int dsi_display_enable(struct dsi_display *display)
  6743. {
  6744. int rc = 0;
  6745. struct dsi_display_mode *mode;
  6746. if (!display || !display->panel) {
  6747. DSI_ERR("Invalid params\n");
  6748. return -EINVAL;
  6749. }
  6750. if (!display->panel->cur_mode) {
  6751. DSI_ERR("no valid mode set for the display\n");
  6752. return -EINVAL;
  6753. }
  6754. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6755. /*
  6756. * Engine states and panel states are populated during splash
  6757. * resource/trusted vm and hence we return early
  6758. */
  6759. if (is_skip_op_required(display)) {
  6760. dsi_display_config_ctrl_for_cont_splash(display);
  6761. rc = dsi_display_splash_res_cleanup(display);
  6762. if (rc) {
  6763. DSI_ERR("Continuous splash res cleanup failed, rc=%d\n",
  6764. rc);
  6765. return -EINVAL;
  6766. }
  6767. display->panel->panel_initialized = true;
  6768. DSI_DEBUG("cont splash enabled, display enable not required\n");
  6769. dsi_display_panel_id_notification(display);
  6770. return 0;
  6771. }
  6772. mutex_lock(&display->display_lock);
  6773. mode = display->panel->cur_mode;
  6774. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6775. rc = dsi_panel_post_switch(display->panel);
  6776. if (rc) {
  6777. DSI_ERR("[%s] failed to switch DSI panel mode, rc=%d\n",
  6778. display->name, rc);
  6779. goto error;
  6780. }
  6781. } else if (!display->poms_pending) {
  6782. rc = dsi_panel_enable(display->panel);
  6783. if (rc) {
  6784. DSI_ERR("[%s] failed to enable DSI panel, rc=%d\n",
  6785. display->name, rc);
  6786. goto error;
  6787. }
  6788. }
  6789. dsi_display_panel_id_notification(display);
  6790. /* Block sending pps command if modeset is due to fps difference */
  6791. if ((mode->priv_info->dsc_enabled ||
  6792. mode->priv_info->vdc_enabled) &&
  6793. !(mode->dsi_mode_flags & DSI_MODE_FLAG_DMS_FPS)) {
  6794. rc = dsi_panel_update_pps(display->panel);
  6795. if (rc) {
  6796. DSI_ERR("[%s] panel pps cmd update failed, rc=%d\n",
  6797. display->name, rc);
  6798. goto error;
  6799. }
  6800. }
  6801. if (mode->dsi_mode_flags & DSI_MODE_FLAG_DMS) {
  6802. rc = dsi_panel_switch(display->panel);
  6803. if (rc)
  6804. DSI_ERR("[%s] failed to switch DSI panel mode, rc=%d\n",
  6805. display->name, rc);
  6806. goto error;
  6807. }
  6808. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6809. DSI_DEBUG("%s:enable video timing eng\n", __func__);
  6810. rc = dsi_display_vid_engine_enable(display);
  6811. if (rc) {
  6812. DSI_ERR("[%s]failed to enable DSI video engine, rc=%d\n",
  6813. display->name, rc);
  6814. goto error_disable_panel;
  6815. }
  6816. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6817. DSI_DEBUG("%s:enable command timing eng\n", __func__);
  6818. rc = dsi_display_cmd_engine_enable(display);
  6819. if (rc) {
  6820. DSI_ERR("[%s]failed to enable DSI cmd engine, rc=%d\n",
  6821. display->name, rc);
  6822. goto error_disable_panel;
  6823. }
  6824. } else {
  6825. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6826. rc = -EINVAL;
  6827. goto error_disable_panel;
  6828. }
  6829. goto error;
  6830. error_disable_panel:
  6831. (void)dsi_panel_disable(display->panel);
  6832. error:
  6833. mutex_unlock(&display->display_lock);
  6834. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6835. return rc;
  6836. }
  6837. int dsi_display_post_enable(struct dsi_display *display)
  6838. {
  6839. int rc = 0;
  6840. if (!display) {
  6841. DSI_ERR("Invalid params\n");
  6842. return -EINVAL;
  6843. }
  6844. mutex_lock(&display->display_lock);
  6845. if (display->panel->cur_mode->dsi_mode_flags &
  6846. DSI_MODE_FLAG_POMS_TO_CMD) {
  6847. dsi_panel_switch_cmd_mode_in(display->panel);
  6848. } else if (display->panel->cur_mode->dsi_mode_flags &
  6849. DSI_MODE_FLAG_POMS_TO_VID)
  6850. dsi_panel_switch_video_mode_in(display->panel);
  6851. else {
  6852. rc = dsi_panel_post_enable(display->panel);
  6853. if (rc)
  6854. DSI_ERR("[%s] panel post-enable failed, rc=%d\n",
  6855. display->name, rc);
  6856. }
  6857. /* remove the clk vote for CMD mode panels */
  6858. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6859. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6860. DSI_ALL_CLKS, DSI_CLK_OFF);
  6861. mutex_unlock(&display->display_lock);
  6862. return rc;
  6863. }
  6864. int dsi_display_pre_disable(struct dsi_display *display)
  6865. {
  6866. int rc = 0;
  6867. if (!display) {
  6868. DSI_ERR("Invalid params\n");
  6869. return -EINVAL;
  6870. }
  6871. mutex_lock(&display->display_lock);
  6872. /* enable the clk vote for CMD mode panels */
  6873. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6874. dsi_display_clk_ctrl(display->dsi_clk_handle,
  6875. DSI_ALL_CLKS, DSI_CLK_ON);
  6876. if (display->poms_pending) {
  6877. if (display->config.panel_mode == DSI_OP_CMD_MODE)
  6878. dsi_panel_switch_cmd_mode_out(display->panel);
  6879. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6880. /*
  6881. * Add unbalanced vote for clock & cmd engine to enable
  6882. * async trigger of pre video to cmd mode switch.
  6883. */
  6884. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6885. DSI_ALL_CLKS, DSI_CLK_ON);
  6886. if (rc) {
  6887. DSI_ERR("[%s]failed to enable all clocks,rc=%d",
  6888. display->name, rc);
  6889. goto exit;
  6890. }
  6891. rc = dsi_display_cmd_engine_enable(display);
  6892. if (rc) {
  6893. DSI_ERR("[%s]failed to enable cmd engine,rc=%d",
  6894. display->name, rc);
  6895. goto error_disable_clks;
  6896. }
  6897. dsi_panel_switch_video_mode_out(display->panel);
  6898. }
  6899. } else {
  6900. rc = dsi_panel_pre_disable(display->panel);
  6901. if (rc)
  6902. DSI_ERR("[%s] panel pre-disable failed, rc=%d\n",
  6903. display->name, rc);
  6904. }
  6905. goto exit;
  6906. error_disable_clks:
  6907. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  6908. DSI_ALL_CLKS, DSI_CLK_OFF);
  6909. if (rc)
  6910. DSI_ERR("[%s] failed to disable all DSI clocks, rc=%d\n",
  6911. display->name, rc);
  6912. exit:
  6913. mutex_unlock(&display->display_lock);
  6914. return rc;
  6915. }
  6916. static void dsi_display_handle_poms_te(struct work_struct *work)
  6917. {
  6918. struct dsi_display *display = NULL;
  6919. struct delayed_work *dw = to_delayed_work(work);
  6920. struct mipi_dsi_device *dsi = NULL;
  6921. struct dsi_panel *panel = NULL;
  6922. int rc = 0;
  6923. display = container_of(dw, struct dsi_display, poms_te_work);
  6924. if (!display || !display->panel) {
  6925. DSI_ERR("Invalid params\n");
  6926. return;
  6927. }
  6928. panel = display->panel;
  6929. mutex_lock(&panel->panel_lock);
  6930. if (!dsi_panel_initialized(panel)) {
  6931. rc = -EINVAL;
  6932. goto error;
  6933. }
  6934. dsi = &panel->mipi_device;
  6935. rc = mipi_dsi_dcs_set_tear_off(dsi);
  6936. error:
  6937. mutex_unlock(&panel->panel_lock);
  6938. if (rc < 0)
  6939. DSI_ERR("failed to set tear off\n");
  6940. }
  6941. int dsi_display_disable(struct dsi_display *display)
  6942. {
  6943. int rc = 0;
  6944. if (!display) {
  6945. DSI_ERR("Invalid params\n");
  6946. return -EINVAL;
  6947. }
  6948. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  6949. mutex_lock(&display->display_lock);
  6950. /* cancel delayed work */
  6951. if (display->poms_pending &&
  6952. display->panel->poms_align_vsync)
  6953. cancel_delayed_work_sync(&display->poms_te_work);
  6954. rc = dsi_display_wake_up(display);
  6955. if (rc)
  6956. DSI_ERR("[%s] display wake up failed, rc=%d\n",
  6957. display->name, rc);
  6958. if (display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  6959. rc = dsi_display_vid_engine_disable(display);
  6960. if (rc)
  6961. DSI_ERR("[%s]failed to disable DSI vid engine, rc=%d\n",
  6962. display->name, rc);
  6963. } else if (display->config.panel_mode == DSI_OP_CMD_MODE) {
  6964. /**
  6965. * On POMS request , disable panel TE through
  6966. * delayed work queue.
  6967. */
  6968. if (display->poms_pending &&
  6969. display->panel->poms_align_vsync) {
  6970. INIT_DELAYED_WORK(&display->poms_te_work,
  6971. dsi_display_handle_poms_te);
  6972. queue_delayed_work(system_wq,
  6973. &display->poms_te_work,
  6974. msecs_to_jiffies(100));
  6975. }
  6976. rc = dsi_display_cmd_engine_disable(display);
  6977. if (rc)
  6978. DSI_ERR("[%s]failed to disable DSI cmd engine, rc=%d\n",
  6979. display->name, rc);
  6980. } else {
  6981. DSI_ERR("[%s] Invalid configuration\n", display->name);
  6982. rc = -EINVAL;
  6983. }
  6984. if (!display->poms_pending && !is_skip_op_required(display)) {
  6985. rc = dsi_panel_disable(display->panel);
  6986. if (rc)
  6987. DSI_ERR("[%s] failed to disable DSI panel, rc=%d\n",
  6988. display->name, rc);
  6989. }
  6990. if (is_skip_op_required(display)) {
  6991. /* applicable only for trusted vm */
  6992. display->panel->panel_initialized = false;
  6993. display->panel->power_mode = SDE_MODE_DPMS_OFF;
  6994. }
  6995. mutex_unlock(&display->display_lock);
  6996. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  6997. return rc;
  6998. }
  6999. int dsi_display_update_pps(char *pps_cmd, void *disp)
  7000. {
  7001. struct dsi_display *display;
  7002. if (pps_cmd == NULL || disp == NULL) {
  7003. DSI_ERR("Invalid parameter\n");
  7004. return -EINVAL;
  7005. }
  7006. display = disp;
  7007. mutex_lock(&display->display_lock);
  7008. memcpy(display->panel->dce_pps_cmd, pps_cmd, DSI_CMD_PPS_SIZE);
  7009. mutex_unlock(&display->display_lock);
  7010. return 0;
  7011. }
  7012. int dsi_display_dump_clks_state(struct dsi_display *display)
  7013. {
  7014. int rc = 0;
  7015. if (!display) {
  7016. DSI_ERR("invalid display argument\n");
  7017. return -EINVAL;
  7018. }
  7019. if (!display->clk_mngr) {
  7020. DSI_ERR("invalid clk manager\n");
  7021. return -EINVAL;
  7022. }
  7023. if (!display->dsi_clk_handle || !display->mdp_clk_handle) {
  7024. DSI_ERR("invalid clk handles\n");
  7025. return -EINVAL;
  7026. }
  7027. mutex_lock(&display->display_lock);
  7028. rc = dsi_display_dump_clk_handle_state(display->dsi_clk_handle);
  7029. if (rc) {
  7030. DSI_ERR("failed to dump dsi clock state\n");
  7031. goto end;
  7032. }
  7033. rc = dsi_display_dump_clk_handle_state(display->mdp_clk_handle);
  7034. if (rc) {
  7035. DSI_ERR("failed to dump mdp clock state\n");
  7036. goto end;
  7037. }
  7038. end:
  7039. mutex_unlock(&display->display_lock);
  7040. return rc;
  7041. }
  7042. int dsi_display_unprepare(struct dsi_display *display)
  7043. {
  7044. int rc = 0, i;
  7045. struct dsi_display_ctrl *ctrl;
  7046. if (!display) {
  7047. DSI_ERR("Invalid params\n");
  7048. return -EINVAL;
  7049. }
  7050. SDE_EVT32(SDE_EVTLOG_FUNC_ENTRY);
  7051. mutex_lock(&display->display_lock);
  7052. rc = dsi_display_wake_up(display);
  7053. if (rc)
  7054. DSI_ERR("[%s] display wake up failed, rc=%d\n",
  7055. display->name, rc);
  7056. if (!display->poms_pending && !is_skip_op_required(display)) {
  7057. rc = dsi_panel_unprepare(display->panel);
  7058. if (rc)
  7059. DSI_ERR("[%s] panel unprepare failed, rc=%d\n",
  7060. display->name, rc);
  7061. }
  7062. /* Remove additional vote added for pre_mode_switch_to_cmd */
  7063. if (display->poms_pending &&
  7064. display->config.panel_mode == DSI_OP_VIDEO_MODE) {
  7065. display_for_each_ctrl(i, display) {
  7066. ctrl = &display->ctrl[i];
  7067. if (!ctrl->ctrl || !ctrl->ctrl->dma_wait_queued)
  7068. continue;
  7069. flush_workqueue(display->dma_cmd_workq);
  7070. cancel_work_sync(&ctrl->ctrl->dma_cmd_wait);
  7071. ctrl->ctrl->dma_wait_queued = false;
  7072. }
  7073. dsi_display_cmd_engine_disable(display);
  7074. dsi_display_clk_ctrl(display->dsi_clk_handle,
  7075. DSI_ALL_CLKS, DSI_CLK_OFF);
  7076. }
  7077. rc = dsi_display_ctrl_host_disable(display);
  7078. if (rc)
  7079. DSI_ERR("[%s] failed to disable DSI host, rc=%d\n",
  7080. display->name, rc);
  7081. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  7082. DSI_LINK_CLK, DSI_CLK_OFF);
  7083. if (rc)
  7084. DSI_ERR("[%s] failed to disable Link clocks, rc=%d\n",
  7085. display->name, rc);
  7086. rc = dsi_display_ctrl_deinit(display);
  7087. if (rc)
  7088. DSI_ERR("[%s] failed to deinit controller, rc=%d\n",
  7089. display->name, rc);
  7090. if (!display->panel->ulps_suspend_enabled) {
  7091. rc = dsi_display_phy_disable(display);
  7092. if (rc)
  7093. DSI_ERR("[%s] failed to disable DSI PHY, rc=%d\n",
  7094. display->name, rc);
  7095. }
  7096. rc = dsi_display_clk_ctrl(display->dsi_clk_handle,
  7097. DSI_CORE_CLK, DSI_CLK_OFF);
  7098. if (rc)
  7099. DSI_ERR("[%s] failed to disable DSI clocks, rc=%d\n",
  7100. display->name, rc);
  7101. /* destrory dsi isr set up */
  7102. dsi_display_ctrl_isr_configure(display, false);
  7103. if (!display->poms_pending && !is_skip_op_required(display)) {
  7104. rc = dsi_panel_post_unprepare(display->panel);
  7105. if (rc)
  7106. DSI_ERR("[%s] panel post-unprepare failed, rc=%d\n",
  7107. display->name, rc);
  7108. }
  7109. mutex_unlock(&display->display_lock);
  7110. /* Free up DSI ERROR event callback */
  7111. dsi_display_unregister_error_handler(display);
  7112. SDE_EVT32(SDE_EVTLOG_FUNC_EXIT);
  7113. return rc;
  7114. }
  7115. void __init dsi_display_register(void)
  7116. {
  7117. dsi_phy_drv_register();
  7118. dsi_ctrl_drv_register();
  7119. dsi_display_parse_boot_display_selection();
  7120. platform_driver_register(&dsi_display_driver);
  7121. }
  7122. void __exit dsi_display_unregister(void)
  7123. {
  7124. platform_driver_unregister(&dsi_display_driver);
  7125. dsi_ctrl_drv_unregister();
  7126. dsi_phy_drv_unregister();
  7127. }
  7128. module_param_string(dsi_display0, dsi_display_primary, MAX_CMDLINE_PARAM_LEN,
  7129. 0600);
  7130. MODULE_PARM_DESC(dsi_display0,
  7131. "msm_drm.dsi_display0=<display node>:<configX> where <display node> is 'primary dsi display node name' and <configX> where x represents index in the topology list");
  7132. module_param_string(dsi_display1, dsi_display_secondary, MAX_CMDLINE_PARAM_LEN,
  7133. 0600);
  7134. MODULE_PARM_DESC(dsi_display1,
  7135. "msm_drm.dsi_display1=<display node>:<configX> where <display node> is 'secondary dsi display node name' and <configX> where x represents index in the topology list");