dsi_display.c 209 KB

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