dsi_display.c 208 KB

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